Files
rk35xx-android14/external/cronet/net/cert/test_root_certs_ios.cc
T
hmz007 36ed224bac Rockchip Anroid14_SDK 20240628-rkr5 (2556df1a)
Signed-off-by: hmz007 <hmz007@gmail.com>
Change-Id: Ib87fdbe7a0be7dc961af3500fe9ea4589a127f9f
2024-10-29 18:12:02 +08:00

59 lines
1.5 KiB
C++

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "net/cert/test_root_certs.h"
#include <Security/Security.h>
#include "build/build_config.h"
#include "net/cert/pki/cert_errors.h"
#include "net/cert/x509_certificate.h"
#include "net/cert/x509_util.h"
#include "net/cert/x509_util_apple.h"
namespace net {
bool TestRootCerts::AddImpl(X509Certificate* certificate) {
base::ScopedCFTypeRef<SecCertificateRef> os_cert(
x509_util::CreateSecCertificateFromX509Certificate(certificate));
if (!os_cert) {
return false;
}
if (CFArrayContainsValue(temporary_roots_,
CFRangeMake(0, CFArrayGetCount(temporary_roots_)),
os_cert.get())) {
return true;
}
CFArrayAppendValue(temporary_roots_, os_cert.get());
return true;
}
void TestRootCerts::ClearImpl() {
CFArrayRemoveAllValues(temporary_roots_);
}
OSStatus TestRootCerts::FixupSecTrustRef(SecTrustRef trust_ref) const {
if (IsEmpty()) {
return noErr;
}
OSStatus status = SecTrustSetAnchorCertificates(trust_ref, temporary_roots_);
if (status) {
return status;
}
// Trust system store in addition to trusting |temporary_roots_|.
return SecTrustSetAnchorCertificatesOnly(trust_ref, false);
}
TestRootCerts::~TestRootCerts() = default;
void TestRootCerts::Init() {
temporary_roots_.reset(
CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks));
}
} // namespace net