blob: 6e9dfd7c7873d95b666e08d29332dc5495f6f87a [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 Afanasyev4c9a3d52017-01-03 17:45:19 -08003 * Copyright (c) 2013-2017 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
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -080025#ifndef NDN_SECURITY_V1_SEC_PUBLIC_INFO_SQLITE3_HPP
26#define NDN_SECURITY_V1_SEC_PUBLIC_INFO_SQLITE3_HPP
Jeff Thompson7ca11f22013-10-04 19:01:30 -070027
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -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 Afanasyev4c9a3d52017-01-03 17:45:19 -080035namespace v1 {
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070036
Alexander Afanasyev2a7f7202014-04-23 14:25:29 -070037class SecPublicInfoSqlite3 : public SecPublicInfo
38{
Jeff Thompson7ca11f22013-10-04 19:01:30 -070039public:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070040 class Error : public SecPublicInfo::Error
41 {
42 public:
43 explicit
44 Error(const std::string& what)
45 : SecPublicInfo::Error(what)
46 {
47 }
48 };
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -080049
Yingdi Yu41546342014-11-30 23:37:53 -080050 explicit
51 SecPublicInfoSqlite3(const std::string& dir = "");
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070052
53 virtual
Yingdi Yu87581582014-01-14 14:28:39 -080054 ~SecPublicInfoSqlite3();
Jeff Thompson7ca11f22013-10-04 19:01:30 -070055
Yingdi Yu2e57a582014-02-20 23:34:43 -080056 /**********************
57 * from SecPublicInfo *
58 **********************/
Yingdi Yu41546342014-11-30 23:37:53 -080059
60 virtual void
61 setTpmLocator(const std::string& tpmLocator);
62
63 virtual std::string
64 getTpmLocator();
65
66 virtual std::string
67 getPibLocator();
68
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070069 virtual bool
Jeff Thompson7ca11f22013-10-04 19:01:30 -070070 doesIdentityExist(const Name& identityName);
71
Jeff Thompson7ca11f22013-10-04 19:01:30 -070072 virtual void
73 addIdentity(const Name& identityName);
74
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070075 virtual bool
Jeff Thompson7ca11f22013-10-04 19:01:30 -070076 revokeIdentity();
77
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070078 virtual bool
Yingdi Yu87581582014-01-14 14:28:39 -080079 doesPublicKeyExist(const Name& keyName);
Jeff Thompson7ca11f22013-10-04 19:01:30 -070080
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070081 virtual void
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -080082 addKey(const Name& keyName, const PublicKey& publicKeyDer);
Jeff Thompson7ca11f22013-10-04 19:01:30 -070083
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -080084 virtual shared_ptr<PublicKey>
Yingdi Yu87581582014-01-14 14:28:39 -080085 getPublicKey(const Name& keyName);
Jeff Thompson7ca11f22013-10-04 19:01:30 -070086
Yingdi Yu40b53092014-06-17 17:10:02 -070087 virtual KeyType
88 getPublicKeyType(const Name& keyName);
89
Jeff Thompson7ca11f22013-10-04 19:01:30 -070090 virtual bool
91 doesCertificateExist(const Name& certificateName);
92
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070093 virtual void
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -080094 addCertificate(const IdentityCertificate& certificate);
Jeff Thompson7ca11f22013-10-04 19:01:30 -070095
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -080096 virtual shared_ptr<IdentityCertificate>
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070097 getCertificate(const Name& certificateName);
Jeff Thompson7ca11f22013-10-04 19:01:30 -070098
99
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700100
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700101 virtual Name
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700102 getDefaultIdentity();
103
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700104 virtual Name
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700105 getDefaultKeyNameForIdentity(const Name& identityName);
106
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700107 virtual Name
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700108 getDefaultCertificateNameForKey(const Name& keyName);
109
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800110 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700111 getAllIdentities(std::vector<Name>& nameList, bool isDefault);
Alexander Afanasyev0c632112013-12-30 15:59:31 -0800112
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800113 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700114 getAllKeyNames(std::vector<Name>& nameList, bool isDefault);
Alexander Afanasyev0c632112013-12-30 15:59:31 -0800115
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800116 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700117 getAllKeyNamesOfIdentity(const Name& identity, std::vector<Name>& nameList, bool isDefault);
Alexander Afanasyev0c632112013-12-30 15:59:31 -0800118
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800119 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700120 getAllCertificateNames(std::vector<Name>& nameList, bool isDefault);
121
122 virtual void
123 getAllCertificateNamesOfKey(const Name& keyName, std::vector<Name>& nameList, bool isDefault);
124
Yingdi Yuf56c68f2014-04-24 21:50:13 -0700125 virtual void
126 deleteCertificateInfo(const Name& certificateName);
127
128 virtual void
129 deletePublicKeyInfo(const Name& keyName);
130
131 virtual void
132 deleteIdentityInfo(const Name& identity);
133
Yingdi Yu41546342014-11-30 23:37:53 -0800134private:
135 bool
136 initializeTable(const std::string& tableName, const std::string& initCommand);
137
138 void
139 deleteTable(const std::string& tableName);
140
141 void
142 setTpmLocatorInternal(const std::string& tpmLocator, bool needReset);
143
144 void
Yingdi Yu87581582014-01-14 14:28:39 -0800145 setDefaultIdentityInternal(const Name& identityName);
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700146
Yingdi Yu41546342014-11-30 23:37:53 -0800147 void
Yingdi Yu87581582014-01-14 14:28:39 -0800148 setDefaultKeyNameForIdentityInternal(const Name& keyName);
149
Yingdi Yu41546342014-11-30 23:37:53 -0800150 void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700151 setDefaultCertificateNameForKeyInternal(const Name& certificateName);
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800152
Yingdi Yu41546342014-11-30 23:37:53 -0800153 std::string
154 getScheme();
155
156NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
157 bool
158 doesTableExist(const std::string& tableName);
159
160public:
161 static const std::string SCHEME;
162
Yingdi Yu87581582014-01-14 14:28:39 -0800163private:
Junxiao Shi98acbb02014-12-02 11:00:42 -0700164 sqlite3* m_database;
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700165};
166
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -0800167} // namespace v1
Alexander Afanasyev2fa59392016-07-29 17:24:23 -0700168} // namespace security
Yingdi Yufc40d872014-02-18 12:56:04 -0800169} // namespace ndn
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700170
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -0800171#endif // NDN_SECURITY_V1_SEC_PUBLIC_INFO_SQLITE3_HPP