Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: net/third_party/nss/ssl/sslsock.c

Issue 8156001: net: rework the NPN patch. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ... Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/third_party/nss/ssl/sslimpl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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);
wtc 2011/10/28 02:06:26 BUG: we need to return SECSuccess at the end of th
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],
1358 protos[i]) == 0) {
1359 /* We found a match. */
1360 ss->ssl3.nextProtoState = SSL_NEXT_PROTO_NEGOTIATED;
1361 result = &protos[i];
1362 goto found;
1363 }
1364 j += (unsigned int)ss->opt.nextProtoNego.data[j] + 1;
1365 }
1366 i += (unsigned int)protos[i] + 1;
1367 }
1368
1369 pick_first:
1370 ss->ssl3.nextProtoState = SSL_NEXT_PROTO_NO_OVERLAP;
1371 result = ss->opt.nextProtoNego.data;
1372
1373 found:
1374 memcpy(protoOut, result + 1, result[0]);
1375 *protoOutLen = result[0];
1376 return SECSuccess;
1377 }
1378
1379 SECStatus
1380 SSL_SetNextProtoNego(PRFileDesc *fd, const unsigned char *data,
1381 unsigned int length)
1382 {
1383 SECStatus rv;
1384
1385 sslSocket *ss = ssl_FindSocket(fd);
1386
1387 if (!ss) {
1388 SSL_DBG(("%d: SSL[%d]: bad socket in SSL_SetNextProtoNego",
1389 SSL_GETPID(), fd));
1390 return SECFailure;
1391 }
1392
1327 if (ssl3_ValidateNextProtoNego(data, length) != SECSuccess) 1393 if (ssl3_ValidateNextProtoNego(data, length) != SECSuccess)
1328 return SECFailure; 1394 return SECFailure;
1329 1395
1330 ssl_GetSSL3HandshakeLock(ss); 1396 ssl_GetSSL3HandshakeLock(ss);
1331 if (ss->opt.nextProtoNego.data) 1397 if (ss->opt.nextProtoNego.data)
1332 PORT_Free(ss->opt.nextProtoNego.data); 1398 PORT_Free(ss->opt.nextProtoNego.data);
1333 ss->opt.nextProtoNego.data = PORT_Alloc(length); 1399 ss->opt.nextProtoNego.data = PORT_Alloc(length);
1334 if (!ss->opt.nextProtoNego.data) { 1400 if (!ss->opt.nextProtoNego.data) {
1335 ssl_ReleaseSSL3HandshakeLock(ss); 1401 ssl_ReleaseSSL3HandshakeLock(ss);
1336 return SECFailure; 1402 return SECFailure;
1337 } 1403 }
1338 memcpy(ss->opt.nextProtoNego.data, data, length); 1404 memcpy(ss->opt.nextProtoNego.data, data, length);
1339 ss->opt.nextProtoNego.len = length; 1405 ss->opt.nextProtoNego.len = length;
1340 ss->opt.nextProtoNego.type = siBuffer; 1406 ss->opt.nextProtoNego.type = siBuffer;
1341 ssl_ReleaseSSL3HandshakeLock(ss); 1407 ssl_ReleaseSSL3HandshakeLock(ss);
1342 1408
1343 return SECSuccess; 1409 return SSL_SetNextProtoCallback(fd, NextProtoStandardCallback, NULL);
1344 } 1410 }
1345 1411
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 1412 SECStatus
1356 SSL_GetNextProto(PRFileDesc *fd, int *state, unsigned char *buf, 1413 SSL_GetNextProto(PRFileDesc *fd, int *state, unsigned char *buf,
1357 unsigned int *length, unsigned int buf_len) 1414 unsigned int *length, unsigned int buf_len)
1358 { 1415 {
1359 sslSocket *ss = ssl_FindSocket(fd); 1416 sslSocket *ss = ssl_FindSocket(fd);
1360 1417
1361 if (!ss) { 1418 if (!ss) {
1362 SSL_DBG(("%d: SSL[%d]: bad socket in SSL_GetNextProto", SSL_GETPID(), 1419 SSL_DBG(("%d: SSL[%d]: bad socket in SSL_GetNextProto", SSL_GETPID(),
1363 fd)); 1420 fd));
1364 return SECFailure; 1421 return SECFailure;
(...skipping 1195 matching lines...) Expand 10 before | Expand all | Expand 10 after
2560 loser: 2617 loser:
2561 ssl_DestroySocketContents(ss); 2618 ssl_DestroySocketContents(ss);
2562 ssl_DestroyLocks(ss); 2619 ssl_DestroyLocks(ss);
2563 PORT_Free(ss); 2620 PORT_Free(ss);
2564 ss = NULL; 2621 ss = NULL;
2565 } 2622 }
2566 } 2623 }
2567 return ss; 2624 return ss;
2568 } 2625 }
2569 2626
OLDNEW
« no previous file with comments | « net/third_party/nss/ssl/sslimpl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698