Search in sources :

Example 1 with DerValue

use of sun.security.util.DerValue in project OpenAM by OpenRock.

the class IssuingDistributionPointExtension method derValueToAVAs.

private static AVA[] derValueToAVAs(DerValue derValue) throws IOException {
    DerInputStream dis = new DerInputStream(derValue.toByteArray());
    DerValue[] avaset = dis.getSet(5);
    AVA[] avas = new AVA[avaset.length];
    for (int i = 0; i < avaset.length; i++) {
        DerValue derval = avaset[i];
        avas[i] = new AVA(derval.data.getOID(), derval.data.getDerValue());
    }
    return avas;
}
Also used : DerValue(sun.security.util.DerValue) DerInputStream(sun.security.util.DerInputStream) AVA(sun.security.x509.AVA)

Example 2 with DerValue

use of sun.security.util.DerValue in project OpenAM by OpenRock.

the class Cert method getTokenFromSubjectAltExt.

private void getTokenFromSubjectAltExt(X509Certificate cert) throws AuthLoginException {
    try {
        X509CertImpl certImpl = new X509CertImpl(cert.getEncoded());
        X509CertInfo cinfo = new X509CertInfo(certImpl.getTBSCertificate());
        CertificateExtensions exts = (CertificateExtensions) cinfo.get(X509CertInfo.EXTENSIONS);
        SubjectAlternativeNameExtension altNameExt = (SubjectAlternativeNameExtension) exts.get(SubjectAlternativeNameExtension.NAME);
        if (altNameExt != null) {
            GeneralNames names = (GeneralNames) altNameExt.get(SubjectAlternativeNameExtension.SUBJECT_NAME);
            GeneralName generalname = null;
            ObjectIdentifier upnoid = new ObjectIdentifier(UPNOID);
            Iterator itr = (Iterator) names.iterator();
            while ((userTokenId == null) && itr.hasNext()) {
                generalname = (GeneralName) itr.next();
                if (generalname != null) {
                    if (amAuthCert_subjectAltExtMapper.equalsIgnoreCase("UPN") && (generalname.getType() == GeneralNameInterface.NAME_ANY)) {
                        OtherName othername = (OtherName) generalname.getName();
                        if (upnoid.equals((Object) (othername.getOID()))) {
                            byte[] nval = othername.getNameValue();
                            DerValue derValue = new DerValue(nval);
                            userTokenId = derValue.getData().getUTF8String();
                        }
                    } else if (amAuthCert_subjectAltExtMapper.equalsIgnoreCase("RFC822Name") && (generalname.getType() == GeneralNameInterface.NAME_RFC822)) {
                        RFC822Name email = (RFC822Name) generalname.getName();
                        userTokenId = email.getName();
                    }
                }
            }
        }
    } catch (Exception e) {
        debug.error("Certificate - " + "Error in getTokenFromSubjectAltExt = ", e);
        throw new AuthLoginException(amAuthCert, "CertNoReg", null);
    }
}
Also used : X509CertInfo(sun.security.x509.X509CertInfo) SubjectAlternativeNameExtension(sun.security.x509.SubjectAlternativeNameExtension) OtherName(sun.security.x509.OtherName) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) CertificateExtensions(sun.security.x509.CertificateExtensions) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) GeneralNames(sun.security.x509.GeneralNames) RFC822Name(sun.security.x509.RFC822Name) X509CertImpl(sun.security.x509.X509CertImpl) DerValue(sun.security.util.DerValue) Iterator(java.util.Iterator) GeneralName(sun.security.x509.GeneralName) ObjectIdentifier(sun.security.util.ObjectIdentifier)

Example 3 with DerValue

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

the class PKCS8Test method main.

