NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
pib-sqlite3.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2019 Regents of the University of California.
4  *
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 
26 
27 #include <sqlite3.h>
28 
29 #include <boost/algorithm/string.hpp>
30 #include <boost/filesystem.hpp>
31 
32 namespace ndn {
33 namespace security {
34 namespace pib {
35 
36 using util::Sqlite3Statement;
37 
38 static const std::string INITIALIZATION = R"SQL(
39 CREATE TABLE IF NOT EXISTS
40  tpmInfo(
41  tpm_locator BLOB
42  );
43 
44 CREATE TABLE IF NOT EXISTS
45  identities(
46  id INTEGER PRIMARY KEY,
47  identity BLOB NOT NULL,
48  is_default INTEGER DEFAULT 0
49  );
50 
51 CREATE UNIQUE INDEX IF NOT EXISTS
52  identityIndex ON identities(identity);
53 
54 CREATE TRIGGER IF NOT EXISTS
55  identity_default_before_insert_trigger
56  BEFORE INSERT ON identities
57  FOR EACH ROW
58  WHEN NEW.is_default=1
59  BEGIN
60  UPDATE identities SET is_default=0;
61  END;
62 
63 CREATE TRIGGER IF NOT EXISTS
64  identity_default_after_insert_trigger
65  AFTER INSERT ON identities
66  FOR EACH ROW
67  WHEN NOT EXISTS
68  (SELECT id
69  FROM identities
70  WHERE is_default=1)
71  BEGIN
72  UPDATE identities
73  SET is_default=1
74  WHERE identity=NEW.identity;
75  END;
76 
77 CREATE TRIGGER IF NOT EXISTS
78  identity_default_update_trigger
79  BEFORE UPDATE ON identities
80  FOR EACH ROW
81  WHEN NEW.is_default=1 AND OLD.is_default=0
82  BEGIN
83  UPDATE identities SET is_default=0;
84  END;
85 
86 CREATE TABLE IF NOT EXISTS
87  keys(
88  id INTEGER PRIMARY KEY,
89  identity_id INTEGER NOT NULL,
90  key_name BLOB NOT NULL,
91  key_bits BLOB NOT NULL,
92  is_default INTEGER DEFAULT 0,
93  FOREIGN KEY(identity_id)
94  REFERENCES identities(id)
95  ON DELETE CASCADE
96  ON UPDATE CASCADE
97  );
98 
99 CREATE UNIQUE INDEX IF NOT EXISTS
100  keyIndex ON keys(key_name);
101 
102 CREATE TRIGGER IF NOT EXISTS
103  key_default_before_insert_trigger
104  BEFORE INSERT ON keys
105  FOR EACH ROW
106  WHEN NEW.is_default=1
107  BEGIN
108  UPDATE keys
109  SET is_default=0
110  WHERE identity_id=NEW.identity_id;
111  END;
112 
113 CREATE TRIGGER IF NOT EXISTS
114  key_default_after_insert_trigger
115  AFTER INSERT ON keys
116  FOR EACH ROW
117  WHEN NOT EXISTS
118  (SELECT id
119  FROM keys
120  WHERE is_default=1
121  AND identity_id=NEW.identity_id)
122  BEGIN
123  UPDATE keys
124  SET is_default=1
125  WHERE key_name=NEW.key_name;
126  END;
127 
128 CREATE TRIGGER IF NOT EXISTS
129  key_default_update_trigger
130  BEFORE UPDATE ON keys
131  FOR EACH ROW
132  WHEN NEW.is_default=1 AND OLD.is_default=0
133  BEGIN
134  UPDATE keys
135  SET is_default=0
136  WHERE identity_id=NEW.identity_id;
137  END;
138 
139 
140 CREATE TABLE IF NOT EXISTS
141  certificates(
142  id INTEGER PRIMARY KEY,
143  key_id INTEGER NOT NULL,
144  certificate_name BLOB NOT NULL,
145  certificate_data BLOB NOT NULL,
146  is_default INTEGER DEFAULT 0,
147  FOREIGN KEY(key_id)
148  REFERENCES keys(id)
149  ON DELETE CASCADE
150  ON UPDATE CASCADE
151  );
152 
153 CREATE UNIQUE INDEX IF NOT EXISTS
154  certIndex ON certificates(certificate_name);
155 
156 CREATE TRIGGER IF NOT EXISTS
157  cert_default_before_insert_trigger
158  BEFORE INSERT ON certificates
159  FOR EACH ROW
160  WHEN NEW.is_default=1
161  BEGIN
162  UPDATE certificates
163  SET is_default=0
164  WHERE key_id=NEW.key_id;
165  END;
166 
167 CREATE TRIGGER IF NOT EXISTS
168  cert_default_after_insert_trigger
169  AFTER INSERT ON certificates
170  FOR EACH ROW
171  WHEN NOT EXISTS
172  (SELECT id
173  FROM certificates
174  WHERE is_default=1
175  AND key_id=NEW.key_id)
176  BEGIN
177  UPDATE certificates
178  SET is_default=1
179  WHERE certificate_name=NEW.certificate_name;
180  END;
181 
182 CREATE TRIGGER IF NOT EXISTS
183  cert_default_update_trigger
184  BEFORE UPDATE ON certificates
185  FOR EACH ROW
186  WHEN NEW.is_default=1 AND OLD.is_default=0
187  BEGIN
188  UPDATE certificates
189  SET is_default=0
190  WHERE key_id=NEW.key_id;
191  END;
192 )SQL";
193 
194 PibSqlite3::PibSqlite3(const std::string& location)
195 {
196  // Determine the path of PIB DB
197  boost::filesystem::path dbDir;
198  if (!location.empty()) {
199  dbDir = boost::filesystem::path(location);
200  }
201 #ifdef NDN_CXX_HAVE_TESTS
202  else if (getenv("TEST_HOME") != nullptr) {
203  dbDir = boost::filesystem::path(getenv("TEST_HOME")) / ".ndn";
204  }
205 #endif // NDN_CXX_HAVE_TESTS
206  else if (getenv("HOME") != nullptr) {
207  dbDir = boost::filesystem::path(getenv("HOME")) / ".ndn";
208  }
209  else {
210  dbDir = boost::filesystem::current_path() / ".ndn";
211  }
212  boost::filesystem::create_directories(dbDir);
213 
214  // Open PIB
215  int result = sqlite3_open_v2((dbDir / "pib.db").c_str(), &m_database,
216  SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
217 #ifdef NDN_CXX_DISABLE_SQLITE3_FS_LOCKING
218  "unix-dotfile"
219 #else
220  nullptr
221 #endif
222  );
223 
224  if (result != SQLITE_OK) {
225  NDN_THROW(PibImpl::Error("PIB database cannot be opened/created in " + dbDir.string()));
226  }
227 
228  // enable foreign key
229  sqlite3_exec(m_database, "PRAGMA foreign_keys=ON", nullptr, nullptr, nullptr);
230 
231  // initialize PIB tables
232  char* errmsg = nullptr;
233  result = sqlite3_exec(m_database, INITIALIZATION.c_str(), nullptr, nullptr, &errmsg);
234  if (result != SQLITE_OK && errmsg != nullptr) {
235  std::string what = "PIB database cannot be initialized: "s + errmsg;
236  sqlite3_free(errmsg);
237  NDN_THROW(PibImpl::Error(what));
238  }
239 }
240 
242 {
243  sqlite3_close(m_database);
244 }
245 
246 const std::string&
248 {
249  static std::string scheme = "pib-sqlite3";
250  return scheme;
251 }
252 
253 void
254 PibSqlite3::setTpmLocator(const std::string& tpmLocator)
255 {
256  Sqlite3Statement statement(m_database, "UPDATE tpmInfo SET tpm_locator=?");
257  statement.bind(1, tpmLocator, SQLITE_TRANSIENT);
258  statement.step();
259 
260  if (sqlite3_changes(m_database) == 0) {
261  // no row is updated, tpm_locator does not exist, insert it directly
262  Sqlite3Statement insertStatement(m_database, "INSERT INTO tpmInfo (tpm_locator) values (?)");
263  insertStatement.bind(1, tpmLocator, SQLITE_TRANSIENT);
264  insertStatement.step();
265  }
266 }
267 
268 std::string
270 {
271  Sqlite3Statement statement(m_database, "SELECT tpm_locator FROM tpmInfo");
272  int res = statement.step();
273  if (res == SQLITE_ROW)
274  return statement.getString(0);
275  else
276  return "";
277 }
278 
279 bool
280 PibSqlite3::hasIdentity(const Name& identity) const
281 {
282  Sqlite3Statement statement(m_database, "SELECT id FROM identities WHERE identity=?");
283  statement.bind(1, identity.wireEncode(), SQLITE_TRANSIENT);
284  return statement.step() == SQLITE_ROW;
285 }
286 
287 void
289 {
290  if (!hasIdentity(identity)) {
291  Sqlite3Statement statement(m_database, "INSERT INTO identities (identity) values (?)");
292  statement.bind(1, identity.wireEncode(), SQLITE_TRANSIENT);
293  statement.step();
294  }
295 
296  if (!hasDefaultIdentity()) {
297  setDefaultIdentity(identity);
298  }
299 }
300 
301 void
303 {
304  Sqlite3Statement statement(m_database, "DELETE FROM identities WHERE identity=?");
305  statement.bind(1, identity.wireEncode(), SQLITE_TRANSIENT);
306  statement.step();
307 }
308 
309 void
311 {
312  Sqlite3Statement statement(m_database, "DELETE FROM identities");
313  statement.step();
314 }
315 
316 std::set<Name>
318 {
319  std::set<Name> identities;
320  Sqlite3Statement statement(m_database, "SELECT identity FROM identities");
321 
322  while (statement.step() == SQLITE_ROW)
323  identities.insert(Name(statement.getBlock(0)));
324 
325  return identities;
326 }
327 
328 void
330 {
331  Sqlite3Statement statement(m_database, "UPDATE identities SET is_default=1 WHERE identity=?");
332  statement.bind(1, identityName.wireEncode(), SQLITE_TRANSIENT);
333  statement.step();
334 }
335 
336 Name
338 {
339  Sqlite3Statement statement(m_database, "SELECT identity FROM identities WHERE is_default=1");
340 
341  if (statement.step() == SQLITE_ROW)
342  return Name(statement.getBlock(0));
343  else
344  NDN_THROW(Pib::Error("No default identity"));
345 }
346 
347 bool
348 PibSqlite3::hasDefaultIdentity() const
349 {
350  Sqlite3Statement statement(m_database, "SELECT identity FROM identities WHERE is_default=1");
351  return (statement.step() == SQLITE_ROW);
352 }
353 
354 bool
355 PibSqlite3::hasKey(const Name& keyName) const
356 {
357  Sqlite3Statement statement(m_database, "SELECT id FROM keys WHERE key_name=?");
358  statement.bind(1, keyName.wireEncode(), SQLITE_TRANSIENT);
359 
360  return (statement.step() == SQLITE_ROW);
361 }
362 
363 void
364 PibSqlite3::addKey(const Name& identity, const Name& keyName,
365  const uint8_t* key, size_t keyLen)
366 {
367  // ensure identity exists
368  addIdentity(identity);
369 
370  if (!hasKey(keyName)) {
371  Sqlite3Statement statement(m_database,
372  "INSERT INTO keys (identity_id, key_name, key_bits) "
373  "VALUES ((SELECT id FROM identities WHERE identity=?), ?, ?)");
374  statement.bind(1, identity.wireEncode(), SQLITE_TRANSIENT);
375  statement.bind(2, keyName.wireEncode(), SQLITE_TRANSIENT);
376  statement.bind(3, key, keyLen, SQLITE_STATIC);
377  statement.step();
378  }
379  else {
380  Sqlite3Statement statement(m_database,
381  "UPDATE keys SET key_bits=? WHERE key_name=?");
382  statement.bind(1, key, keyLen, SQLITE_STATIC);
383  statement.bind(2, keyName.wireEncode(), SQLITE_TRANSIENT);
384  statement.step();
385  }
386 
387  if (!hasDefaultKeyOfIdentity(identity)) {
388  setDefaultKeyOfIdentity(identity, keyName);
389  }
390 }
391 
392 void
394 {
395  Sqlite3Statement statement(m_database, "DELETE FROM keys WHERE key_name=?");
396  statement.bind(1, keyName.wireEncode(), SQLITE_TRANSIENT);
397  statement.step();
398 }
399 
400 Buffer
401 PibSqlite3::getKeyBits(const Name& keyName) const
402 {
403  Sqlite3Statement statement(m_database, "SELECT key_bits FROM keys WHERE key_name=?");
404  statement.bind(1, keyName.wireEncode(), SQLITE_TRANSIENT);
405 
406  if (statement.step() == SQLITE_ROW)
407  return Buffer(statement.getBlob(0), statement.getSize(0));
408  else
409  NDN_THROW(Pib::Error("Key `" + keyName.toUri() + "` does not exist"));
410 }
411 
412 std::set<Name>
413 PibSqlite3::getKeysOfIdentity(const Name& identity) const
414 {
415  std::set<Name> keyNames;
416 
417  Sqlite3Statement statement(m_database,
418  "SELECT key_name "
419  "FROM keys JOIN identities ON keys.identity_id=identities.id "
420  "WHERE identities.identity=?");
421  statement.bind(1, identity.wireEncode(), SQLITE_TRANSIENT);
422 
423  while (statement.step() == SQLITE_ROW) {
424  keyNames.insert(Name(statement.getBlock(0)));
425  }
426 
427  return keyNames;
428 }
429 
430 void
431 PibSqlite3::setDefaultKeyOfIdentity(const Name& identity, const Name& keyName)
432 {
433  if (!hasKey(keyName)) {
434  NDN_THROW(Pib::Error("Key `" + keyName.toUri() + "` does not exist"));
435  }
436 
437  Sqlite3Statement statement(m_database, "UPDATE keys SET is_default=1 WHERE key_name=?");
438  statement.bind(1, keyName.wireEncode(), SQLITE_TRANSIENT);
439  statement.step();
440 }
441 
442 Name
444 {
445  if (!hasIdentity(identity)) {
446  NDN_THROW(Pib::Error("Identity `" + identity.toUri() + "` does not exist"));
447  }
448 
449  Sqlite3Statement statement(m_database,
450  "SELECT key_name "
451  "FROM keys JOIN identities ON keys.identity_id=identities.id "
452  "WHERE identities.identity=? AND keys.is_default=1");
453  statement.bind(1, identity.wireEncode(), SQLITE_TRANSIENT);
454 
455  if (statement.step() == SQLITE_ROW) {
456  return Name(statement.getBlock(0));
457  }
458  else
459  NDN_THROW(Pib::Error("No default key for identity `" + identity.toUri() + "`"));
460 }
461 
462 bool
463 PibSqlite3::hasDefaultKeyOfIdentity(const Name& identity) const
464 {
465  Sqlite3Statement statement(m_database,
466  "SELECT key_name "
467  "FROM keys JOIN identities ON keys.identity_id=identities.id "
468  "WHERE identities.identity=? AND keys.is_default=1");
469  statement.bind(1, identity.wireEncode(), SQLITE_TRANSIENT);
470 
471  return (statement.step() == SQLITE_ROW);
472 }
473 
474 bool
475 PibSqlite3::hasCertificate(const Name& certName) const
476 {
477  Sqlite3Statement statement(m_database, "SELECT id FROM certificates WHERE certificate_name=?");
478  statement.bind(1, certName.wireEncode(), SQLITE_TRANSIENT);
479  return (statement.step() == SQLITE_ROW);
480 }
481 
482 void
484 {
485  // ensure key exists
486  const Block& content = certificate.getContent();
487  addKey(certificate.getIdentity(), certificate.getKeyName(), content.value(), content.value_size());
488 
489  if (!hasCertificate(certificate.getName())) {
490  Sqlite3Statement statement(m_database,
491  "INSERT INTO certificates "
492  "(key_id, certificate_name, certificate_data) "
493  "VALUES ((SELECT id FROM keys WHERE key_name=?), ?, ?)");
494  statement.bind(1, certificate.getKeyName().wireEncode(), SQLITE_TRANSIENT);
495  statement.bind(2, certificate.getName().wireEncode(), SQLITE_TRANSIENT);
496  statement.bind(3, certificate.wireEncode(), SQLITE_STATIC);
497  statement.step();
498  }
499  else {
500  Sqlite3Statement statement(m_database,
501  "UPDATE certificates SET certificate_data=? WHERE certificate_name=?");
502  statement.bind(1, certificate.wireEncode(), SQLITE_STATIC);
503  statement.bind(2, certificate.getName().wireEncode(), SQLITE_TRANSIENT);
504  statement.step();
505  }
506 
507  if (!hasDefaultCertificateOfKey(certificate.getKeyName())) {
508  setDefaultCertificateOfKey(certificate.getKeyName(), certificate.getName());
509  }
510 }
511 
512 void
514 {
515  Sqlite3Statement statement(m_database, "DELETE FROM certificates WHERE certificate_name=?");
516  statement.bind(1, certName.wireEncode(), SQLITE_TRANSIENT);
517  statement.step();
518 }
519 
521 PibSqlite3::getCertificate(const Name& certName) const
522 {
523  Sqlite3Statement statement(m_database,
524  "SELECT certificate_data FROM certificates WHERE certificate_name=?");
525  statement.bind(1, certName.wireEncode(), SQLITE_TRANSIENT);
526 
527  if (statement.step() == SQLITE_ROW)
528  return v2::Certificate(statement.getBlock(0));
529  else
530  NDN_THROW(Pib::Error("Certificate `" + certName.toUri() + "` does not exit"));
531 }
532 
533 std::set<Name>
535 {
536  std::set<Name> certNames;
537 
538  Sqlite3Statement statement(m_database,
539  "SELECT certificate_name "
540  "FROM certificates JOIN keys ON certificates.key_id=keys.id "
541  "WHERE keys.key_name=?");
542  statement.bind(1, keyName.wireEncode(), SQLITE_TRANSIENT);
543 
544  while (statement.step() == SQLITE_ROW)
545  certNames.insert(Name(statement.getBlock(0)));
546 
547  return certNames;
548 }
549 
550 void
551 PibSqlite3::setDefaultCertificateOfKey(const Name& keyName, const Name& certName)
552 {
553  if (!hasCertificate(certName)) {
554  NDN_THROW(Pib::Error("Certificate `" + certName.toUri() + "` does not exist"));
555  }
556 
557  Sqlite3Statement statement(m_database,
558  "UPDATE certificates SET is_default=1 WHERE certificate_name=?");
559  statement.bind(1, certName.wireEncode(), SQLITE_TRANSIENT);
560  statement.step();
561 }
562 
565 {
566  Sqlite3Statement statement(m_database,
567  "SELECT certificate_data "
568  "FROM certificates JOIN keys ON certificates.key_id=keys.id "
569  "WHERE certificates.is_default=1 AND keys.key_name=?");
570  statement.bind(1, keyName.wireEncode(), SQLITE_TRANSIENT);
571 
572  if (statement.step() == SQLITE_ROW)
573  return v2::Certificate(statement.getBlock(0));
574  else
575  NDN_THROW(Pib::Error("No default certificate for key `" + keyName.toUri() + "`"));
576 }
577 
578 bool
579 PibSqlite3::hasDefaultCertificateOfKey(const Name& keyName) const
580 {
581  Sqlite3Statement statement(m_database,
582  "SELECT certificate_data "
583  "FROM certificates JOIN keys ON certificates.key_id=keys.id "
584  "WHERE certificates.is_default=1 AND keys.key_name=?");
585  statement.bind(1, keyName.wireEncode(), SQLITE_TRANSIENT);
586 
587  return statement.step() == SQLITE_ROW;
588 }
589 
590 } // namespace pib
591 } // namespace security
592 } // namespace ndn
ndn::security::pib::PibSqlite3::getKeyBits
Buffer getKeyBits(const Name &keyName) const final
Get the key bits of a key with name keyName.
Definition: pib-sqlite3.cpp:401
ndn::util::Sqlite3Statement::step
int step()
wrapper of sqlite3_step
Definition: sqlite3-statement.cpp:105
ndn::security::pib::PibSqlite3::hasIdentity
bool hasIdentity(const Name &identity) const final
Check the existence of an identity.
Definition: pib-sqlite3.cpp:280
ndn::util::Sqlite3Statement::getBlob
const uint8_t * getBlob(int column)
get a pointer of byte blob from column.
Definition: sqlite3-statement.cpp:93
ndn::security::pib::PibSqlite3::removeCertificate
void removeCertificate(const Name &certName) final
Remove a certificate with name certName.
Definition: pib-sqlite3.cpp:513
ndn::security::v2::Certificate::getIdentity
Name getIdentity() const
Get identity name.
Definition: certificate.cpp:87
ndn::security::pib::PibSqlite3::getDefaultKeyOfIdentity
Name getDefaultKeyOfIdentity(const Name &identity) const final
Definition: pib-sqlite3.cpp:443
ndn::Block::value_size
size_t value_size() const noexcept
Return the size of TLV-VALUE, aka TLV-LENGTH.
Definition: block.cpp:308
security-common.hpp
ndn::security::pib::PibSqlite3::setDefaultCertificateOfKey
void setDefaultCertificateOfKey(const Name &keyName, const Name &certName) final
Set a cert with name certName as the default of a key with keyName.
Definition: pib-sqlite3.cpp:551
ndn::security::pib::PibImpl::Error
represents a non-semantic error
Definition: pib-impl.hpp:50
ndn::Buffer
General-purpose automatically managed/resized buffer.
Definition: buffer.hpp:41
ndn::security::pib::PibSqlite3::setDefaultKeyOfIdentity
void setDefaultKeyOfIdentity(const Name &identity, const Name &keyName) final
Set an key with keyName as the default key of an identity with name identity.
Definition: pib-sqlite3.cpp:431
ndn::security::pib::PibSqlite3::addIdentity
void addIdentity(const Name &identity) final
Add an identity.
Definition: pib-sqlite3.cpp:288
ndn::security::pib::PibSqlite3::getScheme
static const std::string & getScheme()
Definition: pib-sqlite3.cpp:247
ndn::security::v2::Certificate::getKeyName
Name getKeyName() const
Get key name.
Definition: certificate.cpp:81
ndn::Data::getContent
const Block & getContent() const
Get Content.
Definition: data.cpp:232
pib-sqlite3.hpp
ndn::Data::wireEncode
size_t wireEncode(EncodingImpl< TAG > &encoder, bool wantUnsignedPortionOnly=false) const
Prepend wire encoding to encoder in NDN Packet Format v0.2.
Definition: data.cpp:48
ndn::Data::getName
const Name & getName() const
Get name.
Definition: data.hpp:124
ndn::security::pib::PibSqlite3::setTpmLocator
void setTpmLocator(const std::string &tpmLocator) final
Set the corresponding TPM information to tpmLocator.
Definition: pib-sqlite3.cpp:254
ndn::security::pib::INITIALIZATION
static const std::string INITIALIZATION
Definition: pib-sqlite3.cpp:38
ndn::util::Sqlite3Statement
wrap an SQLite3 prepared statement
Definition: sqlite3-statement.hpp:38
ndn::Name
Represents an absolute name.
Definition: name.hpp:44
ns3::ndn::Name
Name
Definition: ndn-common.cpp:25
ndn::security::pib::PibSqlite3::getCertificate
v2::Certificate getCertificate(const Name &certName) const final
Get a certificate with name certName.
Definition: pib-sqlite3.cpp:521
ndn::util::Sqlite3Statement::getSize
int getSize(int column)
get the size of column.
Definition: sqlite3-statement.cpp:99
ndn::security::v2::Certificate
The certificate following the certificate format naming convention.
Definition: certificate.hpp:82
ndn::security::pib::PibSqlite3::getIdentities
std::set< Name > getIdentities() const final
Get the name of all the identities.
Definition: pib-sqlite3.cpp:317
ndn::Name::wireEncode
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Fast encoding or block size estimation.
Definition: name.cpp:117
NDN_THROW
#define NDN_THROW(e)
Definition: exception.hpp:61
ndn::security::pib::Pib::Error
represents a semantic error
Definition: pib.hpp:57
ndn::security::pib::PibSqlite3::~PibSqlite3
~PibSqlite3()
Destruct and cleanup internal state.
Definition: pib-sqlite3.cpp:241
sqlite3-statement.hpp
ndn::security::pib::PibSqlite3::setDefaultIdentity
void setDefaultIdentity(const Name &identityName) final
Set an identity with name identityName as the default identity.
Definition: pib-sqlite3.cpp:329
ndn::security::pib::PibSqlite3::addCertificate
void addCertificate(const v2::Certificate &certificate) final
Add a certificate.
Definition: pib-sqlite3.cpp:483
ndn::Name::toUri
void toUri(std::ostream &os, name::UriFormat format=name::UriFormat::DEFAULT) const
Write URI representation of the name to the output stream.
Definition: name.cpp:348
ndn::security::pib::PibSqlite3::getTpmLocator
std::string getTpmLocator() const final
Get TPM Locator.
Definition: pib-sqlite3.cpp:269
ndn::security::pib::PibSqlite3::hasKey
bool hasKey(const Name &keyName) const final
Check the existence of a key with keyName.
Definition: pib-sqlite3.cpp:355
ndn::security::pib::PibSqlite3::getDefaultIdentity
Name getDefaultIdentity() const final
Get the default identity.
Definition: pib-sqlite3.cpp:337
pib.hpp
ndn::security::pib::PibSqlite3::clearIdentities
void clearIdentities() final
Erasing all certificates, keys, and identities.
Definition: pib-sqlite3.cpp:310
ndn::Block::value
const uint8_t * value() const noexcept
Return a raw pointer to the beginning of TLV-VALUE.
Definition: block.cpp:302
ndn::Block
Represents a TLV element of NDN packet format.
Definition: block.hpp:43
ndn::security::pib::PibSqlite3::hasCertificate
bool hasCertificate(const Name &certName) const final
Check the existence of a certificate with name certName.
Definition: pib-sqlite3.cpp:475
ndn::security::pib::PibSqlite3::addKey
void addKey(const Name &identity, const Name &keyName, const uint8_t *key, size_t keyLen) final
Add a key.
Definition: pib-sqlite3.cpp:364
ndn::security::pib::PibSqlite3::getKeysOfIdentity
std::set< Name > getKeysOfIdentity(const Name &identity) const final
Get all the key names of an identity with name identity.
Definition: pib-sqlite3.cpp:413
ndn::util::Sqlite3Statement::getString
std::string getString(int column)
get a string from column.
Definition: sqlite3-statement.cpp:72
ndn::security::pib::PibSqlite3::getCertificatesOfKey
std::set< Name > getCertificatesOfKey(const Name &keyName) const final
Get a list of certificate names of a key with id keyName.
Definition: pib-sqlite3.cpp:534
ndn::security::pib::PibSqlite3::PibSqlite3
PibSqlite3(const std::string &location="")
Create sqlite3-based PIB backed.
Definition: pib-sqlite3.cpp:194
ndn::security::pib::PibSqlite3::removeKey
void removeKey(const Name &keyName) final
Remove a key with keyName and related certificates.
Definition: pib-sqlite3.cpp:393
ndn::util::Sqlite3Statement::bind
int bind(int index, const char *value, size_t size, void(*destructor)(void *))
bind a string to the statement
Definition: sqlite3-statement.cpp:42
ndn::util::Sqlite3Statement::getBlock
Block getBlock(int column)
get a block from column.
Definition: sqlite3-statement.cpp:79
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-strategy-choice-helper.hpp:34
ndn::security::pib::PibSqlite3::removeIdentity
void removeIdentity(const Name &identity) final
Remove an identity and related keys and certificates.
Definition: pib-sqlite3.cpp:302
ndn::security::pib::PibSqlite3::getDefaultCertificateOfKey
v2::Certificate getDefaultCertificateOfKey(const Name &keyName) const final
Definition: pib-sqlite3.cpp:564