Class SExprParser

java.lang.Object
org.eclipse.jgit.gpg.bc.internal.keys.SExprParser

public class SExprParser extends Object
A parser for secret keys stored in s-expressions. Original BouncyCastle code modified by the JGit team to:
  • handle unencrypted DSA, EC, and ElGamal keys (upstream only handles unencrypted RSA), and
  • handle secret keys using AES/OCB as encryption (those don't have a hash).
  • Field Details

    • digestProvider

      private final org.bouncycastle.openpgp.operator.PGPDigestCalculatorProvider digestProvider
  • Constructor Details

    • SExprParser

      public SExprParser(org.bouncycastle.openpgp.operator.PGPDigestCalculatorProvider digestProvider)
      Base constructor.
      Parameters:
      digestProvider - a provider for digest calculations. Used to confirm key protection hashes.
  • Method Details

    • parseSecretKey

      public org.bouncycastle.openpgp.PGPSecretKey parseSecretKey(InputStream inputStream, org.bouncycastle.openpgp.operator.PBEProtectionRemoverFactory keyProtectionRemoverFactory, org.bouncycastle.openpgp.PGPPublicKey pubKey) throws IOException, org.bouncycastle.openpgp.PGPException
      Parse a secret key from one of the GPG S expression keys associating it with the passed in public key.
      Parameters:
      inputStream - to read from
      keyProtectionRemoverFactory - for decrypting encrypted keys
      pubKey - the private key should belong to
      Returns:
      a secret key object.
      Throws:
      IOException
      org.bouncycastle.openpgp.PGPException
    • parseSecretKey

      public org.bouncycastle.openpgp.PGPSecretKey parseSecretKey(InputStream inputStream, org.bouncycastle.openpgp.operator.PBEProtectionRemoverFactory keyProtectionRemoverFactory, org.bouncycastle.openpgp.operator.KeyFingerPrintCalculator fingerPrintCalculator) throws IOException, org.bouncycastle.openpgp.PGPException
      Parse a secret key from one of the GPG S expression keys.
      Parameters:
      inputStream - to read from
      keyProtectionRemoverFactory - for decrypting encrypted keys
      fingerPrintCalculator - for calculating key fingerprints
      Returns:
      a secret key object.
      Throws:
      IOException
      org.bouncycastle.openpgp.PGPException
    • readBigInteger

      private BigInteger readBigInteger(String expectedType, InputStream inputStream) throws IOException, org.bouncycastle.openpgp.PGPException
      Throws:
      IOException
      org.bouncycastle.openpgp.PGPException
    • extractData

      private static byte[][] extractData(InputStream inputStream, org.bouncycastle.openpgp.operator.PBEProtectionRemoverFactory keyProtectionRemoverFactory) throws org.bouncycastle.openpgp.PGPException, IOException
      Throws:
      org.bouncycastle.openpgp.PGPException
      IOException
    • processDSASecretKey

      private BigInteger processDSASecretKey(InputStream inputStream, BigInteger p, BigInteger q, BigInteger g, BigInteger y, org.bouncycastle.openpgp.operator.PBEProtectionRemoverFactory keyProtectionRemoverFactory) throws IOException, org.bouncycastle.openpgp.PGPException
      Throws:
      IOException
      org.bouncycastle.openpgp.PGPException
    • processElGamalSecretKey

      private BigInteger processElGamalSecretKey(InputStream inputStream, BigInteger p, BigInteger g, BigInteger y, org.bouncycastle.openpgp.operator.PBEProtectionRemoverFactory keyProtectionRemoverFactory) throws IOException, org.bouncycastle.openpgp.PGPException
      Throws:
      IOException
      org.bouncycastle.openpgp.PGPException
    • processECSecretKey

      private BigInteger processECSecretKey(InputStream inputStream, String curveID, String curveName, byte[] qVal, org.bouncycastle.openpgp.operator.PBEProtectionRemoverFactory keyProtectionRemoverFactory) throws IOException, org.bouncycastle.openpgp.PGPException
      Throws:
      IOException
      org.bouncycastle.openpgp.PGPException
    • processRSASecretKey

      private BigInteger[] processRSASecretKey(InputStream inputStream, BigInteger n, BigInteger e, org.bouncycastle.openpgp.operator.PBEProtectionRemoverFactory keyProtectionRemoverFactory) throws IOException, org.bouncycastle.openpgp.PGPException
      Throws:
      IOException
      org.bouncycastle.openpgp.PGPException
    • writeCanonical

      private void writeCanonical(OutputStream dOut, String label, BigInteger i) throws IOException
      Throws:
      IOException
    • writeCanonical

      private void writeCanonical(OutputStream dOut, String label, byte[] data) throws IOException
      Throws:
      IOException