Botan 3.13.0
Crypto and TLS for C&
ffi_cert.cpp File Reference
#include <botan/ffi.h>
#include <botan/assert.h>
#include <botan/internal/ffi_cert.h>
#include <botan/internal/ffi_pkey.h>
#include <botan/internal/ffi_rng.h>
#include <botan/internal/ffi_util.h>
#include <memory>

Go to the source code of this file.

Functions

int botan_x509_cert_allowed_extended_usage_oid (botan_x509_cert_t cert, botan_asn1_oid_t oid)
int botan_x509_cert_allowed_extended_usage_str (botan_x509_cert_t cert, const char *oid)
int botan_x509_cert_allowed_usage (botan_x509_cert_t cert, unsigned int key_usage)
int botan_x509_cert_destroy (botan_x509_cert_t cert)
int botan_x509_cert_dup (botan_x509_cert_t *cert_obj, botan_x509_cert_t cert)
int botan_x509_cert_excluded_name_constraints (botan_x509_cert_t cert, size_t index, botan_x509_general_name_t *constraint)
int botan_x509_cert_excluded_name_constraints_count (botan_x509_cert_t cert, size_t *count)
int botan_x509_cert_get_authority_key_id (botan_x509_cert_t cert, uint8_t out[], size_t *out_len)
int botan_x509_cert_get_fingerprint (botan_x509_cert_t cert, const char *hash, uint8_t out[], size_t *out_len)
int botan_x509_cert_get_issuer_dn (botan_x509_cert_t cert, const char *key, size_t index, uint8_t out[], size_t *out_len)
int botan_x509_cert_get_issuer_dn_count (botan_x509_cert_t cert, const char *key, size_t *count)
int botan_x509_cert_get_path_length_constraint (botan_x509_cert_t cert, size_t *path_limit)
int botan_x509_cert_get_public_key (botan_x509_cert_t cert, botan_pubkey_t *key)
int botan_x509_cert_get_public_key_bits (botan_x509_cert_t cert, uint8_t out[], size_t *out_len)
int botan_x509_cert_get_serial_number (botan_x509_cert_t cert, uint8_t out[], size_t *out_len)
int botan_x509_cert_get_subject_dn (botan_x509_cert_t cert, const char *key, size_t index, uint8_t out[], size_t *out_len)
int botan_x509_cert_get_subject_dn_count (botan_x509_cert_t cert, const char *key, size_t *count)
int botan_x509_cert_get_subject_key_id (botan_x509_cert_t cert, uint8_t out[], size_t *out_len)
int botan_x509_cert_get_time_expires (botan_x509_cert_t cert, char out[], size_t *out_len)
int botan_x509_cert_get_time_starts (botan_x509_cert_t cert, char out[], size_t *out_len)
int botan_x509_cert_hostname_match (botan_x509_cert_t cert, const char *hostname)
int botan_x509_cert_is_ca (botan_x509_cert_t cert)
int botan_x509_cert_issuer_alternative_names (botan_x509_cert_t cert, size_t index, botan_x509_general_name_t *alt_name)
int botan_x509_cert_issuer_alternative_names_count (botan_x509_cert_t cert, size_t *count)
int botan_x509_cert_load (botan_x509_cert_t *cert_obj, const uint8_t cert_bits[], size_t cert_bits_len)
int botan_x509_cert_load_file (botan_x509_cert_t *cert_obj, const char *cert_path)
int botan_x509_cert_not_after (botan_x509_cert_t cert, uint64_t *time_since_epoch)
int botan_x509_cert_not_before (botan_x509_cert_t cert, uint64_t *time_since_epoch)
int botan_x509_cert_permitted_name_constraints (botan_x509_cert_t cert, size_t index, botan_x509_general_name_t *constraint)
int botan_x509_cert_permitted_name_constraints_count (botan_x509_cert_t cert, size_t *count)
int botan_x509_cert_serial_number (botan_x509_cert_t cert, botan_mp_t *serial_number)
int botan_x509_cert_subject_alternative_names (botan_x509_cert_t cert, size_t index, botan_x509_general_name_t *alt_name)
int botan_x509_cert_subject_alternative_names_count (botan_x509_cert_t cert, size_t *count)
int botan_x509_cert_to_string (botan_x509_cert_t cert, char out[], size_t *out_len)
const char * botan_x509_cert_validation_status (int code)
int botan_x509_cert_verify (int *result_code, botan_x509_cert_t cert, const botan_x509_cert_t *intermediates, size_t intermediates_len, const botan_x509_cert_t *trusted, size_t trusted_len, const char *trusted_path, size_t required_strength, const char *hostname_cstr, uint64_t reference_time)
int botan_x509_cert_verify_with_crl (int *result_code, botan_x509_cert_t cert, const botan_x509_cert_t *intermediates, size_t intermediates_len, const botan_x509_cert_t *trusted, size_t trusted_len, const botan_x509_crl_t *crls, size_t crls_len, const char *trusted_path, size_t required_strength, const char *hostname_cstr, uint64_t reference_time)
int botan_x509_cert_view_as_string (botan_x509_cert_t cert, botan_view_ctx ctx, botan_view_str_fn view)
int botan_x509_cert_view_binary_values (botan_x509_cert_t cert, botan_x509_value_type value_type, size_t index, botan_view_ctx ctx, botan_view_bin_fn view_fn)
int botan_x509_cert_view_binary_values_count (botan_x509_cert_t cert, botan_x509_value_type value_type, size_t *count)
int botan_x509_cert_view_public_key_bits (botan_x509_cert_t cert, botan_view_ctx ctx, botan_view_bin_fn view)
int botan_x509_cert_view_string_values (botan_x509_cert_t cert, botan_x509_value_type value_type, size_t index, botan_view_ctx ctx, botan_view_str_fn view_fn)
int botan_x509_cert_view_string_values_count (botan_x509_cert_t cert, botan_x509_value_type value_type, size_t *count)
int botan_x509_crl_create (botan_x509_crl_t *crl_obj, botan_rng_t rng, botan_x509_cert_t ca_cert, botan_privkey_t ca_key, uint64_t issue_time, uint32_t next_update, const char *hash_fn, const char *padding)
int botan_x509_crl_destroy (botan_x509_crl_t crl)
int botan_x509_crl_entries (botan_x509_crl_t crl, size_t index, botan_x509_crl_entry_t *entry)
int botan_x509_crl_entries_count (botan_x509_crl_t crl, size_t *count)
int botan_x509_crl_entry_create (botan_x509_crl_entry_t *entry, botan_x509_cert_t cert, int reason_code)
int botan_x509_crl_entry_destroy (botan_x509_crl_entry_t entry)
int botan_x509_crl_entry_reason (botan_x509_crl_entry_t entry, int *reason_code)
int botan_x509_crl_entry_revocation_date (botan_x509_crl_entry_t entry, uint64_t *time_since_epoch)
int botan_x509_crl_entry_serial_number (botan_x509_crl_entry_t entry, botan_mp_t *serial_number)
int botan_x509_crl_entry_view_serial_number (botan_x509_crl_entry_t entry, botan_view_ctx ctx, botan_view_bin_fn view)
int botan_x509_crl_load (botan_x509_crl_t *crl_obj, const uint8_t crl_bits[], size_t crl_bits_len)
int botan_x509_crl_load_file (botan_x509_crl_t *crl_obj, const char *crl_path)
int botan_x509_crl_next_update (botan_x509_crl_t crl, uint64_t *time_since_epoch)
int botan_x509_crl_this_update (botan_x509_crl_t crl, uint64_t *time_since_epoch)
int botan_x509_crl_update (botan_x509_crl_t *crl_obj, botan_x509_crl_t last_crl, botan_rng_t rng, botan_x509_cert_t ca_cert, botan_privkey_t ca_key, uint64_t issue_time, uint32_t next_update, const botan_x509_crl_entry_t *new_entries, size_t new_entries_len, const char *hash_fn, const char *padding)
int botan_x509_crl_verify_signature (botan_x509_crl_t crl, botan_pubkey_t key)
int botan_x509_crl_view_binary_values (botan_x509_crl_t crl_obj, botan_x509_value_type value_type, size_t index, botan_view_ctx ctx, botan_view_bin_fn view_fn)
int botan_x509_crl_view_binary_values_count (botan_x509_crl_t crl_obj, botan_x509_value_type value_type, size_t *count)
int botan_x509_crl_view_string_values (botan_x509_crl_t crl_obj, botan_x509_value_type value_type, size_t index, botan_view_ctx ctx, botan_view_str_fn view)
int botan_x509_crl_view_string_values_count (botan_x509_crl_t crl_obj, botan_x509_value_type value_type, size_t *count)
int botan_x509_general_name_destroy (botan_x509_general_name_t name)
int botan_x509_general_name_get_type (botan_x509_general_name_t name, unsigned int *type)
int botan_x509_general_name_view_binary_value (botan_x509_general_name_t name, botan_view_ctx ctx, botan_view_bin_fn view)
int botan_x509_general_name_view_string_value (botan_x509_general_name_t name, botan_view_ctx ctx, botan_view_str_fn view)
int botan_x509_is_revoked (botan_x509_crl_t crl, botan_x509_cert_t cert)

Function Documentation

◆ botan_x509_cert_allowed_extended_usage_oid()

int botan_x509_cert_allowed_extended_usage_oid ( botan_x509_cert_t cert,
botan_asn1_oid_t oid )

Check if the certificate allows the specified extended usage OID. See RFC 5280 Section 4.2.1.12 for OIDs to query for this. If no extended key usage extension is found in the certificate, this always returns "not success".

This is similar to botan_x509_cert_allowed_extended_usage_str but takes an OID object instead of a string describing the OID.

Definition at line 574 of file ffi_cert.cpp.

574 {
575#if defined(BOTAN_HAS_X509_CERTIFICATES)
576 return BOTAN_FFI_VISIT(cert, [=](const auto& c) -> int { return c.has_ex_constraint(safe_get(oid)) ? 1 : 0; });
577#else
578 BOTAN_UNUSED(cert, oid);
580#endif
581}
#define BOTAN_UNUSED
Definition assert.h:144
@ BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition ffi.h:138
#define BOTAN_FFI_VISIT(obj, lambda)
Definition ffi_util.h:158
T & safe_get(botan_struct< T, M > *p)
Definition ffi_util.h:79

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_VISIT, BOTAN_UNUSED, and Botan_FFI::safe_get().

◆ botan_x509_cert_allowed_extended_usage_str()

int botan_x509_cert_allowed_extended_usage_str ( botan_x509_cert_t cert,
const char * oid )

Check if the certificate allows the specified extended usage OID. See RFC 5280 Section 4.2.1.12 for OIDs to query for this. If no extended key usage extension is found in the certificate, this always returns "not success".

Typical OIDs to check for:

  • "PKIX.ServerAuth"
  • "PKIX.ClientAuth"
  • "PKIX.CodeSigning"
  • "PKIX.OCSPSigning"

The oid parameter can be either a canonical OID string or identifiers as indicated in the examples above.

Definition at line 559 of file ffi_cert.cpp.

559 {
560#if defined(BOTAN_HAS_X509_CERTIFICATES)
561 return BOTAN_FFI_VISIT(cert, [=](const auto& c) -> int {
562 if(Botan::any_null_pointers(oid)) {
564 }
565
566 return c.has_ex_constraint(oid) ? 1 : 0;
567 });
568#else
569 BOTAN_UNUSED(cert, oid);
571#endif
572}
@ BOTAN_FFI_ERROR_NULL_POINTER
Definition ffi.h:131
bool any_null_pointers(Ptrs... ptr)
Definition mem_utils.h:54

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, and BOTAN_UNUSED.

◆ botan_x509_cert_allowed_usage()

int botan_x509_cert_allowed_usage ( botan_x509_cert_t cert,
unsigned int key_usage )

Check if the certificate allows the specified key usage. If no key usage extension is found in the certificate, this always returns success.

