00001 // $Id: XrdCryptosslX509.hh 22437 2008-03-04 14:35:16Z rdm $ 00002 #ifndef __CRYPTO_SSLX509_H__ 00003 #define __CRYPTO_SSLX509_H__ 00004 /******************************************************************************/ 00005 /* */ 00006 /* X r d C r y p t o s s l X 5 0 9 . h h */ 00007 /* */ 00008 /* */ 00009 /* (c) 2005 G. Ganis , CERN */ 00010 /* */ 00011 /******************************************************************************/ 00012 00013 /* ************************************************************************** */ 00014 /* */ 00015 /* OpenSSL implementation of XrdCryptoX509 */ 00016 /* */ 00017 /* ************************************************************************** */ 00018 00019 #include <XrdCrypto/XrdCryptoX509.hh> 00020 00021 #include <openssl/x509v3.h> 00022 #include <openssl/bio.h> 00023 #include <openssl/evp.h> 00024 00025 // ---------------------------------------------------------------------------// 00026 // 00027 // OpenSSL X509 implementation 00028 // 00029 // ---------------------------------------------------------------------------// 00030 class XrdCryptosslX509 : public XrdCryptoX509 00031 { 00032 00033 public: 00034 XrdCryptosslX509(const char *cf, const char *kf = 0); 00035 XrdCryptosslX509(XrdSutBucket *bck); 00036 XrdCryptosslX509(X509 *cert); 00037 virtual ~XrdCryptosslX509(); 00038 00039 // Access underlying data (in opaque form: used in chains) 00040 XrdCryptoX509data Opaque() { return (XrdCryptoX509data)cert; } 00041 00042 // Access certificate key 00043 XrdCryptoRSA *PKI() { return pki; } 00044 void SetPKI(XrdCryptoX509data pki); 00045 00046 // Export in form of bucket (for transfers) 00047 XrdSutBucket *Export(); 00048 00049 // Parent file 00050 const char *ParentFile() { return (const char *)(srcfile.c_str()); } 00051 00052 // Key strength 00053 int BitStrength() { return ((cert) ? EVP_PKEY_bits(X509_get_pubkey(cert)) : -1);} 00054 00055 // Serial number 00056 kXR_int64 SerialNumber(); 00057 XrdOucString SerialNumberString(); 00058 00059 // Validity 00060 int NotBefore(); // get begin-validity time in secs since Epoch 00061 int NotAfter(); // get end-validity time in secs since Epoch 00062 00063 // Relevant Names 00064 const char *Subject(); // get subject name 00065 const char *Issuer(); // get issuer name 00066 00067 // Relevant hashes 00068 const char *SubjectHash(); // get hash of subject name 00069 const char *IssuerHash(); // get hash of issuer name 00070 00071 // Retrieve a given extension if there (in opaque form) 00072 XrdCryptoX509data GetExtension(const char *oid); 00073 00074 // Verify signature 00075 bool Verify(XrdCryptoX509 *ref); 00076 00077 private: 00078 X509 *cert; // The certificate object 00079 int notbefore; // begin-validity time in secs since Epoch 00080 int notafter; // end-validity time in secs since Epoch 00081 XrdOucString subject; // subject; 00082 XrdOucString issuer; // issuer name; 00083 XrdOucString subjecthash; // hash of subject; 00084 XrdOucString issuerhash; // hash of issuer name; 00085 XrdOucString srcfile; // source file name, if any; 00086 XrdSutBucket *bucket; // Bucket for export operations 00087 XrdCryptoRSA *pki; // PKI of the certificate 00088 00089 bool IsCA(); // Find out if we are a CA 00090 00091 }; 00092 00093 #endif