xrootd
XrdCryptosslX509.hh
Go to the documentation of this file.
1 #ifndef __CRYPTO_SSLX509_H__
2 #define __CRYPTO_SSLX509_H__
3 /******************************************************************************/
4 /* */
5 /* X r d C r y p t o s s l X 5 0 9 . h h */
6 /* */
7 /* (c) 2005 G. Ganis , CERN */
8 /* */
9 /* This file is part of the XRootD software suite. */
10 /* */
11 /* XRootD is free software: you can redistribute it and/or modify it under */
12 /* the terms of the GNU Lesser General Public License as published by the */
13 /* Free Software Foundation, either version 3 of the License, or (at your */
14 /* option) any later version. */
15 /* */
16 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
17 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
18 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
19 /* License for more details. */
20 /* */
21 /* You should have received a copy of the GNU Lesser General Public License */
22 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
23 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
24 /* */
25 /* The copyright holder's institutional names and contributor's names may not */
26 /* be used to endorse or promote products derived from this software without */
27 /* specific prior written permission of the institution or contributor. */
28 /* */
29 /******************************************************************************/
30 
31 /* ************************************************************************** */
32 /* */
33 /* OpenSSL implementation of XrdCryptoX509 */
34 /* */
35 /* ************************************************************************** */
36 
38 
39 #include <openssl/x509v3.h>
40 #include <openssl/bio.h>
41 #include <openssl/evp.h>
42 
43 // ---------------------------------------------------------------------------//
44 //
45 // OpenSSL X509 implementation
46 //
47 // ---------------------------------------------------------------------------//
49 {
50 
51 public:
52  XrdCryptosslX509(const char *cf, const char *kf = 0);
54  XrdCryptosslX509(X509 *cert);
55  virtual ~XrdCryptosslX509();
56 
57  // Access underlying data (in opaque form: used in chains)
59 
60  // Access certificate key
61  XrdCryptoRSA *PKI() { return pki; }
63 
64  // Export in form of bucket (for transfers)
66 
67  // Parent file
68  const char *ParentFile() { return (const char *)(srcfile.c_str()); }
69 
70  // Key strength
71  int BitStrength() { return ((cert) ? EVP_PKEY_bits(X509_get_pubkey(cert)) : -1);}
72 
73  // Serial number
76 
77  // Validity
78  int NotBefore(); // get begin-validity time in secs since Epoch
79  int NotAfter(); // get end-validity time in secs since Epoch
80 
81  // Relevant Names
82  const char *Subject(); // get subject name
83  const char *Issuer(); // get issuer name
84 
85  // Relevant hashes
86  const char *SubjectHash(int = 0); // get hash of subject name
87  const char *IssuerHash(int = 0); // get hash of issuer name
88 
89  // Retrieve a given extension if there (in opaque form)
90  XrdCryptoX509data GetExtension(const char *oid);
91 
92  // Verify signature
93  bool Verify(XrdCryptoX509 *ref);
94 
95 private:
96  X509 *cert; // The certificate object
97  int notbefore; // begin-validity time in secs since Epoch
98  int notafter; // end-validity time in secs since Epoch
99  XrdOucString subject; // subject;
100  XrdOucString issuer; // issuer name;
101  XrdOucString subjecthash; // Default hash of subject;
102  XrdOucString issuerhash; // Default hash of issuer name;
103  XrdOucString subjectoldhash; // Old (md5) hash of subject if v >= 1.0.0;
104  XrdOucString issueroldhash; // Old (md5) hash of issuer name if v >= 1.0.0;
105  XrdOucString srcfile; // source file name, if any;
106  XrdSutBucket *bucket; // Bucket for export operations
107  XrdCryptoRSA *pki; // PKI of the certificate
108 
109  bool IsCA(); // Find out if we are a CA
110 
111 };
112 
113 #endif