blob: bd5819ada0ef34c2c23017b4fda51f9b926d1287 [file] [log] [blame]
Mickey Sweatt11314b72015-06-10 17:20:19 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Yingdi Yu6ee2d362015-07-16 21:48:05 -07003 * Copyright (c) 2013-2017 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
Alexander Afanasyev97709c02016-08-25 19:58:30 -070022#ifndef NDN_SECURITTY_PIB_PIB_SQLITE3_HPP
23#define NDN_SECURITTY_PIB_PIB_SQLITE3_HPP
Mickey Sweatt11314b72015-06-10 17:20:19 -070024
25#include "pib-impl.hpp"
26
27struct sqlite3;
28
29namespace ndn {
30namespace security {
Yingdi Yu6ee2d362015-07-16 21:48:05 -070031namespace pib {
Mickey Sweatt11314b72015-06-10 17:20:19 -070032
33/**
34 * @brief Pib backend implementation based on SQLite3 database
35 *
36 * All the contents in Pib are stored in a SQLite3 database file.
37 * This backend provides more persistent storage than PibMemory.
38 */
39class PibSqlite3 : public PibImpl
40{
41public:
42 /**
43 * @brief Constructor of PibSqlite3
44 *
45 * This method will create a SQLite3 database file under the directory @p dir.
46 * If the directory does not exist, it will be created automatically.
47 * It assumes that the directory does not contain a PIB database of an older version,
48 * It is user's responsibility to update the older version database or remove the database.
49 *
50 * @param dir The directory where the database file is located. By default, it points to the
51 * $HOME/.ndn directory.
52 * @throws PibImpl::Error when initialization fails.
53 */
54 explicit
55 PibSqlite3(const std::string& dir = "");
56
57 /**
58 * @brief Destruct and cleanup internal state
59 */
60 ~PibSqlite3();
61
62public: // TpmLocator management
63
Davide Pesavento57c07df2016-12-11 18:41:45 -050064 void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020065 setTpmLocator(const std::string& tpmLocator) final;
Mickey Sweatt11314b72015-06-10 17:20:19 -070066
Davide Pesavento57c07df2016-12-11 18:41:45 -050067 std::string
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020068 getTpmLocator() const final;
Mickey Sweatt11314b72015-06-10 17:20:19 -070069
70public: // Identity management
71
Davide Pesavento57c07df2016-12-11 18:41:45 -050072 bool
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020073 hasIdentity(const Name& identity) const final;
Mickey Sweatt11314b72015-06-10 17:20:19 -070074
Davide Pesavento57c07df2016-12-11 18:41:45 -050075 void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020076 addIdentity(const Name& identity) final;
Mickey Sweatt11314b72015-06-10 17:20:19 -070077
Davide Pesavento57c07df2016-12-11 18:41:45 -050078 void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020079 removeIdentity(const Name& identity) final;
Mickey Sweatt11314b72015-06-10 17:20:19 -070080
Davide Pesavento57c07df2016-12-11 18:41:45 -050081 std::set<Name>
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020082 getIdentities() const final;
Mickey Sweatt11314b72015-06-10 17:20:19 -070083
Davide Pesavento57c07df2016-12-11 18:41:45 -050084 void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020085 setDefaultIdentity(const Name& identityName) final;
Mickey Sweatt11314b72015-06-10 17:20:19 -070086
Davide Pesavento57c07df2016-12-11 18:41:45 -050087 Name
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020088 getDefaultIdentity() const final;
Mickey Sweatt11314b72015-06-10 17:20:19 -070089
90public: // Key management
Davide Pesavento57c07df2016-12-11 18:41:45 -050091 bool
Yingdi Yu6ee2d362015-07-16 21:48:05 -070092 hasKey(const Name& keyName) const final;
Mickey Sweatt11314b72015-06-10 17:20:19 -070093
Davide Pesavento57c07df2016-12-11 18:41:45 -050094 void
Yingdi Yu6ee2d362015-07-16 21:48:05 -070095 addKey(const Name& identity, const Name& keyName,
96 const uint8_t* key, size_t keyLen) final;
Mickey Sweatt11314b72015-06-10 17:20:19 -070097
Davide Pesavento57c07df2016-12-11 18:41:45 -050098 void
Yingdi Yu6ee2d362015-07-16 21:48:05 -070099 removeKey(const Name& keyName) final;
Mickey Sweatt11314b72015-06-10 17:20:19 -0700100
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700101 Buffer
102 getKeyBits(const Name& keyName) const final;
Mickey Sweatt11314b72015-06-10 17:20:19 -0700103
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700104 std::set<Name>
Davide Pesaventoaa82eb62016-04-22 19:08:40 +0200105 getKeysOfIdentity(const Name& identity) const final;
Mickey Sweatt11314b72015-06-10 17:20:19 -0700106
Davide Pesavento57c07df2016-12-11 18:41:45 -0500107 void
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700108 setDefaultKeyOfIdentity(const Name& identity, const Name& keyName) final;
Mickey Sweatt11314b72015-06-10 17:20:19 -0700109
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700110 Name
Davide Pesaventoaa82eb62016-04-22 19:08:40 +0200111 getDefaultKeyOfIdentity(const Name& identity) const final;
Mickey Sweatt11314b72015-06-10 17:20:19 -0700112
113public: // Certificate Management
Davide Pesavento57c07df2016-12-11 18:41:45 -0500114 bool
Davide Pesaventoaa82eb62016-04-22 19:08:40 +0200115 hasCertificate(const Name& certName) const final;
Mickey Sweatt11314b72015-06-10 17:20:19 -0700116
Davide Pesavento57c07df2016-12-11 18:41:45 -0500117 void
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700118 addCertificate(const v2::Certificate& certificate) final;
Mickey Sweatt11314b72015-06-10 17:20:19 -0700119
Davide Pesavento57c07df2016-12-11 18:41:45 -0500120 void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +0200121 removeCertificate(const Name& certName) final;
Mickey Sweatt11314b72015-06-10 17:20:19 -0700122
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700123 v2::Certificate
Davide Pesaventoaa82eb62016-04-22 19:08:40 +0200124 getCertificate(const Name& certName) const final;
Mickey Sweatt11314b72015-06-10 17:20:19 -0700125
Davide Pesavento57c07df2016-12-11 18:41:45 -0500126 std::set<Name>
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700127 getCertificatesOfKey(const Name& keyName) const final;
Mickey Sweatt11314b72015-06-10 17:20:19 -0700128
Davide Pesavento57c07df2016-12-11 18:41:45 -0500129 void
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700130 setDefaultCertificateOfKey(const Name& keyName, const Name& certName) final;
Mickey Sweatt11314b72015-06-10 17:20:19 -0700131
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700132 v2::Certificate
133 getDefaultCertificateOfKey(const Name& keyName) const final;
Mickey Sweatt11314b72015-06-10 17:20:19 -0700134
135private:
136 sqlite3* m_database;
137};
138
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700139} // namespace pib
Mickey Sweatt11314b72015-06-10 17:20:19 -0700140} // namespace security
141} // namespace ndn
142
Alexander Afanasyev97709c02016-08-25 19:58:30 -0700143#endif // NDN_SECURITTY_PIB_PIB_SQLITE3_HPP