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 58 of file XrdCryptosslX509Crl.cc.

60{
61 // Constructor certificate from file 'cf'.
62 EPNAME("X509Crl::XrdCryptosslX509Crl_file");
63
64 // Make sure file name is defined;
65 if (opt == 0) {
66 if (Init(cf) != 0) {
67 DEBUG("could not initialize the CRL from "<<cf);
68 return;
69 }
70 } else {
71 if (InitFromURI(cf, 0) != 0) {
72 DEBUG("could not initialize the CRL from URI"<<cf);
73 return;
74 }
75 }
76}
#define DEBUG(x)
#define EPNAME(x)

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

+ Here is the call graph for this function:

◆ XrdCryptosslX509Crl() [2/3]

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

Definition at line 79 of file XrdCryptosslX509Crl.cc.

80{
81 // Constructe CRL from a FILE handle `fc` with (assumed) filename `cf`.
82 EPNAME("X509Crl::XrdCryptosslX509Crl_file");
83
84 if (Init(fc, cf)) {
85 DEBUG("could not initialize the CRL from " << cf);
86 return;
87 }
88}

References DEBUG, and EPNAME.

◆ XrdCryptosslX509Crl() [3/3]

XrdCryptosslX509Crl::XrdCryptosslX509Crl ( XrdCryptoX509 * cacert)

Definition at line 91 of file XrdCryptosslX509Crl.cc.

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

149{
150 // Destructor
151
152 // Cleanup CRL
153 if (crl)
154 X509_CRL_free(crl);
155}

Member Function Documentation

◆ Dump()

void XrdCryptosslX509Crl::Dump ( )
virtual

Reimplemented from XrdCryptoX509Crl.

Definition at line 686 of file XrdCryptosslX509Crl.cc.

687{
688 // Dump content
689 EPNAME("X509Crl::Dump");
690
691 // Time strings
692 struct tm tst;
693 char stbeg[256] = {0};
694 time_t tbeg = LastUpdate();
695 localtime_r(&tbeg,&tst);
696 asctime_r(&tst,stbeg);
697 stbeg[strlen(stbeg)-1] = 0;
698 char stend[256] = {0};
699 time_t tend = NextUpdate();
700 localtime_r(&tend,&tst);
701 asctime_r(&tst,stend);
702 stend[strlen(stend)-1] = 0;
703
704 PRINT("+++++++++++++++ X509 CRL dump +++++++++++++++++++++++");
705 PRINT("+");
706 PRINT("+ File: "<<ParentFile());
707 PRINT("+");
708 PRINT("+ Issuer: "<<Issuer());
709 PRINT("+ Issuer hash: "<<IssuerHash(0));
710 PRINT("+");
711 if (IsExpired()) {
712 PRINT("+ Validity: (expired!)");
713 } else {
714 PRINT("+ Validity:");
715 }
716 PRINT("+ LastUpdate: "<<tbeg<<" UTC - "<<stbeg);
717 PRINT("+ NextUpdate: "<<tend<<" UTC - "<<stend);
718 PRINT("+");
719 PRINT("+ Number of revoked certificates: "<<nrevoked);
720 PRINT("+");
721 PRINT("+++++++++++++++++++++++++++++++++++++++++++++++++");
722}
#define PRINT(y)
virtual bool IsExpired(int when=0)
const char * IssuerHash()

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

+ Here is the call graph for this function:

◆ hasCriticalExtension()

bool XrdCryptosslX509Crl::hasCriticalExtension ( )

Definition at line 385 of file XrdCryptosslX509Crl.cc.

385 {
386 // If the X509_CRL_get_ext_by_critical() function returns -1, no critical extension
387 // has been found
388 return X509_CRL_get_ext_by_critical(crl,1,-1) != -1;
389}

◆ IsRevoked() [1/2]

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

Reimplemented from XrdCryptoX509Crl.

Definition at line 648 of file XrdCryptosslX509Crl.cc.

649{
650 // Check if certificate with 'sernum' is in the
651 // list of revocated certificates
652 EPNAME("IsRevoked");
653
654 // Reference time
655 int now = (when > 0) ? when : time(0);
656
657 // Warn if CRL should be updated
658 if (now > NextUpdate()) {
659 DEBUG("WARNING: CRL is expired: you should download the updated one");
660 }
661
662 // We must have something to check against
663 if (nrevoked <= 0) {
664 DEBUG("No certificate in the list");
665 return 0;
666 }
667
668 // Look into the cache
669 bool revoked = false;
670 XrdSutCacheEntry *cent = cache.Get((const char *)sernum);
671 if (cent) {
672 // Check the revocation time
673 if (cent->status == kCE_ok && now > cent->mtime) {
674 DEBUG("certificate "<<sernum<<" has been revoked");
675 revoked = true;
676 }
677 cent->rwmtx.UnLock();
678 }
679 if (revoked) return 1;
680
681 // Certificate not revoked
682 return 0;
683}
@ 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 587 of file XrdCryptosslX509Crl.cc.

