blob: f8665c50f8d8388e39392ac5ae2772cd7dcb3c37 [file] [log] [blame]
Mickey Sweatt11314b72015-06-10 17:20:19 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Davide Pesaventoaa82eb62016-04-22 19:08:40 +02003 * Copyright (c) 2013-2016 Regents of the University of California.
Mickey Sweatt11314b72015-06-10 17:20:19 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6 *
7 * 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.
20 */
21
22#ifndef NDN_SECURITTY_PIB_SQLITE3_HPP
23#define NDN_SECURITTY_PIB_SQLITE3_HPP
24
25#include "pib-impl.hpp"
26
27struct sqlite3;
28
29namespace ndn {
30namespace security {
31
32/**
33 * @brief Pib backend implementation based on SQLite3 database
34 *
35 * All the contents in Pib are stored in a SQLite3 database file.
36 * This backend provides more persistent storage than PibMemory.
37 */
38class PibSqlite3 : public PibImpl
39{
40public:
41 /**
42 * @brief Constructor of PibSqlite3
43 *
44 * This method will create a SQLite3 database file under the directory @p dir.
45 * If the directory does not exist, it will be created automatically.
46 * It assumes that the directory does not contain a PIB database of an older version,
47 * It is user's responsibility to update the older version database or remove the database.
48 *
49 * @param dir The directory where the database file is located. By default, it points to the
50 * $HOME/.ndn directory.
51 * @throws PibImpl::Error when initialization fails.
52 */
53 explicit
54 PibSqlite3(const std::string& dir = "");
55
56 /**
57 * @brief Destruct and cleanup internal state
58 */
59 ~PibSqlite3();
60
61public: // TpmLocator management
62
Mickey Sweatt11314b72015-06-10 17:20:19 -070063 virtual void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020064 setTpmLocator(const std::string& tpmLocator) final;
Mickey Sweatt11314b72015-06-10 17:20:19 -070065
Mickey Sweatt11314b72015-06-10 17:20:19 -070066 virtual std::string
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020067 getTpmLocator() const final;
Mickey Sweatt11314b72015-06-10 17:20:19 -070068
69public: // Identity management
70
Mickey Sweatt11314b72015-06-10 17:20:19 -070071 virtual bool
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020072 hasIdentity(const Name& identity) const final;
Mickey Sweatt11314b72015-06-10 17:20:19 -070073
Mickey Sweatt11314b72015-06-10 17:20:19 -070074 virtual void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020075 addIdentity(const Name& identity) final;
Mickey Sweatt11314b72015-06-10 17:20:19 -070076
Mickey Sweatt11314b72015-06-10 17:20:19 -070077 virtual void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020078 removeIdentity(const Name& identity) final;
Mickey Sweatt11314b72015-06-10 17:20:19 -070079
Mickey Sweatt11314b72015-06-10 17:20:19 -070080 virtual std::set<Name>
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020081 getIdentities() const final;
Mickey Sweatt11314b72015-06-10 17:20:19 -070082
Mickey Sweatt11314b72015-06-10 17:20:19 -070083 virtual void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020084 setDefaultIdentity(const Name& identityName) final;
Mickey Sweatt11314b72015-06-10 17:20:19 -070085
Mickey Sweatt11314b72015-06-10 17:20:19 -070086 virtual Name
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020087 getDefaultIdentity() const final;
Mickey Sweatt11314b72015-06-10 17:20:19 -070088
89public: // Key management
90
Mickey Sweatt11314b72015-06-10 17:20:19 -070091 virtual bool
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020092 hasKey(const Name& identity, const name::Component& keyId) const final;
Mickey Sweatt11314b72015-06-10 17:20:19 -070093
Mickey Sweatt11314b72015-06-10 17:20:19 -070094 virtual void
Alexander Afanasyev2fa59392016-07-29 17:24:23 -070095 addKey(const Name& identity, const name::Component& keyId, const v1::PublicKey& publicKey) final;
Mickey Sweatt11314b72015-06-10 17:20:19 -070096
Mickey Sweatt11314b72015-06-10 17:20:19 -070097 virtual void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020098 removeKey(const Name& identity, const name::Component& keyId) final;
Mickey Sweatt11314b72015-06-10 17:20:19 -070099
Alexander Afanasyev2fa59392016-07-29 17:24:23 -0700100 virtual v1::PublicKey
Davide Pesaventoaa82eb62016-04-22 19:08:40 +0200101 getKeyBits(const Name& identity, const name::Component& keyId) const final;
Mickey Sweatt11314b72015-06-10 17:20:19 -0700102
Mickey Sweatt11314b72015-06-10 17:20:19 -0700103 virtual std::set<name::Component>
Davide Pesaventoaa82eb62016-04-22 19:08:40 +0200104 getKeysOfIdentity(const Name& identity) const final;
Mickey Sweatt11314b72015-06-10 17:20:19 -0700105
Mickey Sweatt11314b72015-06-10 17:20:19 -0700106 virtual void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +0200107 setDefaultKeyOfIdentity(const Name& identity, const name::Component& keyId) final;
Mickey Sweatt11314b72015-06-10 17:20:19 -0700108
Mickey Sweatt11314b72015-06-10 17:20:19 -0700109 virtual name::Component
Davide Pesaventoaa82eb62016-04-22 19:08:40 +0200110 getDefaultKeyOfIdentity(const Name& identity) const final;
Mickey Sweatt11314b72015-06-10 17:20:19 -0700111
112public: // Certificate Management
113
Mickey Sweatt11314b72015-06-10 17:20:19 -0700114 virtual bool
Davide Pesaventoaa82eb62016-04-22 19:08:40 +0200115 hasCertificate(const Name& certName) const final;
Mickey Sweatt11314b72015-06-10 17:20:19 -0700116
Mickey Sweatt11314b72015-06-10 17:20:19 -0700117 virtual void
Alexander Afanasyev2fa59392016-07-29 17:24:23 -0700118 addCertificate(const v1::IdentityCertificate& certificate) final;
Mickey Sweatt11314b72015-06-10 17:20:19 -0700119
Mickey Sweatt11314b72015-06-10 17:20:19 -0700120 virtual void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +0200121 removeCertificate(const Name& certName) final;
Mickey Sweatt11314b72015-06-10 17:20:19 -0700122
Alexander Afanasyev2fa59392016-07-29 17:24:23 -0700123 virtual v1::IdentityCertificate
Davide Pesaventoaa82eb62016-04-22 19:08:40 +0200124 getCertificate(const Name& certName) const final;
Mickey Sweatt11314b72015-06-10 17:20:19 -0700125
Mickey Sweatt11314b72015-06-10 17:20:19 -0700126 virtual std::set<Name>
Davide Pesaventoaa82eb62016-04-22 19:08:40 +0200127 getCertificatesOfKey(const Name& identity, const name::Component& keyId) const final;
Mickey Sweatt11314b72015-06-10 17:20:19 -0700128
Mickey Sweatt11314b72015-06-10 17:20:19 -0700129 virtual void
130 setDefaultCertificateOfKey(const Name& identity, const name::Component& keyId,
Davide Pesaventoaa82eb62016-04-22 19:08:40 +0200131 const Name& certName) final;
Mickey Sweatt11314b72015-06-10 17:20:19 -0700132
Alexander Afanasyev2fa59392016-07-29 17:24:23 -0700133 virtual v1::IdentityCertificate
Davide Pesaventoaa82eb62016-04-22 19:08:40 +0200134 getDefaultCertificateOfKey(const Name& identity, const name::Component& keyId) const final;
Mickey Sweatt11314b72015-06-10 17:20:19 -0700135
136private:
137 sqlite3* m_database;
138};
139
140} // namespace security
141} // namespace ndn
142
143#endif // NDN_SECURITTY_PIB_SQLITE3_HPP