blob: aef2530a944cb387d831011dc40fa3ee4ef8a4f5 [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
Yingdi Yu17bc3012014-02-10 17:37:12 -080022 Name identityName("/TestSignedInterest/SignVerify");
23 Name certificateName;
24 BOOST_REQUIRE_NO_THROW(certificateName = keyChain.createIdentity(identityName));
Yingdi Yu4270f202014-01-28 14:19:16 -080025
Yingdi Yu17bc3012014-02-10 17:37:12 -080026 Interest interest("/TestSignedInterest/SignVerify/Interest1");
Yingdi Yu4270f202014-01-28 14:19:16 -080027 keyChain.signByIdentity(interest, identityName);
28
29 Block interestBlock(interest.wireEncode().wire(), interest.wireEncode().size());
30
31 Interest interest2;
32 interest2.wireDecode(interestBlock);
33
Yingdi Yu17bc3012014-02-10 17:37:12 -080034 shared_ptr<PublicKey> publicKey = keyChain.getPublicKeyFromTpm(keyChain.getDefaultKeyNameForIdentity(identityName));
Yingdi Yu6ac97982014-01-30 14:49:21 -080035 bool result = Validator::verifySignature(interest2, *publicKey);
Yingdi Yu4270f202014-01-28 14:19:16 -080036
Yingdi Yu17bc3012014-02-10 17:37:12 -080037 BOOST_CHECK_EQUAL(result, true);
38
39 BOOST_CHECK_NO_THROW(keyChain.deleteIdentity(identityName));
Yingdi Yu4270f202014-01-28 14:19:16 -080040}
41
42BOOST_AUTO_TEST_SUITE_END()
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -080043
44} // namespace ndn