Botan 1.10.17

cvc_ado.cpp
Go to the documentation of this file.
1 /*
2 * CVC Certificate Constructor
3 * (C) 2007 FlexSecure GmbH
4 * 2008 Jack Lloyd
5 *
6 * Distributed under the terms of the Botan license
7 */
8
9 #include <botan/cvc_ado.h>
10 #include <fstream>
11
12 namespace Botan {
13
14 EAC1_1_ADO::EAC1_1_ADO(DataSource& in)
15 {
16 init(in);
17 do_decode();
18 }
19
20 EAC1_1_ADO::EAC1_1_ADO(const std::string& in)
21 {
22 DataSource_Stream stream(in, true);
23 init(stream);
24 do_decode();
25 }
26
27 void EAC1_1_ADO::force_decode()
28 {
29 SecureVector<byte> inner_cert;
30 BER_Decoder(tbs_bits)
31 .start_cons(ASN1_Tag(33))
32 .raw_bytes(inner_cert)
33 .end_cons()
34 .decode(m_car)
35 .verify_end();
36
37 SecureVector<byte> req_bits = DER_Encoder()
38 .start_cons(ASN1_Tag(33), APPLICATION)
39 .raw_bytes(inner_cert)
40 .end_cons()
41 .get_contents();
42
43 DataSource_Memory req_source(req_bits);
44 m_req = EAC1_1_Req(req_source);
45 sig_algo = m_req.sig_algo;
46 }
47
48 MemoryVector<byte> EAC1_1_ADO::make_signed(PK_Signer& signer,
49 const MemoryRegion<byte>& tbs_bits,
50 RandomNumberGenerator& rng)
51 {
52 SecureVector<byte> concat_sig = signer.sign_message(tbs_bits, rng);
53
54 return DER_Encoder()
55 .start_cons(ASN1_Tag(7), APPLICATION)
56 .raw_bytes(tbs_bits)
57 .encode(concat_sig, OCTET_STRING, ASN1_Tag(55), APPLICATION)
58 .end_cons()
59 .get_contents();
60 }
61
62 ASN1_Car EAC1_1_ADO::get_car() const
63 {
64 return m_car;
65 }
66
67 void EAC1_1_ADO::decode_info(DataSource& source,
68 SecureVector<byte> & res_tbs_bits,
69 ECDSA_Signature & res_sig)
70 {
71 SecureVector<byte> concat_sig;
72 SecureVector<byte> cert_inner_bits;
73 ASN1_Car car;
74
75 BER_Decoder(source)
76 .start_cons(ASN1_Tag(7))
77 .start_cons(ASN1_Tag(33))
78 .raw_bytes(cert_inner_bits)
79 .end_cons()
80 .decode(car)
81 .decode(concat_sig, OCTET_STRING, ASN1_Tag(55), APPLICATION)
82 .end_cons();
83
84 SecureVector<byte> enc_cert = DER_Encoder()
85 .start_cons(ASN1_Tag(33), APPLICATION)
86 .raw_bytes(cert_inner_bits)
87 .end_cons()
88 .get_contents();
89
90 res_tbs_bits = enc_cert;
91 res_tbs_bits += DER_Encoder().encode(car).get_contents();
92 res_sig = decode_concatenation(concat_sig);
93 }
94
95 void EAC1_1_ADO::encode(Pipe& out, X509_Encoding encoding) const
96 {
97 if(encoding == PEM)
98 throw Invalid_Argument("EAC1_1_ADO::encode() cannot PEM encode an EAC object");
99
100 SecureVector<byte> concat_sig(
101 EAC1_1_obj<EAC1_1_ADO>::m_sig.get_concatenation());
102
103 out.write(DER_Encoder()
104 .start_cons(ASN1_Tag(7), APPLICATION)
105 .raw_bytes(tbs_bits)
106 .encode(concat_sig, OCTET_STRING, ASN1_Tag(55), APPLICATION)
107 .end_cons()
108 .get_contents());
109 }
110
111 SecureVector<byte> EAC1_1_ADO::tbs_data() const
112 {
113 return tbs_bits;
114 }
115
116 bool EAC1_1_ADO::operator==(EAC1_1_ADO const& rhs) const
117 {
118 return (this->get_concat_sig() == rhs.get_concat_sig()
119 && this->tbs_data() == rhs.tbs_data()
120 && this->get_car() == rhs.get_car());
121 }
122
123 EAC1_1_Req EAC1_1_ADO::get_request() const
124 {
125 return m_req;
126 }
127
128 }
Botan::EAC1_1_Req
Definition: cvc_req.h:19
Botan::EAC1_1_obj< EAC1_1_ADO >::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_ADO >::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_ADO::make_signed
static MemoryVector< byte > make_signed(PK_Signer &signer, const MemoryRegion< byte > &tbs_bits, RandomNumberGenerator &rng)
Definition: cvc_ado.cpp:48
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::EAC_Signed_Object::sig_algo
AlgorithmIdentifier sig_algo
Definition: signed_obj.h:85
Botan::Pipe::write
void write(const byte in[], size_t length)
Definition: pipe_rw.cpp:34
Botan::BER_Decoder::decode
BER_Decoder & decode(bool &)
Definition: ber_dec.cpp:344
Botan::X509_Encoding
X509_Encoding
Definition: pubkey_enums.h:67
Botan::Invalid_Argument
std::invalid_argument Invalid_Argument
Definition: exceptn.h:20
Botan::DER_Encoder::end_cons
DER_Encoder & end_cons()
Definition: der_enc.cpp:145
Botan::DataSource
Definition: data_src.h:20
Botan::BER_Decoder::start_cons
BER_Decoder start_cons(ASN1_Tag, ASN1_Tag=UNIVERSAL)
Definition: ber_dec.cpp:238
Botan::EAC1_1_ADO::operator==
bool operator==(EAC1_1_ADO const &rhs) const
Definition: cvc_ado.cpp:116
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_ADO::tbs_data
SecureVector< byte > tbs_data() const
Definition: cvc_ado.cpp:111
Botan::EAC1_1_ADO::encode
void encode(Pipe &out, X509_Encoding encoding) const
Definition: cvc_ado.cpp:95
Botan::PK_Signer::sign_message
SecureVector< byte > sign_message(const byte in[], size_t length, RandomNumberGenerator &rng)
Definition: pubkey.cpp:160
Botan::BER_Decoder::end_cons
BER_Decoder & end_cons()
Definition: ber_dec.cpp:252
Botan::ASN1_Tag
ASN1_Tag
Definition: asn1_int.h:19
Botan::EAC1_1_ADO::get_car
ASN1_Car get_car() const
Definition: cvc_ado.cpp:62
Botan::MemoryRegion< byte >
Botan
Definition: algo_base.h:14
Botan::PEM
Definition: pubkey_enums.h:67
Botan::MemoryVector< byte >
Botan::ASN1_Car
Definition: eac_asn_obj.h:201
Botan::APPLICATION
Definition: asn1_int.h:21
Botan::EAC1_1_ADO::EAC1_1_ADO
EAC1_1_ADO(const std::string &str)
Definition: cvc_ado.cpp:20
Botan::decode_concatenation
ECDSA_Signature decode_concatenation(const MemoryRegion< byte > &concat)
Definition: ecdsa_sig.cpp:46
Botan::BER_Decoder::raw_bytes
BER_Decoder & raw_bytes(MemoryRegion< byte > &)
Definition: ber_dec.cpp:173
Botan::BER_Decoder::verify_end
BER_Decoder & verify_end()
Definition: ber_dec.cpp:163
Botan::DataSource_Memory
Definition: data_src.h:94
Botan::EAC1_1_obj
Definition: eac_obj.h:20
Botan::DER_Encoder::start_cons
DER_Encoder & start_cons(ASN1_Tag type_tag, ASN1_Tag class_tag=UNIVERSAL)
Definition: der_enc.cpp:135
Botan::SecureVector< byte >
Botan::Pipe
Definition: pipe.h:25
Botan::EAC_Signed_Object::tbs_bits
SecureVector< byte > tbs_bits
Definition: signed_obj.h:86
Botan::PK_Signer
Definition: pubkey.h:123
Botan::EAC1_1_ADO
Definition: cvc_ado.h:23
Botan::BER_Decoder
Definition: ber_dec.h:19
Botan::ECDSA_Signature
Definition: ecdsa_sig.h:21
Botan::EAC1_1_ADO::get_request
EAC1_1_Req get_request() const
Definition: cvc_ado.cpp:123