8296142: CertAttrSet::(getName|getElements|delete) are mostly useless

Reviewed-by: mullan
This commit is contained in:
Weijun Wang 2022-11-02 14:40:47 +00:00
parent 6626a29a74
commit 16a041a67a
41 changed files with 60 additions and 1162 deletions

@ -176,6 +176,7 @@ public final class OCSPNonceExtension extends Extension {
*
* @return the name of the extension
*/
@Override
public String getName() {
return EXTENSION_NAME;
}

@ -138,6 +138,7 @@ public class AuthorityInfoAccessExtension extends Extension
/**
* Return the name of this attribute.
*/
@Override
public String getName() {
return NAME;
}
@ -189,29 +190,7 @@ public class AuthorityInfoAccessExtension extends Extension
}
}
/**
* Delete the attribute value.
*/
public void delete(String name) throws IOException {
if (name.equalsIgnoreCase(DESCRIPTIONS)) {
accessDescriptions = new ArrayList<>();
} else {
throw new IOException("Attribute name [" + name +
"] not recognized by " +
"CertAttrSet:AuthorityInfoAccessExtension.");
}
encodeThis();
}
/**
* Return an enumeration of names of attributes existing within this
* attribute.
*/
public Enumeration<String> getElements() {
AttributeNameEnumeration elements = new AttributeNameEnumeration();
elements.addElement(DESCRIPTIONS);
return elements.elements();
}
// Encode this extension value
private void encodeThis() throws IOException {

@ -26,7 +26,6 @@
package sun.security.x509;
import java.io.IOException;
import java.util.Enumeration;
import sun.security.util.*;
@ -272,39 +271,12 @@ implements CertAttrSet<String> {
}
}
/**
* Delete the attribute value.
*/
public void delete(String name) throws IOException {
if (name.equalsIgnoreCase(KEY_ID)) {
id = null;
} else if (name.equalsIgnoreCase(AUTH_NAME)) {
names = null;
} else if (name.equalsIgnoreCase(SERIAL_NUMBER)) {
serialNum = null;
} else {
throw new IOException("Attribute name not recognized by " +
"CertAttrSet:AuthorityKeyIdentifier.");
}
encodeThis();
}
/**
* Return an enumeration of names of attributes existing within this
* attribute.
*/
public Enumeration<String> getElements() {
AttributeNameEnumeration elements = new AttributeNameEnumeration();
elements.addElement(KEY_ID);
elements.addElement(AUTH_NAME);
elements.addElement(SERIAL_NUMBER);
return (elements.elements());
}
/**
* Return the name of this attribute.
*/
@Override
public String getName() {
return (NAME);
}

@ -26,7 +26,6 @@
package sun.security.x509;
import java.io.IOException;
import java.util.Enumeration;
import sun.security.util.*;
@ -234,36 +233,12 @@ implements CertAttrSet<String> {
}
}
/**
* Delete the attribute value.
*/
public void delete(String name) throws IOException {
if (name.equalsIgnoreCase(IS_CA)) {
ca = false;
} else if (name.equalsIgnoreCase(PATH_LEN)) {
pathLen = -1;
} else {
throw new IOException("Attribute name not recognized by " +
"CertAttrSet:BasicConstraints.");
}
encodeThis();
}
/**
* Return an enumeration of names of attributes existing within this
* attribute.
*/
public Enumeration<String> getElements() {
AttributeNameEnumeration elements = new AttributeNameEnumeration();
elements.addElement(IS_CA);
elements.addElement(PATH_LEN);
return (elements.elements());
}
/**
* Return the name of this attribute.
*/
@Override
public String getName() {
return (NAME);
}

