Commit graph

74 commits

Author SHA1 Message Date
Shaquille Johnson
ac3c2cdea4 Add new error for system errors that are retryable
Some issues require a system error to be raised that
indicates we should retry the process. This adds a new
error and bumps the version of the api for future use.

Test: atest keystore2_test
Bug: 238619180
Change-Id: Iff8fa83f7b223e08de9fa31434e16aa3aa2153f6
2024-01-12 15:50:54 +00:00
Rajesh Nyamagoud
4347357814 Created libkeystore-engine as cc-library instead of cc-test-library to
avoid issues while linking shared libraries with Rust test binaries.

This change is made to avoid vts-tradefed failure to link the shared
library while running the Rust VTS `keystore2_client_tests` test
suite. As suggested in b/314110490#24 using the libkeystore-engine
static-library to run keystore2_client_tests.

Bug: 314110490, 298668920
Test: atest keystore2_client_tests; run vts -m keystore2_client_tests
Change-Id: If956865eeb4af908f33b1ad81a2b2e26300aae0e
2024-01-03 01:44:24 +00:00
Rajesh Nyamagoud
21e7cadafd Updated libkeystore-engine library to be cc_test_library instead of
cc_library_shared.

Since libkeystore-engine used only in keystore2_client_tests test
module, creating it as cc_test_library.

Bug: 298668920
Test: atest keystore2_client_tests
Change-Id: I656e989186610266c8a59ac11db8ac8a47d3514f
2023-12-12 18:34:14 +00:00
Rajesh Nyamagoud
28abde6189 Adding tests to verify EVP_PKEY_from_keystore2 API [Keystore2-engine].
1. Generate RSA key and grant it to a user. In user context load the
   key using `EVP_PKEY_from_keystore` and perform sign and verify
   opeearions.
   [keystore2_perofrm_crypto_op_using_keystore2_engine_rsa_key_success]

2. Generate EC key and grant it to a user. In user context load the
   key using `EVP_PKEY_from_keystore` and perform sign and verify
   operations.
   [keystore2_perofrm_crypto_op_using_keystore2_engine_ec_key_success]

3. Generate RSA key and grant it to a user. Re-encode the certificate
   as PEM and update the certificate using `updateSubcomponents`.
   In user context load the key using `EVP_PKEY_from_keystore` and
   perform sign and verify operations.

Bug: 201343811
Test: atest keystore2_client_tests
Change-Id: I7dafd598f4198e11103cd11695b2f67636f24755
2023-05-23 19:28:24 +00:00
David Benjamin
66d00307aa Use BoringSSL accessors to set up EVP_PKEY.
Constructing an RSA object is sadly a bit tedious, but that's the API
OpenSSL came up with. While I'm here, switch an EVP_PKEY_get1_RSA to
EVP_PKEY_get0_RSA; we can avoid an unnecessary refcount bump.

Test: mm
Change-Id: I8b368ea1efa71e3f8b3cd0c734c1cdd0f2c964e5
2023-01-30 16:02:49 -05:00
Janis Danisevskis
f2ff9c8ee9 Keystore 2.0 engine: Handle legacy PEM certificates.
Keystore 2.0 in Android S requires all new certificates to be stored in
DER format, however, when upgrading from R or older, there may be
certificates stored in PEM format. This patch allows keystore2-engine to
extract the public keys from certificates in either format.

Bug: 199155260
Test: N/A
Change-Id: I4bd5befcef15af5fbc2cbec3fdf4d581b1558b56
2021-09-27 13:57:54 -07:00
Treehugger Robot
1efb666352 Merge "Keystore 2.0: Small performance gain" 2021-09-16 02:13:06 +00:00
Jiyong Park
0d61dd6c3a Remove ndk_platform backend. Use the ndk backend.
The ndk_platform backend will soon be deprecated because the ndk backend
can serve the same purpose. This is to eliminate the confusion about
having two variants (ndk and ndk_platform) for the same 'ndk' backend.

Bug: 161456198
Test: m
Change-Id: Ibeb4178f99857be75bb5f83a073a2d679058d921
2021-07-27 12:20:26 +09:00
Janis Danisevskis
811b97c066 Merge "Keystore 2.0: Remove Keystore 1.0 and remaining references" 2021-04-07 19:30:12 +00:00
Janis Danisevskis
f985e439ec Keystore 2.0: Update service name to canonical name.
Bug: 179907868
Test: N/A
Change-Id: Ia536a92d212f42af32ed485e19c82b84b0905dc8
2021-03-22 15:22:18 -07:00
Janis Danisevskis
2437fde7a6 Keystore 2.0: Remove Keystore 1.0 and remaining references
* Remove superseded keystore engine backends.
* Remove keystore_cli.
* Update keystoer_cli_v2 to use Keystore 2.0.
* Update confirmationui invocation test.
* Remove reference to enable keystore2 property from keystore2.rc.

