XRootD
Loading...
Searching...
No Matches
XrdCryptosslX509Crl Class Reference

#include <XrdCryptosslX509Crl.hh>

Inheritance diagram for XrdCryptosslX509Crl:
Collaboration diagram for XrdCryptosslX509Crl:

Public Member Functions

 XrdCryptosslX509Crl (const char *crlf, int opt=0)
 XrdCryptosslX509Crl (FILE *, const char *crlf)
 XrdCryptosslX509Crl (XrdCryptoX509 *cacert)
virtual ~XrdCryptosslX509Crl ()
void Dump ()
bool hasCriticalExtension ()
bool IsRevoked (const char *sernum, int when=0)
bool IsRevoked (int serialnumber, int when=0)
const char * Issuer ()
const char * IssuerHash (int)
bool IsValid ()
time_t LastUpdate ()
time_t NextUpdate ()
XrdCryptoX509Crldata Opaque ()
const char * ParentFile ()
bool ToFile (FILE *fh)
bool Verify (XrdCryptoX509 *ref)
Public Member Functions inherited from XrdCryptoX509Crl
 XrdCryptoX509Crl ()
virtual ~XrdCryptoX509Crl ()
virtual bool IsExpired (int when=0)
const char * IssuerHash ()

Detailed Description

Definition at line 50 of file XrdCryptosslX509Crl.hh.

Constructor & Destructor Documentation

◆ XrdCryptosslX509Crl() [1/3]

XrdCryptosslX509Crl::XrdCryptosslX509Crl ( const char * crlf,
int opt = 0 )

Definition at line 51 of file XrdCryptosslX509Crl.cc.

53{
54 // Constructor certificate from file 'cf'.
55 EPNAME("X509Crl::XrdCryptosslX509Crl_file");
56
57 // Make sure file name is defined;
58 if (opt == 0) {
59 if (Init(cf) != 0) {
60 DEBUG("could not initialize the CRL from "<<cf);
61 return;
62 }
63 } else {
64 if (InitFromURI(cf, 0) != 0) {
65 DEBUG("could not initialize the CRL from URI"<<cf);
66 return;
67 }
68 }
69}
#define DEBUG(x)
#define EPNAME(x)

References XrdCryptoX509Crl::XrdCryptoX509Crl(), DEBUG, and EPNAME.

Referenced by XrdCryptosslFactory::X509Crl(), and XrdCryptosslFactory::X509Crl().

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

◆ XrdCryptosslX509Crl() [2/3]

XrdCryptosslX509Crl::XrdCryptosslX509Crl ( FILE * fc,
const char * crlf )

Definition at line 72 of file XrdCryptosslX509Crl.cc.

73{
74 // Constructe CRL from a FILE handle `fc` with (assumed) filename `cf`.
75 EPNAME("X509Crl::XrdCryptosslX509Crl_file");
76
77 if (Init(fc, cf)) {
78 DEBUG("could not initialize the CRL from " << cf);
79 return;
80 }
81}

References DEBUG, and EPNAME.

◆ XrdCryptosslX509Crl() [3/3]

XrdCryptosslX509Crl::XrdCryptosslX509Crl ( XrdCryptoX509 * cacert)

Definition at line 84 of file XrdCryptosslX509Crl.cc.

