1 /* |
|
2 * Copyright (c) 2007 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 "javajniutils.h" |
|
20 #include "com_nokia_mj_impl_security_midp_authentication_OcspChecker.h" |
|
21 #include "ocspclient.h" |
|
22 |
|
23 using namespace java::security; |
|
24 using namespace std; |
|
25 |
|
26 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_security_midp_authentication_OcspChecker__1createNativeThread |
|
27 (JNIEnv *, jobject) |
|
28 { |
|
29 return 0; |
|
30 } |
|
31 |
|
32 JNIEXPORT void JNICALL Java_com_nokia_mj_impl_security_midp_authentication_OcspChecker__1destroyNativeThread |
|
33 (JNIEnv *, jobject, jint) |
|
34 { |
|
35 } |
|
36 |
|
37 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_security_midp_authentication_OcspChecker__1createNativePeer |
|
38 (JNIEnv * env, jobject, jint aNativeThreadHandle, jlong iap, jlong snap, jstring jOcspDefaultUrl) |
|
39 { |
|
40 OcspClient * ocspClient = NULL; |
|
41 const char* ocspDefaultUrl = NULL; |
|
42 if (jOcspDefaultUrl != NULL) |
|
43 { |
|
44 jboolean isCopy; |
|
45 ocspDefaultUrl = env->GetStringUTFChars(jOcspDefaultUrl, &isCopy); |
|
46 ocspClient = OcspClient::createInstance(iap, ocspDefaultUrl); |
|
47 } |
|
48 else |
|
49 { |
|
50 ocspClient = OcspClient::createInstance(iap, NULL); |
|
51 } |
|
52 return reinterpret_cast<int>(ocspClient); |
|
53 } |
|
54 |
|
55 JNIEXPORT void JNICALL Java_com_nokia_mj_impl_security_midp_authentication_OcspChecker__1destroyNativePeer |
|
56 (JNIEnv *, jobject, jint aNativeThreadHandle, jint aNativePeerHandle) |
|
57 { |
|
58 OcspClient* ocspClient = |
|
59 reinterpret_cast< OcspClient* >(aNativePeerHandle); |
|
60 delete ocspClient; |
|
61 } |
|
62 |
|
63 JNIEXPORT void JNICALL Java_com_nokia_mj_impl_security_midp_authentication_OcspChecker__1ocspChecks |
|
64 (JNIEnv * env, jobject, jint aNativeThreadHandle, jint aNativePeerHandle, jobjectArray ocspData) |
|
65 { |
|
66 if (ocspData == NULL) |
|
67 { |
|
68 return; |
|
69 } |
|
70 // do the OCSP check for each of the cert chains |
|
71 OcspClient* ocspClient = |
|
72 reinterpret_cast< OcspClient* >(aNativePeerHandle); |
|
73 jint len = env->GetArrayLength(ocspData); |
|
74 jboolean isCopy; |
|
75 for (int i=0; i<len; i++) |
|
76 { |
|
77 jobject jOcspData = env->GetObjectArrayElement(ocspData, i); |
|
78 jclass ocspDataClass = env->GetObjectClass(jOcspData); |
|
79 jmethodID getCertChainMethod = env->GetMethodID( |
|
80 ocspDataClass,"getCertChain", "()[Ljava/lang/String;"); |
|
81 jmethodID setIndividualResponsesMethod = env->GetMethodID( |
|
82 ocspDataClass,"setIndividualResponses", "([I)V"); |
|
83 jmethodID setSummaryMethod = env->GetMethodID( |
|
84 ocspDataClass,"setSummary", "(I)V"); |
|
85 jobjectArray jCertChain = (jobjectArray)env->CallObjectMethod( |
|
86 jOcspData, getCertChainMethod); |
|
87 jint certChainLen = env->GetArrayLength(jCertChain); |
|
88 const char** certChain = new const char* [certChainLen]; |
|
89 for (int j=0; j<certChainLen; j++) |
|
90 { |
|
91 jstring jCert = (jstring)env->GetObjectArrayElement(jCertChain, j); |
|
92 const char *cert = env->GetStringUTFChars(jCert, &isCopy); |
|
93 certChain[j] = cert; |
|
94 } |
|
95 // do the actual OCSP check for the current cert chain |
|
96 ocspClient->startOcspCheck(certChain, certChainLen); |
|
97 OcspResponse ocspResponse = ocspClient->getOcspCheckResponse(); |
|
98 env->CallVoidMethod(jOcspData, setSummaryMethod, ocspResponse.iSummary); |
|
99 if (ocspResponse.iIndividualResponses.size() > 0) |
|
100 { |
|
101 int size = ocspResponse.iIndividualResponses.size(); |
|
102 jint* tmp = new jint[size]; |
|
103 for (int j=0; j<size; j++) |
|
104 { |
|
105 tmp[j] = ocspResponse.iIndividualResponses[j]; |
|
106 } |
|
107 jintArray individualResponses = (jintArray)env->NewIntArray(size); |
|
108 env->SetIntArrayRegion((jintArray)individualResponses,(jsize)0,(jsize)size,tmp); |
|
109 // set the individual responses |
|
110 env->CallVoidMethod(jOcspData, setIndividualResponsesMethod, individualResponses); |
|
111 delete[] tmp; |
|
112 } |
|
113 // cleanup |
|
114 for (int j=0; j<certChainLen; j++) |
|
115 { |
|
116 jstring jCert = (jstring)env->GetObjectArrayElement(jCertChain, j); |
|
117 env->ReleaseStringUTFChars(jCert,certChain[j]); |
|
118 } |
|
119 delete[] certChain; |
|
120 } |
|
121 } |
|
122 |
|
123 JNIEXPORT void JNICALL Java_com_nokia_mj_impl_security_midp_authentication_OcspChecker__1cancelOcspChecks |
|
124 (JNIEnv *, jobject, jint aNativeThreadHandle, jint aNativePeerHandle) |
|
125 { |
|
126 OcspClient* ocspClient = |
|
127 reinterpret_cast< OcspClient* >(aNativePeerHandle); |
|
128 ocspClient->cancelOcspCheck(true); |
|
129 } |
|