Parameters
certthe certificate to inspect
key_usageone or more values from botan_x509_cert_key_constraints, ORed together
Returns
0 if the usage is allowed, 1 if it is not, negative on error

Definition at line 544 of file ffi_cert.cpp.

544 {
545#if defined(BOTAN_HAS_X509_CERTIFICATES)
546 return BOTAN_FFI_VISIT(cert, [=](const auto& c) -> int {
547 const Botan::Key_Constraints k = static_cast<Botan::Key_Constraints>(key_usage);
548 if(c.allowed_usage(k)) {
549 return BOTAN_FFI_SUCCESS;
550 }
551 return 1;
552 });
553#else
554 BOTAN_UNUSED(cert, key_usage);
556#endif
557}
@ BOTAN_FFI_SUCCESS
Definition ffi.h:114

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_FFI_VISIT, and BOTAN_UNUSED.

◆ botan_x509_cert_destroy()

int botan_x509_cert_destroy ( botan_x509_cert_t cert)

Frees all resources of the certificate object

Parameters
certthe certificate to destroy
Returns
0 if success, error if invalid object handle

Definition at line 583 of file ffi_cert.cpp.

583 {
584#if defined(BOTAN_HAS_X509_CERTIFICATES)
585 return BOTAN_FFI_CHECKED_DELETE(cert);
586#else
587 BOTAN_UNUSED(cert);
589#endif
590}
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition ffi_util.h:188

References BOTAN_FFI_CHECKED_DELETE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, and BOTAN_UNUSED.

◆ botan_x509_cert_dup()

int botan_x509_cert_dup ( botan_x509_cert_t * new_cert,
botan_x509_cert_t cert )

Create a new handle referring to the same certificate

Parameters
new_certthe new object will be placed here
certthe certificate to duplicate
Returns
0 on success, a negative value on failure

Definition at line 193 of file ffi_cert.cpp.

193 {
194 if(cert_obj == nullptr) {
196 }
197
198#if defined(BOTAN_HAS_X509_CERTIFICATES) && defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
199
200 return ffi_guard_thunk(__func__, [=]() -> int {
201 auto c = std::make_unique<Botan::X509_Certificate>(safe_get(cert));
202 return ffi_new_object(cert_obj, std::move(c));
203 });
204
205#else
206 BOTAN_UNUSED(cert);
208#endif
209}
BOTAN_FFI_ERROR ffi_new_object(T *obj, Args &&... args)
Definition ffi_util.h:178
int ffi_guard_thunk(const char *func_name, T thunk)
Definition ffi_util.h:95

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), and Botan_FFI::safe_get().

◆ botan_x509_cert_excluded_name_constraints()

int botan_x509_cert_excluded_name_constraints ( botan_x509_cert_t cert,
size_t index,
botan_x509_general_name_t * constraint )

Extracts "excluded" name constraints from a given cert one-by-one. Returns BOTAN_FFI_ERROR_OUT_OF_RANGE if the given index is larger than the available number of "excluded" name constraints.

Definition at line 823 of file ffi_cert.cpp.

825 {
826#if defined(BOTAN_HAS_X509_CERTIFICATES)
827 return BOTAN_FFI_VISIT(cert, [=](const Botan::X509_Certificate& c) {
828 if(Botan::any_null_pointers(constraint)) {
830 }
831
832 const auto& constraints = c.name_constraints().excluded();
833 if(index >= constraints.size()) {
835 }
836
837 return ffi_new_object(constraint, std::make_unique<Botan::GeneralName>(constraints[index].base()));
838 });
839#else
840 BOTAN_UNUSED(cert, index, constraint);
842#endif
843}
const std::vector< GeneralSubtree > & excluded() const
Definition pkix_types.h:775
const NameConstraints & name_constraints() const
Definition x509cert.cpp:515
@ BOTAN_FFI_ERROR_OUT_OF_RANGE
Definition ffi.h:136

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_ERROR_OUT_OF_RANGE, BOTAN_FFI_VISIT, BOTAN_UNUSED, Botan::NameConstraints::excluded(), Botan_FFI::ffi_new_object(), and Botan::X509_Certificate::name_constraints().

◆ botan_x509_cert_excluded_name_constraints_count()

int botan_x509_cert_excluded_name_constraints_count ( botan_x509_cert_t cert,
size_t * count )

Count the "excluded" name constraints of a given cert.

Parameters
certthe certificate to inspect
countset to the number of available entries
Returns
0 on success, a negative value on failure

Definition at line 845 of file ffi_cert.cpp.

845 {
846#if defined(BOTAN_HAS_X509_CERTIFICATES)
847 if(Botan::any_null_pointers(count)) {
849 }
850
851 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { *count = c.name_constraints().excluded().size(); });
852#else
853 BOTAN_UNUSED(cert, count);
855#endif
856}

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, and BOTAN_UNUSED.

◆ botan_x509_cert_get_authority_key_id()

int botan_x509_cert_get_authority_key_id ( botan_x509_cert_t cert,
uint8_t out[],
size_t * out_len )

Get the key identifier from the authority key identifier extension

Parameters
certthe certificate to inspect
outoutput buffer
out_lenon input the size of out, on output the number of bytes written or required
Returns
0 on success, a negative value on failure

Definition at line 677 of file ffi_cert.cpp.

677 {
678#if defined(BOTAN_HAS_X509_CERTIFICATES)
679 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { return write_vec_output(out, out_len, c.authority_key_id()); });
680#else
681 BOTAN_UNUSED(cert, out, out_len);
683#endif
684}
int write_vec_output(uint8_t out[], size_t *out_len, std::span< const uint8_t > buf)
Definition ffi_util.h:267

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_VISIT, BOTAN_UNUSED, and Botan_FFI::write_vec_output().

◆ botan_x509_cert_get_fingerprint()

int botan_x509_cert_get_fingerprint ( botan_x509_cert_t cert,
const char * hash,
uint8_t out[],
size_t * out_len )

Compute the fingerprint of the certificate, formatted as a hex string with colons between the bytes

Parameters
certthe certificate to inspect
Hashesthe name of the hash to use, eg "SHA-256"
outoutput buffer
out_lenon input the size of out, on output the number of bytes written or required
Returns
0 on success, a negative value on failure

TODO(Botan4) this should use char for the out param

Definition at line 661 of file ffi_cert.cpp.

661 {
662 if(hash == nullptr) {
664 }
665#if defined(BOTAN_HAS_X509_CERTIFICATES)
666 // TODO(Botan4) change the type of out and remove this cast
667
668 return BOTAN_FFI_VISIT(cert, [=](const auto& c) {
669 return write_str_output(reinterpret_cast<char*>(out), out_len, c.fingerprint(hash));
670 });
671#else
672 BOTAN_UNUSED(cert, hash, out, out_len);
674#endif
675}
int write_str_output(char out[], size_t *out_len, const std::string &str)
Definition ffi_util.h:271

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, BOTAN_UNUSED, and Botan_FFI::write_str_output().

◆ botan_x509_cert_get_issuer_dn()

int botan_x509_cert_get_issuer_dn ( botan_x509_cert_t cert,
const char * key,
size_t index,
uint8_t out[],
size_t * out_len )

Enumerates the names of the given key in the issuer DN. If index is out of bounds, BOTAN_FFI_ERROR_BAD_PARAMETER is returned.

TODO(Botan4) use BOTAN_FFI_ERROR_OUT_OF_RANGE instead of BAD_PARAMETER TODO(Botan4) this should use char for the out param

Definition at line 457 of file ffi_cert.cpp.

458 {
459 if(key == nullptr) {
461 }
462#if defined(BOTAN_HAS_X509_CERTIFICATES)
463 return BOTAN_FFI_VISIT(cert, [=](const auto& c) -> int {
464 auto issuer_info = c.issuer_info(key);
465 if(index < issuer_info.size()) {
466 // TODO(Botan4) change the type of out and remove this cast
467 return write_str_output(reinterpret_cast<char*>(out), out_len, c.issuer_info(key).at(index));
468 } else {
469 return BOTAN_FFI_ERROR_BAD_PARAMETER; // TODO(Botan4): use BOTAN_FFI_ERROR_OUT_OF_RANGE
470 }
471 });
472#else
473 BOTAN_UNUSED(cert, key, index, out, out_len);
475#endif
476}
@ BOTAN_FFI_ERROR_BAD_PARAMETER
Definition ffi.h:132

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, BOTAN_UNUSED, and Botan_FFI::write_str_output().

◆ botan_x509_cert_get_issuer_dn_count()

int botan_x509_cert_get_issuer_dn_count ( botan_x509_cert_t cert,
const char * key,
size_t * count )

Count the names of the given key present in the issuer DN.

Parameters
certthe certificate to inspect
keythe DN component to count, eg "Name"
countset to the number of available entries
Returns
0 on success, a negative value on failure

Definition at line 478 of file ffi_cert.cpp.

478 {
479#if defined(BOTAN_HAS_X509_CERTIFICATES)
480 return BOTAN_FFI_VISIT(cert, [=](const auto& c) -> int {
481 if(Botan::any_null_pointers(key, count)) {
483 }
484
485 *count = c.issuer_info(key).size();
486 return BOTAN_FFI_SUCCESS;
487 });
488#else
489 BOTAN_UNUSED(cert, key, count);
491#endif
492}

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_FFI_VISIT, and BOTAN_UNUSED.

◆ botan_x509_cert_get_path_length_constraint()

int botan_x509_cert_get_path_length_constraint ( botan_x509_cert_t cert,
size_t * path_limit )

Retrieves the path length constraint from the certificate. If no such constraint is present, BOTAN_FFI_ERROR_NO_VALUE is returned.

Definition at line 419 of file ffi_cert.cpp.

419 {
420#if defined(BOTAN_HAS_X509_CERTIFICATES)
421 return BOTAN_FFI_VISIT(cert, [=](const auto& c) -> int {
422 if(Botan::any_null_pointers(path_limit)) {
424 }
425
426 if(const auto path_len = c.path_length_constraint()) {
427 *path_limit = path_len.value();
428 return BOTAN_FFI_SUCCESS;
429 } else {
431 }
432 });
433#else
434 BOTAN_UNUSED(cert, path_limit);
436#endif
437}
@ BOTAN_FFI_ERROR_NO_VALUE
Definition ffi.h:120

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NO_VALUE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_FFI_VISIT, and BOTAN_UNUSED.

◆ botan_x509_cert_get_public_key()

int botan_x509_cert_get_public_key ( botan_x509_cert_t cert,
botan_pubkey_t * key )

Get the public key of the certificate

Parameters
certthe certificate to inspect
keythe new object will be placed here
Returns
0 on success, a negative value on failure

Definition at line 439 of file ffi_cert.cpp.

439 {
440 if(key == nullptr) {
442 }
443
444 *key = nullptr;
445
446#if defined(BOTAN_HAS_X509_CERTIFICATES)
447 return ffi_guard_thunk(__func__, [=]() -> int {
448 auto public_key = safe_get(cert).subject_public_key();
449 return ffi_new_object(key, std::move(public_key));
450 });
451#else
452 BOTAN_UNUSED(cert);
454#endif
455}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), and Botan_FFI::safe_get().

◆ botan_x509_cert_get_public_key_bits()

int botan_x509_cert_get_public_key_bits ( botan_x509_cert_t cert,
uint8_t out[],
size_t * out_len )

Get the DER encoded SubjectPublicKeyInfo of the certificate

Parameters
certthe certificate to inspect
outoutput buffer
out_lenon input the size of out, on output the number of bytes written or required
Returns
0 on success, a negative value on failure

Definition at line 695 of file ffi_cert.cpp.

