summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.gpg.bc.test/tst/org/eclipse
diff options
context:
space:
mode:
authorThomas Wolf <thomas.wolf@paranor.ch>2021-02-22 09:29:12 +0100
committerThomas Wolf <thomas.wolf@paranor.ch>2021-02-22 09:43:18 +0100
commit704ccdc096e4f5cf2670c5c58eaf19fe1fdf4df3 (patch)
treea02240b4ed0bcbc1cea0f3a00a85dea7e167b269 /org.eclipse.jgit.gpg.bc.test/tst/org/eclipse
parent81a76383a1b92db34a250c68a28d60fadfffd036 (diff)
downloadjgit-704ccdc096e4f5cf2670c5c58eaf19fe1fdf4df3.tar.gz
jgit-704ccdc096e4f5cf2670c5c58eaf19fe1fdf4df3.zip
GPG: fix reading unprotected old-format secret keys
Fix code and add a test case. The old code passed on the original input stream, which has already been consumed. Bug: 570501 Change-Id: I81f60698ce42443df57e59b1d1ab155574136fa8 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.jgit.gpg.bc.test/tst/org/eclipse')
-rw-r--r--org.eclipse.jgit.gpg.bc.test/tst/org/eclipse/jgit/gpg/bc/internal/keys/SecretKeysTest.java26
1 files changed, 17 insertions, 9 deletions
diff --git a/org.eclipse.jgit.gpg.bc.test/tst/org/eclipse/jgit/gpg/bc/internal/keys/SecretKeysTest.java b/org.eclipse.jgit.gpg.bc.test/tst/org/eclipse/jgit/gpg/bc/internal/keys/SecretKeysTest.java
index 4eecaf3ab5..5e5e303319 100644
--- a/org.eclipse.jgit.gpg.bc.test/tst/org/eclipse/jgit/gpg/bc/internal/keys/SecretKeysTest.java
+++ b/org.eclipse.jgit.gpg.bc.test/tst/org/eclipse/jgit/gpg/bc/internal/keys/SecretKeysTest.java
@@ -76,9 +76,12 @@ public class SecretKeysTest {
final boolean encrypted;
- TestData(String name, boolean encrypted) {
+ final boolean keyValue;
+
+ TestData(String name, boolean encrypted, boolean keyValue) {
this.name = name;
this.encrypted = encrypted;
+ this.keyValue = keyValue;
}
@Override
@@ -90,10 +93,11 @@ public class SecretKeysTest {
@Parameters(name = "{0}")
public static TestData[] initTestData() {
return new TestData[] {
- new TestData("2FB05DBB70FC07CB84C13431F640CA6CEA1DBF8A", false),
- new TestData("66CCECEC2AB46A9735B10FEC54EDF9FD0F77BAF9", true),
- new TestData("F727FAB884DA3BD402B6E0F5472E108D21033124", true),
- new TestData("faked", false) };
+ new TestData("AFDA8EA10E185ACF8C0D0F8885A0EF61A72ECB11", false, false),
+ new TestData("2FB05DBB70FC07CB84C13431F640CA6CEA1DBF8A", false, true),
+ new TestData("66CCECEC2AB46A9735B10FEC54EDF9FD0F77BAF9", true, true),
+ new TestData("F727FAB884DA3BD402B6E0F5472E108D21033124", true, true),
+ new TestData("faked", false, true) };
}
private static byte[] readTestKey(String filename) throws Exception {
@@ -126,9 +130,11 @@ public class SecretKeysTest {
@Test
public void testKeyRead() throws Exception {
- byte[] bytes = readTestKey(data.name + ".key");
- assertEquals('(', bytes[0]);
- assertEquals(')', bytes[bytes.length - 1]);
+ if (data.keyValue) {
+ byte[] bytes = readTestKey(data.name + ".key");
+ assertEquals('(', bytes[0]);
+ assertEquals(')', bytes[bytes.length - 1]);
+ }
try (InputStream pubIn = this.getClass()
.getResourceAsStream(data.name + ".asc")) {
if (pubIn != null) {
@@ -139,7 +145,9 @@ public class SecretKeysTest {
try (InputStream in = new BufferedInputStream(this.getClass()
.getResourceAsStream(data.name + ".key"))) {
PGPSecretKey secretKey = SecretKeys.readSecretKey(in,
- calculatorProvider, () -> "nonsense".toCharArray(),
+ calculatorProvider,
+ data.encrypted ? () -> "nonsense".toCharArray()
+ : null,
publicKey);
assertNotNull(secretKey);
} catch (PGPException e) {