Ejemplo n.º 1
0
def getXIDsNewerThanTimestamp(datastore, someTimestamp):
    sslXIDHash = {}
    mySqlTimeStamp = someTimestamp.strftime('%Y-%m-%d %H:%M:%S')
    sql = """SELECT ssl_xid, ssl_dedicated_ip, ssl_domain_name, ssl_internal_only, ssl_crt
                FROM ATS_SSL_table
            WHERE ssl_date_inserted >= '%s'""" % mySqlTimeStamp
    results = datastore.executeAll(sql)
    if results:
        for row in results:
            xid                            = row[0]
            dedicated_ip                   = row[1]
            domain_name                    = row[2]
            internal_only                  = row[3]
            cert                           = row[4]
            if xid:
                newXID                         = ATSConfigEntry(None, None)
                sslXIDHash[xid]                = newXID
                sslXIDHash[xid].dedicated_ip   = dedicated_ip
                sslXIDHash[xid].domain_name    = domain_name
                sslXIDHash[xid].internal_only  = internal_only
                sslCert                        = SSLCert(domain_name, xid, dedicated_ip)
                sslCert.cert                   = cert
                sslXIDHash[xid].sanList        = sslCert.hasSubjectAltNames()
            else:
                ssllog.log.main_logger.warning("Skipping bad record for dedicated_ip:[%s] domain_name:[%s]" % \
                        (dedicated_ip, domain_name))
                continue

        return sslXIDHash
    else:
        return None
Ejemplo n.º 2
0
def getOneCertByDomain(datastore, domain):
    sql = """SELECT ssl_crt, ssl_key, ssl_private_passphrase, ssl_xid,
                    ssl_dedicated_ip, ssl_domain_name, ssl_date_inserted,
                    ssl_date_expires, ssl_internal_only
                FROM ATS_SSL_table
            WHERE ssl_domain_name = '%s' LIMIT 1""" %  domain
    result = datastore.executeOne(sql)
    if result:
        xid                            = result[3]
        dedicated_ip                   = result[4]
        domain                         = result[5]
        if not xid:
            ssllog.log.main_logger.warning("XID not set in database. Skipping bad record for dedicated_ip:[%s] domain_name:[%s]" % \
                    (dedicated_ip, domain))
            return None
        sslCert                        = SSLCert(domain, xid, dedicated_ip)
        sslCert.cert                   = result[0]
        sslCert.key                    = result[1]
        sslCert.passphrase             = result[2]
        sslCert.date_inserted          = result[6]
        sslCert.date_expires           = result[7]
        sslCert.internal_only          = result[8]
        sslCert.sanList                = sslCert.hasSubjectAltNames()
        return sslCert
    else:
        return None
Ejemplo n.º 3
0
def getAllCerts(datastore):
    sslCertHash = {}
    sql = """SELECT ssl_crt, ssl_key, ssl_private_passphrase, ssl_xid,
                    ssl_dedicated_ip, ssl_domain_name, ssl_date_inserted,
                    ssl_date_expires, ssl_internal_only
               FROM ATS_SSL_table"""
    results = datastore.executeAll(sql)
    if results:
        for row in row:
            domain                         = row[5]
            xid                            = row[3]
            dedicated_ip                   = row[4]
            if not xid:
                ssllog.log.main_logger.warning("XID not set in database. Skipping bad record for dedicated_ip:[%s] domain_name:[%s]" % \
                        (dedicated_ip, domain))
                continue
            sslCert                        = SSLCert(domain, xid, dedicated_ip)
            # row[0] is the ssl_idx - not needed
            sslCert.cert                   = row[0]
            sslCert.key                    = row[1]
            sslCert.passphrase             = row[2]
            sslCert.date_inserted          = row[6]
            sslCert.date_expires           = row[7]
            sslCert.internal_only          = row[8]
            sslCert.sanList                = sslCert.hasSubjectAltNames()
            sslCertHash[xid] = sslCert
        return sslCertHash
    else:
        return None
