Changeset 1125


Ignore:
Timestamp:
11/21/06 10:00:32 (7 years ago)
Author:
mglb1
Message:

Add a facility to retrieve the latest CRL from the configuration system

  • Move CRL generation into a separate routine
  • Add XMLRPC API to retrieve CRL and generate a new one if required
  • Add script to connect to the server over XMLRPC and output the CRL
Location:
ccsd/trunk
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • ccsd/trunk/crcnetd/_utils/ccsd_ca.py

    r1082 r1125  
    124124 
    125125    return (csr, key) 
     126     
     127@exportViaXMLRPC(SESSION_RO, AUTH_AUTHENTICATED) 
     128def fetchCRL(self): 
     129 
     130    ca = ccs_ca(ADMIN_SESSION_ID) 
     131 
     132    # Check when the next CRL is due 
     133    os.environ["CCS_CA_DIR"] = ca.rDir 
     134    (fdi, fdo) = os.popen2("openssl crl -text -in %s/crl.pem 2>&1" % ca.rDir) 
     135    fdi.close() 
     136    lines = fdo.readlines() 
     137    fdo.close() 
     138    del os.environ["CCS_CA_DIR"] 
     139     
     140    try: 
     141        for line in lines: 
     142            if line.strip().startswith("Next Update"): 
     143                parts = line.strip().split(":") 
     144                tmp = ":".join(parts[1:]).strip() 
     145                next = time.mktime(time.strptime(tmp, \ 
     146                        "%b %d %H:%M:%S %Y %Z")) 
     147                now = time.time() 
     148                if (next - now) < (60*60*24*2): 
     149                    # Update the CRL if it expires in less than 2 days 
     150                    ca.updateCRL() 
     151                    ca.checkin("Updated CRL to satisfy user request") 
     152                break 
     153    except: 
     154        log_error("Could not parse CRL output. " \ 
     155                "Returned CRL may be old.\n%s" % "".join(lines), \ 
     156                sys.exc_info()) 
     157 
     158    # Read and return the CRL 
     159    crl = open("%s/crl.pem" % ca.rDir, "r").read() 
     160    return crl 
    126161 
    127162##################################################################### 
     
    560595        cert = open(certfile, "r").read() 
    561596        return cert 
    562      
     597 
     598    def updateCRL(self): 
     599        """Regenerates the Certificate Revocation List""" 
     600 
     601        os.environ["CCS_CA_DIR"] = self.rDir 
     602        (fdi, fdo) = os.popen2("openssl ca -config %s/ca.cnf -gencrl -out " \ 
     603                "%s/crl.pem -batch 2>&1" % (self.rDir, self.rDir)) 
     604        fdi.close() 
     605        rlines = fdo.readlines() 
     606        fdo.close() 
     607        del os.environ["CCS_CA_DIR"] 
     608 
     609        return True 
     610 
    563611    def revoke(self, serial, reasonCode=REVOKE_UNSPECIFIED, reasonText=""): 
    564612        """Revokes the specified certificate optionally giving a reason 
     
    578626        lines = fdo.readlines() 
    579627        fdo.close() 
    580         (fdi, fdo) = os.popen2("openssl ca -config %s/ca.cnf -gencrl -out " \ 
    581                 "%s/crl.pem -batch 2>&1" % (self.rDir, self.rDir)) 
    582         fdi.close() 
    583         rlines = fdo.readlines() 
    584         fdo.close() 
    585628        del os.environ["CCS_CA_DIR"] 
    586629         
     
    607650            log_error("Could not move revoked certificate to new name!", \ 
    608651                    sys.exc_info()) 
     652 
     653        # Generate a new CRL 
     654        self.updateCRL() 
    609655 
    610656        # Commit the changes 
Note: See TracChangeset for help on using the changeset viewer.