@ -28,7 +28,6 @@ package sun.security.x509;
import java.io.IOException;
import java.util.*;
import java.util.Collections;
import sun.security.util.DerOutputStream;
import sun.security.util.DerValue;
@ -188,6 +187,7 @@ public class CRLDistributionPointsExtension extends Extension
/**
* Return the name of this attribute.
*/
@Override
public String getName() {
return extensionName;
}
@ -249,30 +249,7 @@ public class CRLDistributionPointsExtension extends Extension
}
}
/**
* Delete the attribute value.
*/
public void delete(String name) throws IOException {
if (name.equalsIgnoreCase(POINTS)) {
distributionPoints =
Collections.emptyList();
} else {
throw new IOException("Attribute name [" + name +
"] not recognized by " +
"CertAttrSet:" + extensionName + '.');
}
encodeThis();
}
/**
* Return an enumeration of names of attributes existing within this
* attribute.
*/
public Enumeration<String> getElements() {
AttributeNameEnumeration elements = new AttributeNameEnumeration();
elements.addElement(POINTS);
return elements.elements();
}
// Encode this extension value
private void encodeThis() throws IOException {

@ -121,8 +121,8 @@ public class CRLExtensions {
Constructor<?> cons = extClass.getConstructor(PARAMS);
Object[] passed = new Object[] {Boolean.valueOf(ext.isCritical()),
ext.getExtensionValue()};
CertAttrSet<?> crlExt = (CertAttrSet<?>)cons.newInstance(passed);
if (map.put(crlExt.getName(), (Extension)crlExt) != null) {
Extension crlExt = (Extension)cons.newInstance(passed);
if (map.put(crlExt.getName(), crlExt) != null) {
throw new CRLException("Duplicate extensions not allowed");
}
} catch (InvocationTargetException invk) {
@ -238,24 +238,17 @@ public class CRLExtensions {
public boolean equals(Object other) {
if (this == other)
return true;
if (!(other instanceof CRLExtensions))
return false;
Collection<Extension> otherC =
((CRLExtensions)other).getAllExtensions();
Object[] objs = otherC.toArray();
int len = objs.length;
if (len != map.size())
if (!(other instanceof CRLExtensions otherCX))
return false;
Extension otherExt, thisExt;
String key = null;
for (int i = 0; i < len; i++) {
if (objs[i] instanceof CertAttrSet)
key = ((CertAttrSet)objs[i]).getName();
otherExt = (Extension)objs[i];
if (key == null)
key = otherExt.getExtensionId().toString();
Collection<Extension> otherX = otherCX.getAllExtensions();
if (otherX.size() != map.size())
return false;
Extension thisExt;
String key;
for (Extension otherExt : otherX) {
key = otherExt.getName();
thisExt = map.get(key);
if (thisExt == null)
return false;

@ -27,7 +27,6 @@ package sun.security.x509;
import java.io.IOException;
import java.math.BigInteger;
import java.util.Enumeration;
import sun.security.util.*;
@ -163,18 +162,6 @@ implements CertAttrSet<String> {
}
}
/**
* Delete the attribute value.
*/
public void delete(String name) throws IOException {
if (name.equalsIgnoreCase(NUMBER)) {
crlNumber = null;
} else {
throw new IOException("Attribute name not recognized by" +
" CertAttrSet:" + extensionName + '.');
}
encodeThis();
}
/**
* Returns a printable representation of the CRLNumberExtension.
@ -217,19 +204,11 @@ implements CertAttrSet<String> {
super.encode(out);
}
/**
* Return an enumeration of names of attributes existing within this
* attribute.
*/
public Enumeration<String> getElements() {
AttributeNameEnumeration elements = new AttributeNameEnumeration();
elements.addElement(NUMBER);
return (elements.elements());
}
/**
* Return the name of this attribute.
*/
@Override
public String getName() {
return (extensionName);
}

@ -27,7 +27,6 @@ package sun.security.x509;
import java.io.IOException;
import java.security.cert.CRLReason;
import java.util.Enumeration;
import sun.security.util.*;
@ -131,18 +130,6 @@ public class CRLReasonCodeExtension extends Extension
}
}
/**
* Delete the attribute value.
*/
public void delete(String name) throws IOException {
if (name.equalsIgnoreCase(REASON)) {
reasonCode = 0;
} else {
throw new IOException
("Name not supported by CRLReasonCodeExtension");
}
encodeThis();
}
/**
* Returns a printable representation of the Reason code.
@ -167,20 +154,11 @@ public class CRLReasonCodeExtension extends Extension
super.encode(out);
}
/**
* Return an enumeration of names of attributes existing within this
* attribute.
*/
public Enumeration<String> getElements() {
AttributeNameEnumeration elements = new AttributeNameEnumeration();
elements.addElement(REASON);
return elements.elements();
}
/**
* Return the name of this attribute.
*/
@Override
public String getName() {
return NAME;
}

@ -29,7 +29,6 @@ import sun.security.util.DerOutputStream;
import java.io.IOException;
import java.security.cert.CertificateException;
import java.util.Enumeration;
/**
* This interface defines the methods required of a certificate attribute.
@ -47,13 +46,6 @@ import java.util.Enumeration;
* @see CertificateException
*/
public interface CertAttrSet<T> {
/**
* Returns a short string describing this certificate attribute.
*
* @return value of this certificate attribute in
* printable form.
*/
String toString();
/**
* Encodes the attribute to the output stream in a format
@ -89,30 +81,4 @@ public interface CertAttrSet<T> {
*/
Object get(String name)
throws CertificateException, IOException;
/**
* Deletes an attribute value from this CertAttrSet.
*
* @param name the name of the attribute to delete.
*
* @exception CertificateException on attribute handling errors.
* @exception IOException on other errors.
*/
void delete(String name)
throws CertificateException, IOException;
/**
* Returns an enumeration of the names of the attributes existing within
* this attribute.
*
* @return an enumeration of the attribute names.
*/
Enumeration<T> getElements();
/**
* Returns the name (identifier) of this CertAttrSet.
*
* @return the name of this CertAttrSet.
*/
String getName();
}

@ -27,7 +27,6 @@ package sun.security.x509;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import sun.security.util.*;
@ -136,32 +135,4 @@ public class CertificateAlgorithmId implements CertAttrSet<String> {
}
}
/**
* Delete the attribute value.
*/
public void delete(String name) throws IOException {
if (name.equalsIgnoreCase(ALGORITHM)) {
algId = null;
} else {
throw new IOException("Attribute name not recognized by " +
"CertAttrSet:CertificateAlgorithmId.");
}
}
/**
* Return an enumeration of names of attributes existing within this
* attribute.
*/
public Enumeration<String> getElements() {
AttributeNameEnumeration elements = new AttributeNameEnumeration();
elements.addElement(ALGORITHM);
return (elements.elements());
}
/**
* Return the name of this attribute.
*/
public String getName() {
return (NAME);
}
}

@ -105,8 +105,8 @@ public class CertificateExtensions implements CertAttrSet<Extension> {
Object[] passed = new Object[] {Boolean.valueOf(ext.isCritical()),
ext.getExtensionValue()};
CertAttrSet<?> certExt = (CertAttrSet<?>) cons.newInstance(passed);
if (map.put(certExt.getName(), (Extension)certExt) != null) {
Extension certExt = (Extension) cons.newInstance(passed);
if (map.put(certExt.getName(), certExt) != null) {
throw new IOException("Duplicate extensions not allowed");
}
} catch (InvocationTargetException invk) {
@ -233,13 +233,6 @@ public class CertificateExtensions implements CertAttrSet<Extension> {
return null;
}
/**
* Return an enumeration of names of attributes existing within this
* attribute.
*/
public Enumeration<Extension> getElements() {
return Collections.enumeration(map.values());
}
/**
* Return a collection view of the extensions.
@ -254,13 +247,6 @@ public class CertificateExtensions implements CertAttrSet<Extension> {
Collections.emptyMap() : unparseableExtensions;
}
/**
* Return the name of this attribute.
*/
public String getName() {
return NAME;
}
/**
* Return true if a critical extension is found that is
* not supported, otherwise return false.
@ -283,24 +269,17 @@ public class CertificateExtensions implements CertAttrSet<Extension> {
public boolean equals(Object other) {
if (this == other)
return true;
if (!(other instanceof CertificateExtensions))
return false;
Collection<Extension> otherC =
((CertificateExtensions)other).getAllExtensions();
Object[] objs = otherC.toArray();
int len = objs.length;
if (len != map.size())
if (!(other instanceof CertificateExtensions otherCX))
return false;
Extension otherExt, thisExt;
String key = null;
for (int i = 0; i < len; i++) {
if (objs[i] instanceof CertAttrSet)
key = ((CertAttrSet)objs[i]).getName();
otherExt = (Extension)objs[i];
if (key == null)
key = otherExt.getExtensionId().toString();
Collection<Extension> otherX = otherCX.getAllExtensions();
if (otherX.size() != map.size())
return false;
Extension thisExt;
String key;
for (Extension otherExt : otherX) {
key = otherExt.getName();
thisExt = map.get(key);
if (thisExt == null)
return false;
@ -308,7 +287,7 @@ public class CertificateExtensions implements CertAttrSet<Extension> {
return false;
}
return this.getUnparseableExtensions().equals(
((CertificateExtensions)other).getUnparseableExtensions());
otherCX.getUnparseableExtensions());
}
/**

@ -25,7 +25,6 @@
package sun.security.x509;
import java.io.IOException;
import java.util.Enumeration;
import sun.security.util.DerValue;
import sun.security.util.DerOutputStream;
@ -149,20 +148,6 @@ public class CertificateIssuerExtension extends Extension
}
}
/**
* Deletes the attribute value.
*
* @throws IOException on error
*/
public void delete(String name) throws IOException {
if (name.equalsIgnoreCase(ISSUER)) {
names = null;
} else {
throw new IOException("Attribute name not recognized by " +
"CertAttrSet:CertificateIssuer");
}
encodeThis();
}
/**
* Returns a printable representation of the certificate issuer.
@ -188,19 +173,11 @@ public class CertificateIssuerExtension extends Extension
super.encode(out);
}
/**
* Return an enumeration of names of attributes existing within this
* attribute.
*/
public Enumeration<String> getElements() {
AttributeNameEnumeration elements = new AttributeNameEnumeration();
elements.addElement(ISSUER);
return elements.elements();
}
/**
* Return the name of this attribute.
*/
@Override
public String getName() {
return NAME;
}

@ -27,7 +27,6 @@ package sun.security.x509;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import javax.security.auth.x500.X500Principal;
@ -53,7 +52,7 @@ public class CertificateIssuerName implements CertAttrSet<String> {
public static final String DN_NAME = "dname";
// accessor name for cached X500Principal only
// do not allow a set() of this value, do not advertise with getElements()
// do not allow a set() of this value
public static final String DN_PRINCIPAL = "x500principal";
// Private data member
@ -144,34 +143,4 @@ public class CertificateIssuerName implements CertAttrSet<String> {
}
}
/**
* Delete the attribute value.
*/
public void delete(String name) throws IOException {
if (name.equalsIgnoreCase(DN_NAME)) {
dnName = null;
dnPrincipal = null;
} else {
throw new IOException("Attribute name not recognized by " +
"CertAttrSet:CertificateIssuerName.");
}
}
/**
* Return an enumeration of names of attributes existing within this
* attribute.
*/
public Enumeration<String> getElements() {
AttributeNameEnumeration elements = new AttributeNameEnumeration();
elements.addElement(DN_NAME);
return (elements.elements());
}
/**
* Return the name of this attribute.
*/
public String getName() {
return(NAME);
}
}

@ -218,34 +218,12 @@ implements CertAttrSet<String> {
}
}
/**
* Delete the attribute value.
*/
public void delete(String name) throws IOException {
if (name.equalsIgnoreCase(POLICIES)) {
certPolicies = null;
} else {
throw new IOException("Attribute name [" + name +
"] not recognized by " +
"CertAttrSet:CertificatePoliciesExtension.");
}
encodeThis();
}
/**
* Return an enumeration of names of attributes existing within this
* attribute.
*/
public Enumeration<String> getElements() {
AttributeNameEnumeration elements = new AttributeNameEnumeration();
elements.addElement(POLICIES);
return (elements.elements());
}
/**
* Return the name of this attribute.
*/
@Override
public String getName() {
return (NAME);
}

@ -27,7 +27,6 @@ package sun.security.x509;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger;
import java.util.Enumeration;
import java.util.Random;
import sun.security.util.*;
@ -148,36 +147,6 @@ public class CertificateSerialNumber implements CertAttrSet<String> {
}
}
/**
* Delete the attribute value.
*/
public void delete(String name) throws IOException {
if (name.equalsIgnoreCase(NUMBER)) {
serial = null;
} else {
throw new IOException("Attribute name not recognized by " +
"CertAttrSet:CertificateSerialNumber.");
}
}
/**
* Return an enumeration of names of attributes existing within this
* attribute.
*/
public Enumeration<String> getElements() {
AttributeNameEnumeration elements = new AttributeNameEnumeration();
elements.addElement(NUMBER);
return (elements.elements());
}
/**
* Return the name of this attribute.
*/
public String getName() {
return (NAME);
}
/**
* Generates a new random serial number.
*/

@ -27,7 +27,6 @@ package sun.security.x509;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import javax.security.auth.x500.X500Principal;
@ -53,7 +52,7 @@ public class CertificateSubjectName implements CertAttrSet<String> {
public static final String DN_NAME = "dname";
// accessor name for cached X500Principal only
// do not allow a set() of this value, do not advertise with getElements()
// do not allow a set() of this value
public static final String DN_PRINCIPAL = "x500principal";
// Private data member
@ -143,35 +142,4 @@ public class CertificateSubjectName implements CertAttrSet<String> {
"CertAttrSet:CertificateSubjectName.");
}
}
/**
* Delete the attribute value.
*/
public void delete(String name) throws IOException {
if (name.equalsIgnoreCase(DN_NAME)) {
dnName = null;
dnPrincipal = null;
} else {
throw new IOException("Attribute name not recognized by " +
"CertAttrSet:CertificateSubjectName.");
}
}
/**
* Return an enumeration of names of attributes existing within this
* attribute.
*/
public Enumeration<String> getElements() {
AttributeNameEnumeration elements = new AttributeNameEnumeration();
elements.addElement(DN_NAME);
return(elements.elements());
}
/**
* Return the name of this attribute.
*/
public String getName() {
return(NAME);
}
}

