Search in sources :

Example 56 with ObjectIdentifier

use of sun.security.util.ObjectIdentifier in project Payara by payara.

the class GSSUtils method getOID.

/*
     * Return the OID corresponding to an OID represented in DER format as follows: 0x06 -- Tag for
     * OBJECT IDENTIFIER derOID.length -- length in octets of OID DER value of OID -- written as
     * specified byte the DER representation for an ObjectIdentifier.
     */
public static ObjectIdentifier getOID(byte[] derOID) throws IOException {
    DerInputStream dis = new DerInputStream(derOID);
    ObjectIdentifier oid = dis.getOID();
    /*
         * Note: getOID() method call generates an IOException if derOID contains any malformed data
         */
    return oid;
}
Also used : DerInputStream(sun.security.util.DerInputStream) ObjectIdentifier(sun.security.util.ObjectIdentifier)

Example 57 with ObjectIdentifier

use of sun.security.util.ObjectIdentifier in project Payara by payara.

the class GSSUtils method verifyMechOID.

/* verify if exportedName is of object ObjectIdentifier. */
public static boolean verifyMechOID(ObjectIdentifier oid, byte[] externalName) throws IOException {
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "Attempting to verify mechanism independent name");
        _logger.log(Level.FINE, dumpHex(externalName));
    }
    IOException e = new IOException("Invalid Name");
    if (externalName[0] != 0x04)
        throw e;
    if (externalName[1] != 0x01)
        throw e;
    int mechoidlen = ((externalName[2]) << 8) + (externalName[3] & 0xff);
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "Mech OID length = " + mechoidlen);
    }
    if (externalName.length < (4 + mechoidlen + 4))
        throw e;
    /*
         * get the mechanism OID and verify it is the same as oid passed as an argument.
         */
    byte[] deroid = new byte[mechoidlen];
    System.arraycopy(externalName, 4, deroid, 0, mechoidlen);
    ObjectIdentifier oid1 = getOID(deroid);
    if (!oid1.equals(oid))
        return false;
    else
        return true;
}
Also used : IOException(java.io.IOException) ObjectIdentifier(sun.security.util.ObjectIdentifier)

Example 58 with ObjectIdentifier

use of sun.security.util.ObjectIdentifier in project Bytecoder by mirkosertic.

the class CertificateRevokedException method readObject.

/**
 * Deserialize the {@code CertificateRevokedException} instance.
 */
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
    // Read in the non-transient fields
    // (revocationDate, reason, authority)
    ois.defaultReadObject();
    // Defensively copy the revocation date
    revocationDate = new Date(revocationDate.getTime());
    // Read in the size (number of mappings) of the extensions map
    // and create the extensions map
    int size = ois.readInt();
    if (size == 0) {
        extensions = Collections.emptyMap();
    } else {
        extensions = new HashMap<>(size);
    }
    // Read in the extensions and put the mappings in the extensions map
    for (int i = 0; i < size; i++) {
        String oid = (String) ois.readObject();
        boolean critical = ois.readBoolean();
        int length = ois.readInt();
        byte[] extVal = new byte[length];
        ois.readFully(extVal);
        Extension ext = sun.security.x509.Extension.newExtension(new ObjectIdentifier(oid), critical, extVal);
        extensions.put(oid, ext);
    }
}
Also used : InvalidityDateExtension(sun.security.x509.InvalidityDateExtension) Date(java.util.Date) ObjectIdentifier(sun.security.util.ObjectIdentifier)

Example 59 with ObjectIdentifier

use of sun.security.util.ObjectIdentifier in project Bytecoder by mirkosertic.

the class Pair method doPrintCertReq.

