/* * Read SSHFP parameters from key buffer. */ static int dns_read_key(u_int8_t *algorithm, u_int8_t *digest_type, u_char **digest, u_int *digest_len, const Key *key) { int success = 0; switch (key->type) { case KEY_RSA: *algorithm = SSHFP_KEY_RSA; break; case KEY_DSA: *algorithm = SSHFP_KEY_DSA; break; default: *algorithm = SSHFP_KEY_RESERVED; } if (*algorithm) { *digest_type = SSHFP_HASH_SHA1; *digest = key_fingerprint_raw(key, SSH_FP_SHA1, digest_len); success = 1; } else { *digest_type = SSHFP_HASH_RESERVED; *digest = NULL; *digest_len = 0; success = 0; } return success; }
/* * Read SSHFP parameters from key buffer. */ static int dns_read_key(u_int8_t *algorithm, u_int8_t *digest_type, u_char **digest, u_int *digest_len, Key *key) { int success = 0; switch (key->type) { case KEY_RSA: *algorithm = SSHFP_KEY_RSA; break; case KEY_DSA: *algorithm = SSHFP_KEY_DSA; break; /* XXX KEY_ECDSA */ default: *algorithm = SSHFP_KEY_RESERVED; /* 0 */ } if (*algorithm) { *digest_type = SSHFP_HASH_SHA1; *digest = key_fingerprint_raw(key, SSH_FP_SHA1, digest_len); if (*digest == NULL) fatal("dns_read_key: null from key_fingerprint_raw()"); success = 1; } else { *digest_type = SSHFP_HASH_RESERVED; *digest = NULL; *digest_len = 0; success = 0; } return success; }
// // fingerprint(指紋:ホスト公開鍵のハッシュ)を生成する // char *key_fingerprint(Key *key, enum fp_rep dgst_rep) { char *retval = NULL; unsigned char *dgst_raw; int dgst_raw_len; int i, retval_len; // fingerprintのハッシュ値(バイナリ)を求める dgst_raw = key_fingerprint_raw(key, SSH_FP_MD5, &dgst_raw_len); if (dgst_rep == SSH_FP_HEX) { // 16進表記へ変換する retval_len = dgst_raw_len * 3 + 1; retval = malloc(retval_len); retval[0] = '\0'; for (i = 0; i < dgst_raw_len; i++) { char hex[4]; _snprintf_s(hex, sizeof(hex), _TRUNCATE, "%02x:", dgst_raw[i]); strncat_s(retval, retval_len, hex, _TRUNCATE); } /* Remove the trailing ':' character */ retval[(dgst_raw_len * 3) - 1] = '\0'; } else if (dgst_rep == SSH_FP_RANDOMART) { retval = key_fingerprint_randomart(dgst_raw, dgst_raw_len, key); } else { } memset(dgst_raw, 0, dgst_raw_len); free(dgst_raw); return (retval); }