blob: b91fed145a13e36eb29630ba4551822e1b018b77 [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Yingdi Yu28fd32f2014-01-28 19:03:03 -08002/**
Alexander Afanasyevc169a812014-05-20 20:37:29 -04003 * Copyright (c) 2013-2014 Regents of the University of California.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * 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.
Yingdi Yu28fd32f2014-01-28 19:03:03 -080020 */
21
Yingdi Yuf56c68f2014-04-24 21:50:13 -070022#include "security/sec-public-info-sqlite3.hpp"
Yingdi Yu28fd32f2014-01-28 19:03:03 -080023#include "security/key-chain.hpp"
Yingdi Yu9a335352014-01-31 11:57:46 -080024#include "util/time.hpp"
Yingdi Yu28fd32f2014-01-28 19:03:03 -080025
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070026#include "boost-test.hpp"
27
Yingdi Yu28fd32f2014-01-28 19:03:03 -080028using namespace std;
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -080029namespace ndn {
Yingdi Yu28fd32f2014-01-28 19:03:03 -080030
Alexander Afanasyevd1b5c412014-03-27 15:03:51 -070031BOOST_AUTO_TEST_SUITE(SecurityTestSecPublicInfoSqlite3)
Yingdi Yu28fd32f2014-01-28 19:03:03 -080032
Yingdi Yuf56c68f2014-04-24 21:50:13 -070033BOOST_AUTO_TEST_CASE(Delete)
Yingdi Yu28fd32f2014-01-28 19:03:03 -080034{
Yingdi Yuf56c68f2014-04-24 21:50:13 -070035 BOOST_REQUIRE_NO_THROW(KeyChain("sqlite3", "file"));
36 KeyChain keyChain("sqlite3", "file");
Yingdi Yu28fd32f2014-01-28 19:03:03 -080037
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070038 Name identity("/TestSecPublicInfoSqlite3/Delete");
39 identity.appendVersion();
40
Alexander Afanasyevb46f9702014-02-06 18:58:55 -080041 Name certName1;
42 BOOST_REQUIRE_NO_THROW(certName1 = keyChain.createIdentity(identity));
Alexander Afanasyev6835ad82014-02-12 10:07:20 -080043
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070044 Name keyName1 = IdentityCertificate::certificateNameToPublicKeyName(certName1);
Yingdi Yu9a335352014-01-31 11:57:46 -080045 Name keyName2;
Yingdi Yuf56c68f2014-04-24 21:50:13 -070046 BOOST_REQUIRE_NO_THROW(keyName2 = keyChain.generateRsaKeyPairAsDefault(identity));
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070047
Yingdi Yu2e57a582014-02-20 23:34:43 -080048 shared_ptr<IdentityCertificate> cert2;
49 BOOST_REQUIRE_NO_THROW(cert2 = keyChain.selfSign(keyName2));
Yingdi Yu28fd32f2014-01-28 19:03:03 -080050 Name certName2 = cert2->getName();
Yingdi Yu2e57a582014-02-20 23:34:43 -080051 BOOST_REQUIRE_NO_THROW(keyChain.addCertificateAsKeyDefault(*cert2));
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070052
Yingdi Yu9a335352014-01-31 11:57:46 -080053 Name keyName3;
Yingdi Yuf56c68f2014-04-24 21:50:13 -070054 BOOST_REQUIRE_NO_THROW(keyName3 = keyChain.generateRsaKeyPairAsDefault(identity));
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070055
Yingdi Yu2e57a582014-02-20 23:34:43 -080056 shared_ptr<IdentityCertificate> cert3;
57 BOOST_REQUIRE_NO_THROW(cert3 = keyChain.selfSign(keyName3));
Yingdi Yu28fd32f2014-01-28 19:03:03 -080058 Name certName3 = cert3->getName();
Yingdi Yu2e57a582014-02-20 23:34:43 -080059 BOOST_REQUIRE_NO_THROW(keyChain.addCertificateAsKeyDefault(*cert3));
60 shared_ptr<IdentityCertificate> cert4;
61 BOOST_REQUIRE_NO_THROW(cert4 = keyChain.selfSign(keyName3));
Yingdi Yu28fd32f2014-01-28 19:03:03 -080062 Name certName4 = cert4->getName();
Yingdi Yu2e57a582014-02-20 23:34:43 -080063 BOOST_REQUIRE_NO_THROW(keyChain.addCertificateAsKeyDefault(*cert4));
64 shared_ptr<IdentityCertificate> cert5;
65 BOOST_REQUIRE_NO_THROW(cert5 = keyChain.selfSign(keyName3));
Yingdi Yu28fd32f2014-01-28 19:03:03 -080066 Name certName5 = cert5->getName();
Yingdi Yu2e57a582014-02-20 23:34:43 -080067 BOOST_REQUIRE_NO_THROW(keyChain.addCertificateAsKeyDefault(*cert5));
Yingdi Yu28fd32f2014-01-28 19:03:03 -080068
Alexander Afanasyev6835ad82014-02-12 10:07:20 -080069 BOOST_CHECK_EQUAL(keyChain.doesIdentityExist(identity), true);
70 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName1), true);
71 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName2), true);
72 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName3), true);
73 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName1), true);
74 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName2), true);
75 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName3), true);
76 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName4), true);
77 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName5), true);
Yingdi Yu28fd32f2014-01-28 19:03:03 -080078
Yingdi Yuf8fc8de2014-02-25 15:45:39 -080079 BOOST_REQUIRE_NO_THROW(keyChain.deleteCertificate(certName5));
Yingdi Yu28fd32f2014-01-28 19:03:03 -080080 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName5), false);
Alexander Afanasyev6835ad82014-02-12 10:07:20 -080081 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName3), true);
82 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName4), true);
Yingdi Yu28fd32f2014-01-28 19:03:03 -080083 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName3), true);
84
Yingdi Yuf8fc8de2014-02-25 15:45:39 -080085 BOOST_REQUIRE_NO_THROW(keyChain.deleteKey(keyName3));
Yingdi Yu28fd32f2014-01-28 19:03:03 -080086 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName4), false);
87 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName3), false);
88 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName3), false);
89 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName2), true);
90 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName1), true);
91 BOOST_CHECK_EQUAL(keyChain.doesIdentityExist(identity), true);
92
Yingdi Yuf8fc8de2014-02-25 15:45:39 -080093 BOOST_REQUIRE_NO_THROW(keyChain.deleteIdentity(identity));
Yingdi Yu28fd32f2014-01-28 19:03:03 -080094 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName2), false);
95 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName2), false);
96 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName1), false);
97 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName1), false);
98 BOOST_CHECK_EQUAL(keyChain.doesIdentityExist(identity), false);
99}
100
101BOOST_AUTO_TEST_SUITE_END()
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -0800102
103} // namespace ndn