Search in sources :

Example 96 with ASN1Encodable

use of com.github.zhenwei.core.asn1.ASN1Encodable in project jmulticard by ctt-gob-es.

the class X509Name method equals.

/**
 * test for equality - note: case is ignored.
 */
public boolean equals(Object obj) {
    if (obj == this) {
        return true;
    }
    if (!(obj instanceof X509Name || obj instanceof ASN1Sequence)) {
        return false;
    }
    ASN1Primitive derO = ((ASN1Encodable) obj).toASN1Primitive();
    if (this.toASN1Primitive().equals(derO)) {
        return true;
    }
    X509Name other;
    try {
        other = X509Name.getInstance(obj);
    } catch (IllegalArgumentException e) {
        return false;
    }
    int orderingSize = ordering.size();
    if (orderingSize != other.ordering.size()) {
        return false;
    }
    boolean[] indexes = new boolean[orderingSize];
    int start, end, delta;
    if (// guess forward
    ordering.elementAt(0).equals(other.ordering.elementAt(0))) {
        start = 0;
        end = orderingSize;
        delta = 1;
    } else // guess reversed - most common problem
    {
        start = orderingSize - 1;
        end = -1;
        delta = -1;
    }
    for (int i = start; i != end; i += delta) {
        boolean found = false;
        ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier) ordering.elementAt(i);
        String value = (String) values.elementAt(i);
        for (int j = 0; j < orderingSize; j++) {
            if (indexes[j]) {
                continue;
            }
            ASN1ObjectIdentifier oOid = (ASN1ObjectIdentifier) other.ordering.elementAt(j);
            if (oid.equals(oOid)) {
                String oValue = (String) other.values.elementAt(j);
                if (equivalentStrings(value, oValue)) {
                    indexes[j] = true;
                    found = true;
                    break;
                }
            }
        }
        if (!found) {
            return false;
        }
    }
    return true;
}
Also used : ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) ASN1UniversalString(org.bouncycastle.asn1.ASN1UniversalString) ASN1String(org.bouncycastle.asn1.ASN1String) ASN1Primitive(org.bouncycastle.asn1.ASN1Primitive) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Example 97 with ASN1Encodable

use of com.github.zhenwei.core.asn1.ASN1Encodable in project jmulticard by ctt-gob-es.

the class DefaultSignatureNameFinder method getAlgorithmName.

/**
 * Return the signature name for the passed in algorithm identifier. For signatures
 * that require parameters, like RSASSA-PSS, this is the best one to use.
 *
 * @param algorithmIdentifier the AlgorithmIdentifier of interest.
 * @return a string representation of the name.
 */
public String getAlgorithmName(AlgorithmIdentifier algorithmIdentifier) {
    ASN1Encodable params = algorithmIdentifier.getParameters();
    if (params != null && !DERNull.INSTANCE.equals(params)) {
        if (algorithmIdentifier.getAlgorithm().equals(PKCSObjectIdentifiers.id_RSASSA_PSS)) {
            RSASSAPSSparams rsaParams = RSASSAPSSparams.getInstance(params);
            AlgorithmIdentifier mgfAlg = rsaParams.getMaskGenAlgorithm();
            if (mgfAlg.getAlgorithm().equals(PKCSObjectIdentifiers.id_mgf1)) {
                AlgorithmIdentifier digAlg = rsaParams.getHashAlgorithm();
                ASN1ObjectIdentifier mgfHashOid = AlgorithmIdentifier.getInstance(mgfAlg.getParameters()).getAlgorithm();
                if (mgfHashOid.equals(digAlg.getAlgorithm())) {
                    return getDigestName(digAlg.getAlgorithm()) + "WITHRSAANDMGF1";
                } else {
                    return getDigestName(digAlg.getAlgorithm()) + "WITHRSAANDMGF1USING" + getDigestName(mgfHashOid);
                }
            }
            return getDigestName(rsaParams.getHashAlgorithm().getAlgorithm()) + "WITHRSAAND" + mgfAlg.getAlgorithm().getId();
        }
    }
    if (oids.containsKey(algorithmIdentifier.getAlgorithm())) {
        return (String) oids.get(algorithmIdentifier.getAlgorithm());
    }
    return algorithmIdentifier.getAlgorithm().getId();
}
Also used : RSASSAPSSparams(org.bouncycastle.asn1.pkcs.RSASSAPSSparams) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier) AlgorithmIdentifier(org.bouncycastle.asn1.x509.AlgorithmIdentifier)

