Botan 3.14.1
Crypto and TLS for C&
ffi_cert.cpp
Go to the documentation of this file.
1/*
2* (C) 2015,2017,2018 Jack Lloyd
3*
4* Botan is released under the Simplified BSD License (see license.txt)
5*/
6
7#include <botan/ffi.h>
8
9#include <botan/assert.h>
10#include <botan/internal/ffi_cert.h>
11#include <botan/internal/ffi_pkey.h>
12#include <botan/internal/ffi_rng.h>
13#include <botan/internal/ffi_util.h>
14#include <memory>
15
16#if defined(BOTAN_HAS_X509_CERTIFICATES)
17 #include <botan/data_src.h>
18 #include <botan/x509_crl.h>
19 #include <botan/x509_ext.h>
20 #include <botan/x509cert.h>
21 #include <botan/x509path.h>
22 #include <botan/internal/ffi_mp.h>
23 #include <botan/internal/ffi_oid.h>
24#endif
25
26#if defined(BOTAN_HAS_X509_CERTIFICATES)
27
28namespace Botan_FFI {
29
30namespace {
31
32/**
33 * As specified in RFC 5280 Section 4.2.1.6. alternative names essentially are a
34 * collection of GeneralNames. This allows mapping a single entry of @p altnames
35 * to a GeneralName by its @p index. If the index is out of range, std::nullopt
36 * is returned.
37 *
38 * NOTE: if the set of alternative name types handled here is extended,
39 * count_general_names_in() must be updated accordingly!
40 */
41std::optional<Botan::GeneralName> extract_general_name_at(const Botan::AlternativeName& altnames, size_t index) {
42 if(index < altnames.email_addresses().size()) {
43 auto itr = altnames.email_addresses().begin();
44 std::advance(itr, index);
45 return Botan::GeneralName::email(itr->to_string());
46 }
47 index -= altnames.email_addresses().size();
48
49 if(index < altnames.dns_names().size()) {
50 auto itr = altnames.dns_names().begin();
51 std::advance(itr, index);
52 return Botan::GeneralName::_dns_san_value(itr->to_string());
53 }
54 index -= altnames.dns_names().size();
55
56 if(index < altnames.directory_names().size()) {
57 auto itr = altnames.directory_names().begin();
58 std::advance(itr, index);
60 }
61 index -= altnames.directory_names().size();
62
63 if(index < altnames.uri_names().size()) {
64 auto itr = altnames.uri_names().begin();
65 std::advance(itr, index);
66 return Botan::GeneralName::_uri_san_value(itr->original_input());
67 }
68 index -= altnames.uri_names().size();
69
70 if(index < altnames.ipv4_addresses().size()) {
71 auto itr = altnames.ipv4_addresses().begin();
72 std::advance(itr, index);
74 }
75 index -= altnames.ipv4_addresses().size();
76
77 if(index < altnames.ipv6_addresses().size()) {
78 auto itr = altnames.ipv6_addresses().begin();
79 std::advance(itr, index);
81 }
82
83 return std::nullopt;
84}
85
86/**
87 * Counts the total number of GeneralNames contained in the given
88 * AlternativeName @p alt_names.
89 *
90 * NOTE: if the set of alternative name types handled here is extended,
91 * extract_general_name_at() must be updated accordingly!
92 */
93size_t count_general_names_in(const Botan::AlternativeName& alt_names) {
94 return alt_names.email_addresses().size() + alt_names.dns_names().size() + alt_names.directory_names().size() +
95 alt_names.uri_names().size() + alt_names.ipv4_addresses().size() + alt_names.ipv6_addresses().size();
96}
97
98std::optional<botan_x509_general_name_types> to_botan_x509_general_name_types(Botan::GeneralName::NameType gn_type) {
100 switch(gn_type) {
101 case Type::Unknown:
102 return std::nullopt;
103 case Type::RFC822:
105 case Type::DNS:
106 return BOTAN_X509_DNS_NAME;
107 case Type::URI:
108 return BOTAN_X509_URI;
109 case Type::DN:
111 case Type::IPv4:
112 case Type::IPv6:
114 case Type::Other:
116 }
117
119}
120
121/**
122 * Given some enumerator-style function @p fn, count how many values it can
123 * produce before returning BOTAN_FFI_ERROR_OUT_OF_RANGE. If the first call to
124 * @p fn returns BOTAN_FFI_ERROR_NO_VALUE, zero is written to @p count.
125 *
126 * If this function returns BOTAN_FFI_SUCCESS, @p count contains the number of
127 * values that can be enumerated. Otherwise, the value of @p count is undefined.
128 */
129template <std::invocable<size_t> EnumeratorT>
130int enumerator_count_values(size_t* count, EnumeratorT fn) {
131 if(Botan::any_null_pointers(count)) {
133 }
134
135 *count = 0;
136 for(;; ++(*count)) {
137 const auto rc = fn(*count);
138 switch(rc) {
141 // hit the end of the enumeration
142 return BOTAN_FFI_SUCCESS;
144 // got a value, continue counting
145 break;
146 default:
147 // unexpected error from enumerator function
148 return rc;
149 }
150 }
151}
152
153std::chrono::system_clock::time_point timepoint_from_timestamp(uint64_t time_since_epoch) {
154 return std::chrono::system_clock::time_point(std::chrono::seconds(time_since_epoch));
155}
156
157std::string default_from_ptr(const char* value) {
158 std::string ret;
159 if(value != nullptr) {
160 ret = value;
161 }
162 return ret;
163}
164
165} // namespace
166
167} // namespace Botan_FFI
168
169#endif
170
171extern "C" {
172
173using namespace Botan_FFI;
174
175int botan_x509_cert_load_file(botan_x509_cert_t* cert_obj, const char* cert_path) {
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}
191
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}
209
210int botan_x509_cert_load(botan_x509_cert_t* cert_obj, const uint8_t cert_bits[], size_t cert_bits_len) {
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}
226}
227
228namespace {
229
230#if defined(BOTAN_HAS_X509_CERTIFICATES)
231
232int botan_x509_object_view_value(const Botan::X509_Object& object,
233 botan_x509_value_type value_type,
234 size_t index,
235 botan_view_ctx ctx,
236 botan_view_str_fn view_fn) {
237 if(index != 0) {
238 // As of now there are no multi-value generic string entries.
240 }
241
242 const auto view = [=](const std::string& value) { return invoke_view_callback(view_fn, ctx, value); };
243
244 if(value_type == BOTAN_X509_PEM_ENCODING) {
245 return view(object.PEM_encode());
246 }
247
248 BOTAN_ASSERT_UNREACHABLE(); /* called with unexpected (non-generic) value_type */
249}
250
251int botan_x509_object_view_value(const Botan::X509_Object& object,
252 botan_x509_value_type value_type,
253 size_t index,
254 botan_view_ctx ctx,
255 botan_view_bin_fn view_fn) {
256 if(index != 0) {
257 // As of now there are no multi-value generic binary entries.
259 }
260
261 const auto view = [=](std::span<const uint8_t> value) { return invoke_view_callback(view_fn, ctx, value); };
262
263 switch(value_type) {
265 return view(object.tbs_data());
267 return view(object.signature_algorithm().BER_encode());
269 return view(object.signature());
271 return view(object.BER_encode());
272 default:
273 BOTAN_ASSERT_UNREACHABLE(); /* called with unexpected (non-generic) value_type */
274 }
275}
276
277#endif
278
279} // namespace
280
281extern "C" {
282
284 botan_x509_value_type value_type,
285 size_t index,
286 botan_view_ctx ctx,
287 botan_view_bin_fn view_fn) {
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}
337
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}
349
351 botan_x509_value_type value_type,
352 size_t index,
353 botan_view_ctx ctx,
354 botan_view_str_fn view_fn) {
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}
395
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}
407
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}
416
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}
436
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}
454
456 botan_x509_cert_t cert, const char* key, size_t index, uint8_t out[], size_t* out_len) {
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}
475
476int botan_x509_cert_get_issuer_dn_count(botan_x509_cert_t cert, const char* key, size_t* count) {
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}
491
493 botan_x509_cert_t cert, const char* key, size_t index, uint8_t out[], size_t* out_len) {
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}
512
513int botan_x509_cert_get_subject_dn_count(botan_x509_cert_t cert, const char* key, size_t* count) {
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}
528
529int botan_x509_cert_to_string(botan_x509_cert_t cert, char out[], size_t* out_len) {
530 return copy_view_str(reinterpret_cast<uint8_t*>(out), out_len, botan_x509_cert_view_as_string, cert);
531}
532
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}
541
542int botan_x509_cert_allowed_usage(botan_x509_cert_t cert, unsigned int key_usage) {
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}
556
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}
571
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}
580
582#if defined(BOTAN_HAS_X509_CERTIFICATES)
583 return BOTAN_FFI_CHECKED_DELETE(cert);
584#else
585 BOTAN_UNUSED(cert);
587#endif
588}
589
590int botan_x509_cert_get_time_starts(botan_x509_cert_t cert, char out[], size_t* out_len) {
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}
599
600int botan_x509_cert_get_time_expires(botan_x509_cert_t cert, char out[], size_t* out_len) {
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}
609
610int botan_x509_cert_not_before(botan_x509_cert_t cert, uint64_t* time_since_epoch) {
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}
621
622int botan_x509_cert_not_after(botan_x509_cert_t cert, uint64_t* time_since_epoch) {
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}
633
634int botan_x509_cert_get_serial_number(botan_x509_cert_t cert, uint8_t out[], size_t* out_len) {
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}
642
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}
658
659int botan_x509_cert_get_fingerprint(botan_x509_cert_t cert, const char* hash, uint8_t out[], size_t* out_len) {
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}
674
675int botan_x509_cert_get_authority_key_id(botan_x509_cert_t cert, uint8_t out[], size_t* out_len) {
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}
683
684int botan_x509_cert_get_subject_key_id(botan_x509_cert_t cert, uint8_t out[], size_t* out_len) {
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}
692
693int botan_x509_cert_get_public_key_bits(botan_x509_cert_t cert, uint8_t out[], size_t* out_len) {
694 return copy_view_bin(out, out_len, botan_x509_cert_view_public_key_bits, cert);
695}
696
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}
706
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}
731
733 botan_view_ctx ctx,
734 botan_view_str_fn view) {
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}
754
756 botan_view_ctx ctx,
757 botan_view_bin_fn view) {
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}
776
778#if defined(BOTAN_HAS_X509_CERTIFICATES)
780#else
783#endif
784}
785
787 size_t index,
788 botan_x509_general_name_t* constraint) {
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}
807
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}
820
822 size_t index,
823 botan_x509_general_name_t* constraint) {
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}
842
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}
855
857 size_t index,
858 botan_x509_general_name_t* alt_name) {
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}
880
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}
894
896 size_t index,
897 botan_x509_general_name_t* alt_name) {
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}
919
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}
933
934int botan_x509_cert_hostname_match(botan_x509_cert_t cert, const char* hostname) {
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}
946
947int botan_x509_cert_verify(int* result_code,
949 const botan_x509_cert_t* intermediates,
950 size_t intermediates_len,
951 const botan_x509_cert_t* trusted,
952 size_t trusted_len,
953 const char* trusted_path,
954 size_t required_strength,
955 const char* hostname_cstr,
956 uint64_t reference_time) {
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}
1020
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}
1033
1034int botan_x509_crl_load_file(botan_x509_crl_t* crl_obj, const char* crl_path) {
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}
1050
1051int botan_x509_crl_load(botan_x509_crl_t* crl_obj, const uint8_t crl_bits[], size_t crl_bits_len) {
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}
1067
1068int botan_x509_crl_this_update(botan_x509_crl_t crl, uint64_t* time_since_epoch) {
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}
1082
1083int botan_x509_crl_next_update(botan_x509_crl_t crl, uint64_t* time_since_epoch) {
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}
1103
1105 botan_rng_t rng,
1106 botan_x509_cert_t ca_cert,
1107 botan_privkey_t ca_key,
1108 uint64_t issue_time,
1109 uint32_t next_update,
1110 const char* hash_fn,
1111 const char* padding) {
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}
1129
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}
1144
1146 botan_x509_crl_t last_crl,
1147 botan_rng_t rng,
1148 botan_x509_cert_t ca_cert,
1149 botan_privkey_t ca_key,
1150 uint64_t issue_time,
1151 uint32_t next_update,
1152 const botan_x509_crl_entry_t* new_entries,
1153 size_t new_entries_len,
1154 const char* hash_fn,
1155 const char* padding) {
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}
1184
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}
1193
1195#if defined(BOTAN_HAS_X509_CERTIFICATES)
1197#else
1200#endif
1201}
1202
1204 botan_x509_value_type value_type,
1205 size_t index,
1206 botan_view_ctx ctx,
1207 botan_view_bin_fn view_fn) {
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}
1261
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}
1273
1275 botan_x509_value_type value_type,
1276 size_t index,
1277 botan_view_ctx ctx,
1278 botan_view_str_fn view) {
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}
1308
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}
1320
1322 botan_x509_crl_t crl, const char* key, size_t index, botan_view_ctx ctx, botan_view_str_fn view) {
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}
1341
1342int botan_x509_crl_view_issuer_dn_count(botan_x509_crl_t crl, const char* key, size_t* count) {
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}
1358
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}
1368
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}
1388
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}
1401
1403#if defined(BOTAN_HAS_X509_CERTIFICATES)
1404 return BOTAN_FFI_CHECKED_DELETE(entry);
1405#else
1406 BOTAN_UNUSED(entry);
1408#endif
1409}
1410
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}
1426
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}
1442
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}
1452
1453int botan_x509_crl_entry_revocation_date(botan_x509_crl_entry_t entry, uint64_t* time_since_epoch) {
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}
1468
1470 botan_x509_cert_t cert,
1471 const botan_x509_cert_t* intermediates,
1472 size_t intermediates_len,
1473 const botan_x509_cert_t* trusted,
1474 size_t trusted_len,
1475 const botan_x509_crl_t* crls,
1476 size_t crls_len,
1477 const char* trusted_path,
1478 size_t required_strength,
1479 const char* hostname_cstr,
1480 uint64_t reference_time) {
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}
1556}
#define BOTAN_UNUSED
Definition assert.h:151
#define BOTAN_ASSERT_UNREACHABLE()
Definition assert.h:173
uint64_t time_since_epoch() const
Return time since epoch.
const std::set< IPv6Address > & ipv6_addresses() const
Return the set of IPv6 addresses included in this alternative name.
Definition pkix_types.h:421
const std::set< DNSName > & dns_names() const
Return the set of DNS names included in this alternative name.
Definition pkix_types.h:407
const std::set< X509_DN > & directory_names() const
Return the set of directory names included in this alternative name.
Definition pkix_types.h:441
const std::set< EmailAddress > & email_addresses() const
Return the set of email addresses included in this alternative name.
Definition pkix_types.h:398
const std::set< IPv4Address > & ipv4_addresses() const
Return the set of IPv4 addresses included in this alternative name.
Definition pkix_types.h:418
const std::set< URI > & uri_names() const
Return the set of URIs included in this alternative name.
Definition pkix_types.h:389
Definition x509_crl.h:32
CRL_Code reason_code() const
Definition crl_ent.cpp:148
const X509_Serial_Number & serial() const
Definition crl_ent.cpp:140
const X509_Time & expire_time() const
Definition crl_ent.cpp:144
const std::vector< uint8_t > & serial_number() const
Definition crl_ent.cpp:136
bool extension_set(const OID &oid) const
Definition x509_ext.cpp:225
X.509 GeneralName Type.
Definition pkix_types.h:541
static GeneralName email(std::string_view email)
static GeneralName ipv4_address(uint32_t ipv4)
static GeneralName _dns_san_value(std::string_view dns)
std::vector< uint8_t > binary_name() const
std::string name() const
static GeneralName ipv6_address(const IPv6Address &ipv6)
NameType type_code() const
Definition pkix_types.h:594
static GeneralName _uri_san_value(std::string_view full_uri)
static GeneralName directory_name(Botan::X509_DN dn)
const std::vector< GeneralSubtree > & permitted() const
Definition pkix_types.h:766
const std::vector< GeneralSubtree > & excluded() const
Definition pkix_types.h:773
static OID from_string(std::string_view str)
Definition asn1_oid.cpp:80
const std::vector< CRL_Entry > & get_revoked() const
Definition x509_crl.cpp:260
const NameConstraints & name_constraints() const
Definition x509cert.cpp:513
const std::vector< uint8_t > & serial_number() const
Definition x509cert.cpp:438
const std::vector< URI > & ocsp_responder_uris() const
Definition x509cert.cpp:639
const X509_Serial_Number & serial() const
Definition x509cert.cpp:442
const std::vector< uint8_t > & authority_key_id() const
Definition x509cert.cpp:430
const AlternativeName & issuer_alt_name() const
Definition x509cert.cpp:690
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 Extensions & v3_extensions() const
Definition x509cert.cpp:517
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
const std::vector< uint8_t > & raw_issuer_dn() const
Definition x509cert.cpp:462
const AlternativeName & subject_alt_name() const
Definition x509cert.cpp:686
const std::vector< uint8_t > & subject_public_key_info() const
Definition x509cert.cpp:410
struct botan_pubkey_struct * botan_pubkey_t
Definition ffi.h:2224
struct botan_asn1_oid_struct * botan_asn1_oid_t
Definition ffi.h:1484
struct botan_privkey_struct * botan_privkey_t
Definition ffi.h:1874
struct botan_x509_crl_entry_struct * botan_x509_crl_entry_t
Definition ffi.h:4216
struct botan_x509_crl_struct * botan_x509_crl_t
Definition ffi.h:4211
struct botan_x509_general_name_struct * botan_x509_general_name_t
Definition ffi.h:3969
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(* botan_view_bin_fn)(botan_view_ctx view_ctx, const uint8_t *data, size_t len)
Definition ffi.h:161
struct botan_x509_cert_struct * botan_x509_cert_t
Definition ffi.h:3608
@ BOTAN_X509_DNS_NAME
Definition ffi.h:3979
@ BOTAN_X509_DIRECTORY_NAME
Definition ffi.h:3980
@ BOTAN_X509_OTHER_NAME
Definition ffi.h:3977
@ BOTAN_X509_EMAIL_ADDRESS
Definition ffi.h:3978
@ BOTAN_X509_IP_ADDRESS
Definition ffi.h:3982
@ BOTAN_X509_URI
Definition ffi.h:3981
struct botan_mp_struct * botan_mp_t
Definition ffi.h:1109
void * botan_view_ctx
Definition ffi.h:152
struct botan_rng_struct * botan_rng_t
Definition ffi.h:343
@ BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition ffi.h:138
@ BOTAN_FFI_ERROR_OUT_OF_RANGE
Definition ffi.h:136
@ BOTAN_FFI_ERROR_NULL_POINTER
Definition ffi.h:131
@ BOTAN_FFI_SUCCESS
Definition ffi.h:114
@ BOTAN_FFI_ERROR_NO_VALUE
Definition ffi.h:120
@ BOTAN_FFI_ERROR_INVALID_OBJECT_STATE
Definition ffi.h:135
@ BOTAN_FFI_ERROR_BAD_PARAMETER
Definition ffi.h:132
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(* botan_view_str_fn)(botan_view_ctx view_ctx, const char *str, size_t len)
Definition ffi.h:170
botan_x509_value_type
Definition ffi.h:3623
@ 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
int botan_x509_cert_get_subject_dn_count(botan_x509_cert_t cert, const char *key, size_t *count)
Definition ffi_cert.cpp:513
int botan_x509_is_revoked(botan_x509_crl_t crl, botan_x509_cert_t cert)
int botan_x509_crl_destroy(botan_x509_crl_t crl)
int botan_x509_cert_destroy(botan_x509_cert_t cert)
Definition ffi_cert.cpp:581
int botan_x509_cert_load_file(botan_x509_cert_t *cert_obj, const char *cert_path)
Definition ffi_cert.cpp:175
int botan_x509_crl_entry_serial_number(botan_x509_crl_entry_t entry, botan_mp_t *serial_number)
int botan_x509_general_name_destroy(botan_x509_general_name_t name)
Definition ffi_cert.cpp:777
int botan_x509_cert_dup(botan_x509_cert_t *cert_obj, botan_x509_cert_t cert)
Definition ffi_cert.cpp:192
int botan_x509_crl_next_update(botan_x509_crl_t crl, uint64_t *time_since_epoch)
int botan_x509_cert_get_issuer_dn_count(botan_x509_cert_t cert, const char *key, size_t *count)
Definition ffi_cert.cpp:476
int botan_x509_crl_entry_destroy(botan_x509_crl_entry_t entry)
int botan_x509_cert_issuer_alternative_names_count(botan_x509_cert_t cert, size_t *count)
Definition ffi_cert.cpp:920
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_crl_view_binary_values_count(botan_x509_crl_t crl_obj, botan_x509_value_type value_type, size_t *count)
int botan_x509_general_name_view_binary_value(botan_x509_general_name_t name, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_cert.cpp:755
int botan_x509_crl_this_update(botan_x509_crl_t crl, uint64_t *time_since_epoch)
int botan_x509_cert_view_binary_values_count(botan_x509_cert_t cert, botan_x509_value_type value_type, size_t *count)
Definition ffi_cert.cpp:338
int botan_x509_crl_view_issuer_dn_count(botan_x509_crl_t crl, const char *key, size_t *count)
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_cert_get_public_key(botan_x509_cert_t cert, botan_pubkey_t *key)
Definition ffi_cert.cpp:437
int botan_x509_cert_allowed_extended_usage_oid(botan_x509_cert_t cert, botan_asn1_oid_t oid)
Definition ffi_cert.cpp:572
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
const char * botan_x509_cert_validation_status(int code)
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_cert_get_authority_key_id(botan_x509_cert_t cert, uint8_t out[], size_t *out_len)
Definition ffi_cert.cpp:675
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 ffi_cert.cpp:455
int botan_x509_cert_subject_alternative_names_count(botan_x509_cert_t cert, size_t *count)
Definition ffi_cert.cpp:881
int botan_x509_cert_excluded_name_constraints(botan_x509_cert_t cert, size_t index, botan_x509_general_name_t *constraint)
Definition ffi_cert.cpp:821
int botan_x509_crl_entries_count(botan_x509_crl_t crl, size_t *count)
int botan_x509_crl_entries(botan_x509_crl_t crl, size_t index, botan_x509_crl_entry_t *entry)
int botan_x509_cert_subject_alternative_names(botan_x509_cert_t cert, size_t index, botan_x509_general_name_t *alt_name)
Definition ffi_cert.cpp:856
int botan_x509_crl_entry_revocation_date(botan_x509_crl_entry_t entry, uint64_t *time_since_epoch)
int botan_x509_cert_issuer_alternative_names(botan_x509_cert_t cert, size_t index, botan_x509_general_name_t *alt_name)
Definition ffi_cert.cpp:895
int botan_x509_cert_serial_number(botan_x509_cert_t cert, botan_mp_t *serial_number)
Definition ffi_cert.cpp:643
int botan_x509_cert_get_time_expires(botan_x509_cert_t cert, char out[], size_t *out_len)
Definition ffi_cert.cpp:600
int botan_x509_cert_permitted_name_constraints(botan_x509_cert_t cert, size_t index, botan_x509_general_name_t *constraint)
Definition ffi_cert.cpp:786
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_cert_view_as_string(botan_x509_cert_t cert, botan_view_ctx ctx, botan_view_str_fn view)
Definition ffi_cert.cpp:533
int botan_x509_cert_get_time_starts(botan_x509_cert_t cert, char out[], size_t *out_len)
Definition ffi_cert.cpp:590
int botan_x509_cert_load(botan_x509_cert_t *cert_obj, const uint8_t cert_bits[], size_t cert_bits_len)
Definition ffi_cert.cpp:210
int botan_x509_crl_load(botan_x509_crl_t *crl_obj, const uint8_t crl_bits[], size_t crl_bits_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)
Definition ffi_cert.cpp:492
int botan_x509_cert_not_before(botan_x509_cert_t cert, uint64_t *time_since_epoch)
Definition ffi_cert.cpp:610
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_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)
Definition ffi_cert.cpp:947
int botan_x509_cert_excluded_name_constraints_count(botan_x509_cert_t cert, size_t *count)
Definition ffi_cert.cpp:843
int botan_x509_cert_is_ca(botan_x509_cert_t cert)
Definition ffi_cert.cpp:408
int botan_x509_cert_hostname_match(botan_x509_cert_t cert, const char *hostname)
Definition ffi_cert.cpp:934
int botan_x509_crl_entry_create(botan_x509_crl_entry_t *entry, botan_x509_cert_t cert, int reason_code)
int botan_x509_cert_get_serial_number(botan_x509_cert_t cert, uint8_t out[], size_t *out_len)
Definition ffi_cert.cpp:634
int botan_x509_cert_get_subject_key_id(botan_x509_cert_t cert, uint8_t out[], size_t *out_len)
Definition ffi_cert.cpp:684
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_cert_allowed_extended_usage_str(botan_x509_cert_t cert, const char *oid)
Definition ffi_cert.cpp:557
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 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_verify_signature(botan_x509_crl_t crl, botan_pubkey_t key)
int botan_x509_crl_load_file(botan_x509_crl_t *crl_obj, const char *crl_path)
int botan_x509_cert_allowed_usage(botan_x509_cert_t cert, unsigned int key_usage)
Definition ffi_cert.cpp:542
int botan_x509_cert_view_string_values_count(botan_x509_cert_t cert, botan_x509_value_type value_type, size_t *count)
Definition ffi_cert.cpp:396
int botan_x509_cert_not_after(botan_x509_cert_t cert, uint64_t *time_since_epoch)
Definition ffi_cert.cpp:622
int botan_x509_general_name_view_string_value(botan_x509_general_name_t name, botan_view_ctx ctx, botan_view_str_fn view)
Definition ffi_cert.cpp:732
int botan_x509_crl_entry_reason(botan_x509_crl_entry_t entry, int *reason_code)
int botan_x509_cert_get_public_key_bits(botan_x509_cert_t cert, uint8_t out[], size_t *out_len)
Definition ffi_cert.cpp:693
int botan_x509_cert_get_fingerprint(botan_x509_cert_t cert, const char *hash, uint8_t out[], size_t *out_len)
Definition ffi_cert.cpp:659
int botan_x509_cert_get_path_length_constraint(botan_x509_cert_t cert, size_t *path_limit)
Definition ffi_cert.cpp:417
int botan_x509_cert_to_string(botan_x509_cert_t cert, char out[], size_t *out_len)
Definition ffi_cert.cpp:529
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_get_type(botan_x509_general_name_t name, unsigned int *type)
Definition ffi_cert.cpp:707
int botan_x509_cert_permitted_name_constraints_count(botan_x509_cert_t cert, size_t *count)
Definition ffi_cert.cpp:808
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
botan_x509_crl_t crl
Definition ffi_tls.h:127
const char * name
Definition ffi_tls.h:59
#define BOTAN_FFI_VISIT(obj, lambda)
Definition ffi_util.h:327
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition ffi_util.h:357
std::vector< uint8_t > put_in_sequence(const std::vector< uint8_t > &contents)
Definition asn1_obj.cpp:208
std::vector< uint8_t > BER_encode(const Private_Key &key, RandomNumberGenerator &rng, std::string_view pass, std::chrono::milliseconds msec, std::string_view pbe_algo)
Definition pkcs8.cpp:168
std::string PEM_encode(const Private_Key &key)
Definition pkcs8.cpp:122
int invoke_view_callback(botan_view_bin_fn view, botan_view_ctx ctx, std::span< const uint8_t > buf)
Definition ffi_util.h:359
int copy_view_bin(uint8_t out[], size_t *out_len, Fn fn, Args... args)
Definition ffi_util.h:383
auto safe_get(T *p) -> typename T::element_type &
Definition ffi_util.h:191
BOTAN_FFI_ERROR ffi_new_object(T *obj, Args &&... args)
Definition ffi_util.h:347
int copy_view_str(uint8_t out[], size_t *out_len, Fn fn, Args... args)
Definition ffi_util.h:392
int ffi_guard_thunk(const char *func_name, T thunk)
Definition ffi_util.h:229
int write_vec_output(uint8_t out[], size_t *out_len, std::span< const uint8_t > buf)
Definition ffi_util.h:436
int write_str_output(char out[], size_t *out_len, const std::string &str)
Definition ffi_util.h:440
Certificate_Status_Code
Definition pkix_enums.h:21
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)
std::string to_string(ErrorType type)
Convert an ErrorType to string.
Definition exceptn.cpp:13
bool any_null_pointers(Ptrs... ptr)
Definition mem_utils.h:54