Search in sources :

Example 41 with DerOutputStream

use of sun.security.util.DerOutputStream in project jdk8u_jdk by JetBrains.

the class Oid method getDER.

/**
     * Returns the full ASN.1 DER encoding for this oid object, which
     * includes the tag and length.
     *
     * @return byte array containing the DER encoding of this oid object.
     * @exception GSSException may be thrown when the oid can't be encoded
     */
public byte[] getDER() throws GSSException {
    if (derEncoding == null) {
        DerOutputStream dout = new DerOutputStream();
        try {
            dout.putOID(oid);
        } catch (IOException e) {
            throw new GSSException(GSSException.FAILURE, e.getMessage());
        }
        derEncoding = dout.toByteArray();
    }
    return derEncoding.clone();
}
Also used : DerOutputStream(sun.security.util.DerOutputStream) IOException(java.io.IOException)

Example 42 with DerOutputStream

use of sun.security.util.DerOutputStream in project jdk8u_jdk by JetBrains.

the class X509CertSelectorTest method testSubjectAltName.

/*
     * Tests matching on the subject alternative name extension contained in the
     * certificate.
     */
private void testSubjectAltName() throws IOException {
    System.out.println("X.509 Certificate Match on subjectAltName");
    // bad match
    X509CertSelector selector = new X509CertSelector();
    GeneralNameInterface dnsName = new DNSName("foo.com");
    DerOutputStream tmp = new DerOutputStream();
    dnsName.encode(tmp);
    selector.addSubjectAlternativeName(2, tmp.toByteArray());
    checkMatch(selector, cert, false);
    // good match
    DerInputStream in = new DerInputStream(cert.getExtensionValue("2.5.29.17"));
    byte[] encoded = in.getOctetString();
    SubjectAlternativeNameExtension ext = new SubjectAlternativeNameExtension(false, encoded);
    GeneralNames names = (GeneralNames) ext.get(SubjectAlternativeNameExtension.SUBJECT_NAME);
    GeneralName name = (GeneralName) names.get(0);
    selector.setSubjectAlternativeNames(null);
    DerOutputStream tmp2 = new DerOutputStream();
    name.getName().encode(tmp2);
    selector.addSubjectAlternativeName(name.getType(), tmp2.toByteArray());
    checkMatch(selector, cert, true);
    // good match 2 (matches at least one)
    selector.setMatchAllSubjectAltNames(false);
    selector.addSubjectAlternativeName(2, "foo.com");
    checkMatch(selector, cert, true);
}
Also used : GeneralNameInterface(sun.security.x509.GeneralNameInterface) GeneralNames(sun.security.x509.GeneralNames) DerOutputStream(sun.security.util.DerOutputStream) SubjectAlternativeNameExtension(sun.security.x509.SubjectAlternativeNameExtension) X509CertSelector(java.security.cert.X509CertSelector) DerInputStream(sun.security.util.DerInputStream) GeneralName(sun.security.x509.GeneralName) DNSName(sun.security.x509.DNSName)

Example 43 with DerOutputStream

use of sun.security.util.DerOutputStream in project jdk8u_jdk by JetBrains.

the class NullX500Name method main.

public static void main(String[] argv) throws Exception {
    X500Name subject;
    String name = "";
    subject = new X500Name(name);
    System.out.println("subject:" + subject.toString());
    System.out.println("getCN:" + subject.getCommonName());
    System.out.println("getC:" + subject.getCountry());
    System.out.println("getL:" + subject.getLocality());
    System.out.println("getST:" + subject.getState());
    System.out.println("getName:" + subject.getName());
    System.out.println("getO:" + subject.getOrganization());
    System.out.println("getOU:" + subject.getOrganizationalUnit());
    System.out.println("getType:" + subject.getType());
    // encode, getEncoded()
    DerOutputStream dos = new DerOutputStream();
    subject.encode(dos);
    byte[] out = dos.toByteArray();
    byte[] enc = subject.getEncoded();
    HexDumpEncoder e = new HexDumpEncoder();
    if (Arrays.equals(out, enc))
        System.out.println("Sucess: out:" + e.encodeBuffer(out));
    else {
        System.out.println("Failed: encode:" + e.encodeBuffer(out));
        System.out.println("getEncoded:" + e.encodeBuffer(enc));
    }
    X500Name x = new X500Name(enc);
    if (x.equals(subject))
        System.out.println("Sucess: X500Name(byte[]):" + x.toString());
    else
        System.out.println("Failed: X500Name(byte[]):" + x.toString());
}
Also used : DerOutputStream(sun.security.util.DerOutputStream) HexDumpEncoder(sun.misc.HexDumpEncoder)

Example 44 with DerOutputStream

use of sun.security.util.DerOutputStream in project jdk8u_jdk by JetBrains.

the class EncryptedPrivateKeyInfo method getEncoded.

/**
     * Returns the ASN.1 encoding of this object.
     * @return the ASN.1 encoding. Returns a new array
     * each time this method is called.
     * @exception IOException if error occurs when constructing its
     * ASN.1 encoding.
     */
public byte[] getEncoded() throws IOException {
    if (this.encoded == null) {
        DerOutputStream out = new DerOutputStream();
        DerOutputStream tmp = new DerOutputStream();
        // encode encryption algorithm
        algid.encode(tmp);
        // encode encrypted data
        tmp.putOctetString(encryptedData);
        // wrap everything into a SEQUENCE
        out.write(DerValue.tag_Sequence, tmp);
        this.encoded = out.toByteArray();
    }
    return this.encoded.clone();
}
Also used : DerOutputStream(sun.security.util.DerOutputStream)

Example 45 with DerOutputStream

