Botan 3.14.1
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_issuer_dn (botan_x509_crl_t crl, const char *key, size_t index, botan_view_ctx ctx, botan_view_str_fn view)
int botan_x509_crl_view_issuer_dn_count (botan_x509_crl_t crl, const char *key, 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 572 of file ffi_cert.cpp.

572 {
573#if defined(BOTAN_HAS_X509_CERTIFICATES)
574 return BOTAN_FFI_VISIT(cert, [=](const auto& c) -> int { return c.has_ex_constraint(safe_get(oid)) ? 1 : 0; });
575#else
576 BOTAN_UNUSED(cert, oid);
578#endif
579}
#define BOTAN_UNUSED
Definition assert.h:151
@ BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition ffi.h:138
#define BOTAN_FFI_VISIT(obj, lambda)
Definition ffi_util.h:327
auto safe_get(T *p) -> typename T::element_type &
Definition ffi_util.h:191

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 557 of file ffi_cert.cpp.

557 {
558#if defined(BOTAN_HAS_X509_CERTIFICATES)
559 return BOTAN_FFI_VISIT(cert, [=](const auto& c) -> int {
560 if(Botan::any_null_pointers(oid)) {
562 }
563
564 return c.has_ex_constraint(oid) ? 1 : 0;
565 });
566#else
567 BOTAN_UNUSED(cert, oid);
569#endif
570}
@ 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 542 of file ffi_cert.cpp.

542 {
543#if defined(BOTAN_HAS_X509_CERTIFICATES)
544 return BOTAN_FFI_VISIT(cert, [=](const auto& c) -> int {
545 const Botan::Key_Constraints k = static_cast<Botan::Key_Constraints>(key_usage);
546 if(c.allowed_usage(k)) {
547 return BOTAN_FFI_SUCCESS;
548 }
549 return 1;
550 });
551#else
552 BOTAN_UNUSED(cert, key_usage);
554#endif
555}
@ 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 581 of file ffi_cert.cpp.

581 {
582#if defined(BOTAN_HAS_X509_CERTIFICATES)
583 return BOTAN_FFI_CHECKED_DELETE(cert);
584#else
585 BOTAN_UNUSED(cert);
587#endif
588}
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition ffi_util.h:357

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 192 of file ffi_cert.cpp.

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

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 821 of file ffi_cert.cpp.

823 {
824#if defined(BOTAN_HAS_X509_CERTIFICATES)
825 return BOTAN_FFI_VISIT(cert, [=](const Botan::X509_Certificate& c) {
826 if(Botan::any_null_pointers(constraint)) {
828 }
829
830 const auto& constraints = c.name_constraints().excluded();
831 if(index >= constraints.size()) {
833 }
834
835 return ffi_new_object(constraint, std::make_unique<Botan::GeneralName>(constraints[index].base()));
836 });
837#else
838 BOTAN_UNUSED(cert, index, constraint);
840#endif
841}
const std::vector< GeneralSubtree > & excluded() const
Definition pkix_types.h:773
const NameConstraints & name_constraints() const
Definition x509cert.cpp:513
@ 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 843 of file ffi_cert.cpp.

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

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 675 of file ffi_cert.cpp.

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

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 659 of file ffi_cert.cpp.

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

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 455 of file ffi_cert.cpp.

456 {
457 if(key == nullptr) {
459 }
460#if defined(BOTAN_HAS_X509_CERTIFICATES)
461 return BOTAN_FFI_VISIT(cert, [=](const auto& c) -> int {
462 const auto issuer_info = c.issuer_info(key);
463 if(index < issuer_info.size()) {
464 // TODO(Botan4) change the type of out and remove this cast
465 return write_str_output(reinterpret_cast<char*>(out), out_len, c.issuer_info(key).at(index));
466 } else {
467 return BOTAN_FFI_ERROR_BAD_PARAMETER; // TODO(Botan4): use BOTAN_FFI_ERROR_OUT_OF_RANGE
468 }
469 });
470#else
471 BOTAN_UNUSED(cert, key, index, out, out_len);
473#endif
474}
@ 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 476 of file ffi_cert.cpp.

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

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 417 of file ffi_cert.cpp.

417 {
418#if defined(BOTAN_HAS_X509_CERTIFICATES)
419 return BOTAN_FFI_VISIT(cert, [=](const auto& c) -> int {
420 if(Botan::any_null_pointers(path_limit)) {
422 }
423
424 if(const auto path_len = c.path_length_constraint()) {
425 *path_limit = path_len.value();
426 return BOTAN_FFI_SUCCESS;
427 } else {
429 }
430 });
431#else
432 BOTAN_UNUSED(cert, path_limit);
434#endif
435}
@ 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 437 of file ffi_cert.cpp.

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

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 693 of file ffi_cert.cpp.

693 {
694 return copy_view_bin(out, out_len, botan_x509_cert_view_public_key_bits, cert);
695}
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:697
int copy_view_bin(uint8_t out[], size_t *out_len, Fn fn, Args... args)
Definition ffi_util.h:383

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 634 of file ffi_cert.cpp.

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

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 492 of file ffi_cert.cpp.

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

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 513 of file ffi_cert.cpp.

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

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 684 of file ffi_cert.cpp.

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

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 600 of file ffi_cert.cpp.

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

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 590 of file ffi_cert.cpp.

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

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 934 of file ffi_cert.cpp.

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

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 408 of file ffi_cert.cpp.

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

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 895 of file ffi_cert.cpp.

897 {
898#if defined(BOTAN_HAS_X509_CERTIFICATES)
899 return BOTAN_FFI_VISIT(cert, [=](const Botan::X509_Certificate& c) {
900 if(Botan::any_null_pointers(alt_name)) {
902 }
903
904 if(!c.v3_extensions().extension_set(Botan::OID::from_string("X509v3.IssuerAlternativeName"))) {
906 }
907
908 if(auto name = extract_general_name_at(c.issuer_alt_name(), index)) {
909 return ffi_new_object(alt_name, std::make_unique<Botan::GeneralName>(std::move(name).value()));
910 }
911
913 });
914#else
915 BOTAN_UNUSED(cert, index, alt_name);
917#endif
918}
bool extension_set(const OID &oid) const
Definition x509_ext.cpp:225
static OID from_string(std::string_view str)
Definition asn1_oid.cpp:80
const AlternativeName & issuer_alt_name() const
Definition x509cert.cpp:690
const Extensions & v3_extensions() const
Definition x509cert.cpp:517
const char * name
Definition ffi_tls.h:59

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(), 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 920 of file ffi_cert.cpp.

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

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 210 of file ffi_cert.cpp.

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

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 175 of file ffi_cert.cpp.

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

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 622 of file ffi_cert.cpp.

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

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 610 of file ffi_cert.cpp.

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

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 786 of file ffi_cert.cpp.

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

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 808 of file ffi_cert.cpp.

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

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 643 of file ffi_cert.cpp.

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

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 856 of file ffi_cert.cpp.

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

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(), name, 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 881 of file ffi_cert.cpp.

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

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 529 of file ffi_cert.cpp.

529 {
530 return copy_view_str(reinterpret_cast<uint8_t*>(out), out_len, botan_x509_cert_view_as_string, cert);
531}
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:533
int copy_view_str(uint8_t out[], size_t *out_len, Fn fn, Args... args)
Definition ffi_util.h:392

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 1021 of file ffi_cert.cpp.

1021 {
1022 if(code < 0) {
1023 return nullptr;
1024 }
1025
1026#if defined(BOTAN_HAS_X509_CERTIFICATES)
1028 return Botan::to_string(sc);
1029#else
1030 return nullptr;
1031#endif
1032}
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 947 of file ffi_cert.cpp.

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

1480 {
1481 if(required_strength == 0) {
1482 required_strength = 110;
1483 }
1484
1485#if defined(BOTAN_HAS_X509_CERTIFICATES)
1486 return ffi_guard_thunk(__func__, [=]() -> int {
1487 const std::string hostname((hostname_cstr == nullptr) ? "" : hostname_cstr);
1489 const auto validation_time = reference_time == 0
1490 ? std::chrono::system_clock::now()
1491 : std::chrono::system_clock::from_time_t(static_cast<time_t>(reference_time));
1492
1493 if(intermediates_len > 0 && intermediates == nullptr) {
1495 }
1496 if(trusted_len > 0 && trusted == nullptr) {
1498 }
1499 if(crls_len > 0 && crls == nullptr) {
1501 }
1502
1503 std::vector<Botan::X509_Certificate> end_certs;
1504 end_certs.push_back(safe_get(cert));
1505 for(size_t i = 0; i != intermediates_len; ++i) {
1506 end_certs.push_back(safe_get(intermediates[i]));
1507 }
1508
1509 std::unique_ptr<Botan::Certificate_Store> trusted_from_path;
1510 std::unique_ptr<Botan::Certificate_Store_In_Memory> trusted_extra;
1511 std::unique_ptr<Botan::Certificate_Store_In_Memory> trusted_crls;
1512 std::vector<Botan::Certificate_Store*> trusted_roots;
1513
1514 if(trusted_path != nullptr && *trusted_path != 0) {
1515 trusted_from_path = std::make_unique<Botan::Certificate_Store_In_Memory>(trusted_path);
1516 trusted_roots.push_back(trusted_from_path.get());
1517 }
1518
1519 if(trusted_len > 0) {
1520 trusted_extra = std::make_unique<Botan::Certificate_Store_In_Memory>();
1521 for(size_t i = 0; i != trusted_len; ++i) {
1522 trusted_extra->add_certificate(safe_get(trusted[i]));
1523 }
1524 trusted_roots.push_back(trusted_extra.get());
1525 }
1526
1527 if(crls_len > 0) {
1528 trusted_crls = std::make_unique<Botan::Certificate_Store_In_Memory>();
1529 for(size_t i = 0; i != crls_len; ++i) {
1530 trusted_crls->add_crl(safe_get(crls[i]));
1531 }
1532 trusted_roots.push_back(trusted_crls.get());
1533 }
1534
1535 const Botan::Path_Validation_Restrictions restrictions(false, required_strength);
1536
1537 const auto validation_result =
1538 Botan::x509_path_validate(end_certs, restrictions, trusted_roots, hostname, usage, validation_time);
1539
1540 if(result_code != nullptr) {
1541 *result_code = static_cast<int>(validation_result.result());
1542 }
1543
1544 if(validation_result.successful_validation()) {
1545 return 0;
1546 } else {
1547 return 1;
1548 }
1549 });
1550#else
1551 BOTAN_UNUSED(result_code, cert, intermediates, intermediates_len, trusted);
1552 BOTAN_UNUSED(trusted_len, trusted_path, hostname_cstr, reference_time, crls, crls_len);
1554#endif
1555}

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 533 of file ffi_cert.cpp.

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

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 283 of file ffi_cert.cpp.

287 {
288#if defined(BOTAN_HAS_X509_CERTIFICATES)
289 if(index != 0) {
290 // As of now there are no multi-value binary entries.
292 }
293
294 const auto view = [=](std::span<const uint8_t> value) -> int {
295 if(value.empty()) {
297 } else {
298 return invoke_view_callback(view_fn, ctx, value);
299 }
300 };
301
302 return BOTAN_FFI_VISIT(cert, [=](const Botan::X509_Certificate& c) -> int {
303 switch(value_type) {
305 return view(c.serial_number());
307 return view(c.raw_subject_dn());
309 return view(c.raw_issuer_dn());
311 return view(c.subject_key_id());
313 return view(c.authority_key_id());
315 return view(c.subject_public_key_info());
316
321 return botan_x509_object_view_value(c, value_type, index, ctx, view_fn);
322
328 }
329
331 });
332#else
333 BOTAN_UNUSED(cert, value_type, index, ctx, view_fn);
335#endif
336}
const std::vector< uint8_t > & serial_number() const
Definition x509cert.cpp:438
const std::vector< uint8_t > & authority_key_id() const
Definition x509cert.cpp:430
const std::vector< uint8_t > & raw_subject_dn() const
Definition x509cert.cpp:466
const std::vector< uint8_t > & subject_key_id() const
Definition x509cert.cpp:434
const std::vector< uint8_t > & raw_issuer_dn() const
Definition x509cert.cpp:462
const std::vector< uint8_t > & subject_public_key_info() const
Definition x509cert.cpp:410
@ BOTAN_X509_AUTHORITY_KEY_IDENTIFIER
Definition ffi.h:3628
@ BOTAN_X509_SUBJECT_KEY_IDENTIFIER
Definition ffi.h:3627
@ BOTAN_X509_TBS_DATA_BITS
Definition ffi.h:3631
@ BOTAN_X509_SIGNATURE_BITS
Definition ffi.h:3633
@ BOTAN_X509_PUBLIC_KEY_PKCS8_BITS
Definition ffi.h:3630
@ BOTAN_X509_DER_ENCODING
Definition ffi.h:3635
@ BOTAN_X509_PEM_ENCODING
Definition ffi.h:3636
@ BOTAN_X509_OCSP_RESPONDER_URLS
Definition ffi.h:3639
@ BOTAN_X509_SIGNATURE_SCHEME_BITS
Definition ffi.h:3632
@ BOTAN_X509_SUBJECT_DN_BITS
Definition ffi.h:3625
@ BOTAN_X509_CRL_DISTRIBUTION_URLS
Definition ffi.h:3638
@ BOTAN_X509_SERIAL_NUMBER
Definition ffi.h:3624
@ BOTAN_X509_ISSUER_DN_BITS
Definition ffi.h:3626
@ BOTAN_X509_CA_ISSUERS_URLS
Definition ffi.h:3640

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 338 of file ffi_cert.cpp.

338 {
339#if defined(BOTAN_HAS_X509_CERTIFICATES)
340 return enumerator_count_values(count, [=](size_t index) {
342 cert, value_type, index, nullptr, [](auto, auto, auto) -> int { return BOTAN_FFI_SUCCESS; });
343 });
344#else
345 BOTAN_UNUSED(cert, value_type, count);
347#endif
348}
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:283

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 697 of file ffi_cert.cpp.

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

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 350 of file ffi_cert.cpp.