Test: N/A
Bug: 171305684

Change-Id: I855dead9d95c2c8cfa451944087bc8290871c0e5
2021-03-22 14:34:45 -07:00
Greg Kaiser
33bdf3bbed Keystore 2.0: Small performance gain
When 'alias' does not start with 'keystore2_grant_id_prefix',
we'll stop looking immediately, instead of continuing to look
throughout 'alias' for further substring matches.

Test: TreeHugger
Bug: 173546268
Bug: 171305607
Bug: 175068876
Change-Id: I40057abce165b18e6bc0cb38daebef81401b5a72
2021-02-25 07:52:15 -08:00
Janis Danisevskis
670122f587 Keystore 2.0: Add keystore2 support to the keystore-engine.
Test: ???
Bug: 173546268
Bug: 171305607
Bug: 175068876
Change-Id: Ib44a8787d31a994453ab56022546cfbc5b76516e
2021-02-24 12:32:32 -08:00
Bob Badour
4c7858c848 [LSC] Add LOCAL_LICENSE_KINDS to system/security
Added SPDX-license-identifier-Apache-2.0 to:
  fsverity_init/Android.bp
  identity/Android.bp
  keystore/tests/Android.bp
  keystore2/Android.bp
  keystore2/aaid/Android.bp
  keystore2/aidl/Android.bp
  keystore2/apc_compat/Android.bp
  keystore2/selinux/Android.bp
  keystore2/src/crypto/Android.bp
  keystore2/src/km_compat/Android.bp
  ondevice-signing/Android.bp
  provisioner/Android.bp

Added SPDX-license-identifier-Apache-2.0 SPDX-license-identifier-BSD to:
  Android.bp
  keystore/Android.bp

Added SPDX-license-identifier-BSD to:
  keystore-engine/Android.bp

Bug: 68860345
Bug: 151177513
Bug: 151953481

Test: m all

Exempt-From-Owner-Approval: janitorial work
Change-Id: Ic9e19695bd19c3f127dfd545df60e4c9df89af77
2021-02-14 10:37:25 -08:00
Rob Barnes
3af223fde0 Allow for input_data on finish.
Test: Keystore CTS tests

Change-Id: I22e69079e3ad5462ded2c7b71274c29ba5ef58d0
2019-11-14 16:43:12 -07:00
Steven Moreland
de99a52dc4 Remove libhwbinder/libhidltransport deps
Since these were combined into libhidlbase.

Bug: 135686713
Test: build only (libhwbinder/libhidltransport are empty)
Change-Id: I940228446b6f5b747399b408ad9af652ac618fda
2019-09-05 14:18:17 -07:00
David Benjamin
dc4d142303 Replace custom BoringSSL scopers with bssl::UniquePtr.
BoringSSL already provides C++ scopers.

Test: mma
Change-Id: I34d4ec36fc0b51750560be0886768a83fe69fbf5
2019-08-08 13:13:54 -04:00
Janis Danisevskis
61aea51375 keystore_backend_binder: fix misinterpretation of getKeyCharacteristics return value.
The keystore backend used by racoon interprets the return value of
getKeyCharacteristics such that it thinks that it failed when it didn't.

Test: Initiate VPN connection with racoon.
Bug: 120024003
Change-Id: Ibe936a2d2d81181c10f0dd1075cc5ab3646f736e
2019-03-13 14:34:06 -07:00
Treehugger Robot
538a4e789e Merge "C++17 is now the default." 2018-12-05 20:41:50 +00:00
Elliott Hughes
9db4be105a C++17 is now the default.
Test: builds
Change-Id: Ibd6569c25f4ddfed3fd0cec771fba72cd5b9bd14
2018-12-04 13:06:50 -08:00
Branden Archer
7cb02e3c8e Use stream operator to report result code
The cast operator for KeyStoreNativeReturnCode and
KeyStoreNativeReturnCode will be removed later.
There already exists a stream operator to get
at the underlying value. Use that instead.

Bug: 119771891
Test: Built for walleye successfully, basic operations with
      keystore_cli_v2 tool work correctly.
Change-Id: I357e0582841b1deadbffd59bb49b5ae8542c9aee
2018-11-21 13:45:19 -08:00
Dan Willemsen
8bb8464d12 Convert keystore-engine to Android.bp
See build/soong/README.md for more information

Test: cd system/security/keystore-engine; mma
Change-Id: I7ca61f05581aec723e9404c63b45ceb8180938f2
2018-11-16 19:14:53 -08:00
Janis Danisevskis
ba2985a435 Fix keystore_backend_binder
Since the keystore AIDL interface became asynchronous we need a thread to handle the
callbacks.

