Skip to content

Commit

Permalink
Bug 1315735 - TLS 1.3 draft 17 - New Certificate structure. r=mt
Browse files Browse the repository at this point in the history
Subscribers: mt

Differential Revision: https://nss-dev.phacility.com/D136
  • Loading branch information
ekr committed Nov 7, 2016
1 parent a0ae14a commit be32891
Show file tree
Hide file tree
Showing 5 changed files with 288 additions and 38 deletions.
40 changes: 15 additions & 25 deletions lib/ssl/ssl3con.c
Expand Up @@ -45,14 +45,12 @@
(x)->ulValueLen = (l);
#endif

static SECStatus ssl3_AuthCertificate(sslSocket *ss);
static void ssl3_CleanupPeerCerts(sslSocket *ss);
static PK11SymKey *ssl3_GenerateRSAPMS(sslSocket *ss, ssl3CipherSpec *spec,
PK11SlotInfo *serverKeySlot);
static SECStatus ssl3_DeriveMasterSecret(sslSocket *ss, PK11SymKey *pms);
static SECStatus ssl3_DeriveConnectionKeys(sslSocket *ss);
static SECStatus ssl3_HandshakeFailure(sslSocket *ss);

static SECStatus ssl3_SendCertificate(sslSocket *ss);
static SECStatus ssl3_SendCertificateRequest(sslSocket *ss);
static SECStatus ssl3_SendNextProto(sslSocket *ss);
static SECStatus ssl3_SendFinished(sslSocket *ss, PRInt32 flags);
Expand Down Expand Up @@ -3030,17 +3028,9 @@ ssl3_FlushHandshakeMessages(sslSocket *ss, PRInt32 flags)
* Returns SECFailure if the application has required client auth.
* SECSuccess otherwise.
*/
static SECStatus
SECStatus
ssl3_HandleNoCertificate(sslSocket *ss)
{
if (ss->sec.peerCert != NULL) {
if (ss->sec.peerKey != NULL) {
SECKEY_DestroyPublicKey(ss->sec.peerKey);
ss->sec.peerKey = NULL;
}
CERT_DestroyCertificate(ss->sec.peerCert);
ss->sec.peerCert = NULL;
}
ssl3_CleanupPeerCerts(ss);

/* If the server has required client-auth blindly but doesn't
Expand Down Expand Up @@ -3155,7 +3145,7 @@ ssl3_HandshakeFailure(sslSocket *ss)
return SECFailure;
}

static void
void
ssl3_SendAlertForCertError(sslSocket *ss, PRErrorCode errCode)
{
SSL3AlertDescription desc = bad_certificate;
Expand Down Expand Up @@ -10336,7 +10326,7 @@ get_fake_cert(SECItem *pCertItem, int *pIndex)
* Used by both client and server.
* Called from HandleServerHelloDone and from SendServerHelloSequence.
*/
SECStatus
static SECStatus
ssl3_SendCertificate(sslSocket *ss)
{
SECStatus rv;
Expand Down Expand Up @@ -10492,7 +10482,7 @@ ssl3_SendCertificateStatus(sslSocket *ss)
/* This is used to delete the CA certificates in the peer certificate chain
* from the cert database after they've been validated.
*/
static void
void
ssl3_CleanupPeerCerts(sslSocket *ss)
{
PLArenaPool *arena = ss->ssl3.peerCertArena;
Expand All @@ -10505,6 +10495,15 @@ ssl3_CleanupPeerCerts(sslSocket *ss)
PORT_FreeArena(arena, PR_FALSE);
ss->ssl3.peerCertArena = NULL;
ss->ssl3.peerCertChain = NULL;

if (ss->sec.peerCert != NULL) {
if (ss->sec.peerKey) {
SECKEY_DestroyPublicKey(ss->sec.peerKey);
ss->sec.peerKey = NULL;
}
CERT_DestroyCertificate(ss->sec.peerCert);
ss->sec.peerCert = NULL;
}
}

/* Called from ssl3_HandlePostHelloHandshakeMessage() when it has deciphered
Expand Down Expand Up @@ -10613,15 +10612,6 @@ ssl3_CompleteHandleCertificate(sslSocket *ss, SSL3Opaque *b, PRUint32 length)
int errCode = SSL_ERROR_RX_MALFORMED_CERTIFICATE;
SECItem certItem;

if (ss->sec.peerCert != NULL) {
if (ss->sec.peerKey) {
SECKEY_DestroyPublicKey(ss->sec.peerKey);
ss->sec.peerKey = NULL;
}
CERT_DestroyCertificate(ss->sec.peerCert);
ss->sec.peerCert = NULL;
}

ssl3_CleanupPeerCerts(ss);
isTLS = (PRBool)(ss->ssl3.prSpec->version > SSL_LIBRARY_VERSION_3_0);

Expand Down Expand Up @@ -10771,7 +10761,7 @@ ssl3_CompleteHandleCertificate(sslSocket *ss, SSL3Opaque *b, PRUint32 length)
return SECFailure;
}

static SECStatus
SECStatus
ssl3_AuthCertificate(sslSocket *ss)
{
SECStatus rv;
Expand Down
14 changes: 13 additions & 1 deletion lib/ssl/ssl3ext.c
Expand Up @@ -78,6 +78,13 @@ static const ssl3ExtensionHandler newSessionTicketHandlers[] = {
{ -1, NULL }
};

/* This table is used by the client to handle server certificates in TLS 1.3 */
static const ssl3ExtensionHandler serverCertificateHandlers[] = {
{ ssl_signed_cert_timestamp_xtn, &ssl3_ClientHandleSignedCertTimestampXtn },
{ ssl_cert_status_xtn, &ssl3_ClientHandleStatusRequestXtn },
{ -1, NULL }
};

/* Tables of functions to format TLS hello extensions, one function per
* extension.
* These static tables are for the formatting of client hello extensions.
Expand Down Expand Up @@ -263,6 +270,10 @@ ssl3_HandleParsedExtensions(sslSocket *ss,
handlers = serverHelloHandlersSSL3;
}
break;
case certificate:
PORT_Assert(!ss->sec.isServer);
handlers = serverCertificateHandlers;
break;
default:
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
PORT_Assert(0);
Expand Down Expand Up @@ -368,12 +379,13 @@ ssl3_RegisterExtensionSender(const sslSocket *ss,
if (tls13_ExtensionAllowed(ex_type, server_hello)) {
PORT_Assert(!tls13_ExtensionAllowed(ex_type, encrypted_extensions));
sender = &xtnData->serverHelloSenders[0];
} else if (tls13_ExtensionAllowed(ex_type, certificate)) {
sender = &xtnData->certificateSenders[0];
} else {
PORT_Assert(tls13_ExtensionAllowed(ex_type, encrypted_extensions));
sender = &xtnData->encryptedExtensionsSenders[0];
}
}

for (i = 0; i < SSL_MAX_EXTENSIONS; ++i, ++sender) {
if (!sender->ex_sender) {
sender->ex_type = ex_type;
Expand Down
3 changes: 2 additions & 1 deletion lib/ssl/ssl3ext.h
Expand Up @@ -46,7 +46,8 @@ struct TLSExtensionDataStr {
/* registered callbacks that send server hello extensions */
ssl3HelloExtensionSender serverHelloSenders[SSL_MAX_EXTENSIONS];
ssl3HelloExtensionSender encryptedExtensionsSenders[SSL_MAX_EXTENSIONS];

ssl3HelloExtensionSender certificateSenders[SSL_MAX_EXTENSIONS];

/* Keep track of the extensions that are negotiated. */
PRUint16 numAdvertised;
PRUint16 numNegotiated;
Expand Down
8 changes: 4 additions & 4 deletions lib/ssl/sslimpl.h
Expand Up @@ -715,9 +715,6 @@ typedef enum {
client_hello_renegotiation /* A renegotiation attempt. */
} sslClientHelloType;

/*
* TLS extension related constants and data structures.
*/
typedef struct SessionTicketDataStr SessionTicketData;

typedef SECStatus (*sslRestartTarget)(sslSocket *);
Expand Down Expand Up @@ -1783,11 +1780,14 @@ SECStatus ssl3_InitHandshakeHashes(sslSocket *ss);
SECStatus ssl3_ServerCallSNICallback(sslSocket *ss);
SECStatus ssl3_SetupPendingCipherSpec(sslSocket *ss);
SECStatus ssl3_FlushHandshake(sslSocket *ss, PRInt32 flags);
SECStatus ssl3_SendCertificate(sslSocket *ss);
SECStatus ssl3_CompleteHandleCertificate(sslSocket *ss,
SSL3Opaque *b, PRUint32 length);
void ssl3_SendAlertForCertError(sslSocket *ss, PRErrorCode errCode);
SECStatus ssl3_HandleNoCertificate(sslSocket *ss);
SECStatus ssl3_SendEmptyCertificate(sslSocket *ss);
void ssl3_CleanupPeerCerts(sslSocket *ss);
SECStatus ssl3_SendCertificateStatus(sslSocket *ss);
SECStatus ssl3_AuthCertificate(sslSocket *ss);
SECStatus ssl_ReadCertificateStatus(sslSocket *ss, SSL3Opaque *b,
PRUint32 length);
SECStatus ssl3_EncodeSigAlgs(const sslSocket *ss, PRUint8 *buf,
Expand Down

0 comments on commit be32891

Please sign in to comment.