mirror of https://github.com/getdnsapi/getdns.git
Specify TSIG parameters with getdns_query
This commit is contained in:
parent
95e9fa1f35
commit
bc2ec7cee3
|
@ -267,6 +267,66 @@ static enum { GENERAL, ADDRESS, HOSTNAME, SERVICE } calltype = GENERAL;
|
||||||
|
|
||||||
int get_rrtype(const char *t);
|
int get_rrtype(const char *t);
|
||||||
|
|
||||||
|
int gqldns_b64_pton(char const *src, uint8_t *target, size_t targsize)
|
||||||
|
{
|
||||||
|
const uint8_t pad64 = 64; /* is 64th in the b64 array */
|
||||||
|
const char* s = src;
|
||||||
|
uint8_t in[4];
|
||||||
|
size_t o = 0, incount = 0;
|
||||||
|
|
||||||
|
while(*s) {
|
||||||
|
/* skip any character that is not base64 */
|
||||||
|
/* conceptually we do:
|
||||||
|
const char* b64 = pad'=' is appended to array
|
||||||
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
||||||
|
const char* d = strchr(b64, *s++);
|
||||||
|
and use d-b64;
|
||||||
|
*/
|
||||||
|
char d = *s++;
|
||||||
|
if(d <= 'Z' && d >= 'A')
|
||||||
|
d -= 'A';
|
||||||
|
else if(d <= 'z' && d >= 'a')
|
||||||
|
d = d - 'a' + 26;
|
||||||
|
else if(d <= '9' && d >= '0')
|
||||||
|
d = d - '0' + 52;
|
||||||
|
else if(d == '+')
|
||||||
|
d = 62;
|
||||||
|
else if(d == '/')
|
||||||
|
d = 63;
|
||||||
|
else if(d == '=')
|
||||||
|
d = 64;
|
||||||
|
else continue;
|
||||||
|
in[incount++] = (uint8_t)d;
|
||||||
|
if(incount != 4)
|
||||||
|
continue;
|
||||||
|
/* process whole block of 4 characters into 3 output bytes */
|
||||||
|
if(in[3] == pad64 && in[2] == pad64) { /* A B = = */
|
||||||
|
if(o+1 > targsize)
|
||||||
|
return -1;
|
||||||
|
target[o] = (in[0]<<2) | ((in[1]&0x30)>>4);
|
||||||
|
o += 1;
|
||||||
|
break; /* we are done */
|
||||||
|
} else if(in[3] == pad64) { /* A B C = */
|
||||||
|
if(o+2 > targsize)
|
||||||
|
return -1;
|
||||||
|
target[o] = (in[0]<<2) | ((in[1]&0x30)>>4);
|
||||||
|
target[o+1]= ((in[1]&0x0f)<<4) | ((in[2]&0x3c)>>2);
|
||||||
|
o += 2;
|
||||||
|
break; /* we are done */
|
||||||
|
} else {
|
||||||
|
if(o+3 > targsize)
|
||||||
|
return -1;
|
||||||
|
/* write xxxxxxyy yyyyzzzz zzwwwwww */
|
||||||
|
target[o] = (in[0]<<2) | ((in[1]&0x30)>>4);
|
||||||
|
target[o+1]= ((in[1]&0x0f)<<4) | ((in[2]&0x3c)>>2);
|
||||||
|
target[o+2]= ((in[2]&0x03)<<6) | in[3];
|
||||||
|
o += 3;
|
||||||
|
}
|
||||||
|
incount = 0;
|
||||||
|
}
|
||||||
|
return (int)o;
|
||||||
|
}
|
||||||
|
|
||||||
getdns_dict *
|
getdns_dict *
|
||||||
ipaddr_dict(getdns_context *context, char *ipstr)
|
ipaddr_dict(getdns_context *context, char *ipstr)
|
||||||
{
|
{
|
||||||
|
@ -275,6 +335,13 @@ ipaddr_dict(getdns_context *context, char *ipstr)
|
||||||
char *p = strchr(ipstr, '@'), *portstr = "";
|
char *p = strchr(ipstr, '@'), *portstr = "";
|
||||||
char *t = strchr(ipstr, '#'), *tls_portstr = "";
|
char *t = strchr(ipstr, '#'), *tls_portstr = "";
|
||||||
char *n = strchr(ipstr, '~'), *tls_namestr = "";
|
char *n = strchr(ipstr, '~'), *tls_namestr = "";
|
||||||
|
/* ^[alg:]name:key */
|
||||||
|
char *T = strchr(ipstr, '^'), *tsig_name_str = ""
|
||||||
|
, *tsig_secret_str = ""
|
||||||
|
, *tsig_algorithm_str = "";
|
||||||
|
int tsig_secret_size;
|
||||||
|
uint8_t tsig_secret_buf[256]; /* 4 times SHA512 */
|
||||||
|
getdns_bindata tsig_secret;
|
||||||
uint8_t buf[sizeof(struct in6_addr)];
|
uint8_t buf[sizeof(struct in6_addr)];
|
||||||
getdns_bindata addr;
|
getdns_bindata addr;
|
||||||
|
|
||||||
|
@ -297,6 +364,22 @@ ipaddr_dict(getdns_context *context, char *ipstr)
|
||||||
*n = 0;
|
*n = 0;
|
||||||
tls_namestr = n + 1;
|
tls_namestr = n + 1;
|
||||||
}
|
}
|
||||||
|
if (T) {
|
||||||
|
*T = 0;
|
||||||
|
tsig_name_str = T + 1;
|
||||||
|
if ((T = strchr(tsig_name_str, ':'))) {
|
||||||
|
*T = 0;
|
||||||
|
tsig_secret_str = T + 1;
|
||||||
|
if ((T = strchr(tsig_secret_str, ':'))) {
|
||||||
|
*T = 0;
|
||||||
|
tsig_algorithm_str = tsig_name_str;
|
||||||
|
tsig_name_str = tsig_secret_str;
|
||||||
|
tsig_secret_str = T + 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
tsig_name_str = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
if (strchr(ipstr, ':')) {
|
if (strchr(ipstr, ':')) {
|
||||||
getdns_dict_util_set_string(r, "address_type", "IPv6");
|
getdns_dict_util_set_string(r, "address_type", "IPv6");
|
||||||
addr.size = 16;
|
addr.size = 16;
|
||||||
|
@ -322,7 +405,19 @@ ipaddr_dict(getdns_context *context, char *ipstr)
|
||||||
}
|
}
|
||||||
if (*scope_id_str)
|
if (*scope_id_str)
|
||||||
getdns_dict_util_set_string(r, "scope_id", scope_id_str);
|
getdns_dict_util_set_string(r, "scope_id", scope_id_str);
|
||||||
|
if (*tsig_name_str)
|
||||||
|
getdns_dict_util_set_string(r, "tsig_name", tsig_name_str);
|
||||||
|
if (*tsig_algorithm_str)
|
||||||
|
getdns_dict_util_set_string(r, "tsig_algorithm", tsig_name_str);
|
||||||
|
if (*tsig_secret_str) {
|
||||||
|
tsig_secret_size = gqldns_b64_pton(
|
||||||
|
tsig_secret_str, tsig_secret_buf, sizeof(tsig_secret_buf));
|
||||||
|
if (tsig_secret_size > 0) {
|
||||||
|
tsig_secret.size = tsig_secret_size;
|
||||||
|
tsig_secret.data = tsig_secret_buf;
|
||||||
|
getdns_dict_set_bindata(r, "tsig_secret", &tsig_secret);
|
||||||
|
}
|
||||||
|
}
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue