blob: 7e6f4c81d059d01b5c95b4fb3313e43bcee98938 [file] [log] [blame]
Jeff Thompson7ca11f22013-10-04 19:01:30 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
3 * Copyright (C) 2013 Regents of the University of California.
4 * @author: Yingdi Yu <yingdi@cs.ucla.edu>
Jeff Thompson22285ec2013-10-22 17:43:02 -07005 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
Jeff Thompson7ca11f22013-10-04 19:01:30 -07006 * See COPYING for copyright and distribution information.
7 */
8
Yingdi Yu874678f2014-01-22 19:30:34 -08009#include <sqlite3.h>
Jeff Thompson351ac302013-10-19 18:45:00 -070010#include <stdio.h>
Jeff Thompson7ca11f22013-10-04 19:01:30 -070011#include <stdlib.h>
12#include <sstream>
13#include <fstream>
Yingdi Yu0b9c3152014-01-26 16:31:18 -080014#include <boost/filesystem.hpp>
Yingdi Yu4f324632014-01-15 18:10:03 -080015#include "../util/logging.hpp"
Alexander Afanasyevd409d592014-01-28 18:36:38 -080016#include "../util/time.hpp"
17
Alexander Afanasyev09c613f2014-01-29 00:23:58 -080018#include "data.hpp"
19#include "security/identity-certificate.hpp"
20#include "security/sec-public-info-sqlite3.hpp"
21#include "security/signature-sha256-with-rsa.hpp"
Alexander Afanasyevfab95ed2014-01-05 23:26:30 -080022
Jeff Thompson7ca11f22013-10-04 19:01:30 -070023
Yingdi Yu87581582014-01-14 14:28:39 -080024INIT_LOGGER("BasicKeyMetaInfo");
Jeff Thompson7ca11f22013-10-04 19:01:30 -070025
26using namespace std;
Jeff Thompson7ca11f22013-10-04 19:01:30 -070027
28namespace ndn
29{
30
31static const string INIT_ID_TABLE = "\
32CREATE TABLE IF NOT EXISTS \n \
33 Identity( \n \
34 identity_name BLOB NOT NULL, \n \
35 default_identity INTEGER DEFAULT 0, \n \
36 \
37 PRIMARY KEY (identity_name) \n \
38 ); \n \
39 \
40CREATE INDEX identity_index ON Identity(identity_name); \n \
41";
42
43static const string INIT_KEY_TABLE = "\
44CREATE TABLE IF NOT EXISTS \n \
45 Key( \n \
46 identity_name BLOB NOT NULL, \n \
47 key_identifier BLOB NOT NULL, \n \
48 key_type INTEGER, \n \
49 public_key BLOB, \n \
50 default_key INTEGER DEFAULT 0, \n \
51 active INTEGER DEFAULT 0, \n \
52 \
53 PRIMARY KEY (identity_name, key_identifier) \n \
54 ); \n \
55 \
56CREATE INDEX key_index ON Key(identity_name); \n \
57";
58
59static const string INIT_CERT_TABLE = "\
60CREATE TABLE IF NOT EXISTS \n \
61 Certificate( \n \
62 cert_name BLOB NOT NULL, \n \
63 cert_issuer BLOB NOT NULL, \n \
64 identity_name BLOB NOT NULL, \n \
65 key_identifier BLOB NOT NULL, \n \
66 not_before TIMESTAMP, \n \
67 not_after TIMESTAMP, \n \
68 certificate_data BLOB NOT NULL, \n \
Jeff Thompson22285ec2013-10-22 17:43:02 -070069 valid_flag INTEGER DEFAULT 1, \n \
Jeff Thompson7ca11f22013-10-04 19:01:30 -070070 default_cert INTEGER DEFAULT 0, \n \
71 \
72 PRIMARY KEY (cert_name) \n \
73 ); \n \
74 \
75CREATE INDEX cert_index ON Certificate(cert_name); \n \
76CREATE INDEX subject ON Certificate(identity_name); \n \
77";
78
79/**
80 * A utility function to call the normal sqlite3_bind_text where the value and length are value.c_str() and value.size().
81 */
82static int sqlite3_bind_text(sqlite3_stmt* statement, int index, const string& value, void(*destructor)(void*))
83{
84 return sqlite3_bind_text(statement, index, value.c_str(), value.size(), destructor);
85}
86
Yingdi Yu87581582014-01-14 14:28:39 -080087SecPublicInfoSqlite3::SecPublicInfoSqlite3()
Jeff Thompson7ca11f22013-10-04 19:01:30 -070088{
Yingdi Yu0b9c3152014-01-26 16:31:18 -080089 boost::filesystem::path identityDir = boost::filesystem::path(getenv("HOME")) / ".ndnx";
90 boost::filesystem::create_directories (identityDir);
Jeff Thompson7ca11f22013-10-04 19:01:30 -070091
Yingdi Yu28fd32f2014-01-28 19:03:03 -080092 int res = sqlite3_open((identityDir / "ndnsec-public-info.db").c_str(), &m_database);
Jeff Thompson7ca11f22013-10-04 19:01:30 -070093
94 if (res != SQLITE_OK)
Alexander Afanasyevfab95ed2014-01-05 23:26:30 -080095 throw Error("identity DB cannot be opened/created");
Jeff Thompson7ca11f22013-10-04 19:01:30 -070096
97 //Check if Key table exists;
98 sqlite3_stmt *statement;
Yingdi Yu28fd32f2014-01-28 19:03:03 -080099 sqlite3_prepare_v2(m_database, "SELECT name FROM sqlite_master WHERE type='table' And name='Identity'", -1, &statement, 0);
Jeff Thompson351ac302013-10-19 18:45:00 -0700100 res = sqlite3_step(statement);
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700101
102 bool idTableExists = false;
103 if (res == SQLITE_ROW)
104 idTableExists = true;
105
106 sqlite3_finalize(statement);
107
108 if (!idTableExists) {
109 char *errorMessage = 0;
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800110 res = sqlite3_exec(m_database, INIT_ID_TABLE.c_str(), NULL, NULL, &errorMessage);
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700111
112 if (res != SQLITE_OK && errorMessage != 0) {
113 _LOG_TRACE("Init \"error\" in Identity: " << errorMessage);
114 sqlite3_free(errorMessage);
115 }
116 }
117
118 //Check if Key table exists;
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800119 sqlite3_prepare_v2(m_database, "SELECT name FROM sqlite_master WHERE type='table' And name='Key'", -1, &statement, 0);
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700120 res = sqlite3_step(statement);
121
122 bool keyTableExists = false;
123 if (res == SQLITE_ROW)
124 keyTableExists = true;
125
126 sqlite3_finalize(statement);
127
128 if (!keyTableExists) {
129 char *errorMessage = 0;
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800130 res = sqlite3_exec(m_database, INIT_KEY_TABLE.c_str(), NULL, NULL, &errorMessage);
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700131
132 if (res != SQLITE_OK && errorMessage != 0) {
133 _LOG_TRACE("Init \"error\" in KEY: " << errorMessage);
134 sqlite3_free(errorMessage);
135 }
136 }
137
138 //Check if Certificate table exists;
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800139 sqlite3_prepare_v2(m_database, "SELECT name FROM sqlite_master WHERE type='table' And name='Certificate'", -1, &statement, 0);
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700140 res = sqlite3_step(statement);
141
142 bool idCertificateTableExists = false;
143 if (res == SQLITE_ROW)
144 idCertificateTableExists = true;
145
146 sqlite3_finalize(statement);
147
148 if (!idCertificateTableExists) {
149 char *errorMessage = 0;
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800150 res = sqlite3_exec(m_database, INIT_CERT_TABLE.c_str(), NULL, NULL, &errorMessage);
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700151
152 if (res != SQLITE_OK && errorMessage != 0) {
153 _LOG_TRACE("Init \"error\" in ID-CERT: " << errorMessage);
154 sqlite3_free(errorMessage);
155 }
156 }
157}
158
Yingdi Yu87581582014-01-14 14:28:39 -0800159SecPublicInfoSqlite3::~SecPublicInfoSqlite3()
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700160{
161}
162
163bool
Yingdi Yu87581582014-01-14 14:28:39 -0800164SecPublicInfoSqlite3::doesIdentityExist(const Name& identityName)
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700165{
166 bool result = false;
167
168 sqlite3_stmt *statement;
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800169 sqlite3_prepare_v2(m_database, "SELECT count(*) FROM Identity WHERE identity_name=?", -1, &statement, 0);
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700170
171 sqlite3_bind_text(statement, 1, identityName.toUri(), SQLITE_TRANSIENT);
172 int res = sqlite3_step(statement);
173
174 if (res == SQLITE_ROW) {
175 int countAll = sqlite3_column_int(statement, 0);
176 if (countAll > 0)
177 result = true;
178 }
179
180 sqlite3_finalize(statement);
181
182 return result;
183}
184
185void
Yingdi Yu87581582014-01-14 14:28:39 -0800186SecPublicInfoSqlite3::addIdentity(const Name& identityName)
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700187{
188 if (doesIdentityExist(identityName))
Alexander Afanasyevfab95ed2014-01-05 23:26:30 -0800189 throw Error("Identity already exists");
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700190
191 sqlite3_stmt *statement;
192
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800193 sqlite3_prepare_v2(m_database, "INSERT INTO Identity (identity_name) values (?)", -1, &statement, 0);
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700194
195 sqlite3_bind_text(statement, 1, identityName.toUri(), SQLITE_TRANSIENT);
196
Alexander Afanasyev736708b2014-01-06 14:45:34 -0800197 sqlite3_step(statement);
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700198
199 sqlite3_finalize(statement);
200}
201
202bool
Yingdi Yu87581582014-01-14 14:28:39 -0800203SecPublicInfoSqlite3::revokeIdentity()
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700204{
205 //TODO:
206 return false;
207}
208
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700209bool
Yingdi Yu87581582014-01-14 14:28:39 -0800210SecPublicInfoSqlite3::doesPublicKeyExist(const Name& keyName)
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700211{
Yingdi Yu88663af2014-01-15 15:21:38 -0800212 if(keyName.empty())
213 throw Error("Incorrect key name " + keyName.toUri());
214
Yingdi Yu87581582014-01-14 14:28:39 -0800215 string keyId = keyName.get(-1).toEscapedString();
216 Name identityName = keyName.getPrefix(-1);
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700217
218 sqlite3_stmt *statement;
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800219 sqlite3_prepare_v2(m_database, "SELECT count(*) FROM Key WHERE identity_name=? AND key_identifier=?", -1, &statement, 0);
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700220
221 sqlite3_bind_text(statement, 1, identityName.toUri(), SQLITE_TRANSIENT);
222 sqlite3_bind_text(statement, 2, keyId, SQLITE_TRANSIENT);
223
224 int res = sqlite3_step(statement);
225
226 bool keyIdExist = false;
227 if (res == SQLITE_ROW) {
228 int countAll = sqlite3_column_int(statement, 0);
229 if (countAll > 0)
230 keyIdExist = true;
231 }
232
233 sqlite3_finalize(statement);
234
235 return keyIdExist;
236}
237
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700238void
Yingdi Yu87581582014-01-14 14:28:39 -0800239SecPublicInfoSqlite3::addPublicKey(const Name& keyName, KeyType keyType, const PublicKey& publicKeyDer)
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700240{
Yingdi Yu88663af2014-01-15 15:21:38 -0800241 if(keyName.empty())
242 throw Error("Incorrect key name " + keyName.toUri());
243
Yingdi Yu87581582014-01-14 14:28:39 -0800244 string keyId = keyName.get(-1).toEscapedString();
245 Name identityName = keyName.getPrefix(-1);
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700246
247
248 if (!doesIdentityExist(identityName))
249 addIdentity(identityName);
250
Yingdi Yu87581582014-01-14 14:28:39 -0800251 if (doesPublicKeyExist(keyName))
Alexander Afanasyevfab95ed2014-01-05 23:26:30 -0800252 throw Error("a key with the same name already exists!");
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700253
254 sqlite3_stmt *statement;
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800255 sqlite3_prepare_v2(m_database, "INSERT INTO Key (identity_name, key_identifier, key_type, public_key) values (?, ?, ?, ?)", -1, &statement, 0);
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700256
257 sqlite3_bind_text(statement, 1, identityName.toUri(), SQLITE_TRANSIENT);
258 sqlite3_bind_text(statement, 2, keyId, SQLITE_TRANSIENT);
259 sqlite3_bind_int(statement, 3, (int)keyType);
Alexander Afanasyevfab95ed2014-01-05 23:26:30 -0800260 sqlite3_bind_blob(statement, 4, publicKeyDer.get().buf(), publicKeyDer.get().size(), SQLITE_STATIC);
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700261
Alexander Afanasyev736708b2014-01-06 14:45:34 -0800262 sqlite3_step(statement);
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700263
264 sqlite3_finalize(statement);
265}
266
Alexander Afanasyevfab95ed2014-01-05 23:26:30 -0800267ptr_lib::shared_ptr<PublicKey>
Yingdi Yu87581582014-01-14 14:28:39 -0800268SecPublicInfoSqlite3::getPublicKey(const Name& keyName)
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700269{
Yingdi Yu87581582014-01-14 14:28:39 -0800270 if (!doesPublicKeyExist(keyName)) {
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700271 _LOG_DEBUG("keyName does not exist");
Alexander Afanasyevfab95ed2014-01-05 23:26:30 -0800272 return ptr_lib::shared_ptr<PublicKey>();
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700273 }
274
Yingdi Yu87581582014-01-14 14:28:39 -0800275 string keyId = keyName.get(-1).toEscapedString();
276 Name identityName = keyName.getPrefix(-1);
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700277
278 sqlite3_stmt *statement;
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800279 sqlite3_prepare_v2(m_database, "SELECT public_key FROM Key WHERE identity_name=? AND key_identifier=?", -1, &statement, 0);
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700280
281 sqlite3_bind_text(statement, 1, identityName.toUri(), SQLITE_TRANSIENT);
282 sqlite3_bind_text(statement, 2, keyId, SQLITE_TRANSIENT);
283
284 int res = sqlite3_step(statement);
285
Alexander Afanasyevfab95ed2014-01-05 23:26:30 -0800286 ptr_lib::shared_ptr<PublicKey> result;
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700287 if (res == SQLITE_ROW)
Alexander Afanasyevfab95ed2014-01-05 23:26:30 -0800288 result = ptr_lib::make_shared<PublicKey>(static_cast<const uint8_t*>(sqlite3_column_blob(statement, 0)), sqlite3_column_bytes(statement, 0));
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700289
290 sqlite3_finalize(statement);
291
292 return result;
293}
294
295void
Yingdi Yu87581582014-01-14 14:28:39 -0800296SecPublicInfoSqlite3::updateKeyStatus(const Name& keyName, bool isActive)
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700297{
Yingdi Yu88663af2014-01-15 15:21:38 -0800298 if(keyName.empty())
299 throw Error("Incorrect key name " + keyName.toUri());
300
Yingdi Yu87581582014-01-14 14:28:39 -0800301 string keyId = keyName.get(-1).toEscapedString();
302 Name identityName = keyName.getPrefix(-1);
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700303
304 sqlite3_stmt *statement;
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800305 sqlite3_prepare_v2(m_database, "UPDATE Key SET active=? WHERE identity_name=? AND key_identifier=?", -1, &statement, 0);
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700306
307 sqlite3_bind_int(statement, 1, (isActive ? 1 : 0));
308 sqlite3_bind_text(statement, 2, identityName.toUri(), SQLITE_TRANSIENT);
309 sqlite3_bind_text(statement, 3, keyId, SQLITE_TRANSIENT);
310
Alexander Afanasyev736708b2014-01-06 14:45:34 -0800311 sqlite3_step(statement);
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700312
313 sqlite3_finalize(statement);
314}
315
316bool
Yingdi Yu87581582014-01-14 14:28:39 -0800317SecPublicInfoSqlite3::doesCertificateExist(const Name& certificateName)
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700318{
319 sqlite3_stmt *statement;
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800320 sqlite3_prepare_v2(m_database, "SELECT count(*) FROM Certificate WHERE cert_name=?", -1, &statement, 0);
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700321
322 sqlite3_bind_text(statement, 1, certificateName.toUri(), SQLITE_TRANSIENT);
323
324 int res = sqlite3_step(statement);
325
326 bool certExist = false;
327 if (res == SQLITE_ROW) {
328 int countAll = sqlite3_column_int(statement, 0);
329 if (countAll > 0)
330 certExist = true;
331 }
332
333 sqlite3_finalize(statement);
334
335 return certExist;
336}
337
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700338void
Yingdi Yu87581582014-01-14 14:28:39 -0800339SecPublicInfoSqlite3::addAnyCertificate(const IdentityCertificate& certificate)
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700340{
Alexander Afanasyevfab95ed2014-01-05 23:26:30 -0800341 std::string certificateName = certificate.getName().toUri();
Yingdi Yu88663af2014-01-15 15:21:38 -0800342 Name keyName = IdentityCertificate::certificateNameToPublicKeyName(certificate.getName());
343
344 if(keyName.empty())
345 throw Error("Incorrect key name " + keyName.toUri());
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700346
Yingdi Yu87581582014-01-14 14:28:39 -0800347 std::string keyId = keyName.get(-1).toEscapedString();
348 std::string identityName = keyName.getPrefix(-1).toUri();
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700349
350 sqlite3_stmt *statement;
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800351 sqlite3_prepare_v2(m_database,
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700352 "INSERT INTO Certificate (cert_name, cert_issuer, identity_name, key_identifier, not_before, not_after, certificate_data)\
353 values (?, ?, ?, ?, datetime(?, 'unixepoch'), datetime(?, 'unixepoch'), ?)",
354 -1, &statement, 0);
355
356
Alexander Afanasyevfab95ed2014-01-05 23:26:30 -0800357 _LOG_DEBUG("certName: " << certificateName);
358 sqlite3_bind_text(statement, 1, certificateName, SQLITE_STATIC);
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700359
Alexander Afanasyevfab95ed2014-01-05 23:26:30 -0800360 // this will throw an exception if the signature is not the standard one or there is no key locator present
361 SignatureSha256WithRsa signature(certificate.getSignature());
362 std::string signerName = signature.getKeyLocator().getName().toUri();
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700363
Alexander Afanasyevfab95ed2014-01-05 23:26:30 -0800364 sqlite3_bind_text(statement, 2, signerName, SQLITE_STATIC);
365
366 sqlite3_bind_text(statement, 3, identityName, SQLITE_STATIC);
367 sqlite3_bind_text(statement, 4, keyId, SQLITE_STATIC);
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700368
Jeff Thompson9f2b9fc2013-10-19 18:00:12 -0700369 // Convert from milliseconds to seconds since 1/1/1970.
Alexander Afanasyevfab95ed2014-01-05 23:26:30 -0800370 sqlite3_bind_int64(statement, 5, static_cast<sqlite3_int64>(certificate.getNotBefore() / 1000));
371 sqlite3_bind_int64(statement, 6, static_cast<sqlite3_int64>(certificate.getNotAfter() / 1000));
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700372
Alexander Afanasyevfab95ed2014-01-05 23:26:30 -0800373 sqlite3_bind_blob(statement, 7, certificate.wireEncode().wire(), certificate.wireEncode().size(), SQLITE_STATIC);
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700374
Alexander Afanasyev736708b2014-01-06 14:45:34 -0800375 sqlite3_step(statement);
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700376
377 sqlite3_finalize(statement);
378}
379
380void
Yingdi Yu87581582014-01-14 14:28:39 -0800381SecPublicInfoSqlite3::addCertificate(const IdentityCertificate& certificate)
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700382{
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700383 const Name& certificateName = certificate.getName();
Yingdi Yu88663af2014-01-15 15:21:38 -0800384 Name keyName = IdentityCertificate::certificateNameToPublicKeyName(certificate.getName());
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700385
Yingdi Yu87581582014-01-14 14:28:39 -0800386 if (!doesPublicKeyExist(keyName))
Alexander Afanasyevfab95ed2014-01-05 23:26:30 -0800387 throw Error("No corresponding Key record for certificate!" + keyName.toUri() + " " + certificateName.toUri());
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700388
389 // Check if certificate has already existed!
390 if (doesCertificateExist(certificateName))
Alexander Afanasyevfab95ed2014-01-05 23:26:30 -0800391 throw Error("Certificate has already been installed!");
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700392
Yingdi Yu87581582014-01-14 14:28:39 -0800393 string keyId = keyName.get(-1).toEscapedString();
394 Name identity = keyName.getPrefix(-1);
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700395
396 // Check if the public key of certificate is the same as the key record
397
Yingdi Yu87581582014-01-14 14:28:39 -0800398 ptr_lib::shared_ptr<PublicKey> pubKey = getPublicKey(keyName);
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700399
Alexander Afanasyevfab95ed2014-01-05 23:26:30 -0800400 if (!pubKey || (*pubKey) != certificate.getPublicKeyInfo())
401 throw Error("Certificate does not match the public key!");
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700402
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700403 // Insert the certificate
404 sqlite3_stmt *statement;
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800405 sqlite3_prepare_v2(m_database,
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700406 "INSERT INTO Certificate (cert_name, cert_issuer, identity_name, key_identifier, not_before, not_after, certificate_data)\
407 values (?, ?, ?, ?, datetime(?, 'unixepoch'), datetime(?, 'unixepoch'), ?)",
408 -1, &statement, 0);
409
Alexander Afanasyevfab95ed2014-01-05 23:26:30 -0800410 _LOG_DEBUG("certName: " << certificateName.toUri());
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700411 sqlite3_bind_text(statement, 1, certificateName.toUri(), SQLITE_TRANSIENT);
412
Alexander Afanasyevfab95ed2014-01-05 23:26:30 -0800413 // this will throw an exception if the signature is not the standard one or there is no key locator present
414 SignatureSha256WithRsa signature(certificate.getSignature());
415 std::string signerName = signature.getKeyLocator().getName().toUri();
416
417 sqlite3_bind_text(statement, 2, signerName, SQLITE_STATIC);
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700418
419 sqlite3_bind_text(statement, 3, identity.toUri(), SQLITE_TRANSIENT);
Alexander Afanasyevfab95ed2014-01-05 23:26:30 -0800420 sqlite3_bind_text(statement, 4, keyId, SQLITE_STATIC);
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700421
Jeff Thompson9f2b9fc2013-10-19 18:00:12 -0700422 // Convert from milliseconds to seconds since 1/1/1970.
Yingdi Yu88663af2014-01-15 15:21:38 -0800423 sqlite3_bind_int64(statement, 5, static_cast<sqlite3_int64>(certificate.getNotBefore() / 1000));
424 sqlite3_bind_int64(statement, 6, static_cast<sqlite3_int64>(certificate.getNotAfter() / 1000));
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700425
Alexander Afanasyevfab95ed2014-01-05 23:26:30 -0800426 sqlite3_bind_blob(statement, 7, certificate.wireEncode().wire(), certificate.wireEncode().size(), SQLITE_TRANSIENT);
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700427
Alexander Afanasyev736708b2014-01-06 14:45:34 -0800428 sqlite3_step(statement);
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700429
430 sqlite3_finalize(statement);
431}
432
Alexander Afanasyevfab95ed2014-01-05 23:26:30 -0800433ptr_lib::shared_ptr<IdentityCertificate>
Yingdi Yu88663af2014-01-15 15:21:38 -0800434SecPublicInfoSqlite3::getCertificate(const Name &certificateName)
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700435{
Yingdi Yu4270f202014-01-28 14:19:16 -0800436 sqlite3_stmt *statement;
437
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800438 sqlite3_prepare_v2(m_database,
Yingdi Yu4270f202014-01-28 14:19:16 -0800439 "SELECT certificate_data FROM Certificate WHERE cert_name=?",
440 -1, &statement, 0);
441
442 sqlite3_bind_text(statement, 1, certificateName.toUri(), SQLITE_TRANSIENT);
443
444 int res = sqlite3_step(statement);
445
446 ptr_lib::shared_ptr<IdentityCertificate> certificate;
447 if (res == SQLITE_ROW)
448 {
449 certificate = ptr_lib::make_shared<IdentityCertificate>();
450 certificate->wireDecode(Block((const uint8_t*)sqlite3_column_blob(statement, 0), sqlite3_column_bytes(statement, 0)));
451 }
452 sqlite3_finalize(statement);
453
454 return certificate;
Jeff Thompson1975def2013-10-09 17:06:43 -0700455}
Yingdi Yu4270f202014-01-28 14:19:16 -0800456
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700457
458Name
Yingdi Yu87581582014-01-14 14:28:39 -0800459SecPublicInfoSqlite3::getDefaultIdentity()
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700460{
461 sqlite3_stmt *statement;
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800462 sqlite3_prepare_v2(m_database, "SELECT identity_name FROM Identity WHERE default_identity=1", -1, &statement, 0);
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700463
464 int res = sqlite3_step(statement);
465
466 Name identity;
467
468 if (res == SQLITE_ROW)
469 identity = Name(string(reinterpret_cast<const char *>(sqlite3_column_text(statement, 0)), sqlite3_column_bytes(statement, 0)));
470
471 sqlite3_finalize(statement);
472
473 return identity;
474}
475
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700476void
Yingdi Yu87581582014-01-14 14:28:39 -0800477SecPublicInfoSqlite3::setDefaultIdentityInternal(const Name& identityName)
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700478{
479 sqlite3_stmt *statement;
480
481 //Reset previous default identity
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800482 sqlite3_prepare_v2(m_database, "UPDATE Identity SET default_identity=0 WHERE default_identity=1", -1, &statement, 0);
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700483
484 while (sqlite3_step(statement) == SQLITE_ROW)
485 {}
486
487 sqlite3_finalize(statement);
488
489 //Set current default identity
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800490 sqlite3_prepare_v2(m_database, "UPDATE Identity SET default_identity=1 WHERE identity_name=?", -1, &statement, 0);
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700491
492 sqlite3_bind_text(statement, 1, identityName.toUri(), SQLITE_TRANSIENT);
493
494 sqlite3_step(statement);
495
496 sqlite3_finalize(statement);
497}
498
Yingdi Yu87581582014-01-14 14:28:39 -0800499Name
500SecPublicInfoSqlite3::getDefaultKeyNameForIdentity(const Name& identityName)
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700501{
Yingdi Yu87581582014-01-14 14:28:39 -0800502 sqlite3_stmt *statement;
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800503 sqlite3_prepare_v2(m_database, "SELECT key_identifier FROM Key WHERE identity_name=? AND default_key=1", -1, &statement, 0);
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700504
Yingdi Yu87581582014-01-14 14:28:39 -0800505 sqlite3_bind_text(statement, 1, identityName.toUri(), SQLITE_TRANSIENT);
506
507 int res = sqlite3_step(statement);
508
509 Name keyName;
510
511 if (res == SQLITE_ROW)
512 keyName = Name(identityName).append(string(reinterpret_cast<const char *>(sqlite3_column_text(statement, 0)), sqlite3_column_bytes(statement, 0)));
513
514 sqlite3_finalize(statement);
515
516 return keyName;
517}
518
519void
520SecPublicInfoSqlite3::setDefaultKeyNameForIdentityInternal(const Name& keyName)
521{
Yingdi Yu88663af2014-01-15 15:21:38 -0800522 if(keyName.empty())
523 throw Error("Incorrect key name " + keyName.toUri());
524
Yingdi Yu87581582014-01-14 14:28:39 -0800525 string keyId = keyName.get(-1).toEscapedString();
526 Name identityName = keyName.getPrefix(-1);
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700527
528 sqlite3_stmt *statement;
529
530 //Reset previous default Key
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800531 sqlite3_prepare_v2(m_database, "UPDATE Key SET default_key=0 WHERE default_key=1 and identity_name=?", -1, &statement, 0);
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700532
533 sqlite3_bind_text(statement, 1, identityName.toUri(), SQLITE_TRANSIENT);
534
535 while (sqlite3_step(statement) == SQLITE_ROW)
536 {}
537
538 sqlite3_finalize(statement);
539
540 //Set current default Key
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800541 sqlite3_prepare_v2(m_database, "UPDATE Key SET default_key=1 WHERE identity_name=? AND key_identifier=?", -1, &statement, 0);
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700542
543 sqlite3_bind_text(statement, 1, identityName.toUri(), SQLITE_TRANSIENT);
544 sqlite3_bind_text(statement, 2, keyId, SQLITE_TRANSIENT);
545
546 sqlite3_step(statement);
547
548 sqlite3_finalize(statement);
549}
550
Yingdi Yu87581582014-01-14 14:28:39 -0800551Name
552SecPublicInfoSqlite3::getDefaultCertificateNameForKey(const Name& keyName)
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700553{
Yingdi Yu88663af2014-01-15 15:21:38 -0800554 if(keyName.empty())
555 return Name();
556
Yingdi Yu87581582014-01-14 14:28:39 -0800557 string keyId = keyName.get(-1).toEscapedString();
558 Name identityName = keyName.getPrefix(-1);
559
560 sqlite3_stmt *statement;
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800561 sqlite3_prepare_v2(m_database, "SELECT cert_name FROM Certificate WHERE identity_name=? AND key_identifier=? AND default_cert=1", -1, &statement, 0);
Yingdi Yu87581582014-01-14 14:28:39 -0800562
563 sqlite3_bind_text(statement, 1, identityName.toUri(), SQLITE_TRANSIENT);
564 sqlite3_bind_text(statement, 2, keyId, SQLITE_TRANSIENT);
565
566 int res = sqlite3_step(statement);
567
568 Name certName;
569
570 if (res == SQLITE_ROW)
571 certName = Name(string(reinterpret_cast<const char *>(sqlite3_column_text(statement, 0)), sqlite3_column_bytes(statement, 0)));
572
573 sqlite3_finalize(statement);
574
575 return certName;
576}
577
578void
579SecPublicInfoSqlite3::setDefaultCertificateNameForKeyInternal(const Name& certificateName)
580{
581 Name keyName = IdentityCertificate::certificateNameToPublicKeyName(certificateName);
Yingdi Yu88663af2014-01-15 15:21:38 -0800582 if(keyName.empty())
583 throw Error("Incorrect key name for certificate " + certificateName.toUri());
584
Yingdi Yu87581582014-01-14 14:28:39 -0800585 string keyId = keyName.get(-1).toEscapedString();
586 Name identityName = keyName.getPrefix(-1);
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700587
588 sqlite3_stmt *statement;
589
590 //Reset previous default Key
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800591 sqlite3_prepare_v2(m_database, "UPDATE Certificate SET default_cert=0 WHERE default_cert=1 AND identity_name=? AND key_identifier=?", -1, &statement, 0);
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700592
593 sqlite3_bind_text(statement, 1, identityName.toUri(), SQLITE_TRANSIENT);
594 sqlite3_bind_text(statement, 2, keyId, SQLITE_TRANSIENT);
595
596 while (sqlite3_step(statement) == SQLITE_ROW)
597 {}
598
599 sqlite3_finalize(statement);
600
601 //Set current default Key
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800602 sqlite3_prepare_v2(m_database, "UPDATE Certificate SET default_cert=1 WHERE identity_name=? AND key_identifier=? AND cert_name=?", -1, &statement, 0);
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700603
604 sqlite3_bind_text(statement, 1, identityName.toUri(), SQLITE_TRANSIENT);
605 sqlite3_bind_text(statement, 2, keyId, SQLITE_TRANSIENT);
606 sqlite3_bind_text(statement, 3, certificateName.toUri(), SQLITE_TRANSIENT);
607
608 sqlite3_step(statement);
609
610 sqlite3_finalize(statement);
611}
Alexander Afanasyev0c632112013-12-30 15:59:31 -0800612
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800613void
614SecPublicInfoSqlite3::getAllIdentities(vector<Name> &nameList, bool isDefault)
Alexander Afanasyev0c632112013-12-30 15:59:31 -0800615{
616 sqlite3_stmt *stmt;
617 if(isDefault)
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800618 sqlite3_prepare_v2 (m_database, "SELECT identity_name FROM Identity WHERE default_identity=1", -1, &stmt, 0);
Alexander Afanasyev0c632112013-12-30 15:59:31 -0800619 else
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800620 sqlite3_prepare_v2 (m_database, "SELECT identity_name FROM Identity WHERE default_identity=0", -1, &stmt, 0);
Alexander Afanasyev0c632112013-12-30 15:59:31 -0800621
Alexander Afanasyev0c632112013-12-30 15:59:31 -0800622 while(sqlite3_step (stmt) == SQLITE_ROW)
623 nameList.push_back(Name(string(reinterpret_cast<const char *>(sqlite3_column_text(stmt, 0)), sqlite3_column_bytes (stmt, 0))));
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700624
Alexander Afanasyev0c632112013-12-30 15:59:31 -0800625 sqlite3_finalize (stmt);
Jeff Thompson7ca11f22013-10-04 19:01:30 -0700626}
627
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800628void
629SecPublicInfoSqlite3::getAllKeyNames(vector<Name> &nameList, bool isDefault)
Alexander Afanasyev0c632112013-12-30 15:59:31 -0800630{
631 sqlite3_stmt *stmt;
632 if(isDefault)
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800633 sqlite3_prepare_v2 (m_database, "SELECT identity_name, key_identifier FROM Key WHERE default_key=1", -1, &stmt, 0);
Alexander Afanasyev0c632112013-12-30 15:59:31 -0800634 else
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800635 sqlite3_prepare_v2 (m_database, "SELECT identity_name, key_identifier FROM Key WHERE default_key=0", -1, &stmt, 0);
Alexander Afanasyev0c632112013-12-30 15:59:31 -0800636
Alexander Afanasyev0c632112013-12-30 15:59:31 -0800637 while(sqlite3_step (stmt) == SQLITE_ROW)
638 {
639 Name keyName(string(reinterpret_cast<const char *>(sqlite3_column_text(stmt, 0)), sqlite3_column_bytes (stmt, 0)));
640 keyName.append(string(reinterpret_cast<const char *>(sqlite3_column_text(stmt, 1)), sqlite3_column_bytes (stmt, 1)));
641 nameList.push_back(keyName);
642 }
643 sqlite3_finalize (stmt);
Alexander Afanasyev0c632112013-12-30 15:59:31 -0800644}
645
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800646void
647SecPublicInfoSqlite3::getAllKeyNamesOfIdentity(const Name& identity, vector<Name> &nameList, bool isDefault)
Alexander Afanasyev0c632112013-12-30 15:59:31 -0800648{
649 sqlite3_stmt *stmt;
650 if(isDefault)
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800651 sqlite3_prepare_v2 (m_database, "SELECT key_identifier FROM Key WHERE default_key=1 and identity_name=?", -1, &stmt, 0);
Alexander Afanasyev0c632112013-12-30 15:59:31 -0800652 else
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800653 sqlite3_prepare_v2 (m_database, "SELECT key_identifier FROM Key WHERE default_key=0 and identity_name=?", -1, &stmt, 0);
Alexander Afanasyev0c632112013-12-30 15:59:31 -0800654
655 sqlite3_bind_text(stmt, 1, identity.toUri().c_str(), identity.toUri().size (), SQLITE_TRANSIENT);
656
Alexander Afanasyev0c632112013-12-30 15:59:31 -0800657 while(sqlite3_step (stmt) == SQLITE_ROW)
658 {
659 Name keyName(identity);
660 keyName.append(string(reinterpret_cast<const char *>(sqlite3_column_text(stmt, 0)), sqlite3_column_bytes (stmt, 0)));
661 nameList.push_back(keyName);
662 }
663 sqlite3_finalize (stmt);
Alexander Afanasyev0c632112013-12-30 15:59:31 -0800664}
665
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800666void
667SecPublicInfoSqlite3::getAllCertificateNames(vector<Name> &nameList, bool isDefault)
Alexander Afanasyev0c632112013-12-30 15:59:31 -0800668{
669 sqlite3_stmt *stmt;
670 if(isDefault)
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800671 sqlite3_prepare_v2 (m_database, "SELECT cert_name FROM Certificate WHERE default_cert=1", -1, &stmt, 0);
Alexander Afanasyev0c632112013-12-30 15:59:31 -0800672 else
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800673 sqlite3_prepare_v2 (m_database, "SELECT cert_name FROM Certificate WHERE default_cert=0", -1, &stmt, 0);
Alexander Afanasyev0c632112013-12-30 15:59:31 -0800674
Alexander Afanasyev0c632112013-12-30 15:59:31 -0800675 while(sqlite3_step (stmt) == SQLITE_ROW)
676 nameList.push_back(string(reinterpret_cast<const char *>(sqlite3_column_text(stmt, 0)), sqlite3_column_bytes (stmt, 0)));
677
678 sqlite3_finalize (stmt);
Alexander Afanasyev0c632112013-12-30 15:59:31 -0800679}
680
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800681void
682SecPublicInfoSqlite3::getAllCertificateNamesOfKey(const Name& keyName, vector<Name> &nameList, bool isDefault)
Alexander Afanasyev0c632112013-12-30 15:59:31 -0800683{
Yingdi Yu88663af2014-01-15 15:21:38 -0800684 if(keyName.empty())
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800685 return;
Yingdi Yu88663af2014-01-15 15:21:38 -0800686
Alexander Afanasyev0c632112013-12-30 15:59:31 -0800687 sqlite3_stmt *stmt;
688 if(isDefault)
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800689 sqlite3_prepare_v2 (m_database, "SELECT cert_name FROM Certificate WHERE default_cert=1 and identity_name=? and key_identifier=?", -1, &stmt, 0);
Alexander Afanasyev0c632112013-12-30 15:59:31 -0800690 else
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800691 sqlite3_prepare_v2 (m_database, "SELECT cert_name FROM Certificate WHERE default_cert=0 and identity_name=? and key_identifier=?", -1, &stmt, 0);
Alexander Afanasyev0c632112013-12-30 15:59:31 -0800692
Yingdi Yu87581582014-01-14 14:28:39 -0800693 Name identity = keyName.getPrefix(-1);
Alexander Afanasyev0c632112013-12-30 15:59:31 -0800694 sqlite3_bind_text(stmt, 1, identity.toUri().c_str(), identity.toUri().size (), SQLITE_TRANSIENT);
695 std::string baseKeyName = keyName.get(-1).toEscapedString();
696 sqlite3_bind_text(stmt, 2, baseKeyName.c_str(), baseKeyName.size(), SQLITE_TRANSIENT);
697
Alexander Afanasyev0c632112013-12-30 15:59:31 -0800698 while(sqlite3_step (stmt) == SQLITE_ROW)
699 nameList.push_back(string(reinterpret_cast<const char *>(sqlite3_column_text(stmt, 0)), sqlite3_column_bytes (stmt, 0)));
700
701 sqlite3_finalize (stmt);
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800702}
703
704void
705SecPublicInfoSqlite3::deleteCertificateInfo(const Name &certName)
706{
707 if(certName.empty())
708 return;
709
710 sqlite3_stmt *stmt;
711 sqlite3_prepare_v2(m_database, "DELETE FROM Certificate WHERE cert_name=?", -1, &stmt, 0);
712 sqlite3_bind_text(stmt, 1, certName.toUri().c_str(), certName.toUri().size (), SQLITE_TRANSIENT);
713 sqlite3_step(stmt);
714 sqlite3_finalize (stmt);
715}
716
717void
718SecPublicInfoSqlite3::deletePublicKeyInfo(const Name &keyName)
719{
720 if(keyName.empty())
721 return;
722
723 string identity = keyName.getPrefix(-1).toUri();
724 string keyId = keyName.get(-1).toEscapedString();
725
726 sqlite3_stmt *stmt;
727 sqlite3_prepare_v2(m_database, "DELETE FROM Certificate WHERE identity_name=? and key_identifier=?", -1, &stmt, 0);
728 sqlite3_bind_text(stmt, 1, identity.c_str(), identity.size (), SQLITE_TRANSIENT);
729 sqlite3_bind_text(stmt, 2, keyId.c_str(), keyId.size(), SQLITE_TRANSIENT);
730 sqlite3_step(stmt);
731 sqlite3_finalize (stmt);
732
733 sqlite3_prepare_v2(m_database, "DELETE FROM Key WHERE identity_name=? and key_identifier=?", -1, &stmt, 0);
734 sqlite3_bind_text(stmt, 1, identity.c_str(), identity.size (), SQLITE_TRANSIENT);
735 sqlite3_bind_text(stmt, 2, keyId.c_str(), keyId.size(), SQLITE_TRANSIENT);
736 sqlite3_step(stmt);
737 sqlite3_finalize (stmt);
738}
739
740void
741SecPublicInfoSqlite3::deleteIdentityInfo(const Name &identityName)
742{
743 string identity = identityName.toUri();
744
745 sqlite3_stmt *stmt;
746 sqlite3_prepare_v2(m_database, "DELETE FROM Certificate WHERE identity_name=?", -1, &stmt, 0);
747 sqlite3_bind_text(stmt, 1, identity.c_str(), identity.size (), SQLITE_TRANSIENT);
748 sqlite3_step(stmt);
749 sqlite3_finalize (stmt);
750
751 sqlite3_prepare_v2(m_database, "DELETE FROM Key WHERE identity_name=?", -1, &stmt, 0);
752 sqlite3_bind_text(stmt, 1, identity.c_str(), identity.size (), SQLITE_TRANSIENT);
753 sqlite3_step(stmt);
754 sqlite3_finalize (stmt);
755
756 sqlite3_prepare_v2(m_database, "DELETE FROM Identity WHERE identity_name=?", -1, &stmt, 0);
757 sqlite3_bind_text(stmt, 1, identity.c_str(), identity.size (), SQLITE_TRANSIENT);
758 sqlite3_step(stmt);
759 sqlite3_finalize (stmt);
Alexander Afanasyev0c632112013-12-30 15:59:31 -0800760}
761
762} // namespace ndn
763