@ -27,7 +27,6 @@ package sun.security.x509;
import java.io.IOException;
import java.security.cert.*;
import java.util.Date;
import java.util.Enumeration;
import sun.security.util.*;
@ -201,39 +200,6 @@ public class CertificateValidity implements CertAttrSet<String> {
}
}
/**
* Delete the attribute value.
*/
public void delete(String name) throws IOException {
if (name.equalsIgnoreCase(NOT_BEFORE)) {
notBefore = null;
} else if (name.equalsIgnoreCase(NOT_AFTER)) {
notAfter = null;
} else {
throw new IOException("Attribute name not recognized by " +
"CertAttrSet: CertificateValidity.");
}
}
/**
* Return an enumeration of names of attributes existing within this
* attribute.
*/
public Enumeration<String> getElements() {
AttributeNameEnumeration elements = new AttributeNameEnumeration();
elements.addElement(NOT_BEFORE);
elements.addElement(NOT_AFTER);
return (elements.elements());
}
/**
* Return the name of this attribute.
*/
public String getName() {
return (NAME);
}
/**
* Verify that the current time is within the validity period.
*

@ -27,7 +27,6 @@ package sun.security.x509;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import sun.security.util.*;
@ -197,36 +196,6 @@ public class CertificateVersion implements CertAttrSet<String> {
}
}
/**
* Delete the attribute value.
*/
public void delete(String name) throws IOException {
if (name.equalsIgnoreCase(VERSION)) {
version = V1;
} else {
throw new IOException("Attribute name not recognized by " +
"CertAttrSet: CertificateVersion.");
}
}
/**
* Return an enumeration of names of attributes existing within this
* attribute.
*/
public Enumeration<String> getElements() {
AttributeNameEnumeration elements = new AttributeNameEnumeration();
elements.addElement(VERSION);
return (elements.elements());
}
/**
* Return the name of this attribute.
*/
public String getName() {
return(NAME);
}
/**
* Compare versions.
*/

