Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame^] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 2 | /** |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame^] | 3 | * Copyright (c) 2013-2014 Regents of the University of California. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 6 | * |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame^] | 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. |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 20 | */ |
| 21 | |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 22 | #include "security/sec-public-info-sqlite3.hpp" |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 23 | #include "security/key-chain.hpp" |
Yingdi Yu | 9a33535 | 2014-01-31 11:57:46 -0800 | [diff] [blame] | 24 | #include "util/time.hpp" |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 25 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 26 | #include "boost-test.hpp" |
| 27 | |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 28 | using namespace std; |
Alexander Afanasyev | 0abb2da | 2014-01-30 18:07:57 -0800 | [diff] [blame] | 29 | namespace ndn { |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 30 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 31 | BOOST_AUTO_TEST_SUITE(SecurityTestSecPublicInfoSqlite3) |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 32 | |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 33 | BOOST_AUTO_TEST_CASE(Delete) |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 34 | { |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 35 | BOOST_REQUIRE_NO_THROW(KeyChain("sqlite3", "file")); |
| 36 | KeyChain keyChain("sqlite3", "file"); |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 37 | |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 38 | Name identity("/TestSecPublicInfoSqlite3/Delete"); |
| 39 | identity.appendVersion(); |
| 40 | |
Alexander Afanasyev | b46f970 | 2014-02-06 18:58:55 -0800 | [diff] [blame] | 41 | Name certName1; |
| 42 | BOOST_REQUIRE_NO_THROW(certName1 = keyChain.createIdentity(identity)); |
Alexander Afanasyev | 6835ad8 | 2014-02-12 10:07:20 -0800 | [diff] [blame] | 43 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 44 | Name keyName1 = IdentityCertificate::certificateNameToPublicKeyName(certName1); |
Yingdi Yu | 9a33535 | 2014-01-31 11:57:46 -0800 | [diff] [blame] | 45 | Name keyName2; |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 46 | BOOST_REQUIRE_NO_THROW(keyName2 = keyChain.generateRsaKeyPairAsDefault(identity)); |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 47 | |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 48 | shared_ptr<IdentityCertificate> cert2; |
| 49 | BOOST_REQUIRE_NO_THROW(cert2 = keyChain.selfSign(keyName2)); |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 50 | Name certName2 = cert2->getName(); |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 51 | BOOST_REQUIRE_NO_THROW(keyChain.addCertificateAsKeyDefault(*cert2)); |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 52 | |
Yingdi Yu | 9a33535 | 2014-01-31 11:57:46 -0800 | [diff] [blame] | 53 | Name keyName3; |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 54 | BOOST_REQUIRE_NO_THROW(keyName3 = keyChain.generateRsaKeyPairAsDefault(identity)); |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 55 | |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 56 | shared_ptr<IdentityCertificate> cert3; |
| 57 | BOOST_REQUIRE_NO_THROW(cert3 = keyChain.selfSign(keyName3)); |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 58 | Name certName3 = cert3->getName(); |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 59 | BOOST_REQUIRE_NO_THROW(keyChain.addCertificateAsKeyDefault(*cert3)); |
| 60 | shared_ptr<IdentityCertificate> cert4; |
| 61 | BOOST_REQUIRE_NO_THROW(cert4 = keyChain.selfSign(keyName3)); |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 62 | Name certName4 = cert4->getName(); |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 63 | BOOST_REQUIRE_NO_THROW(keyChain.addCertificateAsKeyDefault(*cert4)); |
| 64 | shared_ptr<IdentityCertificate> cert5; |
| 65 | BOOST_REQUIRE_NO_THROW(cert5 = keyChain.selfSign(keyName3)); |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 66 | Name certName5 = cert5->getName(); |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 67 | BOOST_REQUIRE_NO_THROW(keyChain.addCertificateAsKeyDefault(*cert5)); |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 68 | |
Alexander Afanasyev | 6835ad8 | 2014-02-12 10:07:20 -0800 | [diff] [blame] | 69 | 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 Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 78 | |
Yingdi Yu | f8fc8de | 2014-02-25 15:45:39 -0800 | [diff] [blame] | 79 | BOOST_REQUIRE_NO_THROW(keyChain.deleteCertificate(certName5)); |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 80 | BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName5), false); |
Alexander Afanasyev | 6835ad8 | 2014-02-12 10:07:20 -0800 | [diff] [blame] | 81 | BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName3), true); |
| 82 | BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName4), true); |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 83 | BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName3), true); |
| 84 | |
Yingdi Yu | f8fc8de | 2014-02-25 15:45:39 -0800 | [diff] [blame] | 85 | BOOST_REQUIRE_NO_THROW(keyChain.deleteKey(keyName3)); |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 86 | 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 Yu | f8fc8de | 2014-02-25 15:45:39 -0800 | [diff] [blame] | 93 | BOOST_REQUIRE_NO_THROW(keyChain.deleteIdentity(identity)); |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 94 | 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 | |
| 101 | BOOST_AUTO_TEST_SUITE_END() |
Alexander Afanasyev | 0abb2da | 2014-01-30 18:07:57 -0800 | [diff] [blame] | 102 | |
| 103 | } // namespace ndn |