695 {
696 return copy_view_bin(out, out_len, botan_x509_cert_view_public_key_bits, cert);
697}
int botan_x509_cert_view_public_key_bits(botan_x509_cert_t cert, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_cert.cpp:699
int copy_view_bin(uint8_t out[], size_t *out_len, Fn fn, Args... args)
Definition ffi_util.h:214

References botan_x509_cert_view_public_key_bits(), and Botan_FFI::copy_view_bin().

◆ botan_x509_cert_get_serial_number()

int botan_x509_cert_get_serial_number ( botan_x509_cert_t cert,
uint8_t out[],
size_t * out_len )

Get the serial number of the certificate as a big-endian binary string

Parameters
certthe certificate to inspect
outoutput buffer
out_lenon input the size of out, on output the number of bytes written or required
Returns
0 on success, a negative value on failure

Definition at line 636 of file ffi_cert.cpp.

636 {
637#if defined(BOTAN_HAS_X509_CERTIFICATES)
638 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { return write_vec_output(out, out_len, c.serial_number()); });
639#else
640 BOTAN_UNUSED(cert, out, out_len);
642#endif
643}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_VISIT, BOTAN_UNUSED, and Botan_FFI::write_vec_output().

◆ botan_x509_cert_get_subject_dn()

int botan_x509_cert_get_subject_dn ( botan_x509_cert_t cert,
const char * key,
size_t index,
uint8_t out[],
size_t * out_len )

Enumerates the names of the given key in the subject DN. If index is out of bounds, BOTAN_FFI_ERROR_BAD_PARAMETER is returned.

TODO(Botan4) use BOTAN_FFI_ERROR_OUT_OF_RANGE instead of BAD_PARAMETER TODO(Botan4) this should use char for the out param

Definition at line 494 of file ffi_cert.cpp.

495 {
496 if(key == nullptr) {
498 }
499#if defined(BOTAN_HAS_X509_CERTIFICATES)
500 return BOTAN_FFI_VISIT(cert, [=](const auto& c) -> int {
501 auto subject_info = c.subject_info(key);
502 if(index < subject_info.size()) {
503 // TODO(Botan4) change the type of out and remove this cast
504 return write_str_output(reinterpret_cast<char*>(out), out_len, c.subject_info(key).at(index));
505 } else {
506 return BOTAN_FFI_ERROR_BAD_PARAMETER; // TODO(Botan4): use BOTAN_FFI_ERROR_OUT_OF_RANGE
507 }
508 });
509#else
510 BOTAN_UNUSED(cert, key, index, out, out_len);
512#endif
513}

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, BOTAN_UNUSED, and Botan_FFI::write_str_output().

◆ botan_x509_cert_get_subject_dn_count()

int botan_x509_cert_get_subject_dn_count ( botan_x509_cert_t cert,
const char * key,
size_t * count )

Count the names of the given key present in the subject DN.

Parameters
certthe certificate to inspect
keythe DN component to count, eg "Name"
countset to the number of available entries
Returns
0 on success, a negative value on failure

Definition at line 515 of file ffi_cert.cpp.

515 {
516#if defined(BOTAN_HAS_X509_CERTIFICATES)
517 return BOTAN_FFI_VISIT(cert, [=](const auto& c) -> int {
518 if(Botan::any_null_pointers(key, count)) {
520 }
521
522 *count = c.subject_info(key).size();
523 return BOTAN_FFI_SUCCESS;
524 });
525#else
526 BOTAN_UNUSED(cert, key, count);
528#endif
529}

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_FFI_VISIT, and BOTAN_UNUSED.

◆ botan_x509_cert_get_subject_key_id()

int botan_x509_cert_get_subject_key_id ( botan_x509_cert_t cert,
uint8_t out[],
size_t * out_len )

Get the subject key identifier extension

Parameters
certthe certificate to inspect
outoutput buffer
out_lenon input the size of out, on output the number of bytes written or required
Returns
0 on success, a negative value on failure

Definition at line 686 of file ffi_cert.cpp.

686 {
687#if defined(BOTAN_HAS_X509_CERTIFICATES)
688 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { return write_vec_output(out, out_len, c.subject_key_id()); });
689#else
690 BOTAN_UNUSED(cert, out, out_len);
692#endif
693}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_VISIT, BOTAN_UNUSED, and Botan_FFI::write_vec_output().

◆ botan_x509_cert_get_time_expires()

int botan_x509_cert_get_time_expires ( botan_x509_cert_t cert,
char out[],
size_t * out_len )

Get the end of the validity period as a string

Prefer botan_x509_cert_not_after

Parameters
certthe certificate to inspect
outoutput buffer
out_lenon input the size of out, on output the number of bytes written or required
Returns
0 on success, a negative value on failure

Definition at line 602 of file ffi_cert.cpp.

602 {
603#if defined(BOTAN_HAS_X509_CERTIFICATES)
604 return BOTAN_FFI_VISIT(cert,
605 [=](const auto& c) { return write_str_output(out, out_len, c.not_after().to_string()); });
606#else
607 BOTAN_UNUSED(cert, out, out_len);
609#endif
610}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_VISIT, BOTAN_UNUSED, and Botan_FFI::write_str_output().

◆ botan_x509_cert_get_time_starts()

int botan_x509_cert_get_time_starts ( botan_x509_cert_t cert,
char out[],
size_t * out_len )

Get the start of the validity period as a string

Prefer botan_x509_cert_not_before

Parameters
certthe certificate to inspect
outoutput buffer
out_lenon input the size of out, on output the number of bytes written or required
Returns
0 on success, a negative value on failure

Definition at line 592 of file ffi_cert.cpp.

592 {
593#if defined(BOTAN_HAS_X509_CERTIFICATES)
594 return BOTAN_FFI_VISIT(cert,
595 [=](const auto& c) { return write_str_output(out, out_len, c.not_before().to_string()); });
596#else
597 BOTAN_UNUSED(cert, out, out_len);
599#endif
600}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_VISIT, BOTAN_UNUSED, and Botan_FFI::write_str_output().

◆ botan_x509_cert_hostname_match()

int botan_x509_cert_hostname_match ( botan_x509_cert_t cert,
const char * hostname )

Check if the certificate matches the specified hostname via alternative name or CN match. RFC 5280 wildcards also supported.

Definition at line 936 of file ffi_cert.cpp.

936 {
937 if(hostname == nullptr) {
939 }
940
941#if defined(BOTAN_HAS_X509_CERTIFICATES)
942 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { return c.matches_dns_name(hostname) ? 0 : -1; });
943#else
944 BOTAN_UNUSED(cert);
946#endif
947}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, and BOTAN_UNUSED.

◆ botan_x509_cert_is_ca()

int botan_x509_cert_is_ca ( botan_x509_cert_t cert)

Returns 1 iff the cert is a CA certificate

Definition at line 410 of file ffi_cert.cpp.

410 {
411#if defined(BOTAN_HAS_X509_CERTIFICATES)
412 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { return c.is_CA_cert() ? 1 : 0; });
413#else
414 BOTAN_UNUSED(cert);
416#endif
417}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_VISIT, and BOTAN_UNUSED.

◆ botan_x509_cert_issuer_alternative_names()

int botan_x509_cert_issuer_alternative_names ( botan_x509_cert_t cert,
size_t index,
botan_x509_general_name_t * alt_name )

Provides access to all "issuer alternative names", where each entry is returned as a botan_x509_general_name_t. If the given index is not within range of the available entries, BOTAN_FFI_ERROR_OUT_OF_RANGE is returned. If cert does not contain an IssuerAlternativeNames extension, BOTAN_FFI_ERROR_NO_VALUE is returned.

Definition at line 897 of file ffi_cert.cpp.

899 {
900#if defined(BOTAN_HAS_X509_CERTIFICATES)
901 return BOTAN_FFI_VISIT(cert, [=](const Botan::X509_Certificate& c) {
902 if(Botan::any_null_pointers(alt_name)) {
904 }
905
906 if(!c.v3_extensions().extension_set(Botan::OID::from_string("X509v3.IssuerAlternativeName"))) {
908 }
909
910 if(auto name = extract_general_name_at(c.issuer_alt_name(), index)) {
911 return ffi_new_object(alt_name, std::make_unique<Botan::GeneralName>(std::move(name).value()));
912 }
913
915 });
916#else
917 BOTAN_UNUSED(cert, index, alt_name);
919#endif
920}
bool extension_set(const OID &oid) const
Definition x509_ext.cpp:235
static OID from_string(std::string_view str)
Definition asn1_oid.cpp:80
const AlternativeName & issuer_alt_name() const
Definition x509cert.cpp:692
const Extensions & v3_extensions() const
Definition x509cert.cpp:519

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NO_VALUE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_ERROR_OUT_OF_RANGE, BOTAN_FFI_VISIT, BOTAN_UNUSED, Botan::Extensions::extension_set(), Botan_FFI::ffi_new_object(), Botan::OID::from_string(), Botan::X509_Certificate::issuer_alt_name(), and Botan::X509_Certificate::v3_extensions().

◆ botan_x509_cert_issuer_alternative_names_count()

int botan_x509_cert_issuer_alternative_names_count ( botan_x509_cert_t cert,
size_t * count )

Count the "issuer alternative names" of a given cert.

Parameters
certthe certificate to inspect
countset to the number of available entries
Returns
0 on success, a negative value on failure

Definition at line 922 of file ffi_cert.cpp.

922 {
923#if defined(BOTAN_HAS_X509_CERTIFICATES)
924 if(Botan::any_null_pointers(count)) {
926 }
927
928 return BOTAN_FFI_VISIT(
929 cert, [=](const Botan::X509_Certificate& c) { *count = count_general_names_in(c.issuer_alt_name()); });
930#else
931 BOTAN_UNUSED(cert, count);
933#endif
934}

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, BOTAN_UNUSED, and Botan::X509_Certificate::issuer_alt_name().

◆ botan_x509_cert_load()

int botan_x509_cert_load ( botan_x509_cert_t * cert_obj,
const uint8_t cert[],
size_t cert_len )

Load a certificate from a DER or PEM encoding

Parameters
cert_objthe new object will be placed here
certthe encoding to load
cert_lenlength of cert in bytes
Returns
0 on success, a negative value on failure

Definition at line 211 of file ffi_cert.cpp.

211 {
212 if(Botan::any_null_pointers(cert_obj, cert_bits)) {
214 }
215
216#if defined(BOTAN_HAS_X509_CERTIFICATES)
217 return ffi_guard_thunk(__func__, [=]() -> int {
218 Botan::DataSource_Memory bits(cert_bits, cert_bits_len);
219 auto c = std::make_unique<Botan::X509_Certificate>(bits);
220 return ffi_new_object(cert_obj, std::move(c));
221 });
222#else
223 BOTAN_UNUSED(cert_bits_len);
225#endif
226}

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), and Botan_FFI::ffi_new_object().

◆ botan_x509_cert_load_file()

int botan_x509_cert_load_file ( botan_x509_cert_t * cert_obj,
const char * filename )

Load a certificate from a file containing a DER or PEM encoding

Parameters
cert_objthe new object will be placed here
filenamepath of the file to read
Returns
0 on success, a negative value on failure

Definition at line 176 of file ffi_cert.cpp.

176 {
177 if(Botan::any_null_pointers(cert_obj, cert_path)) {
179 }
180
181#if defined(BOTAN_HAS_X509_CERTIFICATES) && defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
182
183 return ffi_guard_thunk(__func__, [=]() -> int {
184 auto c = std::make_unique<Botan::X509_Certificate>(cert_path);
185 return ffi_new_object(cert_obj, std::move(c));
186 });
187
188#else
190#endif
191}

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, Botan_FFI::ffi_guard_thunk(), and Botan_FFI::ffi_new_object().

◆ botan_x509_cert_not_after()

int botan_x509_cert_not_after ( botan_x509_cert_t cert,
uint64_t * time_since_epoch )

Get the end of the validity period as seconds since the Unix epoch

Parameters
certthe certificate to inspect
time_since_epochset to the notAfter time
Returns
0 on success, a negative value on failure

Definition at line 624 of file ffi_cert.cpp.

