Ejemplo n.º 1
0
def test_reproduce_bad():
    """Test fuzzy extractor produces different key when new value is too different"""
    value_orig = 'AABBCCDD'
    value_good = 'ABBBCCDD'  #  2 bits flipped
    value_bad = 'A0B00CDD'  # 13 bits flipped

    extractor = FuzzyExtractor(8, 2)
    key, helpers = extractor.generate(value_orig)

    assert extractor.reproduce(value_good, helpers) == key
    assert extractor.reproduce(value_bad, helpers) != key
Ejemplo n.º 2
0
def FuzzyPoro():

    extractor = FuzzyExtractor(10, 2)  # (CharacterLength, ErrorAllowed)
    BiometricData = "0123456789"  # Sample Biometric Data
    # Create the key and the helper
    key, helper = extractor.generate(BiometricData)

    print('Your key is: %s' % (key))

    # Runs your generated key through TripleSec
    KeyForTripleSec = TripleSec(key)
    EncryptedPrivateKey = KeyForTripleSec.encrypt(
        b"ThisWouldBeYourPrivateKey")  # Encrypts your private key

    print('Your encrypted private key is: %s' % (EncryptedPrivateKey))

    # The second time you scan your fingerprint/biometric data
    KeyRecover = input("Enter your key:")

    KeyReturn = extractor.reproduce(KeyRecover,
                                    helper)  # Creates your original key

    print('Your recovered key is: %s' % (KeyReturn))

    # Runs your regenerated key through TripleSec
    ExtractedKey = TripleSec(KeyReturn)

    print('Your private key is: ')
    # Decodes your EncryptedPrivateKey with your regenerated encryption key
    print(ExtractedKey.decrypt(EncryptedPrivateKey).decode())
Ejemplo n.º 3
0
    def post(self, request):
        try:
            id_num = request.data['id']
            try:
                key = Device.objects.get(id=id_num).key
                helper_json = json.loads(Device.objects.get(id=id_num).helper)
            except:
                return Response(data=traceback.format_exc(),
                                status=status.HTTP_404_NOT_FOUND)

            helper = (
                np.array(bytes_list(helper_json[0]), dtype='uint8'),
                np.array(bytes_list(helper_json[1]), dtype='uint8'),
                np.array(bytes_list(helper_json[2]), dtype='uint8'),
            )
            extractor = FuzzyExtractor(32, 8)
            puf_data = bytes.fromhex(request.data['pufData'])
            r_key = extractor.reproduce(puf_data, helper)

            if r_key and key == r_key.hex():
                return Response(data='true', status=status.HTTP_200_OK)
            return Response(data='false', status=status.HTTP_200_OK)
        except:
            return Response(data=traceback.format_exc(),
                            status=status.HTTP_500_INTERNAL_SERVER_ERROR)
Ejemplo n.º 4
0
def test_encoding():
    """Test ability to encode and decode non-ASCII characters"""
    value = b'\xFF' * 15

    extractor = FuzzyExtractor(len(value), 2)
    key, helpers = extractor.generate(value)

    assert extractor.reproduce(value, helpers) == key
Ejemplo n.º 5
0
def test_locker_args():
    """Test that locker args passed to FuzzyExtractor work"""
    val = b'AAAABBBBCCCCDDDD'

    extractor = FuzzyExtractor(len(val),
                               1,
                               hash_func='sha512',
                               sec_len=3,
                               nonce_len=32)
    key, helpers = extractor.generate(val)

    assert extractor.reproduce(val, helpers) == key
Ejemplo n.º 6
0
def test_reproduce():
    """Tests that a fuzzy extractor can reproduce the same key from the same input"""
    random.seed()

    val_len = 30
    chars = string.ascii_letters
    values = list()
    for _ in range(150):
        values.append("".join(random.choice(chars) for _ in range(val_len)))

    for value in values:
        extractor = FuzzyExtractor(val_len, 2)
        key, helpers = extractor.generate(value)
        assert extractor.reproduce(value, helpers) == key
Ejemplo n.º 7
0
def test_reproduce_fuzzy():
    """Test fuzzy extractor reproduce with some noise added in"""
    random.seed()

    val_len = 30
    chars = string.ascii_letters
    values = list()
    for _ in range(5):
        values.append("".join(random.choice(chars) for _ in range(val_len)))

    for value in values:
        # extractor can handle at least 8 bit flips
        extractor = FuzzyExtractor(val_len, 8)
        key, helpers = extractor.generate(value)
        # change a random character, which could flip up to 8 bits
        pos = random.randint(0, val_len - 2)
        value_noisy = value[:pos] + random.choice(chars) + value[pos + 1:]
        # extractor should still produce same key
        assert extractor.reproduce(value_noisy, helpers) == key
Ejemplo n.º 8
0
def FuzzyPoro():

    extractor = FuzzyExtractor(10, 3)  # (CharacterLength, ErrorAllowed)
    # Sample Biometric Data
    BiometricData = input("Enter biometric data (10 characters):")
    BiometricData = BiometricData.encode('utf-8')
    PrivateKey = input("Enter your private key:")
    PrivateKey = PrivateKey.encode('utf-8')
    # Create the key and the helper
    key, helper = extractor.generate(BiometricData)

    print('Your key is: %s' % (key))

    # Runs your generated key through TripleSec
    KeyForTripleSec = TripleSec(key)
    EncryptedPrivateKey = KeyForTripleSec.encrypt(
        PrivateKey)  # Encrypts your private key

    # Writes a local file with your encrypted private key in it. This file
    #gets uploaded to IPFS and you get to keep a local backup. You can delete it if you want.
    FileWrite = open("EncryptedKey.txt", "w+")
    FileWrite.write(str(EncryptedPrivateKey))
    FileWrite.close()

    print('Your encrypted private key is: %s' % (EncryptedPrivateKey))

    # The second time you scan your fingerprint/biometric data
    KeyRecover = input("Enter your biometric data again:")
    KeyReturn = extractor.reproduce(KeyRecover,
                                    helper)  # Creates your original key

    print('Your recovered key is: %s' % (KeyReturn))

    # Runs your regenerated key through TripleSec
    ExtractedKey = TripleSec(KeyReturn)

    try:
        print('Your private key is: ')

        # Decodes your EncryptedPrivateKey with your regenerated encryption key
        print(ExtractedKey.decrypt(EncryptedPrivateKey).decode())
    except:
        print('Wrong encryption key :(')
Ejemplo n.º 9
0
from fuzzy_extractor import FuzzyExtractor

extractor = FuzzyExtractor(16, 8)
key, helper = extractor.generate('AABBCCDDEEFFGGHH')

print("KEY: " + str(key))
print(extractor.reproduce('AABBCCDDEEFFGGHH', helper))
print(extractor.reproduce('AABBCXDDEEFFGGHH', helper))
print(extractor.reproduce('VABBCXDDNNFFGGHF', helper))
print(extractor.reproduce('AABBCCDDEEFFGGHI', helper))
print(extractor.reproduce('AAAAAAAAAAAAAAAA', helper))
    def fuzzy_extractor_rep(self, fbio, helper):

        extractor = FuzzyExtractor(16, 2)
        r_key = extractor.reproduce(
            fbio, helper)  # r_key will probably still equal key!
        return (r_key)