From c73fe01f1607fb4b1f9afb98fc46960623fef483 Mon Sep 17 00:00:00 2001 From: Seth Moore Date: Wed, 5 May 2021 17:34:15 -0700 Subject: [PATCH] Don't re-wrap DeviceIdAttestationExceptions Instead of always wrapping errors in a DeviceIdAttestationException, check to see if the underlying cause was originally a DeviceIdAttestationException. If so, unwrap the cause and just re-throw that, preserving the original error. Bug: 183827468 Test: GtsGmsCoreSecurityTestApp Change-Id: Iab78ccaff91dd1de615e1d2b18f709027aecd59e --- .../java/android/security/keystore/AttestationUtils.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/keystore/java/android/security/keystore/AttestationUtils.java b/keystore/java/android/security/keystore/AttestationUtils.java index be865a02a945..3980d3a0203b 100644 --- a/keystore/java/android/security/keystore/AttestationUtils.java +++ b/keystore/java/android/security/keystore/AttestationUtils.java @@ -293,6 +293,11 @@ public abstract class AttestationUtils { } catch (SecurityException e) { throw e; } catch (Exception e) { + // If a DeviceIdAttestationException was previously wrapped with some other type, + // let's throw the original exception instead of wrapping it yet again. + if (e.getCause() instanceof DeviceIdAttestationException) { + throw (DeviceIdAttestationException) e.getCause(); + } throw new DeviceIdAttestationException("Unable to perform attestation", e); } }