예제 #1
0
    def test_04_encrypt_decrypt_data(self):
        import os
        data = os.urandom(50)
        iv = os.urandom(16)
        c = encrypt(data, iv)
        # verify
        d = decrypt(binascii.unhexlify(c), iv)
        self.assertEqual(data, d)

        s = u"Encryption Text with unicode chars: äöü"
        c = encrypt(s, iv)
        d = decrypt(binascii.unhexlify(c), iv)
        self.assertEqual(s, d.decode('utf8'))

        # TODO: add checks for broken paddings/encrypted values and malformed enc_data

        # check some data generated with 2.23
        s = u'passwörd'.encode('utf8')
        iv_hex = 'cd5245a2875007d30cc049c2e7eca0c5'
        enc_data_hex = '7ea55168952b33131077f4249cf9e52b5f2b572214ace13194c436451fe3788c'
        self.assertEqual(s, decrypt(binascii.unhexlify(enc_data_hex),
                                     binascii.unhexlify(iv_hex)))
        enc_data_hex = 'fb79a04d69e832aec8ffb4bbfe031b3bd28a2840150212d8c819e' \
                       '362b1711cc389aed70eaf27af53131ea446095da80e88c4caf791' \
                       'c709e9581ff0a5f1e19228dc4c3c278d148951acaab9a164c1770' \
                       '7166134f4ba6111055c65d72771c6f59c2dc150a53753f2cf4c47' \
                       'ec02901022f02a054d1fc7678fd4f66b47967a5d222a'
        self.assertEqual(b'\x01\x02' * 30,
                          decrypt(binascii.unhexlify(enc_data_hex),
                                  binascii.unhexlify(iv_hex)))
예제 #2
0
    def test_04_encrypt_decrypt_data(self):
        import os
        data = os.urandom(50)
        iv = os.urandom(16)
        c = encrypt(data, iv)
        # verify
        d = decrypt(binascii.unhexlify(c), iv)
        self.assertEqual(data, d)

        s = u"Encryption Text with unicode chars: äöü"
        c = encrypt(s, iv)
        d = decrypt(binascii.unhexlify(c), iv)
        self.assertEqual(s, d.decode('utf8'))

        # TODO: add checks for broken paddings/encrypted values and malformed enc_data

        # check some data generated with 2.23
        s = u'passwörd'.encode('utf8')
        iv_hex = 'cd5245a2875007d30cc049c2e7eca0c5'
        enc_data_hex = '7ea55168952b33131077f4249cf9e52b5f2b572214ace13194c436451fe3788c'
        self.assertEqual(
            s,
            decrypt(binascii.unhexlify(enc_data_hex),
                    binascii.unhexlify(iv_hex)))
        enc_data_hex = 'fb79a04d69e832aec8ffb4bbfe031b3bd28a2840150212d8c819e' \
                       '362b1711cc389aed70eaf27af53131ea446095da80e88c4caf791' \
                       'c709e9581ff0a5f1e19228dc4c3c278d148951acaab9a164c1770' \
                       '7166134f4ba6111055c65d72771c6f59c2dc150a53753f2cf4c47' \
                       'ec02901022f02a054d1fc7678fd4f66b47967a5d222a'
        self.assertEqual(
            b'\x01\x02' * 30,
            decrypt(binascii.unhexlify(enc_data_hex),
                    binascii.unhexlify(iv_hex)))
예제 #3
0
    def test_04_encrypt_decrypt_data(self):
        import os
        data = os.urandom(50)
        iv = os.urandom(16)
        c = encrypt(data, iv)
        # verify
        d = decrypt(binascii.unhexlify(c), iv)
        self.assertEqual(data, d)

        s = u"Encryption Text with unicode chars: äöü"
        c = encrypt(s, iv)
        d = decrypt(binascii.unhexlify(c), iv)
        self.assertEqual(s, d.decode('utf8'))
예제 #4
0
 def setSoPin(self, soPin):
     # TODO: we could log the PIN here
     log.debug('setSoPin()')
     iv = geturandom(16)
     enc_soPin = encrypt(soPin, iv)
     self.privacyIDEATokenPinSO = unicode(binascii.hexlify(enc_soPin))
     self.privacyIDEATokenPinSOIV = unicode(binascii.hexlify(iv))
예제 #5
0
 def setHKey(self, hOtpKey, reset_failcount=True):
     iv = geturandom(16)
     #bhOtpKey            = binascii.unhexlify(hOtpKey)
     enc_otp_key = encrypt(hOtpKey, iv)
     self.privacyIDEAKeyEnc = unicode(binascii.hexlify(enc_otp_key))
     self.privacyIDEAKeyIV = unicode(binascii.hexlify(iv))
     self.privacyIDEACount = 0
     if True == reset_failcount:
         self.privacyIDEAFailCount = 0
예제 #6
0
 def setHKey(self, hOtpKey, reset_failcount=True):
     iv = geturandom(16)
     enc_otp_key = encrypt(hOtpKey, iv)
     self.privacyIDEAKeyEnc = unicode(binascii.hexlify(enc_otp_key))
     length = len(self.privacyIDEAKeyEnc)
     if length > 1024:
         log.error("Key %s exceeds database field %d!" % (self.getSerial(),
                                                          length))
     self.privacyIDEAKeyIV = unicode(binascii.hexlify(iv))
     self.privacyIDEACount = 0
     if True == reset_failcount:
         self.privacyIDEAFailCount = 0
def create_subscription_request():
    iv = geturandom(16)
    enc = encrypt("privacy IDEA", iv=iv)
    r = binascii.hexlify(enc + iv)
    return {"systemid": r}
예제 #8
0
 def setUserPin(self, userPin):
     iv = geturandom(16)
     enc_userPin = encrypt(userPin, iv)
     self.privacyIDEATokenPinUser = unicode(binascii.hexlify(enc_userPin))
     self.privacyIDEATokenPinUserIV = unicode(binascii.hexlify(iv))
예제 #9
0
def create_subscription_request():
    iv = geturandom(16)
    enc = encrypt("privacy IDEA", iv=iv)
    r = binascii.hexlify(enc + iv)
    return {"systemid": r}