43
43
import java .security .GeneralSecurityException ;
44
44
import java .security .PrivateKey ;
45
45
import java .security .PublicKey ;
46
+ import java .security .interfaces .RSAPrivateCrtKey ;
46
47
import java .security .interfaces .RSAPublicKey ;
47
48
import java .text .DateFormat ;
48
49
import java .text .ParseException ;
@@ -103,7 +104,7 @@ public void assertWiped() {
103
104
assertArrayEquals (new char [passwordChars .length ], passwordChars );
104
105
}
105
106
}
106
- };
107
+ }
107
108
108
109
final PasswordFinder onlyGivesWhenReady = new PasswordFinder () {
109
110
@ Override
@@ -187,7 +188,7 @@ public void fromString()
187
188
}
188
189
189
190
@ Test
190
- public void shouldHaveCorrectFingerprintForECDSA256 () throws IOException , GeneralSecurityException {
191
+ public void shouldHaveCorrectFingerprintForECDSA256 () throws IOException {
191
192
OpenSSHKeyFile keyFile = new OpenSSHKeyFile ();
192
193
keyFile .init (new File ("src/test/resources/keytypes/test_ecdsa_nistp256" ));
193
194
String expected = "256 MD5:53:ae:db:ed:8f:2d:02:d4:d5:6c:24:bc:a4:66:88:79 root@itgcpkerberosstack-cbgateway-0-20151117031915 (ECDSA)\n " ;
@@ -197,7 +198,7 @@ public void shouldHaveCorrectFingerprintForECDSA256() throws IOException, Genera
197
198
}
198
199
199
200
@ Test
200
- public void shouldHaveCorrectFingerprintForECDSA384 () throws IOException , GeneralSecurityException {
201
+ public void shouldHaveCorrectFingerprintForECDSA384 () throws IOException {
201
202
OpenSSHKeyFile keyFile = new OpenSSHKeyFile ();
202
203
keyFile .init (new File ("src/test/resources/keytypes/test_ecdsa_nistp384" ));
203
204
String expected = "384 MD5:ee:9b:82:d1:47:01:16:1b:27:da:f5:27:fd:b2:eb:e2" ;
@@ -207,7 +208,7 @@ public void shouldHaveCorrectFingerprintForECDSA384() throws IOException, Genera
207
208
}
208
209
209
210
@ Test
210
- public void shouldHaveCorrectFingerprintForECDSA521 () throws IOException , GeneralSecurityException {
211
+ public void shouldHaveCorrectFingerprintForECDSA521 () throws IOException {
211
212
OpenSSHKeyFile keyFile = new OpenSSHKeyFile ();
212
213
keyFile .init (new File ("src/test/resources/keytypes/test_ecdsa_nistp521" ));
213
214
String expected = "521 MD5:22:e2:f4:3c:61:ae:e9:85:a1:4d:d9:6c:13:aa:eb:00" ;
@@ -274,6 +275,35 @@ public void shouldLoadRSAPrivateKeyAsOpenSSHV1() throws IOException {
274
275
assertThat (aPrivate .getAlgorithm (), equalTo ("RSA" ));
275
276
}
276
277
278
+ @ Test
279
+ public void shouldLoadRSAPrivateCrtKeyAsOpenSSHV1 () throws IOException {
280
+ final OpenSSHKeyV1KeyFile keyFile = new OpenSSHKeyV1KeyFile ();
281
+ keyFile .init (new File ("src/test/resources/keyformats/rsa_opensshv1" ));
282
+ final PrivateKey privateKey = keyFile .getPrivate ();
283
+ final PublicKey publicKey = keyFile .getPublic ();
284
+
285
+ assertTrue (publicKey instanceof RSAPublicKey );
286
+ final RSAPublicKey rsaPublicKey = (RSAPublicKey ) publicKey ;
287
+
288
+ assertTrue (privateKey instanceof RSAPrivateCrtKey );
289
+ final RSAPrivateCrtKey rsaPrivateCrtKey = (RSAPrivateCrtKey ) privateKey ;
290
+
291
+ assertEquals ("Public Key Exponent not matched" , rsaPublicKey .getPublicExponent (), rsaPrivateCrtKey .getPublicExponent ());
292
+ assertEquals ("Public Key Modulus not matched" , rsaPublicKey .getModulus (), rsaPrivateCrtKey .getModulus ());
293
+
294
+ final BigInteger privateExponent = rsaPrivateCrtKey .getPrivateExponent ();
295
+
296
+ final BigInteger expectedPrimeExponentP = privateExponent .mod (rsaPrivateCrtKey .getPrimeP ().subtract (BigInteger .ONE ));
297
+ assertEquals ("Prime Exponent P not matched" , expectedPrimeExponentP , rsaPrivateCrtKey .getPrimeExponentP ());
298
+
299
+ final BigInteger expectedPrimeExponentQ = privateExponent .mod (rsaPrivateCrtKey .getPrimeQ ().subtract (BigInteger .ONE ));
300
+ assertEquals ("Prime Exponent Q not matched" , expectedPrimeExponentQ , rsaPrivateCrtKey .getPrimeExponentQ ());
301
+
302
+
303
+ final BigInteger expectedCoefficient = rsaPrivateCrtKey .getPrimeQ ().modInverse (rsaPrivateCrtKey .getPrimeP ());
304
+ assertEquals ("Prime CRT Coefficient not matched" , expectedCoefficient , rsaPrivateCrtKey .getCrtCoefficient ());
305
+ }
306
+
277
307
@ Test
278
308
public void shouldLoadECDSAPrivateKeyAsOpenSSHV1 () throws IOException {
279
309
OpenSSHKeyV1KeyFile keyFile = new OpenSSHKeyV1KeyFile ();
0 commit comments