Exemplo n.º 1
0
/*
 * Read SSHFP parameters from key buffer.
 */
static int
dns_read_key(u_int8_t *algorithm, u_int8_t *digest_type,
             u_char **digest, size_t *digest_len, struct sshkey *key)
{
    int r, success = 0;
    int fp_alg = -1;

    switch (key->type) {
    case KEY_RSA:
        *algorithm = SSHFP_KEY_RSA;
        if (!*digest_type)
            *digest_type = SSHFP_HASH_SHA1;
        break;
    case KEY_DSA:
        *algorithm = SSHFP_KEY_DSA;
        if (!*digest_type)
            *digest_type = SSHFP_HASH_SHA1;
        break;
    case KEY_ECDSA:
        *algorithm = SSHFP_KEY_ECDSA;
        if (!*digest_type)
            *digest_type = SSHFP_HASH_SHA256;
        break;
    case KEY_ED25519:
        *algorithm = SSHFP_KEY_ED25519;
        if (!*digest_type)
            *digest_type = SSHFP_HASH_SHA256;
        break;
    default:
        *algorithm = SSHFP_KEY_RESERVED; /* 0 */
        *digest_type = SSHFP_HASH_RESERVED; /* 0 */
    }

    switch (*digest_type) {
    case SSHFP_HASH_SHA1:
        fp_alg = SSH_DIGEST_SHA1;
        break;
    case SSHFP_HASH_SHA256:
        fp_alg = SSH_DIGEST_SHA256;
        break;
    default:
        *digest_type = SSHFP_HASH_RESERVED; /* 0 */
    }

    if (*algorithm && *digest_type) {
        if ((r = sshkey_fingerprint_raw(key, fp_alg, digest,
                                        digest_len)) != 0)
            fatal("%s: sshkey_fingerprint_raw: %s", __func__,
                  ssh_err(r));
        success = 1;
    } else {
        *digest = NULL;
        *digest_len = 0;
        success = 0;
    }

    return success;
}
Exemplo n.º 2
0
/*
 * Read SSHFP parameters from key buffer.
 */
static int
dns_read_key(u_int8_t *algorithm, u_int8_t *digest_type,
    u_char **digest, size_t *digest_len, struct sshkey *key)
{
	int success = 0;
	enum fp_type fp_type = 0;

	switch (key->type) {
	case KEY_RSA:
		*algorithm = SSHFP_KEY_RSA;
		if (!*digest_type)
			*digest_type = SSHFP_HASH_SHA1;
		break;
	case KEY_DSA:
		*algorithm = SSHFP_KEY_DSA;
		if (!*digest_type)
			*digest_type = SSHFP_HASH_SHA1;
		break;
	case KEY_ECDSA:
		*algorithm = SSHFP_KEY_ECDSA;
		if (!*digest_type)
			*digest_type = SSHFP_HASH_SHA256;
		break;
	default:
		*algorithm = SSHFP_KEY_RESERVED; /* 0 */
		*digest_type = SSHFP_HASH_RESERVED; /* 0 */
	}

	switch (*digest_type) {
	case SSHFP_HASH_SHA1:
		fp_type = SSH_FP_SHA1;
		break;
	case SSHFP_HASH_SHA256:
		fp_type = SSH_FP_SHA256;
		break;
	default:
		*digest_type = SSHFP_HASH_RESERVED; /* 0 */
	}

	if (*algorithm && *digest_type) {
		*digest = sshkey_fingerprint_raw(key, fp_type, digest_len);
		if (*digest == NULL)
			fatal("%s: null from sshkey_fingerprint_raw", __func__);
		success = 1;
	} else {
		*digest = NULL;
		*digest_len = 0;
		success = 0;
	}

	return success;
}
Exemplo n.º 3
0
u_char*
key_fingerprint_raw(const Key *k, enum fp_type dgst_type,
    u_int *dgst_raw_length)
{
	u_char *ret = NULL;
	size_t dlen;
	int r;

	if (dgst_raw_length != NULL)
		*dgst_raw_length = 0;
	if ((r = sshkey_fingerprint_raw(k, dgst_type, &ret, &dlen)) != 0)
		fatal("%s: %s", __func__, ssh_err(r));
	if (dlen > INT_MAX)
		fatal("%s: giant len %zu", __func__, dlen);
	*dgst_raw_length = dlen;
	return ret;
}