Skip to content

Commit de6e013

Browse files
committed
8344310: Remove Security Manager dependencies from javax.crypto and com.sun.crypto packages
Reviewed-by: jpai, ascarpino
1 parent 92271af commit de6e013

File tree

7 files changed

+29
-101
lines changed

7 files changed

+29
-101
lines changed

src/java.base/share/classes/com/sun/crypto/provider/DHKeyAgreement.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,8 @@ public final class DHKeyAgreement
5656

5757
private static class AllowKDF {
5858

59-
private static final boolean VALUE = getValue();
60-
61-
@SuppressWarnings("removal")
62-
private static boolean getValue() {
63-
return AccessController.doPrivileged(
64-
(PrivilegedAction<Boolean>)
65-
() -> Boolean.getBoolean("jdk.crypto.KeyAgreement.legacyKDF"));
66-
}
59+
private static final boolean VALUE =
60+
Boolean.getBoolean("jdk.crypto.KeyAgreement.legacyKDF");
6761
}
6862

6963
/**

src/java.base/share/classes/com/sun/crypto/provider/JceKeyStore.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,12 @@
3030

3131
import java.io.*;
3232
import java.util.*;
33-
import java.security.AccessController;
3433
import java.security.DigestInputStream;
3534
import java.security.DigestOutputStream;
3635
import java.security.MessageDigest;
3736
import java.security.NoSuchAlgorithmException;
3837
import java.security.Key;
3938
import java.security.PrivateKey;
40-
import java.security.PrivilegedAction;
4139
import java.security.KeyStoreSpi;
4240
import java.security.KeyStoreException;
4341
import java.security.UnrecoverableKeyException;
@@ -835,15 +833,9 @@ public void engineLoad(InputStream stream, char[] password)
835833
// read the sealed key
836834
try {
837835
ois = new ObjectInputStream(dis);
838-
final ObjectInputStream ois2 = ois;
839836
// Set a deserialization checker
840-
@SuppressWarnings("removal")
841-
var dummy = AccessController.doPrivileged(
842-
(PrivilegedAction<Void>)() -> {
843-
ois2.setObjectInputFilter(
844-
new DeserializationChecker(fullLength));
845-
return null;
846-
});
837+
ois.setObjectInputFilter(
838+
new DeserializationChecker(fullLength));
847839
entry.sealedKey = (SealedObject)ois.readObject();
848840
entry.maxLength = fullLength;
849841
// NOTE: don't close ois here since we are still

src/java.base/share/classes/com/sun/crypto/provider/SealedObjectForKeyProtector.java

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2024, 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
@@ -73,18 +73,13 @@ AlgorithmParameters getParameters() {
7373
return params;
7474
}
7575

76-
@SuppressWarnings("removal")
7776
final Key getKey(Cipher c, int maxLength)
7877
throws IOException, ClassNotFoundException, IllegalBlockSizeException,
7978
BadPaddingException {
8079

8180
try (ObjectInputStream ois = SharedSecrets.getJavaxCryptoSealedObjectAccess()
8281
.getExtObjectInputStream(this, c)) {
83-
AccessController.doPrivileged(
84-
(PrivilegedAction<Void>) () -> {
85-
ois.setObjectInputFilter(new DeserializationChecker(maxLength));
86-
return null;
87-
});
82+
ois.setObjectInputFilter(new DeserializationChecker(maxLength));
8883
try {
8984
@SuppressWarnings("unchecked")
9085
Key t = (Key) ois.readObject();
@@ -113,16 +108,8 @@ private static class DeserializationChecker implements ObjectInputFilter {
113108
private static final ObjectInputFilter OWN_FILTER;
114109

115110
static {
116-
@SuppressWarnings("removal")
117-
String prop = AccessController.doPrivileged(
118-
(PrivilegedAction<String>) () -> {
119-
String tmp = System.getProperty(KEY_SERIAL_FILTER);
120-
if (tmp != null) {
121-
return tmp;
122-
} else {
123-
return Security.getProperty(KEY_SERIAL_FILTER);
124-
}
125-
});
111+
String prop = System.getProperty(
112+
KEY_SERIAL_FILTER, Security.getProperty(KEY_SERIAL_FILTER));
126113
OWN_FILTER = prop == null
127114
? null
128115
: ObjectInputFilter.Config.createFilter(prop);

src/java.base/share/classes/com/sun/crypto/provider/SunJCE.java

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@
2525

2626
package com.sun.crypto.provider;
2727

28-
import java.security.AccessController;
2928
import java.security.Provider;
3029
import java.security.SecureRandom;
31-
import java.security.PrivilegedAction;
3230
import java.util.HashMap;
3331
import java.util.List;
3432
import static sun.security.util.SecurityConstants.PROVIDER_VER;
@@ -121,24 +119,12 @@ private void psA(String type, String algo, String cn,
121119
attrs));
122120
}
123121

124-
@SuppressWarnings("removal")
125122
public SunJCE() {
126123
/* We are the "SunJCE" provider */
127124
super("SunJCE", PROVIDER_VER, info);
128125

