| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#include <stdio.h> |
| 17 |
#include <string.h> |
| 18 |
|
| 19 |
#include "crypto/s2n_fips.h" |
| 20 |
#include "s2n_test.h" |
| 21 |
#include "stuffer/s2n_stuffer.h" |
| 22 |
#include "testlib/s2n_testlib.h" |
| 23 |
#include "tls/s2n_prf.h" |
| 24 |
|
| 25 |
int s2n_prf_tls_master_secret(struct s2n_connection *conn, struct s2n_blob *premaster_secret); |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
int main(int argc, char **argv) |
| 36 |
{ |
| 37 |
uint8_t master_secret_hex_pad[96]; |
| 38 |
char premaster_secret_hex_in[] = "03009e8e006a7f1451d32164088a8cba5077d1b819160662a97e90a765cec244b5f8f98fd50cfe8e4fba97994a7a4843"; |
| 39 |
char client_random_hex_in[] = "537fb7fdddc05090774e55f8ef8564c2b5b238819703409bfdabe14e4cf1897d"; |
| 40 |
char server_random_hex_in[] = "537fb7fe649225c9f37904b24916452d51794b3b5735fc7e628b6090db52209f"; |
| 41 |
char master_secret_hex_in[] = "02b811717e3aa29e6b0526d7e9ae2b74496d461564401f47498e9cdbdf54c8afa69c25a648b360de2004c74850e8f7db"; |
| 42 |
|
| 43 |
struct s2n_stuffer client_random_in = { 0 }; |
| 44 |
struct s2n_stuffer server_random_in = { 0 }; |
| 45 |
struct s2n_stuffer premaster_secret_in = { 0 }; |
| 46 |
struct s2n_stuffer master_secret_hex_out = { 0 }; |
| 47 |
struct s2n_blob master_secret = { 0 }; |
| 48 |
EXPECT_SUCCESS(s2n_blob_init(&master_secret, master_secret_hex_pad, sizeof(master_secret_hex_pad))); |
| 49 |
struct s2n_blob pms = { 0 }; |
| 50 |
|
| 51 |
struct s2n_connection *conn = NULL; |
| 52 |
|
| 53 |
BEGIN_TEST(); |
| 54 |
EXPECT_SUCCESS(s2n_disable_tls13_in_test()); |
| 55 |
|
| 56 |
if (s2n_is_in_fips_mode()) { |
| 57 |
|
| 58 |
END_TEST(); |
| 59 |
} |
| 60 |
|
| 61 |
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_SERVER)); |
| 62 |
|
| 63 |
EXPECT_SUCCESS(s2n_stuffer_alloc_ro_from_string(&client_random_in, client_random_hex_in)); |
| 64 |
EXPECT_SUCCESS(s2n_stuffer_alloc_ro_from_string(&server_random_in, server_random_hex_in)); |
| 65 |
EXPECT_SUCCESS(s2n_stuffer_alloc_ro_from_string(&premaster_secret_in, premaster_secret_hex_in)); |
| 66 |
|
| 67 |
EXPECT_SUCCESS(s2n_stuffer_init(&master_secret_hex_out, &master_secret)); |
| 68 |
|
| 69 |
|
| 70 |
for (int i = 0; i < 48; i++) { |
| 71 |
uint8_t c = 0; |
| 72 |
EXPECT_OK(s2n_stuffer_read_uint8_hex(&premaster_secret_in, &c)); |
| 73 |
conn->secrets.version.tls12.rsa_premaster_secret[i] = c; |
| 74 |
} |
| 75 |
for (int i = 0; i < 32; i++) { |
| 76 |
uint8_t c = 0; |
| 77 |
EXPECT_OK(s2n_stuffer_read_uint8_hex(&client_random_in, &c)); |
| 78 |
conn->client_hello.random[i] = c; |
| 79 |
} |
| 80 |
for (int i = 0; i < 32; i++) { |
| 81 |
uint8_t c = 0; |
| 82 |
EXPECT_OK(s2n_stuffer_read_uint8_hex(&server_random_in, &c)); |
| 83 |
conn->handshake_params.server_random[i] = c; |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
conn->actual_protocol_version = S2N_SSLv3; |
| 88 |
pms.data = conn->secrets.version.tls12.rsa_premaster_secret; |
| 89 |
pms.size = sizeof(conn->secrets.version.tls12.rsa_premaster_secret); |
| 90 |
EXPECT_SUCCESS(s2n_prf_tls_master_secret(conn, &pms)); |
| 91 |
|
| 92 |
|
| 93 |
for (int i = 0; i < 48; i++) { |
| 94 |
EXPECT_OK(s2n_stuffer_write_uint8_hex(&master_secret_hex_out, conn->secrets.version.tls12.master_secret[i])); |
| 95 |
} |
| 96 |
|
| 97 |
EXPECT_EQUAL(memcmp(master_secret_hex_pad, master_secret_hex_in, sizeof(master_secret_hex_pad)), 0); |
| 98 |
|
| 99 |
EXPECT_SUCCESS(s2n_connection_free(conn)); |
| 100 |
EXPECT_SUCCESS(s2n_stuffer_free(&client_random_in)); |
| 101 |
EXPECT_SUCCESS(s2n_stuffer_free(&server_random_in)); |
| 102 |
EXPECT_SUCCESS(s2n_stuffer_free(&premaster_secret_in)); |
| 103 |
|
| 104 |
END_TEST(); |
| 105 |
} |