|
1 /* |
|
2 * Copyright (c) 2002-2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Implementation of TDmAdCertUtil. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include <x509cert.h> |
|
21 #include <x509keys.h> |
|
22 #include <x500dn.h> |
|
23 |
|
24 #include "dmadcertutil.h" |
|
25 #include "pkcs10.h" |
|
26 #include "utlcrypto.h" |
|
27 |
|
28 |
|
29 void TDmAdCertUtil::ParseAvaL(const CX520AttributeTypeAndValue& aAva, TDes8& aOut) |
|
30 { |
|
31 TPtrC8 attr = CPkcs10Req::AttributeTypeOidToText(aAva.Type()); |
|
32 TBuf8<32> tempOidBuf; |
|
33 HBufC* val = NULL; |
|
34 TRAPD(ret, val = aAva.ValueL()); |
|
35 if(ret == KErrNone) |
|
36 { |
|
37 CleanupStack::PushL(val); |
|
38 if(attr.Length() == 0) |
|
39 { |
|
40 // Dotted oid representation |
|
41 tempOidBuf.Copy(aAva.Type()); |
|
42 aOut.Append(tempOidBuf); |
|
43 } |
|
44 else |
|
45 { |
|
46 aOut.Append(attr); |
|
47 } |
|
48 aOut.Append(_L("=")); |
|
49 aOut.Append(val->Des()); |
|
50 CleanupStack::PopAndDestroy(val); |
|
51 } |
|
52 } |
|
53 |
|
54 void TDmAdCertUtil::CertDnL(const CX500DistinguishedName& aName, TDes8& aOut) |
|
55 { |
|
56 TInt count = aName.Count(); |
|
57 for (TInt i = 0; i < count; i++) |
|
58 { |
|
59 if(i > 0) |
|
60 aOut.Append(_L(",")); |
|
61 const CX520AttributeTypeAndValue& ava = aName.Element(i); |
|
62 ParseAvaL(ava, aOut); |
|
63 } |
|
64 } |
|
65 |
|
66 HBufC8* TDmAdCertUtil::Sha1DigestL(const TDesC8& aData) |
|
67 { |
|
68 CUtlMessageDigest* digester = TUtlCrypto::MakeMessageDigesterL(TUtlCrypto::EUtlMessageDigestSha1); |
|
69 CleanupStack::PushL(digester); |
|
70 |
|
71 HBufC8* hashBuf = HBufC8::NewLC(digester->HashSize()); |
|
72 TPtr8 hashBufDesc(hashBuf->Des()); |
|
73 |
|
74 hashBufDesc.Copy(digester->Final(aData)); |
|
75 CleanupStack::Pop(hashBuf); |
|
76 CleanupStack::PopAndDestroy(digester); |
|
77 return hashBuf; |
|
78 } |
|
79 |
|
80 HBufC8* TDmAdCertUtil::RSAKeyIdentifierLC(const TDesC8& aKeyData) |
|
81 { |
|
82 TX509KeyFactory keyFactory; |
|
83 CRSAPublicKey* rsaKey = keyFactory.RSAPublicKeyL(aKeyData); |
|
84 CleanupStack::PushL(rsaKey); |
|
85 HBufC8* modulusBuffer = rsaKey->N().BufferLC(); |
|
86 HBufC8* hash = TDmAdCertUtil::Sha1DigestL(*modulusBuffer); |
|
87 CleanupStack::PopAndDestroy(2); // modulusBuffer, rsaKey |
|
88 CleanupStack::PushL(hash); |
|
89 return hash; |
|
90 } |