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

Go to the source code of this file.

Functions

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_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_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_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_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_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_public_key_bits (botan_x509_cert_t cert, botan_view_ctx ctx, botan_view_bin_fn view)
int botan_x509_crl_destroy (botan_x509_crl_t crl)
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_is_revoked (botan_x509_crl_t crl, botan_x509_cert_t cert)

Function Documentation

◆ botan_x509_cert_allowed_usage()

int botan_x509_cert_allowed_usage ( botan_x509_cert_t cert,
unsigned int key_usage )

Definition at line 149 of file ffi_cert.cpp.

149 {
150#if defined(BOTAN_HAS_X509_CERTIFICATES)
151 return BOTAN_FFI_VISIT(cert, [=](const auto& c) -> int {
152 const Botan::Key_Constraints k = static_cast<Botan::Key_Constraints>(key_usage);
153 if(c.allowed_usage(k)) {
154 return BOTAN_FFI_SUCCESS;
155 }
156 return 1;
157 });
158#else
159 BOTAN_UNUSED(cert, key_usage);
161#endif
162}
#define BOTAN_UNUSED
Definition assert.h:144
@ BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition ffi.h:138
@ BOTAN_FFI_SUCCESS
Definition ffi.h:115
#define BOTAN_FFI_VISIT(obj, lambda)
Definition ffi_util.h:158

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)
Returns
0 if success, error if invalid object handle

Definition at line 164 of file ffi_cert.cpp.

164 {
165#if defined(BOTAN_HAS_X509_CERTIFICATES)
166 return BOTAN_FFI_CHECKED_DELETE(cert);
167#else
168 BOTAN_UNUSED(cert);
170#endif
171}
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition ffi_util.h:185

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 * cert_obj,
botan_x509_cert_t cert )

Definition at line 47 of file ffi_cert.cpp.

47 {
48 if(cert_obj == nullptr) {
50 }
51
52#if defined(BOTAN_HAS_X509_CERTIFICATES) && defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
53
54 return ffi_guard_thunk(__func__, [=]() -> int {
55 auto c = std::make_unique<Botan::X509_Certificate>(safe_get(cert));
56 return ffi_new_object(cert_obj, std::move(c));
57 });
58
59#else
60 BOTAN_UNUSED(cert);
62#endif
63}
@ BOTAN_FFI_ERROR_NULL_POINTER
Definition ffi.h:132
T & safe_get(botan_struct< T, M > *p)
Definition ffi_util.h:79
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_get_authority_key_id()

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

Definition at line 233 of file ffi_cert.cpp.

233 {
234#if defined(BOTAN_HAS_X509_CERTIFICATES)
235 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { return write_vec_output(out, out_len, c.authority_key_id()); });
236#else
237 BOTAN_UNUSED(cert, out, out_len);
239#endif
240}
int write_vec_output(uint8_t out[], size_t *out_len, std::span< const uint8_t > buf)
Definition ffi_util.h:247

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 )

Definition at line 220 of file ffi_cert.cpp.

220 {
221#if defined(BOTAN_HAS_X509_CERTIFICATES)
222 // TODO(Botan4) change the type of out and remove this cast
223
224 return BOTAN_FFI_VISIT(cert, [=](const auto& c) {
225 return write_str_output(reinterpret_cast<char*>(out), out_len, c.fingerprint(hash));
226 });
227#else
228 BOTAN_UNUSED(cert, hash, out, out_len);
230#endif
231}
int write_str_output(char out[], size_t *out_len, const std::string &str)
Definition ffi_util.h:251

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, 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 )

Definition at line 100 of file ffi_cert.cpp.

101 {
102#if defined(BOTAN_HAS_X509_CERTIFICATES)
103 return BOTAN_FFI_VISIT(cert, [=](const auto& c) -> int {
104 auto issuer_info = c.issuer_info(key);
105 if(index < issuer_info.size()) {
106 // TODO(Botan4) change the type of out and remove this cast
107 return write_str_output(reinterpret_cast<char*>(out), out_len, c.issuer_info(key).at(index));
108 } else {
110 }
111 });
112#else
113 BOTAN_UNUSED(cert, key, index, out, out_len);
115#endif
116}
@ BOTAN_FFI_ERROR_BAD_PARAMETER
Definition ffi.h:133

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

◆ botan_x509_cert_get_public_key()

int botan_x509_cert_get_public_key ( botan_x509_cert_t cert,
botan_pubkey_t * key )

Definition at line 82 of file ffi_cert.cpp.

