-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework authorizedPublicKeys to make it a resource instead of a file
- Loading branch information
Showing
15 changed files
with
123 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
lombok.log.fieldName=LOGGER | ||
lombok.log.fieldName=LOGGER | ||
lombok.equalsandhashcode.callsuper=CALL |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDlkW3hZVrrOPjcswznq5WDbF8IV3iEZo4EP2A9Ofl2dqqfKhgObDQuMUQN1OebBpUCo9W13CUle1ca7AdXJY4ZU62+YJCDKy9+hSz+KWfl7kJx+StL57sv3ProC3n7gAH+uedY6pSlHr6zTjsiEyGZbaKaSShFBX0ta3j+vZ11T+bxyK3j7BFJ2YcUa4ys+gphm3by/LV6xEhr3tohnFhfO5COKrEYqYC97EjsgDhcaFtpzjOnFoYC+HDCAFCwKWJj+Puu9qNj+NlT0gX4DuVFbWEEwH2ZB+qhk5/b75pAGLikRTK9lPLrTX0MX283lAWrD84d6xKWZaqrcxoP1HBnTCaqs5XGrXN81UP2EK+3KYNcNoIwN9x5UABOc1vDfK91IyYNgheVl8NT+T7TYNNj27piXFlvSgDx5dmuqBopYri+IqS17KJXaVgRjbdAwkWHNCqqSW9RoGDxUWlYgOh7KhNlN2m4AcW9YMEd1z2WWaYQpevYG3p3GGEZ8Av5Hbk= [email protected] |
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
73 changes: 73 additions & 0 deletions
73
...t/java/com/github/fonimus/ssh/shell/auth/SshShellPublicKeyAuthenticationProviderTest.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,73 @@ | ||
package com.github.fonimus.ssh.shell.auth; | ||
|
||
import org.apache.sshd.common.io.IoSession; | ||
import org.apache.sshd.server.session.ServerSession; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.core.io.ClassPathResource; | ||
import org.springframework.core.io.FileSystemResource; | ||
|
||
import java.io.File; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.security.KeyFactory; | ||
import java.security.PublicKey; | ||
import java.security.spec.X509EncodedKeySpec; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
class SshShellPublicKeyAuthenticationProviderTest { | ||
|
||
private static PublicKey pub; | ||
private static PublicKey wrongPub; | ||
|
||
private SshShellPublicKeyAuthenticationProvider pubKeyAuthProv; | ||
|
||
@BeforeAll | ||
public static void init() throws Exception { | ||
KeyFactory kf = KeyFactory.getInstance("RSA"); | ||
pub = kf.generatePublic(new X509EncodedKeySpec(Files.readAllBytes(Paths.get("src/test/resources/.ssh/pub.der")))); | ||
wrongPub = kf.generatePublic(new X509EncodedKeySpec(Files.readAllBytes(Paths.get("src/test/resources/.ssh/wrong_pub.der")))); | ||
} | ||
|
||
@Test | ||
public void testFile() throws Exception { | ||
File file = new File("src/test/resources/.ssh/authorized.keys"); | ||
assertTrue(file.exists()); | ||
internalTest(file); | ||
} | ||
|
||
@Test | ||
public void testSpringFileResource() throws Exception { | ||
FileSystemResource resource = new FileSystemResource("src/test/resources/.ssh/authorized.keys"); | ||
assertTrue(resource.exists()); | ||
internalTest(resource.getFile()); | ||
} | ||
|
||
@Test | ||
public void testSpringClasspathResource() throws Exception { | ||
ClassPathResource resource = new ClassPathResource(".ssh/authorized.keys"); | ||
assertTrue(resource.exists()); | ||
internalTest(resource.getFile()); | ||
} | ||
|
||
@Test | ||
public void testNotExisting() throws Exception { | ||
pubKeyAuthProv = new SshShellPublicKeyAuthenticationProvider(new File("not-existing")); | ||
assertFalse(pubKeyAuthProv.exists()); | ||
assertEquals(-1, pubKeyAuthProv.size()); | ||
} | ||
|
||
private void internalTest(File file) throws Exception { | ||
pubKeyAuthProv = new SshShellPublicKeyAuthenticationProvider(file); | ||
assertTrue(pubKeyAuthProv.exists()); | ||
ServerSession session = mock(ServerSession.class); | ||
IoSession io = mock(IoSession.class); | ||
when(session.getIoSession()).thenReturn(io); | ||
assertTrue(pubKeyAuthProv.authenticate("user", pub, session)); | ||
assertFalse(pubKeyAuthProv.authenticate("user", wrongPub, session)); | ||
} | ||
|
||
} |
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 @@ | ||
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDlkW3hZVrrOPjcswznq5WDbF8IV3iEZo4EP2A9Ofl2dqqfKhgObDQuMUQN1OebBpUCo9W13CUle1ca7AdXJY4ZU62+YJCDKy9+hSz+KWfl7kJx+StL57sv3ProC3n7gAH+uedY6pSlHr6zTjsiEyGZbaKaSShFBX0ta3j+vZ11T+bxyK3j7BFJ2YcUa4ys+gphm3by/LV6xEhr3tohnFhfO5COKrEYqYC97EjsgDhcaFtpzjOnFoYC+HDCAFCwKWJj+Puu9qNj+NlT0gX4DuVFbWEEwH2ZB+qhk5/b75pAGLikRTK9lPLrTX0MX283lAWrD84d6xKWZaqrcxoP1HBnTCaqs5XGrXN81UP2EK+3KYNcNoIwN9x5UABOc1vDfK91IyYNgheVl8NT+T7TYNNj27piXFlvSgDx5dmuqBopYri+IqS17KJXaVgRjbdAwkWHNCqqSW9RoGDxUWlYgOh7KhNlN2m4AcW9YMEd1z2WWaYQpevYG3p3GGEZ8Av5Hbk= [email protected] |
Binary file not shown.
Binary file not shown.