blob: aec65a15e012ed170ac6bbd8e126826526a6afbb [file] [log] [blame]
Mickey Sweatt11314b72015-06-10 17:20:19 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Yingdi Yu6ee2d362015-07-16 21:48:05 -07003 * Copyright (c) 2013-2017 Regents of the University of California.
Mickey Sweatt11314b72015-06-10 17:20:19 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6 *
7 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20 */
21
Alexander Afanasyev97709c02016-08-25 19:58:30 -070022#include "security/pib/pib-sqlite3.hpp"
23#include "security/pib/pib.hpp"
Mickey Sweatt11314b72015-06-10 17:20:19 -070024
Mickey Sweatt11314b72015-06-10 17:20:19 -070025#include "boost-test.hpp"
26
Davide Pesaventoeee3e822016-11-26 19:19:34 +010027#include <boost/filesystem.hpp>
28
Mickey Sweatt11314b72015-06-10 17:20:19 -070029namespace ndn {
30namespace security {
Yingdi Yu6ee2d362015-07-16 21:48:05 -070031namespace pib {
Mickey Sweatt11314b72015-06-10 17:20:19 -070032namespace tests {
33
Alexander Afanasyev97709c02016-08-25 19:58:30 -070034BOOST_AUTO_TEST_SUITE(Security)
Yingdi Yu6ee2d362015-07-16 21:48:05 -070035BOOST_AUTO_TEST_SUITE(Pib)
Alexander Afanasyev97709c02016-08-25 19:58:30 -070036
Mickey Sweatt11314b72015-06-10 17:20:19 -070037class PibSqlite3TestFixture
38{
39public:
40 PibSqlite3TestFixture()
41 : m_path(boost::filesystem::path(UNIT_TEST_CONFIG_PATH) / "DbTest")
42 , impl(m_path.c_str())
43 {
44 }
45
46 ~PibSqlite3TestFixture()
47 {
48 boost::filesystem::remove_all(m_path);
49 }
50
51private:
52 boost::filesystem::path m_path;
53
54public:
55 PibSqlite3 impl;
56};
57
Davide Pesaventoeee3e822016-11-26 19:19:34 +010058BOOST_FIXTURE_TEST_SUITE(TestPibSqlite3, PibSqlite3TestFixture)
Mickey Sweatt11314b72015-06-10 17:20:19 -070059
Yingdi Yu6ee2d362015-07-16 21:48:05 -070060using pib::Pib;
61
Mickey Sweatt11314b72015-06-10 17:20:19 -070062// most functionalities are tested in pib-impl.t.cpp
63
64const uint8_t SELF_SIGNED_ECDSA_CERT[] = {
Yingdi Yu6ee2d362015-07-16 21:48:05 -070065 0x06, 0xfd, 0x01, 0x5b, 0x07, 0x33, 0x08, 0x05, 0x65, 0x63, 0x64, 0x73, 0x61, 0x08, 0x03,
66 0x4b, 0x45, 0x59, 0x08, 0x11, 0x6b, 0x73, 0x6b, 0x2d, 0x31, 0x34, 0x31, 0x36, 0x35, 0x39,
67 0x34, 0x35, 0x35, 0x32, 0x38, 0x32, 0x37, 0x08, 0x07, 0x49, 0x44, 0x2d, 0x43, 0x45, 0x52,
68 0x54, 0x08, 0x09, 0xfd, 0x00, 0x00, 0x01, 0x49, 0xd3, 0x9d, 0x78, 0x00, 0x14, 0x03, 0x18,
69 0x01, 0x02, 0x15, 0xa5, 0x30, 0x81, 0xa2, 0x30, 0x22, 0x18, 0x0f, 0x32, 0x30, 0x31, 0x34,
70 0x31, 0x31, 0x32, 0x31, 0x31, 0x38, 0x32, 0x39, 0x31, 0x32, 0x5a, 0x18, 0x0f, 0x32, 0x30,
71 0x33, 0x34, 0x31, 0x31, 0x31, 0x36, 0x31, 0x38, 0x32, 0x39, 0x31, 0x32, 0x5a, 0x30, 0x21,
72 0x30, 0x1f, 0x06, 0x03, 0x55, 0x04, 0x29, 0x13, 0x18, 0x2f, 0x65, 0x63, 0x64, 0x73, 0x61,
73 0x2f, 0x6b, 0x73, 0x6b, 0x2d, 0x31, 0x34, 0x31, 0x36, 0x35, 0x39, 0x34, 0x35, 0x35, 0x32,
74 0x38, 0x32, 0x37, 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02,
75 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04,
76 0x83, 0xe5, 0x81, 0x19, 0xd9, 0xfa, 0x64, 0x40, 0xad, 0x7c, 0x93, 0xfc, 0x15, 0x90, 0x6b,
77 0x38, 0x1e, 0xc5, 0xca, 0xb1, 0x6b, 0x0b, 0x1f, 0x64, 0xbf, 0x48, 0xaa, 0xd0, 0x91, 0x5c,
78 0x24, 0xd6, 0x78, 0x40, 0xfd, 0x95, 0x5d, 0x54, 0x64, 0xe1, 0x2d, 0x0e, 0x98, 0x66, 0x1d,
79 0x7a, 0xb0, 0x61, 0x17, 0x05, 0x26, 0x13, 0x63, 0x25, 0x7c, 0xda, 0x87, 0x11, 0xc9, 0x67,
80 0xcd, 0x12, 0x05, 0xf0, 0x16, 0x2f, 0x1b, 0x01, 0x03, 0x1c, 0x2a, 0x07, 0x28, 0x08, 0x05,
81 0x65, 0x63, 0x64, 0x73, 0x61, 0x08, 0x03, 0x4b, 0x45, 0x59, 0x08, 0x11, 0x6b, 0x73, 0x6b,
82 0x2d, 0x31, 0x34, 0x31, 0x36, 0x35, 0x39, 0x34, 0x35, 0x35, 0x32, 0x38, 0x32, 0x37, 0x08,
83 0x07, 0x49, 0x44, 0x2d, 0x43, 0x45, 0x52, 0x54, 0x17, 0x47, 0x30, 0x45, 0x02, 0x21, 0x00,
84 0x9b, 0xae, 0xf4, 0x87, 0x55, 0xaa, 0x78, 0xbf, 0x00, 0xff, 0x1a, 0xbe, 0x90, 0x46, 0x6e,
85 0xdd, 0xe6, 0x3b, 0x44, 0xfd, 0x41, 0x04, 0x86, 0xcc, 0x6a, 0x8b, 0x5a, 0x25, 0xbb, 0xf1,
86 0x55, 0xcd, 0x02, 0x20, 0x0e, 0x67, 0xd8, 0x86, 0xe8, 0x7c, 0x90, 0x3c, 0x13, 0xfd, 0x36,
87 0x9c, 0xbc, 0xa1, 0xc3, 0x7c, 0xe0, 0x0c, 0x6d, 0x64, 0xac, 0xdb, 0x69, 0x99, 0xde, 0x80,
88 0x35, 0x3f, 0xf4, 0x6a, 0xcd, 0x6f
Mickey Sweatt11314b72015-06-10 17:20:19 -070089};
90
91BOOST_AUTO_TEST_CASE(TpmTest)
92{
Alexander Afanasyev2fa59392016-07-29 17:24:23 -070093 Block selfSignedCertBlock(SELF_SIGNED_ECDSA_CERT, sizeof(SELF_SIGNED_ECDSA_CERT));
Yingdi Yu6ee2d362015-07-16 21:48:05 -070094 v2::Certificate cert;
Mickey Sweatt11314b72015-06-10 17:20:19 -070095 cert.wireDecode(selfSignedCertBlock);
Yingdi Yu6ee2d362015-07-16 21:48:05 -070096 Name identity = cert.getIdentity();
97 Name keyName = cert.getKeyName();
Mickey Sweatt11314b72015-06-10 17:20:19 -070098 Name certName = cert.getName();
99
100 // Basic getting and setting
101 BOOST_REQUIRE_THROW(impl.getTpmLocator(), Pib::Error);
102 impl.setTpmLocator("tpmLocator");
103 BOOST_CHECK_EQUAL(impl.getTpmLocator(), "tpmLocator");
104
105 // Add cert, and do not change tpmLocator
106 impl.addCertificate(cert);
107 BOOST_CHECK(impl.hasIdentity(identity));
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700108 BOOST_CHECK(impl.hasKey(keyName));
Mickey Sweatt11314b72015-06-10 17:20:19 -0700109 BOOST_CHECK(impl.hasCertificate(certName));
110
111 // Set tpmLocator with the existing value, nothing should change.
112 impl.setTpmLocator("tpmLocator");
113 BOOST_CHECK(impl.hasIdentity(identity));
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700114 BOOST_CHECK(impl.hasKey(keyName));
Mickey Sweatt11314b72015-06-10 17:20:19 -0700115 BOOST_CHECK(impl.hasCertificate(certName));
116
117 // Change tpmLocator and ensure the pib is reset
118 impl.setTpmLocator("newTpmLocator");
119 BOOST_CHECK_EQUAL(impl.getTpmLocator(), "newTpmLocator");
120
121 BOOST_CHECK_EQUAL(impl.getIdentities().size(), 0);
122 BOOST_CHECK_EQUAL(impl.getKeysOfIdentity(identity).size(), 0);
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700123 BOOST_CHECK_EQUAL(impl.getCertificatesOfKey(keyName).size(), 0);
Mickey Sweatt11314b72015-06-10 17:20:19 -0700124}
125
Davide Pesaventoeee3e822016-11-26 19:19:34 +0100126BOOST_AUTO_TEST_SUITE_END() // TestPibSqlite3
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700127BOOST_AUTO_TEST_SUITE_END() // Pib
Davide Pesaventoeee3e822016-11-26 19:19:34 +0100128BOOST_AUTO_TEST_SUITE_END() // Security
Mickey Sweatt11314b72015-06-10 17:20:19 -0700129
130} // namespace tests
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700131} // namespace pib
Mickey Sweatt11314b72015-06-10 17:20:19 -0700132} // namespace security
133} // namespace ndn