xaptum / ecdaa

A C implementation of elliptic-curve-based Direct Anonymous Attestation (DAA) signatures. Created to support the Xaptum Edge Network Fabric, an IoT Network Solution.
https://www.xaptum.com
Apache License 2.0
45 stars 8 forks source link

TPM Tests fail persistently #140

Closed preisacm closed 3 years ago

preisacm commented 3 years ago

Problem

The CTests which use a key in a present TPM fail in different setups (Tests #13-16). Generating a key inside the TPM with resulting pub_key.txt and handle.txt works with ecdaa-create_tpm_key-util

Expected behaviour

Given the a working TPM holding the correct key, the TPM tests pass.

How is the problem reproduced

Given a minimal installation, I did the following on Debian 10:

apt install gcc cmake build-essential doxygen doxygen-latex parallel libtss2-dev
apt install git
git clone https://github.com/xaptum/ecdaa
mkdir ecdaa/build && cd ecdaa/build
export CMAKE_PREFIX_PATH=/usr
../.travis/install-amcl.sh 
../.travis/install-amcl.sh  ./amcl /usr FB256BN
../.travis/install-amcl.sh  ./amcl /usr FP256BN
cmake .. -DCMAKE_BUILD_TYPE=Release -DECDAA_CURVES=FP256BN -DCMAKE_INSTALL_PREFIX=/usr -DECDAA_TPM_SUPPORT=ON -DBUILD_EXAMPLES=ON -DBUILD_BENCHMARKS=ON
cmake --build . --target install
testBin/ecdaa-create_tpm_key-util test/tpm/pub_key.txt test/tpm/handle.txt
ctest -V

Instead of using libtss2-dev you provide an install script which builds libtss2 from source. I tried that as well.

Result

UpdateCTestConfiguration  from :/root/ecdaa/build/DartConfiguration.tcl
Parse Config file:/root/ecdaa/build/DartConfiguration.tcl
UpdateCTestConfiguration  from :/root/ecdaa/build/DartConfiguration.tcl
Parse Config file:/root/ecdaa/build/DartConfiguration.tcl
Test project /root/ecdaa/build
Constructing a list of tests
Done constructing a list of tests
Updating test list for fixtures
Added 0 tests to meet fixture requirements
Checking test dependency graph...
Checking test dependency graph end
test 1
      Start  1: ecdaa-big_256_56-tests

1: Test command: /root/ecdaa/build/testBin/ecdaa-big_256_56-tests
1: Test timeout computed to be: 1500
1: Starting mpi_utils::hash_not_zero...
1:  success!
1: Starting mpi_utils::hash_two_not_zero...
1:  success!
1: Starting mpi_utils::hash_two_same_messages...
1:  success!
1: Starting mpi_utils::hash_ok_with_no_msg...
1:  success!
1: Starting mpi_utils::hash_same_message...
1:  success!
1: Starting mpi_utils::mul_and_add_all_zeros...
1:  success
1: Starting mpi_utils::mul_and_add_all_ones...
1:  success
1: Starting mpi_utils::mul_and_add_modulus_two...
1:  success
1: Starting mpi_utils::mul_and_add_normalization_works...
1:  success
1: Starting mpi_utils::mul_and_add_greater_than_modulus_ok...
1:  success
1: Starting mpi_utils::mul_and_add_small_sanity_check...
1:  success
 1/16 Test  #1: ecdaa-big_256_56-tests .................   Passed    0.00 sec
test 2
      Start  2: ecdaa-credential_FP256BN-tests

2: Test command: /root/ecdaa/build/testBin/ecdaa-credential_FP256BN-tests
2: Test timeout computed to be: 1500
2: Starting credential::cred_generate_validate...
2:  success
2: Starting credential::lengths_same...
2:  success
2: Starting credential::cred_generate_then_serialize_deserialize...
2:  success
2: Starting credential::cred_generate_then_serialize_deserialize_file...
2:  success
2: Starting credential::cred_generate_then_serialize_deserialize_fp...
2:  success
 2/16 Test  #2: ecdaa-credential_FP256BN-tests .........   Passed    0.08 sec
test 3
      Start  3: ecdaa-ecp2_FP256BN-tests

3: Test command: /root/ecdaa/build/testBin/ecdaa-ecp2_FP256BN-tests
3: Test timeout computed to be: 1500
3: Starting ecp2_FP256BN::g2_basepoint_not_inf...
3:  success
3: Starting ecp2_FP256BN::g2_serialize_then_deserialize_basepoint...
3:  success
3: Starting ecp2_FP256BN::g2_lengths_same...
3:  success
3: Starting ecp2_FP256BN::g2_deserialize_badformat_fails...
3:  success
3: Starting ecp2_FP256BN::g2_deserialize_badcoords_fails...
3:  success
 3/16 Test  #3: ecdaa-ecp2_FP256BN-tests ...............   Passed    0.00 sec
test 4
      Start  4: ecdaa-ecp_FP256BN-tests

4: Test command: /root/ecdaa/build/testBin/ecdaa-ecp_FP256BN-tests
4: Test timeout computed to be: 1500
4: Starting ecp_FP256BN::g1_basepoint_not_inf...
4:  success
4: Starting ecp_FP256BN::g1_serialize_then_deserialize_basepoint...
4:  success
4: Starting ecp_FP256BN::g1_lengths_same...
4:  success
4: Starting ecp_FP256BN::g1_deserialize_badformat_fails...
4:  success
4: Starting ecp_FP256BN::g1_deserialize_badcoords_fails...
4:  success
4: Starting pairing_curve_utils::random_num_mod_order_is_valid...
4:  success
 4/16 Test  #4: ecdaa-ecp_FP256BN-tests ................   Passed    2.08 sec
test 5
      Start  5: ecdaa-group_public_key_FP256BN-tests

5: Test command: /root/ecdaa/build/testBin/ecdaa-group_public_key_FP256BN-tests
5: Test timeout computed to be: 1500
5: Starting group_public_key::serialize_then_deserialize_basepoints...
5:  success
5: Starting group_public_key::serialize_then_deserialize_basepoints_file...
5:  success
5: Starting group_public_key::serialize_then_deserialize_basepoints_fp...
5:  success
5: Starting group_public_key::lengths_same...
5:  success
5: Starting group_public_key::deserialize_garbage_fails...
5:  success
 5/16 Test  #5: ecdaa-group_public_key_FP256BN-tests ...   Passed    0.01 sec
test 6
      Start  6: ecdaa-issuer_keypair_FP256BN-tests

6: Test command: /root/ecdaa/build/testBin/ecdaa-issuer_keypair_FP256BN-tests
6: Test timeout computed to be: 1500
6: Starting issuer_keypair::issuer_secrets_are_valid...
6:  success
6: Starting issuer_keypair::generated_validates...
6:  success
6: Starting issuer_keypair::lengths_same...
6:  success
6: Starting issuer_keypair::generate_then_serialize_deserialize...
6:  success
6: Starting issuer_keypair::generate_then_serialize_deserialize_file...
6:  success
6: Starting issuer_keypair::generate_then_serialize_deserialize_fp...
6:  success
 6/16 Test  #6: ecdaa-issuer_keypair_FP256BN-tests .....   Passed    0.05 sec
test 7
      Start  7: ecdaa-member_keypair_FP256BN-tests

7: Test command: /root/ecdaa/build/testBin/ecdaa-member_keypair_FP256BN-tests
7: Test timeout computed to be: 1500
7: Starting member_keypair::member_secret_is_valid...
7:  success
7: Starting member_keypair::member_public_is_valid...
7:  success
7: Starting member_keypair::zero_nonce_ok...
7:  success
7: Starting member_keypair::lengths_same...
7:  success
7: Starting member_keypair::generated_validates...
7:  success
7: Starting member_keypair::serialize_deserialize_secret...
7:  success
7: Starting member_keypair::serialize_deserialize_public_no_check...
7:  success
7: Starting member_keypair::serialize_deserialize_public_no_check...
7:  success
7: Starting member_keypair::serialize_deserialize_secret_file...
7:  success
7: Starting member_keypair::serialize_deserialize_public_no_check_file...
7:  success
7: Starting member_keypair::serialize_deserialize_public_no_check_file...
7:  success
7: Starting member_keypair::serialize_deserialize_secret_fp...
7:  success
7: Starting member_keypair::serialize_deserialize_public_no_check_fp...
7:  success
7: Starting member_keypair::serialize_deserialize_public_no_check_fp...
7:  success
 7/16 Test  #7: ecdaa-member_keypair_FP256BN-tests .....   Passed    0.02 sec
test 8
      Start  8: ecdaa-schnorr_FP256BN-tests

8: Test command: /root/ecdaa/build/testBin/ecdaa-schnorr_FP256BN-tests
8: Test timeout computed to be: 1500
8: Starting schnorr::schnorr_keygen_sane...
8:  success
8: Starting schnorr::schnorr_sign_sane...
8:  success
8: Starting schnorr::schnorr_verify_wrong_key...
8:  success
8: Starting schnorr::schnorr_verify_wrong_msg...
8:  success
8: Starting schnorr::schnorr_verify_bad_sig...
8:  success
8: Starting schnorr::schnorr_sign_integration...
8:  success
8: Starting schnorr::schnorr_sign_integration_other_points...
8:  success
8: Starting schnorr::schnorr_basename...
8:  success
8: Starting schnorr::schnorr_wrong_basename_fails...
8:  success
8: Starting schnorr::schnorr_credential_sign_sane...
8:  success
8: Starting schnorr::schnorr_credential_sign_integration...
8:  success
8: Starting schnorr::schnorr_issuer_sign_sane...
8:  success
8: Starting schnorr::schnorr_issuer_sign_integration...
8:  success
 8/16 Test  #8: ecdaa-schnorr_FP256BN-tests ............   Passed    0.04 sec
test 9
      Start  9: ecdaa-signature_FP256BN-tests

9: Test command: /root/ecdaa/build/testBin/ecdaa-signature_FP256BN-tests
9: Test timeout computed to be: 1500
9: Starting signature::sign_then_verify_good...
9:  success
9: Starting signature::sign_then_verify_on_rev_list...
9:  success
9: Starting signature::sign_then_verify_bad_basename_fails...
9:  success
9: Starting signature::sign_then_verify_no_basename...
9:  success
9: Starting signature::sign_then_verify_on_bsn_rev_list...
9:  success
9: Starting signature::sign_then_verify_unlinkable...
9:  success
9: Starting signature::lengths_same...
9:  success
9: Starting signature::serialize_deserialize...
9:  success
9: Starting signature::serialize_deserialize_file...
9:  success
9: Starting signature::serialize_deserialize_fp...
9:  success
9: Starting signature::pseudonym...
9:  success
9: Starting signature::serialize_deserialize...
9:  success
 9/16 Test  #9: ecdaa-signature_FP256BN-tests ..........   Passed    0.26 sec
test 10
      Start 10: ecdaa-schnorr_FP256BN-fuzz

10: Test command: /root/ecdaa/build/testBin/ecdaa-schnorr_FP256BN-fuzz
10: Test timeout computed to be: 1500
10: Starting schnorr::schnorr_repeated...
10:     success
10/16 Test #10: ecdaa-schnorr_FP256BN-fuzz .............   Passed    0.08 sec
test 11
      Start 11: ecdaa-integration-tests

11: Test command: /usr/bin/python "/root/ecdaa/build/testBin//ecdaa-integration-tests.py" "/root/ecdaa/build/bin/"
11: Test timeout computed to be: 1500
11: Group successfully created!
11: Group public key successfully saved!
11: Member key-pair successfully created!
11: Credential successfully created!
11: Credential validated!
11: Signature successfully created!
11: Signature successfully verified!
11: Group successfully created!
11: Group public key successfully saved!
11: Member key-pair successfully created!
11: Credential successfully created!
11: Credential validated!
11: Group public key successfully saved!
11: Member key-pair successfully created!
11: Credential successfully created!
11: Credential validated!
11: Group public key successfully saved!
11: Member key-pair successfully created!
11: Credential successfully created!
11: Credential validated!
11: Signature successfully created!
11: Signature not valid!
11: Signature successfully created!
11: Signature not valid!
11: Signature successfully created!
11: Signature successfully verified!
11: Group successfully created!
11: Group successfully created!
11: Group public key successfully saved!
11: Member key-pair successfully created!
11: Credential successfully created!
11: Credential validated!
11: Group public key successfully saved!
11: Member key-pair successfully created!
11: Credential successfully created!
11: Credential validated!
11: Signature successfully created!
11: Signature not valid!
11/16 Test #11: ecdaa-integration-tests ................   Passed    0.35 sec
test 12
      Start 12: tool_test

12: Test command: /root/ecdaa/test/tool-test.sh "/root/ecdaa/build/tool"
12: Test timeout computed to be: 1500
12: Generating issuer keys...
12: ok
12: Generating member keys...
12: ok
12: Extracting issuer's group public key...
12: ok
12: Create a credential, and credential signature, on the member's public key...
12: ok
12: Validate a credential issued for the given member public key...
12: ok
12: Create a DAA signature over the message...
12: ok
12: Verify the signature...
12: ok
12: Check that signature does NOT verify for a revoked secret key...
12: Signature doesn't verify
12: Check that signature does NOT verify for a different message...
12: Signature doesn't verify
12/16 Test #12: tool_test ..............................   Passed    0.09 sec
test 13
      Start 13: ecdaa-schnorr_TPM_FP256BN-tests

13: Test command: /root/ecdaa/build/testBin/ecdaa-schnorr_TPM_FP256BN-tests
13: Test timeout computed to be: 1500
13: Starting tpm-test::full_test...
13: Error in schnorr_verify_TPM_FP256BN, ret=-1, tpm_rc=0x0
13: Condition '0==1' failed
13:     in file: '/root/ecdaa/build/test/tpm/schnorr_TPM_FP256BN-tests.c'
13:     in function: 'full_test'
13:     at line: 76
13: exiting
13/16 Test #13: ecdaa-schnorr_TPM_FP256BN-tests ........***Failed    0.22 sec
test 14
      Start 14: ecdaa-signature_TPM_FP256BN-tests

14: Test command: /root/ecdaa/build/testBin/ecdaa-signature_TPM_FP256BN-tests
14: Test timeout computed to be: 1500
14: Starting signature_TPM_FP256BN::sign_then_verify_good...
14: Condition '0 == ecdaa_signature_FP256BN_verify(&sig, &fixture.ipk.gpk, &fixture.revocations, fixture.msg, fixture.msg_len, fixture.basename, fixture.basename_len)' failed
14:     in file: '/root/ecdaa/build/test/tpm/signature_TPM_FP256BN-tests.c'
14:     in function: 'sign_then_verify_good'
14:     at line: 117
14: exiting
14/16 Test #14: ecdaa-signature_TPM_FP256BN-tests ......***Failed    0.67 sec
test 15
      Start 15: ecdaa-tpm_FP256BN-test

15: Test command: /root/ecdaa/build/testBin/ecdaa-tpm_FP256BN-test
15: Test timeout computed to be: 1500
15: Called TPM2_Commit with empty buffers, now count=8, and 
15: E:{0X4, 0XC7, 0XEC, 0X21, 0X47, 0X79, 0X4D, 0X9D, 0XF1, 0X9B, 0X86, 0X13, 0XE6, 0X1D, 0XB5, 0XC7, 0X95, 0X77, 0X2C, 0X4D, 0XEC, 0X38, 0XEC, 0X1A, 0XCF, 0XD8, 0X69, 0X7, 0X64, 0XDE, 0XE0, 0XA1, 0XE0, 0X8F, 0XD2, 0XB2, 0XE4, 0X10, 0X66, 0XD4, 0X69, 0X82, 0X39, 0X6D, 0X9F, 0X34, 0XA, 0X18, 0X22, 0X2, 0X8B, 0XE7, 0X74, 0XA8, 0XE6, 0X80, 0X92, 0X95, 0X53, 0X7D, 0X6A, 0XF7, 0XF9, 0XA, 0X43, }
15: 
15: [s]G1 - c*pub_key={0X4, 0XD0, 0X2E, 0X4F, 0X78, 0X72, 0XF6, 0X2A, 0X24, 0X43, 0XD5, 0XB6, 0X68, 0X5A, 0X2F, 0X9E, 0XCD, 0XA8, 0X9E, 0X6C, 0XE3, 0X96, 0X6C, 0X8A, 0X94, 0X33, 0X79, 0XA2, 0XE5, 0X91, 0X13, 0XA6, 0XF5, 0XF0, 0X66, 0X5D, 0XB, 0XF1, 0X89, 0XD3, 0X43, 0X58, 0XDF, 0X3B, 0X4B, 0X3F, 0XDB, 0XB3, 0X18, 0X91, 0X39, 0XE9, 0XCA, 0XB3, 0XA0, 0XFA, 0XAB, 0X49, 0XE8, 0X6A, 0X77, 0X4, 0XF6, 0XF9, 0X78, }
15: 
15: Error: [s]G1 - T*pub_key != E
15: Condition '0 == 1' failed
15:     in file: '/root/ecdaa/build/test/tpm/tpm_FP256BN-test.c'
15:     in function: 'signature_math_checks'
15:     at line: 110
15: exiting
15/16 Test #15: ecdaa-tpm_FP256BN-test .................***Failed    0.21 sec
test 16
      Start 16: ecdaa-schnorr_TPM_FP256BN-fuzz

16: Test command: /root/ecdaa/build/testBin/ecdaa-schnorr_TPM_FP256BN-fuzz
16: Test timeout computed to be: 1500
16: Starting schnorr_TPM::schnorr_TPM_repeated...
16: Error in schnorr_verify_TPM_FP256BN, ret=-1, tpm_rc=0x0
16: Condition '0==1' failed
16:     in file: '/root/ecdaa/build/test/tpm/schnorr_TPM_FP256BN-fuzz.c'
16:     in function: 'schnorr_TPM_repeated'
16:     at line: 92
16: exiting
16/16 Test #16: ecdaa-schnorr_TPM_FP256BN-fuzz .........***Failed    0.42 sec

75% tests passed, 4 tests failed out of 16

Total Test time (real) =   4.58 sec

The following tests FAILED:
     13 - ecdaa-schnorr_TPM_FP256BN-tests (Failed)
     14 - ecdaa-signature_TPM_FP256BN-tests (Failed)
     15 - ecdaa-tpm_FP256BN-test (Failed)
     16 - ecdaa-schnorr_TPM_FP256BN-fuzz (Failed)
Errors while running CTest

I cannot get these test to pass. It seems to be a problem with the file format of pub_key.txt When playing around with the provided functions to parse the public key I ended up with the error message that the pubkey does not lie on the ECC curve (probably a file encoding problem?).

Best regards, Michael Preisach

zanebeckwith commented 3 years ago

Hi @preisacm, sorry for the long delay on responding to this issue

To make sure I understand the issue: you're attempting to create a key in your TPM (using the ecdaa-create_tpm_key-util utility), and use that key in the tests, correct? (I.e. you're not using some other key that was created in the TPM some other way, at another time)

