XRootD
XrdCryptosslX509 Class Reference

#include <XrdCryptosslX509.hh>

+ Inheritance diagram for XrdCryptosslX509:
+ Collaboration diagram for XrdCryptosslX509:

Public Member Functions

 XrdCryptosslX509 (const char *cf, const char *kf=0)
 
 XrdCryptosslX509 (X509 *cert)
 
 XrdCryptosslX509 (XrdSutBucket *bck)
 
virtual ~XrdCryptosslX509 ()
 
int BitStrength ()
 
int DumpExtensions (bool dumpunknown=0)
 
XrdSutBucketExport ()
 
XrdCryptoX509data GetExtension (const char *oid)
 
const char * Issuer ()
 
const char * IssuerHash (int=0)
 
virtual bool MatchesSAN (const char *, bool &)
 
time_t NotAfter ()
 
time_t NotBefore ()
 
XrdCryptoX509data Opaque ()
 
const char * ParentFile ()
 
XrdCryptoRSAPKI ()
 
const char * ProxyType () const
 
kXR_int64 SerialNumber ()
 
XrdOucString SerialNumberString ()
 
void SetPKI (XrdCryptoX509data pki)
 
const char * Subject ()
 
const char * SubjectHash (int=0)
 
bool Verify (XrdCryptoX509 *ref)
 
- Public Member Functions inherited from XrdCryptoX509
 XrdCryptoX509 ()
 
virtual ~XrdCryptoX509 ()
 
virtual void Dump ()
 
virtual bool IsExpired (int when=0)
 
const char * IssuerHash ()
 
virtual bool IsValid (int when=0)
 
const char * SubjectHash ()
 
const char * Type (EX509Type t=kUnknown) const
 

Additional Inherited Members

- Public Types inherited from XrdCryptoX509
enum  EX509Type {
  kUnknown = -1 ,
  kCA = 0 ,
  kEEC = 1 ,
  kProxy = 2
}
 
- Static Public Member Functions inherited from XrdCryptoX509
static bool MatchHostnames (const char *match_pattern, const char *fqdn)
 
- Public Attributes inherited from XrdCryptoX509
EX509Type type
 

Detailed Description

Definition at line 48 of file XrdCryptosslX509.hh.

Constructor & Destructor Documentation

◆ XrdCryptosslX509() [1/3]

XrdCryptosslX509::XrdCryptosslX509 ( const char *  cf,
const char *  kf = 0 
)

Definition at line 66 of file XrdCryptosslX509.cc.

