Search in sources :

Example 31 with ObjectIdentifier

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

the class X509CertSelector method setExtendedKeyUsage.

/**
 * Sets the extendedKeyUsage criterion. The {@code X509Certificate}
 * must allow the specified key purposes in its extended key usage
 * extension. If {@code keyPurposeSet} is empty or {@code null},
 * no extendedKeyUsage check will be done. Note that an
 * {@code X509Certificate} that has no extendedKeyUsage extension
 * implicitly allows all key purposes.
 * <p>
 * Note that the {@code Set} is cloned to protect against
 * subsequent modifications.
 *
 * @param keyPurposeSet a {@code Set} of key purpose OIDs in string
 * format (or {@code null}). Each OID is represented by a set of
 * nonnegative integers separated by periods.
 * @throws IOException if the OID is invalid, such as
 * the first component being not 0, 1 or 2 or the second component
 * being greater than 39.
 * @see #getExtendedKeyUsage
 */
public void setExtendedKeyUsage(Set<String> keyPurposeSet) throws IOException {
    if ((keyPurposeSet == null) || keyPurposeSet.isEmpty()) {
        this.keyPurposeSet = null;
        keyPurposeOIDSet = null;
    } else {
        this.keyPurposeSet = Collections.unmodifiableSet(new HashSet<>(keyPurposeSet));
        keyPurposeOIDSet = new HashSet<>();
        for (String s : this.keyPurposeSet) {
            keyPurposeOIDSet.add(new ObjectIdentifier(s));
        }
    }
}
Also used : ObjectIdentifier(sun.security.util.ObjectIdentifier)

Example 32 with ObjectIdentifier

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

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 33 with ObjectIdentifier

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

the class X509CertSelector method setExtendedKeyUsage.

/**
 * Sets the extendedKeyUsage criterion. The {@code X509Certificate}
 * must allow the specified key purposes in its extended key usage
 * extension. If {@code keyPurposeSet} is empty or {@code null},
 * no extendedKeyUsage check will be done. Note that an
 * {@code X509Certificate} that has no extendedKeyUsage extension
 * implicitly allows all key purposes.
 * <p>
 * Note that the {@code Set} is cloned to protect against
 * subsequent modifications.
 *
 * @param keyPurposeSet a {@code Set} of key purpose OIDs in string
 * format (or {@code null}). Each OID is represented by a set of
 * nonnegative integers separated by periods.
 * @throws IOException if the OID is invalid, such as
 * the first component being not 0, 1 or 2 or the second component
 * being greater than 39.
 * @see #getExtendedKeyUsage
 */
public void setExtendedKeyUsage(Set<String> keyPurposeSet) throws IOException {
    if ((keyPurposeSet == null) || keyPurposeSet.isEmpty()) {
        this.keyPurposeSet = null;
        keyPurposeOIDSet = null;
    } else {
        this.keyPurposeSet = Collections.unmodifiableSet(new HashSet<String>(keyPurposeSet));
        keyPurposeOIDSet = new HashSet<ObjectIdentifier>();
        for (String s : this.keyPurposeSet) {
            keyPurposeOIDSet.add(new ObjectIdentifier(s));
        }
    }
}
Also used : ObjectIdentifier(sun.security.util.ObjectIdentifier)

Example 34 with ObjectIdentifier

use of sun.security.util.ObjectIdentifier in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class CredentialStorage method isHardwareBackedKey.

private boolean isHardwareBackedKey(byte[] keyData) {
    try {
        final ASN1InputStream bIn = new ASN1InputStream(new ByteArrayInputStream(keyData));
        final PrivateKeyInfo pki = PrivateKeyInfo.getInstance(bIn.readObject());
        final String algOid = pki.getPrivateKeyAlgorithm().getAlgorithm().getId();
        final 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)

Example 35 with ObjectIdentifier

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

the class NativeGSSContext method retrieveToken.

private byte[] retrieveToken(InputStream is, int mechTokenLen) throws GSSException {
    try {
        byte[] result = null;
        if (mechTokenLen != -1) {
            // Need to add back the GSS header for a complete GSS token
            SunNativeProvider.debug("Precomputed mechToken length: " + mechTokenLen);
            GSSHeader gssHeader = new GSSHeader(new ObjectIdentifier(cStub.getMech().toString()), mechTokenLen);
            ByteArrayOutputStream baos = new ByteArrayOutputStream(600);
            byte[] mechToken = new byte[mechTokenLen];
            int len = is.read(mechToken);
            assert (mechTokenLen == len);
            gssHeader.encode(baos);
            baos.write(mechToken);
            result = baos.toByteArray();
        } else {
            // Must be unparsed GSS token or SPNEGO's NegTokenTarg token
            assert (mechTokenLen == -1);
            DerValue dv = new DerValue(is);
            result = dv.toByteArray();
        }
        SunNativeProvider.debug("Complete Token length: " + result.length);
        return result;
    } catch (IOException ioe) {
        throw new GSSExceptionImpl(GSSException.FAILURE, ioe);
    }
}
Also used : DerValue(sun.security.util.DerValue) GSSExceptionImpl(sun.security.jgss.GSSExceptionImpl) GSSHeader(sun.security.jgss.GSSHeader) 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