Do you know what firmware version this TPM has? You can use this tool (also available here, if the instructions are more helpful there) to check the firmware version.

The reason I ask is that the failing test 15 (the signature_math_checks in particular) looks like a failure related to Infineon SLB 9670 TPMs with firmware version < 7.63 (I think; I may have those numbers slightly wrong). See this closed issue.

Also, could you post the contents of pub_key.txt and handle.txt?

preisacm commented 3 years ago

The ecdaa-create_tpm_key-util utility clears the TPM before any key is installed, so: yes, there are no other keys in place

I use 3 different TPMs, all Infineon SLB9665. Here is what your tool is saying:

root@intel1:~/infineon-tpm-update# ./TPMFactoryUpd -info
  **********************************************************************
  *    Infineon Technologies AG   TPMFactoryUpd   Ver 01.04.2811.00    *
  **********************************************************************

       TPM information:
       ----------------
       Firmware valid                    :    Yes
       TPM family                        :    2.0
       TPM firmware version              :    5.61.2785.0
       TPM platformAuth                  :    Not Empty Buffer
       Remaining updates                 :    63
root@amd1:~/infineon-tpm-update# ./TPMFactoryUpd -info
  **********************************************************************
  *    Infineon Technologies AG   TPMFactoryUpd   Ver 01.04.2811.00    *
  **********************************************************************

       TPM information:
       ----------------
       Firmware valid                    :    Yes
       TPM family                        :    2.0
       TPM firmware version              :    5.63.3353.0
       TPM platformAuth                  :    Not Empty Buffer
       Remaining updates                 :    64