With this patch keystore_backend_binder starts a thread pool when a
backend is created.

Also change keystore_cli_v2 to use startThreadPool instead of starting a
binder thread explicitely.

Bug: 111443219
Change-Id: Ic5b19d95f51a24d823825d5874ec85eeabd9ef5f
2018-11-15 16:24:10 -08: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
Janis Danisevskis
e5a09aac43 Remove legacy functions from IKeystoreService.aidl
In preparation for making the keystore service asynchronous we remove
redundant legacy functionality from the protocol.

This patch removes the functions get_pubkey, sign, verify, generate,
and import_key. Which have long been superseded by exportKey
(get_pubkey), begin/update/finish (sign, verify), generateKey
(generate), and importKey (import_key).

This patch also removes the implementations of these functions from
key_store_service and updates keystore-engine which still used the
legacy functionality.

It also remove the call isOperationAuthorized which was unused.

Test: Keystore CTS tests
Bug: 109769728
Change-Id: I0de359b3e43fd72faa9d1511f84b7c024968c884
2018-10-31 14:31:26 -07: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
Yi Kong
e353f25791 Modernize codebase by replacing NULL with nullptr
Fixes -Wzero-as-null-pointer-constant warning.

Test: m
Bug: 68236239
Change-Id: I41cd58617d6df6de7942a541fb6dc9519c70bef0
2018-07-30 01:40:01 -07:00
David Benjamin
8bc0be07d6 Merge "Remove RSA_FLAG_CACHE_PUBLIC." am: 6ec80146e5 am: de77a0910b
am: da0d915dfe

Change-Id: I44c48b7c8d6060ecf7c98c113fe3d29f95dddbf9
2017-12-18 15:59:56 +00:00
David Benjamin
48d2ea912e Remove RSA_FLAG_CACHE_PUBLIC.
This flag hasn't done anything in BoringSSL since March 2016.

Test: mma
Change-Id: I3972d7c006daa4370772363d7debf64b0c9713da
2017-12-15 18:37:02 -05:00
Dmitry Dementyev
ab8aa1c0a6 Make libkeystore_aidl shared and export to PDK.
Bug: 69539820
Test: manual

Change-Id: I6b8e8543b89245062790443f1e8b759418f7c162
2017-11-29 14:07:22 -08: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
Robert Sloan
a786d0becd Merge "Switch *_METHOD to a more future-proof pattern."
am: f3147f209c

Change-Id: I68777f100f68cfdcf36d9a79b0c72433764cc429
2017-09-20 16:25:58 +00:00
Robert Sloan
29f72ecdfd Switch *_METHOD to a more future-proof pattern.
This matches the other uses in Android and would have avoided
https://android-review.googlesource.com/c/423260/.

(cherry-picked from 472d59a651 on git_master)

Test: mma
Change-Id: I81f6092ab50ff408a48f18bcbca2a50cf9717ca6
2017-09-20 01:47:57 +00:00
Robert Sloan
472d59a651 Switch *_METHOD to a more future-proof pattern.
This merges go/aog/424219 into master (unfortunately, the
implementations are meaningfully different).

This matches the other uses in Android and would have avoided
https://android-review.googlesource.com/c/423260/.

Test: mma
Change-Id: I81f6092ab50ff408a48f18bcbca2a50cf9717ca6
2017-07-14 12:39:37 -07:00
Rob Sloan
ae9fa426cb Merge "Update BoringSSL structs in keystore-engine." am: 975e1aae69 am: 78505bae4c
am: 7d6eedfc47

Change-Id: Ib22db541b587fdde996d51660eb6f21e19875c13
2017-06-27 17:45:37 +00:00
Rob Sloan
78505bae4c Merge "Update BoringSSL structs in keystore-engine."
am: 975e1aae69

Change-Id: I4cd2a30d7281476eb30083dc04187784f8dad445
2017-06-27 17:38:12 +00:00
Robert Sloan
0a7e807721 Update BoringSSL structs in keystore-engine.
Test: None yet.
Change-Id: I61fef8270a7fce9e891cbb64cfdf082adf630921
2017-06-26 12:42:55 -07:00
Janis Danisevskis
ccfff10f66 Remove use of UniquePtr from keystore
Remove UniquePtr from keystore in favour of std::unique_ptr

Change-Id: I8e02adab4326028e26dbf59ac836679abe2a40de
2017-05-01 12:34:46 -07:00
Jiyong Park
ecb258e775 fix: wifi doesn't work on the generic system image
libkeystore-wifi-hidl and libkeystore-engine-wifi-hidl are required by
/vendor/bin/hw/wpa_supplicant. They are installed to /system partition.
This does not cause any problem as long as both /system and /vendor
partitions are built for the same target product, as we do for most of
our products.