354 {
355#if defined(BOTAN_HAS_X509_CERTIFICATES)
356 const auto enumerate_uris = [view_fn, ctx](const std::vector<Botan::URI>& values, size_t idx) -> int {
357 if(idx >= values.size()) {
359 } else {
360 return invoke_view_callback(view_fn, ctx, values[idx].original_input());
361 }
362 };
363
364 return BOTAN_FFI_VISIT(cert, [=](const Botan::X509_Certificate& c) -> int {
365 switch(value_type) {
367 return enumerate_uris(c.crl_distribution_point_uris(), index);
369 return enumerate_uris(c.ocsp_responder_uris(), index);
371 return enumerate_uris(c.ca_issuer_uris(), index);
373 return botan_x509_object_view_value(c, value_type, index, ctx, view_fn);
374
386 }
387
389 });
390#else
391 BOTAN_UNUSED(cert, value_type, index, ctx, view_fn);
393#endif
394}
const std::vector< URI > & ocsp_responder_uris() const
Definition x509cert.cpp:639
const std::vector< URI > & crl_distribution_point_uris() const
Definition x509cert.cpp:655
const std::vector< URI > & ca_issuer_uris() const
Definition x509cert.cpp:647

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 396 of file ffi_cert.cpp.

396 {
397#if defined(BOTAN_HAS_X509_CERTIFICATES)
398 return enumerator_count_values(count, [=](size_t index) {
400 cert, value_type, index, nullptr, [](auto, auto, auto) -> int { return BOTAN_FFI_SUCCESS; });
401 });
402#else
403 BOTAN_UNUSED(cert, value_type, count);
405#endif
406}
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:350

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 1104 of file ffi_cert.cpp.

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

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, crl, 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 1194 of file ffi_cert.cpp.

