ff3d7f4b83
This patch transitions keystore a threading model with one dispatcher thread and one worker thread per keymaster instance, i.e. fallback, TEE, Strongbox (if available). Singleton objects, such as the user state database, the enforcement policy, and grant database have been moved to KeyStore and were made concurrency safe. Other noteworthy changes in this patch: * Cached key characteristics. The key characteristics file used to hold a limited set of parameters used generate or import the key. This patch introduces a new blob type that holds full characteristics as returned by generate, import, or getKeyCharacteristics, with the original parameters mixed into the software enforced list. When keystore encounters a lagacy characteristics file it will grab the characteristics from keymaster, merge them with the cached parameters, and update the cache file to the new format. If keystore encounters the new cache no call to keymaster will be made for retrieving the key characteristics. * Changed semantic of list. The list call takes a prefix used for filtering key entries. By the old semantic, list would return a list of aliases stripped of the given prefix. By the new semantic list always returns a filtered list of full alias string. Callers may strip prefixes if they are so inclined. * Entertain per keymaster instance operation maps. With the introduction of Strongbox keystore had to deal with multiple keymaster instances. But until now it would entertain a single operations map. Keystore also enforces the invariant that no more than 15 operation slots are used so there is always a free slot available for vold. With a single operation map, this means no more than 15 slots can ever be used although with TEE and Strongbox there are a total of 32 slots. With strongbox implementation that have significantly fewer slots we see another effect of the single operation map. If a slot needs to be freed on Stronbox but the oldest operations are on TEE, the latter will be unnecessarily pruned before a Strongbox slot is freed up. With this patch each keymaster instance has its own operation map and pruning is performed on a per keymaster instance basis. * Introduce KeyBlobEntries which are independent from files. To allow concurrent access to the key blob data base, entries can be individually locked so that operations on entries become atomic. LockedKeyBlobEntries are move only objects that track ownership of an Entry on the stack or in functor object representing keymaster worker requests. Entries must only be locked by the dispatcher Thread. Worker threads can only be granted access to a LockedKeyBlobEntry by the dispatcher thread. This allows the dispatcher thread to execute a barrier that waits until all locks held by workers have been relinquished to perform blob database maintenance operations, e.g., clearing a uid of all entries. * Verification tokens are now acquired asynchronously. When a begin operation requires a verification token a request is submitted to the other keymaster worker while the begin call returns. When the operation commences with update or finish, we block until the verification token becomes available. As of this patch the keystore IPC interface is still synchronous. That is, the dispatcher thread dispatches a request to a worker and then waits until the worker has finished. In a followup patch the IPC interface shall be made asynchronous so that multiple requests may be in flight. Test: Ran full CTS test suite atest android.keystore.cts Bug: 111443219 Bug: 110495056 Change-Id: I305e28d784295a0095a34810d83202f7423498bd
302 lines
6.9 KiB
Text
302 lines
6.9 KiB
Text
cc_defaults {
|
|
name: "keystore_defaults",
|
|
|
|
cflags: [
|
|
"-Wall",
|
|
"-Werror",
|
|
"-Wextra",
|
|
"-Wunused",
|
|
],
|
|
|
|
sanitize: {
|
|
misc_undefined: ["integer"],
|
|
},
|
|
|
|
clang: true,
|
|
cpp_std: "c++17",
|
|
}
|
|
|
|
cc_binary {
|
|
name: "keystore",
|
|
defaults: ["keystore_defaults"],
|
|
|
|
srcs: [
|
|
":IKeyAttestationApplicationIdProvider.aidl",
|
|
"KeyStore.cpp",
|
|
"auth_token_table.cpp",
|
|
"blob.cpp",
|
|
"confirmation_manager.cpp",
|
|
"entropy.cpp",
|
|
"grant_store.cpp",
|
|
"key_config.proto",
|
|
"key_proto_handler.cpp",
|
|
"key_store_service.cpp",
|
|
"keyblob_utils.cpp",
|
|
"keymaster_enforcement.cpp",
|
|
"keymaster_worker.cpp",
|
|
"keystore_attestation_id.cpp",
|
|
"keystore_main.cpp",
|
|
"keystore_utils.cpp",
|
|
"legacy_keymaster_device_wrapper.cpp",
|
|
"operation.cpp",
|
|
"operation_config.proto",
|
|
"operation_proto_handler.cpp",
|
|
"permissions.cpp",
|
|
"user_state.cpp",
|
|
],
|
|
shared_libs: [
|
|
"android.hardware.confirmationui@1.0",
|
|
"android.hardware.keymaster@3.0",
|
|
"android.hardware.keymaster@4.0",
|
|
"android.system.wifi.keystore@1.0",
|
|
"libbase",
|
|
"libbinder",
|
|
"libcrypto",
|
|
"libcutils",
|
|
"libhardware",
|
|
"libhidlbase",
|
|
"libhidltransport",
|
|
"libhwbinder",
|
|
"libkeymaster4support",
|
|
"libkeymaster_messages",
|
|
"libkeymaster_portable",
|
|
"libkeystore_aidl",
|
|
"libkeystore_binder",
|
|
"libkeystore_parcelables",
|
|
"liblog",
|
|
"libprotobuf-cpp-lite",
|
|
"libselinux",
|
|
"libservices",
|
|
"libsoftkeymasterdevice",
|
|
"libutils",
|
|
"libwifikeystorehal",
|
|
],
|
|
init_rc: ["keystore.rc"],
|
|
aidl: {
|
|
include_dirs: ["frameworks/base/core/java/"],
|
|
},
|
|
|
|
product_variables: {
|
|
pdk: {
|
|
enabled: false,
|
|
},
|
|
},
|
|
|
|
required: ["keystore_cli_v2"],
|
|
}
|
|
|
|
cc_binary {
|
|
name: "keystore_cli",
|
|
defaults: ["keystore_defaults"],
|
|
|
|
srcs: ["keystore_cli.cpp"],
|
|
shared_libs: [
|
|
"android.hardware.keymaster@4.0",
|
|
"libbinder",
|
|
"libcrypto",
|
|
"libcutils",
|
|
"libhidlbase",
|
|
"libhwbinder",
|
|
"libkeystore_aidl", // for IKeyStoreService.asInterface()
|
|
"libkeystore_binder",
|
|
"libkeystore_parcelables",
|
|
"liblog",
|
|
"libutils",
|
|
],
|
|
}
|
|
|
|
cc_binary {
|
|
name: "keystore_cli_v2",
|
|
defaults: ["keystore_defaults"],
|
|
|
|
cflags: [
|
|
"-DKEYMASTER_NAME_TAGS",
|
|
"-Wno-unused-parameter",
|
|
],
|
|
srcs: ["keystore_cli_v2.cpp"],
|
|
shared_libs: [
|
|
"android.hardware.confirmationui@1.0",
|
|
"libbinder",
|
|
"android.hardware.keymaster@4.0",
|
|
"libchrome",
|
|
"libutils",
|
|
"libhidlbase",
|
|
"libhwbinder",
|
|
"libkeymaster4support",
|
|
"libkeystore_aidl",
|
|
"libkeystore_binder",
|
|
"libkeystore_parcelables",
|
|
],
|
|
|
|
local_include_dirs: ["include"],
|
|
}
|
|
|
|
cc_library_shared {
|
|
name: "libkeystore_parcelables",
|
|
defaults: ["keystore_defaults"],
|
|
export_include_dirs: ["include"],
|
|
srcs: [
|
|
"KeyAttestationApplicationId.cpp",
|
|
"KeyAttestationPackageInfo.cpp",
|
|
"KeymasterArguments.cpp",
|
|
"KeystoreArguments.cpp",
|
|
"OperationResult.cpp",
|
|
"Signature.cpp",
|
|
"keystore_aidl_hidl_marshalling_utils.cpp",
|
|
],
|
|
shared_libs: [
|
|
"android.hardware.keymaster@4.0",
|
|
"libbinder",
|
|
"libhardware",
|
|
"libhidlbase",
|
|
"libhwbinder",
|
|
"libkeymaster4support",
|
|
"liblog",
|
|
"libprotobuf-cpp-lite",
|
|
"libutils",
|
|
],
|
|
export_shared_lib_headers: [
|
|
"android.hardware.keymaster@4.0",
|
|
"libbinder",
|
|
"libhidlbase",
|
|
"libhwbinder",
|
|
"libkeymaster4support",
|
|
],
|
|
}
|
|
// Library for keystore clients
|
|
cc_library_shared {
|
|
name: "libkeystore_binder",
|
|
defaults: ["keystore_defaults"],
|
|
|
|
srcs: [
|
|
"keyblob_utils.cpp",
|
|
"keystore_client.proto",
|
|
"keystore_client_impl.cpp",
|
|
"keystore_get.cpp",
|
|
],
|
|
shared_libs: [
|
|
"android.hardware.keymaster@4.0",
|
|
"libbinder",
|
|
"libhidlbase",
|
|
"libhwbinder",
|
|
"libkeymaster4support",
|
|
"libkeystore_aidl",
|
|
"libkeystore_parcelables",
|
|
"liblog",
|
|
"libprotobuf-cpp-lite",
|
|
"libutils",
|
|
],
|
|
|
|
proto: {
|
|
type: "lite",
|
|
export_proto_headers: true,
|
|
},
|
|
aidl: {
|
|
export_aidl_headers: true,
|
|
include_dirs: ["frameworks/base/core/java/"],
|
|
},
|
|
export_include_dirs: ["include"],
|
|
export_shared_lib_headers: [
|
|
"android.hardware.keymaster@4.0",
|
|
"libbinder",
|
|
"libhidlbase",
|
|
"libhwbinder",
|
|
"libkeystore_aidl",
|
|
"libkeystore_parcelables",
|
|
],
|
|
}
|
|
|
|
// Library for keystore clients using the WiFi HIDL interface
|
|
cc_library_shared {
|
|
name: "libkeystore-wifi-hidl",
|
|
defaults: ["keystore_defaults"],
|
|
|
|
srcs: ["keystore_get_wifi_hidl.cpp"],
|
|
shared_libs: [
|
|
"android.system.wifi.keystore@1.0",
|
|
"libbase",
|
|
"libhidlbase",
|
|
"libhidltransport",
|
|
"liblog",
|
|
"libutils",
|
|
],
|
|
|
|
export_include_dirs: ["include"],
|
|
|
|
vendor: true,
|
|
}
|
|
|
|
// Library for unit tests
|
|
cc_library_static {
|
|
name: "libkeystore_test",
|
|
defaults: ["keystore_defaults"],
|
|
|
|
srcs: [
|
|
":IKeyAttestationApplicationIdProvider.aidl",
|
|
"auth_token_table.cpp",
|
|
"keystore_attestation_id.cpp",
|
|
"KeyAttestationApplicationId.cpp",
|
|
"KeyAttestationPackageInfo.cpp",
|
|
"Signature.cpp",
|
|
],
|
|
cflags: [ "-O0", ],
|
|
static_libs: ["libgtest_main"],
|
|
shared_libs: [
|
|
"android.hardware.keymaster@4.0",
|
|
"libbinder",
|
|
"libcrypto",
|
|
"libhidlbase",
|
|
"libhwbinder",
|
|
"libkeymaster4support",
|
|
"libutils",
|
|
"libkeystore_aidl",
|
|
"libkeystore_parcelables",
|
|
],
|
|
export_shared_lib_headers: [
|
|
"android.hardware.keymaster@4.0",
|
|
"libhidlbase",
|
|
"libhwbinder",
|
|
"libkeymaster4support",
|
|
],
|
|
|
|
aidl: {
|
|
include_dirs: ["frameworks/base/core/java/"],
|
|
},
|
|
export_include_dirs: ["include"],
|
|
}
|
|
|
|
filegroup {
|
|
name: "keystore_aidl",
|
|
srcs: [
|
|
"binder/android/security/IConfirmationPromptCallback.aidl",
|
|
"binder/android/security/IKeystoreService.aidl",
|
|
],
|
|
path: "binder",
|
|
}
|
|
|
|
cc_library_shared {
|
|
name: "libkeystore_aidl",
|
|
srcs: [":keystore_aidl"],
|
|
aidl: {
|
|
export_aidl_headers: true,
|
|
include_dirs: [
|
|
"system/security/keystore/binder",
|
|
],
|
|
},
|
|
shared_libs: [
|
|
"libbinder",
|
|
"libcutils",
|
|
"libhardware",
|
|
"libhidlbase",
|
|
"libhidltransport",
|
|
"libhwbinder",
|
|
"libkeystore_parcelables",
|
|
"liblog",
|
|
"libselinux",
|
|
"libutils",
|
|
],
|
|
export_shared_lib_headers: [
|
|
"libbinder",
|
|
"libkeystore_parcelables",
|
|
],
|
|
}
|