@@ -75,18 +75,6 @@ JSS_NSS_getEventArrayList(JNIEnv *env, jobject sslfd_proxy, const char *which, j
75
75
return PR_SUCCESS ;
76
76
}
77
77
78
- PRStatus
79
- JSS_NSS_getSSLAlertReceivedList (JNIEnv * env , jobject sslfd_proxy , jobject * list )
80
- {
81
- return JSS_NSS_getEventArrayList (env , sslfd_proxy , "inboundAlerts" , list );
82
- }
83
-
84
- PRStatus
85
- JSS_NSS_getSSLAlertSentList (JNIEnv * env , jobject sslfd_proxy , jobject * list )
86
- {
87
- return JSS_NSS_getEventArrayList (env , sslfd_proxy , "outboundAlerts" , list );
88
- }
89
-
90
78
PRStatus
91
79
JSS_NSS_getGlobalRef (JNIEnv * env , jobject sslfd_proxy , jobject * global_ref )
92
80
{
@@ -104,61 +92,41 @@ JSS_NSS_getGlobalRef(JNIEnv *env, jobject sslfd_proxy, jobject *global_ref)
104
92
return PR_SUCCESS ;
105
93
}
106
94
107
- PRStatus
108
- JSS_NSS_addSSLAlert (JNIEnv * env , jobject sslfd_proxy , jobject list ,
109
- const SSLAlert * alert )
95
+ jobject
96
+ JSS_NSS_createSSLAlert (JNIEnv * env , jobject sslfd_proxy , const SSLAlert * alert )
110
97
{
111
98
jclass eventClass ;
112
99
jmethodID eventConstructor ;
113
100
jobject event ;
114
101
115
- jclass eventListClass ;
116
- jmethodID arrayListAdd ;
117
-
118
- PR_ASSERT (env != NULL && sslfd_proxy != NULL && list != NULL && alert != NULL );
102
+ PR_ASSERT (env != NULL && sslfd_proxy != NULL && alert != NULL );
119
103
120
104
/* Build the new alert event object (org.mozilla.jss.ssl.SSLAlertEvent). */
121
105
eventClass = (* env )-> FindClass (env , SSL_ALERT_EVENT_CLASS );
122
106
if (eventClass == NULL ) {
123
- return PR_FAILURE ;
107
+ return NULL ;
124
108
}
125
109
126
110
eventConstructor = (* env )-> GetMethodID (env , eventClass , "<init>" ,
127
111
"(L" SSLFD_PROXY_CLASS_NAME ";II)V" );
128
112
if (eventConstructor == NULL ) {
129
- return PR_FAILURE ;
113
+ return NULL ;
130
114
}
131
115
132
116
event = (* env )-> NewObject (env , eventClass , eventConstructor ,
133
117
sslfd_proxy , (int )alert -> level ,
134
118
(int )alert -> description );
135
- if (event == NULL ) {
136
- return PR_FAILURE ;
137
- }
138
-
139
- /* Add it to the event list. */
140
- eventListClass = (* env )-> GetObjectClass (env , list );
141
- if (eventListClass == NULL ) {
142
- return PR_FAILURE ;
143
- }
144
-
145
- arrayListAdd = (* env )-> GetMethodID (env , eventListClass , "add" ,
146
- "(Ljava/lang/Object;)Z" );
147
- if (arrayListAdd == NULL ) {
148
- return PR_FAILURE ;
149
- }
150
-
151
- // We ignore the return code: ArrayList.add() always returns true.
152
- (void )(* env )-> CallBooleanMethod (env , list , arrayListAdd , event );
153
- return PR_SUCCESS ;
119
+ return event ;
154
120
}
155
121
156
122
void
157
123
JSSL_SSLFDAlertReceivedCallback (const PRFileDesc * fd , void * arg , const SSLAlert * alert )
158
124
{
159
125
JNIEnv * env ;
160
126
jobject sslfd_proxy = (jobject )arg ;
161
- jobject list ;
127
+ jclass sslfdProxyClass ;
128
+ jmethodID alertReceivedMethod ;
129
+ jobject event ;
162
130
163
131
if (fd == NULL || arg == NULL || alert == NULL || JSS_javaVM == NULL ) {
164
132
return ;
@@ -168,21 +136,41 @@ JSSL_SSLFDAlertReceivedCallback(const PRFileDesc *fd, void *arg, const SSLAlert
168
136
return ;
169
137
}
170
138
171
- if (JSS_NSS_getSSLAlertReceivedList (env , sslfd_proxy , & list ) != PR_SUCCESS ) {
139
+ sslfdProxyClass = (* env )-> GetObjectClass (env , sslfd_proxy );
140
+
141
+ if (sslfdProxyClass == NULL ) {
142
+ return ;
143
+ }
144
+
145
+ alertReceivedMethod = (* env )-> GetMethodID (
146
+ env ,
147
+ sslfdProxyClass ,
148
+ "alertReceived" ,
149
+ "(L" SSL_ALERT_EVENT_CLASS ";)V" );
150
+
151
+ if (alertReceivedMethod == NULL ) {
172
152
return ;
173
153
}
174
154
175
- if (JSS_NSS_addSSLAlert (env , sslfd_proxy , list , alert ) != PR_SUCCESS ) {
155
+ // event = new SSLAlertEvent()
156
+ event = JSS_NSS_createSSLAlert (env , sslfd_proxy , alert );
157
+
158
+ if (event == NULL ) {
176
159
return ;
177
160
}
161
+
162
+ // sslfd_proxy.alertReceived(event)
163
+ (void )(* env )-> CallVoidMethod (env , sslfd_proxy , alertReceivedMethod , event );
178
164
}
179
165
180
166
void
181
167
JSSL_SSLFDAlertSentCallback (const PRFileDesc * fd , void * arg , const SSLAlert * alert )
182
168
{
183
169
JNIEnv * env ;
184
170
jobject sslfd_proxy = (jobject )arg ;
185
- jobject list ;
171
+ jclass sslfdProxyClass ;
172
+ jmethodID alertSentMethod ;
173
+ jobject event ;
186
174
187
175
if (fd == NULL || arg == NULL || alert == NULL || JSS_javaVM == NULL ) {
188
176
return ;
@@ -192,13 +180,31 @@ JSSL_SSLFDAlertSentCallback(const PRFileDesc *fd, void *arg, const SSLAlert *ale
192
180
return ;
193
181
}
194
182
195
- if (JSS_NSS_getSSLAlertSentList (env , sslfd_proxy , & list ) != PR_SUCCESS ) {
183
+ sslfdProxyClass = (* env )-> GetObjectClass (env , sslfd_proxy );
184
+
185
+ if (sslfdProxyClass == NULL ) {
196
186
return ;
197
187
}
198
188
199
- if (JSS_NSS_addSSLAlert (env , sslfd_proxy , list , alert ) != PR_SUCCESS ) {
189
+ alertSentMethod = (* env )-> GetMethodID (
190
+ env ,
191
+ sslfdProxyClass ,
192
+ "alertSent" ,
193
+ "(L" SSL_ALERT_EVENT_CLASS ";)V" );
194
+
195
+ if (alertSentMethod == NULL ) {
200
196
return ;
201
197
}
198
+
199
+ // event = new SSLAlertEvent()
200
+ event = JSS_NSS_createSSLAlert (env , sslfd_proxy , alert );
201
+
202
+ if (event == NULL ) {
203
+ return ;
204
+ }
205
+
206
+ // sslfd_proxy.alertSent(event)
207
+ (void )(* env )-> CallVoidMethod (env , sslfd_proxy , alertSentMethod , event );
202
208
}
203
209
204
210
SECStatus
@@ -248,7 +254,11 @@ JSSL_SSLFDHandshakeComplete(PRFileDesc *fd, void *client_data)
248
254
JNIEnv * env = NULL ;
249
255
jobject sslfd_proxy = (jobject )client_data ;
250
256
jclass sslfdProxyClass ;
251
- jfieldID handshakeCompleteField ;
257
+ jmethodID handshakeCompletedMethod ;
258
+
259
+ jclass eventClass ;
260
+ jmethodID eventConstructor ;
261
+ jobject event ;
252
262
253
263
if (fd == NULL || client_data == NULL || JSS_javaVM == NULL ) {
254
264
return ;
@@ -259,17 +269,50 @@ JSSL_SSLFDHandshakeComplete(PRFileDesc *fd, void *client_data)
259
269
}
260
270
261
271
sslfdProxyClass = (* env )-> GetObjectClass (env , sslfd_proxy );
272
+
262
273
if (sslfdProxyClass == NULL ) {
263
274
return ;
264
275
}
265
276
266
- handshakeCompleteField = (* env )-> GetFieldID (env , sslfdProxyClass ,
267
- "handshakeComplete" , "Z" );
268
- if (handshakeCompleteField == NULL ) {
277
+ handshakeCompletedMethod = (* env )-> GetMethodID (
278
+ env ,
279
+ sslfdProxyClass ,
280
+ "handshakeCompleted" ,
281
+ "(L" SSL_HANDSHAKE_COMPLETED_EVENT_CLASS ";)V" );
282
+
283
+ if (handshakeCompletedMethod == NULL ) {
284
+ return ;
285
+ }
286
+
287
+ eventClass = (* env )-> FindClass (env , SSL_HANDSHAKE_COMPLETED_EVENT_CLASS );
288
+
289
+ if (eventClass == NULL ) {
290
+ return ;
291
+ }
292
+
293
+ eventConstructor = (* env )-> GetMethodID (
294
+ env ,
295
+ eventClass ,
296
+ "<init>" ,
297
+ "(L" SSLFD_PROXY_CLASS_NAME ";)V" );
298
+
299
+ if (eventConstructor == NULL ) {
300
+ return ;
301
+ }
302
+
303
+ // event = new SSLHandshakeCompletedEvent()
304
+ event = (* env )-> NewObject (
305
+ env ,
306
+ eventClass ,
307
+ eventConstructor ,
308
+ sslfd_proxy );
309
+
310
+ if (event == NULL ) {
269
311
return ;
270
312
}
271
313
272
- (* env )-> SetBooleanField (env , sslfd_proxy , handshakeCompleteField , JNI_TRUE );
314
+ // sslfd_proxy.handshakeCompleted(event)
315
+ (void )(* env )-> CallVoidMethod (env , sslfd_proxy , handshakeCompletedMethod , event );
273
316
}
274
317
275
318
SECStatus
0 commit comments