public static void main(String[] args) throws IOException, InvalidKeyException {
    BigInteger x = BigInteger.valueOf(1);
    BigInteger p = BigInteger.valueOf(2);
    BigInteger q = BigInteger.valueOf(3);
    BigInteger g = BigInteger.valueOf(4);
    DSAPrivateKey priv = new DSAPrivateKey(x, p, q, g);
    byte[] encodedKey = priv.getEncoded();
    byte[] expectedBytes = new byte[EXPECTED.length];
    for (int i = 0; i < EXPECTED.length; i++) {
        expectedBytes[i] = (byte) EXPECTED[i];
    }
    dumpByteArray("encodedKey :", encodedKey);
    if (!Arrays.equals(encodedKey, expectedBytes)) {
        raiseException(new String(expectedBytes), new String(encodedKey));
    }
    PKCS8Key decodedKey = PKCS8Key.parse(new DerValue(encodedKey));
    String alg = decodedKey.getAlgorithm();
    AlgorithmId algId = decodedKey.getAlgorithmId();
    out.println("Algorithm :" + alg);
    out.println("AlgorithmId: " + algId);
    if (!ALGORITHM.equals(alg)) {
        raiseException(ALGORITHM, alg);
    }
    if (!EXPECTED_ALG_ID_CHRS.equalsIgnoreCase(algId.toString())) {
        raiseException(EXPECTED_ALG_ID_CHRS, algId.toString());
    }
    decodedKey.encode(derOutput);
    dumpByteArray("Stream encode: ", derOutput.toByteArray());
    if (!Arrays.equals(derOutput.toByteArray(), expectedBytes)) {
        raiseException(new String(expectedBytes), derOutput.toString());
    }
    dumpByteArray("byte[] encoding: ", decodedKey.getEncoded());
    if (!Arrays.equals(decodedKey.getEncoded(), expectedBytes)) {
        raiseException(new String(expectedBytes), new String(decodedKey.getEncoded()));
    }
    if (!FORMAT.equals(decodedKey.getFormat())) {
        raiseException(FORMAT, decodedKey.getFormat());
    }
    try {
        byte[] newEncodedKey = new byte[NEW_ENCODED_KEY_INTS.length];
        for (int i = 0; i < newEncodedKey.length; i++) {
            newEncodedKey[i] = (byte) NEW_ENCODED_KEY_INTS[i];
        }
        PKCS8Key newDecodedKey = PKCS8Key.parse(new DerValue(newEncodedKey));
        throw new RuntimeException("key1: Expected an IOException during " + "parsing");
    } catch (IOException e) {
        System.out.println("newEncodedKey: should have excess data due to " + "attributes, which are not supported");
    }
    try {
        byte[] newEncodedKey2 = new byte[NEW_ENCODED_KEY_INTS_2.length];
        for (int i = 0; i < newEncodedKey2.length; i++) {
            newEncodedKey2[i] = (byte) NEW_ENCODED_KEY_INTS_2[i];
        }
        PKCS8Key newDecodedKey2 = PKCS8Key.parse(new DerValue(newEncodedKey2));
        throw new RuntimeException("key2: Expected an IOException during " + "parsing");
    } catch (IOException e) {
        out.println("Key 2: should be illegal version");
        out.println(e.getMessage());
        if (!EXCEPTION_MESSAGE.equals(e.getMessage())) {
            throw new RuntimeException("Key2: expected: " + EXCEPTION_MESSAGE + " get: " + e.getMessage());
        }
    }
}
Also used : PKCS8Key(sun.security.pkcs.PKCS8Key) AlgorithmId(sun.security.x509.AlgorithmId) DerValue(sun.security.util.DerValue) BigInteger(java.math.BigInteger) DSAPrivateKey(sun.security.provider.DSAPrivateKey) IOException(java.io.IOException)

Example 4 with DerValue

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

the class OptionPADataInKDCReq method main.

