Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2014-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;
 
IdentityStorage is a base class for the storage of identity, public keys and certificates. Private keys are stored in PrivateKeyStorage. This is an abstract base class. A subclass must implement the methods.
 
 public abstract class IdentityStorage {
  
Check if the specified identity already exists.

Parameters:
identityName The identity name.
Returns:
True if the identity exists, otherwise false.
 
   public abstract boolean
   doesIdentityExist(Name identityNamethrows SecurityException;

  
Add a new identity. Do nothing if the identity already exists.

Parameters:
identityName The identity name to be added.
 
   public abstract void
   addIdentity(Name identityNamethrows SecurityException;

  
Revoke the identity.

Returns:
True if the identity was revoked, false if not.
 
   public abstract boolean
   revokeIdentity() throws SecurityException;

  
Generate a name for a new key belonging to the identity.

Parameters:
identityName The identity name.
useKsk If true, generate a KSK name, otherwise a DSK name.
Returns:
The generated key name.
 
   public final Name
   getNewKeyName(Name identityNameboolean useKskthrows SecurityException
   {
     long timestamp = (long)Math.floor(Common.getNowMilliseconds());
     while (timestamp <= )
       // Make the timestamp unique.
       timestamp += 1;
      = timestamp;
 
     // Get the number of seconds as a string.
     String timeString = "" + timestamp;
 
     String keyIdStr;
     if (useKsk)
       keyIdStr = ("KSK-" + timeString);
     else
       keyIdStr = ("DSK-" + timeString);
 
     Name keyName = new Name(identityName).append(keyIdStr);
 
     if (doesKeyExist(keyName))
       throw new SecurityException("Key name already exists");
 
     return keyName;
   }

  
Check if the specified key already exists.

Parameters:
keyName The name of the key.
Returns:
true if the key exists, otherwise false.
 
   public abstract boolean
   doesKeyExist(Name keyNamethrows SecurityException;

  
Add a public key to the identity storage. Also call addIdentity to ensure that the identityName for the key exists.

Parameters:
keyName The name of the public key to be added.
keyType Type of the public key to be added.
publicKeyDer A blob of the public key DER to be added.
Throws:
net.named_data.jndn.security.SecurityException if a key with the keyName already exists.
  public abstract void
  addKey(Name keyNameKeyType keyTypeBlob publicKeyDerthrows SecurityException;

  
Get the public key DER blob from the identity storage.

Parameters:
keyName The name of the requested public key.
Returns:
The DER Blob. If not found, return a Blob with a null pointer.
  public abstract Blob
  getKey(Name keyNamethrows SecurityException;

  
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 abstract void
  activateKey(Name keyNamethrows SecurityException;

  
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 abstract void
  deactivateKey(Name keyNamethrows SecurityException;

  
Check if the specified certificate already exists.

Parameters:
certificateName The name of the certificate.
Returns:
True if the certificate exists, otherwise false.
  public abstract boolean
  doesCertificateExist(Name certificateNamethrows SecurityException;

  
Add a certificate to the identity storage.

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.
  public abstract void
Get a certificate from the identity storage.

Parameters:
certificateName The name of the requested certificate.
allowAny If false, only a valid certificate will be returned, otherwise validity is disregarded.
Returns:
The requested certificate. If not found, return null.
  public abstract IdentityCertificate
  getCertificate(Name certificateNameboolean allowAnythrows SecurityException;

  
Get a certificate from the identity storage, requiring only a valid certificate to be returned.

Parameters:
certificateName The name of the requested certificate.
Returns:
The requested certificate. If not found, return null.
  public final IdentityCertificate
  getCertificate(Name certificateNamethrows SecurityException
  {
    return getCertificate(certificateNamefalse);
  }

  
Get/Set Default * /


  
Get the default identity.

Returns:
The name of default identity.
Throws:
net.named_data.jndn.security.SecurityException if the default identity is not set.
  public abstract Name
Get the default key name for the specified identity.

Parameters:
identityName The identity name.
Returns:
The default key name.
Throws:
net.named_data.jndn.security.SecurityException if the default key name for the identity is not set.
  public abstract Name
  getDefaultKeyNameForIdentity(Name identityNamethrows SecurityException;

  
Get the default certificate name for the specified identity.

Parameters:
identityName The identity name.
Returns:
The default certificate name.
Throws:
net.named_data.jndn.security.SecurityException if the default key name for the identity is not set or the default certificate name for the key name is not set.
  public final Name
  {
    Name keyName = getDefaultKeyNameForIdentity(identityName);
    return getDefaultCertificateNameForKey(keyName);
  }

  
Get the default certificate name for the specified key.

Parameters:
keyName The key name.
Returns:
The default certificate name.
Throws:
net.named_data.jndn.security.SecurityException if the default certificate name for the key name is not set.
  public abstract Name
Append all the key names of a particular identity to the nameList.

Parameters:
identityName The identity name to search for.
nameList Append result names to nameList.
isDefault If true, add only the default key name. If false, add only the non-default key names.
  public abstract void
    (Name identityNameArrayList nameListboolean isDefaultthrows SecurityException;

  
Set the default identity. If the identityName does not exist, then clear the default identity so that getDefaultIdentity() throws an exception.

Parameters:
identityName The default identity name.
  public abstract void
  setDefaultIdentity(Name identityNamethrows SecurityException;

  
Set the default key name for the specified identity.

Parameters:
keyName The key name.
identityNameCheck The identity name to check the keyName.
  public abstract void
  setDefaultKeyNameForIdentity(Name keyNameName identityNameCheckthrows SecurityException;

  
Set the default key name for the specified identity.

Parameters:
keyName The key name.
  public final void
  {
    setDefaultKeyNameForIdentity(keyNamenew Name());
  }

  
Set the default key name for the specified identity.

Parameters:
keyName The key name.
certificateName The certificate name.
  public abstract void
  setDefaultCertificateNameForKey(Name keyNameName certificateNamethrows SecurityException;

  
Delete Methods * /


  
Delete a certificate.

Parameters:
certificateName The certificate name.
  public abstract void
  deleteCertificateInfo(Name certificateNamethrows SecurityException;

  
Delete a public key and related certificates.

Parameters:
keyName The key name.
  public abstract void
  deletePublicKeyInfo(Name keyNamethrows SecurityException;

  
Delete an identity and related public keys and certificates.

Parameters:
identity The identity name.
  public abstract void
  private static long lastTimestamp_ =
    (long)Math.floor(Common.getNowMilliseconds());
New to GrepCode? Check out our FAQ X