1 /*
2  * Copyright (C) 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 #pragma once
18 
19 #include <stdbool.h>
20 #include <stddef.h>
21 #include <sys/cdefs.h>
22 
23 #include "vm_payload.h"
24 
25 #if !defined(__INTRODUCED_IN)
26 #define __INTRODUCED_IN(__api_level) /* nothing */
27 #endif
28 
29 // The functions declared here are restricted to VMs created with a config file;
30 // they will fail if called in other VMs. The ability to create such VMs
31 // requires the android.permission.USE_CUSTOM_VIRTUAL_MACHINE permission, and is
32 // therefore not available to privileged or third party apps.
33 
34 // These functions can be used by tests, if the permission is granted via shell.
35 
36 __BEGIN_DECLS
37 
38 /**
39  * Get the VM's DICE attestation chain.
40  *
41  * \param data pointer to size bytes where the chain is written (may be null if size is 0).
42  * \param size number of bytes that can be written to data.
43  *
44  * \return the total size of the chain
45  */
46 size_t AVmPayload_getDiceAttestationChain(void* _Nullable data, size_t size);
47 
48 /**
49  * Get the VM's DICE attestation CDI.
50  *
51  * \param data pointer to size bytes where the CDI is written (may be null if size is 0).
52  * \param size number of bytes that can be written to data.
53  *
54  * \return the total size of the CDI
55  */
56 size_t AVmPayload_getDiceAttestationCdi(void* _Nullable data, size_t size);
57 
58 /**
59  * Requests attestation for the VM for testing only.
60  *
61  * This function is only for testing and will not return a real RKP server backed
62  * certificate chain.
63  *
64  * Prior to calling this function, the caller must provision a key pair to be used in
65  * this function with `VirtualMachineManager#enableTestAttestation`.
66  *
67  * \param challenge A pointer to the challenge buffer.
68  * \param challenge_size size of the challenge. The maximum supported challenge size is
69  *          64 bytes. The status ATTESTATION_ERROR_INVALID_CHALLENGE will be returned if
70  *          an invalid challenge is passed.
71  * \param result The remote attestation result will be filled here if the attestation
72  *               succeeds. The result remains valid until it is freed with
73  *              `AVmPayload_freeAttestationResult`.
74  */
75 AVmAttestationStatus AVmPayload_requestAttestationForTesting(
76         const void* _Nonnull challenge, size_t challenge_size,
77         struct AVmAttestationResult* _Nullable* _Nonnull result) __INTRODUCED_IN(__ANDROID_API_V__);
78 
79 __END_DECLS
80