Commit graph

14 commits

Author SHA1 Message Date
Janis Danisevskis
6a0d998380 Fix grants get lost on key upgrade
The upgrade routine used to call KeyStore->del which purges the given
key blob from the keystore including all existing grants.
With this patch, upgrade only calls Keymaster::delete on the keyblobs
without purging it from the keystore. Also it only calls
Keymaster::delete once the upgrade key was successfully written to disk.

This patch also calls fsync on the directory containing keyblobs to
narrow the window in which keyblob may be lost due to power loss.

Bug: 110450771
Test: Upgrade path tested by manually creating a key, bumping the
      patchlevel, using the key subsequently and inspecting the logs.
Change-Id: I89241b5d4033b270733ff61838ab9244fce28c60
2019-05-03 16:19:06 -07:00
Rob Barnes
bb6cabdaa1 Multi-threaded keystore
This patches changes the keystore to use the asychronous api model for
begin, update, finish, and abort.

Also removes unused class KeystoreArguments (aidl and implementation).

Test: Keystore CTS tests
Bug: 111443219

Change-Id: Icc6def9ff6dbe32193272d7d015079a006ebc430
2018-11-14 14:01:45 -08:00
Logan Chien
cdc813f782 Deprecate <cutils/log.h> and <utils/Log.h>
This commit replaces <cutils/log.h> and <utils/Log.h> with <log/log.h>.

Background:
<cutils/log.h> has been moved to <log/log.h> for a while.  Both
<cutils/log.h> and <utils/Log.h> simply includes <log/log.h> for
backward compatibility.  This commit is a part of the effort to remove
<cutils/log.h> and <utils/Log.h> from the source tree eventually.

Bug: 78370064
Test: lunch aosp_walleye-userdebug && cd system/security && mma
Change-Id: I798f06d78e2cc5cd197727c0bcdd05c87d769a90
2018-09-19 13:38:34 +08:00
Pavel Grafov
cef39477f9 NIAP: Log key integrity failure to audit log.
Logs key integrity violation in two cases:
1. software-detected corruption of key blob.
2. keymaster operation returning INVALID_KEY_BLOB

Changed AES_gcm_decrypt to return VALUE_CORRUPTED on decryption errors
to be consistent with digest check for older version blob.

Bug: 70886042
Test: manual, by patching some bytes in the blob.
Test: cts-tradefed run cts -m CtsKeystoreTestCases
Change-Id: Ic8f6b7a2a49aee01253b429644af409e568d7deb
2018-02-15 18:20:28 +00:00
Janis Danisevskis
c1460141c0 KeyStore: use security level to chose keymaster device
Keymaster4 introduces security levels. Android devices
may have multiple keymaster implementations, one for each
possible security level, where the presence of a strong
security level implies the presence of all lower levels.

This patch adds code that enumerates all keymaster device
implementations available from ServiceManager and populates
Keystore's keymaster device database with at most one keymaster
implementation per security level. It gives precedence to
newer versions if multiple implementations exist for the same security
level.

The security level is chosen by a set of flags passed to the keystore
operations generate, import, addRngEntropy.
For existing keys the right security level is chosen by the blob flags.

To that end a new flag KEYSTORE_FLAG_STRONGBOX was added, and the
security level is expressed through a combination of
KEYSTORE_FLAG_FALLBACK (F) and KEYSTORE_FLAG_STRONGBOX (S).
Encoding is as follows:

             F     S
