Search in sources :

Example 1 with ASN1Sequence

use of com.unboundid.asn1.ASN1Sequence in project X-Road by nordic-institute.

the class AsicContainerVerifier method getTimeStampToken.

private TimeStampToken getTimeStampToken() throws Exception {
    String timestampDerBase64 = asic.getEntryAsString(ENTRY_TIMESTAMP);
    byte[] tsDerDecoded = decodeBase64(timestampDerBase64);
    return new TimeStampToken(new ContentInfo((ASN1Sequence) ASN1Sequence.fromByteArray(tsDerDecoded)));
}
Also used : ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) ContentInfo(org.bouncycastle.asn1.cms.ContentInfo) TimeStampToken(org.bouncycastle.tsp.TimeStampToken)

Example 2 with ASN1Sequence

use of com.unboundid.asn1.ASN1Sequence in project X-Road by nordic-institute.

the class TimestampVerifierTest method getTimestampFromFile.

private static TimeStampToken getTimestampFromFile(String fileName) throws Exception {
    byte[] data = getBytesFromFile(fileName);
    TimeStampToken token = new TimeStampToken(new ContentInfo((ASN1Sequence) ASN1Sequence.fromByteArray(data)));
    assertNotNull(token);
    return token;
}
Also used : ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) ContentInfo(org.bouncycastle.asn1.cms.ContentInfo) TimeStampToken(org.bouncycastle.tsp.TimeStampToken)

Example 3 with ASN1Sequence

use of com.unboundid.asn1.ASN1Sequence in project sshj by hierynomus.

the class DSAPrivateKeyInfoKeyPairConverter method getDsaParameters.

private DSAParameters getDsaParameters(final AlgorithmIdentifier algorithmIdentifier) {
    final ASN1Sequence sequence = ASN1Sequence.getInstance(algorithmIdentifier.getParameters());
    final ASN1Integer p = ASN1Integer.getInstance(sequence.getObjectAt(P_INDEX));
    final ASN1Integer q = ASN1Integer.getInstance(sequence.getObjectAt(Q_INDEX));
    final ASN1Integer g = ASN1Integer.getInstance(sequence.getObjectAt(G_INDEX));
    return new DSAParameters(p.getValue(), q.getValue(), g.getValue());
}
Also used : ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) ASN1Integer(org.bouncycastle.asn1.ASN1Integer) DSAParameters(org.bouncycastle.crypto.params.DSAParameters)

Example 4 with ASN1Sequence

use of com.unboundid.asn1.ASN1Sequence in project ldapsdk by pingidentity.

the class Filter method encode.

/**
 * Encodes this search filter to an ASN.1 element suitable for inclusion in an
 * LDAP search request protocol op.
 *
 * @return  An ASN.1 element containing the encoded search filter.
 */