588{
589 // Check if certificate with serialnumber is in the
590 // list of revocated certificates
591 EPNAME("IsRevoked");
592
593 // Reference time
594 int now = (when > 0) ? when : time(0);
595
596 // Warn if CRL should be updated
597 if (now > NextUpdate()) {
598 DEBUG("WARNING: CRL is expired: you should download the updated one");
599 }
600
601 // We must have something to check against
602 if (nrevoked <= 0) {
603 DEBUG("No certificate in the list");
604 return 0;
605 }
606
607 // A serial number is never negative
608 if (serialnumber < 0) {
609 DEBUG("invalid serial number: "<<serialnumber);
610 return 0;
611 }
612
613 // Ok, build the tag: the cache is keyed with the serial number in the
614 // format produced by BN_bn2hex(), i.e. upper case with an even number
615 // of digits, so we must use the same format here
616 BIGNUM *bn = BN_new();
617 if (!bn) {
618 DEBUG("could not allocate a big number");
619 return 0;
620 }
621 BN_set_word(bn, (BN_ULONG)serialnumber);
622 char *tagser = BN_bn2hex(bn);
623 BN_free(bn);
624 if (!tagser) {
625 DEBUG("could not format the serial number");
626 return 0;
627 }
628
629 // Look into the cache
630 bool revoked = false;
631 XrdSutCacheEntry *cent = cache.Get((const char *)tagser);
632 if (cent) {
633 // Check the revocation time
634 if (cent->status == kCE_ok && now > cent->mtime) {
635 DEBUG("certificate "<<tagser<<" has been revoked");
636 revoked = true;
637 }
638 cent->rwmtx.UnLock();
639 }
640 OPENSSL_free(tagser);
641 if (revoked) return 1;
642
643 // Certificate not revoked
644 return 0;
645}

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 498 of file XrdCryptosslX509Crl.cc.

499{
500 // Return issuer name
501 EPNAME("X509Crl::Issuer");
502
503 // If we do not have it already, try extraction
504 if (issuer.length() <= 0) {
505
506 // Make sure we have a CRL
507 if (!crl) {
508 DEBUG("WARNING: no CRL available - cannot extract issuer name");
509 return (const char *)0;
510 }
511
512 // Extract issuer name
513 XrdCryptosslNameOneLine(X509_CRL_get_issuer(crl), issuer);
514 }
515
516 // return what we have
517 return (issuer.length() > 0) ? issuer.c_str() : (const char *)0;
518}
void XrdCryptosslNameOneLine(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 521 of file XrdCryptosslX509Crl.cc.

522{
523 // Return hash of issuer name
524 // Use default algorithm (X509_NAME_hash) for alg = 0, old algorithm
525 // (for v>=1.0.0) when alg = 1
526 EPNAME("X509::IssuerHash");
527
528#if (OPENSSL_VERSION_NUMBER >= 0x10000000L && !defined(__APPLE__))
529 if (alg == 1) {
530 // md5 based
531 if (issueroldhash.length() <= 0) {
532 // Make sure we have a certificate
533 if (crl) {
534 char chash[30] = {0};
535 snprintf(chash, sizeof(chash),
536 "%08lx.0",X509_NAME_hash_old(X509_CRL_get_issuer(crl)));
537 issueroldhash = chash;
538 } else {
539 DEBUG("WARNING: no certificate available - cannot extract issuer hash (md5)");
540 }
541 }
542 // return what we have
543 return (issueroldhash.length() > 0) ? issueroldhash.c_str() : (const char *)0;
544 }
545#else
546 if (alg == 1) { }
547#endif
548
549 // If we do not have it already, try extraction
550 if (issuerhash.length() <= 0) {
551
552 // Make sure we have a certificate
553 if (crl) {
554 char chash[30] = {0};
555 snprintf(chash, sizeof(chash),
556 "%08lx.0",X509_NAME_hash(X509_CRL_get_issuer(crl)));
557 issuerhash = chash;
558 } else {
559 DEBUG("WARNING: no certificate available - cannot extract issuer hash (default)");
560 }
561 }
562
563 // return what we have
564 return (issuerhash.length() > 0) ? issuerhash.c_str() : (const char *)0;
565}

References DEBUG, and EPNAME.

◆ 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 466 of file XrdCryptosslX509Crl.cc.

467{
468 // Time of last update
469
470 // If we do not have it already, try extraction
471 if (lastupdate < 0) {
472 // Make sure we have a CRL
473 if (crl)
474 // Extract UTC time in secs from Epoch
476 }
477 // return what we have
478 return lastupdate;
479}
time_t XrdCryptosslASN1toUTC(const ASN1_TIME *tsn1)
#define X509_CRL_get0_lastUpdate

References X509_CRL_get0_lastUpdate, and 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 482 of file XrdCryptosslX509Crl.cc.

483{
484 // Time of next update
485
486 // If we do not have it already, try extraction
487 if (nextupdate < 0) {
488 // Make sure we have a CRL
489 if (crl)
490 // Extract UTC time in secs from Epoch
492 }
493 // return what we have
494 return nextupdate;
495}
#define X509_CRL_get0_nextUpdate

References X509_CRL_get0_nextUpdate, and 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 329 of file XrdCryptosslX509Crl.cc.

330{
331 // Write the CRL's contents to a file in the PEM format.
332 EPNAME("ToFile");
333
334 if (!crl) {
335 DEBUG("CRL object invalid; cannot write to a file");
336 return false;
337 }
338
339 if (PEM_write_X509_CRL(fh, crl) == 0) {
340 DEBUG("Unable to write CRL to file");
341 return false;
342 }
343
344 //
345 // Notify
346 DEBUG("CRL successfully written to file");
347
348 return true;
349}

References DEBUG, and EPNAME.

◆ Verify()

bool XrdCryptosslX509Crl::Verify ( XrdCryptoX509 * ref)
virtual

Reimplemented from XrdCryptoX509Crl.

Definition at line 568 of file XrdCryptosslX509Crl.cc.

569{
570 // Verify certificate signature with pub key of ref cert
571
572 // We must have been initialized
573 if (!crl)
574 return 0;
575
576 // We must have something to check with
577 X509 *r = ref ? (X509 *)(ref->Opaque()) : 0;
578 EVP_PKEY *rk = r ? X509_get_pubkey(r) : 0;
579 if (!rk)
580 return 0;
581
582 // Ok: we can verify
583 return (X509_CRL_verify(crl, rk) > 0);
584}
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: