Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions src/cli/perf_x509.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@
#include <botan/assert.h>

#if defined(BOTAN_HAS_X509)
#include <botan/asn1_time.h>
#include <botan/ber_dec.h>
#include <botan/bigint.h>
#include <botan/der_enc.h>
#include <botan/dns_name.h>
#include <botan/email.h>
#include <botan/pk_algs.h>
#include <botan/pk_keys.h>
#include <botan/rng.h>
#include <botan/x509_builder.h>
#include <botan/x509_ca.h>
#include <botan/x509_ext.h>
#include <botan/x509self.h>
#endif

namespace Botan_CLI {
Expand All @@ -44,14 +47,23 @@ class PerfTest_ASN1_Parsing final : public PerfTest {
}

static CA create_ca(Botan::RandomNumberGenerator& rng) {
auto root_cert_options = Botan::X509_Cert_Options("Benchmark Root/DE/RS/CS");
root_cert_options.dns = "unobtainium.example.com";
root_cert_options.email = "idont@exist.com";
root_cert_options.is_CA = true;

auto root_key = create_private_key(rng);
BOTAN_ASSERT_NONNULL(root_key);
auto root_cert = Botan::X509::create_self_signed_cert(root_cert_options, *root_key, get_hash_function(), rng);

Botan::CertificateParametersBuilder root_cert_params;
root_cert_params.add_common_name("Benchmark Root")
.add_country("DE")
.add_organization("RS")
.add_organizational_unit("CS")
.add_dns(Botan::DNSName::from_string("unobtainium.example.com").value())
.add_email(Botan::EmailAddress::from_string("idont@exist.com").value())
.set_as_ca_certificate();

const auto not_before = std::chrono::system_clock::now();
const auto not_after = not_before + std::chrono::seconds(86400);

auto root_cert = root_cert_params.into_self_signed_cert(
not_before, not_after, *root_key, rng, std::nullopt, get_hash_function());
auto ca = Botan::X509_CA(root_cert, *root_key, get_hash_function(), rng);

return CA{
Expand Down
108 changes: 108 additions & 0 deletions src/lib/ffi/ffi.h
Original file line number Diff line number Diff line change
Expand Up @@ -2704,6 +2704,114 @@ int botan_x509_cert_verify(int* validation_result,
*/
BOTAN_FFI_EXPORT(2, 8) const char* botan_x509_cert_validation_status(int code);

typedef struct botan_x509_cert_builder_struct* botan_x509_cert_builder_t;
typedef struct botan_x509_pkcs10_req_struct* botan_x509_pkcs10_req_t;

BOTAN_FFI_EXPORT(3, 13) int botan_x509_cert_builder_destroy(botan_x509_cert_builder_t builder);

BOTAN_FFI_EXPORT(3, 13) int botan_x509_cert_builder_create(botan_x509_cert_builder_t* builder_obj);

BOTAN_FFI_EXPORT(3, 13)
int botan_x509_cert_builder_add_common_name(botan_x509_cert_builder_t builder, const char* value);

BOTAN_FFI_EXPORT(3, 13) int botan_x509_cert_builder_add_country(botan_x509_cert_builder_t builder, const char* value);

BOTAN_FFI_EXPORT(3, 13)
int botan_x509_cert_builder_add_organization(botan_x509_cert_builder_t builder, const char* value);

BOTAN_FFI_EXPORT(3, 13)
int botan_x509_cert_builder_add_organizational_unit(botan_x509_cert_builder_t builder, const char* value);

BOTAN_FFI_EXPORT(3, 13) int botan_x509_cert_builder_add_locality(botan_x509_cert_builder_t builder, const char* value);

BOTAN_FFI_EXPORT(3, 13) int botan_x509_cert_builder_add_state(botan_x509_cert_builder_t builder, const char* value);

BOTAN_FFI_EXPORT(3, 13)
int botan_x509_cert_builder_add_serial_number(botan_x509_cert_builder_t builder, const char* value);

BOTAN_FFI_EXPORT(3, 13) int botan_x509_cert_builder_add_email(botan_x509_cert_builder_t builder, const char* value);

BOTAN_FFI_EXPORT(3, 13) int botan_x509_cert_builder_add_uri(botan_x509_cert_builder_t builder, const char* value);

BOTAN_FFI_EXPORT(3, 13) int botan_x509_cert_builder_add_dns(botan_x509_cert_builder_t builder, const char* value);

BOTAN_FFI_EXPORT(3, 13) int botan_x509_cert_builder_add_ipv4(botan_x509_cert_builder_t builder, const char* value);

BOTAN_FFI_EXPORT(3, 13) int botan_x509_cert_builder_add_ipv6(botan_x509_cert_builder_t builder, const char* value);

BOTAN_FFI_EXPORT(3, 13)
int botan_x509_cert_builder_add_xmpp(botan_x509_cert_builder_t builder, const char* value);

BOTAN_FFI_EXPORT(3, 13)
int botan_x509_cert_builder_add_allowed_usage(botan_x509_cert_builder_t builder, uint32_t usage);

BOTAN_FFI_EXPORT(3, 13)
int botan_x509_cert_builder_add_allowed_extended_usage(botan_x509_cert_builder_t builder, botan_asn1_oid_t oid);

BOTAN_FFI_EXPORT(3, 13)
int botan_x509_cert_builder_set_as_ca_certificate(botan_x509_cert_builder_t builder, size_t* limit);

BOTAN_FFI_EXPORT(3, 13)
int botan_x509_cert_builder_into_self_signed_cert(botan_x509_cert_t* cert_obj,
botan_x509_cert_builder_t builder,
botan_privkey_t key,
botan_rng_t rng,
uint64_t not_before,
uint64_t not_after,
const botan_mp_t* serial_number,
const char* hash_fn,
const char* padding);

BOTAN_FFI_EXPORT(3, 13)
int botan_x509_cert_builder_into_cert(botan_x509_cert_t* cert_obj,
botan_x509_cert_builder_t builder,
botan_x509_cert_t ca_cert,
botan_privkey_t ca_key,
botan_privkey_t key,
botan_rng_t rng,
uint64_t not_before,
uint64_t not_after,
const botan_mp_t* serial_number,
const char* hash_fn,
const char* padding);

BOTAN_FFI_EXPORT(3, 13)
int botan_x509_cert_builder_into_pkcs10_req(botan_x509_pkcs10_req_t* req_obj,
botan_x509_cert_builder_t builder,
botan_privkey_t key,
botan_rng_t rng,
const char* hash_fn,
const char* padding,
const char* challenge_password);

BOTAN_FFI_EXPORT(3, 13) int botan_x509_pkcs10_req_destroy(botan_x509_pkcs10_req_t req);

BOTAN_FFI_EXPORT(3, 13) int botan_x509_pkcs10_req_load_file(botan_x509_pkcs10_req_t* req_obj, const char* req_path);

BOTAN_FFI_EXPORT(3, 13)
int botan_x509_pkcs10_req_load(botan_x509_pkcs10_req_t* req_obj, const uint8_t req_bits[], size_t req_bits_len);

BOTAN_FFI_EXPORT(3, 13)
int botan_x509_pkcs10_req_view_pem(botan_x509_pkcs10_req_t req, botan_view_ctx ctx, botan_view_str_fn view);

BOTAN_FFI_EXPORT(3, 13)
int botan_x509_pkcs10_req_view_der(botan_x509_pkcs10_req_t req, botan_view_ctx ctx, botan_view_bin_fn view);

BOTAN_FFI_EXPORT(3, 13) int botan_x509_pkcs10_req_get_public_key(botan_x509_pkcs10_req_t req, botan_pubkey_t* key);

BOTAN_FFI_EXPORT(3, 13) int botan_x509_pkcs10_req_verify_signature(botan_x509_pkcs10_req_t req, botan_pubkey_t key);

BOTAN_FFI_EXPORT(3, 13)
int botan_x509_pkcs10_req_sign(botan_x509_cert_t* subject_cert,
botan_x509_pkcs10_req_t subject_req,
botan_x509_cert_t issuing_cert,
botan_privkey_t issuing_key,
botan_rng_t rng,
uint64_t not_before,
uint64_t not_after,
const botan_mp_t* serial_number,
const char* hash_fn,
const char* padding);
/*
* X.509 CRL
**************************/
Expand Down
Loading
Loading