23 #ifndef TAO_CRYPT_ASN_HPP
24 #define TAO_CRYPT_ASN_HPP
38 namespace STL = STL_NAMESPACE;
51 OBJECT_IDENTIFIER = 0x06,
52 OBJECT_DESCRIPTOR = 0x07,
59 NUMERIC_STRING = 0x12,
60 PRINTABLE_STRING = 0x13,
62 VIDEOTEXT_STRING = 0x15,
65 GENERALIZED_TIME = 0x18,
66 GRAPHIC_STRING = 0x19,
67 VISIBLE_STRING = 0x1a,
68 GENERAL_STRING = 0x1b,
79 CONTEXT_SPECIFIC = 0x80,
101 SIGNED_AND_ENVELOPED_DATA = 4,
123 class RSA_PrivateKey;
125 class DSA_PrivateKey;
139 word32 GetSequence();
142 word32 GetExplicitVersion();
146 virtual void ReadHeader() = 0;
170 void ReadHeaderOpenSSL();
219 explicit PublicKey(
const byte* k = 0, word32 s = 0);
222 const byte* GetKey()
const {
return key_; }
223 word32 size()
const {
return sz_; }
225 void SetKey(
const byte*);
226 void SetSize(word32 s);
228 void AddToEnd(
const byte*, word32);
235 enum { SHA_SIZE = 20 };
241 char name_[ASN_NAME_MAX];
242 byte hash_[SHA_SIZE];
244 Signer(
const byte* k, word32 kSz,
const char*
n,
const byte* h);
247 const PublicKey& GetPublicKey()
const {
return key_; }
248 const char* GetName()
const {
return name_; }
249 const byte* GetHash()
const {
return hash_; }
257 typedef STL::list<Signer*> SignerList;
260 enum ContentType { HUH = 651 };
261 enum SigType { SHAwDSA = 517, MD2wRSA = 646, MD5wRSA = 648, SHAwRSA = 649,
262 SHA256wRSA = 655, SHA384wRSA = 656, SHA512wRSA = 657,
264 enum HashType { MD2h = 646, MD5h = 649, SHAh = 88, SHA256h = 414,
265 SHA384h = 415, SHA512h = 416 };
266 enum KeyType { DSAk = 515, RSAk = 645 };
272 enum DateType { BEFORE, AFTER };
273 enum NameType { ISSUER, SUBJECT };
274 enum CertType { CA, USER };
277 bool noVerify =
false, CertType ct = USER);
280 const PublicKey& GetPublicKey()
const {
return key_; }
281 KeyType GetKeyType()
const {
return KeyType(keyOID_); }
282 const char* GetIssuer()
const {
return issuer_; }
283 const char* GetCommonName()
const {
return subject_; }
284 const byte* GetHash()
const {
return subjectHash_; }
285 const char* GetBeforeDate()
const {
return beforeDate_; }
286 byte GetBeforeDateType()
const {
return beforeDateType_; }
287 const char* GetAfterDate()
const {
return afterDate_; }
288 byte GetAfterDateType()
const {
return afterDateType_; }
296 word32 signatureOID_;
298 byte subjectHash_[SHA_SIZE];
299 byte issuerHash_[SHA_SIZE];
301 char issuer_[ASN_NAME_MAX];
302 char subject_[ASN_NAME_MAX];
303 char beforeDate_[MAX_DATE_SZ];
304 byte beforeDateType_;
305 char afterDate_[MAX_DATE_SZ];
310 void Decode(SignerList*, CertType);
313 bool ValidateSelfSignature();
314 bool ValidateSignature(SignerList*);
315 bool ConfirmSignature(
Source&);
317 char* AddTag(
char*,
const char*,
const char*, word32, word32);
318 void GetName(NameType);
320 void GetDate(DateType);
321 void GetCompareHash(
const byte*, word32, byte*, word32);
323 word32 GetSignature();
328 word32 GetLength(
Source&);
330 word32 SetLength(word32, byte*);
331 word32 SetSequence(word32, byte*);
333 word32 EncodeDSA_Signature(
const byte* signature, byte* output);
334 word32 EncodeDSA_Signature(
const Integer& r,
const Integer& s, byte* output);
335 word32 DecodeDSA_Signature(byte* decoded,
const byte* encoded, word32 sz);
344 word32 SetAlgoID(HashType, byte*);
346 Error GetError()
const {
return error_; }
366 word32 SetDigest(
const byte*, word32, byte*);
377 int GetPKCS_Cert(
const char* password,
Source&);
379 bool ASN1_TIME_extract(
const unsigned char* date,
unsigned char format,
385 #endif // TAO_CRYPT_ASN_HPP