Shawn Willden | c1d1fee | 2016-01-26 22:44:56 -0700 | [diff] [blame] | 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 | |
Shawn Willden | bb22a6c | 2017-12-06 19:35:28 -0700 | [diff] [blame^] | 20 | #include <cstdint> |
Shawn Willden | c1d1fee | 2016-01-26 22:44:56 -0700 | [diff] [blame] | 21 | #include <vector> |
| 22 | |
| 23 | #include <openssl/evp.h> |
| 24 | #include <openssl/pem.h> |
| 25 | |
Janis Danisevskis | ccfff10 | 2017-05-01 11:02:51 -0700 | [diff] [blame] | 26 | #include <memory> |
Shawn Willden | c1d1fee | 2016-01-26 22:44:56 -0700 | [diff] [blame] | 27 | |
Shawn Willden | bb22a6c | 2017-12-06 19:35:28 -0700 | [diff] [blame^] | 28 | #include <keystore/keymaster_types.h> |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame] | 29 | |
| 30 | #include "blob.h" |
| 31 | |
Shawn Willden | c1d1fee | 2016-01-26 22:44:56 -0700 | [diff] [blame] | 32 | size_t readFully(int fd, uint8_t* data, size_t size); |
| 33 | size_t writeFully(int fd, uint8_t* data, size_t size); |
| 34 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame] | 35 | void add_legacy_key_authorizations(int keyType, keystore::AuthorizationSet* params); |
Shawn Willden | c1d1fee | 2016-01-26 22:44:56 -0700 | [diff] [blame] | 36 | |
| 37 | /** |
| 38 | * Returns the app ID (in the Android multi-user sense) for the current |
| 39 | * UNIX UID. |
| 40 | */ |
| 41 | uid_t get_app_id(uid_t uid); |
| 42 | |
| 43 | /** |
| 44 | * Returns the user ID (in the Android multi-user sense) for the current |
| 45 | * UNIX UID. |
| 46 | */ |
| 47 | uid_t get_user_id(uid_t uid); |
| 48 | |
| 49 | struct EVP_PKEY_Delete { |
| 50 | void operator()(EVP_PKEY* p) const { EVP_PKEY_free(p); } |
| 51 | }; |
Janis Danisevskis | ccfff10 | 2017-05-01 11:02:51 -0700 | [diff] [blame] | 52 | typedef std::unique_ptr<EVP_PKEY, EVP_PKEY_Delete> Unique_EVP_PKEY; |
Shawn Willden | c1d1fee | 2016-01-26 22:44:56 -0700 | [diff] [blame] | 53 | |
| 54 | struct PKCS8_PRIV_KEY_INFO_Delete { |
| 55 | void operator()(PKCS8_PRIV_KEY_INFO* p) const { PKCS8_PRIV_KEY_INFO_free(p); } |
| 56 | }; |
Janis Danisevskis | ccfff10 | 2017-05-01 11:02:51 -0700 | [diff] [blame] | 57 | typedef std::unique_ptr<PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO_Delete> Unique_PKCS8_PRIV_KEY_INFO; |
Shawn Willden | c1d1fee | 2016-01-26 22:44:56 -0700 | [diff] [blame] | 58 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame] | 59 | namespace keystore { |
| 60 | |
| 61 | inline static hidl_vec<uint8_t> blob2hidlVec(const Blob& blob) { |
| 62 | hidl_vec<uint8_t> result; |
| 63 | result.setToExternal(const_cast<uint8_t*>(blob.getValue()), blob.getLength()); |
| 64 | return result; |
| 65 | } |
| 66 | |
Shawn Willden | bb22a6c | 2017-12-06 19:35:28 -0700 | [diff] [blame^] | 67 | } // namespace keystore |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame] | 68 | |
Shawn Willden | c1d1fee | 2016-01-26 22:44:56 -0700 | [diff] [blame] | 69 | #endif // KEYSTORE_KEYSTORE_UTILS_H_ |