1 /* 2 * Copyright 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef REMOTE_KEYMASTER_H_ 18 #define REMOTE_KEYMASTER_H_ 19 20 #include <keymaster/android_keymaster_messages.h> 21 22 #include "common/libs/security/keymaster_channel.h" 23 24 namespace keymaster { 25 26 class RemoteKeymaster { 27 private: 28 cuttlefish::KeymasterChannel* channel_; 29 const uint32_t message_version_; 30 31 void ForwardCommand(AndroidKeymasterCommand command, const Serializable& req, 32 KeymasterResponse* rsp); 33 34 public: 35 RemoteKeymaster(cuttlefish::KeymasterChannel*, 36 uint32_t message_version = kDefaultMessageVersion); 37 ~RemoteKeymaster(); 38 bool Initialize(); 39 void GetVersion(const GetVersionRequest& request, 40 GetVersionResponse* response); 41 void SupportedAlgorithms(const SupportedAlgorithmsRequest& request, 42 SupportedAlgorithmsResponse* response); 43 void SupportedBlockModes(const SupportedBlockModesRequest& request, 44 SupportedBlockModesResponse* response); 45 void SupportedPaddingModes(const SupportedPaddingModesRequest& request, 46 SupportedPaddingModesResponse* response); 47 void SupportedDigests(const SupportedDigestsRequest& request, 48 SupportedDigestsResponse* response); 49 void SupportedImportFormats(const SupportedImportFormatsRequest& request, 50 SupportedImportFormatsResponse* response); 51 void SupportedExportFormats(const SupportedExportFormatsRequest& request, 52 SupportedExportFormatsResponse* response); 53 void AddRngEntropy(const AddEntropyRequest& request, 54 AddEntropyResponse* response); 55 void Configure(const ConfigureRequest& request, ConfigureResponse* response); 56 void GenerateKey(const GenerateKeyRequest& request, 57 GenerateKeyResponse* response); 58 void GetKeyCharacteristics(const GetKeyCharacteristicsRequest& request, 59 GetKeyCharacteristicsResponse* response); 60 void ImportKey(const ImportKeyRequest& request, ImportKeyResponse* response); 61 void ImportWrappedKey(const ImportWrappedKeyRequest& request, 62 ImportWrappedKeyResponse* response); 63 void ExportKey(const ExportKeyRequest& request, ExportKeyResponse* response); 64 void AttestKey(const AttestKeyRequest& request, AttestKeyResponse* response); 65 void UpgradeKey(const UpgradeKeyRequest& request, 66 UpgradeKeyResponse* response); 67 void DeleteKey(const DeleteKeyRequest& request, DeleteKeyResponse* response); 68 void DeleteAllKeys(const DeleteAllKeysRequest& request, 69 DeleteAllKeysResponse* response); 70 void BeginOperation(const BeginOperationRequest& request, 71 BeginOperationResponse* response); 72 void UpdateOperation(const UpdateOperationRequest& request, 73 UpdateOperationResponse* response); 74 void FinishOperation(const FinishOperationRequest& request, 75 FinishOperationResponse* response); 76 void AbortOperation(const AbortOperationRequest& request, 77 AbortOperationResponse* response); 78 GetHmacSharingParametersResponse GetHmacSharingParameters(); 79 ComputeSharedHmacResponse ComputeSharedHmac( 80 const ComputeSharedHmacRequest& request); 81 VerifyAuthorizationResponse VerifyAuthorization( 82 const VerifyAuthorizationRequest& request); 83 DeviceLockedResponse DeviceLocked(const DeviceLockedRequest& request); 84 EarlyBootEndedResponse EarlyBootEnded(); 85 void GenerateTimestampToken(GenerateTimestampTokenRequest& request, 86 GenerateTimestampTokenResponse* response); 87 88 // CF HAL and remote sides are always compiled together, so will never 89 // disagree about message versions. message_version()90 uint32_t message_version() { return message_version_; } 91 }; 92 93 } // namespace keymaster 94 95 #endif // REMOTE_KEYMASTER_H_ 96