use of sun.security.util.DerOutputStream in project j2objc by google.

the class PKCS9Attribute method derEncode.

/**
     * Write the DER encoding of this attribute to an output stream.
     *
     * <P> N.B.: This method always encodes values of
     * ChallengePassword and UnstructuredAddress attributes as ASN.1
     * <code>PrintableString</code>s, without checking whether they
     * should be encoded as <code>T61String</code>s.
     */
public void derEncode(OutputStream out) throws IOException {
    DerOutputStream temp = new DerOutputStream();
    temp.putOID(oid);
    switch(index) {
        case // Unknown
        -1:
            temp.write((byte[]) value);
            break;
        // email address
        case 1:
        case // unstructured name
        2:
            {
                // open scope
                String[] values = (String[]) value;
                DerOutputStream[] temps = new DerOutputStream[values.length];
                for (int i = 0; i < values.length; i++) {
                    temps[i] = new DerOutputStream();
                    temps[i].putIA5String(values[i]);
                }
                temp.putOrderedSetOf(DerValue.tag_Set, temps);
            }
            // close scope
            break;
        case // content type
        3:
            {
                DerOutputStream temp2 = new DerOutputStream();
                temp2.putOID((ObjectIdentifier) value);
                temp.write(DerValue.tag_Set, temp2.toByteArray());
            }
            break;
        case // message digest
        4:
            {
                DerOutputStream temp2 = new DerOutputStream();
                temp2.putOctetString((byte[]) value);
                temp.write(DerValue.tag_Set, temp2.toByteArray());
            }
            break;
        case // signing time
        5:
            {
                DerOutputStream temp2 = new DerOutputStream();
                temp2.putUTCTime((Date) value);
                temp.write(DerValue.tag_Set, temp2.toByteArray());
            }
            break;
        case // countersignature
        6:
            temp.putOrderedSetOf(DerValue.tag_Set, (DerEncoder[]) value);
            break;
        case // challenge password
        7:
            {
                DerOutputStream temp2 = new DerOutputStream();
                temp2.putPrintableString((String) value);
                temp.write(DerValue.tag_Set, temp2.toByteArray());
            }
            break;
        case // unstructured address
        8:
            {
                // open scope
                String[] values = (String[]) value;
                DerOutputStream[] temps = new DerOutputStream[values.length];
                for (int i = 0; i < values.length; i++) {
                    temps[i] = new DerOutputStream();
                    temps[i].putPrintableString(values[i]);
                }
                temp.putOrderedSetOf(DerValue.tag_Set, temps);
            }
            // close scope
            break;
        case // extended-certificate attribute -- not supported
        9:
            throw new IOException("PKCS9 extended-certificate " + "attribute not supported.");
        // break unnecessary
        case // issuerAndserialNumber attribute -- not supported
        10:
            throw new IOException("PKCS9 IssuerAndSerialNumber" + "attribute not supported.");
        // RSA DSI proprietary
        case 11:
        case // RSA DSI proprietary
        12:
            throw new IOException("PKCS9 RSA DSI attributes" + "11 and 12, not supported.");
        // break unnecessary
        case // S/MIME unused attribute
        13:
            throw new IOException("PKCS9 attribute #13 not supported.");
        case // ExtensionRequest
        14:
            {
                DerOutputStream temp2 = new DerOutputStream();
                CertificateExtensions exts = (CertificateExtensions) value;
                try {
                    exts.encode(temp2, true);
                } catch (CertificateException ex) {
                    throw new IOException(ex.toString());
                }
                temp.write(DerValue.tag_Set, temp2.toByteArray());
            }
            break;
        case // SMIMECapability
        15:
            throw new IOException("PKCS9 attribute #15 not supported.");
        case // SigningCertificate
        16:
            throw new IOException("PKCS9 SigningCertificate attribute not supported.");
        case // SignatureTimestampToken
        17:
            temp.write(DerValue.tag_Set, (byte[]) value);
            break;
        // can't happen
        default:
    }
    DerOutputStream derOut = new DerOutputStream();
    derOut.write(DerValue.tag_Sequence, temp.toByteArray());
    out.write(derOut.toByteArray());
}
Also used : DerOutputStream(sun.security.util.DerOutputStream) DerEncoder(sun.security.util.DerEncoder) CertificateExtensions(sun.security.x509.CertificateExtensions) CertificateException(java.security.cert.CertificateException) IOException(java.io.IOException) Date(java.util.Date) ObjectIdentifier(sun.security.util.ObjectIdentifier)

Aggregations

DerOutputStream (sun.security.util.DerOutputStream)79 IOException (java.io.IOException)9 DerValue (sun.security.util.DerValue)8 ObjectIdentifier (sun.security.util.ObjectIdentifier)6 CertificateException (java.security.cert.CertificateException)5 BitArray (sun.security.util.BitArray)5 X509Certificate (java.security.cert.X509Certificate)4 AlgorithmId (sun.security.x509.AlgorithmId)4 KeyStoreException (java.security.KeyStoreException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 UnrecoverableEntryException (java.security.UnrecoverableEntryException)3 UnrecoverableKeyException (java.security.UnrecoverableKeyException)3 CertificateEncodingException (java.security.cert.CertificateEncodingException)3 Date (java.util.Date)3 SecretKey (javax.crypto.SecretKey)3 DestroyFailedException (javax.security.auth.DestroyFailedException)3 ContentInfo (sun.security.pkcs.ContentInfo)3 DerInputStream (sun.security.util.DerInputStream)3 PolicyQualifierInfo (java.security.cert.PolicyQualifierInfo)2 X509CertSelector (java.security.cert.X509CertSelector)2