1194 {
1195#if defined(BOTAN_HAS_X509_CERTIFICATES)
1197#else
1200#endif
1201}

References BOTAN_FFI_CHECKED_DELETE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_UNUSED, and crl.

◆ 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 1369 of file ffi_cert.cpp.

1369 {
1370#if defined(BOTAN_HAS_X509_CERTIFICATES)
1371 return BOTAN_FFI_VISIT(crl, [=](const Botan::X509_CRL& c) -> int {
1372 const auto& entries = c.get_revoked();
1373 if(index >= entries.size()) {
1375 }
1376
1377 if(Botan::any_null_pointers(entry)) {
1379 }
1380
1381 return ffi_new_object(entry, std::make_unique<Botan::CRL_Entry>(entries[index]));
1382 });
1383#else
1384 BOTAN_UNUSED(crl, index, entry);
1386#endif
1387}
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, crl, 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 1389 of file ffi_cert.cpp.

1389 {
1390#if defined(BOTAN_HAS_X509_CERTIFICATES)
1391 if(Botan::any_null_pointers(count)) {
1393 }
1394
1395 return BOTAN_FFI_VISIT(crl, [=](const Botan::X509_CRL& c) { *count = c.get_revoked().size(); });
1396#else
1397 BOTAN_UNUSED(crl, count);
1399#endif
1400}

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, BOTAN_UNUSED, crl, 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 1130 of file ffi_cert.cpp.

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

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 1402 of file ffi_cert.cpp.

