• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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 KEYSTORE_KEYSTORE_UTILS_H_
18 #define KEYSTORE_KEYSTORE_UTILS_H_
19 
20 #include <stdint.h>
21 
22 #include <vector>
23 
24 #include <openssl/evp.h>
25 #include <openssl/pem.h>
26 
27 #include <hardware/keymaster_defs.h>
28 
29 #include <UniquePtr.h>
30 
31 size_t readFully(int fd, uint8_t* data, size_t size);
32 size_t writeFully(int fd, uint8_t* data, size_t size);
33 
34 void add_legacy_key_authorizations(int keyType, std::vector<keymaster_key_param_t>* params);
35 
36 /**
37  * Returns the app ID (in the Android multi-user sense) for the current
38  * UNIX UID.
39  */
40 uid_t get_app_id(uid_t uid);
41 
42 /**
43  * Returns the user ID (in the Android multi-user sense) for the current
44  * UNIX UID.
45  */
46 uid_t get_user_id(uid_t uid);
47 
48 struct EVP_PKEY_Delete {
operatorEVP_PKEY_Delete49     void operator()(EVP_PKEY* p) const { EVP_PKEY_free(p); }
50 };
51 typedef UniquePtr<EVP_PKEY, EVP_PKEY_Delete> Unique_EVP_PKEY;
52 
53 struct PKCS8_PRIV_KEY_INFO_Delete {
operatorPKCS8_PRIV_KEY_INFO_Delete54     void operator()(PKCS8_PRIV_KEY_INFO* p) const { PKCS8_PRIV_KEY_INFO_free(p); }
55 };
56 typedef UniquePtr<PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO_Delete> Unique_PKCS8_PRIV_KEY_INFO;
57 
58 #endif  // KEYSTORE_KEYSTORE_UTILS_H_
59