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

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

Issue 11275240: Update net/third_party/nss/ssl to NSS 3.14. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Upload before commit Created 8 years, 1 month 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/sslsnce.c ('k') | net/third_party/nss/ssl/sslt.h » ('j') | 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 * This Source Code Form is subject to the terms of the Mozilla Public
7 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 7 * License, v. 2.0. If a copy of the MPL was not distributed with this
8 * 8 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
9 * The contents of this file are subject to the Mozilla Public License Version 9 /* $Id: sslsock.c,v 1.96 2012/09/24 23:57:42 wtc%google.com Exp $ */
10 * 1.1 (the "License"); you may not use this file except in compliance with
11 * the License. You may obtain a copy of the License at
12 * http://www.mozilla.org/MPL/
13 *
14 * Software distributed under the License is distributed on an "AS IS" basis,
15 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
16 * for the specific language governing rights and limitations under the
17 * License.
18 *
19 * The Original Code is the Netscape security libraries.
20 *
21 * The Initial Developer of the Original Code is
22 * Netscape Communications Corporation.
23 * Portions created by the Initial Developer are Copyright (C) 1994-2000
24 * the Initial Developer. All Rights Reserved.
25 *
26 * Contributor(s):
27 * Dr Stephen Henson <stephen.henson@gemplus.com>
28 * Dr Vipul Gupta <vipul.gupta@sun.com>, Sun Microsystems Laboratories
29 *
30 * Alternatively, the contents of this file may be used under the terms of
31 * either the GNU General Public License Version 2 or later (the "GPL"), or
32 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
33 * in which case the provisions of the GPL or the LGPL are applicable instead
34 * of those above. If you wish to allow use of your version of this file only
35 * under the terms of either the GPL or the LGPL, and not to allow others to
36 * use your version of this file under the terms of the MPL, indicate your
37 * decision by deleting the provisions above and replace them with the notice
38 * and other provisions required by the GPL or the LGPL. If you do not delete
39 * the provisions above, a recipient may use your version of this file under
40 * the terms of any one of the MPL, the GPL or the LGPL.
41 *
42 * ***** END LICENSE BLOCK ***** */
43 /* $Id: sslsock.c,v 1.86 2012/03/18 00:31:20 wtc%google.com Exp $ */
44 #include "seccomon.h" 10 #include "seccomon.h"
45 #include "cert.h" 11 #include "cert.h"
46 #include "keyhi.h" 12 #include "keyhi.h"
47 #include "ssl.h" 13 #include "ssl.h"
48 #include "sslimpl.h" 14 #include "sslimpl.h"
49 #include "sslproto.h" 15 #include "sslproto.h"
50 #include "nspr.h" 16 #include "nspr.h"
51 #include "private/pprio.h" 17 #include "private/pprio.h"
18 #ifndef NO_PKCS11_BYPASS
52 #include "blapi.h" 19 #include "blapi.h"
20 #endif
53 #include "nss.h" 21 #include "nss.h"
54 22
55 #define SET_ERROR_CODE /* reminder */ 23 #define SET_ERROR_CODE /* reminder */
56 24
57 struct cipherPolicyStr { 25 struct cipherPolicyStr {
58 int cipher; 26 int cipher;
59 unsigned char export; /* policy value for export policy */ 27 unsigned char export; /* policy value for export policy */
60 unsigned char france; /* policy value for france policy */ 28 unsigned char france; /* policy value for france policy */
61 }; 29 };
62 30
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 if (layer == NULL) { 250 if (layer == NULL) {
283 PORT_SetError(PR_BAD_DESCRIPTOR_ERROR); 251 PORT_SetError(PR_BAD_DESCRIPTOR_ERROR);
284 return NULL; 252 return NULL;
285 } 253 }
286 254
287 ss = (sslSocket *)layer->secret; 255 ss = (sslSocket *)layer->secret;
288 ss->fd = layer; 256 ss->fd = layer;
289 return ss; 257 return ss;
290 } 258 }
291 259
292 sslSocket * 260 static sslSocket *
293 ssl_DupSocket(sslSocket *os) 261 ssl_DupSocket(sslSocket *os)
294 { 262 {
295 sslSocket *ss; 263 sslSocket *ss;
296 SECStatus rv; 264 SECStatus rv;
297 265
298 ss = ssl_NewSocket((PRBool)(!os->opt.noLocks), os->protocolVariant); 266 ss = ssl_NewSocket((PRBool)(!os->opt.noLocks), os->protocolVariant);
299 if (ss) { 267 if (ss) {
300 ss->opt = os->opt; 268 ss->opt = os->opt;
301 ss->opt.useSocks = PR_FALSE; 269 ss->opt.useSocks = PR_FALSE;
302 ss->vrange = os->vrange; 270 ss->vrange = os->vrange;
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 ss->xtnData.sniNameArr = NULL; 451 ss->xtnData.sniNameArr = NULL;
484 } 452 }
485 } 453 }
486 454
487 /* 455 /*
488 * free an sslSocket struct, and all the stuff that hangs off of it 456 * free an sslSocket struct, and all the stuff that hangs off of it
489 */ 457 */
490 void 458 void
491 ssl_FreeSocket(sslSocket *ss) 459 ssl_FreeSocket(sslSocket *ss)
492 { 460 {
493 #ifdef DEBUG
494 sslSocket *fs;
495 sslSocket lSock;
496 #endif
497
498 /* Get every lock you can imagine! 461 /* Get every lock you can imagine!
499 ** Caller already holds these: 462 ** Caller already holds these:
500 ** SSL_LOCK_READER(ss); 463 ** SSL_LOCK_READER(ss);
501 ** SSL_LOCK_WRITER(ss); 464 ** SSL_LOCK_WRITER(ss);
502 */ 465 */
503 ssl_Get1stHandshakeLock(ss); 466 ssl_Get1stHandshakeLock(ss);
504 ssl_GetRecvBufLock(ss); 467 ssl_GetRecvBufLock(ss);
505 ssl_GetSSL3HandshakeLock(ss); 468 ssl_GetSSL3HandshakeLock(ss);
506 ssl_GetXmitBufLock(ss); 469 ssl_GetXmitBufLock(ss);
507 ssl_GetSpecWriteLock(ss); 470 ssl_GetSpecWriteLock(ss);
508 471
509 #ifdef DEBUG 472 ssl_DestroySocketContents(ss);
510 fs = &lSock;
511 *fs = *ss;» » » » /* Copy the old socket structure, */
512 PORT_Memset(ss, 0x1f, sizeof *ss); /* then blast the old struct ASAP. */
513 #else
514 #define fs ss
515 #endif
516
517 ssl_DestroySocketContents(fs);
518 473
519 /* Release all the locks acquired above. */ 474 /* Release all the locks acquired above. */
520 SSL_UNLOCK_READER(fs); 475 SSL_UNLOCK_READER(ss);
521 SSL_UNLOCK_WRITER(fs); 476 SSL_UNLOCK_WRITER(ss);
522 ssl_Release1stHandshakeLock(fs); 477 ssl_Release1stHandshakeLock(ss);
523 ssl_ReleaseRecvBufLock(fs); 478 ssl_ReleaseRecvBufLock(ss);
524 ssl_ReleaseSSL3HandshakeLock(fs); 479 ssl_ReleaseSSL3HandshakeLock(ss);
525 ssl_ReleaseXmitBufLock(fs); 480 ssl_ReleaseXmitBufLock(ss);
526 ssl_ReleaseSpecWriteLock(fs); 481 ssl_ReleaseSpecWriteLock(ss);
527 482
528 ssl_DestroyLocks(fs); 483 ssl_DestroyLocks(ss);
529 484
530 PORT_Free(ss);» /* free the caller's copy, not ours. */ 485 #ifdef DEBUG
486 PORT_Memset(ss, 0x1f, sizeof *ss);
487 #endif
488 PORT_Free(ss);
531 return; 489 return;
532 } 490 }
533 #undef fs
534 491
535 /************************************************************************/ 492 /************************************************************************/
536 SECStatus 493 SECStatus
537 ssl_EnableNagleDelay(sslSocket *ss, PRBool enabled) 494 ssl_EnableNagleDelay(sslSocket *ss, PRBool enabled)
538 { 495 {
539 PRFileDesc * osfd = ss->fd->lower; 496 PRFileDesc * osfd = ss->fd->lower;
540 SECStatus rv = SECFailure; 497 SECStatus rv = SECFailure;
541 PRSocketOptionData opt; 498 PRSocketOptionData opt;
542 499
543 opt.option = PR_SockOpt_NoDelay; 500 opt.option = PR_SockOpt_NoDelay;
(...skipping 23 matching lines...) Expand all
567 ssl_ChooseOps(ss); 524 ssl_ChooseOps(ss);
568 return rv; 525 return rv;
569 } 526 }
570 527
571 SECStatus 528 SECStatus
572 SSL_Enable(PRFileDesc *fd, int which, PRBool on) 529 SSL_Enable(PRFileDesc *fd, int which, PRBool on)
573 { 530 {
574 return SSL_OptionSet(fd, which, on); 531 return SSL_OptionSet(fd, which, on);
575 } 532 }
576 533
534 #ifndef NO_PKCS11_BYPASS
577 static const PRCallOnceType pristineCallOnce; 535 static const PRCallOnceType pristineCallOnce;
578 static PRCallOnceType setupBypassOnce; 536 static PRCallOnceType setupBypassOnce;
579 537
580 static SECStatus SSL_BypassShutdown(void* appData, void* nssData) 538 static SECStatus SSL_BypassShutdown(void* appData, void* nssData)
581 { 539 {
582 /* unload freeBL shared library from memory */ 540 /* unload freeBL shared library from memory */
583 BL_Unload(); 541 BL_Unload();
584 setupBypassOnce = pristineCallOnce; 542 setupBypassOnce = pristineCallOnce;
585 return SECSuccess; 543 return SECSuccess;
586 } 544 }
587 545
588 static PRStatus SSL_BypassRegisterShutdown(void) 546 static PRStatus SSL_BypassRegisterShutdown(void)
589 { 547 {
590 SECStatus rv = NSS_RegisterShutdown(SSL_BypassShutdown, NULL); 548 SECStatus rv = NSS_RegisterShutdown(SSL_BypassShutdown, NULL);
591 PORT_Assert(SECSuccess == rv); 549 PORT_Assert(SECSuccess == rv);
592 return SECSuccess == rv ? PR_SUCCESS : PR_FAILURE; 550 return SECSuccess == rv ? PR_SUCCESS : PR_FAILURE;
593 } 551 }
552 #endif
594 553
595 static PRStatus SSL_BypassSetup(void) 554 static PRStatus SSL_BypassSetup(void)
596 { 555 {
556 #ifdef NO_PKCS11_BYPASS
557 /* Guarantee binary compatibility */
558 return PR_SUCCESS;
559 #else
597 return PR_CallOnce(&setupBypassOnce, &SSL_BypassRegisterShutdown); 560 return PR_CallOnce(&setupBypassOnce, &SSL_BypassRegisterShutdown);
561 #endif
598 } 562 }
599 563
600 /* Implements the semantics for SSL_OptionSet(SSL_ENABLE_TLS, on) described in 564 /* Implements the semantics for SSL_OptionSet(SSL_ENABLE_TLS, on) described in
601 * ssl.h in the section "SSL version range setting API". 565 * ssl.h in the section "SSL version range setting API".
602 */ 566 */
603 static void 567 static void
604 ssl_EnableTLS(SSLVersionRange *vrange, PRBool on) 568 ssl_EnableTLS(SSLVersionRange *vrange, PRBool on)
605 { 569 {
606 if (SSL3_ALL_VERSIONS_DISABLED(vrange)) { 570 if (SSL3_ALL_VERSIONS_DISABLED(vrange)) {
607 if (on) { 571 if (on) {
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 SSL_DisableExportCipherSuites(fd); 770 SSL_DisableExportCipherSuites(fd);
807 break; 771 break;
808 772
809 case SSL_BYPASS_PKCS11: 773 case SSL_BYPASS_PKCS11:
810 if (ss->handshakeBegun) { 774 if (ss->handshakeBegun) {
811 PORT_SetError(PR_INVALID_STATE_ERROR); 775 PORT_SetError(PR_INVALID_STATE_ERROR);
812 rv = SECFailure; 776 rv = SECFailure;
813 } else { 777 } else {
814 if (PR_FALSE != on) { 778 if (PR_FALSE != on) {
815 if (PR_SUCCESS == SSL_BypassSetup() ) { 779 if (PR_SUCCESS == SSL_BypassSetup() ) {
780 #ifdef NO_PKCS11_BYPASS
781 ss->opt.bypassPKCS11 = PR_FALSE;
782 #else
816 ss->opt.bypassPKCS11 = on; 783 ss->opt.bypassPKCS11 = on;
784 #endif
817 } else { 785 } else {
818 rv = SECFailure; 786 rv = SECFailure;
819 } 787 }
820 } else { 788 } else {
821 ss->opt.bypassPKCS11 = PR_FALSE; 789 ss->opt.bypassPKCS11 = PR_FALSE;
822 } 790 }
823 } 791 }
824 break; 792 break;
825 793
826 case SSL_NO_LOCKS: 794 case SSL_NO_LOCKS:
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
1106 1074
1107 case SSL_NO_STEP_DOWN: 1075 case SSL_NO_STEP_DOWN:
1108 ssl_defaults.noStepDown = on; 1076 ssl_defaults.noStepDown = on;
1109 if (on) 1077 if (on)
1110 SSL_DisableDefaultExportCipherSuites(); 1078 SSL_DisableDefaultExportCipherSuites();
1111 break; 1079 break;
1112 1080
1113 case SSL_BYPASS_PKCS11: 1081 case SSL_BYPASS_PKCS11:
1114 if (PR_FALSE != on) { 1082 if (PR_FALSE != on) {
1115 if (PR_SUCCESS == SSL_BypassSetup()) { 1083 if (PR_SUCCESS == SSL_BypassSetup()) {
1084 #ifdef NO_PKCS11_BYPASS
1085 ssl_defaults.bypassPKCS11 = PR_FALSE;
1086 #else
1116 ssl_defaults.bypassPKCS11 = on; 1087 ssl_defaults.bypassPKCS11 = on;
1088 #endif
1117 } else { 1089 } else {
1118 return SECFailure; 1090 return SECFailure;
1119 } 1091 }
1120 } else { 1092 } else {
1121 ssl_defaults.bypassPKCS11 = PR_FALSE; 1093 ssl_defaults.bypassPKCS11 = PR_FALSE;
1122 } 1094 }
1123 break; 1095 break;
1124 1096
1125 case SSL_NO_LOCKS: 1097 case SSL_NO_LOCKS:
1126 if (on && ssl_defaults.fdx) { 1098 if (on && ssl_defaults.fdx) {
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
1597 } 1569 }
1598 1570
1599 return SECSuccess; 1571 return SECSuccess;
1600 } 1572 }
1601 1573
1602 SECStatus SSL_SetSRTPCiphers(PRFileDesc *fd, 1574 SECStatus SSL_SetSRTPCiphers(PRFileDesc *fd,
1603 const PRUint16 *ciphers, 1575 const PRUint16 *ciphers,
1604 unsigned int numCiphers) 1576 unsigned int numCiphers)
1605 { 1577 {
1606 sslSocket *ss; 1578 sslSocket *ss;
1607 int i; 1579 unsigned int i;
1608 1580
1609 ss = ssl_FindSocket(fd); 1581 ss = ssl_FindSocket(fd);
1610 if (!ss || !IS_DTLS(ss)) { 1582 if (!ss || !IS_DTLS(ss)) {
1611 SSL_DBG(("%d: SSL[%d]: bad socket in SSL_SetSRTPCiphers", 1583 SSL_DBG(("%d: SSL[%d]: bad socket in SSL_SetSRTPCiphers",
1612 SSL_GETPID(), fd)); 1584 SSL_GETPID(), fd));
1613 PORT_SetError(SEC_ERROR_INVALID_ARGS); 1585 PORT_SetError(SEC_ERROR_INVALID_ARGS);
1614 return SECFailure; 1586 return SECFailure;
1615 } 1587 }
1616 1588
1617 if (numCiphers > MAX_DTLS_SRTP_CIPHER_SUITES) { 1589 if (numCiphers > MAX_DTLS_SRTP_CIPHER_SUITES) {
(...skipping 1316 matching lines...) Expand 10 before | Expand all | Expand 10 after
2934 ev = getenv("SSLKEYLOGFILE"); 2906 ev = getenv("SSLKEYLOGFILE");
2935 if (ev && ev[0]) { 2907 if (ev && ev[0]) {
2936 ssl_keylog_iob = fopen(ev, "a"); 2908 ssl_keylog_iob = fopen(ev, "a");
2937 if (!ssl_keylog_iob) { 2909 if (!ssl_keylog_iob) {
2938 SSL_TRACE(("Failed to open key log file")); 2910 SSL_TRACE(("Failed to open key log file"));
2939 } else { 2911 } else {
2940 if (ftell(ssl_keylog_iob) == 0) { 2912 if (ftell(ssl_keylog_iob) == 0) {
2941 fputs("# SSL/TLS secrets log file, generated by NSS\n", 2913 fputs("# SSL/TLS secrets log file, generated by NSS\n",
2942 ssl_keylog_iob); 2914 ssl_keylog_iob);
2943 } 2915 }
2944 » » SSL_TRACE(("SSL: logging pre-master secrets to %s", ev)); 2916 » » SSL_TRACE(("SSL: logging SSL/TLS secrets to %s", ev));
2945 } 2917 }
2946 } 2918 }
2919 #ifndef NO_PKCS11_BYPASS
2947 ev = getenv("SSLBYPASS"); 2920 ev = getenv("SSLBYPASS");
2948 if (ev && ev[0]) { 2921 if (ev && ev[0]) {
2949 ssl_defaults.bypassPKCS11 = (ev[0] == '1'); 2922 ssl_defaults.bypassPKCS11 = (ev[0] == '1');
2950 SSL_TRACE(("SSL: bypass default set to %d", \ 2923 SSL_TRACE(("SSL: bypass default set to %d", \
2951 ssl_defaults.bypassPKCS11)); 2924 ssl_defaults.bypassPKCS11));
2952 } 2925 }
2926 #endif /* NO_PKCS11_BYPASS */
2953 ev = getenv("SSLFORCELOCKS"); 2927 ev = getenv("SSLFORCELOCKS");
2954 if (ev && ev[0] == '1') { 2928 if (ev && ev[0] == '1') {
2955 ssl_force_locks = PR_TRUE; 2929 ssl_force_locks = PR_TRUE;
2956 ssl_defaults.noLocks = 0; 2930 ssl_defaults.noLocks = 0;
2957 strcpy(lockStatus + LOCKSTATUS_OFFSET, "FORCED. "); 2931 strcpy(lockStatus + LOCKSTATUS_OFFSET, "FORCED. ");
2958 SSL_TRACE(("SSL: force_locks set to %d", ssl_force_locks)); 2932 SSL_TRACE(("SSL: force_locks set to %d", ssl_force_locks));
2959 } 2933 }
2960 ev = getenv("NSS_SSL_ENABLE_RENEGOTIATION"); 2934 ev = getenv("NSS_SSL_ENABLE_RENEGOTIATION");
2961 if (ev) { 2935 if (ev) {
2962 if (ev[0] == '1' || LOWER(ev[0]) == 'u') 2936 if (ev[0] == '1' || LOWER(ev[0]) == 'u')
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
3066 ssl_DestroySocketContents(ss); 3040 ssl_DestroySocketContents(ss);
3067 ssl_DestroyLocks(ss); 3041 ssl_DestroyLocks(ss);
3068 PORT_Free(ss); 3042 PORT_Free(ss);
3069 ss = NULL; 3043 ss = NULL;
3070 } 3044 }
3071 ss->protocolVariant = protocolVariant; 3045 ss->protocolVariant = protocolVariant;
3072 } 3046 }
3073 return ss; 3047 return ss;
3074 } 3048 }
3075 3049
OLDNEW
« no previous file with comments | « net/third_party/nss/ssl/sslsnce.c ('k') | net/third_party/nss/ssl/sslt.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698