@ -28,7 +28,6 @@ package sun.security.x509;
import java.security.PublicKey;
import java.io.InputStream;
import java.io.IOException;
import java.util.Enumeration;
import sun.security.util.*;
@ -128,33 +127,4 @@ public class CertificateX509Key implements CertAttrSet<String> {
}
}
/**
* Delete the attribute value.
*/
public void delete(String name) throws IOException {
if (name.equalsIgnoreCase(KEY)) {
key = null;
} else {
throw new IOException("Attribute name not recognized by " +
"CertAttrSet: CertificateX509Key.");
}
}
/**
* Return an enumeration of names of attributes existing within this
* attribute.
*/
public Enumeration<String> getElements() {
AttributeNameEnumeration elements = new AttributeNameEnumeration();
elements.addElement(KEY);
return(elements.elements());
}
/**
* Return the name of this attribute.
*/
public String getName() {
return(NAME);
}
}

@ -27,7 +27,6 @@ package sun.security.x509;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Vector;
@ -239,34 +238,12 @@ implements CertAttrSet<String> {
}
}
/**
* Delete the attribute value.
*/
public void delete(String name) throws IOException {
if (name.equalsIgnoreCase(USAGES)) {
keyUsages = null;
} else {
throw new IOException("Attribute name [" + name +
"] not recognized by " +
"CertAttrSet:ExtendedKeyUsageExtension.");
}
encodeThis();
}
/**
* Return an enumeration of names of attributes existing within this
* attribute.
*/
public Enumeration<String> getElements() {
AttributeNameEnumeration elements = new AttributeNameEnumeration();
elements.addElement(USAGES);
return (elements.elements());
}
/**
* Return the name of this attribute.
*/
@Override
public String getName() {
return (NAME);
}

@ -215,6 +215,15 @@ public class Extension implements java.security.cert.Extension {
return extensionValue;
}
/**
* Returns the extension name. The default implementation returns the
* string form of the extensionId. Known extensions should override this
* method to return a human readable name.
*/
public String getName() {
return getId();
}
public String getId() {
return extensionId.toString();
}

@ -26,7 +26,6 @@
package sun.security.x509;
import java.io.IOException;
import java.util.Enumeration;
import sun.security.util.*;
@ -210,40 +209,14 @@ implements CertAttrSet<String> {
"CertAttrSet:InhibitAnyPolicy.");
}
/**
* Delete the attribute value.
*
* @param name name of attribute to delete. Must be SKIP_CERTS.
* @throws IOException on error. In this case, IOException will always be
* thrown, because the only attribute, SKIP_CERTS, is
* required.
*/
public void delete(String name) throws IOException {
if (name.equalsIgnoreCase(SKIP_CERTS))
throw new IOException("Attribute " + SKIP_CERTS +
" may not be deleted.");
else
throw new IOException("Attribute name not recognized by " +
"CertAttrSet:InhibitAnyPolicy.");
}
/**
* Return an enumeration of names of attributes existing within this
* attribute.
*
* @return enumeration of elements
*/
public Enumeration<String> getElements() {
AttributeNameEnumeration elements = new AttributeNameEnumeration();
elements.addElement(SKIP_CERTS);
return (elements.elements());
}
/**
* Return the name of this attribute.
*
* @return name of attribute.
*/
@Override
public String getName() {
return (NAME);
}

