Resolved an illegal argument with the ASN1UTF8String object in the

componentIdentifier
This commit is contained in:
Cyrus 2024-01-16 13:21:03 -05:00
parent 577f3c7035
commit 331e0f54f7
4 changed files with 33 additions and 31 deletions

View File

@ -1,6 +1,5 @@
package hirs.attestationca.persist.entity.userdefined.certificate.attributes;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
@ -75,10 +74,10 @@ public class ComponentIdentifier {
*/
protected static final int COMPONENT_ADDRESS = 4;
private ASN1UTF8String componentManufacturer;
private ASN1UTF8String componentModel;
private ASN1UTF8String componentSerial;
private ASN1UTF8String componentRevision;
private DERUTF8String componentManufacturer;
private DERUTF8String componentModel;
private DERUTF8String componentSerial;
private DERUTF8String componentRevision;
private ASN1ObjectIdentifier componentManufacturerId;
private ASN1Boolean fieldReplaceable;
private List<ComponentAddress> componentAddress;
@ -88,10 +87,10 @@ public class ComponentIdentifier {
* Default constructor.
*/
public ComponentIdentifier() {
componentManufacturer = ASN1UTF8String.getInstance(NOT_SPECIFIED_COMPONENT);
componentModel = ASN1UTF8String.getInstance(NOT_SPECIFIED_COMPONENT);
componentSerial = ASN1UTF8String.getInstance(EMPTY_COMPONENT);
componentRevision = ASN1UTF8String.getInstance(EMPTY_COMPONENT);
componentManufacturer = new DERUTF8String(NOT_SPECIFIED_COMPONENT);
componentModel = new DERUTF8String(NOT_SPECIFIED_COMPONENT);
componentSerial = new DERUTF8String(EMPTY_COMPONENT);
componentRevision = new DERUTF8String(EMPTY_COMPONENT);
componentManufacturerId = null;
fieldReplaceable = null;
componentAddress = new ArrayList<>();
@ -108,10 +107,10 @@ public class ComponentIdentifier {
* @param fieldReplaceable represents if the component is replaceable
* @param componentAddress represents a list of addresses
*/
public ComponentIdentifier(final ASN1UTF8String componentManufacturer,
final ASN1UTF8String componentModel,
final ASN1UTF8String componentSerial,
final ASN1UTF8String componentRevision,
public ComponentIdentifier(final DERUTF8String componentManufacturer,
final DERUTF8String componentModel,
final DERUTF8String componentSerial,
final DERUTF8String componentRevision,
final ASN1ObjectIdentifier componentManufacturerId,
final ASN1Boolean fieldReplaceable,
final List<ComponentAddress> componentAddress) {
@ -138,18 +137,18 @@ public class ComponentIdentifier {
}
//Mandatory values
componentManufacturer = ASN1UTF8String.getInstance(sequence.getObjectAt(0));
componentModel = ASN1UTF8String.getInstance(sequence.getObjectAt(1));
componentManufacturer = (DERUTF8String) ASN1UTF8String.getInstance(sequence.getObjectAt(0));
componentModel = (DERUTF8String) ASN1UTF8String.getInstance(sequence.getObjectAt(1));
//Continue reading the sequence if it does contain more than 2 values
for (int i = 2; i < sequence.size(); i++) {
ASN1TaggedObject taggedObj = ASN1TaggedObject.getInstance(sequence.getObjectAt(i));
switch (taggedObj.getTagNo()) {
case COMPONENT_SERIAL:
componentSerial = ASN1UTF8String.getInstance(taggedObj, false);
componentSerial = (DERUTF8String) ASN1UTF8String.getInstance(taggedObj, false);
break;
case COMPONENT_REVISION:
componentRevision = ASN1UTF8String.getInstance(taggedObj, false);
componentRevision = (DERUTF8String) ASN1UTF8String.getInstance(taggedObj, false);
break;
case COMPONENT_MANUFACTURER_ID:
componentManufacturerId = ASN1ObjectIdentifier.getInstance(taggedObj, false);

View File

@ -14,6 +14,7 @@ import org.bouncycastle.asn1.ASN1OctetString;
import org.bouncycastle.asn1.ASN1Sequence;
import org.bouncycastle.asn1.ASN1TaggedObject;
import org.bouncycastle.asn1.ASN1UTF8String;
import org.bouncycastle.asn1.DERUTF8String;
import java.util.List;
import java.util.stream.Collectors;
@ -81,10 +82,10 @@ public class ComponentIdentifierV2 extends ComponentIdentifier {
*/
@SuppressWarnings("checkstyle:parameternumber")
public ComponentIdentifierV2(final ComponentClass componentClass,
final ASN1UTF8String componentManufacturer,
final ASN1UTF8String componentModel,
final ASN1UTF8String componentSerial,
final ASN1UTF8String componentRevision,
final DERUTF8String componentManufacturer,
final DERUTF8String componentModel,
final DERUTF8String componentSerial,
final DERUTF8String componentRevision,
final ASN1ObjectIdentifier componentManufacturerId,
final ASN1Boolean fieldReplaceable,
final List<ComponentAddress> componentAddress,
@ -120,18 +121,18 @@ public class ComponentIdentifierV2 extends ComponentIdentifier {
ASN1OctetString.getInstance(componentIdSeq.getObjectAt(tag)).toString());
// Mandatory values
this.setComponentManufacturer(ASN1UTF8String.getInstance(sequence.getObjectAt(tag++)));
this.setComponentModel(ASN1UTF8String.getInstance(sequence.getObjectAt(tag++)));
this.setComponentManufacturer((DERUTF8String) ASN1UTF8String.getInstance(sequence.getObjectAt(tag++)));
this.setComponentModel((DERUTF8String) ASN1UTF8String.getInstance(sequence.getObjectAt(tag++)));
// Continue reading the sequence if it does contain more than 2 values
for (int i = tag; i < sequence.size(); i++) {
ASN1TaggedObject taggedObj = ASN1TaggedObject.getInstance(sequence.getObjectAt(i));
switch (taggedObj.getTagNo()) {
case COMPONENT_SERIAL:
this.setComponentSerial(ASN1UTF8String.getInstance(taggedObj, false));
this.setComponentSerial((DERUTF8String) ASN1UTF8String.getInstance(taggedObj, false));
break;
case COMPONENT_REVISION:
this.setComponentRevision(ASN1UTF8String.getInstance(taggedObj, false));
this.setComponentRevision((DERUTF8String) ASN1UTF8String.getInstance(taggedObj, false));
break;
case COMPONENT_MANUFACTURER_ID:
this.setComponentManufacturerId(ASN1ObjectIdentifier

View File

@ -9,6 +9,7 @@ import hirs.attestationca.persist.entity.userdefined.certificate.attributes.V2.C
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.bouncycastle.asn1.ASN1UTF8String;
import org.bouncycastle.asn1.DERUTF8String;
import java.io.File;
import java.io.FileInputStream;
@ -126,8 +127,8 @@ public final class PciIds {
final String compClassValue = component.getComponentClass().getCategory();
if (compClassValue.equals(COMPCLASS_TCG_CAT_NIC)
|| compClassValue.equals(COMPCLASS_TCG_CAT_GFX)) {
ASN1UTF8String manufacturer = translateVendor(component.getComponentManufacturer());
ASN1UTF8String model = translateDevice(component.getComponentManufacturer(),
DERUTF8String manufacturer = (DERUTF8String) translateVendor(component.getComponentManufacturer());
DERUTF8String model = (DERUTF8String) translateDevice(component.getComponentManufacturer(),
component.getComponentModel());
newComponent = new ComponentIdentifierV2(component.getComponentClass(),

View File

@ -19,6 +19,7 @@ import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.util.Strings;
import org.bouncycastle.asn1.ASN1UTF8String;
import org.bouncycastle.asn1.DERUTF8String;
import java.io.IOException;
import java.math.BigInteger;
@ -725,19 +726,19 @@ public class CertificateAttributeScvValidator extends SupplyChainCredentialValid
final List<ComponentIdentifier> pcComponents = new ArrayList<>();
for (ComponentIdentifier component : untrimmedPcComponents) {
if (component.getComponentManufacturer() != null) {
component.setComponentManufacturer(ASN1UTF8String.getInstance(
component.setComponentManufacturer((DERUTF8String) ASN1UTF8String.getInstance(
component.getComponentManufacturer().getString().trim()));
}
if (component.getComponentModel() != null) {
component.setComponentModel(ASN1UTF8String.getInstance(
component.setComponentModel((DERUTF8String) ASN1UTF8String.getInstance(
component.getComponentModel().getString().trim()));
}
if (component.getComponentSerial() != null) {
component.setComponentSerial(ASN1UTF8String.getInstance(
component.setComponentSerial((DERUTF8String) ASN1UTF8String.getInstance(
component.getComponentSerial().getString().trim()));
}
if (component.getComponentRevision() != null) {
component.setComponentRevision(ASN1UTF8String.getInstance(
component.setComponentRevision((DERUTF8String) ASN1UTF8String.getInstance(
component.getComponentRevision().getString().trim()));
}
pcComponents.add(component);