Skip to content

Commit

Permalink
Merge pull request #1 from droe/master
Browse files Browse the repository at this point in the history
Transform ECDSA RRSIG to OpenSSL ASN.1 DER format
  • Loading branch information
stirnim committed Mar 24, 2016
2 parents 8e1a098 + 23e0d77 commit 55c02f2
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions rrsig.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <arpa/inet.h>
#include <openssl/evp.h>
#include <openssl/err.h>
#include <openssl/ecdsa.h>

#include "common.h"
#include "textparse.h"
Expand Down Expand Up @@ -90,6 +91,22 @@ static struct rr* rrsig_parse(char *name, long ttl, int type, char *s)
sig = extract_base64_binary_data(&s, "signature");
if (sig.length < 0) return NULL;
/* TODO validate signature length based on algorithm */
if (algorithm_type(rr->algorithm) == ALG_ECC_FAMILY) {
/*
* Transform ECDSA signatures from DNSSEC vanilla binary
* representation (r || s) into OpenSSL ASN.1 DER format
*/
ECDSA_SIG *ecdsa_sig = ECDSA_SIG_new();
int l = sig.length / 2;
if ((BN_bin2bn((unsigned char *)sig.data, l, ecdsa_sig->r) == NULL) ||
(BN_bin2bn(((unsigned char *)sig.data) + l, l, ecdsa_sig->s) == NULL))
return NULL;
sig.length = i2d_ECDSA_SIG(ecdsa_sig, NULL);
sig.data = getmem(sig.length); /* reallocate larger mempool chunk */
unsigned char *sig_ptr = (unsigned char *)sig.data;
sig.length = i2d_ECDSA_SIG(ecdsa_sig, &sig_ptr);
ECDSA_SIG_free(ecdsa_sig);
}
rr->signature = sig;

if (*s) {
Expand Down

0 comments on commit 55c02f2

Please sign in to comment.