@ -27,7 +27,6 @@ package sun.security.x509;
import java.io.IOException;
import java.util.Date;
import java.util.Enumeration;
import sun.security.util.*;
@ -150,18 +149,6 @@ public class InvalidityDateExtension extends Extension
}
}
/**
* Delete the attribute value.
*/
public void delete(String name) throws IOException {
if (name.equalsIgnoreCase(DATE)) {
date = null;
} else {
throw new IOException
("Name not supported by InvalidityDateExtension");
}
encodeThis();
}
/**
* Returns a printable representation of the Invalidity Date.
@ -186,20 +173,11 @@ public class InvalidityDateExtension extends Extension
super.encode(out);
}
/**
* Return an enumeration of names of attributes existing within this
* attribute.
*/
public Enumeration<String> getElements() {
AttributeNameEnumeration elements = new AttributeNameEnumeration();
elements.addElement(DATE);
return elements.elements();
}
/**
* Return the name of this attribute.
*/
@Override
public String getName() {
return NAME;
}

@ -26,7 +26,6 @@
package sun.security.x509;
import java.io.IOException;
import java.util.Enumeration;
import sun.security.util.*;
@ -200,33 +199,12 @@ extends Extension implements CertAttrSet<String> {
}
}
/**
* Delete the attribute value.
*/
public void delete(String name) throws IOException {
if (name.equalsIgnoreCase(ISSUER_NAME)) {
names = null;
} else {
throw new IOException("Attribute name not recognized by " +
"CertAttrSet:IssuerAlternativeName.");
}
encodeThis();
}
/**
* Return an enumeration of names of attributes existing within this
* attribute.
*/
public Enumeration<String> getElements() {
AttributeNameEnumeration elements = new AttributeNameEnumeration();
elements.addElement(ISSUER_NAME);
return (elements.elements());
}
/**
* Return the name of this attribute.
*/
@Override
public String getName() {
return (NAME);
}

