Debian Codegraph @

debian/rust-vendor/aws-lc-sys/aws-lc/crypto/x509/x_req.c

raw
1 // Copyright (C) 1995-1998 Eric Young ([email protected]) All rights reserved.
2 // SPDX-License-Identifier: Apache-2.0
3
4 #include <stdio.h>
5
6 #include <openssl/asn1t.h>
7 #include <openssl/thread.h>
8 #include <openssl/x509.h>
9
10 #include "internal.h"
11
12
13 // X509_REQ_INFO is handled in an unusual way to get round invalid encodings.
14 // Some broken certificate requests don't encode the attributes field if it
15 // is empty. This is in violation of PKCS#10 but we need to tolerate it. We
16 // do this by making the attributes field OPTIONAL then using the callback to
17 // initialise it to an empty STACK. This means that the field will be
18 // correctly encoded unless we NULL out the field.
19
20 static int rinf_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
21 void *exarg) {
22 X509_REQ_INFO *rinf = (X509_REQ_INFO *)*pval;
23
24 if (operation == ASN1_OP_NEW_POST) {
25 rinf->attributes = sk_X509_ATTRIBUTE_new_null();
26 if (!rinf->attributes) {
27 return 0;
28 }
29 }
30
31 if (operation == ASN1_OP_D2I_POST) {
32 // The only defined CSR version is v1(0). For compatibility, we also accept
33 // a hypothetical v3(2). Although not defined, older versions of certbot
34 // use it. See https://github.com/certbot/certbot/pull/9334.
35 long version = ASN1_INTEGER_get(rinf->version);
36 if (version != X509_REQ_VERSION_1 && version != 2) {
37 OPENSSL_PUT_ERROR(X509, X509_R_INVALID_VERSION);
38 return 0;
39 }
40 }
41
42 return 1;
43 }
44
45 ASN1_SEQUENCE_enc(X509_REQ_INFO, enc, rinf_cb) = {
46 ASN1_SIMPLE(X509_REQ_INFO, version, ASN1_INTEGER),
47 ASN1_SIMPLE(X509_REQ_INFO, subject, X509_NAME),
48 ASN1_SIMPLE(X509_REQ_INFO, pubkey, X509_PUBKEY),
49 // This isn't really OPTIONAL but it gets around invalid encodings.
50 ASN1_IMP_SET_OF_OPT(X509_REQ_INFO, attributes, X509_ATTRIBUTE, 0),
51 } ASN1_SEQUENCE_END_enc(X509_REQ_INFO, X509_REQ_INFO)
52
53 IMPLEMENT_ASN1_FUNCTIONS(X509_REQ_INFO)
54
55 ASN1_SEQUENCE(X509_REQ) = {
56 ASN1_SIMPLE(X509_REQ, req_info, X509_REQ_INFO),
57 ASN1_SIMPLE(X509_REQ, sig_alg, X509_ALGOR),
58 ASN1_SIMPLE(X509_REQ, signature, ASN1_BIT_STRING),
59 } ASN1_SEQUENCE_END(X509_REQ)
60
61 IMPLEMENT_ASN1_FUNCTIONS(X509_REQ)
62
63 IMPLEMENT_ASN1_DUP_FUNCTION(X509_REQ)