blob: f1211de5f449734bd84ca85ff8eace39575f351b [file] [log] [blame]
Shawn Willdenc1d1fee2016-01-26 22:44:56 -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
Shawn Willdenbb22a6c2017-12-06 19:35:28 -070020#include <cstdint>
Shawn Willdenc1d1fee2016-01-26 22:44:56 -070021#include <vector>
22
23#include <openssl/evp.h>
24#include <openssl/pem.h>
25
Janis Danisevskisccfff102017-05-01 11:02:51 -070026#include <memory>
Shawn Willdenc1d1fee2016-01-26 22:44:56 -070027
Shawn Willdenbb22a6c2017-12-06 19:35:28 -070028#include <keystore/keymaster_types.h>
Janis Danisevskisc7a9fa22016-10-13 18:43:45 +010029
Shawn Willdenc1d1fee2016-01-26 22:44:56 -070030size_t readFully(int fd, uint8_t* data, size_t size);
31size_t writeFully(int fd, uint8_t* data, size_t size);
32
Janis Danisevskisc7a9fa22016-10-13 18:43:45 +010033void add_legacy_key_authorizations(int keyType, keystore::AuthorizationSet* params);
Shawn Willdenc1d1fee2016-01-26 22:44:56 -070034
35/**
36 * Returns the app ID (in the Android multi-user sense) for the current
37 * UNIX UID.
38 */
39uid_t get_app_id(uid_t uid);
40
41/**
42 * Returns the user ID (in the Android multi-user sense) for the current
43 * UNIX UID.
44 */
45uid_t get_user_id(uid_t uid);
46
47struct EVP_PKEY_Delete {
48 void operator()(EVP_PKEY* p) const { EVP_PKEY_free(p); }
49};
Janis Danisevskisccfff102017-05-01 11:02:51 -070050typedef std::unique_ptr<EVP_PKEY, EVP_PKEY_Delete> Unique_EVP_PKEY;
Shawn Willdenc1d1fee2016-01-26 22:44:56 -070051
52struct PKCS8_PRIV_KEY_INFO_Delete {
53 void operator()(PKCS8_PRIV_KEY_INFO* p) const { PKCS8_PRIV_KEY_INFO_free(p); }
54};
Janis Danisevskisccfff102017-05-01 11:02:51 -070055typedef std::unique_ptr<PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO_Delete> Unique_PKCS8_PRIV_KEY_INFO;
Shawn Willdenc1d1fee2016-01-26 22:44:56 -070056
Janis Danisevskisc1460142017-12-18 16:48:46 -080057class Blob;
58
Janis Danisevskisc7a9fa22016-10-13 18:43:45 +010059namespace keystore {
60
Janis Danisevskisc1460142017-12-18 16:48:46 -080061hidl_vec<uint8_t> blob2hidlVec(const Blob& blob);
62
63SecurityLevel flagsToSecurityLevel(int32_t flags);
64uint32_t securityLevelToFlags(SecurityLevel secLevel);
Janis Danisevskisc7a9fa22016-10-13 18:43:45 +010065
Shawn Willdenbb22a6c2017-12-06 19:35:28 -070066} // namespace keystore
Janis Danisevskisc7a9fa22016-10-13 18:43:45 +010067
Shawn Willdenc1d1fee2016-01-26 22:44:56 -070068#endif // KEYSTORE_KEYSTORE_UTILS_H_