When the skey is generated on the fly, we will get an empty key on the very
first auth attempt. If that uses basic auth then we'll segfault when trying
to compute the hmac as we pass in a NULL key and immediately dereference it.
Signed-off-by: Simo Sorce <simo@redhat.com>
return HMAC_BUFFER(key, &databuf, &hmacbuf);
}
return HMAC_BUFFER(key, &databuf, &hmacbuf);
}
+static int mag_get_mac_size(struct mag_config *cfg)
+{
+ apr_status_t rc;
+
+ if (!cfg->mag_skey) {
+ ap_log_perror(APLOG_MARK, APLOG_INFO, 0, cfg->pool,
+ "Session key not available, generating new one.");
+ rc = SEAL_KEY_CREATE(cfg->pool, &cfg->mag_skey, NULL);
+ if (rc != OK) {
+ ap_log_perror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, cfg->pool,
+ "Failed to create sealing key!");
+ return 0;
+ }
+ }
+
+ return get_mac_size(cfg->mag_skey);
+}
+
bool mag_basic_check(struct mag_config *cfg, struct mag_conn *mc,
gss_buffer_desc user, gss_buffer_desc pwd)
{
bool mag_basic_check(struct mag_config *cfg, struct mag_conn *mc,
gss_buffer_desc user, gss_buffer_desc pwd)
{
- int mac_size = get_mac_size(cfg->mag_skey);
+ int mac_size = mag_get_mac_size(cfg);
unsigned char mac[mac_size];
int ret, i, j;
bool res = false;
unsigned char mac[mac_size];
int ret, i, j;
bool res = false;
void mag_basic_cache(struct mag_config *cfg, struct mag_conn *mc,
gss_buffer_desc user, gss_buffer_desc pwd)
{
void mag_basic_cache(struct mag_config *cfg, struct mag_conn *mc,
gss_buffer_desc user, gss_buffer_desc pwd)
{
- int mac_size = get_mac_size(cfg->mag_skey);
+ int mac_size = mag_get_mac_size(cfg);
unsigned char mac[mac_size];
int ret;
unsigned char mac[mac_size];
int ret;