67  : XrdCryptoX509()
68 {
69  // Constructor certificate from file 'cf'. If 'kf' is defined,
70  // complete the key of the certificate with the private key in kf.
71  EPNAME("X509::XrdCryptosslX509_file");
72 
73  // Init private members
74  cert = 0; // The certificate object
75  notbefore = -1; // begin-validity time in secs since Epoch
76  notafter = -1; // end-validity time in secs since Epoch
77  subject = ""; // subject;
78  issuer = ""; // issuer;
79  subjecthash = ""; // hash of subject;
80  issuerhash = ""; // hash of issuer;
81  subjectoldhash = ""; // hash of subject (md5 algorithm);
82  issueroldhash = ""; // hash of issuer (md5 algorithm);
83  srcfile = ""; // source file;
84  bucket = 0; // bucket for serialization
85  pki = 0; // PKI of the certificate
86  pxytype = 0; // Proxy sub-type
87 
88  // Make sure file name is defined;
89  if (!cf) {
90  DEBUG("file name undefined");
91  return;
92  }
93  // Make sure file exists;
94  struct stat st;
95  int fd = open(cf, O_RDONLY);
96 
97  if (fd == -1) {
98  if (errno == ENOENT) {
99  DEBUG("file "<<cf<<" does not exist - do nothing");
100  } else {
101  DEBUG("cannot open file "<<cf<<" (errno: "<<errno<<")");
102  }
103  return;
104  }
105 
106  if (fstat(fd, &st) != 0) {
107  DEBUG("cannot stat file "<<cf<<" (errno: "<<errno<<")");
108  close(fd);
109  return;
110  }
111  //
112  // Open file in read mode
113  FILE *fc = fdopen(fd, "r");
114  if (!fc) {
115  DEBUG("cannot fdopen file "<<cf<<" (errno: "<<errno<<")");
116  close(fd);
117  return;
118  }
119  //
120  // Read the content:
121  if (!PEM_read_X509(fc, &cert, 0, 0)) {
122  DEBUG("Unable to load certificate from file");
123  fclose(fc);
124  return;
125  } else {
126  DEBUG("certificate successfully loaded");
127  }
128  //
129  // Close the file
130  fclose(fc);
131  //
132  // Save source file name
133  srcfile = cf;
134 
135  // Init some of the private members (the others upon need)
136  Subject();
137  Issuer();
138  CertType();
139 
140  // Get the public key
141  EVP_PKEY *evpp = 0;
142  // Read the private key file, if specified
143  if (kf) {
144  int fd = open(kf, O_RDONLY);
145  if (fd == -1) {
146  DEBUG("cannot open file "<<kf<<" (errno: "<<errno<<")");
147  return;
148  }
149  if (fstat(fd, &st) == -1) {
150  DEBUG("cannot stat private key file "<<kf<<" (errno:"<<errno<<")");
151  close(fd);
152  return;
153  }
154  if (!S_ISREG(st.st_mode) || S_ISDIR(st.st_mode) ||
155  (st.st_mode & (S_IROTH | S_IWOTH)) != 0 ||
156  (st.st_mode & (S_IWGRP)) != 0) {
157  DEBUG("private key file "<<kf<<" has wrong permissions "<<
158  (st.st_mode & 0777) << " (should be at most 0640)");
159  close(fd);
160  return;
161  }
162  // Open file in read mode
163  FILE *fk = fdopen(fd, "r");
164  if (!fk) {
165  DEBUG("cannot open file "<<kf<<" (errno: "<<errno<<")");
166  close(fd);
167  return;
168  }
169  // This call fills the full key, i.e. also the public part (not really documented, though)
170  if ((evpp = PEM_read_PrivateKey(fk,0,0,0))) {
171  DEBUG("RSA key completed ");
172  // Test consistency
173  auto tmprsa = std::make_unique<XrdCryptosslRSA>(evpp, 1);
174  if (tmprsa->status == XrdCryptoRSA::kComplete) {
175  // Save it in pki
176  pki = tmprsa.release();
177  }
178  } else {
179  DEBUG("cannot read the key from file");
180  }
181  // Close the file
182  fclose(fk);
183  }
184  // If there were no private key or we did not manage to import it
185  // init pki with the partial key
186  if (!pki)
187  pki = new XrdCryptosslRSA(X509_get_pubkey(cert), 0);
188 }
#define DEBUG(x)
Definition: XrdBwmTrace.hh:54
#define EPNAME(x)
Definition: XrdBwmTrace.hh:56
int fclose(FILE *stream)
#define close(a)
Definition: XrdPosix.hh:48
#define fstat(a, b)
Definition: XrdPosix.hh:62
#define open
Definition: XrdPosix.hh:78
#define stat(a, b)
Definition: XrdPosix.hh:105
const char * Issuer()
const char * Subject()

References close, DEBUG, EPNAME, fclose(), fstat, Issuer(), XrdCryptoRSA::kComplete, open, stat, and Subject().

+ Here is the call graph for this function:

◆ XrdCryptosslX509() [2/3]

XrdCryptosslX509::XrdCryptosslX509 ( XrdSutBucket bck)

Definition at line 191 of file XrdCryptosslX509.cc.

