blob: 3515f489466c1778921b2e96f2400a046c8a11a5 [file] [log] [blame]
Seth Moore708da932022-08-18 14:38:05 -07001/*
2 * Copyright 2022 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#include <aidl/android/hardware/security/keymint/IRemotelyProvisionedComponent.h>
18#include <android/binder_manager.h>
19#include <cppbor.h>
20#include <keymaster/cppcose/cppcose.h>
21
22#include <cstdint>
23#include <memory>
Seth Moore708da932022-08-18 14:38:05 -070024#include <string>
Seth Mooreb84a1fb2022-09-13 12:02:49 -070025#include <string_view>
Sean Thomas61c3ed52024-10-16 11:25:42 +000026#include <unordered_set>
Seth Moore708da932022-08-18 14:38:05 -070027#include <vector>
28
Sean Thomas61c3ed52024-10-16 11:25:42 +000029// Parse a comma-delimited string.
Sean Thomas3f38c1c2024-11-05 10:51:56 +000030// Ignores any empty strings.
Sean Thomas61c3ed52024-10-16 11:25:42 +000031std::unordered_set<std::string> parseCommaDelimited(const std::string& input);
32
Tri Voee773a22022-10-26 16:07:52 -070033// Challenge size must be between 32 and 64 bytes inclusive.
34constexpr size_t kChallengeSize = 64;
Seth Moore708da932022-08-18 14:38:05 -070035
Seth Mooreb84a1fb2022-09-13 12:02:49 -070036// Contains a the result of an operation that should return cborData on success.
37// Returns an an error message and null cborData on error.
38template <typename T> struct CborResult {
39 std::unique_ptr<T> cborData;
40 std::string errMsg;
Seth Moore708da932022-08-18 14:38:05 -070041};
42
Seth Moore708da932022-08-18 14:38:05 -070043// Generate a random challenge containing `kChallengeSize` bytes.
44std::vector<uint8_t> generateChallenge();
45
46// Get a certificate signing request for the given IRemotelyProvisionedComponent.
47// On error, the csr Array is null, and the string field contains a description of
48// what went wrong.
Seth Mooreb84a1fb2022-09-13 12:02:49 -070049CborResult<cppbor::Array>
50getCsr(std::string_view componentName,
Seth Mooreed854b22023-05-31 09:38:47 -070051 aidl::android::hardware::security::keymint::IRemotelyProvisionedComponent* irpc,
Sean Thomas61c3ed52024-10-16 11:25:42 +000052 bool selfTest, bool allowDegenerate, bool requireUdsCerts);