Search in sources :

Example 86 with DerOutputStream

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

the class X509CertificatePair method getEncoded.

/**
     * Return the DER encoded form of the certificate pair.
     *
     * @return The encoded form of the certificate pair.
     * @throws CerticateEncodingException If an encoding exception occurs.
     */
public byte[] getEncoded() throws CertificateEncodingException {
    try {
        if (encoded == null) {
            DerOutputStream tmp = new DerOutputStream();
            emit(tmp);
            encoded = tmp.toByteArray();
        }
    } catch (IOException ex) {
        throw new CertificateEncodingException(ex.toString());
    }
    return encoded;
}
Also used : DerOutputStream(sun.security.util.DerOutputStream) CertificateEncodingException(java.security.cert.CertificateEncodingException) IOException(java.io.IOException)

Example 87 with DerOutputStream

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

the class SimpleSigner method main.

public static void main(String[] argv) throws Exception {
    SignerInfo[] signerInfos = new SignerInfo[9];
    SimpleSigner signer1 = new SimpleSigner(null, null, null, null);
    signerInfos[8] = signer1.genSignerInfo(data1);
    signerInfos[7] = signer1.genSignerInfo(new byte[] {});
    signerInfos[6] = signer1.genSignerInfo(data2);
    SimpleSigner signer2 = new SimpleSigner(null, null, null, null);
    signerInfos[5] = signer2.genSignerInfo(data1);
    signerInfos[4] = signer2.genSignerInfo(new byte[] {});
    signerInfos[3] = signer2.genSignerInfo(data2);
    SimpleSigner signer3 = new SimpleSigner(null, null, null, null);
    signerInfos[2] = signer3.genSignerInfo(data1);
    signerInfos[1] = signer3.genSignerInfo(new byte[] {});
    signerInfos[0] = signer3.genSignerInfo(data2);
    ContentInfo contentInfo = new ContentInfo(data1);
    AlgorithmId[] algIds = { new AlgorithmId(AlgorithmId.SHA256_oid) };
    X509Certificate[] certs = { signer3.getCert(), signer2.getCert(), signer1.getCert() };
    PKCS7 pkcs71 = new PKCS7(algIds, contentInfo, certs, signerInfos);
    System.out.println("SignerInfos in original.");
    printSignerInfos(pkcs71.getSignerInfos());
    DerOutputStream out = new DerOutputStream();
    pkcs71.encodeSignedData(out);
    PKCS7 pkcs72 = new PKCS7(out.toByteArray());
    System.out.println("\nSignerInfos read back in:");
    printSignerInfos(pkcs72.getSignerInfos());
    System.out.println("Verified signers of original:");
    SignerInfo[] verifs1 = pkcs71.verify();
    System.out.println("Verified signers of after read-in:");
    SignerInfo[] verifs2 = pkcs72.verify();
    if (verifs1.length != verifs2.length) {
        throw new RuntimeException("Length or Original vs read-in " + "should be same");
    }
}
Also used : SignerInfo(sun.security.pkcs.SignerInfo) ContentInfo(sun.security.pkcs.ContentInfo) CertificateAlgorithmId(sun.security.x509.CertificateAlgorithmId) AlgorithmId(sun.security.x509.AlgorithmId) DerOutputStream(sun.security.util.DerOutputStream) PKCS7(sun.security.pkcs.PKCS7) X509Certificate(java.security.cert.X509Certificate)

Example 88 with DerOutputStream

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

the class NamedBitList method main.

