From febb2251cac30594cf81965bd38714a1abfd8d76 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Fri, 26 Sep 2003 20:41:23 +0000 Subject: Add code to parse fingerprint files and compare routers against fingerprint files. svn:r490 --- src/common/crypto.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/common/crypto.c') diff --git a/src/common/crypto.c b/src/common/crypto.c index cf209451a1..fa1bf2b734 100644 --- a/src/common/crypto.c +++ b/src/common/crypto.c @@ -677,11 +677,27 @@ crypto_pk_get_fingerprint(crypto_pk_env_t *pk, char *fp_out) } *bufp = '\0'; assert(strlen(buf) == FINGERPRINT_LEN); + assert(crypto_pk_check_fingerprint_syntax(buf)); strcpy(fp_out, buf); free(buf); return 0; } +int +crypto_pk_check_fingerprint_syntax(const char *s) +{ + int i; + for (i = 0; i < FINGERPRINT_LEN; ++i) { + if ((i%5) == 4) { + if (!isspace(s[i])) return 0; + } else { + if (!isxdigit(s[i])) return 0; + } + } + if (s[FINGERPRINT_LEN]) return 0; + return 1; +} + /* symmetric crypto */ int crypto_cipher_generate_key(crypto_cipher_env_t *env) { -- cgit v1.2.3-54-g00ecf