1/* 2 * Copyright (C) 2017 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 17syntax = "proto3"; 18 19package nugget.app.keymaster; 20 21import "nugget/app/keymaster/keymaster_defs.proto"; 22import "nugget/app/keymaster/keymaster_types.proto"; 23import "nugget/protobuf/options.proto"; 24 25/* 26 * Keymaster service methods. 27 * 28 * TODO: some methods may be implemented in the host side HAL implementation. 29 */ 30service Keymaster { 31 option (nugget.protobuf.app_id) = "KEYMASTER"; 32 option (nugget.protobuf.app_name) = "Keymaster"; 33 option (nugget.protobuf.app_version) = 1; 34 /* 35 * Both request and response buffers are sized such 36 * that a key-blob may be fully contained. 37 * 38 * TODO: revisit this choice in the event that memory 39 * is running out. Supporting smaller buffers will 40 * require that the keymaster app switch from the 41 * transport API to the datagram API. 42 */ 43 option (nugget.protobuf.request_buffer_size) = 3072; 44 option (nugget.protobuf.response_buffer_size) = 2048; 45 46 /* 47 * KM3 methods, from: 48 * ::android::hardware::keymaster::V3_0::IKeymasterDevice 49 */ 50 rpc AddRngEntropy (AddRngEntropyRequest) returns (AddRngEntropyResponse); 51 rpc GenerateKey (GenerateKeyRequest) returns (GenerateKeyResponse); 52 rpc GetKeyCharacteristics (GetKeyCharacteristicsRequest) returns (GetKeyCharacteristicsResponse); 53 rpc ImportKey (ImportKeyRequest) returns (ImportKeyResponse); 54 rpc ExportKey (ExportKeyRequest) returns (ExportKeyResponse); 55 rpc StartAttestKey (StartAttestKeyRequest) returns (StartAttestKeyResponse); 56 rpc UpgradeKey (UpgradeKeyRequest) returns (UpgradeKeyResponse); 57 rpc DeleteKey (DeleteKeyRequest) returns (DeleteKeyResponse); 58 rpc DeleteAllKeys (DeleteAllKeysRequest) returns (DeleteAllKeysResponse); 59 rpc DestroyAttestationIds (DestroyAttestationIdsRequest) returns (DestroyAttestationIdsResponse); 60 rpc BeginOperation (BeginOperationRequest) returns (BeginOperationResponse); 61 rpc UpdateOperation (UpdateOperationRequest) returns (UpdateOperationResponse); 62 rpc FinishOperation (FinishOperationRequest) returns (FinishOperationResponse); 63 rpc AbortOperation (AbortOperationRequest) returns (AbortOperationResponse); 64 65 /* 66 * KM4 methods. 67 */ 68 rpc ImportWrappedKey (ImportWrappedKeyRequest) returns (ImportKeyResponse); 69 70 /* 71 * Vendor specific methods (bootloader, manufacturing, status, 72 * factory reset, upgrade). 73 */ 74 // Only callable by the Bootloader. 75 rpc SetRootOfTrust (SetRootOfTrustRequest) returns (SetRootOfTrustResponse); 76 // Only callable by the Bootloader. 77 rpc SetBootState (SetBootStateRequest) returns (SetBootStateResponse); 78 // Only callable at the Device Factory. 79 rpc ProvisionDeviceIds (ProvisionDeviceIdsRequest) returns (ProvisionDeviceIdsResponse); 80 // Only callable at the Device Factory. 81 rpc ReadTeeBatchCertificate (ReadTeeBatchCertificateRequest) returns (ReadTeeBatchCertificateResponse); 82 83 /* 84 * More KM4 methods. 85 */ 86 rpc GetHmacSharingParameters (GetHmacSharingParametersRequest) returns (GetHmacSharingParametersResponse); 87 rpc ComputeSharedHmac (ComputeSharedHmacRequest) returns (ComputeSharedHmacResponse); 88 89 /* 90 * DTup input session methods. 91 */ 92 rpc HandshakeDTup (DTupHandshakeRequest) returns (DTupHandshakeResponse); 93 rpc FetchDTupInputEvent (DTupFetchInputEventRequest) returns (DTupFetchInputEventResponse); 94 95 /* 96 * More vendor specific methods. 97 */ 98 // Only callable once per boot. 99 rpc SetSystemVersionInfo (SetSystemVersionInfoRequest) returns (SetSystemVersionInfoResponse); 100 rpc GetBootInfo (GetBootInfoRequest) returns (GetBootInfoResponse); 101 102 /* 103 * Called during provisioning by the CitadelProvision tool. 104 */ 105 rpc ProvisionPresharedSecret (ProvisionPresharedSecretRequest) returns (ProvisionPresharedSecretResponse); 106 107 /* 108 * Additional attestation methods. 109 */ 110 rpc ContinueAttestKey(ContinueAttestKeyRequest) returns (ContinueAttestKeyResponse); 111 rpc FinishAttestKey(FinishAttestKeyRequest) returns (FinishAttestKeyResponse); 112 113 /* 114 * More vendor specific methods. 115 */ 116 rpc ProvisionCertificates(ProvisionCertificatesRequest) returns (ProvisionCertificatesResponse); 117 118 /* 119 * KM4.1 methods. 120 */ 121 rpc DeviceLocked(DeviceLockedRequest) returns (DeviceLockedResponse); 122 rpc EarlyBootEnded(EarlyBootEndedRequest) returns (EarlyBootEndedResponse); 123 124 /* 125 * More vendor specific methods. 126 */ 127 rpc ReadCertificate(ReadCertificateRequest) returns (ReadCertificateResponse); 128 rpc IdentityStartAttestKey (IdentityStartAttestKeyRequest) returns (IdentityStartAttestKeyResponse); 129 rpc IdentityFinishAttestKey (IdentityFinishAttestKeyRequest) returns (IdentityFinishAttestKeyResponse); 130 131 /* 132 * Resume-on-Reboot implementation. 133 */ 134 rpc VigoReadVS(VigoReadVSRequest) returns (VigoReadVSResponse); 135 rpc VigoStartChannel(VigoStartChannelRequest) 136 returns (VigoStartChannelResponse); 137 rpc VigoStoreSecret(VigoStoreSecretRequest) returns (VigoStoreSecretResponse); 138 rpc VigoReleaseSecret(VigoReleaseSecretRequest) 139 returns (VigoReleaseSecretResponse); 140 141 /* 142 * pKVM implementation 143 */ 144 rpc GetPerFactoryResetValue(GetPerFactoryResetValueRequest) returns (GetPerFactoryResetValueResponse); 145 146 /* 147 * RKP implementation 148 */ 149 rpc GenerateRkpKey(GenerateRkpKeyRequest) returns (GenerateRkpKeyResponse); 150 rpc GenerateRkpCsr(GenerateRkpCsrRequest) returns (GenerateRkpCsrResponse); 151 152 /* 153 * Vendor specific method. To export IMEI/DSU to trusty only 154 */ 155 rpc ExportDeviceIds(ExportDeviceIdsRequest) returns (ExportDeviceIdsResponse); 156 157 /* 158 * RKP v3 implementation 159 */ 160 rpc GenerateRkpCsrV2(GenerateRkpCsrV2Request) returns (GenerateRkpCsrV2Response); 161 // These are implemented with a enum, so new RPCs must be appended, and 162 // deprecated RPCs need placeholders. 163} 164 165/* 166 * KM3 messages. 167 */ 168 169// AddEntropy 170message AddRngEntropyRequest { 171 bytes data = 1; 172} 173message AddRngEntropyResponse { 174 ErrorCode error_code = 1; 175} 176 177// GenerateKey 178message GenerateKeyRequest { 179 KeyParameters params = 1; 180 uint64 creation_time_ms = 2; // Rough current time (ms since epoch). 181} 182message GenerateKeyResponse { 183 ErrorCode error_code = 1; 184 KeyBlob blob = 2; 185 KeyCharacteristics characteristics = 3; 186} 187 188// GetKeyCharacteristics 189message GetKeyCharacteristicsRequest { 190 KeyBlob blob = 1; 191 bytes client_id = 2; 192 bytes app_data = 3; 193} 194message GetKeyCharacteristicsResponse { 195 ErrorCode error_code = 1; 196 KeyCharacteristics characteristics = 2; 197} 198 199// ImportKey 200message ImportKeyRequest { 201 KeyParameters params = 1; 202 RSAKey rsa = 2; 203 ECKey ec = 3; 204 SymmetricKey symmetric_key = 4; 205 uint64 creation_time_ms = 5; // Rough current time (ms since epoch). 206}; 207message ImportKeyResponse { 208 ErrorCode error_code = 1; 209 KeyBlob blob = 2; 210 KeyCharacteristics characteristics = 3; 211 OperationHandle handle = 4; 212}; 213 214// ExportKey 215message ExportKeyRequest { 216 KeyFormat format = 1; 217 KeyBlob blob = 2; 218 bytes client_id = 3; 219 bytes app_data = 4; 220}; 221message ExportKeyResponse { 222 ErrorCode error_code = 1; 223 Algorithm algorithm = 2; 224 RSAKey rsa = 3; 225 ECKey ec = 4; 226}; 227 228// StartAttestKey 229message StartAttestKeyRequest { 230 KeyBlob blob = 1; 231 KeyParameters params = 2; 232 uint32 attestation_app_id_len = 3; 233 AttestationSelector selector = 4; 234 bytes not_before = 5; // strftime('%Y%m%d%H%M%SZ') [15 octects] 235 bytes not_after = 6; // strftime('%Y%m%d%H%M%SZ') [15 octects] 236 bytes caller_issuer_subj_name = 7; 237 KeyParameters caller_key_params = 8; 238} 239message StartAttestKeyResponse { 240 ErrorCode error_code = 1; 241 OperationHandle handle = 2; 242 bytes certificate_prologue = 3; 243} 244 245// ContinueAttestKeyRequest 246message ContinueAttestKeyRequest { 247 OperationHandle handle = 1; 248 // bytes attestation_app_id = 2; // Unused, contained within params 249 KeyParameters params = 3; 250} 251message ContinueAttestKeyResponse { 252 ErrorCode error_code = 1; 253 bytes certificate_body = 2; 254} 255 256// FinishAttestKeyRequest 257message FinishAttestKeyRequest { 258 OperationHandle handle = 1; 259 KeyBlob caller_blob = 2; 260 KeyParameters caller_key_params = 3; 261} 262message FinishAttestKeyResponse { 263 ErrorCode error_code = 1; 264 bytes certificate_epilogue = 2; 265 ChipFusing chip_fusing = 3; 266 bool nodelocked_ro = 4; 267} 268 269// UpgradeKey 270message UpgradeKeyRequest { 271 KeyBlob blob = 1; 272 KeyParameters params = 2; 273} 274message UpgradeKeyResponse { 275 ErrorCode error_code = 1; 276 KeyBlob blob = 2; 277} 278 279// DeleteKey 280message DeleteKeyRequest { 281 KeyBlob blob = 1; 282} 283message DeleteKeyResponse { 284 ErrorCode error_code = 1; 285} 286 287// DeleteAllKeys 288message DeleteAllKeysRequest {} 289message DeleteAllKeysResponse { 290 ErrorCode error_code = 1; 291} 292 293// DestroyAttestationIds 294message DestroyAttestationIdsRequest {} 295message DestroyAttestationIdsResponse { 296 ErrorCode error_code = 1; 297} 298 299// BeginOperation 300message BeginOperationRequest { 301 KeyPurpose purpose = 1; 302 KeyBlob blob = 2; 303 KeyParameters params = 3; 304 HardwareAuthToken auth_token = 4; 305} 306message BeginOperationResponse { 307 ErrorCode error_code = 1; 308 KeyParameters params = 2; 309 OperationHandle handle = 3; 310 Algorithm algorithm = 4; 311 uint32 key_bits = 5; 312} 313 314// UpdateOperation 315message UpdateOperationRequest { 316 OperationHandle handle = 1; 317 KeyParameters params = 2; 318 bytes input = 3; 319 HardwareAuthToken auth_token = 4; 320 VerificationToken verification_token = 5; 321} 322message UpdateOperationResponse { 323 ErrorCode error_code = 1; 324 uint32 consumed = 2; 325 KeyParameters params = 3; 326 bytes output = 4; 327} 328 329// FinishOperation 330message FinishOperationRequest { 331 OperationHandle handle = 1; 332 KeyParameters params = 2; 333 bytes input = 3; 334 bytes signature = 4; 335 HardwareAuthToken auth_token = 5; 336 VerificationToken verification_token = 6; 337}; 338message FinishOperationResponse { 339 ErrorCode error_code = 1; 340 KeyParameters params = 2; 341 bytes output = 3; 342}; 343 344// AbortOperation 345message AbortOperationRequest { 346 OperationHandle handle = 1; 347}; 348message AbortOperationResponse { 349 ErrorCode error_code = 1; 350}; 351 352/* 353 * KM4 messages. 354 */ 355 356// ImportWrappedKey 357message ImportWrappedKeyRequest { 358 uint32 key_format = 1; 359 KeyParameters params = 2; 360 bytes rsa_envelope = 3; 361 bytes initialization_vector = 4; // Fixed sized array. 362 bytes encrypted_import_key = 5; 363 bytes aad = 6; 364 bytes gcm_tag = 7; // Fixed sized array. 365 KeyBlob wrapping_key_blob = 8; 366 bytes masking_key = 9; // Fixed sized array. 367 uint64 creation_time_ms = 10; // Rough current time (ms since epoch). 368 ImportWrappedKeyOperation step = 11; 369 OperationHandle handle = 12; 370} 371// ImportWrappedKey returns a ImportKeyResponse. 372 373// GetHmacSharingParametersRequest 374message GetHmacSharingParametersRequest { 375} 376message GetHmacSharingParametersResponse { 377 ErrorCode error_code = 1; 378 HmacSharingParameters hmac_sharing_params = 2; 379} 380 381// ComputeSharedHmacRequest 382message ComputeSharedHmacRequest { 383 repeated HmacSharingParameters hmac_sharing_params = 1; 384} 385message ComputeSharedHmacResponse { 386 ErrorCode error_code = 1; 387 bytes sharing_check = 2; 388} 389 390// DeviceLockedRequest 391message DeviceLockedRequest { 392 bool password_only = 1; 393 VerificationToken verification_token = 2; 394} 395message DeviceLockedResponse { 396 ErrorCode error_code = 1; 397} 398 399// DeviceLockedRequest 400message EarlyBootEndedRequest {} 401message EarlyBootEndedResponse { 402 ErrorCode error_code = 1; 403} 404 405/* 406 * Vendor HAL. 407 */ 408 409// SetRootOfTrustRequest 410// Only callable by the Bootloader. 411message SetRootOfTrustRequest { 412 bytes digest = 1; // This is a SHA256 digest. 413} 414message SetRootOfTrustResponse { 415 // Specified in keymaster_defs.proto:ErrorCode 416 ErrorCode error_code = 1; 417} 418 419// SetBootStateRequest 420// Only callable by the Bootloader. 421message SetBootStateRequest { 422 bool is_unlocked = 1; 423 bytes public_key = 2; // This is a SHA256 digest. 424 BootColor color = 3; 425 uint32 system_version = 4; // Deprecated. 426 uint32 system_security_level = 5; // Patch level of the boot partition. 427 bytes boot_hash = 6; // This is a SHA256 digest. 428 uint32 boot_security_level = 7; 429} 430message SetBootStateResponse { 431 // Specified in keymaster_defs.proto:ErrorCode 432 ErrorCode error_code = 1; 433} 434 435// ProvisionDeviceIds 436// Only callable at the Device Factory 437message ProvisionDeviceIdsRequest { 438 bytes product_brand = 1; 439 bytes product_device = 2; 440 bytes product_name = 3; 441 bytes serialno = 4; 442 bytes product_manufacturer = 5; 443 bytes product_model = 6; 444 bytes imei = 7; 445 bytes meid = 8; 446 bytes imei2 = 9; 447} 448message ProvisionDeviceIdsResponse { 449 // Specified in keymaster_defs.proto:ErrorCode 450 ErrorCode error_code = 1; 451 ChipFusing chip_fusing = 2; 452 bool nodelocked_ro = 3; 453} 454 455message ExportDeviceIdsRequest { 456 bytes challenge = 1; 457 bytes challenge_hmac = 2; 458} 459 460message ExportDeviceIdsResponse { 461 ErrorCode error_code = 1; 462 bytes product_brand = 2; 463 bytes product_device = 3; 464 bytes product_name = 4; 465 bytes serialno = 5; 466 bytes product_manufacturer = 6; 467 bytes product_model = 7; 468 bytes imei = 8; 469 bytes meid = 9; 470 bytes ids_hmac = 10; 471} 472 473// ReadTeeBatchCertificate 474// Only callable at the Device Factory 475message ReadTeeBatchCertificateRequest { 476 Algorithm algorithm = 1; 477} 478message ReadTeeBatchCertificateResponse { 479 ErrorCode error_code = 1; 480 RSAKey rsa = 2; // rsa or ec set based on request algorithm selector. 481 ECKey ec = 3; 482 bytes batch_cert = 4; 483} 484 485message DTupHandshakeRequest { 486 bytes nonce_client = 1; 487} 488 489message DTupHandshakeResponse { 490 DTupError error_code = 1; 491 bytes nonce_citadel = 2; 492 bytes signature = 3; 493} 494 495message DTupFetchInputEventRequest {} 496 497message DTupFetchInputEventResponse { 498 DTupError error_code = 1; 499 DTupKeyEvent event = 2; 500 bytes signature = 3; 501} 502 503message SetSystemVersionInfoRequest { 504 uint32 system_version = 1; // getprop "ro.build.version.release" 505 uint32 system_security_level = 2; // getprop "ro.build.version.security_patch" 506 uint32 vendor_security_level = 3; // getprop "ro.vendor.build.security_patch" 507 uint32 vendor_api_level = 4; 508} 509 510message SetSystemVersionInfoResponse { 511 // Specified in keymaster_defs.proto:ErrorCode 512 ErrorCode error_code = 1; 513} 514 515message GetBootInfoRequest {} 516 517message GetBootInfoResponse { 518 ErrorCode error_code = 1; 519 bool is_unlocked = 2; 520 BootColor boot_color = 3; 521 bytes boot_key = 4; // This is a SHA256 digest. 522 bytes boot_hash = 5; // This is a SHA256 digest. 523} 524 525message ProvisionPresharedSecretRequest { 526 bytes preshared_secret = 1; 527 bool get_status = 2; 528} 529message ProvisionPresharedSecretResponse { 530 ErrorCode error_code = 1; 531 PresharedSecretStatus status = 2; 532 BootColor color = 3; 533 bytes digest = 4; 534} 535 536message ProvisionCertificatesRequest { 537 uint32 block_number = 1; 538 bytes cert_block = 2; 539 bytes digest = 3; 540} 541message ProvisionCertificatesResponse { 542 ErrorCode error_code = 1; 543 CertificateStatus cert_status = 2; 544} 545 546message ReadCertificateRequest { 547 AttestationSelector selector = 1; 548 Algorithm algorithm = 2; 549} 550message ReadCertificateResponse { 551 ErrorCode error_code = 1; 552 Certificate cert = 2; 553} 554 555message VigoReadVSRequest {} 556message VigoReadVSResponse { 557 ErrorCode error_code = 1; 558 VigoKey vs_key = 2; 559} 560message VigoStartChannelRequest { 561 VigoKey client_key = 1; 562} 563message VigoStartChannelResponse { 564 ErrorCode error_code = 1; 565 VigoKey server_key = 2; 566 VigoSignature channel_signature = 3; 567} 568message VigoStoreSecretRequest { 569 VigoKey rs_key = 1; 570 VigoSecret secret_encrypted = 2; 571} 572message VigoStoreSecretResponse { 573 ErrorCode error_code = 1; 574} 575message VigoReleaseSecretRequest { 576 VigoSignature rs_signature = 1; 577} 578message VigoReleaseSecretResponse { 579 ErrorCode error_code = 1; 580 VigoSecret secret_encrypted = 2; 581} 582 583// IdentityStartAttestKey 584message IdentityStartAttestKeyRequest { 585 bytes pubkey = 1; 586 KeyParameters params = 2; 587 uint32 attestation_app_id_len = 3; 588 AttestationSelector selector = 4; 589 bytes not_before = 5; // strftime('%y%m%d%H%M%SZ') [15 octects] 590 bytes not_after = 6; // strftime('%y%m%d%H%M%SZ') [15 octects] 591 uint64 creation_time_ms = 7; // Rough current time (ms since epoch). 592 bool use_km_attest_key = 8; 593 bytes caller_issuer_subj_name = 9; 594} 595message IdentityStartAttestKeyResponse { 596 ErrorCode error_code = 1; 597 OperationHandle handle = 2; 598 bytes certificate_prologue = 3; 599} 600 601// IdentityFinishAttestKeyRequest 602message IdentityFinishAttestKeyRequest { 603 OperationHandle handle = 1; 604 bool use_km_attest_key = 2; 605 KeyBlob caller_blob = 3; 606} 607message IdentityFinishAttestKeyResponse { 608 ErrorCode error_code = 1; 609 bytes certificate_epilogue = 2; 610 ChipFusing chip_fusing = 3; 611 bool nodelocked_ro = 4; 612} 613 614// pKVM messages 615message GetPerFactoryResetValueRequest { 616 bool bootloader_only = 1; 617 bytes input = 2; 618} 619message GetPerFactoryResetValueResponse { 620 ErrorCode error_code = 1; 621 bytes output = 2; 622} 623 624// RKP messages 625message GenerateRkpKeyRequest{ 626 bool test_mode = 1; 627 KeyParameters params = 2; 628 KeyBlob blob = 3; 629} 630message GenerateRkpKeyResponse{ 631 ErrorCode error_code = 1; 632 bytes maced_public_key = 2; 633} 634 635message GenerateRkpCsrRequest{ 636 bool test_mode = 1; 637 KeysToSign keys_to_sign = 2; 638 bytes endpoint_enc_cert_chain = 3; 639 bytes challenge = 4; 640} 641message GenerateRkpCsrResponse{ 642 ErrorCode error_code = 1; 643 bytes keys_to_sign_mac = 2; 644 bytes device_info_blob = 3; 645 bytes protected_data_blob = 4; 646} 647 648message GenerateRkpCsrV2Request{ 649 RkpCsrV2Operation step = 1; 650 bytes challenge = 2; 651 uint32 num_of_public_keys = 3; 652 MacedKey key_to_sign = 4; 653 OperationHandle handle = 5; 654} 655message GenerateRkpCsrV2Response{ 656 ErrorCode error_code = 1; 657 OperationHandle handle = 2; 658 bytes device_info_blob = 3; 659 bytes dice_cert_chain = 4; 660 bytes signature = 5; 661} 662