15 #include <openssl/ssl.h>
16 #include <openssl/evp.h>
17 #include <openssl/rand.h>
18 #include <openssl/err.h>
19 #include <openssl/md5.h>
158 EVP_get_digestbyname(
"md_gost94"));
183 printf(
"unknown algorithm, ");
184 printf(
"is the one used available on this system?\n");
311 unsigned char *sha1_hash;
324 sha1_hash = SHA1((
unsigned char*)ldns_buffer_begin(to_sign),
325 ldns_buffer_position(to_sign), NULL);
331 sig = DSA_do_sign(sha1_hash, SHA_DIGEST_LENGTH, key);
337 data =
LDNS_XMALLOC(uint8_t, 1 + 2 * SHA_DIGEST_LENGTH);
345 pad = 20 - (size_t) BN_num_bytes(sig->r);
347 memset(data + 1, 0, pad);
349 BN_bn2bin(sig->r, (
unsigned char *) (data + 1) + pad);
351 pad = 20 - (size_t) BN_num_bytes(sig->s);
353 memset(data + 1 + SHA_DIGEST_LENGTH, 0, pad);
355 BN_bn2bin(sig->s, (
unsigned char *) (data + 1 + SHA_DIGEST_LENGTH + pad));
358 1 + 2 * SHA_DIGEST_LENGTH,
371 ldns_pkey_is_ecdsa(EVP_PKEY* pkey)
375 if(EVP_PKEY_type(pkey->type) != EVP_PKEY_EC)
377 ec = EVP_PKEY_get1_EC_KEY(pkey);
378 g = EC_KEY_get0_group(ec);
383 if(EC_GROUP_get_curve_name(g) == NID_secp224r1 ||
384 EC_GROUP_get_curve_name(g) == NID_X9_62_prime256v1 ||
385 EC_GROUP_get_curve_name(g) == NID_secp384r1) {
399 const EVP_MD *digest_type)
405 const EVP_MD *md_type;
415 md_type = digest_type;
422 EVP_MD_CTX_init(&ctx);
423 r = EVP_SignInit(&ctx, md_type);
425 r = EVP_SignUpdate(&ctx, (
unsigned char*)
426 ldns_buffer_begin(to_sign),
427 ldns_buffer_position(to_sign));
433 r = EVP_SignFinal(&ctx, (
unsigned char*)
434 ldns_buffer_begin(b64sig), &siglen, key);
446 if (EVP_PKEY_type(key->type) == EVP_PKEY_DSA) {
449 }
else if(EVP_PKEY_type(key->type) == EVP_PKEY_EC &&
450 ldns_pkey_is_ecdsa(key)) {
456 ldns_buffer_begin(b64sig));
460 EVP_MD_CTX_cleanup(&ctx);
467 unsigned char *sha1_hash;
479 sha1_hash = SHA1((
unsigned char*)ldns_buffer_begin(to_sign),
480 ldns_buffer_position(to_sign), NULL);
486 result = RSA_sign(NID_sha1, sha1_hash, SHA_DIGEST_LENGTH,
487 (
unsigned char*)ldns_buffer_begin(b64sig),
495 ldns_buffer_begin(b64sig));
503 unsigned char *md5_hash;
513 md5_hash = MD5((
unsigned char*)ldns_buffer_begin(to_sign),
514 ldns_buffer_position(to_sign), NULL);
520 RSA_sign(NID_md5, md5_hash, MD5_DIGEST_LENGTH,
521 (
unsigned char*)ldns_buffer_begin(b64sig),
525 ldns_buffer_begin(b64sig));
535 ldns_dnssec_addresses_on_glue_list(
543 for (cur_rrs = cur_rrset->
rrs;
545 cur_rrs = cur_rrs->
next) {
559 cur_rrset = cur_rrset->
next;
589 int below_delegation = -1;
592 if (!zone || !zone->
names) {
617 if (below_delegation && glue_list) {
618 s = ldns_dnssec_addresses_on_glue_list(
640 below_delegation = 1;
642 s = ldns_dnssec_addresses_on_glue_list(
651 below_delegation = 0;
727 cur_node = first_node;
735 while (cur_node && next_node) {
747 cur_node = next_node;
754 if (cur_node && !next_node) {
797 if (!zone || !new_rrs || !zone->
names) {
827 current_name_node = first_name_node;
829 while (current_name_node &&
842 if (!current_name->
rrsets) {
854 if (hashmap_node->
key) {
855 hashmap_node->
data = current_name->
name;
886 flags, iterations, salt_length, salt, NULL);
894 ,
int (*func)(
ldns_rr *,
void *)
907 switch(func(NULL, arg)) {
916 fprintf(stderr,
"[XX] unknown return value from callback\n");
921 (void)func(cur_rr->
rr, arg);
924 next_rr = cur_rr->
next;
926 switch (func(cur_rr->
rr, arg)) {
953 prev_rr->
next = next_rr;
961 prev_rr->
next = next_rr;
968 fprintf(stderr,
"[XX] unknown return value from callback\n");
1009 ldns_key_list_filter_for_non_dnskey(
ldns_key_list *key_list)
1030 ,
int (*func)(
ldns_rr *,
void*)
1048 int on_delegation_point = 0;
1068 cur_rrset = cur_name->
rrsets;
1082 ldns_key_list_filter_for_dnskey(key_list);
1085 ldns_key_list_filter_for_non_dnskey(key_list);
1090 cur_rr = cur_rrset->
rrs;
1093 cur_rr = cur_rr->
next;
1099 if (!on_delegation_point ||
1128 cur_rrset = cur_rrset->
next;
1138 ldns_key_list_filter_for_non_dnskey(key_list);
1173 int (*func)(
ldns_rr *,
void *),
1183 int (*func)(
ldns_rr *,
void *),
1189 if (!zone || !new_rrs || !key_list) {
1221 int (*func)(
ldns_rr *,
void *),
1225 uint16_t iterations,
1226 uint8_t salt_length,
1230 func, arg, algorithm, flags, iterations, salt_length, salt, 0,
1238 int (*func)(
ldns_rr *,
void *),
1242 uint16_t iterations,
1243 uint8_t salt_length,
1323 int (*func)(
ldns_rr *,
void *),
1327 uint16_t iterations,
1328 uint8_t salt_length,
1333 func, arg, algorithm, flags, iterations, salt_length, salt,