From ee6049804a86cf7f2f85bb0b96cb4e046e01328e Mon Sep 17 00:00:00 2001 From: Jose Marcial Vieira Bisneto Date: Thu, 26 Jan 2017 23:41:03 -0300 Subject: [PATCH] Using crypto rsa to sign protobuf message in the record. --- record/record.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/record/record.c b/record/record.c index 3cd8af2..f2a8a2d 100644 --- a/record/record.c +++ b/record/record.c @@ -48,12 +48,13 @@ int libp2p_record_make_put_record (char** record, size_t *rec_size, struct RsaPr free (pkh); len += l; if (sign) { - //TODO: missing signature function at libp2p-crypto ? - //sign(sk, signature, p, len); - //proto encode signature. - free (pkh); - free (p); - return -1; // not implemented. + char sign_buf[2048]; + if (!libp2p_crypto_rsa_sign (sk, (unsigned char*) p, len, (unsigned char*) sign_buf) || + !protobuf_encode_string (4, WIRETYPE_LENGTH_DELIMITED, sign_buf, p+len, RECORD_BUFSIZE-len, &l)) { + free (p); + return -1; + } + len += l; } } *record = realloc(p, len); // Reduces memory used for just what is needed.