security/nss/lib/ssl/sslreveal.c

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 * Accessor functions for SSLSocket private members.
michael@0 3 *
michael@0 4 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 5 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 7
michael@0 8 #include "cert.h"
michael@0 9 #include "ssl.h"
michael@0 10 #include "certt.h"
michael@0 11 #include "sslimpl.h"
michael@0 12
michael@0 13 /* given PRFileDesc, returns a copy of certificate associated with the socket
michael@0 14 * the caller should delete the cert when done with SSL_DestroyCertificate
michael@0 15 */
michael@0 16 CERTCertificate *
michael@0 17 SSL_RevealCert(PRFileDesc * fd)
michael@0 18 {
michael@0 19 CERTCertificate * cert = NULL;
michael@0 20 sslSocket * sslsocket = NULL;
michael@0 21
michael@0 22 sslsocket = ssl_FindSocket(fd);
michael@0 23
michael@0 24 /* CERT_DupCertificate increases reference count and returns pointer to
michael@0 25 * the same cert
michael@0 26 */
michael@0 27 if (sslsocket && sslsocket->sec.peerCert)
michael@0 28 cert = CERT_DupCertificate(sslsocket->sec.peerCert);
michael@0 29
michael@0 30 return cert;
michael@0 31 }
michael@0 32
michael@0 33 /* given PRFileDesc, returns a pointer to PinArg associated with the socket
michael@0 34 */
michael@0 35 void *
michael@0 36 SSL_RevealPinArg(PRFileDesc * fd)
michael@0 37 {
michael@0 38 sslSocket * sslsocket = NULL;
michael@0 39 void * PinArg = NULL;
michael@0 40
michael@0 41 sslsocket = ssl_FindSocket(fd);
michael@0 42
michael@0 43 /* is pkcs11PinArg part of the sslSocket or sslSecurityInfo ? */
michael@0 44 if (sslsocket)
michael@0 45 PinArg = sslsocket->pkcs11PinArg;
michael@0 46
michael@0 47 return PinArg;
michael@0 48 }
michael@0 49
michael@0 50
michael@0 51 /* given PRFileDesc, returns a pointer to the URL associated with the socket
michael@0 52 * the caller should free url when done
michael@0 53 */
michael@0 54 char *
michael@0 55 SSL_RevealURL(PRFileDesc * fd)
michael@0 56 {
michael@0 57 sslSocket * sslsocket = NULL;
michael@0 58 char * url = NULL;
michael@0 59
michael@0 60 sslsocket = ssl_FindSocket(fd);
michael@0 61
michael@0 62 if (sslsocket && sslsocket->url)
michael@0 63 url = PL_strdup(sslsocket->url);
michael@0 64
michael@0 65 return url;
michael@0 66 }
michael@0 67
michael@0 68
michael@0 69 /* given PRFileDesc, returns status information related to extensions
michael@0 70 * negotiated with peer during the handshake.
michael@0 71 */
michael@0 72
michael@0 73 SECStatus
michael@0 74 SSL_HandshakeNegotiatedExtension(PRFileDesc * socket,
michael@0 75 SSLExtensionType extId,
michael@0 76 PRBool *pYes)
michael@0 77 {
michael@0 78 /* some decisions derived from SSL_GetChannelInfo */
michael@0 79 sslSocket * sslsocket = NULL;
michael@0 80
michael@0 81 if (!pYes) {
michael@0 82 PORT_SetError(SEC_ERROR_INVALID_ARGS);
michael@0 83 return SECFailure;
michael@0 84 }
michael@0 85
michael@0 86 sslsocket = ssl_FindSocket(socket);
michael@0 87 if (!sslsocket) {
michael@0 88 SSL_DBG(("%d: SSL[%d]: bad socket in HandshakeNegotiatedExtension",
michael@0 89 SSL_GETPID(), socket));
michael@0 90 return SECFailure;
michael@0 91 }
michael@0 92
michael@0 93 *pYes = PR_FALSE;
michael@0 94
michael@0 95 /* according to public API SSL_GetChannelInfo, this doesn't need a lock */
michael@0 96 if (sslsocket->opt.useSecurity) {
michael@0 97 if (sslsocket->ssl3.initialized) { /* SSL3 and TLS */
michael@0 98 /* now we know this socket went through ssl3_InitState() and
michael@0 99 * ss->xtnData got initialized, which is the only member accessed by
michael@0 100 * ssl3_ExtensionNegotiated();
michael@0 101 * Member xtnData appears to get accessed in functions that handle
michael@0 102 * the handshake (hello messages and extension sending),
michael@0 103 * therefore the handshake lock should be sufficient.
michael@0 104 */
michael@0 105 ssl_GetSSL3HandshakeLock(sslsocket);
michael@0 106 *pYes = ssl3_ExtensionNegotiated(sslsocket, extId);
michael@0 107 ssl_ReleaseSSL3HandshakeLock(sslsocket);
michael@0 108 }
michael@0 109 }
michael@0 110
michael@0 111 return SECSuccess;
michael@0 112 }

mercurial