Class SecretKeys
java.lang.Object
org.eclipse.jgit.gpg.bc.internal.keys.SecretKeys
Utilities for reading GPG secret keys from a gpg-agent key file.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Something that can supply a passphrase to decrypt an encrypted secret key. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final byte[]
private static final byte[]
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static byte[]
convertSexpression
(byte[] humanForm) Converts a human-readable serialized s-expression into a binary serialized s-expression.private static byte[]
convertSexpression
(byte[] humanForm, boolean[] isOCB) Converts a human-readable serialized s-expression into a binary serialized s-expression.private static byte[]
dequote
(byte[] in, int from, int to) GPG-style string de-quoting, which is basically C-style, with some literal CR/LF escaping.private static byte[]
getAad
(byte[] sExp) Extract the AAD for the OCB decryption from an s-expression.private static boolean
isGpgSpace
(int ch) private static boolean
isHex
(int ch) private static boolean
isOctal
(int ch) private static boolean
isTokenChar
(int ch) (package private) static byte[]
Extracts the key from a GPG name-value-pair key file.private static boolean
matches
(byte[] src, int from, byte[] needle) Checks whether theneedle
matchessrc
at offsetfrom
.private static int
nibble
(int ch) static org.bouncycastle.openpgp.PGPSecretKey
readSecretKey
(InputStream in, org.bouncycastle.openpgp.operator.PGPDigestCalculatorProvider calculatorProvider, SecretKeys.PassphraseSupplier passphraseSupplier, org.bouncycastle.openpgp.PGPPublicKey publicKey) Reads a GPG secret key from the given stream.private static int
skip
(byte[] sExp, int start) Skips a list including nested lists.
-
Field Details
-
PROTECTED_KEY
private static final byte[] PROTECTED_KEY -
OCB_PROTECTED
private static final byte[] OCB_PROTECTED
-
-
Constructor Details
-
SecretKeys
private SecretKeys()
-
-
Method Details
-
readSecretKey
public static org.bouncycastle.openpgp.PGPSecretKey readSecretKey(InputStream in, org.bouncycastle.openpgp.operator.PGPDigestCalculatorProvider calculatorProvider, SecretKeys.PassphraseSupplier passphraseSupplier, org.bouncycastle.openpgp.PGPPublicKey publicKey) throws IOException, org.bouncycastle.openpgp.PGPException, CanceledException, UnsupportedCredentialItem, URISyntaxException Reads a GPG secret key from the given stream.- Parameters:
in
-InputStream
to read from, doesn't need to be bufferedcalculatorProvider
- for checking digestspassphraseSupplier
- for decrypting encrypted keyspublicKey
- the secret key should be for- Returns:
- the secret key
- Throws:
IOException
- if the stream cannot be parsedorg.bouncycastle.openpgp.PGPException
- if thrown by the underlying S-Expression parser, for instance when the passphrase is wrongCanceledException
- if thrown by thepassphraseSupplier
UnsupportedCredentialItem
- if thrown by thepassphraseSupplier
URISyntaxException
- if thrown by thepassphraseSupplier
-
getAad
private static byte[] getAad(byte[] sExp) Extract the AAD for the OCB decryption from an s-expression.- Parameters:
sExp
- buffer containing a valid binary s-expression- Returns:
- the AAD
-
skip
private static int skip(byte[] sExp, int start) Skips a list including nested lists.- Parameters:
sExp
- buffer containing valid binary s-expression datastart
- index of the opening '(' of the list to skip- Returns:
- the index after the closing ')' of the skipped list
-
matches
private static boolean matches(byte[] src, int from, byte[] needle) Checks whether theneedle
matchessrc
at offsetfrom
.- Parameters:
src
- to match againstneedle
from
- position insrc
to start matchingneedle
- to match against- Returns:
true
ifsrc
containsneedle
at positionfrom
,false
otherwise
-
convertSexpression
Converts a human-readable serialized s-expression into a binary serialized s-expression.- Parameters:
humanForm
- to convert- Returns:
- the converted s-expression
- Throws:
IOException
- if the conversion fails
-
convertSexpression
Converts a human-readable serialized s-expression into a binary serialized s-expression.- Parameters:
humanForm
- to convertisOCB
- returns whether the s-expression specified AES/OCB encryption- Returns:
- the converted s-expression
- Throws:
IOException
- if the conversion fails
-
dequote
GPG-style string de-quoting, which is basically C-style, with some literal CR/LF escaping.- Parameters:
in
- buffer containing the quoted stringfrom
- index after the opening quote inin
to
- index of the closing quote inin
- Returns:
- the dequoted raw string value
- Throws:
StreamCorruptedException
-
keyFromNameValueFormat
Extracts the key from a GPG name-value-pair key file.Package-visible for tests only.
- Parameters:
in
-InputStream
to read from; should be buffered- Returns:
- the raw key data as extracted from the file
- Throws:
IOException
- if thein
stream cannot be read or does not contain a key
-
isGpgSpace
private static boolean isGpgSpace(int ch) -
isTokenChar
private static boolean isTokenChar(int ch) -
isHex
private static boolean isHex(int ch) -
isOctal
private static boolean isOctal(int ch) -
nibble
private static int nibble(int ch)
-