/* * hostkey_method_ssh_rsa_initPEMFromMemory * * Load a Private Key from a memory */ static int hostkey_method_ssh_rsa_initPEMFromMemory(LIBSSH2_SESSION * session, const char *privkeyfiledata, size_t privkeyfiledata_len, unsigned const char *passphrase, void **abstract) { libssh2_rsa_ctx *rsactx; int ret; if (*abstract) { hostkey_method_ssh_rsa_dtor(session, abstract); *abstract = NULL; } ret = _libssh2_rsa_new_private_frommemory(&rsactx, session, privkeyfiledata, privkeyfiledata_len, passphrase); if (ret) { return -1; } *abstract = rsactx; return 0; }
/* * hostkey_method_ssh_rsa_initPEM * * Load a Private Key from a PEM file */ static int hostkey_method_ssh_rsa_initPEM(LIBSSH2_SESSION * session, const char *privkeyfile, unsigned const char *passphrase, void **abstract) { libssh2_rsa_ctx *rsactx; FILE *fp; int ret; if (*abstract) { hostkey_method_ssh_rsa_dtor(session, abstract); *abstract = NULL; } fp = fopen(privkeyfile, "r"); if (!fp) { return -1; } ret = _libssh2_rsa_new_private(&rsactx, session, fp, passphrase); fclose(fp); if (ret) { return -1; } *abstract = rsactx; return 0; }
/* * hostkey_method_ssh_rsa_init * * Initialize the server hostkey working area with e/n pair */ static int hostkey_method_ssh_rsa_init(LIBSSH2_SESSION * session, const unsigned char *hostkey_data, size_t hostkey_data_len, void **abstract) { libssh2_rsa_ctx *rsactx; const unsigned char *s, *e, *n; unsigned long len, e_len, n_len; int ret; (void) hostkey_data_len; if (*abstract) { hostkey_method_ssh_rsa_dtor(session, abstract); *abstract = NULL; } s = hostkey_data; len = _libssh2_ntohu32(s); s += 4; if (len != 7 || strncmp((char *) s, "ssh-rsa", 7) != 0) { return -1; } s += 7; e_len = _libssh2_ntohu32(s); s += 4; e = s; s += e_len; n_len = _libssh2_ntohu32(s); s += 4; n = s; ret = _libssh2_rsa_new(&rsactx, e, e_len, n, n_len, NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0); if (ret) { return -1; } *abstract = rsactx; return 0; }