624 {
625 if(time_since_epoch == nullptr) {
627 }
628#if defined(BOTAN_HAS_X509_CERTIFICATES)
629 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { *time_since_epoch = c.not_after().time_since_epoch(); });
630#else
631 BOTAN_UNUSED(cert, time_since_epoch);
633#endif
634}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, and BOTAN_UNUSED.

◆ botan_x509_cert_not_before()

int botan_x509_cert_not_before ( botan_x509_cert_t cert,
uint64_t * time_since_epoch )

Get the start of the validity period as seconds since the Unix epoch

Parameters
certthe certificate to inspect
time_since_epochset to the notBefore time
Returns
0 on success, a negative value on failure

Definition at line 612 of file ffi_cert.cpp.

612 {
613 if(time_since_epoch == nullptr) {
615 }
616#if defined(BOTAN_HAS_X509_CERTIFICATES)
617 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { *time_since_epoch = c.not_before().time_since_epoch(); });
618#else
619 BOTAN_UNUSED(cert, time_since_epoch);
621#endif
622}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, and BOTAN_UNUSED.

◆ botan_x509_cert_permitted_name_constraints()

int botan_x509_cert_permitted_name_constraints ( botan_x509_cert_t cert,
size_t index,
botan_x509_general_name_t * constraint )

Extracts "permitted" name constraints from a given cert one-by-one. Returns BOTAN_FFI_ERROR_OUT_OF_RANGE if the given index is larger than the available number of "permitted" name constraints.

Definition at line 788 of file ffi_cert.cpp.

790 {
791#if defined(BOTAN_HAS_X509_CERTIFICATES)
792 return BOTAN_FFI_VISIT(cert, [=](const Botan::X509_Certificate& c) {
793 if(Botan::any_null_pointers(constraint)) {
795 }
796
797 const auto& constraints = c.name_constraints().permitted();
798 if(index >= constraints.size()) {
800 }
801
802 return ffi_new_object(constraint, std::make_unique<Botan::GeneralName>(constraints[index].base()));
803 });
804#else
805 BOTAN_UNUSED(cert, index, constraint);
807#endif
808}
const std::vector< GeneralSubtree > & permitted() const
Definition pkix_types.h:768

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_ERROR_OUT_OF_RANGE, BOTAN_FFI_VISIT, BOTAN_UNUSED, Botan_FFI::ffi_new_object(), Botan::X509_Certificate::name_constraints(), and Botan::NameConstraints::permitted().

◆ botan_x509_cert_permitted_name_constraints_count()

int botan_x509_cert_permitted_name_constraints_count ( botan_x509_cert_t cert,
size_t * count )

Count the "permitted" name constraints of a given cert.

Parameters
certthe certificate to inspect
countset to the number of available entries
Returns
0 on success, a negative value on failure

Definition at line 810 of file ffi_cert.cpp.

810 {
811#if defined(BOTAN_HAS_X509_CERTIFICATES)
812 if(Botan::any_null_pointers(count)) {
814 }
815
816 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { *count = c.name_constraints().permitted().size(); });
817#else
818 BOTAN_UNUSED(cert, count);
820#endif
821}

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, and BOTAN_UNUSED.

◆ botan_x509_cert_serial_number()

int botan_x509_cert_serial_number ( botan_x509_cert_t cert,
botan_mp_t * serial_number )

Get the serial number of the certificate as an integer

Parameters
certthe certificate to inspect
serial_numberthe new object will be placed here
Returns
0 on success, a negative value on failure

Definition at line 645 of file ffi_cert.cpp.

645 {
646#if defined(BOTAN_HAS_X509_CERTIFICATES)
647 return BOTAN_FFI_VISIT(cert, [=](const Botan::X509_Certificate& c) {
648 if(Botan::any_null_pointers(serial_number)) {
650 }
651
652 auto serial_bn = c.serial().to_bigint();
653 return ffi_new_object(serial_number, std::make_unique<Botan::BigInt>(std::move(serial_bn)));
654 });
655#else
656 BOTAN_UNUSED(cert, serial_number);
658#endif
659}
const X509_Serial_Number & serial() const
Definition x509cert.cpp:444

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, BOTAN_UNUSED, Botan_FFI::ffi_new_object(), Botan::X509_Certificate::serial(), and Botan::X509_Serial_Number::to_bigint().

◆ botan_x509_cert_subject_alternative_names()

int botan_x509_cert_subject_alternative_names ( botan_x509_cert_t cert,
size_t index,
botan_x509_general_name_t * alt_name )

Provides access to all "subject alternative names", where each entry is returned as a botan_x509_general_name_t. If the given index is not within range of the available entries, BOTAN_FFI_ERROR_OUT_OF_RANGE is returned. If cert does not contain a SubjectAlternativeNames extension, BOTAN_FFI_ERROR_NO_VALUE is returned.

Definition at line 858 of file ffi_cert.cpp.

860 {
861#if defined(BOTAN_HAS_X509_CERTIFICATES)
862 return BOTAN_FFI_VISIT(cert, [=](const Botan::X509_Certificate& c) {
863 if(Botan::any_null_pointers(alt_name)) {
865 }
866
867 if(!c.v3_extensions().extension_set(Botan::OID::from_string("X509v3.SubjectAlternativeName"))) {
869 }
870
871 if(auto name = extract_general_name_at(c.subject_alt_name(), index)) {
872 return ffi_new_object(alt_name, std::make_unique<Botan::GeneralName>(std::move(name).value()));
873 }
874
876 });
877#else
878 BOTAN_UNUSED(cert, index, alt_name);
880#endif
881}
const AlternativeName & subject_alt_name() const
Definition x509cert.cpp:688

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NO_VALUE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_ERROR_OUT_OF_RANGE, BOTAN_FFI_VISIT, BOTAN_UNUSED, Botan::Extensions::extension_set(), Botan_FFI::ffi_new_object(), Botan::OID::from_string(), Botan::X509_Certificate::subject_alt_name(), and Botan::X509_Certificate::v3_extensions().

◆ botan_x509_cert_subject_alternative_names_count()

int botan_x509_cert_subject_alternative_names_count ( botan_x509_cert_t cert,
size_t * count )

Count the "subject alternative names" of a given cert.

Parameters
certthe certificate to inspect
countset to the number of available entries
Returns
0 on success, a negative value on failure

Definition at line 883 of file ffi_cert.cpp.

883 {
884#if defined(BOTAN_HAS_X509_CERTIFICATES)
885 if(Botan::any_null_pointers(count)) {
887 }
888
889 return BOTAN_FFI_VISIT(
890 cert, [=](const Botan::X509_Certificate& c) { *count = count_general_names_in(c.subject_alt_name()); });
891#else
892 BOTAN_UNUSED(cert, count);
894#endif
895}

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, BOTAN_UNUSED, and Botan::X509_Certificate::subject_alt_name().

◆ botan_x509_cert_to_string()

int botan_x509_cert_to_string ( botan_x509_cert_t cert,
char out[],
size_t * out_len )

Format the certificate as a human readable string

Parameters
certthe certificate to format
outoutput buffer
out_lenon input the size of out, on output the number of bytes written or required
Returns
0 on success, a negative value on failure

Definition at line 531 of file ffi_cert.cpp.

531 {
532 return copy_view_str(reinterpret_cast<uint8_t*>(out), out_len, botan_x509_cert_view_as_string, cert);
533}
int botan_x509_cert_view_as_string(botan_x509_cert_t cert, botan_view_ctx ctx, botan_view_str_fn view)
Definition ffi_cert.cpp:535
int copy_view_str(uint8_t out[], size_t *out_len, Fn fn, Args... args)
Definition ffi_util.h:223

References botan_x509_cert_view_as_string(), and Botan_FFI::copy_view_str().

◆ botan_x509_cert_validation_status()

const char * botan_x509_cert_validation_status ( int code)

Returns a pointer to a static character string explaining the status code, or else NULL if unknown.

Definition at line 1023 of file ffi_cert.cpp.

1023 {
1024 if(code < 0) {
1025 return nullptr;
1026 }
1027
1028#if defined(BOTAN_HAS_X509_CERTIFICATES)
1030 return Botan::to_string(sc);
1031#else
1032 return nullptr;
1033#endif
1034}
Certificate_Status_Code
Definition pkix_enums.h:21
std::string to_string(ErrorType type)
Convert an ErrorType to string.
Definition exceptn.cpp:13

References Botan::to_string().

◆ botan_x509_cert_verify()

int botan_x509_cert_verify ( int * validation_result,
botan_x509_cert_t cert,
const botan_x509_cert_t * intermediates,
size_t intermediates_len,
const botan_x509_cert_t * trusted,
size_t trusted_len,
const char * trusted_path,
size_t required_strength,
const char * hostname,
uint64_t reference_time )

Returns 0 if the validation was successful, 1 if validation failed, and negative on error. A status code with details is written to *validation_result

Intermediates or trusted lists can be null Trusted path can be null

Definition at line 949 of file ffi_cert.cpp.

958 {
959 if(required_strength == 0) {
960 required_strength = 110;
961 }
962
963#if defined(BOTAN_HAS_X509_CERTIFICATES)
964 return ffi_guard_thunk(__func__, [=]() -> int {
965 const std::string hostname((hostname_cstr == nullptr) ? "" : hostname_cstr);
967 const auto validation_time = reference_time == 0
968 ? std::chrono::system_clock::now()
969 : std::chrono::system_clock::from_time_t(static_cast<time_t>(reference_time));
970
971 if(intermediates_len > 0 && intermediates == nullptr) {
973 }
974 if(trusted_len > 0 && trusted == nullptr) {
976 }
977
978 std::vector<Botan::X509_Certificate> end_certs;
979 end_certs.push_back(safe_get(cert));
980 for(size_t i = 0; i != intermediates_len; ++i) {
981 end_certs.push_back(safe_get(intermediates[i]));
982 }
983
984 std::unique_ptr<Botan::Certificate_Store> trusted_from_path;
985 std::unique_ptr<Botan::Certificate_Store_In_Memory> trusted_extra;
986 std::vector<Botan::Certificate_Store*> trusted_roots;
987
988 if(trusted_path != nullptr && *trusted_path != 0) {
989 trusted_from_path = std::make_unique<Botan::Certificate_Store_In_Memory>(trusted_path);
990 trusted_roots.push_back(trusted_from_path.get());
991 }
992
993 if(trusted_len > 0) {
994 trusted_extra = std::make_unique<Botan::Certificate_Store_In_Memory>();
995 for(size_t i = 0; i != trusted_len; ++i) {
996 trusted_extra->add_certificate(safe_get(trusted[i]));
997 }
998 trusted_roots.push_back(trusted_extra.get());
999 }
1000
1001 const Botan::Path_Validation_Restrictions restrictions(false, required_strength);
1002
1003 auto validation_result =
1004 Botan::x509_path_validate(end_certs, restrictions, trusted_roots, hostname, usage, validation_time);
1005
1006 if(result_code != nullptr) {
1007 *result_code = static_cast<int>(validation_result.result());
1008 }
1009
1010 if(validation_result.successful_validation()) {
1011 return 0;
1012 } else {
1013 return 1;
1014 }
1015 });
1016#else
1017 BOTAN_UNUSED(result_code, cert, intermediates, intermediates_len, trusted);
1018 BOTAN_UNUSED(trusted_len, trusted_path, hostname_cstr, reference_time);
1020#endif
1021}
Path_Validation_Result x509_path_validate(const std::vector< X509_Certificate > &end_certs, const Path_Validation_Restrictions &restrictions, const std::vector< Certificate_Store * > &trusted_roots, std::string_view hostname, Usage_Type usage, std::chrono::system_clock::time_point ref_time, std::chrono::milliseconds ocsp_timeout, const std::vector< std::optional< OCSP::Response > > &ocsp_resp)

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::safe_get(), Botan::UNSPECIFIED, and Botan::x509_path_validate().

◆ botan_x509_cert_verify_with_crl()

