From 62b87268071e33da408a9bd041bb64001c027714 Mon Sep 17 00:00:00 2001 From: David Solin Date: Fri, 19 Aug 2016 12:18:49 -0500 Subject: [PATCH 1/6] Fixed bug wherein PKCS5KeyFile messed up the data if a bad passphrase was used, which prevented decryption with a subsequent correct passphrase. Also, made it possible for subclasses of PKCS5KeyFile to access the decrypted ASN.1 data directly (useful if you want to decrypt then store a PKCS5 key for later use elsewhere). And I think I made the code a little prettier. --- .../userauth/keyprovider/PKCS5KeyFile.java | 158 +++++++++++------- 1 file changed, 98 insertions(+), 60 deletions(-) diff --git a/src/main/java/net/schmizz/sshj/userauth/keyprovider/PKCS5KeyFile.java b/src/main/java/net/schmizz/sshj/userauth/keyprovider/PKCS5KeyFile.java index 736b78da5..6acb520e6 100644 --- a/src/main/java/net/schmizz/sshj/userauth/keyprovider/PKCS5KeyFile.java +++ b/src/main/java/net/schmizz/sshj/userauth/keyprovider/PKCS5KeyFile.java @@ -27,7 +27,6 @@ import net.schmizz.sshj.transport.digest.Digest; import net.schmizz.sshj.transport.digest.MD5; import net.schmizz.sshj.userauth.password.PasswordFinder; -import net.schmizz.sshj.userauth.password.PasswordUtils; import net.schmizz.sshj.userauth.password.PrivateKeyFileResource; import net.schmizz.sshj.userauth.password.PrivateKeyReaderResource; import net.schmizz.sshj.userauth.password.PrivateKeyStringResource; @@ -77,8 +76,7 @@ public String getName() { protected KeyPair kp; protected KeyType type; - - protected char[] passphrase; // for blanking out + protected byte[] data; @Override public PrivateKey getPrivate() @@ -139,7 +137,6 @@ protected KeyPair readKeyPair() throws IOException { BufferedReader reader = new BufferedReader(resource.getReader()); try { - String type = null; String line = null; Cipher cipher = new NoneCipher(); StringBuffer sb = new StringBuffer(); @@ -148,37 +145,46 @@ protected KeyPair readKeyPair() if (line.startsWith("-----BEGIN ") && line.endsWith(" PRIVATE KEY-----")) { int end = line.length() - 17; if (end > 11) { - type = line.substring(11, line.length() - 17); + String s = line.substring(11, line.length() - 17); + if ("RSA".equals(s)) { + type = KeyType.RSA; + } else if ("DSA".equals(s)) { + type = KeyType.DSA; + } else if ("DSS".equals(s)) { + type = KeyType.DSA; + } else { + throw new FormatException("Unrecognized PKCS5 key type: " + s); + } } else { - type = "UNKNOWN"; + throw new FormatException("Bad header; possibly PKCS8 format?"); } } else if (line.startsWith("-----END")) { break; } else if (type != null) { if (line.startsWith("Proc-Type: ")) { if (!"4,ENCRYPTED".equals(line.substring(11))) { - throw new IOException("Unrecognized Proc-Type: " + line.substring(11)); + throw new FormatException("Unrecognized Proc-Type: " + line.substring(11)); } } else if (line.startsWith("DEK-Info: ")) { int ptr = line.indexOf(","); if (ptr == -1) { - throw new IOException("Unrecognized DEK-Info: " + line.substring(10)); + throw new FormatException("Unrecognized DEK-Info: " + line.substring(10)); } else { String algorithm = line.substring(10,ptr); if ("DES-EDE3-CBC".equals(algorithm)) { cipher = new TripleDESCBC(); - iv = DatatypeConverter.parseHexBinary(line.substring(ptr+1)); + iv = Arrays.copyOfRange(DatatypeConverter.parseHexBinary(line.substring(ptr+1)), 0, cipher.getIVSize()); } else if ("AES-128-CBC".equals(algorithm)) { cipher = new AES128CBC(); - iv = DatatypeConverter.parseHexBinary(line.substring(ptr+1)); + iv = Arrays.copyOfRange(DatatypeConverter.parseHexBinary(line.substring(ptr+1)), 0, cipher.getIVSize()); } else if ("AES-192-CBC".equals(algorithm)) { cipher = new AES192CBC(); - iv = Base64.decode(line.substring(ptr+1)); + iv = Arrays.copyOfRange(Base64.decode(line.substring(ptr+1)), 0, cipher.getIVSize()); } else if ("AES-256-CBC".equals(algorithm)) { cipher = new AES256CBC(); - iv = Base64.decode(line.substring(ptr+1)); + iv = Arrays.copyOfRange(Base64.decode(line.substring(ptr+1)), 0, cipher.getIVSize()); } else { - throw new IOException("Not a supported algorithm: " + algorithm); + throw new FormatException("Not a supported algorithm: " + algorithm); } } } else if (line.length() > 0) { @@ -186,47 +192,12 @@ protected KeyPair readKeyPair() } } } - - byte[] data = Base64.decode(sb.toString()); - if (pwdf != null) { - boolean decrypted = false; - do { - CharBuffer cb = CharBuffer.wrap(pwdf.reqPassword(resource)); - ByteBuffer bb = IOUtils.UTF8.encode(cb); - byte[] passphrase = Arrays.copyOfRange(bb.array(), bb.position(), bb.limit()); - Arrays.fill(cb.array(), '\u0000'); - Arrays.fill(bb.array(), (byte)0); - byte[] key = new byte[cipher.getBlockSize()]; - iv = Arrays.copyOfRange(iv, 0, cipher.getIVSize()); - Digest md5 = new MD5(); - md5.init(); - int hsize = md5.getBlockSize(); - byte[] hn = new byte[key.length / hsize * hsize + (key.length % hsize == 0 ? 0 : hsize)]; - byte[] tmp = null; - for (int i=0; i + hsize <= hn.length;) { - if (tmp != null) { - md5.update(tmp, 0, tmp.length); - } - md5.update(passphrase, 0, passphrase.length); - md5.update(iv, 0, iv.length > 8 ? 8 : iv.length); - tmp = md5.digest(); - System.arraycopy(tmp, 0, hn, i, tmp.length); - i += tmp.length; - } - Arrays.fill(passphrase, (byte)0); - System.arraycopy(hn, 0, key, 0, key.length); - cipher.init(Cipher.Mode.Decrypt, key, iv); - Arrays.fill(key, (byte)0); - cipher.update(data, 0, data.length); - decrypted = 0x30 == data[0]; - } while (!decrypted && pwdf.shouldRetry(resource)); - } - if (0x30 != data[0]) { - throw new IOException("Failed to decrypt key"); + if (type == null) { + throw new FormatException("PKCS5 header not found"); } - - ASN1Data asn = new ASN1Data(data); - if ("RSA".equals(type)) { + ASN1Data asn = new ASN1Data(data = decrypt(Base64.decode(sb.toString()), cipher, iv)); + switch(type) { + case RSA: { KeyFactory factory = KeyFactory.getInstance("RSA"); asn.readNext(); BigInteger modulus = asn.readNext(); @@ -235,7 +206,8 @@ protected KeyPair readKeyPair() PublicKey pubKey = factory.generatePublic(new RSAPublicKeySpec(modulus, pubExp)); PrivateKey prvKey = factory.generatePrivate(new RSAPrivateKeySpec(modulus, prvExp)); return new KeyPair(pubKey, prvKey); - } else if ("DSA".equals(type)) { + } + case DSA: { KeyFactory factory = KeyFactory.getInstance("DSA"); asn.readNext(); BigInteger p = asn.readNext(); @@ -246,8 +218,9 @@ protected KeyPair readKeyPair() PublicKey pubKey = factory.generatePublic(new DSAPublicKeySpec(pub, p, q, g)); PrivateKey prvKey = factory.generatePrivate(new DSAPrivateKeySpec(prv, p, q, g)); return new KeyPair(pubKey, prvKey); - } else { - throw new IOException("Unrecognized key type: " + type); + } + default: + throw new IOException("Unrecognized PKCS5 key type: " + type); } } catch (NoSuchAlgorithmException e) { throw new IOException(e); @@ -263,15 +236,80 @@ public String toString() { return "PKCS5KeyFile{resource=" + resource + "}"; } + private byte[] getPassphraseBytes() { + CharBuffer cb = CharBuffer.wrap(pwdf.reqPassword(resource)); + ByteBuffer bb = IOUtils.UTF8.encode(cb); + byte[] result = Arrays.copyOfRange(bb.array(), bb.position(), bb.limit()); + Arrays.fill(cb.array(), '\u0000'); + Arrays.fill(bb.array(), (byte)0); + return result; + } + + private byte[] decrypt(byte[] raw, Cipher cipher, byte[] iv) throws DecryptException { + if (pwdf == null) { + return raw; + } + Digest md5 = new MD5(); + int bsize = cipher.getBlockSize(); + int hsize = md5.getBlockSize(); + int hnlen = bsize / hsize * hsize + (bsize % hsize == 0 ? 0 : hsize); + do { + md5.init(); + byte[] hn = new byte[hnlen]; + byte[] tmp = null; + byte[] passphrase = getPassphraseBytes(); + for (int i=0; i + hsize <= hn.length;) { + if (tmp != null) { + md5.update(tmp, 0, tmp.length); + } + md5.update(passphrase, 0, passphrase.length); + md5.update(iv, 0, iv.length > 8 ? 8 : iv.length); + tmp = md5.digest(); + System.arraycopy(tmp, 0, hn, i, tmp.length); + i += tmp.length; + } + Arrays.fill(passphrase, (byte)0); + byte[] key = Arrays.copyOfRange(hn, 0, bsize); + cipher.init(Cipher.Mode.Decrypt, key, iv); + Arrays.fill(key, (byte)0); + byte[] decrypted = Arrays.copyOf(raw, raw.length); + cipher.update(decrypted, 0, decrypted.length); + if (ASN1Data.MAGIC == decrypted[0]) { + return decrypted; + } + } while (pwdf.shouldRetry(resource)); + throw new DecryptException("Decryption failed"); + } + + /** + * Indicates a format issue with PKCS5 data + */ + public static class FormatException extends IOException { + FormatException(String msg) { + super(msg); + } + } + + /** + * Indicates a problem decrypting the data + */ + public static class DecryptException extends IOException { + DecryptException(String msg) { + super(msg); + } + } + class ASN1Data { + static final byte MAGIC = (byte)0x30; + private byte[] buff; private int index, length; - ASN1Data(byte[] buff) throws IOException { + ASN1Data(byte[] buff) throws FormatException { this.buff = buff; index = 0; - if (buff[index++] != (byte)0x30) { - throw new IOException("Not ASN.1 data"); + if (buff[index++] != MAGIC) { + throw new FormatException("Not ASN.1 data"); } length = buff[index++] & 0xff; if ((length & 0x80) != 0) { @@ -282,7 +320,7 @@ class ASN1Data { } } if ((index + length) > buff.length) { - throw new IOException("Length mismatch: " + buff.length + " != " + (index + length)); + throw new FormatException("Length mismatch: " + buff.length + " != " + (index + length)); } } From 7786468875372a531c572cd9fb2aa0a7269439a4 Mon Sep 17 00:00:00 2001 From: David Solin Date: Fri, 19 Aug 2016 15:00:12 -0500 Subject: [PATCH 2/6] Simplification? --- .../userauth/keyprovider/PKCS5KeyFile.java | 49 ++++++++++--------- .../sshj/keyprovider/PKCS5KeyFileTest.java | 35 +++++++++++++ 2 files changed, 60 insertions(+), 24 deletions(-) diff --git a/src/main/java/net/schmizz/sshj/userauth/keyprovider/PKCS5KeyFile.java b/src/main/java/net/schmizz/sshj/userauth/keyprovider/PKCS5KeyFile.java index e7aec425b..2964ecbb0 100644 --- a/src/main/java/net/schmizz/sshj/userauth/keyprovider/PKCS5KeyFile.java +++ b/src/main/java/net/schmizz/sshj/userauth/keyprovider/PKCS5KeyFile.java @@ -50,10 +50,31 @@ public String getName() { } } + /** + * Indicates a format issue with PKCS5 data + */ + public static class FormatException + extends IOException { + + FormatException(String msg) { + super(msg); + } + } + + /** + * Indicates a problem decrypting the data + */ + public static class DecryptException + extends IOException { + + DecryptException(String msg) { + super(msg); + } + } + protected PasswordFinder pwdf; protected Resource resource; protected KeyPair kp; - protected KeyType type; protected byte[] data; @@ -114,6 +135,7 @@ public void init(String privateKey, String publicKey, PasswordFinder pwdf) { protected KeyPair readKeyPair() throws IOException { + BufferedReader reader = new BufferedReader(resource.getReader()); try { String line = null; @@ -152,19 +174,16 @@ protected KeyPair readKeyPair() String algorithm = line.substring(10,ptr); if ("DES-EDE3-CBC".equals(algorithm)) { cipher = new TripleDESCBC(); - iv = Arrays.copyOfRange(DatatypeConverter.parseHexBinary(line.substring(ptr+1)), 0, cipher.getIVSize()); } else if ("AES-128-CBC".equals(algorithm)) { cipher = new AES128CBC(); - iv = Arrays.copyOfRange(DatatypeConverter.parseHexBinary(line.substring(ptr+1)), 0, cipher.getIVSize()); } else if ("AES-192-CBC".equals(algorithm)) { cipher = new AES192CBC(); - iv = Arrays.copyOfRange(Base64.decode(line.substring(ptr+1)), 0, cipher.getIVSize()); } else if ("AES-256-CBC".equals(algorithm)) { cipher = new AES256CBC(); - iv = Arrays.copyOfRange(Base64.decode(line.substring(ptr+1)), 0, cipher.getIVSize()); } else { throw new FormatException("Not a supported algorithm: " + algorithm); } + iv = Arrays.copyOfRange(DatatypeConverter.parseHexBinary(line.substring(ptr+1)), 0, Math.min(cipher.getIVSize(), 8)); } } else if (line.length() > 0) { sb.append(line); @@ -242,7 +261,7 @@ private byte[] decrypt(byte[] raw, Cipher cipher, byte[] iv) throws DecryptExcep md5.update(tmp, 0, tmp.length); } md5.update(passphrase, 0, passphrase.length); - md5.update(iv, 0, iv.length > 8 ? 8 : iv.length); + md5.update(iv, 0, iv.length); tmp = md5.digest(); System.arraycopy(tmp, 0, hn, i, tmp.length); i += tmp.length; @@ -260,24 +279,6 @@ private byte[] decrypt(byte[] raw, Cipher cipher, byte[] iv) throws DecryptExcep throw new DecryptException("Decryption failed"); } - /** - * Indicates a format issue with PKCS5 data - */ - public static class FormatException extends IOException { - FormatException(String msg) { - super(msg); - } - } - - /** - * Indicates a problem decrypting the data - */ - public static class DecryptException extends IOException { - DecryptException(String msg) { - super(msg); - } - } - class ASN1Data { static final byte MAGIC = (byte)0x30; diff --git a/src/test/java/net/schmizz/sshj/keyprovider/PKCS5KeyFileTest.java b/src/test/java/net/schmizz/sshj/keyprovider/PKCS5KeyFileTest.java index 952365e2f..08d23deaa 100644 --- a/src/test/java/net/schmizz/sshj/keyprovider/PKCS5KeyFileTest.java +++ b/src/test/java/net/schmizz/sshj/keyprovider/PKCS5KeyFileTest.java @@ -56,4 +56,39 @@ public void testType() assertEquals(rsa.getType(), KeyType.RSA); } + final char[] correctPassphrase = "test_passphrase".toCharArray(); + final char[] incorrectPassphrase = new char[]{' '}; + + static final String g = "23b0484f5ad9cba2b3dba7129419fbec7f8c014e22d3b19de4ebbca20d0ebd2e9f5225dabdd48de75f87e3193377fb1072c08433f82f6e6e581a319d4fc7d283cdcd2ae2000fe572c0a800fd47b7590d6a6afe3df54aedd57696c6538029daebf11d9e277edc0c7e905e237d3b9e6a6f674d83da5cc0131ac0be2e55ac69730e"; + static final String p = "92b746cf7c0e9ea35fd9b09b0c3dbdfde453468984698ff168fefef3f0457d29bcf81c88830ac1099223d00745423e44cdef66f4cdc3fad1d95ce2868b3e885c1d518c9fcda597d5c373f05f6f323553f60bd992404183dab41d82ab6d3b3ecf2dfc3c136fa67c4312ec0b7bbac77a634e1eb5dd9a62efd0ddab477d0b49c0b9"; + static final String q = "96a05e07b9e52d6f1137d11d5d270b568b94162f"; + static final String x = "8981aebb71c60b5951f0ab3ed1a00b5307742f43"; + static final String y = "7e845aada202d31004c52ab170cbe62ce9a962b9f4acbc67a57f62eb090a67b3faa53d38050f87b2b66ddf1185472f27842c3e3e58d025f9148a28f49ebdfb6efefee8ee10fe84a2d56535dddb301dfee15538108639e8a0ec7aa237ddb999f35b6a5c6b875052998233374163ad031f974d29c2631394436ae186b418348193"; + + final PasswordFinder givesOn3rdTry = new PasswordFinder() { + int triesLeft = 3; + + @Override + public char[] reqPassword(Resource resource) { + if (triesLeft == 0) + return correctPassphrase; + else { + triesLeft--; + return incorrectPassphrase; + } + } + + @Override + public boolean shouldRetry(Resource resource) { + return triesLeft >= 0; + } + }; + + @Test + public void retries() + throws IOException, GeneralSecurityException { + FileKeyProvider dsa = new PKCS5KeyFile(); + dsa.init(new File("src/test/resources/id_dsa"), givesOn3rdTry); + assertEquals(KeyUtil.newDSAPrivateKey(x, p, q, g), dsa.getPrivate()); + } } From d198ef121c1e894d275c87af9debb364201b2aa8 Mon Sep 17 00:00:00 2001 From: David Solin Date: Fri, 19 Aug 2016 15:04:55 -0500 Subject: [PATCH 3/6] Missing import in test. --- src/test/java/net/schmizz/sshj/keyprovider/PKCS5KeyFileTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/net/schmizz/sshj/keyprovider/PKCS5KeyFileTest.java b/src/test/java/net/schmizz/sshj/keyprovider/PKCS5KeyFileTest.java index 08d23deaa..e964dba1b 100644 --- a/src/test/java/net/schmizz/sshj/keyprovider/PKCS5KeyFileTest.java +++ b/src/test/java/net/schmizz/sshj/keyprovider/PKCS5KeyFileTest.java @@ -18,6 +18,7 @@ import net.schmizz.sshj.common.KeyType; import net.schmizz.sshj.userauth.keyprovider.FileKeyProvider; import net.schmizz.sshj.userauth.keyprovider.PKCS5KeyFile; +import net.schmizz.sshj.userauth.password.PasswordFinder; import net.schmizz.sshj.util.KeyUtil; import org.junit.Before; import org.junit.Test; From f6b4d47945a5744f2553e8ed02abfc42ee6b3682 Mon Sep 17 00:00:00 2001 From: David Solin Date: Fri, 19 Aug 2016 15:09:50 -0500 Subject: [PATCH 4/6] Another missing import. This should be it. --- src/test/java/net/schmizz/sshj/keyprovider/PKCS5KeyFileTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/net/schmizz/sshj/keyprovider/PKCS5KeyFileTest.java b/src/test/java/net/schmizz/sshj/keyprovider/PKCS5KeyFileTest.java index e964dba1b..c0d571f57 100644 --- a/src/test/java/net/schmizz/sshj/keyprovider/PKCS5KeyFileTest.java +++ b/src/test/java/net/schmizz/sshj/keyprovider/PKCS5KeyFileTest.java @@ -19,6 +19,7 @@ import net.schmizz.sshj.userauth.keyprovider.FileKeyProvider; import net.schmizz.sshj.userauth.keyprovider.PKCS5KeyFile; import net.schmizz.sshj.userauth.password.PasswordFinder; +import net.schmizz.sshj.userauth.password.Resource; import net.schmizz.sshj.util.KeyUtil; import org.junit.Before; import org.junit.Test; From 6321685881e42ddabb9613175be5db0fa1c5edd6 Mon Sep 17 00:00:00 2001 From: David Solin Date: Fri, 19 Aug 2016 15:51:07 -0500 Subject: [PATCH 5/6] Moved constant declarations per codacy. --- .../schmizz/sshj/keyprovider/PKCS5KeyFileTest.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/test/java/net/schmizz/sshj/keyprovider/PKCS5KeyFileTest.java b/src/test/java/net/schmizz/sshj/keyprovider/PKCS5KeyFileTest.java index c0d571f57..b225c8b97 100644 --- a/src/test/java/net/schmizz/sshj/keyprovider/PKCS5KeyFileTest.java +++ b/src/test/java/net/schmizz/sshj/keyprovider/PKCS5KeyFileTest.java @@ -38,6 +38,11 @@ public class PKCS5KeyFileTest { static final String modulus = "a19f65e93926d9a2f5b52072db2c38c54e6cf0113d31fa92ff827b0f3bec609c45ea84264c88e64adba11ff093ed48ee0ed297757654b0884ab5a7e28b3c463bc9074b32837a2b69b61d914abf1d74ccd92b20fa44db3b31fb208c0dd44edaeb4ab097118e8ee374b6727b89ad6ce43f1b70c5a437ccebc36d2dad8ae973caad15cd89ae840fdae02cae42d241baef8fda8aa6bbaa54fd507a23338da6f06f61b34fb07d560e63fbce4a39c073e28573c2962cedb292b14b80d1b4e67b0465f2be0e38526232d0a7f88ce91a055fde082038a87ed91f3ef5ff971e30ea6cccf70d38498b186621c08f8fdceb8632992b480bf57fc218e91f2ca5936770fe9469"; static final String pubExp = "23"; static final String privExp = "57bcee2e2656eb2c94033d802dd62d726c6705fabad1fd0df86b67600a96431301620d395cbf5871c7af3d3974dfe5c30f5c60d95d7e6e75df69ed6c5a36a9c8aef554b5058b76a719b8478efa08ad1ebf08c8c25fe4b9bc0bfbb9be5d4f60e6213b4ab1c26ad33f5bba7d93e1cd65f65f5a79eb6ebfb32f930a2b0244378b4727acf83b5fb376c38d4abecc5dc3fc399e618e792d4c745d2dbbb9735242e5033129f2985ca3e28fa33cad2afe3e70e1b07ed2b6ec8a3f843fb4bffe3385ad211c6600618488f4ac70397e8eb036b82d811283dc728504cddbe1533c4dd31b1ec99ffa74fd0e3883a9cb3e2315cc1a56f55d38ed40520dd9ec91b4d2dd790d1b"; + static final String g = "23b0484f5ad9cba2b3dba7129419fbec7f8c014e22d3b19de4ebbca20d0ebd2e9f5225dabdd48de75f87e3193377fb1072c08433f82f6e6e581a319d4fc7d283cdcd2ae2000fe572c0a800fd47b7590d6a6afe3df54aedd57696c6538029daebf11d9e277edc0c7e905e237d3b9e6a6f674d83da5cc0131ac0be2e55ac69730e"; + static final String p = "92b746cf7c0e9ea35fd9b09b0c3dbdfde453468984698ff168fefef3f0457d29bcf81c88830ac1099223d00745423e44cdef66f4cdc3fad1d95ce2868b3e885c1d518c9fcda597d5c373f05f6f323553f60bd992404183dab41d82ab6d3b3ecf2dfc3c136fa67c4312ec0b7bbac77a634e1eb5dd9a62efd0ddab477d0b49c0b9"; + static final String q = "96a05e07b9e52d6f1137d11d5d270b568b94162f"; + static final String x = "8981aebb71c60b5951f0ab3ed1a00b5307742f43"; + static final String y = "7e845aada202d31004c52ab170cbe62ce9a962b9f4acbc67a57f62eb090a67b3faa53d38050f87b2b66ddf1185472f27842c3e3e58d025f9148a28f49ebdfb6efefee8ee10fe84a2d56535dddb301dfee15538108639e8a0ec7aa237ddb999f35b6a5c6b875052998233374163ad031f974d29c2631394436ae186b418348193"; @Before public void setUp() @@ -61,12 +66,6 @@ public void testType() final char[] correctPassphrase = "test_passphrase".toCharArray(); final char[] incorrectPassphrase = new char[]{' '}; - static final String g = "23b0484f5ad9cba2b3dba7129419fbec7f8c014e22d3b19de4ebbca20d0ebd2e9f5225dabdd48de75f87e3193377fb1072c08433f82f6e6e581a319d4fc7d283cdcd2ae2000fe572c0a800fd47b7590d6a6afe3df54aedd57696c6538029daebf11d9e277edc0c7e905e237d3b9e6a6f674d83da5cc0131ac0be2e55ac69730e"; - static final String p = "92b746cf7c0e9ea35fd9b09b0c3dbdfde453468984698ff168fefef3f0457d29bcf81c88830ac1099223d00745423e44cdef66f4cdc3fad1d95ce2868b3e885c1d518c9fcda597d5c373f05f6f323553f60bd992404183dab41d82ab6d3b3ecf2dfc3c136fa67c4312ec0b7bbac77a634e1eb5dd9a62efd0ddab477d0b49c0b9"; - static final String q = "96a05e07b9e52d6f1137d11d5d270b568b94162f"; - static final String x = "8981aebb71c60b5951f0ab3ed1a00b5307742f43"; - static final String y = "7e845aada202d31004c52ab170cbe62ce9a962b9f4acbc67a57f62eb090a67b3faa53d38050f87b2b66ddf1185472f27842c3e3e58d025f9148a28f49ebdfb6efefee8ee10fe84a2d56535dddb301dfee15538108639e8a0ec7aa237ddb999f35b6a5c6b875052998233374163ad031f974d29c2631394436ae186b418348193"; - final PasswordFinder givesOn3rdTry = new PasswordFinder() { int triesLeft = 3; From ed0156c98510fd3789e562fc06d656f08014fc85 Mon Sep 17 00:00:00 2001 From: David Solin Date: Fri, 19 Aug 2016 15:54:48 -0500 Subject: [PATCH 6/6] Forgot to move 2 fields to the top of the file. --- .../net/schmizz/sshj/keyprovider/PKCS5KeyFileTest.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/test/java/net/schmizz/sshj/keyprovider/PKCS5KeyFileTest.java b/src/test/java/net/schmizz/sshj/keyprovider/PKCS5KeyFileTest.java index b225c8b97..a33afcffa 100644 --- a/src/test/java/net/schmizz/sshj/keyprovider/PKCS5KeyFileTest.java +++ b/src/test/java/net/schmizz/sshj/keyprovider/PKCS5KeyFileTest.java @@ -38,11 +38,15 @@ public class PKCS5KeyFileTest { static final String modulus = "a19f65e93926d9a2f5b52072db2c38c54e6cf0113d31fa92ff827b0f3bec609c45ea84264c88e64adba11ff093ed48ee0ed297757654b0884ab5a7e28b3c463bc9074b32837a2b69b61d914abf1d74ccd92b20fa44db3b31fb208c0dd44edaeb4ab097118e8ee374b6727b89ad6ce43f1b70c5a437ccebc36d2dad8ae973caad15cd89ae840fdae02cae42d241baef8fda8aa6bbaa54fd507a23338da6f06f61b34fb07d560e63fbce4a39c073e28573c2962cedb292b14b80d1b4e67b0465f2be0e38526232d0a7f88ce91a055fde082038a87ed91f3ef5ff971e30ea6cccf70d38498b186621c08f8fdceb8632992b480bf57fc218e91f2ca5936770fe9469"; static final String pubExp = "23"; static final String privExp = "57bcee2e2656eb2c94033d802dd62d726c6705fabad1fd0df86b67600a96431301620d395cbf5871c7af3d3974dfe5c30f5c60d95d7e6e75df69ed6c5a36a9c8aef554b5058b76a719b8478efa08ad1ebf08c8c25fe4b9bc0bfbb9be5d4f60e6213b4ab1c26ad33f5bba7d93e1cd65f65f5a79eb6ebfb32f930a2b0244378b4727acf83b5fb376c38d4abecc5dc3fc399e618e792d4c745d2dbbb9735242e5033129f2985ca3e28fa33cad2afe3e70e1b07ed2b6ec8a3f843fb4bffe3385ad211c6600618488f4ac70397e8eb036b82d811283dc728504cddbe1533c4dd31b1ec99ffa74fd0e3883a9cb3e2315cc1a56f55d38ed40520dd9ec91b4d2dd790d1b"; + static final String g = "23b0484f5ad9cba2b3dba7129419fbec7f8c014e22d3b19de4ebbca20d0ebd2e9f5225dabdd48de75f87e3193377fb1072c08433f82f6e6e581a319d4fc7d283cdcd2ae2000fe572c0a800fd47b7590d6a6afe3df54aedd57696c6538029daebf11d9e277edc0c7e905e237d3b9e6a6f674d83da5cc0131ac0be2e55ac69730e"; static final String p = "92b746cf7c0e9ea35fd9b09b0c3dbdfde453468984698ff168fefef3f0457d29bcf81c88830ac1099223d00745423e44cdef66f4cdc3fad1d95ce2868b3e885c1d518c9fcda597d5c373f05f6f323553f60bd992404183dab41d82ab6d3b3ecf2dfc3c136fa67c4312ec0b7bbac77a634e1eb5dd9a62efd0ddab477d0b49c0b9"; static final String q = "96a05e07b9e52d6f1137d11d5d270b568b94162f"; static final String x = "8981aebb71c60b5951f0ab3ed1a00b5307742f43"; static final String y = "7e845aada202d31004c52ab170cbe62ce9a962b9f4acbc67a57f62eb090a67b3faa53d38050f87b2b66ddf1185472f27842c3e3e58d025f9148a28f49ebdfb6efefee8ee10fe84a2d56535dddb301dfee15538108639e8a0ec7aa237ddb999f35b6a5c6b875052998233374163ad031f974d29c2631394436ae186b418348193"; + final char[] correctPassphrase = "test_passphrase".toCharArray(); + final char[] incorrectPassphrase = new char[]{' '}; + @Before public void setUp() @@ -63,9 +67,6 @@ public void testType() assertEquals(rsa.getType(), KeyType.RSA); } - final char[] correctPassphrase = "test_passphrase".toCharArray(); - final char[] incorrectPassphrase = new char[]{' '}; - final PasswordFinder givesOn3rdTry = new PasswordFinder() { int triesLeft = 3;