| // You may obtain a copy of the License at |
| 7 | // |
| 8 | // https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 |
| 16 | #ifndef OPENSSL_HEADER_X509_H |
| 17 | #define OPENSSL_HEADER_X509_H |
| 18 |
| 19 | #include <openssl/base.h> // IWYU pragma: export |
| 20 |
| 21 | #include <time.h> |
| 22 |
| 23 | #include <openssl/asn1.h> |
| 24 | #include <openssl/bio.h> |
| 25 | #include <openssl/cipher.h> |
| 26 | #include <openssl/conf.h> |
| 27 | #include <openssl/dh.h> |
| 28 | #include <openssl/dsa.h> |
| 29 | #include <openssl/ec.h> |
| 30 | #include <openssl/ecdh.h> |
| 31 | #include <openssl/ecdsa.h> |
| 32 | #include <openssl/evp.h> |
| 33 | #include <openssl/lhash.h> |
| 34 | #include <openssl/obj.h> |
| 35 | #include <openssl/pkcs7.h> |
| 36 | #include <openssl/pool.h> |
| 37 | #include <openssl/rsa.h> |
| 38 | #include <openssl/sha.h> |
| 39 | #include <openssl/stack.h> |
| 40 | #include <openssl/thread.h> |
| 41 | #include <openssl/x509v3_errors.h> // IWYU pragma: export |
| 42 |
| 43 | #if defined(__cplusplus) |
| 44 | extern "C" { |
| 45 | #endif |
| 46 |
| 47 |
| 48 | // Legacy X.509 library. |
| 49 | // |
| 50 | // This header is part of OpenSSL's X.509 implementation. It is retained for |
| 51 | // compatibility but should not be used by new code. The functions are difficult |
| 52 | // to use correctly, and have buggy or non-standard behaviors. They are thus |
| 53 | // particularly prone to behavior changes and API removals, as BoringSSL |
| 54 | // iterates on these issues. |
| 55 | // |
| 56 | // In the future, a replacement library will be available. Meanwhile, minimize |
| 57 | // dependencies on this header where possible. |
| 58 |
| 59 |
| 60 | // Certificates. |
| 61 | // |
| 62 | // An |X509| object represents an X.509 certificate, defined in RFC 5280. |
| 63 | // |
| 64 | // Although an |X509| is a mutable object, mutating an |X509| can give incorrect |
| 65 | // results. Callers typically obtain |X509|s by parsing some input with |
| 66 | // |d2i_X509|, etc. Such objects carry information such as the serialized |
| 67 | // TBSCertificate and decoded extensions, which will become inconsistent when |
| 68 | // mutated. |
| 69 | // |
| 70 | // Instead, mutation functions should only be used when issuing new |
| 71 | // certificates, as described in a later section. |
| 72 |
| 73 | DEFINE_STACK_OF(X509) |
| 74 |
| 75 | // X509 is an |ASN1_ITEM| whose ASN.1 type is X.509 Certificate (RFC 5280) and C |
| 76 | // type is |X509*|. |
| 77 | DECLARE_ASN1_ITEM(X509) |
| 78 |
| 79 | // X509_up_ref adds one to the reference count of |x509| and returns one. |
| 80 | OPENSSL_EXPORT int X509_up_ref(X509 *x509); |
| 81 |
| 82 | // X509_chain_up_ref returns a newly-allocated |STACK_OF(X509)| containing a |
| 83 | // shallow copy of |chain|, or NULL on error. That is, the return value has the |
| 84 | // same contents as |chain|, and each |X509|'s reference count is incremented by |
| 85 | // one. |
| 86 | OPENSSL_EXPORT STACK_OF(X509) *X509_chain_up_ref(STACK_OF(X509) *chain); |
| 87 |
| 88 | // X509_dup returns a newly-allocated copy of |x509|, or NULL on error. This |
| 89 | // function works by serializing the structure, so auxiliary properties (see |
| 90 | // |i2d_X509_AUX|) are not preserved. Additionally, if |x509| is incomplete, |
| 91 | // this function may fail. |
| 92 | // |
| 93 | // TODO(https://crbug.com/boringssl/407): This function should be const and |
| 94 | // thread-safe but is currently neither in some cases, notably if |crl| was |
| 95 | // mutated. |
| 96 | OPENSSL_EXPORT X509 *X509_dup(X509 *x509); |
| 97 |
| 98 | // X509_free decrements |x509|'s reference count and, if zero, releases memory |
| 99 | // associated with |x509|. |
| 100 | OPENSSL_EXPORT void X509_free(X509 *x509); |
| 101 |
| 102 | // d2i_X509 parses up to |len| bytes from |*inp| as a DER-encoded X.509 |
| 103 | // Certificate (RFC 5280), as described in |d2i_SAMPLE|. |
| 104 | OPENSSL_EXPORT X509 *d2i_X509(X509 **out, const uint8_t **inp, long len); |
| 105 |
| 106 | // X509_parse_from_buffer parses an X.509 structure from |buf| and returns a |
| 107 | // fresh X509 or NULL on error. There must not be any trailing data in |buf|. |
| 108 | // The returned structure (if any) holds a reference to |buf| rather than |
| 109 | // copying parts of it as a normal |d2i_X509| call would do. |
| 110 | OPENSSL_EXPORT X509 *X509_parse_from_buffer(CRYPTO_BUFFER *buf); |
| 111 |
| 112 | // i2d_X509 marshals |x509| as a DER-encoded X.509 Certificate (RFC 5280), as |
| 113 | // described in |i2d_SAMPLE|. |
| 114 | // |
| 115 | // TODO(https://crbug.com/boringssl/407): This function should be const and |
| 116 | // thread-safe but is currently neither in some cases, notably if |x509| was |
| 117 | // mutated. |
| 118 | OPENSSL_EXPORT int i2d_X509(X509 *x509, uint8_t **outp); |
| 119 |
| 120 | // X509_VERSION_* are X.509 version numbers. Note the numerical values of all |
| 121 | // defined X.509 versions are one less than the named version. |
| 122 | #define X509_VERSION_1 0 |
| 123 | #define X509_VERSION_2 1 |
| 124 | #define X509_VERSION_3 2 |
| 125 |
| 126 | // X509_get_version returns the numerical value of |x509|'s version, which will |
| 127 | // be one of the |X509_VERSION_*| constants. |
| 128 | OPENSSL_EXPORT long X509_get_version(const X509 *x509); |
| 129 |
| 130 | // X509_get0_serialNumber returns |x509|'s serial number. |
| 131 | OPENSSL_EXPORT const ASN1_INTEGER *X509_get0_serialNumber(const X509 *x509); |
| 132 |
| 133 | // X509_get0_notBefore returns |x509|'s notBefore time. |
| 134 | OPENSSL_EXPORT const ASN1_TIME *X509_get0_notBefore(const X509 *x509); |
| 135 |
| 136 | // X509_get0_notAfter returns |x509|'s notAfter time. |
| 137 | OPENSSL_EXPORT const ASN1_TIME *X509_get0_notAfter(const X509 *x509); |
| 138 |
| 139 | // X509_get_issuer_name returns |x509|'s issuer. |
| 140 | OPENSSL_EXPORT X509_NAME *X509_get_issuer_name(const X509 *x509); |
| 141 |
| 142 | // X509_get_subject_name returns |x509|'s subject. |
| 143 | OPENSSL_EXPORT X509_NAME *X509_get_subject_name(const X509 *x509); |
| 144 |
| 145 | // X509_get_X509_PUBKEY returns the public key of |x509|. Note this function is |
| 146 | // not const-correct for legacy reasons. Callers should not modify the returned |
| 147 | // object. |
| 148 | OPENSSL_EXPORT X509_PUBKEY *X509_get_X509_PUBKEY(const X509 *x509); |
| 149 |
| 150 | // X509_get0_pubkey returns |x509|'s public key as an |EVP_PKEY|, or NULL if the |
| 151 | // public key was unsupported or could not be decoded. The |EVP_PKEY| is cached |
| 152 | // in |x509|, so callers must not mutate the result. |
| 153 | OPENSSL_EXPORT EVP_PKEY *X509_get0_pubkey(const X509 *x509); |
| 154 |
| 155 | // X509_get_pubkey behaves like |X509_get0_pubkey| but increments the reference |
| 156 | // count on the |EVP_PKEY|. The caller must release the result with |
| 157 | // |EVP_PKEY_free| when done. The |EVP_PKEY| is cached in |x509|, so callers |
| 158 | // must not mutate the result. |
| 159 | OPENSSL_EXPORT EVP_PKEY *X509_get_pubkey(const X509 *x509); |
| 160 |
| 161 | // X509_get0_pubkey_bitstr returns the BIT STRING portion of |x509|'s public |
| 162 | // key. Note this does not contain the AlgorithmIdentifier portion. |
| 163 | // |
| 164 | // WARNING: This function returns a non-const pointer for OpenSSL compatibility, |
| 165 | // but the caller must not modify the resulting object. Doing so will break |
| 166 | // internal invariants in |x509|. |
| 167 | OPENSSL_EXPORT ASN1_BIT_STRING *X509_get0_pubkey_bitstr(const X509 *x509); |
| 168 |
| 169 | // X509_check_private_key returns one if |x509|'s public key matches |pkey| and |
| 170 | // zero otherwise. |
| 171 | OPENSSL_EXPORT int X509_check_private_key(const X509 *x509, |
| 172 | const EVP_PKEY *pkey); |
| 173 |
| 174 | // X509_get0_uids sets |*out_issuer_uid| to a non-owning pointer to the |
| 175 | // issuerUID field of |x509|, or NULL if |x509| has no issuerUID. It similarly |
| 176 | // outputs |x509|'s subjectUID field to |*out_subject_uid|. |
| 177 | // |
| 178 | // Callers may pass NULL to either |out_issuer_uid| or |out_subject_uid| to |
| 179 | // ignore the corresponding field. |
| 180 | OPENSSL_EXPORT void X509_get0_uids(const X509 *x509, |
| 181 | const ASN1_BIT_STRING **out_issuer_uid, |
| 182 | const ASN1_BIT_STRING **out_subject_uid); |
| 183 |
| 184 | // The following bits are returned from |X509_get_extension_flags|. |
| 185 |
| 186 | // EXFLAG_BCONS indicates the certificate has a basic constraints extension. |
| 187 | #define EXFLAG_BCONS 0x1 |
| 188 | // EXFLAG_KUSAGE indicates the certifcate has a key usage extension. |
| 189 | #define EXFLAG_KUSAGE 0x2 |
| 190 | // EXFLAG_XKUSAGE indicates the certifcate has an extended key usage extension. |
| 191 | #define EXFLAG_XKUSAGE 0x4 |
| 192 | // EXFLAG_CA indicates the certificate has a basic constraints extension with |
| 193 | // the CA bit set. |
| 194 | #define EXFLAG_CA 0x10 |
| 195 | // EXFLAG_SI indicates the certificate is self-issued, i.e. its subject and |
| 196 | // issuer names match. |
| 197 | #define EXFLAG_SI 0x20 |
| 198 | // EXFLAG_V1 indicates an X.509v1 certificate. |
| 199 | #define EXFLAG_V1 0x40 |
| 200 | // EXFLAG_INVALID indicates an error processing some extension. The certificate |
| 201 | // should not be accepted. Note the lack of this bit does not imply all |
| 202 | // extensions are valid, only those used to compute extension flags. |
| 203 | #define EXFLAG_INVALID 0x80 |
| 204 | // EXFLAG_SET is an internal bit that indicates extension flags were computed. |
| 205 | #define EXFLAG_SET 0x100 |
| 206 | // EXFLAG_CRITICAL indicates an unsupported critical extension. The certificate |
| 207 | // should not be accepted. |
| 208 | #define EXFLAG_CRITICAL 0x200 |
| 209 | // EXFLAG_SS indicates the certificate is likely self-signed. That is, if it is |
| 210 | // self-issued, its authority key identifier (if any) matches itself, and its |
| 211 | // key usage extension (if any) allows certificate signatures. The signature |
| 212 | // itself is not checked in computing this bit. |
| 213 | #define EXFLAG_SS 0x2000 |
| 214 |
| 215 | // X509_get_extension_flags decodes a set of extensions from |x509| and returns |
| 216 | // a collection of |EXFLAG_*| bits which reflect |x509|. If there was an error |
| 217 | // in computing this bitmask, the result will include the |EXFLAG_INVALID| bit. |
| 218 | OPENSSL_EXPORT uint32_t X509_get_extension_flags(X509 *x509); |
| 219 |
| 220 | // X509_get_pathlen returns path length constraint from the basic constraints |
| 221 | // extension in |x509|. (See RFC 5280, section 4.2.1.9.) It returns -1 if the |
| 222 | // constraint is not present, or if some extension in |x509| was invalid. |
| 223 | // |
| 224 | // TODO(crbug.com/boringssl/381): Decoding an |X509| object will not check for |
| 225 | // invalid extensions. To detect the error case, call |
| 226 | // |X509_get_extension_flags| and check the |EXFLAG_INVALID| bit. |
| 227 | OPENSSL_EXPORT long X509_get_pathlen(X509 *x509); |
| 228 |
| 229 | // X509v3_KU_* are key usage bits returned from |X509_get_key_usage|. |
| 230 | #define X509v3_KU_DIGITAL_SIGNATURE 0x0080 |
| 231 | #define X509v3_KU_NON_REPUDIATION 0x0040 |
| 232 | #define X509v3_KU_KEY_ENCIPHERMENT 0x0020 |
| 233 | #define X509v3_KU_DATA_ENCIPHERMENT 0x0010 |
| 234 | #define X509v3_KU_KEY_AGREEMENT 0x0008 |
| 235 | #define X509v3_KU_KEY_CERT_SIGN 0x0004 |
| 236 | #define X509v3_KU_CRL_SIGN 0x0002 |
| 237 | #define X509v3_KU_ENCIPHER_ONLY 0x0001 |
| 238 | #define X509v3_KU_DECIPHER_ONLY 0x8000 |
| 239 |
| 240 | // X509_get_key_usage returns a bitmask of key usages (see Section 4.2.1.3 of |
| 241 | // RFC 5280) which |x509| is valid for. This function only reports the first 16 |
| 242 | // bits, in a little-endian byte order, but big-endian bit order. That is, bits |
| 243 | // 0 though 7 are reported at 1<<7 through 1<<0, and bits 8 through 15 are |
| 244 | // reported at 1<<15 through 1<<8. |
| 245 | // |
| 246 | // Instead of depending on this bit order, callers should compare against the |
| 247 | // |X509v3_KU_*| constants. |
| 248 | // |
| 249 | // If |x509| has no key usage extension, all key usages are valid and this |
| 250 | // function returns |UINT32_MAX|. If there was an error processing |x509|'s |
| 251 | // extensions, or if the first 16 bits in the key usage extension were all zero, |
| 252 | // this function returns zero. |
| 253 | OPENSSL_EXPORT uint32_t X509_get_key_usage(X509 *x509); |
| 254 |
| 255 | // XKU_* are extended key usage bits returned from |
| 256 | // |X509_get_extended_key_usage|. |
| 257 | #define XKU_SSL_SERVER 0x1 |
| 258 | #define XKU_SSL_CLIENT 0x2 |
| 259 | #define XKU_SMIME 0x4 |
| 260 | #define XKU_CODE_SIGN 0x8 |
| 261 | #define XKU_SGC 0x10 |
| 262 | #define XKU_OCSP_SIGN 0x20 |
| 263 | #define XKU_TIMESTAMP 0x40 |
| 264 | #define XKU_DVCS 0x80 |
| 265 | #define XKU_ANYEKU 0x100 |
| 266 |
| 267 | // X509_get_extended_key_usage returns a bitmask of extended key usages (see |
| 268 | // Section 4.2.1.12 of RFC 5280) which |x509| is valid for. The result will be |
| 269 | // a combination of |XKU_*| constants. If checking an extended key usage not |
| 270 | // defined above, callers should extract the extended key usage extension |
| 271 | // separately, e.g. via |X509_get_ext_d2i|. |
| 272 | // |
| 273 | // If |x509| has no extended key usage extension, all extended key usages are |
| 274 | // valid and this function returns |UINT32_MAX|. If there was an error |
| 275 | // processing |x509|'s extensions, or if |x509|'s extended key usage extension |
| 276 | // contained no recognized usages, this function returns zero. |
| 277 | OPENSSL_EXPORT uint32_t X509_get_extended_key_usage(X509 *x509); |
| 278 |
| 279 | // X509_get0_subject_key_id returns |x509|'s subject key identifier, if present. |
| 280 | // (See RFC 5280, section 4.2.1.2.) It returns NULL if the extension is not |
| 281 | // present or if some extension in |x509| was invalid. |
| 282 | // |
| 283 | // TODO(crbug.com/boringssl/381): Decoding an |X509| object will not check for |
| 284 | // invalid extensions. To detect the error case, call |
| 285 | // |X509_get_extension_flags| and check the |EXFLAG_INVALID| bit. |
| 286 | OPENSSL_EXPORT const ASN1_OCTET_STRING *X509_get0_subject_key_id(X509 *x509); |
| 287 |
| 288 | // X509_get0_authority_key_id returns keyIdentifier of |x509|'s authority key |
| 289 | // identifier, if the extension and field are present. (See RFC 5280, |
| 290 | // section 4.2.1.1.) It returns NULL if the extension is not present, if it is |
| 291 | // present but lacks a keyIdentifier field, or if some extension in |x509| was |
| 292 | // invalid. |
| 293 | // |
| 294 | // TODO(crbug.com/boringssl/381): Decoding an |X509| object will not check for |
| 295 | // invalid extensions. To detect the error case, call |
| 296 | // |X509_get_extension_flags| and check the |EXFLAG_INVALID| bit. |
| 297 | OPENSSL_EXPORT const ASN1_OCTET_STRING *X509_get0_authority_key_id(X509 *x509); |
| 298 |
| 299 | DEFINE_STACK_OF(GENERAL_NAME) |
| 300 | typedef STACK_OF(GENERAL_NAME) GENERAL_NAMES; |
| 301 |
| 302 | // X509_get0_authority_issuer returns the authorityCertIssuer of |x509|'s |
| 303 | // authority key identifier, if the extension and field are present. (See |
| 304 | // RFC 5280, section 4.2.1.1.) It returns NULL if the extension is not present, |
| 305 | // if it is present but lacks a authorityCertIssuer field, or if some extension |
| 306 | // in |x509| was invalid. |
| 307 | // |
| 308 | // TODO(crbug.com/boringssl/381): Decoding an |X509| object will not check for |
| 309 | // invalid extensions. To detect the error case, call |
| 310 | // |X509_get_extension_flags| and check the |EXFLAG_INVALID| bit. |
| 311 | OPENSSL_EXPORT const GENERAL_NAMES *X509_get0_authority_issuer(X509 *x509); |
| 312 |
| 313 | // X509_get0_authority_serial returns the authorityCertSerialNumber of |x509|'s |
| 314 | // authority key identifier, if the extension and field are present. (See |
| 315 | // RFC 5280, section 4.2.1.1.) It returns NULL if the extension is not present, |
| 316 | // if it is present but lacks a authorityCertSerialNumber field, or if some |
| 317 | // extension in |x509| was invalid. |
| 318 | // |
| 319 | // TODO(crbug.com/boringssl/381): Decoding an |X509| object will not check for |
| 320 | // invalid extensions. To detect the error case, call |
| 321 | // |X509_get_extension_flags| and check the |EXFLAG_INVALID| bit. |
| 322 | OPENSSL_EXPORT const ASN1_INTEGER *X509_get0_authority_serial(X509 *x509); |
| 323 |
| 324 | // X509_get0_extensions returns |x509|'s extension list, or NULL if |x509| omits |
| 325 | // it. |
| 326 | OPENSSL_EXPORT const STACK_OF(X509_EXTENSION) *X509_get0_extensions( |
| 327 | const X509 *x509); |
| 328 |
| 329 | // X509_get_ext_count returns the number of extensions in |x|. |
| 330 | OPENSSL_EXPORT int X509_get_ext_count(const X509 *x); |
| 331 |
| 332 | // X509_get_ext_by_NID behaves like |X509v3_get_ext_by_NID| but searches for |
| 333 | // extensions in |x|. |
| 334 | OPENSSL_EXPORT int X509_get_ext_by_NID(const X509 *x, int nid, int lastpos); |
| 335 |
| 336 | // X509_get_ext_by_OBJ behaves like |X509v3_get_ext_by_OBJ| but searches for |
| 337 | // extensions in |x|. |
| 338 | OPENSSL_EXPORT int X509_get_ext_by_OBJ(const X509 *x, const ASN1_OBJECT *obj, |
| 339 | int lastpos); |
| 340 |
| 341 | // X509_get_ext_by_critical behaves like |X509v3_get_ext_by_critical| but |
| 342 | // searches for extensions in |x|. |
| 343 | OPENSSL_EXPORT int X509_get_ext_by_critical(const X509 *x, int crit, |
| 344 | int lastpos); |
| 345 |
| 346 | // X509_get_ext returns the extension in |x| at index |loc|, or NULL if |loc| is |
| 347 | // out of bounds. This function returns a non-const pointer for OpenSSL |
| 348 | // compatibility, but callers should not mutate the result. |
| 349 | OPENSSL_EXPORT X509_EXTENSION *X509_get_ext(const X509 *x, int loc); |
| 350 |
| 351 | // X509_get_ext_d2i behaves like |X509V3_get_d2i| but looks for the extension in |
| 352 | // |x509|'s extension list. |
| 353 | // |
| 354 | // WARNING: This function is difficult to use correctly. See the documentation |
| 355 | // for |X509V3_get_d2i| for details. |
| 356 | OPENSSL_EXPORT void *X509_get_ext_d2i(const X509 *x509, int nid, |
| 357 | int *out_critical, int *out_idx); |
| 358 |
| 359 | // X509_get0_tbs_sigalg returns the signature algorithm in |x509|'s |
| 360 | // TBSCertificate. For the outer signature algorithm, see |X509_get0_signature|. |
| 361 | // |
| 362 | // Certificates with mismatched signature algorithms will successfully parse, |
| 363 | // but they will be rejected when verifying. |
| 364 | OPENSSL_EXPORT const X509_ALGOR *X509_get0_tbs_sigalg(const X509 *x509); |
| 365 |
| 366 | // X509_get0_signature sets |*out_sig| and |*out_alg| to the signature and |
| 367 | // signature algorithm of |x509|, respectively. Either output pointer may be |
| 368 | // NULL to ignore the value. |
| 369 | // |
| 370 | // This function outputs the outer signature algorithm. For the one in the |
| 371 | // TBSCertificate, see |X509_get0_tbs_sigalg|. Certificates with mismatched |
| 372 | // signature algorithms will successfully parse, but they will be rejected when |
| 373 | // verifying. |
| 374 | OPENSSL_EXPORT void X509_get0_signature(const ASN1_BIT_STRING **out_sig, |
| 375 | const X509_ALGOR **out_alg, |
| 376 | const X509 *x509); |
| 377 |
| 378 | // X509_get_signature_nid returns the NID corresponding to |x509|'s signature |
| 379 | // algorithm, or |NID_undef| if the signature algorithm does not correspond to |
| 380 | // a known NID. |
| 381 | OPENSSL_EXPORT int X509_get_signature_nid(const X509 *x509); |
| 382 |
| 383 | // i2d_X509_tbs serializes the TBSCertificate portion of |x509|, as described in |
| 384 | // |i2d_SAMPLE|. |
| 385 | // |
| 386 | // This function preserves the original encoding of the TBSCertificate and may |
| 387 | // not reflect modifications made to |x509|. It may be used to manually verify |
| 388 | // the signature of an existing certificate. To generate certificates, use |
| 389 | // |i2d_re_X509_tbs| instead. |
| 390 | OPENSSL_EXPORT int i2d_X509_tbs(X509 *x509, unsigned char **outp); |
| 391 |
| 392 | // X509_verify checks that |x509| has a valid signature by |pkey|. It returns |
| 393 | // one if the signature is valid and zero otherwise. Note this function only |
| 394 | // checks the signature itself and does not perform a full certificate |
| 395 | // validation. |
| 396 | OPENSSL_EXPORT int X509_verify(X509 *x509, EVP_PKEY *pkey); |
| 397 |
| 398 | // X509_get1_email returns a newly-allocated list of NUL-terminated strings |
| 399 | // containing all email addresses in |x509|'s subject and all rfc822name names |
| 400 | // in |x509|'s subject alternative names. Email addresses which contain embedded |
| 401 | // NUL bytes are skipped. |
| 402 | // |
| 403 | // On error, or if there are no such email addresses, it returns NULL. When |
| 404 | // done, the caller must release the result with |X509_email_free|. |
| 405 | OPENSSL_EXPORT STACK_OF(OPENSSL_STRING) *X509_get1_email(const X509 *x509); |
| 406 |
| 407 | // X509_get1_ocsp returns a newly-allocated list of NUL-terminated strings |
| 408 | // containing all OCSP URIs in |x509|. That is, it collects all URI |
| 409 | // AccessDescriptions with an accessMethod of id-ad-ocsp in |x509|'s authority |
| 410 | // information access extension. URIs which contain embedded NUL bytes are |
| 411 | // skipped. |
| 412 | // |
| 413 | // On error, or if there are no such URIs, it returns NULL. When done, the |
| 414 | // caller must release the result with |X509_email_free|. |
| 415 | OPENSSL_EXPORT STACK_OF(OPENSSL_STRING) *X509_get1_ocsp(const X509 *x509); |
| 416 |
| 417 | // X509_email_free releases memory associated with |sk|, including |sk| itself. |
| 418 | // Each |OPENSSL_STRING| in |sk| must be a NUL-terminated string allocated with |
| 419 | // |OPENSSL_malloc|. If |sk| is NULL, no action is taken. |
| 420 | OPENSSL_EXPORT void X509_email_free(STACK_OF(OPENSSL_STRING) *sk); |
| 421 |
| 422 | // X509_cmp compares |a| and |b| and returns zero if they are equal, a negative |
| 423 | // number if |b| sorts after |a| and a negative number if |a| sorts after |b|. |
| 424 | // The sort order implemented by this function is arbitrary and does not |
| 425 | // reflect properties of the certificate such as expiry. Applications should not |
| 426 | // rely on the order itself. |
| 427 | // |
| 428 | // TODO(https://crbug.com/boringssl/355): This function works by comparing a |
| 429 | // cached hash of the encoded certificate. If |a| or |b| could not be |
| 430 | // serialized, the current behavior is to compare all unencodable certificates |
| 431 | // as equal. This function should only be used with |X509| objects that were |
| 432 | // parsed from bytes and never mutated. |
| 433 | // |
| 434 | // TODO(https://crbug.com/boringssl/407): This function is const, but it is not |
| 435 | // always thread-safe, notably if |a| and |b| were mutated. |
| 436 | OPENSSL_EXPORT int X509_cmp(const X509 *a, const X509 *b); |
| 437 |
| 438 |
| 439 | // Issuing certificates. |
| 440 | // |
| 441 | // An |X509| object may also represent an incomplete certificate. Callers may |
| 442 | // construct empty |X509| objects, fill in fields individually, and finally sign |
| 443 | // the result. The following functions may be used for this purpose. |
| 444 |
| 445 | // X509_new returns a newly-allocated, empty |X509| object, or NULL on error. |
| 446 | // This produces an incomplete certificate which may be filled in to issue a new |
| 447 | // certificate. |
| 448 | OPENSSL_EXPORT X509 *X509_new(void); |
| 449 |
| 450 | // X509_set_version sets |x509|'s version to |version|, which should be one of |
| 451 | // the |X509V_VERSION_*| constants. It returns one on success and zero on error. |
| 452 | // |
| 453 | // If unsure, use |X509_VERSION_3|. |
| 454 | OPENSSL_EXPORT int X509_set_version(X509 *x509, long version); |
| 455 |
| 456 | // X509_set_serialNumber sets |x509|'s serial number to |serial|. It returns one |
| 457 | // on success and zero on error. |
| 458 | OPENSSL_EXPORT int X509_set_serialNumber(X509 *x509, |
| 459 | const ASN1_INTEGER *serial); |
| 460 |
| 461 | // X509_set1_notBefore sets |x509|'s notBefore time to |tm|. It returns one on |
| 462 | // success and zero on error. |
| 463 | OPENSSL_EXPORT int X509_set1_notBefore(X509 *x509, const ASN1_TIME *tm); |
| 464 |
| 465 | // X509_set1_notAfter sets |x509|'s notAfter time to |tm|. it returns one on |
| 466 | // success and zero on error. |
| 467 | OPENSSL_EXPORT int X509_set1_notAfter(X509 *x509, const ASN1_TIME *tm); |
| 468 |
| 469 | // X509_getm_notBefore returns a mutable pointer to |x509|'s notBefore time. |
| 470 | OPENSSL_EXPORT ASN1_TIME *X509_getm_notBefore(X509 *x509); |
| 471 |
| 472 | // X509_getm_notAfter returns a mutable pointer to |x509|'s notAfter time. |
| 473 | OPENSSL_EXPORT ASN1_TIME *X509_getm_notAfter(X509 *x); |
| 474 |
| 475 | // X509_set_issuer_name sets |x509|'s issuer to a copy of |name|. It returns one |
| 476 | // on success and zero on error. |
| 477 | OPENSSL_EXPORT int X509_set_issuer_name(X509 *x509, X509_NAME *name); |
| 478 |
| 479 | // X509_set_subject_name sets |x509|'s subject to a copy of |name|. It returns |
| 480 | // one on success and zero on error. |
| 481 | OPENSSL_EXPORT int X509_set_subject_name(X509 *x509, X509_NAME *name); |
| 482 |
| 483 | // X509_set_pubkey sets |x509|'s public key to |pkey|. It returns one on success |
| 484 | // and zero on error. This function does not take ownership of |pkey| and |
| 485 | // internally copies and updates reference counts as needed. |
| 486 | OPENSSL_EXPORT int X509_set_pubkey(X509 *x509, EVP_PKEY *pkey); |
| 487 |
| 488 | // X509_delete_ext removes the extension in |x| at index |loc| and returns the |
| 489 | // removed extension, or NULL if |loc| was out of bounds. If non-NULL, the |
| 490 | // caller must release the result with |X509_EXTENSION_free|. |
| 491 | OPENSSL_EXPORT X509_EXTENSION *X509_delete_ext(X509 *x, int loc); |
| 492 |
| 493 | // X509_add_ext adds a copy of |ex| to |x|. It returns one on success and zero |
| 494 | // on failure. The caller retains ownership of |ex| and can release it |
| 495 | // independently of |x|. |
| 496 | // |
| 497 | // The new extension is inserted at index |loc|, shifting extensions to the |
| 498 | // right. If |loc| is -1 or out of bounds, the new extension is appended to the |
| 499 | // list. |
| 500 | OPENSSL_EXPORT int X509_add_ext(X509 *x, const X509_EXTENSION *ex, int loc); |
| 501 |
| 502 | // X509_add1_ext_i2d behaves like |X509V3_add1_i2d| but adds the extension to |
| 503 | // |x|'s extension list. |
| 504 | // |
| 505 | // WARNING: This function may return zero or -1 on error. The caller must also |
| 506 | // ensure |value|'s type matches |nid|. See the documentation for |
| 507 | // |X509V3_add1_i2d| for details. |
| 508 | OPENSSL_EXPORT int X509_add1_ext_i2d(X509 *x, int nid, void *value, int crit, |
| 509 | unsigned long flags); |
| 510 |
| 511 | // X509_sign signs |x509| with |pkey| and replaces the signature algorithm and |
| 512 | // signature fields. It returns the length of the signature on success and zero |
| 513 | // on error. This function uses digest algorithm |md|, or |pkey|'s default if |
| 514 | // NULL. Other signing parameters use |pkey|'s defaults. To customize them, use |
| 515 | // |X509_sign_ctx|. |
| 516 | OPENSSL_EXPORT int X509_sign(X509 *x509, EVP_PKEY *pkey, const EVP_MD *md); |
| 517 |
| 518 | // X509_sign_ctx signs |x509| with |ctx| and replaces the signature algorithm |
| 519 | // and signature fields. It returns the length of the signature on success and |
| 520 | // zero on error. The signature algorithm and parameters come from |ctx|, which |
| 521 | // must have been initialized with |EVP_DigestSignInit|. The caller should |
| 522 | // configure the corresponding |EVP_PKEY_CTX| before calling this function. |
| 523 | // |
| 524 | // On success or failure, this function mutates |ctx| and resets it to the empty |
| 525 | // state. Caller should not rely on its contents after the function returns. |
| 526 | OPENSSL_EXPORT int X509_sign_ctx(X509 *x509, EVP_MD_CTX *ctx); |
| 527 |
| 528 | // i2d_re_X509_tbs serializes the TBSCertificate portion of |x509|, as described |
| 529 | // in |i2d_SAMPLE|. |
| 530 | // |
| 531 | // This function re-encodes the TBSCertificate and may not reflect |x509|'s |
| 532 | // original encoding. It may be used to manually generate a signature for a new |
| 533 | // certificate. To verify certificates, use |i2d_X509_tbs| instead. |
| 534 | OPENSSL_EXPORT int i2d_re_X509_tbs(X509 *x509, unsigned char **outp); |
| 535 |
| 536 | // X509_set1_signature_algo sets |x509|'s signature algorithm to |algo| and |
| 537 | // returns one on success or zero on error. It updates both the signature field |
| 538 | // of the TBSCertificate structure, and the signatureAlgorithm field of the |
| 539 | // Certificate. |
| 540 | OPENSSL_EXPORT int X509_set1_signature_algo(X509 *x509, const X509_ALGOR *algo); |
| 541 |
| 542 | // X509_set1_signature_value sets |x509|'s signature to a copy of the |sig_len| |
| 543 | // bytes pointed by |sig|. It returns one on success and zero on error. |
| 544 | // |
| 545 | // Due to a specification error, X.509 certificates store signatures in ASN.1 |
| 546 | // BIT STRINGs, but signature algorithms return byte strings rather than bit |
| 547 | // strings. This function creates a BIT STRING containing a whole number of |
| 548 | // bytes, with the bit order matching the DER encoding. This matches the |
| 549 | // encoding used by all X.509 signature algorithms. |
| 550 | OPENSSL_EXPORT int X509_set1_signature_value(X509 *x509, const uint8_t *sig, |
| 551 | size_t sig_len); |
| 552 |
| 553 |
| 554 | // Auxiliary certificate properties. |
| 555 | // |
| 556 | // |X509| objects optionally maintain auxiliary properties. These are not part |
| 557 | // of the certificates themselves, and thus are not covered by signatures or |
| 558 | // preserved by the standard serialization. They are used as inputs or outputs |
| 559 | // to other functions in this library. |
| 560 |
| 561 | // i2d_X509_AUX marshals |x509| as a DER-encoded X.509 Certificate (RFC 5280), |
| 562 | // followed optionally by a separate, OpenSSL-specific structure with auxiliary |
| 563 | // properties. It behaves as described in |i2d_SAMPLE|. |
| 564 | // |
| 565 | // Unlike similarly-named functions, this function does not output a single |
| 566 | // ASN.1 element. Directly embedding the output in a larger ASN.1 structure will |
| 567 | // not behave correctly. |
| 568 | // |
| 569 | // TODO(crbug.com/boringssl/407): |x509| should be const. |
| 570 | OPENSSL_EXPORT int i2d_X509_AUX(X509 *x509, uint8_t **outp); |
| 571 |
| 572 | // d2i_X509_AUX parses up to |length| bytes from |*inp| as a DER-encoded X.509 |
| 573 | // Certificate (RFC 5280), followed optionally by a separate, OpenSSL-specific |
| 574 | // structure with auxiliary properties. It behaves as described in |d2i_SAMPLE|. |
| 575 | // |
| 576 | // WARNING: Passing untrusted input to this function allows an attacker to |
| 577 | // control auxiliary properties. This can allow unexpected influence over the |
| 578 | // application if the certificate is used in a context that reads auxiliary |
| 579 | // properties. This includes PKCS#12 serialization, trusted certificates in |
| 580 | // |X509_STORE|, and callers of |X509_alias_get0| or |X509_keyid_get0|. |
| 581 | // |
| 582 | // Unlike similarly-named functions, this function does not parse a single |
| 583 | // ASN.1 element. Trying to parse data directly embedded in a larger ASN.1 |
| 584 | // structure will not behave correctly. |
| 585 | OPENSSL_EXPORT X509 *d2i_X509_AUX(X509 **x509, const uint8_t **inp, |
| 586 | long length); |
| 587 |
| 588 | // X509_alias_set1 sets |x509|'s alias to |len| bytes from |name|. If |name| is |
| 589 | // NULL, the alias is cleared instead. Aliases are not part of the certificate |
| 590 | // itself and will not be serialized by |i2d_X509|. If |x509| is serialized in |
| 591 | // a PKCS#12 structure, the friendlyName attribute (RFC 2985) will contain this |
| 592 | // alias. |
| 593 | OPENSSL_EXPORT int X509_alias_set1(X509 *x509, const uint8_t *name, |
| 594 | ossl_ssize_t len); |
| 595 |
| 596 | // X509_keyid_set1 sets |x509|'s key ID to |len| bytes from |id|. If |id| is |
| 597 | // NULL, the key ID is cleared instead. Key IDs are not part of the certificate |
| 598 | // itself and will not be serialized by |i2d_X509|. |
| 599 | OPENSSL_EXPORT int X509_keyid_set1(X509 *x509, const uint8_t *id, |
| 600 | ossl_ssize_t len); |
| 601 |
| 602 | // X509_alias_get0 looks up |x509|'s alias. If found, it sets |*out_len| to the |
| 603 | // alias's length and returns a pointer to a buffer containing the contents. If |
| 604 | // not found, it outputs the empty string by returning NULL and setting |
| 605 | // |*out_len| to zero. |
| 606 | // |
| 607 | // If |x509| was parsed from a PKCS#12 structure (see |
| 608 | // |PKCS12_get_key_and_certs|), the alias will reflect the friendlyName |
| 609 | // attribute (RFC 2985). |
| 610 | // |
| 611 | // WARNING: In OpenSSL, this function did not set |*out_len| when the alias was |
| 612 | // missing. Callers that target both OpenSSL and BoringSSL should set the value |
| 613 | // to zero before calling this function. |
| 614 | OPENSSL_EXPORT const uint8_t *X509_alias_get0(const X509 *x509, int *out_len); |
| 615 |
| 616 | // X509_keyid_get0 looks up |x509|'s key ID. If found, it sets |*out_len| to the |
| 617 | // key ID's length and returns a pointer to a buffer containing the contents. If |
| 618 | // not found, it outputs the empty string by returning NULL and setting |
| 619 | // |*out_len| to zero. |
| 620 | // |
| 621 | // WARNING: In OpenSSL, this function did not set |*out_len| when the alias was |
| 622 | // missing. Callers that target both OpenSSL and BoringSSL should set the value |
| 623 | // to zero before calling this function. |
| 624 | OPENSSL_EXPORT const uint8_t *X509_keyid_get0(const X509 *x509, int *out_len); |
| 625 |
| 626 | // X509_add1_trust_object configures |x509| as a valid trust anchor for |obj|. |
| 627 | // It returns one on success and zero on error. |obj| should be a certificate |
| 628 | // usage OID associated with an |X509_TRUST_*| constant. |
| 629 | // |
| 630 | // See |X509_VERIFY_PARAM_set_trust| for details on how this value is evaluated. |
| 631 | // Note this only takes effect if |x509| was configured as a trusted certificate |
| 632 | // via |X509_STORE|. |
| 633 | OPENSSL_EXPORT int X509_add1_trust_object(X509 *x509, const ASN1_OBJECT *obj); |
| 634 |
| 635 | // X509_add1_reject_object configures |x509| as distrusted for |obj|. It returns |
| 636 | // one on success and zero on error. |obj| should be a certificate usage OID |
| 637 | // associated with an |X509_TRUST_*| constant. |
| 638 | // |
| 639 | // See |X509_VERIFY_PARAM_set_trust| for details on how this value is evaluated. |
| 640 | // Note this only takes effect if |x509| was configured as a trusted certificate |
| 641 | // via |X509_STORE|. |
| 642 | OPENSSL_EXPORT int X509_add1_reject_object(X509 *x509, const ASN1_OBJECT *obj); |
| 643 |
| 644 | // X509_trust_clear clears the list of OIDs for which |x509| is trusted. See |
| 645 | // also |X509_add1_trust_object|. |
| 646 | OPENSSL_EXPORT void X509_trust_clear(X509 *x509); |
| 647 |
| 648 | // X509_reject_clear clears the list of OIDs for which |x509| is distrusted. See |
| 649 | // also |X509_add1_reject_object|. |
| 650 | OPENSSL_EXPORT void X509_reject_clear(X509 *x509); |
| 651 |
| 652 |
| 653 | // Certificate revocation lists. |
| 654 | // |
| 655 | // An |X509_CRL| object represents an X.509 certificate revocation list (CRL), |
| 656 | // defined in RFC 5280. A CRL is a signed list of certificates, the |
| 657 | // revokedCertificates field, which are no longer considered valid. Each entry |
| 658 | // of this list is represented with an |X509_REVOKED| object, documented in the |
| 659 | // "CRL entries" section below. |
| 660 | // |
| 661 | // Although an |X509_CRL| is a mutable object, mutating an |X509_CRL| or its |
| 662 | // |X509_REVOKED|s can give incorrect results. Callers typically obtain |
| 663 | // |X509_CRL|s by parsing some input with |d2i_X509_CRL|, etc. Such objects |
| 664 | // carry information such as the serialized TBSCertList and decoded extensions, |
| 665 | // which will become inconsistent when mutated. |
| 666 | // |
| 667 | // Instead, mutation functions should only be used when issuing new CRLs, as |
| 668 | // described in a later section. |
| 669 |
| 670 | DEFINE_STACK_OF(X509_CRL) |
| 671 | DEFINE_STACK_OF(X509_REVOKED) |
| 672 |
| 673 | // X509_CRL_up_ref adds one to the reference count of |crl| and returns one. |
| 674 | OPENSSL_EXPORT int X509_CRL_up_ref(X509_CRL *crl); |
| 675 |
| 676 | // X509_CRL_dup returns a newly-allocated copy of |crl|, or NULL on error. This |
| 677 | // function works by serializing the structure, so if |crl| is incomplete, it |
| 678 | // may fail. |
| 679 | // |
| 680 | // TODO(https://crbug.com/boringssl/407): This function should be const and |
| 681 | // thread-safe but is currently neither in some cases, notably if |crl| was |
| 682 | // mutated. |
| 683 | OPENSSL_EXPORT X509_CRL *X509_CRL_dup(X509_CRL *crl); |
| 684 |
| 685 | // X509_CRL_free decrements |crl|'s reference count and, if zero, releases |
| 686 | // memory associated with |crl|. |
| 687 | OPENSSL_EXPORT void X509_CRL_free(X509_CRL *crl); |
| 688 |
| 689 | // d2i_X509_CRL parses up to |len| bytes from |*inp| as a DER-encoded X.509 |
| 690 | // CertificateList (RFC 5280), as described in |d2i_SAMPLE|. |
| 691 | OPENSSL_EXPORT X509_CRL *d2i_X509_CRL(X509_CRL **out, const uint8_t **inp, |
| 692 | long len); |
| 693 |
| 694 | // i2d_X509_CRL marshals |crl| as a X.509 CertificateList (RFC 5280), as |
| 695 | // described in |i2d_SAMPLE|. |
| 696 | // |
| 697 | // TODO(https://crbug.com/boringssl/407): This function should be const and |
| 698 | // thread-safe but is currently neither in some cases, notably if |crl| was |
| 699 | // mutated. |
| 700 | OPENSSL_EXPORT int i2d_X509_CRL(X509_CRL *crl, uint8_t **outp); |
| 701 |
| 702 | // X509_CRL_match compares |a| and |b| and returns zero if they are equal, a |
| 703 | // negative number if |b| sorts after |a| and a negative number if |a| sorts |
| 704 | // after |b|. The sort order implemented by this function is arbitrary and does |
| 705 | // not reflect properties of the CRL such as expiry. Applications should not |
| 706 | // rely on the order itself. |
| 707 | // |
| 708 | // TODO(https://crbug.com/boringssl/355): This function works by comparing a |
| 709 | // cached hash of the encoded CRL. This cached hash is computed when the CRL is |
| 710 | // parsed, but not when mutating or issuing CRLs. This function should only be |
| 711 | // used with |X509_CRL| objects that were parsed from bytes and never mutated. |
| 712 | OPENSSL_EXPORT int X509_CRL_match(const X509_CRL *a, const X509_CRL *b); |
| 713 |
| 714 | #define X509_CRL_VERSION_1 0 |
| 715 | #define X509_CRL_VERSION_2 1 |
| 716 |
| 717 | // X509_CRL_get_version returns the numerical value of |crl|'s version, which |
| 718 | // will be one of the |X509_CRL_VERSION_*| constants. |
| 719 | OPENSSL_EXPORT long X509_CRL_get_version(const X509_CRL *crl); |
| 720 |
| 721 | // X509_CRL_get0_lastUpdate returns |crl|'s thisUpdate time. The OpenSSL API |
| 722 | // refers to this field as lastUpdate. |
| 723 | OPENSSL_EXPORT const ASN1_TIME *X509_CRL_get0_lastUpdate(const X509_CRL *crl); |
| 724 |
| 725 | // X509_CRL_get0_nextUpdate returns |crl|'s nextUpdate time, or NULL if |crl| |
| 726 | // has none. |
| 727 | OPENSSL_EXPORT const ASN1_TIME *X509_CRL_get0_nextUpdate(const X509_CRL *crl); |
| 728 |
| 729 | // X509_CRL_get_issuer returns |crl|'s issuer name. Note this function is not |
| 730 | // const-correct for legacy reasons. |
| 731 | OPENSSL_EXPORT X509_NAME *X509_CRL_get_issuer(const X509_CRL *crl); |
| 732 |
| 733 | // X509_CRL_get0_by_serial finds the entry in |crl| whose serial number is |
| 734 | // |serial|. If found, it sets |*out| to the entry and returns one. If not |
| 735 | // found, it returns zero. |
| 736 | // |
| 737 | // On success, |*out| continues to be owned by |crl|. It is an error to free or |
| 738 | // otherwise modify |*out|. |
| 739 | // |
| 740 | // TODO(crbug.com/boringssl/600): Ideally |crl| would be const. It is broadly |
| 741 | // thread-safe, but changes the order of entries in |crl|. It cannot be called |
| 742 | // concurrently with |i2d_X509_CRL|. |
| 743 | OPENSSL_EXPORT int X509_CRL_get0_by_serial(X509_CRL *crl, X509_REVOKED **out, |
| 744 | const ASN1_INTEGER *serial); |
| 745 |
| 746 | // X509_CRL_get0_by_cert behaves like |X509_CRL_get0_by_serial|, except it looks |
| 747 | // for the entry that matches |x509|. |
| 748 | OPENSSL_EXPORT int X509_CRL_get0_by_cert(X509_CRL *crl, X509_REVOKED **out, |
| 749 | X509 *x509); |
| 750 |
| 751 | // X509_CRL_get_REVOKED returns the list of revoked certificates in |crl|, or |
| 752 | // NULL if |crl| omits it. |
| 753 | // |
| 754 | // TOOD(davidben): This function was originally a macro, without clear const |
| 755 | // semantics. It should take a const input and give const output, but the latter |
| 756 | // would break existing callers. For now, we match upstream. |
| 757 | OPENSSL_EXPORT STACK_OF(X509_REVOKED) *X509_CRL_get_REVOKED(X509_CRL *crl); |
| 758 |
| 759 | // X509_CRL_get0_extensions returns |crl|'s extension list, or NULL if |crl| |
| 760 | // omits it. A CRL can have extensions on individual entries, which is |
| 761 | // |X509_REVOKED_get0_extensions|, or on the overall CRL, which is this |
| 762 | // function. |
| 763 | OPENSSL_EXPORT const STACK_OF(X509_EXTENSION) *X509_CRL_get0_extensions( |
| 764 | const X509_CRL *crl); |
| 765 |
| 766 | // X509_CRL_get_ext_count returns the number of extensions in |x|. |
| 767 | OPENSSL_EXPORT int X509_CRL_get_ext_count(const X509_CRL *x); |
| 768 |
| 769 | // X509_CRL_get_ext_by_NID behaves like |X509v3_get_ext_by_NID| but searches for |
| 770 | // extensions in |x|. |
| 771 | OPENSSL_EXPORT int X509_CRL_get_ext_by_NID(const X509_CRL *x, int nid, |
| 772 | int lastpos); |
| 773 |
| 774 | // X509_CRL_get_ext_by_OBJ behaves like |X509v3_get_ext_by_OBJ| but searches for |
| 775 | // extensions in |x|. |
| 776 | OPENSSL_EXPORT int X509_CRL_get_ext_by_OBJ(const X509_CRL *x, |
| 777 | const ASN1_OBJECT *obj, int lastpos); |
| 778 |
| 779 | // X509_CRL_get_ext_by_critical behaves like |X509v3_get_ext_by_critical| but |
| 780 | // searches for extensions in |x|. |
| 781 | OPENSSL_EXPORT int X509_CRL_get_ext_by_critical(const X509_CRL *x, int crit, |
| 782 | int lastpos); |
| 783 |
| 784 | // X509_CRL_get_ext returns the extension in |x| at index |loc|, or NULL if |
| 785 | // |loc| is out of bounds. This function returns a non-const pointer for OpenSSL |
| 786 | // compatibility, but callers should not mutate the result. |
| 787 | OPENSSL_EXPORT X509_EXTENSION *X509_CRL_get_ext(const X509_CRL *x, int loc); |
| 788 |
| 789 | // X509_CRL_get_ext_d2i behaves like |X509V3_get_d2i| but looks for the |
| 790 | // extension in |crl|'s extension list. |
| 791 | // |
| 792 | // WARNING: This function is difficult to use correctly. See the documentation |
| 793 | // for |X509V3_get_d2i| for details. |
| 794 | OPENSSL_EXPORT void *X509_CRL_get_ext_d2i(const X509_CRL *crl, int nid, |
| 795 | int *out_critical, int *out_idx); |
| 796 |
| 797 | // X509_CRL_get0_signature sets |*out_sig| and |*out_alg| to the signature and |
| 798 | // signature algorithm of |crl|, respectively. Either output pointer may be NULL |
| 799 | // to ignore the value. |
| 800 | // |
| 801 | // This function outputs the outer signature algorithm, not the one in the |
| 802 | // TBSCertList. CRLs with mismatched signature algorithms will successfully |
| 803 | // parse, but they will be rejected when verifying. |
| 804 | OPENSSL_EXPORT void X509_CRL_get0_signature(const X509_CRL *crl, |
| 805 | const ASN1_BIT_STRING **out_sig, |
| 806 | const X509_ALGOR **out_alg); |
| 807 |
| 808 | // X509_CRL_get_signature_nid returns the NID corresponding to |crl|'s signature |
| 809 | // algorithm, or |NID_undef| if the signature algorithm does not correspond to |
| 810 | // a known NID. |
| 811 | OPENSSL_EXPORT int X509_CRL_get_signature_nid(const X509_CRL *crl); |
| 812 |
| 813 | // i2d_X509_CRL_tbs serializes the TBSCertList portion of |crl|, as described in |
| 814 | // |i2d_SAMPLE|. |
| 815 | // |
| 816 | // This function preserves the original encoding of the TBSCertList and may not |
| 817 | // reflect modifications made to |crl|. It may be used to manually verify the |
| 818 | // signature of an existing CRL. To generate CRLs, use |i2d_re_X509_CRL_tbs| |
| 819 | // instead. |
| 820 | OPENSSL_EXPORT int i2d_X509_CRL_tbs(X509_CRL *crl, unsigned char **outp); |
| 821 |
| 822 | // X509_CRL_verify checks that |crl| has a valid signature by |pkey|. It returns |
| 823 | // one if the signature is valid and zero otherwise. |
| 824 | OPENSSL_EXPORT int X509_CRL_verify(X509_CRL *crl, EVP_PKEY *pkey); |
| 825 |
| 826 |
| 827 | // Issuing certificate revocation lists. |
| 828 | // |
| 829 | // An |X509_CRL| object may also represent an incomplete CRL. Callers may |
| 830 | // construct empty |X509_CRL| objects, fill in fields individually, and finally |
| 831 | // sign the result. The following functions may be used for this purpose. |
| 832 |
| 833 | // X509_CRL_new returns a newly-allocated, empty |X509_CRL| object, or NULL on |
| 834 | // error. This object may be filled in and then signed to construct a CRL. |
| 835 | OPENSSL_EXPORT X509_CRL *X509_CRL_new(void); |
| 836 |
| 837 | // X509_CRL_set_version sets |crl|'s version to |version|, which should be one |
| 838 | // of the |X509_CRL_VERSION_*| constants. It returns one on success and zero on |
| 839 | // error. |
| 840 | // |
| 841 | // If unsure, use |X509_CRL_VERSION_2|. Note that, unlike certificates, CRL |
| 842 | // versions are only defined up to v2. Callers should not use |X509_VERSION_3|. |
| 843 | OPENSSL_EXPORT int X509_CRL_set_version(X509_CRL *crl, long version); |
| 844 |
| 845 | // X509_CRL_set_issuer_name sets |crl|'s issuer to a copy of |name|. It returns |
| 846 | // one on success and zero on error. |
| 847 | OPENSSL_EXPORT int X509_CRL_set_issuer_name(X509_CRL *crl, X509_NAME *name); |
| 848 |
| 849 | // X509_CRL_set1_lastUpdate sets |crl|'s thisUpdate time to |tm|. It returns one |
| 850 | // on success and zero on error. The OpenSSL API refers to this field as |
| 851 | // lastUpdate. |
| 852 | OPENSSL_EXPORT int X509_CRL_set1_lastUpdate(X509_CRL *crl, const ASN1_TIME *tm); |
| 853 |
| 854 | // X509_CRL_set1_nextUpdate sets |crl|'s nextUpdate time to |tm|. It returns one |
| 855 | // on success and zero on error. |
| 856 | OPENSSL_EXPORT int X509_CRL_set1_nextUpdate(X509_CRL *crl, const ASN1_TIME *tm); |
| 857 |
| 858 | // X509_CRL_add0_revoked adds |rev| to |crl|. On success, it takes ownership of |
| 859 | // |rev| and returns one. On error, it returns zero. If this function fails, the |
| 860 | // caller retains ownership of |rev| and must release it when done. |
| 861 | OPENSSL_EXPORT int X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev); |
| 862 |
| 863 | // X509_CRL_sort sorts the entries in |crl| by serial number. It returns one on |
| 864 | // success and zero on error. |
| 865 | OPENSSL_EXPORT int X509_CRL_sort(X509_CRL *crl); |
| 866 |
| 867 | // X509_CRL_delete_ext removes the extension in |x| at index |loc| and returns |
| 868 | // the removed extension, or NULL if |loc| was out of bounds. If non-NULL, the |
| 869 | // caller must release the result with |X509_EXTENSION_free|. |
| 870 | OPENSSL_EXPORT X509_EXTENSION *X509_CRL_delete_ext(X509_CRL *x, int loc); |
| 871 |
| 872 | // X509_CRL_add_ext adds a copy of |ex| to |x|. It returns one on success and |
| 873 | // zero on failure. The caller retains ownership of |ex| and can release it |
| 874 | // independently of |x|. |
| 875 | // |
| 876 | // The new extension is inserted at index |loc|, shifting extensions to the |
| 877 | // right. If |loc| is -1 or out of bounds, the new extension is appended to the |
| 878 | // list. |
| 879 | OPENSSL_EXPORT int X509_CRL_add_ext(X509_CRL *x, const X509_EXTENSION *ex, |
| 880 | int loc); |
| 881 |
| 882 | // X509_CRL_add1_ext_i2d behaves like |X509V3_add1_i2d| but adds the extension |
| 883 | // to |x|'s extension list. |
| 884 | // |
| 885 | // WARNING: This function may return zero or -1 on error. The caller must also |
| 886 | // ensure |value|'s type matches |nid|. See the documentation for |
| 887 | // |X509V3_add1_i2d| for details. |
| 888 | OPENSSL_EXPORT int X509_CRL_add1_ext_i2d(X509_CRL *x, int nid, void *value, |
| 889 | int crit, unsigned long flags); |
| 890 |
| 891 | // X509_CRL_sign signs |crl| with |pkey| and replaces the signature algorithm |
| 892 | // and signature fields. It returns the length of the signature on success and |
| 893 | // zero on error. This function uses digest algorithm |md|, or |pkey|'s default |
| 894 | // if NULL. Other signing parameters use |pkey|'s defaults. To customize them, |
| 895 | // use |X509_CRL_sign_ctx|. |
| 896 | OPENSSL_EXPORT int X509_CRL_sign(X509_CRL *crl, EVP_PKEY *pkey, |
| 897 | const EVP_MD *md); |
| 898 |
| 899 | // X509_CRL_sign_ctx signs |crl| with |ctx| and replaces the signature algorithm |
| 900 | // and signature fields. It returns the length of the signature on success and |
| 901 | // zero on error. The signature algorithm and parameters come from |ctx|, which |
| 902 | // must have been initialized with |EVP_DigestSignInit|. The caller should |
| 903 | // configure the corresponding |EVP_PKEY_CTX| before calling this function. |
| 904 | // |
| 905 | // On success or failure, this function mutates |ctx| and resets it to the empty |
| 906 | // state. Caller should not rely on its contents after the function returns. |
| 907 | OPENSSL_EXPORT int X509_CRL_sign_ctx(X509_CRL *crl, EVP_MD_CTX *ctx); |
| 908 |
| 909 | // i2d_re_X509_CRL_tbs serializes the TBSCertList portion of |crl|, as described |
| 910 | // in |i2d_SAMPLE|. |
| 911 | // |
| 912 | // This function re-encodes the TBSCertList and may not reflect |crl|'s original |
| 913 | // encoding. It may be used to manually generate a signature for a new CRL. To |
| 914 | // verify CRLs, use |i2d_X509_CRL_tbs| instead. |
| 915 | OPENSSL_EXPORT int i2d_re_X509_CRL_tbs(X509_CRL *crl, unsigned char **outp); |
| 916 |
| 917 | // X509_CRL_set1_signature_algo sets |crl|'s signature algorithm to |algo| and |
| 918 | // returns one on success or zero on error. It updates both the signature field |
| 919 | // of the TBSCertList structure, and the signatureAlgorithm field of the CRL. |
| 920 | OPENSSL_EXPORT int X509_CRL_set1_signature_algo(X509_CRL *crl, |
| 921 | const X509_ALGOR *algo); |
| 922 |
| 923 | // X509_CRL_set1_signature_value sets |crl|'s signature to a copy of the |
| 924 | // |sig_len| bytes pointed by |sig|. It returns one on success and zero on |
| 925 | // error. |
| 926 | // |
| 927 | // Due to a specification error, X.509 CRLs store signatures in ASN.1 BIT |
| 928 | // STRINGs, but signature algorithms return byte strings rather than bit |
| 929 | // strings. This function creates a BIT STRING containing a whole number of |
| 930 | // bytes, with the bit order matching the DER encoding. This matches the |
| 931 | // encoding used by all X.509 signature algorithms. |
| 932 | OPENSSL_EXPORT int X509_CRL_set1_signature_value(X509_CRL *crl, |
| 933 | const uint8_t *sig, |
| 934 | size_t sig_len); |
| 935 |
| 936 |
| 937 | // CRL entries. |
| 938 | // |
| 939 | // Each entry of a CRL is represented as an |X509_REVOKED| object, which |
| 940 | // describes a revoked certificate by serial number. |
| 941 | // |
| 942 | // When an |X509_REVOKED| is obtained from an |X509_CRL| object, it is an error |
| 943 | // to mutate the object. Doing so may break |X509_CRL|'s and cause the library |
| 944 | // to behave incorrectly. |
| 945 |
| 946 | // X509_REVOKED_new returns a newly-allocated, empty |X509_REVOKED| object, or |
| 947 | // NULL on allocation error. |
| 948 | OPENSSL_EXPORT X509_REVOKED *X509_REVOKED_new(void); |
| 949 |
| 950 | // X509_REVOKED_free releases memory associated with |rev|. |
| 951 | OPENSSL_EXPORT void X509_REVOKED_free(X509_REVOKED *rev); |
| 952 |
| 953 | // d2i_X509_REVOKED parses up to |len| bytes from |*inp| as a DER-encoded X.509 |
| 954 | // CRL entry, as described in |d2i_SAMPLE|. |
| 955 | OPENSSL_EXPORT X509_REVOKED *d2i_X509_REVOKED(X509_REVOKED **out, |
| 956 | const uint8_t **inp, long len); |
| 957 |
| 958 | // i2d_X509_REVOKED marshals |alg| as a DER-encoded X.509 CRL entry, as |
| 959 | // described in |i2d_SAMPLE|. |
| 960 | OPENSSL_EXPORT int i2d_X509_REVOKED(const X509_REVOKED *alg, uint8_t **outp); |
| 961 |
| 962 | // X509_REVOKED_dup returns a newly-allocated copy of |rev|, or NULL on error. |
| 963 | // This function works by serializing the structure, so if |rev| is incomplete, |
| 964 | // it may fail. |
| 965 | OPENSSL_EXPORT X509_REVOKED *X509_REVOKED_dup(const X509_REVOKED *rev); |
| 966 |
| 967 | // X509_REVOKED_get0_serialNumber returns the serial number of the certificate |
| 968 | // revoked by |revoked|. |
| 969 | OPENSSL_EXPORT const ASN1_INTEGER *X509_REVOKED_get0_serialNumber( |
| 970 | const X509_REVOKED *revoked); |
| 971 |
| 972 | // X509_REVOKED_set_serialNumber sets |revoked|'s serial number to |serial|. It |
| 973 | // returns one on success or zero on error. |
| 974 | OPENSSL_EXPORT int X509_REVOKED_set_serialNumber(X509_REVOKED *revoked, |
| 975 | const ASN1_INTEGER *serial); |
| 976 |
| 977 | // X509_REVOKED_get0_revocationDate returns the revocation time of the |
| 978 | // certificate revoked by |revoked|. |
| 979 | OPENSSL_EXPORT const ASN1_TIME *X509_REVOKED_get0_revocationDate( |
| 980 | const X509_REVOKED *revoked); |
| 981 |
| 982 | // X509_REVOKED_set_revocationDate sets |revoked|'s revocation time to |tm|. It |
| 983 | // returns one on success or zero on error. |
| 984 | OPENSSL_EXPORT int X509_REVOKED_set_revocationDate(X509_REVOKED *revoked, |
| 985 | const ASN1_TIME *tm); |
| 986 |
| 987 | // X509_REVOKED_get0_extensions returns |r|'s extensions list, or NULL if |r| |
| 988 | // omits it. A CRL can have extensions on individual entries, which is this |
| 989 | // function, or on the overall CRL, which is |X509_CRL_get0_extensions|. |
| 990 | OPENSSL_EXPORT const STACK_OF(X509_EXTENSION) *X509_REVOKED_get0_extensions( |
| 991 | const X509_REVOKED *r); |
| 992 |
| 993 | // X509_REVOKED_get_ext_count returns the number of extensions in |x|. |
| 994 | OPENSSL_EXPORT int X509_REVOKED_get_ext_count(const X509_REVOKED *x); |
| 995 |
| 996 | // X509_REVOKED_get_ext_by_NID behaves like |X509v3_get_ext_by_NID| but searches |
| 997 | // for extensions in |x|. |
| 998 | OPENSSL_EXPORT int X509_REVOKED_get_ext_by_NID(const X509_REVOKED *x, int nid, |
| 999 | int lastpos); |
| 1000 |
| 1001 | // X509_REVOKED_get_ext_by_OBJ behaves like |X509v3_get_ext_by_OBJ| but searches |
| 1002 | // for extensions in |x|. |
| 1003 | OPENSSL_EXPORT int X509_REVOKED_get_ext_by_OBJ(const X509_REVOKED *x, |
| 1004 | const ASN1_OBJECT *obj, |
| 1005 | int lastpos); |
| 1006 |
| 1007 | // X509_REVOKED_get_ext_by_critical behaves like |X509v3_get_ext_by_critical| |
| 1008 | // but searches for extensions in |x|. |
| 1009 | OPENSSL_EXPORT int X509_REVOKED_get_ext_by_critical(const X509_REVOKED *x, |
| 1010 | int crit, int lastpos); |
| 1011 |
| 1012 | // X509_REVOKED_get_ext returns the extension in |x| at index |loc|, or NULL if |
| 1013 | // |loc| is out of bounds. This function returns a non-const pointer for OpenSSL |
| 1014 | // compatibility, but callers should not mutate the result. |
| 1015 | OPENSSL_EXPORT X509_EXTENSION *X509_REVOKED_get_ext(const X509_REVOKED *x, |
| 1016 | int loc); |
| 1017 |
| 1018 | // X509_REVOKED_delete_ext removes the extension in |x| at index |loc| and |
| 1019 | // returns the removed extension, or NULL if |loc| was out of bounds. If |
| 1020 | // non-NULL, the caller must release the result with |X509_EXTENSION_free|. |
| 1021 | OPENSSL_EXPORT X509_EXTENSION *X509_REVOKED_delete_ext(X509_REVOKED *x, |
| 1022 | int loc); |
| 1023 |
| 1024 | // X509_REVOKED_add_ext adds a copy of |ex| to |x|. It returns one on success |
| 1025 | // and zero on failure. The caller retains ownership of |ex| and can release it |
| 1026 | // independently of |x|. |
| 1027 | // |
| 1028 | // The new extension is inserted at index |loc|, shifting extensions to the |
| 1029 | // right. If |loc| is -1 or out of bounds, the new extension is appended to the |
| 1030 | // list. |
| 1031 | OPENSSL_EXPORT int X509_REVOKED_add_ext(X509_REVOKED *x, |
| 1032 | const X509_EXTENSION *ex, int loc); |
| 1033 |
| 1034 | // X509_REVOKED_get_ext_d2i behaves like |X509V3_get_d2i| but looks for the |
| 1035 | // extension in |revoked|'s extension list. |
| 1036 | // |
| 1037 | // WARNING: This function is difficult to use correctly. See the documentation |
| 1038 | // for |X509V3_get_d2i| for details. |
| 1039 | OPENSSL_EXPORT void *X509_REVOKED_get_ext_d2i(const X509_REVOKED *revoked, |
| 1040 | int nid, int *out_critical, |
| 1041 | int *out_idx); |
| 1042 |
| 1043 | // X509_REVOKED_add1_ext_i2d behaves like |X509V3_add1_i2d| but adds the |
| 1044 | // extension to |x|'s extension list. |
| 1045 | // |
| 1046 | // WARNING: This function may return zero or -1 on error. The caller must also |
| 1047 | // ensure |value|'s type matches |nid|. See the documentation for |
| 1048 | // |X509V3_add1_i2d| for details. |
| 1049 | OPENSSL_EXPORT int X509_REVOKED_add1_ext_i2d(X509_REVOKED *x, int nid, |
| 1050 | void *value, int crit, |
| 1051 | unsigned long flags); |
| 1052 |
| 1053 |
| 1054 | // Certificate requests. |
| 1055 | // |
| 1056 | // An |X509_REQ| represents a PKCS #10 certificate request (RFC 2986). These are |
| 1057 | // also referred to as certificate signing requests or CSRs. CSRs are a common |
| 1058 | // format used to request a certificate from a CA. |
| 1059 | // |
| 1060 | // Although an |X509_REQ| is a mutable object, mutating an |X509_REQ| can give |
| 1061 | // incorrect results. Callers typically obtain |X509_REQ|s by parsing some input |
| 1062 | // with |d2i_X509_REQ|, etc. Such objects carry information such as the |
| 1063 | // serialized CertificationRequestInfo, which will become inconsistent when |
| 1064 | // mutated. |
| 1065 | // |
| 1066 | // Instead, mutation functions should only be used when issuing new CRLs, as |
| 1067 | // described in a later section. |
| 1068 |
| 1069 | // X509_REQ_dup returns a newly-allocated copy of |req|, or NULL on error. This |
| 1070 | // function works by serializing the structure, so if |req| is incomplete, it |
| 1071 | // may fail. |
| 1072 | // |
| 1073 | // TODO(https://crbug.com/boringssl/407): This function should be const and |
| 1074 | // thread-safe but is currently neither in some cases, notably if |req| was |
| 1075 | // mutated. |
| 1076 | OPENSSL_EXPORT X509_REQ *X509_REQ_dup(X509_REQ *req); |
| 1077 |
| 1078 | // X509_REQ_free releases memory associated with |req|. |
| 1079 | OPENSSL_EXPORT void X509_REQ_free(X509_REQ *req); |
| 1080 |
| 1081 | // d2i_X509_REQ parses up to |len| bytes from |*inp| as a DER-encoded |
| 1082 | // CertificateRequest (RFC 2986), as described in |d2i_SAMPLE|. |
| 1083 | OPENSSL_EXPORT X509_REQ *d2i_X509_REQ(X509_REQ **out, const uint8_t **inp, |
| 1084 | long len); |
| 1085 |
| 1086 | // i2d_X509_REQ marshals |req| as a CertificateRequest (RFC 2986), as described |
| 1087 | // in |i2d_SAMPLE|. |
| 1088 | // |
| 1089 | // TODO(https://crbug.com/boringssl/407): This function should be const and |
| 1090 | // thread-safe but is currently neither in some cases, notably if |req| was |
| 1091 | // mutated. |
| 1092 | OPENSSL_EXPORT int i2d_X509_REQ(X509_REQ *req, uint8_t **outp); |
| 1093 |
| 1094 | // X509_REQ_VERSION_1 is the version constant for |X509_REQ| objects. No other |
| 1095 | // versions are defined. |
| 1096 | #define X509_REQ_VERSION_1 0 |
| 1097 |
| 1098 | // X509_REQ_get_version returns the numerical value of |req|'s version. This |
| 1099 | // will always be |X509_REQ_VERSION_1| for valid CSRs. For compatibility, |
| 1100 | // |d2i_X509_REQ| also accepts some invalid version numbers, in which case this |
| 1101 | // function may return other values. |
| 1102 | OPENSSL_EXPORT long X509_REQ_get_version(const X509_REQ *req); |
| 1103 |
| 1104 | // X509_REQ_get_subject_name returns |req|'s subject name. Note this function is |
| 1105 | // not const-correct for legacy reasons. |
| 1106 | OPENSSL_EXPORT X509_NAME *X509_REQ_get_subject_name(const X509_REQ *req); |
| 1107 |
| 1108 | // X509_REQ_get0_pubkey returns |req|'s public key as an |EVP_PKEY|, or NULL if |
| 1109 | // the public key was unsupported or could not be decoded. The |EVP_PKEY| is |
| 1110 | // cached in |req|, so callers must not mutate the result. |
| 1111 | OPENSSL_EXPORT EVP_PKEY *X509_REQ_get0_pubkey(const X509_REQ *req); |
| 1112 |
| 1113 | // X509_REQ_get_pubkey behaves like |X509_REQ_get0_pubkey| but increments the |
| 1114 | // reference count on the |EVP_PKEY|. The caller must release the result with |
| 1115 | // |EVP_PKEY_free| when done. The |EVP_PKEY| is cached in |req|, so callers must |
| 1116 | // not mutate the result. |
| 1117 | OPENSSL_EXPORT EVP_PKEY *X509_REQ_get_pubkey(const X509_REQ *req); |
| 1118 |
| 1119 | // X509_REQ_check_private_key returns one if |req|'s public key matches |pkey| |
| 1120 | // and zero otherwise. |
| 1121 | OPENSSL_EXPORT int X509_REQ_check_private_key(const X509_REQ *req, |
| 1122 | const EVP_PKEY *pkey); |
| 1123 |
| 1124 | // X509_REQ_get_attr_count returns the number of attributes in |req|. |
| 1125 | OPENSSL_EXPORT int X509_REQ_get_attr_count(const X509_REQ *req); |
| 1126 |
| 1127 | // X509_REQ_get_attr returns the attribute at index |loc| in |req|, or NULL if |
| 1128 | // out of bounds. |
| 1129 | OPENSSL_EXPORT X509_ATTRIBUTE *X509_REQ_get_attr(const X509_REQ *req, int loc); |
| 1130 |
| 1131 | // X509_REQ_get_attr_by_NID returns the index of the attribute in |req| of type |
| 1132 | // |nid|, or a negative number if not found. If found, callers can use |
| 1133 | // |X509_REQ_get_attr| to look up the attribute by index. |
| 1134 | // |
| 1135 | // If |lastpos| is non-negative, it begins searching at |lastpos| + 1. Callers |
| 1136 | // can thus loop over all matching attributes by first passing -1 and then |
| 1137 | // passing the previously-returned value until no match is returned. |
| 1138 | OPENSSL_EXPORT int X509_REQ_get_attr_by_NID(const X509_REQ *req, int nid, |
| 1139 | int lastpos); |
| 1140 |
| 1141 | // X509_REQ_get_attr_by_OBJ behaves like |X509_REQ_get_attr_by_NID| but looks |
| 1142 | // for attributes of type |obj|. |
| 1143 | OPENSSL_EXPORT int X509_REQ_get_attr_by_OBJ(const X509_REQ *req, |
| 1144 | const ASN1_OBJECT *obj, |
| 1145 | int lastpos); |
| 1146 |
| 1147 | // X509_REQ_extension_nid returns one if |nid| is a supported CSR attribute type |
| 1148 | // for carrying extensions and zero otherwise. The supported types are |
| 1149 | // |NID_ext_req| (pkcs-9-at-extensionRequest from RFC 2985) and |NID_ms_ext_req| |
| 1150 | // (a Microsoft szOID_CERT_EXTENSIONS variant). |
| 1151 | OPENSSL_EXPORT int X509_REQ_extension_nid(int nid); |
| 1152 |
| 1153 | // X509_REQ_get_extensions decodes the most preferred list of requested |
| 1154 | // extensions in |req| and returns a newly-allocated |STACK_OF(X509_EXTENSION)| |
| 1155 | // containing the result. It returns NULL on error, or if |req| did not request |
| 1156 | // extensions. |
| 1157 | // |
| 1158 | // CSRs do not store extensions directly. Instead there are attribute types |
| 1159 | // which are defined to hold extensions. See |X509_REQ_extension_nid|. This |
| 1160 | // function supports both pkcs-9-at-extensionRequest from RFC 2985 and the |
| 1161 | // Microsoft szOID_CERT_EXTENSIONS variant. If both are present, |
| 1162 | // pkcs-9-at-extensionRequest is preferred. |
| 1163 | OPENSSL_EXPORT STACK_OF(X509_EXTENSION) *X509_REQ_get_extensions( |
| 1164 | const X509_REQ *req); |
| 1165 |
| 1166 | // X509_REQ_get0_signature sets |*out_sig| and |*out_alg| to the signature and |
| 1167 | // signature algorithm of |req|, respectively. Either output pointer may be NULL |
| 1168 | // to ignore the value. |
| 1169 | OPENSSL_EXPORT void X509_REQ_get0_signature(const X509_REQ *req, |
| 1170 | const ASN1_BIT_STRING **out_sig, |
| 1171 | const X509_ALGOR **out_alg); |
| 1172 |
| 1173 | // X509_REQ_get_signature_nid returns the NID corresponding to |req|'s signature |
| 1174 | // algorithm, or |NID_undef| if the signature algorithm does not correspond to |
| 1175 | // a known NID. |
| 1176 | OPENSSL_EXPORT int X509_REQ_get_signature_nid(const X509_REQ *req); |
| 1177 |
| 1178 | // X509_REQ_verify checks that |req| has a valid signature by |pkey|. It returns |
| 1179 | // one if the signature is valid and zero otherwise. |
| 1180 | OPENSSL_EXPORT int X509_REQ_verify(X509_REQ *req, EVP_PKEY *pkey); |
| 1181 |
| 1182 | // X509_REQ_get1_email returns a newly-allocated list of NUL-terminated strings |
| 1183 | // containing all email addresses in |req|'s subject and all rfc822name names |
| 1184 | // in |req|'s subject alternative names. The subject alternative names extension |
| 1185 | // is extracted from the result of |X509_REQ_get_extensions|. Email addresses |
| 1186 | // which contain embedded NUL bytes are skipped. |
| 1187 | // |
| 1188 | // On error, or if there are no such email addresses, it returns NULL. When |
| 1189 | // done, the caller must release the result with |X509_email_free|. |
| 1190 | OPENSSL_EXPORT STACK_OF(OPENSSL_STRING) *X509_REQ_get1_email( |
| 1191 | const X509_REQ *req); |
| 1192 |
| 1193 |
| 1194 | // Issuing certificate requests. |
| 1195 | // |
| 1196 | // An |X509_REQ| object may also represent an incomplete CSR. Callers may |
| 1197 | // construct empty |X509_REQ| objects, fill in fields individually, and finally |
| 1198 | // sign the result. The following functions may be used for this purpose. |
| 1199 |
| 1200 | // X509_REQ_new returns a newly-allocated, empty |X509_REQ| object, or NULL on |
| 1201 | // error. This object may be filled in and then signed to construct a CSR. |
| 1202 | OPENSSL_EXPORT X509_REQ *X509_REQ_new(void); |
| 1203 |
| 1204 | // X509_REQ_set_version sets |req|'s version to |version|, which should be |
| 1205 | // |X509_REQ_VERSION_1|. It returns one on success and zero on error. |
| 1206 | // |
| 1207 | // The only defined CSR version is |X509_REQ_VERSION_1|, so there is no need to |
| 1208 | // call this function. |
| 1209 | OPENSSL_EXPORT int X509_REQ_set_version(X509_REQ *req, long version); |
| 1210 |
| 1211 | // X509_REQ_set_subject_name sets |req|'s subject to a copy of |name|. It |
| 1212 | // returns one on success and zero on error. |
| 1213 | OPENSSL_EXPORT int X509_REQ_set_subject_name(X509_REQ *req, X509_NAME *name); |
| 1214 |
| 1215 | // X509_REQ_set_pubkey sets |req|'s public key to |pkey|. It returns one on |
| 1216 | // success and zero on error. This function does not take ownership of |pkey| |
| 1217 | // and internally copies and updates reference counts as needed. |
| 1218 | OPENSSL_EXPORT int X509_REQ_set_pubkey(X509_REQ *req, EVP_PKEY *pkey); |
| 1219 |
| 1220 | // X509_REQ_delete_attr removes the attribute at index |loc| in |req|. It |
| 1221 | // returns the removed attribute to the caller, or NULL if |loc| was out of |
| 1222 | // bounds. If non-NULL, the caller must release the result with |
| 1223 | // |X509_ATTRIBUTE_free| when done. It is also safe, but not necessary, to call |
| 1224 | // |X509_ATTRIBUTE_free| if the result is NULL. |
| 1225 | OPENSSL_EXPORT X509_ATTRIBUTE *X509_REQ_delete_attr(X509_REQ *req, int loc); |
| 1226 |
| 1227 | // X509_REQ_add1_attr appends a copy of |attr| to |req|'s list of attributes. It |
| 1228 | // returns one on success and zero on error. |
| 1229 | OPENSSL_EXPORT int X509_REQ_add1_attr(X509_REQ *req, |
| 1230 | const X509_ATTRIBUTE *attr); |
| 1231 |
| 1232 | // X509_REQ_add1_attr_by_OBJ appends a new attribute to |req| with type |obj|. |
| 1233 | // It returns one on success and zero on error. The value is determined by |
| 1234 | // |X509_ATTRIBUTE_set1_data|. |
| 1235 | // |
| 1236 | // WARNING: The interpretation of |attrtype|, |data|, and |len| is complex and |
| 1237 | // error-prone. See |X509_ATTRIBUTE_set1_data| for details. |
| 1238 | OPENSSL_EXPORT int X509_REQ_add1_attr_by_OBJ(X509_REQ *req, |
| 1239 | const ASN1_OBJECT *obj, |
| 1240 | int attrtype, |
| 1241 | const unsigned char *data, |
| 1242 | int len); |
| 1243 |
| 1244 | // X509_REQ_add1_attr_by_NID behaves like |X509_REQ_add1_attr_by_OBJ| except the |
| 1245 | // attribute type is determined by |nid|. |
| 1246 | OPENSSL_EXPORT int X509_REQ_add1_attr_by_NID(X509_REQ *req, int nid, |
| 1247 | int attrtype, |
| 1248 | const unsigned char *data, |
| 1249 | int len); |
| 1250 |
| 1251 | // X509_REQ_add1_attr_by_txt behaves like |X509_REQ_add1_attr_by_OBJ| except the |
| 1252 | // attribute type is determined by calling |OBJ_txt2obj| with |attrname|. |
| 1253 | OPENSSL_EXPORT int X509_REQ_add1_attr_by_txt(X509_REQ *req, |
| 1254 | const char *attrname, int attrtype, |
| 1255 | const unsigned char *data, |
| 1256 | int len); |
| 1257 |
| 1258 | // X509_REQ_add_extensions_nid adds an attribute to |req| of type |nid|, to |
| 1259 | // request the certificate extensions in |exts|. It returns one on success and |
| 1260 | // zero on error. |nid| should be |NID_ext_req| or |NID_ms_ext_req|. |
| 1261 | OPENSSL_EXPORT int X509_REQ_add_extensions_nid( |
| 1262 | X509_REQ *req, const STACK_OF(X509_EXTENSION) *exts, int nid); |
| 1263 |
| 1264 | // X509_REQ_add_extensions behaves like |X509_REQ_add_extensions_nid|, using the |
| 1265 | // standard |NID_ext_req| for the attribute type. |
| 1266 | OPENSSL_EXPORT int X509_REQ_add_extensions( |
| 1267 | X509_REQ *req, const STACK_OF(X509_EXTENSION) *exts); |
| 1268 |
| 1269 | // X509_REQ_sign signs |req| with |pkey| and replaces the signature algorithm |
| 1270 | // and signature fields. It returns the length of the signature on success and |
| 1271 | // zero on error. This function uses digest algorithm |md|, or |pkey|'s default |
| 1272 | // if NULL. Other signing parameters use |pkey|'s defaults. To customize them, |
| 1273 | // use |X509_REQ_sign_ctx|. |
| 1274 | OPENSSL_EXPORT int X509_REQ_sign(X509_REQ *req, EVP_PKEY *pkey, |
| 1275 | const EVP_MD *md); |
| 1276 |
| 1277 | // X509_REQ_sign_ctx signs |req| with |ctx| and replaces the signature algorithm |
| 1278 | // and signature fields. It returns the length of the signature on success and |
| 1279 | // zero on error. The signature algorithm and parameters come from |ctx|, which |
| 1280 | // must have been initialized with |EVP_DigestSignInit|. The caller should |
| 1281 | // configure the corresponding |EVP_PKEY_CTX| before calling this function. |
| 1282 | // |
| 1283 | // On success or failure, this function mutates |ctx| and resets it to the empty |
| 1284 | // state. Caller should not rely on its contents after the function returns. |
| 1285 | OPENSSL_EXPORT int X509_REQ_sign_ctx(X509_REQ *req, EVP_MD_CTX *ctx); |
| 1286 |
| 1287 | // i2d_re_X509_REQ_tbs serializes the CertificationRequestInfo (see RFC 2986) |
| 1288 | // portion of |req|, as described in |i2d_SAMPLE|. |
| 1289 | // |
| 1290 | // This function re-encodes the CertificationRequestInfo and may not reflect |
| 1291 | // |req|'s original encoding. It may be used to manually generate a signature |
| 1292 | // for a new certificate request. |
| 1293 | OPENSSL_EXPORT int i2d_re_X509_REQ_tbs(X509_REQ *req, uint8_t **outp); |
| 1294 |
| 1295 | // X509_REQ_set1_signature_algo sets |req|'s signature algorithm to |algo| and |
| 1296 | // returns one on success or zero on error. |
| 1297 | OPENSSL_EXPORT int X509_REQ_set1_signature_algo(X509_REQ *req, |
| 1298 | const X509_ALGOR *algo); |
| 1299 |
| 1300 | // X509_REQ_set1_signature_value sets |req|'s signature to a copy of the |
| 1301 | // |sig_len| bytes pointed by |sig|. It returns one on success and zero on |
| 1302 | // error. |
| 1303 | // |
| 1304 | // Due to a specification error, PKCS#10 certificate requests store signatures |
| 1305 | // in ASN.1 BIT STRINGs, but signature algorithms return byte strings rather |
| 1306 | // than bit strings. This function creates a BIT STRING containing a whole |
| 1307 | // number of bytes, with the bit order matching the DER encoding. This matches |
| 1308 | // the encoding used by all X.509 signature algorithms. |
| 1309 | OPENSSL_EXPORT int X509_REQ_set1_signature_value(X509_REQ *req, |
| 1310 | const uint8_t *sig, |
| 1311 | size_t sig_len); |
| 1312 |
| 1313 |
| 1314 | // Names. |
| 1315 | // |
| 1316 | // An |X509_NAME| represents an X.509 Name structure (RFC 5280). X.509 names are |
| 1317 | // a complex, hierarchical structure over a collection of attributes. Each name |
| 1318 | // is sequence of relative distinguished names (RDNs), decreasing in |
| 1319 | // specificity. For example, the first RDN may specify the country, while the |
| 1320 | // next RDN may specify a locality. Each RDN is, itself, a set of attributes. |
| 1321 | // Having more than one attribute in an RDN is uncommon, but possible. Within an |
| 1322 | // RDN, attributes have the same level in specificity. Attribute types are |
| 1323 | // OBJECT IDENTIFIERs. This determines the ASN.1 type of the value, which is |
| 1324 | // commonly a string but may be other types. |
| 1325 | // |
| 1326 | // The |X509_NAME| representation flattens this two-level structure into a |
| 1327 | // single list of attributes. Each attribute is stored in an |X509_NAME_ENTRY|, |
| 1328 | // with also maintains the index of the RDN it is part of, accessible via |
| 1329 | // |X509_NAME_ENTRY_set|. This can be used to recover the two-level structure. |
| 1330 | // |
| 1331 | // X.509 names are largely vestigial. Historically, DNS names were parsed out of |
| 1332 | // the subject's common name attribute, but this is deprecated and has since |
| 1333 | // moved to the subject alternative name extension. In modern usage, X.509 names |
| 1334 | // are primarily opaque identifiers to link a certificate with its issuer. |
| 1335 |
| 1336 | DEFINE_STACK_OF(X509_NAME_ENTRY) |
| 1337 | DEFINE_STACK_OF(X509_NAME) |
| 1338 |
| 1339 | // X509_NAME is an |ASN1_ITEM| whose ASN.1 type is X.509 Name (RFC 5280) and C |
| 1340 | // type is |X509_NAME*|. |
| 1341 | DECLARE_ASN1_ITEM(X509_NAME) |
| 1342 |
| 1343 | // X509_NAME_new returns a new, empty |X509_NAME|, or NULL on error. |
| 1344 | OPENSSL_EXPORT X509_NAME *X509_NAME_new(void); |
| 1345 |
| 1346 | // X509_NAME_free releases memory associated with |name|. |
| 1347 | OPENSSL_EXPORT void X509_NAME_free(X509_NAME *name); |
| 1348 |
| 1349 | // d2i_X509_NAME parses up to |len| bytes from |*inp| as a DER-encoded X.509 |
| 1350 | // Name (RFC 5280), as described in |d2i_SAMPLE|. |
| 1351 | OPENSSL_EXPORT X509_NAME *d2i_X509_NAME(X509_NAME **out, const uint8_t **inp, |
| 1352 | long len); |
| 1353 |
| 1354 | // i2d_X509_NAME marshals |in| as a DER-encoded X.509 Name (RFC 5280), as |
| 1355 | // described in |i2d_SAMPLE|. |
| 1356 | // |
| 1357 | // TODO(https://crbug.com/boringssl/407): This function should be const and |
| 1358 | // thread-safe but is currently neither in some cases, notably if |in| was |
| 1359 | // mutated. |
| 1360 | OPENSSL_EXPORT int i2d_X509_NAME(X509_NAME *in, uint8_t **outp); |
| 1361 |
| 1362 | // X509_NAME_dup returns a newly-allocated copy of |name|, or NULL on error. |
| 1363 | // |
| 1364 | // TODO(https://crbug.com/boringssl/407): This function should be const and |
| 1365 | // thread-safe but is currently neither in some cases, notably if |name| was |
| 1366 | // mutated. |
| 1367 | OPENSSL_EXPORT X509_NAME *X509_NAME_dup(X509_NAME *name); |
| 1368 |
| 1369 | // X509_NAME_cmp compares |a| and |b|'s canonicalized forms. It returns zero if |
| 1370 | // they are equal, one if |a| sorts after |b|, -1 if |b| sorts after |a|, and -2 |
| 1371 | // on error. |
| 1372 | // |
| 1373 | // TODO(https://crbug.com/boringssl/407): This function is const, but it is not |
| 1374 | // always thread-safe, notably if |name| was mutated. |
| 1375 | // |
| 1376 | // TODO(https://crbug.com/boringssl/355): The -2 return is very inconvenient to |
| 1377 | // pass to a sorting function. Can we make this infallible? In the meantime, |
| 1378 | // prefer to use this function only for equality checks rather than comparisons. |
| 1379 | // Although even the library itself passes this to a sorting function. |
| 1380 | OPENSSL_EXPORT int X509_NAME_cmp(const X509_NAME *a, const X509_NAME *b); |
| 1381 |
| 1382 | // X509_NAME_get0_der marshals |name| as a DER-encoded X.509 Name (RFC 5280). On |
| 1383 | // success, it returns one and sets |*out_der| and |*out_der_len| to a buffer |
| 1384 | // containing the result. Otherwise, it returns zero. |*out_der| is owned by |
| 1385 | // |name| and must not be freed by the caller. It is invalidated after |name| is |
| 1386 | // mutated or freed. |
| 1387 | // |
| 1388 | // Avoid this function and prefer |i2d_X509_NAME|. It is one of the reasons |
| 1389 | // |X509_NAME| functions, including this one, are not consistently thread-safe |
| 1390 | // or const-correct. Depending on the resolution of |
| 1391 | // https://crbug.com/boringssl/407, this function may be removed or cause poor |
| 1392 | // performance. |
| 1393 | OPENSSL_EXPORT int X509_NAME_get0_der(X509_NAME *name, const uint8_t **out_der, |
| 1394 | size_t *out_der_len); |
| 1395 |
| 1396 | // X509_NAME_set makes a copy of |name|. On success, it frees |*xn|, sets |*xn| |
| 1397 | // to the copy, and returns one. Otherwise, it returns zero. |
| 1398 | // |
| 1399 | // TODO(https://crbug.com/boringssl/407): This function should be const and |
| 1400 | // thread-safe but is currently neither in some cases, notably if |name| was |
| 1401 | // mutated. |
| 1402 | OPENSSL_EXPORT int X509_NAME_set(X509_NAME **xn, X509_NAME *name); |
| 1403 |
| 1404 | // X509_NAME_entry_count returns the number of entries in |name|. |
| 1405 | OPENSSL_EXPORT int X509_NAME_entry_count(const X509_NAME *name); |
| 1406 |
| 1407 | // X509_NAME_get_index_by_NID returns the zero-based index of the first |
| 1408 | // attribute in |name| with type |nid|, or -1 if there is none. |nid| should be |
| 1409 | // one of the |NID_*| constants. If |lastpos| is non-negative, it begins |
| 1410 | // searching at |lastpos+1|. To search all attributes, pass in -1, not zero. |
| 1411 | // |
| 1412 | // Indices from this function refer to |X509_NAME|'s flattened representation. |
| 1413 | OPENSSL_EXPORT int X509_NAME_get_index_by_NID(const X509_NAME *name, int nid, |
| 1414 | int lastpos); |
| 1415 |
| 1416 | // X509_NAME_get_index_by_OBJ behaves like |X509_NAME_get_index_by_NID| but |
| 1417 | // looks for attributes with type |obj|. |
| 1418 | OPENSSL_EXPORT int X509_NAME_get_index_by_OBJ(const X509_NAME *name, |
| 1419 | const ASN1_OBJECT *obj, |
| 1420 | int lastpos); |
| 1421 |
| 1422 | // X509_NAME_get_entry returns the attribute in |name| at index |loc|, or NULL |
| 1423 | // if |loc| is out of range. |loc| is interpreted using |X509_NAME|'s flattened |
| 1424 | // representation. This function returns a non-const pointer for OpenSSL |
| 1425 | // compatibility, but callers should not mutate the result. Doing so will break |
| 1426 | // internal invariants in the library. |
| 1427 | OPENSSL_EXPORT X509_NAME_ENTRY *X509_NAME_get_entry(const X509_NAME *name, |
| 1428 | int loc); |
| 1429 |
| 1430 | // X509_NAME_delete_entry removes and returns the attribute in |name| at index |
| 1431 | // |loc|, or NULL if |loc| is out of range. |loc| is interpreted using |
| 1432 | // |X509_NAME|'s flattened representation. If the attribute is found, the caller |
| 1433 | // is responsible for releasing the result with |X509_NAME_ENTRY_free|. |
| 1434 | // |
| 1435 | // This function will internally update RDN indices (see |X509_NAME_ENTRY_set|) |
| 1436 | // so they continue to be consecutive. |
| 1437 | OPENSSL_EXPORT X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name, |
| 1438 | int loc); |
| 1439 |
| 1440 | // X509_NAME_add_entry adds a copy of |entry| to |name| and returns one on |
| 1441 | // success or zero on error. If |loc| is -1, the entry is appended to |name|. |
| 1442 | // Otherwise, it is inserted at index |loc|. If |set| is -1, the entry is added |
| 1443 | // to the previous entry's RDN. If it is 0, the entry becomes a singleton RDN. |
| 1444 | // If 1, it is added to next entry's RDN. |
| 1445 | // |
| 1446 | // This function will internally update RDN indices (see |X509_NAME_ENTRY_set|) |
| 1447 | // so they continue to be consecutive. |
| 1448 | OPENSSL_EXPORT int X509_NAME_add_entry(X509_NAME *name, |
| 1449 | const X509_NAME_ENTRY *entry, int loc, |
| 1450 | int set); |
| 1451 |
| 1452 | // X509_NAME_add_entry_by_OBJ adds a new entry to |name| and returns one on |
| 1453 | // success or zero on error. The entry's attribute type is |obj|. The entry's |
| 1454 | // attribute value is determined by |type|, |bytes|, and |len|, as in |
| 1455 | // |X509_NAME_ENTRY_set_data|. The entry's position is determined by |loc| and |
| 1456 | // |set| as in |X509_NAME_add_entry|. |
| 1457 | OPENSSL_EXPORT int X509_NAME_add_entry_by_OBJ(X509_NAME *name, |
| 1458 | const ASN1_OBJECT *obj, int type, |
| 1459 | const uint8_t *bytes, |
| 1460 | ossl_ssize_t len, int loc, |
| 1461 | int set); |
| 1462 |
| 1463 | // X509_NAME_add_entry_by_NID behaves like |X509_NAME_add_entry_by_OBJ| but sets |
| 1464 | // the entry's attribute type to |nid|, which should be one of the |NID_*| |
| 1465 | // constants. |
| 1466 | OPENSSL_EXPORT int X509_NAME_add_entry_by_NID(X509_NAME *name, int nid, |
| 1467 | int type, const uint8_t *bytes, |
| 1468 | ossl_ssize_t len, int loc, |
| 1469 | int set); |
| 1470 |
| 1471 | // X509_NAME_add_entry_by_txt behaves like |X509_NAME_add_entry_by_OBJ| but sets |
| 1472 | // the entry's attribute type to |field|, which is passed to |OBJ_txt2obj|. |
| 1473 | OPENSSL_EXPORT int X509_NAME_add_entry_by_txt(X509_NAME *name, |
| 1474 | const char *field, int type, |
| 1475 | const uint8_t *bytes, |
| 1476 | ossl_ssize_t len, int loc, |
| 1477 | int set); |
| 1478 |
| 1479 | // X509_NAME_ENTRY_new returns a new, empty |X509_NAME_ENTRY|, or NULL on error. |
| 1480 | OPENSSL_EXPORT X509_NAME_ENTRY *X509_NAME_ENTRY_new(void); |
| 1481 |
| 1482 | // X509_NAME_ENTRY_free releases memory associated with |entry|. |
| 1483 | OPENSSL_EXPORT void X509_NAME_ENTRY_free(X509_NAME_ENTRY *entry); |
| 1484 |
| 1485 | // X509_NAME_ENTRY_dup returns a newly-allocated copy of |entry|, or NULL on |
| 1486 | // error. |
| 1487 | OPENSSL_EXPORT X509_NAME_ENTRY *X509_NAME_ENTRY_dup( |
| 1488 | const X509_NAME_ENTRY *entry); |
| 1489 |
| 1490 | // X509_NAME_ENTRY_get_object returns |entry|'s attribute type. This function |
| 1491 | // returns a non-const pointer for OpenSSL compatibility, but callers should not |
| 1492 | // mutate the result. Doing so will break internal invariants in the library. |
| 1493 | OPENSSL_EXPORT ASN1_OBJECT *X509_NAME_ENTRY_get_object( |
| 1494 | const X509_NAME_ENTRY *entry); |
| 1495 |
| 1496 | // X509_NAME_ENTRY_set_object sets |entry|'s attribute type to |obj|. It returns |
| 1497 | // one on success and zero on error. |
| 1498 | OPENSSL_EXPORT int X509_NAME_ENTRY_set_object(X509_NAME_ENTRY *entry, |
| 1499 | const ASN1_OBJECT *obj); |
| 1500 |
| 1501 | // X509_NAME_ENTRY_get_data returns |entry|'s attribute value, represented as an |
| 1502 | // |ASN1_STRING|. This value may have any ASN.1 type, so callers must check the |
| 1503 | // type before interpreting the contents. This function returns a non-const |
| 1504 | // pointer for OpenSSL compatibility, but callers should not mutate the result. |
| 1505 | // Doing so will break internal invariants in the library. |
| 1506 | // |
| 1507 | // TODO(https://crbug.com/boringssl/412): Although the spec says any ASN.1 type |
| 1508 | // is allowed, we currently only allow an ad-hoc set of types. Additionally, it |
| 1509 | // is unclear if some types can even be represented by this function. |
| 1510 | OPENSSL_EXPORT ASN1_STRING *X509_NAME_ENTRY_get_data( |
| 1511 | const X509_NAME_ENTRY *entry); |
| 1512 |
| 1513 | // X509_NAME_ENTRY_set_data sets |entry|'s value to |len| bytes from |bytes|. It |
| 1514 | // returns one on success and zero on error. If |len| is -1, |bytes| must be a |
| 1515 | // NUL-terminated C string and the length is determined by |strlen|. |bytes| is |
| 1516 | // converted to an ASN.1 type as follows: |
| 1517 | // |
| 1518 | // If |type| is a |MBSTRING_*| constant, the value is an ASN.1 string. The |
| 1519 | // string is determined by decoding |bytes| in the encoding specified by |type|, |
| 1520 | // and then re-encoding it in a form appropriate for |entry|'s attribute type. |
| 1521 | // See |ASN1_STRING_set_by_NID| for details. |
| 1522 | // |
| 1523 | // Otherwise, the value is an |ASN1_STRING| with type |type| and value |bytes|. |
| 1524 | // See |ASN1_STRING| for how to format ASN.1 types as an |ASN1_STRING|. If |
| 1525 | // |type| is |V_ASN1_UNDEF| the previous |ASN1_STRING| type is reused. |
| 1526 | OPENSSL_EXPORT int X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *entry, int type, |
| 1527 | const uint8_t *bytes, |
| 1528 | ossl_ssize_t len); |
| 1529 |
| 1530 | // X509_NAME_ENTRY_set returns the zero-based index of the RDN which contains |
| 1531 | // |entry|. Consecutive entries with the same index are part of the same RDN. |
| 1532 | OPENSSL_EXPORT int X509_NAME_ENTRY_set(const X509_NAME_ENTRY *entry); |
| 1533 |
| 1534 | // X509_NAME_ENTRY_create_by_OBJ creates a new |X509_NAME_ENTRY| with attribute |
| 1535 | // type |obj|. The attribute value is determined from |type|, |bytes|, and |len| |
| 1536 | // as in |X509_NAME_ENTRY_set_data|. It returns the |X509_NAME_ENTRY| on success |
| 1537 | // and NULL on error. |
| 1538 | // |
| 1539 | // If |out| is non-NULL and |*out| is NULL, it additionally sets |*out| to the |
| 1540 | // result on success. If both |out| and |*out| are non-NULL, it updates the |
| 1541 | // object at |*out| instead of allocating a new one. |
| 1542 | OPENSSL_EXPORT X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ( |
| 1543 | X509_NAME_ENTRY **out, const ASN1_OBJECT *obj, int type, |
| 1544 | const uint8_t *bytes, ossl_ssize_t len); |
| 1545 |
| 1546 | // X509_NAME_ENTRY_create_by_NID behaves like |X509_NAME_ENTRY_create_by_OBJ| |
| 1547 | // except the attribute type is |nid|, which should be one of the |NID_*| |
| 1548 | // constants. |
| 1549 | OPENSSL_EXPORT X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID( |
| 1550 | X509_NAME_ENTRY **out, int nid, int type, const uint8_t *bytes, |
| 1551 | ossl_ssize_t len); |
| 1552 |
| 1553 | // X509_NAME_ENTRY_create_by_txt behaves like |X509_NAME_ENTRY_create_by_OBJ| |
| 1554 | // except the attribute type is |field|, which is passed to |OBJ_txt2obj|. |
| 1555 | OPENSSL_EXPORT X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_txt( |
| 1556 | X509_NAME_ENTRY **out, const char *field, int type, const uint8_t *bytes, |
| 1557 | ossl_ssize_t len); |
| 1558 |
| 1559 |
| 1560 | // Public keys. |
| 1561 | // |
| 1562 | // X.509 encodes public keys as SubjectPublicKeyInfo (RFC 5280), sometimes |
| 1563 | // referred to as SPKI. These are represented in this library by |X509_PUBKEY|. |
| 1564 |
| 1565 | // X509_PUBKEY_new returns a newly-allocated, empty |X509_PUBKEY| object, or |
| 1566 | // NULL on error. |
| 1567 | OPENSSL_EXPORT X509_PUBKEY *X509_PUBKEY_new(void); |
| 1568 |
| 1569 | // X509_PUBKEY_free releases memory associated with |key|. |
| 1570 | OPENSSL_EXPORT void X509_PUBKEY_free(X509_PUBKEY *key); |
| 1571 |
| 1572 | // d2i_X509_PUBKEY parses up to |len| bytes from |*inp| as a DER-encoded |
| 1573 | // SubjectPublicKeyInfo, as described in |d2i_SAMPLE|. |
| 1574 | OPENSSL_EXPORT X509_PUBKEY *d2i_X509_PUBKEY(X509_PUBKEY **out, |
| 1575 | const uint8_t **inp, long len); |
| 1576 |
| 1577 | // i2d_X509_PUBKEY marshals |key| as a DER-encoded SubjectPublicKeyInfo, as |
| 1578 | // described in |i2d_SAMPLE|. |
| 1579 | OPENSSL_EXPORT int i2d_X509_PUBKEY(const X509_PUBKEY *key, uint8_t **outp); |
| 1580 |
| 1581 | // X509_PUBKEY_set serializes |pkey| into a newly-allocated |X509_PUBKEY| |
| 1582 | // structure. On success, it frees |*x| if non-NULL, then sets |*x| to the new |
| 1583 | // object, and returns one. Otherwise, it returns zero. |
| 1584 | OPENSSL_EXPORT int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey); |
| 1585 |
| 1586 | // X509_PUBKEY_get0 returns |key| as an |EVP_PKEY|, or NULL if |key| either |
| 1587 | // could not be parsed or is an unrecognized algorithm. The |EVP_PKEY| is cached |
| 1588 | // in |key|, so callers must not mutate the result. |
| 1589 | OPENSSL_EXPORT EVP_PKEY *X509_PUBKEY_get0(const X509_PUBKEY *key); |
| 1590 |
| 1591 | // X509_PUBKEY_get behaves like |X509_PUBKEY_get0| but increments the reference |
| 1592 | // count on the |EVP_PKEY|. The caller must release the result with |
| 1593 | // |EVP_PKEY_free| when done. The |EVP_PKEY| is cached in |key|, so callers must |
| 1594 | // not mutate the result. |
| 1595 | OPENSSL_EXPORT EVP_PKEY *X509_PUBKEY_get(const X509_PUBKEY *key); |
| 1596 |
| 1597 | // X509_PUBKEY_set0_param sets |pub| to a key with AlgorithmIdentifier |
| 1598 | // determined by |obj|, |param_type|, and |param_value|, and an encoded |
| 1599 | // public key of |key|. On success, it gives |pub| ownership of all the other |
| 1600 | // parameters and returns one. Otherwise, it returns zero. |key| must have been |
| 1601 | // allocated by |OPENSSL_malloc|. |obj| and, if applicable, |param_value| must |
| 1602 | // not be freed after a successful call, and must have been allocated in a |
| 1603 | // manner compatible with |ASN1_OBJECT_free| or |ASN1_STRING_free|. |
| 1604 | // |
| 1605 | // |obj|, |param_type|, and |param_value| are interpreted as in |
| 1606 | // |X509_ALGOR_set0|. See |X509_ALGOR_set0| for details. |
| 1607 | OPENSSL_EXPORT int X509_PUBKEY_set0_param(X509_PUBKEY *pub, ASN1_OBJECT *obj, |
| 1608 | int param_type, void *param_value, |
| 1609 | uint8_t *key, int key_len); |
| 1610 |
| 1611 | // X509_PUBKEY_get0_param outputs fields of |pub| and returns one. If |out_obj| |
| 1612 | // is not NULL, it sets |*out_obj| to AlgorithmIdentifier's OID. If |out_key| |
| 1613 | // is not NULL, it sets |*out_key| and |*out_key_len| to the encoded public key. |
| 1614 | // If |out_alg| is not NULL, it sets |*out_alg| to the AlgorithmIdentifier. |
| 1615 | // |
| 1616 | // All pointers outputted by this function are internal to |pub| and must not be |
| 1617 | // freed by the caller. Additionally, although some outputs are non-const, |
| 1618 | // callers must not mutate the resulting objects. |
| 1619 | // |
| 1620 | // Note: X.509 SubjectPublicKeyInfo structures store the encoded public key as a |
| 1621 | // BIT STRING. |*out_key| and |*out_key_len| will silently pad the key with zero |
| 1622 | // bits if |pub| did not contain a whole number of bytes. Use |
| 1623 | // |X509_PUBKEY_get0_public_key| to preserve this information. |
| 1624 | OPENSSL_EXPORT int X509_PUBKEY_get0_param(ASN1_OBJECT **out_obj, |
| 1625 | const uint8_t **out_key, |
| 1626 | int *out_key_len, |
| 1627 | X509_ALGOR **out_alg, |
| 1628 | X509_PUBKEY *pub); |
| 1629 |
| 1630 | // X509_PUBKEY_get0_public_key returns |pub|'s encoded public key. |
| 1631 | OPENSSL_EXPORT const ASN1_BIT_STRING *X509_PUBKEY_get0_public_key( |
| 1632 | const X509_PUBKEY *pub); |
| 1633 |
| 1634 |
| 1635 | // Extensions. |
| 1636 | // |
| 1637 | // X.509 certificates and CRLs may contain a list of extensions (RFC 5280). |
| 1638 | // Extensions have a type, specified by an object identifier (|ASN1_OBJECT|) and |
| 1639 | // a byte string value, which should a DER-encoded structure whose type is |
| 1640 | // determined by the extension type. This library represents extensions with the |
| 1641 | // |X509_EXTENSION| type. |
| 1642 |
| 1643 | // X509_EXTENSION is an |ASN1_ITEM| whose ASN.1 type is X.509 Extension (RFC |
| 1644 | // 5280) and C type is |X509_EXTENSION*|. |
| 1645 | DECLARE_ASN1_ITEM(X509_EXTENSION) |
| 1646 |
| 1647 | // X509_EXTENSION_new returns a newly-allocated, empty |X509_EXTENSION| object |
| 1648 | // or NULL on error. |
| 1649 | OPENSSL_EXPORT X509_EXTENSION *X509_EXTENSION_new(void); |
| 1650 |
| 1651 | // X509_EXTENSION_free releases memory associated with |ex|. |
| 1652 | OPENSSL_EXPORT void X509_EXTENSION_free(X509_EXTENSION *ex); |
| 1653 |
| 1654 | // d2i_X509_EXTENSION parses up to |len| bytes from |*inp| as a DER-encoded |
| 1655 | // X.509 Extension (RFC 5280), as described in |d2i_SAMPLE|. |
| 1656 | OPENSSL_EXPORT X509_EXTENSION *d2i_X509_EXTENSION(X509_EXTENSION **out, |
| 1657 | const uint8_t **inp, |
| 1658 | long len); |
| 1659 |
| 1660 | // i2d_X509_EXTENSION marshals |ex| as a DER-encoded X.509 Extension (RFC |
| 1661 | // 5280), as described in |i2d_SAMPLE|. |
| 1662 | OPENSSL_EXPORT int i2d_X509_EXTENSION(const X509_EXTENSION *ex, uint8_t **outp); |
| 1663 |
| 1664 | // X509_EXTENSION_dup returns a newly-allocated copy of |ex|, or NULL on error. |
| 1665 | // This function works by serializing the structure, so if |ex| is incomplete, |
| 1666 | // it may fail. |
| 1667 | OPENSSL_EXPORT X509_EXTENSION *X509_EXTENSION_dup(const X509_EXTENSION *ex); |
| 1668 |
| 1669 | // X509_EXTENSION_create_by_NID creates a new |X509_EXTENSION| with type |nid|, |
| 1670 | // value |data|, and critical bit |crit|. It returns an |X509_EXTENSION| on |
| 1671 | // success, and NULL on error. |nid| should be a |NID_*| constant. |
| 1672 | // |
| 1673 | // If |ex| and |*ex| are both non-NULL, |*ex| is used to hold the result, |
| 1674 | // otherwise a new object is allocated. If |ex| is non-NULL and |*ex| is NULL, |
| 1675 | // the function sets |*ex| to point to the newly allocated result, in addition |
| 1676 | // to returning the result. |
| 1677 | OPENSSL_EXPORT X509_EXTENSION *X509_EXTENSION_create_by_NID( |
| 1678 | X509_EXTENSION **ex, int nid, int crit, const ASN1_OCTET_STRING *data); |
| 1679 |
| 1680 | // X509_EXTENSION_create_by_OBJ behaves like |X509_EXTENSION_create_by_NID|, but |
| 1681 | // the extension type is determined by an |ASN1_OBJECT|. |
| 1682 | OPENSSL_EXPORT X509_EXTENSION *X509_EXTENSION_create_by_OBJ( |
| 1683 | X509_EXTENSION **ex, const ASN1_OBJECT *obj, int crit, |
| 1684 | const ASN1_OCTET_STRING *data); |
| 1685 |
| 1686 | // X509_EXTENSION_get_object returns |ex|'s extension type. This function |
| 1687 | // returns a non-const pointer for OpenSSL compatibility, but callers should not |
| 1688 | // mutate the result. |
| 1689 | OPENSSL_EXPORT ASN1_OBJECT *X509_EXTENSION_get_object(const X509_EXTENSION *ex); |
| 1690 |
| 1691 | // X509_EXTENSION_get_data returns |ne|'s extension value. This function returns |
| 1692 | // a non-const pointer for OpenSSL compatibility, but callers should not mutate |
| 1693 | // the result. |
| 1694 | OPENSSL_EXPORT ASN1_OCTET_STRING *X509_EXTENSION_get_data( |
| 1695 | const X509_EXTENSION *ne); |
| 1696 |
| 1697 | // X509_EXTENSION_get_critical returns one if |ex| is critical and zero |
| 1698 | // otherwise. |
| 1699 | OPENSSL_EXPORT int X509_EXTENSION_get_critical(const X509_EXTENSION *ex); |
| 1700 |
| 1701 | // X509_EXTENSION_set_object sets |ex|'s extension type to |obj|. It returns one |
| 1702 | // on success and zero on error. |
| 1703 | OPENSSL_EXPORT int X509_EXTENSION_set_object(X509_EXTENSION *ex, |
| 1704 | const ASN1_OBJECT *obj); |
| 1705 |
| 1706 | // X509_EXTENSION_set_critical sets |ex| to critical if |crit| is non-zero and |
| 1707 | // to non-critical if |crit| is zero. |
| 1708 | OPENSSL_EXPORT int X509_EXTENSION_set_critical(X509_EXTENSION *ex, int crit); |
| 1709 |
| 1710 | // X509_EXTENSION_set_data set's |ex|'s extension value to a copy of |data|. It |
| 1711 | // returns one on success and zero on error. |
| 1712 | OPENSSL_EXPORT int X509_EXTENSION_set_data(X509_EXTENSION *ex, |
| 1713 | const ASN1_OCTET_STRING *data); |
| 1714 |
| 1715 |
| 1716 | // Extension lists. |
| 1717 | // |
| 1718 | // The following functions manipulate lists of extensions. Most of them have |
| 1719 | // corresponding functions on the containing |X509|, |X509_CRL|, or |
| 1720 | // |X509_REVOKED|. |
| 1721 |
| 1722 | DEFINE_STACK_OF(X509_EXTENSION) |
| 1723 | typedef STACK_OF(X509_EXTENSION) X509_EXTENSIONS; |
| 1724 |
| 1725 | // d2i_X509_EXTENSIONS parses up to |len| bytes from |*inp| as a DER-encoded |
| 1726 | // SEQUENCE OF Extension (RFC 5280), as described in |d2i_SAMPLE|. |
| 1727 | OPENSSL_EXPORT X509_EXTENSIONS *d2i_X509_EXTENSIONS(X509_EXTENSIONS **out, |
| 1728 | const uint8_t **inp, |
| 1729 | long len); |
| 1730 |
| 1731 | // i2d_X509_EXTENSIONS marshals |alg| as a DER-encoded SEQUENCE OF Extension |
| 1732 | // (RFC 5280), as described in |i2d_SAMPLE|. |
| 1733 | OPENSSL_EXPORT int i2d_X509_EXTENSIONS(const X509_EXTENSIONS *alg, |
| 1734 | uint8_t **outp); |
| 1735 |
| 1736 | // X509v3_get_ext_count returns the number of extensions in |x|. |
| 1737 | OPENSSL_EXPORT int X509v3_get_ext_count(const STACK_OF(X509_EXTENSION) *x); |
| 1738 |
| 1739 | // X509v3_get_ext_by_NID returns the index of the first extension in |x| with |
| 1740 | // type |nid|, or a negative number if not found. If found, callers can use |
| 1741 | // |X509v3_get_ext| to look up the extension by index. |
| 1742 | // |
| 1743 | // If |lastpos| is non-negative, it begins searching at |lastpos| + 1. Callers |
| 1744 | // can thus loop over all matching extensions by first passing -1 and then |
| 1745 | // passing the previously-returned value until no match is returned. |
| 1746 | OPENSSL_EXPORT int X509v3_get_ext_by_NID(const STACK_OF(X509_EXTENSION) *x, |
| 1747 | int nid, int lastpos); |
| 1748 |
| 1749 | // X509v3_get_ext_by_OBJ behaves like |X509v3_get_ext_by_NID| but looks for |
| 1750 | // extensions matching |obj|. |
| 1751 | OPENSSL_EXPORT int X509v3_get_ext_by_OBJ(const STACK_OF(X509_EXTENSION) *x, |
| 1752 | const ASN1_OBJECT *obj, int lastpos); |
| 1753 |
| 1754 | // X509v3_get_ext_by_critical returns the index of the first extension in |x| |
| 1755 | // whose critical bit matches |crit|, or a negative number if no such extension |
| 1756 | // was found. |
| 1757 | // |
| 1758 | // If |lastpos| is non-negative, it begins searching at |lastpos| + 1. Callers |
| 1759 | // can thus loop over all matching extensions by first passing -1 and then |
| 1760 | // passing the previously-returned value until no match is returned. |
| 1761 | OPENSSL_EXPORT int X509v3_get_ext_by_critical(const STACK_OF(X509_EXTENSION) *x, |
| 1762 | int crit, int lastpos); |
| 1763 |
| 1764 | // X509v3_get_ext returns the extension in |x| at index |loc|, or NULL if |loc| |
| 1765 | // is out of bounds. This function returns a non-const pointer for OpenSSL |
| 1766 | // compatibility, but callers should not mutate the result. |
| 1767 | OPENSSL_EXPORT X509_EXTENSION *X509v3_get_ext(const STACK_OF(X509_EXTENSION) *x, |
| 1768 | int loc); |
| 1769 |
| 1770 | // X509v3_delete_ext removes the extension in |x| at index |loc| and returns the |
| 1771 | // removed extension, or NULL if |loc| was out of bounds. If an extension was |
| 1772 | // returned, the caller must release it with |X509_EXTENSION_free|. |
| 1773 | OPENSSL_EXPORT X509_EXTENSION *X509v3_delete_ext(STACK_OF(X509_EXTENSION) *x, |
| 1774 | int loc); |
| 1775 |
| 1776 | // X509v3_add_ext adds a copy of |ex| to the extension list in |*x|. If |*x| is |
| 1777 | // NULL, it allocates a new |STACK_OF(X509_EXTENSION)| to hold the copy and sets |
| 1778 | // |*x| to the new list. It returns |*x| on success and NULL on error. The |
| 1779 | // caller retains ownership of |ex| and can release it independently of |*x|. |
| 1780 | // |
| 1781 | // The new extension is inserted at index |loc|, shifting extensions to the |
| 1782 | // right. If |loc| is -1 or out of bounds, the new extension is appended to the |
| 1783 | // list. |
| 1784 | OPENSSL_EXPORT STACK_OF(X509_EXTENSION) *X509v3_add_ext( |
| 1785 | STACK_OF(X509_EXTENSION) **x, const X509_EXTENSION *ex, int loc); |
| 1786 |
| 1787 |
| 1788 | // Built-in extensions. |
| 1789 | // |
| 1790 | // Several functions in the library encode and decode extension values into a |
| 1791 | // C structure to that extension. The following extensions are supported: |
| 1792 | // |
| 1793 | // - |NID_authority_key_identifier| with type |AUTHORITY_KEYID| |
| 1794 | // - |NID_basic_constraints| with type |BASIC_CONSTRAINTS| |
| 1795 | // - |NID_certificate_issuer| with type |GENERAL_NAMES| |
| 1796 | // - |NID_certificate_policies| with type |CERTIFICATEPOLICIES| |
| 1797 | // - |NID_crl_distribution_points| with type |CRL_DIST_POINTS| |
| 1798 | // - |NID_crl_number| with type |ASN1_INTEGER| |
| 1799 | // - |NID_crl_reason| with type |ASN1_ENUMERATED| |
| 1800 | // - |NID_delta_crl| with type |ASN1_INTEGER| |
| 1801 | // - |NID_ext_key_usage| with type |EXTENDED_KEY_USAGE| |
| 1802 | // - |NID_freshest_crl| with type |ISSUING_DIST_POINT| |
| 1803 | // - |NID_id_pkix_OCSP_noCheck| with type |ASN1_NULL| |
| 1804 | // - |NID_info_access| with type |AUTHORITY_INFO_ACCESS| |
| 1805 | // - |NID_inhibit_any_policy| with type |ASN1_INTEGER| |
| 1806 | // - |NID_invalidity_date| with type |ASN1_GENERALIZEDTIME| |
| 1807 | // - |NID_issuer_alt_name| with type |GENERAL_NAMES| |
| 1808 | // - |NID_issuing_distribution_point| with type |ISSUING_DIST_POINT| |
| 1809 | // - |NID_key_usage| with type |ASN1_BIT_STRING| |
| 1810 | // - |NID_name_constraints| with type |NAME_CONSTRAINTS| |
| 1811 | // - |NID_netscape_base_url| with type |ASN1_IA5STRING| |
| 1812 | // - |NID_netscape_ca_policy_url| with type |ASN1_IA5STRING| |
| 1813 | // - |NID_netscape_ca_revocation_url| with type |ASN1_IA5STRING| |
| 1814 | // - |NID_netscape_cert_type| with type |ASN1_BIT_STRING| |
| 1815 | // - |NID_netscape_comment| with type |ASN1_IA5STRING| |
| 1816 | // - |NID_netscape_renewal_url| with type |ASN1_IA5STRING| |
| 1817 | // - |NID_netscape_revocation_url| with type |ASN1_IA5STRING| |
| 1818 | // - |NID_netscape_ssl_server_name| with type |ASN1_IA5STRING| |
| 1819 | // - |NID_policy_constraints| with type |POLICY_CONSTRAINTS| |
| 1820 | // - |NID_policy_mappings| with type |POLICY_MAPPINGS| |
| 1821 | // - |NID_sinfo_access| with type |AUTHORITY_INFO_ACCESS| |
| 1822 | // - |NID_subject_alt_name| with type |GENERAL_NAMES| |
| 1823 | // - |NID_subject_key_identifier| with type |ASN1_OCTET_STRING| |
| 1824 | // |
| 1825 | // If an extension does not appear in this list, e.g. for a custom extension, |
| 1826 | // callers can instead use functions such as |X509_get_ext_by_OBJ|, |
| 1827 | // |X509_EXTENSION_get_data|, and |X509_EXTENSION_create_by_OBJ| to inspect or |
| 1828 | // create extensions directly. Although the |X509V3_EXT_METHOD| mechanism allows |
| 1829 | // registering custom extensions, doing so is deprecated and may result in |
| 1830 | // threading or memory errors. |
| 1831 |
| 1832 | // X509V3_EXT_d2i decodes |ext| and returns a pointer to a newly-allocated |
| 1833 | // structure, with type dependent on the type of the extension. It returns NULL |
| 1834 | // if |ext| is an unsupported extension or if there was a syntax error in the |
| 1835 | // extension. The caller should cast the return value to the expected type and |
| 1836 | // free the structure when done. |
| 1837 | // |
| 1838 | // WARNING: Casting the return value to the wrong type is a potentially |
| 1839 | // exploitable memory error, so callers must not use this function before |
| 1840 | // checking |ext| is of a known type. See the list at the top of this section |
| 1841 | // for the correct types. |
| 1842 | OPENSSL_EXPORT void *X509V3_EXT_d2i(const X509_EXTENSION *ext); |
| 1843 |
| 1844 | // X509V3_get_d2i finds and decodes the extension in |extensions| of type |nid|. |
| 1845 | // If found, it decodes it and returns a newly-allocated structure, with type |
| 1846 | // dependent on |nid|. If the extension is not found or on error, it returns |
| 1847 | // NULL. The caller may distinguish these cases using the |out_critical| value. |
| 1848 | // |
| 1849 | // If |out_critical| is not NULL, this function sets |*out_critical| to one if |
| 1850 | // the extension is found and critical, zero if it is found and not critical, -1 |
| 1851 | // if it is not found, and -2 if there is an invalid duplicate extension. Note |
| 1852 | // this function may set |*out_critical| to one or zero and still return NULL if |
| 1853 | // the extension is found but has a syntax error. |
| 1854 | // |
| 1855 | // If |out_idx| is not NULL, this function looks for the first occurrence of the |
| 1856 | // extension after |*out_idx|. It then sets |*out_idx| to the index of the |
| 1857 | // extension, or -1 if not found. If |out_idx| is non-NULL, duplicate extensions |
| 1858 | // are not treated as an error. Callers, however, should not rely on this |
| 1859 | // behavior as it may be removed in the future. Duplicate extensions are |
| 1860 | // forbidden in RFC 5280. |
| 1861 | // |
| 1862 | // WARNING: This function is difficult to use correctly. Callers should pass a |
| 1863 | // non-NULL |out_critical| and check both the return value and |*out_critical| |
| 1864 | // to handle errors. If the return value is NULL and |*out_critical| is not -1, |
| 1865 | // there was an error. Otherwise, the function succeeded and but may return NULL |
| 1866 | // for a missing extension. Callers should pass NULL to |out_idx| so that |
| 1867 | // duplicate extensions are handled correctly. |
| 1868 | // |
| 1869 | // Additionally, casting the return value to the wrong type is a potentially |
| 1870 | // exploitable memory error, so callers must ensure the cast and |nid| match. |
| 1871 | // See the list at the top of this section for the correct types. |
| 1872 | OPENSSL_EXPORT void *X509V3_get_d2i(const STACK_OF(X509_EXTENSION) *extensions, |
| 1873 | int nid, int *out_critical, int *out_idx); |
| 1874 |
| 1875 | // X509V3_EXT_free casts |ext_data| into the type that corresponds to |nid| and |
| 1876 | // releases memory associated with it. It returns one on success and zero if |
| 1877 | // |nid| is not a known extension. |
| 1878 | // |
| 1879 | // WARNING: Casting |ext_data| to the wrong type is a potentially exploitable |
| 1880 | // memory error, so callers must ensure |ext_data|'s type matches |nid|. See the |
| 1881 | // list at the top of this section for the correct types. |
| 1882 | // |
| 1883 | // TODO(davidben): OpenSSL upstream no longer exposes this function. Remove it? |
| 1884 | OPENSSL_EXPORT int X509V3_EXT_free(int nid, void *ext_data); |
| 1885 |
| 1886 | // X509V3_EXT_i2d casts |ext_struc| into the type that corresponds to |
| 1887 | // |ext_nid|, serializes it, and returns a newly-allocated |X509_EXTENSION| |
| 1888 | // object containing the serialization, or NULL on error. The |X509_EXTENSION| |
| 1889 | // has OID |ext_nid| and is critical if |crit| is one. |
| 1890 | // |
| 1891 | // WARNING: Casting |ext_struc| to the wrong type is a potentially exploitable |
| 1892 | // memory error, so callers must ensure |ext_struct|'s type matches |ext_nid|. |
| 1893 | // See the list at the top of this section for the correct types. |
| 1894 | OPENSSL_EXPORT X509_EXTENSION *X509V3_EXT_i2d(int ext_nid, int crit, |
| 1895 | void *ext_struc); |
| 1896 |
| 1897 | // The following constants control the behavior of |X509V3_add1_i2d| and related |
| 1898 | // functions. |
| 1899 |
| 1900 | // X509V3_ADD_OP_MASK can be ANDed with the flags to determine how duplicate |
| 1901 | // extensions are processed. |
| 1902 | #define X509V3_ADD_OP_MASK 0xfL |
| 1903 |
| 1904 | // X509V3_ADD_DEFAULT causes the function to fail if the extension was already |
| 1905 | // present. |
| 1906 | #define X509V3_ADD_DEFAULT 0L |
| 1907 |
| 1908 | // X509V3_ADD_APPEND causes the function to unconditionally appended the new |
| 1909 | // extension to to the extensions list, even if there is a duplicate. |
| 1910 | #define X509V3_ADD_APPEND 1L |
| 1911 |
| 1912 | // X509V3_ADD_REPLACE causes the function to replace the existing extension, or |
| 1913 | // append if it is not present. |
| 1914 | #define X509V3_ADD_REPLACE 2L |
| 1915 |
| 1916 | // X509V3_ADD_REPLACE_EXISTING causes the function to replace the existing |
| 1917 | // extension and fail if it is not present. |
| 1918 | #define X509V3_ADD_REPLACE_EXISTING 3L |
| 1919 |
| 1920 | // X509V3_ADD_KEEP_EXISTING causes the function to succeed without replacing the |
| 1921 | // extension if already present. |
| 1922 | #define X509V3_ADD_KEEP_EXISTING 4L |
| 1923 |
| 1924 | // X509V3_ADD_DELETE causes the function to remove the matching extension. No |
| 1925 | // new extension is added. If there is no matching extension, the function |
| 1926 | // fails. The |value| parameter is ignored in this mode. |
| 1927 | #define X509V3_ADD_DELETE 5L |
| 1928 |
| 1929 | // X509V3_ADD_SILENT may be ORed into one of the values above to indicate the |
| 1930 | // function should not add to the error queue on duplicate or missing extension. |
| 1931 | // The function will continue to return zero in those cases, and it will |
| 1932 | // continue to return -1 and add to the error queue on other errors. |
| 1933 | #define X509V3_ADD_SILENT 0x10 |
| 1934 |
| 1935 | // X509V3_add1_i2d casts |value| to the type that corresponds to |nid|, |
| 1936 | // serializes it, and appends it to the extension list in |*x|. If |*x| is NULL, |
| 1937 | // it will set |*x| to a newly-allocated |STACK_OF(X509_EXTENSION)| as needed. |
| 1938 | // The |crit| parameter determines whether the new extension is critical. |
| 1939 | // |flags| may be some combination of the |X509V3_ADD_*| constants to control |
| 1940 | // the function's behavior on duplicate extension. |
| 1941 | // |
| 1942 | // This function returns one on success, zero if the operation failed due to a |
| 1943 | // missing or duplicate extension, and -1 on other errors. |
| 1944 | // |
| 1945 | // WARNING: Casting |value| to the wrong type is a potentially exploitable |
| 1946 | // memory error, so callers must ensure |value|'s type matches |nid|. See the |
| 1947 | // list at the top of this section for the correct types. |
| 1948 | OPENSSL_EXPORT int X509V3_add1_i2d(STACK_OF(X509_EXTENSION) **x, int nid, |
| 1949 | void *value, int crit, unsigned long flags); |
| 1950 |
| 1951 |
| 1952 | // Basic constraints. |
| 1953 | // |
| 1954 | // The basic constraints extension (RFC 5280, section 4.2.1.9) determines |
| 1955 | // whether a certificate is a CA certificate and, if so, optionally constrains |
| 1956 | // the maximum depth of the certificate chain. |
| 1957 |
| 1958 | // A BASIC_CONSTRAINTS_st, aka |BASIC_CONSTRAINTS| represents an |
| 1959 | // BasicConstraints structure (RFC 5280). |
| 1960 | struct BASIC_CONSTRAINTS_st { |
| 1961 | ASN1_BOOLEAN ca; |
| 1962 | ASN1_INTEGER *pathlen; |
| 1963 | } /* BASIC_CONSTRAINTS */; |
| 1964 |
| 1965 | // BASIC_CONSTRAINTS is an |ASN1_ITEM| whose ASN.1 type is BasicConstraints (RFC |
| 1966 | // 5280) and C type is |BASIC_CONSTRAINTS*|. |
| 1967 | DECLARE_ASN1_ITEM(BASIC_CONSTRAINTS) |
| 1968 |
| 1969 | // BASIC_CONSTRAINTS_new returns a newly-allocated, empty |BASIC_CONSTRAINTS| |
| 1970 | // object, or NULL on error. |
| 1971 | OPENSSL_EXPORT BASIC_CONSTRAINTS *BASIC_CONSTRAINTS_new(void); |
| 1972 |
| 1973 | // BASIC_CONSTRAINTS_free releases memory associated with |bcons|. |
| 1974 | OPENSSL_EXPORT void BASIC_CONSTRAINTS_free(BASIC_CONSTRAINTS *bcons); |
| 1975 |
| 1976 | // d2i_BASIC_CONSTRAINTS parses up to |len| bytes from |*inp| as a DER-encoded |
| 1977 | // BasicConstraints (RFC 5280), as described in |d2i_SAMPLE|. |
| 1978 | OPENSSL_EXPORT BASIC_CONSTRAINTS *d2i_BASIC_CONSTRAINTS(BASIC_CONSTRAINTS **out, |
| 1979 | const uint8_t **inp, |
| 1980 | long len); |
| 1981 |
| 1982 | // i2d_BASIC_CONSTRAINTS marshals |bcons| as a DER-encoded BasicConstraints (RFC |
| 1983 | // 5280), as described in |i2d_SAMPLE|. |
| 1984 | OPENSSL_EXPORT int i2d_BASIC_CONSTRAINTS(const BASIC_CONSTRAINTS *bcons, |
| 1985 | uint8_t **outp); |
| 1986 |
| 1987 |
| 1988 | // Extended key usage. |
| 1989 | // |
| 1990 | // The extended key usage extension (RFC 5280, section 4.2.1.12) indicates the |
| 1991 | // purposes of the certificate's public key. Such constraints are important to |
| 1992 | // avoid cross-protocol attacks. |
| 1993 |
| 1994 | typedef STACK_OF(ASN1_OBJECT) EXTENDED_KEY_USAGE; |
| 1995 |
| 1996 | // EXTENDED_KEY_USAGE is an |ASN1_ITEM| whose ASN.1 type is ExtKeyUsageSyntax |
| 1997 | // (RFC 5280) and C type is |STACK_OF(ASN1_OBJECT)*|, or |EXTENDED_KEY_USAGE*|. |
| 1998 | DECLARE_ASN1_ITEM(EXTENDED_KEY_USAGE) |
| 1999 |
| 2000 | // EXTENDED_KEY_USAGE_new returns a newly-allocated, empty |EXTENDED_KEY_USAGE| |
| 2001 | // object, or NULL on error. |
| 2002 | OPENSSL_EXPORT EXTENDED_KEY_USAGE *EXTENDED_KEY_USAGE_new(void); |
| 2003 |
| 2004 | // EXTENDED_KEY_USAGE_free releases memory associated with |eku|. |
| 2005 | OPENSSL_EXPORT void EXTENDED_KEY_USAGE_free(EXTENDED_KEY_USAGE *eku); |
| 2006 |
| 2007 | // d2i_EXTENDED_KEY_USAGE parses up to |len| bytes from |*inp| as a DER-encoded |
| 2008 | // ExtKeyUsageSyntax (RFC 5280), as described in |d2i_SAMPLE|. |
| 2009 | OPENSSL_EXPORT EXTENDED_KEY_USAGE *d2i_EXTENDED_KEY_USAGE( |
| 2010 | EXTENDED_KEY_USAGE **out, const uint8_t **inp, long len); |
| 2011 |
| 2012 | // i2d_EXTENDED_KEY_USAGE marshals |eku| as a DER-encoded ExtKeyUsageSyntax (RFC |
| 2013 | // 5280), as described in |i2d_SAMPLE|. |
| 2014 | OPENSSL_EXPORT int i2d_EXTENDED_KEY_USAGE(const EXTENDED_KEY_USAGE *eku, |
| 2015 | uint8_t **outp); |
| 2016 |
| 2017 |
| 2018 | // General names. |
| 2019 | // |
| 2020 | // A |GENERAL_NAME| represents an X.509 GeneralName structure, defined in RFC |
| 2021 | // 5280, Section 4.2.1.6. General names are distinct from names (|X509_NAME|). A |
| 2022 | // general name is a CHOICE type which may contain one of several name types, |
| 2023 | // most commonly a DNS name or an IP address. General names most commonly appear |
| 2024 | // in the subject alternative name (SAN) extension, though they are also used in |
| 2025 | // other extensions. |
| 2026 | // |
| 2027 | // Many extensions contain a SEQUENCE OF GeneralName, or GeneralNames, so |
| 2028 | // |STACK_OF(GENERAL_NAME)| is defined and aliased to |GENERAL_NAMES|. |
| 2029 |
| 2030 | typedef struct otherName_st { |
| 2031 | ASN1_OBJECT *type_id; |
| 2032 | ASN1_TYPE *value; |
| 2033 | } OTHERNAME; |
| 2034 |
| 2035 | typedef struct EDIPartyName_st { |
| 2036 | ASN1_STRING *nameAssigner; |
| 2037 | ASN1_STRING *partyName; |
| 2038 | } EDIPARTYNAME; |
| 2039 |
| 2040 | // GEN_* are constants for the |type| field of |GENERAL_NAME|, defined below. |
| 2041 | #define GEN_OTHERNAME 0 |
| 2042 | #define GEN_EMAIL 1 |
| 2043 | #define GEN_DNS 2 |
| 2044 | #define GEN_X400 3 |
| 2045 | #define GEN_DIRNAME 4 |
| 2046 | #define GEN_EDIPARTY 5 |
| 2047 | #define GEN_URI 6 |
| 2048 | #define GEN_IPADD 7 |
| 2049 | #define GEN_RID 8 |
| 2050 |
| 2051 | // A GENERAL_NAME_st, aka |GENERAL_NAME|, represents an X.509 GeneralName. The |
| 2052 | // |type| field determines which member of |d| is active. A |GENERAL_NAME| may |
| 2053 | // also be empty, in which case |type| is -1 and |d| is NULL. Empty |
| 2054 | // |GENERAL_NAME|s are invalid and will never be returned from the parser, but |
| 2055 | // may be created temporarily, e.g. by |GENERAL_NAME_new|. |
| 2056 | // |
| 2057 | // WARNING: |type| and |d| must be kept consistent. An inconsistency will result |
| 2058 | // in a potentially exploitable memory error. |
| 2059 | struct GENERAL_NAME_st { |
| 2060 | int type; |
| 2061 | union { |
| 2062 | char *ptr; |
| 2063 | OTHERNAME *otherName; |
| 2064 | ASN1_IA5STRING *rfc822Name; |
| 2065 | ASN1_IA5STRING *dNSName; |
| 2066 | ASN1_STRING *x400Address; |
| 2067 | X509_NAME *directoryName; |
| 2068 | EDIPARTYNAME *ediPartyName; |
| 2069 | ASN1_IA5STRING *uniformResourceIdentifier; |
| 2070 | ASN1_OCTET_STRING *iPAddress; |
| 2071 | ASN1_OBJECT *registeredID; |
| 2072 |
| 2073 | // Old names |
| 2074 | ASN1_OCTET_STRING *ip; // iPAddress |
| 2075 | X509_NAME *dirn; // dirn |
| 2076 | ASN1_IA5STRING *ia5; // rfc822Name, dNSName, uniformResourceIdentifier |
| 2077 | ASN1_OBJECT *rid; // registeredID |
| 2078 | } d; |
| 2079 | } /* GENERAL_NAME */; |
| 2080 |
| 2081 | // GENERAL_NAME_new returns a new, empty |GENERAL_NAME|, or NULL on error. |
| 2082 | OPENSSL_EXPORT GENERAL_NAME *GENERAL_NAME_new(void); |
| 2083 |
| 2084 | // GENERAL_NAME_free releases memory associated with |gen|. |
| 2085 | OPENSSL_EXPORT void GENERAL_NAME_free(GENERAL_NAME *gen); |
| 2086 |
| 2087 | // d2i_GENERAL_NAME parses up to |len| bytes from |*inp| as a DER-encoded X.509 |
| 2088 | // GeneralName (RFC 5280), as described in |d2i_SAMPLE|. |
| 2089 | OPENSSL_EXPORT GENERAL_NAME *d2i_GENERAL_NAME(GENERAL_NAME **out, |
| 2090 | const uint8_t **inp, long len); |
| 2091 |
| 2092 | // i2d_GENERAL_NAME marshals |in| as a DER-encoded X.509 GeneralName (RFC 5280), |
| 2093 | // as described in |i2d_SAMPLE|. |
| 2094 | // |
| 2095 | // TODO(https://crbug.com/boringssl/407): This function should be const and |
| 2096 | // thread-safe but is currently neither in some cases, notably if |in| is an |
| 2097 | // directoryName and the |X509_NAME| has been modified. |
| 2098 | OPENSSL_EXPORT int i2d_GENERAL_NAME(GENERAL_NAME *in, uint8_t **outp); |
| 2099 |
| 2100 | // GENERAL_NAME_dup returns a newly-allocated copy of |gen|, or NULL on error. |
| 2101 | // This function works by serializing the structure, so it will fail if |gen| is |
| 2102 | // empty. |
| 2103 | // |
| 2104 | // TODO(https://crbug.com/boringssl/407): This function should be const and |
| 2105 | // thread-safe but is currently neither in some cases, notably if |gen| is an |
| 2106 | // directoryName and the |X509_NAME| has been modified. |
| 2107 | OPENSSL_EXPORT GENERAL_NAME *GENERAL_NAME_dup(GENERAL_NAME *gen); |
| 2108 |
| 2109 | // GENERAL_NAMES_new returns a new, empty |GENERAL_NAMES|, or NULL on error. |
| 2110 | OPENSSL_EXPORT GENERAL_NAMES *GENERAL_NAMES_new(void); |
| 2111 |
| 2112 | // GENERAL_NAMES_free releases memory associated with |gens|. |
| 2113 | OPENSSL_EXPORT void GENERAL_NAMES_free(GENERAL_NAMES *gens); |
| 2114 |
| 2115 | // d2i_GENERAL_NAMES parses up to |len| bytes from |*inp| as a DER-encoded |
| 2116 | // SEQUENCE OF GeneralName, as described in |d2i_SAMPLE|. |
| 2117 | OPENSSL_EXPORT GENERAL_NAMES *d2i_GENERAL_NAMES(GENERAL_NAMES **out, |
| 2118 | const uint8_t **inp, long len); |
| 2119 |
| 2120 | // i2d_GENERAL_NAMES marshals |in| as a DER-encoded SEQUENCE OF GeneralName, as |
| 2121 | // described in |i2d_SAMPLE|. |
| 2122 | // |
| 2123 | // TODO(https://crbug.com/boringssl/407): This function should be const and |
| 2124 | // thread-safe but is currently neither in some cases, notably if some element |
| 2125 | // of |in| is an directoryName and the |X509_NAME| has been modified. |
| 2126 | OPENSSL_EXPORT int i2d_GENERAL_NAMES(GENERAL_NAMES *in, uint8_t **outp); |
| 2127 |
| 2128 | // OTHERNAME_new returns a new, empty |OTHERNAME|, or NULL on error. |
| 2129 | OPENSSL_EXPORT OTHERNAME *OTHERNAME_new(void); |
| 2130 |
| 2131 | // OTHERNAME_free releases memory associated with |name|. |
| 2132 | OPENSSL_EXPORT void OTHERNAME_free(OTHERNAME *name); |
| 2133 |
| 2134 | // EDIPARTYNAME_new returns a new, empty |EDIPARTYNAME|, or NULL on error. |
| 2135 | // EDIPartyName is rarely used in practice, so callers are unlikely to need this |
| 2136 | // function. |
| 2137 | OPENSSL_EXPORT EDIPARTYNAME *EDIPARTYNAME_new(void); |
| 2138 |
| 2139 | // EDIPARTYNAME_free releases memory associated with |name|. EDIPartyName is |
| 2140 | // rarely used in practice, so callers are unlikely to need this function. |
| 2141 | OPENSSL_EXPORT void EDIPARTYNAME_free(EDIPARTYNAME *name); |
| 2142 |
| 2143 | // GENERAL_NAME_set0_value set |gen|'s type and value to |type| and |value|. |
| 2144 | // |type| must be a |GEN_*| constant and |value| must be an object of the |
| 2145 | // corresponding type. |gen| takes ownership of |value|, so |value| must have |
| 2146 | // been an allocated object. |
| 2147 | // |
| 2148 | // WARNING: |gen| must be empty (typically as returned from |GENERAL_NAME_new|) |
| 2149 | // before calling this function. If |gen| already contained a value, the |
| 2150 | // previous contents will be leaked. |
| 2151 | OPENSSL_EXPORT void GENERAL_NAME_set0_value(GENERAL_NAME *gen, int type, |
| 2152 | void *value); |
| 2153 |
| 2154 | // GENERAL_NAME_get0_value returns the in-memory representation of |gen|'s |
| 2155 | // contents and, |out_type| is not NULL, sets |*out_type| to the type of |gen|, |
| 2156 | // which will be a |GEN_*| constant. If |gen| is incomplete, the return value |
| 2157 | // will be NULL and the type will be -1. |
| 2158 | // |
| 2159 | // WARNING: Casting the result of this function to the wrong type is a |
| 2160 | // potentially exploitable memory error. Callers must check |gen|'s type, either |
| 2161 | // via |*out_type| or checking |gen->type| directly, before inspecting the |
| 2162 | // result. |
| 2163 | // |
| 2164 | // WARNING: This function is not const-correct. The return value should be |
| 2165 | // const. Callers shoudl not mutate the returned object. |
| 2166 | OPENSSL_EXPORT void *GENERAL_NAME_get0_value(const GENERAL_NAME *gen, |
| 2167 | int *out_type); |
| 2168 |
| 2169 | // GENERAL_NAME_set0_othername sets |gen| to be an OtherName with type |oid| and |
| 2170 | // value |value|. On success, it returns one and takes ownership of |oid| and |
| 2171 | // |value|, which must be created in a way compatible with |ASN1_OBJECT_free| |
| 2172 | // and |ASN1_TYPE_free|, respectively. On allocation failure, it returns zero. |
| 2173 | // In the failure case, the caller retains ownership of |oid| and |value| and |
| 2174 | // must release them when done. |
| 2175 | // |
| 2176 | // WARNING: |gen| must be empty (typically as returned from |GENERAL_NAME_new|) |
| 2177 | // before calling this function. If |gen| already contained a value, the |
| 2178 | // previously contents will be leaked. |
| 2179 | OPENSSL_EXPORT int GENERAL_NAME_set0_othername(GENERAL_NAME *gen, |
| 2180 | ASN1_OBJECT *oid, |
| 2181 | ASN1_TYPE *value); |
| 2182 |
| 2183 | // GENERAL_NAME_get0_otherName, if |gen| is an OtherName, sets |*out_oid| and |
| 2184 | // |*out_value| to the OtherName's type-id and value, respectively, and returns |
| 2185 | // one. If |gen| is not an OtherName, it returns zero and leaves |*out_oid| and |
| 2186 | // |*out_value| unmodified. Either of |out_oid| or |out_value| may be NULL to |
| 2187 | // ignore the value. |
| 2188 | // |
| 2189 | // WARNING: This function is not const-correct. |out_oid| and |out_value| are |
| 2190 | // not const, but callers should not mutate the resulting objects. |
| 2191 | OPENSSL_EXPORT int GENERAL_NAME_get0_otherName(const GENERAL_NAME *gen, |
| 2192 | ASN1_OBJECT **out_oid, |
| 2193 | ASN1_TYPE **out_value); |
| 2194 |
| 2195 |
| 2196 | // Authority key identifier. |
| 2197 | // |
| 2198 | // The authority key identifier extension (RFC 5280, section 4.2.1.1) allows a |
| 2199 | // certificate to more precisely identify its issuer. This is helpful when |
| 2200 | // multiple certificates share a name. Only the keyIdentifier (|keyid| in |
| 2201 | // |AUTHORITY_KEYID|) field is used in practice. |
| 2202 |
| 2203 | // A AUTHORITY_KEYID_st, aka |AUTHORITY_KEYID|, represents an |
| 2204 | // AuthorityKeyIdentifier structure (RFC 5280). |
| 2205 | struct AUTHORITY_KEYID_st { |
| 2206 | ASN1_OCTET_STRING *keyid; |
| 2207 | GENERAL_NAMES *issuer; |
| 2208 | ASN1_INTEGER *serial; |
| 2209 | } /* AUTHORITY_KEYID */; |
| 2210 |
| 2211 | // AUTHORITY_KEYID is an |ASN1_ITEM| whose ASN.1 type is AuthorityKeyIdentifier |
| 2212 | // (RFC 5280) and C type is |AUTHORITY_KEYID*|. |
| 2213 | DECLARE_ASN1_ITEM(AUTHORITY_KEYID) |
| 2214 |
| 2215 | // AUTHORITY_KEYID_new returns a newly-allocated, empty |AUTHORITY_KEYID| |
| 2216 | // object, or NULL on error. |
| 2217 | OPENSSL_EXPORT AUTHORITY_KEYID *AUTHORITY_KEYID_new(void); |
| 2218 |
| 2219 | // AUTHORITY_KEYID_free releases memory associated with |akid|. |
| 2220 | OPENSSL_EXPORT void AUTHORITY_KEYID_free(AUTHORITY_KEYID *akid); |
| 2221 |
| 2222 | // d2i_AUTHORITY_KEYID parses up to |len| bytes from |*inp| as a DER-encoded |
| 2223 | // AuthorityKeyIdentifier (RFC 5280), as described in |d2i_SAMPLE|. |
| 2224 | OPENSSL_EXPORT AUTHORITY_KEYID *d2i_AUTHORITY_KEYID(AUTHORITY_KEYID **out, |
| 2225 | const uint8_t **inp, |
| 2226 | long len); |
| 2227 |
| 2228 | // i2d_AUTHORITY_KEYID marshals |akid| as a DER-encoded AuthorityKeyIdentifier |
| 2229 | // (RFC 5280), as described in |i2d_SAMPLE|. |
| 2230 | // |
| 2231 | // TODO(https://crbug.com/boringssl/407): |akid| is not const because it |
| 2232 | // contains an |X509_NAME|. |
| 2233 | OPENSSL_EXPORT int i2d_AUTHORITY_KEYID(AUTHORITY_KEYID *akid, uint8_t **outp); |
| 2234 |
| 2235 |
| 2236 | // Name constraints. |
| 2237 | // |
| 2238 | // The name constraints extension (RFC 5280, section 4.2.1.10) constrains which |
| 2239 | // names may be asserted by certificates issued by some CA. For example, a |
| 2240 | // general CA may issue an intermediate certificate to the owner of example.com, |
| 2241 | // but constrained to ".example.com". |
| 2242 |
| 2243 | // A GENERAL_SUBTREE represents a GeneralSubtree structure (RFC 5280). |
| 2244 | typedef struct GENERAL_SUBTREE_st { |
| 2245 | GENERAL_NAME *base; |
| 2246 | ASN1_INTEGER *minimum; |
| 2247 | ASN1_INTEGER *maximum; |
| 2248 | } GENERAL_SUBTREE; |
| 2249 |
| 2250 | DEFINE_STACK_OF(GENERAL_SUBTREE) |
| 2251 |
| 2252 | // GENERAL_SUBTREE_new returns a newly-allocated, empty |GENERAL_SUBTREE| |
| 2253 | // object, or NULL on error. |
| 2254 | OPENSSL_EXPORT GENERAL_SUBTREE *GENERAL_SUBTREE_new(void); |
| 2255 |
| 2256 | // GENERAL_SUBTREE_free releases memory associated with |subtree|. |
| 2257 | OPENSSL_EXPORT void GENERAL_SUBTREE_free(GENERAL_SUBTREE *subtree); |
| 2258 |
| 2259 | // A NAME_CONSTRAINTS_st, aka |NAME_CONSTRAINTS|, represents a NameConstraints |
| 2260 | // structure (RFC 5280). |
| 2261 | struct NAME_CONSTRAINTS_st { |
| 2262 | STACK_OF(GENERAL_SUBTREE) *permittedSubtrees; |
| 2263 | STACK_OF(GENERAL_SUBTREE) *excludedSubtrees; |
| 2264 | } /* NAME_CONSTRAINTS */; |
| 2265 |
| 2266 | // NAME_CONSTRAINTS is an |ASN1_ITEM| whose ASN.1 type is NameConstraints (RFC |
| 2267 | // 5280) and C type is |NAME_CONSTRAINTS*|. |
| 2268 | DECLARE_ASN1_ITEM(NAME_CONSTRAINTS) |
| 2269 |
| 2270 | // NAME_CONSTRAINTS_new returns a newly-allocated, empty |NAME_CONSTRAINTS| |
| 2271 | // object, or NULL on error. |
| 2272 | OPENSSL_EXPORT NAME_CONSTRAINTS *NAME_CONSTRAINTS_new(void); |
| 2273 |
| 2274 | // NAME_CONSTRAINTS_free releases memory associated with |ncons|. |
| 2275 | OPENSSL_EXPORT void NAME_CONSTRAINTS_free(NAME_CONSTRAINTS *ncons); |
| 2276 |
| 2277 |
| 2278 | // Authority information access. |
| 2279 | // |
| 2280 | // The authority information access extension (RFC 5280, 4.2.2.1) describes |
| 2281 | // where to obtain information about the issuer of a certificate. It is most |
| 2282 | // commonly used with accessMethod values of id-ad-caIssuers and id-ad-ocsp, to |
| 2283 | // indicate where to fetch the issuer certificate (if not provided in-band) and |
| 2284 | // the issuer's OCSP responder, respectively. |
| 2285 |
| 2286 | // An ACCESS_DESCRIPTION represents an AccessDescription structure (RFC 5280). |
| 2287 | typedef struct ACCESS_DESCRIPTION_st { |
| 2288 | ASN1_OBJECT *method; |
| 2289 | GENERAL_NAME *location; |
| 2290 | } ACCESS_DESCRIPTION; |
| 2291 |
| 2292 | DEFINE_STACK_OF(ACCESS_DESCRIPTION) |
| 2293 |
| 2294 | // ACCESS_DESCRIPTION_new returns a newly-allocated, empty |ACCESS_DESCRIPTION| |
| 2295 | // object, or NULL on error. |
| 2296 | OPENSSL_EXPORT ACCESS_DESCRIPTION *ACCESS_DESCRIPTION_new(void); |
| 2297 |
| 2298 | // ACCESS_DESCRIPTION_free releases memory associated with |desc|. |
| 2299 | OPENSSL_EXPORT void ACCESS_DESCRIPTION_free(ACCESS_DESCRIPTION *desc); |
| 2300 |
| 2301 | typedef STACK_OF(ACCESS_DESCRIPTION) AUTHORITY_INFO_ACCESS; |
| 2302 |
| 2303 | // AUTHORITY_INFO_ACCESS is an |ASN1_ITEM| whose ASN.1 type is |
| 2304 | // AuthorityInfoAccessSyntax (RFC 5280) and C type is |
| 2305 | // |STACK_OF(ACCESS_DESCRIPTION)*|, or |AUTHORITY_INFO_ACCESS*|. |
| 2306 | DECLARE_ASN1_ITEM(AUTHORITY_INFO_ACCESS) |
| 2307 |
| 2308 | // AUTHORITY_INFO_ACCESS_new returns a newly-allocated, empty |
| 2309 | // |AUTHORITY_INFO_ACCESS| object, or NULL on error. |
| 2310 | OPENSSL_EXPORT AUTHORITY_INFO_ACCESS *AUTHORITY_INFO_ACCESS_new(void); |
| 2311 |
| 2312 | // AUTHORITY_INFO_ACCESS_free releases memory associated with |aia|. |
| 2313 | OPENSSL_EXPORT void AUTHORITY_INFO_ACCESS_free(AUTHORITY_INFO_ACCESS *aia); |
| 2314 |
| 2315 | // d2i_AUTHORITY_INFO_ACCESS parses up to |len| bytes from |*inp| as a |
| 2316 | // DER-encoded AuthorityInfoAccessSyntax (RFC 5280), as described in |
| 2317 | // |d2i_SAMPLE|. |
| 2318 | OPENSSL_EXPORT AUTHORITY_INFO_ACCESS *d2i_AUTHORITY_INFO_ACCESS( |
| 2319 | AUTHORITY_INFO_ACCESS **out, const uint8_t **inp, long len); |
| 2320 |
| 2321 | // i2d_AUTHORITY_INFO_ACCESS marshals |aia| as a DER-encoded |
| 2322 | // AuthorityInfoAccessSyntax (RFC 5280), as described in |i2d_SAMPLE|. |
| 2323 | // |
| 2324 | // TODO(https://crbug.com/boringssl/407): |aia| is not const because it |
| 2325 | // contains an |X509_NAME|. |
| 2326 | OPENSSL_EXPORT int i2d_AUTHORITY_INFO_ACCESS(AUTHORITY_INFO_ACCESS *aia, |
| 2327 | uint8_t **outp); |
| 2328 |
| 2329 |
| 2330 | // CRL distribution points. |
| 2331 | // |
| 2332 | // The CRL distribution points extension (RFC 5280, 4.2.1.13) indicates where to |
| 2333 | // fetch a certificate issuer's CRL. The corresponding issuing distribution |
| 2334 | // point CRL extension (RFC 5280, section 5.2.5) matches against this extension. |
| 2335 |
| 2336 | // A DIST_POINT_NAME represents a DistributionPointName structure (RFC 5280). |
| 2337 | // The |name| field contains the CHOICE value and is determined by |type|. If |
| 2338 | // |type| is zero, |name| must be a |fullname|. If |type| is one, |name| must be |
| 2339 | // a |relativename|. |
| 2340 | // |
| 2341 | // WARNING: |type| and |name| must be kept consistent. An inconsistency will |
| 2342 | // result in a potentially exploitable memory error. |
| 2343 | typedef struct DIST_POINT_NAME_st { |
| 2344 | int type; |
| 2345 | union { |
| 2346 | GENERAL_NAMES *fullname; |
| 2347 | STACK_OF(X509_NAME_ENTRY) *relativename; |
| 2348 | } name; |
| 2349 | // If relativename then this contains the full distribution point name |
| 2350 | X509_NAME *dpname; |
| 2351 | } DIST_POINT_NAME; |
| 2352 |
| 2353 | // DIST_POINT_NAME_new returns a newly-allocated, empty |DIST_POINT_NAME| |
| 2354 | // object, or NULL on error. |
| 2355 | OPENSSL_EXPORT DIST_POINT_NAME *DIST_POINT_NAME_new(void); |
| 2356 |
| 2357 | // DIST_POINT_NAME_free releases memory associated with |name|. |
| 2358 | OPENSSL_EXPORT void DIST_POINT_NAME_free(DIST_POINT_NAME *name); |
| 2359 |
| 2360 | // A DIST_POINT_st, aka |DIST_POINT|, represents a DistributionPoint structure |
| 2361 | // (RFC 5280). |
| 2362 | struct DIST_POINT_st { |
| 2363 | DIST_POINT_NAME *distpoint; |
| 2364 | ASN1_BIT_STRING *reasons; |
| 2365 | GENERAL_NAMES *CRLissuer; |
| 2366 | } /* DIST_POINT */; |
| 2367 |
| 2368 | DEFINE_STACK_OF(DIST_POINT) |
| 2369 |
| 2370 | // DIST_POINT_new returns a newly-allocated, empty |DIST_POINT| object, or NULL |
| 2371 | // on error. |
| 2372 | OPENSSL_EXPORT DIST_POINT *DIST_POINT_new(void); |
| 2373 |
| 2374 | // DIST_POINT_free releases memory associated with |dp|. |
| 2375 | OPENSSL_EXPORT void DIST_POINT_free(DIST_POINT *dp); |
| 2376 |
| 2377 | typedef STACK_OF(DIST_POINT) CRL_DIST_POINTS; |
| 2378 |
| 2379 | // CRL_DIST_POINTS is an |ASN1_ITEM| whose ASN.1 type is CRLDistributionPoints |
| 2380 | // (RFC 5280) and C type is |CRL_DIST_POINTS*|. |
| 2381 | DECLARE_ASN1_ITEM(CRL_DIST_POINTS) |
| 2382 |
| 2383 | // CRL_DIST_POINTS_new returns a newly-allocated, empty |CRL_DIST_POINTS| |
| 2384 | // object, or NULL on error. |
| 2385 | OPENSSL_EXPORT CRL_DIST_POINTS *CRL_DIST_POINTS_new(void); |
| 2386 |
| 2387 | // CRL_DIST_POINTS_free releases memory associated with |crldp|. |
| 2388 | OPENSSL_EXPORT void CRL_DIST_POINTS_free(CRL_DIST_POINTS *crldp); |
| 2389 |
| 2390 | // d2i_CRL_DIST_POINTS parses up to |len| bytes from |*inp| as a DER-encoded |
| 2391 | // CRLDistributionPoints (RFC 5280), as described in |d2i_SAMPLE|. |
| 2392 | OPENSSL_EXPORT CRL_DIST_POINTS *d2i_CRL_DIST_POINTS(CRL_DIST_POINTS **out, |
| 2393 | const uint8_t **inp, |
| 2394 | long len); |
| 2395 |
| 2396 | // i2d_CRL_DIST_POINTS marshals |crldp| as a DER-encoded CRLDistributionPoints |
| 2397 | // (RFC 5280), as described in |i2d_SAMPLE|. |
| 2398 | // |
| 2399 | // TODO(https://crbug.com/boringssl/407): |crldp| is not const because it |
| 2400 | // contains an |X509_NAME|. |
| 2401 | OPENSSL_EXPORT int i2d_CRL_DIST_POINTS(CRL_DIST_POINTS *crldp, uint8_t **outp); |
| 2402 |
| 2403 | // A ISSUING_DIST_POINT_st, aka |ISSUING_DIST_POINT|, represents a |
| 2404 | // IssuingDistributionPoint structure (RFC 5280). |
| 2405 | struct ISSUING_DIST_POINT_st { |
| 2406 | DIST_POINT_NAME *distpoint; |
| 2407 | ASN1_BOOLEAN onlyuser; |
| 2408 | ASN1_BOOLEAN onlyCA; |
| 2409 | ASN1_BIT_STRING *onlysomereasons; |
| 2410 | ASN1_BOOLEAN indirectCRL; |
| 2411 | ASN1_BOOLEAN onlyattr; |
| 2412 | } /* ISSUING_DIST_POINT */; |
| 2413 |
| 2414 | // ISSUING_DIST_POINT is an |ASN1_ITEM| whose ASN.1 type is |
| 2415 | // IssuingDistributionPoint (RFC 5280) and C type is |ISSUING_DIST_POINT*|. |
| 2416 | DECLARE_ASN1_ITEM(ISSUING_DIST_POINT) |
| 2417 |
| 2418 | // ISSUING_DIST_POINT_new returns a newly-allocated, empty |ISSUING_DIST_POINT| |
| 2419 | // object, or NULL on error. |
| 2420 | OPENSSL_EXPORT ISSUING_DIST_POINT *ISSUING_DIST_POINT_new(void); |
| 2421 |
| 2422 | // ISSUING_DIST_POINT_free releases memory associated with |idp|. |
| 2423 | OPENSSL_EXPORT void ISSUING_DIST_POINT_free(ISSUING_DIST_POINT *idp); |
| 2424 |
| 2425 | // d2i_ISSUING_DIST_POINT parses up to |len| bytes from |*inp| as a DER-encoded |
| 2426 | // IssuingDistributionPoint (RFC 5280), as described in |d2i_SAMPLE|. |
| 2427 | OPENSSL_EXPORT ISSUING_DIST_POINT *d2i_ISSUING_DIST_POINT( |
| 2428 | ISSUING_DIST_POINT **out, const uint8_t **inp, long len); |
| 2429 |
| 2430 | // i2d_ISSUING_DIST_POINT marshals |idp| as a DER-encoded |
| 2431 | // IssuingDistributionPoint (RFC 5280), as described in |i2d_SAMPLE|. |
| 2432 | // |
| 2433 | // TODO(https://crbug.com/boringssl/407): |idp| is not const because it |
| 2434 | // contains an |X509_NAME|. |
| 2435 | OPENSSL_EXPORT int i2d_ISSUING_DIST_POINT(ISSUING_DIST_POINT *idp, |
| 2436 | uint8_t **outp); |
| 2437 |
| 2438 |
| 2439 | // Certificate policies. |
| 2440 | // |
| 2441 | // The certificate policies extension (RFC 5280, section 4.2.1.4), along with a |
| 2442 | // suite of related extensions determines the "policies" that apply to a |
| 2443 | // certificate path. Evaluating these policies is extremely complex and has led |
| 2444 | // to denial-of-service vulnerabilities in several X.509 implementations. See |
| 2445 | // draft-ietf-lamps-x509-policy-graph. |
| 2446 | // |
| 2447 | // Do not use this mechanism. |
| 2448 |
| 2449 | // A NOTICEREF represents a NoticeReference structure (RFC 5280). |
| 2450 | typedef struct NOTICEREF_st { |
| 2451 | ASN1_STRING *organization; |
| 2452 | STACK_OF(ASN1_INTEGER) *noticenos; |
| 2453 | } NOTICEREF; |
| 2454 |
| 2455 | // NOTICEREF_new returns a newly-allocated, empty |NOTICEREF| object, or NULL |
| 2456 | // on error. |
| 2457 | OPENSSL_EXPORT NOTICEREF *NOTICEREF_new(void); |
| 2458 |
| 2459 | // NOTICEREF_free releases memory associated with |ref|. |
| 2460 | OPENSSL_EXPORT void NOTICEREF_free(NOTICEREF *ref); |
| 2461 |
| 2462 | // A USERNOTICE represents a UserNotice structure (RFC 5280). |
| 2463 | typedef struct USERNOTICE_st { |
| 2464 | NOTICEREF *noticeref; |
| 2465 | ASN1_STRING *exptext; |
| 2466 | } USERNOTICE; |
| 2467 |
| 2468 | // USERNOTICE_new returns a newly-allocated, empty |USERNOTICE| object, or NULL |
| 2469 | // on error. |
| 2470 | OPENSSL_EXPORT USERNOTICE *USERNOTICE_new(void); |
| 2471 |
| 2472 | // USERNOTICE_free releases memory associated with |notice|. |
| 2473 | OPENSSL_EXPORT void USERNOTICE_free(USERNOTICE *notice); |
| 2474 |
| 2475 | // A POLICYQUALINFO represents a PolicyQualifierInfo structure (RFC 5280). |d| |
| 2476 | // contains the qualifier field of the PolicyQualifierInfo. Its type is |
| 2477 | // determined by |pqualid|. If |pqualid| is |NID_id_qt_cps|, |d| must be |
| 2478 | // |cpsuri|. If |pqualid| is |NID_id_qt_unotice|, |d| must be |usernotice|. |
| 2479 | // Otherwise, |d| must be |other|. |
| 2480 | // |
| 2481 | // WARNING: |pqualid| and |d| must be kept consistent. An inconsistency will |
| 2482 | // result in a potentially exploitable memory error. |
| 2483 | typedef struct POLICYQUALINFO_st { |
| 2484 | ASN1_OBJECT *pqualid; |
| 2485 | union { |
| 2486 | ASN1_IA5STRING *cpsuri; |
| 2487 | USERNOTICE *usernotice; |
| 2488 | ASN1_TYPE *other; |
| 2489 | } d; |
| 2490 | } POLICYQUALINFO; |
| 2491 |
| 2492 | DEFINE_STACK_OF(POLICYQUALINFO) |
| 2493 |
| 2494 | // POLICYQUALINFO_new returns a newly-allocated, empty |POLICYQUALINFO| object, |
| 2495 | // or NULL on error. |
| 2496 | OPENSSL_EXPORT POLICYQUALINFO *POLICYQUALINFO_new(void); |
| 2497 |
| 2498 | // POLICYQUALINFO_free releases memory associated with |info|. |
| 2499 | OPENSSL_EXPORT void POLICYQUALINFO_free(POLICYQUALINFO *info); |
| 2500 |
| 2501 | // A POLICYINFO represents a PolicyInformation structure (RFC 5280). |
| 2502 | typedef struct POLICYINFO_st { |
| 2503 | ASN1_OBJECT *policyid; |
| 2504 | STACK_OF(POLICYQUALINFO) *qualifiers; |
| 2505 | } POLICYINFO; |
| 2506 |
| 2507 | DEFINE_STACK_OF(POLICYINFO) |
| 2508 |
| 2509 | // POLICYINFO_new returns a newly-allocated, empty |POLICYINFO| object, or NULL |
| 2510 | // on error. |
| 2511 | OPENSSL_EXPORT POLICYINFO *POLICYINFO_new(void); |
| 2512 |
| 2513 | // POLICYINFO_free releases memory associated with |info|. |
| 2514 | OPENSSL_EXPORT void POLICYINFO_free(POLICYINFO *info); |
| 2515 |
| 2516 | typedef STACK_OF(POLICYINFO) CERTIFICATEPOLICIES; |
| 2517 |
| 2518 | // CERTIFICATEPOLICIES is an |ASN1_ITEM| whose ASN.1 type is CertificatePolicies |
| 2519 | // (RFC 5280) and C type is |STACK_OF(POLICYINFO)*|, or |CERTIFICATEPOLICIES*|. |
| 2520 | DECLARE_ASN1_ITEM(CERTIFICATEPOLICIES) |
| 2521 |
| 2522 | // CERTIFICATEPOLICIES_new returns a newly-allocated, empty |
| 2523 | // |CERTIFICATEPOLICIES| object, or NULL on error. |
| 2524 | OPENSSL_EXPORT CERTIFICATEPOLICIES *CERTIFICATEPOLICIES_new(void); |
| 2525 |
| 2526 | // CERTIFICATEPOLICIES_free releases memory associated with |policies|. |
| 2527 | OPENSSL_EXPORT void CERTIFICATEPOLICIES_free(CERTIFICATEPOLICIES *policies); |
| 2528 |
| 2529 | // d2i_CERTIFICATEPOLICIES parses up to |len| bytes from |*inp| as a DER-encoded |
| 2530 | // CertificatePolicies (RFC 5280), as described in |d2i_SAMPLE|. |
| 2531 | OPENSSL_EXPORT CERTIFICATEPOLICIES *d2i_CERTIFICATEPOLICIES( |
| 2532 | CERTIFICATEPOLICIES **out, const uint8_t **inp, long len); |
| 2533 |
| 2534 | // i2d_CERTIFICATEPOLICIES marshals |policies| as a DER-encoded |
| 2535 | // CertificatePolicies (RFC 5280), as described in |i2d_SAMPLE|. |
| 2536 | OPENSSL_EXPORT int i2d_CERTIFICATEPOLICIES(const CERTIFICATEPOLICIES *policies, |
| 2537 | uint8_t **outp); |
| 2538 |
| 2539 | // A POLICY_MAPPING represents an individual element of a PolicyMappings |
| 2540 | // structure (RFC 5280). |
| 2541 | typedef struct POLICY_MAPPING_st { |
| 2542 | ASN1_OBJECT *issuerDomainPolicy; |
| 2543 | ASN1_OBJECT *subjectDomainPolicy; |
| 2544 | } POLICY_MAPPING; |
| 2545 |
| 2546 | DEFINE_STACK_OF(POLICY_MAPPING) |
| 2547 |
| 2548 | // POLICY_MAPPING_new returns a newly-allocated, empty |POLICY_MAPPING| object, |
| 2549 | // or NULL on error. |
| 2550 | OPENSSL_EXPORT POLICY_MAPPING *POLICY_MAPPING_new(void); |
| 2551 |
| 2552 | // POLICY_MAPPING_free releases memory associated with |mapping|. |
| 2553 | OPENSSL_EXPORT void POLICY_MAPPING_free(POLICY_MAPPING *mapping); |
| 2554 |
| 2555 | typedef STACK_OF(POLICY_MAPPING) POLICY_MAPPINGS; |
| 2556 |
| 2557 | // POLICY_MAPPINGS is an |ASN1_ITEM| whose ASN.1 type is PolicyMappings (RFC |
| 2558 | // 5280) and C type is |STACK_OF(POLICY_MAPPING)*|, or |POLICY_MAPPINGS*|. |
| 2559 | DECLARE_ASN1_ITEM(POLICY_MAPPINGS) |
| 2560 |
| 2561 | // A POLICY_CONSTRAINTS represents a PolicyConstraints structure (RFC 5280). |
| 2562 | typedef struct POLICY_CONSTRAINTS_st { |
| 2563 | ASN1_INTEGER *requireExplicitPolicy; |
| 2564 | ASN1_INTEGER *inhibitPolicyMapping; |
| 2565 | } POLICY_CONSTRAINTS; |
| 2566 |
| 2567 | // POLICY_CONSTRAINTS is an |ASN1_ITEM| whose ASN.1 type is PolicyConstraints |
| 2568 | // (RFC 5280) and C type is |POLICY_CONSTRAINTS*|. |
| 2569 | DECLARE_ASN1_ITEM(POLICY_CONSTRAINTS) |
| 2570 |
| 2571 | // POLICY_CONSTRAINTS_new returns a newly-allocated, empty |POLICY_CONSTRAINTS| |
| 2572 | // object, or NULL on error. |
| 2573 | OPENSSL_EXPORT POLICY_CONSTRAINTS *POLICY_CONSTRAINTS_new(void); |
| 2574 |
| 2575 | // POLICY_CONSTRAINTS_free releases memory associated with |pcons|. |
| 2576 | OPENSSL_EXPORT void POLICY_CONSTRAINTS_free(POLICY_CONSTRAINTS *pcons); |
| 2577 |
| 2578 |
| 2579 | // Algorithm identifiers. |
| 2580 | // |
| 2581 | // An |X509_ALGOR| represents an AlgorithmIdentifier structure, used in X.509 |
| 2582 | // to represent signature algorithms and public key algorithms. |
| 2583 |
| 2584 | DEFINE_STACK_OF(X509_ALGOR) |
| 2585 |
| 2586 | // X509_ALGOR is an |ASN1_ITEM| whose ASN.1 type is AlgorithmIdentifier and C |
| 2587 | // type is |X509_ALGOR*|. |
| 2588 | DECLARE_ASN1_ITEM(X509_ALGOR) |
| 2589 |
| 2590 | // X509_ALGOR_new returns a newly-allocated, empty |X509_ALGOR| object, or NULL |
| 2591 | // on error. |
| 2592 | OPENSSL_EXPORT X509_ALGOR *X509_ALGOR_new(void); |
| 2593 |
| 2594 | // X509_ALGOR_dup returns a newly-allocated copy of |alg|, or NULL on error. |
| 2595 | // This function works by serializing the structure, so if |alg| is incomplete, |
| 2596 | // it may fail. |
| 2597 | OPENSSL_EXPORT X509_ALGOR *X509_ALGOR_dup(const X509_ALGOR *alg); |
| 2598 |
| 2599 | // X509_ALGOR_free releases memory associated with |alg|. |
| 2600 | OPENSSL_EXPORT void X509_ALGOR_free(X509_ALGOR *alg); |
| 2601 |
| 2602 | // d2i_X509_ALGOR parses up to |len| bytes from |*inp| as a DER-encoded |
| 2603 | // AlgorithmIdentifier, as described in |d2i_SAMPLE|. |
| 2604 | OPENSSL_EXPORT X509_ALGOR *d2i_X509_ALGOR(X509_ALGOR **out, const uint8_t **inp, |
| 2605 | long len); |
| 2606 |
| 2607 | // i2d_X509_ALGOR marshals |alg| as a DER-encoded AlgorithmIdentifier, as |
| 2608 | // described in |i2d_SAMPLE|. |
| 2609 | OPENSSL_EXPORT int i2d_X509_ALGOR(const X509_ALGOR *alg, uint8_t **outp); |
| 2610 |
| 2611 | // X509_ALGOR_set0 sets |alg| to an AlgorithmIdentifier with algorithm |obj| and |
| 2612 | // parameter determined by |param_type| and |param_value|. It returns one on |
| 2613 | // success and zero on error. This function takes ownership of |obj| and |
| 2614 | // |param_value| on success. |
| 2615 | // |
| 2616 | // If |param_type| is |V_ASN1_UNDEF|, the parameter is omitted. If |param_type| |
| 2617 | // is zero, the parameter is left unchanged. Otherwise, |param_type| and |
| 2618 | // |param_value| are interpreted as in |ASN1_TYPE_set|. |
| 2619 | // |
| 2620 | // Note omitting the parameter (|V_ASN1_UNDEF|) and encoding an explicit NULL |
| 2621 | // value (|V_ASN1_NULL|) are different. Some algorithms require one and some the |
| 2622 | // other. Consult the relevant specification before calling this function. The |
| 2623 | // correct parameter for an RSASSA-PKCS1-v1_5 signature is |V_ASN1_NULL|. The |
| 2624 | // correct one for an ECDSA or Ed25519 signature is |V_ASN1_UNDEF|. |
| 2625 | OPENSSL_EXPORT int X509_ALGOR_set0(X509_ALGOR *alg, ASN1_OBJECT *obj, |
| 2626 | int param_type, void *param_value); |
| 2627 |
| 2628 | // X509_ALGOR_get0 sets |*out_obj| to the |alg|'s algorithm. If |alg|'s |
| 2629 | // parameter is omitted, it sets |*out_param_type| and |*out_param_value| to |
| 2630 | // |V_ASN1_UNDEF| and NULL. Otherwise, it sets |*out_param_type| and |
| 2631 | // |*out_param_value| to the parameter, using the same representation as |
| 2632 | // |ASN1_TYPE_set0|. See |ASN1_TYPE_set0| and |ASN1_TYPE| for details. |
| 2633 | // |
| 2634 | // Callers that require the parameter in serialized form should, after checking |
| 2635 | // for |V_ASN1_UNDEF|, use |ASN1_TYPE_set1| and |d2i_ASN1_TYPE|, rather than |
| 2636 | // inspecting |*out_param_value|. |
| 2637 | // |
| 2638 | // Each of |out_obj|, |out_param_type|, and |out_param_value| may be NULL to |
| 2639 | // ignore the output. If |out_param_type| is NULL, |out_param_value| is ignored. |
| 2640 | // |
| 2641 | // WARNING: If |*out_param_type| is set to |V_ASN1_UNDEF|, OpenSSL and older |
| 2642 | // revisions of BoringSSL leave |*out_param_value| unset rather than setting it |
| 2643 | // to NULL. Callers that support both OpenSSL and BoringSSL should not assume |
| 2644 | // |*out_param_value| is uniformly initialized. |
| 2645 | OPENSSL_EXPORT void X509_ALGOR_get0(const ASN1_OBJECT **out_obj, |
| 2646 | int *out_param_type, |
| 2647 | const void **out_param_value, |
| 2648 | const X509_ALGOR *alg); |
| 2649 |
| 2650 | // X509_ALGOR_set_md sets |alg| to the hash function |md|. Note this |
| 2651 | // AlgorithmIdentifier represents the hash function itself, not a signature |
| 2652 | // algorithm that uses |md|. It returns one on success and zero on error. |
| 2653 | // |
| 2654 | // Due to historical specification mistakes (see Section 2.1 of RFC 4055), the |
| 2655 | // parameters field is sometimes omitted and sometimes a NULL value. When used |
| 2656 | // in RSASSA-PSS and RSAES-OAEP, it should be a NULL value. In other contexts, |
| 2657 | // the parameters should be omitted. This function assumes the caller is |
| 2658 | // constructing a RSASSA-PSS or RSAES-OAEP AlgorithmIdentifier and includes a |
| 2659 | // NULL parameter. This differs from OpenSSL's behavior. |
| 2660 | // |
| 2661 | // TODO(davidben): Rename this function, or perhaps just add a bespoke API for |
| 2662 | // constructing PSS and move on. |
| 2663 | OPENSSL_EXPORT int X509_ALGOR_set_md(X509_ALGOR *alg, const EVP_MD *md); |
| 2664 |
| 2665 | // X509_ALGOR_cmp returns zero if |a| and |b| are equal, and some non-zero value |
| 2666 | // otherwise. Note this function can only be used for equality checks, not an |
| 2667 | // ordering. |
| 2668 | OPENSSL_EXPORT int X509_ALGOR_cmp(const X509_ALGOR *a, const X509_ALGOR *b); |
| 2669 |
| 2670 |
| 2671 | // Attributes. |
| 2672 | // |
| 2673 | // Unlike certificates and CRLs, CSRs use a separate Attribute structure (RFC |
| 2674 | // 2985, RFC 2986) for extensibility. This is represented by the library as |
| 2675 | // |X509_ATTRIBUTE|. |
| 2676 |
| 2677 | DEFINE_STACK_OF(X509_ATTRIBUTE) |
| 2678 |
| 2679 | // X509_ATTRIBUTE_new returns a newly-allocated, empty |X509_ATTRIBUTE| object, |
| 2680 | // or NULL on error. |X509_ATTRIBUTE_set1_*| may be used to finish initializing |
| 2681 | // it. |
| 2682 | OPENSSL_EXPORT X509_ATTRIBUTE *X509_ATTRIBUTE_new(void); |
| 2683 |
| 2684 | // X509_ATTRIBUTE_dup returns a newly-allocated copy of |attr|, or NULL on |
| 2685 | // error. This function works by serializing the structure, so if |attr| is |
| 2686 | // incomplete, it may fail. |
| 2687 | OPENSSL_EXPORT X509_ATTRIBUTE *X509_ATTRIBUTE_dup(const X509_ATTRIBUTE *attr); |
| 2688 |
| 2689 | // X509_ATTRIBUTE_free releases memory associated with |attr|. |
| 2690 | OPENSSL_EXPORT void X509_ATTRIBUTE_free(X509_ATTRIBUTE *attr); |
| 2691 |
| 2692 | // d2i_X509_ATTRIBUTE parses up to |len| bytes from |*inp| as a DER-encoded |
| 2693 | // Attribute (RFC 2986), as described in |d2i_SAMPLE|. |
| 2694 | OPENSSL_EXPORT X509_ATTRIBUTE *d2i_X509_ATTRIBUTE(X509_ATTRIBUTE **out, |
| 2695 | const uint8_t **inp, |
| 2696 | long len); |
| 2697 |
| 2698 | // i2d_X509_ATTRIBUTE marshals |alg| as a DER-encoded Attribute (RFC 2986), as |
| 2699 | // described in |i2d_SAMPLE|. |
| 2700 | OPENSSL_EXPORT int i2d_X509_ATTRIBUTE(const X509_ATTRIBUTE *alg, |
| 2701 | uint8_t **outp); |
| 2702 |
| 2703 | // X509_ATTRIBUTE_create returns a newly-allocated |X509_ATTRIBUTE|, or NULL on |
| 2704 | // error. The attribute has type |nid| and contains a single value determined by |
| 2705 | // |attrtype| and |value|, which are interpreted as in |ASN1_TYPE_set|. Note |
| 2706 | // this function takes ownership of |value|. |
| 2707 | OPENSSL_EXPORT X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int attrtype, |
| 2708 | void *value); |
| 2709 |
| 2710 | // X509_ATTRIBUTE_create_by_NID returns a newly-allocated |X509_ATTRIBUTE| of |
| 2711 | // type |nid|, or NULL on error. The value is determined as in |
| 2712 | // |X509_ATTRIBUTE_set1_data|. |
| 2713 | // |
| 2714 | // If |attr| is non-NULL, the resulting |X509_ATTRIBUTE| is also written to |
| 2715 | // |*attr|. If |*attr| was non-NULL when the function was called, |*attr| is |
| 2716 | // reused instead of creating a new object. |
| 2717 | // |
| 2718 | // WARNING: The interpretation of |attrtype|, |data|, and |len| is complex and |
| 2719 | // error-prone. See |X509_ATTRIBUTE_set1_data| for details. |
| 2720 | // |
| 2721 | // WARNING: The object reuse form is deprecated and may be removed in the |
| 2722 | // future. It also currently incorrectly appends to the reused object's value |
| 2723 | // set rather than overwriting it. |
| 2724 | OPENSSL_EXPORT X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_NID( |
| 2725 | X509_ATTRIBUTE **attr, int nid, int attrtype, const void *data, int len); |
| 2726 |
| 2727 | // X509_ATTRIBUTE_create_by_OBJ behaves like |X509_ATTRIBUTE_create_by_NID| |
| 2728 | // except the attribute's type is determined by |obj|. |
| 2729 | OPENSSL_EXPORT X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_OBJ( |
| 2730 | X509_ATTRIBUTE **attr, const ASN1_OBJECT *obj, int attrtype, |
| 2731 | const void *data, int len); |
| 2732 |
| 2733 | // X509_ATTRIBUTE_create_by_txt behaves like |X509_ATTRIBUTE_create_by_NID| |
| 2734 | // except the attribute's type is determined by calling |OBJ_txt2obj| with |
| 2735 | // |attrname|. |
| 2736 | OPENSSL_EXPORT X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_txt( |
| 2737 | X509_ATTRIBUTE **attr, const char *attrname, int type, |
| 2738 | const unsigned char *bytes, int len); |
| 2739 |
| 2740 | // X509_ATTRIBUTE_set1_object sets |attr|'s type to |obj|. It returns one on |
| 2741 | // success and zero on error. |
| 2742 | OPENSSL_EXPORT int X509_ATTRIBUTE_set1_object(X509_ATTRIBUTE *attr, |
| 2743 | const ASN1_OBJECT *obj); |
| 2744 |
| 2745 | // X509_ATTRIBUTE_set1_data appends a value to |attr|'s value set and returns |
| 2746 | // one on success or zero on error. The value is determined as follows: |
| 2747 | // |
| 2748 | // If |attrtype| is zero, this function returns one and does nothing. This form |
| 2749 | // may be used when calling |X509_ATTRIBUTE_create_by_*| to create an attribute |
| 2750 | // with an empty value set. Such attributes are invalid, but OpenSSL supports |
| 2751 | // creating them. |
| 2752 | // |
| 2753 | // Otherwise, if |attrtype| is a |MBSTRING_*| constant, the value is an ASN.1 |
| 2754 | // string. The string is determined by decoding |len| bytes from |data| in the |
| 2755 | // encoding specified by |attrtype|, and then re-encoding it in a form |
| 2756 | // appropriate for |attr|'s type. If |len| is -1, |strlen(data)| is used |
| 2757 | // instead. See |ASN1_STRING_set_by_NID| for details. |
| 2758 | // |
| 2759 | // Otherwise, if |len| is not -1, the value is an ASN.1 string. |attrtype| is an |
| 2760 | // |ASN1_STRING| type value and the |len| bytes from |data| are copied as the |
| 2761 | // type-specific representation of |ASN1_STRING|. See |ASN1_STRING| for details. |
| 2762 | // |
| 2763 | // Otherwise, if |len| is -1, the value is constructed by passing |attrtype| and |
| 2764 | // |data| to |ASN1_TYPE_set1|. That is, |attrtype| is an |ASN1_TYPE| type value, |
| 2765 | // and |data| is cast to the corresponding pointer type. |
| 2766 | // |
| 2767 | // WARNING: Despite the name, this function appends to |attr|'s value set, |
| 2768 | // rather than overwriting it. To overwrite the value set, create a new |
| 2769 | // |X509_ATTRIBUTE| with |X509_ATTRIBUTE_new|. |
| 2770 | // |
| 2771 | // WARNING: If using the |MBSTRING_*| form, pass a length rather than relying on |
| 2772 | // |strlen|. In particular, |strlen| will not behave correctly if the input is |
| 2773 | // |MBSTRING_BMP| or |MBSTRING_UNIV|. |
| 2774 | // |
| 2775 | // WARNING: This function currently misinterprets |V_ASN1_OTHER| as an |
| 2776 | // |MBSTRING_*| constant. This matches OpenSSL but means it is impossible to |
| 2777 | // construct a value with a non-universal tag. |
| 2778 | OPENSSL_EXPORT int X509_ATTRIBUTE_set1_data(X509_ATTRIBUTE *attr, int attrtype, |
| 2779 | const void *data, int len); |
| 2780 |
| 2781 | // X509_ATTRIBUTE_get0_data returns the |idx|th value of |attr| in a |
| 2782 | // type-specific representation to |attrtype|, or NULL if out of bounds or the |
| 2783 | // type does not match. |attrtype| is one of the type values in |ASN1_TYPE|. On |
| 2784 | // match, the return value uses the same representation as |ASN1_TYPE_set0|. See |
| 2785 | // |ASN1_TYPE| for details. |
| 2786 | OPENSSL_EXPORT void *X509_ATTRIBUTE_get0_data(X509_ATTRIBUTE *attr, int idx, |
| 2787 | int attrtype, void *unused); |
| 2788 |
| 2789 | // X509_ATTRIBUTE_count returns the number of values in |attr|. |
| 2790 | OPENSSL_EXPORT int X509_ATTRIBUTE_count(const X509_ATTRIBUTE *attr); |
| 2791 |
| 2792 | // X509_ATTRIBUTE_get0_object returns the type of |attr|. |
| 2793 | OPENSSL_EXPORT ASN1_OBJECT *X509_ATTRIBUTE_get0_object(X509_ATTRIBUTE *attr); |
| 2794 |
| 2795 | // X509_ATTRIBUTE_get0_type returns the |idx|th value in |attr|, or NULL if out |
| 2796 | // of bounds. Note this function returns one of |attr|'s values, not the type. |
| 2797 | OPENSSL_EXPORT ASN1_TYPE *X509_ATTRIBUTE_get0_type(X509_ATTRIBUTE *attr, |
| 2798 | int idx); |
| 2799 |
| 2800 |
| 2801 | // Certificate stores. |
| 2802 | // |
| 2803 | // An |X509_STORE| contains trusted certificates, CRLs, and verification |
| 2804 | // parameters that are shared between multiple certificate verifications. |
| 2805 | // |
| 2806 | // Certificates in an |X509_STORE| are referred to as "trusted certificates", |
| 2807 | // but an individual certificate verification may not necessarily treat every |
| 2808 | // trusted certificate as a trust anchor. See |X509_VERIFY_PARAM_set_trust| for |
| 2809 | // details. |
| 2810 | // |
| 2811 | // WARNING: Although a trusted certificate which fails the |
| 2812 | // |X509_VERIFY_PARAM_set_trust| check is functionally an untrusted |
| 2813 | // intermediate certificate, callers should not rely on this to configure |
| 2814 | // untrusted intermediates in an |X509_STORE|. The trust check is complex, so |
| 2815 | // this risks inadvertently treating it as a trust anchor. Instead, configure |
| 2816 | // untrusted intermediates with the |chain| parameter of |X509_STORE_CTX_init|. |
| 2817 | // |
| 2818 | // Certificates in |X509_STORE| may be specified in several ways: |
| 2819 | // - Added by |X509_STORE_add_cert|. |
| 2820 | // - Returned by an |X509_LOOKUP| added by |X509_STORE_add_lookup|. |
| 2821 | // |
| 2822 | // |X509_STORE|s are reference-counted and may be shared by certificate |
| 2823 | // verifications running concurrently on multiple threads. However, an |
| 2824 | // |X509_STORE|'s verification parameters may not be modified concurrently with |
| 2825 | // certificate verification or other operations. Unless otherwise documented, |
| 2826 | // functions which take const pointer may be used concurrently, while |
| 2827 | // functions which take a non-const pointer may not. Callers that wish to modify |
| 2828 | // verification parameters in a shared |X509_STORE| should instead modify |
| 2829 | // |X509_STORE_CTX|s individually. |
| 2830 | // |
| 2831 | // Objects in an |X509_STORE| are represented as an |X509_OBJECT|. Some |
| 2832 | // functions in this library return values with this type. |
| 2833 |
| 2834 | // X509_STORE_new returns a newly-allocated |X509_STORE|, or NULL on error. |
| 2835 | OPENSSL_EXPORT X509_STORE *X509_STORE_new(void); |
| 2836 |
| 2837 | // X509_STORE_up_ref adds one to the reference count of |store| and returns one. |
| 2838 | // Although |store| is not const, this function's use of |store| is thread-safe. |
| 2839 | OPENSSL_EXPORT int X509_STORE_up_ref(X509_STORE *store); |
| 2840 |
| 2841 | // X509_STORE_free releases memory associated with |store|. |
| 2842 | OPENSSL_EXPORT void X509_STORE_free(X509_STORE *store); |
| 2843 |
| 2844 | // X509_STORE_add_cert adds |x509| to |store| as a trusted certificate. It |
| 2845 | // returns one on success and zero on error. This function internally increments |
| 2846 | // |x509|'s reference count, so the caller retains ownership of |x509|. |
| 2847 | // |
| 2848 | // Certificates configured by this function are still subject to the checks |
| 2849 | // described in |X509_VERIFY_PARAM_set_trust|. |
| 2850 | // |
| 2851 | // Although |store| is not const, this function's use of |store| is thread-safe. |
| 2852 | // However, if this function is called concurrently with |X509_verify_cert|, it |
| 2853 | // is a race condition whether |x509| is available for issuer lookups. |
| 2854 | // Moreover, the result may differ for each issuer lookup performed by a single |
| 2855 | // |X509_verify_cert| call. |
| 2856 | OPENSSL_EXPORT int X509_STORE_add_cert(X509_STORE *store, X509 *x509); |
| 2857 |
| 2858 | // X509_STORE_add_crl adds |crl| to |store|. It returns one on success and zero |
| 2859 | // on error. This function internally increments |crl|'s reference count, so the |
| 2860 | // caller retains ownership of |crl|. CRLs added in this way are candidates for |
| 2861 | // CRL lookup when |X509_V_FLAG_CRL_CHECK| is set. |
| 2862 | // |
| 2863 | // Although |store| is not const, this function's use of |store| is thread-safe. |
| 2864 | // However, if this function is called concurrently with |X509_verify_cert|, it |
| 2865 | // is a race condition whether |crl| is available for CRL checks. Moreover, the |
| 2866 | // result may differ for each CRL check performed by a single |
| 2867 | // |X509_verify_cert| call. |
| 2868 | // |
| 2869 | // Note there are no supported APIs to remove CRLs from |store| once inserted. |
| 2870 | // To vary the set of CRLs over time, callers should either create a new |
| 2871 | // |X509_STORE| or configure CRLs on a per-verification basis with |
| 2872 | // |X509_STORE_CTX_set0_crls|. |
| 2873 | OPENSSL_EXPORT int X509_STORE_add_crl(X509_STORE *store, X509_CRL *crl); |
| 2874 |
| 2875 | // X509_STORE_get0_param returns |store|'s verification parameters. This object |
| 2876 | // is mutable and may be modified by the caller. For an individual certificate |
| 2877 | // verification operation, |X509_STORE_CTX_init| initializes the |
| 2878 | // |X509_STORE_CTX|'s parameters with these parameters. |
| 2879 | // |
| 2880 | // WARNING: |X509_STORE_CTX_init| applies some default parameters (as in |
| 2881 | // |X509_VERIFY_PARAM_inherit|) after copying |store|'s parameters. This means |
| 2882 | // it is impossible to leave some parameters unset at |store|. They must be |
| 2883 | // explicitly unset after creating the |X509_STORE_CTX|. |
| 2884 | // |
| 2885 | // As of writing these late defaults are a depth limit (see |
| 2886 | // |X509_VERIFY_PARAM_set_depth|) and the |X509_V_FLAG_TRUSTED_FIRST| flag. This |
| 2887 | // warning does not apply if the parameters were set in |store|. |
| 2888 | // |
| 2889 | // TODO(crbug.com/boringssl/441): This behavior is very surprising. Can we |
| 2890 | // remove this notion of late defaults? The unsettable value at |X509_STORE| is |
| 2891 | // -1, which rejects everything but explicitly-trusted self-signed certificates. |
| 2892 | // |X509_V_FLAG_TRUSTED_FIRST| is mostly a workaround for poor path-building. |
| 2893 | OPENSSL_EXPORT X509_VERIFY_PARAM *X509_STORE_get0_param(X509_STORE *store); |
| 2894 |
| 2895 | // X509_STORE_set1_param copies verification parameters from |param| as in |
| 2896 | // |X509_VERIFY_PARAM_set1|. It returns one on success and zero on error. |
| 2897 | OPENSSL_EXPORT int X509_STORE_set1_param(X509_STORE *store, |
| 2898 | const X509_VERIFY_PARAM *param); |
| 2899 |
| 2900 | // X509_STORE_set_flags enables all values in |flags| in |store|'s verification |
| 2901 | // flags. |flags| should be a combination of |X509_V_FLAG_*| constants. |
| 2902 | // |
| 2903 | // WARNING: These flags will be combined with default flags when copied to an |
| 2904 | // |X509_STORE_CTX|. This means it is impossible to unset those defaults from |
| 2905 | // the |X509_STORE|. See discussion in |X509_STORE_get0_param|. |
| 2906 | OPENSSL_EXPORT int X509_STORE_set_flags(X509_STORE *store, unsigned long flags); |
| 2907 |
| 2908 | // X509_STORE_set_depth configures |store| to, by default, limit certificate |
| 2909 | // chains to |depth| intermediate certificates. This count excludes both the |
| 2910 | // target certificate and the trust anchor (root certificate). |
| 2911 | OPENSSL_EXPORT int X509_STORE_set_depth(X509_STORE *store, int depth); |
| 2912 |
| 2913 | // X509_STORE_set_purpose configures the purpose check for |store|. See |
| 2914 | // |X509_VERIFY_PARAM_set_purpose| for details. |
| 2915 | OPENSSL_EXPORT int X509_STORE_set_purpose(X509_STORE *store, int purpose); |
| 2916 |
| 2917 | // X509_STORE_set_trust configures the trust check for |store|. See |
| 2918 | // |X509_VERIFY_PARAM_set_trust| for details. |
| 2919 | OPENSSL_EXPORT int X509_STORE_set_trust(X509_STORE *store, int trust); |
| 2920 |
| 2921 | // The following constants indicate the type of an |X509_OBJECT|. |
| 2922 | #define X509_LU_NONE 0 |
| 2923 | #define X509_LU_X509 1 |
| 2924 | #define X509_LU_CRL 2 |
| 2925 | #define X509_LU_PKEY 3 |
| 2926 |
| 2927 | DEFINE_STACK_OF(X509_OBJECT) |
| 2928 |
| 2929 | // X509_OBJECT_new returns a newly-allocated, empty |X509_OBJECT| or NULL on |
| 2930 | // error. |
| 2931 | OPENSSL_EXPORT X509_OBJECT *X509_OBJECT_new(void); |
| 2932 |
| 2933 | // X509_OBJECT_free releases memory associated with |obj|. |
| 2934 | OPENSSL_EXPORT void X509_OBJECT_free(X509_OBJECT *obj); |
| 2935 |
| 2936 | // X509_OBJECT_get_type returns the type of |obj|, which will be one of the |
| 2937 | // |X509_LU_*| constants. |
| 2938 | OPENSSL_EXPORT int X509_OBJECT_get_type(const X509_OBJECT *obj); |
| 2939 |
| 2940 | // X509_OBJECT_get0_X509 returns |obj| as a certificate, or NULL if |obj| is not |
| 2941 | // a certificate. |
| 2942 | OPENSSL_EXPORT X509 *X509_OBJECT_get0_X509(const X509_OBJECT *obj); |
| 2943 |
| 2944 | // X509_STORE_get1_objects returns a newly-allocated stack containing the |
| 2945 | // contents of |store|, or NULL on error. The caller must release the result |
| 2946 | // with |sk_X509_OBJECT_pop_free| and |X509_OBJECT_free| when done. |
| 2947 | // |
| 2948 | // The result will include all certificates and CRLs added via |
| 2949 | // |X509_STORE_add_cert| and |X509_STORE_add_crl|, as well as any cached objects |
| 2950 | // added by |X509_LOOKUP_add_dir|. The last of these may change over time, as |
| 2951 | // different objects are loaded from the filesystem. Callers should not depend |
| 2952 | // on this caching behavior. The objects are returned in no particular order. |
| 2953 | OPENSSL_EXPORT STACK_OF(X509_OBJECT) *X509_STORE_get1_objects( |
| 2954 | X509_STORE *store); |
| 2955 |
| 2956 |
| 2957 | // Certificate verification. |
| 2958 | // |
| 2959 | // An |X509_STORE_CTX| object represents a single certificate verification |
| 2960 | // operation. To verify a certificate chain, callers construct an |
| 2961 | // |X509_STORE_CTX|, initialize it with |X509_STORE_CTX_init|, configure extra |
| 2962 | // parameters with |X509_STORE_CTX_get0_param|, and call |X509_verify_cert|. |
| 2963 |
| 2964 | // X509_STORE_CTX_new returns a newly-allocated, empty |X509_STORE_CTX|, or NULL |
| 2965 | // on error. |
| 2966 | OPENSSL_EXPORT X509_STORE_CTX *X509_STORE_CTX_new(void); |
| 2967 |
| 2968 | // X509_STORE_CTX_free releases memory associated with |ctx|. |
| 2969 | OPENSSL_EXPORT void X509_STORE_CTX_free(X509_STORE_CTX *ctx); |
| 2970 |
| 2971 | // X509_STORE_CTX_init initializes |ctx| to verify |x509|, using trusted |
| 2972 | // certificates and parameters in |store|. It returns one on success and zero on |
| 2973 | // error. |chain| is a list of untrusted intermediate certificates to use in |
| 2974 | // verification. |
| 2975 | // |
| 2976 | // |ctx| stores pointers to |store|, |x509|, and |chain|. Each of these objects |
| 2977 | // must outlive |ctx| and may not be mutated for the duration of the certificate |
| 2978 | // verification. |
| 2979 | OPENSSL_EXPORT int X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, |
| 2980 | X509 *x509, STACK_OF(X509) *chain); |
| 2981 |
| 2982 | // X509_verify_cert performs certifice verification with |ctx|, which must have |
| 2983 | // been initialized with |X509_STORE_CTX_init|. It returns one on success and |
| 2984 | // zero on error. On success, |X509_STORE_CTX_get0_chain| or |
| 2985 | // |X509_STORE_CTX_get1_chain| may be used to return the verified certificate |
| 2986 | // chain. On error, |X509_STORE_CTX_get_error| may be used to return additional |
| 2987 | // error information. |
| 2988 | // |
| 2989 | // WARNING: Most failure conditions from this function do not use the error |
| 2990 | // queue. Use |X509_STORE_CTX_get_error| to determine the cause of the error. |
| 2991 | OPENSSL_EXPORT int X509_verify_cert(X509_STORE_CTX *ctx); |
| 2992 |
| 2993 | // X509_STORE_CTX_get0_chain, after a successful |X509_verify_cert| call, |
| 2994 | // returns the verified certificate chain. The chain begins with the leaf and |
| 2995 | // ends with trust anchor. |
| 2996 | // |
| 2997 | // At other points, such as after a failed verification or during the deprecated |
| 2998 | // verification callback, it returns the partial chain built so far. Callers |
| 2999 | // should avoid relying on this as this exposes unstable library implementation |
| 3000 | // details. |
| 3001 | OPENSSL_EXPORT STACK_OF(X509) *X509_STORE_CTX_get0_chain( |
| 3002 | const X509_STORE_CTX *ctx); |
| 3003 |
| 3004 | // X509_STORE_CTX_get1_chain behaves like |X509_STORE_CTX_get0_chain| but |
| 3005 | // returns a newly-allocated |STACK_OF(X509)| containing the completed chain, |
| 3006 | // with each certificate's reference count incremented. Callers must free the |
| 3007 | // result with |sk_X509_pop_free| and |X509_free| when done. |
| 3008 | OPENSSL_EXPORT STACK_OF(X509) *X509_STORE_CTX_get1_chain( |
| 3009 | const X509_STORE_CTX *ctx); |
| 3010 |
| 3011 | // The following values are possible outputs of |X509_STORE_CTX_get_error|. |
| 3012 | #define X509_V_OK 0 |
| 3013 | #define X509_V_ERR_UNSPECIFIED 1 |
| 3014 | #define X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT 2 |
| 3015 | #define X509_V_ERR_UNABLE_TO_GET_CRL 3 |
| 3016 | #define X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE 4 |
| 3017 | #define X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE 5 |
| 3018 | #define X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY 6 |
| 3019 | #define X509_V_ERR_CERT_SIGNATURE_FAILURE 7 |
| 3020 | #define X509_V_ERR_CRL_SIGNATURE_FAILURE 8 |
| 3021 | #define X509_V_ERR_CERT_NOT_YET_VALID 9 |
| 3022 | #define X509_V_ERR_CERT_HAS_EXPIRED 10 |
| 3023 | #define X509_V_ERR_CRL_NOT_YET_VALID 11 |
| 3024 | #define X509_V_ERR_CRL_HAS_EXPIRED 12 |
| 3025 | #define X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD 13 |
| 3026 | #define X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD 14 |
| 3027 | #define X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD 15 |
| 3028 | #define X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD 16 |
| 3029 | #define X509_V_ERR_OUT_OF_MEM 17 |
| 3030 | #define X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT 18 |
| 3031 | #define X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN 19 |
| 3032 | #define X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY 20 |
| 3033 | #define X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE 21 |
| 3034 | #define X509_V_ERR_CERT_CHAIN_TOO_LONG 22 |
| 3035 | #define X509_V_ERR_CERT_REVOKED 23 |
| 3036 | #define X509_V_ERR_INVALID_CA 24 |
| 3037 | #define X509_V_ERR_PATH_LENGTH_EXCEEDED 25 |
| 3038 | #define X509_V_ERR_INVALID_PURPOSE 26 |
| 3039 | #define X509_V_ERR_CERT_UNTRUSTED 27 |
| 3040 | #define X509_V_ERR_CERT_REJECTED 28 |
| 3041 | #define X509_V_ERR_SUBJECT_ISSUER_MISMATCH 29 |
| 3042 | #define X509_V_ERR_AKID_SKID_MISMATCH 30 |
| 3043 | #define X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH 31 |
| 3044 | #define X509_V_ERR_KEYUSAGE_NO_CERTSIGN 32 |
| 3045 | #define X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER 33 |
| 3046 | #define X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION 34 |
| 3047 | #define X509_V_ERR_KEYUSAGE_NO_CRL_SIGN 35 |
| 3048 | #define X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION 36 |
| 3049 | #define X509_V_ERR_INVALID_NON_CA 37 |
| 3050 | #define X509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED 38 |
| 3051 | #define X509_V_ERR_KEYUSAGE_NO_DIGITAL_SIGNATURE 39 |
| 3052 | #define X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED 40 |
| 3053 | #define X509_V_ERR_INVALID_EXTENSION 41 |
| 3054 | #define X509_V_ERR_INVALID_POLICY_EXTENSION 42 |
| 3055 | #define X509_V_ERR_NO_EXPLICIT_POLICY 43 |
| 3056 | #define X509_V_ERR_DIFFERENT_CRL_SCOPE 44 |
| 3057 | #define X509_V_ERR_UNSUPPORTED_EXTENSION_FEATURE 45 |
| 3058 | #define X509_V_ERR_UNNESTED_RESOURCE 46 |
| 3059 | #define X509_V_ERR_PERMITTED_VIOLATION 47 |
| 3060 | #define X509_V_ERR_EXCLUDED_VIOLATION 48 |
| 3061 | #define X509_V_ERR_SUBTREE_MINMAX 49 |
| 3062 | #define X509_V_ERR_APPLICATION_VERIFICATION 50 |
| 3063 | #define X509_V_ERR_UNSUPPORTED_CONSTRAINT_TYPE 51 |
| 3064 | #define X509_V_ERR_UNSUPPORTED_CONSTRAINT_SYNTAX 52 |
| 3065 | #define X509_V_ERR_UNSUPPORTED_NAME_SYNTAX 53 |
| 3066 | #define X509_V_ERR_CRL_PATH_VALIDATION_ERROR 54 |
| 3067 | #define X509_V_ERR_HOSTNAME_MISMATCH 62 |
| 3068 | #define X509_V_ERR_EMAIL_MISMATCH 63 |
| 3069 | #define X509_V_ERR_IP_ADDRESS_MISMATCH 64 |
| 3070 | #define X509_V_ERR_INVALID_CALL 65 |
| 3071 | #define X509_V_ERR_STORE_LOOKUP 66 |
| 3072 | #define X509_V_ERR_NAME_CONSTRAINTS_WITHOUT_SANS 67 |
| 3073 |
| 3074 | // X509_STORE_CTX_get_error, after |X509_verify_cert| returns, returns |
| 3075 | // |X509_V_OK| if verification succeeded or an |X509_V_ERR_*| describing why |
| 3076 | // verification failed. This will be consistent with |X509_verify_cert|'s return |
| 3077 | // value, unless the caller used the deprecated verification callback (see |
| 3078 | // |X509_STORE_CTX_set_verify_cb|) in a way that breaks |ctx|'s invariants. |
| 3079 | // |
| 3080 | // If called during the deprecated verification callback when |ok| is zero, it |
| 3081 | // returns the current error under consideration. |
| 3082 | OPENSSL_EXPORT int X509_STORE_CTX_get_error(const X509_STORE_CTX *ctx); |
| 3083 |
| 3084 | // X509_STORE_CTX_set_error sets |ctx|'s error to |err|, which should be |
| 3085 | // |X509_V_OK| or an |X509_V_ERR_*| constant. It is not expected to be called in |
| 3086 | // typical |X509_STORE_CTX| usage, but may be used in callback APIs where |
| 3087 | // applications synthesize |X509_STORE_CTX| error conditions. See also |
| 3088 | // |X509_STORE_CTX_set_verify_cb| and |SSL_CTX_set_cert_verify_callback|. |
| 3089 | OPENSSL_EXPORT void X509_STORE_CTX_set_error(X509_STORE_CTX *ctx, int err); |
| 3090 |
| 3091 | // X509_verify_cert_error_string returns |err| as a human-readable string, where |
| 3092 | // |err| should be one of the |X509_V_*| values. If |err| is unknown, it returns |
| 3093 | // a default description. |
| 3094 | OPENSSL_EXPORT const char *X509_verify_cert_error_string(long err); |
| 3095 |
| 3096 | // X509_STORE_CTX_get_error_depth returns the depth at which the error returned |
| 3097 | // by |X509_STORE_CTX_get_error| occured. This is zero-indexed integer into the |
| 3098 | // certificate chain. Zero indicates the target certificate, one its issuer, and |
| 3099 | // so on. |
| 3100 | OPENSSL_EXPORT int X509_STORE_CTX_get_error_depth(const X509_STORE_CTX *ctx); |
| 3101 |
| 3102 | // X509_STORE_CTX_get_current_cert returns the certificate which caused the |
| 3103 | // error returned by |X509_STORE_CTX_get_error|. |
| 3104 | OPENSSL_EXPORT X509 *X509_STORE_CTX_get_current_cert(const X509_STORE_CTX *ctx); |
| 3105 |
| 3106 | // X509_STORE_CTX_get0_current_crl returns the CRL which caused the error |
| 3107 | // returned by |X509_STORE_CTX_get_error|. |
| 3108 | OPENSSL_EXPORT X509_CRL *X509_STORE_CTX_get0_current_crl( |
| 3109 | const X509_STORE_CTX *ctx); |
| 3110 |
| 3111 | // X509_STORE_CTX_get0_store returns the |X509_STORE| that |ctx| uses. |
| 3112 | OPENSSL_EXPORT X509_STORE *X509_STORE_CTX_get0_store(const X509_STORE_CTX *ctx); |
| 3113 |
| 3114 | // X509_STORE_CTX_get0_cert returns the leaf certificate that |ctx| is |
| 3115 | // verifying. |
| 3116 | OPENSSL_EXPORT X509 *X509_STORE_CTX_get0_cert(const X509_STORE_CTX *ctx); |
| 3117 |
| 3118 | // X509_STORE_CTX_get0_untrusted returns the stack of untrusted intermediates |
| 3119 | // used by |ctx| for certificate verification. |
| 3120 | OPENSSL_EXPORT STACK_OF(X509) *X509_STORE_CTX_get0_untrusted( |
| 3121 | const X509_STORE_CTX *ctx); |
| 3122 |
| 3123 | // X509_STORE_CTX_set0_trusted_stack configures |ctx| to trust the certificates |
| 3124 | // in |sk|. |sk| must remain valid for the duration of |ctx|. Calling this |
| 3125 | // function causes |ctx| to ignore any certificates configured in the |
| 3126 | // |X509_STORE|. Certificates in |sk| are still subject to the check described |
| 3127 | // in |X509_VERIFY_PARAM_set_trust|. |
| 3128 | // |
| 3129 | // WARNING: This function differs from most |set0| functions in that it does not |
| 3130 | // take ownership of its input. The caller is required to ensure the lifetimes |
| 3131 | // are consistent. |
| 3132 | OPENSSL_EXPORT void X509_STORE_CTX_set0_trusted_stack(X509_STORE_CTX *ctx, |
| 3133 | STACK_OF(X509) *sk); |
| 3134 |
| 3135 | // X509_STORE_CTX_set0_crls configures |ctx| to consider the CRLs in |sk| as |
| 3136 | // candidates for CRL lookup. |sk| must remain valid for the duration of |ctx|. |
| 3137 | // These CRLs are considered in addition to CRLs found in |X509_STORE|. |
| 3138 | // |
| 3139 | // WARNING: This function differs from most |set0| functions in that it does not |
| 3140 | // take ownership of its input. The caller is required to ensure the lifetimes |
| 3141 | // are consistent. |
| 3142 | OPENSSL_EXPORT void X509_STORE_CTX_set0_crls(X509_STORE_CTX *ctx, |
| 3143 | STACK_OF(X509_CRL) *sk); |
| 3144 |
| 3145 | // X509_STORE_CTX_set_default looks up the set of parameters named |name| and |
| 3146 | // applies those default verification parameters for |ctx|. As in |
| 3147 | // |X509_VERIFY_PARAM_inherit|, only unset parameters are changed. This function |
| 3148 | // returns one on success and zero on error. |
| 3149 | // |
| 3150 | // The supported values of |name| are: |
| 3151 | // - "default" is an internal value which configures some late defaults. See the |
| 3152 | // discussion in |X509_STORE_get0_param|. |
| 3153 | // - "pkcs7" configures default trust and purpose checks for PKCS#7 signatures. |
| 3154 | // - "smime_sign" configures trust and purpose checks for S/MIME signatures. |
| 3155 | // - "ssl_client" configures trust and purpose checks for TLS clients. |
| 3156 | // - "ssl_server" configures trust and purpose checks for TLS servers. |
| 3157 | // |
| 3158 | // TODO(crbug.com/boringssl/441): Make "default" a no-op. |
| 3159 | OPENSSL_EXPORT int X509_STORE_CTX_set_default(X509_STORE_CTX *ctx, |
| 3160 | const char *name); |
| 3161 |
| 3162 | // X509_STORE_CTX_get0_param returns |ctx|'s verification parameters. This |
| 3163 | // object is mutable and may be modified by the caller. |
| 3164 | OPENSSL_EXPORT X509_VERIFY_PARAM *X509_STORE_CTX_get0_param( |
| 3165 | X509_STORE_CTX *ctx); |
| 3166 |
| 3167 | // X509_STORE_CTX_set0_param returns |ctx|'s verification parameters to |param| |
| 3168 | // and takes ownership of |param|. After this function returns, the caller |
| 3169 | // should not free |param|. |
| 3170 | // |
| 3171 | // WARNING: This function discards any values which were previously applied in |
| 3172 | // |ctx|, including the "default" parameters applied late in |
| 3173 | // |X509_STORE_CTX_init|. These late defaults are not applied to parameters |
| 3174 | // created standalone by |X509_VERIFY_PARAM_new|. |
| 3175 | // |
| 3176 | // TODO(crbug.com/boringssl/441): This behavior is very surprising. Should we |
| 3177 | // re-apply the late defaults in |param|, or somehow avoid this notion of late |
| 3178 | // defaults altogether? |
| 3179 | OPENSSL_EXPORT void X509_STORE_CTX_set0_param(X509_STORE_CTX *ctx, |
| 3180 | X509_VERIFY_PARAM *param); |
| 3181 |
| 3182 | // X509_STORE_CTX_set_flags enables all values in |flags| in |ctx|'s |
| 3183 | // verification flags. |flags| should be a combination of |X509_V_FLAG_*| |
| 3184 | // constants. |
| 3185 | OPENSSL_EXPORT void X509_STORE_CTX_set_flags(X509_STORE_CTX *ctx, |
| 3186 | unsigned long flags); |
| 3187 |
| 3188 | // X509_STORE_CTX_set_time configures certificate verification to use |t| |
| 3189 | // instead of the current time. |flags| is ignored and should be zero. |
| 3190 | OPENSSL_EXPORT void X509_STORE_CTX_set_time(X509_STORE_CTX *ctx, |
| 3191 | unsigned long flags, time_t t); |
| 3192 |
| 3193 | // X509_STORE_CTX_set_time_posix configures certificate verification to use |t| |
| 3194 | // instead of the current time. |t| is interpreted as a POSIX timestamp in |
| 3195 | // seconds. |flags| is ignored and should be zero. |
| 3196 | OPENSSL_EXPORT void X509_STORE_CTX_set_time_posix(X509_STORE_CTX *ctx, |
| 3197 | unsigned long flags, |
| 3198 | int64_t t); |
| 3199 |
| 3200 | // X509_STORE_CTX_set_depth configures |ctx| to, by default, limit certificate |
| 3201 | // chains to |depth| intermediate certificates. This count excludes both the |
| 3202 | // target certificate and the trust anchor (root certificate). |
| 3203 | OPENSSL_EXPORT void X509_STORE_CTX_set_depth(X509_STORE_CTX *ctx, int depth); |
| 3204 |
| 3205 | // X509_STORE_CTX_set_purpose simultaneously configures |ctx|'s purpose and |
| 3206 | // trust checks, if unset. It returns one on success and zero if |purpose| is |
| 3207 | // not a valid purpose value. |purpose| should be an |X509_PURPOSE_*| constant. |
| 3208 | // If so, it configures |ctx| with a purpose check of |purpose| and a trust |
| 3209 | // check of |purpose|'s corresponding trust value. If either the purpose or |
| 3210 | // trust check had already been specified for |ctx|, that corresponding |
| 3211 | // modification is silently dropped. |
| 3212 | // |
| 3213 | // See |X509_VERIFY_PARAM_set_purpose| and |X509_VERIFY_PARAM_set_trust| for |
| 3214 | // details on the purpose and trust checks, respectively. |
| 3215 | // |
| 3216 | // If |purpose| is |X509_PURPOSE_ANY|, this function returns an error because it |
| 3217 | // has no corresponding |X509_TRUST_*| value. It is not possible to set |
| 3218 | // |X509_PURPOSE_ANY| with this function, only |X509_VERIFY_PARAM_set_purpose|. |
| 3219 | // |
| 3220 | // WARNING: Unlike similarly named functions in this header, this function |
| 3221 | // silently does not behave the same as |X509_VERIFY_PARAM_set_purpose|. Callers |
| 3222 | // may use |X509_VERIFY_PARAM_set_purpose| with |X509_STORE_CTX_get0_param| to |
| 3223 | // avoid this difference. |
| 3224 | OPENSSL_EXPORT int X509_STORE_CTX_set_purpose(X509_STORE_CTX *ctx, int purpose); |
| 3225 |
| 3226 | // X509_STORE_CTX_set_trust configures |ctx|'s trust check, if unset. It returns |
| 3227 | // one on success and zero if |trust| is not a valid trust value. |trust| should |
| 3228 | // be an |X509_TRUST_*| constant. If so, it configures |ctx| with a trust check |
| 3229 | // of |trust|. If the trust check had already been specified for |ctx|, it |
| 3230 | // silently does nothing. |
| 3231 | // |
| 3232 | // See |X509_VERIFY_PARAM_set_trust| for details on the purpose and trust check. |
| 3233 | // |
| 3234 | // WARNING: Unlike similarly named functions in this header, this function |
| 3235 | // does not behave the same as |X509_VERIFY_PARAM_set_trust|. Callers may use |
| 3236 | // |X509_VERIFY_PARAM_set_trust| with |X509_STORE_CTX_get0_param| to avoid this |
| 3237 | // difference. |
| 3238 | OPENSSL_EXPORT int X509_STORE_CTX_set_trust(X509_STORE_CTX *ctx, int trust); |
| 3239 |
| 3240 |
| 3241 | // Verification parameters. |
| 3242 | // |
| 3243 | // An |X509_VERIFY_PARAM| contains a set of parameters for certificate |
| 3244 | // verification. |
| 3245 |
| 3246 | // X509_VERIFY_PARAM_new returns a newly-allocated |X509_VERIFY_PARAM|, or NULL |
| 3247 | // on error. |
| 3248 | OPENSSL_EXPORT X509_VERIFY_PARAM *X509_VERIFY_PARAM_new(void); |
| 3249 |
| 3250 | // X509_VERIFY_PARAM_free releases memory associated with |param|. |
| 3251 | OPENSSL_EXPORT void X509_VERIFY_PARAM_free(X509_VERIFY_PARAM *param); |
| 3252 |
| 3253 | // X509_VERIFY_PARAM_inherit applies |from| as the default values for |to|. That |
| 3254 | // is, for each parameter that is unset in |to|, it copies the value in |from|. |
| 3255 | // This function returns one on success and zero on error. |
| 3256 | OPENSSL_EXPORT int X509_VERIFY_PARAM_inherit(X509_VERIFY_PARAM *to, |
| 3257 | const X509_VERIFY_PARAM *from); |
| 3258 |
| 3259 | // X509_VERIFY_PARAM_set1 copies parameters from |from| to |to|. If a parameter |
| 3260 | // is unset in |from|, the existing value in |to| is preserved. This function |
| 3261 | // returns one on success and zero on error. |
| 3262 | OPENSSL_EXPORT int X509_VERIFY_PARAM_set1(X509_VERIFY_PARAM *to, |
| 3263 | const X509_VERIFY_PARAM *from); |
| 3264 |
| 3265 | // X509_V_FLAG_* are flags for |X509_VERIFY_PARAM_set_flags| and |
| 3266 | // |X509_VERIFY_PARAM_clear_flags|. |
| 3267 |
| 3268 | // X509_V_FLAG_CB_ISSUER_CHECK causes the deprecated verify callback (see |
| 3269 | // |X509_STORE_CTX_set_verify_cb|) to be called for errors while matching |
| 3270 | // subject and issuer certificates. |
| 3271 | #define X509_V_FLAG_CB_ISSUER_CHECK 0x1 |
| 3272 | // X509_V_FLAG_USE_CHECK_TIME is an internal flag used to track whether |
| 3273 | // |X509_STORE_CTX_set_time| has been used. If cleared, the system time is |
| 3274 | // restored. |
| 3275 | #define X509_V_FLAG_USE_CHECK_TIME 0x2 |
| 3276 | // X509_V_FLAG_CRL_CHECK enables CRL lookup and checking for the leaf. |
| 3277 | #define X509_V_FLAG_CRL_CHECK 0x4 |
| 3278 | // X509_V_FLAG_CRL_CHECK_ALL enables CRL lookup and checking for the entire |
| 3279 | // certificate chain. |X509_V_FLAG_CRL_CHECK| must be set for this flag to take |
| 3280 | // effect. |
| 3281 | #define X509_V_FLAG_CRL_CHECK_ALL 0x8 |
| 3282 | // X509_V_FLAG_IGNORE_CRITICAL ignores unhandled critical extensions. Do not use |
| 3283 | // this option. Critical extensions ensure the verifier does not bypass |
| 3284 | // unrecognized security restrictions in certificates. |
| 3285 | #define X509_V_FLAG_IGNORE_CRITICAL 0x10 |
| 3286 | // X509_V_FLAG_X509_STRICT does nothing. Its functionality has been enabled by |
| 3287 | // default. |
| 3288 | #define X509_V_FLAG_X509_STRICT 0x00 |
| 3289 | // X509_V_FLAG_ALLOW_PROXY_CERTS does nothing. Proxy certificate support has |
| 3290 | // been removed. |
| 3291 | #define X509_V_FLAG_ALLOW_PROXY_CERTS 0x40 |
| 3292 | // X509_V_FLAG_POLICY_CHECK does nothing. Policy checking is always enabled. |
| 3293 | #define X509_V_FLAG_POLICY_CHECK 0x80 |
| 3294 | // X509_V_FLAG_EXPLICIT_POLICY requires some policy OID to be asserted by the |
| 3295 | // final certificate chain. See initial-explicit-policy from RFC 5280, |
| 3296 | // section 6.1.1. |
| 3297 | #define X509_V_FLAG_EXPLICIT_POLICY 0x100 |
| 3298 | // X509_V_FLAG_INHIBIT_ANY inhibits the anyPolicy OID. See |
| 3299 | // initial-any-policy-inhibit from RFC 5280, section 6.1.1. |
| 3300 | #define X509_V_FLAG_INHIBIT_ANY 0x200 |
| 3301 | // X509_V_FLAG_INHIBIT_MAP inhibits policy mapping. See |
| 3302 | // initial-policy-mapping-inhibit from RFC 5280, section 6.1.1. |
| 3303 | #define X509_V_FLAG_INHIBIT_MAP 0x400 |
| 3304 | // X509_V_FLAG_NOTIFY_POLICY does nothing. Its functionality has been removed. |
| 3305 | #define X509_V_FLAG_NOTIFY_POLICY 0x800 |
| 3306 | // X509_V_FLAG_EXTENDED_CRL_SUPPORT causes all verifications to fail. Extended |
| 3307 | // CRL features have been removed. |
| 3308 | #define X509_V_FLAG_EXTENDED_CRL_SUPPORT 0x1000 |
| 3309 | // X509_V_FLAG_USE_DELTAS causes all verifications to fail. Delta CRL support |
| 3310 | // has been removed. |
| 3311 | #define X509_V_FLAG_USE_DELTAS 0x2000 |
| 3312 | // X509_V_FLAG_CHECK_SS_SIGNATURE checks the redundant signature on self-signed |
| 3313 | // trust anchors. This check provides no security benefit and only wastes CPU. |
| 3314 | #define X509_V_FLAG_CHECK_SS_SIGNATURE 0x4000 |
| 3315 | // X509_V_FLAG_TRUSTED_FIRST, during path-building, checks for a match in the |
| 3316 | // trust store before considering an untrusted intermediate. This flag is |
| 3317 | // enabled by default. |
| 3318 | #define X509_V_FLAG_TRUSTED_FIRST 0x8000 |
| 3319 | // X509_V_FLAG_PARTIAL_CHAIN treats all trusted certificates as trust anchors, |
| 3320 | // independent of the |X509_VERIFY_PARAM_set_trust| setting. |
| 3321 | #define X509_V_FLAG_PARTIAL_CHAIN 0x80000 |
| 3322 | // X509_V_FLAG_NO_ALT_CHAINS disables building alternative chains if the initial |
| 3323 | // one was rejected. |
| 3324 | #define X509_V_FLAG_NO_ALT_CHAINS 0x100000 |
| 3325 | // X509_V_FLAG_NO_CHECK_TIME disables all time checks in certificate |
| 3326 | // verification. |
| 3327 | #define X509_V_FLAG_NO_CHECK_TIME 0x200000 |
| 3328 |
| 3329 | // X509_VERIFY_PARAM_set_flags enables all values in |flags| in |param|'s |
| 3330 | // verification flags and returns one. |flags| should be a combination of |
| 3331 | // |X509_V_FLAG_*| constants. |
| 3332 | OPENSSL_EXPORT int X509_VERIFY_PARAM_set_flags(X509_VERIFY_PARAM *param, |
| 3333 | unsigned long flags); |
| 3334 |
| 3335 | // X509_VERIFY_PARAM_clear_flags disables all values in |flags| in |param|'s |
| 3336 | // verification flags and returns one. |flags| should be a combination of |
| 3337 | // |X509_V_FLAG_*| constants. |
| 3338 | OPENSSL_EXPORT int X509_VERIFY_PARAM_clear_flags(X509_VERIFY_PARAM *param, |
| 3339 | unsigned long flags); |
| 3340 |
| 3341 | // X509_VERIFY_PARAM_get_flags returns |param|'s verification flags. |
| 3342 | OPENSSL_EXPORT unsigned long X509_VERIFY_PARAM_get_flags( |
| 3343 | const X509_VERIFY_PARAM *param); |
| 3344 |
| 3345 | // X509_VERIFY_PARAM_set_depth configures |param| to limit certificate chains to |
| 3346 | // |depth| intermediate certificates. This count excludes both the target |
| 3347 | // certificate and the trust anchor (root certificate). |
| 3348 | OPENSSL_EXPORT void X509_VERIFY_PARAM_set_depth(X509_VERIFY_PARAM *param, |
| 3349 | int depth); |
| 3350 |
| 3351 | // X509_VERIFY_PARAM_get_depth returns the maximum depth configured in |param|. |
| 3352 | // See |X509_VERIFY_PARAM_set_depth|. |
| 3353 | OPENSSL_EXPORT int X509_VERIFY_PARAM_get_depth(const X509_VERIFY_PARAM *param); |
| 3354 |
| 3355 | // X509_VERIFY_PARAM_set_time configures certificate verification to use |t| |
| 3356 | // instead of the current time. |
| 3357 | OPENSSL_EXPORT void X509_VERIFY_PARAM_set_time(X509_VERIFY_PARAM *param, |
| 3358 | time_t t); |
| 3359 |
| 3360 | // X509_VERIFY_PARAM_set_time_posix configures certificate verification to use |
| 3361 | // |t| instead of the current time. |t| is interpreted as a POSIX timestamp in |
| 3362 | // seconds. |
| 3363 | OPENSSL_EXPORT void X509_VERIFY_PARAM_set_time_posix(X509_VERIFY_PARAM *param, |
| 3364 | int64_t t); |
| 3365 |
| 3366 | // X509_VERIFY_PARAM_add0_policy adds |policy| to the user-initial-policy-set |
| 3367 | // (see Section 6.1.1 of RFC 5280). On success, it takes ownership of |
| 3368 | // |policy| and returns one. Otherwise, it returns zero and the caller retains |
| 3369 | // owneship of |policy|. |
| 3370 | OPENSSL_EXPORT int X509_VERIFY_PARAM_add0_policy(X509_VERIFY_PARAM *param, |
| 3371 | ASN1_OBJECT *policy); |
| 3372 |
| 3373 | // X509_VERIFY_PARAM_set1_policies sets the user-initial-policy-set (see |
| 3374 | // Section 6.1.1 of RFC 5280) to a copy of |policies|. It returns one on success |
| 3375 | // and zero on error. |
| 3376 | OPENSSL_EXPORT int X509_VERIFY_PARAM_set1_policies( |
| 3377 | X509_VERIFY_PARAM *param, const STACK_OF(ASN1_OBJECT) *policies); |
| 3378 |
| 3379 | // X509_VERIFY_PARAM_set1_host configures |param| to check for the DNS name |
| 3380 | // specified by |name|. It returns one on success and zero on error. |
| 3381 | // |
| 3382 | // By default, both subject alternative names and the subject's common name |
| 3383 | // attribute are checked. The latter has long been deprecated, so callers should |
| 3384 | // call |X509_VERIFY_PARAM_set_hostflags| with |
| 3385 | // |X509_CHECK_FLAG_NEVER_CHECK_SUBJECT| to use the standard behavior. |
| 3386 | // https://crbug.com/boringssl/464 tracks fixing the default. |
| 3387 | OPENSSL_EXPORT int X509_VERIFY_PARAM_set1_host(X509_VERIFY_PARAM *param, |
| 3388 | const char *name, |
| 3389 | size_t name_len); |
| 3390 |
| 3391 | // X509_VERIFY_PARAM_add1_host adds |name| to the list of names checked by |
| 3392 | // |param|. If any configured DNS name matches the certificate, verification |
| 3393 | // succeeds. It returns one on success and zero on error. |
| 3394 | // |
| 3395 | // By default, both subject alternative names and the subject's common name |
| 3396 | // attribute are checked. The latter has long been deprecated, so callers should |
| 3397 | // call |X509_VERIFY_PARAM_set_hostflags| with |
| 3398 | // |X509_CHECK_FLAG_NEVER_CHECK_SUBJECT| to use the standard behavior. |
| 3399 | // https://crbug.com/boringssl/464 tracks fixing the default. |
| 3400 | OPENSSL_EXPORT int X509_VERIFY_PARAM_add1_host(X509_VERIFY_PARAM *param, |
| 3401 | const char *name, |
| 3402 | size_t name_len); |
| 3403 |
| 3404 | // X509_CHECK_FLAG_NO_WILDCARDS disables wildcard matching for DNS names. |
| 3405 | #define X509_CHECK_FLAG_NO_WILDCARDS 0x2 |
| 3406 |
| 3407 | // X509_CHECK_FLAG_NEVER_CHECK_SUBJECT disables the subject fallback, normally |
| 3408 | // enabled when subjectAltNames is missing. |
| 3409 | #define X509_CHECK_FLAG_NEVER_CHECK_SUBJECT 0x20 |
| 3410 |
| 3411 | // X509_VERIFY_PARAM_set_hostflags sets the name-checking flags on |param| to |
| 3412 | // |flags|. |flags| should be a combination of |X509_CHECK_FLAG_*| constants. |
| 3413 | OPENSSL_EXPORT void X509_VERIFY_PARAM_set_hostflags(X509_VERIFY_PARAM *param, |
| 3414 | unsigned int flags); |
| 3415 |
| 3416 | // X509_VERIFY_PARAM_set1_email configures |param| to check for the email |
| 3417 | // address specified by |email|. It returns one on success and zero on error. |
| 3418 | // |
| 3419 | // By default, both subject alternative names and the subject's email address |
| 3420 | // attribute are checked. The |X509_CHECK_FLAG_NEVER_CHECK_SUBJECT| flag may be |
| 3421 | // used to change this behavior. |
| 3422 | OPENSSL_EXPORT int X509_VERIFY_PARAM_set1_email(X509_VERIFY_PARAM *param, |
| 3423 | const char *email, |
| 3424 | size_t email_len); |
| 3425 |
| 3426 | // X509_VERIFY_PARAM_set1_ip configures |param| to check for the IP address |
| 3427 | // specified by |ip|. It returns one on success and zero on error. The IP |
| 3428 | // address is specified in its binary representation. |ip_len| must be 4 for an |
| 3429 | // IPv4 address and 16 for an IPv6 address. |
| 3430 | OPENSSL_EXPORT int X509_VERIFY_PARAM_set1_ip(X509_VERIFY_PARAM *param, |
| 3431 | const uint8_t *ip, size_t ip_len); |
| 3432 |
| 3433 | // X509_VERIFY_PARAM_set1_ip_asc decodes |ipasc| as the ASCII representation of |
| 3434 | // an IPv4 or IPv6 address, and configures |param| to check for it. It returns |
| 3435 | // one on success and zero on error. |
| 3436 | OPENSSL_EXPORT int X509_VERIFY_PARAM_set1_ip_asc(X509_VERIFY_PARAM *param, |
| 3437 | const char *ipasc); |
| 3438 |
| 3439 | // X509_PURPOSE_SSL_CLIENT validates TLS client certificates. It checks for the |
| 3440 | // id-kp-clientAuth EKU and one of digitalSignature or keyAgreement key usages. |
| 3441 | // The TLS library is expected to check for the key usage specific to the |
| 3442 | // negotiated TLS parameters. |
| 3443 | #define X509_PURPOSE_SSL_CLIENT 1 |
| 3444 | // X509_PURPOSE_SSL_SERVER validates TLS server certificates. It checks for the |
| 3445 | // id-kp-clientAuth EKU and one of digitalSignature, keyAgreement, or |
| 3446 | // keyEncipherment key usages. The TLS library is expected to check for the key |
| 3447 | // usage specific to the negotiated TLS parameters. |
| 3448 | #define X509_PURPOSE_SSL_SERVER 2 |
| 3449 | // X509_PURPOSE_NS_SSL_SERVER is a legacy mode. It behaves like |
| 3450 | // |X509_PURPOSE_SSL_SERVER|, but only accepts the keyEncipherment key usage, |
| 3451 | // used by SSL 2.0 and RSA key exchange. Do not use this. |
| 3452 | #define X509_PURPOSE_NS_SSL_SERVER 3 |
| 3453 | // X509_PURPOSE_SMIME_SIGN validates S/MIME signing certificates. It checks for |
| 3454 | // the id-kp-emailProtection EKU and one of digitalSignature or nonRepudiation |
| 3455 | // key usages. |
| 3456 | #define X509_PURPOSE_SMIME_SIGN 4 |
| 3457 | // X509_PURPOSE_SMIME_ENCRYPT validates S/MIME encryption certificates. It |
| 3458 | // checks for the id-kp-emailProtection EKU and keyEncipherment key usage. |
| 3459 | #define X509_PURPOSE_SMIME_ENCRYPT 5 |
| 3460 | // X509_PURPOSE_CRL_SIGN validates indirect CRL signers. It checks for the |
| 3461 | // cRLSign key usage. BoringSSL does not support indirect CRLs and does not use |
| 3462 | // this mode. |
| 3463 | #define X509_PURPOSE_CRL_SIGN 6 |
| 3464 | // X509_PURPOSE_ANY performs no EKU or key usage checks. Such checks are the |
| 3465 | // responsibility of the caller. |
| 3466 | #define X509_PURPOSE_ANY 7 |
| 3467 | // X509_PURPOSE_OCSP_HELPER performs no EKU or key usage checks. It was |
| 3468 | // historically used in OpenSSL's OCSP implementation, which left those checks |
| 3469 | // to the OCSP implementation itself. |
| 3470 | #define X509_PURPOSE_OCSP_HELPER 8 |
| 3471 | // X509_PURPOSE_TIMESTAMP_SIGN validates Time Stamping Authority (RFC 3161) |
| 3472 | // certificates. It checks for the id-kp-timeStamping EKU and one of |
| 3473 | // digitalSignature or nonRepudiation key usages. It additionally checks that |
| 3474 | // the EKU extension is critical and that no other EKUs or key usages are |
| 3475 | // asserted. |
| 3476 | #define X509_PURPOSE_TIMESTAMP_SIGN 9 |
| 3477 |
| 3478 | // X509_VERIFY_PARAM_set_purpose configures |param| to validate certificates for |
| 3479 | // a specified purpose. It returns one on success and zero if |purpose| is not a |
| 3480 | // valid purpose type. |purpose| should be one of the |X509_PURPOSE_*| values. |
| 3481 | // |
| 3482 | // This option controls checking the extended key usage (EKU) and key usage |
| 3483 | // extensions. These extensions specify how a certificate's public key may be |
| 3484 | // used and are important to avoid cross-protocol attacks, particularly in PKIs |
| 3485 | // that may issue certificates for multiple protocols, or for protocols that use |
| 3486 | // keys in multiple ways. If not configured, these security checks are the |
| 3487 | // caller's responsibility. |
| 3488 | // |
| 3489 | // This library applies the EKU checks to all untrusted intermediates. Although |
| 3490 | // not defined in RFC 5280, this matches widely-deployed practice. It also does |
| 3491 | // not accept anyExtendedKeyUsage. |
| 3492 | // |
| 3493 | // Many purpose values have a corresponding trust value, which is not configured |
| 3494 | // by this function. See |X509_VERIFY_PARAM_set_trust| for details. Callers |
| 3495 | // that wish to configure both should either call both functions, or use |
| 3496 | // |X509_STORE_CTX_set_purpose|. |
| 3497 | // |
| 3498 | // It is currently not possible to configure custom EKU OIDs or key usage bits. |
| 3499 | // Contact the BoringSSL maintainers if your application needs to do so. OpenSSL |
| 3500 | // had an |X509_PURPOSE_add| API, but it was not thread-safe and relied on |
| 3501 | // global mutable state, so we removed it. |
| 3502 | // |
| 3503 | // TODO(davidben): This function additionally configures checking the legacy |
| 3504 | // Netscape certificate type extension. Remove this. |
| 3505 | OPENSSL_EXPORT int X509_VERIFY_PARAM_set_purpose(X509_VERIFY_PARAM *param, |
| 3506 | int purpose); |
| 3507 |
| 3508 | // X509_TRUST_COMPAT evaluates trust using only the self-signed fallback. Trust |
| 3509 | // and distrust OIDs are ignored. |
| 3510 | #define X509_TRUST_COMPAT 1 |
| 3511 | // X509_TRUST_SSL_CLIENT evaluates trust with the |NID_client_auth| OID, for |
| 3512 | // validating TLS client certificates. |
| 3513 | #define X509_TRUST_SSL_CLIENT 2 |
| 3514 | // X509_TRUST_SSL_SERVER evaluates trust with the |NID_server_auth| OID, for |
| 3515 | // validating TLS server certificates. |
| 3516 | #define X509_TRUST_SSL_SERVER 3 |
| 3517 | // X509_TRUST_EMAIL evaluates trust with the |NID_email_protect| OID, for |
| 3518 | // validating S/MIME email certificates. |
| 3519 | #define X509_TRUST_EMAIL 4 |
| 3520 | // X509_TRUST_OBJECT_SIGN evaluates trust with the |NID_code_sign| OID, for |
| 3521 | // validating code signing certificates. |
| 3522 | #define X509_TRUST_OBJECT_SIGN 5 |
| 3523 | // X509_TRUST_TSA evaluates trust with the |NID_time_stamp| OID, for validating |
| 3524 | // Time Stamping Authority (RFC 3161) certificates. |
| 3525 | #define X509_TRUST_TSA 8 |
| 3526 |
| 3527 | // X509_VERIFY_PARAM_set_trust configures which certificates from |X509_STORE| |
| 3528 | // are trust anchors. It returns one on success and zero if |trust| is not a |
| 3529 | // valid trust value. |trust| should be one of the |X509_TRUST_*| constants. |
| 3530 | // This function allows applications to vary trust anchors when the same set of |
| 3531 | // trusted certificates is used in multiple contexts. |
| 3532 | // |
| 3533 | // Two properties determine whether a certificate is a trust anchor: |
| 3534 | // |
| 3535 | // - Whether it is trusted or distrusted for some OID, via auxiliary information |
| 3536 | // configured by |X509_add1_trust_object| or |X509_add1_reject_object|. |
| 3537 | // |
| 3538 | // - Whether it is "self-signed". That is, whether |X509_get_extension_flags| |
| 3539 | // includes |EXFLAG_SS|. The signature itself is not checked. |
| 3540 | // |
| 3541 | // When this function is called, |trust| determines the OID to check in the |
| 3542 | // first case. If the certificate is not explicitly trusted or distrusted for |
| 3543 | // any OID, it is trusted if self-signed instead. |
| 3544 | // |
| 3545 | // If unset, the default behavior is to check for the |NID_anyExtendedKeyUsage| |
| 3546 | // OID. If the certificate is not explicitly trusted or distrusted for this OID, |
| 3547 | // it is trusted if self-signed instead. Note this slightly differs from the |
| 3548 | // above. |
| 3549 | // |
| 3550 | // If the |X509_V_FLAG_PARTIAL_CHAIN| is set, every certificate from |
| 3551 | // |X509_STORE| is a trust anchor, unless it was explicitly distrusted for the |
| 3552 | // OID. |
| 3553 | // |
| 3554 | // It is currently not possible to configure custom trust OIDs. Contact the |
| 3555 | // BoringSSL maintainers if your application needs to do so. OpenSSL had an |
| 3556 | // |X509_TRUST_add| API, but it was not thread-safe and relied on global mutable |
| 3557 | // state, so we removed it. |
| 3558 | OPENSSL_EXPORT int X509_VERIFY_PARAM_set_trust(X509_VERIFY_PARAM *param, |
| 3559 | int trust); |
| 3560 |
| 3561 |
| 3562 | // Filesystem-based certificate stores. |
| 3563 | // |
| 3564 | // An |X509_STORE| may be configured to get its contents from the filesystem. |
| 3565 | // This is done by adding |X509_LOOKUP| structures to the |X509_STORE| with |
| 3566 | // |X509_STORE_add_lookup| and then configuring the |X509_LOOKUP| with paths. |
| 3567 | // |
| 3568 | // Most cases can use |X509_STORE_load_locations|, which configures the same |
| 3569 | // thing but is simpler to use. |
| 3570 |
| 3571 | // X509_STORE_load_locations configures |store| to load data from filepaths |
| 3572 | // |file| and |dir|. It returns one on success and zero on error. Either of |
| 3573 | // |file| or |dir| may be NULL, but at least one must be non-NULL. |
| 3574 | // |
| 3575 | // If |file| is non-NULL, it loads CRLs and trusted certificates in PEM format |
| 3576 | // from the file at |file|, and them to |store|, as in |X509_load_cert_crl_file| |
| 3577 | // with |X509_FILETYPE_PEM|. |
| 3578 | // |
| 3579 | // If |dir| is non-NULL, it configures |store| to load CRLs and trusted |
| 3580 | // certificates from the directory at |dir| in PEM format, as in |
| 3581 | // |X509_LOOKUP_add_dir| with |X509_FILETYPE_PEM|. |
| 3582 | OPENSSL_EXPORT int X509_STORE_load_locations(X509_STORE *store, |
| 3583 | const char *file, const char *dir); |
| 3584 |
| 3585 | // X509_STORE_add_lookup returns an |X509_LOOKUP| associated with |store| with |
| 3586 | // type |method|, or NULL on error. The result is owned by |store|, so callers |
| 3587 | // are not expected to free it. This may be used with |X509_LOOKUP_add_dir| or |
| 3588 | // |X509_LOOKUP_load_file|, depending on |method|, to configure |store|. |
| 3589 | // |
| 3590 | // A single |X509_LOOKUP| may be configured with multiple paths, and an |
| 3591 | // |X509_STORE| only contains one |X509_LOOKUP| of each type, so there is no |
| 3592 | // need to call this function multiple times for a single type. Calling it |
| 3593 | // multiple times will return the previous |X509_LOOKUP| of that type. |
| 3594 | OPENSSL_EXPORT X509_LOOKUP *X509_STORE_add_lookup( |
| 3595 | X509_STORE *store, const X509_LOOKUP_METHOD *method); |
| 3596 |
| 3597 | // X509_LOOKUP_hash_dir creates |X509_LOOKUP|s that may be used with |
| 3598 | // |X509_LOOKUP_add_dir|. |
| 3599 | OPENSSL_EXPORT const X509_LOOKUP_METHOD *X509_LOOKUP_hash_dir(void); |
| 3600 |
| 3601 | // X509_LOOKUP_file creates |X509_LOOKUP|s that may be used with |
| 3602 | // |X509_LOOKUP_load_file|. |
| 3603 | // |
| 3604 | // Although this is modeled as an |X509_LOOKUP|, this function is redundant. It |
| 3605 | // has the same effect as loading a certificate or CRL from the filesystem, in |
| 3606 | // the caller's desired format, and then adding it with |X509_STORE_add_cert| |
| 3607 | // and |X509_STORE_add_crl|. |
| 3608 | OPENSSL_EXPORT const X509_LOOKUP_METHOD *X509_LOOKUP_file(void); |
| 3609 |
| 3610 | // The following constants are used to specify the format of files in an |
| 3611 | // |X509_LOOKUP|. |
| 3612 | #define X509_FILETYPE_PEM 1 |
| 3613 | #define X509_FILETYPE_ASN1 2 |
| 3614 | #define X509_FILETYPE_DEFAULT 3 |
| 3615 |
| 3616 | // X509_LOOKUP_load_file calls |X509_load_cert_crl_file|. |lookup| must have |
| 3617 | // been constructed with |X509_LOOKUP_file|. |
| 3618 | // |
| 3619 | // If |type| is |X509_FILETYPE_DEFAULT|, it ignores |file| and instead uses some |
| 3620 | // default system path with |X509_FILETYPE_PEM|. See also |
| 3621 | // |X509_STORE_set_default_paths|. |
| 3622 | OPENSSL_EXPORT int X509_LOOKUP_load_file(X509_LOOKUP *lookup, const char *file, |
| 3623 | int type); |
| 3624 |
| 3625 | // X509_LOOKUP_add_dir configures |lookup| to load CRLs and trusted certificates |
| 3626 | // from the directories in |path|. It returns one on success and zero on error. |
| 3627 | // |lookup| must have been constructed with |X509_LOOKUP_hash_dir|. |
| 3628 | // |
| 3629 | // WARNING: |path| is interpreted as a colon-separated (semicolon-separated on |
| 3630 | // Windows) list of paths. It is not possible to configure a path containing the |
| 3631 | // separator character. https://crbug.com/boringssl/691 tracks removing this |
| 3632 | // behavior. |
| 3633 | // |
| 3634 | // |type| should be one of the |X509_FILETYPE_*| constants and determines the |
| 3635 | // format of the files. If |type| is |X509_FILETYPE_DEFAULT|, |path| is ignored |
| 3636 | // and some default system path is used with |X509_FILETYPE_PEM|. See also |
| 3637 | // |X509_STORE_set_default_paths|. |
| 3638 | // |
| 3639 | // Trusted certificates should be named HASH.N and CRLs should be |
| 3640 | // named HASH.rN. HASH is |X509_NAME_hash| of the certificate subject and CRL |
| 3641 | // issuer, respectively, in hexadecimal. N is in decimal and counts hash |
| 3642 | // collisions consecutively, starting from zero. For example, "002c0b4f.0" and |
| 3643 | // "002c0b4f.r0". |
| 3644 | // |
| 3645 | // WARNING: Objects from |path| are loaded on demand, but cached in memory on |
| 3646 | // the |X509_STORE|. If a CA is removed from the directory, existing |
| 3647 | // |X509_STORE|s will continue to trust it. Cache entries are not evicted for |
| 3648 | // the lifetime of the |X509_STORE|. |
| 3649 | // |
| 3650 | // WARNING: This mechanism is also not well-suited for CRL updates. |
| 3651 | // |X509_STORE|s rely on this cache and never load the same CRL file twice. CRL |
| 3652 | // updates must use a new file, with an incremented suffix, to be reflected in |
| 3653 | // existing |X509_STORE|s. However, this means each CRL update will use |
| 3654 | // additional storage and memory. Instead, configure inputs that vary per |
| 3655 | // verification, such as CRLs, on each |X509_STORE_CTX| separately, using |
| 3656 | // functions like |X509_STORE_CTX_set0_crl|. |
| 3657 | OPENSSL_EXPORT int X509_LOOKUP_add_dir(X509_LOOKUP *lookup, const char *path, |
| 3658 | int type); |
| 3659 |
| 3660 | // X509_L_* are commands for |X509_LOOKUP_ctrl|. |
| 3661 | #define X509_L_FILE_LOAD 1 |
| 3662 | #define X509_L_ADD_DIR 2 |
| 3663 |
| 3664 | // X509_LOOKUP_ctrl implements commands on |lookup|. |cmd| specifies the |
| 3665 | // command. The other arguments specify the operation in a command-specific way. |
| 3666 | // Use |X509_LOOKUP_load_file| or |X509_LOOKUP_add_dir| instead. |
| 3667 | OPENSSL_EXPORT int X509_LOOKUP_ctrl(X509_LOOKUP *lookup, int cmd, |
| 3668 | const char *argc, long argl, char **ret); |
| 3669 |
| 3670 | // X509_load_cert_file loads trusted certificates from |file| and adds them to |
| 3671 | // |lookup|'s |X509_STORE|. It returns one on success and zero on error. |
| 3672 | // |
| 3673 | // If |type| is |X509_FILETYPE_ASN1|, it loads a single DER-encoded certificate. |
| 3674 | // If |type| is |X509_FILETYPE_PEM|, it loads a sequence of PEM-encoded |
| 3675 | // certificates. |type| may not be |X509_FILETYPE_DEFAULT|. |
| 3676 | OPENSSL_EXPORT int X509_load_cert_file(X509_LOOKUP *lookup, const char *file, |
| 3677 | int type); |
| 3678 |
| 3679 | // X509_load_crl_file loads CRLs from |file| and add them it to |lookup|'s |
| 3680 | // |X509_STORE|. It returns one on success and zero on error. |
| 3681 | // |
| 3682 | // If |type| is |X509_FILETYPE_ASN1|, it loads a single DER-encoded CRL. If |
| 3683 | // |type| is |X509_FILETYPE_PEM|, it loads a sequence of PEM-encoded CRLs. |
| 3684 | // |type| may not be |X509_FILETYPE_DEFAULT|. |
| 3685 | OPENSSL_EXPORT int X509_load_crl_file(X509_LOOKUP *lookup, const char *file, |
| 3686 | int type); |
| 3687 |
| 3688 | // X509_load_cert_crl_file loads CRLs and trusted certificates from |file| and |
| 3689 | // adds them to |lookup|'s |X509_STORE|. It returns one on success and zero on |
| 3690 | // error. |
| 3691 | // |
| 3692 | // If |type| is |X509_FILETYPE_ASN1|, it loads a single DER-encoded certificate. |
| 3693 | // This function cannot be used to load a DER-encoded CRL. If |type| is |
| 3694 | // |X509_FILETYPE_PEM|, it loads a sequence of PEM-encoded certificates and |
| 3695 | // CRLs. |type| may not be |X509_FILETYPE_DEFAULT|. |
| 3696 | OPENSSL_EXPORT int X509_load_cert_crl_file(X509_LOOKUP *lookup, |
| 3697 | const char *file, int type); |
| 3698 |
| 3699 | // X509_NAME_hash returns a hash of |name|, or zero on error. This is the new |
| 3700 | // hash used by |X509_LOOKUP_add_dir|. |
| 3701 | // |
| 3702 | // This hash is specific to the |X509_LOOKUP_add_dir| filesystem format and is |
| 3703 | // not suitable for general-purpose X.509 name processing. It is very short, so |
| 3704 | // there will be hash collisions. It also depends on an OpenSSL-specific |
| 3705 | // canonicalization process. |
| 3706 | // |
| 3707 | // TODO(https://crbug.com/boringssl/407): This should be const and thread-safe |
| 3708 | // but currently is neither, notably if |name| was modified from its parsed |
| 3709 | // value. |
| 3710 | OPENSSL_EXPORT uint32_t X509_NAME_hash(X509_NAME *name); |
| 3711 |
| 3712 | // X509_NAME_hash_old returns a hash of |name|, or zero on error. This is the |
| 3713 | // legacy hash used by |X509_LOOKUP_add_dir|, which is still supported for |
| 3714 | // compatibility. |
| 3715 | // |
| 3716 | // This hash is specific to the |X509_LOOKUP_add_dir| filesystem format and is |
| 3717 | // not suitable for general-purpose X.509 name processing. It is very short, so |
| 3718 | // there will be hash collisions. |
| 3719 | // |
| 3720 | // TODO(https://crbug.com/boringssl/407): This should be const and thread-safe |
| 3721 | // but currently is neither, notably if |name| was modified from its parsed |
| 3722 | // value. |
| 3723 | OPENSSL_EXPORT uint32_t X509_NAME_hash_old(X509_NAME *name); |
| 3724 |
| 3725 | // X509_STORE_set_default_paths configures |store| to read from some "default" |
| 3726 | // filesystem paths. It returns one on success and zero on error. The filesystem |
| 3727 | // paths are determined by a combination of hardcoded paths and the SSL_CERT_DIR |
| 3728 | // and SSL_CERT_FILE environment variables. |
| 3729 | // |
| 3730 | // Using this function is not recommended. In OpenSSL, these defaults are |
| 3731 | // determined by OpenSSL's install prefix. There is no corresponding concept for |
| 3732 | // BoringSSL. Future versions of BoringSSL may change or remove this |
| 3733 | // functionality. |
| 3734 | OPENSSL_EXPORT int X509_STORE_set_default_paths(X509_STORE *store); |
| 3735 |
| 3736 | // The following functions return filesystem paths used to determine the above |
| 3737 | // "default" paths, when the corresponding environment variables are not set. |
| 3738 | // |
| 3739 | // Using these functions is not recommended. In OpenSSL, these defaults are |
| 3740 | // determined by OpenSSL's install prefix. There is no corresponding concept for |
| 3741 | // BoringSSL. Future versions of BoringSSL may change or remove this |
| 3742 | // functionality. |
| 3743 | OPENSSL_EXPORT const char *X509_get_default_cert_area(void); |
| 3744 | OPENSSL_EXPORT const char *X509_get_default_cert_dir(void); |
| 3745 | OPENSSL_EXPORT const char *X509_get_default_cert_file(void); |
| 3746 | OPENSSL_EXPORT const char *X509_get_default_private_dir(void); |
| 3747 |
| 3748 | // X509_get_default_cert_dir_env returns "SSL_CERT_DIR", an environment variable |
| 3749 | // used to determine the above "default" paths. |
| 3750 | OPENSSL_EXPORT const char *X509_get_default_cert_dir_env(void); |
| 3751 |
| 3752 | // X509_get_default_cert_file_env returns "SSL_CERT_FILE", an environment |
| 3753 | // variable used to determine the above "default" paths. |
| 3754 | OPENSSL_EXPORT const char *X509_get_default_cert_file_env(void); |
| 3755 |
| 3756 |
| 3757 | // SignedPublicKeyAndChallenge structures. |
| 3758 | // |
| 3759 | // The SignedPublicKeyAndChallenge (SPKAC) is a legacy structure to request |
| 3760 | // certificates, primarily in the legacy <keygen> HTML tag. An SPKAC structure |
| 3761 | // is represented by a |NETSCAPE_SPKI| structure. |
| 3762 | // |
| 3763 | // The structure is described in |
| 3764 | // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/keygen |
| 3765 |
| 3766 | // A Netscape_spki_st, or |NETSCAPE_SPKI|, represents a |
| 3767 | // SignedPublicKeyAndChallenge structure. Although this structure contains a |
| 3768 | // |spkac| field of type |NETSCAPE_SPKAC|, these are misnamed. The SPKAC is the |
| 3769 | // entire structure, not the signed portion. |
| 3770 | struct Netscape_spki_st { |
| 3771 | NETSCAPE_SPKAC *spkac; |
| 3772 | X509_ALGOR *sig_algor; |
| 3773 | ASN1_BIT_STRING *signature; |
| 3774 | } /* NETSCAPE_SPKI */; |
| 3775 |
| 3776 | // NETSCAPE_SPKI_new returns a newly-allocated, empty |NETSCAPE_SPKI| object, or |
| 3777 | // NULL on error. |
| 3778 | OPENSSL_EXPORT NETSCAPE_SPKI *NETSCAPE_SPKI_new(void); |
| 3779 |
| 3780 | // NETSCAPE_SPKI_free releases memory associated with |spki|. |
| 3781 | OPENSSL_EXPORT void NETSCAPE_SPKI_free(NETSCAPE_SPKI *spki); |
| 3782 |
| 3783 | // d2i_NETSCAPE_SPKI parses up to |len| bytes from |*inp| as a DER-encoded |
| 3784 | // SignedPublicKeyAndChallenge structure, as described in |d2i_SAMPLE|. |
| 3785 | OPENSSL_EXPORT NETSCAPE_SPKI *d2i_NETSCAPE_SPKI(NETSCAPE_SPKI **out, |
| 3786 | const uint8_t **inp, long len); |
| 3787 |
| 3788 | // i2d_NETSCAPE_SPKI marshals |spki| as a DER-encoded |
| 3789 | // SignedPublicKeyAndChallenge structure, as described in |i2d_SAMPLE|. |
| 3790 | OPENSSL_EXPORT int i2d_NETSCAPE_SPKI(const NETSCAPE_SPKI *spki, uint8_t **outp); |
| 3791 |
| 3792 | // NETSCAPE_SPKI_verify checks that |spki| has a valid signature by |pkey|. It |
| 3793 | // returns one if the signature is valid and zero otherwise. |
| 3794 | OPENSSL_EXPORT int NETSCAPE_SPKI_verify(NETSCAPE_SPKI *spki, EVP_PKEY *pkey); |
| 3795 |
| 3796 | // NETSCAPE_SPKI_b64_decode decodes |len| bytes from |str| as a base64-encoded |
| 3797 | // SignedPublicKeyAndChallenge structure. It returns a newly-allocated |
| 3798 | // |NETSCAPE_SPKI| structure with the result, or NULL on error. If |len| is 0 or |
| 3799 | // negative, the length is calculated with |strlen| and |str| must be a |
| 3800 | // NUL-terminated C string. |
| 3801 | OPENSSL_EXPORT NETSCAPE_SPKI *NETSCAPE_SPKI_b64_decode(const char *str, |
| 3802 | ossl_ssize_t len); |
| 3803 |
| 3804 | // NETSCAPE_SPKI_b64_encode encodes |spki| as a base64-encoded |
| 3805 | // SignedPublicKeyAndChallenge structure. It returns a newly-allocated |
| 3806 | // NUL-terminated C string with the result, or NULL on error. The caller must |
| 3807 | // release the memory with |OPENSSL_free| when done. |
| 3808 | OPENSSL_EXPORT char *NETSCAPE_SPKI_b64_encode(NETSCAPE_SPKI *spki); |
| 3809 |
| 3810 | // NETSCAPE_SPKI_get_pubkey decodes and returns the public key in |spki| as an |
| 3811 | // |EVP_PKEY|, or NULL on error. The caller takes ownership of the resulting |
| 3812 | // pointer and must call |EVP_PKEY_free| when done. |
| 3813 | OPENSSL_EXPORT EVP_PKEY *NETSCAPE_SPKI_get_pubkey(const NETSCAPE_SPKI *spki); |
| 3814 |
| 3815 | // NETSCAPE_SPKI_set_pubkey sets |spki|'s public key to |pkey|. It returns one |
| 3816 | // on success or zero on error. This function does not take ownership of |pkey|, |
| 3817 | // so the caller may continue to manage its lifetime independently of |spki|. |
| 3818 | OPENSSL_EXPORT int NETSCAPE_SPKI_set_pubkey(NETSCAPE_SPKI *spki, |
| 3819 | EVP_PKEY *pkey); |
| 3820 |
| 3821 | // NETSCAPE_SPKI_sign signs |spki| with |pkey| and replaces the signature |
| 3822 | // algorithm and signature fields. It returns the length of the signature on |
| 3823 | // success and zero on error. This function uses digest algorithm |md|, or |
| 3824 | // |pkey|'s default if NULL. Other signing parameters use |pkey|'s defaults. |
| 3825 | OPENSSL_EXPORT int NETSCAPE_SPKI_sign(NETSCAPE_SPKI *spki, EVP_PKEY *pkey, |
| 3826 | const EVP_MD *md); |
| 3827 |
| 3828 | // A Netscape_spkac_st, or |NETSCAPE_SPKAC|, represents a PublicKeyAndChallenge |
| 3829 | // structure. This type is misnamed. The full SPKAC includes the signature, |
| 3830 | // which is represented with the |NETSCAPE_SPKI| type. |
| 3831 | struct Netscape_spkac_st { |
| 3832 | X509_PUBKEY *pubkey; |
| 3833 | ASN1_IA5STRING *challenge; |
| 3834 | } /* NETSCAPE_SPKAC */; |
| 3835 |
| 3836 | // NETSCAPE_SPKAC_new returns a newly-allocated, empty |NETSCAPE_SPKAC| object, |
| 3837 | // or NULL on error. |
| 3838 | OPENSSL_EXPORT NETSCAPE_SPKAC *NETSCAPE_SPKAC_new(void); |
| 3839 |
| 3840 | // NETSCAPE_SPKAC_free releases memory associated with |spkac|. |
| 3841 | OPENSSL_EXPORT void NETSCAPE_SPKAC_free(NETSCAPE_SPKAC *spkac); |
| 3842 |
| 3843 | // d2i_NETSCAPE_SPKAC parses up to |len| bytes from |*inp| as a DER-encoded |
| 3844 | // PublicKeyAndChallenge structure, as described in |d2i_SAMPLE|. |
| 3845 | OPENSSL_EXPORT NETSCAPE_SPKAC *d2i_NETSCAPE_SPKAC(NETSCAPE_SPKAC **out, |
| 3846 | const uint8_t **inp, |
| 3847 | long len); |
| 3848 |
| 3849 | // i2d_NETSCAPE_SPKAC marshals |spkac| as a DER-encoded PublicKeyAndChallenge |
| 3850 | // structure, as described in |i2d_SAMPLE|. |
| 3851 | OPENSSL_EXPORT int i2d_NETSCAPE_SPKAC(const NETSCAPE_SPKAC *spkac, |
| 3852 | uint8_t **outp); |
| 3853 |
| 3854 |
| 3855 | // RSASSA-PSS Parameters. |
| 3856 | // |
| 3857 | // In X.509, RSASSA-PSS signatures and keys use a complex parameter structure, |
| 3858 | // defined in RFC 4055. The following functions are provided for compatibility |
| 3859 | // with some OpenSSL APIs relating to this. Use of RSASSA-PSS in X.509 is |
| 3860 | // discouraged. The parameters structure is very complex, and it takes more |
| 3861 | // bytes to merely encode parameters than an entire P-256 ECDSA signature. |
| 3862 |
| 3863 | // An rsa_pss_params_st, aka |RSA_PSS_PARAMS|, represents a parsed |
| 3864 | // RSASSA-PSS-params structure, as defined in (RFC 4055). |
| 3865 | struct rsa_pss_params_st { |
| 3866 | X509_ALGOR *hashAlgorithm; |
| 3867 | X509_ALGOR *maskGenAlgorithm; |
| 3868 | ASN1_INTEGER *saltLength; |
| 3869 | ASN1_INTEGER *trailerField; |
| 3870 | // OpenSSL caches the MGF hash on |RSA_PSS_PARAMS| in some cases. None of the |
| 3871 | // cases apply to BoringSSL, so this is always NULL, but Node expects the |
| 3872 | // field to be present. |
| 3873 | X509_ALGOR *maskHash; |
| 3874 | } /* RSA_PSS_PARAMS */; |
| 3875 |
| 3876 | // RSA_PSS_PARAMS is an |ASN1_ITEM| whose ASN.1 type is RSASSA-PSS-params (RFC |
| 3877 | // 4055) and C type is |RSA_PSS_PARAMS*|. |
| 3878 | DECLARE_ASN1_ITEM(RSA_PSS_PARAMS) |
| 3879 |
| 3880 | // RSA_PSS_PARAMS_new returns a new, empty |RSA_PSS_PARAMS|, or NULL on error. |
| 3881 | OPENSSL_EXPORT RSA_PSS_PARAMS *RSA_PSS_PARAMS_new(void); |
| 3882 |
| 3883 | // RSA_PSS_PARAMS_free releases memory associated with |params|. |
| 3884 | OPENSSL_EXPORT void RSA_PSS_PARAMS_free(RSA_PSS_PARAMS *params); |
| 3885 |
| 3886 | // d2i_RSA_PSS_PARAMS parses up to |len| bytes from |*inp| as a DER-encoded |
| 3887 | // RSASSA-PSS-params (RFC 4055), as described in |d2i_SAMPLE|. |
| 3888 | OPENSSL_EXPORT RSA_PSS_PARAMS *d2i_RSA_PSS_PARAMS(RSA_PSS_PARAMS **out, |
| 3889 | const uint8_t **inp, |
| 3890 | long len); |
| 3891 |
| 3892 | // i2d_RSA_PSS_PARAMS marshals |in| as a DER-encoded RSASSA-PSS-params (RFC |
| 3893 | // 4055), as described in |i2d_SAMPLE|. |
| 3894 | OPENSSL_EXPORT int i2d_RSA_PSS_PARAMS(const RSA_PSS_PARAMS *in, uint8_t **outp); |
| 3895 |
| 3896 |
| 3897 | // PKCS#8 private keys. |
| 3898 | // |
| 3899 | // The |PKCS8_PRIV_KEY_INFO| type represents a PKCS#8 PrivateKeyInfo (RFC 5208) |
| 3900 | // structure. This is analogous to SubjectPublicKeyInfo and uses the same |
| 3901 | // AlgorithmIdentifiers, but carries private keys and is not part of X.509 |
| 3902 | // itself. |
| 3903 | // |
| 3904 | // TODO(davidben): Do these functions really belong in this header? |
| 3905 |
| 3906 | // PKCS8_PRIV_KEY_INFO_new returns a newly-allocated, empty |
| 3907 | // |PKCS8_PRIV_KEY_INFO| object, or NULL on error. |
| 3908 | OPENSSL_EXPORT PKCS8_PRIV_KEY_INFO *PKCS8_PRIV_KEY_INFO_new(void); |
| 3909 |
| 3910 | // PKCS8_PRIV_KEY_INFO_free releases memory associated with |key|. |
| 3911 | OPENSSL_EXPORT void PKCS8_PRIV_KEY_INFO_free(PKCS8_PRIV_KEY_INFO *key); |
| 3912 |
| 3913 | // d2i_PKCS8_PRIV_KEY_INFO parses up to |len| bytes from |*inp| as a DER-encoded |
| 3914 | // PrivateKeyInfo, as described in |d2i_SAMPLE|. |
| 3915 | OPENSSL_EXPORT PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO( |
| 3916 | PKCS8_PRIV_KEY_INFO **out, const uint8_t **inp, long len); |
| 3917 |
| 3918 | // i2d_PKCS8_PRIV_KEY_INFO marshals |key| as a DER-encoded PrivateKeyInfo, as |
| 3919 | // described in |i2d_SAMPLE|. |
| 3920 | OPENSSL_EXPORT int i2d_PKCS8_PRIV_KEY_INFO(const PKCS8_PRIV_KEY_INFO *key, |
| 3921 | uint8_t **outp); |
| 3922 |
| 3923 | // EVP_PKCS82PKEY returns |p8| as a newly-allocated |EVP_PKEY|, or NULL if the |
| 3924 | // key was unsupported or could not be decoded. The caller must release the |
| 3925 | // result with |EVP_PKEY_free| when done. |
| 3926 | // |
| 3927 | // Use |EVP_parse_private_key| instead. |
| 3928 | OPENSSL_EXPORT EVP_PKEY *EVP_PKCS82PKEY(const PKCS8_PRIV_KEY_INFO *p8); |
| 3929 |
| 3930 | // EVP_PKEY2PKCS8 encodes |pkey| as a PKCS#8 PrivateKeyInfo (RFC 5208), |
| 3931 | // represented as a newly-allocated |PKCS8_PRIV_KEY_INFO|, or NULL on error. The |
| 3932 | // caller must release the result with |PKCS8_PRIV_KEY_INFO_free| when done. |
| 3933 | // |
| 3934 | // Use |EVP_marshal_private_key| instead. |
| 3935 | OPENSSL_EXPORT PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(const EVP_PKEY *pkey); |
| 3936 |
| 3937 |
| 3938 | // Algorithm and octet string pairs. |
| 3939 | // |
| 3940 | // The |X509_SIG| type represents an ASN.1 SEQUENCE type of an |
| 3941 | // AlgorithmIdentifier and an OCTET STRING. Although named |X509_SIG|, there is |
| 3942 | // no type in X.509 which matches this format. The two common types which do are |
| 3943 | // DigestInfo (RFC 2315 and RFC 8017), and EncryptedPrivateKeyInfo (RFC 5208). |
| 3944 |
| 3945 | // X509_SIG_new returns a newly-allocated, empty |X509_SIG| object, or NULL on |
| 3946 | // error. |
| 3947 | OPENSSL_EXPORT X509_SIG *X509_SIG_new(void); |
| 3948 |
| 3949 | // X509_SIG_free releases memory associated with |key|. |
| 3950 | OPENSSL_EXPORT void X509_SIG_free(X509_SIG *key); |
| 3951 |
| 3952 | // d2i_X509_SIG parses up to |len| bytes from |*inp| as a DER-encoded algorithm |
| 3953 | // and octet string pair, as described in |d2i_SAMPLE|. |
| 3954 | OPENSSL_EXPORT X509_SIG *d2i_X509_SIG(X509_SIG **out, const uint8_t **inp, |
| 3955 | long len); |
| 3956 |
| 3957 | // i2d_X509_SIG marshals |sig| as a DER-encoded algorithm |
| 3958 | // and octet string pair, as described in |i2d_SAMPLE|. |
| 3959 | OPENSSL_EXPORT int i2d_X509_SIG(const X509_SIG *sig, uint8_t **outp); |
| 3960 |
| 3961 | // X509_SIG_get0 sets |*out_alg| and |*out_digest| to non-owning pointers to |
| 3962 | // |sig|'s algorithm and digest fields, respectively. Either |out_alg| and |
| 3963 | // |out_digest| may be NULL to skip those fields. |
| 3964 | OPENSSL_EXPORT void X509_SIG_get0(const X509_SIG *sig, |
| 3965 | const X509_ALGOR **out_alg, |
| 3966 | const ASN1_OCTET_STRING **out_digest); |
| 3967 |
| 3968 | // X509_SIG_getm behaves like |X509_SIG_get0| but returns mutable pointers. |
| 3969 | OPENSSL_EXPORT void X509_SIG_getm(X509_SIG *sig, X509_ALGOR **out_alg, |
| 3970 | ASN1_OCTET_STRING **out_digest); |
| 3971 |
| 3972 |
| 3973 | // Printing functions. |
| 3974 | // |
| 3975 | // The following functions output human-readable representations of |
| 3976 | // X.509-related structures. They should only be used for debugging or logging |
| 3977 | // and not parsed programmatically. In many cases, the outputs are ambiguous, so |
| 3978 | // attempting to parse them can lead to string injection vulnerabilities. |
| 3979 |
| 3980 | // The following flags control |X509_print_ex| and |X509_REQ_print_ex|. These |
| 3981 | // flags co-exist with |X509V3_EXT_*|, so avoid collisions when adding new ones. |
| 3982 |
| 3983 | // X509_FLAG_COMPAT disables all flags. It additionally causes names to be |
| 3984 | // printed with a 16-byte indent. |
| 3985 | #define X509_FLAG_COMPAT 0 |
| 3986 |
| 3987 | // X509_FLAG_NO_HEADER skips a header identifying the type of object printed. |
| 3988 | #define X509_FLAG_NO_HEADER 1L |
| 3989 |
| 3990 | // X509_FLAG_NO_VERSION skips printing the X.509 version number. |
| 3991 | #define X509_FLAG_NO_VERSION (1L << 1) |
| 3992 |
| 3993 | // X509_FLAG_NO_SERIAL skips printing the serial number. It is ignored in |
| 3994 | // |X509_REQ_print_fp|. |
| 3995 | #define X509_FLAG_NO_SERIAL (1L << 2) |
| 3996 |
| 3997 | // X509_FLAG_NO_SIGNAME skips printing the signature algorithm in the |
| 3998 | // TBSCertificate. It is ignored in |X509_REQ_print_fp|. |
| 3999 | #define X509_FLAG_NO_SIGNAME (1L << 3) |
| 4000 |
| 4001 | // X509_FLAG_NO_ISSUER skips printing the issuer. |
| 4002 | #define X509_FLAG_NO_ISSUER (1L << 4) |
| 4003 |
| 4004 | // X509_FLAG_NO_VALIDITY skips printing the notBefore and notAfter times. It is |
| 4005 | // ignored in |X509_REQ_print_fp|. |
| 4006 | #define X509_FLAG_NO_VALIDITY (1L << 5) |
| 4007 |
| 4008 | // X509_FLAG_NO_SUBJECT skips printing the subject. |
| 4009 | #define X509_FLAG_NO_SUBJECT (1L << 6) |
| 4010 |
| 4011 | // X509_FLAG_NO_PUBKEY skips printing the public key. |
| 4012 | #define X509_FLAG_NO_PUBKEY (1L << 7) |
| 4013 |
| 4014 | // X509_FLAG_NO_EXTENSIONS skips printing the extension list. It is ignored in |
| 4015 | // |X509_REQ_print_fp|. CSRs instead have attributes, which is controlled by |
| 4016 | // |X509_FLAG_NO_ATTRIBUTES|. |
| 4017 | #define X509_FLAG_NO_EXTENSIONS (1L << 8) |
| 4018 |
| 4019 | // X509_FLAG_NO_SIGDUMP skips printing the signature and outer signature |
| 4020 | // algorithm. |
| 4021 | #define X509_FLAG_NO_SIGDUMP (1L << 9) |
| 4022 |
| 4023 | // X509_FLAG_NO_AUX skips printing auxiliary properties. (See |d2i_X509_AUX| and |
| 4024 | // related functions.) |
| 4025 | #define X509_FLAG_NO_AUX (1L << 10) |
| 4026 |
| 4027 | // X509_FLAG_NO_ATTRIBUTES skips printing CSR attributes. It does nothing for |
| 4028 | // certificates and CRLs. |
| 4029 | #define X509_FLAG_NO_ATTRIBUTES (1L << 11) |
| 4030 |
| 4031 | // X509_FLAG_NO_IDS skips printing the issuerUniqueID and subjectUniqueID in a |
| 4032 | // certificate. It is ignored in |X509_REQ_print_fp|. |
| 4033 | #define X509_FLAG_NO_IDS (1L << 12) |
| 4034 |
| 4035 | // The following flags control |X509_print_ex|, |X509_REQ_print_ex|, |
| 4036 | // |X509V3_EXT_print|, and |X509V3_extensions_print|. These flags coexist with |
| 4037 | // |X509_FLAG_*|, so avoid collisions when adding new ones. |
| 4038 |
| 4039 | // X509V3_EXT_UNKNOWN_MASK is a mask that determines how unknown extensions are |
| 4040 | // processed. |
| 4041 | #define X509V3_EXT_UNKNOWN_MASK (0xfL << 16) |
| 4042 |
| 4043 | // X509V3_EXT_DEFAULT causes unknown extensions or syntax errors to return |
| 4044 | // failure. |
| 4045 | #define X509V3_EXT_DEFAULT 0 |
| 4046 |
| 4047 | // X509V3_EXT_ERROR_UNKNOWN causes unknown extensions or syntax errors to print |
| 4048 | // as "<Not Supported>" or "<Parse Error>", respectively. |
| 4049 | #define X509V3_EXT_ERROR_UNKNOWN (1L << 16) |
| 4050 |
| 4051 | // X509V3_EXT_PARSE_UNKNOWN is deprecated and behaves like |
| 4052 | // |X509V3_EXT_DUMP_UNKNOWN|. |
| 4053 | #define X509V3_EXT_PARSE_UNKNOWN (2L << 16) |
| 4054 |
| 4055 | // X509V3_EXT_DUMP_UNKNOWN causes unknown extensions to be displayed as a |
| 4056 | // hexdump. |
| 4057 | #define X509V3_EXT_DUMP_UNKNOWN (3L << 16) |
| 4058 |
| 4059 | // X509_print_ex writes a human-readable representation of |x| to |bp|. It |
| 4060 | // returns one on success and zero on error. |nmflags| is the flags parameter |
| 4061 | // for |X509_NAME_print_ex| when printing the subject and issuer. |cflag| should |
| 4062 | // be some combination of the |X509_FLAG_*| and |X509V3_EXT_*| constants. |
| 4063 | OPENSSL_EXPORT int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflag, |
| 4064 | unsigned long cflag); |
| 4065 |
| 4066 | // X509_print_ex_fp behaves like |X509_print_ex| but writes to |fp|. |
| 4067 | OPENSSL_EXPORT int X509_print_ex_fp(FILE *fp, X509 *x, unsigned long nmflag, |
| 4068 | unsigned long cflag); |
| 4069 |
| 4070 | // X509_print calls |X509_print_ex| with |XN_FLAG_COMPAT| and |X509_FLAG_COMPAT| |
| 4071 | // flags. |
| 4072 | OPENSSL_EXPORT int X509_print(BIO *bp, X509 *x); |
| 4073 |
| 4074 | // X509_print_fp behaves like |X509_print| but writes to |fp|. |
| 4075 | OPENSSL_EXPORT int X509_print_fp(FILE *fp, X509 *x); |
| 4076 |
| 4077 | // X509_CRL_print writes a human-readable representation of |x| to |bp|. It |
| 4078 | // returns one on success and zero on error. |
| 4079 | OPENSSL_EXPORT int X509_CRL_print(BIO *bp, X509_CRL *x); |
| 4080 |
| 4081 | // X509_CRL_print_fp behaves like |X509_CRL_print| but writes to |fp|. |
| 4082 | OPENSSL_EXPORT int X509_CRL_print_fp(FILE *fp, X509_CRL *x); |
| 4083 |
| 4084 | // X509_REQ_print_ex writes a human-readable representation of |x| to |bp|. It |
| 4085 | // returns one on success and zero on error. |nmflags| is the flags parameter |
| 4086 | // for |X509_NAME_print_ex|, when printing the subject. |cflag| should be some |
| 4087 | // combination of the |X509_FLAG_*| and |X509V3_EXT_*| constants. |
| 4088 | OPENSSL_EXPORT int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflag, |
| 4089 | unsigned long cflag); |
| 4090 |
| 4091 | // X509_REQ_print calls |X509_REQ_print_ex| with |XN_FLAG_COMPAT| and |
| 4092 | // |X509_FLAG_COMPAT| flags. |
| 4093 | OPENSSL_EXPORT int X509_REQ_print(BIO *bp, X509_REQ *req); |
| 4094 |
| 4095 | // X509_REQ_print_fp behaves like |X509_REQ_print| but writes to |fp|. |
| 4096 | OPENSSL_EXPORT int X509_REQ_print_fp(FILE *fp, X509_REQ *req); |
| 4097 |
| 4098 | // The following flags are control |X509_NAME_print_ex|. They must not collide |
| 4099 | // with |ASN1_STRFLGS_*|. |
| 4100 | // |
| 4101 | // TODO(davidben): This is far, far too many options and most of them are |
| 4102 | // useless. Trim this down. |
| 4103 |
| 4104 | // XN_FLAG_COMPAT prints with |X509_NAME_print|'s format and return value |
| 4105 | // convention. |
| 4106 | #define XN_FLAG_COMPAT 0ul |
| 4107 |
| 4108 | // XN_FLAG_SEP_MASK determines the separators to use between attributes. |
| 4109 | #define XN_FLAG_SEP_MASK (0xful << 16) |
| 4110 |
| 4111 | // XN_FLAG_SEP_COMMA_PLUS separates RDNs with "," and attributes within an RDN |
| 4112 | // with "+", as in RFC 2253. |
| 4113 | #define XN_FLAG_SEP_COMMA_PLUS (1ul << 16) |
| 4114 |
| 4115 | // XN_FLAG_SEP_CPLUS_SPC behaves like |XN_FLAG_SEP_COMMA_PLUS| but adds spaces |
| 4116 | // between the separators. |
| 4117 | #define XN_FLAG_SEP_CPLUS_SPC (2ul << 16) |
| 4118 |
| 4119 | // XN_FLAG_SEP_SPLUS_SPC separates RDNs with "; " and attributes within an RDN |
| 4120 | // with " + ". |
| 4121 | #define XN_FLAG_SEP_SPLUS_SPC (3ul << 16) |
| 4122 |
| 4123 | // XN_FLAG_SEP_MULTILINE prints each attribute on one line. |
| 4124 | #define XN_FLAG_SEP_MULTILINE (4ul << 16) |
| 4125 |
| 4126 | // XN_FLAG_DN_REV prints RDNs in reverse, from least significant to most |
| 4127 | // significant, as RFC 2253. |
| 4128 | #define XN_FLAG_DN_REV (1ul << 20) |
| 4129 |
| 4130 | // XN_FLAG_FN_MASK determines how attribute types are displayed. |
| 4131 | #define XN_FLAG_FN_MASK (0x3ul << 21) |
| 4132 |
| 4133 | // XN_FLAG_FN_SN uses the attribute type's short name, when available. |
| 4134 | #define XN_FLAG_FN_SN 0ul |
| 4135 |
| 4136 | // XN_FLAG_SPC_EQ wraps the "=" operator with spaces when printing attributes. |
| 4137 | #define XN_FLAG_SPC_EQ (1ul << 23) |
| 4138 |
| 4139 | // XN_FLAG_DUMP_UNKNOWN_FIELDS causes unknown attribute types to be printed in |
| 4140 | // hex, as in RFC 2253. |
| 4141 | #define XN_FLAG_DUMP_UNKNOWN_FIELDS (1ul << 24) |
| 4142 |
| 4143 | // XN_FLAG_RFC2253 prints like RFC 2253. |
| 4144 | #define XN_FLAG_RFC2253 \ |
| 4145 | (ASN1_STRFLGS_RFC2253 | XN_FLAG_SEP_COMMA_PLUS | XN_FLAG_DN_REV | \ |
| 4146 | XN_FLAG_FN_SN | XN_FLAG_DUMP_UNKNOWN_FIELDS) |
| 4147 |
| 4148 | // XN_FLAG_ONELINE prints a one-line representation of the name. |
| 4149 | #define XN_FLAG_ONELINE \ |
| 4150 | (ASN1_STRFLGS_RFC2253 | ASN1_STRFLGS_ESC_QUOTE | XN_FLAG_SEP_CPLUS_SPC | \ |
| 4151 | XN_FLAG_SPC_EQ | XN_FLAG_FN_SN) |
| 4152 |
| 4153 | // X509_NAME_print_ex writes a human-readable representation of |nm| to |out|. |
| 4154 | // Each line of output is indented by |indent| spaces. It returns the number of |
| 4155 | // bytes written on success, and -1 on error. If |out| is NULL, it returns the |
| 4156 | // number of bytes it would have written but does not write anything. |flags| |
| 4157 | // should be some combination of |XN_FLAG_*| and |ASN1_STRFLGS_*| values and |
| 4158 | // determines the output. If unsure, use |XN_FLAG_RFC2253|. |
| 4159 | // |
| 4160 | // If |flags| is |XN_FLAG_COMPAT|, or zero, this function calls |
| 4161 | // |X509_NAME_print| instead. In that case, it returns one on success, rather |
| 4162 | // than the output length. |
| 4163 | OPENSSL_EXPORT int X509_NAME_print_ex(BIO *out, const X509_NAME *nm, int indent, |
| 4164 | unsigned long flags); |
| 4165 |
| 4166 | // X509_NAME_print prints a human-readable representation of |name| to |bp|. It |
| 4167 | // returns one on success and zero on error. |obase| is ignored. |
| 4168 | // |
| 4169 | // This function outputs a legacy format that does not correctly handle string |
| 4170 | // encodings and other cases. Prefer |X509_NAME_print_ex| if printing a name for |
| 4171 | // debugging purposes. |
| 4172 | OPENSSL_EXPORT int X509_NAME_print(BIO *bp, const X509_NAME *name, int obase); |
| 4173 |
| 4174 | // X509_NAME_oneline writes a human-readable representation to |name| to a |
| 4175 | // buffer as a NUL-terminated C string. |
| 4176 | // |
| 4177 | // If |buf| is NULL, returns a newly-allocated buffer containing the result on |
| 4178 | // success, or NULL on error. The buffer must be released with |OPENSSL_free| |
| 4179 | // when done. |
| 4180 | // |
| 4181 | // If |buf| is non-NULL, at most |size| bytes of output are written to |buf| |
| 4182 | // instead. |size| includes the trailing NUL. The function then returns |buf| on |
| 4183 | // success or NULL on error. If the output does not fit in |size| bytes, the |
| 4184 | // output is silently truncated at an attribute boundary. |
| 4185 | // |
| 4186 | // This function outputs a legacy format that does not correctly handle string |
| 4187 | // encodings and other cases. Prefer |X509_NAME_print_ex| if printing a name for |
| 4188 | // debugging purposes. |
| 4189 | OPENSSL_EXPORT char *X509_NAME_oneline(const X509_NAME *name, char *buf, int size); |
| 4190 |
| 4191 | // X509_NAME_print_ex_fp behaves like |X509_NAME_print_ex| but writes to |fp|. |
| 4192 | OPENSSL_EXPORT int X509_NAME_print_ex_fp(FILE *fp, const X509_NAME *nm, |
| 4193 | int indent, unsigned long flags); |
| 4194 |
| 4195 | // X509_signature_dump writes a human-readable representation of |sig| to |bio|, |
| 4196 | // indented with |indent| spaces. It returns one on success and zero on error. |
| 4197 | OPENSSL_EXPORT int X509_signature_dump(BIO *bio, const ASN1_STRING *sig, |
| 4198 | int indent); |
| 4199 |
| 4200 | // X509_signature_print writes a human-readable representation of |alg| and |
| 4201 | // |sig| to |bio|. It returns one on success and zero on error. |
| 4202 | OPENSSL_EXPORT int X509_signature_print(BIO *bio, const X509_ALGOR *alg, |
| 4203 | const ASN1_STRING *sig); |
| 4204 |
| 4205 | // X509V3_EXT_print prints a human-readable representation of |ext| to out. It |
| 4206 | // returns one on success and zero on error. The output is indented by |indent| |
| 4207 | // spaces. |flag| is one of the |X509V3_EXT_*| constants and controls printing |
| 4208 | // of unknown extensions and syntax errors. |
| 4209 | // |
| 4210 | // WARNING: Although some applications programmatically parse the output of this |
| 4211 | // function to process X.509 extensions, this is not safe. In many cases, the |
| 4212 | // outputs are ambiguous to attempting to parse them can lead to string |
| 4213 | // injection vulnerabilities. These functions should only be used for debugging |
| 4214 | // or logging. |
| 4215 | OPENSSL_EXPORT int X509V3_EXT_print(BIO *out, const X509_EXTENSION *ext, |
| 4216 | unsigned long flag, int indent); |
| 4217 |
| 4218 | // X509V3_EXT_print_fp behaves like |X509V3_EXT_print| but writes to a |FILE| |
| 4219 | // instead of a |BIO|. |
| 4220 | OPENSSL_EXPORT int X509V3_EXT_print_fp(FILE *out, const X509_EXTENSION *ext, |
| 4221 | int flag, int indent); |
| 4222 |
| 4223 | // X509V3_extensions_print prints |title|, followed by a human-readable |
| 4224 | // representation of |exts| to |out|. It returns one on success and zero on |
| 4225 | // error. The output is indented by |indent| spaces. |flag| is one of the |
| 4226 | // |X509V3_EXT_*| constants and controls printing of unknown extensions and |
| 4227 | // syntax errors. |
| 4228 | OPENSSL_EXPORT int X509V3_extensions_print(BIO *out, const char *title, |
| 4229 | const STACK_OF(X509_EXTENSION) *exts, |
| 4230 | unsigned long flag, int indent); |
| 4231 |
| 4232 | // GENERAL_NAME_print prints a human-readable representation of |gen| to |out|. |
| 4233 | // It returns one on success and zero on error. |
| 4234 | // |
| 4235 | // TODO(davidben): Actually, it just returns one and doesn't check for I/O or |
| 4236 | // allocation errors. But it should return zero on error. |
| 4237 | OPENSSL_EXPORT int GENERAL_NAME_print(BIO *out, const GENERAL_NAME *gen); |
| 4238 |
| 4239 |
| 4240 | // Convenience functions. |
| 4241 |
| 4242 | // X509_pubkey_digest hashes the contents of the BIT STRING in |x509|'s |
| 4243 | // subjectPublicKeyInfo field with |md| and writes the result to |out|. |
| 4244 | // |EVP_MD_CTX_size| bytes are written, which is at most |EVP_MAX_MD_SIZE|. If |
| 4245 | // |out_len| is not NULL, |*out_len| is set to the number of bytes written. This |
| 4246 | // function returns one on success and zero on error. |
| 4247 | // |
| 4248 | // This hash omits the BIT STRING tag, length, and number of unused bits. It |
| 4249 | // also omits the AlgorithmIdentifier which describes the key type. It |
| 4250 | // corresponds to the OCSP KeyHash definition and is not suitable for other |
| 4251 | // purposes. |
| 4252 | OPENSSL_EXPORT int X509_pubkey_digest(const X509 *x509, const EVP_MD *md, |
| 4253 | uint8_t *out, unsigned *out_len); |
| 4254 |
| 4255 | // X509_digest hashes |x509|'s DER encoding with |md| and writes the result to |
| 4256 | // |out|. |EVP_MD_CTX_size| bytes are written, which is at most |
| 4257 | // |EVP_MAX_MD_SIZE|. If |out_len| is not NULL, |*out_len| is set to the number |
| 4258 | // of bytes written. This function returns one on success and zero on error. |
| 4259 | // Note this digest covers the entire certificate, not just the signed portion. |
| 4260 | OPENSSL_EXPORT int X509_digest(const X509 *x509, const EVP_MD *md, uint8_t *out, |
| 4261 | unsigned *out_len); |
| 4262 |
| 4263 | // X509_CRL_digest hashes |crl|'s DER encoding with |md| and writes the result |
| 4264 | // to |out|. |EVP_MD_CTX_size| bytes are written, which is at most |
| 4265 | // |EVP_MAX_MD_SIZE|. If |out_len| is not NULL, |*out_len| is set to the number |
| 4266 | // of bytes written. This function returns one on success and zero on error. |
| 4267 | // Note this digest covers the entire CRL, not just the signed portion. |
| 4268 | OPENSSL_EXPORT int X509_CRL_digest(const X509_CRL *crl, const EVP_MD *md, |
| 4269 | uint8_t *out, unsigned *out_len); |
| 4270 |
| 4271 | // X509_REQ_digest hashes |req|'s DER encoding with |md| and writes the result |
| 4272 | // to |out|. |EVP_MD_CTX_size| bytes are written, which is at most |
| 4273 | // |EVP_MAX_MD_SIZE|. If |out_len| is not NULL, |*out_len| is set to the number |
| 4274 | // of bytes written. This function returns one on success and zero on error. |
| 4275 | // Note this digest covers the entire certificate request, not just the signed |
| 4276 | // portion. |
| 4277 | OPENSSL_EXPORT int X509_REQ_digest(const X509_REQ *req, const EVP_MD *md, |
| 4278 | uint8_t *out, unsigned *out_len); |
| 4279 |
| 4280 | // X509_NAME_digest hashes |name|'s DER encoding with |md| and writes the result |
| 4281 | // to |out|. |EVP_MD_CTX_size| bytes are written, which is at most |
| 4282 | // |EVP_MAX_MD_SIZE|. If |out_len| is not NULL, |*out_len| is set to the number |
| 4283 | // of bytes written. This function returns one on success and zero on error. |
| 4284 | OPENSSL_EXPORT int X509_NAME_digest(const X509_NAME *name, const EVP_MD *md, |
| 4285 | uint8_t *out, unsigned *out_len); |
| 4286 |
| 4287 | // The following functions behave like the corresponding unsuffixed |d2i_*| |
| 4288 | // functions, but read the result from |bp| instead. Callers using these |
| 4289 | // functions with memory |BIO|s to parse structures already in memory should use |
| 4290 | // |d2i_*| instead. |
| 4291 | OPENSSL_EXPORT X509 *d2i_X509_bio(BIO *bp, X509 **x509); |
| 4292 | OPENSSL_EXPORT X509_CRL *d2i_X509_CRL_bio(BIO *bp, X509_CRL **crl); |
| 4293 | OPENSSL_EXPORT X509_REQ *d2i_X509_REQ_bio(BIO *bp, X509_REQ **req); |
| 4294 | OPENSSL_EXPORT RSA *d2i_RSAPrivateKey_bio(BIO *bp, RSA **rsa); |
| 4295 | OPENSSL_EXPORT RSA *d2i_RSAPublicKey_bio(BIO *bp, RSA **rsa); |
| 4296 | OPENSSL_EXPORT RSA *d2i_RSA_PUBKEY_bio(BIO *bp, RSA **rsa); |
| 4297 | OPENSSL_EXPORT DSA *d2i_DSA_PUBKEY_bio(BIO *bp, DSA **dsa); |
| 4298 | OPENSSL_EXPORT DSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA **dsa); |
| 4299 | OPENSSL_EXPORT EC_KEY *d2i_EC_PUBKEY_bio(BIO *bp, EC_KEY **eckey); |
| 4300 | OPENSSL_EXPORT EC_KEY *d2i_ECPrivateKey_bio(BIO *bp, EC_KEY **eckey); |
| 4301 | OPENSSL_EXPORT X509_SIG *d2i_PKCS8_bio(BIO *bp, X509_SIG **p8); |
| 4302 | OPENSSL_EXPORT PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_bio( |
| 4303 | BIO *bp, PKCS8_PRIV_KEY_INFO **p8inf); |
| 4304 | OPENSSL_EXPORT EVP_PKEY *d2i_PUBKEY_bio(BIO *bp, EVP_PKEY **a); |
| 4305 | OPENSSL_EXPORT DH *d2i_DHparams_bio(BIO *bp, DH **dh); |
| 4306 |
| 4307 | // d2i_PrivateKey_bio behaves like |d2i_AutoPrivateKey|, but reads from |bp| |
| 4308 | // instead. |
| 4309 | OPENSSL_EXPORT EVP_PKEY *d2i_PrivateKey_bio(BIO *bp, EVP_PKEY **a); |
| 4310 |
| 4311 | // The following functions behave like the corresponding unsuffixed |i2d_*| |
| 4312 | // functions, but write the result to |bp|. They return one on success and zero |
| 4313 | // on error. Callers using them with memory |BIO|s to encode structures to |
| 4314 | // memory should use |i2d_*| directly instead. |
| 4315 | OPENSSL_EXPORT int i2d_X509_bio(BIO *bp, X509 *x509); |
| 4316 | OPENSSL_EXPORT int i2d_X509_CRL_bio(BIO *bp, X509_CRL *crl); |
| 4317 | OPENSSL_EXPORT int i2d_X509_REQ_bio(BIO *bp, X509_REQ *req); |
| 4318 | OPENSSL_EXPORT int i2d_RSAPrivateKey_bio(BIO *bp, RSA *rsa); |
| 4319 | OPENSSL_EXPORT int i2d_RSAPublicKey_bio(BIO *bp, RSA *rsa); |
| 4320 | OPENSSL_EXPORT int i2d_RSA_PUBKEY_bio(BIO *bp, RSA *rsa); |
| 4321 | OPENSSL_EXPORT int i2d_DSA_PUBKEY_bio(BIO *bp, DSA *dsa); |
| 4322 | OPENSSL_EXPORT int i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa); |
| 4323 | OPENSSL_EXPORT int i2d_EC_PUBKEY_bio(BIO *bp, EC_KEY *eckey); |
| 4324 | OPENSSL_EXPORT int i2d_ECPrivateKey_bio(BIO *bp, EC_KEY *eckey); |
| 4325 | OPENSSL_EXPORT int i2d_PKCS8_bio(BIO *bp, X509_SIG *p8); |
| 4326 | OPENSSL_EXPORT int i2d_PKCS8_PRIV_KEY_INFO_bio(BIO *bp, |
| 4327 | PKCS8_PRIV_KEY_INFO *p8inf); |
| 4328 | OPENSSL_EXPORT int i2d_PrivateKey_bio(BIO *bp, EVP_PKEY *pkey); |
| 4329 | OPENSSL_EXPORT int i2d_PUBKEY_bio(BIO *bp, EVP_PKEY *pkey); |
| 4330 | OPENSSL_EXPORT int i2d_DHparams_bio(BIO *bp, const DH *dh); |
| 4331 |
| 4332 | // i2d_PKCS8PrivateKeyInfo_bio encodes |key| as a PKCS#8 PrivateKeyInfo |
| 4333 | // structure (see |EVP_marshal_private_key|) and writes the result to |bp|. It |
| 4334 | // returns one on success and zero on error. |
| 4335 | OPENSSL_EXPORT int i2d_PKCS8PrivateKeyInfo_bio(BIO *bp, EVP_PKEY *key); |
| 4336 |
| 4337 | // The following functions behave like the corresponding |d2i_*_bio| functions, |
| 4338 | // but read from |fp| instead. |
| 4339 | OPENSSL_EXPORT X509 *d2i_X509_fp(FILE *fp, X509 **x509); |
| 4340 | OPENSSL_EXPORT X509_CRL *d2i_X509_CRL_fp(FILE *fp, X509_CRL **crl); |
| 4341 | OPENSSL_EXPORT X509_REQ *d2i_X509_REQ_fp(FILE *fp, X509_REQ **req); |
| 4342 | OPENSSL_EXPORT RSA *d2i_RSAPrivateKey_fp(FILE *fp, RSA **rsa); |
| 4343 | OPENSSL_EXPORT RSA *d2i_RSAPublicKey_fp(FILE *fp, RSA **rsa); |
| 4344 | OPENSSL_EXPORT RSA *d2i_RSA_PUBKEY_fp(FILE *fp, RSA **rsa); |
| 4345 | OPENSSL_EXPORT DSA *d2i_DSA_PUBKEY_fp(FILE *fp, DSA **dsa); |
| 4346 | OPENSSL_EXPORT DSA *d2i_DSAPrivateKey_fp(FILE *fp, DSA **dsa); |
| 4347 | OPENSSL_EXPORT EC_KEY *d2i_EC_PUBKEY_fp(FILE *fp, EC_KEY **eckey); |
| 4348 | OPENSSL_EXPORT EC_KEY *d2i_ECPrivateKey_fp(FILE *fp, EC_KEY **eckey); |
| 4349 | OPENSSL_EXPORT X509_SIG *d2i_PKCS8_fp(FILE *fp, X509_SIG **p8); |
| 4350 | OPENSSL_EXPORT PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_fp( |
| 4351 | FILE *fp, PKCS8_PRIV_KEY_INFO **p8inf); |
| 4352 | OPENSSL_EXPORT EVP_PKEY *d2i_PrivateKey_fp(FILE *fp, EVP_PKEY **a); |
| 4353 | OPENSSL_EXPORT EVP_PKEY *d2i_PUBKEY_fp(FILE *fp, EVP_PKEY **a); |
| 4354 |
| 4355 | // The following functions behave like the corresponding |i2d_*_bio| functions, |
| 4356 | // but write to |fp| instead. |
| 4357 | OPENSSL_EXPORT int i2d_X509_fp(FILE *fp, X509 *x509); |
| 4358 | OPENSSL_EXPORT int i2d_X509_CRL_fp(FILE *fp, X509_CRL *crl); |
| 4359 | OPENSSL_EXPORT int i2d_X509_REQ_fp(FILE *fp, X509_REQ *req); |
| 4360 | OPENSSL_EXPORT int i2d_RSAPrivateKey_fp(FILE *fp, RSA *rsa); |
| 4361 | OPENSSL_EXPORT int i2d_RSAPublicKey_fp(FILE *fp, RSA *rsa); |
| 4362 | OPENSSL_EXPORT int i2d_RSA_PUBKEY_fp(FILE *fp, RSA *rsa); |
| 4363 | OPENSSL_EXPORT int i2d_DSA_PUBKEY_fp(FILE *fp, DSA *dsa); |
| 4364 | OPENSSL_EXPORT int i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa); |
| 4365 | OPENSSL_EXPORT int i2d_EC_PUBKEY_fp(FILE *fp, EC_KEY *eckey); |
| 4366 | OPENSSL_EXPORT int i2d_ECPrivateKey_fp(FILE *fp, EC_KEY *eckey); |
| 4367 | OPENSSL_EXPORT int i2d_PKCS8_fp(FILE *fp, X509_SIG *p8); |
| 4368 | OPENSSL_EXPORT int i2d_PKCS8_PRIV_KEY_INFO_fp(FILE *fp, |
| 4369 | PKCS8_PRIV_KEY_INFO *p8inf); |
| 4370 | OPENSSL_EXPORT int i2d_PKCS8PrivateKeyInfo_fp(FILE *fp, EVP_PKEY *key); |
| 4371 | OPENSSL_EXPORT int i2d_PrivateKey_fp(FILE *fp, EVP_PKEY *pkey); |
| 4372 | OPENSSL_EXPORT int i2d_PUBKEY_fp(FILE *fp, EVP_PKEY *pkey); |
| 4373 |
| 4374 | // X509_find_by_issuer_and_serial returns the first |X509| in |sk| whose issuer |
| 4375 | // and serial are |name| and |serial|, respectively. If no match is found, it |
| 4376 | // returns NULL. |
| 4377 | OPENSSL_EXPORT X509 *X509_find_by_issuer_and_serial(const STACK_OF(X509) *sk, |
| 4378 | X509_NAME *name, |
| 4379 | const ASN1_INTEGER *serial); |
| 4380 |
| 4381 | // X509_find_by_subject returns the first |X509| in |sk| whose subject is |
| 4382 | // |name|. If no match is found, it returns NULL. |
| 4383 | OPENSSL_EXPORT X509 *X509_find_by_subject(const STACK_OF(X509) *sk, |
| 4384 | X509_NAME *name); |
| 4385 |
| 4386 | // X509_cmp_time compares |s| against |*t|. On success, it returns a negative |
| 4387 | // number if |s| <= |*t| and a positive number if |s| > |*t|. On error, it |
| 4388 | // returns zero. If |t| is NULL, it uses the current time instead of |*t|. |
| 4389 | // |
| 4390 | // WARNING: Unlike most comparison functions, this function returns zero on |
| 4391 | // error, not equality. |
| 4392 | OPENSSL_EXPORT int X509_cmp_time(const ASN1_TIME *s, const time_t *t); |
| 4393 |
| 4394 | // X509_cmp_time_posix compares |s| against |t|. On success, it returns a |
| 4395 | // negative number if |s| <= |t| and a positive number if |s| > |t|. On error, |
| 4396 | // it returns zero. |
| 4397 | // |
| 4398 | // WARNING: Unlike most comparison functions, this function returns zero on |
| 4399 | // error, not equality. |
| 4400 | OPENSSL_EXPORT int X509_cmp_time_posix(const ASN1_TIME *s, int64_t t); |
| 4401 |
| 4402 | // X509_cmp_current_time behaves like |X509_cmp_time| but compares |s| against |
| 4403 | // the current time. |
| 4404 | OPENSSL_EXPORT int X509_cmp_current_time(const ASN1_TIME *s); |
| 4405 |
| 4406 | // X509_time_adj calls |X509_time_adj_ex| with |offset_day| equal to zero. |
| 4407 | OPENSSL_EXPORT ASN1_TIME *X509_time_adj(ASN1_TIME *s, long offset_sec, |
| 4408 | const time_t *t); |
| 4409 |
| 4410 | // X509_time_adj_ex behaves like |ASN1_TIME_adj|, but adds an offset to |*t|. If |
| 4411 | // |t| is NULL, it uses the current time instead of |*t|. |
| 4412 | OPENSSL_EXPORT ASN1_TIME *X509_time_adj_ex(ASN1_TIME *s, int offset_day, |
| 4413 | long offset_sec, const time_t *t); |
| 4414 |
| 4415 | // X509_gmtime_adj behaves like |X509_time_adj_ex| but adds |offset_sec| to the |
| 4416 | // current time. |
| 4417 | OPENSSL_EXPORT ASN1_TIME *X509_gmtime_adj(ASN1_TIME *s, long offset_sec); |
| 4418 |
| 4419 | // X509_issuer_name_cmp behaves like |X509_NAME_cmp|, but compares |a| and |b|'s |
| 4420 | // issuer names. |
| 4421 | OPENSSL_EXPORT int X509_issuer_name_cmp(const X509 *a, const X509 *b); |
| 4422 |
| 4423 | // X509_subject_name_cmp behaves like |X509_NAME_cmp|, but compares |a| and |
| 4424 | // |b|'s subject names. |
| 4425 | OPENSSL_EXPORT int X509_subject_name_cmp(const X509 *a, const X509 *b); |
| 4426 |
| 4427 | // X509_CRL_cmp behaves like |X509_NAME_cmp|, but compares |a| and |b|'s |
| 4428 | // issuer names. |
| 4429 | // |
| 4430 | // WARNING: This function is misnamed. It does not compare other parts of the |
| 4431 | // CRL, only the issuer fields using |X509_NAME_cmp|. |
| 4432 | OPENSSL_EXPORT int X509_CRL_cmp(const X509_CRL *a, const X509_CRL *b); |
| 4433 |
| 4434 | // X509_issuer_name_hash returns the hash of |x509|'s issuer name with |
| 4435 | // |X509_NAME_hash|. |
| 4436 | // |
| 4437 | // This hash is specific to the |X509_LOOKUP_add_dir| filesystem format and is |
| 4438 | // not suitable for general-purpose X.509 name processing. It is very short, so |
| 4439 | // there will be hash collisions. It also depends on an OpenSSL-specific |
| 4440 | // canonicalization process. |
| 4441 | OPENSSL_EXPORT uint32_t X509_issuer_name_hash(X509 *x509); |
| 4442 |
| 4443 | // X509_subject_name_hash returns the hash of |x509|'s subject name with |
| 4444 | // |X509_NAME_hash|. |
| 4445 | // |
| 4446 | // This hash is specific to the |X509_LOOKUP_add_dir| filesystem format and is |
| 4447 | // not suitable for general-purpose X.509 name processing. It is very short, so |
| 4448 | // there will be hash collisions. It also depends on an OpenSSL-specific |
| 4449 | // canonicalization process. |
| 4450 | OPENSSL_EXPORT uint32_t X509_subject_name_hash(X509 *x509); |
| 4451 |
| 4452 | // X509_issuer_name_hash_old returns the hash of |x509|'s issuer name with |
| 4453 | // |X509_NAME_hash_old|. |
| 4454 | // |
| 4455 | // This hash is specific to the |X509_LOOKUP_add_dir| filesystem format and is |
| 4456 | // not suitable for general-purpose X.509 name processing. It is very short, so |
| 4457 | // there will be hash collisions. |
| 4458 | OPENSSL_EXPORT uint32_t X509_issuer_name_hash_old(X509 *x509); |
| 4459 |
| 4460 | // X509_subject_name_hash_old returns the hash of |x509|'s usjbect name with |
| 4461 | // |X509_NAME_hash_old|. |
| 4462 | // |
| 4463 | // This hash is specific to the |X509_LOOKUP_add_dir| filesystem format and is |
| 4464 | // not suitable for general-purpose X.509 name processing. It is very short, so |
| 4465 | // there will be hash collisions. |
| 4466 | OPENSSL_EXPORT uint32_t X509_subject_name_hash_old(X509 *x509); |
| 4467 |
| 4468 |
| 4469 | // ex_data functions. |
| 4470 | // |
| 4471 | // See |ex_data.h| for details. |
| 4472 |
| 4473 | OPENSSL_EXPORT int X509_get_ex_new_index(long argl, void *argp, |
| 4474 | CRYPTO_EX_unused *unused, |
| 4475 | CRYPTO_EX_dup *dup_unused, |
| 4476 | CRYPTO_EX_free *free_func); |
| 4477 | OPENSSL_EXPORT int X509_set_ex_data(X509 *r, int idx, void *arg); |
| 4478 | OPENSSL_EXPORT void *X509_get_ex_data(X509 *r, int idx); |
| 4479 |
| 4480 | OPENSSL_EXPORT int X509_STORE_CTX_get_ex_new_index(long argl, void *argp, |
| 4481 | CRYPTO_EX_unused *unused, |
| 4482 | CRYPTO_EX_dup *dup_unused, |
| 4483 | CRYPTO_EX_free *free_func); |
| 4484 | OPENSSL_EXPORT int X509_STORE_CTX_set_ex_data(X509_STORE_CTX *ctx, int idx, |
| 4485 | void *data); |
| 4486 | OPENSSL_EXPORT void *X509_STORE_CTX_get_ex_data(X509_STORE_CTX *ctx, int idx); |
| 4487 |
| 4488 | #define X509_STORE_CTX_set_app_data(ctx, data) \ |
| 4489 | X509_STORE_CTX_set_ex_data(ctx, 0, data) |
| 4490 | #define X509_STORE_CTX_get_app_data(ctx) X509_STORE_CTX_get_ex_data(ctx, 0) |
| 4491 |
| 4492 |
| 4493 | // Hashing and signing ASN.1 structures. |
| 4494 |
| 4495 | // ASN1_digest serializes |data| with |i2d| and then hashes the result with |
| 4496 | // |type|. On success, it returns one, writes the digest to |md|, and sets |
| 4497 | // |*len| to the digest length if non-NULL. On error, it returns zero. |
| 4498 | // |
| 4499 | // |EVP_MD_CTX_size| bytes are written, which is at most |EVP_MAX_MD_SIZE|. The |
| 4500 | // buffer must have sufficient space for this output. |
| 4501 | OPENSSL_EXPORT int ASN1_digest(i2d_of_void *i2d, const EVP_MD *type, char *data, |
| 4502 | unsigned char *md, unsigned int *len); |
| 4503 |
| 4504 | // ASN1_item_digest serializes |data| with |it| and then hashes the result with |
| 4505 | // |type|. On success, it returns one, writes the digest to |md|, and sets |
| 4506 | // |*len| to the digest length if non-NULL. On error, it returns zero. |
| 4507 | // |
| 4508 | // |EVP_MD_CTX_size| bytes are written, which is at most |EVP_MAX_MD_SIZE|. The |
| 4509 | // buffer must have sufficient space for this output. |
| 4510 | // |
| 4511 | // WARNING: |data| must be a pointer with the same type as |it|'s corresponding |
| 4512 | // C type. Using the wrong type is a potentially exploitable memory error. |
| 4513 | OPENSSL_EXPORT int ASN1_item_digest(const ASN1_ITEM *it, const EVP_MD *type, |
| 4514 | void *data, unsigned char *md, |
| 4515 | unsigned int *len); |
| 4516 |
| 4517 | // ASN1_item_verify serializes |data| with |it| and then verifies |signature| is |
| 4518 | // a valid signature for the result with |algor1| and |pkey|. It returns one on |
| 4519 | // success and zero on error. The signature and algorithm are interpreted as in |
| 4520 | // X.509. |
| 4521 | // |
| 4522 | // WARNING: |data| must be a pointer with the same type as |it|'s corresponding |
| 4523 | // C type. Using the wrong type is a potentially exploitable memory error. |
| 4524 | OPENSSL_EXPORT int ASN1_item_verify(const ASN1_ITEM *it, |
| 4525 | const X509_ALGOR *algor1, |
| 4526 | const ASN1_BIT_STRING *signature, |
| 4527 | void *data, EVP_PKEY *pkey); |
| 4528 |
| 4529 | // ASN1_item_sign serializes |data| with |it| and then signs the result with |
| 4530 | // the private key |pkey|. It returns the length of the signature on success and |
| 4531 | // zero on error. On success, it writes the signature to |signature| and the |
| 4532 | // signature algorithm to each of |algor1| and |algor2|. Either of |algor1| or |
| 4533 | // |algor2| may be NULL to ignore them. This function uses digest algorithm |
| 4534 | // |md|, or |pkey|'s default if NULL. Other signing parameters use |pkey|'s |
| 4535 | // defaults. To customize them, use |ASN1_item_sign_ctx|. |
| 4536 | // |
| 4537 | // WARNING: |data| must be a pointer with the same type as |it|'s corresponding |
| 4538 | // C type. Using the wrong type is a potentially exploitable memory error. |
| 4539 | OPENSSL_EXPORT int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, |
| 4540 | X509_ALGOR *algor2, |
| 4541 | ASN1_BIT_STRING *signature, void *data, |
| 4542 | EVP_PKEY *pkey, const EVP_MD *type); |
| 4543 |
| 4544 | // ASN1_item_sign_ctx behaves like |ASN1_item_sign| except the signature is |
| 4545 | // signed with |ctx|, |ctx|, which must have been initialized with |
| 4546 | // |EVP_DigestSignInit|. The caller should configure the corresponding |
| 4547 | // |EVP_PKEY_CTX| with any additional parameters before calling this function. |
| 4548 | // |
| 4549 | // On success or failure, this function mutates |ctx| and resets it to the empty |
| 4550 | // state. Caller should not rely on its contents after the function returns. |
| 4551 | // |
| 4552 | // WARNING: |data| must be a pointer with the same type as |it|'s corresponding |
| 4553 | // C type. Using the wrong type is a potentially exploitable memory error. |
| 4554 | OPENSSL_EXPORT int ASN1_item_sign_ctx(const ASN1_ITEM *it, X509_ALGOR *algor1, |
| 4555 | X509_ALGOR *algor2, |
| 4556 | ASN1_BIT_STRING *signature, void *asn, |
| 4557 | EVP_MD_CTX *ctx); |
| 4558 |
| 4559 |
| 4560 | // Verification internals. |
| 4561 | // |
| 4562 | // The following functions expose portions of certificate validation. They are |
| 4563 | // exported for compatibility with existing callers, or to support some obscure |
| 4564 | // use cases. Most callers, however, will not need these functions and should |
| 4565 | // instead use |X509_STORE_CTX| APIs. |
| 4566 |
| 4567 | // X509_supported_extension returns one if |ex| is a critical X.509 certificate |
| 4568 | // extension, supported by |X509_verify_cert|, and zero otherwise. |
| 4569 | // |
| 4570 | // Note this function only reports certificate extensions (as opposed to CRL or |
| 4571 | // CRL extensions), and only extensions that are expected to be marked critical. |
| 4572 | // Additionally, |X509_verify_cert| checks for unsupported critical extensions |
| 4573 | // internally, so most callers will not need to call this function separately. |
| 4574 | OPENSSL_EXPORT int X509_supported_extension(const X509_EXTENSION *ex); |
| 4575 |
| 4576 | // X509_check_ca returns one if |x509| may be considered a CA certificate, |
| 4577 | // according to basic constraints and key usage extensions. Otherwise, it |
| 4578 | // returns zero. If |x509| is an X509v1 certificate, and thus has no extensions, |
| 4579 | // it is considered eligible. |
| 4580 | // |
| 4581 | // This function returning one does not indicate that |x509| is trusted, only |
| 4582 | // that it is eligible to be a CA. |
| 4583 | // |
| 4584 | // TODO(crbug.com/boringssl/407): |x509| should be const. |
| 4585 | OPENSSL_EXPORT int X509_check_ca(X509 *x509); |
| 4586 |
| 4587 | // X509_check_issued checks if |issuer| and |subject|'s name, authority key |
| 4588 | // identifier, and key usage fields allow |issuer| to have issued |subject|. It |
| 4589 | // returns |X509_V_OK| on success and an |X509_V_ERR_*| value otherwise. |
| 4590 | // |
| 4591 | // This function does not check the signature on |subject|. Rather, it is |
| 4592 | // intended to prune the set of possible issuer certificates during |
| 4593 | // path-building. |
| 4594 | // |
| 4595 | // TODO(crbug.com/boringssl/407): Both parameters should be const. |
| 4596 | OPENSSL_EXPORT int X509_check_issued(X509 *issuer, X509 *subject); |
| 4597 |
| 4598 | // NAME_CONSTRAINTS_check checks if |x509| satisfies name constraints in |nc|. |
| 4599 | // It returns |X509_V_OK| on success and some |X509_V_ERR_*| constant on error. |
| 4600 | // |
| 4601 | // TODO(crbug.com/boringssl/407): Both parameters should be const. |
| 4602 | OPENSSL_EXPORT int NAME_CONSTRAINTS_check(X509 *x509, NAME_CONSTRAINTS *nc); |
| 4603 |
| 4604 | // X509_check_host checks if |x509| matches the DNS name |chk|. It returns one |
| 4605 | // on match, zero on mismatch, or a negative number on error. |flags| should be |
| 4606 | // some combination of |X509_CHECK_FLAG_*| and modifies the behavior. On match, |
| 4607 | // if |out_peername| is non-NULL, it additionally sets |*out_peername| to a |
| 4608 | // newly-allocated, NUL-terminated string containing the DNS name or wildcard in |
| 4609 | // the certificate which matched. The caller must then free |*out_peername| with |
| 4610 | // |OPENSSL_free| when done. |
| 4611 | // |
| 4612 | // By default, both subject alternative names and the subject's common name |
| 4613 | // attribute are checked. The latter has long been deprecated, so callers should |
| 4614 | // include |X509_CHECK_FLAG_NEVER_CHECK_SUBJECT| in |flags| to use the standard |
| 4615 | // behavior. https://crbug.com/boringssl/464 tracks fixing the default. |
| 4616 | // |
| 4617 | // This function does not check if |x509| is a trusted certificate, only if, |
| 4618 | // were it trusted, it would match |chk|. |
| 4619 | // |
| 4620 | // WARNING: This function differs from the usual calling convention and may |
| 4621 | // return either 0 or a negative number on error. |
| 4622 | // |
| 4623 | // TODO(davidben): Make the error case also return zero. |
| 4624 | OPENSSL_EXPORT int X509_check_host(const X509 *x509, const char *chk, |
| 4625 | size_t chklen, unsigned int flags, |
| 4626 | char **out_peername); |
| 4627 |
| 4628 | // X509_check_email checks if |x509| matches the email address |chk|. It returns |
| 4629 | // one on match, zero on mismatch, or a negative number on error. |flags| should |
| 4630 | // be some combination of |X509_CHECK_FLAG_*| and modifies the behavior. |
| 4631 | // |
| 4632 | // By default, both subject alternative names and the subject's email address |
| 4633 | // attribute are checked. The |X509_CHECK_FLAG_NEVER_CHECK_SUBJECT| flag may be |
| 4634 | // used to change this behavior. |
| 4635 | // |
| 4636 | // This function does not check if |x509| is a trusted certificate, only if, |
| 4637 | // were it trusted, it would match |chk|. |
| 4638 | // |
| 4639 | // WARNING: This function differs from the usual calling convention and may |
| 4640 | // return either 0 or a negative number on error. |
| 4641 | // |
| 4642 | // TODO(davidben): Make the error case also return zero. |
| 4643 | OPENSSL_EXPORT int X509_check_email(const X509 *x509, const char *chk, |
| 4644 | size_t chklen, unsigned int flags); |
| 4645 |
| 4646 | // X509_check_ip checks if |x509| matches the IP address |chk|. The IP address |
| 4647 | // is represented in byte form and should be 4 bytes for an IPv4 address and 16 |
| 4648 | // bytes for an IPv6 address. It returns one on match, zero on mismatch, or a |
| 4649 | // negative number on error. |flags| should be some combination of |
| 4650 | // |X509_CHECK_FLAG_*| and modifies the behavior. |
| 4651 | // |
| 4652 | // This function does not check if |x509| is a trusted certificate, only if, |
| 4653 | // were it trusted, it would match |chk|. |
| 4654 | // |
| 4655 | // WARNING: This function differs from the usual calling convention and may |
| 4656 | // return either 0 or a negative number on error. |
| 4657 | // |
| 4658 | // TODO(davidben): Make the error case also return zero. |
| 4659 | OPENSSL_EXPORT int X509_check_ip(const X509 *x509, const uint8_t *chk, |
| 4660 | size_t chklen, unsigned int flags); |
| 4661 |
| 4662 | // X509_check_ip_asc behaves like |X509_check_ip| except the IP address is |
| 4663 | // specified in textual form in |ipasc|. |
| 4664 | // |
| 4665 | // WARNING: This function differs from the usual calling convention and may |
| 4666 | // return either 0 or a negative number on error. |
| 4667 | // |
| 4668 | // TODO(davidben): Make the error case also return zero. |
| 4669 | OPENSSL_EXPORT int X509_check_ip_asc(const X509 *x509, const char *ipasc, |
| 4670 | unsigned int flags); |
| 4671 |
| 4672 | // X509_STORE_CTX_get1_issuer looks up a candidate trusted issuer for |x509| out |
| 4673 | // of |ctx|'s |X509_STORE|, based on the criteria in |X509_check_issued|. If one |
| 4674 | // was found, it returns one and sets |*out_issuer| to the issuer. The caller |
| 4675 | // must release |*out_issuer| with |X509_free| when done. If none was found, it |
| 4676 | // returns zero and leaves |*out_issuer| unchanged. |
| 4677 | // |
| 4678 | // This function only searches for trusted issuers. It does not consider |
| 4679 | // untrusted intermediates passed in to |X509_STORE_CTX_init|. |
| 4680 | // |
| 4681 | // TODO(crbug.com/boringssl/407): |x509| should be const. |
| 4682 | OPENSSL_EXPORT int X509_STORE_CTX_get1_issuer(X509 **out_issuer, |
| 4683 | X509_STORE_CTX *ctx, X509 *x509); |
| 4684 |
| 4685 | // X509_check_purpose performs checks if |x509|'s basic constraints, key usage, |
| 4686 | // and extended key usage extensions for the specified purpose. |purpose| should |
| 4687 | // be one of |X509_PURPOSE_*| constants. See |X509_VERIFY_PARAM_set_purpose| for |
| 4688 | // details. It returns one if |x509|'s extensions are consistent with |purpose| |
| 4689 | // and zero otherwise. If |ca| is non-zero, |x509| is checked as a CA |
| 4690 | // certificate. Otherwise, it is checked as an end-entity certificate. |
| 4691 | // |
| 4692 | // If |purpose| is -1, this function performs no purpose checks, but it parses |
| 4693 | // some extensions in |x509| and may return zero on syntax error. Historically, |
| 4694 | // callers primarily used this function to trigger this parsing, but this is no |
| 4695 | // longer necessary. Functions acting on |X509| will internally parse as needed. |
| 4696 | OPENSSL_EXPORT int X509_check_purpose(X509 *x509, int purpose, int ca); |
| 4697 |
| 4698 | #define X509_TRUST_TRUSTED 1 |
| 4699 | #define X509_TRUST_REJECTED 2 |
| 4700 | #define X509_TRUST_UNTRUSTED 3 |
| 4701 |
| 4702 | // X509_check_trust checks if |x509| is a valid trust anchor for trust type |
| 4703 | // |id|. See |X509_VERIFY_PARAM_set_trust| for details. It returns |
| 4704 | // |X509_TRUST_TRUSTED| if |x509| is a trust anchor, |X509_TRUST_REJECTED| if it |
| 4705 | // was distrusted, and |X509_TRUST_UNTRUSTED| otherwise. |id| should be one of |
| 4706 | // the |X509_TRUST_*| constants, or zero to indicate the default behavior. |
| 4707 | // |flags| should be zero and is ignored. |
| 4708 | OPENSSL_EXPORT int X509_check_trust(X509 *x509, int id, int flags); |
| 4709 |
| 4710 | // X509_STORE_CTX_get1_certs returns a newly-allocated stack containing all |
| 4711 | // trusted certificates in |ctx|'s |X509_STORE| whose subject matches |name|, or |
| 4712 | // NULL on error. The caller must release the result with |sk_X509_pop_free| and |
| 4713 | // |X509_free| when done. |
| 4714 | // |
| 4715 | // TODO(crbug.com/boringssl/407): |name| should be const. |
| 4716 | OPENSSL_EXPORT STACK_OF(X509) *X509_STORE_CTX_get1_certs(X509_STORE_CTX *ctx, |
| 4717 | X509_NAME *name); |
| 4718 |
| 4719 | // X509_STORE_CTX_get1_crls returns a newly-allocated stack containing all |
| 4720 | // CRLs in |ctx|'s |X509_STORE| whose subject matches |name|, or NULL on error. |
| 4721 | // The caller must release the result with |sk_X509_CRL_pop_free| and |
| 4722 | // |X509_CRL_free| when done. |
| 4723 | // |
| 4724 | // TODO(crbug.com/boringssl/407): |name| should be const. |
| 4725 | OPENSSL_EXPORT STACK_OF(X509_CRL) *X509_STORE_CTX_get1_crls(X509_STORE_CTX *ctx, |
| 4726 | X509_NAME *name); |
| 4727 |
| 4728 | // X509_STORE_CTX_get_by_subject looks up an object of type |type| in |ctx|'s |
| 4729 | // |X509_STORE| that matches |name|. |type| should be one of the |X509_LU_*| |
| 4730 | // constants to indicate the type of object. If a match was found, it stores the |
| 4731 | // result in |ret| and returns one. Otherwise, it returns zero. If multiple |
| 4732 | // objects match, this function outputs an arbitray one. |
| 4733 | // |
| 4734 | // WARNING: |ret| must be in the empty state, as returned by |X509_OBJECT_new|. |
| 4735 | // Otherwise, the object currently in |ret| will be leaked when overwritten. |
| 4736 | // https://crbug.com/boringssl/685 tracks fixing this. |
| 4737 | // |
| 4738 | // WARNING: Multiple trusted certificates or CRLs may share a name. In this |
| 4739 | // case, this function returns an arbitrary match. Use |
| 4740 | // |X509_STORE_CTX_get1_certs| or |X509_STORE_CTX_get1_crls| instead. |
| 4741 | // |
| 4742 | // TODO(crbug.com/boringssl/407): |name| should be const. |
| 4743 | OPENSSL_EXPORT int X509_STORE_CTX_get_by_subject(X509_STORE_CTX *ctx, int type, |
| 4744 | X509_NAME *name, |
| 4745 | X509_OBJECT *ret); |
| 4746 |
| 4747 |
| 4748 | // X.509 information. |
| 4749 | // |
| 4750 | // |X509_INFO| is the return type for |PEM_X509_INFO_read_bio|, defined in |
| 4751 | // <openssl/pem.h>. It is used to store a certificate, CRL, or private key. This |
| 4752 | // type is defined in this header for OpenSSL compatibility. |
| 4753 |
| 4754 | struct private_key_st { |
| 4755 | EVP_PKEY *dec_pkey; |
| 4756 | } /* X509_PKEY */; |
| 4757 |
| 4758 | struct X509_info_st { |
| 4759 | X509 *x509; |
| 4760 | X509_CRL *crl; |
| 4761 | X509_PKEY *x_pkey; |
| 4762 |
| 4763 | EVP_CIPHER_INFO enc_cipher; |
| 4764 | int enc_len; |
| 4765 | char *enc_data; |
| 4766 | } /* X509_INFO */; |
| 4767 |
| 4768 | DEFINE_STACK_OF(X509_INFO) |
| 4769 |
| 4770 | // X509_INFO_free releases memory associated with |info|. |
| 4771 | OPENSSL_EXPORT void X509_INFO_free(X509_INFO *info); |
| 4772 |
| 4773 |
| 4774 | // Deprecated custom extension registration. |
| 4775 | // |
| 4776 | // The following functions allow callers to register custom extensions for use |
| 4777 | // with |X509V3_EXT_d2i| and related functions. This mechanism is deprecated and |
| 4778 | // will be removed in the future. As discussed in |X509V3_EXT_add|, it is not |
| 4779 | // possible to safely register a custom extension without risking race |
| 4780 | // conditions and memory errors when linked with other users of BoringSSL. |
| 4781 | // |
| 4782 | // Moreover, it is not necessary to register a custom extension to process |
| 4783 | // extensions unknown to BoringSSL. Registration does not impact certificate |
| 4784 | // verification. Caller should instead use functions such as |
| 4785 | // |ASN1_OBJECT_create|, |X509_get_ext_by_OBJ|, |X509_EXTENSION_get_data|, and |
| 4786 | // |X509_EXTENSION_create_by_OBJ| to inspect or create extensions directly. |
| 4787 |
| 4788 | // The following function pointer types are used in |X509V3_EXT_METHOD|. |
| 4789 | typedef void *(*X509V3_EXT_NEW)(void); |
| 4790 | typedef void (*X509V3_EXT_FREE)(void *ext); |
| 4791 | typedef void *(*X509V3_EXT_D2I)(void *ext, const uint8_t **inp, long len); |
| 4792 | typedef int (*X509V3_EXT_I2D)(void *ext, uint8_t **outp); |
| 4793 | typedef STACK_OF(CONF_VALUE) *(*X509V3_EXT_I2V)(const X509V3_EXT_METHOD *method, |
| 4794 | void *ext, |
| 4795 | STACK_OF(CONF_VALUE) *extlist); |
| 4796 | typedef void *(*X509V3_EXT_V2I)(const X509V3_EXT_METHOD *method, |
| 4797 | const X509V3_CTX *ctx, |
| 4798 | const STACK_OF(CONF_VALUE) *values); |
| 4799 | typedef char *(*X509V3_EXT_I2S)(const X509V3_EXT_METHOD *method, void *ext); |
| 4800 | typedef void *(*X509V3_EXT_S2I)(const X509V3_EXT_METHOD *method, |
| 4801 | const X509V3_CTX *ctx, const char *str); |
| 4802 | typedef int (*X509V3_EXT_I2R)(const X509V3_EXT_METHOD *method, void *ext, |
| 4803 | BIO *out, int indent); |
| 4804 | typedef void *(*X509V3_EXT_R2I)(const X509V3_EXT_METHOD *method, |
| 4805 | const X509V3_CTX *ctx, const char *str); |
| 4806 |
| 4807 | // A v3_ext_method, aka |X509V3_EXT_METHOD|, is a deprecated type which defines |
| 4808 | // a custom extension. |
| 4809 | struct v3_ext_method { |
| 4810 | // ext_nid is the NID of the extension. |
| 4811 | int ext_nid; |
| 4812 |
| 4813 | // ext_flags is a combination of |X509V3_EXT_*| constants. |
| 4814 | int ext_flags; |
| 4815 |
| 4816 | // it determines how values of this extension are allocated, released, parsed, |
| 4817 | // and marshalled. This must be non-NULL. |
| 4818 | ASN1_ITEM_EXP *it; |
| 4819 |
| 4820 | // The following functions are ignored in favor of |it|. They are retained in |
| 4821 | // the struct only for source compatibility with existing struct definitions. |
| 4822 | X509V3_EXT_NEW ext_new; |
| 4823 | X509V3_EXT_FREE ext_free; |
| 4824 | X509V3_EXT_D2I d2i; |
| 4825 | X509V3_EXT_I2D i2d; |
| 4826 |
| 4827 | // The following functions are used for string extensions. |
| 4828 | X509V3_EXT_I2S i2s; |
| 4829 | X509V3_EXT_S2I s2i; |
| 4830 |
| 4831 | // The following functions are used for multi-valued extensions. |
| 4832 | X509V3_EXT_I2V i2v; |
| 4833 | X509V3_EXT_V2I v2i; |
| 4834 |
| 4835 | // The following functions are used for "raw" extensions, which implement |
| 4836 | // custom printing behavior. |
| 4837 | X509V3_EXT_I2R i2r; |
| 4838 | X509V3_EXT_R2I r2i; |
| 4839 |
| 4840 | void *usr_data; // Any extension specific data |
| 4841 | } /* X509V3_EXT_METHOD */; |
| 4842 |
| 4843 | // X509V3_EXT_MULTILINE causes the result of an |X509V3_EXT_METHOD|'s |i2v| |
| 4844 | // function to be printed on separate lines, rather than separated by commas. |
| 4845 | #define X509V3_EXT_MULTILINE 0x4 |
| 4846 |
| 4847 | // X509V3_EXT_get returns the |X509V3_EXT_METHOD| corresponding to |ext|'s |
| 4848 | // extension type, or NULL if none was registered. |
| 4849 | OPENSSL_EXPORT const X509V3_EXT_METHOD *X509V3_EXT_get( |
| 4850 | const X509_EXTENSION *ext); |
| 4851 |
| 4852 | // X509V3_EXT_get_nid returns the |X509V3_EXT_METHOD| corresponding to |nid|, or |
| 4853 | // NULL if none was registered. |
| 4854 | OPENSSL_EXPORT const X509V3_EXT_METHOD *X509V3_EXT_get_nid(int nid); |
| 4855 |
| 4856 | // X509V3_EXT_add registers |ext| as a custom extension for the extension type |
| 4857 | // |ext->ext_nid|. |ext| must be valid for the remainder of the address space's |
| 4858 | // lifetime. It returns one on success and zero on error. |
| 4859 | // |
| 4860 | // WARNING: This function modifies global state. If other code in the same |
| 4861 | // address space also registers an extension with type |ext->ext_nid|, the two |
| 4862 | // registrations will conflict. Which registration takes effect is undefined. If |
| 4863 | // the two registrations use incompatible in-memory representations, code |
| 4864 | // expecting the other registration will then cast a type to the wrong type, |
| 4865 | // resulting in a potentially exploitable memory error. This conflict can also |
| 4866 | // occur if BoringSSL later adds support for |ext->ext_nid|, with a different |
| 4867 | // in-memory representation than the one expected by |ext|. |
| 4868 | // |
| 4869 | // This function, additionally, is not thread-safe and cannot be called |
| 4870 | // concurrently with any other BoringSSL function. |
| 4871 | // |
| 4872 | // As a result, it is impossible to safely use this function. Registering a |
| 4873 | // custom extension has no impact on certificate verification so, instead, |
| 4874 | // callers should simply handle the custom extension with the byte-based |
| 4875 | // |X509_EXTENSION| APIs directly. Registering |ext| with the library has little |
| 4876 | // practical value. |
| 4877 | OPENSSL_EXPORT OPENSSL_DEPRECATED int X509V3_EXT_add(X509V3_EXT_METHOD *ext); |
| 4878 |
| 4879 | // X509V3_EXT_add_alias registers a custom extension with NID |nid_to|. The |
| 4880 | // corresponding ASN.1 type is copied from |nid_from|. It returns one on success |
| 4881 | // and zero on error. |
| 4882 | // |
| 4883 | // WARNING: Do not use this function. See |X509V3_EXT_add|. |
| 4884 | OPENSSL_EXPORT OPENSSL_DEPRECATED int X509V3_EXT_add_alias(int nid_to, |
| 4885 | int nid_from); |
| 4886 |
| 4887 |
| 4888 | // Deprecated config-based extension creation. |
| 4889 | // |
| 4890 | // The following functions allow specifying X.509 extensions using OpenSSL's |
| 4891 | // config file syntax, from the OpenSSL command-line tool. They are retained, |
| 4892 | // for now, for compatibility with legacy software but may be removed in the |
| 4893 | // future. Construct the extensions using the typed C APIs instead. |
| 4894 | // |
| 4895 | // Callers should especially avoid these functions if passing in non-constant |
| 4896 | // values. They use ad-hoc, string-based formats which are prone to injection |
| 4897 | // vulnerabilities. For a CA, this means using them risks misissuance. |
| 4898 | // |
| 4899 | // These functions are not safe to use with untrusted inputs. The string formats |
| 4900 | // may implicitly reference context information and, in OpenSSL (though not |
| 4901 | // BoringSSL), one even allows reading arbitrary files. Many formats can also |
| 4902 | // produce far larger outputs than their inputs, so untrusted inputs may lead to |
| 4903 | // denial-of-service attacks. Finally, the parsers see much less testing and |
| 4904 | // review than most of the library and may have bugs including memory leaks or |
| 4905 | // crashes. |
| 4906 |
| 4907 | // v3_ext_ctx, aka |X509V3_CTX|, contains additional context information for |
| 4908 | // constructing extensions. Some string formats reference additional values in |
| 4909 | // these objects. It must be initialized with |X509V3_set_ctx| or |
| 4910 | // |X509V3_set_ctx_test| before use. |
| 4911 | struct v3_ext_ctx { |
| 4912 | int flags; |
| 4913 | const X509 *issuer_cert; |
| 4914 | const X509 *subject_cert; |
| 4915 | const X509_REQ *subject_req; |
| 4916 | const X509_CRL *crl; |
| 4917 | const CONF *db; |
| 4918 | }; |
| 4919 |
| 4920 | #define X509V3_CTX_TEST 0x1 |
| 4921 |
| 4922 | // X509V3_set_ctx initializes |ctx| with the specified objects. Some string |
| 4923 | // formats will reference fields in these objects. Each object may be NULL to |
| 4924 | // omit it, in which case those formats cannot be used. |flags| should be zero, |
| 4925 | // unless called via |X509V3_set_ctx_test|. |
| 4926 | // |
| 4927 | // |issuer|, |subject|, |req|, and |crl|, if non-NULL, must outlive |ctx|. |
| 4928 | OPENSSL_EXPORT void X509V3_set_ctx(X509V3_CTX *ctx, const X509 *issuer, |
| 4929 | const X509 *subject, const X509_REQ *req, |
| 4930 | const X509_CRL *crl, int flags); |
| 4931 |
| 4932 | // X509V3_set_ctx_test calls |X509V3_set_ctx| without any reference objects and |
| 4933 | // mocks out some features that use them. The resulting extensions may be |
| 4934 | // incomplete and should be discarded. This can be used to partially validate |
| 4935 | // syntax. |
| 4936 | // |
| 4937 | // TODO(davidben): Can we remove this? |
| 4938 | #define X509V3_set_ctx_test(ctx) \ |
| 4939 | X509V3_set_ctx(ctx, NULL, NULL, NULL, NULL, X509V3_CTX_TEST) |
| 4940 |
| 4941 | // X509V3_set_nconf sets |ctx| to use |conf| as the config database. |ctx| must |
| 4942 | // have previously been initialized by |X509V3_set_ctx| or |
| 4943 | // |X509V3_set_ctx_test|. Some string formats will reference sections in |conf|. |
| 4944 | // |conf| may be NULL, in which case these formats cannot be used. If non-NULL, |
| 4945 | // |conf| must outlive |ctx|. |
| 4946 | OPENSSL_EXPORT void X509V3_set_nconf(X509V3_CTX *ctx, const CONF *conf); |
| 4947 |
| 4948 | // X509V3_set_ctx_nodb calls |X509V3_set_nconf| with no config database. |
| 4949 | #define X509V3_set_ctx_nodb(ctx) X509V3_set_nconf(ctx, NULL) |
| 4950 |
| 4951 | // X509V3_EXT_nconf constructs an extension of type specified by |name|, and |
| 4952 | // value specified by |value|. It returns a newly-allocated |X509_EXTENSION| |
| 4953 | // object on success, or NULL on error. |conf| and |ctx| specify additional |
| 4954 | // information referenced by some formats. Either |conf| or |ctx| may be NULL, |
| 4955 | // in which case features which use it will be disabled. |
| 4956 | // |
| 4957 | // If non-NULL, |ctx| must be initialized with |X509V3_set_ctx| or |
| 4958 | // |X509V3_set_ctx_test|. |
| 4959 | // |
| 4960 | // Both |conf| and |ctx| provide a |CONF| object. When |ctx| is non-NULL, most |
| 4961 | // features use the |ctx| copy, configured with |X509V3_set_ctx|, but some use |
| 4962 | // |conf|. Callers should ensure the two match to avoid surprisingly behavior. |
| 4963 | OPENSSL_EXPORT X509_EXTENSION *X509V3_EXT_nconf(const CONF *conf, |
| 4964 | const X509V3_CTX *ctx, |
| 4965 | const char *name, |
| 4966 | const char *value); |
| 4967 |
| 4968 | // X509V3_EXT_nconf_nid behaves like |X509V3_EXT_nconf|, except the extension |
| 4969 | // type is specified as a NID. |
| 4970 | OPENSSL_EXPORT X509_EXTENSION *X509V3_EXT_nconf_nid(const CONF *conf, |
| 4971 | const X509V3_CTX *ctx, |
| 4972 | int ext_nid, |
| 4973 | const char *value); |
| 4974 |
| 4975 | // X509V3_EXT_conf_nid calls |X509V3_EXT_nconf_nid|. |conf| must be NULL. |
| 4976 | // |
| 4977 | // TODO(davidben): This is the only exposed instance of an LHASH in our public |
| 4978 | // headers. cryptography.io wraps this function so we cannot, yet, replace the |
| 4979 | // type with a dummy struct. |
| 4980 | OPENSSL_EXPORT X509_EXTENSION *X509V3_EXT_conf_nid(LHASH_OF(CONF_VALUE) *conf, |
| 4981 | const X509V3_CTX *ctx, |
| 4982 | int ext_nid, |
| 4983 | const char *value); |
| 4984 |
| 4985 | // X509V3_EXT_add_nconf_sk looks up the section named |section| in |conf|. For |
| 4986 | // each |CONF_VALUE| in the section, it constructs an extension as in |
| 4987 | // |X509V3_EXT_nconf|, taking |name| and |value| from the |CONF_VALUE|. Each new |
| 4988 | // extension is appended to |*sk|. If |*sk| is non-NULL, and at least one |
| 4989 | // extension is added, it sets |*sk| to a newly-allocated |
| 4990 | // |STACK_OF(X509_EXTENSION)|. It returns one on success and zero on error. |
| 4991 | OPENSSL_EXPORT int X509V3_EXT_add_nconf_sk(const CONF *conf, |
| 4992 | const X509V3_CTX *ctx, |
| 4993 | const char *section, |
| 4994 | STACK_OF(X509_EXTENSION) **sk); |
| 4995 |
| 4996 | // X509V3_EXT_add_nconf adds extensions to |cert| as in |
| 4997 | // |X509V3_EXT_add_nconf_sk|. It returns one on success and zero on error. |
| 4998 | OPENSSL_EXPORT int X509V3_EXT_add_nconf(const CONF *conf, const X509V3_CTX *ctx, |
| 4999 | const char *section, X509 *cert); |
| 5000 |
| 5001 | // X509V3_EXT_REQ_add_nconf adds extensions to |req| as in |
| 5002 | // |X509V3_EXT_add_nconf_sk|. It returns one on success and zero on error. |
| 5003 | OPENSSL_EXPORT int X509V3_EXT_REQ_add_nconf(const CONF *conf, |
| 5004 | const X509V3_CTX *ctx, |
| 5005 | const char *section, X509_REQ *req); |
| 5006 |
| 5007 | // X509V3_EXT_CRL_add_nconf adds extensions to |crl| as in |
| 5008 | // |X509V3_EXT_add_nconf_sk|. It returns one on success and zero on error. |
| 5009 | OPENSSL_EXPORT int X509V3_EXT_CRL_add_nconf(const CONF *conf, |
| 5010 | const X509V3_CTX *ctx, |
| 5011 | const char *section, X509_CRL *crl); |
| 5012 |
| 5013 | // i2s_ASN1_OCTET_STRING returns a human-readable representation of |oct| as a |
| 5014 | // newly-allocated, NUL-terminated string, or NULL on error. |method| is |
| 5015 | // ignored. The caller must release the result with |OPENSSL_free| when done. |
| 5016 | OPENSSL_EXPORT char *i2s_ASN1_OCTET_STRING(const X509V3_EXT_METHOD *method, |
| 5017 | const ASN1_OCTET_STRING *oct); |
| 5018 |
| 5019 | // s2i_ASN1_OCTET_STRING decodes |str| as a hexdecimal byte string, with |
| 5020 | // optional colon separators between bytes. It returns a newly-allocated |
| 5021 | // |ASN1_OCTET_STRING| with the result on success, or NULL on error. |method| |
| 5022 | // and |ctx| are ignored. |
| 5023 | OPENSSL_EXPORT ASN1_OCTET_STRING *s2i_ASN1_OCTET_STRING( |
| 5024 | const X509V3_EXT_METHOD *method, const X509V3_CTX *ctx, const char *str); |
| 5025 |
| 5026 | // i2s_ASN1_INTEGER returns a human-readable representation of |aint| as a |
| 5027 | // newly-allocated, NUL-terminated string, or NULL on error. |method| is |
| 5028 | // ignored. The caller must release the result with |OPENSSL_free| when done. |
| 5029 | OPENSSL_EXPORT char *i2s_ASN1_INTEGER(const X509V3_EXT_METHOD *method, |
| 5030 | const ASN1_INTEGER *aint); |
| 5031 |
| 5032 | // s2i_ASN1_INTEGER decodes |value| as the ASCII representation of an integer, |
| 5033 | // and returns a newly-allocated |ASN1_INTEGER| containing the result, or NULL |
| 5034 | // on error. |method| is ignored. If |value| begins with "0x" or "0X", the input |
| 5035 | // is decoded in hexadecimal, otherwise decimal. |
| 5036 | OPENSSL_EXPORT ASN1_INTEGER *s2i_ASN1_INTEGER(const X509V3_EXT_METHOD *method, |
| 5037 | const char *value); |
| 5038 |
| 5039 | // i2s_ASN1_ENUMERATED returns a human-readable representation of |aint| as a |
| 5040 | // newly-allocated, NUL-terminated string, or NULL on error. |method| is |
| 5041 | // ignored. The caller must release the result with |OPENSSL_free| when done. |
| 5042 | OPENSSL_EXPORT char *i2s_ASN1_ENUMERATED(const X509V3_EXT_METHOD *method, |
| 5043 | const ASN1_ENUMERATED *aint); |
| 5044 |
| 5045 | // X509V3_conf_free releases memory associated with |CONF_VALUE|. |
| 5046 | OPENSSL_EXPORT void X509V3_conf_free(CONF_VALUE *val); |
| 5047 |
| 5048 | // i2v_GENERAL_NAME serializes |gen| as a |CONF_VALUE|. If |ret| is non-NULL, it |
| 5049 | // appends the value to |ret| and returns |ret| on success or NULL on error. If |
| 5050 | // it returns NULL, the caller is still responsible for freeing |ret|. If |ret| |
| 5051 | // is NULL, it returns a newly-allocated |STACK_OF(CONF_VALUE)| containing the |
| 5052 | // result. |method| is ignored. When done, the caller should release the result |
| 5053 | // with |sk_CONF_VALUE_pop_free| and |X509V3_conf_free|. |
| 5054 | // |
| 5055 | // Do not use this function. This is an internal implementation detail of the |
| 5056 | // human-readable print functions. If extracting a SAN list from a certificate, |
| 5057 | // look at |gen| directly. |
| 5058 | OPENSSL_EXPORT STACK_OF(CONF_VALUE) *i2v_GENERAL_NAME( |
| 5059 | const X509V3_EXT_METHOD *method, const GENERAL_NAME *gen, |
| 5060 | STACK_OF(CONF_VALUE) *ret); |
| 5061 |
| 5062 | // i2v_GENERAL_NAMES serializes |gen| as a list of |CONF_VALUE|s. If |ret| is |
| 5063 | // non-NULL, it appends the values to |ret| and returns |ret| on success or NULL |
| 5064 | // on error. If it returns NULL, the caller is still responsible for freeing |
| 5065 | // |ret|. If |ret| is NULL, it returns a newly-allocated |STACK_OF(CONF_VALUE)| |
| 5066 | // containing the results. |method| is ignored. |
| 5067 | // |
| 5068 | // Do not use this function. This is an internal implementation detail of the |
| 5069 | // human-readable print functions. If extracting a SAN list from a certificate, |
| 5070 | // look at |gen| directly. |
| 5071 | OPENSSL_EXPORT STACK_OF(CONF_VALUE) *i2v_GENERAL_NAMES( |
| 5072 | const X509V3_EXT_METHOD *method, const GENERAL_NAMES *gen, |
| 5073 | STACK_OF(CONF_VALUE) *extlist); |
| 5074 |
| 5075 | // a2i_IPADDRESS decodes |ipasc| as the textual representation of an IPv4 or |
| 5076 | // IPv6 address. On success, it returns a newly-allocated |ASN1_OCTET_STRING| |
| 5077 | // containing the decoded IP address. IPv4 addresses are represented as 4-byte |
| 5078 | // strings and IPv6 addresses as 16-byte strings. On failure, it returns NULL. |
| 5079 | OPENSSL_EXPORT ASN1_OCTET_STRING *a2i_IPADDRESS(const char *ipasc); |
| 5080 |
| 5081 | // a2i_IPADDRESS_NC decodes |ipasc| as the textual representation of an IPv4 or |
| 5082 | // IPv6 address range. On success, it returns a newly-allocated |
| 5083 | // |ASN1_OCTET_STRING| containing the decoded IP address, followed by the |
| 5084 | // decoded mask. IPv4 ranges are represented as 8-byte strings and IPv6 ranges |
| 5085 | // as 32-byte strings. On failure, it returns NULL. |
| 5086 | // |
| 5087 | // The text format decoded by this function is not the standard CIDR notiation. |
| 5088 | // Instead, the mask after the "/" is represented as another IP address. For |
| 5089 | // example, "192.168.0.0/16" would be written "192.168.0.0/255.255.0.0". |
| 5090 | OPENSSL_EXPORT ASN1_OCTET_STRING *a2i_IPADDRESS_NC(const char *ipasc); |
| 5091 |
| 5092 |
| 5093 | // Deprecated functions. |
| 5094 |
| 5095 | // X509_get_notBefore returns |x509|'s notBefore time. Note this function is not |
| 5096 | // const-correct for legacy reasons. Use |X509_get0_notBefore| or |
| 5097 | // |X509_getm_notBefore| instead. |
| 5098 | OPENSSL_EXPORT ASN1_TIME *X509_get_notBefore(const X509 *x509); |
| 5099 |
| 5100 | // X509_get_notAfter returns |x509|'s notAfter time. Note this function is not |
| 5101 | // const-correct for legacy reasons. Use |X509_get0_notAfter| or |
| 5102 | // |X509_getm_notAfter| instead. |
| 5103 | OPENSSL_EXPORT ASN1_TIME *X509_get_notAfter(const X509 *x509); |
| 5104 |
| 5105 | // X509_set_notBefore calls |X509_set1_notBefore|. Use |X509_set1_notBefore| |
| 5106 | // instead. |
| 5107 | OPENSSL_EXPORT int X509_set_notBefore(X509 *x509, const ASN1_TIME *tm); |
| 5108 |
| 5109 | // X509_set_notAfter calls |X509_set1_notAfter|. Use |X509_set1_notAfter| |
| 5110 | // instead. |
| 5111 | OPENSSL_EXPORT int X509_set_notAfter(X509 *x509, const ASN1_TIME *tm); |
| 5112 |
| 5113 | // X509_CRL_get_lastUpdate returns a mutable pointer to |crl|'s thisUpdate time. |
| 5114 | // The OpenSSL API refers to this field as lastUpdate. |
| 5115 | // |
| 5116 | // Use |X509_CRL_get0_lastUpdate| or |X509_CRL_set1_lastUpdate| instead. |
| 5117 | OPENSSL_EXPORT ASN1_TIME *X509_CRL_get_lastUpdate(X509_CRL *crl); |
| 5118 |
| 5119 | // X509_CRL_get_nextUpdate returns a mutable pointer to |crl|'s nextUpdate time, |
| 5120 | // or NULL if |crl| has none. Use |X509_CRL_get0_nextUpdate| or |
| 5121 | // |X509_CRL_set1_nextUpdate| instead. |
| 5122 | OPENSSL_EXPORT ASN1_TIME *X509_CRL_get_nextUpdate(X509_CRL *crl); |
| 5123 |
| 5124 | // X509_extract_key is a legacy alias to |X509_get_pubkey|. Use |
| 5125 | // |X509_get_pubkey| instead. |
| 5126 | #define X509_extract_key(x) X509_get_pubkey(x) |
| 5127 |
| 5128 | // X509_REQ_extract_key is a legacy alias for |X509_REQ_get_pubkey|. |
| 5129 | #define X509_REQ_extract_key(a) X509_REQ_get_pubkey(a) |
| 5130 |
| 5131 | // X509_name_cmp is a legacy alias for |X509_NAME_cmp|. |
| 5132 | #define X509_name_cmp(a, b) X509_NAME_cmp((a), (b)) |
| 5133 |
| 5134 | // The following symbols are deprecated aliases to |X509_CRL_set1_*|. |
| 5135 | #define X509_CRL_set_lastUpdate X509_CRL_set1_lastUpdate |
| 5136 | #define X509_CRL_set_nextUpdate X509_CRL_set1_nextUpdate |
| 5137 |
| 5138 | // X509_get_serialNumber returns a mutable pointer to |x509|'s serial number. |
| 5139 | // Prefer |X509_get0_serialNumber|. |
| 5140 | OPENSSL_EXPORT ASN1_INTEGER *X509_get_serialNumber(X509 *x509); |
| 5141 |
| 5142 | // X509_NAME_get_text_by_OBJ finds the first attribute with type |obj| in |
| 5143 | // |name|. If found, it writes the value's UTF-8 representation to |buf|. |
| 5144 | // followed by a NUL byte, and returns the number of bytes in the output, |
| 5145 | // excluding the NUL byte. This is unlike OpenSSL which returns the raw |
| 5146 | // ASN1_STRING data. The UTF-8 encoding of the |ASN1_STRING| may not contain a 0 |
| 5147 | // codepoint. |
| 5148 | // |
| 5149 | // This function writes at most |len| bytes, including the NUL byte. If |buf| |
| 5150 | // is NULL, it writes nothing and returns the number of bytes in the |
| 5151 | // output, excluding the NUL byte that would be required for the full UTF-8 |
| 5152 | // output. |
| 5153 | // |
| 5154 | // This function may return -1 if an error occurs for any reason, including the |
| 5155 | // value not being a recognized string type, |len| being of insufficient size to |
| 5156 | // hold the full UTF-8 encoding and NUL byte, memory allocation failures, an |
| 5157 | // object with type |obj| not existing in |name|, or if the UTF-8 encoding of |
| 5158 | // the string contains a zero byte. |
| 5159 | OPENSSL_EXPORT int X509_NAME_get_text_by_OBJ(const X509_NAME *name, |
| 5160 | const ASN1_OBJECT *obj, char *buf, |
| 5161 | int len); |
| 5162 |
| 5163 | // X509_NAME_get_text_by_NID behaves like |X509_NAME_get_text_by_OBJ| except it |
| 5164 | // finds an attribute of type |nid|, which should be one of the |NID_*| |
| 5165 | // constants. |
| 5166 | OPENSSL_EXPORT int X509_NAME_get_text_by_NID(const X509_NAME *name, int nid, |
| 5167 | char *buf, int len); |
| 5168 |
| 5169 | // X509_STORE_CTX_get0_parent_ctx returns NULL. |
| 5170 | OPENSSL_EXPORT X509_STORE_CTX *X509_STORE_CTX_get0_parent_ctx( |
| 5171 | const X509_STORE_CTX *ctx); |
| 5172 |
| 5173 | // X509_OBJECT_free_contents sets |obj| to the empty object, freeing any values |
| 5174 | // that were previously there. |
| 5175 | // |
| 5176 | // TODO(davidben): Unexport this function after rust-openssl is fixed to no |
| 5177 | // longer call it. |
| 5178 | OPENSSL_EXPORT void X509_OBJECT_free_contents(X509_OBJECT *obj); |
| 5179 |
| 5180 | // X509_LOOKUP_free releases memory associated with |ctx|. This function should |
| 5181 | // never be used outside the library. No function in the public API hands |
| 5182 | // ownership of an |X509_LOOKUP| to the caller. |
| 5183 | // |
| 5184 | // TODO(davidben): Unexport this function after rust-openssl is fixed to no |
| 5185 | // longer call it. |
| 5186 | OPENSSL_EXPORT void X509_LOOKUP_free(X509_LOOKUP *ctx); |
| 5187 |
| 5188 | // X509_STORE_CTX_cleanup resets |ctx| to the empty state. |
| 5189 | // |
| 5190 | // This function is a remnant of when |X509_STORE_CTX| was stack-allocated and |
| 5191 | // should not be used. If releasing |ctx|, call |X509_STORE_CTX_free|. If |
| 5192 | // reusing |ctx| for a new verification, release the old one and create a new |
| 5193 | // one. |
| 5194 | OPENSSL_EXPORT void X509_STORE_CTX_cleanup(X509_STORE_CTX *ctx); |
| 5195 |
| 5196 | // X509V3_add_standard_extensions returns one. |
| 5197 | OPENSSL_EXPORT int X509V3_add_standard_extensions(void); |
| 5198 |
| 5199 | // The following symbols are legacy aliases for |X509_STORE_CTX| functions. |
| 5200 | #define X509_STORE_get_by_subject X509_STORE_CTX_get_by_subject |
| 5201 | #define X509_STORE_get1_certs X509_STORE_CTX_get1_certs |
| 5202 | #define X509_STORE_get1_crls X509_STORE_CTX_get1_crls |
| 5203 |
| 5204 | // X509_STORE_CTX_get_chain is a legacy alias for |X509_STORE_CTX_get0_chain|. |
| 5205 | OPENSSL_EXPORT STACK_OF(X509) *X509_STORE_CTX_get_chain( |
| 5206 | const X509_STORE_CTX *ctx); |
| 5207 |
| 5208 | // X509_STORE_CTX_trusted_stack is a deprecated alias for |
| 5209 | // |X509_STORE_CTX_set0_trusted_stack|. |
| 5210 | OPENSSL_EXPORT void X509_STORE_CTX_trusted_stack(X509_STORE_CTX *ctx, |
| 5211 | STACK_OF(X509) *sk); |
| 5212 |
| 5213 | typedef int (*X509_STORE_CTX_verify_cb)(int, X509_STORE_CTX *); |
| 5214 |
| 5215 | // X509_STORE_CTX_set_verify_cb configures a callback function for |ctx| that is |
| 5216 | // called multiple times during |X509_verify_cert|. The callback returns zero to |
| 5217 | // fail verification and one to proceed. Typically, it will return |ok|, which |
| 5218 | // preserves the default behavior. Returning one when |ok| is zero will proceed |
| 5219 | // past some error. The callback may inspect |ctx| and the error queue to |
| 5220 | // attempt to determine the current stage of certificate verification, but this |
| 5221 | // is often unreliable. When synthesizing an error, callbacks should use |
| 5222 | // |X509_STORE_CTX_set_error| to set a corresponding error. |
| 5223 | // |
| 5224 | // WARNING: Do not use this function. It is extremely fragile and unpredictable. |
| 5225 | // This callback exposes implementation details of certificate verification, |
| 5226 | // which change as the library evolves. Attempting to use it for security checks |
| 5227 | // can introduce vulnerabilities if making incorrect assumptions about when the |
| 5228 | // callback is called. Some errors, when suppressed, may implicitly suppress |
| 5229 | // other errors due to internal implementation details. Additionally, overriding |
| 5230 | // |ok| may leave |ctx| in an inconsistent state and break invariants. |
| 5231 | // |
| 5232 | // Instead, customize certificate verification by configuring options on the |
| 5233 | // |X509_STORE_CTX| before verification, or applying additional checks after |
| 5234 | // |X509_verify_cert| completes successfully. |
| 5235 | OPENSSL_EXPORT void X509_STORE_CTX_set_verify_cb( |
| 5236 | X509_STORE_CTX *ctx, int (*verify_cb)(int ok, X509_STORE_CTX *ctx)); |
| 5237 |
| 5238 | // X509_STORE_set_verify_cb acts like |X509_STORE_CTX_set_verify_cb| but sets |
| 5239 | // the verify callback for any |X509_STORE_CTX| created from this |X509_STORE| |
| 5240 | // |
| 5241 | // Do not use this function. See |X509_STORE_CTX_set_verify_cb| for details. |
| 5242 | OPENSSL_EXPORT void X509_STORE_set_verify_cb( |
| 5243 | X509_STORE *store, X509_STORE_CTX_verify_cb verify_cb); |
| 5244 |
| 5245 | // X509_STORE_set_verify_cb_func is a deprecated alias for |
| 5246 | // |X509_STORE_set_verify_cb|. |
| 5247 | #define X509_STORE_set_verify_cb_func(store, func) \ |
| 5248 | X509_STORE_set_verify_cb((store), (func)) |
| 5249 |
| 5250 | // X509_STORE_CTX_set_chain configures |ctx| to use |sk| for untrusted |
| 5251 | // intermediate certificates to use in verification. This function is redundant |
| 5252 | // with the |chain| parameter of |X509_STORE_CTX_init|. Use the parameter |
| 5253 | // instead. |
| 5254 | // |
| 5255 | // WARNING: Despite the similar name, this function is unrelated to |
| 5256 | // |X509_STORE_CTX_get0_chain|. |
| 5257 | // |
| 5258 | // WARNING: This function saves a pointer to |sk| without copying or |
| 5259 | // incrementing reference counts. |sk| must outlive |ctx| and may not be mutated |
| 5260 | // for the duration of the certificate verification. |
| 5261 | OPENSSL_EXPORT void X509_STORE_CTX_set_chain(X509_STORE_CTX *ctx, |
| 5262 | STACK_OF(X509) *sk); |
| 5263 |
| 5264 | // The following flags do nothing. The corresponding non-standard options have |
| 5265 | // been removed. |
| 5266 | #define X509_CHECK_FLAG_ALWAYS_CHECK_SUBJECT 0 |
| 5267 | #define X509_CHECK_FLAG_MULTI_LABEL_WILDCARDS 0 |
| 5268 | #define X509_CHECK_FLAG_SINGLE_LABEL_SUBDOMAINS 0 |
| 5269 |
| 5270 | // X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS does nothing, but is necessary in |
| 5271 | // OpenSSL to enable standard wildcard matching. In BoringSSL, this behavior is |
| 5272 | // always enabled. |
| 5273 | #define X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS 0 |
| 5274 |
| 5275 | // X509_STORE_get0_objects returns a non-owning pointer of |store|'s internal |
| 5276 | // object list. Although this function is not const, callers must not modify |
| 5277 | // the result of this function. |
| 5278 | // |
| 5279 | // WARNING: This function is not thread-safe. If |store| is shared across |
| 5280 | // multiple threads, callers cannot safely inspect the result of this function, |
| 5281 | // because another thread may have concurrently added to it. In particular, |
| 5282 | // |X509_LOOKUP_add_dir| treats this list as a cache and may add to it in the |
| 5283 | // course of certificate verification. This API additionally prevents fixing |
| 5284 | // some quadratic worst-case behavior in |X509_STORE| and may be removed in the |
| 5285 | // future. Use |X509_STORE_get1_objects| instead. |
| 5286 | OPENSSL_EXPORT STACK_OF(X509_OBJECT) *X509_STORE_get0_objects( |
| 5287 | X509_STORE *store); |
| 5288 |
| 5289 | // X509_PURPOSE_get_by_sname returns the |X509_PURPOSE_*| constant corresponding |
| 5290 | // a short name |sname|, or -1 if |sname| was not recognized. |
| 5291 | // |
| 5292 | // Use |X509_PURPOSE_*| constants directly instead. The short names used by this |
| 5293 | // function look like "sslserver" or "smimeencrypt", so they do not make |
| 5294 | // especially good APIs. |
| 5295 | // |
| 5296 | // This function differs from OpenSSL, which returns an "index" to be passed to |
| 5297 | // |X509_PURPOSE_get0|, followed by |X509_PURPOSE_get_id|, to finally obtain an |
| 5298 | // |X509_PURPOSE_*| value suitable for use with |X509_VERIFY_PARAM_set_purpose|. |
| 5299 | OPENSSL_EXPORT int X509_PURPOSE_get_by_sname(const char *sname); |
| 5300 |
| 5301 | // X509_PURPOSE_get0 returns the |X509_PURPOSE| object corresponding to |id|, |
| 5302 | // which should be one of the |X509_PURPOSE_*| constants, or NULL if none |
| 5303 | // exists. |
| 5304 | // |
| 5305 | // This function differs from OpenSSL, which takes an "index", returned from |
| 5306 | // |X509_PURPOSE_get_by_sname|. In BoringSSL, indices and |X509_PURPOSE_*| IDs |
| 5307 | // are the same. |
| 5308 | OPENSSL_EXPORT const X509_PURPOSE *X509_PURPOSE_get0(int id); |
| 5309 |
| 5310 | // X509_PURPOSE_get_id returns |purpose|'s ID. This will be one of the |
| 5311 | // |X509_PURPOSE_*| constants. |
| 5312 | OPENSSL_EXPORT int X509_PURPOSE_get_id(const X509_PURPOSE *purpose); |
| 5313 |
| 5314 | // The following constants are values for the legacy Netscape certificate type |
| 5315 | // X.509 extension, a precursor to extended key usage. These values correspond |
| 5316 | // to the DER encoding of the first byte of the BIT STRING. That is, 0x80 is |
| 5317 | // bit zero and 0x01 is bit seven. |
| 5318 | // |
| 5319 | // TODO(davidben): These constants are only used by OpenVPN, which deprecated |
| 5320 | // the feature in 2017. The documentation says it was removed, but they did not |
| 5321 | // actually remove it. See if OpenVPN will accept a patch to finish this. |
| 5322 | #define NS_SSL_CLIENT 0x80 |
| 5323 | #define NS_SSL_SERVER 0x40 |
| 5324 | #define NS_SMIME 0x20 |
| 5325 | #define NS_OBJSIGN 0x10 |
| 5326 | #define NS_SSL_CA 0x04 |
| 5327 | #define NS_SMIME_CA 0x02 |
| 5328 | #define NS_OBJSIGN_CA 0x01 |
| 5329 | #define NS_ANY_CA (NS_SSL_CA | NS_SMIME_CA | NS_OBJSIGN_CA) |
| 5330 |
| 5331 |
| 5332 | // Private structures. |
| 5333 |
| 5334 | struct X509_algor_st { |
| 5335 | ASN1_OBJECT *algorithm; |
| 5336 | ASN1_TYPE *parameter; |
| 5337 | } /* X509_ALGOR */; |
| 5338 |
| 5339 |
| 5340 | #if defined(__cplusplus) |
| 5341 | } // extern C |
| 5342 | #endif |
| 5343 |
| 5344 | #if !defined(BORINGSSL_NO_CXX) |
| 5345 | extern "C++" { |
| 5346 |
| 5347 | BSSL_NAMESPACE_BEGIN |
| 5348 |
| 5349 | BORINGSSL_MAKE_DELETER(ACCESS_DESCRIPTION, ACCESS_DESCRIPTION_free) |
| 5350 | BORINGSSL_MAKE_DELETER(AUTHORITY_KEYID, AUTHORITY_KEYID_free) |
| 5351 | BORINGSSL_MAKE_DELETER(BASIC_CONSTRAINTS, BASIC_CONSTRAINTS_free) |
| 5352 | // TODO(davidben): Move this to conf.h and rename to CONF_VALUE_free. |
| 5353 | BORINGSSL_MAKE_DELETER(CONF_VALUE, X509V3_conf_free) |
| 5354 | BORINGSSL_MAKE_DELETER(DIST_POINT, DIST_POINT_free) |
| 5355 | BORINGSSL_MAKE_DELETER(GENERAL_NAME, GENERAL_NAME_free) |
| 5356 | BORINGSSL_MAKE_DELETER(GENERAL_SUBTREE, GENERAL_SUBTREE_free) |
| 5357 | BORINGSSL_MAKE_DELETER(NAME_CONSTRAINTS, NAME_CONSTRAINTS_free) |
| 5358 | BORINGSSL_MAKE_DELETER(NETSCAPE_SPKI, NETSCAPE_SPKI_free) |
| 5359 | BORINGSSL_MAKE_DELETER(POLICY_MAPPING, POLICY_MAPPING_free) |
| 5360 | BORINGSSL_MAKE_DELETER(POLICYINFO, POLICYINFO_free) |
| 5361 | BORINGSSL_MAKE_DELETER(RSA_PSS_PARAMS, RSA_PSS_PARAMS_free) |
| 5362 | BORINGSSL_MAKE_DELETER(X509, X509_free) |
| 5363 | BORINGSSL_MAKE_UP_REF(X509, X509_up_ref) |
| 5364 | BORINGSSL_MAKE_DELETER(X509_ALGOR, X509_ALGOR_free) |
| 5365 | BORINGSSL_MAKE_DELETER(X509_ATTRIBUTE, X509_ATTRIBUTE_free) |
| 5366 | BORINGSSL_MAKE_DELETER(X509_CRL, X509_CRL_free) |
| 5367 | BORINGSSL_MAKE_UP_REF(X509_CRL, X509_CRL_up_ref) |
| 5368 | BORINGSSL_MAKE_DELETER(X509_EXTENSION, X509_EXTENSION_free) |
| 5369 | BORINGSSL_MAKE_DELETER(X509_INFO, X509_INFO_free) |
| 5370 | BORINGSSL_MAKE_DELETER(X509_LOOKUP, X509_LOOKUP_free) |
| 5371 | BORINGSSL_MAKE_DELETER(X509_NAME, X509_NAME_free) |
| 5372 | BORINGSSL_MAKE_DELETER(X509_NAME_ENTRY, X509_NAME_ENTRY_free) |
| 5373 | BORINGSSL_MAKE_DELETER(X509_OBJECT, X509_OBJECT_free) |
| 5374 | BORINGSSL_MAKE_DELETER(X509_PUBKEY, X509_PUBKEY_free) |
| 5375 | BORINGSSL_MAKE_DELETER(X509_REQ, X509_REQ_free) |
| 5376 | BORINGSSL_MAKE_DELETER(X509_REVOKED, X509_REVOKED_free) |
| 5377 | BORINGSSL_MAKE_DELETER(X509_SIG, X509_SIG_free) |
| 5378 | BORINGSSL_MAKE_DELETER(X509_STORE, X509_STORE_free) |
| 5379 | BORINGSSL_MAKE_UP_REF(X509_STORE, X509_STORE_up_ref) |
| 5380 | BORINGSSL_MAKE_DELETER(X509_STORE_CTX, X509_STORE_CTX_free) |
| 5381 | BORINGSSL_MAKE_DELETER(X509_VERIFY_PARAM, X509_VERIFY_PARAM_free) |
| 5382 |
| 5383 | BSSL_NAMESPACE_END |
| 5384 |
| 5385 | } // extern C++ |
| 5386 | #endif // !BORINGSSL_NO_CXX |
| 5387 |
| 5388 | #define X509_R_AKID_MISMATCH 100 |
| 5389 | #define X509_R_BAD_PKCS7_VERSION 101 |
| 5390 | #define X509_R_BAD_X509_FILETYPE 102 |
| 5391 | #define X509_R_BASE64_DECODE_ERROR 103 |
| 5392 | #define X509_R_CANT_CHECK_DH_KEY 104 |
| 5393 | #define X509_R_CERT_ALREADY_IN_HASH_TABLE 105 |
| 5394 | #define X509_R_CRL_ALREADY_DELTA 106 |
| 5395 | #define X509_R_CRL_VERIFY_FAILURE 107 |
| 5396 | #define X509_R_IDP_MISMATCH 108 |
| 5397 | #define X509_R_INVALID_BIT_STRING_BITS_LEFT 109 |
| 5398 | #define X509_R_INVALID_DIRECTORY 110 |
| 5399 | #define X509_R_INVALID_FIELD_NAME 111 |
| 5400 | #define X509_R_INVALID_PSS_PARAMETERS 112 |
| 5401 | #define X509_R_INVALID_TRUST 113 |
| 5402 | #define X509_R_ISSUER_MISMATCH 114 |
| 5403 | #define X509_R_KEY_TYPE_MISMATCH 115 |
| 5404 | #define X509_R_KEY_VALUES_MISMATCH 116 |
| 5405 | #define X509_R_LOADING_CERT_DIR 117 |
| 5406 | #define X509_R_LOADING_DEFAULTS 118 |
| 5407 | #define X509_R_NEWER_CRL_NOT_NEWER 119 |
| 5408 | #define X509_R_NOT_PKCS7_SIGNED_DATA 120 |
| 5409 | #define X509_R_NO_CERTIFICATES_INCLUDED 121 |
| 5410 | #define X509_R_NO_CERT_SET_FOR_US_TO_VERIFY 122 |
| 5411 | #define X509_R_NO_CRLS_INCLUDED 123 |
| 5412 | #define X509_R_NO_CRL_NUMBER 124 |
| 5413 | #define X509_R_PUBLIC_KEY_DECODE_ERROR 125 |
| 5414 | #define X509_R_PUBLIC_KEY_ENCODE_ERROR 126 |
| 5415 | #define X509_R_SHOULD_RETRY 127 |
| 5416 | #define X509_R_UNKNOWN_KEY_TYPE 128 |
| 5417 | #define X509_R_UNKNOWN_NID 129 |
| 5418 | #define X509_R_UNKNOWN_PURPOSE_ID 130 |
| 5419 | #define X509_R_UNKNOWN_TRUST_ID 131 |
| 5420 | #define X509_R_UNSUPPORTED_ALGORITHM 132 |
| 5421 | #define X509_R_WRONG_LOOKUP_TYPE 133 |
| 5422 | #define X509_R_WRONG_TYPE 134 |
| 5423 | #define X509_R_NAME_TOO_LONG 135 |
| 5424 | #define X509_R_INVALID_PARAMETER 136 |
| 5425 | #define X509_R_SIGNATURE_ALGORITHM_MISMATCH 137 |
| 5426 | #define X509_R_DELTA_CRL_WITHOUT_CRL_NUMBER 138 |
| 5427 | #define X509_R_INVALID_FIELD_FOR_VERSION 139 |
| 5428 | #define X509_R_INVALID_VERSION 140 |
| 5429 | #define X509_R_NO_CERTIFICATE_FOUND 141 |
| 5430 | #define X509_R_NO_CERTIFICATE_OR_CRL_FOUND 142 |
| 5431 | #define X509_R_NO_CRL_FOUND 143 |
| 5432 | #define X509_R_INVALID_POLICY_EXTENSION 144 |
| 5433 |
| 5434 | #endif // OPENSSL_HEADER_X509_H |
| 5435 |