1402 {
1403#if defined(BOTAN_HAS_X509_CERTIFICATES)
1404 return BOTAN_FFI_CHECKED_DELETE(entry);
1405#else
1406 BOTAN_UNUSED(entry);
1408#endif
1409}

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 1411 of file ffi_cert.cpp.

1411 {
1412#if defined(BOTAN_HAS_X509_CERTIFICATES)
1413 return BOTAN_FFI_VISIT(entry, [=](const Botan::CRL_Entry& e) {
1414 if(Botan::any_null_pointers(reason_code)) {
1416 }
1417
1418 *reason_code = static_cast<int>(e.reason_code());
1419 return BOTAN_FFI_SUCCESS;
1420 });
1421#else
1422 BOTAN_UNUSED(entry, reason_code);
1424#endif
1425}
Definition x509_crl.h:32
CRL_Code reason_code() const
Definition crl_ent.cpp:148

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 1453 of file ffi_cert.cpp.

1453 {
1454#if defined(BOTAN_HAS_X509_CERTIFICATES)
1455 return BOTAN_FFI_VISIT(entry, [=](const Botan::CRL_Entry& e) {
1456 if(Botan::any_null_pointers(time_since_epoch)) {
1458 }
1459
1460 *time_since_epoch = e.expire_time().time_since_epoch();
1461 return BOTAN_FFI_SUCCESS;
1462 });
1463#else
1464 BOTAN_UNUSED(entry, time_since_epoch);
1466#endif
1467}
uint64_t time_since_epoch() const
Return time since epoch.
const X509_Time & expire_time() const
Definition crl_ent.cpp:144

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 1427 of file ffi_cert.cpp.

