Java Code Examples for javax.security.auth.DestroyFailedException

The following examples show how to use javax.security.auth.DestroyFailedException. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: jdk1.8-source-analysis   Source File: KerberosTicket.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Destroys the ticket and destroys any sensitive information stored in
 * it.
 */
public void destroy() throws DestroyFailedException {
    if (!destroyed) {
        Arrays.fill(asn1Encoding, (byte) 0);
        client = null;
        server = null;
        sessionKey.destroy();
        flags = null;
        authTime = null;
        startTime = null;
        endTime = null;
        renewTill = null;
        clientAddresses = null;
        destroyed = true;
    }
}
 
Example 2
Source Project: cxf   Source File: CryptoUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static byte[] wrapSecretKey(byte[] keyBytes,
                                   String keyAlgo,
                                   Key wrapperKey,
                                   KeyProperties wrapperKeyProps)  throws SecurityException {
    SecretKeySpec secretKey = new SecretKeySpec(keyBytes, convertJCECipherToSecretKeyName(keyAlgo));
    byte[] encryptedKey = wrapSecretKey(secretKey,
                         wrapperKey,
                         wrapperKeyProps);

    // Here we're finished with the SecretKey we created, so we can destroy it
    try {
        secretKey.destroy();
    } catch (DestroyFailedException e) {
        // ignore
    }
    return encryptedKey;
}
 
Example 3
Source Project: cxf   Source File: ModelEncryptionSupport.java    License: Apache License 2.0 6 votes vote down vote up
public static RefreshToken decryptRefreshToken(OAuthDataProvider provider,
                                              String encodedToken,
                                              String encodedSecretKey,
                                              KeyProperties props) throws SecurityException {
    SecretKey key = CryptoUtils.decodeSecretKey(encodedSecretKey, props.getKeyAlgo());
    RefreshToken refreshToken = decryptRefreshToken(provider, encodedToken, key, props);

    // Clean the secret key from memory when we're done
    try {
        key.destroy();
    } catch (DestroyFailedException ex) {
        // ignore
    }

    return refreshToken;
}
 
Example 4
private static void testNoKeyDestruction(Destroyable key)
    throws Exception {
    String klass = key.getClass().getName();

    if (key.isDestroyed()) {
        throw new Exception("error: a " + klass +
            " key has been unexpectedly destroyed");
    }
    try {
        key.destroy();
    } catch (DestroyFailedException dfe) {
        // not an error

        if (key.isDestroyed()) {
            throw new Exception("error: a " + klass +
                " key has been unexpectedly destroyed");
        }
        System.out.println(klass + " keys are not destroyable");
        return;
    }
    throw new Exception("error: key may been unexpectedly destroyed");
}
 
Example 5
Source Project: j2objc   Source File: KSPasswordProtectionTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Test for <code>KeyStore.PasswordProtection(char[] password, String protectionAlgorithm,
 * AlgorithmParameterSpec protectionParameters)</code> constructor
 * and the method <code>getProtectionAlgorithm()</code>

 * Assertions: constructor throws NullPointerException if protectionAlgorithm is null.
 * getProtectionAlgorithm() returns the protection algorithm passed in the constructor.
 */
public void testGetProtectionAlgorithm() throws DestroyFailedException {
    char [] pass = {'a', 'b', 'c'};
    String protectionAlgorithm = "ThisBeautifulAlgorithm";
    AlgorithmParameterSpec protectionParameters = new IvParameterSpec(new byte[]{});
    KeyStore.PasswordProtection ksPWP;
    try {
        ksPWP = new KeyStore.PasswordProtection(
                pass, null /* protectionAlgorithm */, protectionParameters);
        fail("Expected null pointer exception");
    } catch (NullPointerException expected) {
    }
    ksPWP = new KeyStore.PasswordProtection(
            pass, protectionAlgorithm, null /* protectionParameters */);
    assertSame(protectionAlgorithm, ksPWP.getProtectionAlgorithm());
}
 
