blob: a803582f9e45d7f75baf6c8ddc01bd211cd020e4 [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>
Seth Moore708da932022-08-18 14:38:05 -070026#include <vector>
27
28constexpr size_t kChallengeSize = 16;
29
Seth Mooreb84a1fb2022-09-13 12:02:49 -070030// Contains a the result of an operation that should return cborData on success.
31// Returns an an error message and null cborData on error.
32template <typename T> struct CborResult {
33 std::unique_ptr<T> cborData;
34 std::string errMsg;
Seth Moore708da932022-08-18 14:38:05 -070035};
36
37// Return `buffer` encoded as a base64 string.
38std::string toBase64(const std::vector<uint8_t>& buffer);
39
40// Generate a random challenge containing `kChallengeSize` bytes.
41std::vector<uint8_t> generateChallenge();
42
43// Get a certificate signing request for the given IRemotelyProvisionedComponent.
44// On error, the csr Array is null, and the string field contains a description of
45// what went wrong.
Seth Mooreb84a1fb2022-09-13 12:02:49 -070046CborResult<cppbor::Array>
47getCsr(std::string_view componentName,
Seth Moore04756782022-09-13 16:09:15 -070048 aidl::android::hardware::security::keymint::IRemotelyProvisionedComponent* irpc);
49
50// Generates a test certificate chain and validates it, exiting the process on error.
51void selfTestGetCsr(
52 std::string_view componentName,
53 aidl::android::hardware::security::keymint::IRemotelyProvisionedComponent* irpc);