Ejemplo n.º 4
0
def getCertsNewerThanTimestamp(datastore, someTimestamp, limitStart, limitSize):
    sslCertHash = {}
    mySqlTimeStamp = someTimestamp.strftime('%Y-%m-%d %H:%M:%S')
    sql = """SELECT ssl_crt, ssl_key, ssl_private_passphrase, ssl_xid,
                    ssl_dedicated_ip, ssl_domain_name, ssl_date_inserted,
                    ssl_date_expires, ssl_internal_only
               FROM ATS_SSL_table
              WHERE ssl_date_inserted >= '%s'
              ORDER BY ssl_date_inserted
              LIMIT %d, %d""" % (mySqlTimeStamp, limitStart, limitSize)
    results = datastore.executeAll(sql)
    if results:
        for row in results:
            domain                         = row[5]
            xid                            = row[3]
            dedicated_ip                   = row[4]
            if not xid:
                ssllog.log.main_logger.warning("Skipping bad record for dedicated_ip:[%s] domain_name:[%s]" % \
                        (dedicated_ip, domain))
                continue
            sslCert                        = SSLCert(domain, xid, dedicated_ip)
            sslCert.cert                   = row[0]
            sslCert.key                    = row[1]
            sslCert.passphrase             = row[2]
            sslCert.date_inserted          = row[6]
            sslCert.date_expires           = row[7]
            sslCert.internal_only          = row[8]
            sslCert.sanList                = sslCert.hasSubjectAltNames()
            sslCertHash[xid] = sslCert
            # Lets keep track of our greatest timestamp and return that for use
            # next time as the starting timestamp
            thisTimestamp = sslCert.date_inserted
            if thisTimestamp > someTimestamp:
                someTimestamp = thisTimestamp
        return (sslCertHash, someTimestamp)
    else:
        return (None, None)
Ejemplo n.º 5
0
def getOneCertByXID(datastore, xid):
    sql = """SELECT ssl_crt, ssl_key, ssl_private_passphrase, ssl_xid,
                    ssl_dedicated_ip, ssl_domain_name, ssl_date_inserted,
                    ssl_date_expires, ssl_internal_only
                FROM ATS_SSL_table
            WHERE ssl_xid = '%d' LIMIT 1""" % xid
    result = datastore.executeOne(sql)
    if result:
        domain                         = result[5]
        xid                            = result[3]
        dedicated_ip                   = result[4]
        sslCert                        = SSLCert(domain, xid, dedicated_ip)
        sslCert.cert                   = result[0]
        sslCert.key                    = result[1]
        sslCert.passphrase             = result[2]
        sslCert.date_inserted          = result[6]
        sslCert.date_expires           = result[7]
        sslCert.internal_only          = result[8]
        sslCert.sanList                = sslCert.hasSubjectAltNames()
        sslCert.dumpExtensions()
        return sslCert
    else:
        return None
Ejemplo n.º 6
0
 def test_insertOneSelfSignedCert_Success(self):
     sslCert = SSLCert("booger.com", 30720009)
     sslCert.selfSignThisCert()
     self.failUnless(insertOneCert(self.datastore, sslCert))
Ejemplo n.º 7
0
 def test_insertOneCert_Success(self):
     sslcert = SSLCert("test1999.com", 19720009)
     sslcert.selfSignThisCert()
     self.failUnless(insertOneCert(self.datastore, sslcert))
Ejemplo n.º 8
0
    while 1:
        try:
            datastore.connect()
            if datastore.con.open:
                datastore.cursor = datastore.con.cursor()
            else:
                ssllog.log.main_logger.error("Houston, we have a problem with connecting to the database.")
                exit(1)
        except mdb.Error, e:
            ssllog.log.main_logger.error("Error %d: %s" % (e.args[0],e.args[1]))
        finally:
            for each in range(1, random.randrange(1, 10+1)):
                # Define a cert and generate it
                domain = "test%05d.com" % ctr
                ssllog.log.main_logger.warning("Creating %s - # %d" % (domain, ctr))
                sslcert = SSLCert(domain, ctr)
                if not sslcert:
                    ssllog.log.main_logger.error("Houston, we have a problem with setting up the SSL \
                            certificate for %s." % domain)
                    exit(1)

                if not sslcert.selfSignThisCert():
                    ssllog.log.main_logger.error("Houston, we have a problem with creating the SSL \
                            certificate for %s." % domain)
                    exit(1)

                if not sslcertdatabase.insertOneCert(datastore, sslcert):
                    ssllog.log.main_logger.error("Houston, we have a problem with insertting the SSL \
                            certificate for %s into the database." % domain)
                    exit(1)
                ctr += 1