java.lang.Object
net.i2p.crypto.DirKeyRing
All Implemented Interfaces:
KeyRing

public class DirKeyRingextends Object implements KeyRing
Simple storage of each cert in a separate file in a directory. Limited sanitization of filenames.
  • Field Details

    • _base

      private final File _base
      Directory the key files are read from and written to.
  • Constructor Details

    • DirKeyRing

      public DirKeyRing(File baseDir)
      Constructor for a read-only keyring on the local filesystem.
      Parameters:
      baseDir - the directory holding one subdirectory per scope
  • Method Details

    • getKey

      public PublicKey getKey(String keyName, String scope, SigType type) throws GeneralSecurityException, IOException
      Load a public key from the certificate in the given scope. Cert must be in the file (escaped keyName).crt, and have a CN == keyName.

      This DOES do a revocation check.

      CN check unsupported on Android.

      Specified by:
      getKey in interface KeyRing
      Parameters:
      keyName - the key name, also the expected certificate CN
      scope - the directory under the keyring base
      type - the expected signature type, checked against the cert's actual key type; null skips the check
      Returns:
      null if file doesn't exist, throws on all other errors
      Throws:
      GeneralSecurityException - if the stored key cannot be decoded
      IOException - if the backing store cannot be read
    • jcaAlgorithm

      private static SigAlgo jcaAlgorithm(String alg)
      Map a JCA public key algorithm name to a SigAlgo, or null if the name is not recognized (check is then skipped).
      Parameters:
      alg - the JCA public key algorithm name
      Returns:
      the matching signature algorithm, or null if unrecognized
    • setKey

      public void setKey(String keyName, String scope, PublicKey key)
      Store a public key. Unimplemented, unused - this ring is read-only.
      Specified by:
      setKey in interface KeyRing
      Parameters:
      keyName - the key name
      scope - the directory under the keyring base
      key - the key that would be stored, ignored