@NotNull()
public ASN1Element encode() {
    switch(filterType) {
        case FILTER_TYPE_AND:
        case FILTER_TYPE_OR:
            final ASN1Element[] filterElements = new ASN1Element[filterComps.length];
            for (int i = 0; i < filterComps.length; i++) {
                filterElements[i] = filterComps[i].encode();
            }
            return new ASN1Set(filterType, filterElements);
        case FILTER_TYPE_NOT:
            return new ASN1Element(filterType, notComp.encode().encode());
        case FILTER_TYPE_EQUALITY:
        case FILTER_TYPE_GREATER_OR_EQUAL:
        case FILTER_TYPE_LESS_OR_EQUAL:
        case FILTER_TYPE_APPROXIMATE_MATCH:
            final ASN1OctetString[] attrValueAssertionElements = { new ASN1OctetString(attrName), assertionValue };
            return new ASN1Sequence(filterType, attrValueAssertionElements);
        case FILTER_TYPE_SUBSTRING:
            final ArrayList<ASN1OctetString> subList = new ArrayList<>(2 + subAny.length);
            if (subInitial != null) {
                subList.add(new ASN1OctetString(SUBSTRING_TYPE_SUBINITIAL, subInitial.getValue()));
            }
            for (final ASN1Element subAnyElement : subAny) {
                subList.add(new ASN1OctetString(SUBSTRING_TYPE_SUBANY, subAnyElement.getValue()));
            }
            if (subFinal != null) {
                subList.add(new ASN1OctetString(SUBSTRING_TYPE_SUBFINAL, subFinal.getValue()));
            }
            final ASN1Element[] subFilterElements = { new ASN1OctetString(attrName), new ASN1Sequence(subList) };
            return new ASN1Sequence(filterType, subFilterElements);
        case FILTER_TYPE_PRESENCE:
            return new ASN1OctetString(filterType, attrName);
        case FILTER_TYPE_EXTENSIBLE_MATCH:
            final ArrayList<ASN1Element> emElementList = new ArrayList<>(4);
            if (matchingRuleID != null) {
                emElementList.add(new ASN1OctetString(EXTENSIBLE_TYPE_MATCHING_RULE_ID, matchingRuleID));
            }
            if (attrName != null) {
                emElementList.add(new ASN1OctetString(EXTENSIBLE_TYPE_ATTRIBUTE_NAME, attrName));
            }
            emElementList.add(new ASN1OctetString(EXTENSIBLE_TYPE_MATCH_VALUE, assertionValue.getValue()));
            if (dnAttributes) {
                emElementList.add(new ASN1Boolean(EXTENSIBLE_TYPE_DN_ATTRIBUTES, true));
            }
            return new ASN1Sequence(filterType, emElementList);
        default:
            throw new AssertionError(ERR_FILTER_INVALID_TYPE.get(StaticUtils.toHex(filterType)));
    }
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Set(com.unboundid.asn1.ASN1Set) ASN1Element(com.unboundid.asn1.ASN1Element) ArrayList(java.util.ArrayList) ASN1Boolean(com.unboundid.asn1.ASN1Boolean) NotNull(com.unboundid.util.NotNull)

Example 5 with ASN1Sequence

use of com.unboundid.asn1.ASN1Sequence in project ldapsdk by pingidentity.

the class Control method decode.

/**
 * Decodes the provided ASN.1 sequence as an LDAP control.
 *
 * @param  controlSequence  The ASN.1 sequence to be decoded.
 *
 * @return  The decoded control.
 *
 * @throws  LDAPException  If a problem occurs while attempting to decode the
 *                         provided ASN.1 sequence as an LDAP control.
 */
@NotNull()
public static Control decode(@NotNull final ASN1Sequence controlSequence) throws LDAPException {
    final ASN1Element[] elements = controlSequence.elements();
    if ((elements.length < 1) || (elements.length > 3)) {
        throw new LDAPException(ResultCode.DECODING_ERROR, ERR_CONTROL_DECODE_INVALID_ELEMENT_COUNT.get(elements.length));
    }
    final String oid = ASN1OctetString.decodeAsOctetString(elements[0]).stringValue();
    boolean isCritical = false;
    ASN1OctetString value = null;
    if (elements.length == 2) {
        switch(elements[1].getType()) {
            case ASN1Constants.UNIVERSAL_BOOLEAN_TYPE:
                try {
                    isCritical = ASN1Boolean.decodeAsBoolean(elements[1]).booleanValue();
                } catch (final ASN1Exception ae) {
                    Debug.debugException(ae);
                    throw new LDAPException(ResultCode.DECODING_ERROR, ERR_CONTROL_DECODE_CRITICALITY.get(StaticUtils.getExceptionMessage(ae)), ae);
                }
                break;
            case ASN1Constants.UNIVERSAL_OCTET_STRING_TYPE:
                value = ASN1OctetString.decodeAsOctetString(elements[1]);
                break;
            default:
                throw new LDAPException(ResultCode.DECODING_ERROR, ERR_CONTROL_INVALID_TYPE.get(StaticUtils.toHex(elements[1].getType())));
        }
    } else if (elements.length == 3) {
        try {
            isCritical = ASN1Boolean.decodeAsBoolean(elements[1]).booleanValue();
        } catch (final ASN1Exception ae) {
            Debug.debugException(ae);
            throw new LDAPException(ResultCode.DECODING_ERROR, ERR_CONTROL_DECODE_CRITICALITY.get(StaticUtils.getExceptionMessage(ae)), ae);
        }
        value = ASN1OctetString.decodeAsOctetString(elements[2]);
    }
    return decode(oid, isCritical, value);
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Exception(com.unboundid.asn1.ASN1Exception) ASN1Element(com.unboundid.asn1.ASN1Element) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) NotNull(com.unboundid.util.NotNull)

Aggregations

ASN1Sequence (com.unboundid.asn1.ASN1Sequence)455 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)400 Test (org.testng.annotations.Test)311 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)297 ASN1Element (com.unboundid.asn1.ASN1Element)234 ArrayList (java.util.ArrayList)184 IOException (java.io.IOException)137 NotNull (com.unboundid.util.NotNull)118 ASN1Enumerated (com.unboundid.asn1.ASN1Enumerated)95 ASN1Integer (com.unboundid.asn1.ASN1Integer)95 ASN1Sequence (com.github.zhenwei.core.asn1.ASN1Sequence)85 ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)76 ASN1InputStream (org.bouncycastle.asn1.ASN1InputStream)73 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)69 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)64 ASN1Primitive (org.bouncycastle.asn1.ASN1Primitive)57 ASN1Boolean (com.unboundid.asn1.ASN1Boolean)53 X509Certificate (java.security.cert.X509Certificate)53 Enumeration (java.util.Enumeration)52 BigInteger (java.math.BigInteger)50