Search in sources :

Example 51 with DerValue

use of org.mozilla.jss.netscape.security.util.DerValue in project jss by dogtagpki.

the class ContentInfo method encode.

public void encode(DerOutputStream out) throws IOException {
    DerOutputStream contentDerCode;
    DerOutputStream seq;
    DerValue taggedContent;
    contentDerCode = new DerOutputStream();
    content.encode(contentDerCode);
    // Add the [0] EXPLICIT tag in front of the content encoding
    taggedContent = new DerValue((byte) 0xA0, contentDerCode.toByteArray());
    seq = new DerOutputStream();
    seq.putOID(contentType);
    seq.putDerValue(taggedContent);
    out.write(DerValue.tag_Sequence, seq);
}
Also used : DerOutputStream(org.mozilla.jss.netscape.security.util.DerOutputStream) DerValue(org.mozilla.jss.netscape.security.util.DerValue)

Example 52 with DerValue

use of org.mozilla.jss.netscape.security.util.DerValue in project jss by dogtagpki.

the class InhibitAnyPolicyExtension method decodeThis.

private void decodeThis() throws IOException {
    DerValue val = new DerValue(this.extensionValue);
    mSkipCerts = val.getInteger();
}
Also used : DerValue(org.mozilla.jss.netscape.security.util.DerValue)

Example 53 with DerValue

use of org.mozilla.jss.netscape.security.util.DerValue in project jss by dogtagpki.

the class CertificateScopeOfUseExtension method decodeThis.

private void decodeThis() throws IOException {
    DerValue val = new DerValue(this.extensionValue);
    if (val.tag != DerValue.tag_Sequence) {
        throw new IOException("Invalid encoding of CertificateWindow extension");
    }
    mEntries = new Vector<>();
    while (val.data.available() != 0) {
        mEntries.addElement(new CertificateScopeEntry(val.data.getDerValue()));
    }
}
Also used : DerValue(org.mozilla.jss.netscape.security.util.DerValue) IOException(java.io.IOException)

Example 54 with DerValue

use of org.mozilla.jss.netscape.security.util.DerValue in project jss by dogtagpki.

the class GenericASN1Extension method encodePattern.

// Encode pattern
private byte[] encodePattern() throws IOException, ParseException {
    DerOutputStream tmp = new DerOutputStream();
    String type = null;
    String value = null;
    String source = null;
    while (index < pattern.length()) {
        char ch = pattern.charAt(index);
        switch(ch) {
            case '{':
                index++;
                byte[] buff = encodePattern();
                tmp.putDerValue(new DerValue(buff));
                break;
            case '}':
                try (DerOutputStream os = new DerOutputStream()) {
                    os.write(DerValue.tag_Sequence, tmp);
                    return os.toByteArray();
                }
            default:
                type = mConfig.get(PROP_ATTRIBUTE + "." + ch + "." + PROP_TYPE);
                if (type.equalsIgnoreCase("integer")) {
                    int num = Integer.parseInt(mConfig.get(PROP_ATTRIBUTE + "." + ch + "." + PROP_VALUE));
                    PutInteger(tmp, num);
                } else if (type.equalsIgnoreCase("ia5string")) {
                    source = mConfig.get(PROP_ATTRIBUTE + "." + ch + "." + PROP_SOURCE);
                    value = mConfig.get(PROP_ATTRIBUTE + "." + ch + "." + PROP_VALUE);
                    if (source.equalsIgnoreCase("file"))
                        PutIA5String(tmp, getFromFile(value));
                    else
                        PutIA5String(tmp, value);
                } else if (type.equalsIgnoreCase("octetstring")) {
                    source = mConfig.get(PROP_ATTRIBUTE + "." + ch + "." + PROP_SOURCE);
                    value = mConfig.get(PROP_ATTRIBUTE + "." + ch + "." + PROP_VALUE);
                    // It should be colon seperated ASCII Hexdecimal String
                    if (source.equalsIgnoreCase("file"))
                        PutOctetString(tmp, getFromFile(value));
                    else
                        PutOctetString(tmp, value);
                } else if (type.equalsIgnoreCase("bmpstring")) {
                    source = mConfig.get(PROP_ATTRIBUTE + "." + ch + "." + PROP_SOURCE);
                    value = mConfig.get(PROP_ATTRIBUTE + "." + ch + "." + PROP_VALUE);
                    if (source.equalsIgnoreCase("file"))
                        PutBMPString(tmp, getFromFile(value));
                    else
                        PutBMPString(tmp, value);
                } else if (type.equalsIgnoreCase("printablestring")) {
                    source = mConfig.get(PROP_ATTRIBUTE + "." + ch + "." + PROP_SOURCE);
                    value = mConfig.get(PROP_ATTRIBUTE + "." + ch + "." + PROP_VALUE);
                    if (source.equalsIgnoreCase("file"))
                        PutPrintableString(tmp, getFromFile(value));
                    else
                        PutPrintableString(tmp, value);
                } else if (type.equalsIgnoreCase("visiblestring")) {
                    source = mConfig.get(PROP_ATTRIBUTE + "." + ch + "." + PROP_SOURCE);
                    value = mConfig.get(PROP_ATTRIBUTE + "." + ch + "." + PROP_VALUE);
                    if (source.equalsIgnoreCase("file"))
                        PutVisibleString(tmp, getFromFile(value));
                    else
                        PutVisibleString(tmp, value);
                } else if (type.equalsIgnoreCase("utctime")) {
                    value = mConfig.get(PROP_ATTRIBUTE + "." + ch + "." + PROP_VALUE);
                    PutUTCtime(tmp, value);
                } else if (type.equalsIgnoreCase("oid")) {
                    value = mConfig.get(PROP_ATTRIBUTE + "." + ch + "." + PROP_VALUE);
                    PutOID(tmp, value);
                } else if (type.equalsIgnoreCase("boolean")) {
                    boolean bool = false;
                    String b = mConfig.get(PROP_ATTRIBUTE + "." + ch + "." + PROP_VALUE);
                    if (b.equalsIgnoreCase("true"))
                        bool = true;
                    else
                        bool = false;
                    PutBoolean(tmp, bool);
                } else if (type.equalsIgnoreCase("null")) {
                    tmp.putNull();
                } else {
                    throw new ParseException("Unknown Attribute Type", 0);
                }
        }
        index++;
    }
    return tmp.toByteArray();
}
Also used : DerOutputStream(org.mozilla.jss.netscape.security.util.DerOutputStream) DerValue(org.mozilla.jss.netscape.security.util.DerValue) ParseException(java.text.ParseException)