However, it becomes a problem when we build only the /system partition
for the generic AOSP system.img. In that case, the libs are not
installed to the partition since we don't build vendor image for the
target and thus wpa_supplicant (and its dependencies as well) aren't
on the list of dmoules to be built/installed.

Moving them to vendor partition by adding LOCAL_VENDOR_MODULE := true
solves the problem.

Bug: 37126829
Test: basic functionalities of wifi work on marlin/sailfish with
system.img built from aosp_arm64_ab.

Change-Id: I783756a5848786b15c1f227f06a1ee2e291d3ce9
2017-04-11 09:12:00 +09:00
Steven Moreland
4cb6f38017 Fix transitive include.
Was relying on include from MQDescriptor.h

Test: pass
Change-Id: Ic3f24fea3875ed1f598b18e4a1fa05c226a86037
2017-04-06 12:41:59 -07:00
Roshan Pius
30b220e734 keystore-engine: Couple of bug fixes for HIDL keystore
Fixes for issues found in wifi integration tests:
1. ensure_keystore_engine() needs to be invoked before we access
|g_keystore_backend|.
2. The HIDL backends need to return 0 when the operation succeeds.

Bug: 34603782
Test: Manual tests.
Change-Id: If61d3bef27dab6f4fb73113f0ed6d3e784a29f32
2017-04-03 13:50:00 -07:00
Roshan Pius
e653c93db1 keystore: Run Wifi keystore HAL in keystore daemon
The wifi keystore hal will run in the context of the main keystore
daemon.

Also,
Use the new IKeystore::tryGetService() for retrieveing the HAL service.

Bug: 34603782
Test: Able to connect to wifi passpoint networks.

Change-Id: I1436ea83166e5ad17372d98b0fd699c0dd732a11
2017-03-30 13:04:46 -07:00
Paul Stewart
bf7fc8df76 Add a HIDL-based keystore_get variant
Create a "keystore_get" library that uses the HIDL path insted
of using binder directly.

Bug: 34603782
Test: Able to connect to wifi passpoint networks.
Change-Id: I0f545ea104e3f27bebd262bc5a2e79f6b517c972
2017-03-29 11:29:43 -07:00
Paul Stewart
657356c169 Add HIDL backend to keystore service
This CL adds variants of the public key retrieval and signing
routine which use the WiFi Keystore HIDL for the backend.
The Android.mk has been modified to build a second variant of
the library to expose this HIDL backend.  While here, add
guards to all headers.

Bug: 34603782
Test: Able to connect to wifi passpoint networks.
Change-Id: I444ef383e4d3fdabc10c3e44c1bae9747613c8cf
2017-03-29 11:29:43 -07:00
Paul Stewart
ac0ffbf62c Separate the binder backend from android_engine
Create a pure virtual class "KeystoreBackend" which supplies the
crypto methods used by android_engine.  Create a KestoreBackendBinder
class which implements the binder backend as a no-op change that
will allow future backends to be added.

Bug: 34603782
Test: Compiles
Change-Id: I16620aba569bd53290145b2b30242c4888106d0a
2017-03-29 11:29:40 -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
Kenny Root
ddf4742f09 Remove OpenSSL support
Only BoringSSL is supported anymore. The OpenSSL code is not tested.

Test: make -j32
Bug: 31464605
Change-Id: I6394bcf71f9e0b17bd8cbb50f6868df03aa00780
2016-09-16 12:40:13 -07:00
Chih-Hung Hsieh
26275ad6ba Fix misc-macro-parentheses warnings.
Add parentheses around macro arguments used beside binary operators.

Bug: 28705665
Change-Id: I4ea2db63c18e40dabc10d42bfa5c936a71d6c628
2016-05-11 14:26:35 -07:00
David Benjamin
30c77521ca Remove RSA_FLAG_EXT_PKEY from android_engine.cpp.
RSA_FLAG_EXT_PKEY, despite the name, is only about calling the RSA_METHOD's
mod_exp hook while reusing the rest of the RSA_private_transform logic. This
code doesn't provide mod_exp and instead overrides private_transform, so the
flag is a no-op.
2016-03-28 18:06:31 -04:00
Adam Langley
862cf6af40 system/security: remove BORINGSSL_201509 support.
The BORINGSSL_201509 define was used to make updating BoringSSL in
external/boringssl less painful. It allowed code to compile with either
the old BoringSSL (which didn't define BORINGSSL_201509) or with the new
(which does).

Now that the new version has landed, this change removes that support.

Change-Id: I19e661419f830459d015bf14e7905af2ec41b735
2015-09-30 15:06:45 -07:00