OLD | NEW |
---|---|
1 /* | 1 /* |
2 * vtables (and methods that call through them) for the 4 types of | 2 * vtables (and methods that call through them) for the 4 types of |
3 * SSLSockets supported. Only one type is still supported. | 3 * SSLSockets supported. Only one type is still supported. |
4 * Various other functions. | 4 * Various other functions. |
5 * | 5 * |
6 * ***** BEGIN LICENSE BLOCK ***** | 6 * ***** BEGIN LICENSE BLOCK ***** |
7 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 7 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
8 * | 8 * |
9 * The contents of this file are subject to the Mozilla Public License Version | 9 * The contents of this file are subject to the Mozilla Public License Version |
10 * 1.1 (the "License"); you may not use this file except in compliance with | 10 * 1.1 (the "License"); you may not use this file except in compliance with |
(...skipping 1292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1303 #ifdef _WIN32 | 1303 #ifdef _WIN32 |
1304 PR_Sleep(PR_INTERVAL_NO_WAIT); /* workaround NT winsock connect bug. */ | 1304 PR_Sleep(PR_INTERVAL_NO_WAIT); /* workaround NT winsock connect bug. */ |
1305 #endif | 1305 #endif |
1306 ns = ssl_FindSocket(fd); | 1306 ns = ssl_FindSocket(fd); |
1307 PORT_Assert(ns); | 1307 PORT_Assert(ns); |
1308 if (ns) | 1308 if (ns) |
1309 ns->TCPconnected = (PR_SUCCESS == ssl_DefGetpeername(ns, &addr)); | 1309 ns->TCPconnected = (PR_SUCCESS == ssl_DefGetpeername(ns, &addr)); |
1310 return fd; | 1310 return fd; |
1311 } | 1311 } |
1312 | 1312 |
1313 /* SSL_SetNextProtoNego sets the list of supported protocols for the given | |
1314 * socket. The list is a series of 8-bit, length prefixed strings. */ | |
1315 SECStatus | 1313 SECStatus |
1316 SSL_SetNextProtoNego(PRFileDesc *fd, const unsigned char *data, | 1314 SSL_SetNextProtoCallback(PRFileDesc *fd, |
1317 » » unsigned short length) | 1315 SSLNextProtoCallback callback, |
1318 { | 1316 void *arg) { |
1319 sslSocket *ss = ssl_FindSocket(fd); | 1317 sslSocket *ss = ssl_FindSocket(fd); |
1320 | 1318 |
1321 if (!ss) { | 1319 if (!ss) { |
1322 SSL_DBG(("%d: SSL[%d]: bad socket in SSL_SetNextProtoNego", SSL_GETPID() , | 1320 SSL_DBG(("%d: SSL[%d]: bad socket in SSL_SetNextProtoNego", SSL_GETPID() , |
1323 fd)); | 1321 fd)); |
1324 return SECFailure; | 1322 return SECFailure; |
1325 } | 1323 } |
1326 | 1324 |
1325 ssl_GetSSL3HandshakeLock(ss); | |
1326 ss->nextProtoCallback = callback; | |
1327 ss->nextProtoArg = arg; | |
1328 ssl_ReleaseSSL3HandshakeLock(ss); | |
1329 } | |
1330 | |
1331 /* NextProtoStandardCallback is set as an NPN callback for the case when the | |
1332 * user of the sockets wants the standard selection algorithm. */ | |
1333 static SECStatus | |
1334 NextProtoStandardCallback(void *arg, | |
1335 PRFileDesc *fd, | |
1336 const unsigned char *protos, | |
1337 unsigned int protos_len, | |
1338 unsigned char *protoOut, | |
1339 unsigned int *protoOutLen) | |
1340 { | |
1341 unsigned int i, j; | |
1342 const unsigned char *result; | |
1343 | |
1344 sslSocket *ss = ssl_FindSocket(fd); | |
1345 PORT_Assert(ss); | |
1346 | |
1347 if (protos_len == 0) { | |
1348 /* The server supports the extension, but doesn't have any protocols | |
1349 * configured. In this case we request our favoured protocol. */ | |
1350 goto pick_first; | |
1351 } | |
1352 | |
1353 /* For each protocol in server preference, see if we support it. */ | |
1354 for (i = 0; i < protos_len; ) { | |
1355 for (j = 0; j < ss->opt.nextProtoNego.len; ) { | |
1356 if (protos[i] == ss->opt.nextProtoNego.data[j] && | |
1357 memcmp(&protos[i+1], &ss->opt.nextProtoNego.data[j+1], protos[i] ) == 0) { | |
wtc
2011/10/18 00:58:08
Nit: is this line longer than 80 characters?
agl
2011/10/18 16:44:43
Done.
| |
1358 /* We found a match. */ | |
1359 ss->ssl3.nextProtoState = SSL_NEXT_PROTO_NEGOTIATED; | |
1360 result = &protos[i]; | |
1361 goto found; | |
1362 } | |
1363 j += (unsigned int)ss->opt.nextProtoNego.data[j] + 1; | |
1364 } | |
1365 i += (unsigned int)protos[i] + 1; | |
wtc
2011/10/18 00:58:08
Nit: since ss->opt.nextProtoNego.data[j] and proto
agl
2011/10/18 16:44:43
Right. I want the addition to occur in ℤ/2**32ℤ to
| |
1366 } | |
1367 | |
1368 pick_first: | |
1369 ss->ssl3.nextProtoState = SSL_NEXT_PROTO_NO_OVERLAP; | |
1370 result = ss->opt.nextProtoNego.data; | |
1371 | |
1372 found: | |
wtc
2011/10/18 00:58:08
Nit: in NSS source code, labels are not indented.
agl
2011/10/18 16:44:43
Done.
| |
1373 memcpy(protoOut, result + 1, result[0]); | |
1374 *protoOutLen = result[0]; | |
1375 return SECSuccess; | |
1376 } | |
1377 | |
1378 SECStatus | |
1379 SSL_SetNextProtoNego(PRFileDesc *fd, const unsigned char *data, | |
1380 unsigned int length) | |
1381 { | |
1382 SECStatus rv; | |
1383 | |
1384 sslSocket *ss = ssl_FindSocket(fd); | |
1385 | |
1386 if (!ss) { | |
1387 SSL_DBG(("%d: SSL[%d]: bad socket in SSL_SetNextProtoNego", | |
1388 SSL_GETPID(), fd)); | |
1389 return SECFailure; | |
1390 } | |
1391 | |
1327 if (ssl3_ValidateNextProtoNego(data, length) != SECSuccess) | 1392 if (ssl3_ValidateNextProtoNego(data, length) != SECSuccess) |
1328 return SECFailure; | 1393 return SECFailure; |
1329 | 1394 |
1330 ssl_GetSSL3HandshakeLock(ss); | 1395 ssl_GetSSL3HandshakeLock(ss); |
1331 if (ss->opt.nextProtoNego.data) | 1396 if (ss->opt.nextProtoNego.data) |
1332 PORT_Free(ss->opt.nextProtoNego.data); | 1397 PORT_Free(ss->opt.nextProtoNego.data); |
1333 ss->opt.nextProtoNego.data = PORT_Alloc(length); | 1398 ss->opt.nextProtoNego.data = PORT_Alloc(length); |
1334 if (!ss->opt.nextProtoNego.data) { | 1399 if (!ss->opt.nextProtoNego.data) { |
1335 ssl_ReleaseSSL3HandshakeLock(ss); | 1400 ssl_ReleaseSSL3HandshakeLock(ss); |
1336 return SECFailure; | 1401 return SECFailure; |
1337 } | 1402 } |
1338 memcpy(ss->opt.nextProtoNego.data, data, length); | 1403 memcpy(ss->opt.nextProtoNego.data, data, length); |
1339 ss->opt.nextProtoNego.len = length; | 1404 ss->opt.nextProtoNego.len = length; |
1340 ss->opt.nextProtoNego.type = siBuffer; | 1405 ss->opt.nextProtoNego.type = siBuffer; |
1341 ssl_ReleaseSSL3HandshakeLock(ss); | 1406 ssl_ReleaseSSL3HandshakeLock(ss); |
1342 | 1407 |
1343 return SECSuccess; | 1408 return SSL_SetNextProtoCallback(fd, NextProtoStandardCallback, NULL); |
1344 } | 1409 } |
1345 | 1410 |
1346 /* SSL_GetNextProto reads the resulting Next Protocol Negotiation result for | |
1347 * the given socket. It's only valid to call this once the handshake has | |
1348 * completed. | |
1349 * | |
1350 * state is set to one of the SSL_NEXT_PROTO_* constants. The negotiated | |
1351 * protocol, if any, is written into buf, which must be at least buf_len | |
1352 * bytes long. If the negotiated protocol is longer than this, it is truncated. | |
1353 * The number of bytes copied is written into length. | |
1354 */ | |
1355 SECStatus | 1411 SECStatus |
1356 SSL_GetNextProto(PRFileDesc *fd, int *state, unsigned char *buf, | 1412 SSL_GetNextProto(PRFileDesc *fd, int *state, unsigned char *buf, |
1357 unsigned int *length, unsigned int buf_len) | 1413 unsigned int *length, unsigned int buf_len) |
1358 { | 1414 { |
1359 sslSocket *ss = ssl_FindSocket(fd); | 1415 sslSocket *ss = ssl_FindSocket(fd); |
1360 | 1416 |
1361 if (!ss) { | 1417 if (!ss) { |
1362 SSL_DBG(("%d: SSL[%d]: bad socket in SSL_GetNextProto", SSL_GETPID(), | 1418 SSL_DBG(("%d: SSL[%d]: bad socket in SSL_GetNextProto", SSL_GETPID(), |
1363 fd)); | 1419 fd)); |
1364 return SECFailure; | 1420 return SECFailure; |
(...skipping 1195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2560 loser: | 2616 loser: |
2561 ssl_DestroySocketContents(ss); | 2617 ssl_DestroySocketContents(ss); |
2562 ssl_DestroyLocks(ss); | 2618 ssl_DestroyLocks(ss); |
2563 PORT_Free(ss); | 2619 PORT_Free(ss); |
2564 ss = NULL; | 2620 ss = NULL; |
2565 } | 2621 } |
2566 } | 2622 } |
2567 return ss; | 2623 return ss; |
2568 } | 2624 } |
2569 | 2625 |
OLD | NEW |