blob: eaa5eb36fc788756ba4e0576cd48c3c7cb446ad5 [file] [log] [blame]
Shawn Willden6507c272016-01-05 22:51:48 -07001/*
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
31size_t readFully(int fd, uint8_t* data, size_t size);
32size_t writeFully(int fd, uint8_t* data, size_t size);
33
34void 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 */
40uid_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 */
46uid_t get_user_id(uid_t uid);
47
48struct EVP_PKEY_Delete {
49 void operator()(EVP_PKEY* p) const { EVP_PKEY_free(p); }
50};
51typedef UniquePtr<EVP_PKEY, EVP_PKEY_Delete> Unique_EVP_PKEY;
52
53struct PKCS8_PRIV_KEY_INFO_Delete {
54 void operator()(PKCS8_PRIV_KEY_INFO* p) const { PKCS8_PRIV_KEY_INFO_free(p); }
55};
56typedef UniquePtr<PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO_Delete> Unique_PKCS8_PRIV_KEY_INFO;
57
58#endif // KEYSTORE_KEYSTORE_UTILS_H_