8296741: Illegal X400Address and EDIPartyName should not be created

Reviewed-by: xuelei, valeriep
This commit is contained in:
Weijun Wang 2022-11-14 14:53:53 +00:00
parent b0edfc1159
commit e1d298c12d
4 changed files with 59 additions and 12 deletions

View file

@ -26,6 +26,8 @@
package sun.security.x509;
import java.io.IOException;
import java.util.Objects;
import sun.security.util.*;
/**
@ -61,7 +63,7 @@ public class EDIPartyName implements GeneralNameInterface {
*/
public EDIPartyName(String assignerName, String partyName) {
this.assigner = assignerName;
this.party = partyName;
this.party = Objects.requireNonNull(partyName);
}
/**
@ -70,7 +72,7 @@ public class EDIPartyName implements GeneralNameInterface {
* @param partyName the name of the EDI party.
*/
public EDIPartyName(String partyName) {
this.party = partyName;
this(null, partyName);
}
/**
@ -106,6 +108,9 @@ public class EDIPartyName implements GeneralNameInterface {
party = opt.getAsString();
}
}
if (party == null) {
throw new IOException("party cannot be missing");
}
}
/**
@ -132,9 +137,6 @@ public class EDIPartyName implements GeneralNameInterface {
tagged.write(DerValue.createTag(DerValue.TAG_CONTEXT,
false, TAG_ASSIGNER), tmp2);
}
if (party == null)
throw new IOException("Cannot have null partyName");
// XXX - shd check is chars fit into PrintableString
tmp.putPrintableString(party);
tagged.write(DerValue.createTag(DerValue.TAG_CONTEXT,

View file

@ -253,7 +253,7 @@ public class GeneralSubtrees implements Cloneable {
newName = new GeneralName(new DNSName(""));
break;
case GeneralNameInterface.NAME_X400:
newName = new GeneralName(new X400Address((byte[])null));
newName = new GeneralName(new X400Address(null));
break;
case GeneralNameInterface.NAME_DIRECTORY:
newName = new GeneralName(new X500Name(""));

View file

@ -335,16 +335,13 @@ import sun.security.util.DerOutputStream;
public class X400Address implements GeneralNameInterface {
// Private data members
byte[] nameValue;
DerValue derValue;
/**
* Create the X400Address object from the specified byte array
*
* @param value value of the name as a byte array
*/
public X400Address(byte[] value) {
nameValue = value;
}
/**
* Create the X400Address object from the passed encoded Der value.
@ -353,7 +350,7 @@ public class X400Address implements GeneralNameInterface {
* @exception IOException on error.
*/
public X400Address(DerValue derValue) throws IOException {
nameValue = derValue.toByteArray();
this.derValue = derValue;
}
/**
@ -369,8 +366,8 @@ public class X400Address implements GeneralNameInterface {
* @param out the DER stream to encode the X400Address to.
* @exception IOException on encoding errors.
*/
@Override
public void encode(DerOutputStream out) throws IOException {
DerValue derValue = new DerValue(nameValue);
out.putDerValue(derValue);
}