Botan 3.6.1
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 139 of file ffi_cert.cpp.

139 {
140#if defined(BOTAN_HAS_X509_CERTIFICATES)
141 return BOTAN_FFI_VISIT(cert, [=](const auto& c) -> int {
142 const Botan::Key_Constraints k = static_cast<Botan::Key_Constraints>(key_usage);
143 if(c.allowed_usage(k))
144 return BOTAN_FFI_SUCCESS;
145 return 1;
146 });
147#else
148 BOTAN_UNUSED(cert, key_usage);
150#endif
151}
#define BOTAN_UNUSED
Definition assert.h:118
@ BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition ffi.h:135
@ BOTAN_FFI_SUCCESS
Definition ffi.h:114
#define BOTAN_FFI_VISIT(obj, lambda)
Definition ffi_util.h:124

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

153 {
154#if defined(BOTAN_HAS_X509_CERTIFICATES)
155 return BOTAN_FFI_CHECKED_DELETE(cert);
156#else
157 BOTAN_UNUSED(cert);
159#endif
160}
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition ffi_util.h:143

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

48 {
49 if(!cert_obj) {
51 }
52
53#if defined(BOTAN_HAS_X509_CERTIFICATES) && defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
54
55 return ffi_guard_thunk(__func__, [=]() -> int {
56 auto c = std::make_unique<Botan::X509_Certificate>(safe_get(cert));
57 *cert_obj = new botan_x509_cert_struct(std::move(c));
58 return BOTAN_FFI_SUCCESS;
59 });
60
61#else
62 BOTAN_UNUSED(cert);
64#endif
65}
@ BOTAN_FFI_ERROR_NULL_POINTER
Definition ffi.h:129
T & safe_get(botan_struct< T, M > *p)
Definition ffi_util.h:63
int ffi_guard_thunk(const char *func_name, const std::function< int()> &thunk)
Definition ffi.cpp:118

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), 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 218 of file ffi_cert.cpp.

218 {
219#if defined(BOTAN_HAS_X509_CERTIFICATES)
220 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { return write_vec_output(out, out_len, c.authority_key_id()); });
221#else
222 BOTAN_UNUSED(cert, out, out_len);
224#endif
225}
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition ffi_util.h:201

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

209 {
210#if defined(BOTAN_HAS_X509_CERTIFICATES)
211 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { return write_str_output(out, out_len, c.fingerprint(hash)); });
212#else
213 BOTAN_UNUSED(cert, hash, out, out_len);
215#endif
216}
int write_str_output(uint8_t out[], size_t *out_len, std::string_view str)
Definition ffi_util.h:205

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

105 {
106#if defined(BOTAN_HAS_X509_CERTIFICATES)
107 return BOTAN_FFI_VISIT(cert,
108 [=](const auto& c) { return write_str_output(out, out_len, c.issuer_info(key).at(index)); });
109#else
110 BOTAN_UNUSED(cert, key, index, out, out_len);
112#endif
113}

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

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

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), 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 236 of file ffi_cert.cpp.

236 {
237 return copy_view_bin(out, out_len, botan_x509_cert_view_public_key_bits, cert);
238}
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:240
int copy_view_bin(uint8_t out[], size_t *out_len, Fn fn, Args... args)
Definition ffi_util.h:163

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

200 {
201#if defined(BOTAN_HAS_X509_CERTIFICATES)
202 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { return write_vec_output(out, out_len, c.serial_number()); });
203#else
204 BOTAN_UNUSED(cert, out, out_len);
206#endif
207}

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

116 {
117#if defined(BOTAN_HAS_X509_CERTIFICATES)
118 return BOTAN_FFI_VISIT(cert,
119 [=](const auto& c) { return write_str_output(out, out_len, c.subject_info(key).at(index)); });
120#else
121 BOTAN_UNUSED(cert, key, index, out, out_len);
123#endif
124}

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

