aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib/ffi/ffi.h6
-rw-r--r--src/lib/ffi/ffi_cert.cpp22
-rw-r--r--src/tests/test_ffi.cpp6
3 files changed, 30 insertions, 4 deletions
diff --git a/src/lib/ffi/ffi.h b/src/lib/ffi/ffi.h
index 27eb8f6d1..a680a0c19 100644
--- a/src/lib/ffi/ffi.h
+++ b/src/lib/ffi/ffi.h
@@ -1343,6 +1343,8 @@ BOTAN_PUBLIC_API(2,0) int botan_x509_cert_load(botan_x509_cert_t* cert_obj, cons
BOTAN_PUBLIC_API(2,0) int botan_x509_cert_load_file(botan_x509_cert_t* cert_obj, const char* filename);
BOTAN_PUBLIC_API(2,0) int botan_x509_cert_destroy(botan_x509_cert_t cert);
+BOTAN_PUBLIC_API(2,8) int botan_x509_cert_dup(botan_x509_cert_t* new_cert, botan_x509_cert_t cert);
+
BOTAN_PUBLIC_API(2,0)
int botan_x509_cert_gen_selfsigned(botan_x509_cert_t* cert,
botan_privkey_t key,
@@ -1413,9 +1415,9 @@ BOTAN_PUBLIC_API(2,5) int botan_x509_cert_hostname_match(botan_x509_cert_t cert,
BOTAN_PUBLIC_API(2,8) int botan_x509_cert_verify(
int* validation_result,
botan_x509_cert_t cert,
- botan_x509_cert_t* intermediates,
+ const botan_x509_cert_t* intermediates,
size_t intermediates_len,
- botan_x509_cert_t* trusted,
+ const botan_x509_cert_t* trusted,
size_t trusted_len,
const char* trusted_path,
size_t required_strength);
diff --git a/src/lib/ffi/ffi_cert.cpp b/src/lib/ffi/ffi_cert.cpp
index 20a7ed567..1e832765c 100644
--- a/src/lib/ffi/ffi_cert.cpp
+++ b/src/lib/ffi/ffi_cert.cpp
@@ -42,6 +42,24 @@ int botan_x509_cert_load_file(botan_x509_cert_t* cert_obj, const char* cert_path
#endif
}
+int botan_x509_cert_dup(botan_x509_cert_t* cert_obj, botan_x509_cert_t cert)
+ {
+ if(!cert_obj)
+ return BOTAN_FFI_ERROR_NULL_POINTER;
+
+#if defined(BOTAN_HAS_X509_CERTIFICATES) && defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
+
+ return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
+ std::unique_ptr<Botan::X509_Certificate> c(new Botan::X509_Certificate(safe_get(cert)));
+ *cert_obj = new botan_x509_cert_struct(c.release());
+ return BOTAN_FFI_SUCCESS;
+ });
+
+#else
+ return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
+#endif
+ }
+
int botan_x509_cert_load(botan_x509_cert_t* cert_obj, const uint8_t cert_bits[], size_t cert_bits_len)
{
if(!cert_obj || !cert_bits)
@@ -238,9 +256,9 @@ int botan_x509_cert_hostname_match(botan_x509_cert_t cert, const char* hostname)
int botan_x509_cert_verify(int* result_code,
botan_x509_cert_t cert,
- botan_x509_cert_t* intermediates,
+ const botan_x509_cert_t* intermediates,
size_t intermediates_len,
- botan_x509_cert_t* trusted,
+ const botan_x509_cert_t* trusted,
size_t trusted_len,
const char* trusted_path,
size_t required_strength)
diff --git a/src/tests/test_ffi.cpp b/src/tests/test_ffi.cpp
index 45c756706..20a531820 100644
--- a/src/tests/test_ffi.cpp
+++ b/src/tests/test_ffi.cpp
@@ -251,6 +251,12 @@ class FFI_Unit_Tests final : public Test
TEST_FFI_RC(-1, botan_x509_cert_hostname_match, (cert, "*.randombit.net"));
TEST_FFI_RC(-1, botan_x509_cert_hostname_match, (cert, "flub.randombit.net"));
TEST_FFI_RC(-1, botan_x509_cert_hostname_match, (cert, "randombit.net.com"));
+
+ botan_x509_cert_t copy;
+ TEST_FFI_OK(botan_x509_cert_dup, (&copy, cert));
+ TEST_FFI_RC(0, botan_x509_cert_hostname_match, (copy, "randombit.net"));
+
+ TEST_FFI_OK(botan_x509_cert_destroy, (copy));
TEST_FFI_OK(botan_x509_cert_destroy, (cert));
}
#endif