@ -27,8 +27,6 @@ package sun.security.x509;
import java.io.IOException;
import java.util.*;
import sun.security.util.DerInputStream;
import sun.security.util.DerOutputStream;
import sun.security.util.DerValue;
@ -222,6 +220,7 @@ public class IssuingDistributionPointExtension extends Extension
/**
* Returns the name of this attribute.
*/
@Override
public String getName() {
return NAME;
}
@ -326,50 +325,7 @@ public class IssuingDistributionPointExtension extends Extension
}
}
/**
* Deletes the attribute value.
*/
public void delete(String name) throws IOException {
if (name.equalsIgnoreCase(POINT)) {
distributionPoint = null;
} else if (name.equalsIgnoreCase(INDIRECT_CRL)) {
isIndirectCRL = false;
} else if (name.equalsIgnoreCase(REASONS)) {
revocationReasons = null;
} else if (name.equalsIgnoreCase(ONLY_USER_CERTS)) {
hasOnlyUserCerts = false;
} else if (name.equalsIgnoreCase(ONLY_CA_CERTS)) {
hasOnlyCACerts = false;
} else if (name.equalsIgnoreCase(ONLY_ATTRIBUTE_CERTS)) {
hasOnlyAttributeCerts = false;
} else {
throw new IOException("Attribute name [" + name +
"] not recognized by " +
"CertAttrSet:IssuingDistributionPointExtension.");
}
encodeThis();
}
/**
* Returns an enumeration of names of attributes existing within this
* attribute.
*/
public Enumeration<String> getElements() {
AttributeNameEnumeration elements = new AttributeNameEnumeration();
elements.addElement(POINT);
elements.addElement(REASONS);
elements.addElement(ONLY_USER_CERTS);
elements.addElement(ONLY_CA_CERTS);
elements.addElement(ONLY_ATTRIBUTE_CERTS);
elements.addElement(INDIRECT_CRL);
return elements.elements();
}
// Encodes this extension value
private void encodeThis() throws IOException {

@ -26,7 +26,6 @@
package sun.security.x509;
import java.io.IOException;
import java.util.Enumeration;
import sun.security.util.*;
@ -242,34 +241,6 @@ implements CertAttrSet<String> {
}
}
/**
* Delete the attribute value.
*/
public void delete(String name) throws IOException {
if (name.equalsIgnoreCase(DIGITAL_SIGNATURE)) {
set(0,false);
} else if (name.equalsIgnoreCase(NON_REPUDIATION)) {
set(1,false);
} else if (name.equalsIgnoreCase(KEY_ENCIPHERMENT)) {
set(2,false);
} else if (name.equalsIgnoreCase(DATA_ENCIPHERMENT)) {
set(3,false);
} else if (name.equalsIgnoreCase(KEY_AGREEMENT)) {
set(4,false);
} else if (name.equalsIgnoreCase(KEY_CERTSIGN)) {
set(5,false);
} else if (name.equalsIgnoreCase(CRL_SIGN)) {
set(6,false);
} else if (name.equalsIgnoreCase(ENCIPHER_ONLY)) {
set(7,false);
} else if (name.equalsIgnoreCase(DECIPHER_ONLY)) {
set(8,false);
} else {
throw new IOException("Attribute name not recognized by"
+ " CertAttrSet:KeyUsage.");
}
encodeThis();
}
/**
* Returns a printable representation of the KeyUsage.
@ -327,24 +298,6 @@ implements CertAttrSet<String> {
super.encode(out);
}
/**
* Return an enumeration of names of attributes existing within this
* attribute.
*/
public Enumeration<String> getElements() {
AttributeNameEnumeration elements = new AttributeNameEnumeration();
elements.addElement(DIGITAL_SIGNATURE);
elements.addElement(NON_REPUDIATION);
elements.addElement(KEY_ENCIPHERMENT);
elements.addElement(DATA_ENCIPHERMENT);
elements.addElement(KEY_AGREEMENT);
elements.addElement(KEY_CERTSIGN);
elements.addElement(CRL_SIGN);
elements.addElement(ENCIPHER_ONLY);
elements.addElement(DECIPHER_ONLY);
return (elements.elements());
}
public boolean[] getBits() {
@ -354,6 +307,7 @@ implements CertAttrSet<String> {
/**
* Return the name of this attribute.
*/
@Override
public String getName() {
return (NAME);
}

@ -28,7 +28,6 @@ package sun.security.x509;
import java.io.IOException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.*;
import javax.security.auth.x500.X500Principal;
@ -282,36 +281,12 @@ implements CertAttrSet<String>, Cloneable {
}
}
/**
* Delete the attribute value.
*/
public void delete(String name) throws IOException {
if (name.equalsIgnoreCase(PERMITTED_SUBTREES)) {
permitted = null;
} else if (name.equalsIgnoreCase(EXCLUDED_SUBTREES)) {
excluded = null;
} else {
throw new IOException("Attribute name not recognized by " +
"CertAttrSet:NameConstraintsExtension.");
}
encodeThis();
}
/**
* Return an enumeration of names of attributes existing within this
* attribute.
*/
public Enumeration<String> getElements() {
AttributeNameEnumeration elements = new AttributeNameEnumeration();
elements.addElement(PERMITTED_SUBTREES);
elements.addElement(EXCLUDED_SUBTREES);
return (elements.elements());
}
/**
* Return the name of this attribute.
*/
@Override
public String getName() {
return (NAME);
}

@ -215,13 +215,6 @@ implements CertAttrSet<String> {
return Boolean.valueOf(isSet(getPosition(name)));
}
/**
* Delete the attribute value.
*/
public void delete(String name) throws IOException {
set(getPosition(name), false);
encodeThis();
}
/**
* Returns a printable representation of the NetscapeCertType.
@ -273,17 +266,11 @@ implements CertAttrSet<String> {
super.encode(out);
}
/**
* Return an enumeration of names of attributes existing within this
* attribute.
*/
public Enumeration<String> getElements() {
return mAttributeNames.elements();
}
/**
* Return the name of this attribute.
*/
@Override
public String getName() {
return (NAME);
}

@ -26,7 +26,6 @@
package sun.security.x509;
import java.io.IOException;
import java.util.Enumeration;
/**
* Represent the OCSP NoCheck Extension from RFC2560.
@ -104,25 +103,12 @@ public class OCSPNoCheckExtension extends Extension
"CertAttrSet:OCSPNoCheckExtension.");
}
/**
* Delete the attribute value.
*/
public void delete(String name) throws IOException {
throw new IOException("No attribute is allowed by " +
"CertAttrSet:OCSPNoCheckExtension.");
}
/**
* Return an enumeration of names of attributes existing within this
* attribute.
*/
public Enumeration<String> getElements() {
return (new AttributeNameEnumeration()).elements();
}
/**
* Return the name of this attribute.
*/
@Override
public String getName() {
return NAME;
}

@ -26,7 +26,6 @@
package sun.security.x509;
import java.io.IOException;
import java.util.Enumeration;
import sun.security.util.*;
@ -243,36 +242,12 @@ implements CertAttrSet<String> {
}
}
/**
* Delete the attribute value.
*/
public void delete(String name) throws IOException {
if (name.equalsIgnoreCase(REQUIRE)) {
require = -1;
} else if (name.equalsIgnoreCase(INHIBIT)) {
inhibit = -1;
} else {
throw new IOException("Attribute name not recognized by " +
"CertAttrSet:PolicyConstraints.");
}
encodeThis();
}
/**
* Return an enumeration of names of attributes existing within this
* attribute.
*/
public Enumeration<String> getElements() {
AttributeNameEnumeration elements = new AttributeNameEnumeration();
elements.addElement(REQUIRE);
elements.addElement(INHIBIT);
return (elements.elements());
}
/**
* Return the name of this attribute.
*/
@Override
public String getName() {
return (NAME);
}

@ -28,7 +28,6 @@ package sun.security.x509;
import java.io.IOException;
import java.security.cert.PolicyQualifierInfo;
import java.util.Collections;
import java.util.Enumeration;
import java.util.LinkedHashSet;
import java.util.Set;
@ -215,41 +214,6 @@ public class PolicyInformation {
}
}
/**
* Delete the attribute value.
*/
public void delete(String name) throws IOException {
if (name.equalsIgnoreCase(QUALIFIERS)) {
policyQualifiers = Collections.emptySet();
} else if (name.equalsIgnoreCase(ID)) {
throw new IOException("Attribute ID may not be deleted from " +
"PolicyInformation.");
} else {
//ID may not be deleted
throw new IOException("Attribute name [" + name +
"] not recognized by PolicyInformation.");
}
}
/**
* Return an enumeration of names of attributes existing within this
* attribute.
*/
public Enumeration<String> getElements() {
AttributeNameEnumeration elements = new AttributeNameEnumeration();
elements.addElement(ID);
elements.addElement(QUALIFIERS);
return elements.elements();
}
/**
* Return the name of this attribute.
*/
public String getName() {
return NAME;
}
/**
* Return a printable representation of the PolicyInformation.
*/