227 {
228#if defined(BOTAN_HAS_X509_CERTIFICATES)
229 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { return write_vec_output(out, out_len, c.subject_key_id()); });
230#else
231 BOTAN_UNUSED(cert, out, out_len);
233#endif
234}

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

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

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

162 {
163#if defined(BOTAN_HAS_X509_CERTIFICATES)
164 return BOTAN_FFI_VISIT(cert,
165 [=](const auto& c) { return write_str_output(out, out_len, c.not_before().to_string()); });
166#else
167 BOTAN_UNUSED(cert, out, out_len);
169#endif
170}

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

250 {
251 if(hostname == nullptr) {
253 }
254
255#if defined(BOTAN_HAS_X509_CERTIFICATES)
256 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { return c.matches_dns_name(hostname) ? 0 : -1; });
257#else
258 BOTAN_UNUSED(cert);
260#endif
261}

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

67 {
68 if(!cert_obj || !cert_bits) {
70 }
71
72#if defined(BOTAN_HAS_X509_CERTIFICATES)
73 return ffi_guard_thunk(__func__, [=]() -> int {
74 Botan::DataSource_Memory bits(cert_bits, cert_bits_len);
75 auto c = std::make_unique<Botan::X509_Certificate>(bits);
76 *cert_obj = new botan_x509_cert_struct(std::move(c));
77 return BOTAN_FFI_SUCCESS;
78 });
79#else
80 BOTAN_UNUSED(cert_bits_len);
82#endif
83}

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

◆ 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 || !cert_path) {
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 *cert_obj = new botan_x509_cert_struct(std::move(c));
40 return BOTAN_FFI_SUCCESS;
41 });
42
43#else
45#endif
46}

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

◆ botan_x509_cert_not_after()

int botan_x509_cert_not_after ( botan_x509_cert_t cert,
uint64_t * time_since_epoch )

Definition at line 191 of file ffi_cert.cpp.

191 {
192#if defined(BOTAN_HAS_X509_CERTIFICATES)
193 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { *time_since_epoch = c.not_after().time_since_epoch(); });
194#else
195 BOTAN_UNUSED(cert, time_since_epoch);
197#endif
198}

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

182 {
183#if defined(BOTAN_HAS_X509_CERTIFICATES)
184 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { *time_since_epoch = c.not_before().time_since_epoch(); });
185#else
186 BOTAN_UNUSED(cert, time_since_epoch);
188#endif
189}

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

126 {
127 return copy_view_str(reinterpret_cast<uint8_t*>(out), out_len, botan_x509_cert_view_as_string, cert);
128}
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:130
int copy_view_str(uint8_t out[], size_t *out_len, Fn fn, Args... args)
Definition ffi_util.h:171

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

330 {
331 if(code < 0) {
332 return nullptr;
333 }
334
335#if defined(BOTAN_HAS_X509_CERTIFICATES)
337 return Botan::to_string(sc);
338#else
339 return nullptr;
340#endif
341}
std::string to_string(ErrorType type)
Convert an ErrorType to string.
Definition exceptn.cpp:13
Certificate_Status_Code
Definition pkix_enums.h:20

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

