Skip to content

Commit

Permalink
Bug 1315735 - TLS 1.3 draft 18 - clang-format. r=me
Browse files Browse the repository at this point in the history
  • Loading branch information
ekr committed Nov 7, 2016
1 parent 66bb8cf commit d0d67f6
Show file tree
Hide file tree
Showing 14 changed files with 81 additions and 126 deletions.
18 changes: 7 additions & 11 deletions gtests/ssl_gtest/ssl_agent_unittest.cc
Expand Up @@ -44,17 +44,13 @@ const static uint8_t kCannedTls13ClientHello[] = {
0x02, 0x05, 0x02, 0x06, 0x02, 0x02, 0x02};

const static uint8_t kCannedTls13ServerHello[] = {
0x7f, kD13, 0x9c, 0xbc,
0x14, 0x9b, 0x0e, 0x2e, 0xfa, 0x0d, 0xf3, 0xf0,
0x5c, 0x70, 0x7a, 0xe0, 0xd1, 0x9b, 0x3e, 0x5a,
0x44, 0x6b, 0xdf, 0xe5, 0xc2, 0x28, 0x64, 0xf7,
0x00, 0xc1, 0x9c, 0x08, 0x76, 0x08, 0x13, 0x01,
0x00, 0x28, 0x00, 0x28, 0x00, 0x24, 0x00, 0x1d,
0x00, 0x20, 0xc2, 0xcf, 0x23, 0x17, 0x64, 0x23,
0x03, 0xf0, 0xfb, 0x45, 0x98, 0x26, 0xd1, 0x65,
0x24, 0xa1, 0x6c, 0xa9, 0x80, 0x8f, 0x2c, 0xac,
0x0a, 0xea, 0x53, 0x3a, 0xcb, 0xe3, 0x08, 0x84,
0xae, 0x19};
0x7f, kD13, 0x9c, 0xbc, 0x14, 0x9b, 0x0e, 0x2e, 0xfa, 0x0d, 0xf3, 0xf0,
0x5c, 0x70, 0x7a, 0xe0, 0xd1, 0x9b, 0x3e, 0x5a, 0x44, 0x6b, 0xdf, 0xe5,
0xc2, 0x28, 0x64, 0xf7, 0x00, 0xc1, 0x9c, 0x08, 0x76, 0x08, 0x13, 0x01,
0x00, 0x28, 0x00, 0x28, 0x00, 0x24, 0x00, 0x1d, 0x00, 0x20, 0xc2, 0xcf,
0x23, 0x17, 0x64, 0x23, 0x03, 0xf0, 0xfb, 0x45, 0x98, 0x26, 0xd1, 0x65,
0x24, 0xa1, 0x6c, 0xa9, 0x80, 0x8f, 0x2c, 0xac, 0x0a, 0xea, 0x53, 0x3a,
0xcb, 0xe3, 0x08, 0x84, 0xae, 0x19};
static const char *k0RttData = "ABCDEF";

