aboutsummaryrefslogtreecommitdiff
path: root/nugget/proto/nugget/app/keymaster/keymaster.proto
blob: ceb96a50ed972c1e7de65ac445c66e91fcf8424f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

syntax = "proto3";

package nugget.app.keymaster;

import "nugget/app/keymaster/keymaster_defs.proto";
import "nugget/app/keymaster/keymaster_types.proto";
import "nugget/protobuf/options.proto";

/*
 * Keymaster service methods.
 *
 * TODO: some methods may be implemented in the host side HAL implementation.
 */
service Keymaster {
  option (nugget.protobuf.app_id) = "KEYMASTER";
  option (nugget.protobuf.app_name) = "Keymaster";
  option (nugget.protobuf.app_version) = 1;
  /*
   * Both request and response buffers are sized such
   * that a key-blob may be fully contained.
   *
   * TODO: revisit this choice in the event that memory
   * is running out.  Supporting smaller buffers will
   * require that the keymaster app switch from the
   * transport API to the datagram API.
   */
  option (nugget.protobuf.request_buffer_size) = 3072;
  option (nugget.protobuf.response_buffer_size) = 2048;

  /*
   * KM3 methods, from:
   *     ::android::hardware::keymaster::V3_0::IKeymasterDevice
   */
  rpc AddRngEntropy (AddRngEntropyRequest) returns (AddRngEntropyResponse);
  rpc GenerateKey (GenerateKeyRequest) returns (GenerateKeyResponse);
  rpc GetKeyCharacteristics (GetKeyCharacteristicsRequest) returns (GetKeyCharacteristicsResponse);
  rpc ImportKey (ImportKeyRequest) returns (ImportKeyResponse);
  rpc ExportKey (ExportKeyRequest) returns (ExportKeyResponse);
  rpc StartAttestKey (StartAttestKeyRequest) returns (StartAttestKeyResponse);
  rpc UpgradeKey (UpgradeKeyRequest) returns (UpgradeKeyResponse);
  rpc DeleteKey (DeleteKeyRequest) returns (DeleteKeyResponse);
  rpc DeleteAllKeys (DeleteAllKeysRequest) returns (DeleteAllKeysResponse);
  rpc DestroyAttestationIds (DestroyAttestationIdsRequest) returns (DestroyAttestationIdsResponse);
  rpc BeginOperation (BeginOperationRequest) returns (BeginOperationResponse);
  rpc UpdateOperation (UpdateOperationRequest) returns (UpdateOperationResponse);
  rpc FinishOperation (FinishOperationRequest) returns (FinishOperationResponse);
  rpc AbortOperation (AbortOperationRequest) returns (AbortOperationResponse);

  /*
   * KM4 methods.
   */
  rpc ImportWrappedKey (ImportWrappedKeyRequest) returns (ImportKeyResponse);

  /*
   * Vendor specific methods (bootloader, manufacturing, status,
   * factory reset, upgrade).
   */
  // Only callable by the Bootloader.
  rpc SetRootOfTrust (SetRootOfTrustRequest) returns (SetRootOfTrustResponse);
  // Only callable by the Bootloader.
  rpc SetBootState (SetBootStateRequest) returns (SetBootStateResponse);
  // Only callable at the Device Factory.
  rpc ProvisionDeviceIds (ProvisionDeviceIdsRequest) returns (ProvisionDeviceIdsResponse);
  // Only callable at the Device Factory.
  rpc ReadTeeBatchCertificate (ReadTeeBatchCertificateRequest) returns (ReadTeeBatchCertificateResponse);

  /*
   * More KM4 methods.
   */
  rpc GetHmacSharingParameters (GetHmacSharingParametersRequest) returns (GetHmacSharingParametersResponse);
  rpc ComputeSharedHmac (ComputeSharedHmacRequest) returns (ComputeSharedHmacResponse);

  /*
   * DTup input session methods.
   */
  rpc HandshakeDTup (DTupHandshakeRequest) returns (DTupHandshakeResponse);
  rpc FetchDTupInputEvent (DTupFetchInputEventRequest) returns (DTupFetchInputEventResponse);

  /*
   * More vendor specific methods.
   */
  // Only callable once per boot.
  rpc SetSystemVersionInfo (SetSystemVersionInfoRequest) returns (SetSystemVersionInfoResponse);
  rpc GetBootInfo (GetBootInfoRequest) returns (GetBootInfoResponse);

  /*
   * Called during provisioning by the CitadelProvision tool.
   */
  rpc ProvisionPresharedSecret (ProvisionPresharedSecretRequest) returns (ProvisionPresharedSecretResponse);

  /*
   * Additional attestation methods.
   */
  rpc ContinueAttestKey(ContinueAttestKeyRequest) returns (ContinueAttestKeyResponse);
  rpc FinishAttestKey(FinishAttestKeyRequest) returns (FinishAttestKeyResponse);

  /*
   * More vendor specific methods.
   */
  rpc ProvisionCertificates(ProvisionCertificatesRequest) returns (ProvisionCertificatesResponse);

  // These are implemented with a enum, so new RPCs must be appended, and
  // deprecated RPCs need placeholders.
}