86{
87 // Constructor certificate from CA certificate 'cacert'. This constructor
88 // extracts the information about the location of the CRL cerificate from the
89 // CA certificate extension 'crlDistributionPoints', downloads the file and
90 // loads it in the cache
91 EPNAME("X509Crl::XrdCryptosslX509Crl_CA");
92
93 // The CA certificate must be defined
94 if (!cacert || cacert->type != XrdCryptoX509::kCA) {
95 DEBUG("the CA certificate is undefined or not CA! ("<<cacert<<")");
96 return;
97 }
98
99 // Get the extension
100 X509_EXTENSION *crlext = (X509_EXTENSION *) cacert->GetExtension("crlDistributionPoints");
101 if (!crlext) {
102 DEBUG("extension 'crlDistributionPoints' not found in the CA certificate");
103 return;
104 }
105
106 // Bio for exporting the extension
107 BIO *bext = BIO_new(BIO_s_mem());
108 const ASN1_OBJECT *obj = X509_EXTENSION_get_object(crlext);
109 i2a_ASN1_OBJECT(bext, obj);
110 X509V3_EXT_print(bext, crlext, 0, 4);
111 // data length
112 char *cbio = 0;
113 int lbio = (int) BIO_get_mem_data(bext, &cbio);
114 char *buf = (char *) malloc(lbio+1);
115 // Read key from BIO to buf
116 memcpy(buf, cbio, lbio);
117 buf[lbio] = 0;
118 BIO_free(bext);
119 // Save it
120 XrdOucString uris(buf);
121 free(buf);
122
123 DEBUG("URI string: "<< uris);
124
125 XrdOucString uri;
126 int from = 0;
127 while ((from = uris.tokenize(uri, from, ' ')) != -1) {
128 if (uri.beginswith("URI:")) {
129 uri.replace("URI:","");
130 uri.replace("\n","");
131 if (InitFromURI(uri.c_str(), cacert->SubjectHash()) == 0) {
132 crluri = uri;
133 // We are done
134 break;
135 }
136 }
137 }
138}
virtual XrdCryptoX509data GetExtension(const char *oid)
virtual const char * SubjectHash(int)
bool beginswith(char c)
int replace(const char *s1, const char *s2, int from=0, int to=-1)
const char * c_str() const

References XrdCryptoX509Crl::XrdCryptoX509Crl(), XrdOucString::beginswith(), XrdOucString::c_str(), DEBUG, EPNAME, XrdCryptoX509::GetExtension(), XrdCryptoX509::kCA, XrdOucString::replace(), XrdCryptoX509::SubjectHash(), XrdOucString::tokenize(), and XrdCryptoX509::type.

Here is the call graph for this function:

◆ ~XrdCryptosslX509Crl()

XrdCryptosslX509Crl::~XrdCryptosslX509Crl ( )
virtual

Definition at line 141 of file XrdCryptosslX509Crl.cc.

142{
143 // Destructor
144
145 // Cleanup CRL
146 if (crl)
147 X509_CRL_free(crl);
148}

Member Function Documentation

◆ Dump()

void XrdCryptosslX509Crl::Dump ( )
virtual

Reimplemented from XrdCryptoX509Crl.

Definition at line 663 of file XrdCryptosslX509Crl.cc.

664{
665 // Dump content
666 EPNAME("X509Crl::Dump");
667
668 // Time strings
669 struct tm tst;
670 char stbeg[256] = {0};
671 time_t tbeg = LastUpdate();
672 localtime_r(&tbeg,&tst);
673 asctime_r(&tst,stbeg);
674 stbeg[strlen(stbeg)-1] = 0;
675 char stend[256] = {0};
676 time_t tend = NextUpdate();
677 localtime_r(&tend,&tst);
678 asctime_r(&tst,stend);
679 stend[strlen(stend)-1] = 0;
680
681 PRINT("+++++++++++++++ X509 CRL dump +++++++++++++++++++++++");
682 PRINT("+");
683 PRINT("+ File: "<<ParentFile());
684 PRINT("+");
685 PRINT("+ Issuer: "<<Issuer());
686 PRINT("+ Issuer hash: "<<IssuerHash(0));
687 PRINT("+");
688 if (IsExpired()) {
689 PRINT("+ Validity: (expired!)");
690 } else {
691 PRINT("+ Validity:");
692 }
693 PRINT("+ LastUpdate: "<<tbeg<<" UTC - "<<stbeg);
694 PRINT("+ NextUpdate: "<<tend<<" UTC - "<<stend);
695 PRINT("+");
696 PRINT("+ Number of revoked certificates: "<<nrevoked);
697 PRINT("+");
698 PRINT("+++++++++++++++++++++++++++++++++++++++++++++++++");
699}
#define PRINT(y)
virtual bool IsExpired(int when=0)
const char * IssuerHash(int)