public static void main(String[] args) throws Exception {
    boolean[] bb = (new boolean[] { true, false, true, false, false, false });
    GeneralNames gns = new GeneralNames();
    gns.add(new GeneralName(new DNSName("dns")));
    DerOutputStream out;
    // length should be 5 since only {T,F,T} should be encoded
    KeyUsageExtension x1 = new KeyUsageExtension(bb);
    check(new DerValue(x1.getExtensionValue()).getUnalignedBitString().length(), 3);
    NetscapeCertTypeExtension x2 = new NetscapeCertTypeExtension(bb);
    check(new DerValue(x2.getExtensionValue()).getUnalignedBitString().length(), 3);
    ReasonFlags r = new ReasonFlags(bb);
    out = new DerOutputStream();
    r.encode(out);
    check(new DerValue(out.toByteArray()).getUnalignedBitString().length(), 3);
    // Read sun.security.x509.DistributionPoint for ASN.1 definition
    DistributionPoint dp = new DistributionPoint(gns, bb, gns);
    out = new DerOutputStream();
    dp.encode(out);
    DerValue v = new DerValue(out.toByteArray());
    // skip distributionPoint
    v.data.getDerValue();
    // read reasons
    DerValue v2 = v.data.getDerValue();
    // reset to BitString since it's context-specfic[1] encoded
    v2.resetTag(DerValue.tag_BitString);
    // length should be 5 since only {T,F,T} should be encoded
    check(v2.getUnalignedBitString().length(), 3);
    BitArray ba;
    ba = new BitArray(new boolean[] { false, false, false });
    check(ba.length(), 3);
    ba = ba.truncate();
    check(ba.length(), 1);
    ba = new BitArray(new boolean[] { true, true, true, true, true, true, true, true, false, false });
    check(ba.length(), 10);
    check(ba.toByteArray().length, 2);
    ba = ba.truncate();
    check(ba.length(), 8);
    check(ba.toByteArray().length, 1);
    ba = new BitArray(new boolean[] { true, true, true, true, true, true, true, true, true, false });
    check(ba.length(), 10);
    check(ba.toByteArray().length, 2);
    ba = ba.truncate();
    check(ba.length(), 9);
    check(ba.toByteArray().length, 2);
}
Also used : GeneralNames(sun.security.x509.GeneralNames) DerOutputStream(sun.security.util.DerOutputStream) ReasonFlags(sun.security.x509.ReasonFlags) DerValue(sun.security.util.DerValue) GeneralName(sun.security.x509.GeneralName) DistributionPoint(sun.security.x509.DistributionPoint) BitArray(sun.security.util.BitArray) DNSName(sun.security.x509.DNSName) NetscapeCertTypeExtension(sun.security.x509.NetscapeCertTypeExtension) KeyUsageExtension(sun.security.x509.KeyUsageExtension)

Example 89 with DerOutputStream

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

the class LocaleInTime method main.

public static void main(String[] args) throws Exception {
    DerOutputStream out = new DerOutputStream();
    out.putUTCTime(new Date());
    DerValue val = new DerValue(out.toByteArray());
    System.out.println(val.getUTCTime());
}
Also used : DerOutputStream(sun.security.util.DerOutputStream) DerValue(sun.security.util.DerValue) Date(java.util.Date)

Example 90 with DerOutputStream

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

the class NegInt method main.

public static void main(String[] args) throws Exception {
    DerOutputStream out;
    out = new DerOutputStream();
    out.putInteger(-128);
    if (out.toByteArray().length != 3) {
        throw new Exception("-128 encode error");
    }
    out = new DerOutputStream();
    out.putInteger(-129);
    if (out.toByteArray().length != 4) {
        throw new Exception("-129 encode error");
    }
}
Also used : DerOutputStream(sun.security.util.DerOutputStream)

Aggregations

DerOutputStream (sun.security.util.DerOutputStream)125 IOException (java.io.IOException)17 DerValue (sun.security.util.DerValue)11 CertificateEncodingException (java.security.cert.CertificateEncodingException)9 CertificateException (java.security.cert.CertificateException)9 X509Certificate (java.security.cert.X509Certificate)9 ObjectIdentifier (sun.security.util.ObjectIdentifier)9 AlgorithmId (sun.security.x509.AlgorithmId)7 KeyStoreException (java.security.KeyStoreException)6 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)6 UnrecoverableEntryException (java.security.UnrecoverableEntryException)6 UnrecoverableKeyException (java.security.UnrecoverableKeyException)6 SecretKey (javax.crypto.SecretKey)6 DestroyFailedException (javax.security.auth.DestroyFailedException)6 ContentInfo (sun.security.pkcs.ContentInfo)6 BitArray (sun.security.util.BitArray)6 Date (java.util.Date)4 PKCS7 (sun.security.pkcs.PKCS7)4 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)3 InvalidKeyException (java.security.InvalidKeyException)3