- ret = n_size;
- PARA_INFO_LOG("successfully read %u bit asn public key\n", n_size * 8);
-
-release_e:
- gcry_mpi_release(e);
-release_n:
- gcry_mpi_release(n);
-free_blob:
- free(blob);
- return ret;
-}
-
-static int get_ssh_public_key(unsigned char *data, int size, gcry_sexp_t *result)
-{
- int ret;
- gcry_error_t gret;
- unsigned char *blob = NULL, *p, *end;
- size_t nr_scanned, erroff, decoded_size;
- gcry_mpi_t e = NULL, n = NULL;
-
- PARA_DEBUG_LOG("decoding %d byte public rsa-ssh key\n", size);
- if (size > INT_MAX / 4)
- return -ERRNO_TO_PARA_ERROR(EOVERFLOW);
- blob = para_malloc(2 * size);
- ret = uudecode((char *)data, blob, 2 * size);
- if (ret < 0)
- goto free_blob;
- decoded_size = ret;
- end = blob + decoded_size;
- dump_buffer("decoded key", blob, decoded_size);
- ret = check_ssh_key_header(blob, decoded_size);
- if (ret < 0)
- goto free_blob;
- p = blob + ret;
- ret = -E_SSH_PARSE;
- if (p >= end)
- goto free_blob;
- PARA_DEBUG_LOG("scanning modulus and public exponent\n");
- gret = gcry_mpi_scan(&e, GCRYMPI_FMT_SSH, p, end - p, &nr_scanned);
- if (gret) {
- ret = -E_MPI_SCAN;
- PARA_CRIT_LOG("%s\n", gcry_strerror(gcry_err_code(gret)));
- goto free_blob;
- }
- PARA_DEBUG_LOG("scanned e (%zu bytes)\n", nr_scanned);
-// gcry_mpi_aprint(GCRYMPI_FMT_HEX, &buf, NULL, rsa_e);
-// PARA_CRIT_LOG("e: %s\n", buf);
- p += nr_scanned;
- if (p >= end)
- goto release_e;
- gret = gcry_mpi_scan(&n, GCRYMPI_FMT_SSH, p, end - p, &nr_scanned);
- if (gret) {
- ret = -E_MPI_SCAN;
- PARA_ERROR_LOG("%s\n", gcry_strerror(gcry_err_code(gret)));
- goto release_e;
- }
- PARA_DEBUG_LOG("scanned n (%zu bytes)\n", nr_scanned);
-// gcry_mpi_aprint(GCRYMPI_FMT_HEX, &buf, NULL, rsa_n);
-// PARA_CRIT_LOG("n: %s\n", buf);
- gret = gcry_sexp_build(result, &erroff, RSA_PUBKEY_SEXP, n, e);
- if (gret) {
- PARA_ERROR_LOG("offset %zu: %s\n", erroff,
- gcry_strerror(gcry_err_code(gret)));
- ret = -E_SEXP_BUILD;
- goto release_n;
- }
- ret = nr_scanned / 32 * 32;
- PARA_INFO_LOG("successfully read %u bit ssh public key\n", ret * 8);