1 /*
2 * (C) 1999-2019 Jack Lloyd
3 * (C) 2019 René Meusel
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7
8 #include "test_certstor_utils.h"
9
10 #if defined(BOTAN_HAS_X509_CERTIFICATES)
11
12 #include <botan/ber_dec.h>
13 #include <botan/hex.h>
14
15 namespace Botan_Tests {
16
read_dn(const std::string hex)17 Botan::X509_DN read_dn(const std::string hex)
18 {
19 Botan::X509_DN dn;
20 Botan::BER_Decoder decoder(Botan::hex_decode(hex));
21 dn.decode_from(decoder);
22 return dn;
23 }
24
get_dn()25 Botan::X509_DN get_dn()
26 {
27 // ASN.1 encoded subject DN of "ISRG Root X1"
28 // This certificate is in the standard "System Roots" of any macOS setup,
29 // serves as the trust root of botan.randombit.net and expires on
30 // Monday, 4. June 2035 at 13:04:38 Central European Summer Time
31 return read_dn("304F310B300906035504061302555331293027060355040A1320496E74657"
32 "26E65742053656375726974792052657365617263682047726F7570311530"
33 "130603550403130C4953524720526F6F74205831");
34 }
35
get_utf8_dn()36 Botan::X509_DN get_utf8_dn()
37 {
38 // ASN.1 encoded subject DN of "D-TRUST Root Class 3 CA 2 EV 2009"
39 // This DN contains UTF8-encoded strings
40 // expires on 05. November 2029 at 8:50:46 UTC
41 return read_dn("3050310B300906035504061302444531153013060355040A0C0C442D54727"
42 "5737420476D6248312A302806035504030C21442D545255535420526F6F74"
43 "20436C617373203320434120322045562032303039");
44 }
45
get_key_id()46 std::vector<uint8_t> get_key_id()
47 {
48 // this is the same as the public key SHA1 of "ISRG Root X1"
49 return Botan::hex_decode("79B459E67BB6E5E40173800888C81A58F6E99B6E");
50 }
51
get_subject_cn()52 std::string get_subject_cn()
53 {
54 return "ISRG Root X1";
55 }
56
get_unknown_dn()57 Botan::X509_DN get_unknown_dn()
58 {
59 // thats a D-Trust "Test Certificate". It should be fairly likely that
60 // _nobody_ will _ever_ have that in their system keychain
61 // CN: D-TRUST Limited Basic Test PU CA 1-4 2016
62 return read_dn("305b310b300906035504061302444531153013060355040a0c0c442d5472"
63 "75737420476d62483135303306035504030c2c442d5452555354204c696d"
64 "6974656420426173696320526f6f74205465737420505520434120312032"
65 "303135");
66 }
67
get_skewed_dn()68 Botan::X509_DN get_skewed_dn()
69 {
70 // This DN contains ASN.1 PrintableString fields that are not 'normalized'
71 // according to Apple's idea of a normalized PrintableString field:
72 // (1) It has leading and trailing white space
73 // (2) It contains multiple spaces between 'words'
74 //
75 // This skewed DN was fabricated using the program below and the DN-info of
76 // "ISRG Root X1" which expires on Monday, 4. June 2035 at 13:04:38 CEST
77 //
78 // ```C++
79 // #include <iostream>
80 //
81 // #include <botan/pkix_types.h>
82 // #include <botan/der_enc.h>
83 // #include <botan/hex.h>
84 //
85 // using namespace Botan;
86 //
87 // int main()
88 // {
89 // X509_DN dn{};
90 //
91 // dn.add_attribute(OID{2,5,4,6}, ASN1_String("US", ASN1_Type::PrintableString));
92 // dn.add_attribute(OID{2,5,4,10}, ASN1_String("Internet Security Research Group ", ASN1_Type::PrintableString));
93 // dn.add_attribute(OID{2,5,4,3}, ASN1_String(" ISRG Root X1", ASN1_Type::PrintableString));
94 //
95 // DER_Encoder enc;
96 // dn.encode_into(enc);
97 //
98 // std::cout << hex_encode(enc.get_contents()) << std::endl;
99 // }
100 // ```
101
102 return read_dn("3055310B3009060355040613025553312C302A060355040A1323496E74657"
103 "26E6574205365637572697479202052657365617263682047726F75702020"
104 "311830160603550403130F20204953524720526F6F7420205831");
105 }
106
get_unknown_key_id()107 std::vector<uint8_t> get_unknown_key_id()
108 {
109 // this is the same as the public key SHA1
110 return Botan::hex_decode("785c0b67b536eeacbb2b27cf9123301abe7ab09a");
111 }
112 }
113
114 #endif
115