blob: ce64d42335480728a5fa0d811c17d9b6c8402d68 [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>
Janis Danisevskis6a0d9982019-04-30 15:43:59 -070021#include <string>
Shawn Willdenc1d1fee2016-01-26 22:44:56 -070022#include <vector>
23
24#include <openssl/evp.h>
25#include <openssl/pem.h>
26
Janis Danisevskisccfff102017-05-01 11:02:51 -070027#include <memory>
Shawn Willdenc1d1fee2016-01-26 22:44:56 -070028
Shawn Willdenbb22a6c2017-12-06 19:35:28 -070029#include <keystore/keymaster_types.h>
Janis Danisevskisc7a9fa22016-10-13 18:43:45 +010030
Shawn Willdenc1d1fee2016-01-26 22:44:56 -070031size_t readFully(int fd, uint8_t* data, size_t size);
32size_t writeFully(int fd, uint8_t* data, size_t size);
Janis Danisevskis6a0d9982019-04-30 15:43:59 -070033std::string getContainingDirectory(const std::string& filename);
34void fsyncDirectory(const std::string& path);
Shawn Willdenc1d1fee2016-01-26 22:44:56 -070035
Janis Danisevskisc7a9fa22016-10-13 18:43:45 +010036void add_legacy_key_authorizations(int keyType, keystore::AuthorizationSet* params);
Shawn Willdenc1d1fee2016-01-26 22:44:56 -070037
38/**
39 * Returns the app ID (in the Android multi-user sense) for the current
40 * UNIX UID.
41 */
42uid_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 */
48uid_t get_user_id(uid_t uid);
49
Janis Danisevskisc1460142017-12-18 16:48:46 -080050class Blob;
51
Pavel Grafovcef39472018-02-12 18:45:02 +000052// 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
54constexpr int SEC_TAG_KEY_DESTROYED = 210026;
55constexpr int SEC_TAG_KEY_INTEGRITY_VIOLATION = 210032;
56constexpr int SEC_TAG_AUTH_KEY_GENERATED = 210024;
57constexpr int SEC_TAG_KEY_IMPORTED = 210025;
58
59void log_key_integrity_violation(const char* name, uid_t uid);
60
Janis Danisevskisc7a9fa22016-10-13 18:43:45 +010061namespace keystore {
62
Janis Danisevskisc1460142017-12-18 16:48:46 -080063hidl_vec<uint8_t> blob2hidlVec(const Blob& blob);
64
65SecurityLevel flagsToSecurityLevel(int32_t flags);
66uint32_t securityLevelToFlags(SecurityLevel secLevel);
Janis Danisevskisc7a9fa22016-10-13 18:43:45 +010067
Shawn Willdenbb22a6c2017-12-06 19:35:28 -070068} // namespace keystore
Janis Danisevskisc7a9fa22016-10-13 18:43:45 +010069
Shawn Willdenc1d1fee2016-01-26 22:44:56 -070070#endif // KEYSTORE_KEYSTORE_UTILS_H_