/*
 *  KM3 messages.
 */

// AddEntropy
message AddRngEntropyRequest {
  bytes data = 1;
}
message AddRngEntropyResponse {
  ErrorCode error_code = 1;
}

// GenerateKey
message GenerateKeyRequest {
  KeyParameters params = 1;
}
message GenerateKeyResponse {
  ErrorCode error_code = 1;
  KeyBlob blob = 2;
  KeyCharacteristics characteristics = 3;
}

// GetKeyCharacteristics
message GetKeyCharacteristicsRequest {
  KeyBlob blob = 1;
  bytes client_id = 2;
  bytes app_data = 3;
}
message GetKeyCharacteristicsResponse {
  ErrorCode error_code = 1;
  KeyCharacteristics characteristics = 2;
}

// ImportKey
message ImportKeyRequest {
  KeyParameters params = 1;
  RSAKey rsa = 2;
  ECKey ec = 3;
  SymmetricKey symmetric_key = 4;
};
message ImportKeyResponse {
  ErrorCode error_code = 1;
  KeyBlob blob = 2;
  KeyCharacteristics characteristics = 3;
};

// ExportKey
message ExportKeyRequest {
  KeyFormat format = 1;
  KeyBlob blob = 2;
  bytes client_id = 3;
  bytes app_data = 4;
};
message ExportKeyResponse {
  ErrorCode error_code = 1;
  Algorithm algorithm = 2;
  RSAKey rsa = 3;
  ECKey ec = 4;
};

// StartAttestKey
message StartAttestKeyRequest {
  KeyBlob blob = 1;
  KeyParameters params = 2;
  uint32 attestation_app_id_len = 3;
  AttestationSelector selector = 4;
  bytes not_before = 5;      // strftime('%y%m%d%H%M%SZ') [13 octects]
  bytes not_after = 6;       // strftime('%y%m%d%H%M%SZ') [13 octects]
}
message StartAttestKeyResponse {
  ErrorCode error_code = 1;
  OperationHandle handle = 2;
  bytes certificate_prologue = 3;
}

// ContinueAttestKeyRequest
message ContinueAttestKeyRequest {
  OperationHandle handle = 1;
  //  bytes attestation_app_id = 2;    // Unused, contained within params
  KeyParameters params = 3;
}
message  ContinueAttestKeyResponse {
  ErrorCode error_code = 1;
  bytes certificate_body = 2;
}

// FinishAttestKeyRequest
message FinishAttestKeyRequest {
  OperationHandle handle = 1;
}
message  FinishAttestKeyResponse {
  ErrorCode error_code = 1;
  bytes certificate_epilogue = 2;
  ChipFusing chip_fusing = 3;
  bool nodelocked_ro = 4;
}

// UpgradeKey
message UpgradeKeyRequest {
  KeyBlob blob = 1;
  KeyParameters params = 2;
}
message UpgradeKeyResponse {
  ErrorCode error_code = 1;
  KeyBlob blob = 2;
}

// DeleteKey
message DeleteKeyRequest {
  KeyBlob blob = 1;
}
message DeleteKeyResponse {
  ErrorCode error_code = 1;
}

// DeleteAllKeys
message DeleteAllKeysRequest {}
message DeleteAllKeysResponse {
  ErrorCode error_code = 1;
}

// DestroyAttestationIds
message DestroyAttestationIdsRequest {}
message DestroyAttestationIdsResponse {
  ErrorCode error_code = 1;
}

// BeginOperation
message BeginOperationRequest {
  KeyPurpose purpose = 1;
  KeyBlob blob = 2;
  KeyParameters params = 3;
  HardwareAuthToken auth_token = 4;
}
message BeginOperationResponse {
  ErrorCode error_code = 1;
  KeyParameters params = 2;
  OperationHandle handle = 3;
  Algorithm algorithm = 4;
  uint32 key_bits = 5;
}

// UpdateOperation
message UpdateOperationRequest {
  OperationHandle handle = 1;
  KeyParameters params = 2;
  bytes input = 3;
  HardwareAuthToken auth_token = 4;
  VerificationToken verification_token = 5;
}
message UpdateOperationResponse {
  ErrorCode error_code = 1;
  uint32 consumed = 2;
  KeyParameters params = 3;
  bytes output = 4;
}

// FinishOperation
message FinishOperationRequest {
  OperationHandle handle = 1;
  KeyParameters params = 2;
  bytes input = 3;
  bytes signature = 4;
  HardwareAuthToken auth_token = 5;
  VerificationToken verification_token = 6;
};
message FinishOperationResponse {
  ErrorCode error_code = 1;
  KeyParameters params = 2;
  bytes output = 3;
};

