Botan 1.10.17

cvc_cert.cpp
Go to the documentation of this file.
1 /*
2 (C) 2007 FlexSecure GmbH
3 2008-2010 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7
8 #include <botan/cvc_cert.h>
9 #include <botan/oids.h>
10
11 namespace Botan {
12
13 ASN1_Car EAC1_1_CVC::get_car() const
14 {
15 return m_car;
16 }
17
18 ASN1_Ced EAC1_1_CVC::get_ced() const
19 {
20 return m_ced;
21 }
22 ASN1_Cex EAC1_1_CVC::get_cex() const
23 {
24 return m_cex;
25 }
26 u32bit EAC1_1_CVC::get_chat_value() const
27 {
28 return m_chat_val;
29 }
30
31 /*
32 * Decode the TBSCertificate data
33 */
34 void EAC1_1_CVC::force_decode()
35 {
36 SecureVector<byte> enc_pk;
37 SecureVector<byte> enc_chat_val;
38 size_t cpi;
39 BER_Decoder tbs_cert(tbs_bits);
40 tbs_cert.decode(cpi, ASN1_Tag(41), APPLICATION)
41 .decode(m_car)
42 .start_cons(ASN1_Tag(73))
43 .raw_bytes(enc_pk)
44 .end_cons()
45 .decode(m_chr)
46 .start_cons(ASN1_Tag(76))
47 .decode(m_chat_oid)
48 .decode(enc_chat_val, OCTET_STRING, ASN1_Tag(19), APPLICATION)
49 .end_cons()
50 .decode(m_ced)
51 .decode(m_cex)
52 .verify_end();
53
54 if(enc_chat_val.size() != 1)
55 throw Decoding_Error("CertificateHolderAuthorizationValue was not of length 1");
56
57 if(cpi != 0)
58 throw Decoding_Error("EAC1_1 certificate's cpi was not 0");
59
60 m_pk = decode_eac1_1_key(enc_pk, sig_algo);
61
62 m_chat_val = enc_chat_val[0];
63
64 self_signed = (m_car.iso_8859() == m_chr.iso_8859());
65 }
66
67 /*
68 * CVC Certificate Constructor
69 */
70 EAC1_1_CVC::EAC1_1_CVC(DataSource& in)
71 {
72 init(in);
73 self_signed = false;
74 do_decode();
75 }
76
77 EAC1_1_CVC::EAC1_1_CVC(const std::string& in)
78 {
79 DataSource_Stream stream(in, true);
80 init(stream);
81 self_signed = false;
82 do_decode();
83 }
84
85 bool EAC1_1_CVC::operator==(EAC1_1_CVC const& rhs) const
86 {
87 return (tbs_data() == rhs.tbs_data()
88 && get_concat_sig() == rhs.get_concat_sig());
89 }
90
91 ECDSA_PublicKey* decode_eac1_1_key(const MemoryRegion<byte>&,
92 AlgorithmIdentifier&)
93 {
94 throw Internal_Error("decode_eac1_1_key: Unimplemented");
95 return 0;
96 }
97
98 EAC1_1_CVC make_cvc_cert(PK_Signer& signer,
99 MemoryRegion<byte> const& public_key,
100 ASN1_Car const& car,
101 ASN1_Chr const& chr,
102 byte holder_auth_templ,
103 ASN1_Ced ced,
104 ASN1_Cex cex,
105 RandomNumberGenerator& rng)
106 {
107 OID chat_oid(OIDS::lookup("CertificateHolderAuthorizationTemplate"));
108 MemoryVector<byte> enc_chat_val;
109 enc_chat_val.push_back(holder_auth_templ);
110
111 MemoryVector<byte> enc_cpi;
112 enc_cpi.push_back(0x00);
113 MemoryVector<byte> tbs = DER_Encoder()
114 .encode(enc_cpi, OCTET_STRING, ASN1_Tag(41), APPLICATION) // cpi
115 .encode(car)
116 .raw_bytes(public_key)
117 .encode(chr)
118 .start_cons(ASN1_Tag(76), APPLICATION)
119 .encode(chat_oid)
120 .encode(enc_chat_val, OCTET_STRING, ASN1_Tag(19), APPLICATION)
121 .end_cons()
122 .encode(ced)
123 .encode(cex)
124 .get_contents();
125
126 MemoryVector<byte> signed_cert =
127 EAC1_1_CVC::make_signed(signer,
128 EAC1_1_CVC::build_cert_body(tbs),
129 rng);
130
131 DataSource_Memory source(signed_cert);
132 return EAC1_1_CVC(source);
133 }
134
135 }
Botan::EAC1_1_obj< EAC1_1_CVC >::get_concat_sig
SecureVector< byte > get_concat_sig() const
Definition: eac_obj.h:27
Botan::DataSource_Stream
Definition: data_src.h:128
Botan::EAC1_1_obj< EAC1_1_CVC >::init
void init(DataSource &in)
Definition: eac_obj.h:38
Botan::EAC_Signed_Object::do_decode
void do_decode()
Definition: signed_obj.cpp:79
Botan::DER_Encoder::get_contents
SecureVector< byte > get_contents()
Definition: der_enc.cpp:122
Botan::EAC1_1_CVC
Definition: cvc_cert.h:21
Botan::DER_Encoder::raw_bytes
DER_Encoder & raw_bytes(const byte val[], size_t len)
Definition: der_enc.cpp:188
Botan::RandomNumberGenerator
Definition: rng.h:20
Botan::ASN1_Cex
Definition: eac_asn_obj.h:139
Botan::EAC1_1_CVC::operator==
bool operator==(const EAC1_1_CVC &) const
Definition: cvc_cert.cpp:85
Botan::EAC_Signed_Object::sig_algo
AlgorithmIdentifier sig_algo
Definition: signed_obj.h:85
Botan::Internal_Error
Definition: exceptn.h:45
Botan::MemoryRegion::push_back
void push_back(T x)
Definition: secmem.h:149
Botan::DER_Encoder::end_cons
DER_Encoder & end_cons()
Definition: der_enc.cpp:145
Botan::DataSource
Definition: data_src.h:20
Botan::EAC1_1_CVC::get_chat_value
u32bit get_chat_value() const
Definition: cvc_cert.cpp:26
Botan::make_cvc_cert
EAC1_1_CVC make_cvc_cert(PK_Signer &signer, MemoryRegion< byte > const &public_key, ASN1_Car const &car, ASN1_Chr const &chr, byte holder_auth_templ, ASN1_Ced ced, ASN1_Cex cex, RandomNumberGenerator &rng)
Definition: cvc_cert.cpp:98
Botan::byte
unsigned char byte
Definition: types.h:22
Botan::DER_Encoder::encode
DER_Encoder & encode(bool b)
Definition: der_enc.cpp:209
Botan::OCTET_STRING
Definition: asn1_int.h:31
Botan::DER_Encoder
Definition: der_enc.h:22
Botan::EAC1_1_CVC::get_ced
ASN1_Ced get_ced() const
Definition: cvc_cert.cpp:18
Botan::OIDS::lookup
std::string lookup(const OID &oid)
Definition: oids.cpp:31
Botan::EAC1_1_gen_CVC< EAC1_1_CVC >::make_signed
static MemoryVector< byte > make_signed(PK_Signer &signer, const MemoryRegion< byte > &tbs_bits, RandomNumberGenerator &rng)
Definition: cvc_gen_cert.h:107
Botan::ASN1_Tag
ASN1_Tag
Definition: asn1_int.h:19
Botan::ECDSA_PublicKey
Definition: ecdsa.h:22
Botan::EAC1_1_CVC::get_car
ASN1_Car get_car() const
Definition: cvc_cert.cpp:13
Botan::Decoding_Error
Definition: exceptn.h:138
Botan::MemoryRegion< byte >
Botan
Definition: algo_base.h:14
Botan::MemoryVector< byte >
Botan::ASN1_Car
Definition: eac_asn_obj.h:201
Botan::ASN1_EAC_String::iso_8859
std::string iso_8859() const
Definition: asn1_eac_str.cpp:33
Botan::EAC1_1_gen_CVC< EAC1_1_CVC >::self_signed
bool self_signed
Definition: cvc_gen_cert.h:88
Botan::decode_eac1_1_key
ECDSA_PublicKey * decode_eac1_1_key(const MemoryRegion< byte > &, AlgorithmIdentifier &)
Definition: cvc_cert.cpp:91
Botan::MemoryRegion::size
size_t size() const
Definition: secmem.h:29
Botan::APPLICATION
Definition: asn1_int.h:21
Botan::DataSource_Memory
Definition: data_src.h:94
Botan::EAC1_1_CVC::get_cex
ASN1_Cex get_cex() const
Definition: cvc_cert.cpp:22
Botan::AlgorithmIdentifier
Definition: alg_id.h:20
Botan::EAC1_1_gen_CVC< EAC1_1_CVC >::m_chr
ASN1_Chr m_chr
Definition: cvc_gen_cert.h:87
Botan::DER_Encoder::start_cons
DER_Encoder & start_cons(ASN1_Tag type_tag, ASN1_Tag class_tag=UNIVERSAL)
Definition: der_enc.cpp:135
Botan::EAC1_1_gen_CVC< EAC1_1_CVC >::build_cert_body
static SecureVector< byte > build_cert_body(MemoryRegion< byte > const &tbs)
Definition: cvc_gen_cert.h:128
Botan::SecureVector< byte >
Botan::EAC_Signed_Object::tbs_bits
SecureVector< byte > tbs_bits
Definition: signed_obj.h:86
Botan::PK_Signer
Definition: pubkey.h:123
Botan::OID
Definition: asn1_oid.h:20
Botan::ASN1_Chr
Definition: eac_asn_obj.h:214
Botan::BER_Decoder
Definition: ber_dec.h:19
Botan::EAC1_1_gen_CVC< EAC1_1_CVC >::tbs_data
SecureVector< byte > tbs_data() const
Definition: cvc_gen_cert.h:136
Botan::ASN1_Ced
Definition: eac_asn_obj.h:108
Botan::u32bit
unsigned int u32bit
Definition: types.h:32
Botan::EAC1_1_gen_CVC< EAC1_1_CVC >::m_pk
ECDSA_PublicKey * m_pk
Definition: cvc_gen_cert.h:86