@ -187,33 +187,10 @@ implements CertAttrSet<String> {
}
}
/**
* Delete the attribute value.
*/
public void delete(String name) throws IOException {
if (name.equalsIgnoreCase(MAP)) {
maps = null;
} else {
throw new IOException("Attribute name not recognized by " +
"CertAttrSet:PolicyMappingsExtension.");
}
encodeThis();
}
/**
* Return an enumeration of names of attributes existing within this
* attribute.
*/
public Enumeration<String> getElements () {
AttributeNameEnumeration elements = new AttributeNameEnumeration();
elements.addElement(MAP);
return elements.elements();
}
/**
* Return the name of this attribute.
*/
@Override
public String getName () {
return (NAME);
}

@ -31,7 +31,6 @@ import java.security.cert.CertificateParsingException;
import java.security.cert.CertificateExpiredException;
import java.security.cert.CertificateNotYetValidException;
import java.util.Date;
import java.util.Enumeration;
import java.util.Objects;
import sun.security.util.*;
@ -284,37 +283,12 @@ implements CertAttrSet<String> {
}
}
/**
* Delete the attribute value.
* @exception CertificateException on attribute handling errors.
*/
public void delete(String name) throws CertificateException, IOException {
if (name.equalsIgnoreCase(NOT_BEFORE)) {
notBefore = null;
} else if (name.equalsIgnoreCase(NOT_AFTER)) {
notAfter = null;
} else {
throw new CertificateException("Attribute name not recognized by"
+ " CertAttrSet:PrivateKeyUsage.");
}
encodeThis();
}
/**
* Return an enumeration of names of attributes existing within this
* attribute.
*/
public Enumeration<String> getElements() {
AttributeNameEnumeration elements = new AttributeNameEnumeration();
elements.addElement(NOT_BEFORE);
elements.addElement(NOT_AFTER);
return(elements.elements());
}
/**
* Return the name of this attribute.
*/
@Override
public String getName() {
return(NAME);
}

@ -26,7 +26,6 @@
package sun.security.x509;
import java.io.IOException;
import java.util.Enumeration;
import sun.security.util.BitArray;
import sun.security.util.DerInputStream;
@ -190,13 +189,6 @@ public class ReasonFlags {
return Boolean.valueOf(isSet(name2Index(name)));
}
/**
* Delete the attribute value.
*/
public void delete(String name) throws IOException {
set(name, Boolean.FALSE);
}
/**
* Returns a printable representation of the ReasonFlags.
*/
@ -244,16 +236,4 @@ public class ReasonFlags {
public void encode(DerOutputStream out) throws IOException {
out.putTruncatedUnalignedBitString(new BitArray(this.bitString));
}
/**
* Return an enumeration of names of attributes existing within this
* attribute.
*/
public Enumeration<String> getElements () {
AttributeNameEnumeration elements = new AttributeNameEnumeration();
for( int i=0; i<NAMES.length; i++ ) {
elements.addElement(NAMES[i]);
}
return (elements.elements());
}
}

@ -26,7 +26,6 @@
package sun.security.x509;
import java.io.IOException;
import java.util.Enumeration;
import sun.security.util.*;
@ -202,33 +201,12 @@ implements CertAttrSet<String> {
}
}
/**
* Delete the attribute value.
*/
public void delete(String name) throws IOException {
if (name.equalsIgnoreCase(SUBJECT_NAME)) {
names = null;
} else {
throw new IOException("Attribute name not recognized by " +
"CertAttrSet:SubjectAlternativeName.");
}
encodeThis();
}
/**
* Return an enumeration of names of attributes existing within this
* attribute.
*/
public Enumeration<String> getElements() {
AttributeNameEnumeration elements = new AttributeNameEnumeration();
elements.addElement(SUBJECT_NAME);
return (elements.elements());
}
/**
* Return the name of this attribute.
*/
@Override
public String getName() {
return (NAME);
}

@ -27,7 +27,6 @@ package sun.security.x509;
import java.io.IOException;
import java.util.Collections;
import java.util.*;
import sun.security.util.DerOutputStream;
@ -143,6 +142,7 @@ public class SubjectInfoAccessExtension extends Extension
/**
* Return the name of this attribute.
*/
@Override
public String getName() {
return NAME;
}
@ -194,30 +194,7 @@ public class SubjectInfoAccessExtension extends Extension
}
}
/**
* Delete the attribute value.
*/
public void delete(String name) throws IOException {
if (name.equalsIgnoreCase(DESCRIPTIONS)) {
accessDescriptions =
Collections.emptyList();
} else {
throw new IOException("Attribute name [" + name +
"] not recognized by " +
"CertAttrSet:SubjectInfoAccessExtension.");
}
encodeThis();
}
/**
* Return an enumeration of names of attributes existing within this
* attribute.
*/
public Enumeration<String> getElements() {
AttributeNameEnumeration elements = new AttributeNameEnumeration();
elements.addElement(DESCRIPTIONS);
return elements.elements();
}
// Encode this extension value
private void encodeThis() throws IOException {

@ -26,7 +26,6 @@
package sun.security.x509;
import java.io.IOException;
import java.util.Enumeration;
import sun.security.util.*;
@ -163,33 +162,12 @@ implements CertAttrSet<String> {
}
}
/**
* Delete the attribute value.
*/
public void delete(String name) throws IOException {
if (name.equalsIgnoreCase(KEY_ID)) {
id = null;
} else {
throw new IOException("Attribute name not recognized by " +
"CertAttrSet:SubjectKeyIdentifierExtension.");
}
encodeThis();
}
/**
* Return an enumeration of names of attributes existing within this
* attribute.
*/
public Enumeration<String> getElements() {
AttributeNameEnumeration elements = new AttributeNameEnumeration();
elements.addElement(KEY_ID);
return (elements.elements());
}
/**
* Return the name of this attribute.
*/
@Override
public String getName() {
return (NAME);
}

