Search in sources :

Example 1 with AttributeType

use of com.intel.mtwilson.tag.selection.xml.AttributeType in project OpenAttestation by OpenAttestation.

the class ProvisionTagCertificate method certificateAttributesEqual.

//    
//    /**
//     * Check that the attributes in the certificate are the same as the attributes in the given selection.
//     * The order is not considered so they do not have to be in the same order.
//     * 
//     * The given selection must have inline attributes (not requiring any lookup by id or name).
//     * 
//     * @return true if the attribute certificate has exactly the same attributes as in the given selection
//     */
protected boolean certificateAttributesEqual(X509AttributeCertificate certificate, SelectionType selection) throws IOException {
    List<Attribute> certAttributes = certificate.getAttribute();
    // initialized with all false, later we mark individual elements true if they are found within the given selection, so that if any are left false at the end we know that there are attributes in the cert that were not in the selection
    boolean[] certAttrMatch = new boolean[certAttributes.size()];
    // for every attribute in the selection, check if it's present in the certificate 
    for (AttributeType xmlAttribute : selection.getAttribute()) {
        X509AttrBuilder.Attribute oidAndValue = Util.toAttributeOidValue(xmlAttribute);
        // look through the certificate for same oid and value
        boolean found = false;
        for (int i = 0; i < certAttrMatch.length; i++) {
            if (Arrays.equals(certAttributes.get(i).getAttrType().getDEREncoded(), oidAndValue.oid.getDEREncoded())) {
                if (Arrays.equals(certAttributes.get(i).getAttributeValues()[0].getDEREncoded(), oidAndValue.value.getDEREncoded())) {
                    certAttrMatch[i] = true;
                    found = true;
                }
            }
        }
        if (!found) {
            log.debug("Certificate does not have attribute oid {} and value {}", Hex.encodeHexString(oidAndValue.oid.getDEREncoded()), Hex.encodeHexString(oidAndValue.value.getDEREncoded()));
            return false;
        }
    }
    // check if the certificate has any attributes that are not in the selection 
    for (int i = 0; i < certAttrMatch.length; i++) {
        if (!certAttrMatch[i]) {
            log.debug("Selection does not have attribute oid {} and value {}", Hex.encodeHexString(certAttributes.get(i).getAttrType().getDEREncoded()), Hex.encodeHexString(certAttributes.get(i).getAttributeValues()[0].getDEREncoded()));
            return false;
        }
    }
    // certificate and selection have same set of attribute (oid,value) pairs
    return true;
}
Also used : Attribute(org.bouncycastle.asn1.x509.Attribute) AttributeType(com.intel.mtwilson.tag.selection.xml.AttributeType) X509AttrBuilder(com.intel.mtwilson.tag.common.X509AttrBuilder)

Example 2 with AttributeType

use of com.intel.mtwilson.tag.selection.xml.AttributeType in project OpenAttestation by OpenAttestation.

the class TagSelectionJsonTest method printSelection.

private void printSelection(SelectionType selection) {
    log.debug("selection id {} name {} notBefore {} notAfter {}", selection.getId(), selection.getName(), selection.getNotBefore(), selection.getNotAfter());
    List<SubjectType> subjectList = selection.getSubject();
    for (SubjectType subject : subjectList) {
        // only one will appear 
        log.debug("subject uuid {} name {} ip {}", (subject.getUuid() == null ? "null" : subject.getUuid().getValue()), (subject.getName() == null ? "null" : subject.getName().getValue()), (subject.getIp() == null ? "null" : subject.getIp().getValue()));
    }
    List<AttributeType> attributeList = selection.getAttribute();
    for (AttributeType attribute : attributeList) {
        log.debug("attribute oid {} text {}", attribute.getOid(), attribute.getText().getValue());
    }
}
Also used : SubjectType(com.intel.mtwilson.tag.selection.xml.SubjectType) AttributeType(com.intel.mtwilson.tag.selection.xml.AttributeType)

Aggregations

AttributeType (com.intel.mtwilson.tag.selection.xml.AttributeType)2 X509AttrBuilder (com.intel.mtwilson.tag.common.X509AttrBuilder)1 SubjectType (com.intel.mtwilson.tag.selection.xml.SubjectType)1 Attribute (org.bouncycastle.asn1.x509.Attribute)1