コード例 #1
0
ファイル: db_operations.py プロジェクト: makkalot/pysign
 def load_db(self):
     """
     Load the certs and chain into the memory
     actually we load the index file with summary of 
     the certs
     """
     if not self.__db_dir or not os.path.exists(os.path.join(self.__db_dir, INTERNAL_DB_FILE)):
         # Make here a logger plzzz
         # print "The internal db file is corrupted or doesnt exists,you should run recreate_internal_db method"
         return False
     result = get_index_data(self.__db_dir)
     self.__cert_store = result
     return True
コード例 #2
0
ファイル: cert_tools.py プロジェクト: makkalot/pysign
def load_private_key(chain_dir):
    """
    The mentioned private key here is the one that is
    in the latest part of the chain,what we mean is the child
    cert's private key ...
    """
    if os.path.exists(os.path.join(chain_dir,INTERNAL_DB_FILE)):
        #continue by scanning the file ...
        store = get_index_data(chain_dir)
        #print store
        if not store.has_key("private") or not store['private']:
            #print "No cert wa found into the INTERNAL_DB_FILE"
            return None
        else:
            return os.path.join(chain_dir,"private",store['private'])
    else:
        return None
コード例 #3
0
ファイル: cert_tools.py プロジェクト: makkalot/pysign
def load_cert_from_dir(scan_dir,get_all=False):
    """
    Gets a single cert from a dir. It gets the first one it 
    finds. Therefore donot expect some magic here ...
    """
    from M2Crypto import X509 as x
    import sys
    from imzaci.config import INTERNAL_DB_FILE
    import os

    #firstly we should check if we have some index file that locates
    #the cert of the current directory ...
    if os.path.exists(os.path.join(scan_dir,INTERNAL_DB_FILE)) and not get_all:
        #continue by scanning the file ...
        store = get_index_data(scan_dir)
        #print store
        if not store.has_key("cert") or not store['cert']:
            #print "No cert wa found into the INTERNAL_DB_FILE"
            return None
        else:
            cert_path = os.path.join(scan_dir,store['cert'])
            try:
                tmp = x.load_cert(cert_path)
                #print "Loaded cert :",store['cert']
                return X509Cert(tmp)
            except:
                #print "Error when loading ",store['cert']
                return None

    #we continue by scanning
    get_all_certs = []
    possible_certs = glob.glob("".join([scan_dir,"/","*.pem"]))    
    for cert_path in possible_certs:
        try:
            tmp = x.load_cert(cert_path)
            #print "Cert loaded :",cert_path
            if not get_all:
                return X509Cert(tmp)
            else:
                get_all_certs.append(X509Cert(tmp))
        except Exception,e:
            #print "The cert is not valid ",e
            continue