Commit 866c3d4a authored by davidben's avatar davidben Committed by Commit bot

Fix the OpenSSL implementation of ExportKeyingMaterial.

The empty context and not using a context are different.

BUG=none

Review URL: https://codereview.chromium.org/1053233003

Cr-Commit-Position: refs/heads/master@{#323958}
parent 66a82b0b
......@@ -422,8 +422,8 @@ int SSLClientSocketOpenSSL::ExportKeyingMaterial(
int rv = SSL_export_keying_material(
ssl_, out, outlen, label.data(), label.size(),
reinterpret_cast<const unsigned char*>(context.data()),
context.length(), context.length() > 0);
reinterpret_cast<const unsigned char*>(context.data()), context.length(),
has_context ? 1 : 0);
if (rv != 1) {
int ssl_error = SSL_get_error(ssl_, rv);
......
......@@ -2331,18 +2331,32 @@ TEST_F(SSLClientSocketTest, ExportKeyingMaterial) {
const int kKeyingMaterialSize = 32;
const char kKeyingLabel1[] = "client-socket-test-1";
const char kKeyingContext[] = "";
const char kKeyingContext1[] = "";
unsigned char client_out1[kKeyingMaterialSize];
memset(client_out1, 0, sizeof(client_out1));
rv = sock->ExportKeyingMaterial(
kKeyingLabel1, false, kKeyingContext, client_out1, sizeof(client_out1));
rv = sock->ExportKeyingMaterial(kKeyingLabel1, false, kKeyingContext1,
client_out1, sizeof(client_out1));
EXPECT_EQ(rv, OK);
const char kKeyingLabel2[] = "client-socket-test-2";
unsigned char client_out2[kKeyingMaterialSize];
memset(client_out2, 0, sizeof(client_out2));
rv = sock->ExportKeyingMaterial(
kKeyingLabel2, false, kKeyingContext, client_out2, sizeof(client_out2));
rv = sock->ExportKeyingMaterial(kKeyingLabel2, false, kKeyingContext1,
client_out2, sizeof(client_out2));
EXPECT_EQ(rv, OK);
EXPECT_NE(memcmp(client_out1, client_out2, kKeyingMaterialSize), 0);
const char kKeyingContext2[] = "context";
rv = sock->ExportKeyingMaterial(kKeyingLabel1, true, kKeyingContext2,
client_out2, sizeof(client_out2));
EXPECT_EQ(rv, OK);
EXPECT_NE(memcmp(client_out1, client_out2, kKeyingMaterialSize), 0);
// Using an empty context should give different key material from not using a
// context at all.
memset(client_out2, 0, sizeof(client_out2));
rv = sock->ExportKeyingMaterial(kKeyingLabel1, true, kKeyingContext1,
client_out2, sizeof(client_out2));
EXPECT_EQ(rv, OK);
EXPECT_NE(memcmp(client_out1, client_out2, kKeyingMaterialSize), 0);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment