blob: ae7135bb9099cb7c48f9ded041ab5f42e3993038 [file] [log] [blame]
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Yingdi Yu28fd32f2014-01-28 19:03:03 -08002/**
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07003 * 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 Yu28fd32f2014-01-28 19:03:03 -080011 */
12
Yingdi Yu28fd32f2014-01-28 19:03:03 -080013#include "security/key-chain.hpp"
Yingdi Yu9a335352014-01-31 11:57:46 -080014#include "util/time.hpp"
Yingdi Yu28fd32f2014-01-28 19:03:03 -080015
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070016#include "boost-test.hpp"
17
Yingdi Yu28fd32f2014-01-28 19:03:03 -080018using namespace std;
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -080019namespace ndn {
Yingdi Yu28fd32f2014-01-28 19:03:03 -080020
Alexander Afanasyevd1b5c412014-03-27 15:03:51 -070021BOOST_AUTO_TEST_SUITE(SecurityTestSecPublicInfoSqlite3)
Yingdi Yu28fd32f2014-01-28 19:03:03 -080022
23BOOST_AUTO_TEST_CASE (Delete)
24{
25 KeyChainImpl<SecPublicInfoSqlite3, SecTpmFile> keyChain;
26
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070027 Name identity("/TestSecPublicInfoSqlite3/Delete");
28 identity.appendVersion();
29
Alexander Afanasyevb46f9702014-02-06 18:58:55 -080030 Name certName1;
31 BOOST_REQUIRE_NO_THROW(certName1 = keyChain.createIdentity(identity));
Alexander Afanasyev6835ad82014-02-12 10:07:20 -080032
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070033 Name keyName1 = IdentityCertificate::certificateNameToPublicKeyName(certName1);
Yingdi Yu9a335352014-01-31 11:57:46 -080034 Name keyName2;
Yingdi Yu2e57a582014-02-20 23:34:43 -080035 BOOST_REQUIRE_NO_THROW(keyName2 = keyChain.generateRSAKeyPairAsDefault(identity));
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070036
Yingdi Yu2e57a582014-02-20 23:34:43 -080037 shared_ptr<IdentityCertificate> cert2;
38 BOOST_REQUIRE_NO_THROW(cert2 = keyChain.selfSign(keyName2));
Yingdi Yu28fd32f2014-01-28 19:03:03 -080039 Name certName2 = cert2->getName();
Yingdi Yu2e57a582014-02-20 23:34:43 -080040 BOOST_REQUIRE_NO_THROW(keyChain.addCertificateAsKeyDefault(*cert2));
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070041
Yingdi Yu9a335352014-01-31 11:57:46 -080042 Name keyName3;
Yingdi Yu2e57a582014-02-20 23:34:43 -080043 BOOST_REQUIRE_NO_THROW(keyName3 = keyChain.generateRSAKeyPairAsDefault(identity));
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070044
Yingdi Yu2e57a582014-02-20 23:34:43 -080045 shared_ptr<IdentityCertificate> cert3;
46 BOOST_REQUIRE_NO_THROW(cert3 = keyChain.selfSign(keyName3));
Yingdi Yu28fd32f2014-01-28 19:03:03 -080047 Name certName3 = cert3->getName();
Yingdi Yu2e57a582014-02-20 23:34:43 -080048 BOOST_REQUIRE_NO_THROW(keyChain.addCertificateAsKeyDefault(*cert3));
49 shared_ptr<IdentityCertificate> cert4;
50 BOOST_REQUIRE_NO_THROW(cert4 = keyChain.selfSign(keyName3));
Yingdi Yu28fd32f2014-01-28 19:03:03 -080051 Name certName4 = cert4->getName();
Yingdi Yu2e57a582014-02-20 23:34:43 -080052 BOOST_REQUIRE_NO_THROW(keyChain.addCertificateAsKeyDefault(*cert4));
53 shared_ptr<IdentityCertificate> cert5;
54 BOOST_REQUIRE_NO_THROW(cert5 = keyChain.selfSign(keyName3));
Yingdi Yu28fd32f2014-01-28 19:03:03 -080055 Name certName5 = cert5->getName();
Yingdi Yu2e57a582014-02-20 23:34:43 -080056 BOOST_REQUIRE_NO_THROW(keyChain.addCertificateAsKeyDefault(*cert5));
Yingdi Yu28fd32f2014-01-28 19:03:03 -080057
Alexander Afanasyev6835ad82014-02-12 10:07:20 -080058 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 Yu28fd32f2014-01-28 19:03:03 -080067
Yingdi Yuf8fc8de2014-02-25 15:45:39 -080068 BOOST_REQUIRE_NO_THROW(keyChain.deleteCertificate(certName5));
Yingdi Yu28fd32f2014-01-28 19:03:03 -080069 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName5), false);
Alexander Afanasyev6835ad82014-02-12 10:07:20 -080070 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName3), true);
71 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName4), true);
Yingdi Yu28fd32f2014-01-28 19:03:03 -080072 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName3), true);
73
Yingdi Yuf8fc8de2014-02-25 15:45:39 -080074 BOOST_REQUIRE_NO_THROW(keyChain.deleteKey(keyName3));
Yingdi Yu28fd32f2014-01-28 19:03:03 -080075 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 Yuf8fc8de2014-02-25 15:45:39 -080082 BOOST_REQUIRE_NO_THROW(keyChain.deleteIdentity(identity));
Yingdi Yu28fd32f2014-01-28 19:03:03 -080083 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
90BOOST_AUTO_TEST_SUITE_END()
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -080091
92} // namespace ndn