1427 {
1428#if defined(BOTAN_HAS_X509_CERTIFICATES)
1429 return BOTAN_FFI_VISIT(entry, [=](const Botan::CRL_Entry& e) {
1430 if(Botan::any_null_pointers(serial_number)) {
1432 }
1433
1434 auto serial_bn = e.serial().to_bigint();
1435 return ffi_new_object(serial_number, std::make_unique<Botan::BigInt>(std::move(serial_bn)));
1436 });
1437#else
1438 BOTAN_UNUSED(entry, serial_number);
1440#endif
1441}
const X509_Serial_Number & serial() const
Definition crl_ent.cpp:140

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 1443 of file ffi_cert.cpp.

1443 {
1444#if defined(BOTAN_HAS_X509_CERTIFICATES)
1445 return BOTAN_FFI_VISIT(
1446 entry, [=](const Botan::CRL_Entry& e) { return invoke_view_callback(view, ctx, e.serial_number()); });
1447#else
1448 BOTAN_UNUSED(entry, ctx, view);
1450#endif
1451}
const std::vector< uint8_t > & serial_number() const
Definition crl_ent.cpp:136

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 1051 of file ffi_cert.cpp.

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

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 1034 of file ffi_cert.cpp.

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

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 1083 of file ffi_cert.cpp.

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

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, BOTAN_UNUSED, and crl.