@ -713,69 +713,6 @@ public class X509CertImpl extends X509Certificate implements DerEncoder {
}
}
/**
* Delete the requested attribute from the certificate.
*
* @param name the name of the attribute.
* @exception CertificateException on invalid attribute identifier.
* @exception IOException on other errors.
*/
public void delete(String name)
throws CertificateException, IOException {
// check if immutable
if (readOnly)
throw new CertificateException("cannot over-write existing"
+ " certificate");
X509AttributeName attr = new X509AttributeName(name);
String id = attr.getPrefix();
if (!(id.equalsIgnoreCase(NAME))) {
throw new CertificateException("Invalid root of attribute name,"
+ " expected ["
+ NAME + "], received " + id);
}
attr = new X509AttributeName(attr.getSuffix());
id = attr.getPrefix();
if (id.equalsIgnoreCase(INFO)) {
if (attr.getSuffix() == null) {
info = null;
} else {
info.delete(attr.getSuffix());
}
} else if (id.equalsIgnoreCase(ALG_ID)) {
algId = null;
} else if (id.equalsIgnoreCase(SIGNATURE)) {
signature = null;
} else if (id.equalsIgnoreCase(SIGNED_CERT)) {
signedCert = null;
} else {
throw new CertificateException("Attribute name not recognized or " +
"delete() not allowed for the same: " + id);
}
}
/**
* Return an enumeration of names of attributes existing within this
* attribute.
*/
public Enumeration<String> getElements() {
AttributeNameEnumeration elements = new AttributeNameEnumeration();
elements.addElement(NAME + DOT + INFO);
elements.addElement(NAME + DOT + ALG_ID);
elements.addElement(NAME + DOT + SIGNATURE);
elements.addElement(NAME + DOT + SIGNED_CERT);
return elements.elements();
}
/**
* Return the name of this attribute.
*/
public String getName() {
return(NAME);
}
/**
* Returns a printable representation of the certificate. This does not
* contain all the information available to distinguish this from any

@ -189,33 +189,6 @@ public class X509CertInfo implements CertAttrSet<String> {
}
}
/**
* Return an enumeration of names of attributes existing within this
* attribute.
*/
public Enumeration<String> getElements() {
AttributeNameEnumeration elements = new AttributeNameEnumeration();
elements.addElement(VERSION);
elements.addElement(SERIAL_NUMBER);
elements.addElement(ALGORITHM_ID);
elements.addElement(ISSUER);
elements.addElement(VALIDITY);
elements.addElement(SUBJECT);
elements.addElement(KEY);
elements.addElement(ISSUER_ID);
elements.addElement(SUBJECT_ID);
elements.addElement(EXTENSIONS);
return elements.elements();
}
/**
* Return the name of this attribute.
*/
public String getName() {
return(NAME);
}
/**
* Returns the encoded certificate info.
*
@ -448,84 +421,6 @@ public class X509CertInfo implements CertAttrSet<String> {
}
}
/**
* Delete the certificate attribute.
*
* @param name the name of the Certificate attribute.
* @exception CertificateException on invalid attributes.
* @exception IOException on other errors.
*/
public void delete(String name)
throws CertificateException, IOException {
X509AttributeName attrName = new X509AttributeName(name);
int attr = attributeMap(attrName.getPrefix());
if (attr == 0) {
throw new CertificateException("Attribute name not recognized: "
+ name);
}
// set rawCertInfo to null, so that we are forced to re-encode
rawCertInfo = null;
String suffix = attrName.getSuffix();
switch (attr) {
case ATTR_VERSION:
if (suffix == null) {
version = null;
} else {
version.delete(suffix);
}
break;
case (ATTR_SERIAL):
if (suffix == null) {
serialNum = null;
} else {
serialNum.delete(suffix);
}
break;
case (ATTR_ALGORITHM):
if (suffix == null) {
algId = null;
} else {
algId.delete(suffix);
}
break;
case (ATTR_ISSUER):
issuer = null;
break;
case (ATTR_VALIDITY):
if (suffix == null) {
interval = null;
} else {
interval.delete(suffix);
}
break;
case (ATTR_SUBJECT):
subject = null;
break;
case (ATTR_KEY):
if (suffix == null) {
pubKey = null;
} else {
pubKey.delete(suffix);
}
break;
case (ATTR_ISSUER_ID):
issuerUniqueId = null;
break;
case (ATTR_SUBJECT_ID):
subjectUniqueId = null;
break;
case (ATTR_EXTENSIONS):
if (suffix == null) {
extensions = null;
} else {
if (extensions != null)
extensions.delete(suffix);
}
break;
}
}
/**
* Get the certificate attribute.

@ -10,9 +10,8 @@ In JDK1.2 we provide an implementation of X.509 (version 3).
The X509CertImpl class supports the following methods to
manipulate the various attributes of a certificate:
<pre>
Object get(String name)
void set(String name, Object value), and
void delete(String name)
Object get(String name), and
void set(String name, Object value)
</pre>
A list of all the X.509 v3 Certificate attributes that can be manipulated
is provided in the following table.

@ -1,45 +0,0 @@
/*
* Copyright (c) 2022, Red Hat, Inc.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 8283082
* @modules java.base/sun.security.x509
* @summary This test is to confirm that
* sun.security.x509.X509CertImpl.delete("x509.info.validity") doesn't
* null out info field as reported by bug 8283082
*/
import sun.security.x509.X500Name;
import sun.security.x509.X509CertImpl;
import sun.security.x509.X509CertInfo;
public class JDK8283082{
public static void main(String[] args) throws Exception {
var c = new X509CertImpl();
c.set("x509.info", new X509CertInfo());
c.set("x509.info.issuer", new X500Name("CN=one"));
c.delete("x509.info.issuer");
c.set("x509.info.issuer", new X500Name("CN=two"));
}
}