int botan_x509_cert_verify_with_crl ( int * validation_result,
botan_x509_cert_t cert,
const botan_x509_cert_t * intermediates,
size_t intermediates_len,
const botan_x509_cert_t * trusted,
size_t trusted_len,
const botan_x509_crl_t * crls,
size_t crls_len,
const char * trusted_path,
size_t required_strength,
const char * hostname,
uint64_t reference_time )

Different flavor of botan_x509_cert_verify, supports revocation lists. CRLs are passed as an array, same as intermediates and trusted CAs

Definition at line 1433 of file ffi_cert.cpp.

1444 {
1445 if(required_strength == 0) {
1446 required_strength = 110;
1447 }
1448
1449#if defined(BOTAN_HAS_X509_CERTIFICATES)
1450 return ffi_guard_thunk(__func__, [=]() -> int {
1451 const std::string hostname((hostname_cstr == nullptr) ? "" : hostname_cstr);
1453 const auto validation_time = reference_time == 0
1454 ? std::chrono::system_clock::now()
1455 : std::chrono::system_clock::from_time_t(static_cast<time_t>(reference_time));
1456
1457 if(intermediates_len > 0 && intermediates == nullptr) {
1459 }
1460 if(trusted_len > 0 && trusted == nullptr) {
1462 }
1463 if(crls_len > 0 && crls == nullptr) {
1465 }
1466
1467 std::vector<Botan::X509_Certificate> end_certs;
1468 end_certs.push_back(safe_get(cert));
1469 for(size_t i = 0; i != intermediates_len; ++i) {
1470 end_certs.push_back(safe_get(intermediates[i]));
1471 }
1472
1473 std::unique_ptr<Botan::Certificate_Store> trusted_from_path;
1474 std::unique_ptr<Botan::Certificate_Store_In_Memory> trusted_extra;
1475 std::unique_ptr<Botan::Certificate_Store_In_Memory> trusted_crls;
1476 std::vector<Botan::Certificate_Store*> trusted_roots;
1477
1478 if(trusted_path != nullptr && *trusted_path != 0) {
1479 trusted_from_path = std::make_unique<Botan::Certificate_Store_In_Memory>(trusted_path);
1480 trusted_roots.push_back(trusted_from_path.get());
1481 }
1482
1483 if(trusted_len > 0) {
1484 trusted_extra = std::make_unique<Botan::Certificate_Store_In_Memory>();
1485 for(size_t i = 0; i != trusted_len; ++i) {
1486 trusted_extra->add_certificate(safe_get(trusted[i]));
1487 }
1488 trusted_roots.push_back(trusted_extra.get());
1489 }
1490
1491 if(crls_len > 0) {
1492 trusted_crls = std::make_unique<Botan::Certificate_Store_In_Memory>();
1493 for(size_t i = 0; i != crls_len; ++i) {
1494 trusted_crls->add_crl(safe_get(crls[i]));
1495 }
1496 trusted_roots.push_back(trusted_crls.get());
1497 }
1498
1499 const Botan::Path_Validation_Restrictions restrictions(false, required_strength);
1500
1501 auto validation_result =
1502 Botan::x509_path_validate(end_certs, restrictions, trusted_roots, hostname, usage, validation_time);
1503
1504 if(result_code != nullptr) {
1505 *result_code = static_cast<int>(validation_result.result());
1506 }
1507
1508 if(validation_result.successful_validation()) {
1509 return 0;
1510 } else {
1511 return 1;
1512 }
1513 });
1514#else
1515 BOTAN_UNUSED(result_code, cert, intermediates, intermediates_len, trusted);
1516 BOTAN_UNUSED(trusted_len, trusted_path, hostname_cstr, reference_time, crls, crls_len);
1518#endif
1519}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::safe_get(), Botan::UNSPECIFIED, and Botan::x509_path_validate().

◆ botan_x509_cert_view_as_string()

int botan_x509_cert_view_as_string ( botan_x509_cert_t cert,
botan_view_ctx ctx,
botan_view_str_fn view )

View the certificate formatted as a human readable string

Parameters
certthe certificate to format
ctxan application context passed to the view function
viewthe view callback which receives the string
Returns
0 on success, a negative value on failure

Definition at line 535 of file ffi_cert.cpp.

535 {
536#if defined(BOTAN_HAS_X509_CERTIFICATES)
537 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { return invoke_view_callback(view, ctx, c.to_string()); });
538#else
539 BOTAN_UNUSED(cert, ctx, view);
541#endif
542}
int invoke_view_callback(botan_view_bin_fn view, botan_view_ctx ctx, std::span< const uint8_t > buf)
Definition ffi_util.h:190

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_VISIT, BOTAN_UNUSED, and Botan_FFI::invoke_view_callback().

Referenced by botan_x509_cert_to_string().

◆ botan_x509_cert_view_binary_values()

int botan_x509_cert_view_binary_values ( botan_x509_cert_t cert,
botan_x509_value_type value_type,
size_t index,
botan_view_ctx ctx,
botan_view_bin_fn view )

Retrieve a specific binary value from an X.509 certificate.

For multi-values index allows enumerating the available entries, until BOTAN_FFI_ERROR_OUT_OF_RANGE is returned. For singleton values, an index of value "0" is expected.

Returns
BOTAN_FFI_ERROR_NO_VALUE if the provided cert does not provide the requested value_type at all or not in binary format.

Definition at line 285 of file ffi_cert.cpp.

289 {
290#if defined(BOTAN_HAS_X509_CERTIFICATES)
291 if(index != 0) {
292 // As of now there are no multi-value binary entries.
294 }
295
296 auto view = [=](std::span<const uint8_t> value) -> int {
297 if(value.empty()) {
299 } else {
300 return invoke_view_callback(view_fn, ctx, value);
301 }
302 };
303
304 return BOTAN_FFI_VISIT(cert, [=](const Botan::X509_Certificate& c) -> int {
305 switch(value_type) {
307 return view(c.serial_number());
309 return view(c.raw_subject_dn());
311 return view(c.raw_issuer_dn());
313 return view(c.subject_key_id());
315 return view(c.authority_key_id());
317 return view(c.subject_public_key_info());
318
323 return botan_x509_object_view_value(c, value_type, index, ctx, view_fn);
324
330 }
331
333 });
334#else
335 BOTAN_UNUSED(cert, value_type, index, ctx, view_fn);
337#endif
338}
const std::vector< uint8_t > & serial_number() const
Definition x509cert.cpp:440
const std::vector< uint8_t > & authority_key_id() const
Definition x509cert.cpp:432
const std::vector< uint8_t > & raw_subject_dn() const
Definition x509cert.cpp:468
const std::vector< uint8_t > & subject_key_id() const
Definition x509cert.cpp:436
const std::vector< uint8_t > & raw_issuer_dn() const
Definition x509cert.cpp:464
const std::vector< uint8_t > & subject_public_key_info() const
Definition x509cert.cpp:412
@ BOTAN_X509_AUTHORITY_KEY_IDENTIFIER
Definition ffi.h:3503
@ BOTAN_X509_SUBJECT_KEY_IDENTIFIER
Definition ffi.h:3502
@ BOTAN_X509_TBS_DATA_BITS
Definition ffi.h:3506
@ BOTAN_X509_SIGNATURE_BITS
Definition ffi.h:3508
@ BOTAN_X509_PUBLIC_KEY_PKCS8_BITS
Definition ffi.h:3505
@ BOTAN_X509_DER_ENCODING
Definition ffi.h:3510
@ BOTAN_X509_PEM_ENCODING
Definition ffi.h:3511
@ BOTAN_X509_OCSP_RESPONDER_URLS
Definition ffi.h:3514
@ BOTAN_X509_SIGNATURE_SCHEME_BITS
Definition ffi.h:3507
@ BOTAN_X509_SUBJECT_DN_BITS
Definition ffi.h:3500
@ BOTAN_X509_CRL_DISTRIBUTION_URLS
Definition ffi.h:3513
@ BOTAN_X509_SERIAL_NUMBER
Definition ffi.h:3499
@ BOTAN_X509_ISSUER_DN_BITS
Definition ffi.h:3501
@ BOTAN_X509_CA_ISSUERS_URLS
Definition ffi.h:3515

References Botan::X509_Certificate::authority_key_id(), BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NO_VALUE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_OUT_OF_RANGE, BOTAN_FFI_VISIT, BOTAN_UNUSED, BOTAN_X509_AUTHORITY_KEY_IDENTIFIER, BOTAN_X509_CA_ISSUERS_URLS, BOTAN_X509_CRL_DISTRIBUTION_URLS, BOTAN_X509_DER_ENCODING, BOTAN_X509_ISSUER_DN_BITS, BOTAN_X509_OCSP_RESPONDER_URLS, BOTAN_X509_PEM_ENCODING, BOTAN_X509_PUBLIC_KEY_PKCS8_BITS, BOTAN_X509_SERIAL_NUMBER, BOTAN_X509_SIGNATURE_BITS, BOTAN_X509_SIGNATURE_SCHEME_BITS, BOTAN_X509_SUBJECT_DN_BITS, BOTAN_X509_SUBJECT_KEY_IDENTIFIER, BOTAN_X509_TBS_DATA_BITS, Botan_FFI::invoke_view_callback(), Botan::X509_Certificate::raw_issuer_dn(), Botan::X509_Certificate::raw_subject_dn(), Botan::X509_Certificate::serial_number(), Botan::X509_Certificate::subject_key_id(), and Botan::X509_Certificate::subject_public_key_info().

Referenced by botan_x509_cert_view_binary_values_count().

◆ botan_x509_cert_view_binary_values_count()

int botan_x509_cert_view_binary_values_count ( botan_x509_cert_t cert,
botan_x509_value_type value_type,
size_t * count )

Count the binary values of the given type available in an X.509 certificate.

Parameters
certthe certificate to inspect
value_typethe value type to count
countset to the number of available entries
Returns
0 on success, a negative value on failure

Definition at line 340 of file ffi_cert.cpp.

340 {
341#if defined(BOTAN_HAS_X509_CERTIFICATES)
342 return enumerator_count_values(count, [=](size_t index) {
344 cert, value_type, index, nullptr, [](auto, auto, auto) -> int { return BOTAN_FFI_SUCCESS; });
345 });
346#else
347 BOTAN_UNUSED(cert, value_type, count);
349#endif
350}
int botan_x509_cert_view_binary_values(botan_x509_cert_t cert, botan_x509_value_type value_type, size_t index, botan_view_ctx ctx, botan_view_bin_fn view_fn)
Definition ffi_cert.cpp:285

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, and botan_x509_cert_view_binary_values().

◆ botan_x509_cert_view_public_key_bits()

int botan_x509_cert_view_public_key_bits ( botan_x509_cert_t cert,
botan_view_ctx ctx,
botan_view_bin_fn view )

View the DER encoded SubjectPublicKeyInfo of the certificate

Parameters
certthe certificate to inspect
ctxan application context passed to the view function
viewthe view callback which receives the encoding
Returns
0 on success, a negative value on failure

Definition at line 699 of file ffi_cert.cpp.

699 {
700#if defined(BOTAN_HAS_X509_CERTIFICATES)
701 return BOTAN_FFI_VISIT(cert,
702 [=](const auto& c) { return invoke_view_callback(view, ctx, c.subject_public_key_bits()); });
703#else
704 BOTAN_UNUSED(cert, ctx, view);
706#endif
707}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_VISIT, BOTAN_UNUSED, and Botan_FFI::invoke_view_callback().

Referenced by botan_x509_cert_get_public_key_bits().

◆ botan_x509_cert_view_string_values()

int botan_x509_cert_view_string_values ( botan_x509_cert_t cert,
botan_x509_value_type value_type,
size_t index,
botan_view_ctx ctx,
botan_view_str_fn view )

Retrieve a specific string value from an X.509 certificate.

