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> |
Janis Danisevskis | 6a0d998 | 2019-04-30 15:43:59 -0700 | [diff] [blame] | 21 | #include <string> |
Shawn Willden | c1d1fee | 2016-01-26 22:44:56 -0700 | [diff] [blame] | 22 | #include <vector> |
| 23 | |
| 24 | #include <openssl/evp.h> |
| 25 | #include <openssl/pem.h> |
| 26 | |
Janis Danisevskis | ccfff10 | 2017-05-01 11:02:51 -0700 | [diff] [blame] | 27 | #include <memory> |
Shawn Willden | c1d1fee | 2016-01-26 22:44:56 -0700 | [diff] [blame] | 28 | |
Shawn Willden | bb22a6c | 2017-12-06 19:35:28 -0700 | [diff] [blame] | 29 | #include <keystore/keymaster_types.h> |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame] | 30 | |
Shawn Willden | c1d1fee | 2016-01-26 22:44:56 -0700 | [diff] [blame] | 31 | size_t readFully(int fd, uint8_t* data, size_t size); |
| 32 | size_t writeFully(int fd, uint8_t* data, size_t size); |
Janis Danisevskis | 6a0d998 | 2019-04-30 15:43:59 -0700 | [diff] [blame] | 33 | std::string getContainingDirectory(const std::string& filename); |
| 34 | void fsyncDirectory(const std::string& path); |
Shawn Willden | c1d1fee | 2016-01-26 22:44:56 -0700 | [diff] [blame] | 35 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame] | 36 | void add_legacy_key_authorizations(int keyType, keystore::AuthorizationSet* params); |
Shawn Willden | c1d1fee | 2016-01-26 22:44:56 -0700 | [diff] [blame] | 37 | |
| 38 | /** |
| 39 | * Returns the app ID (in the Android multi-user sense) for the current |
| 40 | * UNIX UID. |
| 41 | */ |
| 42 | uid_t get_app_id(uid_t uid); |
| 43 | |
| 44 | /** |
| 45 | * Returns the user ID (in the Android multi-user sense) for the current |
| 46 | * UNIX UID. |
| 47 | */ |
| 48 | uid_t get_user_id(uid_t uid); |
| 49 | |
Janis Danisevskis | c146014 | 2017-12-18 16:48:46 -0800 | [diff] [blame] | 50 | class Blob; |
| 51 | |
Pavel Grafov | cef3947 | 2018-02-12 18:45:02 +0000 | [diff] [blame] | 52 | // Tags for audit logging. Be careful and don't log sensitive data. |
| 53 | // Should be in sync with frameworks/base/core/java/android/app/admin/SecurityLogTags.logtags |
| 54 | constexpr int SEC_TAG_KEY_DESTROYED = 210026; |
| 55 | constexpr int SEC_TAG_KEY_INTEGRITY_VIOLATION = 210032; |
| 56 | constexpr int SEC_TAG_AUTH_KEY_GENERATED = 210024; |
| 57 | constexpr int SEC_TAG_KEY_IMPORTED = 210025; |
| 58 | |
| 59 | void log_key_integrity_violation(const char* name, uid_t uid); |
| 60 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame] | 61 | namespace keystore { |
| 62 | |
Janis Danisevskis | c146014 | 2017-12-18 16:48:46 -0800 | [diff] [blame] | 63 | hidl_vec<uint8_t> blob2hidlVec(const Blob& blob); |
| 64 | |
| 65 | SecurityLevel flagsToSecurityLevel(int32_t flags); |
| 66 | uint32_t securityLevelToFlags(SecurityLevel secLevel); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame] | 67 | |
Shawn Willden | bb22a6c | 2017-12-06 19:35:28 -0700 | [diff] [blame] | 68 | } // namespace keystore |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame] | 69 | |
Shawn Willden | c1d1fee | 2016-01-26 22:44:56 -0700 | [diff] [blame] | 70 | #endif // KEYSTORE_KEYSTORE_UTILS_H_ |