Example 6
Source Project: cxf   Source File: AbstractJweEncryption.java    License: Apache License 2.0 6 votes vote down vote up
protected byte[] encryptInternal(JweEncryptionInternal state, byte[] content) {
    try {
        SecretKey createCekSecretKey = createCekSecretKey(state);
        byte[] encryptedBytes = CryptoUtils.encryptBytes(content, createCekSecretKey, state.keyProps);

        // Here we're finished with the SecretKey we created, so we can destroy it
        try {
            createCekSecretKey.destroy();
        } catch (DestroyFailedException e) {
            // ignore
        }
        return encryptedBytes;
    } catch (SecurityException ex) {
        LOG.fine(ex.getMessage());
        if (ex.getCause() instanceof NoSuchAlgorithmException) {
            LOG.warning("Unsupported algorithm: " + state.keyProps.getKeyAlgo());
            throw new JweException(JweException.Error.INVALID_CONTENT_ALGORITHM);
        }
        throw new JweException(JweException.Error.CONTENT_ENCRYPTION_FAILURE, ex);
    }
}
 
Example 7
private static void testNoKeyDestruction(Destroyable key)
    throws Exception {
    String klass = key.getClass().getName();

    if (key.isDestroyed()) {
        throw new Exception("error: a " + klass +
            " key has been unexpectedly destroyed");
    }
    try {
        key.destroy();
    } catch (DestroyFailedException dfe) {
        // not an error

        if (key.isDestroyed()) {
            throw new Exception("error: a " + klass +
                " key has been unexpectedly destroyed");
        }
        System.out.println(klass + " keys are not destroyable");
        return;
    }
    throw new Exception("error: key may been unexpectedly destroyed");
}
 
Example 8
Source Project: jdk8u-jdk   Source File: KeyDestructionTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static void testNoKeyDestruction(Destroyable key)
    throws Exception {
    String klass = key.getClass().getName();

    if (key.isDestroyed()) {
        throw new Exception("error: a " + klass +
            " key has been unexpectedly destroyed");
    }
    try {
        key.destroy();
    } catch (DestroyFailedException dfe) {
        // not an error

        if (key.isDestroyed()) {
            throw new Exception("error: a " + klass +
                " key has been unexpectedly destroyed");
        }
        System.out.println(klass + " keys are not destroyable");
        return;
    }
    throw new Exception("error: key may been unexpectedly destroyed");
}
 
Example 9
Source Project: JDKSourceCode1.8   Source File: KerberosTicket.java    License: MIT License 6 votes vote down vote up
/**
 * Destroys the ticket and destroys any sensitive information stored in
 * it.
 */
public void destroy() throws DestroyFailedException {
    if (!destroyed) {
        Arrays.fill(asn1Encoding, (byte) 0);
        client = null;
        server = null;
        sessionKey.destroy();
        flags = null;
        authTime = null;
        startTime = null;
        endTime = null;
        renewTill = null;
        clientAddresses = null;
        destroyed = true;
    }
}
 
Example 10
/**
 * Destroys the ticket and destroys any sensitive information stored in
 * it.
 */
public void destroy() throws DestroyFailedException {
    if (!destroyed) {
        Arrays.fill(asn1Encoding, (byte) 0);
        client = null;
        server = null;
        sessionKey.destroy();
        flags = null;
        authTime = null;
        startTime = null;
        endTime = null;
        renewTill = null;
        clientAddresses = null;
        destroyed = true;
    }
}
 
Example 11
private static void testNoKeyDestruction(Destroyable key)
    throws Exception {
    String klass = key.getClass().getName();

    if (key.isDestroyed()) {
        throw new Exception("error: a " + klass +
            " key has been unexpectedly destroyed");
    }
    try {
        key.destroy();
    } catch (DestroyFailedException dfe) {
        // not an error

        if (key.isDestroyed()) {
            throw new Exception("error: a " + klass +
                " key has been unexpectedly destroyed");
        }
        System.out.println(klass + " keys are not destroyable");
        return;
    }
    throw new Exception("error: key may been unexpectedly destroyed");
}
 