For multi-values index allows enumerating the available entries, until BOTAN_FFI_ERROR_OUT_OF_RANGE is returned. For singleton values, an index of value "0" is expected.

Returns
BOTAN_FFI_ERROR_NO_VALUE if the provided cert does not provide the requested value_type at all or not in string format.

Definition at line 352 of file ffi_cert.cpp.

356 {
357#if defined(BOTAN_HAS_X509_CERTIFICATES)
358 auto enumerate_uris = [view_fn, ctx](const std::vector<Botan::URI>& values, size_t idx) -> int {
359 if(idx >= values.size()) {
361 } else {
362 return invoke_view_callback(view_fn, ctx, values[idx].original_input());
363 }
364 };
365
366 return BOTAN_FFI_VISIT(cert, [=](const Botan::X509_Certificate& c) -> int {
367 switch(value_type) {
369 return enumerate_uris(c.crl_distribution_point_uris(), index);
371 return enumerate_uris(c.ocsp_responder_uris(), index);
373 return enumerate_uris(c.ca_issuer_uris(), index);
375 return botan_x509_object_view_value(c, value_type, index, ctx, view_fn);
376
388 }
389
391 });
392#else
393 BOTAN_UNUSED(cert, value_type, index, ctx, view_fn);
395#endif
396}
const std::vector< URI > & ocsp_responder_uris() const
Definition x509cert.cpp:641
const std::vector< URI > & crl_distribution_point_uris() const
Definition x509cert.cpp:657
const std::vector< URI > & ca_issuer_uris() const
Definition x509cert.cpp:649

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NO_VALUE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_OUT_OF_RANGE, BOTAN_FFI_VISIT, BOTAN_UNUSED, BOTAN_X509_AUTHORITY_KEY_IDENTIFIER, BOTAN_X509_CA_ISSUERS_URLS, BOTAN_X509_CRL_DISTRIBUTION_URLS, BOTAN_X509_DER_ENCODING, BOTAN_X509_ISSUER_DN_BITS, BOTAN_X509_OCSP_RESPONDER_URLS, BOTAN_X509_PEM_ENCODING, BOTAN_X509_PUBLIC_KEY_PKCS8_BITS, BOTAN_X509_SERIAL_NUMBER, BOTAN_X509_SIGNATURE_BITS, BOTAN_X509_SIGNATURE_SCHEME_BITS, BOTAN_X509_SUBJECT_DN_BITS, BOTAN_X509_SUBJECT_KEY_IDENTIFIER, BOTAN_X509_TBS_DATA_BITS, Botan::X509_Certificate::ca_issuer_uris(), Botan::X509_Certificate::crl_distribution_point_uris(), Botan_FFI::invoke_view_callback(), and Botan::X509_Certificate::ocsp_responder_uris().

Referenced by botan_x509_cert_view_string_values_count().

◆ botan_x509_cert_view_string_values_count()

int botan_x509_cert_view_string_values_count ( botan_x509_cert_t cert,
botan_x509_value_type value_type,
size_t * count )

Count the string values of the given type available in an X.509 certificate.

Parameters
certthe certificate to inspect
value_typethe value type to count
countset to the number of available entries
Returns
0 on success, a negative value on failure

Definition at line 398 of file ffi_cert.cpp.

398 {
399#if defined(BOTAN_HAS_X509_CERTIFICATES)
400 return enumerator_count_values(count, [=](size_t index) {
402 cert, value_type, index, nullptr, [](auto, auto, auto) -> int { return BOTAN_FFI_SUCCESS; });
403 });
404#else
405 BOTAN_UNUSED(cert, value_type, count);
407#endif
408}
int botan_x509_cert_view_string_values(botan_x509_cert_t cert, botan_x509_value_type value_type, size_t index, botan_view_ctx ctx, botan_view_str_fn view_fn)
Definition ffi_cert.cpp:352

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, and botan_x509_cert_view_string_values().

◆ botan_x509_crl_create()

int botan_x509_crl_create ( botan_x509_crl_t * crl_obj,
botan_rng_t rng,
botan_x509_cert_t ca_cert,
botan_privkey_t ca_key,
uint64_t issue_time,
uint32_t next_update,
const char * hash_fn,
const char * padding )

Create a new CRL

Parameters
crl_objThe newly created CRL
Random Number Generatorsa random number generator object
ca_certThe CA Certificate the CRL belongs to
ca_keyThe private key of that CA
issue_timeThe time when the CRL becomes valid
next_updateThe number of seconds after issue_time until the CRL expires
hash_fnThe hash function to use, may be null
paddingThe padding to use, may be null

Definition at line 1106 of file ffi_cert.cpp.

1113 {
1114 if(Botan::any_null_pointers(crl_obj)) {
1116 }
1117#if defined(BOTAN_HAS_X509_CERTIFICATES)
1118 return ffi_guard_thunk(__func__, [=]() -> int {
1119 auto& rng_ = safe_get(rng);
1120 auto ca = Botan::X509_CA(
1121 safe_get(ca_cert), safe_get(ca_key), default_from_ptr(hash_fn), default_from_ptr(padding), rng_);
1122 auto crl = std::make_unique<Botan::X509_CRL>(
1123 ca.new_crl(rng_, timepoint_from_timestamp(issue_time), std::chrono::seconds(next_update)));
1124 return ffi_new_object(crl_obj, std::move(crl));
1125 });
1126#else
1127 BOTAN_UNUSED(rng, ca_cert, ca_key, hash_fn, padding, issue_time, next_update);
1129#endif
1130}

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), and Botan_FFI::safe_get().

◆ botan_x509_crl_destroy()

int botan_x509_crl_destroy ( botan_x509_crl_t crl)

Frees all resources of the CRL object

Parameters
crlthe CRL to destroy
Returns
0 if success, error if invalid object handle

Definition at line 1196 of file ffi_cert.cpp.

1196 {
1197#if defined(BOTAN_HAS_X509_CERTIFICATES)
1198 return BOTAN_FFI_CHECKED_DELETE(crl);
1199#else
1200 BOTAN_UNUSED(crl);
1202#endif
1203}

References BOTAN_FFI_CHECKED_DELETE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, and BOTAN_UNUSED.

◆ botan_x509_crl_entries()

int botan_x509_crl_entries ( botan_x509_crl_t crl,
size_t index,
botan_x509_crl_entry_t * entry )

Allows iterating all entries of the CRL.

Parameters
crlthe CRL whose entries should be listed
indexthe index of the CRL entry to return
entryan object handle containing the CRL entry data
Returns
BOTAN_FFI_ERROR_OUT_OF_RANGE if the given index is out of range of the CRL entry list.

Definition at line 1333 of file ffi_cert.cpp.

1333 {
1334#if defined(BOTAN_HAS_X509_CERTIFICATES)
1335 return BOTAN_FFI_VISIT(crl, [=](const Botan::X509_CRL& c) -> int {
1336 const auto& entries = c.get_revoked();
1337 if(index >= entries.size()) {
1339 }
1340
1341 if(Botan::any_null_pointers(entry)) {
1343 }
1344
1345 return ffi_new_object(entry, std::make_unique<Botan::CRL_Entry>(entries[index]));
1346 });
1347#else
1348 BOTAN_UNUSED(crl, index, entry);
1350#endif
1351}
const std::vector< CRL_Entry > & get_revoked() const
Definition x509_crl.cpp:260

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_ERROR_OUT_OF_RANGE, BOTAN_FFI_VISIT, BOTAN_UNUSED, Botan_FFI::ffi_new_object(), and Botan::X509_CRL::get_revoked().

◆ botan_x509_crl_entries_count()

int botan_x509_crl_entries_count ( botan_x509_crl_t crl,
size_t * count )

Count the entries of the CRL.

Parameters
crlthe CRL whose entries should be counted
countset to the number of available entries
Returns
0 on success, a negative value on failure

Definition at line 1353 of file ffi_cert.cpp.

1353 {
1354#if defined(BOTAN_HAS_X509_CERTIFICATES)
1355 if(Botan::any_null_pointers(count)) {
1357 }
1358
1359 return BOTAN_FFI_VISIT(crl, [=](const Botan::X509_CRL& c) { *count = c.get_revoked().size(); });
1360#else
1361 BOTAN_UNUSED(crl, count);
1363#endif
1364}

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, BOTAN_UNUSED, and Botan::X509_CRL::get_revoked().

◆ botan_x509_crl_entry_create()

int botan_x509_crl_entry_create ( botan_x509_crl_entry_t * entry,
botan_x509_cert_t cert,
int reason_code )

Create a new CRL entry that marks cert as revoked

Parameters
entryThe newly created CRL entry
certThe certificate to mark as revoked
reason_codeThe reason code for revocation

Definition at line 1132 of file ffi_cert.cpp.

1132 {
1133 if(Botan::any_null_pointers(entry)) {
1135 }
1136#if defined(BOTAN_HAS_X509_CERTIFICATES)
1137 return ffi_guard_thunk(__func__, [=]() -> int {
1138 return ffi_new_object(
1139 entry, std::make_unique<Botan::CRL_Entry>(safe_get(cert), static_cast<Botan::CRL_Code>(reason_code)));
1140 });
1141#else
1142 BOTAN_UNUSED(cert, reason_code);
1144#endif
1145}

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), and Botan_FFI::safe_get().

◆ botan_x509_crl_entry_destroy()

int botan_x509_crl_entry_destroy ( botan_x509_crl_entry_t entry)

Frees all resources of the CRL entry object

Parameters
entrythe CRL entry to destroy
Returns
0 if success, error if invalid object handle

Definition at line 1366 of file ffi_cert.cpp.

1366 {
1367#if defined(BOTAN_HAS_X509_CERTIFICATES)
1368 return BOTAN_FFI_CHECKED_DELETE(entry);
1369#else
1370 BOTAN_UNUSED(entry);
1372#endif
1373}

References BOTAN_FFI_CHECKED_DELETE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, and BOTAN_UNUSED.

◆ botan_x509_crl_entry_reason()

int botan_x509_crl_entry_reason ( botan_x509_crl_entry_t entry,
int * reason_code )

Return the revocation reason code for the given CRL entry. See botan_x509_crl_reason_code and RFC 5280 - 5.3.1 for possible reason codes.

Definition at line 1375 of file ffi_cert.cpp.

1375 {
1376#if defined(BOTAN_HAS_X509_CERTIFICATES)
1377 return BOTAN_FFI_VISIT(entry, [=](const Botan::CRL_Entry& e) {
1378 if(Botan::any_null_pointers(reason_code)) {
1380 }
1381
1382 *reason_code = static_cast<int>(e.reason_code());
1383 return BOTAN_FFI_SUCCESS;
1384 });
1385#else
1386 BOTAN_UNUSED(entry, reason_code);
1388#endif
1389}
Definition x509_crl.h:32
CRL_Code reason_code() const
Definition crl_ent.cpp:149

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_FFI_VISIT, BOTAN_UNUSED, and Botan::CRL_Entry::reason_code().

◆ botan_x509_crl_entry_revocation_date()

int botan_x509_crl_entry_revocation_date ( botan_x509_crl_entry_t entry,
uint64_t * time_since_epoch )

Return the revocation date for the given CRL entry as time since epoch in seconds.

Definition at line 1417 of file ffi_cert.cpp.

1417 {
1418#if defined(BOTAN_HAS_X509_CERTIFICATES)
1419 return BOTAN_FFI_VISIT(entry, [=](const Botan::CRL_Entry& e) {
1420 if(Botan::any_null_pointers(time_since_epoch)) {
1422 }
1423
1424 *time_since_epoch = e.expire_time().time_since_epoch();
1425 return BOTAN_FFI_SUCCESS;
1426 });
1427#else
1428 BOTAN_UNUSED(entry, time_since_epoch);
1430#endif
1431}
uint64_t time_since_epoch() const
Return time since epoch.
const X509_Time & expire_time() const
Definition crl_ent.cpp:145

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_FFI_VISIT, BOTAN_UNUSED, Botan::CRL_Entry::expire_time(), and Botan::ASN1_Time::time_since_epoch().

