Yingdi Yu | 0402092 | 2014-01-22 12:46:53 -0800 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (C) 2013 Regents of the University of California. |
| 3 | * @author: Yingdi Yu <yingdi0@cs.ucla.edu> |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #if __clang__ |
| 8 | #pragma clang diagnostic ignored "-Wtautological-compare" |
| 9 | // #pragma clang diagnostic push |
| 10 | // #pragma clang diagnostic ignored "-Wreorder" |
| 11 | // #pragma clang diagnostic ignored "-Wunused-variable" |
| 12 | // #pragma clang diagnostic ignored "-Wunused-function" |
| 13 | // #elif __GNUC__ |
| 14 | // #pragma GCC diagnostic ignored "-Wreorder" |
| 15 | // #pragma GCC diagnostic ignored "-Wunused-variable" |
| 16 | // #pragma GCC diagnostic ignored "-Wunused-function" |
| 17 | #endif |
| 18 | |
| 19 | #include <boost/test/unit_test.hpp> |
| 20 | |
Alexander Afanasyev | 09c613f | 2014-01-29 00:23:58 -0800 | [diff] [blame] | 21 | #include "security/key-chain.hpp" |
Yingdi Yu | 0402092 | 2014-01-22 12:46:53 -0800 | [diff] [blame] | 22 | #include <cryptopp/rsa.h> |
| 23 | |
| 24 | using namespace std; |
| 25 | using namespace ndn; |
| 26 | |
| 27 | |
| 28 | BOOST_AUTO_TEST_SUITE(TestSecTpmFile) |
| 29 | |
| 30 | BOOST_AUTO_TEST_CASE (SignVerify) |
| 31 | { |
| 32 | SecTpmFile tpm; |
| 33 | |
| 34 | Name keyName("/tmp/ksk-123456"); |
Alexander Afanasyev | 1e0a077 | 2014-01-28 20:07:07 -0800 | [diff] [blame] | 35 | try { |
| 36 | tpm.generateKeyPairInTpm(keyName, KEY_TYPE_RSA, 2048); |
| 37 | } |
| 38 | catch(const SecTpm::Error&) { |
| 39 | } |
Yingdi Yu | 0402092 | 2014-01-22 12:46:53 -0800 | [diff] [blame] | 40 | |
Yingdi Yu | 0402092 | 2014-01-22 12:46:53 -0800 | [diff] [blame] | 41 | Data data("/tmp/test/1"); |
| 42 | const uint8_t content[] = {0x01, 0x02, 0x03, 0x04}; |
| 43 | |
| 44 | Block sigBlock = tpm.signInTpm(content, sizeof(content), keyName, DIGEST_ALGORITHM_SHA256); |
| 45 | ptr_lib::shared_ptr<PublicKey> pubkeyPtr = tpm.getPublicKeyFromTpm(keyName); |
| 46 | |
| 47 | { |
| 48 | using namespace CryptoPP; |
| 49 | |
| 50 | RSA::PublicKey publicKey; |
| 51 | ByteQueue queue; |
| 52 | queue.Put(reinterpret_cast<const byte*>(pubkeyPtr->get().buf()), pubkeyPtr->get().size()); |
| 53 | publicKey.Load(queue); |
| 54 | |
| 55 | RSASS<PKCS1v15, SHA256>::Verifier verifier (publicKey); |
| 56 | bool result = verifier.VerifyMessage(content, sizeof(content), |
| 57 | sigBlock.value(), sigBlock.value_size()); |
| 58 | |
| 59 | BOOST_REQUIRE_EQUAL(result, true); |
| 60 | } |
| 61 | |
| 62 | //We should remove the temporary test key, this should be fixed in a later commit which will add delete operation in SecTpm. |
| 63 | } |
| 64 | |
| 65 | BOOST_AUTO_TEST_SUITE_END() |