mirror of
https://github.com/apple/swift-crypto
synced 2026-11-28 05:04:21 +00:00
Fix multiple issues in the BoringSSL vendoring script and update BoringSSL to 0226f30467f540a3f62ef48d453f93927da199b6 ### Checklist - [x] I've run tests to see all new and existing tests pass - [x] I've followed the code style of the rest of the project - [x] I've read the [Contribution Guidelines](CONTRIBUTING.md) - [x] I've updated the documentation if necessary ### Motivation: The `vendor-boringssl.sh` script is currently broken in a number of ways, both in general and relative to the latest BoringSSL version: - `--enable-test-discovery` is still in use - The Linux Swift SDKs being generated are out of date (5.10-jammy) - The script does not prefix exported C++ symbols - Invoking the script without a `BORINGSSL_REVISION` results in an unconditional error - The `PATTERNS` list is out of date for the latest BoringSSL - The latest BoringSSL contains a bug which fails to apply `extern "C"` to two exported symbols, allowing for collisions. In addition, the latest BoringSSL has made `BN_MONT_CTX` opaque, necessitating that it be referenced with `OpaquePointer` rather than `UnsafePointer<>`. ### Modifications: The following changes are included: - `--enable-test-discovery` has been removed - `vendor-boringssl.sh` and `generate-linux-sdks.sh` have been updated to use Swift 6.1.2 SDKs built for Ubuntu Noble - The `mangle_cpp_structures` function from `swift-nio-ssl`'s version of `vendor-boringssl.sh` has been copied over (thanks @Lukasa!) - `BORINGSSL_REVISION` is now allowed to be an empty string - The `PATTERNS` array has been updated - A patch has been added which applies `extern "C"` to the functions which should have it - `s/UnsafePointer<BN_MONT_CTX>/OpaquePointer/g` - Updated `CMakeLists.txt` per `update-cmake-lists.sh` - Update BoringSSL to `0226f30467f540a3f62ef48d453f93927da199b6` ### Result: Vendoring the latest BoringSSL will work again. The latest BoringSSL is vendored.
204 lines
5.8 KiB
C++
204 lines
5.8 KiB
C++
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
|
//
|
|
// 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 <assert.h>
|
|
#include <stdio.h>
|
|
|
|
#include <CCryptoBoringSSL_bn.h>
|
|
#include <CCryptoBoringSSL_buffer.h>
|
|
#include <CCryptoBoringSSL_err.h>
|
|
#include <CCryptoBoringSSL_objects.h>
|
|
#include <CCryptoBoringSSL_x509.h>
|
|
|
|
#include "internal.h"
|
|
|
|
|
|
int X509_REQ_print_fp(FILE *fp, X509_REQ *x) {
|
|
BIO *bio = BIO_new_fp(fp, BIO_NOCLOSE);
|
|
if (bio == NULL) {
|
|
OPENSSL_PUT_ERROR(X509, ERR_R_BUF_LIB);
|
|
return 0;
|
|
}
|
|
int ret = X509_REQ_print(bio, x);
|
|
BIO_free(bio);
|
|
return ret;
|
|
}
|
|
|
|
int X509_REQ_print_ex(BIO *bio, X509_REQ *x, unsigned long nmflags,
|
|
unsigned long cflag) {
|
|
long l;
|
|
STACK_OF(X509_ATTRIBUTE) *sk;
|
|
char mlch = ' ';
|
|
|
|
int nmindent = 0;
|
|
|
|
if ((nmflags & XN_FLAG_SEP_MASK) == XN_FLAG_SEP_MULTILINE) {
|
|
mlch = '\n';
|
|
nmindent = 12;
|
|
}
|
|
|
|
if (nmflags == X509_FLAG_COMPAT) {
|
|
nmindent = 16;
|
|
}
|
|
|
|
X509_REQ_INFO *ri = x->req_info;
|
|
if (!(cflag & X509_FLAG_NO_HEADER)) {
|
|
if (BIO_write(bio, "Certificate Request:\n", 21) <= 0 ||
|
|
BIO_write(bio, " Data:\n", 10) <= 0) {
|
|
goto err;
|
|
}
|
|
}
|
|
if (!(cflag & X509_FLAG_NO_VERSION)) {
|
|
l = X509_REQ_get_version(x);
|
|
// Only zero, |X509_REQ_VERSION_1|, is valid but our parser accepts some
|
|
// invalid values for compatibility.
|
|
assert(0 <= l && l <= 2);
|
|
if (BIO_printf(bio, "%8sVersion: %ld (0x%lx)\n", "", l + 1,
|
|
(unsigned long)l) <= 0) {
|
|
goto err;
|
|
}
|
|
}
|
|
if (!(cflag & X509_FLAG_NO_SUBJECT)) {
|
|
if (BIO_printf(bio, " Subject:%c", mlch) <= 0 ||
|
|
X509_NAME_print_ex(bio, ri->subject, nmindent, nmflags) < 0 ||
|
|
BIO_write(bio, "\n", 1) <= 0) {
|
|
goto err;
|
|
}
|
|
}
|
|
if (!(cflag & X509_FLAG_NO_PUBKEY)) {
|
|
if (BIO_write(bio, " Subject Public Key Info:\n", 33) <= 0 ||
|
|
BIO_printf(bio, "%12sPublic Key Algorithm: ", "") <= 0 ||
|
|
i2a_ASN1_OBJECT(bio, ri->pubkey->algor.algorithm) <= 0 ||
|
|
BIO_puts(bio, "\n") <= 0) {
|
|
goto err;
|
|
}
|
|
|
|
const EVP_PKEY *pkey = X509_REQ_get0_pubkey(x);
|
|
if (pkey == NULL) {
|
|
BIO_printf(bio, "%12sUnable to load Public Key\n", "");
|
|
ERR_print_errors(bio);
|
|
} else {
|
|
EVP_PKEY_print_public(bio, pkey, 16, NULL);
|
|
}
|
|
}
|
|
|
|
if (!(cflag & X509_FLAG_NO_ATTRIBUTES)) {
|
|
if (BIO_printf(bio, "%8sAttributes:\n", "") <= 0) {
|
|
goto err;
|
|
}
|
|
|
|
sk = x->req_info->attributes;
|
|
if (sk_X509_ATTRIBUTE_num(sk) == 0) {
|
|
if (BIO_printf(bio, "%12sa0:00\n", "") <= 0) {
|
|
goto err;
|
|
}
|
|
} else {
|
|
size_t i;
|
|
for (i = 0; i < sk_X509_ATTRIBUTE_num(sk); i++) {
|
|
X509_ATTRIBUTE *a = sk_X509_ATTRIBUTE_value(sk, i);
|
|
ASN1_OBJECT *aobj = X509_ATTRIBUTE_get0_object(a);
|
|
|
|
if (X509_REQ_extension_nid(OBJ_obj2nid(aobj))) {
|
|
continue;
|
|
}
|
|
|
|
if (BIO_printf(bio, "%12s", "") <= 0) {
|
|
goto err;
|
|
}
|
|
|
|
const int num_attrs = X509_ATTRIBUTE_count(a);
|
|
const int obj_str_len = i2a_ASN1_OBJECT(bio, aobj);
|
|
if (obj_str_len <= 0) {
|
|
if (BIO_puts(bio, "(Unable to print attribute ID.)\n") < 0) {
|
|
goto err;
|
|
} else {
|
|
continue;
|
|
}
|
|
}
|
|
|
|
int j;
|
|
for (j = 0; j < num_attrs; j++) {
|
|
const ASN1_TYPE *at = X509_ATTRIBUTE_get0_type(a, j);
|
|
const int type = at->type;
|
|
ASN1_BIT_STRING *bs = at->value.asn1_string;
|
|
|
|
int k;
|
|
for (k = 25 - obj_str_len; k > 0; k--) {
|
|
if (BIO_write(bio, " ", 1) != 1) {
|
|
goto err;
|
|
}
|
|
}
|
|
|
|
if (BIO_puts(bio, ":") <= 0) {
|
|
goto err;
|
|
}
|
|
|
|
if (type == V_ASN1_PRINTABLESTRING || type == V_ASN1_UTF8STRING ||
|
|
type == V_ASN1_IA5STRING || type == V_ASN1_T61STRING) {
|
|
if (BIO_write(bio, (char *)bs->data, bs->length) != bs->length) {
|
|
goto err;
|
|
}
|
|
BIO_puts(bio, "\n");
|
|
} else {
|
|
BIO_puts(bio, "unable to print attribute\n");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!(cflag & X509_FLAG_NO_EXTENSIONS)) {
|
|
STACK_OF(X509_EXTENSION) *exts = X509_REQ_get_extensions(x);
|
|
if (exts) {
|
|
BIO_printf(bio, "%8sRequested Extensions:\n", "");
|
|
|
|
for (size_t i = 0; i < sk_X509_EXTENSION_num(exts); i++) {
|
|
const X509_EXTENSION *ex = sk_X509_EXTENSION_value(exts, i);
|
|
if (BIO_printf(bio, "%12s", "") <= 0) {
|
|
goto err;
|
|
}
|
|
const ASN1_OBJECT *obj = X509_EXTENSION_get_object(ex);
|
|
i2a_ASN1_OBJECT(bio, obj);
|
|
const int is_critical = X509_EXTENSION_get_critical(ex);
|
|
if (BIO_printf(bio, ": %s\n", is_critical ? "critical" : "") <= 0) {
|
|
goto err;
|
|
}
|
|
if (!X509V3_EXT_print(bio, ex, cflag, 16)) {
|
|
BIO_printf(bio, "%16s", "");
|
|
ASN1_STRING_print(bio, X509_EXTENSION_get_data(ex));
|
|
}
|
|
if (BIO_write(bio, "\n", 1) <= 0) {
|
|
goto err;
|
|
}
|
|
}
|
|
sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);
|
|
}
|
|
}
|
|
|
|
if (!(cflag & X509_FLAG_NO_SIGDUMP) &&
|
|
!X509_signature_print(bio, x->sig_alg, x->signature)) {
|
|
goto err;
|
|
}
|
|
|
|
return 1;
|
|
|
|
err:
|
|
OPENSSL_PUT_ERROR(X509, ERR_R_BUF_LIB);
|
|
return 0;
|
|
}
|
|
|
|
int X509_REQ_print(BIO *bio, X509_REQ *req) {
|
|
return X509_REQ_print_ex(bio, req, XN_FLAG_COMPAT, X509_FLAG_COMPAT);
|
|
}
|