And I see that the older firmware version fails, while the newer one works perfectly fine. I did obviously test only the old machine. Thanks for bringing that up!

I assume that i can use the key created with the util (pubkey.txt and handle.txt) also for testing the member_tpm functions of your library? Basically by creating a file-based DAA protocol similar to the demo in zour repo.

Your tool can upgrade a firmware, but do you know where I get the firmware binary (the TPM is detachable and was bought separately from the computer). I didn't find an Infineon binary Repo at all and the board vendor (Gigabyte) does not seem to provide anything either.

zanebeckwith commented 3 years ago

the older firmware version fails, while the newer one works perfectly fine

Ah, OK, I'm glad this at least makes sense.

I should explain this in the docs, if it's not there (and perhaps have the test I noticed explicitly scream something about "this TPM may be too old". Ha)

I assume that i can use the key created with the util (pubkey.txt and handle.txt) also for testing the member_tpm functions of your library? Basically by creating a file-based DAA protocol similar to the demo in zour repo.

Yes (assuming you're using a new-enough TPM, of course). Apologies that I still haven't updated those demo examples to use a TPM

do you know where I get the firmware binary

Hmm, no, not really, sorry. Perhaps you can reach out to Infineon?

preisacm commented 3 years ago

Thanks for your help. I'm asking for support at Infineon to get the FW updates. Regarding the DAA Example with TPM: I still fail there to get it run, but i will file a new issue for that when I have a proper demo code showing my problem.

zanebeckwith commented 3 years ago

I'm asking for support at Infineon to get the FW updates.

Ok, good luck! Sorry I couldn't help more.

i will file a new issue for that when I have a proper demo

Sounds good. Thanks for doing that.