129-
// if there is no security manager installed, put directly into
130-
// the provider
131-
if (System.getSecurityManager() == null) {
132-
putEntries();
133-
} else {
134-
AccessController.doPrivileged(new PrivilegedAction<Void>() {
135-
@Override
136-
public Void run() {
137-
putEntries();
138-
return null;
139-
}
140-
});
141-
}
126+
putEntries();
127+
142128
if (instance == null) {
143129
instance = this;
144130
}

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

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ import sun.security.util.Debug;
7676
* @since 1.4
7777
*/
7878

79-
@SuppressWarnings("removal")
8079
final class JceSecurity {
8180

8281
private static final Debug debug = Debug.getInstance("jca");
@@ -109,15 +108,7 @@ final class JceSecurity {
109108

110109
static {
111110
try {
112-
AccessController.doPrivileged(
113-
new PrivilegedExceptionAction<> () {
114-
@Override
115-
public Void run() throws Exception {
116-
setupJurisdictionPolicies();
117-
return null;
118-
}
119-
}
120-
);
111+
setupJurisdictionPolicies();
121112

122113
isRestricted = defaultPolicy.implies(
123114
CryptoAllPermission.INSTANCE) ? false : true;
@@ -285,20 +276,14 @@ final class JceSecurity {
285276
synchronized (codeBaseCacheRef) {
286277
URL url = codeBaseCacheRef.get(clazz);
287278
if (url == null) {
288-
url = AccessController.doPrivileged(
289-
new PrivilegedAction<>() {
290-
@Override
291-
public URL run() {
292-
ProtectionDomain pd = clazz.getProtectionDomain();
293-
if (pd != null) {
294-
CodeSource cs = pd.getCodeSource();
295-
if (cs != null) {
296-
return cs.getLocation();
297-
}
298-
}
299-
return NULL_URL;
300-
}
301-
});
279+
url = NULL_URL;
280+
ProtectionDomain pd = clazz.getProtectionDomain();
281+
if (pd != null) {
282+
CodeSource cs = pd.getCodeSource();
283+
if (cs != null) {
284+
url = cs.getLocation();
285+
}
286+
}
302287
codeBaseCacheRef.put(clazz, url);
303288
}
304289
return (url == NULL_URL) ? null : url;

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,10 @@ final class JceSecurityManager {
6565
exemptPolicy = JceSecurity.getExemptPolicy();
6666
allPerm = CryptoAllPermission.INSTANCE;
6767

68-
PrivilegedAction<JceSecurityManager> paSM = JceSecurityManager::new;
69-
@SuppressWarnings("removal")
70-
JceSecurityManager dummySecurityManager =
71-
AccessController.doPrivileged(paSM);
72-
INSTANCE = dummySecurityManager;
68+
INSTANCE = new JceSecurityManager();
7369

74-
PrivilegedAction<StackWalker> paWalker =
75-
() -> StackWalker.getInstance(Set.of(Option.DROP_METHOD_INFO, Option.RETAIN_CLASS_REFERENCE));
76-
@SuppressWarnings("removal")
77-
StackWalker dummyWalker = AccessController.doPrivileged(paWalker);
78-
79-
WALKER = dummyWalker;
70+
WALKER = StackWalker.getInstance(
71+
Set.of(Option.DROP_METHOD_INFO, Option.RETAIN_CLASS_REFERENCE));
8072
}
8173

8274
private JceSecurityManager() {

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

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2007, 2024, 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
@@ -100,20 +100,12 @@ void verify() throws IOException {
100100

101101
// Get a link to the Jarfile to search.
102102
try {
103-
@SuppressWarnings("removal")
104-
var tmp = AccessController.doPrivileged(
105-
(PrivilegedExceptionAction<JarFile>) () -> {
106-
JarURLConnection conn =
107-
(JarURLConnection) url.openConnection();
108-
// You could do some caching here as
109-
// an optimization.
110-
conn.setUseCaches(false);
111-
return conn.getJarFile();
112-
});
113-
jf = tmp;
114-
} catch (java.security.PrivilegedActionException pae) {
115-
throw new SecurityException("Cannot load " + url,
116-
pae.getCause());
103+
JarURLConnection conn = (JarURLConnection) url.openConnection();
104+
// You could do some caching here as an optimization.
105+
conn.setUseCaches(false);
106+
jf = conn.getJarFile();
107+
} catch (IOException ioe) {
108+
throw new SecurityException("Cannot load " + url, ioe);
117109
}
118110

119111
if (jf != null) {

0 commit comments

Comments
 (0)