private void doPrintCertReq(InputStream in, PrintStream out) throws Exception {
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
    StringBuffer sb = new StringBuffer();
    boolean started = false;
    while (true) {
        String s = reader.readLine();
        if (s == null)
            break;
        if (!started) {
            if (s.startsWith("-----")) {
                started = true;
            }
        } else {
            if (s.startsWith("-----")) {
                break;
            }
            sb.append(s);
        }
    }
    PKCS10 req = new PKCS10(Pem.decode(new String(sb)));
    PublicKey pkey = req.getSubjectPublicKeyInfo();
    out.printf(rb.getString("PKCS.10.with.weak"), req.getSubjectName(), pkey.getFormat(), withWeak(pkey), withWeak(req.getSigAlg()));
    for (PKCS10Attribute attr : req.getAttributes().getAttributes()) {
        ObjectIdentifier oid = attr.getAttributeId();
        if (oid.equals(PKCS9Attribute.EXTENSION_REQUEST_OID)) {
            CertificateExtensions exts = (CertificateExtensions) attr.getAttributeValue();
            if (exts != null) {
                printExtensions(rb.getString("Extension.Request."), exts, out);
            }
        } else {
            out.println("Attribute: " + attr.getAttributeId());
            PKCS9Attribute pkcs9Attr = new PKCS9Attribute(attr.getAttributeId(), attr.getAttributeValue());
            out.print(pkcs9Attr.getName() + ": ");
            Object attrVal = attr.getAttributeValue();
            out.println(attrVal instanceof String[] ? Arrays.toString((String[]) attrVal) : attrVal);
        }
    }
    if (debug) {
        // Just to see more, say, public key length...
        out.println(req);
    }
    checkWeak(rb.getString("the.certificate.request"), req);
}
Also used : PKCS10Attribute(sun.security.pkcs10.PKCS10Attribute) PKCS9Attribute(sun.security.pkcs.PKCS9Attribute) PublicKey(java.security.PublicKey) PKCS10(sun.security.pkcs10.PKCS10) ObjectIdentifier(sun.security.util.ObjectIdentifier)

Example 60 with ObjectIdentifier

use of sun.security.util.ObjectIdentifier in project Bytecoder by mirkosertic.

the class TSRequest method encode.

public byte[] encode() throws IOException {
    DerOutputStream request = new DerOutputStream();
    // encode version
    request.putInteger(version);
    // encode messageImprint
    DerOutputStream messageImprint = new DerOutputStream();
    hashAlgorithmId.encode(messageImprint);
    messageImprint.putOctetString(hashValue);
    request.write(DerValue.tag_Sequence, messageImprint);
    if (policyId != null) {
        request.putOID(new ObjectIdentifier(policyId));
    }
    if (nonce != null) {
        request.putInteger(nonce);
    }
    if (returnCertificate) {
        request.putBoolean(true);
    }
    DerOutputStream out = new DerOutputStream();
    out.write(DerValue.tag_Sequence, request);
    return out.toByteArray();
}
Also used : DerOutputStream(sun.security.util.DerOutputStream) ObjectIdentifier(sun.security.util.ObjectIdentifier)

Aggregations

ObjectIdentifier (sun.security.util.ObjectIdentifier)76 IOException (java.io.IOException)27 DerValue (sun.security.util.DerValue)17 AlgorithmId (sun.security.x509.AlgorithmId)17 DerInputStream (sun.security.util.DerInputStream)16 CertificateException (java.security.cert.CertificateException)14 KeyStoreException (java.security.KeyStoreException)12 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)11 UnrecoverableEntryException (java.security.UnrecoverableEntryException)10 UnrecoverableKeyException (java.security.UnrecoverableKeyException)10 AlgorithmParameters (java.security.AlgorithmParameters)9 X509Certificate (java.security.cert.X509Certificate)9 SecretKey (javax.crypto.SecretKey)9 DerOutputStream (sun.security.util.DerOutputStream)9 ASN1InputStream (com.android.org.bouncycastle.asn1.ASN1InputStream)8 PrivateKeyInfo (com.android.org.bouncycastle.asn1.pkcs.PrivateKeyInfo)8 ByteArrayInputStream (java.io.ByteArrayInputStream)8 Date (java.util.Date)8 DestroyFailedException (javax.security.auth.DestroyFailedException)8 Cipher (javax.crypto.Cipher)7