Example #1
0
 def getRandomBytes(howMany):
     randomKey = cryptlib_py.cryptCreateContext(cryptlib_py.CRYPT_UNUSED, cryptlib_py.CRYPT_ALGO_AES)
     cryptlib_py.cryptSetAttribute(randomKey, cryptlib_py.CRYPT_CTXINFO_MODE, cryptlib_py.CRYPT_MODE_OFB)
     cryptlib_py.cryptGenerateKey(randomKey)
     bytes = createByteArrayZeros(howMany)
     cryptlib_py.cryptEncrypt(randomKey, bytes)
     return bytes
Example #2
0
 def getRandomBytes(howMany):
     randomKey = cryptlib_py.cryptCreateContext(
         cryptlib_py.CRYPT_UNUSED, cryptlib_py.CRYPT_ALGO_AES)
     cryptlib_py.cryptSetAttribute(randomKey,
                                   cryptlib_py.CRYPT_CTXINFO_MODE,
                                   cryptlib_py.CRYPT_MODE_OFB)
     cryptlib_py.cryptGenerateKey(randomKey)
     bytes = createByteArrayZeros(howMany)
     cryptlib_py.cryptEncrypt(randomKey, bytes)
     return bytes
    def _checkChaining(self, lastC, rootC):
        import cryptlib_py
        import array

        def compareNames(name):
            try:
                length = cryptlib_py.cryptGetAttributeString(lastC, name, None)
                lastName = array.array('B', [0] * length)
                cryptlib_py.cryptGetAttributeString(lastC, name, lastName)
                lastName = lastName.tostring()
            except cryptlib_py.CryptException as e:
                if e[0] == cryptlib_py.CRYPT_ERROR_NOTFOUND:
                    lastName = None
            try:
                length = cryptlib_py.cryptGetAttributeString(rootC, name, None)
                rootName = array.array('B', [0] * length)
                cryptlib_py.cryptGetAttributeString(rootC, name, rootName)
                rootName = rootName.tostring()
            except cryptlib_py.CryptException as e:
                if e[0] == cryptlib_py.CRYPT_ERROR_NOTFOUND:
                    rootName = None

            return lastName == rootName

        cryptlib_py.cryptSetAttribute(lastC,
                                      cryptlib_py.CRYPT_CERTINFO_ISSUERNAME,
                                      cryptlib_py.CRYPT_UNUSED)

        if not compareNames(cryptlib_py.CRYPT_CERTINFO_COUNTRYNAME):
            return False
        if not compareNames(cryptlib_py.CRYPT_CERTINFO_LOCALITYNAME):
            return False
        if not compareNames(cryptlib_py.CRYPT_CERTINFO_ORGANIZATIONNAME):
            return False
        if not compareNames(cryptlib_py.CRYPT_CERTINFO_ORGANIZATIONALUNITNAME):
            return False
        if not compareNames(cryptlib_py.CRYPT_CERTINFO_COMMONNAME):
            return False
        return True
    def _checkChaining(self, lastC, rootC):
        import cryptlib_py
        import array
        def compareNames(name):
            try:
                length = cryptlib_py.cryptGetAttributeString(lastC, name, None)
                lastName = array.array('B', [0] * length)
                cryptlib_py.cryptGetAttributeString(lastC, name, lastName)
                lastName = lastName.tostring()
            except cryptlib_py.CryptException as e:
                if e[0] == cryptlib_py.CRYPT_ERROR_NOTFOUND:
                    lastName = None
            try:
                length = cryptlib_py.cryptGetAttributeString(rootC, name, None)
                rootName = array.array('B', [0] * length)
                cryptlib_py.cryptGetAttributeString(rootC, name, rootName)
                rootName = rootName.tostring()
            except cryptlib_py.CryptException as e:
                if e[0] == cryptlib_py.CRYPT_ERROR_NOTFOUND:
                    rootName = None

            return lastName == rootName

        cryptlib_py.cryptSetAttribute(lastC,
                                      cryptlib_py.CRYPT_CERTINFO_ISSUERNAME,
                                      cryptlib_py.CRYPT_UNUSED)

        if not compareNames(cryptlib_py.CRYPT_CERTINFO_COUNTRYNAME):
            return False
        if not compareNames(cryptlib_py.CRYPT_CERTINFO_LOCALITYNAME):
            return False
        if not compareNames(cryptlib_py.CRYPT_CERTINFO_ORGANIZATIONNAME):
            return False
        if not compareNames(cryptlib_py.CRYPT_CERTINFO_ORGANIZATIONALUNITNAME):
            return False
        if not compareNames(cryptlib_py.CRYPT_CERTINFO_COMMONNAME):
            return False
        return True
Example #5
0
                cryptlib_py.cryptGetAttributeString(lastC, name, lastName)
                lastName = lastName.tostring()
            except cryptlib_py.CryptException, e:
                if e[0] == cryptlib_py.CRYPT_ERROR_NOTFOUND:
                    lastName = None
            try:
                length = cryptlib_py.cryptGetAttributeString(rootC, name, None)
                rootName = array.array('B', [0] * length)
                cryptlib_py.cryptGetAttributeString(rootC, name, rootName)
                rootName = rootName.tostring()
            except cryptlib_py.CryptException, e:
                if e[0] == cryptlib_py.CRYPT_ERROR_NOTFOUND:
                    rootName = None

            return lastName == rootName

        cryptlib_py.cryptSetAttribute(lastC,
                                      cryptlib_py.CRYPT_CERTINFO_ISSUERNAME,
                                      cryptlib_py.CRYPT_UNUSED)

        if not compareNames(cryptlib_py.CRYPT_CERTINFO_COUNTRYNAME):
            return False
        if not compareNames(cryptlib_py.CRYPT_CERTINFO_LOCALITYNAME):
            return False
        if not compareNames(cryptlib_py.CRYPT_CERTINFO_ORGANIZATIONNAME):
            return False
        if not compareNames(cryptlib_py.CRYPT_CERTINFO_ORGANIZATIONALUNITNAME):
            return False
        if not compareNames(cryptlib_py.CRYPT_CERTINFO_COMMONNAME):
            return False
        return True