diff options
author | Nick Mathewson <nickm@torproject.org> | 2005-08-26 15:34:53 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2005-08-26 15:34:53 +0000 |
commit | d54d7b7ec1321bd2f6e0779aa1080f49f4bea756 (patch) | |
tree | 41ea25df334bd5a108a8cdd3fa40cbf138764631 /src/or/routerparse.c | |
parent | 893acb3acc8a340a7686eb09cb56bde7d75d6bd3 (diff) | |
download | tor-d54d7b7ec1321bd2f6e0779aa1080f49f4bea756.tar.gz tor-d54d7b7ec1321bd2f6e0779aa1080f49f4bea756.zip |
Add some documentation; move the signature generation logic into routerparse.c along with the hash generation logic; make router signing use it as well.
svn:r4840
Diffstat (limited to 'src/or/routerparse.c')
-rw-r--r-- | src/or/routerparse.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/or/routerparse.c b/src/or/routerparse.c index 6ebd5ff296..14d16f62ff 100644 --- a/src/or/routerparse.c +++ b/src/or/routerparse.c @@ -187,6 +187,44 @@ router_get_networkstatus_v2_hash(const char *s, char *digest) "network-status-version","\ndirectory-signature"); } +/** Helper: used to generate signatures for routers, directories and + * network-status objects. Given a digest in <b>digest</b> and a secret + * <b>private_key</b>, generate an PKCS1-padded signature, BASE64-encode it, + * surround it with -----BEGIN/END----- pairs, and write it to the + * <b>buf_len</b>-byte buffer at <b>buf</b>. Return 0 on success, -1 on + * failure. + */ +int +router_append_dirobj_signature(char *buf, size_t buf_len, const char *digest, + crypto_pk_env_t *private_key) +{ + char signature[PK_BYTES]; + int i; + + if (crypto_pk_private_sign(private_key, signature, digest, DIGEST_LEN) < 0) { + + log_fn(LOG_WARN,"Couldn't sign digest."); + return -1; + } + if (strlcat(buf, "-----BEGIN SIGNATURE-----\n", buf_len) >= buf_len) + goto truncated; + + i = strlen(buf); + if (base64_encode(buf+i, buf_len-i, signature, 128) < 0) { + log_fn(LOG_WARN,"couldn't base64-encode signature"); + tor_free(buf); + return -1; + } + + if (strlcat(buf, "-----END SIGNATURE-----\n", buf_len) >= buf_len) + goto truncated; + + return 0; + truncated: + log_fn(LOG_WARN,"tried to exceed string length."); + return -1; +} + /** * Find the first instance of "recommended-software ...\n" at the start of * a line; return a newly allocated string containing the "..." portion. |