You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
proxysql/deps/mariadb-client-library/ma_password.c.patch

57 lines
1.4 KiB

@@ -105,6 +105,35 @@
}
}
+unsigned char decode_char(char x) {
+ if (x >= '0' && x <= '9')
+ return (x - 0x30);
+ else if (x >= 'A' && x <= 'F')
+ return(x - 0x37);
+ else if (x >= 'a' && x <= 'f')
+ return(x - 0x57);
+ else {
+ fprintf(stderr,"%s:%d:%s(): [ERROR in libmariadbclient]: \n", __FILE__, __LINE__, __func__);
+ return 0;
+ }
+}
+
+void unhex_pass(unsigned char *out, const char *in) {
+ int i=0;
+ for (i=0;i<SHA1_MAX_LENGTH;i++) {
+ // this can be simplified a lot, but leaving like this to make it easy to debug
+ unsigned char c=0, d=0;
+ c=decode_char(in[i*2]);
+ c=(c*16) & 0xF0;
+ d=decode_char(in[i*2+1]);
+ d=d & 0x0F;
+ c+=d;
+ out[i]=c;
+ }
+}
+
+
+
void ma_scramble_41(const unsigned char *buffer, const char *scramble, const char *password)
{
_MA_SHA1_CTX context;
@@ -112,10 +141,15 @@
unsigned char sha2[SHA1_MAX_LENGTH];
- /* Phase 1: hash password */
- ma_SHA1Init(&context);
- ma_SHA1Update(&context, (unsigned char *)password, strlen((char *)password));
- ma_SHA1Final(sha1, &context);
+ if (password[0]=='*') {
+ unhex_pass(sha1,password+1);
+ } else {
+ /* Phase 1: hash password */
+ ma_SHA1Init(&context);
+ ma_SHA1Update(&context, (unsigned char *)password, strlen((char *)password));
+ ma_SHA1Final(sha1, &context);
+ }
+
/* Phase 2: hash sha1 */
ma_SHA1Init(&context);