blob: 52ae0eca2b7b8b0c7aec81bed38285bab1ee1296 [file] [log] [blame]
Yingdi Yu28fd32f2014-01-28 19:03:03 -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
Yingdi Yu28fd32f2014-01-28 19:03:03 -08007#include "security/key-chain.hpp"
Yingdi Yu9a335352014-01-31 11:57:46 -08008#include "util/time.hpp"
Yingdi Yu28fd32f2014-01-28 19:03:03 -08009
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070010#include "boost-test.hpp"
11
Yingdi Yu28fd32f2014-01-28 19:03:03 -080012using namespace std;
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -080013namespace ndn {
Yingdi Yu28fd32f2014-01-28 19:03:03 -080014
15BOOST_AUTO_TEST_SUITE(TestSecPublicInfoSqlite3)
16
17BOOST_AUTO_TEST_CASE (Delete)
18{
19 KeyChainImpl<SecPublicInfoSqlite3, SecTpmFile> keyChain;
20
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070021 Name identity("/TestSecPublicInfoSqlite3/Delete");
22 identity.appendVersion();
23
Alexander Afanasyevb46f9702014-02-06 18:58:55 -080024 Name certName1;
25 BOOST_REQUIRE_NO_THROW(certName1 = keyChain.createIdentity(identity));
Alexander Afanasyev6835ad82014-02-12 10:07:20 -080026
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070027 Name keyName1 = IdentityCertificate::certificateNameToPublicKeyName(certName1);
Yingdi Yu9a335352014-01-31 11:57:46 -080028 Name keyName2;
Yingdi Yu2e57a582014-02-20 23:34:43 -080029 BOOST_REQUIRE_NO_THROW(keyName2 = keyChain.generateRSAKeyPairAsDefault(identity));
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070030
Yingdi Yu2e57a582014-02-20 23:34:43 -080031 shared_ptr<IdentityCertificate> cert2;
32 BOOST_REQUIRE_NO_THROW(cert2 = keyChain.selfSign(keyName2));
Yingdi Yu28fd32f2014-01-28 19:03:03 -080033 Name certName2 = cert2->getName();
Yingdi Yu2e57a582014-02-20 23:34:43 -080034 BOOST_REQUIRE_NO_THROW(keyChain.addCertificateAsKeyDefault(*cert2));
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070035
Yingdi Yu9a335352014-01-31 11:57:46 -080036 Name keyName3;
Yingdi Yu2e57a582014-02-20 23:34:43 -080037 BOOST_REQUIRE_NO_THROW(keyName3 = keyChain.generateRSAKeyPairAsDefault(identity));
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070038
Yingdi Yu2e57a582014-02-20 23:34:43 -080039 shared_ptr<IdentityCertificate> cert3;
40 BOOST_REQUIRE_NO_THROW(cert3 = keyChain.selfSign(keyName3));
Yingdi Yu28fd32f2014-01-28 19:03:03 -080041 Name certName3 = cert3->getName();
Yingdi Yu2e57a582014-02-20 23:34:43 -080042 BOOST_REQUIRE_NO_THROW(keyChain.addCertificateAsKeyDefault(*cert3));
43 shared_ptr<IdentityCertificate> cert4;
44 BOOST_REQUIRE_NO_THROW(cert4 = keyChain.selfSign(keyName3));
Yingdi Yu28fd32f2014-01-28 19:03:03 -080045 Name certName4 = cert4->getName();
Yingdi Yu2e57a582014-02-20 23:34:43 -080046 BOOST_REQUIRE_NO_THROW(keyChain.addCertificateAsKeyDefault(*cert4));
47 shared_ptr<IdentityCertificate> cert5;
48 BOOST_REQUIRE_NO_THROW(cert5 = keyChain.selfSign(keyName3));
Yingdi Yu28fd32f2014-01-28 19:03:03 -080049 Name certName5 = cert5->getName();
Yingdi Yu2e57a582014-02-20 23:34:43 -080050 BOOST_REQUIRE_NO_THROW(keyChain.addCertificateAsKeyDefault(*cert5));
Yingdi Yu28fd32f2014-01-28 19:03:03 -080051
Alexander Afanasyev6835ad82014-02-12 10:07:20 -080052 BOOST_CHECK_EQUAL(keyChain.doesIdentityExist(identity), true);
53 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName1), true);
54 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName2), true);
55 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName3), true);
56 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName1), true);
57 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName2), true);
58 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName3), true);
59 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName4), true);
60 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName5), true);
Yingdi Yu28fd32f2014-01-28 19:03:03 -080061
Yingdi Yuf8fc8de2014-02-25 15:45:39 -080062 BOOST_REQUIRE_NO_THROW(keyChain.deleteCertificate(certName5));
Yingdi Yu28fd32f2014-01-28 19:03:03 -080063 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName5), false);
Alexander Afanasyev6835ad82014-02-12 10:07:20 -080064 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName3), true);
65 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName4), true);
Yingdi Yu28fd32f2014-01-28 19:03:03 -080066 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName3), true);
67
Yingdi Yuf8fc8de2014-02-25 15:45:39 -080068 BOOST_REQUIRE_NO_THROW(keyChain.deleteKey(keyName3));
Yingdi Yu28fd32f2014-01-28 19:03:03 -080069 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName4), false);
70 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName3), false);
71 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName3), false);
72 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName2), true);
73 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName1), true);
74 BOOST_CHECK_EQUAL(keyChain.doesIdentityExist(identity), true);
75
Yingdi Yuf8fc8de2014-02-25 15:45:39 -080076 BOOST_REQUIRE_NO_THROW(keyChain.deleteIdentity(identity));
Yingdi Yu28fd32f2014-01-28 19:03:03 -080077 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName2), false);
78 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName2), false);
79 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName1), false);
80 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName1), false);
81 BOOST_CHECK_EQUAL(keyChain.doesIdentityExist(identity), false);
82}
83
84BOOST_AUTO_TEST_SUITE_END()
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -080085
86} // namespace ndn