272 {
273 if(required_strength == 0) {
274 required_strength = 110;
275 }
276
277#if defined(BOTAN_HAS_X509_CERTIFICATES)
278 return ffi_guard_thunk(__func__, [=]() -> int {
279 const std::string hostname((hostname_cstr == nullptr) ? "" : hostname_cstr);
281 const auto validation_time = reference_time == 0
282 ? std::chrono::system_clock::now()
283 : std::chrono::system_clock::from_time_t(static_cast<time_t>(reference_time));
284
285 std::vector<Botan::X509_Certificate> end_certs;
286 end_certs.push_back(safe_get(cert));
287 for(size_t i = 0; i != intermediates_len; ++i) {
288 end_certs.push_back(safe_get(intermediates[i]));
289 }
290
291 std::unique_ptr<Botan::Certificate_Store> trusted_from_path;
292 std::unique_ptr<Botan::Certificate_Store_In_Memory> trusted_extra;
293 std::vector<Botan::Certificate_Store*> trusted_roots;
294
295 if(trusted_path && *trusted_path) {
296 trusted_from_path = std::make_unique<Botan::Certificate_Store_In_Memory>(trusted_path);
297 trusted_roots.push_back(trusted_from_path.get());
298 }
299
300 if(trusted_len > 0) {
301 trusted_extra = std::make_unique<Botan::Certificate_Store_In_Memory>();
302 for(size_t i = 0; i != trusted_len; ++i) {
303 trusted_extra->add_certificate(safe_get(trusted[i]));
304 }
305 trusted_roots.push_back(trusted_extra.get());
306 }
307
308 Botan::Path_Validation_Restrictions restrictions(false, required_strength);
309
310 auto validation_result =
311 Botan::x509_path_validate(end_certs, restrictions, trusted_roots, hostname, usage, validation_time);
312
313 if(result_code) {
314 *result_code = static_cast<int>(validation_result.result());
315 }
316
317 if(validation_result.successful_validation()) {
318 return 0;
319 } else {
320 return 1;
321 }
322 });
323#else
324 BOTAN_UNUSED(result_code, cert, intermediates, intermediates_len, trusted);
325 BOTAN_UNUSED(trusted_len, trusted_path, hostname_cstr, reference_time);
327#endif
328}
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:882
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 404 of file ffi_cert.cpp.

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

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

130 {
131#if defined(BOTAN_HAS_X509_CERTIFICATES)
132 return BOTAN_FFI_VISIT(cert, [=](const auto& c) { return invoke_view_callback(view, ctx, c.to_string()); });
133#else
134 BOTAN_UNUSED(cert, ctx, view);
136#endif
137}
int invoke_view_callback(botan_view_bin_fn view, botan_view_ctx ctx, const std::vector< uint8_t, Alloc > &buf)
Definition ffi_util.h:146

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

240 {
241#if defined(BOTAN_HAS_X509_CERTIFICATES)
242 return BOTAN_FFI_VISIT(cert,
243 [=](const auto& c) { return invoke_view_callback(view, ctx, c.subject_public_key_bits()); });
244#else
245 BOTAN_UNUSED(cert, ctx, view);
247#endif
248}

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

385 {
386#if defined(BOTAN_HAS_X509_CERTIFICATES)
387 return BOTAN_FFI_CHECKED_DELETE(crl);
388#else
389 BOTAN_UNUSED(crl);
391#endif
392}

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

367 {
368 if(!crl_obj || !crl_bits) {
370 }
371
372#if defined(BOTAN_HAS_X509_CERTIFICATES)
373 return ffi_guard_thunk(__func__, [=]() -> int {
374 Botan::DataSource_Memory bits(crl_bits, crl_bits_len);
375 auto c = std::make_unique<Botan::X509_CRL>(bits);
376 *crl_obj = new botan_x509_crl_struct(std::move(c));
377 return BOTAN_FFI_SUCCESS;
378 });
379#else
380 BOTAN_UNUSED(crl_bits_len);
382#endif
383}

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

◆ botan_x509_crl_load_file()

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

Definition at line 349 of file ffi_cert.cpp.

349 {
350 if(!crl_obj || !crl_path) {
352 }
353
354#if defined(BOTAN_HAS_X509_CERTIFICATES) && defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
355
356 return ffi_guard_thunk(__func__, [=]() -> int {
357 auto c = std::make_unique<Botan::X509_CRL>(crl_path);
358 *crl_obj = new botan_x509_crl_struct(std::move(c));
359 return BOTAN_FFI_SUCCESS;
360 });
361
362#else
364#endif
365}

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

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

394 {
395#if defined(BOTAN_HAS_X509_CERTIFICATES)
396 return BOTAN_FFI_VISIT(crl, [=](const auto& c) { return c.is_revoked(safe_get(cert)) ? 0 : -1; });
397#else
398 BOTAN_UNUSED(cert);
399 BOTAN_UNUSED(crl);
401#endif
402}

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