2 // btls-x509-verify-param.c
5 // Created by Martin Baulig on 3/5/16.
6 // Copyright © 2016 Xamarin. All rights reserved.
9 #include "btls-x509-verify-param.h"
10 #include "btls-x509-store-ctx.h"
12 struct MonoBtlsX509VerifyParam
{
14 MonoBtlsX509StoreCtx
*owner
;
15 X509_VERIFY_PARAM
*param
;
18 MONO_API MonoBtlsX509VerifyParam
*
19 mono_btls_x509_verify_param_new (void)
21 MonoBtlsX509VerifyParam
*param
;
23 param
= OPENSSL_malloc (sizeof(MonoBtlsX509VerifyParam
));
26 memset (param
, 0, sizeof (MonoBtlsX509VerifyParam
));
27 param
->param
= X509_VERIFY_PARAM_new();
32 MONO_API MonoBtlsX509VerifyParam
*
33 mono_btls_x509_verify_param_from_store_ctx (MonoBtlsX509StoreCtx
*ctx
, X509_VERIFY_PARAM
*param
)
35 MonoBtlsX509VerifyParam
*instance
;
37 instance
= OPENSSL_malloc (sizeof(MonoBtlsX509VerifyParam
));
40 memset (instance
, 0, sizeof (MonoBtlsX509VerifyParam
));
41 instance
->param
= param
;
42 instance
->owner
= mono_btls_x509_store_ctx_up_ref (ctx
);
46 MONO_API MonoBtlsX509VerifyParam
*
47 mono_btls_x509_verify_param_copy (const MonoBtlsX509VerifyParam
*from
)
49 MonoBtlsX509VerifyParam
*param
;
51 param
= mono_btls_x509_verify_param_new ();
55 X509_VERIFY_PARAM_set1 (param
->param
, from
->param
);
59 MONO_API
const X509_VERIFY_PARAM
*
60 mono_btls_x509_verify_param_peek_param (const MonoBtlsX509VerifyParam
*param
)
66 mono_btls_x509_verify_param_can_modify (MonoBtlsX509VerifyParam
*param
)
71 MONO_API MonoBtlsX509VerifyParam
*
72 mono_btls_x509_verify_param_lookup (const char *name
)
74 MonoBtlsX509VerifyParam
*param
;
75 const X509_VERIFY_PARAM
*p
;
77 p
= X509_VERIFY_PARAM_lookup(name
);
81 param
= OPENSSL_malloc (sizeof(MonoBtlsX509VerifyParam
));
84 memset (param
, 0, sizeof (MonoBtlsX509VerifyParam
));
85 param
->param
= (X509_VERIFY_PARAM
*)p
;
90 mono_btls_x509_verify_param_free (MonoBtlsX509VerifyParam
*param
)
94 X509_VERIFY_PARAM_free (param
->param
);
99 mono_btls_x509_store_ctx_free (param
->owner
);
102 OPENSSL_free (param
);
106 mono_btls_x509_verify_param_set_name (MonoBtlsX509VerifyParam
*param
, const char *name
)
110 return X509_VERIFY_PARAM_set1_name (param
->param
, name
);
114 mono_btls_x509_verify_param_set_host (MonoBtlsX509VerifyParam
*param
, const char *host
, int namelen
)
118 return X509_VERIFY_PARAM_set1_host (param
->param
, host
, namelen
);
122 mono_btls_x509_verify_param_add_host (MonoBtlsX509VerifyParam
*param
, const char *host
, int namelen
)
126 return X509_VERIFY_PARAM_set1_host (param
->param
, host
, namelen
);
130 mono_btls_x509_verify_param_get_flags (MonoBtlsX509VerifyParam
*param
)
132 return X509_VERIFY_PARAM_get_flags (param
->param
);
136 mono_btls_x509_verify_param_set_flags (MonoBtlsX509VerifyParam
*param
, uint64_t flags
)
140 return X509_VERIFY_PARAM_set_flags (param
->param
, flags
);
143 MONO_API MonoBtlsX509VerifyFlags
144 mono_btls_x509_verify_param_get_mono_flags (MonoBtlsX509VerifyParam
*param
)
146 MonoBtlsX509VerifyFlags current
;
153 flags
= X509_VERIFY_PARAM_get_flags (param
->param
);
155 if (flags
& X509_V_FLAG_CRL_CHECK
)
156 current
|= MONO_BTLS_X509_VERIFY_FLAGS_CRL_CHECK
;
157 if (flags
& X509_V_FLAG_CRL_CHECK_ALL
)
158 current
|= MONO_BTLS_X509_VERIFY_FLAGS_CRL_CHECK_ALL
;
159 if (flags
& X509_V_FLAG_X509_STRICT
)
160 current
|= MONO_BTLS_X509_VERIFY_FLAGS_X509_STRICT
;
166 mono_btls_x509_verify_param_set_mono_flags (MonoBtlsX509VerifyParam
*param
, MonoBtlsX509VerifyFlags flags
)
173 current
= X509_VERIFY_PARAM_get_flags (param
->param
);
174 if (flags
& MONO_BTLS_X509_VERIFY_FLAGS_CRL_CHECK
)
175 current
|= X509_V_FLAG_CRL_CHECK
;
176 if (flags
& MONO_BTLS_X509_VERIFY_FLAGS_CRL_CHECK_ALL
)
177 current
|= X509_V_FLAG_CRL_CHECK_ALL
;
178 if (flags
& MONO_BTLS_X509_VERIFY_FLAGS_X509_STRICT
)
179 current
|= X509_V_FLAG_X509_STRICT
;
181 return X509_VERIFY_PARAM_set_flags (param
->param
, current
);
185 mono_btls_x509_verify_param_set_purpose (MonoBtlsX509VerifyParam
*param
, MonoBtlsX509Purpose purpose
)
189 return X509_VERIFY_PARAM_set_purpose (param
->param
, purpose
);
193 mono_btls_x509_verify_param_get_depth (MonoBtlsX509VerifyParam
*param
)
195 return X509_VERIFY_PARAM_get_depth (param
->param
);
199 mono_btls_x509_verify_param_set_depth (MonoBtlsX509VerifyParam
*param
, int depth
)
203 X509_VERIFY_PARAM_set_depth (param
->param
, depth
);
208 mono_btls_x509_verify_param_set_time (MonoBtlsX509VerifyParam
*param
, int64_t time
)
212 X509_VERIFY_PARAM_set_time (param
->param
, time
);
217 mono_btls_x509_verify_param_get_peername (MonoBtlsX509VerifyParam
*param
)
219 char *peer
= X509_VERIFY_PARAM_get0_peername (param
->param
);