mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8174756: Extra validation for public keys
Reviewed-by: valeriep
This commit is contained in:
parent
933e26ad58
commit
248948c08b
1 changed files with 15 additions and 0 deletions
|
@ -48,6 +48,7 @@ import sun.security.x509.X509Key;
|
||||||
public final class RSAPublicKeyImpl extends X509Key implements RSAPublicKey {
|
public final class RSAPublicKeyImpl extends X509Key implements RSAPublicKey {
|
||||||
|
|
||||||
private static final long serialVersionUID = 2644735423591199609L;
|
private static final long serialVersionUID = 2644735423591199609L;
|
||||||
|
private static final BigInteger THREE = BigInteger.valueOf(3);
|
||||||
|
|
||||||
private BigInteger n; // modulus
|
private BigInteger n; // modulus
|
||||||
private BigInteger e; // public exponent
|
private BigInteger e; // public exponent
|
||||||
|
@ -61,6 +62,7 @@ public final class RSAPublicKeyImpl extends X509Key implements RSAPublicKey {
|
||||||
this.n = n;
|
this.n = n;
|
||||||
this.e = e;
|
this.e = e;
|
||||||
RSAKeyFactory.checkRSAProviderKeyLengths(n.bitLength(), e);
|
RSAKeyFactory.checkRSAProviderKeyLengths(n.bitLength(), e);
|
||||||
|
checkExponentRange();
|
||||||
// generate the encoding
|
// generate the encoding
|
||||||
algid = RSAPrivateCrtKeyImpl.rsaId;
|
algid = RSAPrivateCrtKeyImpl.rsaId;
|
||||||
try {
|
try {
|
||||||
|
@ -83,6 +85,19 @@ public final class RSAPublicKeyImpl extends X509Key implements RSAPublicKey {
|
||||||
public RSAPublicKeyImpl(byte[] encoded) throws InvalidKeyException {
|
public RSAPublicKeyImpl(byte[] encoded) throws InvalidKeyException {
|
||||||
decode(encoded);
|
decode(encoded);
|
||||||
RSAKeyFactory.checkRSAProviderKeyLengths(n.bitLength(), e);
|
RSAKeyFactory.checkRSAProviderKeyLengths(n.bitLength(), e);
|
||||||
|
checkExponentRange();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkExponentRange() throws InvalidKeyException {
|
||||||
|
// the exponent should be smaller than the modulus
|
||||||
|
if (e.compareTo(n) >= 0) {
|
||||||
|
throw new InvalidKeyException("exponent is larger than modulus");
|
||||||
|
}
|
||||||
|
|
||||||
|
// the exponent should be at least 3
|
||||||
|
if (e.compareTo(THREE) < 0) {
|
||||||
|
throw new InvalidKeyException("exponent is smaller than 3");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// see JCA doc
|
// see JCA doc
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue