Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2015 Regents of the University of California.

Author(s):
Jeff Thompson <jefft0@remap.ucla.edu>
From code in ndn-cxx by Yingdi Yu <yingdi@cs.ucla.edu> This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. A copy of the GNU Lesser General Public License is in the file COPYING.
 
 
 package net.named_data.jndn.security.identity;
 
SqliteIdentityStorageBase is an abstract base class for the storage of identity, public keys and certificates using SQLite. This base class has protected SQL strings and helpers so the subclasses can work with similar tables using their own SQLite libraries.
 
 public abstract class Sqlite3IdentityStorageBase extends IdentityStorage {
  
Activate a key. If a key is marked as inactive, its private part will not be used in packet signing.

Parameters:
keyName The name of the key.
 
   public final void
   activateKey(Name keyNamethrows SecurityException
   {
     updateKeyStatus(keyNametrue);
   }

  
Deactivate a key. If a key is marked as inactive, its private part will not be used in packet signing.

Parameters:
keyName The name of the key.
 
   public final void
   deactivateKey(Name keyNamethrows SecurityException
   {
     updateKeyStatus(keyNamefalse);
   }

  
In table Key, set 'active' to isActive for the keyName.

Parameters:
keyName The name of the key.
isActive The value for the 'active' field.
 
   protected abstract void
   updateKeyStatus(Name keyNameboolean isActivethrows SecurityException;

  
Throw an exception if it is an error for addKey to add the key.

Parameters:
keyName The name of the public key to be added.
Throws:
net.named_data.jndn.security.SecurityException if the key already exists or other problem.
 
   protected void
   checkAddKey(Name keyNamethrows SecurityException
   {
     if (doesKeyExist(keyName))
       throw new SecurityException("a key with the same name already exists!");
   }

  
Throw an exception if it is an error for addCertificate to add the certificate.

Parameters:
certificate The certificate to be added. This makes a copy of the certificate.
Throws:
net.named_data.jndn.security.SecurityException if the certificate is already installed or other problem.
 
   protected void
   {
     Name certificateName = certificate.getName();
     Name keyName = certificate.getPublicKeyName();
 
     if (!doesKeyExist(keyName))
       throw new SecurityException
         ("No corresponding Key record for certificate!" + keyName.toUri() +
          " " + certificateName.toUri());
 
     // Check if the certificate already exists.
     if (doesCertificateExist(certificateName))
       throw new SecurityException("Certificate has already been installed!");
 
     // Check if the public key of the certificate is the same as the key record.
    Blob keyBlob = getKey(keyName);
    if (keyBlob.isNull() || !keyBlob.equals(certificate.getPublicKeyInfo().getKeyDer()))
      throw new SecurityException("Certificate does not match the public key!");
  }

  
Throw an exception if it is an error for setDefaultKeyNameForIdentity to set it.

Parameters:
keyName The key name.
identityNameCheck The identity name to check the keyName.
Throws:
net.named_data.jndn.security.SecurityException if the identity name does not match the key name or other problem.
  protected void
  checkSetDefaultKeyNameForIdentity(Name keyNameName identityNameCheck)
    throws SecurityException
  {
    String keyId = keyName.get(-1).toEscapedString();
    Name identityName = keyName.getPrefix(-1);
    if (identityNameCheck.size() > 0 && !identityNameCheck.equals(identityName))
      throw new SecurityException
        ("The specified identity name does not match the key name");
  }
  protected static final String SELECT_MASTER_ID_TABLE =
    "SELECT name FROM sqlite_master WHERE type='table' And name='Identity'";
  protected static final String SELECT_MASTER_KEY_TABLE =
    "SELECT name FROM sqlite_master WHERE type='table' And name='Key'";
  protected static final String SELECT_MASTER_CERT_TABLE =
    "SELECT name FROM sqlite_master WHERE type='table' And name='Certificate'";
  protected static final String INIT_ID_TABLE =
"CREATE TABLE IF NOT EXISTS                                           \n" +
"  Identity(                                                          \n" +
"      identity_name     BLOB NOT NULL,                               \n" +
"      default_identity  INTEGER DEFAULT 0,                           \n" +
"                                                                     \n" +
"      PRIMARY KEY (identity_name)                                    \n" +
"  );                                                                 \n" +
"                                                                     \n" +
"CREATE INDEX identity_index ON Identity(identity_name);              \n";
  protected static final String INIT_KEY_TABLE =
"CREATE TABLE IF NOT EXISTS                                           \n" +
"  Key(                                                               \n" +
"      identity_name     BLOB NOT NULL,                               \n" +
"      key_identifier    BLOB NOT NULL,                               \n" +
"      key_type          INTEGER,                                     \n" +
"      public_key        BLOB,                                        \n" +
"      default_key       INTEGER DEFAULT 0,                           \n" +
"      active            INTEGER DEFAULT 0,                           \n" +
"                                                                     \n" +
"      PRIMARY KEY (identity_name, key_identifier)                    \n" +
"  );                                                                 \n" +
"                                                                     \n" +
"CREATE INDEX key_index ON Key(identity_name);                        \n";
  protected static final String INIT_CERT_TABLE =
"CREATE TABLE IF NOT EXISTS                                           \n" +
"  Certificate(                                                       \n" +
"      cert_name         BLOB NOT NULL,                               \n" +
"      cert_issuer       BLOB NOT NULL,                               \n" +
"      identity_name     BLOB NOT NULL,                               \n" +
"      key_identifier    BLOB NOT NULL,                               \n" +
"      not_before        TIMESTAMP,                                   \n" +
"      not_after         TIMESTAMP,                                   \n" +
"      certificate_data  BLOB NOT NULL,                               \n" +
"      valid_flag        INTEGER DEFAULT 1,                           \n" +
"      default_cert      INTEGER DEFAULT 0,                           \n" +
"                                                                     \n" +
"      PRIMARY KEY (cert_name)                                        \n" +
"  );                                                                 \n" +
"                                                                     \n" +
"CREATE INDEX cert_index ON Certificate(cert_name);           \n" +
"CREATE INDEX subject ON Certificate(identity_name);          \n";
  protected static final String SELECT_doesIdentityExist =
    "SELECT count(*) FROM Identity WHERE identity_name=?";
  protected static final String SELECT_doesKeyExist =
    "SELECT count(*) FROM Key WHERE identity_name=? AND key_identifier=?";
  protected static final String SELECT_getKey =
    "SELECT public_key FROM Key WHERE identity_name=? AND key_identifier=?";
  protected static final String SELECT_doesCertificateExist =
    "SELECT count(*) FROM Certificate WHERE cert_name=?";
  protected static final String SELECT_getCertificate =
    "SELECT certificate_data FROM Certificate WHERE cert_name=?";
  protected static final String SELECT_getDefaultIdentity =
    "SELECT identity_name FROM Identity WHERE default_identity=1";
  protected static final String SELECT_getDefaultKeyNameForIdentity =
    "SELECT key_identifier FROM Key WHERE identity_name=? AND default_key=1";
  protected static final String SELECT_getDefaultCertificateNameForKey =
    "SELECT cert_name FROM Certificate WHERE identity_name=? AND key_identifier=? AND default_cert=1";
    "SELECT key_identifier FROM Key WHERE default_key=1 and identity_name=?";
    "SELECT key_identifier FROM Key WHERE default_key=0 and identity_name=?";
  protected static final String WHERE_updateKeyStatus =
    "identity_name=? AND key_identifier=?";
  protected static final String WHERE_setDefaultIdentity_reset =
    "default_identity=1";
  protected static final String WHERE_setDefaultIdentity_set =
    "identity_name=?";
  protected static final String WHERE_setDefaultKeyNameForIdentity_reset =
    "default_key=1 and identity_name=?";
  protected static final String WHERE_setDefaultKeyNameForIdentity_set =
    "identity_name=? AND key_identifier=?";
  protected static final String WHERE_setDefaultCertificateNameForKey_reset =
    "default_cert=1 AND identity_name=? AND key_identifier=?";
  protected static final String WHERE_setDefaultCertificateNameForKey_set =
    "identity_name=? AND key_identifier=? AND cert_name=?";
  protected static final String WHERE_deleteCertificateInfo =
    "cert_name=?";
  protected static final String WHERE_deletePublicKeyInfo =
    "identity_name=? and key_identifier=?";
  protected static final String WHERE_deleteIdentityInfo =
    "identity_name=?";
New to GrepCode? Check out our FAQ X