Botan
1.11.15
|
00001 /* 00002 * X.509 SIGNED Object 00003 * (C) 1999-2007 Jack Lloyd 00004 * 00005 * Botan is released under the Simplified BSD License (see license.txt) 00006 */ 00007 00008 #ifndef BOTAN_X509_OBJECT_H__ 00009 #define BOTAN_X509_OBJECT_H__ 00010 00011 #include <botan/asn1_obj.h> 00012 #include <botan/x509_key.h> 00013 #include <botan/rng.h> 00014 #include <vector> 00015 00016 namespace Botan { 00017 00018 /** 00019 * This class represents abstract X.509 signed objects as 00020 * in the X.500 SIGNED macro 00021 */ 00022 class BOTAN_DLL X509_Object : public ASN1_Object 00023 { 00024 public: 00025 /** 00026 * The underlying data that is to be or was signed 00027 * @return data that is or was signed 00028 */ 00029 std::vector<byte> tbs_data() const; 00030 00031 /** 00032 * @return signature on tbs_data() 00033 */ 00034 std::vector<byte> signature() const; 00035 00036 /** 00037 * @return signature algorithm that was used to generate signature 00038 */ 00039 AlgorithmIdentifier signature_algorithm() const; 00040 00041 /** 00042 * @return hash algorithm that was used to generate signature 00043 */ 00044 std::string hash_used_for_signature() const; 00045 00046 /** 00047 * Create a signed X509 object. 00048 * @param signer the signer used to sign the object 00049 * @param rng the random number generator to use 00050 * @param alg_id the algorithm identifier of the signature scheme 00051 * @param tbs the tbs bits to be signed 00052 * @return signed X509 object 00053 */ 00054 static std::vector<byte> make_signed(class PK_Signer* signer, 00055 RandomNumberGenerator& rng, 00056 const AlgorithmIdentifier& alg_id, 00057 const secure_vector<byte>& tbs); 00058 00059 /** 00060 * Check the signature on this data 00061 * @param key the public key purportedly used to sign this data 00062 * @return true if the signature is valid, otherwise false 00063 */ 00064 bool check_signature(const Public_Key& key) const; 00065 00066 /** 00067 * Check the signature on this data 00068 * @param key the public key purportedly used to sign this data 00069 * the pointer will be deleted after use 00070 * @return true if the signature is valid, otherwise false 00071 */ 00072 bool check_signature(const Public_Key* key) const; 00073 00074 void encode_into(class DER_Encoder& to) const override; 00075 00076 void decode_from(class BER_Decoder& from) override; 00077 00078 /** 00079 * @return BER encoding of this 00080 */ 00081 std::vector<byte> BER_encode() const; 00082 00083 /** 00084 * @return PEM encoding of this 00085 */ 00086 std::string PEM_encode() const; 00087 00088 virtual ~X509_Object() {} 00089 protected: 00090 X509_Object(DataSource& src, const std::string& pem_labels); 00091 X509_Object(const std::string& file, const std::string& pem_labels); 00092 X509_Object(const std::vector<byte>& vec, const std::string& labels); 00093 00094 void do_decode(); 00095 X509_Object() {} 00096 AlgorithmIdentifier sig_algo; 00097 std::vector<byte> tbs_bits, sig; 00098 private: 00099 virtual void force_decode() = 0; 00100 void init(DataSource&, const std::string&); 00101 00102 std::vector<std::string> PEM_labels_allowed; 00103 std::string PEM_label_pref; 00104 }; 00105 00106 } 00107 00108 #endif