Example 55 with DerValue

use of org.mozilla.jss.netscape.security.util.DerValue in project jss by dogtagpki.

the class AuthInfoAccessExtension method decodeThis.

private void decodeThis() throws IOException {
    DerValue val = new DerValue(this.extensionValue);
    if (val.tag != DerValue.tag_Sequence) {
        throw new IOException("Invalid encoding of AuthInfoAccess extension");
    }
    while (val.data.available() != 0) {
        DerValue seq = val.data.getDerValue();
        ObjectIdentifier method = seq.data.getDerValue().getOID();
        GeneralName gn = new GeneralName(seq.data.getDerValue());
        addAccessDescription(method, gn);
    }
}
Also used : DerValue(org.mozilla.jss.netscape.security.util.DerValue) IOException(java.io.IOException) GeneralName(org.mozilla.jss.netscape.security.x509.GeneralName) ObjectIdentifier(org.mozilla.jss.netscape.security.util.ObjectIdentifier)

Aggregations

DerValue (org.mozilla.jss.netscape.security.util.DerValue)70 IOException (java.io.IOException)31 DerInputStream (org.mozilla.jss.netscape.security.util.DerInputStream)20 DerOutputStream (org.mozilla.jss.netscape.security.util.DerOutputStream)8 ObjectIdentifier (org.mozilla.jss.netscape.security.util.ObjectIdentifier)8 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 ByteBuffer (java.nio.ByteBuffer)4 CharBuffer (java.nio.CharBuffer)4 CharacterCodingException (java.nio.charset.CharacterCodingException)4 CharsetEncoder (java.nio.charset.CharsetEncoder)4 MessageDigest (java.security.MessageDigest)4 CRLException (java.security.cert.CRLException)4 BitArray (org.mozilla.jss.netscape.security.util.BitArray)4 AuthorityKeyIdentifierExtension (org.mozilla.jss.netscape.security.x509.AuthorityKeyIdentifierExtension)4 KeyIdentifier (org.mozilla.jss.netscape.security.x509.KeyIdentifier)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 InvalidKeyException (java.security.InvalidKeyException)3 BigInt (org.mozilla.jss.netscape.security.util.BigInt)3 GeneralName (org.mozilla.jss.netscape.security.x509.GeneralName)3 CertificateException (java.security.cert.CertificateException)2