blob: 9d75a387adccb038f71def67e71de54a6e3661b9 [file] [log] [blame]
Yingdi Yu04020922014-01-22 12:46:53 -08001/**
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
21#include <ndn-cpp-dev/security/key-chain.hpp>
22#include <cryptopp/rsa.h>
23
24using namespace std;
25using namespace ndn;
26
27
28BOOST_AUTO_TEST_SUITE(TestSecTpmFile)
29
30BOOST_AUTO_TEST_CASE (SignVerify)
31{
32 SecTpmFile tpm;
33
34 Name keyName("/tmp/ksk-123456");
35 tpm.generateKeyPairInTpm(keyName, KEY_TYPE_RSA, 2048);
36
37
38
39 Data data("/tmp/test/1");
40 const uint8_t content[] = {0x01, 0x02, 0x03, 0x04};
41
42 Block sigBlock = tpm.signInTpm(content, sizeof(content), keyName, DIGEST_ALGORITHM_SHA256);
43 ptr_lib::shared_ptr<PublicKey> pubkeyPtr = tpm.getPublicKeyFromTpm(keyName);
44
45 {
46 using namespace CryptoPP;
47
48 RSA::PublicKey publicKey;
49 ByteQueue queue;
50 queue.Put(reinterpret_cast<const byte*>(pubkeyPtr->get().buf()), pubkeyPtr->get().size());
51 publicKey.Load(queue);
52
53 RSASS<PKCS1v15, SHA256>::Verifier verifier (publicKey);
54 bool result = verifier.VerifyMessage(content, sizeof(content),
55 sigBlock.value(), sigBlock.value_size());
56
57 BOOST_REQUIRE_EQUAL(result, true);
58 }
59
60 //We should remove the temporary test key, this should be fixed in a later commit which will add delete operation in SecTpm.
61}
62
63BOOST_AUTO_TEST_SUITE_END()