Skip to content

Commit 94da38d

Browse files
authored
feat: add custom critical extension support (#5321)
1 parent f1e6e0d commit 94da38d

21 files changed

+631
-2
lines changed

.gitmodules

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
[submodule "tests/cbmc/aws-verification-model-for-libcrypto"]
22
path = tests/cbmc/aws-verification-model-for-libcrypto
3-
url = https://github.com/awslabs/aws-verification-model-for-libcrypto.git
3+
url = https://github.com/goatgoose/aws-verification-model-for-libcrypto.git
4+
branch = cbmc-test
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
#pragma once
17+
18+
#include <s2n.h>
19+
20+
/**
21+
* @file custom_x509_extensions.h
22+
*
23+
* The following API enables applications to configure custom x509 critical extensions unknown to s2n-tls.
24+
* s2n-tls will ignore these extensions during certificate validation. Applications MUST validate their
25+
* custom critical extensions in the cert validation callback or after the handshake.
26+
*/
27+
28+
/**
29+
* Specify a custom critical extension to be ignored during certificate validation.
30+
*
31+
* By default, s2n-tls will reject received certificates with unknown critical extensions. Calling
32+
* s2n_config_add_custom_x509_extension will mark the given extension_oid as known and handled.
33+
* This allows applications to provide their own validation for certificate extensions unknown to s2n-tls.
34+
*
35+
* This API adds a single custom critical extension to the config at a time.
36+
*
37+
* Libcrypto Requirement: AWS-LC >= 1.51.0
38+
*
39+
* # Safety
40+
*
41+
* RFC 5280 indicates that certificate extensions are to be marked critical when validators MUST
42+
* understand the extension in order to safely determine the certificate's validity. As such, s2n-tls
43+
* assumes that this validation is performed by the application. Applications MUST implement this
44+
* validation for all provided certificate extensions outside of s2n-tls. The `s2n_cert_validation_callback`
45+
* can be used for this purpose. An alternative is to wait until after the handshake completes,
46+
* but before any application data is sent or accepted.
47+
*
48+
* @param config The configuration object being updated
49+
* @param extension_oid The pointer to a custom critical extension OID
50+
* @param extension_oid_len The length of the extension OID
51+
* @returns S2N_SUCCESS on success. S2N_FAILURE on failure
52+
*/
53+
S2N_API extern int s2n_config_add_custom_x509_extension(struct s2n_config *config, uint8_t *extension_oid, uint32_t extension_oid_len);

bindings/rust/extended/s2n-tls-sys/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ stacktrace = []
3434
unstable-cert_authorities = []
3535
unstable-cleanup = []
3636
unstable-crl = []
37+
unstable-custom_x509_extensions = []
3738
unstable-fingerprint = []
3839
unstable-ktls = []
3940
unstable-npn = []

crypto/s2n_libcrypto.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,12 @@ bool s2n_libcrypto_supports_providers(void)
235235
return false;
236236
#endif
237237
}
238+
239+
bool s2n_libcrypto_supports_custom_oid(void)
240+
{
241+
#if S2N_LIBCRYPTO_SUPPORTS_CUSTOM_OID
242+
return true;
243+
#else
244+
return false;
245+
#endif
246+
}

crypto/s2n_libcrypto.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ S2N_RESULT s2n_libcrypto_validate_runtime(void);
2929
const char *s2n_libcrypto_get_version_name(void);
3030
bool s2n_libcrypto_supports_flag_no_check_time(void);
3131
bool s2n_libcrypto_supports_providers(void);
32+
bool s2n_libcrypto_supports_custom_oid(void);

error/s2n_errno.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ static const char *no_such_error = "Internal s2n error";
105105
ERR_ENTRY(S2N_ERR_CERT_INVALID, "Certificate is invalid") \
106106
ERR_ENTRY(S2N_ERR_CERT_MAX_CHAIN_DEPTH_EXCEEDED, "The maximum certificate chain depth has been exceeded") \
107107
ERR_ENTRY(S2N_ERR_CERT_REJECTED, "Certificate failed custom application validation") \
108+
ERR_ENTRY(S2N_ERR_CERT_UNHANDLED_CRITICAL_EXTENSION, "Unhandled critical certificate extension") \
108109
ERR_ENTRY(S2N_ERR_SECURITY_POLICY_INCOMPATIBLE_CERT, "Incompatibility found between loaded certificates and chosen security policy") \
109110
ERR_ENTRY(S2N_ERR_CRL_LOOKUP_FAILED, "No CRL could be found for the corresponding certificate") \
110111
ERR_ENTRY(S2N_ERR_CRL_SIGNATURE, "The signature of the CRL is invalid") \

error/s2n_errno.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ typedef enum {
122122
S2N_ERR_CERT_INVALID,
123123
S2N_ERR_CERT_MAX_CHAIN_DEPTH_EXCEEDED,
124124
S2N_ERR_CERT_REJECTED,
125+
S2N_ERR_CERT_UNHANDLED_CRITICAL_EXTENSION,
125126
S2N_ERR_CRL_LOOKUP_FAILED,
126127
S2N_ERR_CRL_SIGNATURE,
127128
S2N_ERR_CRL_ISSUER,
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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 <openssl/x509.h>
17+
18+
static int verify_custom_crit_oids_cb(X509_STORE_CTX *ctx, X509 *x509, STACK_OF(ASN1_OBJECT) *oids) {
19+
return 1;
20+
}
21+
22+
int main()
23+
{
24+
ASN1_OBJECT *critical_oid = NULL;
25+
X509_STORE_CTX *store_ctx = NULL;
26+
27+
X509_STORE_CTX_add_custom_crit_oid(store_ctx, critical_oid);
28+
X509_STORE_CTX_set_verify_crit_oids(store_ctx, verify_custom_crit_oids_cb);
29+
30+
return 0;
31+
}

tests/features/S2N_LIBCRYPTO_SUPPORTS_CUSTOM_OID.flags

Whitespace-only changes.

0 commit comments

Comments
 (0)