| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#include "api/s2n.h" |
| 17 |
#include "error/s2n_errno.h" |
| 18 |
#include "tls/s2n_auth_selection.h" |
| 19 |
#include "tls/s2n_cipher_suites.h" |
| 20 |
#include "tls/s2n_tls.h" |
| 21 |
#include "utils/s2n_safety.h" |
| 22 |
|
| 23 |
int s2n_server_cert_recv(struct s2n_connection *conn) |
| 24 |
{ |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
struct s2n_stuffer in = conn->handshake.io; |
| 29 |
|
| 30 |
if (conn->actual_protocol_version == S2N_TLS13) { |
| 31 |
uint8_t certificate_request_context_len = 0; |
| 32 |
POSIX_GUARD(s2n_stuffer_read_uint8(&in, &certificate_request_context_len)); |
| 33 |
S2N_ERROR_IF(certificate_request_context_len != 0, S2N_ERR_BAD_MESSAGE); |
| 34 |
} |
| 35 |
|
| 36 |
uint32_t size_of_all_certificates = 0; |
| 37 |
POSIX_GUARD(s2n_stuffer_read_uint24(&in, &size_of_all_certificates)); |
| 38 |
|
| 39 |
S2N_ERROR_IF(size_of_all_certificates > s2n_stuffer_data_available(&in) || size_of_all_certificates < 3, |
| 40 |
S2N_ERR_BAD_MESSAGE); |
| 41 |
|
| 42 |
DEFER_CLEANUP(s2n_cert_public_key public_key = { 0 }, s2n_pkey_free); |
| 43 |
POSIX_GUARD(s2n_pkey_zero_init(&public_key)); |
| 44 |
|
| 45 |
s2n_pkey_type actual_cert_pkey_type; |
| 46 |
struct s2n_blob cert_chain = { 0 }; |
| 47 |
cert_chain.size = size_of_all_certificates; |
| 48 |
cert_chain.data = s2n_stuffer_raw_read(&in, size_of_all_certificates); |
| 49 |
POSIX_ENSURE_REF(cert_chain.data); |
| 50 |
|
| 51 |
POSIX_GUARD_RESULT(s2n_x509_validator_validate_cert_chain(&conn->x509_validator, conn, cert_chain.data, |
| 52 |
cert_chain.size, &actual_cert_pkey_type, &public_key)); |
| 53 |
|
| 54 |
POSIX_GUARD(s2n_is_cert_type_valid_for_auth(conn, actual_cert_pkey_type)); |
| 55 |
POSIX_GUARD_RESULT(s2n_pkey_setup_for_type(&public_key, actual_cert_pkey_type)); |
| 56 |
conn->handshake_params.server_public_key = public_key; |
| 57 |
ZERO_TO_DISABLE_DEFER_CLEANUP(public_key); |
| 58 |
|
| 59 |
|
| 60 |
conn->handshake.io = in; |
| 61 |
|
| 62 |
return 0; |
| 63 |
} |
| 64 |
|
| 65 |
int s2n_server_cert_send(struct s2n_connection *conn) |
| 66 |
{ |
| 67 |
S2N_ERROR_IF(conn->handshake_params.our_chain_and_key == NULL, S2N_ERR_CERT_TYPE_UNSUPPORTED); |
| 68 |
if (conn->actual_protocol_version == S2N_TLS13) { |
| 69 |
|
| 70 |
|
| 71 |
uint8_t certificate_request_context_len = 0; |
| 72 |
POSIX_GUARD(s2n_stuffer_write_uint8(&conn->handshake.io, certificate_request_context_len)); |
| 73 |
} |
| 74 |
|
| 75 |
POSIX_GUARD(s2n_send_cert_chain(conn, &conn->handshake.io, conn->handshake_params.our_chain_and_key)); |
| 76 |
|
| 77 |
return 0; |
| 78 |
} |