blob: 985ef825cd3f3e37dd3804a345398b0af7c7dc8b [file] [log] [blame]
Yingdi Yu8dceb1d2014-02-18 12:45:10 -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"
10#include "util/time.hpp"
11
12using namespace std;
13
14namespace ndn {
15
16BOOST_AUTO_TEST_SUITE(TestKeyChain)
17
18BOOST_AUTO_TEST_CASE (ExportIdentity)
19{
20 KeyChainImpl<SecPublicInfoSqlite3, SecTpmFile> keyChain;
21
22 Name identity(string("/TestKeyChain/ExportIdentity/") + boost::lexical_cast<std::string>(time::now()));
23 keyChain.createIdentity(identity);
24
25 Block exported = keyChain.exportIdentity(identity, true, "1234");
26
27 Name keyName = keyChain.getDefaultKeyNameForIdentity(identity);
28 Name certName = keyChain.getDefaultCertificateNameForKey(keyName);
29
30 keyChain.deleteIdentity(identity);
31
32 BOOST_REQUIRE(keyChain.doesIdentityExist(identity) == false);
33 BOOST_REQUIRE(keyChain.doesPublicKeyExist(keyName) == false);
34 BOOST_REQUIRE(keyChain.doesKeyExistInTpm(keyName, KEY_CLASS_PRIVATE) == false);
35 BOOST_REQUIRE(keyChain.doesKeyExistInTpm(keyName, KEY_CLASS_PUBLIC) == false);
36 BOOST_REQUIRE(keyChain.doesCertificateExist(certName) == false);
37
38 keyChain.importIdentity(exported, true, "1234");
39
40 BOOST_REQUIRE(keyChain.doesIdentityExist(identity));
41 BOOST_REQUIRE(keyChain.doesPublicKeyExist(keyName));
42 BOOST_REQUIRE(keyChain.doesKeyExistInTpm(keyName, KEY_CLASS_PRIVATE));
43 BOOST_REQUIRE(keyChain.doesKeyExistInTpm(keyName, KEY_CLASS_PUBLIC));
44 BOOST_REQUIRE(keyChain.doesCertificateExist(certName));
45
46 keyChain.deleteIdentity(identity);
47
48 BOOST_REQUIRE(keyChain.doesIdentityExist(identity) == false);
49 BOOST_REQUIRE(keyChain.doesPublicKeyExist(keyName) == false);
50 BOOST_REQUIRE(keyChain.doesKeyExistInTpm(keyName, KEY_CLASS_PRIVATE) == false);
51 BOOST_REQUIRE(keyChain.doesKeyExistInTpm(keyName, KEY_CLASS_PUBLIC) == false);
52 BOOST_REQUIRE(keyChain.doesCertificateExist(certName) == false);
53}
54
55BOOST_AUTO_TEST_SUITE_END()
56
57} // namespace ndn