191  : XrdCryptoX509()
192 {
193  // Constructor certificate from BIO 'bcer'
194  EPNAME("X509::XrdCryptosslX509_bio");
195 
196  // Init private members
197  cert = 0; // The certificate object
198  notbefore = -1; // begin-validity time in secs since Epoch
199  notafter = -1; // end-validity time in secs since Epoch
200  subject = ""; // subject;
201  issuer = ""; // issuer;
202  subjecthash = ""; // hash of subject;
203  issuerhash = ""; // hash of issuer;
204  subjectoldhash = ""; // hash of subject (md5 algorithm);
205  issueroldhash = ""; // hash of issuer (md5 algorithm);
206  srcfile = ""; // source file;
207  bucket = 0; // bucket for serialization
208  pki = 0; // PKI of the certificate
209  pxytype = 0; // Proxy sub-type
210 
211  // Make sure we got something;
212  if (!buck) {
213  DEBUG("got undefined opaque buffer");
214  return;
215  }
216 
217  //
218  // Create a bio_mem to store the certificates
219  BIO *bmem = BIO_new(BIO_s_mem());
220  if (!bmem) {
221  DEBUG("unable to create BIO for memory operations");
222  return;
223  }
224 
225  // Write data to BIO
226  int nw = BIO_write(bmem,(const void *)(buck->buffer),buck->size);
227  if (nw != buck->size) {
228  DEBUG("problems writing data to memory BIO (nw: "<<nw<<")");
229  return;
230  }
231 
232  // Get certificate from BIO
233  if (!(cert = PEM_read_bio_X509(bmem,0,0,0))) {
234  DEBUG("unable to read certificate to memory BIO");
235  return;
236  }
237  //
238  // Free BIO
239  BIO_free(bmem);
240 
241  //
242  // Init some of the private members (the others upon need)
243  Subject();
244  Issuer();
245  CertType();
246 
247  // Get the public key
248  EVP_PKEY *evpp = X509_get_pubkey(cert);
249  //
250  if (evpp) {
251  // init pki with the partial key
252  if (!pki)
253  pki = new XrdCryptosslRSA(evpp, 0);
254  } else {
255  DEBUG("could not access the public key");
256  }
257 }

References XrdSutBucket::buffer, DEBUG, EPNAME, Issuer(), XrdSutBucket::size, and Subject().

+ Here is the call graph for this function:

◆ XrdCryptosslX509() [3/3]

XrdCryptosslX509::XrdCryptosslX509 ( X509 *  cert)

Definition at line 260 of file XrdCryptosslX509.cc.

260  : XrdCryptoX509()
261 {
262  // Constructor: import X509 object
263  EPNAME("X509::XrdCryptosslX509_x509");
264 
265  // Init private members
266  cert = 0; // The certificate object
267  notbefore = -1; // begin-validity time in secs since Epoch
268  notafter = -1; // end-validity time in secs since Epoch
269  subject = ""; // subject;
270  issuer = ""; // issuer;
271  subjecthash = ""; // hash of subject;
272  issuerhash = ""; // hash of issuer;
273  subjectoldhash = ""; // hash of subject (md5 algorithm);
274  issueroldhash = ""; // hash of issuer (md5 algorithm);
275  srcfile = ""; // source file;
276  bucket = 0; // bucket for serialization
277  pki = 0; // PKI of the certificate
278  pxytype = 0; // Proxy sub-type
279 
280  // Make sure we got something;
281  if (!xc) {
282  DEBUG("got undefined X509 object");
283  return;
284  }
285 
286  // Set certificate
287  cert = xc;
288 
289  //
290  // Init some of the private members (the others upon need)
291  Subject();
292  Issuer();
293  CertType();
294 
295  // Get the public key
296  EVP_PKEY *evpp = X509_get_pubkey(cert);
297  //
298  if (evpp) {
299  // init pki with the partial key
300  if (!pki)
301  pki = new XrdCryptosslRSA(evpp, 0);
302  } else {
303  DEBUG("could not access the public key");
304  }
305 }

References DEBUG, EPNAME, Issuer(), and Subject().

+ Here is the call graph for this function:

◆ ~XrdCryptosslX509()

XrdCryptosslX509::~XrdCryptosslX509 ( )
virtual

Definition at line 308 of file XrdCryptosslX509.cc.

309 {
310  // Destructor
311 
312  // Cleanup certificate
313  if (cert) X509_free(cert);
314  // Cleanup key
315  if (pki) delete pki;
316 }

Member Function Documentation

◆ BitStrength()

int XrdCryptosslX509::BitStrength ( )
inlinevirtual

Reimplemented from XrdCryptoX509.

Definition at line 77 of file XrdCryptosslX509.hh.

77 { return ((cert) ? EVP_PKEY_bits(X509_get_pubkey(cert)) : -1);}

◆ DumpExtensions()

int XrdCryptosslX509::DumpExtensions ( bool  dumpunknown = 0)
virtual

