5 // Created by Martin Baulig on 3/3/16.
6 // Copyright © 2016 Xamarin. All rights reserved.
9 #include <btls-x509-store.h>
11 struct MonoBtlsX509Store {
13 CRYPTO_refcount_t references;
16 MONO_API MonoBtlsX509Store *
17 mono_btls_x509_store_from_store (X509_STORE *ctx)
19 MonoBtlsX509Store *store;
21 store = OPENSSL_malloc (sizeof(MonoBtlsX509Store));
25 memset (store, 0, sizeof(MonoBtlsX509Store));
27 CRYPTO_refcount_inc (&store->store->references);
28 store->references = 1;
32 MONO_API MonoBtlsX509Store *
33 mono_btls_x509_store_from_ctx (X509_STORE_CTX *ctx)
35 return mono_btls_x509_store_from_store (ctx->ctx);
38 MONO_API MonoBtlsX509Store *
39 mono_btls_x509_store_new (void)
41 MonoBtlsX509Store *store;
43 store = OPENSSL_malloc (sizeof(MonoBtlsX509Store));
47 memset (store, 0, sizeof(MonoBtlsX509Store));
48 store->store = X509_STORE_new ();
49 store->references = 1;
54 mono_btls_x509_store_peek_store (MonoBtlsX509Store *store)
59 MONO_API MonoBtlsX509Store *
60 mono_btls_x509_store_from_ssl_ctx (MonoBtlsSslCtx *ctx)
62 X509_STORE *store = mono_btls_ssl_ctx_peek_store (ctx);
63 return mono_btls_x509_store_from_store (store);
67 mono_btls_x509_store_free (MonoBtlsX509Store *store)
69 if (!CRYPTO_refcount_dec_and_test_zero(&store->references))
73 X509_STORE_free (store->store);
80 MONO_API MonoBtlsX509Store *
81 mono_btls_x509_store_up_ref (MonoBtlsX509Store *store)
83 CRYPTO_refcount_inc (&store->references);
88 mono_btls_x509_store_add_cert (MonoBtlsX509Store *store, X509 *cert)
90 return X509_STORE_add_cert (store->store, cert);
94 mono_btls_x509_store_load_locations (MonoBtlsX509Store *store, const char *file, const char *path)
96 return X509_STORE_load_locations (store->store, file, path);
100 mono_btls_x509_store_set_default_paths (MonoBtlsX509Store *store)
102 return X509_STORE_set_default_paths (store->store);
106 mono_btls_x509_store_get_count (MonoBtlsX509Store *store)
108 return (int)sk_X509_OBJECT_num (store->store->objs);