|
1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "stepbase.h" |
|
17 |
|
18 #include <f32file.h> |
|
19 |
|
20 void CStepBase::InitializeL() |
|
21 { |
|
22 // Read the certificate parameter and construct |
|
23 // the required certificate |
|
24 |
|
25 _LIT(KCertificateName, "cert"); |
|
26 TPtrC fileName; |
|
27 |
|
28 if (!GetStringFromConfig(ConfigSection(), KCertificateName, fileName)) |
|
29 { |
|
30 |
|
31 _LIT(KMessage, "Could not read certificate path from INI, abort."); |
|
32 Logger().Write(KMessage); |
|
33 |
|
34 SetTestStepResult(EAbort); |
|
35 User::Leave(KErrAbort); |
|
36 } |
|
37 else |
|
38 { |
|
39 _LIT(KMessageFormat, "Using certificate file for test '%S'"); |
|
40 Logger().WriteFormat(KMessageFormat, &fileName); |
|
41 } |
|
42 |
|
43 RFs fs; |
|
44 User::LeaveIfError(fs.Connect()); |
|
45 CleanupClosePushL(fs); |
|
46 |
|
47 RFile file; |
|
48 User::LeaveIfError(file.Open(fs, fileName, EFileRead | EFileShareReadersOnly)); |
|
49 CleanupClosePushL(file); |
|
50 |
|
51 TInt size; |
|
52 User::LeaveIfError(file.Size(size)); |
|
53 |
|
54 HBufC8* certBuffer = HBufC8::NewL(size); |
|
55 TPtr8 buf = certBuffer->Des(); |
|
56 CleanupStack::PushL(certBuffer); |
|
57 User::LeaveIfError(file.Read(buf)); |
|
58 |
|
59 // construct the certificate from the raw data |
|
60 iCertificate = CX509Certificate::NewL(*certBuffer); |
|
61 |
|
62 CleanupStack::PopAndDestroy(3, &fs); |
|
63 |
|
64 // connect to the tls cache server |
|
65 User::LeaveIfError(iSession.Open(Certificate())); |
|
66 |
|
67 } |
|
68 |
|
69 HBufC* CStepBase::SubjectLC() |
|
70 { |
|
71 HBufC* subject = iCertificate->SubjectL(); |
|
72 CleanupStack::PushL(subject); |
|
73 return subject; |
|
74 } |
|
75 |
|
76 CStepBase::~CStepBase() |
|
77 { |
|
78 iSession.Close(); |
|
79 delete iCertificate; |
|
80 } |