|
1 /* |
|
2 * Copyright (c) 2007-2009 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: Class containing information about one CA cert |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include <x509cert.h> |
|
22 |
|
23 #include "ikecaelem.h" |
|
24 #include "ikecert.h" |
|
25 #include "utlcrypto.h" |
|
26 #include "ikev1pkiservice.h" |
|
27 #include "ikecertconst.h" |
|
28 |
|
29 EXPORT_C CIkeCaElem* CIkeCaElem::NewL(HBufC8* aCert) |
|
30 { |
|
31 ASSERT(aCert); |
|
32 CIkeCaElem* CaElem = new (ELeave) CIkeCaElem(); |
|
33 CleanupStack::PushL(CaElem); |
|
34 CaElem->iCaCert = CX509Certificate::NewL(*aCert); |
|
35 delete aCert; |
|
36 HBufC8* PublicKeyInfo = IkeCert::GetCertificateFieldDERL(CaElem->iCaCert, KPublicKeyInfo); |
|
37 CleanupStack::PushL(PublicKeyInfo); |
|
38 |
|
39 // |
|
40 // Calculate "Key Id" value as a SHA1 hash Subject Public Key Info element |
|
41 // (specified so in IKEv2 draft) |
|
42 // |
|
43 CaElem->iKeyInfo = HBufC8::NewL(IKEV2_CERT_KEYID_SIZE); |
|
44 CUtlMessageDigest* Digest = TUtlCrypto::MakeMessageDigesterL(TUtlCrypto::EUtlMessageDigestSha1); |
|
45 TPtrC8 InData(PublicKeyInfo->Des()); |
|
46 TPtrC8 KeyId = Digest->Final(InData); |
|
47 CaElem->iKeyInfo->Des().Copy(KeyId); |
|
48 delete Digest; |
|
49 |
|
50 CleanupStack::PopAndDestroy(PublicKeyInfo); |
|
51 CleanupStack::Pop(CaElem); |
|
52 return CaElem; |
|
53 } |
|
54 |
|
55 |
|
56 EXPORT_C CIkeCaElem::~CIkeCaElem() |
|
57 { |
|
58 delete iCaCert; |
|
59 delete iKeyInfo; |
|
60 } |
|
61 |
|
62 |
|
63 EXPORT_C CX509Certificate* CIkeCaElem::Certificate() const |
|
64 { |
|
65 return iCaCert; |
|
66 } |
|
67 |
|
68 |
|
69 EXPORT_C const TDesC8& CIkeCaElem::KeyHash() const |
|
70 { |
|
71 return *iKeyInfo; |
|
72 } |
|
73 |