TEST_P(TlsAgentTest, EarlyFinished) {
Expand Down
78 changes: 27 additions & 51 deletions gtests/ssl_gtest/ssl_extension_unittest.cc
Expand Up @@ -643,7 +643,8 @@ struct PskIdentity {

class TlsPreSharedKeyReplacer;

typedef std::function<void(TlsPreSharedKeyReplacer*)> TlsPreSharedKeyReplacerFunc;
typedef std::function<void(TlsPreSharedKeyReplacer*)>
TlsPreSharedKeyReplacerFunc;

class TlsPreSharedKeyReplacer : public TlsExtensionFilter {
public:
Expand Down Expand Up @@ -722,7 +723,7 @@ class TlsPreSharedKeyReplacer : public TlsExtensionFilter {
}

parser.reset(new TlsParser(binders));
while(parser->remaining()) {
while (parser->remaining()) {
DataBuffer binder;

if (!parser->ReadVariable(&binder, 1)) {
Expand Down Expand Up @@ -762,12 +763,8 @@ class TlsPreSharedKeyReplacer : public TlsExtensionFilter {
TEST_F(TlsExtensionTest13Stream, ResumeEmptyPskLabel) {
SetupForResume();

client_->SetPacketFilter(
new TlsPreSharedKeyReplacer(
[](TlsPreSharedKeyReplacer *r) {
r->identities_[0].identity.Truncate(0);
}
));
client_->SetPacketFilter(new TlsPreSharedKeyReplacer([](
TlsPreSharedKeyReplacer* r) { r->identities_[0].identity.Truncate(0); }));
ConnectExpectFail();
client_->CheckErrorCode(SSL_ERROR_ILLEGAL_PARAMETER_ALERT);
server_->CheckErrorCode(SSL_ERROR_RX_MALFORMED_CLIENT_HELLO);
Expand All @@ -778,12 +775,9 @@ TEST_F(TlsExtensionTest13Stream, ResumeIncorrectBinderValue) {
SetupForResume();

client_->SetPacketFilter(
new TlsPreSharedKeyReplacer(
[](TlsPreSharedKeyReplacer *r) {
r->binders_[0].Write(0,
r->binders_[0].data()[0] ^ 0xff, 1);
}
));
new TlsPreSharedKeyReplacer([](TlsPreSharedKeyReplacer* r) {
r->binders_[0].Write(0, r->binders_[0].data()[0] ^ 0xff, 1);
}));
ConnectExpectFail();
client_->CheckErrorCode(SSL_ERROR_DECRYPT_ERROR_ALERT);
server_->CheckErrorCode(SSL_ERROR_BAD_HANDSHAKE_HASH_VALUE);
Expand All @@ -794,11 +788,9 @@ TEST_F(TlsExtensionTest13Stream, ResumeIncorrectBinderLength) {
SetupForResume();

client_->SetPacketFilter(
new TlsPreSharedKeyReplacer(
[](TlsPreSharedKeyReplacer *r) {
r->binders_[0].Write(r->binders_[0].len(), 0xff, 1);
}
));
new TlsPreSharedKeyReplacer([](TlsPreSharedKeyReplacer* r) {
r->binders_[0].Write(r->binders_[0].len(), 0xff, 1);
}));
ConnectExpectFail();
client_->CheckErrorCode(SSL_ERROR_ILLEGAL_PARAMETER_ALERT);
server_->CheckErrorCode(SSL_ERROR_RX_MALFORMED_CLIENT_HELLO);
Expand All @@ -808,12 +800,8 @@ TEST_F(TlsExtensionTest13Stream, ResumeIncorrectBinderLength) {
TEST_F(TlsExtensionTest13Stream, ResumeBinderTooShort) {
SetupForResume();

client_->SetPacketFilter(
new TlsPreSharedKeyReplacer(
[](TlsPreSharedKeyReplacer *r) {
r->binders_[0].Truncate(31);
}
));
client_->SetPacketFilter(new TlsPreSharedKeyReplacer(
[](TlsPreSharedKeyReplacer* r) { r->binders_[0].Truncate(31); }));
ConnectExpectFail();
client_->CheckErrorCode(SSL_ERROR_ILLEGAL_PARAMETER_ALERT);
server_->CheckErrorCode(SSL_ERROR_RX_MALFORMED_CLIENT_HELLO);
Expand All @@ -825,12 +813,10 @@ TEST_F(TlsExtensionTest13Stream, ResumeTwoPsks) {
SetupForResume();

client_->SetPacketFilter(
new TlsPreSharedKeyReplacer(
[](TlsPreSharedKeyReplacer *r) {
r->identities_.push_back(r->identities_[0]);
r->binders_.push_back(r->binders_[0]);
}
));
new TlsPreSharedKeyReplacer([](TlsPreSharedKeyReplacer* r) {
r->identities_.push_back(r->identities_[0]);
r->binders_.push_back(r->binders_[0]);
}));
ConnectExpectFail();
client_->CheckErrorCode(SSL_ERROR_DECRYPT_ERROR_ALERT);
server_->CheckErrorCode(SSL_ERROR_BAD_HANDSHAKE_HASH_VALUE);
Expand All @@ -842,11 +828,9 @@ TEST_F(TlsExtensionTest13Stream, ResumeTwoIdentitiesOneBinder) {
SetupForResume();

client_->SetPacketFilter(
new TlsPreSharedKeyReplacer(
[](TlsPreSharedKeyReplacer *r) {
r->identities_.push_back(r->identities_[0]);
}
));
new TlsPreSharedKeyReplacer([](TlsPreSharedKeyReplacer* r) {
r->identities_.push_back(r->identities_[0]);
}));
ConnectExpectFail();
client_->CheckErrorCode(SSL_ERROR_ILLEGAL_PARAMETER_ALERT);
server_->CheckErrorCode(SSL_ERROR_RX_MALFORMED_CLIENT_HELLO);
Expand All @@ -855,23 +839,18 @@ TEST_F(TlsExtensionTest13Stream, ResumeTwoIdentitiesOneBinder) {
TEST_F(TlsExtensionTest13Stream, ResumeOneIdentityTwoBinders) {
SetupForResume();

client_->SetPacketFilter(
new TlsPreSharedKeyReplacer(
[](TlsPreSharedKeyReplacer *r) {
r->binders_.push_back(r->binders_[0]);
}
));
client_->SetPacketFilter(new TlsPreSharedKeyReplacer([](
TlsPreSharedKeyReplacer* r) { r->binders_.push_back(r->binders_[0]); }));
ConnectExpectFail();
client_->CheckErrorCode(SSL_ERROR_ILLEGAL_PARAMETER_ALERT);
server_->CheckErrorCode(SSL_ERROR_RX_MALFORMED_CLIENT_HELLO);
}


TEST_F(TlsExtensionTest13Stream, ResumePskExtensionNotLast) {
SetupForResume();

const uint8_t empty_buf[] = { 0 };
DataBuffer empty (empty_buf, 0);
const uint8_t empty_buf[] = {0};
DataBuffer empty(empty_buf, 0);
client_->SetPacketFilter(
// Inject an unused extension.
new TlsExtensionAppender(0xffff, empty));
Expand All @@ -896,15 +875,12 @@ TEST_F(TlsExtensionTest13Stream, ResumeNoKeModes) {
// errors.
TEST_F(TlsExtensionTest13Stream, ResumeBogusKeModes) {
SetupForResume();
const static uint8_t ke_modes[] = {
1, // Length
kTls13PskKe
};
const static uint8_t ke_modes[] = {1, // Length
kTls13PskKe};

DataBuffer modes(ke_modes, sizeof(ke_modes));
client_->SetPacketFilter(
new TlsExtensionReplacer(ssl_tls13_psk_key_exchange_modes_xtn,
modes));
new TlsExtensionReplacer(ssl_tls13_psk_key_exchange_modes_xtn, modes));
ConnectExpectFail();
client_->CheckErrorCode(SSL_ERROR_BAD_MAC_READ);
server_->CheckErrorCode(SSL_ERROR_BAD_MAC_READ);
Expand Down
4 changes: 2 additions & 2 deletions gtests/ssl_gtest/tls_agent.cc
Expand Up @@ -863,8 +863,8 @@ void TlsAgentTestBase::EnsureInit() {
Init();
}
const std::vector<SSLNamedGroup> groups = {
ssl_grp_ec_curve25519, ssl_grp_ec_secp256r1,
ssl_grp_ec_secp384r1, ssl_grp_ffdhe_2048};
ssl_grp_ec_curve25519, ssl_grp_ec_secp256r1, ssl_grp_ec_secp384r1,
ssl_grp_ffdhe_2048};
agent_->ConfigNamedGroups(groups);
}

Expand Down
6 changes: 2 additions & 4 deletions gtests/ssl_gtest/tls_connect.cc
Expand Up @@ -700,11 +700,9 @@ void TlsKeyExchangeTest::CheckKEXDetails(
for (auto it : expected_shares) {
EXPECT_NE(expected_share2, it);
}
std::vector<SSLNamedGroup> expected_shares2 = {
expected_share2
};
std::vector<SSLNamedGroup> expected_shares2 = {expected_share2};
std::vector<SSLNamedGroup> shares =
GetShareDetails(shares_capture2_->extension());
GetShareDetails(shares_capture2_->extension());
EXPECT_EQ(expected_shares2, shares);
}
} // namespace nss_test
1 change: 1 addition & 0 deletions gtests/ssl_gtest/tls_connect.h
Expand Up @@ -259,6 +259,7 @@ class TlsKeyExchangeTest : public TlsConnectGeneric {
void CheckKEXDetails(const std::vector<SSLNamedGroup>& expectedGroups,
const std::vector<SSLNamedGroup>& expectedShares,
SSLNamedGroup expectedShare2);

private:
void CheckKEXDetails(const std::vector<SSLNamedGroup>& expectedGroups,
const std::vector<SSLNamedGroup>& expectedShares,
Expand Down
4 changes: 2 additions & 2 deletions gtests/ssl_gtest/tls_filter.h
Expand Up @@ -234,8 +234,8 @@ class TlsExtensionFilter : public TlsHandshakeFilter {

class TlsExtensionCapture : public TlsExtensionFilter {
public:
TlsExtensionCapture(uint16_t ext, bool last = false) :
extension_(ext), captured_(false), last_(last), data_() {}
TlsExtensionCapture(uint16_t ext, bool last = false)
: extension_(ext), captured_(false), last_(last), data_() {}

const DataBuffer& extension() const { return data_; }
bool captured() const { return captured_; }
Expand Down
18 changes: 7 additions & 11 deletions gtests/ssl_gtest/tls_hkdf_unittest.cc
Expand Up @@ -241,17 +241,13 @@ TEST_P(TlsHkdfTest, HkdfExpandLabel) {
{/* ssl_hash_md5 */},
{/* ssl_hash_sha1 */},
{/* ssl_hash_sha224 */},
{0x34, 0x7c, 0x67, 0x80, 0xff, 0x0b, 0xba, 0xd7,
0x1c, 0x28, 0x3b, 0x16, 0xeb, 0x2f, 0x9c, 0xf6,
0x2d, 0x24, 0xe6, 0xcd, 0xb6, 0x13, 0xd5, 0x17,
0x76, 0x54, 0x8c, 0xb0, 0x7d, 0xcd, 0xe7, 0x4c},
{0x4b, 0x1e, 0x5e, 0xc1, 0x49, 0x30, 0x78, 0xea,
0x35, 0xbd, 0x3f, 0x01, 0x04, 0xe6, 0x1a, 0xea,
0x14, 0xcc, 0x18, 0x2a, 0xd1, 0xc4, 0x76, 0x21,
0xc4, 0x64, 0xc0, 0x4e, 0x4b, 0x36, 0x16, 0x05,
0x6f, 0x04, 0xab, 0xe9, 0x43, 0xb1, 0x2d, 0xa8,
0xa7, 0x17, 0x9a, 0x5f, 0x09, 0x91, 0x7d, 0x1f}
};
{0x34, 0x7c, 0x67, 0x80, 0xff, 0x0b, 0xba, 0xd7, 0x1c, 0x28, 0x3b,
0x16, 0xeb, 0x2f, 0x9c, 0xf6, 0x2d, 0x24, 0xe6, 0xcd, 0xb6, 0x13,
0xd5, 0x17, 0x76, 0x54, 0x8c, 0xb0, 0x7d, 0xcd, 0xe7, 0x4c},
{0x4b, 0x1e, 0x5e, 0xc1, 0x49, 0x30, 0x78, 0xea, 0x35, 0xbd, 0x3f, 0x01,
0x04, 0xe6, 0x1a, 0xea, 0x14, 0xcc, 0x18, 0x2a, 0xd1, 0xc4, 0x76, 0x21,
0xc4, 0x64, 0xc0, 0x4e, 0x4b, 0x36, 0x16, 0x05, 0x6f, 0x04, 0xab, 0xe9,
0x43, 0xb1, 0x2d, 0xa8, 0xa7, 0x17, 0x9a, 0x5f, 0x09, 0x91, 0x7d, 0x1f}};

const DataBuffer expected_data(tv[hash_type_], kHashLength[hash_type_]);
HkdfExpandLabel(&k1_, hash_type_, kSessionHash, kHashLength[hash_type_],
Expand Down
1 change: 0 additions & 1 deletion lib/ssl/SSLerrs.h
Expand Up @@ -505,4 +505,3 @@ ER3(SSL_ERROR_MALFORMED_PSK_KEY_EXCHANGE_MODES, (SSL_ERROR_BASE + 158),

ER3(SSL_ERROR_MISSING_PSK_KEY_EXCHANGE_MODES, (SSL_ERROR_BASE + 159),
"SSL expected a missing PSK key exchange modes extension.")

2 changes: 1 addition & 1 deletion lib/ssl/ssl3con.c
Expand Up @@ -11653,7 +11653,7 @@ ssl3_HandleHandshakeMessage(sslSocket *ss, SSL3Opaque *b, PRUint32 length,
computeHashes = TLS13_IN_HS_STATE(ss, wait_cert_verify);
} else if (type == finished) {
computeHashes =
TLS13_IN_HS_STATE(ss, wait_cert_request, wait_finished);
TLS13_IN_HS_STATE(ss, wait_cert_request, wait_finished);
}
}

Expand Down
3 changes: 1 addition & 2 deletions lib/ssl/ssl3ext.c
Expand Up @@ -183,7 +183,7 @@ ssl3_ParseExtensions(sslSocket *ss, SSL3Opaque **b, PRUint32 *length)
}

SSL_TRC(10, ("%d: SSL3[%d]: parsing extension %d",
SSL_GETPID(), ss->fd, extension_type));
SSL_GETPID(), ss->fd, extension_type));
/* Check whether an extension has been sent multiple times. */
for (cursor = PR_NEXT_LINK(&ss->ssl3.hs.remoteExtensions);
cursor != &ss->ssl3.hs.remoteExtensions;
Expand Down Expand Up @@ -336,7 +336,6 @@ ssl3_HandleParsedExtensions(sslSocket *ss,
return SECFailure;
}
}

}
}
return SECSuccess;
Expand Down
6 changes: 3 additions & 3 deletions lib/ssl/ssl3ext.h
Expand Up @@ -47,7 +47,7 @@ struct TLSExtensionDataStr {
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 Expand Up @@ -96,9 +96,9 @@ struct TLSExtensionDataStr {

PRUint16 dtlsSRTPCipherSuite; /* 0 if not selected */

SECItem pskBinder; /* The PSK binder for the first PSK (TLS 1.3) */
SECItem pskBinder; /* The PSK binder for the first PSK (TLS 1.3) */
unsigned long pskBinderPrefixLen; /* The length of the binder input. */
PRCList remoteKeyShares; /* The other side's public keys (TLS 1.3) */
PRCList remoteKeyShares; /* The other side's public keys (TLS 1.3) */
};

typedef struct TLSExtensionStr {
Expand Down

0 comments on commit d0d67f6

Please sign in to comment.