-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for ssh-ed25519 to jagged-ssh (#7)
- Loading branch information
1 parent
6b9315c
commit 0e3e6e4
Showing
51 changed files
with
3,089 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...c/main/java/com/exceptionfactory/jagged/framework/crypto/CryptographicKeyDescription.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright 2023 Jagged Contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.exceptionfactory.jagged.framework.crypto; | ||
|
||
/** | ||
* Abstraction for describing Cryptographic Key properties | ||
*/ | ||
public interface CryptographicKeyDescription { | ||
/** | ||
* Get key length in bytes | ||
* | ||
* @return Key length in bytes | ||
*/ | ||
int getKeyLength(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
jagged-ssh/src/main/java/com/exceptionfactory/jagged/ssh/Ed25519KeyConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright 2023 Jagged Contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.exceptionfactory.jagged.ssh; | ||
|
||
import com.exceptionfactory.jagged.framework.crypto.SharedSecretKey; | ||
|
||
import java.security.GeneralSecurityException; | ||
import java.security.PrivateKey; | ||
import java.security.PublicKey; | ||
|
||
/** | ||
* Abstraction for converting Ed25519 keys to X25519 keys | ||
*/ | ||
interface Ed25519KeyConverter { | ||
/** | ||
* Get X25519 Private Key from Ed25519 Private Key using first 32 bytes of SHA-512 digested key | ||
* | ||
* @param ed25519PrivateKey Ed25519 private key | ||
* @return X25519 Private Key | ||
* @throws GeneralSecurityException Thrown on failure to convert private key | ||
*/ | ||
PrivateKey getPrivateKey(Ed25519PrivateKey ed25519PrivateKey) throws GeneralSecurityException; | ||
|
||
/** | ||
* Get X25519 Private Key from SSH Ed25519 derived key | ||
* | ||
* @param derivedKey SSH Ed25519 derived key | ||
* @return X25519 Private Key | ||
* @throws GeneralSecurityException Thrown on failure to convert private key | ||
*/ | ||
PrivateKey getPrivateKey(SshEd25519DerivedKey derivedKey) throws GeneralSecurityException; | ||
|
||
/** | ||
* Get X25519 Public Key from Ed25519 Public Key computed using birational mapping described in RFC 7748 Section 4.1 | ||
* | ||
* @param ed25519PublicKey Ed25519 public key | ||
* @return X25519 Public Key | ||
* @throws GeneralSecurityException Thrown on failure to convert public key | ||
*/ | ||
PublicKey getPublicKey(Ed25519PublicKey ed25519PublicKey) throws GeneralSecurityException; | ||
|
||
/** | ||
* Get X25519 Public Key from computed Shared Secret Key | ||
* | ||
* @param sharedSecretKey Computed shared secret key | ||
* @return X25519 Public Key | ||
* @throws GeneralSecurityException Thrown on key processing failures | ||
*/ | ||
PublicKey getPublicKey(SharedSecretKey sharedSecretKey) throws GeneralSecurityException; | ||
} |
37 changes: 37 additions & 0 deletions
37
jagged-ssh/src/main/java/com/exceptionfactory/jagged/ssh/Ed25519KeyIndicator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright 2023 Jagged Contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.exceptionfactory.jagged.ssh; | ||
|
||
/** | ||
* Ed25519 Key indicator fields | ||
*/ | ||
enum Ed25519KeyIndicator { | ||
/** Algorithm */ | ||
KEY_ALGORITHM("Ed25519"), | ||
|
||
/** Format */ | ||
KEY_FORMAT("RAW"); | ||
|
||
private final String indicator; | ||
|
||
Ed25519KeyIndicator(final String indicator) { | ||
this.indicator = indicator; | ||
} | ||
|
||
String getIndicator() { | ||
return indicator; | ||
} | ||
} |
100 changes: 100 additions & 0 deletions
100
jagged-ssh/src/main/java/com/exceptionfactory/jagged/ssh/Ed25519PrivateKey.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* Copyright 2023 Jagged Contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.exceptionfactory.jagged.ssh; | ||
|
||
import java.security.PrivateKey; | ||
import java.util.Arrays; | ||
import java.util.Objects; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
/** | ||
* Ed25519 Private Key containing raw key bytes | ||
*/ | ||
class Ed25519PrivateKey implements PrivateKey { | ||
private static final byte ZERO = 0; | ||
|
||
private final AtomicBoolean destroyed = new AtomicBoolean(); | ||
|
||
private final byte[] encoded; | ||
|
||
/** | ||
* Ed25519 Private Key constructor with raw bytes containing private key seed | ||
* | ||
* @param encoded private key seed of 32 bytes | ||
*/ | ||
Ed25519PrivateKey(final byte[] encoded) { | ||
this.encoded = Objects.requireNonNull(encoded, "Encoded Key required"); | ||
} | ||
|
||
/** | ||
* Get algorithm describes the type of key | ||
* | ||
* @return Algorithm is Ed25519 | ||
*/ | ||
@Override | ||
public String getAlgorithm() { | ||
return Ed25519KeyIndicator.KEY_ALGORITHM.getIndicator(); | ||
} | ||
|
||
/** | ||
* Get format describes the encoded content bytes | ||
* | ||
* @return Encoded key format is RAW | ||
*/ | ||
@Override | ||
public String getFormat() { | ||
return Ed25519KeyIndicator.KEY_FORMAT.getIndicator(); | ||
} | ||
|
||
/** | ||
* Get encoded key bytes consisting of private key seed | ||
* | ||
* @return encoded private key array of 32 bytes | ||
*/ | ||
@Override | ||
public byte[] getEncoded() { | ||
return encoded.clone(); | ||
} | ||
|
||
/** | ||
* Get string representation of key algorithm | ||
* | ||
* @return Key algorithm | ||
*/ | ||
@Override | ||
public String toString() { | ||
return getAlgorithm(); | ||
} | ||
|
||
/** | ||
* Destroy Key so that it cannot be used for subsequent operations | ||
*/ | ||
@Override | ||
public void destroy() { | ||
Arrays.fill(encoded, ZERO); | ||
destroyed.set(true); | ||
} | ||
|
||
/** | ||
* Return destroyed status | ||
* | ||
* @return Key destroyed status | ||
*/ | ||
@Override | ||
public boolean isDestroyed() { | ||
return destroyed.get(); | ||
} | ||
} |
Oops, something went wrong.