◆ botan_x509_crl_entry_serial_number()

int botan_x509_crl_entry_serial_number ( botan_x509_crl_entry_t entry,
botan_mp_t * serial_number )

Return the serial number associated with the given CRL entry.

Definition at line 1391 of file ffi_cert.cpp.

1391 {
1392#if defined(BOTAN_HAS_X509_CERTIFICATES)
1393 return BOTAN_FFI_VISIT(entry, [=](const Botan::CRL_Entry& e) {
1394 if(Botan::any_null_pointers(serial_number)) {
1396 }
1397
1398 auto serial_bn = e.serial().to_bigint();
1399 return ffi_new_object(serial_number, std::make_unique<Botan::BigInt>(std::move(serial_bn)));
1400 });
1401#else
1402 BOTAN_UNUSED(entry, serial_number);
1404#endif
1405}
const X509_Serial_Number & serial() const
Definition crl_ent.cpp:141

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, BOTAN_UNUSED, Botan_FFI::ffi_new_object(), Botan::CRL_Entry::serial(), and Botan::X509_Serial_Number::to_bigint().

◆ botan_x509_crl_entry_view_serial_number()

int botan_x509_crl_entry_view_serial_number ( botan_x509_crl_entry_t entry,
botan_view_ctx ctx,
botan_view_bin_fn view )

View the serial number associated with the given CRL entry.

Definition at line 1407 of file ffi_cert.cpp.

1407 {
1408#if defined(BOTAN_HAS_X509_CERTIFICATES)
1409 return BOTAN_FFI_VISIT(
1410 entry, [=](const Botan::CRL_Entry& e) { return invoke_view_callback(view, ctx, e.serial_number()); });
1411#else
1412 BOTAN_UNUSED(entry, ctx, view);
1414#endif
1415}
const std::vector< uint8_t > & serial_number() const
Definition crl_ent.cpp:137

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_VISIT, BOTAN_UNUSED, Botan_FFI::invoke_view_callback(), and Botan::CRL_Entry::serial_number().

◆ botan_x509_crl_load()

int botan_x509_crl_load ( botan_x509_crl_t * crl_obj,
const uint8_t crl_bits[],
size_t crl_bits_len )

Load a CRL from a DER or PEM encoding

Parameters
crl_objthe new object will be placed here
crl_bitsthe encoding to load
crl_bits_lenlength of crl_bits in bytes
Returns
0 on success, a negative value on failure

Definition at line 1053 of file ffi_cert.cpp.

1053 {
1054 if(Botan::any_null_pointers(crl_obj, crl_bits)) {
1056 }
1057
1058#if defined(BOTAN_HAS_X509_CERTIFICATES)
1059 return ffi_guard_thunk(__func__, [=]() -> int {
1060 Botan::DataSource_Memory bits(crl_bits, crl_bits_len);
1061 auto c = std::make_unique<Botan::X509_CRL>(bits);
1062 return ffi_new_object(crl_obj, std::move(c));
1063 });
1064#else
1065 BOTAN_UNUSED(crl_bits_len);
1067#endif
1068}

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), and Botan_FFI::ffi_new_object().

◆ botan_x509_crl_load_file()

int botan_x509_crl_load_file ( botan_x509_crl_t * crl_obj,
const char * crl_path )

Load a CRL from a file containing a DER or PEM encoding

Parameters
crl_objthe new object will be placed here
crl_pathpath of the file to read
Returns
0 on success, a negative value on failure

Definition at line 1036 of file ffi_cert.cpp.

1036 {
1037 if(Botan::any_null_pointers(crl_obj, crl_path)) {
1039 }
1040
1041#if defined(BOTAN_HAS_X509_CERTIFICATES) && defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
1042
1043 return ffi_guard_thunk(__func__, [=]() -> int {
1044 auto c = std::make_unique<Botan::X509_CRL>(crl_path);
1045 return ffi_new_object(crl_obj, std::move(c));
1046 });
1047
1048#else
1050#endif
1051}

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, Botan_FFI::ffi_guard_thunk(), and Botan_FFI::ffi_new_object().

◆ botan_x509_crl_next_update()

int botan_x509_crl_next_update ( botan_x509_crl_t crl,
uint64_t * time_since_epoch )

Get the nextUpdate field of the CRL as seconds since the Unix epoch

Parameters
crlthe CRL to inspect
time_since_epochset to the nextUpdate time
Returns
0 on success, or BOTAN_FFI_ERROR_NO_VALUE if the field is absent

Definition at line 1085 of file ffi_cert.cpp.

1085 {
1086#if defined(BOTAN_HAS_X509_CERTIFICATES)
1087 return BOTAN_FFI_VISIT(crl, [=](const auto& c) {
1088 const auto& time = c.next_update();
1089 if(!time.time_is_set()) {
1091 }
1092
1093 if(Botan::any_null_pointers(time_since_epoch)) {
1095 }
1096
1097 *time_since_epoch = c.next_update().time_since_epoch();
1098 return BOTAN_FFI_SUCCESS;
1099 });
1100#else
1101 BOTAN_UNUSED(crl, time_since_epoch);
1103#endif
1104}

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NO_VALUE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_FFI_VISIT, and BOTAN_UNUSED.

◆ botan_x509_crl_this_update()

int botan_x509_crl_this_update ( botan_x509_crl_t crl,
uint64_t * time_since_epoch )

Get the thisUpdate field of the CRL as seconds since the Unix epoch

Parameters
crlthe CRL to inspect
time_since_epochset to the thisUpdate time
Returns
0 on success, a negative value on failure

Definition at line 1070 of file ffi_cert.cpp.

1070 {
1071#if defined(BOTAN_HAS_X509_CERTIFICATES)
1072 return BOTAN_FFI_VISIT(crl, [=](const auto& c) {
1073 if(Botan::any_null_pointers(time_since_epoch)) {
1075 }
1076 *time_since_epoch = c.this_update().time_since_epoch();
1077 return BOTAN_FFI_SUCCESS;
1078 });
1079#else
1080 BOTAN_UNUSED(crl, time_since_epoch);
1082#endif
1083}

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_FFI_VISIT, and BOTAN_UNUSED.

◆ botan_x509_crl_update()

int botan_x509_crl_update ( botan_x509_crl_t * crl_obj,
botan_x509_crl_t last_crl,
botan_rng_t rng,
botan_x509_cert_t ca_cert,
botan_privkey_t ca_key,
uint64_t issue_time,
uint32_t next_update,
const botan_x509_crl_entry_t * new_entries,
size_t new_entries_len,
const char * hash_fn,
const char * padding )

Update a CRL with new revoked entries. This does not modify the old crl, and instead creates a new one.

Parameters
crl_objThe newly created CRL
last_crlThe CRL to update
Random Number Generatorsa random number generator object
ca_certThe CA Certificate the CRL belongs to
ca_keyThe private key of that CA
issue_timeThe time when the CRL becomes valid
next_updateThe number of seconds after issue_time until the CRL expires
new_entriesThe entries to add to the CRL
new_entries_lenThe number of entries
hash_fnThe hash function to use, may be null
paddingThe padding to use, may be null

Definition at line 1147 of file ffi_cert.cpp.

1157 {
1158 if(Botan::any_null_pointers(crl_obj)) {
1160 }
1161 if(new_entries_len > 0 && Botan::any_null_pointers(new_entries)) {
1163 }
1164#if defined(BOTAN_HAS_X509_CERTIFICATES)
1165 return ffi_guard_thunk(__func__, [=]() -> int {
1166 auto& rng_ = safe_get(rng);
1167 auto ca = Botan::X509_CA(
1168 safe_get(ca_cert), safe_get(ca_key), default_from_ptr(hash_fn), default_from_ptr(padding), rng_);
1169
1170 std::vector<Botan::CRL_Entry> entries;
1171 entries.reserve(new_entries_len);
1172 for(size_t i = 0; i < new_entries_len; i++) {
1173 entries.push_back(safe_get(new_entries[i]));
1174 }
1175
1176 auto crl = std::make_unique<Botan::X509_CRL>(ca.update_crl(
1177 safe_get(last_crl), entries, rng_, timepoint_from_timestamp(issue_time), std::chrono::seconds(next_update)));
1178 return ffi_new_object(crl_obj, std::move(crl));
1179 });
1180#else
1182 last_crl, rng, ca_cert, ca_key, hash_fn, padding, issue_time, next_update, new_entries, new_entries_len);
1184#endif
1185}

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), and Botan_FFI::safe_get().

◆ botan_x509_crl_verify_signature()

int botan_x509_crl_verify_signature ( botan_x509_crl_t crl,
botan_pubkey_t key )

Check the signature on a CRL against the issuer's public key

Parameters
crlthe CRL to verify
keythe public key of the issuing CA
Returns
1 if the signature is valid, 0 if it is not, negative on error

Definition at line 1187 of file ffi_cert.cpp.

1187 {
1188#if defined(BOTAN_HAS_X509_CERTIFICATES)
1189 return BOTAN_FFI_VISIT(crl, [=](const auto& c) -> int { return c.check_signature(safe_get(key)) ? 1 : 0; });
1190#else
1191 BOTAN_UNUSED(crl, key);
1193#endif
1194}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_VISIT, BOTAN_UNUSED, and Botan_FFI::safe_get().

◆ botan_x509_crl_view_binary_values()

int botan_x509_crl_view_binary_values ( botan_x509_crl_t crl_obj,
botan_x509_value_type value_type,
size_t index,
botan_view_ctx ctx,
botan_view_bin_fn view )

Retrieve a specific binary value from an X.509 certificate revocation list.

For multi-values index allows enumerating the available entries, until BOTAN_FFI_ERROR_OUT_OF_RANGE is returned. For singleton values, an index of value "0" is expected.

Returns
BOTAN_FFI_ERROR_NO_VALUE if the provided crl_obj does not provide the requested value_type at all or not in binary format.

Definition at line 1205 of file ffi_cert.cpp.

1209 {
1210#if defined(BOTAN_HAS_X509_CERTIFICATES)
1211 if(index != 0) {
1212 // As of now there are no multi-value binary entries.
1214 }
1215
1216 auto view = [=](std::span<const uint8_t> value) -> int {
1217 if(value.empty()) {
1219 } else {
1220 return invoke_view_callback(view_fn, ctx, value);
1221 }
1222 };
1223
1224 return BOTAN_FFI_VISIT(crl_obj, [=](const Botan::X509_CRL& crl) -> int {
1225 switch(value_type) {
1227 if(const auto& crln = crl.crl_number_bigint()) {
1228 // Previously CRL number was a fixed 4 byte value, continue this for small CRL numbers
1229 const size_t view_bytes = std::min<size_t>(crln->bytes(), 4);
1230 return view(crln->serialize<std::vector<uint8_t>>(view_bytes));
1231 } else {
1233 }
1234 }
1236 return view(Botan::ASN1::put_in_sequence(crl.issuer_dn().get_bits()));
1238 return view(crl.authority_key_id());
1239
1244 return botan_x509_object_view_value(crl, value_type, index, ctx, view_fn);
1245
1254 }
1255
1257 });
1258#else
1259 BOTAN_UNUSED(crl_obj, value_type, index, ctx, view_fn);
1261#endif
1262}
const std::vector< uint8_t > & authority_key_id() const
Definition x509_crl.cpp:282
const X509_DN & issuer_dn() const
Definition x509_crl.cpp:275
const std::optional< BigInt > & crl_number_bigint() const
Definition x509_crl.cpp:289
const std::vector< uint8_t > & get_bits() const
Definition pkix_types.h:198
std::vector< uint8_t > put_in_sequence(const std::vector< uint8_t > &contents)
Definition asn1_obj.cpp:208

