Exemplo n.º 1
0
def main():
    ssllog.log.initLog("./sslmakecert.log", "WARNING")
    ssllog.log.main_logger.warning("Starting")

    sleepInSecs            = sslconfig.sslConfig.sleepSecs
    sslCertDestinationPath = sslconfig.sslConfig.sslCertDestinationPath
    lastTimestamp          = sslconfig.sslConfig.lastTimestamp
    myHostname             = socket.gethostname()

    # Create a connection to the database
    datastore = SSLDataStore(sslconfig.sslConfig.databaseHost, \
        sslconfig.sslConfig.databaseUser, \
        sslconfig.sslConfig.databasePass, \
        sslconfig.sslConfig.databaseName)
    if not datastore:
        ssllog.log.main_logger.error("Houston, we have a problem with connecting to the database.")
        exit(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]))
Exemplo n.º 2
0
def main():

    cont = 1

    ssllog.log.initLog(sslconfig.sslConfig.logFilename, sslconfig.sslConfig.logLevel)
    if options.runOnceMode:
        ssllog.log.enableLogToConsole()

    ssllog.log.main_logger.debug("Starting main()")

    sleepInSecs            = sslconfig.sslConfig.sleepSecs
    sslCertDestinationPath = sslconfig.sslConfig.sslCertDestinationPath
    lastTimestamp          = sslconfig.sslConfigTimestamp.lastTimestamp

    myHostname = socket.gethostname()
    ssllog.log.main_logger.info("My hostname: " + myHostname)

    datastore = SSLDataStore(sslconfig.sslConfig.databaseHost, \
        sslconfig.sslConfig.databaseUser, \
        sslconfig.sslConfig.databasePass, \
        sslconfig.sslConfig.databaseName)

    if not datastore:
        ssllog.log.main_logger.critical("Error: Problem connecting to the "\
                "database. Exiting!")
        exit(2)

    #
    # Let's see whats changed since we were last here
    #
    dbConnected = 0
    dbSleep = 60
    while not dbConnected:
        try:
            datastore.connect()
        except mdb.Error, e:
            ssllog.log.main_logger.error("Error: Problem getting current state " \
                    "from the database. Sleeping for %d before trying again." \
                    % (dbSleep))
            ssllog.log.main_logger.error("Error %d: %s" % (e.args[0],e.args[1]))
            time.sleep(dbSleep)

        if datastore.con and datastore.con.open:
            dbConnected = 1
            datastore.cursor = datastore.con.cursor()

            # Parse out the starting ss-multicert.conf file into a hash (past
            # state)
            pastSSLConfigHash = atsParseSSLMultiCertConfig()
            # Grab all of the XIDs in the SSL datastore (present state)
            originTimestamp = datetime.datetime(1970, 1, 1, 0, 0, 0)
            presentSSLConfigHash = sslcertdatabase.getXIDsNewerThanTimestamp(\
                    datastore, originTimestamp)
        else:
            ssllog.log.main_logger.error("Error: Problem getting opening " \
                    "connection to database in order to obtain the current " \
                "state from the database. Sleeping for %d before trying again." \
                    % (dbSleep))
            time.sleep(dbSleep)
Exemplo n.º 3
0
 def setUp(self):
     import sslconfig
     ssllog.log.initLog("./sslcertdatabase-unittest.log", sslconfig.sslConfig.logLevel)
     ssllog.log.main_logger.debug("Starting unittests")
     self.datastore        = SSLDataStore('10.224.27.16', 'dev_WordPaaS', 'YjAyZmQxOTAyMTNm', 'SSLDataStore')
     self.datastore.connect();
     self.datastore.cursor = self.datastore.con.cursor()
Exemplo n.º 4
0
class SSLServerDatabaseTests(unittest.TestCase):
    def setUp(self):
        self.datastore = SSLDataStore("localhost", "ats_sysuser", "ats_sysuser", "SSLDataStore")
        self.datastore.connect()
        self.datastore.cursor = self.datastore.con.cursor()

    def test_getServersChanged_Success(self):
        self.failUnless(getServersChanged(self.datastore))

    def test_getServerChangedFlag_Success(self):
        import socket

        hostname = socket.gethostname()
        self.failUnless(getServerChangedFlag(self.datastore, hostname))

    def test_getServerChangedFlag_Fail(self):
        hostname = "somebogushostnamethatdoesntexistinthedatabase"
        self.failIf(getServerChangedFlag(self.datastore, hostname))

    def test_updateServerChangedFlag_Success(self):
        server = "g1dlcent6ats001"
        self.failUnless(updateServerChangedFlag(self.datastore, server, 0))
Exemplo n.º 5
0
class SSLCertDatabaseTests(unittest.TestCase):

    def setUp(self):
        import sslconfig
        ssllog.log.initLog("./sslcertdatabase-unittest.log", sslconfig.sslConfig.logLevel)
        ssllog.log.main_logger.debug("Starting unittests")
        self.datastore        = SSLDataStore('10.224.27.16', 'dev_WordPaaS', 'YjAyZmQxOTAyMTNm', 'SSLDataStore')
        self.datastore.connect();
        self.datastore.cursor = self.datastore.con.cursor()

    def test_getOneCertByDomain_Success(self):
        sslCert = getOneCertByDomain(self.datastore, "felixg.me")
        self.failUnless(sslCert.hasSubjectAltNames())

    def test_getOneCertByDomain_Fail(self):
        sslCert = self.failIf(getOneCertByDomain(self.datastore, "wrong.com") == "this is a test crt")

    def test_getAllCerts_Success(self):
        self.failUnless(self.datastore, getAllCerts(self.datastore))

    def test_getCertsNewerThanTimestamp_Success(self):
        # 2014-02-20 12:22:55 -> MySQL Timestamp
        # Format: '%Y-%m-%d %H:%M:%S'
        # SELECT ssl_crt FROM ATS_SSL_table WHERE ssl_date_inserted > "2014-02-20 12:22:00"
        someTimestamp = datetime.datetime(2014, 2, 20, 12, 22, 00)
        self.failUnless(getCertsNewerThanTimestamp(self.datastore, someTimestamp))

    def test_insertOneCert_Success(self):
        sslcert = SSLCert("test1999.com", 19720009)
        sslcert.selfSignThisCert()
        self.failUnless(insertOneCert(self.datastore, sslcert))

    def test_insertOneSelfSignedCert_Success(self):
        sslCert = SSLCert("booger.com", 30720009)
        sslCert.selfSignThisCert()
        self.failUnless(insertOneCert(self.datastore, sslCert))
Exemplo n.º 6
0
 def setUp(self):
     self.datastore = SSLDataStore("localhost", "ats_sysuser", "ats_sysuser", "SSLDataStore")
     self.datastore.connect()
     self.datastore.cursor = self.datastore.con.cursor()