blob: 806a29c4eb29d65b9c300bbeecc9ce69da0459d7 [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
Davide Pesavento57c07df2016-12-11 18:41:45 -050063 void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020064 setTpmLocator(const std::string& tpmLocator) final;
Mickey Sweatt11314b72015-06-10 17:20:19 -070065
Davide Pesavento57c07df2016-12-11 18:41:45 -050066 std::string
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020067 getTpmLocator() const final;
Mickey Sweatt11314b72015-06-10 17:20:19 -070068
69public: // Identity management
Davide Pesavento57c07df2016-12-11 18:41:45 -050070 bool
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020071 hasIdentity(const Name& identity) const final;
Mickey Sweatt11314b72015-06-10 17:20:19 -070072
Davide Pesavento57c07df2016-12-11 18:41:45 -050073 void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020074 addIdentity(const Name& identity) final;
Mickey Sweatt11314b72015-06-10 17:20:19 -070075
Davide Pesavento57c07df2016-12-11 18:41:45 -050076 void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020077 removeIdentity(const Name& identity) final;
Mickey Sweatt11314b72015-06-10 17:20:19 -070078
Yingdi Yu7b3b5e92015-08-13 19:52:35 -070079 void
80 clearIdentities() final;
81
Davide Pesavento57c07df2016-12-11 18:41:45 -050082 std::set<Name>
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020083 getIdentities() const final;
Mickey Sweatt11314b72015-06-10 17:20:19 -070084
Davide Pesavento57c07df2016-12-11 18:41:45 -050085 void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020086 setDefaultIdentity(const Name& identityName) final;
Mickey Sweatt11314b72015-06-10 17:20:19 -070087
Davide Pesavento57c07df2016-12-11 18:41:45 -050088 Name
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020089 getDefaultIdentity() const final;
Mickey Sweatt11314b72015-06-10 17:20:19 -070090
91public: // Key management
Davide Pesavento57c07df2016-12-11 18:41:45 -050092 bool
Yingdi Yu6ee2d362015-07-16 21:48:05 -070093 hasKey(const Name& keyName) const final;
Mickey Sweatt11314b72015-06-10 17:20:19 -070094
Davide Pesavento57c07df2016-12-11 18:41:45 -050095 void
Yingdi Yu6ee2d362015-07-16 21:48:05 -070096 addKey(const Name& identity, const Name& keyName,
97 const uint8_t* key, size_t keyLen) final;
Mickey Sweatt11314b72015-06-10 17:20:19 -070098
Davide Pesavento57c07df2016-12-11 18:41:45 -050099 void
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700100 removeKey(const Name& keyName) final;
Mickey Sweatt11314b72015-06-10 17:20:19 -0700101
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700102 Buffer
103 getKeyBits(const Name& keyName) const final;
Mickey Sweatt11314b72015-06-10 17:20:19 -0700104
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700105 std::set<Name>
Davide Pesaventoaa82eb62016-04-22 19:08:40 +0200106 getKeysOfIdentity(const Name& identity) const final;
Mickey Sweatt11314b72015-06-10 17:20:19 -0700107
Davide Pesavento57c07df2016-12-11 18:41:45 -0500108 void
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700109 setDefaultKeyOfIdentity(const Name& identity, const Name& keyName) final;
Mickey Sweatt11314b72015-06-10 17:20:19 -0700110
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700111 Name
Davide Pesaventoaa82eb62016-04-22 19:08:40 +0200112 getDefaultKeyOfIdentity(const Name& identity) const final;
Mickey Sweatt11314b72015-06-10 17:20:19 -0700113
114public: // Certificate Management
Davide Pesavento57c07df2016-12-11 18:41:45 -0500115 bool
Davide Pesaventoaa82eb62016-04-22 19:08:40 +0200116 hasCertificate(const Name& certName) const final;
Mickey Sweatt11314b72015-06-10 17:20:19 -0700117
Davide Pesavento57c07df2016-12-11 18:41:45 -0500118 void
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700119 addCertificate(const v2::Certificate& certificate) final;
Mickey Sweatt11314b72015-06-10 17:20:19 -0700120
Davide Pesavento57c07df2016-12-11 18:41:45 -0500121 void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +0200122 removeCertificate(const Name& certName) final;
Mickey Sweatt11314b72015-06-10 17:20:19 -0700123
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700124 v2::Certificate
Davide Pesaventoaa82eb62016-04-22 19:08:40 +0200125 getCertificate(const Name& certName) const final;
Mickey Sweatt11314b72015-06-10 17:20:19 -0700126
Davide Pesavento57c07df2016-12-11 18:41:45 -0500127 std::set<Name>
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700128 getCertificatesOfKey(const Name& keyName) const final;
Mickey Sweatt11314b72015-06-10 17:20:19 -0700129
Davide Pesavento57c07df2016-12-11 18:41:45 -0500130 void
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700131 setDefaultCertificateOfKey(const Name& keyName, const Name& certName) final;
Mickey Sweatt11314b72015-06-10 17:20:19 -0700132
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700133 v2::Certificate
134 getDefaultCertificateOfKey(const Name& keyName) const final;
Mickey Sweatt11314b72015-06-10 17:20:19 -0700135
136private:
137 sqlite3* m_database;
138};
139
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700140} // namespace pib
Mickey Sweatt11314b72015-06-10 17:20:19 -0700141} // namespace security
142} // namespace ndn
143
Alexander Afanasyev97709c02016-08-25 19:58:30 -0700144#endif // NDN_SECURITTY_PIB_PIB_SQLITE3_HPP