Botan 3.6.1
Crypto and TLS for C&
x509_ext.cpp
Go to the documentation of this file.
1/*
2* X.509 Certificate Extensions
3* (C) 1999-2010,2012 Jack Lloyd
4* (C) 2016 René Korthaus, Rohde & Schwarz Cybersecurity
5* (C) 2017 Fabian Weissberg, Rohde & Schwarz Cybersecurity
6*
7* Botan is released under the Simplified BSD License (see license.txt)
8*/
9
10#include <botan/x509_ext.h>
11
12#include <botan/ber_dec.h>
13#include <botan/der_enc.h>
14#include <botan/hash.h>
15#include <botan/x509cert.h>
16#include <botan/internal/bit_ops.h>
17#include <botan/internal/fmt.h>
18#include <botan/internal/loadstor.h>
19#include <algorithm>
20#include <set>
21#include <sstream>
22
23namespace Botan {
24
25namespace {
26
27std::unique_ptr<Certificate_Extension> extension_from_oid(const OID& oid) {
29 return std::make_unique<Cert_Extension::Subject_Key_ID>();
30 }
31
33 return std::make_unique<Cert_Extension::Key_Usage>();
34 }
35
37 return std::make_unique<Cert_Extension::Subject_Alternative_Name>();
38 }
39
41 return std::make_unique<Cert_Extension::Issuer_Alternative_Name>();
42 }
43
45 return std::make_unique<Cert_Extension::Basic_Constraints>();
46 }
47
49 return std::make_unique<Cert_Extension::CRL_Number>();
50 }
51
53 return std::make_unique<Cert_Extension::CRL_ReasonCode>();
54 }
55
57 return std::make_unique<Cert_Extension::Authority_Key_ID>();
58 }
59
61 return std::make_unique<Cert_Extension::Name_Constraints>();
62 }
63
65 return std::make_unique<Cert_Extension::CRL_Distribution_Points>();
66 }
67
69 return std::make_unique<Cert_Extension::CRL_Issuing_Distribution_Point>();
70 }
71
73 return std::make_unique<Cert_Extension::Certificate_Policies>();
74 }
75
77 return std::make_unique<Cert_Extension::Extended_Key_Usage>();
78 }
79
81 return std::make_unique<Cert_Extension::Authority_Information_Access>();
82 }
83
85 return std::make_unique<Cert_Extension::TNAuthList>();
86 }
87
88 return nullptr; // unknown
89}
90
91bool is_valid_telephone_number(const ASN1_String& tn) {
92 //TelephoneNumber ::= IA5String (SIZE (1..15)) (FROM ("0123456789#*"))
93 static std::string valid_tn_chars("0123456789#*");
94
95 if(tn.empty() || (tn.size() > 15)) {
96 return false;
97 }
98
99 if(tn.value().find_first_not_of(valid_tn_chars) != std::string::npos) {
100 return false;
101 }
102
103 return true;
104}
105
106} // namespace
107
108/*
109* Create a Certificate_Extension object of some kind to handle
110*/
111std::unique_ptr<Certificate_Extension> Extensions::create_extn_obj(const OID& oid,
112 bool critical,
113 const std::vector<uint8_t>& body) {
114 auto extn = extension_from_oid(oid);
115
116 if(!extn) {
117 // some other unknown extension type
118 extn = std::make_unique<Cert_Extension::Unknown_Extension>(oid, critical);
119 }
120
121 try {
122 extn->decode_inner(body);
123 } catch(Decoding_Error&) {
124 extn = std::make_unique<Cert_Extension::Unknown_Extension>(oid, critical);
125 extn->decode_inner(body);
126 }
127 return extn;
128}
129
130/*
131* Validate the extension (the default implementation is a NOP)
132*/
134 const X509_Certificate& /*unused*/,
135 const std::vector<X509_Certificate>& /*unused*/,
136 std::vector<std::set<Certificate_Status_Code>>& /*unused*/,
137 size_t /*unused*/) {}
138
139/*
140* Add a new cert
141*/
142void Extensions::add(std::unique_ptr<Certificate_Extension> extn, bool critical) {
143 // sanity check: we don't want to have the same extension more than once
144 if(m_extension_info.contains(extn->oid_of())) {
145 const std::string name = extn->oid_name();
146 throw Invalid_Argument("Extension " + name + " already present in Extensions::add");
147 }
148
149 const OID oid = extn->oid_of();
150 Extensions_Info info(critical, std::move(extn));
151 m_extension_oids.push_back(oid);
152 m_extension_info.emplace(oid, info);
153}
154
155bool Extensions::add_new(std::unique_ptr<Certificate_Extension> extn, bool critical) {
156 if(m_extension_info.contains(extn->oid_of())) {
157 return false; // already exists
158 }
159
160 const OID oid = extn->oid_of();
161 Extensions_Info info(critical, std::move(extn));
162 m_extension_oids.push_back(oid);
163 m_extension_info.emplace(oid, info);
164 return true;
165}
166
167bool Extensions::remove(const OID& oid) {
168 const bool erased = m_extension_info.erase(oid) > 0;
169
170 if(erased) {
171 m_extension_oids.erase(std::find(m_extension_oids.begin(), m_extension_oids.end(), oid));
172 }
173
174 return erased;
175}
176
177void Extensions::replace(std::unique_ptr<Certificate_Extension> extn, bool critical) {
178 // Remove it if it existed
179 remove(extn->oid_of());
180
181 const OID oid = extn->oid_of();
182 Extensions_Info info(critical, std::move(extn));
183 m_extension_oids.push_back(oid);
184 m_extension_info.emplace(oid, info);
185}
186
187bool Extensions::extension_set(const OID& oid) const {
188 return (m_extension_info.find(oid) != m_extension_info.end());
189}
190
192 auto i = m_extension_info.find(oid);
193 if(i != m_extension_info.end()) {
194 return i->second.is_critical();
195 }
196 return false;
197}
198
199std::vector<uint8_t> Extensions::get_extension_bits(const OID& oid) const {
200 auto i = m_extension_info.find(oid);
201 if(i == m_extension_info.end()) {
202 throw Invalid_Argument("Extensions::get_extension_bits no such extension set");
203 }
204
205 return i->second.bits();
206}
207
209 auto extn = m_extension_info.find(oid);
210 if(extn == m_extension_info.end()) {
211 return nullptr;
212 }
213
214 return &extn->second.obj();
215}
216
217std::unique_ptr<Certificate_Extension> Extensions::get(const OID& oid) const {
218 if(const Certificate_Extension* ext = this->get_extension_object(oid)) {
219 return ext->copy();
220 }
221 return nullptr;
222}
223
224std::vector<std::pair<std::unique_ptr<Certificate_Extension>, bool>> Extensions::extensions() const {
225 std::vector<std::pair<std::unique_ptr<Certificate_Extension>, bool>> exts;
226 exts.reserve(m_extension_info.size());
227 for(auto&& ext : m_extension_info) {
228 exts.push_back(std::make_pair(ext.second.obj().copy(), ext.second.is_critical()));
229 }
230 return exts;
231}
232
233std::map<OID, std::pair<std::vector<uint8_t>, bool>> Extensions::extensions_raw() const {
234 std::map<OID, std::pair<std::vector<uint8_t>, bool>> out;
235 for(auto&& ext : m_extension_info) {
236 out.emplace(ext.first, std::make_pair(ext.second.bits(), ext.second.is_critical()));
237 }
238 return out;
239}
240
241/*
242* Encode an Extensions list
243*/
244void Extensions::encode_into(DER_Encoder& to_object) const {
245 for(const auto& ext_info : m_extension_info) {
246 const OID& oid = ext_info.first;
247 const bool should_encode = ext_info.second.obj().should_encode();
248
249 if(should_encode) {
250 const bool is_critical = ext_info.second.is_critical();
251 const std::vector<uint8_t>& ext_value = ext_info.second.bits();
252
253 to_object.start_sequence()
254 .encode(oid)
255 .encode_optional(is_critical, false)
256 .encode(ext_value, ASN1_Type::OctetString)
257 .end_cons();
258 }
259 }
260}
261
262/*
263* Decode a list of Extensions
264*/
266 m_extension_oids.clear();
267 m_extension_info.clear();
268
269 BER_Decoder sequence = from_source.start_sequence();
270
271 while(sequence.more_items()) {
272 OID oid;
273 bool critical;
274 std::vector<uint8_t> bits;
275
276 sequence.start_sequence()
277 .decode(oid)
280 .end_cons();
281
282 auto obj = create_extn_obj(oid, critical, bits);
283 Extensions_Info info(critical, bits, std::move(obj));
284
285 m_extension_oids.push_back(oid);
286 m_extension_info.emplace(oid, info);
287 }
288 sequence.verify_end();
289}
290
291namespace Cert_Extension {
292
293/*
294* Checked accessor for the path_limit member
295*/
297 if(!m_is_ca) {
298 throw Invalid_State("Basic_Constraints::get_path_limit: Not a CA");
299 }
300 return m_path_limit;
301}
302
303/*
304* Encode the extension
305*/
306std::vector<uint8_t> Basic_Constraints::encode_inner() const {
307 std::vector<uint8_t> output;
308 DER_Encoder(output)
310 .encode_if(m_is_ca, DER_Encoder().encode(m_is_ca).encode_optional(m_path_limit, NO_CERT_PATH_LIMIT))
311 .end_cons();
312 return output;
313}
314
315/*
316* Decode the extension
317*/
318void Basic_Constraints::decode_inner(const std::vector<uint8_t>& in) {
319 BER_Decoder(in)
322 .decode_optional(m_path_limit, ASN1_Type::Integer, ASN1_Class::Universal, NO_CERT_PATH_LIMIT)
323 .end_cons();
324
325 if(m_is_ca == false) {
326 m_path_limit = 0;
327 }
328}
329
330/*
331* Encode the extension
332*/
333std::vector<uint8_t> Key_Usage::encode_inner() const {
334 if(m_constraints.empty()) {
335 throw Encoding_Error("Cannot encode empty PKIX key constraints");
336 }
337
338 const size_t constraint_bits = m_constraints.value();
339 const size_t unused_bits = ctz(static_cast<uint32_t>(constraint_bits));
340
341 std::vector<uint8_t> der;
342 der.push_back(static_cast<uint8_t>(ASN1_Type::BitString));
343 der.push_back(2 + ((unused_bits < 8) ? 1 : 0));
344 der.push_back(unused_bits % 8);
345 der.push_back((constraint_bits >> 8) & 0xFF);
346 if(constraint_bits & 0xFF) {
347 der.push_back(constraint_bits & 0xFF);
348 }
349
350 return der;
351}
352
353/*
354* Decode the extension
355*/
356void Key_Usage::decode_inner(const std::vector<uint8_t>& in) {
357 BER_Decoder ber(in);
358
359 BER_Object obj = ber.get_next_object();
360
361 obj.assert_is_a(ASN1_Type::BitString, ASN1_Class::Universal, "usage constraint");
362
363 if(obj.length() == 2 || obj.length() == 3) {
364 uint16_t usage = 0;
365
366 const uint8_t* bits = obj.bits();
367
368 if(bits[0] >= 8) {
369 throw BER_Decoding_Error("Invalid unused bits in usage constraint");
370 }
371
372 const uint8_t mask = static_cast<uint8_t>(0xFF << bits[0]);
373
374 if(obj.length() == 2) {
375 usage = make_uint16(bits[1] & mask, 0);
376 } else if(obj.length() == 3) {
377 usage = make_uint16(bits[1], bits[2] & mask);
378 }
379
380 m_constraints = Key_Constraints(usage);
381 } else {
382 m_constraints = Key_Constraints(0);
383 }
384}
385
386/*
387* Encode the extension
388*/
389std::vector<uint8_t> Subject_Key_ID::encode_inner() const {
390 std::vector<uint8_t> output;
391 DER_Encoder(output).encode(m_key_id, ASN1_Type::OctetString);
392 return output;
393}
394
395/*
396* Decode the extension
397*/
398void Subject_Key_ID::decode_inner(const std::vector<uint8_t>& in) {
399 BER_Decoder(in).decode(m_key_id, ASN1_Type::OctetString).verify_end();
400}
401
402/*
403* Subject_Key_ID Constructor
404*/
405Subject_Key_ID::Subject_Key_ID(const std::vector<uint8_t>& pub_key, std::string_view hash_name) {
406 auto hash = HashFunction::create_or_throw(hash_name);
407
408 m_key_id.resize(hash->output_length());
409
410 hash->update(pub_key);
411 hash->final(m_key_id.data());
412
413 // Truncate longer hashes, 192 bits here seems plenty
414 const size_t max_skid_len = (192 / 8);
415 if(m_key_id.size() > max_skid_len) {
416 m_key_id.resize(max_skid_len);
417 }
418}
419
420/*
421* Encode the extension
422*/
423std::vector<uint8_t> Authority_Key_ID::encode_inner() const {
424 std::vector<uint8_t> output;
425 DER_Encoder(output)
428 .end_cons();
429 return output;
430}
431
432/*
433* Decode the extension
434*/
435void Authority_Key_ID::decode_inner(const std::vector<uint8_t>& in) {
437}
438
439/*
440* Encode the extension
441*/
442std::vector<uint8_t> Subject_Alternative_Name::encode_inner() const {
443 std::vector<uint8_t> output;
444 DER_Encoder(output).encode(m_alt_name);
445 return output;
446}
447
448/*
449* Encode the extension
450*/
451std::vector<uint8_t> Issuer_Alternative_Name::encode_inner() const {
452 std::vector<uint8_t> output;
453 DER_Encoder(output).encode(m_alt_name);
454 return output;
455}
456
457/*
458* Decode the extension
459*/
460void Subject_Alternative_Name::decode_inner(const std::vector<uint8_t>& in) {
461 BER_Decoder(in).decode(m_alt_name);
462}
463
464/*
465* Decode the extension
466*/
467void Issuer_Alternative_Name::decode_inner(const std::vector<uint8_t>& in) {
468 BER_Decoder(in).decode(m_alt_name);
469}
470
471/*
472* Encode the extension
473*/
474std::vector<uint8_t> Extended_Key_Usage::encode_inner() const {
475 std::vector<uint8_t> output;
476 DER_Encoder(output).start_sequence().encode_list(m_oids).end_cons();
477 return output;
478}
479
480/*
481* Decode the extension
482*/
483void Extended_Key_Usage::decode_inner(const std::vector<uint8_t>& in) {
484 BER_Decoder(in).decode_list(m_oids);
485}
486
487/*
488* Encode the extension
489*/
490std::vector<uint8_t> Name_Constraints::encode_inner() const {
491 throw Not_Implemented("Name_Constraints encoding");
492}
493
494/*
495* Decode the extension
496*/
497void Name_Constraints::decode_inner(const std::vector<uint8_t>& in) {
498 BER_Decoder ber(in);
499 BER_Decoder inner = ber.start_sequence();
500
501 std::vector<GeneralSubtree> permitted;
502 if(inner.decode_optional_list(permitted, ASN1_Type(0), ASN1_Class::ExplicitContextSpecific)) {
503 if(permitted.empty()) {
504 throw Decoding_Error("Empty NameConstraint permitted list");
505 }
506 }
507
508 std::vector<GeneralSubtree> excluded;
509 if(inner.decode_optional_list(excluded, ASN1_Type(1), ASN1_Class::ExplicitContextSpecific)) {
510 if(excluded.empty()) {
511 throw Decoding_Error("Empty NameConstraint excluded list");
512 }
513 }
514
515 inner.end_cons();
516
517 if(permitted.empty() && excluded.empty()) {
518 throw Decoding_Error("Empty NameConstraint extension");
519 }
520
521 m_name_constraints = NameConstraints(std::move(permitted), std::move(excluded));
522}
523
525 const X509_Certificate& /*issuer*/,
526 const std::vector<X509_Certificate>& cert_path,
527 std::vector<std::set<Certificate_Status_Code>>& cert_status,
528 size_t pos) {
529 if(!m_name_constraints.permitted().empty() || !m_name_constraints.excluded().empty()) {
530 if(!subject.is_CA_cert()) {
531 cert_status.at(pos).insert(Certificate_Status_Code::NAME_CONSTRAINT_ERROR);
532 }
533
534 const bool issuer_name_constraint_critical = subject.is_critical("X509v3.NameConstraints");
535
536 // Check that all subordinate certs pass the name constraint
537 for(size_t j = 0; j < pos; ++j) {
538 const auto& cert = cert_path.at(j);
539
540 if(!m_name_constraints.is_permitted(cert, issuer_name_constraint_critical)) {
541 cert_status.at(j).insert(Certificate_Status_Code::NAME_CONSTRAINT_ERROR);
542 continue;
543 }
544
545 if(m_name_constraints.is_excluded(cert, issuer_name_constraint_critical)) {
546 cert_status.at(j).insert(Certificate_Status_Code::NAME_CONSTRAINT_ERROR);
547 continue;
548 }
549 }
550 }
551}
552
553namespace {
554
555/*
556* A policy specifier
557*/
558class Policy_Information final : public ASN1_Object {
559 public:
560 Policy_Information() = default;
561
562 explicit Policy_Information(const OID& oid) : m_oid(oid) {}
563
564 const OID& oid() const { return m_oid; }
565
566 void encode_into(DER_Encoder& codec) const override { codec.start_sequence().encode(m_oid).end_cons(); }
567
568 void decode_from(BER_Decoder& codec) override {
569 codec.start_sequence().decode(m_oid).discard_remaining().end_cons();
570 }
571
572 private:
573 OID m_oid;
574};
575
576} // namespace
577
578/*
579* Encode the extension
580*/
581std::vector<uint8_t> Certificate_Policies::encode_inner() const {
582 std::vector<Policy_Information> policies;
583
584 policies.reserve(m_oids.size());
585 for(const auto& oid : m_oids) {
586 policies.push_back(Policy_Information(oid));
587 }
588
589 std::vector<uint8_t> output;
590 DER_Encoder(output).start_sequence().encode_list(policies).end_cons();
591 return output;
592}
593
594/*
595* Decode the extension
596*/
597void Certificate_Policies::decode_inner(const std::vector<uint8_t>& in) {
598 std::vector<Policy_Information> policies;
599
600 BER_Decoder(in).decode_list(policies);
601 m_oids.clear();
602 for(const auto& policy : policies) {
603 m_oids.push_back(policy.oid());
604 }
605}
606
608 const X509_Certificate& /*issuer*/,
609 const std::vector<X509_Certificate>& /*cert_path*/,
610 std::vector<std::set<Certificate_Status_Code>>& cert_status,
611 size_t pos) {
612 std::set<OID> oid_set(m_oids.begin(), m_oids.end());
613 if(oid_set.size() != m_oids.size()) {
614 cert_status.at(pos).insert(Certificate_Status_Code::DUPLICATE_CERT_POLICY);
615 }
616}
617
618std::vector<uint8_t> Authority_Information_Access::encode_inner() const {
619 std::vector<uint8_t> output;
620 DER_Encoder der(output);
621
622 der.start_sequence();
623 // OCSP
624 if(!m_ocsp_responder.empty()) {
625 ASN1_String url(m_ocsp_responder, ASN1_Type::Ia5String);
626 der.start_sequence()
627 .encode(OID::from_string("PKIX.OCSP"))
628 .add_object(ASN1_Type(6), ASN1_Class::ContextSpecific, url.value())
629 .end_cons();
630 }
631
632 // CA Issuers
633 for(const auto& ca_isser : m_ca_issuers) {
634 ASN1_String asn1_ca_issuer(ca_isser, ASN1_Type::Ia5String);
635 der.start_sequence()
636 .encode(OID::from_string("PKIX.CertificateAuthorityIssuers"))
637 .add_object(ASN1_Type(6), ASN1_Class::ContextSpecific, asn1_ca_issuer.value())
638 .end_cons();
639 }
640
641 der.end_cons();
642 return output;
643}
644
645void Authority_Information_Access::decode_inner(const std::vector<uint8_t>& in) {
646 BER_Decoder ber = BER_Decoder(in).start_sequence();
647
648 while(ber.more_items()) {
649 OID oid;
650
651 BER_Decoder info = ber.start_sequence();
652
653 info.decode(oid);
654
655 if(oid == OID::from_string("PKIX.OCSP")) {
656 BER_Object name = info.get_next_object();
657
658 if(name.is_a(6, ASN1_Class::ContextSpecific)) {
659 m_ocsp_responder = ASN1::to_string(name);
660 }
661 }
662 if(oid == OID::from_string("PKIX.CertificateAuthorityIssuers")) {
663 BER_Object name = info.get_next_object();
664
665 if(name.is_a(6, ASN1_Class::ContextSpecific)) {
666 m_ca_issuers.push_back(ASN1::to_string(name));
667 }
668 }
669 }
670}
671
672/*
673* Checked accessor for the crl_number member
674*/
676 if(!m_has_value) {
677 throw Invalid_State("CRL_Number::get_crl_number: Not set");
678 }
679 return m_crl_number;
680}
681
682/*
683* Copy a CRL_Number extension
684*/
685std::unique_ptr<Certificate_Extension> CRL_Number::copy() const {
686 if(!m_has_value) {
687 throw Invalid_State("CRL_Number::copy: Not set");
688 }
689 return std::make_unique<CRL_Number>(m_crl_number);
690}
691
692/*
693* Encode the extension
694*/
695std::vector<uint8_t> CRL_Number::encode_inner() const {
696 std::vector<uint8_t> output;
697 DER_Encoder(output).encode(m_crl_number);
698 return output;
699}
700
701/*
702* Decode the extension
703*/
704void CRL_Number::decode_inner(const std::vector<uint8_t>& in) {
705 BER_Decoder(in).decode(m_crl_number);
706 m_has_value = true;
707}
708
709/*
710* Encode the extension
711*/
712std::vector<uint8_t> CRL_ReasonCode::encode_inner() const {
713 std::vector<uint8_t> output;
714 DER_Encoder(output).encode(static_cast<size_t>(m_reason), ASN1_Type::Enumerated, ASN1_Class::Universal);
715 return output;
716}
717
718/*
719* Decode the extension
720*/
721void CRL_ReasonCode::decode_inner(const std::vector<uint8_t>& in) {
722 size_t reason_code = 0;
723 BER_Decoder(in).decode(reason_code, ASN1_Type::Enumerated, ASN1_Class::Universal);
724 m_reason = static_cast<CRL_Code>(reason_code);
725}
726
727std::vector<uint8_t> CRL_Distribution_Points::encode_inner() const {
728 std::vector<uint8_t> output;
729 DER_Encoder(output).start_sequence().encode_list(m_distribution_points).end_cons();
730 return output;
731}
732
733void CRL_Distribution_Points::decode_inner(const std::vector<uint8_t>& buf) {
734 BER_Decoder(buf).decode_list(m_distribution_points).verify_end();
735
736 std::stringstream ss;
737
738 for(const auto& distribution_point : m_distribution_points) {
739 auto contents = distribution_point.point().contents();
740
741 for(const auto& pair : contents) {
742 ss << pair.first << ": " << pair.second << " ";
743 }
744 }
745
746 m_crl_distribution_urls.push_back(ss.str());
747}
748
750 const auto uris = m_point.uris();
751
752 if(uris.empty()) {
753 throw Not_Implemented("Empty CRL_Distribution_Point encoding not implemented");
754 }
755
756 for(const auto& uri : uris) {
757 der.start_sequence()
761 .end_cons()
762 .end_cons()
763 .end_cons();
764 }
765}
766
778
779std::vector<uint8_t> CRL_Issuing_Distribution_Point::encode_inner() const {
780 throw Not_Implemented("CRL_Issuing_Distribution_Point encoding");
781}
782
783void CRL_Issuing_Distribution_Point::decode_inner(const std::vector<uint8_t>& buf) {
784 BER_Decoder(buf).decode(m_distribution_point).verify_end();
785}
786
788 throw Not_Implemented("TNAuthList extension entry serialization is not supported");
789}
790
792 BER_Object obj = ber.get_next_object();
793
794 const uint32_t type_tag = static_cast<Type>(obj.type_tag());
795
796 if(type_tag == ServiceProviderCode) {
797 m_type = ServiceProviderCode;
798 ASN1_String spc_string;
799 BER_Decoder(obj).decode(spc_string);
800 m_data = std::move(spc_string);
801 } else if(type_tag == TelephoneNumberRange) {
802 m_type = TelephoneNumberRange;
803 m_data = RangeContainer();
804 auto& range_items = std::get<RangeContainer>(m_data);
806 while(list.more_items()) {
808
809 list.decode(entry.start);
810 if(!is_valid_telephone_number(entry.start)) {
811 throw Decoding_Error(fmt("Invalid TelephoneNumberRange start {}", entry.start.value()));
812 }
813
814 list.decode(entry.count);
815 if(entry.count < 2) {
816 throw Decoding_Error(fmt("Invalid TelephoneNumberRange count {}", entry.count));
817 }
818
819 range_items.emplace_back(std::move(entry));
820 }
821 list.end_cons();
822
823 if(range_items.empty()) {
824 throw Decoding_Error("TelephoneNumberRange is empty");
825 }
826 } else if(type_tag == TelephoneNumber) {
827 m_type = TelephoneNumber;
828 ASN1_String one_string;
829 BER_Decoder(obj).decode(one_string);
830 if(!is_valid_telephone_number(one_string)) {
831 throw Decoding_Error(fmt("Invalid TelephoneNumber {}", one_string.value()));
832 }
833 m_data = std::move(one_string);
834 } else {
835 throw Decoding_Error(fmt("Unexpected TNEntry type code {}", type_tag));
836 };
837}
838
839std::vector<uint8_t> TNAuthList::encode_inner() const {
840 throw Not_Implemented("TNAuthList extension serialization is not supported");
841}
842
843void TNAuthList::decode_inner(const std::vector<uint8_t>& in) {
844 BER_Decoder(in).decode_list(m_tn_entries).verify_end();
845 if(m_tn_entries.empty()) {
846 throw Decoding_Error("TNAuthorizationList is empty");
847 }
848}
849
850void OCSP_NoCheck::decode_inner(const std::vector<uint8_t>& buf) {
851 BER_Decoder(buf).verify_end();
852}
853
854std::vector<uint8_t> Unknown_Extension::encode_inner() const {
855 return m_bytes;
856}
857
858void Unknown_Extension::decode_inner(const std::vector<uint8_t>& bytes) {
859 // Just treat as an opaque blob at this level
860 m_bytes = bytes;
861}
862
863} // namespace Cert_Extension
864
865} // namespace Botan
const std::string & value() const
Definition asn1_obj.h:422
const std::set< std::string > & uris() const
Return the set of URIs included in this alternative name.
Definition pkix_types.h:146
BER_Object get_next_object()
Definition ber_dec.cpp:245
BER_Decoder & decode(bool &out)
Definition ber_dec.h:186
bool more_items() const
Definition ber_dec.cpp:201
BER_Decoder & verify_end()
Definition ber_dec.cpp:211
BER_Decoder & end_cons()
Definition ber_dec.cpp:309
BER_Decoder & decode_list(std::vector< T > &out, ASN1_Type type_tag=ASN1_Type::Sequence, ASN1_Class class_tag=ASN1_Class::Universal)
Definition ber_dec.h:379
BER_Decoder start_sequence()
Definition ber_dec.h:123
BER_Decoder start_context_specific(uint32_t tag)
Definition ber_dec.h:127
BER_Decoder & decode_optional(T &out, ASN1_Type type_tag, ASN1_Class class_tag, const T &default_value=T())
Definition ber_dec.h:332
BER_Decoder & decode_optional_string(std::vector< uint8_t, Alloc > &out, ASN1_Type real_type, uint32_t expected_tag, ASN1_Class class_tag=ASN1_Class::ContextSpecific)
Definition ber_dec.h:287
BER_Decoder & decode_optional_implicit(T &out, ASN1_Type type_tag, ASN1_Class class_tag, ASN1_Type real_type, ASN1_Class real_class, const T &default_value=T())
Definition ber_dec.h:354
ASN1_Type type_tag() const
Definition asn1_obj.h:143
std::unique_ptr< Certificate_Extension > copy() const override
Definition x509_ext.cpp:685
void validate(const X509_Certificate &subject, const X509_Certificate &issuer, const std::vector< X509_Certificate > &cert_path, std::vector< std::set< Certificate_Status_Code > > &cert_status, size_t pos) override
Definition x509_ext.cpp:607
void validate(const X509_Certificate &subject, const X509_Certificate &issuer, const std::vector< X509_Certificate > &cert_path, std::vector< std::set< Certificate_Status_Code > > &cert_status, size_t pos) override
Definition x509_ext.cpp:524
void encode_into(DER_Encoder &) const override
Definition x509_ext.cpp:787
std::vector< TelephoneNumberRangeData > RangeContainer
Definition x509_ext.h:522
void decode_from(class BER_Decoder &from) override
Definition x509_ext.cpp:791
virtual void validate(const X509_Certificate &subject, const X509_Certificate &issuer, const std::vector< X509_Certificate > &cert_path, std::vector< std::set< Certificate_Status_Code > > &cert_status, size_t pos)
Definition x509_ext.cpp:133
DER_Encoder & add_object(ASN1_Type type_tag, ASN1_Class class_tag, const uint8_t rep[], size_t length)
Definition der_enc.cpp:222
DER_Encoder & encode_optional(const T &value, const T &default_value)
Definition der_enc.h:123
DER_Encoder & start_sequence()
Definition der_enc.h:64
DER_Encoder & encode_if(bool pred, DER_Encoder &enc)
Definition der_enc.h:146
DER_Encoder & start_cons(ASN1_Type type_tag, ASN1_Class class_tag)
Definition der_enc.cpp:163
DER_Encoder & end_cons()
Definition der_enc.cpp:171
DER_Encoder & encode(bool b)
Definition der_enc.cpp:250
const Certificate_Extension * get_extension_object(const OID &oid) const
Definition x509_ext.cpp:208
std::map< OID, std::pair< std::vector< uint8_t >, bool > > extensions_raw() const
Definition x509_ext.cpp:233
std::unique_ptr< Certificate_Extension > get(const OID &oid) const
Definition x509_ext.cpp:217
void decode_from(BER_Decoder &) override
Definition x509_ext.cpp:265
bool remove(const OID &oid)
Definition x509_ext.cpp:167
std::vector< uint8_t > get_extension_bits(const OID &oid) const
Definition x509_ext.cpp:199
bool critical_extension_set(const OID &oid) const
Definition x509_ext.cpp:191
std::vector< std::pair< std::unique_ptr< Certificate_Extension >, bool > > extensions() const
Definition x509_ext.cpp:224
void encode_into(DER_Encoder &) const override
Definition x509_ext.cpp:244
void replace(std::unique_ptr< Certificate_Extension > extn, bool critical=false)
Definition x509_ext.cpp:177
bool add_new(std::unique_ptr< Certificate_Extension > extn, bool critical=false)
Definition x509_ext.cpp:155
bool extension_set(const OID &oid) const
Definition x509_ext.cpp:187
void add(std::unique_ptr< Certificate_Extension > extn, bool critical=false)
Definition x509_ext.cpp:142
static std::unique_ptr< HashFunction > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition hash.cpp:298
uint32_t value() const
Definition pkix_enums.h:169
bool is_permitted(const X509_Certificate &cert, bool reject_unknown) const
bool is_excluded(const X509_Certificate &cert, bool reject_unknown) const
const std::vector< GeneralSubtree > & permitted() const
Definition pkix_types.h:376
const std::vector< GeneralSubtree > & excluded() const
Definition pkix_types.h:383
static OID from_string(std::string_view str)
Definition asn1_oid.cpp:86
bool is_CA_cert() const
Definition x509cert.cpp:407
bool is_critical(std::string_view ex_name) const
Definition x509cert.cpp:514
std::string name
int(* final)(unsigned char *, CTX *)
std::string to_string(const BER_Object &obj)
Definition asn1_obj.cpp:185
std::string fmt(std::string_view format, const T &... args)
Definition fmt.h:53
ASN1_Type
Definition asn1_obj.h:44
constexpr size_t ctz(T n)
Definition bit_ops.h:102
constexpr uint16_t make_uint16(uint8_t i0, uint8_t i1)
Definition loadstor.h:88