82 {
83 if(key == nullptr) {
85 }
86
87 *key = nullptr;
88
89#if defined(BOTAN_HAS_X509_CERTIFICATES)
90 return ffi_guard_thunk(__func__, [=]() -> int {
91 auto public_key = safe_get(cert).subject_public_key();
92 return ffi_new_object(key, std::move(public_key));
93 });
94#else
95 BOTAN_UNUSED(cert);
97#endif
98}

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 )

Definition at line 251 of file ffi_cert.cpp.

251 {
252 return copy_view_bin(out, out_len, botan_x509_cert_view_public_key_bits, cert);
253}
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:255
int copy_view_bin(uint8_t out[], size_t *out_len, Fn fn, Args... args)
Definition ffi_util.h:211

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 )

Definition at line 211 of file ffi_cert.cpp.

211 {
212#if defined(BOTAN_HAS_X509_CERTIFICATES)
213 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { return write_vec_output(out, out_len, c.serial_number()); });
214#else
215 BOTAN_UNUSED(cert, out, out_len);
217#endif
218}

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 )

Definition at line 118 of file ffi_cert.cpp.

119 {
120#if defined(BOTAN_HAS_X509_CERTIFICATES)
121 return BOTAN_FFI_VISIT(cert, [=](const auto& c) -> int {
122 auto subject_info = c.subject_info(key);
123 if(index < subject_info.size()) {
124 // TODO(Botan4) change the type of out and remove this cast
125 return write_str_output(reinterpret_cast<char*>(out), out_len, c.subject_info(key).at(index));
126 } else {
128 }
129 });
130#else
131 BOTAN_UNUSED(cert, key, index, out, out_len);
133#endif
134}

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

◆ 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 )

Definition at line 242 of file ffi_cert.cpp.

242 {
243#if defined(BOTAN_HAS_X509_CERTIFICATES)
244 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { return write_vec_output(out, out_len, c.subject_key_id()); });
245#else
246 BOTAN_UNUSED(cert, out, out_len);
248#endif
249}

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 )

Definition at line 183 of file ffi_cert.cpp.

183 {
184#if defined(BOTAN_HAS_X509_CERTIFICATES)
185 return BOTAN_FFI_VISIT(cert,
186 [=](const auto& c) { return write_str_output(out, out_len, c.not_after().to_string()); });
187#else
188 BOTAN_UNUSED(cert, out, out_len);
190#endif
191}

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 )

Definition at line 173 of file ffi_cert.cpp.

173 {
174#if defined(BOTAN_HAS_X509_CERTIFICATES)
175 return BOTAN_FFI_VISIT(cert,
176 [=](const auto& c) { return write_str_output(out, out_len, c.not_before().to_string()); });
177#else
178 BOTAN_UNUSED(cert, out, out_len);
180#endif
181}

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

265 {
266 if(hostname == nullptr) {
268 }
269
270#if defined(BOTAN_HAS_X509_CERTIFICATES)
271 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { return c.matches_dns_name(hostname) ? 0 : -1; });
272#else
273 BOTAN_UNUSED(cert);
275#endif
276}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, and BOTAN_UNUSED.

◆ botan_x509_cert_load()

int botan_x509_cert_load ( botan_x509_cert_t * cert_obj,
const uint8_t cert_bits[],
size_t cert_bits_len )

Definition at line 65 of file ffi_cert.cpp.

65 {
66 if(cert_obj == nullptr || cert_bits == nullptr) {
68 }
69
70#if defined(BOTAN_HAS_X509_CERTIFICATES)
71 return ffi_guard_thunk(__func__, [=]() -> int {
72 Botan::DataSource_Memory bits(cert_bits, cert_bits_len);
73 auto c = std::make_unique<Botan::X509_Certificate>(bits);
74 return ffi_new_object(cert_obj, std::move(c));
75 });
76#else
77 BOTAN_UNUSED(cert_bits_len);
79#endif
80}

References 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 * cert_path )

Definition at line 30 of file ffi_cert.cpp.

30 {
31 if(cert_obj == nullptr || cert_path == nullptr) {
33 }
34
35#if defined(BOTAN_HAS_X509_CERTIFICATES) && defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
36
37 return ffi_guard_thunk(__func__, [=]() -> int {
38 auto c = std::make_unique<Botan::X509_Certificate>(cert_path);
39 return ffi_new_object(cert_obj, std::move(c));
40 });
41
42#else
44#endif
45}

References 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 )

Definition at line 202 of file ffi_cert.cpp.