public static void main(String[] args) throws Exception {
    /*
         * This is a AS-REQ block without padata. The content is --
        [APPLICATION 10] SEQUENCE {
            [1] INTEGER 5
            [2] INTEGER 10
            [4] SEQUENCE {
                [0] BIT STRING 01000000 10000001 00000000 00010000
                [1] SEQUENCE {
                    [0] INTEGER 1
                    [1] SEQUENCE {
                        STRING administrator
                    }
                }
                [2] STRING N3
                [3] SEQUENCE {
                    [0] INTEGER 2
                    [1] SEQUENCE {
                        STRING krbtgt
                        STRING N3
                    }
                }
                [5] TIME Sun Sep 13 10:48:05 CST 2037
                [6] TIME Sun Sep 13 10:48:05 CST 2037
                [7] INTEGER 2101281516
                [8] SEQUENCE {
                    INTEGER 23
                    INTEGER -133
                    INTEGER -128
                    INTEGER 3
                    INTEGER 1
                    INTEGER 24
                    INTEGER -135
                }
                [9] SEQUENCE {
                    SEQUENCE {
                        [0] INTEGER 20
                        [1] OCTET STRING
                            0000: 58 50 20 20 20 20 20 20   20 20 20 20 20 20 20 20  XP
                    }
                }
            }
        }
        */
    byte[] b = { (byte) 0x6a, (byte) 0x81, (byte) 0xbf, (byte) 0x30, (byte) 0x81, (byte) 0xbc, (byte) 0xa1, (byte) 0x03, (byte) 0x02, (byte) 0x01, (byte) 0x05, (byte) 0xa2, (byte) 0x03, (byte) 0x02, (byte) 0x01, (byte) 0x0a, (byte) 0xa4, (byte) 0x81, (byte) 0xaf, (byte) 0x30, (byte) 0x81, (byte) 0xac, (byte) 0xa0, (byte) 0x07, (byte) 0x03, (byte) 0x05, (byte) 0x00, (byte) 0x40, (byte) 0x81, (byte) 0x00, (byte) 0x10, (byte) 0xa1, (byte) 0x1a, (byte) 0x30, (byte) 0x18, (byte) 0xa0, (byte) 0x03, (byte) 0x02, (byte) 0x01, (byte) 0x01, (byte) 0xa1, (byte) 0x11, (byte) 0x30, (byte) 0x0f, (byte) 0x1b, (byte) 0x0d, (byte) 0x61, (byte) 0x64, (byte) 0x6d, (byte) 0x69, (byte) 0x6e, (byte) 0x69, (byte) 0x73, (byte) 0x74, (byte) 0x72, (byte) 0x61, (byte) 0x74, (byte) 0x6f, (byte) 0x72, (byte) 0xa2, (byte) 0x04, (byte) 0x1b, (byte) 0x02, (byte) 0x4e, (byte) 0x33, (byte) 0xa3, (byte) 0x17, (byte) 0x30, (byte) 0x15, (byte) 0xa0, (byte) 0x03, (byte) 0x02, (byte) 0x01, (byte) 0x02, (byte) 0xa1, (byte) 0x0e, (byte) 0x30, (byte) 0x0c, (byte) 0x1b, (byte) 0x06, (byte) 0x6b, (byte) 0x72, (byte) 0x62, (byte) 0x74, (byte) 0x67, (byte) 0x74, (byte) 0x1b, (byte) 0x02, (byte) 0x4e, (byte) 0x33, (byte) 0xa5, (byte) 0x11, (byte) 0x18, (byte) 0x0f, (byte) 0x32, (byte) 0x30, (byte) 0x33, (byte) 0x37, (byte) 0x30, (byte) 0x39, (byte) 0x31, (byte) 0x33, (byte) 0x30, (byte) 0x32, (byte) 0x34, (byte) 0x38, (byte) 0x30, (byte) 0x35, (byte) 0x5a, (byte) 0xa6, (byte) 0x11, (byte) 0x18, (byte) 0x0f, (byte) 0x32, (byte) 0x30, (byte) 0x33, (byte) 0x37, (byte) 0x30, (byte) 0x39, (byte) 0x31, (byte) 0x33, (byte) 0x30, (byte) 0x32, (byte) 0x34, (byte) 0x38, (byte) 0x30, (byte) 0x35, (byte) 0x5a, (byte) 0xa7, (byte) 0x06, (byte) 0x02, (byte) 0x04, (byte) 0x7d, (byte) 0x3f, (byte) 0x02, (byte) 0xec, (byte) 0xa8, (byte) 0x19, (byte) 0x30, (byte) 0x17, (byte) 0x02, (byte) 0x01, (byte) 0x17, (byte) 0x02, (byte) 0x02, (byte) 0xff, (byte) 0x7b, (byte) 0x02, (byte) 0x01, (byte) 0x80, (byte) 0x02, (byte) 0x01, (byte) 0x03, (byte) 0x02, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x01, (byte) 0x18, (byte) 0x02, (byte) 0x02, (byte) 0xff, (byte) 0x79, (byte) 0xa9, (byte) 0x1d, (byte) 0x30, (byte) 0x1b, (byte) 0x30, (byte) 0x19, (byte) 0xa0, (byte) 0x03, (byte) 0x02, (byte) 0x01, (byte) 0x14, (byte) 0xa1, (byte) 0x12, (byte) 0x04, (byte) 0x10, (byte) 0x58, (byte) 0x50, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20 };
    new KDCReq(b, 0x0a);
    /*
         * This is a fake ETYPEINFO2 block with no salt
            SEQUENCE {
                [0] INTEGER 0
                [2] OCTET STRING 0000: 00                                                 .
            }
         */
    byte[] b2 = { (byte) 0x30, (byte) 0x0a, (byte) 0xa0, (byte) 0x03, (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0xa2, (byte) 0x03, (byte) 0x04, (byte) 0x01, (byte) 0x00 };
    ETypeInfo2 e2 = new ETypeInfo2(new DerValue(b2));
    if (e2.getSalt() != null || e2.getParams() == null) {
        throw new Exception("ETypeInfo2 decoding error");
    }
}
Also used : DerValue(sun.security.util.DerValue) ETypeInfo2(sun.security.krb5.internal.ETypeInfo2) KDCReq(sun.security.krb5.internal.KDCReq)

Example 5 with DerValue

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

the class PAData method main.

public static void main(String[] args) throws Exception {
    // This is the dump of a KRB-ERROR data, no sensitive info included.
    byte[] bytes = { (byte) 0X7E, (byte) 0X71, (byte) 0X30, (byte) 0X6F, (byte) 0XA0, (byte) 0X03, (byte) 0X02, (byte) 0X01, (byte) 0X05, (byte) 0XA1, (byte) 0X03, (byte) 0X02, (byte) 0X01, (byte) 0X1E, (byte) 0XA4, (byte) 0X11, (byte) 0X18, (byte) 0X0F, (byte) 0X32, (byte) 0X30, (byte) 0X30, (byte) 0X37, (byte) 0X30, (byte) 0X36, (byte) 0X32, (byte) 0X31, (byte) 0X32, (byte) 0X31, (byte) 0X30, (byte) 0X32, (byte) 0X34, (byte) 0X33, (byte) 0X5A, (byte) 0XA5, (byte) 0X05, (byte) 0X02, (byte) 0X03, (byte) 0X0A, (byte) 0XC8, (byte) 0XC5, (byte) 0XA6, (byte) 0X03, (byte) 0X02, (byte) 0X01, (byte) 0X12, /* The errorcode at bytes[44] */
    (byte) 0XA9, (byte) 0X0A, (byte) 0X1B, (byte) 0X08, (byte) 0X4E, (byte) 0X33, (byte) 0X2E, (byte) 0X4C, (byte) 0X4F, (byte) 0X43, (byte) 0X41, (byte) 0X4C, (byte) 0XAA, (byte) 0X1D, (byte) 0X30, (byte) 0X1B, (byte) 0XA0, (byte) 0X03, (byte) 0X02, (byte) 0X01, (byte) 0X02, (byte) 0XA1, (byte) 0X14, (byte) 0X30, (byte) 0X12, (byte) 0X1B, (byte) 0X06, (byte) 0X6B, (byte) 0X72, (byte) 0X62, (byte) 0X74, (byte) 0X67, (byte) 0X74, (byte) 0X1B, (byte) 0X08, (byte) 0X4E, (byte) 0X33, (byte) 0X2E, (byte) 0X4C, (byte) 0X4F, (byte) 0X43, (byte) 0X41, (byte) 0X4C, (byte) 0XAC, (byte) 0X19, (byte) 0X04, (byte) 0X17, (byte) 0X30, (byte) 0X15, (byte) 0XA1, (byte) 0X03, (byte) 0X02, (byte) 0X01, (byte) 0X03, (byte) 0XA2, (byte) 0X0E, (byte) 0X04, (byte) 0X0C, (byte) 0X72, (byte) 0X00, (byte) 0X00, (byte) 0XC0, (byte) 0X00, (byte) 0X00, (byte) 0X00, (byte) 0X00, (byte) 0X01, (byte) 0X00, (byte) 0X00, (byte) 0X00 };
    String err = "";
    try {
        new KRBError(new DerValue(bytes));
    } catch (Exception e) {
        err += "Test 1 fails.\n";
    }
    try {
        bytes[44] = Krb5.KDC_ERR_PREAUTH_REQUIRED;
        new KRBError(new DerValue(bytes));
        err += "Test 2 fails.\n";
    } catch (Exception e) {
    // correct bahavior
    }
    if (err != "") {
        throw new Exception(err);
    }
}
Also used : KRBError(sun.security.krb5.internal.KRBError) DerValue(sun.security.util.DerValue)

Aggregations

DerValue (sun.security.util.DerValue)76 IOException (java.io.IOException)30 DerInputStream (sun.security.util.DerInputStream)26 ObjectIdentifier (sun.security.util.ObjectIdentifier)17 CertificateException (java.security.cert.CertificateException)14 DerOutputStream (sun.security.util.DerOutputStream)11 BigInteger (java.math.BigInteger)10 KeyStoreException (java.security.KeyStoreException)10 UnrecoverableKeyException (java.security.UnrecoverableKeyException)10 X509Certificate (java.security.cert.X509Certificate)10 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)9 UnrecoverableEntryException (java.security.UnrecoverableEntryException)8 CertificateFactory (java.security.cert.CertificateFactory)8 X500Principal (javax.security.auth.x500.X500Principal)7 DestroyFailedException (javax.security.auth.DestroyFailedException)6 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)5 AlgorithmId (sun.security.x509.AlgorithmId)5 AlgorithmParameters (java.security.AlgorithmParameters)4 KeyFactory (java.security.KeyFactory)4 PrivateKey (java.security.PrivateKey)4