Reimplemented from XrdCryptoX509.

Definition at line 807 of file XrdCryptosslX509.cc.

808 {
809  // Dump our extensions, if any
810  // Returns -1 on failure, 0 on success
811  EPNAME("DumpExtensions");
812 
813  int rc = -1;
814  // Point to the cerificate
815  X509 *xpi = (X509 *) Opaque();
816 
817  // Make sure we got the right inputs
818  if (!xpi) {
819  PRINT("we are empty! Do nothing");
820  return rc;
821  }
822 
823  rc = 1;
824  // Go through the extensions
825  X509_EXTENSION *xpiext = 0;
826  int npiext = X509_get_ext_count(xpi);
827  PRINT("found "<<npiext<<" extensions ");
828  int i = 0;
829  for (i = 0; i< npiext; i++) {
830  xpiext = X509_get_ext(xpi, i);
831  char s[256];
832  OBJ_obj2txt(s, sizeof(s), X509_EXTENSION_get_object(xpiext), 1);
833  int crit = X509_EXTENSION_get_critical(xpiext);
834  // Notify what we found
835  PRINT(i << ": found extension '"<<s<<"', critical: " << crit);
836  // Dump its content
837  rc = 0;
838  const unsigned char *pp = (const unsigned char *) X509_EXTENSION_get_data(xpiext)->data;
839  long length = X509_EXTENSION_get_data(xpiext)->length;
840  int ret = FillUnknownExt(&pp, length, dumpunknown);
841  PRINT("ret: " << ret);
842  }
843 
844  // Done
845  return rc;
846 }
#define PRINT(y)
XrdCryptoX509data Opaque()

References EPNAME, Opaque(), and PRINT.

+ Here is the call graph for this function:

◆ Export()

XrdSutBucket * XrdCryptosslX509::Export ( )
virtual

Reimplemented from XrdCryptoX509.

Definition at line 717 of file XrdCryptosslX509.cc.

718 {
719  // Export in form of bucket
720  EPNAME("X509::Export");
721 
722  // If we have already done it, return the previous result
723  if (bucket) {
724  DEBUG("serialization already performed:"
725  " return previous result ("<<bucket->size<<" bytes)");
726  return bucket;
727  }
728 
729  // Make sure we got something to export
730  if (!cert) {
731  DEBUG("certificate is not initialized");
732  return 0;
733  }
734 
735  //
736  // Now we create a bio_mem to serialize the certificate
737  BIO *bmem = BIO_new(BIO_s_mem());
738  if (!bmem) {
739  DEBUG("unable to create BIO for memory operations");
740  return 0;
741  }
742 
743  // Write certificate to BIO
744  if (!PEM_write_bio_X509(bmem, cert)) {
745  DEBUG("unable to write certificate to memory BIO");
746  return 0;
747  }
748 
749  // Extract pointer to BIO data and length of segment
750  char *bdata = 0;
751  int blen = BIO_get_mem_data(bmem, &bdata);
752  DEBUG("BIO data: "<<blen<<" bytes at 0x"<<(int *)bdata);
753 
754  // create the bucket now
755  bucket = new XrdSutBucket(0,0,kXRS_x509);
756  if (bucket) {
757  // Fill bucket
758  bucket->SetBuf(bdata, blen);
759  DEBUG("result of serialization: "<<bucket->size<<" bytes");
760  } else {
761  DEBUG("unable to create bucket for serialized format");
762  BIO_free(bmem);
763  return 0;
764  }
765  //
766  // Free BIO
767  BIO_free(bmem);
768  //
769  // We are done
770  return bucket;
771 }
@ kXRS_x509
Definition: XrdSutAux.hh:79
kXR_int32 size
Definition: XrdSutBucket.hh:47
int SetBuf(const char *nb=0, int ns=0)

References DEBUG, EPNAME, kXRS_x509, XrdSutBucket::SetBuf(), and XrdSutBucket::size.

+ Here is the call graph for this function:

◆ GetExtension()

XrdCryptoX509data XrdCryptosslX509::GetExtension ( const char *  oid)
virtual

Reimplemented from XrdCryptoX509.

Definition at line 654 of file XrdCryptosslX509.cc.

