示例#1
0
    def post(self, request):
        try:
            # Generates a unique key and the corresponding helper.
            puf_data = bytes.fromhex(request.data['pufData'])
            extractor = FuzzyExtractor(32, 8)
            key, helper = extractor.generate(puf_data)

            # Creates device object from the data in the request body.
            helper_string = json.dumps((
                hex_list(helper[0]),
                hex_list(helper[1]),
                hex_list(helper[2]),
            ))
            id_num = hex(zlib.crc32(key))
            device = {
                "id": id_num,
                "model": request.data['model'],
                "key": key.hex(),
                "helper": helper_string
            }

            # Serializes the device object and saves it in the database.
            serializer = DeviceSerializer(data=device)
            if serializer.is_valid():
                serializer.save()
                return Response(status=status.HTTP_201_CREATED)
            return Response(data=serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)
        except:
            return Response(data=traceback.format_exc(),
                            status=status.HTTP_500_INTERNAL_SERVER_ERROR)
示例#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())
示例#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)
    def fuzzy_extractor_gen(self, bio):

        extractor = FuzzyExtractor(
            16, 2
        )  # '16' means biometrics length, '2' is the hamming errors that can handle.
        (key, helper) = extractor.generate(bio)
        return (key, helper)
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
示例#6
0
def FuzzyPoro():

        extractor = FuzzyExtractor(10, 2)  # (CharacterLength, ErrorAllowed)
        # Sample Biometric Data
        BiometricData = raw_input("Enter a biometric data (10 characters):")
        PrivateKey = raw_input("Enter your private key:")
        # Create the key and the helper
        key, helper = extractor.generate(BiometricData)
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
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
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
示例#10
0
def FuzzyPoro():

    extractor = FuzzyExtractor(10, 2)  # (CharacterLength, ErrorAllowed)
    # Sample Biometric Data
    BiometricData = input("Enter a 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
示例#11
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
示例#12
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 :(')
示例#13
0
def test_init():
    """Test initialization to make sure it produces sane values"""
    random.seed()

    lens = [random.randint(1, 32) for _ in range(10000)]
    ham_errs = [random.randint(1, 7) for _ in range(len(lens))]

    for b_len, ham_err in zip(lens, ham_errs):
        extractor = FuzzyExtractor(b_len, ham_err)
        sys.stdout.write(str(b_len) + ' ' + str(ham_err) + "\n")
        assert extractor.num_helpers >= 1
示例#14
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)