-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
538 additions
and
94 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
sshsig-bcprov/SshPublicKeyEncoderTest (bcprov)(JDK17).launch
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,24 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<launchConfiguration type="org.eclipse.jdt.junit.launchconfig"> | ||
<booleanAttribute key="org.eclipse.debug.core.ATTR_FORCE_SYSTEM_CONSOLE_ENCODING" value="false"/> | ||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"> | ||
<listEntry value="/sshsig-bcprov/src/test/java/de/profhenry/sshsig/bcprov/SshPublicKeyEncoderTest.java"/> | ||
</listAttribute> | ||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"> | ||
<listEntry value="1"/> | ||
</listAttribute> | ||
<stringAttribute key="org.eclipse.debug.core.SOURCE_PATH_COMPUTER_ID" value="de.gebit.maven.osgi.launcher.plugin.sourcelookup.patchedJavaSourcePathComputer"/> | ||
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/> | ||
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/> | ||
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/> | ||
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit5"/> | ||
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_ATTR_USE_ARGFILE" value="false"/> | ||
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_SHOW_CODEDETAILS_IN_EXCEPTION_MESSAGES" value="true"/> | ||
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_CLASSPATH_ONLY_JAR" value="false"/> | ||
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.m2e.launchconfig.classpathProvider"/> | ||
<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17/"/> | ||
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="de.profhenry.sshsig.bcprov.SshPublicKeyEncoderTest"/> | ||
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="sshsig-bcprov"/> | ||
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.m2e.launchconfig.sourcepathProvider"/> | ||
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-ea"/> | ||
</launchConfiguration> |
20 changes: 20 additions & 0 deletions
20
sshsig-bcprov/SshPublicKeyEncoderTest (bcprov)(JDK8).launch
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,20 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<launchConfiguration type="org.eclipse.jdt.junit.launchconfig"> | ||
<booleanAttribute key="org.eclipse.debug.core.ATTR_FORCE_SYSTEM_CONSOLE_ENCODING" value="false"/> | ||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"> | ||
<listEntry value="/sshsig-bcprov/src/test/java/de/profhenry/sshsig/bcprov/SshPublicKeyEncoderTest.java"/> | ||
</listAttribute> | ||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"> | ||
<listEntry value="1"/> | ||
</listAttribute> | ||
<stringAttribute key="org.eclipse.debug.core.SOURCE_PATH_COMPUTER_ID" value="de.gebit.maven.osgi.launcher.plugin.sourcelookup.patchedJavaSourcePathComputer"/> | ||
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/> | ||
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/> | ||
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/> | ||
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit5"/> | ||
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.m2e.launchconfig.classpathProvider"/> | ||
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="de.profhenry.sshsig.bcprov.SshPublicKeyEncoderTest"/> | ||
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="sshsig-bcprov"/> | ||
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.m2e.launchconfig.sourcepathProvider"/> | ||
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-ea"/> | ||
</launchConfiguration> |
78 changes: 78 additions & 0 deletions
78
sshsig-bcprov/src/test/java/de/profhenry/sshsig/bcprov/SshPublicKeyEncoderTest.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,78 @@ | ||
/* | ||
* Copyright 2023 Jan Henrik Wiesner | ||
* | ||
* 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 de.profhenry.sshsig.bcprov; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.security.PublicKey; | ||
import java.security.Security; | ||
|
||
import org.bouncycastle.jce.provider.BouncyCastleProvider; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Disabled; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import de.profhenry.sshsig.core.SshPublicKeyEncoder; | ||
|
||
/** | ||
* Unit tests for {@link SshPublicKeyEncoder}. | ||
* <p> | ||
* | ||
* @author profhenry | ||
*/ | ||
public class SshPublicKeyEncoderTest { | ||
|
||
@BeforeAll | ||
static void setup() { | ||
Security.addProvider(new BouncyCastleProvider()); | ||
} | ||
|
||
@Test | ||
@Disabled | ||
void testEncodeDsaPublicKey() throws Exception { | ||
PublicKey tPublicKey = SshKeyUtil.readDsaKeyPair().getPublic(); | ||
|
||
SshPublicKeyEncoder tPublicKeyEncoder = new SshPublicKeyEncoder(); | ||
byte[] tSshEncodedPublicKey = tPublicKeyEncoder.encodePublicKey(tPublicKey); | ||
|
||
assertThat(tSshEncodedPublicKey).asBase64Encoded() | ||
.isEqualTo( | ||
"AAAAB3NzaC1kc3MAAACBAP8BC5pi3uxvOtlb1ikWNeLUubiaT0l7aMOhAbOFmtivswcg0r+rZiX/UOjhxCATRiaTXV42byLnf0cKzQrZ5QEnm8uTf1aK0gdT/bdQaZwWmkMB2LdHQ4xEt3slsDLYoXwwzV+stpRcFQ1VyUlJQV754HqHZT8RbkUBJHIsIqslAAAAFQCKvLgJmuxvJy6DvdRB5Fm/VZR5PwAAAIEA1y5UQItEth5WSS6166Aujc+7x9jgaztoC4Uo0iskMM5D0oVrJSyVwCAOcNPEeya4zNnJgkD16Wco3XOryBcgjWScEoTgict2J8rnaUWDkyOMptfbiF+oU39INh3m+2tvIfsgX81bAQJD0STYiF9J3G/PQYjvRIxhybtHJHGcuaUAAACBANTDVZW7LC9PbzQ1e2SxMOznf76/WV8RfwfKALh0DpJvyaEuOQkgwO/AzSNoN1mJgkn7mjXKgsJLYB/49d1arv8n/nG+7oLGdKYlKlXOkJ2bW+yxnFwLvBTBniCbdyylPP1iNbw2SArns44xxBszjTedAZcpJQiv+ThZI3Bzg5dM"); | ||
} | ||
|
||
@Test | ||
void testEncodeRsaPublicKey() throws Exception { | ||
PublicKey tPublicKey = SshKeyUtil.readRsaKeyPair().getPublic(); | ||
|
||
SshPublicKeyEncoder tPublicKeyEncoder = new SshPublicKeyEncoder(); | ||
byte[] tSshEncodedPublicKey = tPublicKeyEncoder.encodePublicKey(tPublicKey); | ||
|
||
assertThat(tSshEncodedPublicKey).asBase64Encoded() | ||
.isEqualTo( | ||
"AAAAB3NzaC1yc2EAAAADAQABAAABgQDg9Lf347GyGfq+SZjWnLEFY61tz3czkkpeU71piNtCD9M18vsonIKmLRwUC4dKBE+UJQf7F79Mx/Z6XqgNCTP9tAVj1YMKtIIXbl6F4hkMWZr1XTjq78jCk3yWx7BA9CYaTxK185l3WbcZovrx9iTrVafi6+cXhxAC4HYHQYjB/1YubPhWIJ4mtqo7e22xP84Kdr/aYmSJbx0vaUjRJQaFJkYVi2Sb8GYAagd5YQ5aODU6CuY/ycp18UMQ56G/uSR19O+OGXrHbF2GEZTko6ESOAbu7EjquU1fOL3xeh/3GYNtYjeztQFCXGz2iXrKNk+wMjHGvrg8w11NdgpT983UMwA8bV8kctz4qaH/89HhR49pkLSxOc9AMzjSL8N4bueId598KnfutEzT0N+Ghwsi+1fDrohCTRx2x+PyLYe5syehjn/IxhnQlKEvtRitjUqCn32mAufx2BbCl8rykPTUxBE/QAUYPlA/Surv8j9yE8tEpDIdEBc78kpwBxH60p8="); | ||
} | ||
|
||
@Test | ||
void testEncodeEd25519PublicKey() throws Exception { | ||
PublicKey tPublicKey = SshKeyUtil.readEd25519KeyPair().getPublic(); | ||
|
||
SshPublicKeyEncoder tPublicKeyEncoder = new SshPublicKeyEncoder(); | ||
byte[] tSshEncodedPublicKey = tPublicKeyEncoder.encodePublicKey(tPublicKey); | ||
|
||
assertThat(tSshEncodedPublicKey).asBase64Encoded() | ||
.isEqualTo("AAAAC3NzaC1lZDI1NTE5AAAAIDuDUZReuNqkLI5pqXRzx6+LtMtLMji2HPoDccHOE4XF"); | ||
} | ||
} |
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,24 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<launchConfiguration type="org.eclipse.jdt.junit.launchconfig"> | ||
<booleanAttribute key="org.eclipse.debug.core.ATTR_FORCE_SYSTEM_CONSOLE_ENCODING" value="false"/> | ||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"> | ||
<listEntry value="/sshsig-core/src/test/java/de/profhenry/sshsig/core/SshPublicKeyEncoderTest.java"/> | ||
</listAttribute> | ||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"> | ||
<listEntry value="1"/> | ||
</listAttribute> | ||
<stringAttribute key="org.eclipse.debug.core.SOURCE_PATH_COMPUTER_ID" value="de.gebit.maven.osgi.launcher.plugin.sourcelookup.patchedJavaSourcePathComputer"/> | ||
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/> | ||
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/> | ||
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/> | ||
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit5"/> | ||
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_ATTR_USE_ARGFILE" value="false"/> | ||
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_SHOW_CODEDETAILS_IN_EXCEPTION_MESSAGES" value="true"/> | ||
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_CLASSPATH_ONLY_JAR" value="false"/> | ||
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.m2e.launchconfig.classpathProvider"/> | ||
<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17/"/> | ||
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="de.profhenry.sshsig.core.SshPublicKeyEncoderTest"/> | ||
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="sshsig-core"/> | ||
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.m2e.launchconfig.sourcepathProvider"/> | ||
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-ea"/> | ||
</launchConfiguration> |
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,20 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<launchConfiguration type="org.eclipse.jdt.junit.launchconfig"> | ||
<booleanAttribute key="org.eclipse.debug.core.ATTR_FORCE_SYSTEM_CONSOLE_ENCODING" value="false"/> | ||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"> | ||
<listEntry value="/sshsig-core/src/test/java/de/profhenry/sshsig/core/SshPublicKeyEncoderTest.java"/> | ||
</listAttribute> | ||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"> | ||
<listEntry value="1"/> | ||
</listAttribute> | ||
<stringAttribute key="org.eclipse.debug.core.SOURCE_PATH_COMPUTER_ID" value="de.gebit.maven.osgi.launcher.plugin.sourcelookup.patchedJavaSourcePathComputer"/> | ||
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/> | ||
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/> | ||
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/> | ||
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit5"/> | ||
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.m2e.launchconfig.classpathProvider"/> | ||
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="de.profhenry.sshsig.core.SshPublicKeyEncoderTest"/> | ||
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="sshsig-core"/> | ||
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.m2e.launchconfig.sourcepathProvider"/> | ||
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-ea"/> | ||
</launchConfiguration> |
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
69 changes: 69 additions & 0 deletions
69
sshsig-core/src/main/java/de/profhenry/sshsig/core/PemWriter.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,69 @@ | ||
/* | ||
* Copyright 2023 Jan Henrik Wiesner | ||
* | ||
* 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 de.profhenry.sshsig.core; | ||
|
||
import java.io.PrintWriter; | ||
import java.io.Writer; | ||
import java.util.Base64; | ||
|
||
/** | ||
* @author profhenry | ||
*/ | ||
public class PemWriter { | ||
|
||
/** | ||
* The default line length of the base 64 encoded content. | ||
* <p> | ||
* RFC7468 states that the base 64 content MUST wrap after 64 chars. | ||
*/ | ||
private static final int DEFAULT_LINE_LENGTH = 64; | ||
|
||
private final PrintWriter printWriter; | ||
|
||
private final int lineLength; | ||
|
||
public PemWriter(Writer aWriter, int aLineLength) { | ||
printWriter = new PrintWriter(aWriter); | ||
lineLength = aLineLength; | ||
} | ||
|
||
public PemWriter(Writer aWriter) { | ||
this(aWriter, DEFAULT_LINE_LENGTH); | ||
} | ||
|
||
public void writeData(String aLabel, byte[] someBytes) { | ||
writeHeader(aLabel); | ||
writeData(someBytes); | ||
writeFooter(aLabel); | ||
printWriter.flush(); | ||
} | ||
|
||
private void writeHeader(String aLabel) { | ||
printWriter.println("-----BEGIN " + aLabel + "-----"); | ||
} | ||
|
||
private void writeData(byte[] someBytes) { | ||
String tEncoded = Base64.getEncoder().encodeToString(someBytes); | ||
|
||
for (int i = 0; i < tEncoded.length(); i += lineLength) { | ||
printWriter.println(tEncoded.substring(i, Math.min(tEncoded.length(), i + lineLength))); | ||
} | ||
} | ||
|
||
private void writeFooter(String aLabel) { | ||
printWriter.println("-----END " + aLabel + "-----"); | ||
} | ||
} |
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
Oops, something went wrong.