◆ 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 1068 of file ffi_cert.cpp.

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

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

◆ 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 1145 of file ffi_cert.cpp.

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

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_UNUSED, crl, 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 1185 of file ffi_cert.cpp.

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

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_VISIT, BOTAN_UNUSED, crl, 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 1203 of file ffi_cert.cpp.

1207 {
1208#if defined(BOTAN_HAS_X509_CERTIFICATES)
1209 if(index != 0) {
1210 // As of now there are no multi-value binary entries.
1212 }
1213
1214 const auto view = [=](std::span<const uint8_t> value) -> int {
1215 if(value.empty()) {
1217 } else {
1218 return invoke_view_callback(view_fn, ctx, value);
1219 }
1220 };
1221
1222 return BOTAN_FFI_VISIT(crl_obj, [=](const Botan::X509_CRL& crl) -> int {
1223 switch(value_type) {
1225 if(const auto& crln = crl.crl_number_bigint()) {
1226 // Previously CRL number was a fixed 4 byte value, continue this for small CRL numbers
1227 const size_t view_bytes = std::min<size_t>(crln->bytes(), 4);
1228 return view(crln->serialize<std::vector<uint8_t>>(view_bytes));
1229 } else {
1231 }
1232 }
1234 return view(Botan::ASN1::put_in_sequence(crl.issuer_dn().get_bits()));
1236 return view(crl.authority_key_id());
1237
1242 return botan_x509_object_view_value(crl, value_type, index, ctx, view_fn);
1243
1252 }
1253
1255 });
1256#else
1257 BOTAN_UNUSED(crl_obj, value_type, index, ctx, view_fn);
1259#endif
1260}
std::vector< uint8_t > put_in_sequence(const std::vector< uint8_t > &contents)
Definition asn1_obj.cpp:208

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, crl, Botan_FFI::invoke_view_callback(), 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 1262 of file ffi_cert.cpp.

1262 {
1263#if defined(BOTAN_HAS_X509_CERTIFICATES)
1264 return enumerator_count_values(count, [=](size_t index) {
1266 crl_obj, value_type, index, nullptr, [](auto, auto, auto) -> int { return BOTAN_FFI_SUCCESS; });
1267 });
1268#else
1269 BOTAN_UNUSED(crl_obj, value_type, count);
1271#endif
1272}
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_issuer_dn()

int botan_x509_crl_view_issuer_dn ( botan_x509_crl_t crl,
const char * key,
size_t index,
botan_view_ctx ctx,
botan_view_str_fn view )

Enumerates the names of the given key in the issuer DN.

Parameters
crlthe CRL whose DN should be enumerated
keythe key to to look up
indexthe index of the entry to return for the given key
Returns
0 on success, BOTAN_FFI_ERROR_OUT_OF_RANGE if the given index is out of range, a negative number on failure

Definition at line 1321 of file ffi_cert.cpp.

1322 {
1323 if(Botan::any_null_pointers(key)) {
1325 }
1326#if defined(BOTAN_HAS_X509_CERTIFICATES)
1327 return BOTAN_FFI_VISIT(crl, [=](const auto& c) -> int {
1328 const auto& dn = c.issuer_dn();
1329 const auto& issuer_info = dn.get_attribute(key);
1330 if(index < issuer_info.size()) {
1331 return invoke_view_callback(view, ctx, issuer_info.at(index));
1332 } else {
1334 }
1335 });
1336#else
1337 BOTAN_UNUSED(crl, index, ctx, view);
1339#endif
1340}

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, crl, and Botan_FFI::invoke_view_callback().

◆ botan_x509_crl_view_issuer_dn_count()

int botan_x509_crl_view_issuer_dn_count ( botan_x509_crl_t crl,
const char * key,
size_t * count )

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

Parameters
crlthe CRL to inspect
keythe DN component to count
countset to the number of available entries
Returns
0 on success, a negative value on failure

Definition at line 1342 of file ffi_cert.cpp.

