blob: 697ff12caa337a314dd8e6397806869879174aec [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 Afanasyevaf99f462015-01-19 21:43:09 -08003 * Copyright (c) 2013-2015 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 Afanasyevfdbfc6d2014-04-14 15:12:11 -070034
Alexander Afanasyev2a7f7202014-04-23 14:25:29 -070035class SecPublicInfoSqlite3 : public SecPublicInfo
36{
Jeff Thompson7ca11f22013-10-04 19:01:30 -070037public:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070038 class Error : public SecPublicInfo::Error
39 {
40 public:
41 explicit
42 Error(const std::string& what)
43 : SecPublicInfo::Error(what)
44 {
45 }
46 };
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -080047
Yingdi Yu41546342014-11-30 23:37:53 -080048 explicit
49 SecPublicInfoSqlite3(const std::string& dir = "");
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070050
51 virtual
Yingdi Yu87581582014-01-14 14:28:39 -080052 ~SecPublicInfoSqlite3();
Jeff Thompson7ca11f22013-10-04 19:01:30 -070053
Yingdi Yu2e57a582014-02-20 23:34:43 -080054 /**********************
55 * from SecPublicInfo *
56 **********************/
Yingdi Yu41546342014-11-30 23:37:53 -080057
58 virtual void
59 setTpmLocator(const std::string& tpmLocator);
60
61 virtual std::string
62 getTpmLocator();
63
64 virtual std::string
65 getPibLocator();
66
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070067 virtual bool
Jeff Thompson7ca11f22013-10-04 19:01:30 -070068 doesIdentityExist(const Name& identityName);
69
Jeff Thompson7ca11f22013-10-04 19:01:30 -070070 virtual void
71 addIdentity(const Name& identityName);
72
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070073 virtual bool
Jeff Thompson7ca11f22013-10-04 19:01:30 -070074 revokeIdentity();
75
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070076 virtual bool
Yingdi Yu87581582014-01-14 14:28:39 -080077 doesPublicKeyExist(const Name& keyName);
Jeff Thompson7ca11f22013-10-04 19:01:30 -070078
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070079 virtual void
Yingdi Yu40b53092014-06-17 17:10:02 -070080 addKey(const Name& keyName, const PublicKey& publicKeyDer);
Jeff Thompson7ca11f22013-10-04 19:01:30 -070081
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070082 virtual shared_ptr<PublicKey>
Yingdi Yu87581582014-01-14 14:28:39 -080083 getPublicKey(const Name& keyName);
Jeff Thompson7ca11f22013-10-04 19:01:30 -070084
Yingdi Yu40b53092014-06-17 17:10:02 -070085 virtual KeyType
86 getPublicKeyType(const Name& keyName);
87
Jeff Thompson7ca11f22013-10-04 19:01:30 -070088 virtual bool
89 doesCertificateExist(const Name& certificateName);
90
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070091 virtual void
Jeff Thompsonc69163b2013-10-12 13:49:50 -070092 addCertificate(const IdentityCertificate& certificate);
Jeff Thompson7ca11f22013-10-04 19:01:30 -070093
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070094 virtual shared_ptr<IdentityCertificate>
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070095 getCertificate(const Name& certificateName);
Jeff Thompson7ca11f22013-10-04 19:01:30 -070096
97
Jeff Thompson7ca11f22013-10-04 19:01:30 -070098
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070099 virtual Name
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700100 getDefaultIdentity();
101
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700102 virtual Name
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700103 getDefaultKeyNameForIdentity(const Name& identityName);
104
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700105 virtual Name
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700106 getDefaultCertificateNameForKey(const Name& keyName);
107
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800108 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700109 getAllIdentities(std::vector<Name>& nameList, bool isDefault);
Alexander Afanasyev0c632112013-12-30 15:59:31 -0800110
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800111 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700112 getAllKeyNames(std::vector<Name>& nameList, bool isDefault);
Alexander Afanasyev0c632112013-12-30 15:59:31 -0800113
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800114 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700115 getAllKeyNamesOfIdentity(const Name& identity, std::vector<Name>& nameList, bool isDefault);
Alexander Afanasyev0c632112013-12-30 15:59:31 -0800116
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800117 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700118 getAllCertificateNames(std::vector<Name>& nameList, bool isDefault);
119
120 virtual void
121 getAllCertificateNamesOfKey(const Name& keyName, std::vector<Name>& nameList, bool isDefault);
122
Yingdi Yuf56c68f2014-04-24 21:50:13 -0700123 virtual void
124 deleteCertificateInfo(const Name& certificateName);
125
126 virtual void
127 deletePublicKeyInfo(const Name& keyName);
128
129 virtual void
130 deleteIdentityInfo(const Name& identity);
131
Yingdi Yu41546342014-11-30 23:37:53 -0800132private:
133 bool
134 initializeTable(const std::string& tableName, const std::string& initCommand);
135
136 void
137 deleteTable(const std::string& tableName);
138
139 void
140 setTpmLocatorInternal(const std::string& tpmLocator, bool needReset);
141
142 void
Yingdi Yu87581582014-01-14 14:28:39 -0800143 setDefaultIdentityInternal(const Name& identityName);
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700144
Yingdi Yu41546342014-11-30 23:37:53 -0800145 void
Yingdi Yu87581582014-01-14 14:28:39 -0800146 setDefaultKeyNameForIdentityInternal(const Name& keyName);
147
Yingdi Yu41546342014-11-30 23:37:53 -0800148 void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700149 setDefaultCertificateNameForKeyInternal(const Name& certificateName);
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800150
Yingdi Yu41546342014-11-30 23:37:53 -0800151 std::string
152 getScheme();
153
154NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
155 bool
156 doesTableExist(const std::string& tableName);
157
158public:
159 static const std::string SCHEME;
160
Yingdi Yu87581582014-01-14 14:28:39 -0800161private:
Junxiao Shi98acbb02014-12-02 11:00:42 -0700162 sqlite3* m_database;
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700163};
164
Yingdi Yufc40d872014-02-18 12:56:04 -0800165} // namespace ndn
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700166
Junxiao Shi98acbb02014-12-02 11:00:42 -0700167#endif // NDN_SECURITY_SEC_PUBLIC_INFO_SQLITE3_HPP