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_ec_point_format.h" 17 : : 18 : : #include <stdint.h> 19 : : 20 : : #include "tls/extensions/s2n_client_supported_groups.h" 21 : : #include "tls/s2n_tls.h" 22 : : #include "utils/s2n_safety.h" 23 : : 24 : : static int s2n_ec_point_format_send(struct s2n_connection *conn, struct s2n_stuffer *out); 25 : : static int s2n_ec_point_format_recv(struct s2n_connection *conn, struct s2n_stuffer *extension); 26 : : 27 : : const s2n_extension_type s2n_client_ec_point_format_extension = { 28 : : .iana_value = TLS_EXTENSION_EC_POINT_FORMATS, 29 : : .is_response = false, 30 : : .send = s2n_ec_point_format_send, 31 : : .recv = s2n_ec_point_format_recv, 32 : : .should_send = s2n_extension_should_send_if_ecc_enabled, 33 : : .if_missing = s2n_extension_noop_if_missing, 34 : : }; 35 : : 36 : : static bool s2n_server_ec_point_format_should_send(struct s2n_connection *conn); 37 : : 38 : : const s2n_extension_type s2n_server_ec_point_format_extension = { 39 : : .iana_value = TLS_EXTENSION_EC_POINT_FORMATS, 40 : : .is_response = true, 41 : : .send = s2n_ec_point_format_send, 42 : : .recv = s2n_extension_recv_noop, 43 : : .should_send = s2n_server_ec_point_format_should_send, 44 : : .if_missing = s2n_extension_noop_if_missing, 45 : : }; 46 : : 47 : : static bool s2n_server_ec_point_format_should_send(struct s2n_connection *conn) 48 : 1149 : { 49 [ + + ][ + - ]: 1149 : return conn && conn->secure && conn->secure->cipher_suite [ + + ] 50 [ + + ]: 1149 : && s2n_kex_includes(conn->secure->cipher_suite->key_exchange_alg, &s2n_ecdhe); 51 : 1149 : } 52 : : 53 : : static int s2n_ec_point_format_send(struct s2n_connection *conn, struct s2n_stuffer *out) 54 : 7366 : { 55 : : /* Point format list len. We only support one. */ 56 [ - + ]: 7366 : POSIX_GUARD(s2n_stuffer_write_uint8(out, 1)); 57 : : 58 : : /* Only allow uncompressed format */ 59 [ - + ]: 7366 : POSIX_GUARD(s2n_stuffer_write_uint8(out, TLS_EC_POINT_FORMAT_UNCOMPRESSED)); 60 : : 61 : 7366 : return S2N_SUCCESS; 62 : 7366 : } 63 : : 64 : : static int s2n_ec_point_format_recv(struct s2n_connection *conn, struct s2n_stuffer *extension) 65 : 6481 : { 66 : : /* Only uncompressed points are supported by the server and the client must include it in 67 : : * the extension. Just skip the extension. 68 : : * 69 : : *= https://www.rfc-editor.org/rfc/rfc8422#section-5.1.2 70 : : *= type=exception 71 : : *= reason=Incorrect implementations exist in the wild. Skipping validation. 72 : : *# If the client sends the extension and the extension does not contain 73 : : *# the uncompressed point format, and the client has used the Supported 74 : : *# Groups extension to indicate support for any of the curves defined in 75 : : *# this specification, then the server MUST abort the handshake and 76 : : *# return an illegal_parameter alert. 77 : : */ 78 : 6481 : conn->ec_point_formats = 1; 79 : 6481 : return S2N_SUCCESS; 80 : 6481 : }