blob: a7df5560955859a69476d8f3f7a6bbf0eaad876b [file] [log] [blame]
Yingdi Yu4270f202014-01-28 14:19:16 -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#include <boost/test/unit_test.hpp>
8
9#include "security/key-chain.hpp"
Yingdi Yu6ac97982014-01-30 14:49:21 -080010#include "security/validator.hpp"
Yingdi Yu4270f202014-01-28 14:19:16 -080011#include <iostream>
12
13using namespace std;
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -080014namespace ndn {
Yingdi Yu4270f202014-01-28 14:19:16 -080015
16BOOST_AUTO_TEST_SUITE(TestSignedInterest)
17
18BOOST_AUTO_TEST_CASE (SignVerify)
19{
20 KeyChainImpl<SecPublicInfoSqlite3, SecTpmFile> keyChain;
21
22 Name identityName("/test");
Yingdi Yu52e79532014-01-29 23:57:19 -080023 Name certificateName = keyChain.createIdentity(identityName);
Yingdi Yu4270f202014-01-28 14:19:16 -080024
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 Yu52e79532014-01-29 23:57:19 -080033 ptr_lib::shared_ptr<PublicKey> publicKey = keyChain.getPublicKeyFromTpm(keyChain.getDefaultKeyNameForIdentity(identityName));
Yingdi Yu6ac97982014-01-30 14:49:21 -080034 bool result = Validator::verifySignature(interest2, *publicKey);
Yingdi Yu4270f202014-01-28 14:19:16 -080035
36 BOOST_REQUIRE_EQUAL(result, true);
37}
38
39BOOST_AUTO_TEST_SUITE_END()
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -080040
41} // namespace ndn