Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 14bc1c58 authored by Alex Klyubin's avatar Alex Klyubin Committed by Android (Google) Code Review
Browse files

Merge "Use ProviderException in AndroidKeyStore." into mnc-dev

parents 38dc1542 658cd660
Loading
Loading
Loading
Loading
+8 −7
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.security.ProviderException;
import java.security.SecureRandom;
import java.security.spec.AlgorithmParameterSpec;
import java.security.spec.InvalidParameterSpecException;
@@ -315,15 +316,15 @@ public abstract class KeyStoreCipherSpi extends CipherSpi implements KeyStoreCry
            } else if (e instanceof InvalidAlgorithmParameterException) {
                throw (InvalidAlgorithmParameterException) e;
            } else {
                throw new RuntimeException("Unexpected exception type", e);
                throw new ProviderException("Unexpected exception type", e);
            }
        }

        if (mOperationToken == null) {
            throw new IllegalStateException("Keystore returned null operation token");
            throw new ProviderException("Keystore returned null operation token");
        }
        if (mOperationHandle == 0) {
            throw new IllegalStateException("Keystore returned invalid operation handle");
            throw new ProviderException("Keystore returned invalid operation handle");
        }

        loadAlgorithmSpecificParametersFromBeginResult(keymasterOutputArgs);
@@ -499,9 +500,9 @@ public abstract class KeyStoreCipherSpi extends CipherSpi implements KeyStoreCry
                params.init(new IvParameterSpec(mIv));
                return params;
            } catch (NoSuchAlgorithmException e) {
                throw new RuntimeException("Failed to obtain AES AlgorithmParameters", e);
                throw new ProviderException("Failed to obtain AES AlgorithmParameters", e);
            } catch (InvalidParameterSpecException e) {
                throw new RuntimeException(
                throw new ProviderException(
                        "Failed to initialize AES AlgorithmParameters with an IV", e);
            }
        }
@@ -668,11 +669,11 @@ public abstract class KeyStoreCipherSpi extends CipherSpi implements KeyStoreCry
            if (mIv == null) {
                mIv = returnedIv;
            } else if ((returnedIv != null) && (!Arrays.equals(returnedIv, mIv))) {
                throw new IllegalStateException("IV in use differs from provided IV");
                throw new ProviderException("IV in use differs from provided IV");
            }
        } else {
            if (returnedIv != null) {
                throw new IllegalStateException(
                throw new ProviderException(
                        "IV in use despite IV not being used by this transformation");
            }
        }
+3 −1
Original line number Diff line number Diff line
@@ -16,12 +16,14 @@

package android.security;

import java.security.ProviderException;

/**
 * Indicates a communications error with keystore service.
 *
 * @hide
 */
public class KeyStoreConnectException extends IllegalStateException {
public class KeyStoreConnectException extends ProviderException {
    public KeyStoreConnectException() {
        super("Failed to communicate with keystore service");
    }
+8 −7
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.security.keymaster.OperationResult;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.ProviderException;
import java.security.spec.AlgorithmParameterSpec;

import javax.crypto.MacSpi;
@@ -185,10 +186,10 @@ public abstract class KeyStoreHmacSpi extends MacSpi implements KeyStoreCryptoOp
        }

        if (mOperationToken == null) {
            throw new IllegalStateException("Keystore returned null operation token");
            throw new ProviderException("Keystore returned null operation token");
        }
        if (mOperationHandle == 0) {
            throw new IllegalStateException("Keystore returned invalid operation handle");
            throw new ProviderException("Keystore returned invalid operation handle");
        }

        mChunkedStreamer = new KeyStoreCryptoOperationChunkedStreamer(
@@ -206,17 +207,17 @@ public abstract class KeyStoreHmacSpi extends MacSpi implements KeyStoreCryptoOp
        try {
            ensureKeystoreOperationInitialized();
        } catch (InvalidKeyException e) {
            throw new IllegalStateException("Failed to reinitialize MAC", e);
            throw new ProviderException("Failed to reinitialize MAC", e);
        }

        byte[] output;
        try {
            output = mChunkedStreamer.update(input, offset, len);
        } catch (KeyStoreException e) {
            throw new IllegalStateException("Keystore operation failed", e);
            throw new ProviderException("Keystore operation failed", e);
        }
        if ((output != null) && (output.length != 0)) {
            throw new IllegalStateException("Update operation unexpectedly produced output");
            throw new ProviderException("Update operation unexpectedly produced output");
        }
    }

@@ -225,14 +226,14 @@ public abstract class KeyStoreHmacSpi extends MacSpi implements KeyStoreCryptoOp
        try {
            ensureKeystoreOperationInitialized();
        } catch (InvalidKeyException e) {
            throw new IllegalStateException("Failed to reinitialize MAC", e);
            throw new ProviderException("Failed to reinitialize MAC", e);
        }

        byte[] result;
        try {
            result = mChunkedStreamer.doFinal(null, 0, 0);
        } catch (KeyStoreException e) {
            throw new IllegalStateException("Keystore operation failed", e);
            throw new ProviderException("Keystore operation failed", e);
        }

        resetWhilePreservingInitState();