Package io.deephaven.enterprise.auth
Class KeyPairFile
java.lang.Object
io.deephaven.enterprise.auth.KeyPairFile
- Direct Known Subclasses:
PubKeyFile
A public and private key used to authenticate to Deephaven.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final byte[]
If the key bytes start with "EC:", then we treat the key as an ECDSA key; otherwise we assume it is DSA.static final String
The tag for the "operateas" line in a private key file, which is the user to operate as after authentication.static final String
The tag for the "private" line in a private key file, which contains the DER encoded private key.static final String
The tag for the "public" line in a private key file, which contains the DER encoded public key.static final String
The tag for the "user" line in a private key file, which is the user to authenticate as. -
Constructor Summary
ConstructorsConstructorDescriptionKeyPairFile
(String privateKeyFileOrResource) KeyPairFile
(String[] privateKeyLines) KeyPairFile
(String source, Map<String, String> keyLines) -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
addEcSentinel
(byte[] encoded) Add "EC" sentinel to encoded keystatic KeyPairFile
generateNewKeys
(String privateKeyFile, String publicKeyFile, String user) Generates a new ECDSA public and private key pair and writes it in Deephaven format.static KeyPairFile
generateNewKeys
(String privateKeyFile, String publicKeyFile, String user, String operateAs) Generates a new ECDSA public and private key pair and writes it in Deephaven format.byte[]
getSignedBytes
(byte[] bytes) getUser()
static boolean
hasEcSentinel
(byte[] x509encoded) Returns true if the byte array begins with the "EC:" sentinelstatic String
maybeAddSentinelAndBase64Encode
(PublicKey publicKey) Encode publicKey into a base64 string, possibly adding the EC sentinel as appropriate.static byte[]
maybeAddSentinelAndEncode
(PublicKey publicKey) Encode publicKey, adding the EC sentinel as appropriate.readFromStream
(InputStream keyInputStream, String sourceDescription) readKeyLines
(Class clazz, String privateKeyFileOrResource) static byte[]
stripEcSentinel
(byte[] encoded) Remove "EC:" from the beginning of the encoded key.
-
Field Details
-
USER_TAG
The tag for the "user" line in a private key file, which is the user to authenticate as.- See Also:
-
OPERATEAS_TAG
The tag for the "operateas" line in a private key file, which is the user to operate as after authentication.- See Also:
-
PRIVATE_TAG
The tag for the "private" line in a private key file, which contains the DER encoded private key.- See Also:
-
PUBLIC_TAG
The tag for the "public" line in a private key file, which contains the DER encoded public key.- See Also:
-
EC_SENTINEL
public static final byte[] EC_SENTINELIf the key bytes start with "EC:", then we treat the key as an ECDSA key; otherwise we assume it is DSA.
-
-
Constructor Details
-
KeyPairFile
-
KeyPairFile
-
KeyPairFile
-
-
Method Details
-
readKeyLines
-
readFromStream
public static Map<String,String> readFromStream(@NotNull InputStream keyInputStream, String sourceDescription) throws IOException - Throws:
IOException
-
hasEcSentinel
public static boolean hasEcSentinel(byte[] x509encoded) Returns true if the byte array begins with the "EC:" sentinel- Parameters:
x509encoded
- the encoded key, possibly prepended with "EC:"- Returns:
- true if we should decode this as an EC key, after calling stripEcSentinel
-
stripEcSentinel
public static byte[] stripEcSentinel(byte[] encoded) Remove "EC:" from the beginning of the encoded key. The encoded array must begin with "EC:" or result are undefined.- Parameters:
encoded
- the encoded key with the sentinel- Returns:
- the encoded key without the sentinel
-
addEcSentinel
public static byte[] addEcSentinel(byte[] encoded) Add "EC" sentinel to encoded key- Parameters:
encoded
- the encoded key- Returns:
- the encoded key prepended with "EC:"
-
maybeAddSentinelAndBase64Encode
Encode publicKey into a base64 string, possibly adding the EC sentinel as appropriate.- Parameters:
publicKey
- the public key to encode- Returns:
- an encoded string of the public key
-
maybeAddSentinelAndEncode
Encode publicKey, adding the EC sentinel as appropriate.- Parameters:
publicKey
- the public key to encode- Returns:
- an encoded public key
-
getUser
-
getOperateAs
-
getPublicKey
-
getPrivateKey
-
getSignedBytes
public byte[] getSignedBytes(byte[] bytes) throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeyException, SignatureException -
generateNewKeys
public static KeyPairFile generateNewKeys(String privateKeyFile, String publicKeyFile, String user) throws NoSuchAlgorithmException, NoSuchProviderException, IOException Generates a new ECDSA public and private key pair and writes it in Deephaven format.This method delegates to
generateNewKeys(String, String, String, String)
, with a value for operateas that is equal to user.To use the key, you must store the public key in the ACL database.
- Parameters:
privateKeyFile
- the destination for the private key filepublicKeyFile
- the destination for the public key fileuser
- the username to write to the key file- Returns:
- a KeyPairFile with the new key
- Throws:
NoSuchAlgorithmException
NoSuchProviderException
IOException
-
generateNewKeys
public static KeyPairFile generateNewKeys(String privateKeyFile, String publicKeyFile, String user, String operateAs) throws NoSuchAlgorithmException, NoSuchProviderException, IOException Generates a new ECDSA public and private key pair and writes it in Deephaven format.To use the key, you must store the public key in the ACL database.
- Parameters:
privateKeyFile
- the destination for the private key filepublicKeyFile
- the destination for the public key fileuser
- the username to write to the key fileoperateAs
- the user to operate as after authentication- Returns:
- a KeyPairFile with the new key
- Throws:
NoSuchAlgorithmException
NoSuchProviderException
IOException
-