def isValidKey(streamObj):
    """
    checks if the given stream contains a valid key block
    """
    streamObj.seek(0)
    kk = ezKey()
    return kk.importKey(streamObj.read())
def getKeyFor(path=defaultKeyFilePath()):
    """
    @return: the key stored in the supplied file
    """
    angelKey = ezKey()
    angelKey.importKey(open(path).read())
    return angelKey
Exemplo n.º 3
0
    def _metaDataIsCorrect(self):

        publicKey = ezKey()
        publicKey.importKey(self.publicKeyString())

        sm = self.signableMetadata()
        ms = self.metaDataSignature()

        #log.debug(ms)
        #log.debug(sm)
        try:
            isCorrect = publicKey.verifyString(sm, ms)
            if not isCorrect:
                log.info("Incorrect meta data for: %r", self.resourceID())
                log.info("Meta data to be signed: %r", self.signableMetadata())
                return False
            else:
                return True
        except Exception, e:
            log.debug("TODO more specific error handling needed here",
                      exc_info=e)
            log.info("Can not verify metadata %s against signature %s",
                     sm,
                     ms,
                     exc_info=e)
            return False
def createKey(filePath=defaultKeyFilePath()):
    kk = ezKey()
    # TODO: make key size configurable
    kk.makeNewKeys()
    log.info("creating new key in file: %r", filePath)
    t = SingleFileTransaction()
    safe = t.open(filePath, 'w')
    safe.write(kk.exportKeyPrivate())
    t.commit()
    return kk
def isValidKeyPair(streamObj):
    """
    check sif the given stream contains a key pair (public AND private key)
    """
    kk = ezKey()
    streamObj.seek(0)
    result = False
    if isValidKey(streamObj):
        log.debug("Valid key!")
        streamObj.seek(0)
        if kk.importKey(streamObj.read()):
            log.debug("could import")
            if len(kk.exportKeyPrivate()) > 0:
                log.debug("could export")
                result = True


#    streamObj.seek(0)
    return result
Exemplo n.º 6
0
    def _metaDataIsCorrect(self):

        publicKey = ezKey()
        publicKey.importKey(self.publicKeyString())
        
        sm = self.signableMetadata()
        ms = self.metaDataSignature()
        
        #log.debug(ms)
        #log.debug(sm)
        try:
            isCorrect = publicKey.verifyString(sm, ms)
            if not isCorrect:
                log.info("Incorrect meta data for: %r", self.resourceID())
                log.info("Meta data to be signed: %r", self.signableMetadata())
                return False
            else:
                return True
        except Exception, e:
            log.debug("TODO more specific error handling needed here", exc_info = e)
            log.info("Can not verify metadata %s against signature %s", sm, ms, exc_info = e)
            return False