References Botan::X509_CRL::authority_key_id(), BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NO_VALUE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_OUT_OF_RANGE, BOTAN_FFI_VISIT, BOTAN_UNUSED, BOTAN_X509_AUTHORITY_KEY_IDENTIFIER, BOTAN_X509_CA_ISSUERS_URLS, BOTAN_X509_CRL_DISTRIBUTION_URLS, BOTAN_X509_DER_ENCODING, BOTAN_X509_ISSUER_DN_BITS, BOTAN_X509_OCSP_RESPONDER_URLS, BOTAN_X509_PEM_ENCODING, BOTAN_X509_PUBLIC_KEY_PKCS8_BITS, BOTAN_X509_SERIAL_NUMBER, BOTAN_X509_SIGNATURE_BITS, BOTAN_X509_SIGNATURE_SCHEME_BITS, BOTAN_X509_SUBJECT_DN_BITS, BOTAN_X509_SUBJECT_KEY_IDENTIFIER, BOTAN_X509_TBS_DATA_BITS, Botan::X509_CRL::crl_number_bigint(), Botan::X509_DN::get_bits(), Botan_FFI::invoke_view_callback(), Botan::X509_CRL::issuer_dn(), and Botan::ASN1::put_in_sequence().

Referenced by botan_x509_crl_view_binary_values_count().

◆ botan_x509_crl_view_binary_values_count()

int botan_x509_crl_view_binary_values_count ( botan_x509_crl_t crl_obj,
botan_x509_value_type value_type,
size_t * count )

Count the binary values of the given type available in a CRL.

Parameters
crl_objthe CRL to inspect
value_typethe value type to count
countset to the number of available entries
Returns
0 on success, a negative value on failure

Definition at line 1264 of file ffi_cert.cpp.

1264 {
1265#if defined(BOTAN_HAS_X509_CERTIFICATES)
1266 return enumerator_count_values(count, [=](size_t index) {
1268 crl_obj, value_type, index, nullptr, [](auto, auto, auto) -> int { return BOTAN_FFI_SUCCESS; });
1269 });
1270#else
1271 BOTAN_UNUSED(crl_obj, value_type, count);
1273#endif
1274}
int botan_x509_crl_view_binary_values(botan_x509_crl_t crl_obj, botan_x509_value_type value_type, size_t index, botan_view_ctx ctx, botan_view_bin_fn view_fn)

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, and botan_x509_crl_view_binary_values().

◆ botan_x509_crl_view_string_values()

int botan_x509_crl_view_string_values ( botan_x509_crl_t crl_obj,
botan_x509_value_type value_type,
size_t index,
botan_view_ctx ctx,
botan_view_str_fn view )

Retrieve a specific string value from an X.509 certificate revocation list.

For multi-values index allows enumerating the available entries, until BOTAN_FFI_ERROR_OUT_OF_RANGE is returned. For singleton values, an index of value "0" is expected.

Returns
BOTAN_FFI_ERROR_NO_VALUE if the provided crl_obj does not provide the requested value_type at all or not in string format.

Definition at line 1276 of file ffi_cert.cpp.

1280 {
1281#if defined(BOTAN_HAS_X509_CERTIFICATES)
1282 return BOTAN_FFI_VISIT(crl_obj, [=](const Botan::X509_CRL& crl) -> int {
1283 switch(value_type) {
1285 return botan_x509_object_view_value(crl, value_type, index, ctx, view);
1286
1301 }
1302
1304 });
1305#else
1306 BOTAN_UNUSED(crl_obj, value_type, index, ctx, view);
1308#endif
1309}

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NO_VALUE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_VISIT, BOTAN_UNUSED, BOTAN_X509_AUTHORITY_KEY_IDENTIFIER, BOTAN_X509_CA_ISSUERS_URLS, BOTAN_X509_CRL_DISTRIBUTION_URLS, BOTAN_X509_DER_ENCODING, BOTAN_X509_ISSUER_DN_BITS, BOTAN_X509_OCSP_RESPONDER_URLS, BOTAN_X509_PEM_ENCODING, BOTAN_X509_PUBLIC_KEY_PKCS8_BITS, BOTAN_X509_SERIAL_NUMBER, BOTAN_X509_SIGNATURE_BITS, BOTAN_X509_SIGNATURE_SCHEME_BITS, BOTAN_X509_SUBJECT_DN_BITS, BOTAN_X509_SUBJECT_KEY_IDENTIFIER, and BOTAN_X509_TBS_DATA_BITS.

Referenced by botan_x509_crl_view_string_values_count().

◆ botan_x509_crl_view_string_values_count()

int botan_x509_crl_view_string_values_count ( botan_x509_crl_t crl_obj,
botan_x509_value_type value_type,
size_t * count )

Count the string values of the given type available in a CRL.

Parameters
crl_objthe CRL to inspect
value_typethe value type to count
countset to the number of available entries
Returns
0 on success, a negative value on failure

Definition at line 1311 of file ffi_cert.cpp.

1311 {
1312#if defined(BOTAN_HAS_X509_CERTIFICATES)
1313 return enumerator_count_values(count, [=](size_t index) {
1315 crl_obj, value_type, index, nullptr, [](auto, auto, auto) -> int { return BOTAN_FFI_SUCCESS; });
1316 });
1317#else
1318 BOTAN_UNUSED(crl_obj, value_type, count);
1320#endif
1321}
int botan_x509_crl_view_string_values(botan_x509_crl_t crl_obj, botan_x509_value_type value_type, size_t index, botan_view_ctx ctx, botan_view_str_fn view)

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, and botan_x509_crl_view_string_values().

◆ botan_x509_general_name_destroy()

int botan_x509_general_name_destroy ( botan_x509_general_name_t alt_names)

Frees all resources of the GeneralName object

Parameters
alt_namesthe GeneralName to destroy
Returns
0 if success, error if invalid object handle

Definition at line 779 of file ffi_cert.cpp.

779 {
780#if defined(BOTAN_HAS_X509_CERTIFICATES)
781 return BOTAN_FFI_CHECKED_DELETE(name);
782#else
783 BOTAN_UNUSED(name);
785#endif
786}

References BOTAN_FFI_CHECKED_DELETE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, and BOTAN_UNUSED.

◆ botan_x509_general_name_get_type()

int botan_x509_general_name_get_type ( botan_x509_general_name_t name,
unsigned int * type )

Provides the contained type of the name and returns BOTAN_FFI_SUCCESS if that type is supported and may be retrieved via the view functions below. Otherwise BOTAN_FFI_ERROR_INVALID_OBJECT_STATE is returned.

Definition at line 709 of file ffi_cert.cpp.

709 {
710#if defined(BOTAN_HAS_X509_CERTIFICATES)
711 return BOTAN_FFI_VISIT(name, [=](const Botan::GeneralName& n) {
712 if(Botan::any_null_pointers(type)) {
714 }
715
716 const auto mapped_type = to_botan_x509_general_name_types(n.type_code());
717 if(!mapped_type.has_value()) {
719 }
720
721 *type = mapped_type.value();
722 if(*type == BOTAN_X509_OTHER_NAME /* ... viewing of other-names not supported */) {
724 }
725
726 return BOTAN_FFI_SUCCESS;
727 });
728#else
729 BOTAN_UNUSED(name, type);
731#endif
732}
X.509 GeneralName Type.
Definition pkix_types.h:543
NameType type_code() const
Definition pkix_types.h:596
@ BOTAN_X509_OTHER_NAME
Definition ffi.h:3852
@ BOTAN_FFI_ERROR_INVALID_OBJECT_STATE
Definition ffi.h:135

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_INVALID_OBJECT_STATE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_FFI_VISIT, BOTAN_UNUSED, BOTAN_X509_OTHER_NAME, and Botan::GeneralName::type_code().

◆ botan_x509_general_name_view_binary_value()

int botan_x509_general_name_view_binary_value ( botan_x509_general_name_t name,
botan_view_ctx ctx,
botan_view_bin_fn view )

Views the name as a bit string or returns BOTAN_FFI_ERROR_INVALID_OBJECT_STATE if the contained GeneralName value cannot be represented as a binary string.

The types BOTAN_X509_DIRECTORY_NAME, BOTAN_X509_IP_ADDRESS may be viewed as "binary".

Definition at line 757 of file ffi_cert.cpp.

759 {
760#if defined(BOTAN_HAS_X509_CERTIFICATES)
761 return BOTAN_FFI_VISIT(name, [=](const Botan::GeneralName& n) -> int {
762 const auto type = to_botan_x509_general_name_types(n.type_code());
763 if(!type) {
765 }
766
767 if(type != BOTAN_X509_DIRECTORY_NAME && type != BOTAN_X509_IP_ADDRESS) {
769 }
770
771 return invoke_view_callback(view, ctx, n.binary_name());
772 });
773#else
774 BOTAN_UNUSED(name, ctx, view);
776#endif
777}
std::vector< uint8_t > binary_name() const
@ BOTAN_X509_DIRECTORY_NAME
Definition ffi.h:3855
@ BOTAN_X509_IP_ADDRESS
Definition ffi.h:3857

References Botan::GeneralName::binary_name(), BOTAN_FFI_ERROR_INVALID_OBJECT_STATE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_VISIT, BOTAN_UNUSED, BOTAN_X509_DIRECTORY_NAME, BOTAN_X509_IP_ADDRESS, Botan_FFI::invoke_view_callback(), and Botan::GeneralName::type_code().

◆ botan_x509_general_name_view_string_value()

int botan_x509_general_name_view_string_value ( botan_x509_general_name_t name,
botan_view_ctx ctx,
botan_view_str_fn view )

Views the name as a string or returns BOTAN_FFI_ERROR_INVALID_OBJECT_STATE if the contained GeneralName value cannot be represented as a string.

The types BOTAN_X509_EMAIL_ADDRESS, BOTAN_X509_DNS_NAME, BOTAN_X509_URI, BOTAN_X509_IP_ADDRESS may be viewed as "string".

Definition at line 734 of file ffi_cert.cpp.

736 {
737#if defined(BOTAN_HAS_X509_CERTIFICATES)
738 return BOTAN_FFI_VISIT(name, [=](const Botan::GeneralName& n) -> int {
739 const auto type = to_botan_x509_general_name_types(n.type_code());
740 if(!type) {
742 }
743
744 if(type != BOTAN_X509_EMAIL_ADDRESS && type != BOTAN_X509_DNS_NAME && type != BOTAN_X509_URI &&
745 type != BOTAN_X509_IP_ADDRESS) {
747 }
748
749 return invoke_view_callback(view, ctx, n.name());
750 });
751#else
752 BOTAN_UNUSED(name, ctx, view);
754#endif
755}
std::string name() const
@ BOTAN_X509_DNS_NAME
Definition ffi.h:3854
@ BOTAN_X509_EMAIL_ADDRESS
Definition ffi.h:3853
@ BOTAN_X509_URI
Definition ffi.h:3856

References BOTAN_FFI_ERROR_INVALID_OBJECT_STATE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_VISIT, BOTAN_UNUSED, BOTAN_X509_DNS_NAME, BOTAN_X509_EMAIL_ADDRESS, BOTAN_X509_IP_ADDRESS, BOTAN_X509_URI, Botan_FFI::invoke_view_callback(), Botan::GeneralName::name(), and Botan::GeneralName::type_code().

◆ botan_x509_is_revoked()

int botan_x509_is_revoked ( botan_x509_crl_t crl,
botan_x509_cert_t cert )

Given a CRL and a certificate, check if the certificate is revoked on that particular CRL

Definition at line 1323 of file ffi_cert.cpp.

1323 {
1324#if defined(BOTAN_HAS_X509_CERTIFICATES)
1325 return BOTAN_FFI_VISIT(crl, [=](const auto& c) { return c.is_revoked(safe_get(cert)) ? 0 : -1; });
1326#else
1327 BOTAN_UNUSED(cert);
1328 BOTAN_UNUSED(crl);
1330#endif
1331}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_VISIT, BOTAN_UNUSED, and Botan_FFI::safe_get().