diff options
| author | Joel Klinghed <the_jk@spawned.biz> | 2024-10-31 22:38:03 +0100 |
|---|---|---|
| committer | Joel Klinghed <the_jk@spawned.biz> | 2024-10-31 22:40:33 +0100 |
| commit | 284a09b19bc3be8849fc71acd0ad407c43ec7380 (patch) | |
| tree | 616691547cf01371131aabd2585dc82b81da2826 /libs/sftp/src/main/cpp | |
| parent | 542454c4056fb5361c982c5ecdd2aef38b9c6b9f (diff) | |
sftp: Simplify authentication with private key
Let ssh2 derive the public key from the private key. Much easier.
Diffstat (limited to 'libs/sftp/src/main/cpp')
| -rw-r--r-- | libs/sftp/src/main/cpp/sftp.cpp | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/libs/sftp/src/main/cpp/sftp.cpp b/libs/sftp/src/main/cpp/sftp.cpp index 1bc4fcb..3368c53 100644 --- a/libs/sftp/src/main/cpp/sftp.cpp +++ b/libs/sftp/src/main/cpp/sftp.cpp @@ -364,11 +364,10 @@ class SshSession { nullptr) == 0; } - bool Authenticate(const std::string& username, const std::vector<uint8_t>& public_key, - const std::vector<uint8_t>& private_key, const std::string& passphrase) { + bool Authenticate(const std::string& username, const std::vector<uint8_t>& private_key, const std::string& passphrase) { return libssh2_userauth_publickey_frommemory( session_.get(), username.data(), username.size(), - reinterpret_cast<const char*>(public_key.data()), public_key.size(), + nullptr, 0, reinterpret_cast<const char*>(private_key.data()), private_key.size(), passphrase.c_str()) == 0; } @@ -425,13 +424,11 @@ jbyteArray nativeSshSessionHandshake(JNIEnv* env, jclass, jlong ptr) { } jboolean nativeSshSessionAuthenticate(JNIEnv* env, jclass, jlong ptr, jstring j_username, - jstring password, jbyteArray public_key, - jbyteArray private_key) { + jstring password, jbyteArray private_key) { auto username = jni::StringToUTF8(env, jni::ParamRef<jstring>(env, j_username)); - if (public_key != nullptr && private_key != nullptr) { + if (private_key != nullptr) { return reinterpret_cast<SshSession*>(ptr)->Authenticate( username, - jni::ByteArrayToVector(env, jni::ParamRef<jbyteArray>(env, public_key)), jni::ByteArrayToVector(env, jni::ParamRef<jbyteArray>(env, private_key)), password != nullptr ? jni::StringToUTF8(env, jni::ParamRef<jstring>(env, password)) : "") ? JNI_TRUE : JNI_FALSE; @@ -576,7 +573,7 @@ void RegisterSftp(JNIEnv* env) { { "nativeSshSessionGetLastError", "(J)Ljava/lang/String;", reinterpret_cast<void*>(&nativeSshSessionGetLastError) }, { "nativeSshSessionConnect", "(JLjava/lang/String;I)Z", reinterpret_cast<void*>(&nativeSshSessionConnect) }, { "nativeSshSessionHandshake", "(J)[B", reinterpret_cast<void*>(&nativeSshSessionHandshake) }, - { "nativeSshSessionAuthenticate", "(JLjava/lang/String;Ljava/lang/String;[B[B)Z", reinterpret_cast<void*>(&nativeSshSessionAuthenticate) }, + { "nativeSshSessionAuthenticate", "(JLjava/lang/String;Ljava/lang/String;[B)Z", reinterpret_cast<void*>(&nativeSshSessionAuthenticate) }, { "nativeSshSessionNewSftpSession", "(J)J", reinterpret_cast<void*>(&nativeSshSessionNewSftpSession) }, { "nativeSftpSessionDestroy", "(J)V", reinterpret_cast<void*>(&nativeSftpSessionDestroy) }, |