References EPNAME, XrdCryptoX509Crl::IsExpired(), Issuer(), IssuerHash(), LastUpdate(), NextUpdate(), ParentFile(), and PRINT.

Here is the call graph for this function:

◆ hasCriticalExtension()

bool XrdCryptosslX509Crl::hasCriticalExtension ( )

Definition at line 378 of file XrdCryptosslX509Crl.cc.

378 {
379 // If the X509_CRL_get_ext_by_critical() function returns -1, no critical extension
380 // has been found
381 return X509_CRL_get_ext_by_critical(crl,1,-1) != -1;
382}

◆ IsRevoked() [1/2]

bool XrdCryptosslX509Crl::IsRevoked ( const char * sernum,
int when = 0 )
virtual

Reimplemented from XrdCryptoX509Crl.

Definition at line 625 of file XrdCryptosslX509Crl.cc.

626{
627 // Check if certificate with 'sernum' is in the
628 // list of revocated certificates
629 EPNAME("IsRevoked");
630
631 // Reference time
632 int now = (when > 0) ? when : time(0);
633
634 // Warn if CRL should be updated
635 if (now > NextUpdate()) {
636 DEBUG("WARNING: CRL is expired: you should download the updated one");
637 }
638
639 // We must have something to check against
640 if (nrevoked <= 0) {
641 DEBUG("No certificate in the list");
642 return 0;
643 }
644
645 // Look into the cache
646 bool revoked = false;
647 XrdSutCacheEntry *cent = cache.Get((const char *)sernum);
648 if (cent) {
649 // Check the revocation time
650 if (cent->status == kCE_ok && now > cent->mtime) {
651 DEBUG("certificate "<<sernum<<" has been revoked");
652 revoked = true;
653 }
654 cent->rwmtx.UnLock();
655 }
656 if (revoked) return 1;
657
658 // Certificate not revoked
659 return 0;
660}
@ kCE_ok

References DEBUG, EPNAME, kCE_ok, XrdSutCacheEntry::mtime, NextUpdate(), XrdSutCacheEntry::rwmtx, XrdSutCacheEntry::status, and XrdSysRWLock::UnLock().

Here is the call graph for this function:

◆ IsRevoked() [2/2]

bool XrdCryptosslX509Crl::IsRevoked ( int serialnumber,
int when = 0 )
virtual

Reimplemented from XrdCryptoX509Crl.

Definition at line 564 of file XrdCryptosslX509Crl.cc.

565{
566 // Check if certificate with serialnumber is in the
567 // list of revocated certificates
568 EPNAME("IsRevoked");
569
570 // Reference time
571 int now = (when > 0) ? when : time(0);
572
573 // Warn if CRL should be updated
574 if (now > NextUpdate()) {
575 DEBUG("WARNING: CRL is expired: you should download the updated one");
576 }
577
578 // We must have something to check against
579 if (nrevoked <= 0) {
580 DEBUG("No certificate in the list");
581 return 0;
582 }
583
584 // A serial number is never negative
585 if (serialnumber < 0) {
586 DEBUG("invalid serial number: "<<serialnumber);
587 return 0;
588 }
589
590 // Ok, build the tag: the cache is keyed with the serial number in the
591 // format produced by BN_bn2hex(), i.e. upper case with an even number
592 // of digits, so we must use the same format here
593 BIGNUM *bn = BN_new();
594 if (!bn) {
595 DEBUG("could not allocate a big number");
596 return 0;
597 }
598 BN_set_word(bn, (BN_ULONG)serialnumber);
599 char *tagser = BN_bn2hex(bn);
600 BN_free(bn);
601 if (!tagser) {
602 DEBUG("could not format the serial number");
603 return 0;
604 }
605
606 // Look into the cache
607 bool revoked = false;
608 XrdSutCacheEntry *cent = cache.Get((const char *)tagser);
609 if (cent) {
610 // Check the revocation time
611 if (cent->status == kCE_ok && now > cent->mtime) {
612 DEBUG("certificate "<<tagser<<" has been revoked");
613 revoked = true;
614 }
615 cent->rwmtx.UnLock();
616 }
617 OPENSSL_free(tagser);
618 if (revoked) return 1;
619
620 // Certificate not revoked
621 return 0;
622}

