MCPcopy Create free account
hub / github.com/apache/httpd / md_jws_hmac

Function md_jws_hmac

modules/md/md_jws.c:112–148  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

110}
111
112apr_status_t md_jws_hmac(md_json_t **pmsg, apr_pool_t *p,
113 md_data_t *payload, md_json_t *prot_fields,
114 const md_data_t *hmac_key)
115{
116 md_json_t *msg, *jprotected;
117 const char *prot64, *pay64, *mac64, *sign, *prot;
118 md_data_t data;
119 apr_status_t rv;
120
121 msg = md_json_create(p);
122 jprotected = md_json_clone(p, prot_fields);
123 md_json_sets("HS256", jprotected, "alg", NULL);
124 prot = md_json_writep(jprotected, p, MD_JSON_FMT_COMPACT);
125 if (!prot) {
126 rv = APR_EINVAL;
127 md_log_perror(MD_LOG_MARK, MD_LOG_WARNING, rv, p, "serialize protected");
128 goto cleanup;
129 }
130
131 md_data_init(&data, prot, strlen(prot));
132 prot64 = md_util_base64url_encode(&data, p);
133 md_json_sets(prot64, msg, "protected", NULL);
134
135 pay64 = md_util_base64url_encode(payload, p);
136 md_json_sets(pay64, msg, "payload", NULL);
137 sign = apr_psprintf(p, "%s.%s", prot64, pay64);
138
139 rv = md_crypt_hmac64(&mac64, hmac_key, p, sign, strlen(sign));
140 if (APR_SUCCESS != rv) {
141 goto cleanup;
142 }
143 md_json_sets(mac64, msg, "signature", NULL);
144
145cleanup:
146 *pmsg = (APR_SUCCESS == rv)? msg : NULL;
147 return rv;
148}

Callers 1

get_eabFunction · 0.85

Calls 8

md_json_createFunction · 0.85
md_json_cloneFunction · 0.85
md_json_setsFunction · 0.85
md_json_writepFunction · 0.85
md_log_perrorFunction · 0.85
md_data_initFunction · 0.85
md_util_base64url_encodeFunction · 0.85
md_crypt_hmac64Function · 0.85

Tested by

no test coverage detected