blob: 5facdf423e06213f55c6a0eb2d34f5d3deaca1b4 [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
Alexander Afanasyev09c613f2014-01-29 00:23:58 -080021#include "security/key-chain.hpp"
Yingdi Yu04020922014-01-22 12:46:53 -080022#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");
Alexander Afanasyev1e0a0772014-01-28 20:07:07 -080035 try {
36 tpm.generateKeyPairInTpm(keyName, KEY_TYPE_RSA, 2048);
37 }
38 catch(const SecTpm::Error&) {
39 }
Yingdi Yu04020922014-01-22 12:46:53 -080040
Yingdi Yu04020922014-01-22 12:46:53 -080041 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
65BOOST_AUTO_TEST_SUITE_END()