-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow partial validation of DAC and CD (for external cloud or custom app based validation) #21725
Merged
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
51afde7
Draft: Allow partial validation of DAC and CD (when PAA list is not l…
chrisdecenzo 2478c68
Draft: Allow partial validation of DAC and CD (when PAA list is not l…
chrisdecenzo a253ab2
Move cloud attestation to a separate class, re-structure default atte…
chrisdecenzo d93e8a3
Move cloud attestation to a separate class, re-structure default atte…
chrisdecenzo 08b9a47
straggler
chrisdecenzo c87bfd0
address feedback
chrisdecenzo 3349401
address feedback
chrisdecenzo f910097
straggler
chrisdecenzo edcd119
fix builds, integration tests
chrisdecenzo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -541,6 +541,17 @@ JNI_METHOD(void, setUseJavaCallbackForNOCRequest) | |
AndroidDeviceControllerWrapper * wrapper = AndroidDeviceControllerWrapper::FromJNIHandle(handle); | ||
|
||
wrapper->GetAndroidOperationalCredentialsIssuer()->SetUseJavaCallbackForNOCRequest(useCallback); | ||
|
||
if (useCallback) | ||
{ | ||
// if we are assigning a callback, then make the device commissioner delegate verification to the cloud | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no cloud involved. Suggest removing the word cloud |
||
wrapper->Controller()->SetDeviceAttestationVerifier(wrapper->GetCloudDACVerifier()); | ||
woody-apple marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
else | ||
{ | ||
// if we are setting callback to null, then make the device commissioner use the default verifier | ||
wrapper->Controller()->SetDeviceAttestationVerifier(GetDeviceAttestationVerifier()); | ||
} | ||
} | ||
|
||
JNI_METHOD(void, updateCommissioningNetworkCredentials) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
169 changes: 169 additions & 0 deletions
169
src/credentials/attestation_verifier/CloudDeviceAttestationVerifier.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
/* | ||
* | ||
* Copyright (c) 2021-2022 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. | ||
*/ | ||
#include "CloudDeviceAttestationVerifier.h" | ||
|
||
#include <controller/OperationalCredentialsDelegate.h> | ||
#include <credentials/CHIPCert.h> | ||
#include <credentials/CertificationDeclaration.h> | ||
#include <credentials/DeviceAttestationConstructor.h> | ||
#include <credentials/DeviceAttestationVendorReserved.h> | ||
#include <crypto/CHIPCryptoPAL.h> | ||
|
||
#include <lib/core/CHIPError.h> | ||
#include <lib/support/CodeUtils.h> | ||
#include <lib/support/ScopedBuffer.h> | ||
#include <lib/support/Span.h> | ||
|
||
using namespace chip::Crypto; | ||
|
||
namespace chip { | ||
namespace Credentials { | ||
|
||
// As per specifications section 11.22.5.1. Constant RESP_MAX | ||
constexpr size_t kMaxResponseLength = 900; | ||
|
||
AttestationVerificationResult CloudDACVerifier::CheckPAA(const DeviceAttestationVerifier::AttestationInfo & info, | ||
DeviceInfoForAttestation & deviceInfo, | ||
Platform::ScopedMemoryBuffer<uint8_t> & paaCert, | ||
MutableByteSpan & paaDerBuffer, AttestationCertVidPid & paaVidPid, | ||
AttestationCertVidPid & paiVidPid) | ||
{ | ||
AttestationVerificationResult attestationError = AttestationVerificationResult::kSuccess; | ||
MutableByteSpan akid(deviceInfo.paaSKID); | ||
|
||
VerifyOrExit(ExtractAKIDFromX509Cert(info.paiDerBuffer, akid) == CHIP_NO_ERROR, | ||
attestationError = AttestationVerificationResult::kPaiFormatInvalid); | ||
|
||
ChipLogProgress(Support, "CloudDACVerifier::CheckPAA skipping vid-scoped PAA check - PAARootStore disabled"); | ||
|
||
exit: | ||
return attestationError; | ||
} | ||
|
||
AttestationVerificationResult CloudDACVerifier::CheckCertTimes(const DeviceAttestationVerifier::AttestationInfo & info, | ||
MutableByteSpan & paaDerBuffer) | ||
{ | ||
AttestationVerificationResult attestationError = AttestationVerificationResult::kSuccess; | ||
|
||
#if !defined(CURRENT_TIME_NOT_IMPLEMENTED) | ||
VerifyOrExit(IsCertificateValidAtCurrentTime(info.dacDerBuffer) == CHIP_NO_ERROR, | ||
attestationError = AttestationVerificationResult::kDacExpired); | ||
#endif | ||
|
||
VerifyOrExit(IsCertificateValidAtIssuance(info.dacDerBuffer, info.paiDerBuffer) == CHIP_NO_ERROR, | ||
attestationError = AttestationVerificationResult::kPaiExpired); | ||
|
||
ChipLogProgress(Support, "CloudDACVerifier::CheckCertTimes skipping PAA expiry check - PAARootStore disabled"); | ||
|
||
exit: | ||
return attestationError; | ||
} | ||
|
||
AttestationVerificationResult CloudDACVerifier::CheckCertChain(const DeviceAttestationVerifier::AttestationInfo & info, | ||
MutableByteSpan & paaDerBuffer) | ||
{ | ||
ChipLogProgress(Support, "CloudDACVerifier::CheckCertChain skipping cert chain check - PAARootStore disabled"); | ||
|
||
return AttestationVerificationResult::kSuccess; | ||
} | ||
|
||
AttestationVerificationResult | ||
CloudDACVerifier::CheckCertDeclaration(const DeviceAttestationVerifier::AttestationInfo & info, MutableByteSpan & paaDerBuffer, | ||
AttestationCertVidPid & dacVidPid, AttestationCertVidPid & paiVidPid, | ||
AttestationCertVidPid & paaVidPid, DeviceInfoForAttestation & deviceInfo) | ||
{ | ||
AttestationVerificationResult attestationError = AttestationVerificationResult::kSuccess; | ||
|
||
ByteSpan certificationDeclarationSpan; | ||
ByteSpan attestationNonceSpan; | ||
uint32_t timestampDeconstructed; | ||
ByteSpan firmwareInfoSpan; | ||
DeviceAttestationVendorReservedDeconstructor vendorReserved; | ||
ByteSpan certificationDeclarationPayload; | ||
|
||
deviceInfo.dacVendorId = dacVidPid.mVendorId.Value(); | ||
deviceInfo.dacProductId = dacVidPid.mProductId.Value(); | ||
deviceInfo.paiVendorId = paiVidPid.mVendorId.Value(); | ||
deviceInfo.paiProductId = paiVidPid.mProductId.ValueOr(0); | ||
deviceInfo.paaVendorId = paaVidPid.mVendorId.ValueOr(VendorId::NotSpecified); | ||
|
||
VerifyOrExit(DeconstructAttestationElements(info.attestationElementsBuffer, certificationDeclarationSpan, attestationNonceSpan, | ||
timestampDeconstructed, firmwareInfoSpan, vendorReserved) == CHIP_NO_ERROR, | ||
attestationError = AttestationVerificationResult::kAttestationElementsMalformed); | ||
|
||
// Verify that Nonce matches with what we sent | ||
VerifyOrExit(attestationNonceSpan.data_equal(info.attestationNonceBuffer), | ||
attestationError = AttestationVerificationResult::kAttestationNonceMismatch); | ||
|
||
ChipLogProgress(Support, "CloudDACVerifier::VerifyAttestationInformation skipping CD signature check - LocalCSAStore disabled"); | ||
VerifyOrExit(CMS_ExtractCDContent(certificationDeclarationSpan, certificationDeclarationPayload) == CHIP_NO_ERROR, | ||
attestationError = AttestationVerificationResult::kPaaFormatInvalid); | ||
|
||
attestationError = ValidateCertificateDeclarationPayload(certificationDeclarationPayload, firmwareInfoSpan, deviceInfo); | ||
VerifyOrExit(attestationError == AttestationVerificationResult::kSuccess, attestationError = attestationError); | ||
exit: | ||
return attestationError; | ||
} | ||
|
||
void CloudDACVerifier::VerifyAttestationInformation(const DeviceAttestationVerifier::AttestationInfo & info, | ||
Callback::Callback<OnAttestationInformationVerification> * onCompletion) | ||
{ | ||
AttestationVerificationResult attestationError = AttestationVerificationResult::kSuccess; | ||
|
||
Platform::ScopedMemoryBuffer<uint8_t> paaCert; | ||
MutableByteSpan paaDerBuffer; | ||
AttestationCertVidPid dacVidPid; | ||
AttestationCertVidPid paiVidPid; | ||
AttestationCertVidPid paaVidPid; | ||
|
||
DeviceInfoForAttestation deviceInfo{ | ||
.vendorId = info.vendorId, | ||
.productId = info.productId, | ||
}; | ||
|
||
VerifyOrExit(!info.attestationElementsBuffer.empty() && !info.attestationChallengeBuffer.empty() && | ||
!info.attestationSignatureBuffer.empty() && !info.paiDerBuffer.empty() && !info.dacDerBuffer.empty() && | ||
!info.attestationNonceBuffer.empty() && onCompletion != nullptr, | ||
attestationError = AttestationVerificationResult::kInvalidArgument); | ||
|
||
VerifyOrExit(info.attestationElementsBuffer.size() <= kMaxResponseLength, | ||
attestationError = AttestationVerificationResult::kInvalidArgument); | ||
|
||
attestationError = CheckDacPaiVidPids(info, dacVidPid, paiVidPid); | ||
VerifyOrExit(attestationError == AttestationVerificationResult::kSuccess, attestationError = attestationError); | ||
|
||
attestationError = CheckAttestationSignature(info); | ||
VerifyOrExit(attestationError == AttestationVerificationResult::kSuccess, attestationError = attestationError); | ||
|
||
attestationError = CheckPAA(info, deviceInfo, paaCert, paaDerBuffer, paaVidPid, paiVidPid); | ||
VerifyOrExit(attestationError == AttestationVerificationResult::kSuccess, attestationError = attestationError); | ||
|
||
attestationError = CheckCertTimes(info, paaDerBuffer); | ||
VerifyOrExit(attestationError == AttestationVerificationResult::kSuccess, attestationError = attestationError); | ||
|
||
attestationError = CheckCertChain(info, paaDerBuffer); | ||
VerifyOrExit(attestationError == AttestationVerificationResult::kSuccess, attestationError = attestationError); | ||
|
||
attestationError = CheckCertDeclaration(info, paaDerBuffer, dacVidPid, paiVidPid, paaVidPid, deviceInfo); | ||
VerifyOrExit(attestationError == AttestationVerificationResult::kSuccess, attestationError = attestationError); | ||
|
||
exit: | ||
onCompletion->mCall(onCompletion->mContext, attestationError); // TODO: is this check getting done? | ||
} | ||
|
||
} // namespace Credentials | ||
} // namespace chip |
52 changes: 52 additions & 0 deletions
52
src/credentials/attestation_verifier/CloudDeviceAttestationVerifier.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* | ||
* 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/attestation_verifier/DefaultDeviceAttestationVerifier.h> | ||
|
||
namespace chip { | ||
namespace Credentials { | ||
|
||
class CloudDACVerifier : public DefaultDACVerifier | ||
{ | ||
public: | ||
CloudDACVerifier() {} | ||
|
||
void VerifyAttestationInformation(const DeviceAttestationVerifier::AttestationInfo & info, | ||
Callback::Callback<OnAttestationInformationVerification> * onCompletion) override; | ||
|
||
protected: | ||
AttestationVerificationResult CheckPAA(const DeviceAttestationVerifier::AttestationInfo & info, | ||
DeviceInfoForAttestation & deviceInfo, Platform::ScopedMemoryBuffer<uint8_t> & paaCert, | ||
MutableByteSpan & paaDerBuffer, Crypto::AttestationCertVidPid & paaVidPid, | ||
Crypto::AttestationCertVidPid & paiVidPid); | ||
|
||
AttestationVerificationResult CheckCertTimes(const DeviceAttestationVerifier::AttestationInfo & info, | ||
MutableByteSpan & paaDerBuffer); | ||
|
||
AttestationVerificationResult CheckCertChain(const DeviceAttestationVerifier::AttestationInfo & info, | ||
MutableByteSpan & paaDerBuffer); | ||
|
||
AttestationVerificationResult CheckCertDeclaration(const DeviceAttestationVerifier::AttestationInfo & info, | ||
MutableByteSpan & paaDerBuffer, Crypto::AttestationCertVidPid & dacVidPid, | ||
Crypto::AttestationCertVidPid & paiVidPid, | ||
Crypto::AttestationCertVidPid & paaVidPid, | ||
DeviceInfoForAttestation & deviceInfo); | ||
}; | ||
|
||
} // namespace Credentials | ||
} // namespace chip |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this TODO intended to remain?