javax.security.auth.DestroyFailedException Java Examples

The following examples show how to use javax.security.auth.DestroyFailedException. 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 File: KerberosTicket.java    From jdk8u_jdk with 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 #2
Source File: KSPasswordProtectionTest.java    From j2objc with 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 #3
Source File: KeyDestructionTest.java    From jdk8u-jdk with 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 #4
Source File: KeyDestructionTest.java    From openjdk-jdk9 with 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 #5
Source File: KeyDestructionTest.java    From dragonwell8_jdk with 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 #6
Source File: ModelEncryptionSupport.java    From cxf with 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 #7
Source File: AbstractJweEncryption.java    From cxf with 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 #8
Source File: KeyDestructionTest.java    From TencentKona-8 with 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 File: CryptoUtils.java    From cxf with 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 #10
Source File: KerberosTicket.java    From JDKSourceCode1.8 with 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 #11
Source File: KerberosTicket.java    From jdk1.8-source-analysis with 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 #12
Source File: KeyDestructionTest.java    From openjdk-jdk8u-backup with 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 #13
Source File: KerberosTicket.java    From openjdk-8-source with 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 #14
Source File: KeyDestructionTest.java    From jdk8u_jdk with 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 #15
Source File: KerberosKey.java    From jdk8u60 with 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 #16
Source File: Krb5AcceptCredential.java    From jdk8u-jdk with 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 #17
Source File: DestroyFailedExceptionTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * javax.security.auth.DestroyFailedException#DestroyFailedException(String msg)
 * Assertion: constructs with null parameter.
 */
public void testDestroyFailedException03() {
    String msg = null;
    DestroyFailedException dfE = new DestroyFailedException(msg);
    assertNull("getMessage() must return null.", dfE.getMessage());
    assertNull("getCause() must return null", dfE.getCause());
}
 
Example #18
Source File: KeyDestructionTest.java    From jdk8u-jdk with 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
Source File: KerberosKey.java    From dragonwell8_jdk with 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 #20
Source File: KeyStore.java    From openjdk-jdk9 with 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 #21
Source File: KeyStore.java    From jdk8u60 with 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 File: Krb5AcceptCredential.java    From jdk8u60 with 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 #23
Source File: KeyStore.java    From openjdk-8 with 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 File: Krb5AcceptCredential.java    From jdk8u-dev-jdk with 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 #25
Source File: KerberosKey.java    From jdk8u-dev-jdk with 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 #26
Source File: KeyDestructionTest.java    From jdk8u60 with 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 #27
Source File: KerberosKey.java    From openjdk-8-source with 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 #28
Source File: KerberosKey.java    From JDKSourceCode1.8 with MIT License 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 File: KeyDestructionTest.java    From openjdk-jdk9 with 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 File: Krb5AcceptCredential.java    From openjdk-jdk8u with 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);
    }
}