We use the standard Apache 2.0 file header, described in "APPENDIX: How to apply the Apache License to your work." This was primarily automated by running: git ls-tree -r --name-only HEAD | xargs go run ./util/relicense.go See go/boringssl-relicensing-triage for the results of triaging the output of the tool. As part of this, switch from taking fiat-crypto under MIT license to Apache 2.0. (It is licensed under MIT OR Apache-2.0 OR BSD-1-Clause.) The copyright_summary tool can also be used to confirm we didn't accidentally drop any copyright lines: # Run before the CL git grep -l Copyright | xargs go run ./util/copyright_summary.go -out /tmp/old.json # Run after the CL git grep -l Copyright | xargs go run ./util/copyright_summary.go -compare /tmp/old.json Bug: 364634028 Change-Id: I17c50e761e9d077a1f92e25969e50ed35e320c59 Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/75852 Reviewed-by: Bob Beck <bbe@google.com> Commit-Queue: David Benjamin <davidben@google.com> Reviewed-by: Adam Langley <agl@google.com>
75 lines
2.7 KiB
C++
75 lines
2.7 KiB
C++
// Copyright 2016 The BoringSSL 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
|
|
//
|
|
// https://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 <openssl/err.h>
|
|
#include <openssl/mem.h>
|
|
#include <openssl/x509.h>
|
|
|
|
#include "../crypto/x509/internal.h"
|
|
|
|
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) {
|
|
bssl::UniquePtr<X509> x509(d2i_X509(nullptr, &buf, len));
|
|
if (x509 != nullptr) {
|
|
// Extract the public key.
|
|
EVP_PKEY_free(X509_get_pubkey(x509.get()));
|
|
|
|
// Fuzz some deferred parsing.
|
|
x509v3_cache_extensions(x509.get());
|
|
|
|
// Fuzz every supported extension.
|
|
for (int i = 0; i < X509_get_ext_count(x509.get()); i++) {
|
|
const X509_EXTENSION *ext = X509_get_ext(x509.get(), i);
|
|
void *parsed = X509V3_EXT_d2i(ext);
|
|
if (parsed != nullptr) {
|
|
int nid = OBJ_obj2nid(X509_EXTENSION_get_object(ext));
|
|
BSSL_CHECK(nid != NID_undef);
|
|
|
|
// Reserialize the extension. This should succeed if we were able to
|
|
// parse it.
|
|
// TODO(crbug.com/boringssl/352): Ideally we would also assert that
|
|
// |new_ext| is identical to |ext|, but our parser is not strict enough.
|
|
bssl::UniquePtr<X509_EXTENSION> new_ext(
|
|
X509V3_EXT_i2d(nid, X509_EXTENSION_get_critical(ext), parsed));
|
|
BSSL_CHECK(new_ext != nullptr);
|
|
|
|
// This can only fail if |ext| was not a supported type, but then
|
|
// |X509V3_EXT_d2i| should have failed.
|
|
BSSL_CHECK(X509V3_EXT_free(nid, parsed));
|
|
}
|
|
}
|
|
|
|
// Reserialize |x509|. This should succeed if we were able to parse it.
|
|
// TODO(crbug.com/boringssl/352): Ideally we would also assert the output
|
|
// matches the input, but our parser is not strict enough.
|
|
uint8_t *der = nullptr;
|
|
int der_len = i2d_X509(x509.get(), &der);
|
|
BSSL_CHECK(der_len > 0);
|
|
OPENSSL_free(der);
|
|
|
|
// Reserialize |x509|'s TBSCertificate without reusing the cached encoding.
|
|
// TODO(crbug.com/boringssl/352): Ideally we would also assert the output
|
|
// matches the input TBSCertificate, but our parser is not strict enough.
|
|
der = nullptr;
|
|
der_len = i2d_re_X509_tbs(x509.get(), &der);
|
|
BSSL_CHECK(der_len > 0);
|
|
OPENSSL_free(der);
|
|
|
|
BIO *bio = BIO_new(BIO_s_mem());
|
|
X509_print(bio, x509.get());
|
|
BIO_free(bio);
|
|
}
|
|
ERR_clear_error();
|
|
return 0;
|
|
}
|