655 {
656  // Return pointer to extension with OID oid, if any, in
657  // opaque form
658  EPNAME("X509::GetExtension");
659  XrdCryptoX509data ext = 0;
660 
661  // Make sure we got something to look for
662  if (!oid) {
663  DEBUG("OID string not defined");
664  return ext;
665  }
666 
667  // Make sure we got something to look for
668  if (!cert) {
669  DEBUG("certificate is not initialized");
670  return ext;
671  }
672 
673  // Are there any extension?
674  int numext = X509_get_ext_count(cert);
675  if (numext <= 0) {
676  DEBUG("certificate has got no extensions");
677  return ext;
678  }
679  DEBUG("certificate has "<<numext<<" extensions");
680 
681  // If the string is the Standard Name of a known extension check
682  // searche the corresponding NID
683  int nid = OBJ_sn2nid(oid);
684  bool usenid = (nid > 0);
685 
686  // Loop to identify the one we would like
687  int i = 0;
688  X509_EXTENSION *wext = 0;
689  for (i = 0; i< numext; i++) {
690  wext = X509_get_ext(cert, i);
691  if (usenid) {
692  int enid = OBJ_obj2nid(X509_EXTENSION_get_object(wext));
693  if (enid == nid)
694  break;
695  } else {
696  // Try matching of the text
697  char s[256];
698  OBJ_obj2txt(s, sizeof(s), X509_EXTENSION_get_object(wext), 1);
699  if (!strcmp(s, oid))
700  break;
701  }
702  // Do not free the extension: its owned by the certificate
703  wext = 0;
704  }
705 
706  // We are done if nothing was found
707  if (!wext) {
708  DEBUG("Extension "<<oid<<" not found");
709  return ext;
710  }
711 
712  // We are done
713  return (XrdCryptoX509data)wext;
714 }
void * XrdCryptoX509data

References DEBUG, and EPNAME.

◆ Issuer()

const char * XrdCryptosslX509::Issuer ( )
virtual

Reimplemented from XrdCryptoX509.

Definition at line 509 of file XrdCryptosslX509.cc.

510 {
511  // Return issuer name
512  EPNAME("X509::Issuer");
513 
514  // If we do not have it already, try extraction
515  if (issuer.length() <= 0) {
516 
517  // Make sure we have a certificate
518  if (!cert) {
519  DEBUG("WARNING: no certificate available - cannot extract issuer name");
520  return (const char *)0;
521  }
522 
523  // Extract issuer name
524  XrdCryptosslNameOneLine(X509_get_issuer_name(cert), issuer);
525  }
526 
527  // return what we have
528  return (issuer.length() > 0) ? issuer.c_str() : (const char *)0;
529 }
void XrdCryptosslNameOneLine(X509_NAME *nm, XrdOucString &s)
const char * c_str() const
int length() const

References XrdOucString::c_str(), DEBUG, EPNAME, XrdOucString::length(), and XrdCryptosslNameOneLine().

Referenced by XrdCryptosslX509().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ IssuerHash()

const char * XrdCryptosslX509::IssuerHash ( int  alg = 0)
virtual

Reimplemented from XrdCryptoX509.

Definition at line 532 of file XrdCryptosslX509.cc.

533 {
534  // Return hash of issuer name
535  // Use default algorithm (X509_NAME_hash) for alg = 0, old algorithm
536  // (for v>=1.0.0) when alg = 1
537  EPNAME("X509::IssuerHash");
538 
539  if (alg == 1) {
540  // md5 based
541  if (issueroldhash.length() <= 0) {
542  // Make sure we have a certificate
543  if (cert) {
544  char chash[30] = {0};
545  snprintf(chash, sizeof(chash),
546  "%08lx.0",X509_NAME_hash_old(X509_get_issuer_name(cert)));
547  issueroldhash = chash;
548  } else {
549  DEBUG("WARNING: no certificate available - cannot extract issuer hash (md5)");
550  }
551  }
552  // return what we have
553  return (issueroldhash.length() > 0) ? issueroldhash.c_str() : (const char *)0;
554  }
555 
556  // If we do not have it already, try extraction
557  if (issuerhash.length() <= 0) {
558 
559  // Make sure we have a certificate
560  if (cert) {
561  char chash[30] = {0};
562  snprintf(chash, sizeof(chash),
563  "%08lx.0",X509_NAME_hash(X509_get_issuer_name(cert)));
564  issuerhash = chash;
565  } else {
566  DEBUG("WARNING: no certificate available - cannot extract issuer hash (default)");
567  }
568  }
569 
570  // return what we have
571  return (issuerhash.length() > 0) ? issuerhash.c_str() : (const char *)0;
572 }