Example 12
Source Project: jdk8u_jdk   Source File: KerberosTicket.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Destroys the ticket and destroys any sensitive information stored in
 * it.
 */
public void destroy() throws DestroyFailedException {
    if (!destroyed) {
        Arrays.fill(asn1Encoding, (byte) 0);
        client = null;
        server = null;
        sessionKey.destroy();
        flags = null;
        authTime = null;
        startTime = null;
        endTime = null;
        renewTill = null;
        clientAddresses = null;
        destroyed = true;
    }
}
 
Example 13
private static void testNoKeyDestruction(Destroyable key)
    throws Exception {
    String klass = key.getClass().getName();

    if (key.isDestroyed()) {
        throw new Exception("error: a " + klass +
            " key has been unexpectedly destroyed");
    }
    try {
        key.destroy();
    } catch (DestroyFailedException dfe) {
        // not an error

        if (key.isDestroyed()) {
            throw new Exception("error: a " + klass +
                " key has been unexpectedly destroyed");
        }
        System.out.println(klass + " keys are not destroyable");
        return;
    }
    throw new Exception("error: key may been unexpectedly destroyed");
}
 
Example 14
Source Project: jdk1.8-source-analysis   Source File: KerberosKey.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Destroys this key. A call to any of its other methods after this
 * will cause an  IllegalStateException to be thrown.
 *
 * @throws DestroyFailedException if some error occurs while destorying
 * this key.
 */
public void destroy() throws DestroyFailedException {
    if (!destroyed) {
        key.destroy();
        principal = null;
        destroyed = true;
    }
}
 
Example 15
Source Project: hottub   Source File: KeyDestructionTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void destroy() throws DestroyFailedException {
    if (!this.isDestroyed) {
        Arrays.fill(encoded, (byte) 0);
        this.isDestroyed = true;
    }
}
 
Example 16
Source Project: j2objc   Source File: KSPasswordProtectionTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Test for <code>KeyStore.PasswordProtection(char[] password, String protectionAlgorithm,
 * AlgorithmParameterSpec protectionParameters)</code> constructor
 * and the method <code>getProtectionParameters()</code>

 * Assertions: constructor creates new PasswordProtection object, even if protectionParameters
 * is null. getProtectionParameterrs() returns the protection algorithm passed in the
 * constructor.
 */
public void testGetProtectionParameters() throws DestroyFailedException {
    char [] pass = {'a', 'b', 'c'};
    AlgorithmParameterSpec protectionParameters = new IvParameterSpec(new byte[]{});
    KeyStore.PasswordProtection ksPWP =
            new KeyStore.PasswordProtection(
                    pass, "protectionAlgorithm", null /* protectionParameters */);
    assertNull(ksPWP.getProtectionParameters());
    ksPWP = new KeyStore.PasswordProtection(
            pass, "protectionAlgorithm", protectionParameters);
    assertSame(protectionParameters, ksPWP.getProtectionParameters());
}
 
Example 17
Source Project: dragonwell8_jdk   Source File: KerberosKey.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Destroys this key. A call to any of its other methods after this
 * will cause an  IllegalStateException to be thrown.
 *
 * @throws DestroyFailedException if some error occurs while destorying
 * this key.
 */
public void destroy() throws DestroyFailedException {
    if (!destroyed) {
        key.destroy();
        principal = null;
        destroyed = true;
    }
}
 
Example 18
Source Project: openjdk-8   Source File: KeyDestructionTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void destroy() throws DestroyFailedException {
    if (!this.isDestroyed) {
        Arrays.fill(encoded, (byte) 0);
        this.isDestroyed = true;
    }
}
 
Example 19
@Override
public void destroy() throws DestroyFailedException {
    if (!this.isDestroyed) {
        Arrays.fill(encoded, (byte) 0);
        this.isDestroyed = true;
    }
}
 
