-
Notifications
You must be signed in to change notification settings - Fork 195
When adding an identity, validate that private key and public key (or… #1168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
5251950
eeb4b20
36bcde0
fd18b36
49ba149
3c8e6dc
bb832f0
c88ad15
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| package com.jcraft.jsch; | ||
|
|
||
| import static com.jcraft.jsch.ResourceUtil.getResourceFile; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| /** | ||
| * Unit tests for openssh certificate key compatibility: does public key signed by certificate match | ||
| * private key | ||
| */ | ||
| public class OpenSshCertificateKeyCompatTest { | ||
|
Check warning on line 12 in src/test/java/com/jcraft/jsch/OpenSshCertificateKeyCompatTest.java
|
||
|
|
||
| /** | ||
| * Test that adding an identity of a private key with matching user certificate succeeds | ||
| */ | ||
| @Test | ||
| public void testCheckPrivKeyWithMatchingUserCert() throws Exception { | ||
| JSch jsch = new JSch(); | ||
| jsch.addIdentity(getResourceFile("certificates/ed25519/root_ed25519_key"), | ||
| getResourceFile("certificates/ed25519/root_ed25519_key-cert.pub"), null); | ||
| } | ||
|
|
||
| /** | ||
| * Test that adding an identity of a private key with unmatching user certificate fails | ||
| */ | ||
| @Test | ||
| public void testCheckPrivKeyWithNonMatchingUserCert() throws Exception { | ||
|
Check warning on line 28 in src/test/java/com/jcraft/jsch/OpenSshCertificateKeyCompatTest.java
|
||
| JSch jsch = new JSch(); | ||
| assertThrows(JSchException.class, | ||
|
|
||
| () -> jsch.addIdentity(getResourceFile("docker/id_ed25519"), | ||
| getResourceFile("certificates/ed25519/root_ed25519_key-cert.pub"), null)); | ||
| } | ||
|
|
||
| /** | ||
| * Test that adding an identity of a private key with matching public key succeeds | ||
| */ | ||
| @Test | ||
| public void testCheckPrivKeyWithMatchingPubKey() throws Exception { | ||
| JSch jsch = new JSch(); | ||
| jsch.addIdentity(getResourceFile("docker/id_ed25519"), getResourceFile("docker/id_ed25519.pub"), | ||
| null); | ||
| } | ||
|
|
||
| /** | ||
| * Test that adding an identity of a private key with non-matching public key fails | ||
| */ | ||
| @Test | ||
| public void testCheckPrivKeyWithNonMatchingPubKey() throws Exception { | ||
|
Check warning on line 50 in src/test/java/com/jcraft/jsch/OpenSshCertificateKeyCompatTest.java
|
||
| JSch jsch = new JSch(); | ||
| assertThrows(JSchException.class, | ||
|
|
||
| () -> jsch.addIdentity(getResourceFile("docker/id_ed25519"), | ||
| getResourceFile("certificates/ed25519/root_ed25519_key.pub"), null)); | ||
| } | ||
|
|
||
| /** | ||
| * Test that adding an identity of a private key with something that is neither a public key nor a | ||
| * certificate fails | ||
| */ | ||
| @Test | ||
| public void testCheckPrivKeyWithNonPubKey() throws Exception { | ||
|
Check warning on line 63 in src/test/java/com/jcraft/jsch/OpenSshCertificateKeyCompatTest.java
|
||
| JSch jsch = new JSch(); | ||
| assertThrows(JSchException.class, | ||
|
|
||
| () -> jsch.addIdentity(getResourceFile("docker/id_ed25519"), | ||
| getResourceFile("certificates/host/sshd_config"), null)); | ||
| } | ||
|
|
||
|
|
||
| private String getResourceFile(String fileName) { | ||
| return ResourceUtil.getResourceFile(getClass(), fileName); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.