References XrdOucString::c_str(), DEBUG, EPNAME, and XrdOucString::length().

+ Here is the call graph for this function:

◆ MatchesSAN()

bool XrdCryptosslX509::MatchesSAN ( const char *  fqdn,
bool &  hasSAN 
)
virtual

Implements XrdCryptoX509.

Definition at line 1112 of file XrdCryptosslX509.cc.

1113 {
1114  EPNAME("MatchesSAN");
1115 
1116  // Statically allocated array for hostname lengths. RFC1035 limits
1117  // valid lengths to 255 characters.
1118  char san_fqdn[256];
1119 
1120  // Assume we have no SAN extension. Failure may allow the caller to try
1121  // using the common name before giving up.
1122  hasSAN = false;
1123 
1124  GENERAL_NAMES *gens = static_cast<GENERAL_NAMES *>(X509_get_ext_d2i(cert,
1125  NID_subject_alt_name, NULL, NULL));
1126  if (!gens)
1127  return false;
1128 
1129  // Only an EEC is usable as a host certificate.
1130  if (type != kEEC)
1131  return false;
1132 
1133  // All failures are under the notion that we have a SAN extension.
1134  hasSAN = true;
1135 
1136  if (!fqdn)
1137  return false;
1138 
1139  bool success = false;
1140  for (int idx = 0; idx < sk_GENERAL_NAME_num(gens); idx++) {
1141  GENERAL_NAME *gen;
1142  ASN1_STRING *cstr;
1143  gen = sk_GENERAL_NAME_value(gens, idx);
1144  if (gen->type != GEN_DNS)
1145  continue;
1146  cstr = gen->d.dNSName;
1147  if (ASN1_STRING_type(cstr) != V_ASN1_IA5STRING)
1148  continue;
1149  int san_fqdn_len = ASN1_STRING_length(cstr);
1150  if (san_fqdn_len > 255)
1151  continue;
1152  memcpy(san_fqdn, ASN1_STRING_get0_data(cstr), san_fqdn_len);
1153  san_fqdn[san_fqdn_len] = '\0';
1154  if (strlen(san_fqdn) != static_cast<size_t>(san_fqdn_len)) // Avoid embedded null's.
1155  continue;
1156  DEBUG("Comparing SAN " << san_fqdn << " with " << fqdn);
1157  if (MatchHostnames(san_fqdn, fqdn)) {
1158  DEBUG("SAN " << san_fqdn << " matches with " << fqdn);
1159  success = true;
1160  break;
1161  }
1162  }
1163  sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free);
1164  return success;
1165 }
static bool MatchHostnames(const char *match_pattern, const char *fqdn)
EX509Type type

References DEBUG, EPNAME, XrdCryptoX509::kEEC, XrdCryptoX509::MatchHostnames(), and XrdCryptoX509::type.

+ Here is the call graph for this function:

◆ NotAfter()

time_t XrdCryptosslX509::NotAfter ( )
virtual

Reimplemented from XrdCryptoX509.

Definition at line 470 of file XrdCryptosslX509.cc.

471 {
472  // End-validity time in secs since Epoch
473 
474  // If we do not have it already, try extraction
475  if (notafter < 0) {
476  // Make sure we have a certificate
477  if (cert)
478  // Extract UTC time in secs from Epoch
479  notafter = XrdCryptosslASN1toUTC(X509_get_notAfter(cert));
480  }
481  // return what we have
482  return notafter;
483 }
time_t XrdCryptosslASN1toUTC(const ASN1_TIME *tsn1)

References XrdCryptosslASN1toUTC().

+ Here is the call graph for this function:

◆ NotBefore()

time_t XrdCryptosslX509::NotBefore ( )
virtual

Reimplemented from XrdCryptoX509.