// AbortOperation
message AbortOperationRequest {
  OperationHandle handle = 1;
};
message AbortOperationResponse {
  ErrorCode error_code = 1;
};

/*
 * KM4 messages.
 */

// ImportWrappedKey
message ImportWrappedKeyRequest {
  uint32 key_format = 1;
  KeyParameters params = 2;
  bytes rsa_envelope = 3;
  bytes initialization_vector = 4;   // Fixed sized array.
  bytes encrypted_import_key = 5;
  bytes aad = 6;
  bytes gcm_tag = 7;                 // Fixed sized array.
  KeyBlob wrapping_key_blob = 8;
  bytes masking_key = 9;             // Fixed sized array.
}
// ImportWrappedKey returns a ImportKeyResponse.

// GetHmacSharingParametersRequest
message GetHmacSharingParametersRequest {
}
message GetHmacSharingParametersResponse {
  ErrorCode error_code = 1;
  HmacSharingParameters hmac_sharing_params = 2;
}

// ComputeSharedHmacRequest
message ComputeSharedHmacRequest {
  repeated HmacSharingParameters hmac_sharing_params = 1;
}
message ComputeSharedHmacResponse {
  ErrorCode error_code = 1;
  bytes sharing_check = 2;
}

/*
 * Vendor HAL.
 */

// SetRootOfTrustRequest
// Only callable by the Bootloader.
message SetRootOfTrustRequest {
  bytes digest = 1;                  // This is a SHA256 digest.
}
message SetRootOfTrustResponse {
  // Specified in keymaster_defs.proto:ErrorCode
  ErrorCode error_code = 1;
}

// SetBootStateRequest
// Only callable by the Bootloader.
message SetBootStateRequest {
  bool is_unlocked = 1;
  bytes public_key = 2;              // This is a SHA256 digest.
  BootColor color = 3;
  uint32 system_version = 4;         // Deprecated.
  uint32 system_security_level = 5;  // Patch level of the boot partition.
  bytes boot_hash = 6;               // This is a SHA256 digest.
}
message SetBootStateResponse {
  // Specified in keymaster_defs.proto:ErrorCode
  ErrorCode error_code = 1;
}

// ProvisionDeviceIds
// Only callable at the Device Factory
message ProvisionDeviceIdsRequest {
  bytes product_brand = 1;
  bytes product_device = 2;
  bytes product_name = 3;
  bytes serialno = 4;
  bytes product_manufacturer = 5;
  bytes product_model = 6;
  bytes imei = 7;
  bytes meid = 8;
}
message ProvisionDeviceIdsResponse {
  // Specified in keymaster_defs.proto:ErrorCode
  ErrorCode error_code = 1;
  ChipFusing chip_fusing = 2;
  bool nodelocked_ro = 3;
}

// ReadTeeBatchCertificate
// Only callable at the Device Factory
message ReadTeeBatchCertificateRequest {
  Algorithm algorithm = 1;
}
message ReadTeeBatchCertificateResponse {
  ErrorCode error_code = 1;
  RSAKey rsa = 2;   // rsa or ec set based on request algorithm selector.
  ECKey ec = 3;
  bytes batch_cert = 4;
}

message DTupHandshakeRequest {
  bytes nonce_client = 1;
}

message DTupHandshakeResponse {
  DTupError error_code = 1;
  bytes nonce_citadel = 2;
  bytes signature = 3;
}

message DTupFetchInputEventRequest {}

message DTupFetchInputEventResponse {
  DTupError error_code = 1;
  DTupKeyEvent event = 2;
  bytes signature = 3;
}

message SetSystemVersionInfoRequest {
  uint32 system_version = 1;  // getprop "ro.build.version.release"
  uint32 system_security_level = 2; // getprop "ro.build.version.security_patch"
  uint32 vendor_security_level = 3; // getprop "ro.vendor.build.security_patch"
}

message SetSystemVersionInfoResponse {
  // Specified in keymaster_defs.proto:ErrorCode
  ErrorCode error_code = 1;
}

message GetBootInfoRequest {}

message GetBootInfoResponse {
  ErrorCode error_code = 1;
  bool is_unlocked = 2;
  BootColor boot_color = 3;
  bytes boot_key = 4;               // This is a SHA256 digest.
  bytes boot_hash = 5;              // This is a SHA256 digest.
}

message ProvisionPresharedSecretRequest {
  bytes preshared_secret = 1;
  bool get_status = 2;
}
message ProvisionPresharedSecretResponse {
  ErrorCode error_code = 1;
  PresharedSecretStatus status = 2;
  BootColor color = 3;
  bytes digest = 4;
}

message ProvisionCertificatesRequest {
  uint32 block_number = 1;
  bytes cert_block = 2;
  bytes digest = 3;
}
message ProvisionCertificatesResponse {
  ErrorCode error_code = 1;
  CertificateStatus cert_status = 2;
}