Skip to content

Commit 9eded68

Browse files
committed
8246383: NullPointerException in JceSecurity.getVerificationResult when using Entrust provider
Removed the static SecureRandom object in JceSecurity whose instantion caused NPE Backport-of: 03f2ab3
1 parent 1cbdcc9 commit 9eded68

File tree

5 files changed

+15
-17
lines changed

5 files changed

+15
-17
lines changed

src/java.base/share/classes/java/security/AlgorithmParameterGenerator.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -27,6 +27,7 @@
2727

2828
import java.security.spec.AlgorithmParameterSpec;
2929
import java.util.Objects;
30+
import sun.security.jca.JCAUtil;
3031

3132
/**
3233
* The {@code AlgorithmParameterGenerator} class is used to generate a
@@ -308,7 +309,7 @@ public final Provider getProvider() {
308309
* @param size the size (number of bits).
309310
*/
310311
public final void init(int size) {
311-
paramGenSpi.engineInit(size, new SecureRandom());
312+
paramGenSpi.engineInit(size, JCAUtil.getSecureRandom());
312313
}
313314

314315
/**
@@ -339,7 +340,7 @@ public final void init(int size, SecureRandom random) {
339340
*/
340341
public final void init(AlgorithmParameterSpec genParamSpec)
341342
throws InvalidAlgorithmParameterException {
342-
paramGenSpi.engineInit(genParamSpec, new SecureRandom());
343+
paramGenSpi.engineInit(genParamSpec, JCAUtil.getSecureRandom());
343344
}
344345

345346
/**

src/java.base/share/classes/javax/crypto/Cipher.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,7 +1220,7 @@ private static String getOpmodeString(int opmode) {
12201220
* by the underlying {@code CipherSpi}.
12211221
*/
12221222
public final void init(int opmode, Key key) throws InvalidKeyException {
1223-
init(opmode, key, JceSecurity.RANDOM);
1223+
init(opmode, key, JCAUtil.getSecureRandom());
12241224
}
12251225

12261226
/**
@@ -1361,7 +1361,7 @@ public final void init(int opmode, Key key, SecureRandom random)
13611361
public final void init(int opmode, Key key, AlgorithmParameterSpec params)
13621362
throws InvalidKeyException, InvalidAlgorithmParameterException
13631363
{
1364-
init(opmode, key, params, JceSecurity.RANDOM);
1364+
init(opmode, key, params, JCAUtil.getSecureRandom());
13651365
}
13661366

13671367
/**
@@ -1504,7 +1504,7 @@ public final void init(int opmode, Key key, AlgorithmParameterSpec params,
15041504
public final void init(int opmode, Key key, AlgorithmParameters params)
15051505
throws InvalidKeyException, InvalidAlgorithmParameterException
15061506
{
1507-
init(opmode, key, params, JceSecurity.RANDOM);
1507+
init(opmode, key, params, JCAUtil.getSecureRandom());
15081508
}
15091509

15101510
/**
@@ -1652,7 +1652,7 @@ public final void init(int opmode, Key key, AlgorithmParameters params,
16521652
public final void init(int opmode, Certificate certificate)
16531653
throws InvalidKeyException
16541654
{
1655-
init(opmode, certificate, JceSecurity.RANDOM);
1655+
init(opmode, certificate, JCAUtil.getSecureRandom());
16561656
}
16571657

16581658
/**

src/java.base/share/classes/javax/crypto/JceSecurity.java.template

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -74,11 +74,8 @@ import sun.security.util.Debug;
7474

7575
final class JceSecurity {
7676

77-
7877
private static final Debug debug = Debug.getInstance("jca");
7978

80-
static final SecureRandom RANDOM = new SecureRandom();
81-
8279
// The defaultPolicy and exemptPolicy will be set up
8380
// in the static initializer.
8481
private static CryptoPermissions defaultPolicy = null;

src/java.base/share/classes/javax/crypto/KeyAgreement.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -446,7 +446,7 @@ public final Provider getProvider() {
446446
* has an incompatible algorithm type.
447447
*/
448448
public final void init(Key key) throws InvalidKeyException {
449-
init(key, JceSecurity.RANDOM);
449+
init(key, JCAUtil.getSecureRandom());
450450
}
451451

452452
/**
@@ -514,7 +514,7 @@ public final void init(Key key, SecureRandom random)
514514
public final void init(Key key, AlgorithmParameterSpec params)
515515
throws InvalidKeyException, InvalidAlgorithmParameterException
516516
{
517-
init(key, params, JceSecurity.RANDOM);
517+
init(key, params, JCAUtil.getSecureRandom());
518518
}
519519

520520
private String getProviderName() {

src/java.base/share/classes/javax/crypto/KeyGenerator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -450,7 +450,7 @@ public final void init(SecureRandom random) {
450450
public final void init(AlgorithmParameterSpec params)
451451
throws InvalidAlgorithmParameterException
452452
{
453-
init(params, JceSecurity.RANDOM);
453+
init(params, JCAUtil.getSecureRandom());
454454
}
455455

456456
/**
@@ -514,7 +514,7 @@ public final void init(AlgorithmParameterSpec params, SecureRandom random)
514514
* supported.
515515
*/
516516
public final void init(int keysize) {
517-
init(keysize, JceSecurity.RANDOM);
517+
init(keysize, JCAUtil.getSecureRandom());
518518
}
519519

520520
/**

0 commit comments

Comments
 (0)