Example 98 with ASN1Encodable

use of com.github.zhenwei.core.asn1.ASN1Encodable in project jmulticard by ctt-gob-es.

the class CMSUtils method getOthersFromStore.

static Collection getOthersFromStore(ASN1ObjectIdentifier otherRevocationInfoFormat, Store otherRevocationInfos) {
    List others = new ArrayList();
    for (Iterator it = otherRevocationInfos.getMatches(null).iterator(); it.hasNext(); ) {
        ASN1Encodable info = (ASN1Encodable) it.next();
        OtherRevocationInfoFormat infoFormat = new OtherRevocationInfoFormat(otherRevocationInfoFormat, info);
        validateInfoFormat(infoFormat);
        others.add(new DERTaggedObject(false, 1, infoFormat));
    }
    return others;
}
Also used : OtherRevocationInfoFormat(org.bouncycastle.asn1.cms.OtherRevocationInfoFormat) DERTaggedObject(org.bouncycastle.asn1.DERTaggedObject) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable)

Example 99 with ASN1Encodable

use of com.github.zhenwei.core.asn1.ASN1Encodable in project jmulticard by ctt-gob-es.

the class CMSUtils method isEquivalent.

static boolean isEquivalent(AlgorithmIdentifier algId1, AlgorithmIdentifier algId2) {
    if (algId1 == null || algId2 == null) {
        return false;
    }
    if (!algId1.getAlgorithm().equals(algId2.getAlgorithm())) {
        return false;
    }
    ASN1Encodable params1 = algId1.getParameters();
    ASN1Encodable params2 = algId2.getParameters();
    if (params1 != null) {
        return params1.equals(params2) || (params1.equals(DERNull.INSTANCE) && params2 == null);
    }
    return params2 == null || params2.equals(DERNull.INSTANCE);
}
Also used : ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable)

Example 100 with ASN1Encodable

use of com.github.zhenwei.core.asn1.ASN1Encodable in project jmulticard by ctt-gob-es.

the class PKCS7ProcessableObject method write.

public void write(OutputStream cOut) throws IOException, CMSException {
    if (structure instanceof ASN1Sequence) {
        ASN1Sequence s = ASN1Sequence.getInstance(structure);
        for (Iterator it = s.iterator(); it.hasNext(); ) {
            ASN1Encodable enc = (ASN1Encodable) it.next();
            cOut.write(enc.toASN1Primitive().getEncoded(ASN1Encoding.DER));
        }
    } else {
        byte[] encoded = structure.toASN1Primitive().getEncoded(ASN1Encoding.DER);
        int index = 1;
        while ((encoded[index] & 0xff) > 127) {
            index++;
        }
        index++;
        cOut.write(encoded, index, encoded.length - index);
    }
}
Also used : ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) Iterator(java.util.Iterator) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable)

Aggregations

ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)209 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)89 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)76 IOException (java.io.IOException)72 ASN1Encodable (com.github.zhenwei.core.asn1.ASN1Encodable)58 ArrayList (java.util.ArrayList)45 DEROctetString (org.bouncycastle.asn1.DEROctetString)43 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)42 DERSequence (org.bouncycastle.asn1.DERSequence)35 BigInteger (java.math.BigInteger)31 ASN1Primitive (org.bouncycastle.asn1.ASN1Primitive)30 DERIA5String (org.bouncycastle.asn1.DERIA5String)30 X509Certificate (java.security.cert.X509Certificate)29 ASN1Integer (org.bouncycastle.asn1.ASN1Integer)29 DERUTF8String (org.bouncycastle.asn1.DERUTF8String)29 GeneralName (org.bouncycastle.asn1.x509.GeneralName)26 List (java.util.List)25 ASN1ObjectIdentifier (com.github.zhenwei.core.asn1.ASN1ObjectIdentifier)24 HashSet (java.util.HashSet)24 ASN1TaggedObject (org.bouncycastle.asn1.ASN1TaggedObject)23