|
1 /* |
|
2 * Copyright (c) 2008 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 |
|
19 // INCLUDE FILES |
|
20 |
|
21 #include "javax_microedition_pki_UserCredentialManager.h" |
|
22 #include "cstscredentialmanager.h" |
|
23 #include "satsajnitools.h" |
|
24 #include "s60commonutils.h" |
|
25 #include "fs_methodcall.h" |
|
26 |
|
27 |
|
28 |
|
29 LOCAL_C void CallCreateCredentialManagerAddToEventSourceL( |
|
30 TInt* aManagerHandle) |
|
31 { |
|
32 CSTSCredentialManager* manager = CSTSCredentialManager::NewLC(); |
|
33 TInt managerHandle = reinterpret_cast<TInt>(manager) ; |
|
34 CleanupStack::Pop(manager); |
|
35 *aManagerHandle = managerHandle; |
|
36 } |
|
37 |
|
38 JNIEXPORT jint JNICALL |
|
39 Java_javax_microedition_pki_UserCredentialManager__1createUCManager( |
|
40 JNIEnv* /* aJniEnv */, |
|
41 jobject /* aPeer */) |
|
42 { |
|
43 |
|
44 |
|
45 TInt managerHandle = KErrGeneral; |
|
46 |
|
47 TInt error = KErrNone; |
|
48 TRAP(error, |
|
49 CallCreateCredentialManagerAddToEventSourceL( |
|
50 &managerHandle)); |
|
51 |
|
52 if (error != KErrNone) |
|
53 { |
|
54 return error; |
|
55 } |
|
56 |
|
57 return managerHandle; |
|
58 } |
|
59 |
|
60 JNIEXPORT jint |
|
61 JNICALL Java_javax_microedition_pki_UserCredentialManager__1addCredential( |
|
62 JNIEnv* aJniEnv, |
|
63 jobject /* aPeer */, |
|
64 jint aManagerHandle, |
|
65 jstring aCertDisplayName, jbyteArray aPkiPath) |
|
66 { |
|
67 |
|
68 |
|
69 CSTSCredentialManager* manager = |
|
70 reinterpret_cast<CSTSCredentialManager *>(aManagerHandle); |
|
71 |
|
72 const RJString certDisplayName(*aJniEnv, aCertDisplayName); |
|
73 const TInt pkiPathLength = aJniEnv->GetArrayLength(aPkiPath); |
|
74 jbyte* pkiPath = aJniEnv->GetByteArrayElements(aPkiPath, NULL); |
|
75 if (!pkiPath) |
|
76 { |
|
77 return KErrNoMemory; |
|
78 } |
|
79 TPtrC8 pkiDes(reinterpret_cast< const TUint8 * >(pkiPath), |
|
80 pkiPathLength); |
|
81 |
|
82 TBool completed = EFalse; |
|
83 TInt arg1 = reinterpret_cast<TInt>(&certDisplayName); |
|
84 TInt arg2 = reinterpret_cast<TInt>(&pkiDes); |
|
85 |
|
86 TInt error = KErrNone; |
|
87 TRAP(error,CallMethodL(completed,manager, |
|
88 &CSTSCredentialManager::AddCredentialL, |
|
89 arg1, |
|
90 arg2,manager)); |
|
91 |
|
92 aJniEnv->ReleaseByteArrayElements(aPkiPath, pkiPath, 0); |
|
93 |
|
94 if (error == KErrNone) |
|
95 { |
|
96 return !completed; |
|
97 } |
|
98 return error; |
|
99 } |
|
100 |
|
101 JNIEXPORT jint |
|
102 JNICALL Java_javax_microedition_pki_UserCredentialManager__1removeCredential( |
|
103 JNIEnv* aJniEnv, |
|
104 jobject /* aPeer */, |
|
105 jint aManagerHandle, |
|
106 jstring aCertDisplayName, jbyteArray aIssuerAndSerialNumber, |
|
107 jstring aSecurityElementID, jstring aSecurityElementPrompt) |
|
108 { |
|
109 |
|
110 CSTSCredentialManager* manager = |
|
111 reinterpret_cast<CSTSCredentialManager *>(aManagerHandle); |
|
112 |
|
113 const RJString certDisplayName(*aJniEnv, aCertDisplayName); |
|
114 const TInt issuerLength = |
|
115 aJniEnv->GetArrayLength(aIssuerAndSerialNumber); |
|
116 jbyte* issuerAndSerialNumber = |
|
117 aJniEnv->GetByteArrayElements(aIssuerAndSerialNumber, NULL); |
|
118 if (!issuerAndSerialNumber) |
|
119 { |
|
120 return KErrNoMemory; |
|
121 } |
|
122 |
|
123 TPtrC8 issuerDes( |
|
124 reinterpret_cast< const TUint8 * >(issuerAndSerialNumber), |
|
125 issuerLength); |
|
126 |
|
127 const RJString securityElementID(*aJniEnv, aSecurityElementID); |
|
128 const RJString securityElementPrompt(*aJniEnv, aSecurityElementPrompt); |
|
129 |
|
130 TBool completed = EFalse; |
|
131 TInt arg1 = reinterpret_cast<TInt>(&certDisplayName); |
|
132 TInt arg2 = reinterpret_cast<TInt>(&issuerDes); |
|
133 TInt arg3 = reinterpret_cast<TInt>(&securityElementID); |
|
134 TInt arg4 = reinterpret_cast<TInt>(&securityElementPrompt); |
|
135 TInt arg5 = reinterpret_cast<TInt>(&completed); |
|
136 |
|
137 TInt error = KErrNone; |
|
138 TRAP(error, |
|
139 CallMethodL(manager,&CSTSCredentialManager::StaticRemoveCredentialL, |
|
140 arg1, |
|
141 arg2, |
|
142 arg3, |
|
143 arg4, |
|
144 arg5,manager)); |
|
145 |
|
146 aJniEnv->ReleaseByteArrayElements(aIssuerAndSerialNumber, |
|
147 issuerAndSerialNumber, 0); |
|
148 |
|
149 |
|
150 if (error == KErrNone) |
|
151 { |
|
152 return completed ? 0 : 1; |
|
153 } |
|
154 return error; |
|
155 } |
|
156 |
|
157 |
|
158 JNIEXPORT jbyteArray |
|
159 JNICALL Java_javax_microedition_pki_UserCredentialManager__1generateCSR( |
|
160 JNIEnv* aJniEnv, |
|
161 jobject /*aPeer*/, |
|
162 jint aManagerHandle, jstring aNameInfo, |
|
163 jstring aAlgorithm, jint aKeyLen, jint aKeyUsage, |
|
164 jstring aSecurityElementID, jstring aSecurityElementPrompt, |
|
165 jintArray aError) |
|
166 { |
|
167 CSTSCredentialManager* manager = |
|
168 reinterpret_cast<CSTSCredentialManager *>(aManagerHandle); |
|
169 |
|
170 const RJString nameInfo(*aJniEnv, aNameInfo); |
|
171 const RJString algorithm(*aJniEnv, aAlgorithm); |
|
172 const RJString securityElementID(*aJniEnv, aSecurityElementID); |
|
173 const RJString securityElementPrompt(*aJniEnv, aSecurityElementPrompt); |
|
174 |
|
175 TDesC8* retVal = NULL; |
|
176 |
|
177 CSTSCredentialManager::TGenerateCSRParams params = |
|
178 { |
|
179 static_cast< const TDesC* >(&nameInfo), |
|
180 static_cast< const TDesC* >(&algorithm), |
|
181 aKeyLen, aKeyUsage, |
|
182 static_cast< const TDesC* >(&securityElementID), |
|
183 static_cast< const TDesC* >(&securityElementPrompt) |
|
184 }; |
|
185 |
|
186 TInt arg1 = reinterpret_cast<TInt>(¶ms); |
|
187 TInt arg2 = reinterpret_cast<TInt>(&retVal); |
|
188 |
|
189 TInt error = KErrNone; |
|
190 TRAP(error, |
|
191 CallMethodL(manager,&CSTSCredentialManager::StaticGenerateCSRL, |
|
192 arg1, arg2, |
|
193 manager)); |
|
194 |
|
195 |
|
196 STSSetJavaErrorCode(aJniEnv, aError, error); |
|
197 |
|
198 if (error != KErrNone) |
|
199 { |
|
200 return NULL; |
|
201 } |
|
202 |
|
203 const TInt numBytes = retVal->Length(); |
|
204 jbyteArray javaValue = aJniEnv->NewByteArray(numBytes); |
|
205 |
|
206 if (!javaValue) |
|
207 { |
|
208 STSSetJavaErrorCode(aJniEnv, aError, KErrNoMemory); |
|
209 return NULL; |
|
210 } |
|
211 |
|
212 if (numBytes > 0) |
|
213 { |
|
214 aJniEnv->SetByteArrayRegion( |
|
215 javaValue, 0, numBytes, |
|
216 JAVA_PTR(retVal->Ptr())); |
|
217 } |
|
218 return javaValue; |
|
219 } |