Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [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 | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame^] | 3 | * Copyright (c) 2013-2014, Regents of the University of California. |
| 4 | * All rights reserved. |
| 5 | * |
| 6 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 7 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 8 | * |
| 9 | * This file licensed under New BSD License. See COPYING for detailed information about |
| 10 | * ndn-cxx library copyright, permissions, and redistribution restrictions. |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 11 | */ |
| 12 | |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 13 | #include "security/key-chain.hpp" |
Yingdi Yu | 9a33535 | 2014-01-31 11:57:46 -0800 | [diff] [blame] | 14 | #include "util/time.hpp" |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 15 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 16 | #include "boost-test.hpp" |
| 17 | |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 18 | using namespace std; |
Alexander Afanasyev | 0abb2da | 2014-01-30 18:07:57 -0800 | [diff] [blame] | 19 | namespace ndn { |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 20 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 21 | BOOST_AUTO_TEST_SUITE(SecurityTestSecPublicInfoSqlite3) |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 22 | |
| 23 | BOOST_AUTO_TEST_CASE (Delete) |
| 24 | { |
| 25 | KeyChainImpl<SecPublicInfoSqlite3, SecTpmFile> keyChain; |
| 26 | |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 27 | Name identity("/TestSecPublicInfoSqlite3/Delete"); |
| 28 | identity.appendVersion(); |
| 29 | |
Alexander Afanasyev | b46f970 | 2014-02-06 18:58:55 -0800 | [diff] [blame] | 30 | Name certName1; |
| 31 | BOOST_REQUIRE_NO_THROW(certName1 = keyChain.createIdentity(identity)); |
Alexander Afanasyev | 6835ad8 | 2014-02-12 10:07:20 -0800 | [diff] [blame] | 32 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 33 | Name keyName1 = IdentityCertificate::certificateNameToPublicKeyName(certName1); |
Yingdi Yu | 9a33535 | 2014-01-31 11:57:46 -0800 | [diff] [blame] | 34 | Name keyName2; |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 35 | BOOST_REQUIRE_NO_THROW(keyName2 = keyChain.generateRSAKeyPairAsDefault(identity)); |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 36 | |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 37 | shared_ptr<IdentityCertificate> cert2; |
| 38 | BOOST_REQUIRE_NO_THROW(cert2 = keyChain.selfSign(keyName2)); |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 39 | Name certName2 = cert2->getName(); |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 40 | BOOST_REQUIRE_NO_THROW(keyChain.addCertificateAsKeyDefault(*cert2)); |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 41 | |
Yingdi Yu | 9a33535 | 2014-01-31 11:57:46 -0800 | [diff] [blame] | 42 | Name keyName3; |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 43 | BOOST_REQUIRE_NO_THROW(keyName3 = keyChain.generateRSAKeyPairAsDefault(identity)); |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 44 | |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 45 | shared_ptr<IdentityCertificate> cert3; |
| 46 | BOOST_REQUIRE_NO_THROW(cert3 = keyChain.selfSign(keyName3)); |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 47 | Name certName3 = cert3->getName(); |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 48 | BOOST_REQUIRE_NO_THROW(keyChain.addCertificateAsKeyDefault(*cert3)); |
| 49 | shared_ptr<IdentityCertificate> cert4; |
| 50 | BOOST_REQUIRE_NO_THROW(cert4 = keyChain.selfSign(keyName3)); |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 51 | Name certName4 = cert4->getName(); |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 52 | BOOST_REQUIRE_NO_THROW(keyChain.addCertificateAsKeyDefault(*cert4)); |
| 53 | shared_ptr<IdentityCertificate> cert5; |
| 54 | BOOST_REQUIRE_NO_THROW(cert5 = keyChain.selfSign(keyName3)); |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 55 | Name certName5 = cert5->getName(); |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 56 | BOOST_REQUIRE_NO_THROW(keyChain.addCertificateAsKeyDefault(*cert5)); |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 57 | |
Alexander Afanasyev | 6835ad8 | 2014-02-12 10:07:20 -0800 | [diff] [blame] | 58 | BOOST_CHECK_EQUAL(keyChain.doesIdentityExist(identity), true); |
| 59 | BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName1), true); |
| 60 | BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName2), true); |
| 61 | BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName3), true); |
| 62 | BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName1), true); |
| 63 | BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName2), true); |
| 64 | BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName3), true); |
| 65 | BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName4), true); |
| 66 | BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName5), true); |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 67 | |
Yingdi Yu | f8fc8de | 2014-02-25 15:45:39 -0800 | [diff] [blame] | 68 | BOOST_REQUIRE_NO_THROW(keyChain.deleteCertificate(certName5)); |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 69 | BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName5), false); |
Alexander Afanasyev | 6835ad8 | 2014-02-12 10:07:20 -0800 | [diff] [blame] | 70 | BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName3), true); |
| 71 | BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName4), true); |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 72 | BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName3), true); |
| 73 | |
Yingdi Yu | f8fc8de | 2014-02-25 15:45:39 -0800 | [diff] [blame] | 74 | BOOST_REQUIRE_NO_THROW(keyChain.deleteKey(keyName3)); |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 75 | BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName4), false); |
| 76 | BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName3), false); |
| 77 | BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName3), false); |
| 78 | BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName2), true); |
| 79 | BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName1), true); |
| 80 | BOOST_CHECK_EQUAL(keyChain.doesIdentityExist(identity), true); |
| 81 | |
Yingdi Yu | f8fc8de | 2014-02-25 15:45:39 -0800 | [diff] [blame] | 82 | BOOST_REQUIRE_NO_THROW(keyChain.deleteIdentity(identity)); |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 83 | BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName2), false); |
| 84 | BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName2), false); |
| 85 | BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName1), false); |
| 86 | BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName1), false); |
| 87 | BOOST_CHECK_EQUAL(keyChain.doesIdentityExist(identity), false); |
| 88 | } |
| 89 | |
| 90 | BOOST_AUTO_TEST_SUITE_END() |
Alexander Afanasyev | 0abb2da | 2014-01-30 18:07:57 -0800 | [diff] [blame] | 91 | |
| 92 | } // namespace ndn |