|
1 /* |
|
2 * Copyright (c) 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <spawn.h> |
|
19 #include <memory> |
|
20 #include <stdlib.h> |
|
21 #include <ccertattributefilter.h> |
|
22 #include "testutils.h" |
|
23 #include "testfailedexception.h" |
|
24 #include "logger.h" |
|
25 |
|
26 _LIT(KMIDP2TrustRoot, "Java Trust Root"); |
|
27 |
|
28 bool TestUtils::sCaptainRunning = false; |
|
29 |
|
30 void tbufC8tochar(TDesC8 aSrc, char* aDes) |
|
31 { |
|
32 char *temp = (char*)aSrc.Ptr(); |
|
33 const TInt size = aSrc.Length(); |
|
34 *(temp + size) = '\0'; |
|
35 strcpy(aDes, temp); |
|
36 } |
|
37 |
|
38 void CheckCertInfo(std::list<CertMetaData>& aExpected,CCTCertInfo* aInfo) |
|
39 { |
|
40 std::list<CertMetaData>::iterator iter = aExpected.begin(); |
|
41 bool metaDataObjFound = false; |
|
42 for (; iter != aExpected.end(); ++iter) |
|
43 { |
|
44 int expectedSize = iter->mCertContent.size(); |
|
45 //'-1' is decreased because Windows file system adds one extra byte to the file size. |
|
46 int actualSize = aInfo->Size() - 1; |
|
47 if (expectedSize == actualSize) |
|
48 { |
|
49 metaDataObjFound = true; |
|
50 if (EX509Certificate != aInfo->CertificateFormat()) |
|
51 { |
|
52 throw TestFailedException("Incorrect CertificateFormat", |
|
53 __FILE__,__FUNCTION__,__LINE__); |
|
54 } |
|
55 if (ECACertificate != aInfo->CertificateOwnerType()) |
|
56 { |
|
57 throw TestFailedException("Incorrect CertificateOwnerType", |
|
58 __FILE__,__FUNCTION__,__LINE__); |
|
59 } |
|
60 if (iter->mRemovable != aInfo->IsDeletable()) |
|
61 { |
|
62 throw TestFailedException("Incorrect IsDeletable value", |
|
63 __FILE__,__FUNCTION__,__LINE__); |
|
64 } |
|
65 break; |
|
66 }//end if(expectedSize == actualSize) |
|
67 }//end for |
|
68 if (false == metaDataObjFound) |
|
69 { |
|
70 throw TestFailedException("Corresponding CertMetaData obj was not found", |
|
71 __FILE__,__FUNCTION__,__LINE__); |
|
72 } |
|
73 } |
|
74 |
|
75 int TestUtils::StartJavaCaptain() |
|
76 { |
|
77 if (true == sCaptainRunning) |
|
78 { |
|
79 return 0; |
|
80 } |
|
81 int rc = 0; |
|
82 int pid = 0; |
|
83 char* av[2]; |
|
84 int index = 0; |
|
85 av[index++] = "javacaptain"; |
|
86 av[index] = NULL; |
|
87 |
|
88 #ifdef __SYMBIAN32__ |
|
89 rc = posix_spawn(&pid, "javacaptain", NULL, NULL, av, NULL); |
|
90 #else |
|
91 if (!(pid = fork())) |
|
92 { |
|
93 rc = execvp("javacaptain", av); |
|
94 if (rc == -1) |
|
95 { |
|
96 rc = errno; |
|
97 } |
|
98 } |
|
99 #endif // __SYMBIAN32__ |
|
100 |
|
101 if (rc) |
|
102 { |
|
103 ELOG3(EJavaSecurity,"%s failed, %s - errno=%d", __PRETTY_FUNCTION__, strerror(rc), rc); |
|
104 } |
|
105 sCaptainRunning = true; |
|
106 return rc; |
|
107 } |
|
108 |
|
109 CCertAttributeFilter* TestUtils::GetFilterObj() |
|
110 { |
|
111 std::auto_ptr< CCertAttributeFilter> retObj(CCertAttributeFilter::NewL()); |
|
112 TUid uid = TUid::Uid(0x101F9B28); |
|
113 retObj->SetUid(uid); |
|
114 retObj->SetFormat(EX509Certificate); |
|
115 retObj->SetOwnerType(ECACertificate); |
|
116 retObj->SetLabel(KMIDP2TrustRoot()); |
|
117 return retObj.release(); |
|
118 } |
|
119 |
|
120 void TestUtils::CheckResultOfList(std::list<CertMetaData>& aExpected, |
|
121 RMPointerArray<CCTCertInfo>& aResult) |
|
122 { |
|
123 for (TInt i = 0; i < aResult.Count(); i++) |
|
124 { |
|
125 CheckCertInfo(aExpected,aResult[i]); |
|
126 } |
|
127 } |
|
128 |
|
129 void TestUtils::CheckContentOfCert(std::list<CertMetaData>& aExpected, |
|
130 HBufC8* aContent) |
|
131 { |
|
132 std::list<CertMetaData>::iterator iter = aExpected.begin(); |
|
133 bool metaDataObjFound = false; |
|
134 char* tmpChar = new char[aContent->Length()+1]; |
|
135 tbufC8tochar(aContent->Des(),tmpChar); |
|
136 std::string returnedContent(tmpChar); |
|
137 delete [] tmpChar; |
|
138 for (; iter != aExpected.end(); ++iter) |
|
139 { |
|
140 if (returnedContent.size() == iter->mCertContent.size()) |
|
141 { |
|
142 metaDataObjFound = true; |
|
143 if (0 == returnedContent.compare(iter->mCertContent)) |
|
144 { |
|
145 throw TestFailedException("Incorrect cert content", |
|
146 __FILE__,__FUNCTION__,__LINE__); |
|
147 } |
|
148 break; |
|
149 } |
|
150 }//end for |
|
151 if (false == metaDataObjFound) |
|
152 { |
|
153 throw TestFailedException("Corresponding CertMetaData obj was not found", |
|
154 __FILE__,__FUNCTION__,__LINE__); |
|
155 } |
|
156 } |
|
157 |