Search in sources :

Example 16 with DestroyFailedException

use of javax.security.auth.DestroyFailedException in project j2objc by google.

the class DestroyFailedExceptionTest method testDestroyFailedException02.

/**
 * javax.security.auth.DestroyFailedException#DestroyFailedException(String msg)
 * Assertion: constructs with not null parameter.
 */
public void testDestroyFailedException02() {
    DestroyFailedException dfE;
    for (int i = 0; i < msgs.length; i++) {
        dfE = new DestroyFailedException(msgs[i]);
        assertEquals("getMessage() must return: ".concat(msgs[i]), dfE.getMessage(), msgs[i]);
        assertNull("getCause() must return null", dfE.getCause());
    }
}
Also used : DestroyFailedException(javax.security.auth.DestroyFailedException)

Example 17 with DestroyFailedException

use of javax.security.auth.DestroyFailedException in project cxf by apache.

the class AbstractContentEncryptionAlgorithm method getContentEncryptionKey.

public byte[] getContentEncryptionKey(JweHeaders headers) {
    final byte[] theCek;
    if (cek == null) {
        String algoJava = getAlgorithm().getJavaName();
        SecretKey secretKey = CryptoUtils.getSecretKey(AlgorithmUtils.stripAlgoProperties(algoJava), getContentEncryptionKeySize(headers));
        theCek = secretKey.getEncoded();
        if (generateCekOnce) {
            synchronized (this) {
                cek = theCek;
            }
        }
        // Clean the key after we're done with it
        try {
            secretKey.destroy();
        } catch (DestroyFailedException e) {
        // ignore
        }
    } else {
        theCek = cek;
    }
    return theCek;
}
Also used : SecretKey(javax.crypto.SecretKey) DestroyFailedException(javax.security.auth.DestroyFailedException)

Example 18 with DestroyFailedException

use of javax.security.auth.DestroyFailedException in project cxf by apache.

the class AbstractJweDecryption method doDecrypt.

protected JweDecryptionOutput doDecrypt(JweDecryptionInput jweDecryptionInput, byte[] cek) {
    KeyProperties keyProperties = new KeyProperties(getContentEncryptionAlgorithm(jweDecryptionInput));
    keyProperties.setAdditionalData(getContentEncryptionCipherAAD(jweDecryptionInput));
    AlgorithmParameterSpec spec = getContentEncryptionCipherSpec(jweDecryptionInput);
    keyProperties.setAlgoSpec(spec);
    boolean compressionSupported = JoseConstants.JWE_DEFLATE_ZIP_ALGORITHM.equals(jweDecryptionInput.getJweHeaders().getZipAlgorithm());
    keyProperties.setCompressionSupported(compressionSupported);
    byte[] actualCek = getActualCek(cek, jweDecryptionInput.getJweHeaders().getContentEncryptionAlgorithm().getJwaName());
    SecretKey secretKey = CryptoUtils.createSecretKeySpec(actualCek, keyProperties.getKeyAlgo());
    byte[] bytes = CryptoUtils.decryptBytes(getEncryptedContentWithAuthTag(jweDecryptionInput), secretKey, keyProperties);
    // Here we're finished with the SecretKey we created, so we can destroy it
    try {
        secretKey.destroy();
    } catch (DestroyFailedException e) {
    // ignore
    }
    Arrays.fill(cek, (byte) 0);
    if (actualCek != cek) {
        Arrays.fill(actualCek, (byte) 0);
    }
    return new JweDecryptionOutput(jweDecryptionInput.getJweHeaders(), bytes);
}
Also used : SecretKey(javax.crypto.SecretKey) DestroyFailedException(javax.security.auth.DestroyFailedException) KeyProperties(org.apache.cxf.rt.security.crypto.KeyProperties) AlgorithmParameterSpec(java.security.spec.AlgorithmParameterSpec)

Example 19 with DestroyFailedException

use of javax.security.auth.DestroyFailedException in project cxf by apache.

the class ModelEncryptionSupport method decryptRefreshToken.

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;
}
Also used : SecretKey(javax.crypto.SecretKey) DestroyFailedException(javax.security.auth.DestroyFailedException) RefreshToken(org.apache.cxf.rs.security.oauth2.tokens.refresh.RefreshToken)

Example 20 with DestroyFailedException

use of javax.security.auth.DestroyFailedException in project cxf by apache.

the class ModelEncryptionSupport method decryptClient.

public static Client decryptClient(String encodedSequence, String encodedSecretKey, KeyProperties props) throws SecurityException {
    SecretKey key = CryptoUtils.decodeSecretKey(encodedSecretKey, props.getKeyAlgo());
    Client client = decryptClient(encodedSequence, key, props);
    // Clean the secret key from memory when we're done
    try {
        key.destroy();
    } catch (DestroyFailedException ex) {
    // ignore
    }
    return client;
}
Also used : SecretKey(javax.crypto.SecretKey) DestroyFailedException(javax.security.auth.DestroyFailedException) Client(org.apache.cxf.rs.security.oauth2.common.Client)

Aggregations

DestroyFailedException (javax.security.auth.DestroyFailedException)30 SecretKey (javax.crypto.SecretKey)9 PrivateKey (java.security.PrivateKey)5 X509Certificate (java.security.cert.X509Certificate)4 CallbackHandler (javax.security.auth.callback.CallbackHandler)4 Crypto (org.apache.wss4j.common.crypto.Crypto)4 SecretKeySpec (javax.crypto.spec.SecretKeySpec)3 KerberosTicket (javax.security.auth.kerberos.KerberosTicket)3 CryptoType (org.apache.wss4j.common.crypto.CryptoType)3 WSPasswordCallback (org.apache.wss4j.common.ext.WSPasswordCallback)3 WSSecurityException (org.apache.wss4j.common.ext.WSSecurityException)3 IOException (java.io.IOException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 XMLCipher (org.apache.xml.security.encryption.XMLCipher)2 XMLEncryptionException (org.apache.xml.security.encryption.XMLEncryptionException)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 java.io (java.io)1 Signature (java.security.Signature)1 AlgorithmParameterSpec (java.security.spec.AlgorithmParameterSpec)1 Cipher (javax.crypto.Cipher)1