• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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 #include "aaid.hpp"
18 
19 #include <keystore/keystore_attestation_id.h>
20 
21 using android::security::gather_attestation_application_id;
22 
aaid_keystore_attestation_id(uint32_t uid,uint8_t * aaid,size_t * aaid_size)23 uint32_t aaid_keystore_attestation_id(uint32_t uid, uint8_t* aaid, size_t* aaid_size) {
24     static_assert(sizeof(uint32_t) == sizeof(uid_t), "uid_t has unexpected size");
25     static_assert(sizeof(uint32_t) == sizeof(android::status_t), "status_t has unexpected size");
26     static_assert(KEY_ATTESTATION_APPLICATION_ID_MAX_SIZE ==
27                       android::security::KEY_ATTESTATION_APPLICATION_ID_MAX_SIZE,
28                   "KEY_ATTESTATION_APPLICATION_ID_MAX_SIZE sizes don't match.");
29     auto result = gather_attestation_application_id(uid);
30     if (!result.isOk()) {
31         return result.status();
32     }
33     if (result.value().size() > KEY_ATTESTATION_APPLICATION_ID_MAX_SIZE) {
34         return ::android::NO_MEMORY;
35     }
36     if (*aaid_size != KEY_ATTESTATION_APPLICATION_ID_MAX_SIZE) {
37         return ::android::BAD_VALUE;
38     }
39     std::copy(result.value().begin(), result.value().end(), aaid);
40     *aaid_size = result.value().size();
41     return ::android::OK;
42 }
43