Skip to content
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

Decryption fix and junit test updates for PKCS5 #266

Merged
merged 3 commits into from
Aug 24, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Updated test case for PKCS5 over-"simplification", to prevent regress…
…ion.
  • Loading branch information
David Solin authored and David Solin committed Aug 24, 2016
commit 8c1329036a911d2ae25212958c7c97dde3476737
38 changes: 38 additions & 0 deletions src/main/java/net/schmizz/sshj/common/LoggerFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (C)2016 - SSHJ Contributors
*
* 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 net.schmizz.sshj.common;

import org.slf4j.Logger;

public interface LoggerFactory {
Logger getLogger(String name);
Logger getLogger(Class<?> clazz);

/**
* Default SLF4J-based implementation of the SSHJ LoggerFactory.
*/
LoggerFactory DEFAULT = new LoggerFactory() {
@Override
public Logger getLogger(String name) {
return org.slf4j.LoggerFactory.getLogger(name);
}

@Override
public Logger getLogger(Class<?> clazz) {
return org.slf4j.LoggerFactory.getLogger(clazz);
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,8 @@ public class PKCS5KeyFileTest {
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[]{' '};

final char[] correctPassphrase = "passphrase".toCharArray();
final char[] incorrectPassphrase = "incorrect".toCharArray();

@Before
public void setUp()
Expand Down Expand Up @@ -89,8 +83,9 @@ public boolean shouldRetry(Resource resource) {
@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());
FileKeyProvider rsa = new PKCS5KeyFile();
rsa.init(new File("src/test/resources/rsa.pk5"), givesOn3rdTry);
assertEquals(KeyUtil.newRSAPublicKey(modulus, pubExp), rsa.getPublic());
assertEquals(KeyUtil.newRSAPrivateKey(modulus, privExp), rsa.getPrivate());
}
}
30 changes: 30 additions & 0 deletions src/test/resources/rsa.pk5
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-128-CBC,AE7ED92A1A2D5FB584B537DAB45A62E5

J/o72rIJRjtdVzgu862AH79AXyZaSakgRh9SbzGQ00msDss6jKY6GxHhaZFutilO
BX0bc3sOx+8XWlqnNpMiWy6ImorTMH6gr95SotrUQ3LuZ3rVW4u4FI+VQ/Jc7Dm9
LkLj7N7hHGfsVw6SsywKtfYdnAu/ySg5hlngVDB+pTKNDon1Fzs8vYI4n0ou1OAM
G/XjqMEbcQdqhhbdlLmmTElNRzIJE6Ojrx5swXmeVj31teH4oXKLiOVKNJQg37A+
CN51VN8GNalqPBXeZ/DcguB18M/CMb8YTlk3V3XaOwgLLc1vXpDBz2rtkaluhcD+
GzmquGZbcX9saP89Gq2HWzWzIMCuMFGHGSJlZvNp805PCVX0nF+iIqcwIArNRetA
gAWxBIm6Y9f5Kp4kQE2UNFsaLKrQlKQHIPAwdQFBmIyQulYJ1qMJeCQvCTB8jPkk
yrl2diiaK/TxexRaKgxeuML8jcSjfY8dYsaSda7gt8i/zCn+rSjc4CfOGSlCnSwl
DDh3i9Yv0enZ+oHzRjYjwUFXxfQBg8MFSoth4YkPV2oMn+pKXyaIqe4AcFml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