Yingdi Yu | 4270f20 | 2014-01-28 14:19:16 -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 | #include <boost/test/unit_test.hpp> |
| 8 | |
| 9 | #include "security/key-chain.hpp" |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 10 | #include "security/validator.hpp" |
Yingdi Yu | 4270f20 | 2014-01-28 14:19:16 -0800 | [diff] [blame] | 11 | #include <iostream> |
| 12 | |
| 13 | using namespace std; |
Alexander Afanasyev | 0abb2da | 2014-01-30 18:07:57 -0800 | [diff] [blame] | 14 | namespace ndn { |
Yingdi Yu | 4270f20 | 2014-01-28 14:19:16 -0800 | [diff] [blame] | 15 | |
| 16 | BOOST_AUTO_TEST_SUITE(TestSignedInterest) |
| 17 | |
| 18 | BOOST_AUTO_TEST_CASE (SignVerify) |
| 19 | { |
| 20 | KeyChainImpl<SecPublicInfoSqlite3, SecTpmFile> keyChain; |
| 21 | |
| 22 | Name identityName("/test"); |
Yingdi Yu | 52e7953 | 2014-01-29 23:57:19 -0800 | [diff] [blame] | 23 | Name certificateName = keyChain.createIdentity(identityName); |
Yingdi Yu | 4270f20 | 2014-01-28 14:19:16 -0800 | [diff] [blame] | 24 | |
| 25 | Interest interest("/test/interest"); |
| 26 | keyChain.signByIdentity(interest, identityName); |
| 27 | |
| 28 | Block interestBlock(interest.wireEncode().wire(), interest.wireEncode().size()); |
| 29 | |
| 30 | Interest interest2; |
| 31 | interest2.wireDecode(interestBlock); |
| 32 | |
Yingdi Yu | 52e7953 | 2014-01-29 23:57:19 -0800 | [diff] [blame] | 33 | ptr_lib::shared_ptr<PublicKey> publicKey = keyChain.getPublicKeyFromTpm(keyChain.getDefaultKeyNameForIdentity(identityName)); |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 34 | bool result = Validator::verifySignature(interest2, *publicKey); |
Yingdi Yu | 4270f20 | 2014-01-28 14:19:16 -0800 | [diff] [blame] | 35 | |
| 36 | BOOST_REQUIRE_EQUAL(result, true); |
| 37 | } |
| 38 | |
| 39 | BOOST_AUTO_TEST_SUITE_END() |
Alexander Afanasyev | 0abb2da | 2014-01-30 18:07:57 -0800 | [diff] [blame] | 40 | |
| 41 | } // namespace ndn |