OSDN Git Service

resolved conflicts for merge of b068f162 to master
authorAlex Klyubin <klyubin@google.com>
Fri, 3 Apr 2015 20:01:09 +0000 (13:01 -0700)
committerAlex Klyubin <klyubin@google.com>
Fri, 3 Apr 2015 20:01:09 +0000 (13:01 -0700)
Change-Id: I5bc234e1da047880d3437a861ff93474a9797e18

1  2 
keystore/java/android/security/KeyStore.java
keystore/java/android/security/KeyStoreKeyGeneratorSpi.java

@@@ -506,4 -507,57 +507,60 @@@ public class KeyStore 
              return SYSTEM_ERROR;
          }
      }
+     public static KeyStoreException getKeyStoreException(int errorCode) {
+         if (errorCode > 0) {
+             // KeyStore layer error
+             switch (errorCode) {
+                 case NO_ERROR:
+                     return new KeyStoreException(errorCode, "OK");
+                 case LOCKED:
+                     return new KeyStoreException(errorCode, "Keystore locked");
+                 case UNINITIALIZED:
+                     return new KeyStoreException(errorCode, "Keystore not initialized");
+                 case SYSTEM_ERROR:
+                     return new KeyStoreException(errorCode, "System error");
+                 case PERMISSION_DENIED:
+                     return new KeyStoreException(errorCode, "Permission denied");
+                 case KEY_NOT_FOUND:
+                     return new KeyStoreException(errorCode, "Key not found");
+                 case VALUE_CORRUPTED:
+                     return new KeyStoreException(errorCode, "Key blob corrupted");
+                 default:
+                     return new KeyStoreException(errorCode, String.valueOf(errorCode));
+             }
+         } else {
+             // Keymaster layer error
+             switch (errorCode) {
+                 case KeymasterDefs.KM_ERROR_INVALID_AUTHORIZATION_TIMEOUT:
+                     // The name of this parameter significantly differs between Keymaster and
+                     // framework APIs. Use the framework wording to make life easier for developers.
+                     return new KeyStoreException(errorCode,
+                             "Invalid user authentication validity duration");
+                 default:
+                     return new KeyStoreException(errorCode,
+                             KeymasterDefs.getErrorMessage(errorCode));
+             }
+         }
+     }
+     public static CryptoOperationException getCryptoOperationException(KeyStoreException e) {
+         switch (e.getErrorCode()) {
+             case KeymasterDefs.KM_ERROR_KEY_EXPIRED:
+                 return new KeyExpiredException();
+             case KeymasterDefs.KM_ERROR_KEY_NOT_YET_VALID:
+                 return new KeyNotYetValidException();
+             case KeymasterDefs.KM_ERROR_KEY_USER_NOT_AUTHENTICATED:
+                 return new UserNotAuthenticatedException();
++            // TODO: Handle TBD Keymaster error code "invalid key: new fingerprint enrolled"
++            // case KeymasterDefs.KM_ERROR_TBD
++            //     return new NewFingerprintEnrolledException();
+             default:
+                 return new CryptoOperationException("Crypto operation failed", e);
+         }
+     }
+     public static CryptoOperationException getCryptoOperationException(int errorCode) {
+         return getCryptoOperationException(getKeyStoreException(errorCode));
+     }
  }