mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8254717: isAssignableFrom checks in KeyFactorySpi.engineGetKeySpec appear to be backwards
Reviewed-by: jnimeh
This commit is contained in:
parent
d2c4ed08a2
commit
a777e82cd8
17 changed files with 136 additions and 63 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -148,7 +148,7 @@ public class DSAKeyFactory extends KeyFactorySpi {
|
|||
Class<?> x509KeySpec = Class.forName
|
||||
("java.security.spec.X509EncodedKeySpec");
|
||||
|
||||
if (dsaPubKeySpec.isAssignableFrom(keySpec)) {
|
||||
if (keySpec.isAssignableFrom(dsaPubKeySpec)) {
|
||||
java.security.interfaces.DSAPublicKey dsaPubKey
|
||||
= (java.security.interfaces.DSAPublicKey)key;
|
||||
params = dsaPubKey.getParams();
|
||||
|
@ -157,7 +157,7 @@ public class DSAKeyFactory extends KeyFactorySpi {
|
|||
params.getQ(),
|
||||
params.getG()));
|
||||
|
||||
} else if (x509KeySpec.isAssignableFrom(keySpec)) {
|
||||
} else if (keySpec.isAssignableFrom(x509KeySpec)) {
|
||||
return keySpec.cast(new X509EncodedKeySpec(key.getEncoded()));
|
||||
|
||||
} else {
|
||||
|
@ -173,7 +173,7 @@ public class DSAKeyFactory extends KeyFactorySpi {
|
|||
Class<?> pkcs8KeySpec = Class.forName
|
||||
("java.security.spec.PKCS8EncodedKeySpec");
|
||||
|
||||
if (dsaPrivKeySpec.isAssignableFrom(keySpec)) {
|
||||
if (keySpec.isAssignableFrom(dsaPrivKeySpec)) {
|
||||
java.security.interfaces.DSAPrivateKey dsaPrivKey
|
||||
= (java.security.interfaces.DSAPrivateKey)key;
|
||||
params = dsaPrivKey.getParams();
|
||||
|
@ -182,7 +182,7 @@ public class DSAKeyFactory extends KeyFactorySpi {
|
|||
params.getQ(),
|
||||
params.getG()));
|
||||
|
||||
} else if (pkcs8KeySpec.isAssignableFrom(keySpec)) {
|
||||
} else if (keySpec.isAssignableFrom(pkcs8KeySpec)) {
|
||||
return keySpec.cast(new PKCS8EncodedKeySpec(key.getEncoded()));
|
||||
|
||||
} else {
|
||||
|
|
|
@ -389,13 +389,13 @@ public class RSAKeyFactory extends KeyFactorySpi {
|
|||
}
|
||||
if (key instanceof RSAPublicKey) {
|
||||
RSAPublicKey rsaKey = (RSAPublicKey)key;
|
||||
if (RSA_PUB_KEYSPEC_CLS.isAssignableFrom(keySpec)) {
|
||||
if (keySpec.isAssignableFrom(RSA_PUB_KEYSPEC_CLS)) {
|
||||
return keySpec.cast(new RSAPublicKeySpec(
|
||||
rsaKey.getModulus(),
|
||||
rsaKey.getPublicExponent(),
|
||||
rsaKey.getParams()
|
||||
));
|
||||
} else if (X509_KEYSPEC_CLS.isAssignableFrom(keySpec)) {
|
||||
} else if (keySpec.isAssignableFrom(X509_KEYSPEC_CLS)) {
|
||||
return keySpec.cast(new X509EncodedKeySpec(key.getEncoded()));
|
||||
} else {
|
||||
throw new InvalidKeySpecException
|
||||
|
@ -403,9 +403,9 @@ public class RSAKeyFactory extends KeyFactorySpi {
|
|||
+ "X509EncodedKeySpec for RSA public keys");
|
||||
}
|
||||
} else if (key instanceof RSAPrivateKey) {
|
||||
if (PKCS8_KEYSPEC_CLS.isAssignableFrom(keySpec)) {
|
||||
if (keySpec.isAssignableFrom(PKCS8_KEYSPEC_CLS)) {
|
||||
return keySpec.cast(new PKCS8EncodedKeySpec(key.getEncoded()));
|
||||
} else if (RSA_PRIVCRT_KEYSPEC_CLS.isAssignableFrom(keySpec)) {
|
||||
} else if (keySpec.isAssignableFrom(RSA_PRIVCRT_KEYSPEC_CLS)) {
|
||||
if (key instanceof RSAPrivateCrtKey) {
|
||||
RSAPrivateCrtKey crtKey = (RSAPrivateCrtKey)key;
|
||||
return keySpec.cast(new RSAPrivateCrtKeySpec(
|
||||
|
@ -423,7 +423,7 @@ public class RSAKeyFactory extends KeyFactorySpi {
|
|||
throw new InvalidKeySpecException
|
||||
("RSAPrivateCrtKeySpec can only be used with CRT keys");
|
||||
}
|
||||
} else if (RSA_PRIV_KEYSPEC_CLS.isAssignableFrom(keySpec)) {
|
||||
} else if (keySpec.isAssignableFrom(RSA_PRIV_KEYSPEC_CLS)) {
|
||||
RSAPrivateKey rsaKey = (RSAPrivateKey)key;
|
||||
return keySpec.cast(new RSAPrivateKeySpec(
|
||||
rsaKey.getModulus(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue