blob: fbe7d7e22ca34889897418bf4f52d494835df92f [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Jeff Thompson7ca11f22013-10-04 19:01:30 -07002/**
Alexander Afanasyev2fa59392016-07-29 17:24:23 -07003 * Copyright (c) 2013-2016 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.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -070020 *
21 * @author Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/>
22 * @author Jeff Thompson <jefft0@remap.ucla.edu>
Jeff Thompson7ca11f22013-10-04 19:01:30 -070023 */
24
Yingdi Yufc40d872014-02-18 12:56:04 -080025#ifndef NDN_SECURITY_SEC_PUBLIC_INFO_SQLITE3_HPP
26#define NDN_SECURITY_SEC_PUBLIC_INFO_SQLITE3_HPP
Jeff Thompson7ca11f22013-10-04 19:01:30 -070027
Yingdi Yu4f324632014-01-15 18:10:03 -080028#include "../common.hpp"
Yingdi Yu87581582014-01-14 14:28:39 -080029#include "sec-public-info.hpp"
Jeff Thompson7ca11f22013-10-04 19:01:30 -070030
Yingdi Yu874678f2014-01-22 19:30:34 -080031struct sqlite3;
32
Yingdi Yufc40d872014-02-18 12:56:04 -080033namespace ndn {
Alexander Afanasyev2fa59392016-07-29 17:24:23 -070034namespace security {
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070035
Alexander Afanasyev2a7f7202014-04-23 14:25:29 -070036class SecPublicInfoSqlite3 : public SecPublicInfo
37{
Jeff Thompson7ca11f22013-10-04 19:01:30 -070038public:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070039 class Error : public SecPublicInfo::Error
40 {
41 public:
42 explicit
43 Error(const std::string& what)
44 : SecPublicInfo::Error(what)
45 {
46 }
47 };
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -080048
Yingdi Yu41546342014-11-30 23:37:53 -080049 explicit
50 SecPublicInfoSqlite3(const std::string& dir = "");
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070051
52 virtual
Yingdi Yu87581582014-01-14 14:28:39 -080053 ~SecPublicInfoSqlite3();
Jeff Thompson7ca11f22013-10-04 19:01:30 -070054
Yingdi Yu2e57a582014-02-20 23:34:43 -080055 /**********************
56 * from SecPublicInfo *
57 **********************/
Yingdi Yu41546342014-11-30 23:37:53 -080058
59 virtual void
60 setTpmLocator(const std::string& tpmLocator);
61
62 virtual std::string
63 getTpmLocator();
64
65 virtual std::string
66 getPibLocator();
67
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070068 virtual bool
Jeff Thompson7ca11f22013-10-04 19:01:30 -070069 doesIdentityExist(const Name& identityName);
70
Jeff Thompson7ca11f22013-10-04 19:01:30 -070071 virtual void
72 addIdentity(const Name& identityName);
73
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070074 virtual bool
Jeff Thompson7ca11f22013-10-04 19:01:30 -070075 revokeIdentity();
76
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070077 virtual bool
Yingdi Yu87581582014-01-14 14:28:39 -080078 doesPublicKeyExist(const Name& keyName);
Jeff Thompson7ca11f22013-10-04 19:01:30 -070079
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070080 virtual void
Alexander Afanasyev2fa59392016-07-29 17:24:23 -070081 addKey(const Name& keyName, const v1::PublicKey& publicKeyDer);
Jeff Thompson7ca11f22013-10-04 19:01:30 -070082
Alexander Afanasyev2fa59392016-07-29 17:24:23 -070083 virtual shared_ptr<v1::PublicKey>
Yingdi Yu87581582014-01-14 14:28:39 -080084 getPublicKey(const Name& keyName);
Jeff Thompson7ca11f22013-10-04 19:01:30 -070085
Yingdi Yu40b53092014-06-17 17:10:02 -070086 virtual KeyType
87 getPublicKeyType(const Name& keyName);
88
Jeff Thompson7ca11f22013-10-04 19:01:30 -070089 virtual bool
90 doesCertificateExist(const Name& certificateName);
91
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070092 virtual void
Alexander Afanasyev2fa59392016-07-29 17:24:23 -070093 addCertificate(const v1::IdentityCertificate& certificate);
Jeff Thompson7ca11f22013-10-04 19:01:30 -070094
Alexander Afanasyev2fa59392016-07-29 17:24:23 -070095 virtual shared_ptr<v1::IdentityCertificate>
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070096 getCertificate(const Name& certificateName);
Jeff Thompson7ca11f22013-10-04 19:01:30 -070097
98
Jeff Thompson7ca11f22013-10-04 19:01:30 -070099
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700100 virtual Name
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700101 getDefaultIdentity();
102
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700103 virtual Name
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700104 getDefaultKeyNameForIdentity(const Name& identityName);
105
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700106 virtual Name
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700107 getDefaultCertificateNameForKey(const Name& keyName);
108
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800109 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700110 getAllIdentities(std::vector<Name>& nameList, bool isDefault);
Alexander Afanasyev0c632112013-12-30 15:59:31 -0800111
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800112 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700113 getAllKeyNames(std::vector<Name>& nameList, bool isDefault);
Alexander Afanasyev0c632112013-12-30 15:59:31 -0800114
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800115 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700116 getAllKeyNamesOfIdentity(const Name& identity, std::vector<Name>& nameList, bool isDefault);
Alexander Afanasyev0c632112013-12-30 15:59:31 -0800117
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800118 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700119 getAllCertificateNames(std::vector<Name>& nameList, bool isDefault);
120
121 virtual void
122 getAllCertificateNamesOfKey(const Name& keyName, std::vector<Name>& nameList, bool isDefault);
123
Yingdi Yuf56c68f2014-04-24 21:50:13 -0700124 virtual void
125 deleteCertificateInfo(const Name& certificateName);
126
127 virtual void
128 deletePublicKeyInfo(const Name& keyName);
129
130 virtual void
131 deleteIdentityInfo(const Name& identity);
132
Yingdi Yu41546342014-11-30 23:37:53 -0800133private:
134 bool
135 initializeTable(const std::string& tableName, const std::string& initCommand);
136
137 void
138 deleteTable(const std::string& tableName);
139
140 void
141 setTpmLocatorInternal(const std::string& tpmLocator, bool needReset);
142
143 void
Yingdi Yu87581582014-01-14 14:28:39 -0800144 setDefaultIdentityInternal(const Name& identityName);
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700145
Yingdi Yu41546342014-11-30 23:37:53 -0800146 void
Yingdi Yu87581582014-01-14 14:28:39 -0800147 setDefaultKeyNameForIdentityInternal(const Name& keyName);
148
Yingdi Yu41546342014-11-30 23:37:53 -0800149 void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700150 setDefaultCertificateNameForKeyInternal(const Name& certificateName);
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800151
Yingdi Yu41546342014-11-30 23:37:53 -0800152 std::string
153 getScheme();
154
155NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
156 bool
157 doesTableExist(const std::string& tableName);
158
159public:
160 static const std::string SCHEME;
161
Yingdi Yu87581582014-01-14 14:28:39 -0800162private:
Junxiao Shi98acbb02014-12-02 11:00:42 -0700163 sqlite3* m_database;
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700164};
165
Alexander Afanasyev2fa59392016-07-29 17:24:23 -0700166} // namespace security
167
168using security::SecPublicInfoSqlite3;
169
Yingdi Yufc40d872014-02-18 12:56:04 -0800170} // namespace ndn
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700171
Junxiao Shi98acbb02014-12-02 11:00:42 -0700172#endif // NDN_SECURITY_SEC_PUBLIC_INFO_SQLITE3_HPP