Definition at line 454 of file XrdCryptosslX509.cc.

455 {
456  // Begin-validity time in secs since Epoch
457 
458  // If we do not have it already, try extraction
459  if (notbefore < 0) {
460  // Make sure we have a certificate
461  if (cert)
462  // Extract UTC time in secs from Epoch
463  notbefore = XrdCryptosslASN1toUTC(X509_get_notBefore(cert));
464  }
465  // return what we have
466  return notbefore;
467 }

References XrdCryptosslASN1toUTC().

+ Here is the call graph for this function:

◆ Opaque()

XrdCryptoX509data XrdCryptosslX509::Opaque ( )
inlinevirtual

Reimplemented from XrdCryptoX509.

Definition at line 58 of file XrdCryptosslX509.hh.

58 { return (XrdCryptoX509data)cert; }

Referenced by DumpExtensions().

+ Here is the caller graph for this function:

◆ ParentFile()

const char* XrdCryptosslX509::ParentFile ( )
inlinevirtual

Reimplemented from XrdCryptoX509.

Definition at line 71 of file XrdCryptosslX509.hh.

71 { return (const char *)(srcfile.c_str()); }

References XrdOucString::c_str().

+ Here is the call graph for this function:

◆ PKI()

XrdCryptoRSA* XrdCryptosslX509::PKI ( )
inlinevirtual

Reimplemented from XrdCryptoX509.

Definition at line 64 of file XrdCryptosslX509.hh.

64 { return pki; }

◆ ProxyType()

const char* XrdCryptosslX509::ProxyType ( ) const
inlinevirtual

Reimplemented from XrdCryptoX509.

Definition at line 74 of file XrdCryptosslX509.hh.

74 { return cpxytype[pxytype]; }

◆ SerialNumber()

kXR_int64 XrdCryptosslX509::SerialNumber ( )
virtual

Reimplemented from XrdCryptoX509.

Definition at line 618 of file XrdCryptosslX509.cc.

619 {
620  // Return serial number as a kXR_int64
621 
622  kXR_int64 sernum = -1;
623  if (cert && X509_get_serialNumber(cert)) {
624  BIGNUM *bn = BN_new();
625  ASN1_INTEGER_to_BN(X509_get_serialNumber(cert), bn);
626  char *sn = BN_bn2dec(bn);
627  sernum = strtoll(sn, 0, 10);
628  BN_free(bn);
629  OPENSSL_free(sn);
630  }
631 
632  return sernum;
633 }
long long kXR_int64
Definition: XPtypes.hh:98

◆ SerialNumberString()

XrdOucString XrdCryptosslX509::SerialNumberString ( )
virtual

Reimplemented from XrdCryptoX509.

Definition at line 636 of file XrdCryptosslX509.cc.

637 {
638  // Return serial number as a hex string
639 
640  XrdOucString sernum;
641  if (cert && X509_get_serialNumber(cert)) {
642  BIGNUM *bn = BN_new();
643  ASN1_INTEGER_to_BN(X509_get_serialNumber(cert), bn);
644  char *sn = BN_bn2hex(bn);
645  sernum = sn;
646  BN_free(bn);
647  OPENSSL_free(sn);
648  }
649 
650  return sernum;
651 }

◆ SetPKI()

void XrdCryptosslX509::SetPKI ( XrdCryptoX509data  pki)
virtual

Reimplemented from XrdCryptoX509.

Definition at line 429 of file XrdCryptosslX509.cc.

430 {
431  // SetPKI:
432  // if newpki is null does nothing
433  // if newpki contains a consistent private & public key we take ownership
434  // so that this->PKI()->status will be kComplete.
435  // otherwise, newpki is not consistent:
436  // if the previous PKI() was null or was already kComplete it is and reset
437  // so that this->PKI()->status will be kInvalid.
438 
439  if (!newpki) return;
440 
441  auto tmprsa = std::make_unique<XrdCryptosslRSA>((EVP_PKEY*)newpki, 1);
442  if (!pki || pki->status == XrdCryptoRSA::kComplete ||
443  tmprsa->status == XrdCryptoRSA::kComplete) {
444  // Cleanup any existing key first
445  if (pki)
446  delete pki;
447 
448  // Set PKI
449  pki = tmprsa.release();
450  }
451 }
ERSAStatus status
Definition: XrdCryptoRSA.hh:58

