Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | 1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 /* | 2 /* |
| 3 * SSL3 Protocol | 3 * SSL3 Protocol |
| 4 * | 4 * |
| 5 * This Source Code Form is subject to the terms of the Mozilla Public | 5 * This Source Code Form is subject to the terms of the Mozilla Public |
| 6 * License, v. 2.0. If a copy of the MPL was not distributed with this | 6 * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | 7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 8 | 8 |
| 9 /* TODO(ekr): Implement HelloVerifyRequest on server side. OK for now. */ | 9 /* TODO(ekr): Implement HelloVerifyRequest on server side. OK for now. */ |
| 10 | 10 |
| (...skipping 7552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7563 SSL_GETPID(), ss->fd)); | 7563 SSL_GETPID(), ss->fd)); |
| 7564 } | 7564 } |
| 7565 } | 7565 } |
| 7566 } | 7566 } |
| 7567 | 7567 |
| 7568 rv = ssl3_SendFinished(ss, 0); | 7568 rv = ssl3_SendFinished(ss, 0); |
| 7569 if (rv != SECSuccess) { | 7569 if (rv != SECSuccess) { |
| 7570 goto loser; /* err code was set. */ | 7570 goto loser; /* err code was set. */ |
| 7571 } | 7571 } |
| 7572 | 7572 |
| 7573 if (!ss->ssl3.hs.isResuming && | |
| 7574 ssl3_ExtensionNegotiated(ss, ssl_channel_id_xtn)) { | |
| 7575 /* If we are negotiating ChannelID on a full handshake then we record | |
| 7576 * the handshake hashes in |sid| at this point. They will be needed in | |
| 7577 * the event that we resume this session and use ChannelID on the | |
| 7578 * resumption handshake. */ | |
| 7579 SSL3Hashes hashes; | |
| 7580 SECItem *lastHandshakeHash = &ss->sec.ci.sid->u.ssl3.lastHandshakeHash; | |
| 7581 | |
|
wtc
2013/11/14 00:50:56
Can you assert ss->sec.ci.sid->cached == never_cac
agl
2013/11/14 18:50:42
Done.
| |
| 7582 ssl_GetSpecReadLock(ss); | |
| 7583 /* the cwSpec and zero arguments are only used for SSLv3, but we know | |
|
wtc
2013/11/14 00:50:56
The cwSpec argument is also used by ssl3_ComputeHa
agl
2013/11/14 18:50:42
This comment is clearly confusing. I've deleted it
| |
| 7584 * that this connection is not SSLv3 because we negotiated ChannelID. */ | |
| 7585 PORT_Assert(ss->version > SSL_LIBRARY_VERSION_3_0); | |
| 7586 ssl3_ComputeHandshakeHashes(ss, ss->ssl3.cwSpec, &hashes, 0); | |
|
wtc
2013/11/14 00:50:56
Check the return value?
agl
2013/11/14 18:50:42
Done.
| |
| 7587 ssl_ReleaseSpecReadLock(ss); | |
| 7588 | |
| 7589 PORT_Assert(lastHandshakeHash->len == 0); | |
| 7590 lastHandshakeHash->data = PORT_Alloc(hashes.len); | |
| 7591 if (!lastHandshakeHash->data) | |
| 7592 goto loser; | |
|
wtc
2013/11/14 00:50:56
This should be simply "return SECFailure" if you m
agl
2013/11/14 18:50:42
Done.
| |
| 7593 lastHandshakeHash->len = hashes.len; | |
| 7594 memcpy(lastHandshakeHash->data, hashes.u.raw, hashes.len); | |
| 7595 } | |
| 7596 | |
| 7573 ssl_ReleaseXmitBufLock(ss); /*******************************/ | 7597 ssl_ReleaseXmitBufLock(ss); /*******************************/ |
|
wtc
2013/11/14 00:50:56
We should call ssl_ReleaseXmitBufLock(ss) before r
agl
2013/11/14 18:50:42
Done.
| |
| 7574 | 7598 |
| 7575 if (ssl3_ExtensionNegotiated(ss, ssl_session_ticket_xtn)) | 7599 if (ssl3_ExtensionNegotiated(ss, ssl_session_ticket_xtn)) |
| 7576 ss->ssl3.hs.ws = wait_new_session_ticket; | 7600 ss->ssl3.hs.ws = wait_new_session_ticket; |
| 7577 else | 7601 else |
| 7578 ss->ssl3.hs.ws = wait_change_cipher; | 7602 ss->ssl3.hs.ws = wait_change_cipher; |
| 7579 | 7603 |
| 7580 if (ss->handshakeCallback && | 7604 if (ss->handshakeCallback && |
| 7581 (ss->ssl3.hs.canFalseStart && !ss->canFalseStartCallback)) { | 7605 (ss->ssl3.hs.canFalseStart && !ss->canFalseStartCallback)) { |
| 7582 /* Call the handshake callback here for backwards compatibility with | 7606 /* Call the handshake callback here for backwards compatibility with |
| 7583 * applications that were using false start before | 7607 * applications that were using false start before |
| (...skipping 2977 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10561 return; | 10585 return; |
| 10562 } | 10586 } |
| 10563 | 10587 |
| 10564 /* called from ssl3_SendClientSecondRound | 10588 /* called from ssl3_SendClientSecondRound |
| 10565 * ssl3_HandleFinished | 10589 * ssl3_HandleFinished |
| 10566 */ | 10590 */ |
| 10567 static SECStatus | 10591 static SECStatus |
| 10568 ssl3_SendEncryptedExtensions(sslSocket *ss) | 10592 ssl3_SendEncryptedExtensions(sslSocket *ss) |
| 10569 { | 10593 { |
| 10570 static const char CHANNEL_ID_MAGIC[] = "TLS Channel ID signature"; | 10594 static const char CHANNEL_ID_MAGIC[] = "TLS Channel ID signature"; |
| 10595 static const char CHANNEL_ID_RESUMPTION_MAGIC[] = "Resumption"; | |
| 10571 /* This is the ASN.1 prefix for a P-256 public key. Specifically it's: | 10596 /* This is the ASN.1 prefix for a P-256 public key. Specifically it's: |
| 10572 * SEQUENCE | 10597 * SEQUENCE |
| 10573 * SEQUENCE | 10598 * SEQUENCE |
| 10574 * OID id-ecPublicKey | 10599 * OID id-ecPublicKey |
| 10575 * OID prime256v1 | 10600 * OID prime256v1 |
| 10576 * BIT STRING, length 66, 0 trailing bits: 0x04 | 10601 * BIT STRING, length 66, 0 trailing bits: 0x04 |
| 10577 * | 10602 * |
| 10578 * The 0x04 in the BIT STRING is the prefix for an uncompressed, X9.62 | 10603 * The 0x04 in the BIT STRING is the prefix for an uncompressed, X9.62 |
| 10579 * public key. Following that are the two field elements as 32-byte, | 10604 * public key. Following that are the two field elements as 32-byte, |
| 10580 * big-endian numbers, as required by the Channel ID. */ | 10605 * big-endian numbers, as required by the Channel ID. */ |
| 10581 static const unsigned char P256_SPKI_PREFIX[] = { | 10606 static const unsigned char P256_SPKI_PREFIX[] = { |
| 10582 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, | 10607 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, |
| 10583 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, | 10608 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, |
| 10584 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, | 10609 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, |
| 10585 0x42, 0x00, 0x04 | 10610 0x42, 0x00, 0x04 |
| 10586 }; | 10611 }; |
| 10587 /* ChannelIDs are always 128 bytes long: 64 bytes of P-256 public key and 64 | 10612 /* ChannelIDs are always 128 bytes long: 64 bytes of P-256 public key and 64 |
| 10588 * bytes of ECDSA signature. */ | 10613 * bytes of ECDSA signature. */ |
| 10589 static const int CHANNEL_ID_PUBLIC_KEY_LENGTH = 64; | 10614 static const int CHANNEL_ID_PUBLIC_KEY_LENGTH = 64; |
| 10590 static const int CHANNEL_ID_LENGTH = 128; | 10615 static const int CHANNEL_ID_LENGTH = 128; |
| 10591 | 10616 |
| 10592 SECStatus rv = SECFailure; | 10617 SECStatus rv = SECFailure; |
| 10593 SECItem *spki = NULL; | 10618 SECItem *spki = NULL; |
| 10594 SSL3Hashes hashes; | 10619 SSL3Hashes hashes; |
| 10595 const unsigned char *pub_bytes; | 10620 const unsigned char *pub_bytes; |
| 10596 unsigned char signed_data[sizeof(CHANNEL_ID_MAGIC) + sizeof(SSL3Hashes)]; | 10621 unsigned char signed_data[sizeof(CHANNEL_ID_MAGIC) + |
| 10622 sizeof(CHANNEL_ID_RESUMPTION_MAGIC) + | |
| 10623 sizeof(SSL3Hashes)*2]; | |
| 10624 size_t j; | |
|
wtc
2013/11/14 00:50:56
Nit: this variable should be named signed_data_len
agl
2013/11/14 18:50:42
Done.
| |
| 10597 unsigned char digest[SHA256_LENGTH]; | 10625 unsigned char digest[SHA256_LENGTH]; |
| 10598 SECItem digest_item; | 10626 SECItem digest_item; |
| 10599 unsigned char signature[64]; | 10627 unsigned char signature[64]; |
| 10600 SECItem signature_item; | 10628 SECItem signature_item; |
| 10601 | 10629 |
| 10602 PORT_Assert(ss->opt.noLocks || ssl_HaveXmitBufLock(ss)); | 10630 PORT_Assert(ss->opt.noLocks || ssl_HaveXmitBufLock(ss)); |
| 10603 PORT_Assert(ss->opt.noLocks || ssl_HaveSSL3HandshakeLock(ss)); | 10631 PORT_Assert(ss->opt.noLocks || ssl_HaveSSL3HandshakeLock(ss)); |
| 10604 | 10632 |
| 10605 if (ss->ssl3.channelID == NULL) | 10633 if (ss->ssl3.channelID == NULL) |
| 10606 return SECSuccess; | 10634 return SECSuccess; |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 10636 | 10664 |
| 10637 if (spki->len != sizeof(P256_SPKI_PREFIX) + CHANNEL_ID_PUBLIC_KEY_LENGTH || | 10665 if (spki->len != sizeof(P256_SPKI_PREFIX) + CHANNEL_ID_PUBLIC_KEY_LENGTH || |
| 10638 memcmp(spki->data, P256_SPKI_PREFIX, sizeof(P256_SPKI_PREFIX) != 0)) { | 10666 memcmp(spki->data, P256_SPKI_PREFIX, sizeof(P256_SPKI_PREFIX) != 0)) { |
| 10639 PORT_SetError(SSL_ERROR_INVALID_CHANNEL_ID_KEY); | 10667 PORT_SetError(SSL_ERROR_INVALID_CHANNEL_ID_KEY); |
| 10640 rv = SECFailure; | 10668 rv = SECFailure; |
| 10641 goto loser; | 10669 goto loser; |
| 10642 } | 10670 } |
| 10643 | 10671 |
| 10644 pub_bytes = spki->data + sizeof(P256_SPKI_PREFIX); | 10672 pub_bytes = spki->data + sizeof(P256_SPKI_PREFIX); |
| 10645 | 10673 |
| 10646 memcpy(signed_data, CHANNEL_ID_MAGIC, sizeof(CHANNEL_ID_MAGIC)); | 10674 j = 0; |
| 10647 memcpy(signed_data + sizeof(CHANNEL_ID_MAGIC), hashes.u.raw, hashes.len); | 10675 memcpy(signed_data + j, CHANNEL_ID_MAGIC, sizeof(CHANNEL_ID_MAGIC)); |
| 10676 j += sizeof(CHANNEL_ID_MAGIC); | |
| 10677 if (ss->ssl3.hs.isResuming) { | |
| 10678 SECItem *lastHandshakeHash = &ss->sec.ci.sid->u.ssl3.lastHandshakeHash; | |
| 10679 PORT_Assert(lastHandshakeHash->len > 0); | |
| 10648 | 10680 |
| 10649 rv = PK11_HashBuf(SEC_OID_SHA256, digest, signed_data, | 10681 memcpy(signed_data + j, CHANNEL_ID_RESUMPTION_MAGIC, |
| 10650 » » sizeof(CHANNEL_ID_MAGIC) + hashes.len); | 10682 sizeof(CHANNEL_ID_RESUMPTION_MAGIC)); |
| 10683 j += sizeof(CHANNEL_ID_RESUMPTION_MAGIC); | |
| 10684 memcpy(signed_data + j, lastHandshakeHash->data, | |
| 10685 lastHandshakeHash->len); | |
| 10686 j += lastHandshakeHash->len; | |
| 10687 } | |
| 10688 memcpy(signed_data + j, hashes.u.raw, hashes.len); | |
| 10689 j += hashes.len; | |
| 10690 | |
| 10691 rv = PK11_HashBuf(SEC_OID_SHA256, digest, signed_data, j); | |
| 10651 if (rv != SECSuccess) | 10692 if (rv != SECSuccess) |
| 10652 goto loser; | 10693 goto loser; |
| 10653 | 10694 |
| 10654 digest_item.data = digest; | 10695 digest_item.data = digest; |
| 10655 digest_item.len = sizeof(digest); | 10696 digest_item.len = sizeof(digest); |
| 10656 | 10697 |
| 10657 signature_item.data = signature; | 10698 signature_item.data = signature; |
| 10658 signature_item.len = sizeof(signature); | 10699 signature_item.len = sizeof(signature); |
| 10659 | 10700 |
| 10660 rv = PK11_Sign(ss->ssl3.channelID, &signature_item, &digest_item); | 10701 rv = PK11_Sign(ss->ssl3.channelID, &signature_item, &digest_item); |
| (...skipping 1907 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 12568 PORT_Free(ss->ssl3.hs.recvdFragments.buf); | 12609 PORT_Free(ss->ssl3.hs.recvdFragments.buf); |
| 12569 } | 12610 } |
| 12570 } | 12611 } |
| 12571 | 12612 |
| 12572 ss->ssl3.initialized = PR_FALSE; | 12613 ss->ssl3.initialized = PR_FALSE; |
| 12573 | 12614 |
| 12574 SECITEM_FreeItem(&ss->ssl3.nextProto, PR_FALSE); | 12615 SECITEM_FreeItem(&ss->ssl3.nextProto, PR_FALSE); |
| 12575 } | 12616 } |
| 12576 | 12617 |
| 12577 /* End of ssl3con.c */ | 12618 /* End of ssl3con.c */ |
| OLD | NEW |