References DEBUG, EPNAME, kCE_ok, XrdSutCacheEntry::mtime, NextUpdate(), XrdSutCacheEntry::rwmtx, XrdSutCacheEntry::status, and XrdSysRWLock::UnLock().

Here is the call graph for this function:

◆ Issuer()

const char * XrdCryptosslX509Crl::Issuer ( )
virtual

Reimplemented from XrdCryptoX509Crl.

Definition at line 479 of file XrdCryptosslX509Crl.cc.

480{
481 // Return issuer name
482 EPNAME("X509Crl::Issuer");
483
484 // If we do not have it already, try extraction
485 if (issuer.length() <= 0) {
486
487 // Make sure we have a CRL
488 if (!crl) {
489 DEBUG("WARNING: no CRL available - cannot extract issuer name");
490 return (const char *)0;
491 }
492
493 // Extract issuer name
494 XrdCryptosslNameOneLine(X509_CRL_get_issuer(crl), issuer);
495 }
496
497 // return what we have
498 return (issuer.length() > 0) ? issuer.c_str() : (const char *)0;
499}
void XrdCryptosslNameOneLine(const X509_NAME *nm, XrdOucString &s)

References DEBUG, EPNAME, and XrdCryptosslNameOneLine().

Referenced by Dump().

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

◆ IssuerHash()

const char * XrdCryptosslX509Crl::IssuerHash ( int alg)
virtual

Reimplemented from XrdCryptoX509Crl.

Definition at line 502 of file XrdCryptosslX509Crl.cc.

503{
504 // Return hash of issuer name
505 // Use default algorithm (X509_NAME_hash) for alg = 0, old algorithm
506 // (for v>=1.0.0) when alg = 1
507 EPNAME("X509::IssuerHash");
508
509 if (alg == 1) {
510 // md5 based
511 if (issueroldhash.length() <= 0) {
512 // Make sure we have a certificate
513 if (crl) {
514 char chash[30] = {0};
515 snprintf(chash, sizeof(chash),
516 "%08lx.0",X509_NAME_hash_old(X509_CRL_get_issuer(crl)));
517 issueroldhash = chash;
518 } else {
519 DEBUG("WARNING: no certificate available - cannot extract issuer hash (md5)");
520 }
521 }
522 // return what we have
523 return (issueroldhash.length() > 0) ? issueroldhash.c_str() : (const char *)0;
524 }
525
526 // If we do not have it already, try extraction
527 if (issuerhash.length() <= 0) {
528
529 // Make sure we have a certificate
530 if (crl) {
531 char chash[30] = {0};
532 snprintf(chash, sizeof(chash),
533 "%08lx.0",X509_NAME_hash(X509_CRL_get_issuer(crl)));
534 issuerhash = chash;
535 } else {
536 DEBUG("WARNING: no certificate available - cannot extract issuer hash (default)");
537 }
538 }
539
540 // return what we have
541 return (issuerhash.length() > 0) ? issuerhash.c_str() : (const char *)0;
542}

References DEBUG, and EPNAME.

Referenced by Dump().

Here is the caller graph for this function:

◆ IsValid()

bool XrdCryptosslX509Crl::IsValid ( )
inlinevirtual