202 {
203#if defined(BOTAN_HAS_X509_CERTIFICATES)
204 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { *time_since_epoch = c.not_after().time_since_epoch(); });
205#else
206 BOTAN_UNUSED(cert, time_since_epoch);
208#endif
209}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, 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 )

Definition at line 193 of file ffi_cert.cpp.

193 {
194#if defined(BOTAN_HAS_X509_CERTIFICATES)
195 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { *time_since_epoch = c.not_before().time_since_epoch(); });
196#else
197 BOTAN_UNUSED(cert, time_since_epoch);
199#endif
200}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_VISIT, and BOTAN_UNUSED.

◆ botan_x509_cert_to_string()

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

Definition at line 136 of file ffi_cert.cpp.

136 {
137 return copy_view_str(reinterpret_cast<uint8_t*>(out), out_len, botan_x509_cert_view_as_string, cert);
138}
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:140
int copy_view_str(uint8_t out[], size_t *out_len, Fn fn, Args... args)
Definition ffi_util.h:217

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

345 {
346 if(code < 0) {
347 return nullptr;
348 }
349
350#if defined(BOTAN_HAS_X509_CERTIFICATES)
352 return Botan::to_string(sc);
353#else
354 return nullptr;
355#endif
356}
Certificate_Status_Code
Definition pkix_enums.h:20
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 278 of file ffi_cert.cpp.

287 {
288 if(required_strength == 0) {
289 required_strength = 110;
290 }
291
292#if defined(BOTAN_HAS_X509_CERTIFICATES)
293 return ffi_guard_thunk(__func__, [=]() -> int {
294 const std::string hostname((hostname_cstr == nullptr) ? "" : hostname_cstr);
296 const auto validation_time = reference_time == 0
297 ? std::chrono::system_clock::now()
298 : std::chrono::system_clock::from_time_t(static_cast<time_t>(reference_time));
299
300 std::vector<Botan::X509_Certificate> end_certs;
301 end_certs.push_back(safe_get(cert));
302 for(size_t i = 0; i != intermediates_len; ++i) {
303 end_certs.push_back(safe_get(intermediates[i]));
304 }
305
306 std::unique_ptr<Botan::Certificate_Store> trusted_from_path;
307 std::unique_ptr<Botan::Certificate_Store_In_Memory> trusted_extra;
308 std::vector<Botan::Certificate_Store*> trusted_roots;
309
310 if(trusted_path != nullptr && *trusted_path != 0) {
311 trusted_from_path = std::make_unique<Botan::Certificate_Store_In_Memory>(trusted_path);
312 trusted_roots.push_back(trusted_from_path.get());
313 }
314
315 if(trusted_len > 0) {
316 trusted_extra = std::make_unique<Botan::Certificate_Store_In_Memory>();
317 for(size_t i = 0; i != trusted_len; ++i) {
318 trusted_extra->add_certificate(safe_get(trusted[i]));
319 }
320 trusted_roots.push_back(trusted_extra.get());
321 }
322
323 Botan::Path_Validation_Restrictions restrictions(false, required_strength);
324
325 auto validation_result =
326 Botan::x509_path_validate(end_certs, restrictions, trusted_roots, hostname, usage, validation_time);
327
328 if(result_code != nullptr) {
329 *result_code = static_cast<int>(validation_result.result());
330 }
331
332 if(validation_result.successful_validation()) {
333 return 0;
334 } else {
335 return 1;
336 }
337 });
338#else
339 BOTAN_UNUSED(result_code, cert, intermediates, intermediates_len, trusted);
340 BOTAN_UNUSED(trusted_len, trusted_path, hostname_cstr, reference_time);
342#endif
343}
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)
Definition x509path.cpp:883
Usage_Type
Definition x509cert.h:22

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

