8000 Add a callback context for the findHashedTA CB · Adam5Wu/bearssl-esp8266@1cd87d2 · GitHub
[go: up one dir, main page]

8000
Skip to content

Commit 1cd87d2

Browse files
Add a callback context for the findHashedTA CB
1 parent ba9df5b commit 1cd87d2

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

inc/bearssl_x509.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -700,10 +700,12 @@ typedef struct {
700700
const br_x509_trust_anchor *trust_anchors;
701701
size_t trust_anchors_num;
702702

703+
/* private context for dynamic callbacks */
704+
void *trust_anchor_dynamic_ctx;
703705
/* Dynamic trust anchor, for on-the-fly loading of TAs */
704-
const br_x509_trust_anchor* (*trust_anchor_dynamic)(void *hashed_dn, size_t hashed_dn_len);
706+
const br_x509_trust_anchor* (*trust_anchor_dynamic)(void *ctx, void *hashed_dn, size_t hashed_dn_len);
705707
/* And a chance to free any dynamically allocated TA returned from above */
706-
void (*trust_anchor_dynamic_free)(const br_x509_trust_anchor *ta);
708+
void (*trust_anchor_dynamic_free)(void *ctx, const br_x509_trust_anchor *ta);
707709

708710
/*
709711
* Multi-hasher for the TBS.
@@ -779,14 +781,16 @@ void br_x509_minimal_init(br_x509_minimal_context *ctx,
779781
* chance to deallocate its memory, if needed.
780782
*
781783
* \param ctx context to initialise.
784+
* \param dynamic_ctx private context for the dynamic callback
782785
* \param trust_anchor_dynamic provides a trust_anchor* for a hashed_dn
783786
* \param trust_anchor_dynamic_free allows deallocation of returned TA
784787
*/
785788
static inline void
786-
br_x509_minimal_set_dynamic(br_x509_minimal_context *ctx,
787-
const br_x509_trust_anchor* (*dynamic)(void *hashed_dn, size_t hashed_dn_len),
788-
void (*dynamic_free)(const br_x509_trust_anchor *ta))
789+
br_x509_minimal_set_dynamic(br_x509_minimal_context *ctx, void *dynamic_ctx,
790+
const br_x509_trust_anchor* (*dynamic)(void *ctx, void *hashed_dn, size_t hashed_dn_len),
791+
void (*dynamic_free)(void *ctx, const br_x509_trust_anchor *ta))
789792
{
793+
ctx->trust_anchor_dynamic_ctx = dynamic_ctx;
790794
ctx->trust_anchor_dynamic = dynamic;
791795
ctx->trust_anchor_dynamic_free = dynamic_free;
792796
}

src/x509/x509_minimal.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,12 +1258,12 @@ br_x509_minimal_run(void *t0ctx)
12581258
}
12591259
}
12601260
if (CTX->err != BR_ERR_X509_OK && CTX->trust_anchor_dynamic) {
1261-
ta = CTX->trust_anchor_dynamic(CTX->current_dn_hash, DNHASH_LEN);
1261+
ta = CTX->trust_anchor_dynamic(CTX->trust_anchor_dynamic_ctx, CTX->current_dn_hash, DNHASH_LEN);
12621262
if (ta) {
12631263
memcpy(hashed_DN, ta->dn.data, DNHASH_LEN);
12641264
int ret = check_single_direct_trust(CTX, hashed_DN, ta);
12651265
if (CTX->trust_anchor_dynamic_free) {
1266-
CTX->trust_anchor_dynamic_free(ta);
1266+
CTX->trust_anchor_dynamic_free(CTX->trust_anchor_dynamic_ctx, ta);
12671267
}
12681268
if (ret) {
12691269
/*
@@ -1298,13 +1298,13 @@ br_x509_minimal_run(void *t0ctx)
12981298
}
12991299
}
13001300
if (CTX->err != BR_ERR_X509_OK && CTX->trust_anchor_dynamic) {
1301-
ta = CTX->trust_anchor_dynamic(CTX->saved_dn_hash, DNHASH_LEN);
1301+
ta = CTX->trust_anchor_dynamic(CTX->trust_anchor_dynamic_ctx, CTX->saved_dn_hash, DNHASH_LEN);
13021302
if (ta) {
13031303
memcpy(hashed_DN, ta->dn.data, DNHASH_LEN);
13041304
int ret;
13051305
ret = check_single_trust_anchor_CA(CTX, hashed_DN, ta);
13061306
if (CTX->trust_anchor_dynamic_free) {
1307-
CTX->trust_anchor_dynamic_free(ta);
1307+
CTX->trust_anchor_dynamic_free(CTX->trust_anchor_dynamic_ctx, ta);
13081308
}
13091309
if (ret) {
13101310
CTX->err = BR_ERR_X509_OK;

src/x509/x509_minimal.t0

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -921,12 +921,12 @@ cc: check-direct-trust ( -- ) {
921921
}
922922
}
923923
if (CTX->err != BR_ERR_X509_OK && CTX->trust_anchor_dynamic) {
924-
ta = CTX->trust_anchor_dynamic(CTX->current_dn_hash, DNHASH_LEN);
924+
ta = CTX->trust_anchor_dynamic(CTX->trust_anchor_dynamic_ctx, CTX->current_dn_hash, DNHASH_LEN);
925925
if (ta) {
926926
memcpy(hashed_DN, ta->dn.data, DNHASH_LEN);
927927
int ret = check_single_direct_trust(CTX, hashed_DN, ta);
928928
if (CTX->trust_anchor_dynamic_free) {
929-
CTX->trust_anchor_dynamic_free(ta);
929+
CTX->trust_anchor_dynamic_free(CTX->trust_anchor_dynamic_ctx, ta);
930930
}
931931
if (ret) {
932932
/*
@@ -960,13 +960,13 @@ cc: check-trust-anchor-CA ( -- ) {
960960
}
961961
}
962962
if (CTX->err != BR_ERR_X509_OK && CTX->trust_anchor_dynamic) {
963-
ta = CTX->trust_anchor_dynamic(CTX->saved_dn_hash, DNHASH_LEN);
963+
ta = CTX->trust_anchor_dynamic(CTX->trust_anchor_dynamic_ctx, CTX->saved_dn_hash, DNHASH_LEN);
964964
if (ta) {
965965
memcpy(hashed_DN, ta->dn.data, DNHASH_LEN);
966966
int ret;
967967
ret = check_single_trust_anchor_CA(CTX, hashed_DN, ta);
968968
if (CTX->trust_anchor_dynamic_free) {
969-
CTX->trust_anchor_dynamic_free(ta);
969+
CTX->trust_anchor_dynamic_free(CTX->trust_anchor_dynamic_ctx, ta);
970970
}
971971
if (ret) {
972972
CTX->err = BR_ERR_X509_OK;

0 commit comments

Comments
 (0)
0