Search in sources :

Example 16 with ObjectIdentifier

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

the class GSSNameImpl method importName.

private void importName(GSSManagerImpl gssManager, Object appName) throws GSSException {
    int pos = 0;
    byte[] bytes = null;
    if (appName instanceof String) {
        try {
            bytes = ((String) appName).getBytes("UTF-8");
        } catch (UnsupportedEncodingException e) {
        // Won't happen
        }
    } else
        bytes = (byte[]) appName;
    if ((bytes[pos++] != 0x04) || (bytes[pos++] != 0x01))
        throw new GSSExceptionImpl(GSSException.BAD_NAME, "Exported name token id is corrupted!");
    int oidLen = (((0xFF & bytes[pos++]) << 8) | (0xFF & bytes[pos++]));
    ObjectIdentifier temp = null;
    try {
        DerInputStream din = new DerInputStream(bytes, pos, oidLen);
        temp = new ObjectIdentifier(din);
    } catch (IOException e) {
        throw new GSSExceptionImpl(GSSException.BAD_NAME, "Exported name Object identifier is corrupted!");
    }
    Oid oid = new Oid(temp.toString());
    pos += oidLen;
    int mechPortionLen = (((0xFF & bytes[pos++]) << 24) | ((0xFF & bytes[pos++]) << 16) | ((0xFF & bytes[pos++]) << 8) | (0xFF & bytes[pos++]));
    if (mechPortionLen < 0 || pos > bytes.length - mechPortionLen) {
        throw new GSSExceptionImpl(GSSException.BAD_NAME, "Exported name mech name is corrupted!");
    }
    byte[] mechPortion = new byte[mechPortionLen];
    System.arraycopy(bytes, pos, mechPortion, 0, mechPortionLen);
    init(gssManager, mechPortion, NT_EXPORT_NAME, oid);
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) DerInputStream(sun.security.util.DerInputStream) IOException(java.io.IOException) ObjectIdentifier(sun.security.util.ObjectIdentifier)

Example 17 with ObjectIdentifier

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

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<String, Extension>(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 18 with ObjectIdentifier

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

the class GSSUtils method verifyTokenHeader.

/*
     * Verfies the header of a mechanism independent token. The header must be as specified in RFC 2743,
     * section 3.1. The header must contain an object identifier specified by the first parameter. If
     * the header is well formed, then the starting position of the mechanism specific token within the
     * token is returned. If the header is mal formed, then an exception is thrown.
     */
private static int verifyTokenHeader(ObjectIdentifier oid, byte[] token) throws IOException {
    int index = 0;
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "Attempting to verify tokenheader in the mechanism independent token.");
    }
    // verify header
    if (token[index++] != 0x60)
        throw new IOException("Defective Token");
    // derOID length + token length
    int toklen = readDERLength(token, index);
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "Mech OID length + Mech specific length = " + toklen);
    }
    index += getDERLengthSize(toklen);
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "Mechanism OID index : " + index);
    }
    if (token[index] != 0x06)
        throw new IOException("Defective Token");
    byte[] buf = new byte[token.length - index];
    System.arraycopy(token, index, buf, 0, token.length - index);
    ObjectIdentifier mechoid = getOID(buf);
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "Comparing mech OID in token with the expected mech OID");
        _logger.log(Level.FINE, "mech OID: " + dumpHex(getDER(mechoid)));
        _logger.log(Level.FINE, "expected mech OID: " + dumpHex(getDER(oid)));
    }
    if (!mechoid.equals(oid)) {
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, "mech OID in token does not match expected mech OID");
        }
        throw new IOException("Defective token");
    }
    int mechoidlen = getDER(oid).length;
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "Mechanism specific token index : " + index + mechoidlen);
        _logger.log(Level.FINE, "Successfully verified header in the mechanism independent token.");
    }
    // starting position of mech specific token
    return (index + mechoidlen);
}
Also used : IOException(java.io.IOException) ObjectIdentifier(sun.security.util.ObjectIdentifier)

Example 19 with ObjectIdentifier

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

the class GSSUtils method importName.

/*
     * Import the exported name from the mechanism independent exported name.
     */
public static byte[] importName(ObjectIdentifier oid, byte[] externalName) throws IOException {
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "Attempting to import 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))
        throw e;
    int pos = 4 + mechoidlen;
    int namelen = ((externalName[pos]) << 24) + ((externalName[pos + 1]) << 16) + ((externalName[pos + 2]) << 8) + ((externalName[pos + 3]));
    // start of the mechanism specific exported name
    pos += 4;
    if (externalName.length != (4 + mechoidlen + 4 + namelen))
        throw e;
    byte[] name = new byte[externalName.length - pos];
    System.arraycopy(externalName, pos, name, 0, externalName.length - pos);
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "Mechanism specific name:");
        _logger.log(Level.FINE, dumpHex(name));
        _logger.log(Level.FINE, "Successfully imported mechanism independent name");
    }
    return name;
}
Also used : IOException(java.io.IOException) ObjectIdentifier(sun.security.util.ObjectIdentifier)

Example 20 with ObjectIdentifier

use of sun.security.util.ObjectIdentifier in project android_packages_apps_Settings by LineageOS.

the class CredentialStorage method isHardwareBackedKey.

private boolean isHardwareBackedKey(byte[] keyData) {
    try {
        ASN1InputStream bIn = new ASN1InputStream(new ByteArrayInputStream(keyData));
        PrivateKeyInfo pki = PrivateKeyInfo.getInstance(bIn.readObject());
        String algOid = pki.getAlgorithmId().getAlgorithm().getId();
        String algName = new AlgorithmId(new ObjectIdentifier(algOid)).getName();
        return KeyChain.isBoundKeyAlgorithm(algName);
    } catch (IOException e) {
        Log.e(TAG, "Failed to parse key data");
        return false;
    }
}
Also used : ASN1InputStream(com.android.org.bouncycastle.asn1.ASN1InputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) AlgorithmId(sun.security.x509.AlgorithmId) IOException(java.io.IOException) PrivateKeyInfo(com.android.org.bouncycastle.asn1.pkcs.PrivateKeyInfo) 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