Example 20
@Override
public void destroy() throws DestroyFailedException {
    if (!this.isDestroyed) {
        Arrays.fill(encoded, (byte) 0);
        this.isDestroyed = true;
    }
}
 
Example 21
Source Project: TencentKona-8   Source File: KeyStore.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Clears the password.
 *
 * @exception DestroyFailedException if this method was unable
 *      to clear the password
 */
public synchronized void destroy() throws DestroyFailedException {
    destroyed = true;
    if (password != null) {
        Arrays.fill(password, ' ');
    }
}
 
Example 22
Source Project: openjdk-jdk9   Source File: EncryptionKey.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Destroys this key by clearing out the key material of this key.
 *
 * @throws DestroyFailedException if some error occurs while destorying
 * this key.
 */
@Override
public void destroy() throws DestroyFailedException {
    if (!destroyed) {
        key.destroy();
        destroyed = true;
    }
}
 
Example 23
Source Project: openjdk-8   Source File: KeyStore.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Clears the password.
 *
 * @exception DestroyFailedException if this method was unable
 *      to clear the password
 */
public synchronized void destroy() throws DestroyFailedException {
    destroyed = true;
    if (password != null) {
        Arrays.fill(password, ' ');
    }
}
 
Example 24
Source Project: jdk8u60   Source File: KeyStore.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Clears the password.
 *
 * @exception DestroyFailedException if this method was unable
 *      to clear the password
 */
public synchronized void destroy() throws DestroyFailedException {
    destroyed = true;
    if (password != null) {
        Arrays.fill(password, ' ');
    }
}
 
Example 25
Source Project: jdk8u60   Source File: Krb5AcceptCredential.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Called to invalidate this credential element.
 */
public void dispose() throws GSSException {
    try {
        destroy();
    } catch (DestroyFailedException e) {
        GSSException gssException =
            new GSSException(GSSException.FAILURE, -1,
             "Could not destroy credentials - " + e.getMessage());
        gssException.initCause(e);
    }
}
 
Example 26
Source Project: jdk8u60   Source File: KerberosKey.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Destroys this key. A call to any of its other methods after this
 * will cause an  IllegalStateException to be thrown.
 *
 * @throws DestroyFailedException if some error occurs while destorying
 * this key.
 */
public void destroy() throws DestroyFailedException {
    if (!destroyed) {
        key.destroy();
        principal = null;
        destroyed = true;
    }
}
 
Example 27
/**
 * Called to invalidate this credential element.
 */
public void dispose() throws GSSException {
    try {
        destroy();
    } catch (DestroyFailedException e) {
        GSSException gssException =
            new GSSException(GSSException.FAILURE, -1,
             "Could not destroy credentials - " + e.getMessage());
        gssException.initCause(e);
    }
}
 
Example 28
Source Project: jdk8u-dev-jdk   Source File: KerberosKey.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Destroys this key. A call to any of its other methods after this
 * will cause an  IllegalStateException to be thrown.
 *
 * @throws DestroyFailedException if some error occurs while destorying
 * this key.
 */
public void destroy() throws DestroyFailedException {
    if (!destroyed) {
        key.destroy();
        principal = null;
        destroyed = true;
    }
}
 
Example 29
Source Project: jdk8u60   Source File: KeyDestructionTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void destroy() throws DestroyFailedException {
    if (!this.isDestroyed) {
        Arrays.fill(encoded, (byte) 0);
        this.isDestroyed = true;
    }
}
 
Example 30
Source Project: openjdk-8-source   Source File: KerberosKey.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Destroys this key. A call to any of its other methods after this
 * will cause an  IllegalStateException to be thrown.
 *
 * @throws DestroyFailedException if some error occurs while destorying
 * this key.
 */
public void destroy() throws DestroyFailedException {
    if (!destroyed) {
        key.destroy();
        principal = null;
        destroyed = true;
    }
}