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

Commit a0f656f9 authored by Alex Klyubin's avatar Alex Klyubin
Browse files

Obtain SPI without using Reflection.

Bug: 18088752
Change-Id: I76d42e17f5f28af6fd9a96ee812d286f6c6a085b
parent 6aed9ec1
Loading
Loading
Loading
Loading
+7 −14
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package android.security;

import java.lang.reflect.Method;
import java.security.Provider;

import javax.crypto.Cipher;
@@ -92,19 +91,13 @@ public class AndroidKeyStoreProvider extends Provider {
        if (cryptoPrimitive == null) {
            throw new NullPointerException();
        }
        if ((!(cryptoPrimitive instanceof Mac)) && (!(cryptoPrimitive instanceof Cipher))) {
            throw new IllegalArgumentException("Unsupported crypto primitive: " + cryptoPrimitive);
        }
        Object spi;
        // TODO: Replace this Reflection based codewith direct invocations once the libcore changes
        // are in.
        try {
            Method getSpiMethod = cryptoPrimitive.getClass().getDeclaredMethod("getSpi");
            getSpiMethod.setAccessible(true);
            spi = getSpiMethod.invoke(cryptoPrimitive);
        } catch (ReflectiveOperationException e) {
            throw new IllegalArgumentException(
                    "Unsupported crypto primitive: " + cryptoPrimitive, e);
        if (cryptoPrimitive instanceof Mac) {
            spi = ((Mac) cryptoPrimitive).getSpi();
        } else if (cryptoPrimitive instanceof Cipher) {
            spi = ((Cipher) cryptoPrimitive).getSpi();
        } else {
            throw new IllegalArgumentException("Unsupported crypto primitive: " + cryptoPrimitive);
        }
        if (!(spi instanceof KeyStoreCryptoOperation)) {
            throw new IllegalArgumentException(