8285263: Minor cleanup could be done in java.security

Reviewed-by: weijun
This commit is contained in:
Mark Powers 2022-06-13 15:13:56 +00:00 committed by Weijun Wang
parent b97a4f6cdc
commit 17695962ac
94 changed files with 480 additions and 601 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2010, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -61,12 +61,12 @@ public interface AlgorithmConstraints {
* parameters * parameters
* *
* @return true if the algorithm is permitted and can be used for all * @return true if the algorithm is permitted and can be used for all
* of the specified cryptographic primitives * the specified cryptographic primitives
* *
* @throws IllegalArgumentException if primitives or algorithm is null * @throws IllegalArgumentException if primitives or algorithm is null
* or empty * or empty
*/ */
public boolean permits(Set<CryptoPrimitive> primitives, boolean permits(Set<CryptoPrimitive> primitives,
String algorithm, AlgorithmParameters parameters); String algorithm, AlgorithmParameters parameters);
/** /**
@ -78,13 +78,13 @@ public interface AlgorithmConstraints {
* @param primitives a set of cryptographic primitives * @param primitives a set of cryptographic primitives
* @param key the key * @param key the key
* *
* @return true if the key can be used for all of the specified * @return true if the key can be used for all the specified
* cryptographic primitives * cryptographic primitives
* *
* @throws IllegalArgumentException if primitives is null or empty, * @throws IllegalArgumentException if primitives is null or empty,
* or the key is null * or the key is null
*/ */
public boolean permits(Set<CryptoPrimitive> primitives, Key key); boolean permits(Set<CryptoPrimitive> primitives, Key key);
/** /**
* Determines whether an algorithm and the corresponding key are granted * Determines whether an algorithm and the corresponding key are granted
@ -96,13 +96,13 @@ public interface AlgorithmConstraints {
* @param parameters the algorithm parameters, or null if no additional * @param parameters the algorithm parameters, or null if no additional
* parameters * parameters
* *
* @return true if the key and the algorithm can be used for all of the * @return true if the key and the algorithm can be used for all the
* specified cryptographic primitives * specified cryptographic primitives
* *
* @throws IllegalArgumentException if primitives or algorithm is null * @throws IllegalArgumentException if primitives or algorithm is null
* or empty, or the key is null * or empty, or the key is null
*/ */
public boolean permits(Set<CryptoPrimitive> primitives, boolean permits(Set<CryptoPrimitive> primitives,
String algorithm, Key key, AlgorithmParameters parameters); String algorithm, Key key, AlgorithmParameters parameters);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -99,13 +99,13 @@ import sun.security.jca.JCAUtil;
public class AlgorithmParameterGenerator { public class AlgorithmParameterGenerator {
// The provider // The provider
private Provider provider; private final Provider provider;
// The provider implementation (delegate) // The provider implementation (delegate)
private AlgorithmParameterGeneratorSpi paramGenSpi; private final AlgorithmParameterGeneratorSpi paramGenSpi;
// The algorithm // The algorithm
private String algorithm; private final String algorithm;
/** /**
* Creates an AlgorithmParameterGenerator object. * Creates an AlgorithmParameterGenerator object.
@ -150,7 +150,7 @@ public class AlgorithmParameterGenerator {
* {@code jdk.security.provider.preferred} * {@code jdk.security.provider.preferred}
* {@link Security#getProperty(String) Security} property to determine * {@link Security#getProperty(String) Security} property to determine
* the preferred provider order for the specified algorithm. This * the preferred provider order for the specified algorithm. This
* may be different than the order of providers returned by * may be different from the order of providers returned by
* {@link Security#getProviders() Security.getProviders()}. * {@link Security#getProviders() Security.getProviders()}.
* *
* @param algorithm the name of the algorithm this * @param algorithm the name of the algorithm this

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -75,13 +75,13 @@ import java.util.Objects;
public class AlgorithmParameters { public class AlgorithmParameters {
// The provider // The provider
private Provider provider; private final Provider provider;
// The provider implementation (delegate) // The provider implementation (delegate)
private AlgorithmParametersSpi paramSpi; private final AlgorithmParametersSpi paramSpi;
// The algorithm // The algorithm
private String algorithm; private final String algorithm;
// Has this object been initialized? // Has this object been initialized?
private boolean initialized = false; private boolean initialized = false;
@ -131,7 +131,7 @@ public class AlgorithmParameters {
* {@code jdk.security.provider.preferred} * {@code jdk.security.provider.preferred}
* {@link Security#getProperty(String) Security} property to determine * {@link Security#getProperty(String) Security} property to determine
* the preferred provider order for the specified algorithm. This * the preferred provider order for the specified algorithm. This
* may be different than the order of providers returned by * may be different from the order of providers returned by
* {@link Security#getProviders() Security.getProviders()}. * {@link Security#getProviders() Security.getProviders()}.
* *
* @param algorithm the name of the algorithm requested. * @param algorithm the name of the algorithm requested.
@ -342,7 +342,7 @@ public class AlgorithmParameters {
* parameters should be returned in an instance of the * parameters should be returned in an instance of the
* {@code DSAParameterSpec} class. * {@code DSAParameterSpec} class.
* *
* @param <T> the type of the parameter specification to be returrned * @param <T> the type of the parameter specification to be returned
* @param paramSpec the specification class in which * @param paramSpec the specification class in which
* the parameters should be returned. * the parameters should be returned.
* *
@ -356,7 +356,7 @@ public class AlgorithmParameters {
T getParameterSpec(Class<T> paramSpec) T getParameterSpec(Class<T> paramSpec)
throws InvalidParameterSpecException throws InvalidParameterSpecException
{ {
if (this.initialized == false) { if (!this.initialized) {
throw new InvalidParameterSpecException("not initialized"); throw new InvalidParameterSpecException("not initialized");
} }
return paramSpi.engineGetParameterSpec(paramSpec); return paramSpi.engineGetParameterSpec(paramSpec);
@ -374,7 +374,7 @@ public class AlgorithmParameters {
*/ */
public final byte[] getEncoded() throws IOException public final byte[] getEncoded() throws IOException
{ {
if (this.initialized == false) { if (!this.initialized) {
throw new IOException("not initialized"); throw new IOException("not initialized");
} }
return paramSpi.engineGetEncoded(); return paramSpi.engineGetEncoded();
@ -396,7 +396,7 @@ public class AlgorithmParameters {
*/ */
public final byte[] getEncoded(String format) throws IOException public final byte[] getEncoded(String format) throws IOException
{ {
if (this.initialized == false) { if (!this.initialized) {
throw new IOException("not initialized"); throw new IOException("not initialized");
} }
return paramSpi.engineGetEncoded(format); return paramSpi.engineGetEncoded(format);
@ -409,7 +409,7 @@ public class AlgorithmParameters {
* parameter object has not been initialized. * parameter object has not been initialized.
*/ */
public final String toString() { public final String toString() {
if (this.initialized == false) { if (!this.initialized) {
return null; return null;
} }
return paramSpi.engineToString(); return paramSpi.engineToString();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,12 +25,10 @@
package java.security; package java.security;
import java.security.*;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.StringTokenizer;
import sun.security.util.SecurityConstants; import sun.security.util.SecurityConstants;
import java.util.Enumeration;
/** /**
* The AllPermission is a permission that implies all other permissions. * The AllPermission is a permission that implies all other permissions.
* <p> * <p>

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -40,7 +40,7 @@ import java.util.concurrent.ConcurrentHashMap;
* <P> * <P>
* The name for a BasicPermission is the name of the given permission * The name for a BasicPermission is the name of the given permission
* (for example, "exit", * (for example, "exit",
* "setFactory", "print.queueJob", etc). The naming * "setFactory", "print.queueJob", etc.). The naming
* convention follows the hierarchical property naming convention. * convention follows the hierarchical property naming convention.
* An asterisk may appear by itself, or if immediately preceded by a "." * An asterisk may appear by itself, or if immediately preceded by a "."
* may appear at the end of the name, to signify a wildcard match. * may appear at the end of the name, to signify a wildcard match.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -46,14 +46,14 @@ public final class CodeSigner implements Serializable {
* *
* @serial * @serial
*/ */
private CertPath signerCertPath; private final CertPath signerCertPath;
/** /**
* The signature timestamp. * The signature timestamp.
* *
* @serial * @serial
*/ */
private Timestamp timestamp; private final Timestamp timestamp;
/* /*
* Hash code for this code signer. * Hash code for this code signer.
@ -126,7 +126,7 @@ public final class CodeSigner implements Serializable {
* @return true if the objects are considered equal, false otherwise. * @return true if the objects are considered equal, false otherwise.
*/ */
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj == null || (!(obj instanceof CodeSigner that))) { if ((!(obj instanceof CodeSigner that))) {
return false; return false;
} }
@ -139,8 +139,7 @@ public final class CodeSigner implements Serializable {
return false; return false;
} }
} else { } else {
if (thatTimestamp == null || if ((!timestamp.equals(thatTimestamp))) {
(! timestamp.equals(thatTimestamp))) {
return false; return false;
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -80,7 +80,7 @@ public class CodeSource implements java.io.Serializable {
/** /**
* A String form of the URL for use as a key in HashMaps/Sets. The String * A String form of the URL for use as a key in HashMaps/Sets. The String
* form should be behave in the same manner as the URL when compared for * form should behave in the same manner as the URL when compared for
* equality in a HashMap/Set, except that no nameservice lookup is done * equality in a HashMap/Set, except that no nameservice lookup is done
* on the hostname (only string comparison), and the fragment is not * on the hostname (only string comparison), and the fragment is not
* considered. * considered.
@ -211,7 +211,7 @@ public class CodeSource implements java.io.Serializable {
signers[i].getSignerCertPath().getCertificates()); signers[i].getSignerCertPath().getCertificates());
} }
certs = certChains.toArray( certs = certChains.toArray(
new java.security.cert.Certificate[certChains.size()]); new java.security.cert.Certificate[0]);
return certs.clone(); return certs.clone();
} else { } else {
@ -330,7 +330,7 @@ public class CodeSource implements java.io.Serializable {
* *
* @param that the CodeSource to check against. * @param that the CodeSource to check against.
* @param strict if true then a strict equality match is performed. * @param strict if true then a strict equality match is performed.
* Otherwise a subset match is performed. * Otherwise, a subset match is performed.
*/ */
boolean matchCerts(CodeSource that, boolean strict) boolean matchCerts(CodeSource that, boolean strict)
{ {
@ -461,9 +461,7 @@ public class CodeSource implements java.io.Serializable {
if (that.sp == null) { if (that.sp == null) {
that.sp = new SocketPermission(thatHost, "resolve"); that.sp = new SocketPermission(thatHost, "resolve");
} }
if (!this.sp.implies(that.sp)) { return this.sp.implies(that.sp);
return false;
}
} }
} }
// everything matches // everything matches
@ -570,7 +568,7 @@ public class CodeSource implements java.io.Serializable {
// we know of 3 different cert types: X.509, PGP, SDSI, which // we know of 3 different cert types: X.509, PGP, SDSI, which
// could all be present in the stream at the same time // could all be present in the stream at the same time
cfs = new Hashtable<>(3); cfs = new Hashtable<>(3);
certList = new ArrayList<>(size > 20 ? 20 : size); certList = new ArrayList<>(Math.min(size, 20));
} else if (size < 0) { } else if (size < 0) {
throw new IOException("size cannot be negative"); throw new IOException("size cannot be negative");
} }
@ -665,7 +663,7 @@ public class CodeSource implements java.io.Serializable {
if (signers.isEmpty()) { if (signers.isEmpty()) {
return null; return null;
} else { } else {
return signers.toArray(new CodeSigner[signers.size()]); return signers.toArray(new CodeSigner[0]);
} }
} catch (CertificateException e) { } catch (CertificateException e) {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,12 +25,9 @@
package java.security; package java.security;
import java.io.IOException;
import java.io.EOFException;
import java.io.InputStream;
import java.io.FilterInputStream; import java.io.FilterInputStream;
import java.io.PrintStream; import java.io.IOException;
import java.io.ByteArrayInputStream; import java.io.InputStream;
/** /**
* A transparent stream that updates the associated message digest using * A transparent stream that updates the associated message digest using

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,12 +25,9 @@
package java.security; package java.security;
import java.io.IOException;
import java.io.EOFException;
import java.io.OutputStream;
import java.io.FilterOutputStream; import java.io.FilterOutputStream;
import java.io.PrintStream; import java.io.IOException;
import java.io.ByteArrayOutputStream; import java.io.OutputStream;
/** /**
* A transparent stream that updates the associated message digest using * A transparent stream that updates the associated message digest using

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -49,7 +49,7 @@ import static java.security.KeyStore.*;
* and {@code property} is a key/value pairing. The key and value are * and {@code property} is a key/value pairing. The key and value are
* separated by an 'equals' symbol and the value is enclosed in double * separated by an 'equals' symbol and the value is enclosed in double
* quotes. A property value may be either a printable string or a binary * quotes. A property value may be either a printable string or a binary
* string of colon-separated pairs of hexadecimal digits. Multi-valued * string of colon-separated pairs of hexadecimal digits. Multivalued
* properties are represented as a comma-separated list of values, * properties are represented as a comma-separated list of values,
* enclosed in square brackets. * enclosed in square brackets.
* See {@link Arrays#toString(java.lang.Object[])}. * See {@link Arrays#toString(java.lang.Object[])}.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,6 +25,7 @@
package java.security; package java.security;
import java.util.Arrays;
import java.util.Locale; import java.util.Locale;
import java.util.Objects; import java.util.Objects;
@ -403,7 +404,7 @@ public class DrbgParameters {
@Override @Override
public String toString() { public String toString() {
// I don't care what personalizationString looks like // I don't care what personalizationString looks like
return strength + "," + capability + "," + personalizationString; return strength + "," + capability + "," + Arrays.toString(personalizationString);
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -32,7 +32,7 @@ package java.security;
* <p>This interface contains a single method, {@code checkGuard}, * <p>This interface contains a single method, {@code checkGuard},
* with a single {@code object} argument. {@code checkGuard} is * with a single {@code object} argument. {@code checkGuard} is
* invoked (by the GuardedObject {@code getObject} method) * invoked (by the GuardedObject {@code getObject} method)
* to determine whether or not to allow access to the object. * to determine whether to allow access to the object.
* *
* @see GuardedObject * @see GuardedObject
* *
@ -44,7 +44,7 @@ package java.security;
public interface Guard { public interface Guard {
/** /**
* Determines whether or not to allow access to the guarded object * Determines whether to allow access to the guarded object
* {@code object}. Returns silently if access is allowed. * {@code object}. Returns silently if access is allowed.
* Otherwise, throws a SecurityException. * Otherwise, throws a SecurityException.
* *

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -58,13 +58,13 @@ public class GuardedObject implements java.io.Serializable {
* The object we are guarding. * The object we are guarding.
*/ */
@SuppressWarnings("serial") // Not statically typed as Serializable @SuppressWarnings("serial") // Not statically typed as Serializable
private Object object; private final Object object;
/** /**
* The guard object. * The guard object.
*/ */
@SuppressWarnings("serial") // Not statically typed as Serializable @SuppressWarnings("serial") // Not statically typed as Serializable
private Guard guard; private final Guard guard;
/** /**
* Constructs a GuardedObject using the specified object and guard. * Constructs a GuardedObject using the specified object and guard.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -28,7 +28,7 @@ package java.security;
/** /**
* This is the exception for invalid Keys (invalid encoding, wrong * This is the exception for invalid Keys (invalid encoding, wrong
* length, uninitialized, etc). * length, uninitialized, etc.).
* *
* @author Benjamin Renaud * @author Benjamin Renaud
* @since 1.1 * @since 1.1

View File

@ -113,7 +113,7 @@ public interface Key extends java.io.Serializable {
@Deprecated @Deprecated
@SuppressWarnings("serial") @SuppressWarnings("serial")
@java.io.Serial @java.io.Serial
static final long serialVersionUID = 6603384152749567654L; long serialVersionUID = 6603384152749567654L;
/** /**
* Returns the standard algorithm name for this key. For * Returns the standard algorithm name for this key. For
@ -126,7 +126,7 @@ public interface Key extends java.io.Serializable {
* *
* @return the name of the algorithm associated with this key. * @return the name of the algorithm associated with this key.
*/ */
public String getAlgorithm(); String getAlgorithm();
/** /**
* Returns the name of the primary encoding format of this key, * Returns the name of the primary encoding format of this key,
@ -145,7 +145,7 @@ public interface Key extends java.io.Serializable {
* *
* @return the primary encoding format of the key. * @return the primary encoding format of the key.
*/ */
public String getFormat(); String getFormat();
/** /**
* Returns the key in its primary encoding format, or null * Returns the key in its primary encoding format, or null
@ -154,5 +154,5 @@ public interface Key extends java.io.Serializable {
* @return the encoded key, or null if the key does not support * @return the encoded key, or null if the key does not support
* encoding. * encoding.
*/ */
public byte[] getEncoded(); byte[] getEncoded();
} }

View File

@ -41,7 +41,7 @@ import sun.security.jca.GetInstance.Instance;
* (transparent representations of the underlying key material), and vice * (transparent representations of the underlying key material), and vice
* versa. * versa.
* *
* <P> Key factories are bi-directional. That is, they allow you to build an * <P> Key factories are bidirectional. That is, they allow you to build an
* opaque key object from a given key specification (key material), or to * opaque key object from a given key specification (key material), or to
* retrieve the underlying key material of a key object in a suitable format. * retrieve the underlying key material of a key object in a suitable format.
* *
@ -158,7 +158,7 @@ public class KeyFactory {
* {@code jdk.security.provider.preferred} * {@code jdk.security.provider.preferred}
* {@link Security#getProperty(String) Security} property to determine * {@link Security#getProperty(String) Security} property to determine
* the preferred provider order for the specified algorithm. This * the preferred provider order for the specified algorithm. This
* may be different than the order of providers returned by * may be different from the order of providers returned by
* {@link Security#getProviders() Security.getProviders()}. * {@link Security#getProviders() Security.getProviders()}.
* *
* @param algorithm the name of the requested key algorithm. * @param algorithm the name of the requested key algorithm.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -40,7 +40,7 @@ import java.security.spec.InvalidKeySpecException;
* (transparent representations of the underlying key material), and vice * (transparent representations of the underlying key material), and vice
* versa. * versa.
* *
* <P> Key factories are bi-directional. That is, they allow you to build an * <P> Key factories are bidirectional. That is, they allow you to build an
* opaque key object from a given key specification (key material), or to * opaque key object from a given key specification (key material), or to
* retrieve the underlying key material of a key object in a suitable format. * retrieve the underlying key material of a key object in a suitable format.
* *

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,8 +25,6 @@
package java.security; package java.security;
import java.util.*;
/** /**
* This class is a simple holder for a key pair (a public key and a * This class is a simple holder for a key pair (a public key and a
* private key). It does not enforce any security, and, when initialized, * private key). It does not enforce any security, and, when initialized,
@ -45,10 +43,10 @@ public final class KeyPair implements java.io.Serializable {
private static final long serialVersionUID = -7565189502268009837L; private static final long serialVersionUID = -7565189502268009837L;
/** The private key. */ /** The private key. */
private PrivateKey privateKey; private final PrivateKey privateKey;
/** The public key. */ /** The public key. */
private PublicKey publicKey; private final PublicKey publicKey;
/** /**
* Constructs a key pair from the given public key and private key. * Constructs a key pair from the given public key and private key.

View File

@ -207,7 +207,7 @@ public abstract class KeyPairGenerator extends KeyPairGeneratorSpi {
* {@code jdk.security.provider.preferred} * {@code jdk.security.provider.preferred}
* {@link Security#getProperty(String) Security} property to determine * {@link Security#getProperty(String) Security} property to determine
* the preferred provider order for the specified algorithm. This * the preferred provider order for the specified algorithm. This
* may be different than the order of providers returned by * may be different from the order of providers returned by
* {@link Security#getProviders() Security.getProviders()}. * {@link Security#getProviders() Security.getProviders()}.
* *
* @param algorithm the standard string name of the algorithm. * @param algorithm the standard string name of the algorithm.
@ -232,7 +232,7 @@ public abstract class KeyPairGenerator extends KeyPairGeneratorSpi {
List<Service> list = List<Service> list =
GetInstance.getServices("KeyPairGenerator", algorithm); GetInstance.getServices("KeyPairGenerator", algorithm);
Iterator<Service> t = list.iterator(); Iterator<Service> t = list.iterator();
if (t.hasNext() == false) { if (!t.hasNext()) {
throw new NoSuchAlgorithmException throw new NoSuchAlgorithmException
(algorithm + " KeyPairGenerator not available"); (algorithm + " KeyPairGenerator not available");
} }

View File

@ -25,15 +25,13 @@
package java.security; package java.security;
import java.io.*; import javax.crypto.spec.SecretKeySpec;
import java.util.Locale; import java.io.NotSerializableException;
import java.io.ObjectStreamException;
import java.io.Serializable;
import java.security.spec.PKCS8EncodedKeySpec; import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec; import java.security.spec.X509EncodedKeySpec;
import java.security.spec.InvalidKeySpecException; import java.util.Locale;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.SecretKeySpec;
/** /**
* Standardized representation for serialized Key objects. * Standardized representation for serialized Key objects.
@ -65,7 +63,7 @@ public class KeyRep implements Serializable {
* *
* @since 1.5 * @since 1.5
*/ */
public static enum Type { public enum Type {
/** Type for secret keys. */ /** Type for secret keys. */
SECRET, SECRET,
@ -87,28 +85,28 @@ public class KeyRep implements Serializable {
* *
* @serial * @serial
*/ */
private Type type; private final Type type;
/** /**
* The Key algorithm * The Key algorithm
* *
* @serial * @serial
*/ */
private String algorithm; private final String algorithm;
/** /**
* The Key encoding format * The Key encoding format
* *
* @serial * @serial
*/ */
private String format; private final String format;
/** /**
* The encoded Key bytes * The encoded Key bytes
* *
* @serial * @serial
*/ */
private byte[] encoded; private final byte[] encoded;
/** /**
* Construct the alternate Key class. * Construct the alternate Key class.

View File

@ -79,7 +79,7 @@ import sun.security.util.Debug;
* itself. For example, the entity may authenticate itself using different * itself. For example, the entity may authenticate itself using different
* certificate authorities, or using different public key algorithms. * certificate authorities, or using different public key algorithms.
* *
* <p> Whether aliases are case sensitive is implementation dependent. In order * <p> Whether aliases are case-sensitive is implementation dependent. In order
* to avoid problems, it is recommended not to use aliases in a KeyStore that * to avoid problems, it is recommended not to use aliases in a KeyStore that
* only differ in case. * only differ in case.
* *
@ -211,13 +211,13 @@ public class KeyStore {
private static final String KEYSTORE_TYPE = "keystore.type"; private static final String KEYSTORE_TYPE = "keystore.type";
// The keystore type // The keystore type
private String type; private final String type;
// The provider // The provider
private Provider provider; private final Provider provider;
// The provider implementation // The provider implementation
private KeyStoreSpi keyStoreSpi; private final KeyStoreSpi keyStoreSpi;
// Has this keystore been initialized (loaded)? // Has this keystore been initialized (loaded)?
private boolean initialized; private boolean initialized;
@ -231,13 +231,13 @@ public class KeyStore {
* *
* @since 1.5 * @since 1.5
*/ */
public static interface LoadStoreParameter { public interface LoadStoreParameter {
/** /**
* Gets the parameter used to protect keystore data. * Gets the parameter used to protect keystore data.
* *
* @return the parameter used to protect keystore data, or null * @return the parameter used to protect keystore data, or null
*/ */
public ProtectionParameter getProtectionParameter(); ProtectionParameter getProtectionParameter();
} }
/** /**
@ -252,7 +252,7 @@ public class KeyStore {
* *
* @since 1.5 * @since 1.5
*/ */
public static interface ProtectionParameter { } public interface ProtectionParameter { }
/** /**
* A password-based implementation of {@code ProtectionParameter}. * A password-based implementation of {@code ProtectionParameter}.
@ -420,7 +420,7 @@ public class KeyStore {
* *
* @since 1.5 * @since 1.5
*/ */
public static interface Entry { public interface Entry {
/** /**
* Retrieves the attributes associated with an entry. * Retrieves the attributes associated with an entry.
@ -432,8 +432,8 @@ public class KeyStore {
* *
* @since 1.8 * @since 1.8
*/ */
public default Set<Attribute> getAttributes() { default Set<Attribute> getAttributes() {
return Collections.<Attribute>emptySet(); return Collections.emptySet();
} }
/** /**
@ -442,21 +442,21 @@ public class KeyStore {
* *
* @since 1.8 * @since 1.8
*/ */
public interface Attribute { interface Attribute {
/** /**
* Returns the attribute's name. * Returns the attribute's name.
* *
* @return the attribute name * @return the attribute name
*/ */
public String getName(); String getName();
/** /**
* Returns the attribute's value. * Returns the attribute's value.
* Multi-valued attributes encode their values as a single string. * Multivalued attributes encode their values as a single string.
* *
* @return the attribute value * @return the attribute value
*/ */
public String getValue(); String getValue();
} }
} }
@ -497,7 +497,7 @@ public class KeyStore {
* in the end entity {@code Certificate} (at index 0) * in the end entity {@code Certificate} (at index 0)
*/ */
public PrivateKeyEntry(PrivateKey privateKey, Certificate[] chain) { public PrivateKeyEntry(PrivateKey privateKey, Certificate[] chain) {
this(privateKey, chain, Collections.<Attribute>emptySet()); this(privateKey, chain, Collections.emptySet());
} }
/** /**
@ -660,7 +660,7 @@ public class KeyStore {
throw new NullPointerException("invalid null input"); throw new NullPointerException("invalid null input");
} }
this.sKey = secretKey; this.sKey = secretKey;
this.attributes = Collections.<Attribute>emptySet(); this.attributes = Collections.emptySet();
} }
/** /**
@ -743,7 +743,7 @@ public class KeyStore {
throw new NullPointerException("invalid null input"); throw new NullPointerException("invalid null input");
} }
this.cert = trustedCert; this.cert = trustedCert;
this.attributes = Collections.<Attribute>emptySet(); this.attributes = Collections.emptySet();
} }
/** /**
@ -842,7 +842,7 @@ public class KeyStore {
* {@code jdk.security.provider.preferred} * {@code jdk.security.provider.preferred}
* {@link Security#getProperty(String) Security} property to determine * {@link Security#getProperty(String) Security} property to determine
* the preferred provider order for the specified algorithm. This * the preferred provider order for the specified algorithm. This
* may be different than the order of providers returned by * may be different from the order of providers returned by
* {@link Security#getProviders() Security.getProviders()}. * {@link Security#getProviders() Security.getProviders()}.
* *
* @param type the type of keystore. * @param type the type of keystore.
@ -988,11 +988,8 @@ public class KeyStore {
*/ */
public static final String getDefaultType() { public static final String getDefaultType() {
@SuppressWarnings("removal") @SuppressWarnings("removal")
String kstype = AccessController.doPrivileged(new PrivilegedAction<>() { String kstype = AccessController.doPrivileged((PrivilegedAction<String>) () ->
public String run() { Security.getProperty(KEYSTORE_TYPE));
return Security.getProperty(KEYSTORE_TYPE);
}
});
if (kstype == null) { if (kstype == null) {
kstype = "jks"; kstype = "jks";
} }
@ -1776,7 +1773,7 @@ public class KeyStore {
throw new NullPointerException(); throw new NullPointerException();
} }
if (file.isFile() == false) { if (!file.isFile()) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"File does not exist or it does not refer to a normal file: " + "File does not exist or it does not refer to a normal file: " +
file); file);
@ -1917,7 +1914,7 @@ public class KeyStore {
if ((keyStore == null) || (protectionParameter == null)) { if ((keyStore == null) || (protectionParameter == null)) {
throw new NullPointerException(); throw new NullPointerException();
} }
if (keyStore.initialized == false) { if (!keyStore.initialized) {
throw new IllegalArgumentException("KeyStore not initialized"); throw new IllegalArgumentException("KeyStore not initialized");
} }
return new Builder() { return new Builder() {
@ -1933,7 +1930,7 @@ public class KeyStore {
if (alias == null) { if (alias == null) {
throw new NullPointerException(); throw new NullPointerException();
} }
if (getCalled == false) { if (!getCalled) {
throw new IllegalStateException throw new IllegalStateException
("getKeyStore() must be called first"); ("getKeyStore() must be called first");
} }
@ -2055,7 +2052,7 @@ public class KeyStore {
private final String type; private final String type;
private final Provider provider; private final Provider provider;
private final File file; private final File file;
private ProtectionParameter protection; private final ProtectionParameter protection;
private ProtectionParameter keyProtection; private ProtectionParameter keyProtection;
@SuppressWarnings("removal") @SuppressWarnings("removal")
private final AccessControlContext context; private final AccessControlContext context;
@ -2109,7 +2106,7 @@ public class KeyStore {
} }
public KeyStore run0() throws Exception { public KeyStore run0() throws Exception {
KeyStore ks; KeyStore ks;
char[] password = null; char[] password;
// Acquire keystore password // Acquire keystore password
if (protection instanceof PasswordProtection) { if (protection instanceof PasswordProtection) {
@ -2213,7 +2210,7 @@ public class KeyStore {
private IOException oldException; private IOException oldException;
private final PrivilegedExceptionAction<KeyStore> action private final PrivilegedExceptionAction<KeyStore> action
= new PrivilegedExceptionAction<KeyStore>() { = new PrivilegedExceptionAction<>() {
public KeyStore run() throws Exception { public KeyStore run() throws Exception {
KeyStore ks; KeyStore ks;
@ -2273,7 +2270,7 @@ public class KeyStore {
if (alias == null) { if (alias == null) {
throw new NullPointerException(); throw new NullPointerException();
} }
if (getCalled == false) { if (!getCalled) {
throw new IllegalStateException throw new IllegalStateException
("getKeyStore() must be called first"); ("getKeyStore() must be called first");
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -380,7 +380,7 @@ public abstract class KeyStoreSpi {
* <p> * <p>
* If {@code KeyStore.LoadStoreParameter} is {@code null} then * If {@code KeyStore.LoadStoreParameter} is {@code null} then
* the password parameter will also be {@code null}. * the password parameter will also be {@code null}.
* Otherwise the {@code KeyStore.ProtectionParameter} of * Otherwise, the {@code KeyStore.ProtectionParameter} of
* {@code KeyStore.LoadStoreParameter} must be either a * {@code KeyStore.LoadStoreParameter} must be either a
* {@code KeyStore.PasswordProtection} or a * {@code KeyStore.PasswordProtection} or a
* {@code KeyStore.CallbackHandlerProtection} that supports * {@code KeyStore.CallbackHandlerProtection} that supports
@ -415,7 +415,7 @@ public abstract class KeyStoreSpi {
CertificateException { CertificateException {
if (param == null) { if (param == null) {
engineLoad((InputStream)null, (char[])null); engineLoad(null, (char[])null);
return; return;
} }
@ -444,7 +444,6 @@ public abstract class KeyStoreSpi {
+ " be PasswordProtection or CallbackHandlerProtection"); + " be PasswordProtection or CallbackHandlerProtection");
} }
engineLoad(stream, password); engineLoad(stream, password);
return;
} }
/** /**
@ -610,8 +609,7 @@ public abstract class KeyStoreSpi {
engineSetKeyEntry engineSetKeyEntry
(alias, (alias,
((KeyStore.SecretKeyEntry)entry).getSecretKey(), ((KeyStore.SecretKeyEntry)entry).getSecretKey(),
pProtect.getPassword(), pProtect.getPassword(), null);
(Certificate[])null);
return; return;
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -109,7 +109,7 @@ public abstract class MessageDigest extends MessageDigestSpi {
private static final boolean skipDebug = private static final boolean skipDebug =
Debug.isOn("engine=") && !Debug.isOn("messagedigest"); Debug.isOn("engine=") && !Debug.isOn("messagedigest");
private String algorithm; private final String algorithm;
// The state of this digest // The state of this digest
private static final int INITIAL = 0; private static final int INITIAL = 0;
@ -156,7 +156,7 @@ public abstract class MessageDigest extends MessageDigestSpi {
* {@code jdk.security.provider.preferred} * {@code jdk.security.provider.preferred}
* {@link Security#getProperty(String) Security} property to determine * {@link Security#getProperty(String) Security} property to determine
* the preferred provider order for the specified algorithm. This * the preferred provider order for the specified algorithm. This
* may be different than the order of providers returned by * may be different from the order of providers returned by
* {@link Security#getProviders() Security.getProviders()}. * {@link Security#getProviders() Security.getProviders()}.
* *
* @param algorithm the name of the algorithm requested. * @param algorithm the name of the algorithm requested.
@ -302,10 +302,8 @@ public abstract class MessageDigest extends MessageDigestSpi {
md.provider = (Provider)objs[1]; md.provider = (Provider)objs[1];
return md; return md;
} else { } else {
MessageDigest delegate = return Delegate.of((MessageDigestSpi)objs[0], algorithm,
Delegate.of((MessageDigestSpi)objs[0], algorithm, (Provider)objs[1]);
(Provider)objs[1]);
return delegate;
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -109,7 +109,7 @@ public abstract class MessageDigestSpi {
* @since 1.5 * @since 1.5
*/ */
protected void engineUpdate(ByteBuffer input) { protected void engineUpdate(ByteBuffer input) {
if (input.hasRemaining() == false) { if (!input.hasRemaining()) {
return; return;
} }
if (input.hasArray()) { if (input.hasArray()) {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -54,7 +54,7 @@ public final class PKCS12Attribute implements KeyStore.Entry.Attribute {
* A string value is represented as the string itself. * A string value is represented as the string itself.
* A binary value is represented as a string of colon-separated * A binary value is represented as a string of colon-separated
* pairs of hexadecimal digits. * pairs of hexadecimal digits.
* Multi-valued attributes are represented as a comma-separated * Multivalued attributes are represented as a comma-separated
* list of values, enclosed in square brackets. See * list of values, enclosed in square brackets. See
* {@link Arrays#toString(java.lang.Object[])}. * {@link Arrays#toString(java.lang.Object[])}.
* <p> * <p>
@ -162,7 +162,7 @@ public final class PKCS12Attribute implements KeyStore.Entry.Attribute {
* returned as a binary string of colon-separated pairs of * returned as a binary string of colon-separated pairs of
* hexadecimal digits. * hexadecimal digits.
* </ul> * </ul>
* Multi-valued attributes are represented as a comma-separated * Multivalued attributes are represented as a comma-separated
* list of values, enclosed in square brackets. See * list of values, enclosed in square brackets. See
* {@link Arrays#toString(java.lang.Object[])}. * {@link Arrays#toString(java.lang.Object[])}.
* *

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -71,7 +71,7 @@ public abstract class Permission implements Guard, java.io.Serializable {
/** /**
* The permission name. * The permission name.
*/ */
private String name; private final String name;
/** /**
* Constructs a permission with the specified name. * Constructs a permission with the specified name.
@ -116,7 +116,7 @@ public abstract class Permission implements Guard, java.io.Serializable {
* only ones that can impose semantics on a Permission object. * only ones that can impose semantics on a Permission object.
* *
* <p>The {@code implies} method is used by the AccessController to determine * <p>The {@code implies} method is used by the AccessController to determine
* whether or not a requested permission is implied by another permission that * whether a requested permission is implied by another permission that
* is known to be valid in the current execution context. * is known to be valid in the current execution context.
* *
* @param permission the permission to check against. * @param permission the permission to check against.
@ -207,7 +207,7 @@ public abstract class Permission implements Guard, java.io.Serializable {
* If null is returned, * If null is returned,
* then the caller of this method is free to store permissions of this * then the caller of this method is free to store permissions of this
* type in any PermissionCollection they choose (one that uses a Hashtable, * type in any PermissionCollection they choose (one that uses a Hashtable,
* one that uses a Vector, etc). * one that uses a Vector, etc.).
* *
* @return a new PermissionCollection object for this type of Permission, or * @return a new PermissionCollection object for this type of Permission, or
* null if one is not defined. * null if one is not defined.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -52,7 +52,7 @@ import java.util.stream.StreamSupport;
* If null is returned, then the caller of {@code newPermissionCollection} * If null is returned, then the caller of {@code newPermissionCollection}
* is free to store permissions of the * is free to store permissions of the
* given type in any PermissionCollection they choose * given type in any PermissionCollection they choose
* (one that uses a Hashtable, one that uses a Vector, etc). * (one that uses a Hashtable, one that uses a Vector, etc.).
* *
* <p>The PermissionCollection returned by the * <p>The PermissionCollection returned by the
* {@code Permission.newPermissionCollection} * {@code Permission.newPermissionCollection}

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -432,7 +432,7 @@ implements Serializable
final class PermissionsEnumerator implements Enumeration<Permission> { final class PermissionsEnumerator implements Enumeration<Permission> {
// all the perms // all the perms
private Iterator<PermissionCollection> perms; private final Iterator<PermissionCollection> perms;
// the current set // the current set
private Enumeration<Permission> permset; private Enumeration<Permission> permset;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -49,28 +49,28 @@ public interface Principal {
* @return true if the principal passed in is the same as that * @return true if the principal passed in is the same as that
* encapsulated by this principal, and false otherwise. * encapsulated by this principal, and false otherwise.
*/ */
public boolean equals(Object another); boolean equals(Object another);
/** /**
* Returns a string representation of this principal. * Returns a string representation of this principal.
* *
* @return a string representation of this principal. * @return a string representation of this principal.
*/ */
public String toString(); String toString();
/** /**
* Returns a hashcode for this principal. * Returns a hashcode for this principal.
* *
* @return a hashcode for this principal. * @return a hashcode for this principal.
*/ */
public int hashCode(); int hashCode();
/** /**
* Returns the name of this principal. * Returns the name of this principal.
* *
* @return the name of this principal. * @return the name of this principal.
*/ */
public String getName(); String getName();
/** /**
* Returns true if the specified subject is implied by this principal. * Returns true if the specified subject is implied by this principal.
@ -88,7 +88,7 @@ public interface Principal {
* implied by this principal, or false otherwise. * implied by this principal, or false otherwise.
* @since 1.8 * @since 1.8
*/ */
public default boolean implies(Subject subject) { default boolean implies(Subject subject) {
if (subject == null) if (subject == null)
return false; return false;
return subject.getPrincipals().contains(this); return subject.getPrincipals().contains(this);

View File

@ -70,5 +70,5 @@ public interface PrivateKey extends Key, javax.security.auth.Destroyable {
@Deprecated @Deprecated
@SuppressWarnings("serial") @SuppressWarnings("serial")
@java.io.Serial @java.io.Serial
static final long serialVersionUID = 6034044314589513430L; long serialVersionUID = 6034044314589513430L;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -134,13 +134,13 @@ public class ProtectionDomain {
} }
/* CodeSource */ /* CodeSource */
private CodeSource codesource ; private final CodeSource codesource ;
/* ClassLoader the protection domain was consed from */ /* ClassLoader the protection domain was consed from */
private ClassLoader classloader; private final ClassLoader classloader;
/* Principals running-as within this protection domain */ /* Principals running-as within this protection domain */
private Principal[] principals; private final Principal[] principals;
/* the rights this protection domain is granted */ /* the rights this protection domain is granted */
private PermissionCollection permissions; private PermissionCollection permissions;
@ -371,7 +371,7 @@ public class ProtectionDomain {
Policy policy = Policy.getPolicyNoCheck(); Policy policy = Policy.getPolicyNoCheck();
if (policy instanceof PolicyFile) { if (policy instanceof PolicyFile) {
// The PolicyFile implementation supports compatibility // The PolicyFile implementation supports compatibility
// inside and it also covers the static permissions. // inside, and it also covers the static permissions.
return policy.implies(this, perm); return policy.implies(this, perm);
} else { } else {
if (policy.implies(this, perm)) { if (policy.implies(this, perm)) {
@ -447,7 +447,7 @@ public class ProtectionDomain {
* *
* . SecurityManager is not null, * . SecurityManager is not null,
* debug is not null, * debug is not null,
* SecurityManager impelmentation is in bootclasspath, * SecurityManager implementation is in bootclasspath,
* Policy implementation is in bootclasspath * Policy implementation is in bootclasspath
* (the bootclasspath restrictions avoid recursion) * (the bootclasspath restrictions avoid recursion)
* *
@ -463,22 +463,18 @@ public class ProtectionDomain {
return true; return true;
} else { } else {
if (DebugHolder.debug != null) { if (DebugHolder.debug != null) {
if (sm.getClass().getClassLoader() == null && return sm.getClass().getClassLoader() == null &&
Policy.getPolicyNoCheck().getClass().getClassLoader() Policy.getPolicyNoCheck().getClass().getClassLoader()
== null) { == null;
return true;
}
} else { } else {
try { try {
sm.checkPermission(SecurityConstants.GET_POLICY_PERMISSION); sm.checkPermission(SecurityConstants.GET_POLICY_PERMISSION);
return true; return true;
} catch (SecurityException se) { } catch (SecurityException se) {
// fall thru and return false return false;
} }
} }
} }
return false;
} }
private PermissionCollection mergePermissions() { private PermissionCollection mergePermissions() {
@ -488,12 +484,8 @@ public class ProtectionDomain {
@SuppressWarnings("removal") @SuppressWarnings("removal")
PermissionCollection perms = PermissionCollection perms =
java.security.AccessController.doPrivileged java.security.AccessController.doPrivileged
(new java.security.PrivilegedAction<>() { ((PrivilegedAction<PermissionCollection>) () ->
public PermissionCollection run() { Policy.getPolicyNoCheck().getPermissions(ProtectionDomain.this));
Policy p = Policy.getPolicyNoCheck();
return p.getPermissions(ProtectionDomain.this);
}
});
Permissions mergedPerms = new Permissions(); Permissions mergedPerms = new Permissions();
int swag = 32; int swag = 32;

View File

@ -119,14 +119,14 @@ public abstract class Provider extends Properties {
* *
* @serial * @serial
*/ */
private String name; private final String name;
/** /**
* A description of the provider and its services. * A description of the provider and its services.
* *
* @serial * @serial
*/ */
private String info; private final String info;
/** /**
* The provider version number. * The provider version number.
@ -192,7 +192,7 @@ public abstract class Provider extends Properties {
this.info = info; this.info = info;
this.serviceMap = new ConcurrentHashMap<>(); this.serviceMap = new ConcurrentHashMap<>();
this.legacyMap = new ConcurrentHashMap<>(); this.legacyMap = new ConcurrentHashMap<>();
this.prngAlgos = new LinkedHashSet<String>(6); this.prngAlgos = new LinkedHashSet<>(6);
putId(); putId();
initialized = true; initialized = true;
} }
@ -232,7 +232,7 @@ public abstract class Provider extends Properties {
this.info = info; this.info = info;
this.serviceMap = new ConcurrentHashMap<>(); this.serviceMap = new ConcurrentHashMap<>();
this.legacyMap = new ConcurrentHashMap<>(); this.legacyMap = new ConcurrentHashMap<>();
this.prngAlgos = new LinkedHashSet<String>(6); this.prngAlgos = new LinkedHashSet<>(6);
putId(); putId();
initialized = true; initialized = true;
} }
@ -386,7 +386,7 @@ public abstract class Provider extends Properties {
} }
/** /**
* Copies all of the mappings from the specified Map to this provider. * Copies all the mappings from the specified Map to this provider.
* These mappings will replace any properties that this provider had * These mappings will replace any properties that this provider had
* for any of the keys currently in the specified Map. * for any of the keys currently in the specified Map.
* *
@ -883,14 +883,14 @@ public abstract class Provider extends Properties {
} }
this.serviceMap = new ConcurrentHashMap<>(); this.serviceMap = new ConcurrentHashMap<>();
this.legacyMap = new ConcurrentHashMap<>(); this.legacyMap = new ConcurrentHashMap<>();
this.prngAlgos = new LinkedHashSet<String>(6); this.prngAlgos = new LinkedHashSet<>(6);
implClear(); implClear();
initialized = true; initialized = true;
putAll(copy); putAll(copy);
} }
// returns false if no update necessary, i.e. key isn't String or // returns false if no update necessary, i.e. key isn't String or
// is String but it's provider-related (name/version/info/className) // is String, but it's provider-related (name/version/info/className)
private static boolean checkLegacy(Object key) { private static boolean checkLegacy(Object key) {
if (key instanceof String && ((String)key).startsWith("Provider.")) { if (key instanceof String && ((String)key).startsWith("Provider.")) {
// ignore provider related updates // ignore provider related updates
@ -901,7 +901,7 @@ public abstract class Provider extends Properties {
} }
/** /**
* Copies all of the mappings from the specified Map to this provider. * Copies all the mappings from the specified Map to this provider.
* Internal method to be called AFTER the security check has been * Internal method to be called AFTER the security check has been
* performed. * performed.
*/ */
@ -1093,6 +1093,9 @@ public abstract class Provider extends Properties {
&& this.type.equals(other.type) && this.type.equals(other.type)
&& this.algorithm.equals(other.algorithm); && this.algorithm.equals(other.algorithm);
} }
// Don't change '==' to equals.
// This method tests for equality of pointers.
boolean matches(String type, String algorithm) { boolean matches(String type, String algorithm) {
return (this.type == type) && (this.originalAlgorithm == algorithm); return (this.type == type) && (this.originalAlgorithm == algorithm);
} }
@ -1119,8 +1122,8 @@ public abstract class Provider extends Properties {
private static final String ALIAS_PREFIX_LOWER = "alg.alias."; private static final String ALIAS_PREFIX_LOWER = "alg.alias.";
private static final int ALIAS_LENGTH = ALIAS_PREFIX.length(); private static final int ALIAS_LENGTH = ALIAS_PREFIX.length();
private static enum OPType { private enum OPType {
ADD, REMOVE; ADD, REMOVE
} }
private void parseLegacy(String name, String value, OPType opType) { private void parseLegacy(String name, String value, OPType opType) {
@ -1254,7 +1257,7 @@ public abstract class Provider extends Properties {
* *
* @param type the type of {@link Service service} requested * @param type the type of {@link Service service} requested
* (for example, {@code MessageDigest}) * (for example, {@code MessageDigest})
* @param algorithm the case insensitive algorithm name (or alternate * @param algorithm the case-insensitive algorithm name (or alternate
* alias) of the service requested (for example, {@code SHA-1}) * alias) of the service requested (for example, {@code SHA-1})
* *
* @return the service describing this Provider's matching service * @return the service describing this Provider's matching service
@ -1268,7 +1271,7 @@ public abstract class Provider extends Properties {
checkInitialized(); checkInitialized();
// avoid allocating a new ServiceKey object if possible // avoid allocating a new ServiceKey object if possible
ServiceKey key = previousKey; ServiceKey key = previousKey;
if (key.matches(type, algorithm) == false) { if (!key.matches(type, algorithm)) {
key = new ServiceKey(type, algorithm, false); key = new ServiceKey(type, algorithm, false);
previousKey = key; previousKey = key;
} }
@ -1325,7 +1328,7 @@ public abstract class Provider extends Properties {
/** /**
* Add a service. If a service of the same type with the same algorithm * Add a service. If a service of the same type with the same algorithm
* name exists and it was added using {@link #putService putService()}, * name exists, and it was added using {@link #putService putService()},
* it is replaced by the new service. * it is replaced by the new service.
* This method also places information about this service * This method also places information about this service
* in the provider's Hashtable values in the format described in the * in the provider's Hashtable values in the format described in the
@ -1506,7 +1509,7 @@ public abstract class Provider extends Properties {
checkAndUpdateSecureRandom(type, algorithm, false); checkAndUpdateSecureRandom(type, algorithm, false);
} }
// Wrapped String that behaves in a case insensitive way for equals/hashCode // Wrapped String that behaves in a case-insensitive way for equals/hashCode
private static class UString { private static class UString {
final String string; final String string;
final String lowerString; final String lowerString;
@ -1665,7 +1668,7 @@ public abstract class Provider extends Properties {
// flag indicating whether this service has its attributes for // flag indicating whether this service has its attributes for
// supportedKeyFormats or supportedKeyClasses set // supportedKeyFormats or supportedKeyClasses set
// if null, the values have not been initialized // if null, the values have not been initialized
// if TRUE, at least one of supportedFormats/Classes is non null // if TRUE, at least one of supportedFormats/Classes is non-null
private volatile Boolean hasKeyAttributes; private volatile Boolean hasKeyAttributes;
// supported encoding formats // supported encoding formats
@ -1687,8 +1690,8 @@ public abstract class Provider extends Properties {
this.type = type; this.type = type;
this.algorithm = algorithm; this.algorithm = algorithm;
engineDescription = knownEngines.get(type); engineDescription = knownEngines.get(type);
aliases = Collections.<String>emptyList(); aliases = Collections.emptyList();
attributes = Collections.<UString,String>emptyMap(); attributes = Collections.emptyMap();
} }
private boolean isValid() { private boolean isValid() {
@ -1754,12 +1757,12 @@ public abstract class Provider extends Properties {
this.algorithm = algorithm; this.algorithm = algorithm;
this.className = className; this.className = className;
if (aliases == null) { if (aliases == null) {
this.aliases = Collections.<String>emptyList(); this.aliases = Collections.emptyList();
} else { } else {
this.aliases = new ArrayList<>(aliases); this.aliases = new ArrayList<>(aliases);
} }
if (attributes == null) { if (attributes == null) {
this.attributes = Collections.<UString,String>emptyMap(); this.attributes = Collections.emptyMap();
} else { } else {
this.attributes = new HashMap<>(); this.attributes = new HashMap<>();
for (Map.Entry<String,String> entry : attributes.entrySet()) { for (Map.Entry<String,String> entry : attributes.entrySet()) {
@ -1806,7 +1809,7 @@ public abstract class Provider extends Properties {
} }
// internal only // internal only
private final List<String> getAliases() { private List<String> getAliases() {
return aliases; return aliases;
} }
@ -1855,7 +1858,7 @@ public abstract class Provider extends Properties {
*/ */
public Object newInstance(Object constructorParameter) public Object newInstance(Object constructorParameter)
throws NoSuchAlgorithmException { throws NoSuchAlgorithmException {
if (registered == false) { if (!registered) {
if (provider.getService(type, algorithm) != this) { if (provider.getService(type, algorithm) != this) {
throw new NoSuchAlgorithmException throw new NoSuchAlgorithmException
("Service not registered with Provider " ("Service not registered with Provider "
@ -1882,7 +1885,7 @@ public abstract class Provider extends Properties {
+ " engines"); + " engines");
} else { } else {
Class<?> argClass = constructorParameter.getClass(); Class<?> argClass = constructorParameter.getClass();
if (ctrParamClz.isAssignableFrom(argClass) == false) { if (!ctrParamClz.isAssignableFrom(argClass)) {
throw new InvalidParameterException throw new InvalidParameterException
("constructorParameter must be instanceof " ("constructorParameter must be instanceof "
+ cap.constructorParameterClassName.replace('$', '.') + cap.constructorParameterClassName.replace('$', '.')
@ -2054,10 +2057,7 @@ public abstract class Provider extends Properties {
if (supportsKeyFormat(key)) { if (supportsKeyFormat(key)) {
return true; return true;
} }
if (supportsKeyClass(key)) { return supportsKeyClass(key);
return true;
}
return false;
} }
/** /**
@ -2088,9 +2088,8 @@ public abstract class Provider extends Properties {
} }
supportedClasses = classList.toArray(CLASS0); supportedClasses = classList.toArray(CLASS0);
} }
boolean bool = (supportedFormats != null) b = (supportedFormats != null)
|| (supportedClasses != null); || (supportedClasses != null);
b = Boolean.valueOf(bool);
hasKeyAttributes = b; hasKeyAttributes = b;
} }
} }

View File

@ -56,5 +56,5 @@ public interface PublicKey extends Key {
@Deprecated @Deprecated
@SuppressWarnings("serial") @SuppressWarnings("serial")
@java.io.Serial @java.io.Serial
static final long serialVersionUID = 7187392471159151072L; long serialVersionUID = 7187392471159151072L;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,12 +25,11 @@
package java.security; package java.security;
import sun.security.util.Debug;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import sun.security.util.Debug;
/** /**
* This class extends ClassLoader with additional support for defining * This class extends ClassLoader with additional support for defining
@ -219,28 +218,20 @@ public class SecureClassLoader extends ClassLoader {
// that no nameservice lookup is done on the hostname (String comparison // that no nameservice lookup is done on the hostname (String comparison
// only), and the fragment is not considered. // only), and the fragment is not considered.
CodeSourceKey key = new CodeSourceKey(cs); CodeSourceKey key = new CodeSourceKey(cs);
return pdcache.computeIfAbsent(key, new Function<>() { return pdcache.computeIfAbsent(key, unused -> {
@Override PermissionCollection perms
public ProtectionDomain apply(CodeSourceKey key /* not used */) { = SecureClassLoader.this.getPermissions(cs);
PermissionCollection perms ProtectionDomain pd = new ProtectionDomain(
= SecureClassLoader.this.getPermissions(cs); cs, perms, SecureClassLoader.this, null);
ProtectionDomain pd = new ProtectionDomain( if (DebugHolder.debug != null) {
cs, perms, SecureClassLoader.this, null); DebugHolder.debug.println(" getPermissions " + pd);
if (DebugHolder.debug != null) { DebugHolder.debug.println("");
DebugHolder.debug.println(" getPermissions " + pd);
DebugHolder.debug.println("");
}
return pd;
} }
return pd;
}); });
} }
private static class CodeSourceKey { private record CodeSourceKey(CodeSource cs) {
private final CodeSource cs;
CodeSourceKey(CodeSource cs) {
this.cs = cs;
}
@Override @Override
public int hashCode() { public int hashCode() {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,18 +25,18 @@
package java.security; package java.security;
import java.math.BigInteger;
import java.util.*;
import java.util.random.RandomGenerator;
import java.util.regex.*;
import java.security.Provider.Service;
import jdk.internal.util.random.RandomSupport.RandomGeneratorProperties; import jdk.internal.util.random.RandomSupport.RandomGeneratorProperties;
import sun.security.jca.*; import sun.security.jca.GetInstance;
import sun.security.jca.GetInstance.Instance; import sun.security.jca.GetInstance.Instance;
import sun.security.jca.Providers;
import sun.security.provider.SunEntries; import sun.security.provider.SunEntries;
import sun.security.util.Debug; import sun.security.util.Debug;
import java.security.Provider.Service;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/** /**
* This class provides a cryptographically strong random number * This class provides a cryptographically strong random number
* generator (RNG). * generator (RNG).
@ -47,7 +47,7 @@ import sun.security.util.Debug;
* <i>FIPS 140-2, Security Requirements for Cryptographic Modules</i></a>, * <i>FIPS 140-2, Security Requirements for Cryptographic Modules</i></a>,
* section 4.9.1. * section 4.9.1.
* Additionally, {@code SecureRandom} must produce non-deterministic output. * Additionally, {@code SecureRandom} must produce non-deterministic output.
* Therefore any seed material passed to a {@code SecureRandom} object must be * Therefore, any seed material passed to a {@code SecureRandom} object must be
* unpredictable, and all {@code SecureRandom} output sequences must be * unpredictable, and all {@code SecureRandom} output sequences must be
* cryptographically strong, as described in * cryptographically strong, as described in
* <a href="https://tools.ietf.org/html/rfc4086"> * <a href="https://tools.ietf.org/html/rfc4086">
@ -204,7 +204,7 @@ public class SecureRandom extends java.util.Random {
* A new {@code SecureRandom} object encapsulating the * A new {@code SecureRandom} object encapsulating the
* {@code SecureRandomSpi} implementation from the first * {@code SecureRandomSpi} implementation from the first
* Provider that supports a {@code SecureRandom} (RNG) algorithm is returned. * Provider that supports a {@code SecureRandom} (RNG) algorithm is returned.
* If none of the Providers support a RNG algorithm, * If none of the Providers support an RNG algorithm,
* then an implementation-specific default is returned. * then an implementation-specific default is returned.
* *
* <p> Note that the list of registered providers may be retrieved via * <p> Note that the list of registered providers may be retrieved via
@ -245,7 +245,7 @@ public class SecureRandom extends java.util.Random {
* A new {@code SecureRandom} object encapsulating the * A new {@code SecureRandom} object encapsulating the
* {@code SecureRandomSpi} implementation from the first * {@code SecureRandomSpi} implementation from the first
* Provider that supports a {@code SecureRandom} (RNG) algorithm is returned. * Provider that supports a {@code SecureRandom} (RNG) algorithm is returned.
* If none of the Providers support a RNG algorithm, * If none of the Providers support an RNG algorithm,
* then an implementation-specific default is returned. * then an implementation-specific default is returned.
* *
* <p> Note that the list of registered providers may be retrieved via * <p> Note that the list of registered providers may be retrieved via
@ -284,7 +284,7 @@ public class SecureRandom extends java.util.Random {
} }
} }
} }
// per javadoc, if none of the Providers support a RNG algorithm, // per javadoc, if none of the Providers support an RNG algorithm,
// then an implementation-specific default is returned. // then an implementation-specific default is returned.
if (prngService == null) { if (prngService == null) {
prngAlgorithm = "SHA1PRNG"; prngAlgorithm = "SHA1PRNG";
@ -360,7 +360,7 @@ public class SecureRandom extends java.util.Random {
* {@code jdk.security.provider.preferred} * {@code jdk.security.provider.preferred}
* {@link Security#getProperty(String) Security} property to determine * {@link Security#getProperty(String) Security} property to determine
* the preferred provider order for the specified algorithm. This * the preferred provider order for the specified algorithm. This
* may be different than the order of providers returned by * may be different from the order of providers returned by
* {@link Security#getProviders() Security.getProviders()}. * {@link Security#getProviders() Security.getProviders()}.
* *
* @param algorithm the name of the RNG algorithm. * @param algorithm the name of the RNG algorithm.
@ -497,7 +497,7 @@ public class SecureRandom extends java.util.Random {
* The JDK Reference Implementation additionally uses the * The JDK Reference Implementation additionally uses the
* {@code jdk.security.provider.preferred} property to determine * {@code jdk.security.provider.preferred} property to determine
* the preferred provider order for the specified algorithm. This * the preferred provider order for the specified algorithm. This
* may be different than the order of providers returned by * may be different from the order of providers returned by
* {@link Security#getProviders() Security.getProviders()}. * {@link Security#getProviders() Security.getProviders()}.
* *
* @param algorithm the name of the RNG algorithm. * @param algorithm the name of the RNG algorithm.
@ -796,7 +796,7 @@ public class SecureRandom extends java.util.Random {
* Generates an integer containing the user-specified number of * Generates an integer containing the user-specified number of
* pseudo-random bits (right justified, with leading zeros). This * pseudo-random bits (right justified, with leading zeros). This
* method overrides a {@code java.util.Random} method, and serves * method overrides a {@code java.util.Random} method, and serves
* to provide a source of random bits to all of the methods inherited * to provide a source of random bits to all the methods inherited
* from that class (for example, {@code nextInt}, * from that class (for example, {@code nextInt},
* {@code nextLong}, and {@code nextFloat}). * {@code nextLong}, and {@code nextFloat}).
* *
@ -900,9 +900,9 @@ public class SecureRandom extends java.util.Random {
* 4 - ,nextEntry (optional) * 4 - ,nextEntry (optional)
* 5 - nextEntry (optional) * 5 - nextEntry (optional)
*/ */
private static Pattern pattern = private static final Pattern pattern =
Pattern.compile( Pattern.compile(
"\\s*([\\S&&[^:,]]*)(\\:([\\S&&[^,]]*))?\\s*(\\,(.*))?"); "\\s*([\\S&&[^:,]]*)(:([\\S&&[^,]]*))?\\s*(,(.*))?");
} }
/** /**
@ -935,13 +935,8 @@ public class SecureRandom extends java.util.Random {
@SuppressWarnings("removal") @SuppressWarnings("removal")
String property = AccessController.doPrivileged( String property = AccessController.doPrivileged(
new PrivilegedAction<>() { (PrivilegedAction<String>) () -> Security.getProperty(
@Override "securerandom.strongAlgorithms"));
public String run() {
return Security.getProperty(
"securerandom.strongAlgorithms");
}
});
if (property == null || property.isEmpty()) { if (property == null || property.isEmpty()) {
throw new NoSuchAlgorithmException( throw new NoSuchAlgorithmException(

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -50,7 +50,7 @@ package java.security;
* <p> * <p>
* Otherwise, if the {@code SecureRandomSpi(SecureRandomParameters)} * Otherwise, if the {@code SecureRandomSpi(SecureRandomParameters)}
* constructor is not overridden in an implementation, the * constructor is not overridden in an implementation, the
* {@link #SecureRandomSpi()} constructor must be overridden and it will be * {@link #SecureRandomSpi()} constructor must be overridden, and it will be
* called if an object is instantiated with one of {@code SecureRandom}'s * called if an object is instantiated with one of {@code SecureRandom}'s
* {@code getInstance} methods <em>without</em> a * {@code getInstance} methods <em>without</em> a
* {@code SecureRandomParameters} argument. Calling one of * {@code SecureRandomParameters} argument. Calling one of

View File

@ -72,11 +72,9 @@ public final class Security {
// (the FileInputStream call and the File.exists call, // (the FileInputStream call and the File.exists call,
// the securityPropFile call, etc) // the securityPropFile call, etc)
@SuppressWarnings("removal") @SuppressWarnings("removal")
var dummy = AccessController.doPrivileged(new PrivilegedAction<>() { var dummy = AccessController.doPrivileged((PrivilegedAction<Object>) () -> {
public Void run() { initialize();
initialize(); return null;
return null;
}
}); });
} }
@ -229,12 +227,11 @@ public final class Security {
* properties file. * properties file.
*/ */
private static ProviderProperty getProviderProperty(String key) { private static ProviderProperty getProviderProperty(String key) {
ProviderProperty entry = null;
List<Provider> providers = Providers.getProviderList().providers(); List<Provider> providers = Providers.getProviderList().providers();
for (int i = 0; i < providers.size(); i++) { for (int i = 0; i < providers.size(); i++) {
String matchKey = null; String matchKey;
Provider prov = providers.get(i); Provider prov = providers.get(i);
String prop = prov.getProperty(key); String prop = prov.getProperty(key);
@ -242,7 +239,7 @@ public final class Security {
// Is there a match if we do a case-insensitive property name // Is there a match if we do a case-insensitive property name
// comparison? Let's try ... // comparison? Let's try ...
for (Enumeration<Object> e = prov.keys(); for (Enumeration<Object> e = prov.keys();
e.hasMoreElements() && prop == null; ) { e.hasMoreElements(); ) {
matchKey = (String)e.nextElement(); matchKey = (String)e.nextElement();
if (key.equalsIgnoreCase(matchKey)) { if (key.equalsIgnoreCase(matchKey)) {
prop = prov.getProperty(matchKey); prop = prov.getProperty(matchKey);
@ -259,7 +256,7 @@ public final class Security {
} }
} }
return entry; return null;
} }
/** /**
@ -271,7 +268,7 @@ public final class Security {
// Is there a match if we do a case-insensitive property name // Is there a match if we do a case-insensitive property name
// comparison? Let's try ... // comparison? Let's try ...
for (Enumeration<Object> e = provider.keys(); for (Enumeration<Object> e = provider.keys();
e.hasMoreElements() && prop == null; ) { e.hasMoreElements(); ) {
String matchKey = (String)e.nextElement(); String matchKey = (String)e.nextElement();
if (key.equalsIgnoreCase(matchKey)) { if (key.equalsIgnoreCase(matchKey)) {
prop = provider.getProperty(matchKey); prop = provider.getProperty(matchKey);
@ -534,8 +531,8 @@ public final class Security {
* @since 1.3 * @since 1.3
*/ */
public static Provider[] getProviders(String filter) { public static Provider[] getProviders(String filter) {
String key = null; String key;
String value = null; String value;
int index = filter.indexOf(':'); int index = filter.indexOf(':');
if (index == -1) { if (index == -1) {
@ -631,17 +628,11 @@ public final class Security {
firstSearch = false; firstSearch = false;
} }
if ((newCandidates != null) && !newCandidates.isEmpty()) { if (!newCandidates.isEmpty()) {
// For each provider in the candidates set, if it // For each provider in the candidates set, if it
// isn't in the newCandidate set, we should remove // isn't in the newCandidate set, we should remove
// it from the candidate set. // it from the candidate set.
for (Iterator<Provider> cansIte = candidates.iterator(); candidates.removeIf(prov -> !newCandidates.contains(prov));
cansIte.hasNext(); ) {
Provider prov = cansIte.next();
if (!newCandidates.contains(prov)) {
cansIte.remove();
}
}
} else { } else {
candidates = null; candidates = null;
break; break;
@ -735,7 +726,7 @@ public final class Security {
* {@code checkPermission} method is called with a * {@code checkPermission} method is called with a
* {@code java.security.SecurityPermission("getProperty."+key)} * {@code java.security.SecurityPermission("getProperty."+key)}
* permission to see if it's ok to retrieve the specified * permission to see if it's ok to retrieve the specified
* security property value.. * security property value.
* *
* @param key the key of the property being retrieved. * @param key the key of the property being retrieved.
* *
@ -858,7 +849,7 @@ public final class Security {
// The first component is the service name. // The first component is the service name.
// The second is the algorithm name. // The second is the algorithm name.
// If the third isn't null, that is the attrinute name. // If the third isn't null, that is the attribute name.
String serviceName = filterComponents[0]; String serviceName = filterComponents[0];
String algName = filterComponents[1]; String algName = filterComponents[1];
String attrName = filterComponents[2]; String attrName = filterComponents[2];
@ -953,10 +944,7 @@ public final class Security {
if (attribute.equalsIgnoreCase("KeySize")) if (attribute.equalsIgnoreCase("KeySize"))
return true; return true;
if (attribute.equalsIgnoreCase("ImplementedIn")) return attribute.equalsIgnoreCase("ImplementedIn");
return true;
return false;
} }
/* /*
@ -971,11 +959,7 @@ public final class Security {
if (attribute.equalsIgnoreCase("KeySize")) { if (attribute.equalsIgnoreCase("KeySize")) {
int requestedSize = Integer.parseInt(value); int requestedSize = Integer.parseInt(value);
int maxSize = Integer.parseInt(prop); int maxSize = Integer.parseInt(prop);
if (requestedSize <= maxSize) { return requestedSize <= maxSize;
return true;
} else {
return false;
}
} }
// For Type, prop is the type of the implementation // For Type, prop is the type of the implementation
@ -997,7 +981,7 @@ public final class Security {
} }
String serviceName = filterKey.substring(0, algIndex); String serviceName = filterKey.substring(0, algIndex);
String algName = null; String algName;
String attrName = null; String attrName = null;
if (filterValue.isEmpty()) { if (filterValue.isEmpty()) {
@ -1005,7 +989,7 @@ public final class Security {
// should be in the format of <crypto_service>.<algorithm_or_type>. // should be in the format of <crypto_service>.<algorithm_or_type>.
algName = filterKey.substring(algIndex + 1).trim(); algName = filterKey.substring(algIndex + 1).trim();
if (algName.isEmpty()) { if (algName.isEmpty()) {
// There must be a algorithm or type name. // There must be an algorithm or type name.
throw new InvalidParameterException("Invalid filter"); throw new InvalidParameterException("Invalid filter");
} }
} else { } else {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,18 +25,13 @@
package java.security; package java.security;
import java.security.*;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.StringTokenizer;
/** /**
* This class is for security permissions. A {@code SecurityPermission} * This class is for security permissions. A {@code SecurityPermission}
* contains a name (also referred to as a "target name") but no actions list; * contains a name (also referred to as a "target name") but no actions list;
* you either have the named permission or you don't. * you either have the named permission or you don't.
* <p> * <p>
* The target name is the name of a security configuration parameter * The target name is the name of a security configuration parameter
* (see below). Currently the {@code SecurityPermission} object is used to * (see below). Currently, the {@code SecurityPermission} object is used to
* guard access to the {@link AccessControlContext}, {@link Policy}, * guard access to the {@link AccessControlContext}, {@link Policy},
* {@link Provider}, {@link Security}, {@link Signer}, and {@link Identity} * {@link Provider}, {@link Security}, {@link Signer}, and {@link Identity}
* objects. * objects.

View File

@ -235,7 +235,7 @@ public abstract class Signature extends SignatureSpi {
* {@code jdk.security.provider.preferred} * {@code jdk.security.provider.preferred}
* {@link Security#getProperty(String) Security} property to determine * {@link Security#getProperty(String) Security} property to determine
* the preferred provider order for the specified algorithm. This * the preferred provider order for the specified algorithm. This
* may be different than the order of providers returned by * may be different from the order of providers returned by
* {@link Security#getProviders() Security.getProviders()}. * {@link Security#getProviders() Security.getProviders()}.
* *
* @param algorithm the standard name of the algorithm requested. * @param algorithm the standard name of the algorithm requested.
@ -264,7 +264,7 @@ public abstract class Signature extends SignatureSpi {
list = GetInstance.getServices("Signature", algorithm); list = GetInstance.getServices("Signature", algorithm);
} }
Iterator<Service> t = list.iterator(); Iterator<Service> t = list.iterator();
if (t.hasNext() == false) { if (!t.hasNext()) {
throw new NoSuchAlgorithmException throw new NoSuchAlgorithmException
(algorithm + " Signature not available"); (algorithm + " Signature not available");
} }
@ -305,18 +305,17 @@ public abstract class Signature extends SignatureSpi {
static { static {
signatureInfo = new ConcurrentHashMap<>(); signatureInfo = new ConcurrentHashMap<>();
Boolean TRUE = Boolean.TRUE;
// pre-initialize with values for our SignatureSpi implementations // pre-initialize with values for our SignatureSpi implementations
signatureInfo.put("sun.security.provider.DSA$RawDSA", TRUE); signatureInfo.put("sun.security.provider.DSA$RawDSA", true);
signatureInfo.put("sun.security.provider.DSA$SHA1withDSA", TRUE); signatureInfo.put("sun.security.provider.DSA$SHA1withDSA", true);
signatureInfo.put("sun.security.rsa.RSASignature$MD2withRSA", TRUE); signatureInfo.put("sun.security.rsa.RSASignature$MD2withRSA", true);
signatureInfo.put("sun.security.rsa.RSASignature$MD5withRSA", TRUE); signatureInfo.put("sun.security.rsa.RSASignature$MD5withRSA", true);
signatureInfo.put("sun.security.rsa.RSASignature$SHA1withRSA", TRUE); signatureInfo.put("sun.security.rsa.RSASignature$SHA1withRSA", true);
signatureInfo.put("sun.security.rsa.RSASignature$SHA256withRSA", TRUE); signatureInfo.put("sun.security.rsa.RSASignature$SHA256withRSA", true);
signatureInfo.put("sun.security.rsa.RSASignature$SHA384withRSA", TRUE); signatureInfo.put("sun.security.rsa.RSASignature$SHA384withRSA", true);
signatureInfo.put("sun.security.rsa.RSASignature$SHA512withRSA", TRUE); signatureInfo.put("sun.security.rsa.RSASignature$SHA512withRSA", true);
signatureInfo.put("sun.security.rsa.RSAPSSSignature", TRUE); signatureInfo.put("sun.security.rsa.RSAPSSSignature", true);
signatureInfo.put("sun.security.pkcs11.P11Signature", TRUE); signatureInfo.put("sun.security.pkcs11.P11Signature", true);
} }
private static boolean isSpi(Service s) { private static boolean isSpi(Service s) {
@ -334,7 +333,7 @@ public abstract class Signature extends SignatureSpi {
// instance of SignatureSpi but not Signature // instance of SignatureSpi but not Signature
boolean r = (instance instanceof SignatureSpi) boolean r = (instance instanceof SignatureSpi)
&& (!(instance instanceof Signature)); && (!(instance instanceof Signature));
if ((debug != null) && (r == false)) { if ((debug != null) && (!r)) {
debug.println("Not a SignatureSpi " + className); debug.println("Not a SignatureSpi " + className);
debug.println("Delayed provider selection may not be " debug.println("Delayed provider selection may not be "
+ "available for algorithm " + s.getAlgorithm()); + "available for algorithm " + s.getAlgorithm());
@ -551,7 +550,7 @@ public abstract class Signature extends SignatureSpi {
&& critSet.contains(KnownOIDs.KeyUsage.value())) { && critSet.contains(KnownOIDs.KeyUsage.value())) {
boolean[] keyUsageInfo = xcert.getKeyUsage(); boolean[] keyUsageInfo = xcert.getKeyUsage();
// keyUsageInfo[0] is for digitalSignature. // keyUsageInfo[0] is for digitalSignature.
if ((keyUsageInfo != null) && (keyUsageInfo[0] == false)) if ((keyUsageInfo != null) && (!keyUsageInfo[0]))
throw new InvalidKeyException("Wrong key usage"); throw new InvalidKeyException("Wrong key usage");
} }
} }
@ -962,7 +961,7 @@ public abstract class Signature extends SignatureSpi {
* which it is possible to set the various parameters of this object. * which it is possible to set the various parameters of this object.
* A parameter may be any settable parameter for the algorithm, such as * A parameter may be any settable parameter for the algorithm, such as
* a parameter size, or a source of random bits for signature generation * a parameter size, or a source of random bits for signature generation
* (if appropriate), or an indication of whether or not to perform * (if appropriate), or an indication of whether to perform
* a specific but optional computation. A uniform algorithm-specific * a specific but optional computation. A uniform algorithm-specific
* naming scheme for each parameter is desirable but left unspecified * naming scheme for each parameter is desirable but left unspecified
* at this time. * at this time.
@ -1033,7 +1032,7 @@ public abstract class Signature extends SignatureSpi {
* get the various parameters of this object. A parameter may be any * get the various parameters of this object. A parameter may be any
* settable parameter for the algorithm, such as a parameter size, or * settable parameter for the algorithm, such as a parameter size, or
* a source of random bits for signature generation (if appropriate), * a source of random bits for signature generation (if appropriate),
* or an indication of whether or not to perform a specific but optional * or an indication of whether to perform a specific but optional
* computation. A uniform algorithm-specific naming scheme for each * computation. A uniform algorithm-specific naming scheme for each
* parameter is desirable but left unspecified at this time. * parameter is desirable but left unspecified at this time.
* *
@ -1218,7 +1217,7 @@ public abstract class Signature extends SignatureSpi {
} else { } else {
s = serviceIterator.next(); s = serviceIterator.next();
} }
if (isSpi(s) == false) { if (!isSpi(s)) {
continue; continue;
} }
try { try {
@ -1260,11 +1259,11 @@ public abstract class Signature extends SignatureSpi {
s = serviceIterator.next(); s = serviceIterator.next();
} }
// if provider says it does not support this key, ignore it // if provider says it does not support this key, ignore it
if (key != null && s.supportsParameter(key) == false) { if (key != null && !s.supportsParameter(key)) {
continue; continue;
} }
// if instance is not a SignatureSpi, ignore it // if instance is not a SignatureSpi, ignore it
if (isSpi(s) == false) { if (!isSpi(s)) {
continue; continue;
} }
try { try {

View File

@ -25,13 +25,10 @@
package java.security; package java.security;
import java.security.spec.AlgorithmParameterSpec; import sun.security.jca.JCAUtil;
import java.util.*;
import java.io.*;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.security.spec.AlgorithmParameterSpec;
import sun.security.jca.JCAUtil;
/** /**
* This class defines the <i>Service Provider Interface</i> (<b>SPI</b>) * This class defines the <i>Service Provider Interface</i> (<b>SPI</b>)
@ -203,7 +200,7 @@ public abstract class SignatureSpi {
* @since 1.5 * @since 1.5
*/ */
protected void engineUpdate(ByteBuffer input) { protected void engineUpdate(ByteBuffer input) {
if (input.hasRemaining() == false) { if (!input.hasRemaining()) {
return; return;
} }
try { try {
@ -348,7 +345,7 @@ public abstract class SignatureSpi {
* which it is possible to set the various parameters of this object. * which it is possible to set the various parameters of this object.
* A parameter may be any settable parameter for the algorithm, such as * A parameter may be any settable parameter for the algorithm, such as
* a parameter size, or a source of random bits for signature generation * a parameter size, or a source of random bits for signature generation
* (if appropriate), or an indication of whether or not to perform * (if appropriate), or an indication of whether to perform
* a specific but optional computation. A uniform algorithm-specific * a specific but optional computation. A uniform algorithm-specific
* naming scheme for each parameter is desirable but left unspecified * naming scheme for each parameter is desirable but left unspecified
* at this time. * at this time.
@ -417,7 +414,7 @@ public abstract class SignatureSpi {
* is possible to get the various parameters of this object. A parameter * is possible to get the various parameters of this object. A parameter
* may be any settable parameter for the algorithm, such as a parameter * may be any settable parameter for the algorithm, such as a parameter
* size, or a source of random bits for signature generation (if * size, or a source of random bits for signature generation (if
* appropriate), or an indication of whether or not to perform a * appropriate), or an indication of whether to perform a
* specific but optional computation. A uniform algorithm-specific * specific but optional computation. A uniform algorithm-specific
* naming scheme for each parameter is desirable but left unspecified * naming scheme for each parameter is desirable but left unspecified
* at this time. * at this time.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,10 +25,11 @@
package java.security; package java.security;
import java.io.*; import java.io.IOException;
import java.security.cert.Certificate; import java.io.ObjectInputStream;
import java.io.Serializable;
import java.security.cert.CertPath; import java.security.cert.CertPath;
import java.security.cert.X509Extension; import java.security.cert.Certificate;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -59,7 +60,7 @@ public final class Timestamp implements Serializable {
* *
* @serial * @serial
*/ */
private CertPath signerCertPath; private final CertPath signerCertPath;
/* /*
* Hash code for this timestamp. * Hash code for this timestamp.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -36,7 +36,7 @@ package java.security;
public class URIParameter implements public class URIParameter implements
Policy.Parameters, javax.security.auth.login.Configuration.Parameters { Policy.Parameters, javax.security.auth.login.Configuration.Parameters {
private java.net.URI uri; private final java.net.URI uri;
/** /**
* Constructs a URIParameter with the URI pointing to * Constructs a URIParameter with the URI pointing to

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -120,21 +120,21 @@ implements java.io.Serializable
* *
* @serial * @serial
*/ */
private String type; private final String type;
/** /**
* The permission name. * The permission name.
* *
* @serial * @serial
*/ */
private String name; private final String name;
/** /**
* The actions of the permission. * The actions of the permission.
* *
* @serial * @serial
*/ */
private String actions; private final String actions;
private transient java.security.cert.Certificate[] certs; private transient java.security.cert.Certificate[] certs;
@ -261,11 +261,11 @@ implements java.io.Serializable
try { try {
Constructor<?> c = pc.getConstructor(PARAMS1); Constructor<?> c = pc.getConstructor(PARAMS1);
return (Permission) c.newInstance( return (Permission) c.newInstance(
new Object[] { name}); new Object[] {null});
} catch (NoSuchMethodException ne1) { } catch (NoSuchMethodException ne1) {
Constructor<?> c = pc.getConstructor(PARAMS2); Constructor<?> c = pc.getConstructor(PARAMS2);
return (Permission) c.newInstance( return (Permission) c.newInstance(
new Object[] { name, actions }); new Object[] {null, null});
} }
} }
} else { } else {
@ -277,7 +277,7 @@ implements java.io.Serializable
} catch (NoSuchMethodException ne) { } catch (NoSuchMethodException ne) {
Constructor<?> c = pc.getConstructor(PARAMS2); Constructor<?> c = pc.getConstructor(PARAMS2);
return (Permission) c.newInstance( return (Permission) c.newInstance(
new Object[] { name, actions }); new Object[] { name, null});
} }
} else { } else {
Constructor<?> c = pc.getConstructor(PARAMS2); Constructor<?> c = pc.getConstructor(PARAMS2);
@ -363,10 +363,10 @@ implements java.io.Serializable
} }
// check certs // check certs
if ((this.certs == null && that.certs != null) || if (this.certs == null && that.certs != null ||
(this.certs != null && that.certs == null) || this.certs != null && that.certs == null ||
(this.certs != null && that.certs != null && this.certs != null &&
this.certs.length != that.certs.length)) { this.certs.length != that.certs.length) {
return false; return false;
} }
@ -576,7 +576,7 @@ implements java.io.Serializable
// we know of 3 different cert types: X.509, PGP, SDSI, which // we know of 3 different cert types: X.509, PGP, SDSI, which
// could all be present in the stream at the same time // could all be present in the stream at the same time
cfs = new Hashtable<>(3); cfs = new Hashtable<>(3);
certList = new ArrayList<>(size > 20 ? 20 : size); certList = new ArrayList<>(Math.min(size, 20));
} else if (size < 0) { } else if (size < 0) {
throw new IOException("size cannot be negative"); throw new IOException("size cannot be negative");
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -29,7 +29,7 @@ package java.security.cert;
* This class is an abstraction of certificate revocation lists (CRLs) that * This class is an abstraction of certificate revocation lists (CRLs) that
* have different formats but important common uses. For example, all CRLs * have different formats but important common uses. For example, all CRLs
* share the functionality of listing revoked certificates, and can be queried * share the functionality of listing revoked certificates, and can be queried
* on whether or not they list a given certificate. * on whether they list a given certificate.
* <p> * <p>
* Specialized CRL types can be defined by subclassing off of this abstract * Specialized CRL types can be defined by subclassing off of this abstract
* class. * class.
@ -46,7 +46,7 @@ package java.security.cert;
public abstract class CRL { public abstract class CRL {
// the CRL type // the CRL type
private String type; private final String type;
/** /**
* Creates a CRL of the specified type. * Creates a CRL of the specified type.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -302,9 +302,9 @@ public abstract class CertPath implements Serializable {
private static final long serialVersionUID = 3015633072427920915L; private static final long serialVersionUID = 3015633072427920915L;
/** The type of {@code Certificate}s in the {@code CertPath}. */ /** The type of {@code Certificate}s in the {@code CertPath}. */
private String type; private final String type;
/** The encoded form of the {@code CertPath}. */ /** The encoded form of the {@code CertPath}. */
private byte[] data; private final byte[] data;
/** /**
* Creates a {@code CertPathRep} with the specified * Creates a {@code CertPathRep} with the specified

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -147,7 +147,7 @@ public class CertPathBuilder {
* {@code jdk.security.provider.preferred} * {@code jdk.security.provider.preferred}
* {@link Security#getProperty(String) Security} property to determine * {@link Security#getProperty(String) Security} property to determine
* the preferred provider order for the specified algorithm. This * the preferred provider order for the specified algorithm. This
* may be different than the order of providers returned by * may be different from the order of providers returned by
* {@link Security#getProviders() Security.getProviders()}. * {@link Security#getProviders() Security.getProviders()}.
* *
* @param algorithm the name of the requested {@code CertPathBuilder} * @param algorithm the name of the requested {@code CertPathBuilder}
@ -319,11 +319,8 @@ public class CertPathBuilder {
public static final String getDefaultType() { public static final String getDefaultType() {
@SuppressWarnings("removal") @SuppressWarnings("removal")
String cpbtype = String cpbtype =
AccessController.doPrivileged(new PrivilegedAction<>() { AccessController.doPrivileged((PrivilegedAction<String>) () ->
public String run() { Security.getProperty(CPB_TYPE));
return Security.getProperty(CPB_TYPE);
}
});
return (cpbtype == null) ? "PKIX" : cpbtype; return (cpbtype == null) ? "PKIX" : cpbtype;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -148,7 +148,7 @@ public class CertPathValidator {
* {@code jdk.security.provider.preferred} * {@code jdk.security.provider.preferred}
* {@link Security#getProperty(String) Security} property to determine * {@link Security#getProperty(String) Security} property to determine
* the preferred provider order for the specified algorithm. This * the preferred provider order for the specified algorithm. This
* may be different than the order of providers returned by * may be different from the order of providers returned by
* {@link Security#getProviders() Security.getProviders()}. * {@link Security#getProviders() Security.getProviders()}.
* *
* @param algorithm the name of the requested {@code CertPathValidator} * @param algorithm the name of the requested {@code CertPathValidator}
@ -331,11 +331,8 @@ public class CertPathValidator {
public static final String getDefaultType() { public static final String getDefaultType() {
@SuppressWarnings("removal") @SuppressWarnings("removal")
String cpvtype = String cpvtype =
AccessController.doPrivileged(new PrivilegedAction<>() { AccessController.doPrivileged((PrivilegedAction<String>) () ->
public String run() { Security.getProperty(CPV_TYPE));
return Security.getProperty(CPV_TYPE);
}
});
return (cpvtype == null) ? "PKIX" : cpvtype; return (cpvtype == null) ? "PKIX" : cpvtype;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -74,7 +74,7 @@ public class CertPathValidatorException extends GeneralSecurityException {
* @serial the {@code CertPath} that was being validated when * @serial the {@code CertPath} that was being validated when
* the exception was thrown * the exception was thrown
*/ */
private CertPath certPath; private final CertPath certPath;
/** /**
* @serial the reason the validation failed * @serial the reason the validation failed
@ -257,7 +257,7 @@ public class CertPathValidatorException extends GeneralSecurityException {
* *
* @since 1.7 * @since 1.7
*/ */
public static interface Reason extends java.io.Serializable { } public interface Reason extends java.io.Serializable { }
/** /**
@ -266,7 +266,7 @@ public class CertPathValidatorException extends GeneralSecurityException {
* *
* @since 1.7 * @since 1.7
*/ */
public static enum BasicReason implements Reason { public enum BasicReason implements Reason {
/** /**
* Unspecified reason. * Unspecified reason.
*/ */

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -99,9 +99,9 @@ public class CertStore {
* </pre> * </pre>
*/ */
private static final String CERTSTORE_TYPE = "certstore.type"; private static final String CERTSTORE_TYPE = "certstore.type";
private CertStoreSpi storeSpi; private final CertStoreSpi storeSpi;
private Provider provider; private final Provider provider;
private String type; private final String type;
private CertStoreParameters params; private CertStoreParameters params;
/** /**
@ -207,7 +207,7 @@ public class CertStore {
* {@code jdk.security.provider.preferred} * {@code jdk.security.provider.preferred}
* {@link Security#getProperty(String) Security} property to determine * {@link Security#getProperty(String) Security} property to determine
* the preferred provider order for the specified algorithm. This * the preferred provider order for the specified algorithm. This
* may be different than the order of providers returned by * may be different from the order of providers returned by
* {@link Security#getProviders() Security.getProviders()}. * {@link Security#getProviders() Security.getProviders()}.
* *
* @param type the name of the requested {@code CertStore} type. * @param type the name of the requested {@code CertStore} type.
@ -427,13 +427,10 @@ public class CertStore {
* {@literal "LDAP"} if no such property exists. * {@literal "LDAP"} if no such property exists.
*/ */
@SuppressWarnings("removal") @SuppressWarnings("removal")
public static final String getDefaultType() { public static String getDefaultType() {
String cstype; String cstype;
cstype = AccessController.doPrivileged(new PrivilegedAction<>() { cstype = AccessController.doPrivileged((PrivilegedAction<String>) () ->
public String run() { Security.getProperty(CERTSTORE_TYPE));
return Security.getProperty(CERTSTORE_TYPE);
}
});
if (cstype == null) { if (cstype == null) {
cstype = "LDAP"; cstype = "LDAP";
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -245,10 +245,10 @@ public abstract class Certificate implements java.io.Serializable {
private static final long serialVersionUID = -8563758940495660020L; private static final long serialVersionUID = -8563758940495660020L;
/** The standard name of the certificate type. */ /** The standard name of the certificate type. */
private String type; private final String type;
/** The certificate data. */ /** The certificate data. */
private byte[] data; private final byte[] data;
/** /**
* Construct the alternate {@code Certificate} class with the * Construct the alternate {@code Certificate} class with the

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -125,13 +125,13 @@ import sun.security.jca.GetInstance.Instance;
public class CertificateFactory { public class CertificateFactory {
// The certificate type // The certificate type
private String type; private final String type;
// The provider // The provider
private Provider provider; private final Provider provider;
// The provider implementation // The provider implementation
private CertificateFactorySpi certFacSpi; private final CertificateFactorySpi certFacSpi;
/** /**
* Creates a CertificateFactory object of the given type, and encapsulates * Creates a CertificateFactory object of the given type, and encapsulates
@ -167,7 +167,7 @@ public class CertificateFactory {
* {@code jdk.security.provider.preferred} * {@code jdk.security.provider.preferred}
* {@link Security#getProperty(String) Security} property to determine * {@link Security#getProperty(String) Security} property to determine
* the preferred provider order for the specified algorithm. This * the preferred provider order for the specified algorithm. This
* may be different than the order of providers returned by * may be different from the order of providers returned by
* {@link Security#getProviders() Security.getProviders()}. * {@link Security#getProviders() Security.getProviders()}.
* *
* @param type the name of the requested certificate type. * @param type the name of the requested certificate type.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -29,9 +29,6 @@ import java.io.InputStream;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.security.Provider;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
/** /**
* This class defines the <i>Service Provider Interface</i> (<b>SPI</b>) * This class defines the <i>Service Provider Interface</i> (<b>SPI</b>)

View File

@ -187,8 +187,8 @@ public class CertificateRevokedException extends CertificateException {
/** /**
* Serialize this {@code CertificateRevokedException} instance. * Serialize this {@code CertificateRevokedException} instance.
* *
* @serialData the size of the extensions map (int), followed by all of * @serialData the size of the extensions map (int), followed by all the
* the extensions in the map, in no particular order. For each extension, * extensions in the map, in no particular order. For each extension,
* the following data is emitted: the OID String (Object), the criticality * the following data is emitted: the OID String (Object), the criticality
* flag (boolean), the length of the encoded extension value byte array * flag (boolean), the length of the encoded extension value byte array
* (int), and the encoded extension value bytes. * (int), and the encoded extension value bytes.
@ -245,7 +245,7 @@ public class CertificateRevokedException extends CertificateException {
} else if (size < 0) { } else if (size < 0) {
throw new IOException("size cannot be negative"); throw new IOException("size cannot be negative");
} else { } else {
extensions = HashMap.newHashMap(size > 20 ? 20 : size); extensions = HashMap.newHashMap(Math.min(size, 20));
} }
// Read in the extensions and put the mappings in the extensions map // Read in the extensions and put the mappings in the extensions map

View File

@ -25,7 +25,6 @@
package java.security.cert; package java.security.cert;
import java.io.Serializable;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
@ -55,7 +54,7 @@ import java.util.Collections;
public class CollectionCertStoreParameters public class CollectionCertStoreParameters
implements CertStoreParameters { implements CertStoreParameters {
private Collection<?> coll; private final Collection<?> coll;
/** /**
* Creates an instance of {@code CollectionCertStoreParameters} * Creates an instance of {@code CollectionCertStoreParameters}
@ -132,10 +131,8 @@ public class CollectionCertStoreParameters
* @return a formatted string describing the parameters * @return a formatted string describing the parameters
*/ */
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder(); return "CollectionCertStoreParameters: [\n" +
sb.append("CollectionCertStoreParameters: [\n"); " collection: " + coll + "\n" +
sb.append(" collection: " + coll + "\n"); "]";
sb.append("]");
return sb.toString();
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -27,7 +27,6 @@ package java.security.cert;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.Serializable;
/** /**
* This interface represents an X.509 extension. * This interface represents an X.509 extension.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -33,7 +33,7 @@ package java.security.cert;
* algorithm. However, if you are retrieving certificates or CRLs from * algorithm. However, if you are retrieving certificates or CRLs from
* an ldap URI as specified by RFC 5280, use the * an ldap URI as specified by RFC 5280, use the
* {@link java.security.cert.URICertStoreParameters URICertStoreParameters} * {@link java.security.cert.URICertStoreParameters URICertStoreParameters}
* instead as the URI may contain additional information such as the * instead, as the URI may contain additional information such as the
* distinguished name that will help the LDAP CertStore find the specific * distinguished name that will help the LDAP CertStore find the specific
* certificates and CRLs. * certificates and CRLs.
* <p> * <p>
@ -56,12 +56,12 @@ public class LDAPCertStoreParameters implements CertStoreParameters {
/** /**
* the port number of the LDAP server * the port number of the LDAP server
*/ */
private int port; private final int port;
/** /**
* the DNS name of the LDAP server * the DNS name of the LDAP server
*/ */
private String serverName; private final String serverName;
/** /**
* Creates an instance of {@code LDAPCertStoreParameters} with the * Creates an instance of {@code LDAPCertStoreParameters} with the
@ -143,12 +143,10 @@ public class LDAPCertStoreParameters implements CertStoreParameters {
* @return a formatted string describing the parameters * @return a formatted string describing the parameters
*/ */
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("LDAPCertStoreParameters: [\n");
sb.append(" serverName: " + serverName + "\n"); return "LDAPCertStoreParameters: [\n" +
sb.append(" port: " + port + "\n"); " serverName: " + serverName + "\n" +
sb.append("]"); " port: " + port + "\n" +
return sb.toString(); "]";
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -189,11 +189,9 @@ public class PKIXBuilderParameters extends PKIXParameters {
* @return a formatted string describing the parameters * @return a formatted string describing the parameters
*/ */
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder(); return "[\n" +
sb.append("[\n"); super.toString() +
sb.append(super.toString()); " Maximum Path Length: " + maxPathLength + "\n" +
sb.append(" Maximum Path Length: " + maxPathLength + "\n"); "]\n";
sb.append("]\n");
return sb.toString();
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -59,7 +59,7 @@ import java.security.PublicKey;
public class PKIXCertPathBuilderResult extends PKIXCertPathValidatorResult public class PKIXCertPathBuilderResult extends PKIXCertPathValidatorResult
implements CertPathBuilderResult { implements CertPathBuilderResult {
private CertPath certPath; private final CertPath certPath;
/** /**
* Creates an instance of {@code PKIXCertPathBuilderResult} * Creates an instance of {@code PKIXCertPathBuilderResult}
@ -107,13 +107,11 @@ public class PKIXCertPathBuilderResult extends PKIXCertPathValidatorResult
* {@code PKIXCertPathBuilderResult} * {@code PKIXCertPathBuilderResult}
*/ */
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder(); return "PKIXCertPathBuilderResult: [\n" +
sb.append("PKIXCertPathBuilderResult: [\n"); " Certification Path: " + certPath + "\n" +
sb.append(" Certification Path: " + certPath + "\n"); " Trust Anchor: " + getTrustAnchor() + "\n" +
sb.append(" Trust Anchor: " + getTrustAnchor() + "\n"); " Policy Tree: " + getPolicyTree() + "\n" +
sb.append(" Policy Tree: " + getPolicyTree() + "\n"); " Subject Public Key: " + getPublicKey() + "\n" +
sb.append(" Subject Public Key: " + getPublicKey() + "\n"); "]";
sb.append("]");
return sb.toString();
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -173,7 +173,7 @@ public abstract class PKIXCertPathChecker
*/ */
@Override @Override
public void check(Certificate cert) throws CertPathValidatorException { public void check(Certificate cert) throws CertPathValidatorException {
check(cert, java.util.Collections.<String>emptySet()); check(cert, java.util.Collections.emptySet());
} }
/** /**

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -57,9 +57,9 @@ import java.security.PublicKey;
*/ */
public class PKIXCertPathValidatorResult implements CertPathValidatorResult { public class PKIXCertPathValidatorResult implements CertPathValidatorResult {
private TrustAnchor trustAnchor; private final TrustAnchor trustAnchor;
private PolicyNode policyTree; private final PolicyNode policyTree;
private PublicKey subjectPublicKey; private final PublicKey subjectPublicKey;
/** /**
* Creates an instance of {@code PKIXCertPathValidatorResult} * Creates an instance of {@code PKIXCertPathValidatorResult}
@ -148,12 +148,10 @@ public class PKIXCertPathValidatorResult implements CertPathValidatorResult {
* {@code PKIXCertPathValidatorResult} * {@code PKIXCertPathValidatorResult}
*/ */
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder(); return "PKIXCertPathValidatorResult: [\n" +
sb.append("PKIXCertPathValidatorResult: [\n"); " Trust Anchor: " + trustAnchor + "\n" +
sb.append(" Trust Anchor: " + trustAnchor + "\n"); " Policy Tree: " + policyTree + "\n" +
sb.append(" Policy Tree: " + policyTree + "\n"); " Subject Public Key: " + subjectPublicKey + "\n" +
sb.append(" Subject Public Key: " + subjectPublicKey + "\n"); "]";
sb.append("]");
return sb.toString();
} }
} }

View File

@ -25,14 +25,7 @@
package java.security.cert; package java.security.cert;
import java.net.URI; import java.net.URI;
import java.util.ArrayList; import java.util.*;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
/** /**
* A {@code PKIXCertPathChecker} for checking the revocation status of * A {@code PKIXCertPathChecker} for checking the revocation status of
@ -100,7 +93,7 @@ import java.util.Set;
public abstract class PKIXRevocationChecker extends PKIXCertPathChecker { public abstract class PKIXRevocationChecker extends PKIXCertPathChecker {
private URI ocspResponder; private URI ocspResponder;
private X509Certificate ocspResponderCert; private X509Certificate ocspResponderCert;
private List<Extension> ocspExtensions = Collections.<Extension>emptyList(); private List<Extension> ocspExtensions = Collections.emptyList();
private Map<X509Certificate, byte[]> ocspResponses = Collections.emptyMap(); private Map<X509Certificate, byte[]> ocspResponses = Collections.emptyMap();
private Set<Option> options = Collections.emptySet(); private Set<Option> options = Collections.emptySet();
@ -170,7 +163,7 @@ public abstract class PKIXRevocationChecker extends PKIXCertPathChecker {
public void setOcspExtensions(List<Extension> extensions) public void setOcspExtensions(List<Extension> extensions)
{ {
this.ocspExtensions = (extensions == null) this.ocspExtensions = (extensions == null)
? Collections.<Extension>emptyList() ? Collections.emptyList()
: new ArrayList<>(extensions); : new ArrayList<>(extensions);
} }
@ -196,7 +189,7 @@ public abstract class PKIXRevocationChecker extends PKIXCertPathChecker {
public void setOcspResponses(Map<X509Certificate, byte[]> responses) public void setOcspResponses(Map<X509Certificate, byte[]> responses)
{ {
if (responses == null) { if (responses == null) {
this.ocspResponses = Collections.<X509Certificate, byte[]>emptyMap(); this.ocspResponses = Collections.emptyMap();
} else { } else {
Map<X509Certificate, byte[]> copy = HashMap.newHashMap(responses.size()); Map<X509Certificate, byte[]> copy = HashMap.newHashMap(responses.size());
for (Map.Entry<X509Certificate, byte[]> e : responses.entrySet()) { for (Map.Entry<X509Certificate, byte[]> e : responses.entrySet()) {
@ -232,7 +225,7 @@ public abstract class PKIXRevocationChecker extends PKIXCertPathChecker {
*/ */
public void setOptions(Set<Option> options) { public void setOptions(Set<Option> options) {
this.options = (options == null) this.options = (options == null)
? Collections.<Option>emptySet() ? Collections.emptySet()
: new HashSet<>(options); : new HashSet<>(options);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -62,7 +62,7 @@ import sun.security.util.DerValue;
* *
* <p>Note that the PKIX certification path validation algorithm specifies * <p>Note that the PKIX certification path validation algorithm specifies
* that any policy qualifier in a certificate policies extension that is * that any policy qualifier in a certificate policies extension that is
* marked critical must be processed and validated. Otherwise the * marked critical must be processed and validated. Otherwise, the
* certification path must be rejected. If the * certification path must be rejected. If the
* {@code policyQualifiersRejected} flag is set to false, it is up to * {@code policyQualifiersRejected} flag is set to false, it is up to
* the application to validate all policy qualifiers in this manner in order * the application to validate all policy qualifiers in this manner in order
@ -84,9 +84,9 @@ import sun.security.util.DerValue;
*/ */
public class PolicyQualifierInfo { public class PolicyQualifierInfo {
private byte [] mEncoded; private final byte [] mEncoded;
private String mId; private final String mId;
private byte [] mData; private final byte [] mData;
private String pqiString; private String pqiString;
/** /**
@ -161,13 +161,11 @@ public class PolicyQualifierInfo {
if (pqiString != null) if (pqiString != null)
return pqiString; return pqiString;
HexDumpEncoder enc = new HexDumpEncoder(); HexDumpEncoder enc = new HexDumpEncoder();
StringBuilder sb = new StringBuilder(); pqiString = "PolicyQualifierInfo: [\n" +
sb.append("PolicyQualifierInfo: [\n"); " qualifierID: " + mId + "\n" +
sb.append(" qualifierID: " + mId + "\n"); " qualifier: " +
sb.append(" qualifier: " + (mData == null ? "null" : enc.encodeBuffer(mData)) + "\n" +
(mData == null ? "null" : enc.encodeBuffer(mData)) + "\n"); "]";
sb.append("]");
pqiString = sb.toString();
return pqiString; return pqiString;
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -55,7 +55,7 @@ public final class URICertStoreParameters implements CertStoreParameters {
private final URI uri; private final URI uri;
/* /*
* Hash code for this parameters. * Hash code for this parameters object.
*/ */
private int myhash = -1; private int myhash = -1;
@ -103,7 +103,7 @@ public final class URICertStoreParameters implements CertStoreParameters {
* Returns a hash code value for this parameters object. * Returns a hash code value for this parameters object.
* The hash code is generated using the URI supplied at construction. * The hash code is generated using the URI supplied at construction.
* *
* @return a hash code value for this parameters. * @return a hash code value for this parameters object.
*/ */
@Override @Override
public int hashCode() { public int hashCode() {
@ -118,7 +118,7 @@ public final class URICertStoreParameters implements CertStoreParameters {
* Two URICertStoreParameters are considered equal if the URIs used * Two URICertStoreParameters are considered equal if the URIs used
* to construct them are equal. * to construct them are equal.
* *
* @param p the object to test for equality with this parameters. * @param p the object to test for equality with this parameters object.
* *
* @return true if the specified object is equal to this parameters object. * @return true if the specified object is equal to this parameters object.
*/ */

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,18 +25,15 @@
package java.security.cert; package java.security.cert;
import java.security.*; import sun.security.util.SignatureUtil;
import java.security.spec.*; import sun.security.x509.X509CRLImpl;
import javax.security.auth.x500.X500Principal; import javax.security.auth.x500.X500Principal;
import java.math.BigInteger; import java.math.BigInteger;
import java.security.*;
import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.Set; import java.util.Set;
import java.util.Arrays;
import sun.security.x509.X509CRLImpl;
import sun.security.util.SignatureUtil;
/** /**
* <p> * <p>
@ -257,7 +254,7 @@ public abstract class X509CRL extends CRL implements X509Extension {
byte[] tbsCRL = getTBSCertList(); byte[] tbsCRL = getTBSCertList();
sig.update(tbsCRL, 0, tbsCRL.length); sig.update(tbsCRL, 0, tbsCRL.length);
if (sig.verify(getSignature()) == false) { if (!sig.verify(getSignature())) {
throw new SignatureException("Signature does not match."); throw new SignatureException("Signature does not match.");
} }
} }
@ -390,7 +387,7 @@ public abstract class X509CRL extends CRL implements X509Extension {
public X509CRLEntry getRevokedCertificate(X509Certificate certificate) { public X509CRLEntry getRevokedCertificate(X509Certificate certificate) {
X500Principal certIssuer = certificate.getIssuerX500Principal(); X500Principal certIssuer = certificate.getIssuerX500Principal();
X500Principal crlIssuer = getIssuerX500Principal(); X500Principal crlIssuer = getIssuerX500Principal();
if (certIssuer.equals(crlIssuer) == false) { if (!certIssuer.equals(crlIssuer)) {
return null; return null;
} }
return getRevokedCertificate(certificate.getSerialNumber()); return getRevokedCertificate(certificate.getSerialNumber());

View File

@ -25,16 +25,15 @@
package java.security.cert; package java.security.cert;
import sun.security.util.SignatureUtil;
import sun.security.x509.X509CertImpl;
import javax.security.auth.x500.X500Principal;
import java.math.BigInteger; import java.math.BigInteger;
import java.security.*; import java.security.*;
import java.security.spec.*;
import java.util.Collection; import java.util.Collection;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import javax.security.auth.x500.X500Principal;
import sun.security.x509.X509CertImpl;
import sun.security.util.SignatureUtil;
/** /**
* <p> * <p>
@ -708,7 +707,7 @@ implements X509Extension {
byte[] tbsCert = getTBSCertificate(); byte[] tbsCert = getTBSCertificate();
sig.update(tbsCert, 0, tbsCert.length); sig.update(tbsCert, 0, tbsCert.length);
if (sig.verify(getSignature()) == false) { if (!sig.verify(getSignature())) {
throw new SignatureException("Signature does not match."); throw new SignatureException("Signature does not match.");
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -76,7 +76,7 @@ public interface X509Extension {
* @return {@code true} if a critical extension is found that is * @return {@code true} if a critical extension is found that is
* not supported, otherwise {@code false}. * not supported, otherwise {@code false}.
*/ */
public boolean hasUnsupportedCriticalExtension(); boolean hasUnsupportedCriticalExtension();
/** /**
* Gets a Set of the OID strings for the extension(s) marked * Gets a Set of the OID strings for the extension(s) marked
@ -105,7 +105,7 @@ public interface X509Extension {
* If there are no extensions present at all, then this method returns * If there are no extensions present at all, then this method returns
* null. * null.
*/ */
public Set<String> getCriticalExtensionOIDs(); Set<String> getCriticalExtensionOIDs();
/** /**
* Gets a Set of the OID strings for the extension(s) marked * Gets a Set of the OID strings for the extension(s) marked
@ -142,7 +142,7 @@ public interface X509Extension {
* If there are no extensions present at all, then this method returns * If there are no extensions present at all, then this method returns
* null. * null.
*/ */
public Set<String> getNonCriticalExtensionOIDs(); Set<String> getNonCriticalExtensionOIDs();
/** /**
* Gets the DER-encoded OCTET string for the extension value * Gets the DER-encoded OCTET string for the extension value
@ -188,5 +188,5 @@ public interface X509Extension {
* @return the DER-encoded octet string of the extension value or * @return the DER-encoded octet string of the extension value or
* null if it is not present. * null if it is not present.
*/ */
public byte[] getExtensionValue(String oid); byte[] getExtensionValue(String oid);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1996, 1998, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -47,5 +47,5 @@ public interface DSAKey {
* *
* @see DSAParams * @see DSAParams
*/ */
public DSAParams getParams(); DSAParams getParams();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -88,8 +88,7 @@ public interface DSAKeyPairGenerator {
* @throws InvalidParameterException if the {@code params} * @throws InvalidParameterException if the {@code params}
* value is invalid, null, or unsupported. * value is invalid, null, or unsupported.
*/ */
public void initialize(DSAParams params, SecureRandom random) void initialize(DSAParams params, SecureRandom random);
throws InvalidParameterException;
/** /**
* Initializes the key pair generator for a given modulus length * Initializes the key pair generator for a given modulus length
@ -109,13 +108,12 @@ public interface DSAKeyPairGenerator {
* @param random the random bit source to use to generate key bits; * @param random the random bit source to use to generate key bits;
* can be null. * can be null.
* *
* @param genParams whether or not to generate new parameters for * @param genParams whether to generate new parameters for
* the modulus length requested. * the modulus length requested.
* *
* @throws InvalidParameterException if {@code modlen} is * @throws InvalidParameterException if {@code modlen} is
* invalid, or unsupported, or if {@code genParams} is false and there * invalid, or unsupported, or if {@code genParams} is false and there
* are no precomputed parameters for the requested modulus length. * are no precomputed parameters for the requested modulus length.
*/ */
public void initialize(int modlen, boolean genParams, SecureRandom random) void initialize(int modlen, boolean genParams, SecureRandom random);
throws InvalidParameterException;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -47,19 +47,19 @@ public interface DSAParams {
* *
* @return the prime, {@code p}. * @return the prime, {@code p}.
*/ */
public BigInteger getP(); BigInteger getP();
/** /**
* Returns the subprime, {@code q}. * Returns the subprime, {@code q}.
* *
* @return the subprime, {@code q}. * @return the subprime, {@code q}.
*/ */
public BigInteger getQ(); BigInteger getQ();
/** /**
* Returns the base, {@code g}. * Returns the base, {@code g}.
* *
* @return the base, {@code g}. * @return the base, {@code g}.
*/ */
public BigInteger getG(); BigInteger getG();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -54,12 +54,12 @@ public interface DSAPrivateKey extends DSAKey, java.security.PrivateKey {
@Deprecated @Deprecated
@SuppressWarnings("serial") @SuppressWarnings("serial")
@java.io.Serial @java.io.Serial
static final long serialVersionUID = 7776497482533790279L; long serialVersionUID = 7776497482533790279L;
/** /**
* Returns the value of the private key, {@code x}. * Returns the value of the private key, {@code x}.
* *
* @return the value of the private key, {@code x}. * @return the value of the private key, {@code x}.
*/ */
public BigInteger getX(); BigInteger getX();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -54,12 +54,12 @@ public interface DSAPublicKey extends DSAKey, java.security.PublicKey {
@Deprecated @Deprecated
@SuppressWarnings("serial") @SuppressWarnings("serial")
@java.io.Serial @java.io.Serial
static final long serialVersionUID = 1234526332779022332L; long serialVersionUID = 1234526332779022332L;
/** /**
* Returns the value of the public key, {@code y}. * Returns the value of the public key, {@code y}.
* *
* @return the value of the public key, {@code y}. * @return the value of the public key, {@code y}.
*/ */
public BigInteger getY(); BigInteger getY();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -49,7 +49,7 @@ public interface ECPrivateKey extends PrivateKey, ECKey {
@Deprecated @Deprecated
@SuppressWarnings("serial") @SuppressWarnings("serial")
@java.io.Serial @java.io.Serial
static final long serialVersionUID = -7896394956925609184L; long serialVersionUID = -7896394956925609184L;
/** /**
* Returns the private value S. * Returns the private value S.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -51,7 +51,7 @@ public interface ECPublicKey extends PublicKey, ECKey {
@Deprecated @Deprecated
@SuppressWarnings("serial") @SuppressWarnings("serial")
@java.io.Serial @java.io.Serial
static final long serialVersionUID = -3314988629879632826L; long serialVersionUID = -3314988629879632826L;
/** /**
* Returns the public point W. * Returns the public point W.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -48,7 +48,7 @@ public interface RSAKey {
* *
* @return the modulus * @return the modulus
*/ */
public BigInteger getModulus(); BigInteger getModulus();
/** /**
* Returns the parameters associated with this key. * Returns the parameters associated with this key.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2001, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -57,49 +57,49 @@ public interface RSAMultiPrimePrivateCrtKey extends RSAPrivateKey {
@Deprecated @Deprecated
@SuppressWarnings("serial") @SuppressWarnings("serial")
@java.io.Serial @java.io.Serial
static final long serialVersionUID = 618058533534628008L; long serialVersionUID = 618058533534628008L;
/** /**
* Returns the public exponent. * Returns the public exponent.
* *
* @return the public exponent. * @return the public exponent.
*/ */
public BigInteger getPublicExponent(); BigInteger getPublicExponent();
/** /**
* Returns the primeP. * Returns the primeP.
* *
* @return the primeP. * @return the primeP.
*/ */
public BigInteger getPrimeP(); BigInteger getPrimeP();
/** /**
* Returns the primeQ. * Returns the primeQ.
* *
* @return the primeQ. * @return the primeQ.
*/ */
public BigInteger getPrimeQ(); BigInteger getPrimeQ();
/** /**
* Returns the primeExponentP. * Returns the primeExponentP.
* *
* @return the primeExponentP. * @return the primeExponentP.
*/ */
public BigInteger getPrimeExponentP(); BigInteger getPrimeExponentP();
/** /**
* Returns the primeExponentQ. * Returns the primeExponentQ.
* *
* @return the primeExponentQ. * @return the primeExponentQ.
*/ */
public BigInteger getPrimeExponentQ(); BigInteger getPrimeExponentQ();
/** /**
* Returns the crtCoefficient. * Returns the crtCoefficient.
* *
* @return the crtCoefficient. * @return the crtCoefficient.
*/ */
public BigInteger getCrtCoefficient(); BigInteger getCrtCoefficient();
/** /**
* Returns the otherPrimeInfo or null if there are only * Returns the otherPrimeInfo or null if there are only
@ -107,5 +107,5 @@ public interface RSAMultiPrimePrivateCrtKey extends RSAPrivateKey {
* *
* @return the otherPrimeInfo. * @return the otherPrimeInfo.
*/ */
public RSAOtherPrimeInfo[] getOtherPrimeInfo(); RSAOtherPrimeInfo[] getOtherPrimeInfo();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -52,47 +52,47 @@ public interface RSAPrivateCrtKey extends RSAPrivateKey {
@Deprecated @Deprecated
@SuppressWarnings("serial") @SuppressWarnings("serial")
@java.io.Serial @java.io.Serial
static final long serialVersionUID = -5682214253527700368L; long serialVersionUID = -5682214253527700368L;
/** /**
* Returns the public exponent. * Returns the public exponent.
* *
* @return the public exponent * @return the public exponent
*/ */
public BigInteger getPublicExponent(); BigInteger getPublicExponent();
/** /**
* Returns the primeP. * Returns the primeP.
* *
* @return the primeP * @return the primeP
*/ */
public BigInteger getPrimeP(); BigInteger getPrimeP();
/** /**
* Returns the primeQ. * Returns the primeQ.
* *
* @return the primeQ * @return the primeQ
*/ */
public BigInteger getPrimeQ(); BigInteger getPrimeQ();
/** /**
* Returns the primeExponentP. * Returns the primeExponentP.
* *
* @return the primeExponentP * @return the primeExponentP
*/ */
public BigInteger getPrimeExponentP(); BigInteger getPrimeExponentP();
/** /**
* Returns the primeExponentQ. * Returns the primeExponentQ.
* *
* @return the primeExponentQ * @return the primeExponentQ
*/ */
public BigInteger getPrimeExponentQ(); BigInteger getPrimeExponentQ();
/** /**
* Returns the crtCoefficient. * Returns the crtCoefficient.
* *
* @return the crtCoefficient * @return the crtCoefficient
*/ */
public BigInteger getCrtCoefficient(); BigInteger getCrtCoefficient();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -51,12 +51,12 @@ public interface RSAPrivateKey extends java.security.PrivateKey, RSAKey
@Deprecated @Deprecated
@SuppressWarnings("serial") @SuppressWarnings("serial")
@java.io.Serial @java.io.Serial
static final long serialVersionUID = 5187144804936595022L; long serialVersionUID = 5187144804936595022L;
/** /**
* Returns the private exponent. * Returns the private exponent.
* *
* @return the private exponent * @return the private exponent
*/ */
public BigInteger getPrivateExponent(); BigInteger getPrivateExponent();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -48,12 +48,12 @@ public interface RSAPublicKey extends java.security.PublicKey, RSAKey
@Deprecated @Deprecated
@SuppressWarnings("serial") @SuppressWarnings("serial")
@java.io.Serial @java.io.Serial
static final long serialVersionUID = -8727434096241101194L; long serialVersionUID = -8727434096241101194L;
/** /**
* Returns the public exponent. * Returns the public exponent.
* *
* @return the public exponent * @return the public exponent
*/ */
public BigInteger getPublicExponent(); BigInteger getPublicExponent();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -39,7 +39,7 @@
* provider-based. The class itself defines a programming interface * provider-based. The class itself defines a programming interface
* to which applications may write. The implementations themselves may * to which applications may write. The implementations themselves may
* then be written by independent third-party vendors and plugged * then be written by independent third-party vendors and plugged
* in seamlessly as needed. Therefore application developers may * in seamlessly as needed. Therefore, application developers may
* take advantage of any number of provider-based implementations * take advantage of any number of provider-based implementations
* without having to add or rewrite code. * without having to add or rewrite code.
* *

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -44,10 +44,10 @@ import java.math.BigInteger;
public class DSAPrivateKeySpec implements KeySpec { public class DSAPrivateKeySpec implements KeySpec {
private BigInteger x; private final BigInteger x;
private BigInteger p; private final BigInteger p;
private BigInteger q; private final BigInteger q;
private BigInteger g; private final BigInteger g;
/** /**
* Creates a new DSAPrivateKeySpec with the specified parameter values. * Creates a new DSAPrivateKeySpec with the specified parameter values.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -44,10 +44,10 @@ import java.math.BigInteger;
public class DSAPublicKeySpec implements KeySpec { public class DSAPublicKeySpec implements KeySpec {
private BigInteger y; private final BigInteger y;
private BigInteger p; private final BigInteger p;
private BigInteger q; private final BigInteger q;
private BigInteger g; private final BigInteger g;
/** /**
* Creates a new DSAPublicKeySpec with the specified parameter values. * Creates a new DSAPublicKeySpec with the specified parameter values.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -24,9 +24,6 @@
*/ */
package java.security.spec; package java.security.spec;
import java.math.BigInteger;
import java.util.Arrays;
/** /**
* This interface represents an elliptic curve (EC) finite field. * This interface represents an elliptic curve (EC) finite field.
* All specialized EC fields must implements this interface. * All specialized EC fields must implements this interface.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -39,8 +39,8 @@ import java.util.Arrays;
*/ */
public class ECFieldF2m implements ECField { public class ECFieldF2m implements ECField {
private int m; private final int m;
private int[] ks; private final int[] ks;
private BigInteger rp; private BigInteger rp;
/** /**

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,7 +25,6 @@
package java.security.spec; package java.security.spec;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.Arrays;
/** /**
* This immutable class defines an elliptic curve (EC) prime * This immutable class defines an elliptic curve (EC) prime
@ -39,7 +38,7 @@ import java.util.Arrays;
*/ */
public class ECFieldFp implements ECField { public class ECFieldFp implements ECField {
private BigInteger p; private final BigInteger p;
/** /**
* Creates an elliptic curve prime finite field * Creates an elliptic curve prime finite field
@ -63,7 +62,7 @@ public class ECFieldFp implements ECField {
*/ */
public int getFieldSize() { public int getFieldSize() {
return p.bitLength(); return p.bitLength();
}; }
/** /**
* Returns the prime {@code p} of this prime finite field. * Returns the prime {@code p} of this prime finite field.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -39,8 +39,8 @@ import java.math.BigInteger;
*/ */
public class ECPrivateKeySpec implements KeySpec { public class ECPrivateKeySpec implements KeySpec {
private BigInteger s; private final BigInteger s;
private ECParameterSpec params; private final ECParameterSpec params;
/** /**
* Creates a new ECPrivateKeySpec with the specified * Creates a new ECPrivateKeySpec with the specified

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -38,8 +38,8 @@ package java.security.spec;
*/ */
public class ECPublicKeySpec implements KeySpec { public class ECPublicKeySpec implements KeySpec {
private ECPoint w; private final ECPoint w;
private ECParameterSpec params; private final ECParameterSpec params;
/** /**
* Creates a new ECPublicKeySpec with the specified * Creates a new ECPublicKeySpec with the specified

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -53,7 +53,7 @@ public class EdDSAParameterSpec implements AlgorithmParameterSpec {
* Construct an {@code EdDSAParameterSpec} by specifying whether the prehash mode * Construct an {@code EdDSAParameterSpec} by specifying whether the prehash mode
* is used. No context is provided so this constructor specifies a mode * is used. No context is provided so this constructor specifies a mode
* in which the context is null. Note that this mode may be different * in which the context is null. Note that this mode may be different
* than the mode in which an empty array is used as the context. * from the mode in which an empty array is used as the context.
* *
* @param prehash whether the prehash mode is specified. * @param prehash whether the prehash mode is specified.
*/ */

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -26,7 +26,6 @@
package java.security.spec; package java.security.spec;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.Arrays;
/** /**
* This immutable class holds the necessary values needed to represent * This immutable class holds the necessary values needed to represent

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,7 +25,6 @@
package java.security.spec; package java.security.spec;
import jdk.internal.access.JavaSecuritySpecAccess;
import jdk.internal.access.SharedSecrets; import jdk.internal.access.SharedSecrets;
import java.util.Arrays; import java.util.Arrays;
@ -47,20 +46,15 @@ import java.util.Arrays;
public abstract class EncodedKeySpec implements KeySpec { public abstract class EncodedKeySpec implements KeySpec {
private byte[] encodedKey; private final byte[] encodedKey;
private String algorithmName; private String algorithmName;
static { static {
SharedSecrets.setJavaSecuritySpecAccess( SharedSecrets.setJavaSecuritySpecAccess(
new JavaSecuritySpecAccess() { EncodedKeySpec::clear);
@Override
public void clearEncodedKeySpec(EncodedKeySpec keySpec) {
keySpec.clear();
}
});
} }
/** /**
* Creates a new {@code EncodedKeySpec} with the given encoded key. * Creates a new {@code EncodedKeySpec} with the given encoded key.
* *
* @param encodedKey the encoded key. The contents of the * @param encodedKey the encoded key. The contents of the

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -68,7 +68,7 @@ public class NamedParameterSpec implements AlgorithmParameterSpec {
public static final NamedParameterSpec ED448 public static final NamedParameterSpec ED448
= new NamedParameterSpec("Ed448"); = new NamedParameterSpec("Ed448");
private String name; private final String name;
/** /**
* Creates a parameter specification using a standard (or predefined) * Creates a parameter specification using a standard (or predefined)

View File

@ -225,12 +225,10 @@ public class PSSParameterSpec implements AlgorithmParameterSpec {
@Override @Override
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder("PSSParameterSpec["); return "PSSParameterSpec[" + "hashAlgorithm=" + mdName + ", " +
sb.append("hashAlgorithm=" + mdName + ", ") "maskGenAlgorithm=" + mgfSpec + ", " +
.append("maskGenAlgorithm=" + mgfSpec + ", ") "saltLength=" + saltLen + ", " +
.append("saltLength=" + saltLen + ", ") "trailerField=" + trailerField +
.append("trailerField=" + trailerField) ']';
.append(']');
return sb.toString();
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -26,7 +26,6 @@
package java.security.spec; package java.security.spec;
import java.math.BigInteger; import java.math.BigInteger;
import java.security.spec.AlgorithmParameterSpec;
/** /**
* This class specifies the set of parameters used to generate an RSA * This class specifies the set of parameters used to generate an RSA
@ -41,9 +40,9 @@ import java.security.spec.AlgorithmParameterSpec;
public class RSAKeyGenParameterSpec implements AlgorithmParameterSpec { public class RSAKeyGenParameterSpec implements AlgorithmParameterSpec {
private int keysize; private final int keysize;
private BigInteger publicExponent; private final BigInteger publicExponent;
private AlgorithmParameterSpec keyParams; private final AlgorithmParameterSpec keyParams;
/** /**
* The public-exponent value F0 = 3. * The public-exponent value F0 = 3.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2001, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -78,7 +78,7 @@ public class RSAMultiPrimePrivateCrtKeySpec extends RSAPrivateKeySpec {
* specified if there are only two prime factors * specified if there are only two prime factors
* (p and q) * (p and q)
* @throws NullPointerException if any of the specified parameters * @throws NullPointerException if any of the specified parameters
* with the exception of {@code otherPrimeInfo} is null * except {@code otherPrimeInfo} is null
* @throws IllegalArgumentException if an empty, i.e. 0-length, * @throws IllegalArgumentException if an empty, i.e. 0-length,
* {@code otherPrimeInfo} is specified * {@code otherPrimeInfo} is specified
*/ */
@ -118,7 +118,7 @@ public class RSAMultiPrimePrivateCrtKeySpec extends RSAPrivateKeySpec {
* (p and q) * (p and q)
* @param keyParams the parameters associated with key * @param keyParams the parameters associated with key
* @throws NullPointerException if any of the specified parameters * @throws NullPointerException if any of the specified parameters
* with the exception of {@code otherPrimeInfo} and {@code keyParams} * except {@code otherPrimeInfo} and {@code keyParams}
* is null * is null
* @throws IllegalArgumentException if an empty, i.e. 0-length, * @throws IllegalArgumentException if an empty, i.e. 0-length,
* {@code otherPrimeInfo} is specified * {@code otherPrimeInfo} is specified

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -53,9 +53,9 @@ import java.math.BigInteger;
public class RSAOtherPrimeInfo { public class RSAOtherPrimeInfo {
private BigInteger prime; private final BigInteger prime;
private BigInteger primeExponent; private final BigInteger primeExponent;
private BigInteger crtCoefficient; private final BigInteger crtCoefficient;
/** /**