Reimplemented from XrdCryptoX509Crl.

Definition at line 59 of file XrdCryptosslX509Crl.hh.

59{ return (crl != 0); }

◆ LastUpdate()

time_t XrdCryptosslX509Crl::LastUpdate ( )
virtual

Reimplemented from XrdCryptoX509Crl.

Definition at line 447 of file XrdCryptosslX509Crl.cc.

448{
449 // Time of last update
450
451 // If we do not have it already, try extraction
452 if (lastupdate < 0) {
453 // Make sure we have a CRL
454 if (crl)
455 // Extract UTC time in secs from Epoch
456 lastupdate = XrdCryptosslASN1toUTC(X509_CRL_get0_lastUpdate(crl));
457 }
458 // return what we have
459 return lastupdate;
460}
time_t XrdCryptosslASN1toUTC(const ASN1_TIME *tsn1)

References XrdCryptosslASN1toUTC().

Referenced by Dump().

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

◆ NextUpdate()

time_t XrdCryptosslX509Crl::NextUpdate ( )
virtual

Reimplemented from XrdCryptoX509Crl.

Definition at line 463 of file XrdCryptosslX509Crl.cc.

464{
465 // Time of next update
466
467 // If we do not have it already, try extraction
468 if (nextupdate < 0) {
469 // Make sure we have a CRL
470 if (crl)
471 // Extract UTC time in secs from Epoch
472 nextupdate = XrdCryptosslASN1toUTC(X509_CRL_get0_nextUpdate(crl));
473 }
474 // return what we have
475 return nextupdate;
476}

References XrdCryptosslASN1toUTC().

Referenced by Dump(), IsRevoked(), and IsRevoked().

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

◆ Opaque()

XrdCryptoX509Crldata XrdCryptosslX509Crl::Opaque ( )
inlinevirtual

Reimplemented from XrdCryptoX509Crl.

Definition at line 62 of file XrdCryptosslX509Crl.hh.

62{ return (XrdCryptoX509Crldata)crl; }
void * XrdCryptoX509Crldata

◆ ParentFile()

const char * XrdCryptosslX509Crl::ParentFile ( )
inlinevirtual

Reimplemented from XrdCryptoX509Crl.

Definition at line 66 of file XrdCryptosslX509Crl.hh.

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

Referenced by Dump().

Here is the caller graph for this function:

◆ ToFile()

bool XrdCryptosslX509Crl::ToFile ( FILE * fh)

Definition at line 322 of file XrdCryptosslX509Crl.cc.

323{
324 // Write the CRL's contents to a file in the PEM format.
325 EPNAME("ToFile");
326
327 if (!crl) {
328 DEBUG("CRL object invalid; cannot write to a file");
329 return false;
330 }
331
332 if (PEM_write_X509_CRL(fh, crl) == 0) {
333 DEBUG("Unable to write CRL to file");
334 return false;
335 }
336
337 //
338 // Notify
339 DEBUG("CRL successfully written to file");
340
341 return true;
342}

References DEBUG, and EPNAME.

◆ Verify()

bool XrdCryptosslX509Crl::Verify ( XrdCryptoX509 * ref)
virtual

Reimplemented from XrdCryptoX509Crl.

Definition at line 545 of file XrdCryptosslX509Crl.cc.

546{
547 // Verify certificate signature with pub key of ref cert
548
549 // We must have been initialized
550 if (!crl)
551 return 0;
552
553 // We must have something to check with
554 X509 *r = ref ? (X509 *)(ref->Opaque()) : 0;
555 EVP_PKEY *rk = r ? X509_get_pubkey(r) : 0;
556 if (!rk)
557 return 0;
558
559 // Ok: we can verify
560 return (X509_CRL_verify(crl, rk) > 0);
561}
virtual XrdCryptoX509data Opaque()

References XrdCryptoX509::Opaque().

Here is the call graph for this function:

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