Software     1     X (don't care)
TEE          0     0
Strongbox    0     1

Some operations in keystore cli2 where amended with the optional
--seclevel flags. Allowing the user to chose the security level for the
given operation. Possible options are "software", "strongbox", and "tee"
where tee is the default value.

Test: Existing KeyStore CTS tests run

Change-Id: I01ef238f5e7067e480cf9b171630237236046bb1
2017-12-27 16:38:09 -08:00
Shawn Willden
bb22a6c50d Use libkeymaster4support in keystore.
Test: CTS
Change-Id: Iee8f308a5255a03b02fce162cc4184d45f75fd1b
2017-12-27 09:24:19 -08:00
Shawn Willden
0329a82c48 Move keystore to Keymaster4
Test: CTS
Change-Id: I6b7fa300f505ee685b1fe503edea3188225a98e3
2017-12-20 09:01:01 -07:00
Dmitry Dementyev
a447b3c9af Get rid of manually created IKeystoreService.
Generated IKeystoreService has different signature, which required lots
of refactoring.
After update methods relevant data using last parameter.
Test: cts-tradefed run cts -m CtsKeystoreTestCases
Bug: 68389643

Change-Id: I0ca36a2e9e007143a3b403b306a8f979ee98b232
2017-11-16 18:35:51 -08:00
Janis Danisevskis
5cc0d5ee60 Split libkeymaster1 into libkeymaster and libkeymaster_portable
Also removed unused include

Bug: 37467707
Test: trivial
Change-Id: Ie029462cb79d7aec28a37aac22f04ce73ebac8da
2017-05-03 15:53:26 +00:00
Janis Danisevskis
be0ec4f4be Revert "Split libkeymaster1 into libkeymaster and libkeymaster_portable"
This reverts commit ea3b820b93.

Reason for revert: build breakage

Change-Id: Ib101a5e896ffa816a7b9fb46774113846fa82590
2017-05-03 00:23:24 +00:00
Janis Danisevskis
ea3b820b93 Split libkeymaster1 into libkeymaster and libkeymaster_portable
Also removed unused include

Test: trivial
Change-Id: I37122aead5b60be8dd0697afa22489532d314b9c
2017-05-01 12:34:46 -07:00
Janis Danisevskis
c7a9fa29c1 Port to binderized keymaster HAL
This patch ports keystore to the HIDL based binderized keymaster HAL.
Keystore has no more dependencies on legacy keymaster headers, and
therefore data structures, constant declarations, or enums. All
keymaster related data structures and enums used by keystore are the
once defined by the HIDL based keymaster HAL definition.  In the process
of porting, keystore underwent some changes:

* Keystore got a new implementation of AuthorizationSet that is fully
  based on the new HIDL data structures. Key parameters are now either
  organised as AuthorizationSets or hidl_vec<KeyParameter>.  (Formerly,
  this was a mixture of keymaster's AuthorizationSet,
  std::vec<keymaster_key_param_t>, and keymaster_key_param_set_t.)  The
  former is used for memory management and provides algorithms for
  assembling, joining, and subtracting sets of parameters.  The latter
  is used as wire format for the HAL IPC; it can wrap the memory owned
  by an AuthorizationSet for this purpose.  The AuthorizationSet is
  accompanied by a new implementation of type safe functions for
  creating and accessing tagged key parameters,
  Authorizations (keystore/keymaster_tags.h).
* A new type (KSSReturnCode) was introduced that wraps keystore service
  response codes. Keystore has two sets of error codes.  ErrorCode
  errors are less than 0 and use 0 as success value.  ResponseCode
  errors are greater than zero and use 1 as success value.  This patch
  changes ResponseCode to be an enum class so that is no longer
  assignable to int without a cast. The new return type can only be
  initialized by ResponseCode or ErrorCode and when accessed as int32_t,
  which happens on serialization when the response is send to a client,
  the success values are coalesced onto 1 as expected by the
  clients. KSSreturnCode is also comparable to ResponseCode and
  ErrorCode, and the predicate isOk() returns true if it was initialized
  with either ErrorCode::OK (0) or ReponseCode::NO_ERROR (1).
* A bug was fixed, that caused the keystore verify function to return
  success, regardless of the input, internal errors, or lack of
  permissions.
* The marshalling code in IKeystoreService.cpp was rewritten.  For data
  structures that are known to keymaster, the client facing side of
  keystore uses HIDL based data structures as (target) source
  for (un)marshaling to avoid further conversion.  hidl_vecs are used to
  wrap parcel memory without copying and taking ownership where
  possible.
* Explicit use of malloc is reduced (malloc was required by the C nature
  of the old HAL).  The new implementations avoid explicit use of
  malloc/new and waive the use of pointers for return values. Instead,
  functions return by value objects that take ownership of secondary
  memory allocations where required.

Test: runtest --path=cts/tests/tests/keystore/src/android/keystore/cts

Bug: 32020919
Change-Id: I59d3a0f4a6bdf6bb3bbf791ad8827c463effa286
2017-01-23 08:30:49 -07:00
Jacob Abrams
3b06f80f60 Reduce chance of zero-length keystore files
The open/write/close/rename pattern can result in
zero-length files on some file systems if crash or power
loss occurs. Prefer open/write/fsync/close/rename.

BUG: https://code.google.com/p/android/issues/detail?id=207607
Change-Id: I2742c3ab967d5cf254b22cffb5164881315623d5
2016-08-31 21:23:54 +00:00
Shawn Willden
c1d1feee51 Refactor keystore.
This CL isn't nearly as big as it looks.  It doesn't change keystore
functionality, it just moves all of the classes out of the former
keystore.cpp into their own .h and .cpp files.

Note that this is a cherry-pick from:

    https://android-review.googlesource.com/#/c/194971

Change-Id: Ide326c4f1d03984994d1bd9a76fa68d37da230dc
2016-01-26 22:48:06 -07:00