1342 {
1343 if(Botan::any_null_pointers(key)) {
1345 }
1346#if defined(BOTAN_HAS_X509_CERTIFICATES)
1347 return BOTAN_FFI_VISIT(crl, [=](const auto& c) -> int {
1348 const auto& dn = c.issuer_dn();
1349 *count = dn.get_attribute(key).size();
1350
1351 return BOTAN_FFI_SUCCESS;
1352 });
1353#else
1354 BOTAN_UNUSED(crl, count);
1356#endif
1357}

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

◆ 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 1274 of file ffi_cert.cpp.

1278 {
1279#if defined(BOTAN_HAS_X509_CERTIFICATES)
1280 return BOTAN_FFI_VISIT(crl_obj, [=](const Botan::X509_CRL& crl) -> int {
1281 switch(value_type) {
1283 return botan_x509_object_view_value(crl, value_type, index, ctx, view);
1284
1299 }
1300
1302 });
1303#else
1304 BOTAN_UNUSED(crl_obj, value_type, index, ctx, view);
1306#endif
1307}

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, BOTAN_X509_TBS_DATA_BITS, and crl.

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 1309 of file ffi_cert.cpp.

1309 {
1310#if defined(BOTAN_HAS_X509_CERTIFICATES)
1311 return enumerator_count_values(count, [=](size_t index) {
1313 crl_obj, value_type, index, nullptr, [](auto, auto, auto) -> int { return BOTAN_FFI_SUCCESS; });
1314 });
1315#else
1316 BOTAN_UNUSED(crl_obj, value_type, count);
1318#endif
1319}
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 777 of file ffi_cert.cpp.

777 {
778#if defined(BOTAN_HAS_X509_CERTIFICATES)
780#else
783#endif
784}

References BOTAN_FFI_CHECKED_DELETE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_UNUSED, and name.

◆ 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 707 of file ffi_cert.cpp.

707 {
708#if defined(BOTAN_HAS_X509_CERTIFICATES)
709 return BOTAN_FFI_VISIT(name, [=](const Botan::GeneralName& n) {
710 if(Botan::any_null_pointers(type)) {
712 }
713
714 const auto mapped_type = to_botan_x509_general_name_types(n.type_code());
715 if(!mapped_type.has_value()) {
717 }
718
719 *type = mapped_type.value();
720 if(*type == BOTAN_X509_OTHER_NAME /* ... viewing of other-names not supported */) {
722 }
723
724 return BOTAN_FFI_SUCCESS;
725 });
726#else
727 BOTAN_UNUSED(name, type);
729#endif
730}
X.509 GeneralName Type.
Definition pkix_types.h:541
NameType type_code() const
Definition pkix_types.h:594
@ BOTAN_X509_OTHER_NAME
Definition ffi.h:3977
@ 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, 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 755 of file ffi_cert.cpp.

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

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(), name, 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 732 of file ffi_cert.cpp.

734 {
735#if defined(BOTAN_HAS_X509_CERTIFICATES)
736 return BOTAN_FFI_VISIT(name, [=](const Botan::GeneralName& n) -> int {
737 const auto type = to_botan_x509_general_name_types(n.type_code());
738 if(!type) {
740 }
741
742 if(type != BOTAN_X509_EMAIL_ADDRESS && type != BOTAN_X509_DNS_NAME && type != BOTAN_X509_URI &&
743 type != BOTAN_X509_IP_ADDRESS) {
745 }
746
747 return invoke_view_callback(view, ctx, n.name());
748 });
749#else
750 BOTAN_UNUSED(name, ctx, view);
752#endif
753}
std::string name() const
@ BOTAN_X509_DNS_NAME
Definition ffi.h:3979
@ BOTAN_X509_EMAIL_ADDRESS
Definition ffi.h:3978
@ BOTAN_X509_URI
Definition ffi.h:3981

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(), 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 1359 of file ffi_cert.cpp.

1359 {
1360#if defined(BOTAN_HAS_X509_CERTIFICATES)
1361 return BOTAN_FFI_VISIT(crl, [=](const auto& c) { return c.is_revoked(safe_get(cert)) ? 0 : -1; });
1362#else
1363 BOTAN_UNUSED(cert);
1366#endif
1367}

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