Branch data Line data Source code
1 : : /* 2 : : * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 : : * 4 : : * Licensed under the Apache License, Version 2.0 (the "License"). 5 : : * You may not use this file except in compliance with the License. 6 : : * A copy of the License is located at 7 : : * 8 : : * http://aws.amazon.com/apache2.0 9 : : * 10 : : * or in the "license" file accompanying this file. This file is distributed 11 : : * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 : : * express or implied. See the License for the specific language governing 13 : : * permissions and limitations under the License. 14 : : */ 15 : : 16 : : #include "tls/extensions/s2n_client_cert_status_request.h" 17 : : 18 : : #include <stdint.h> 19 : : #include <sys/param.h> 20 : : 21 : : #include "tls/s2n_tls.h" 22 : : #include "tls/s2n_tls_parameters.h" 23 : : #include "utils/s2n_safety.h" 24 : : 25 : : static bool s2n_client_cert_status_request_should_send(struct s2n_connection *conn); 26 : : static int s2n_client_cert_status_request_send(struct s2n_connection *conn, struct s2n_stuffer *out); 27 : : static int s2n_client_cert_status_request_recv(struct s2n_connection *conn, struct s2n_stuffer *extension); 28 : : 29 : : const s2n_extension_type s2n_client_cert_status_request_extension = { 30 : : .iana_value = TLS_EXTENSION_STATUS_REQUEST, 31 : : .is_response = false, 32 : : .send = s2n_client_cert_status_request_send, 33 : : .recv = s2n_client_cert_status_request_recv, 34 : : .should_send = s2n_client_cert_status_request_should_send, 35 : : .if_missing = s2n_extension_noop_if_missing, 36 : : }; 37 : : 38 : : static bool s2n_client_cert_status_request_should_send(struct s2n_connection *conn) 39 : 7354 : { 40 : 7354 : return conn->request_ocsp_status; 41 : 7354 : } 42 : : 43 : : static int s2n_client_cert_status_request_send(struct s2n_connection *conn, struct s2n_stuffer *out) 44 : 276 : { 45 [ - + ]: 276 : POSIX_GUARD(s2n_stuffer_write_uint8(out, (uint8_t) S2N_STATUS_REQUEST_OCSP)); 46 : : 47 : : /* responder_id_list 48 : : * 49 : : * From https://tools.ietf.org/html/rfc6066#section-8: 50 : : * A zero-length "responder_id_list" sequence has the special meaning that the responders are implicitly 51 : : * known to the server, e.g., by prior arrangement */ 52 [ - + ]: 276 : POSIX_GUARD(s2n_stuffer_write_uint16(out, 0)); 53 : : 54 : : /* request_extensions 55 : : * 56 : : * From https://tools.ietf.org/html/rfc6066#section-8: 57 : : * A zero-length "request_extensions" value means that there are no extensions. */ 58 [ - + ]: 276 : POSIX_GUARD(s2n_stuffer_write_uint16(out, 0)); 59 : : 60 : 276 : return S2N_SUCCESS; 61 : 276 : } 62 : : 63 : : static int s2n_client_cert_status_request_recv(struct s2n_connection *conn, struct s2n_stuffer *extension) 64 : 277 : { 65 [ + + ]: 277 : if (s2n_stuffer_data_available(extension) < 5) { 66 : : /* Malformed length, ignore the extension */ 67 : 1 : return S2N_SUCCESS; 68 : 1 : } 69 : : 70 : 276 : uint8_t type = 0; 71 [ - + ]: 276 : POSIX_GUARD(s2n_stuffer_read_uint8(extension, &type)); 72 [ + + ]: 276 : if (type != (uint8_t) S2N_STATUS_REQUEST_OCSP) { 73 : : /* We only support OCSP (type 1), ignore the extension */ 74 : 1 : return S2N_SUCCESS; 75 : 1 : } 76 : : 77 : 275 : conn->status_type = (s2n_status_request_type) type; 78 : 275 : return S2N_SUCCESS; 79 : 276 : }