termux-packages/packages/dropbear/svr-authpasswd.c.patch

60 lines
1.9 KiB
Diff

diff -u -r ../dropbear-2019.77/svr-authpasswd.c ./svr-authpasswd.c
--- ../dropbear-2019.77/svr-authpasswd.c 2019-03-23 13:46:29.000000000 +0000
+++ ./svr-authpasswd.c 2019-03-24 22:40:59.586161245 +0000
@@ -33,28 +33,13 @@
#if DROPBEAR_SVR_PASSWORD_AUTH
-/* not constant time when strings are differing lengths.
- string content isn't leaked, and crypt hashes are predictable length. */
-static int constant_time_strcmp(const char* a, const char* b) {
- size_t la = strlen(a);
- size_t lb = strlen(b);
-
- if (la != lb) {
- return 1;
- }
-
- return constant_time_memcmp(a, b, la);
-}
+#include <termux-auth.h>
/* Process a password auth request, sending success or failure messages as
* appropriate */
void svr_auth_password(int valid_user) {
-
- char * passwdcrypt = NULL; /* the crypt from /etc/passwd or /etc/shadow */
- char * testcrypt = NULL; /* crypt generated from the user's password sent */
- char * password = NULL;
- unsigned int passwordlen;
- unsigned int changepw;
+ char *password;
+ unsigned int changepw, passwordlen;
/* check if client wants to change password */
changepw = buf_getbool(ses.payload);
@@ -65,6 +50,7 @@
}
password = buf_getstring(ses.payload, &passwordlen);
+#ifndef __ANDROID__
if (valid_user && passwordlen <= DROPBEAR_MAX_PASSWORD_LEN) {
/* the first bytes of passwdcrypt are the salt */
passwdcrypt = ses.authstate.pw_passwd;
@@ -106,6 +92,15 @@
}
if (constant_time_strcmp(testcrypt, passwdcrypt) == 0) {
+#else /* __ANDROID__ */
+ /* check if password is valid */
+ if (termux_auth(ses.authstate.pw_name, password)) {
+ if (!ses.authstate.pw_name) {
+ dropbear_log(LOG_WARNING, "Login name is NULL");
+ send_msg_userauth_failure(0, 1);
+ return;
+ }
+#endif /* __ANDROID__ */
if (svr_opts.multiauthmethod && (ses.authstate.authtypes & ~AUTH_TYPE_PASSWORD)) {
/* successful password authentication, but extra auth required */
dropbear_log(LOG_NOTICE,