blob: 8aaebeef4592b7caef06135bfd8e24706fa99786 [file] [log] [blame]
/*
*
* Copyright (c) 2021 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <credentials/DeviceAttestationVendorReserved.h>
#include <lib/core/CHIPError.h>
#include <lib/support/Span.h>
namespace chip {
namespace Credentials {
// CSRNonce and AttestationNonce need to be this size
constexpr size_t kExpectedAttestationNonceSize = 32;
/**
* @brief Take the attestation elements buffer and return each component seperately.
* All output data stays valid while attestationElements buffer is valid.
*
* @param[in] attestationElements ByteSpan containg source of Attestation Elements data.
* @param[out] certificationDeclaration
* @param[out] attestationNonce
* @param[out] timestamp
* @param[out] firmwareInfo ByteSpan containing Firmware Information data if present within attestationElements.
* Empty ByteSpan if not present in attestationElements.
* @param[out] VendorReserved Placeholder to for client to examine VendorReserved elements later
*/
CHIP_ERROR DeconstructAttestationElements(const ByteSpan & attestationElements, ByteSpan & certificationDeclaration,
ByteSpan & attestationNonce, uint32_t & timestamp, ByteSpan & firmwareInfo,
DeviceAttestationVendorReservedDeconstructor & vendorReserved);
/**
* @brief Take each component separately and form the Attestation Elements buffer.
*
* @param[in] certificationDeclaration Valid Certification Declaration data.
* @param[in] attestationNonce Attestation Nonce - 32 octets required.
* @param[in] timestamp Timestamp data in epoch time format.
* @param[in] firmwareInfo Optional Firmware Information data - Can be empty.
* @param[in] VendorReserved Prefilled-in vendor reserved elements to be put into DA elements.
* @param[out] attestationElements Buffer used to write all AttestationElements data, formed with all the data fields above.
* Provided buffer needs to be capable to handle all data fields + tags.
*/
CHIP_ERROR ConstructAttestationElements(const ByteSpan & certificationDeclaration, const ByteSpan & attestationNonce,
uint32_t timestamp, const ByteSpan & firmwareInfo,
DeviceAttestationVendorReservedConstructor & vendorReserved,
MutableByteSpan & attestationElements);
/***
* @brief Count the number of VendorReservedElements in a DeviceAttestation blob
*
* @param[in] attestationElements ByeSpan conitaining source of Attestation Elements data
* @param[out]
* @returns CHIP_NO_ERROR on success
*/
CHIP_ERROR CountVendorReservedElementsInDA(const ByteSpan & attestationElements, size_t & numElements);
/**
* @brief Take each component separately and form the CSRElements buffer.
*
* @param[in] csr Certificate Signing Request body
* @param[in] csrNonce CSR Nonce - 32 octets required.
* @param[in] vendor_reserved1 Optional vendor_reserved1 blob, can be empty to omit
* @param[in] vendor_reserved2 Optional vendor_reserved2 blob, can be empty to omit
* @param[in] vendor_reserved3 Optional vendor_reserved3 blob, can be empty to omit
* @param[out] nocsrElements Buffer used to write all nocsrElements data, formed with all the data fields above.
* Provided buffer needs to be capable to handle all data fields + tags.
*/
CHIP_ERROR ConstructNOCSRElements(const ByteSpan & csr, const ByteSpan & csrNonce, const ByteSpan & vendor_reserved1,
const ByteSpan & vendor_reserved2, const ByteSpan & vendor_reserved3,
MutableByteSpan & nocsrElements);
} // namespace Credentials
} // namespace chip