428 {
429 if(required_strength == 0) {
430 required_strength = 110;
431 }
432
433#if defined(BOTAN_HAS_X509_CERTIFICATES)
434 return ffi_guard_thunk(__func__, [=]() -> int {
435 const std::string hostname((hostname_cstr == nullptr) ? "" : hostname_cstr);
437 const auto validation_time = reference_time == 0
438 ? std::chrono::system_clock::now()
439 : std::chrono::system_clock::from_time_t(static_cast<time_t>(reference_time));
440
441 std::vector<Botan::X509_Certificate> end_certs;
442 end_certs.push_back(safe_get(cert));
443 for(size_t i = 0; i != intermediates_len; ++i) {
444 end_certs.push_back(safe_get(intermediates[i]));
445 }
446
447 std::unique_ptr<Botan::Certificate_Store> trusted_from_path;
448 std::unique_ptr<Botan::Certificate_Store_In_Memory> trusted_extra;
449 std::unique_ptr<Botan::Certificate_Store_In_Memory> trusted_crls;
450 std::vector<Botan::Certificate_Store*> trusted_roots;
451
452 if(trusted_path != nullptr && *trusted_path != 0) {
453 trusted_from_path = std::make_unique<Botan::Certificate_Store_In_Memory>(trusted_path);
454 trusted_roots.push_back(trusted_from_path.get());
455 }
456
457 if(trusted_len > 0) {
458 trusted_extra = std::make_unique<Botan::Certificate_Store_In_Memory>();
459 for(size_t i = 0; i != trusted_len; ++i) {
460 trusted_extra->add_certificate(safe_get(trusted[i]));
461 }
462 trusted_roots.push_back(trusted_extra.get());
463 }
464
465 if(crls_len > 0) {
466 trusted_crls = std::make_unique<Botan::Certificate_Store_In_Memory>();
467 for(size_t i = 0; i != crls_len; ++i) {
468 trusted_crls->add_crl(safe_get(crls[i]));
469 }
470 trusted_roots.push_back(trusted_crls.get());
471 }
472
473 Botan::Path_Validation_Restrictions restrictions(false, required_strength);
474
475 auto validation_result =
476 Botan::x509_path_validate(end_certs, restrictions, trusted_roots, hostname, usage, validation_time);
477
478 if(result_code != nullptr) {
479 *result_code = static_cast<int>(validation_result.result());
480 }
481
482 if(validation_result.successful_validation()) {
483 return 0;
484 } else {
485 return 1;
486 }
487 });
488#else
489 BOTAN_UNUSED(result_code, cert, intermediates, intermediates_len, trusted);
490 BOTAN_UNUSED(trusted_len, trusted_path, hostname_cstr, reference_time, crls, crls_len);
492#endif
493}

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, 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 )

Definition at line 140 of file ffi_cert.cpp.

140 {
141#if defined(BOTAN_HAS_X509_CERTIFICATES)
142 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { return invoke_view_callback(view, ctx, c.to_string()); });
143#else
144 BOTAN_UNUSED(cert, ctx, view);
146#endif
147}
int invoke_view_callback(botan_view_bin_fn view, botan_view_ctx ctx, std::span< const uint8_t > buf)
Definition ffi_util.h:187

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_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 )

Definition at line 255 of file ffi_cert.cpp.

255 {
256#if defined(BOTAN_HAS_X509_CERTIFICATES)
257 return BOTAN_FFI_VISIT(cert,
258 [=](const auto& c) { return invoke_view_callback(view, ctx, c.subject_public_key_bits()); });
259#else
260 BOTAN_UNUSED(cert, ctx, view);
262#endif
263}

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_crl_destroy()

int botan_x509_crl_destroy ( botan_x509_crl_t crl)

Definition at line 398 of file ffi_cert.cpp.

398 {
399#if defined(BOTAN_HAS_X509_CERTIFICATES)
400 return BOTAN_FFI_CHECKED_DELETE(crl);
401#else
402 BOTAN_UNUSED(crl);
404#endif
405}

References BOTAN_FFI_CHECKED_DELETE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, and BOTAN_UNUSED.

◆ 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 )

Definition at line 381 of file ffi_cert.cpp.

381 {
382 if(crl_obj == nullptr || crl_bits == nullptr) {
384 }
385
386#if defined(BOTAN_HAS_X509_CERTIFICATES)
387 return ffi_guard_thunk(__func__, [=]() -> int {
388 Botan::DataSource_Memory bits(crl_bits, crl_bits_len);
389 auto c = std::make_unique<Botan::X509_CRL>(bits);
390 return ffi_new_object(crl_obj, std::move(c));
391 });
392#else
393 BOTAN_UNUSED(crl_bits_len);
395#endif
396}

References 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 )

Definition at line 364 of file ffi_cert.cpp.

364 {
365 if(crl_obj == nullptr || crl_path == nullptr) {
367 }
368
369#if defined(BOTAN_HAS_X509_CERTIFICATES) && defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
370
371 return ffi_guard_thunk(__func__, [=]() -> int {
372 auto c = std::make_unique<Botan::X509_CRL>(crl_path);
373 return ffi_new_object(crl_obj, std::move(c));
374 });
375
376#else
378#endif
379}

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

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

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

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