References XrdCryptoRSA::kComplete, and XrdCryptoRSA::status.

◆ Subject()

const char * XrdCryptosslX509::Subject ( )
virtual

Reimplemented from XrdCryptoX509.

Definition at line 486 of file XrdCryptosslX509.cc.

487 {
488  // Return subject name
489  EPNAME("X509::Subject");
490 
491  // If we do not have it already, try extraction
492  if (subject.length() <= 0) {
493 
494  // Make sure we have a certificate
495  if (!cert) {
496  DEBUG("WARNING: no certificate available - cannot extract subject name");
497  return (const char *)0;
498  }
499 
500  // Extract subject name
501  XrdCryptosslNameOneLine(X509_get_subject_name(cert), subject);
502  }
503 
504  // return what we have
505  return (subject.length() > 0) ? subject.c_str() : (const char *)0;
506 }

References XrdOucString::c_str(), DEBUG, EPNAME, XrdOucString::length(), and XrdCryptosslNameOneLine().

Referenced by XrdCryptosslX509().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SubjectHash()

const char * XrdCryptosslX509::SubjectHash ( int  alg = 0)
virtual

Reimplemented from XrdCryptoX509.

Definition at line 575 of file XrdCryptosslX509.cc.

576 {
577  // Return hash of subject name
578  // Use default algorithm (X509_NAME_hash) for alg = 0, old algorithm
579  // (for v>=1.0.0) when alg = 1
580  EPNAME("X509::SubjectHash");
581 
582  if (alg == 1) {
583  // md5 based
584  if (subjectoldhash.length() <= 0) {
585  // Make sure we have a certificate
586  if (cert) {
587  char chash[30] = {0};
588  snprintf(chash, sizeof(chash),
589  "%08lx.0",X509_NAME_hash_old(X509_get_subject_name(cert)));
590  subjectoldhash = chash;
591  } else {
592  DEBUG("WARNING: no certificate available - cannot extract subject hash (md5)");
593  }
594  }
595  // return what we have
596  return (subjectoldhash.length() > 0) ? subjectoldhash.c_str() : (const char *)0;
597  }
598 
599  // If we do not have it already, try extraction
600  if (subjecthash.length() <= 0) {
601 
602  // Make sure we have a certificate
603  if (cert) {
604  char chash[30] = {0};
605  snprintf(chash, sizeof(chash),
606  "%08lx.0",X509_NAME_hash(X509_get_subject_name(cert)));
607  subjecthash = chash;
608  } else {
609  DEBUG("WARNING: no certificate available - cannot extract subject hash (default)");
610  }
611  }
612 
613  // return what we have
614  return (subjecthash.length() > 0) ? subjecthash.c_str() : (const char *)0;
615 }

References XrdOucString::c_str(), DEBUG, EPNAME, and XrdOucString::length().

+ Here is the call graph for this function:

◆ Verify()

bool XrdCryptosslX509::Verify ( XrdCryptoX509 ref)
virtual

Reimplemented from XrdCryptoX509.

Definition at line 774 of file XrdCryptosslX509.cc.

775 {
776  // Verify certificate signature with pub key of ref cert
777  EPNAME("X509::Verify");
778 
779  // We must have been initialized
780  if (!cert)
781  return 0;
782 
783  // We must have something to check with
784  X509 *r = ref ? (X509 *)(ref->Opaque()) : 0;
785  EVP_PKEY *rk = r ? X509_get_pubkey(r) : 0;
786  if (!rk)
787  return 0;
788 
789  // Ok: we can verify
790  int rc = X509_verify(cert, rk);
791  EVP_PKEY_free(rk);
792  if (rc <= 0) {
793  if (rc == 0) {
794  // Signatures are not OK
795  DEBUG("signature not OK");
796  } else {
797  // General failure
798  DEBUG("could not verify signature");
799  }
800  return 0;
801  }
802  // Success
803  return 1;
804 }
virtual XrdCryptoX509data Opaque()

References DEBUG, EPNAME, and XrdCryptoX509::Opaque().

+ Here is the call graph for this function:

The documentation for this class was generated from the following files: