8 #include <botan/x509_obj.h>
9 #include <botan/x509_key.h>
10 #include <botan/pubkey.h>
11 #include <botan/oids.h>
12 #include <botan/der_enc.h>
13 #include <botan/ber_dec.h>
14 #include <botan/parsing.h>
15 #include <botan/pem.h>
28 #if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
51 void X509_Object::init(
DataSource& in,
const std::string& labels)
53 m_PEM_labels_allowed =
split_on(labels,
'/');
54 if(m_PEM_labels_allowed.size() < 1)
57 m_PEM_label_pref = m_PEM_labels_allowed[0];
58 std::sort(m_PEM_labels_allowed.begin(), m_PEM_labels_allowed.end());
68 std::string got_label;
71 if(!std::binary_search(m_PEM_labels_allowed.begin(),
72 m_PEM_labels_allowed.end(), got_label))
73 throw Decoding_Error(
"Invalid PEM label: " + got_label);
79 catch(Decoding_Error& e)
81 throw Decoding_Error(m_PEM_label_pref +
" decoding failed: " + e.what());
158 std::vector<std::string> sig_info =
161 if(sig_info.size() != 2)
165 std::vector<std::string> pad_and_hash =
168 if(pad_and_hash.size() != 2)
171 return pad_and_hash[1];
180 throw Exception(
"No key provided for " + m_PEM_label_pref +
" signature check");
181 std::unique_ptr<const Public_Key> key(pub_key);
191 std::vector<std::string> sig_info =
194 if(sig_info.size() != 2 || sig_info[0] != pub_key.
algo_name())
197 std::string padding = sig_info[1];
205 catch(std::exception&)
std::vector< std::string > parse_algorithm_name(const std::string &namex)
AlgorithmIdentifier m_sig_algo
secure_vector< uint8_t > decode(DataSource &source, std::string &label)
std::string hash_used_for_signature() const
std::vector< uint8_t > BER_encode() const
std::vector< uint8_t > get_contents_unlocked()
bool verify_message(const uint8_t msg[], size_t msg_length, const uint8_t sig[], size_t sig_length)
void encode_into(class DER_Encoder &to) const override
std::string encode(const uint8_t der[], size_t length, const std::string &label, size_t width)
static std::vector< uint8_t > make_signed(class PK_Signer *signer, RandomNumberGenerator &rng, const AlgorithmIdentifier &alg_id, const secure_vector< uint8_t > &tbs)
std::vector< std::string > split_on(const std::string &str, char delim)
virtual std::string algo_name() const =0
BER_Decoder & decode(bool &v)
bool maybe_BER(DataSource &source)
std::vector< uint8_t > sign_message(const uint8_t in[], size_t length, RandomNumberGenerator &rng)
DER_Encoder & raw_bytes(const uint8_t val[], size_t len)
void decode_from(class BER_Decoder &from) override
DER_Encoder & encode(bool b)
std::string PEM_encode() const
std::vector< T, secure_allocator< T >> secure_vector
std::vector< uint8_t > m_tbs_bits
std::string lookup(const OID &oid)
virtual size_t message_parts() const
const char * what() const BOTAN_NOEXCEPT override
BER_Decoder start_cons(ASN1_Tag type_tag, ASN1_Tag class_tag=UNIVERSAL)
bool matches(DataSource &source, const std::string &extra, size_t search_range)
std::vector< uint8_t > signature() const
std::vector< uint8_t > put_in_sequence(const std::vector< uint8_t > &contents)
std::vector< uint8_t > tbs_data() const
bool check_signature(const Public_Key &key) const
std::string as_string() const
DER_Encoder & start_cons(ASN1_Tag type_tag, ASN1_Tag class_tag=UNIVERSAL)
BER_Decoder & raw_bytes(secure_vector< uint8_t > &v)
std::vector< uint8_t > m_sig
AlgorithmIdentifier signature_algorithm() const