diff --git a/src/common/backend/libpq/md5.cpp b/src/common/backend/libpq/md5.cpp index 9b8072e0f..f5af86993 100644 --- a/src/common/backend/libpq/md5.cpp +++ b/src/common/backend/libpq/md5.cpp @@ -309,6 +309,7 @@ bool pg_md5_encrypt(const char* passwd, const char* salt, size_t salt_len, char* { size_t passwd_len = strlen(passwd); errno_t rc = EOK; + /* the length of salt and password is <= SIZE_MAX */ #ifndef WIN32 if (unlikely(passwd_len >= SIZE_MAX - salt_len)) { return false; @@ -322,6 +323,7 @@ bool pg_md5_encrypt(const char* passwd, const char* salt, size_t salt_len, char* char* crypt_buf = (char*)malloc(passwd_len + salt_len + 1); bool ret = false; + /* the buffer is not exist */ if (crypt_buf == NULL) return false; diff --git a/src/common/backend/libpq/sha2.cpp b/src/common/backend/libpq/sha2.cpp index 3b996ffe2..484b55c18 100644 --- a/src/common/backend/libpq/sha2.cpp +++ b/src/common/backend/libpq/sha2.cpp @@ -772,6 +772,15 @@ bool pg_sha256_encrypt_for_md5(const char* password, const char* salt, size_t sa return true; } +/* + * @Description: calculate the encrypted password for GsSm3. + * @const char* password : the password need be encrypted. + * @const char* salt_s : the content fo the slat. + * @size_t salt_len : the length fo the slat. + * @char* buf : the buffer to store the encrypted key with GsSm3. + * @char* client_key_buf : the buffer to store the key of client. + * @int iteration_count : to record the number of the iteration. + */ bool GsSm3Encrypt( const char* password, const char* salt_s, size_t salt_len, char* buf, char* client_key_buf, int iteration_count) { @@ -799,6 +808,7 @@ bool GsSm3Encrypt( } password_len = strlen(password); + /* Tranform string(64Bytes) to binary(32Bytes) */ sha_hex_to_bytes32(salt, (char*)salt_s); /* calculate k */ pkcs_ret = PKCS5_PBKDF2_HMAC((char*)password, diff --git a/src/gausskernel/optimizer/commands/user.cpp b/src/gausskernel/optimizer/commands/user.cpp old mode 100755 new mode 100644 index 634d0976d..ae352ad88 --- a/src/gausskernel/optimizer/commands/user.cpp +++ b/src/gausskernel/optimizer/commands/user.cpp @@ -5911,6 +5911,7 @@ Datum calculate_encrypted_combined_password(const char* password, const char* ro errno_t rc = EOK; /* For PG ecological compatibility, we stored both sha256 and md5 password. */ + /* the encrypted method of sha256 */ if (!pg_sha256_encrypt(password, salt_string, strlen(salt_string), @@ -5921,7 +5922,7 @@ Datum calculate_encrypted_combined_password(const char* password, const char* ro securec_check(rc, "\0", "\0"); ereport(ERROR, (errcode(ERRCODE_INVALID_PASSWORD), errmsg("first stage encryption password failed"))); } - + /* the encrypted method of md5 */ if (!pg_md5_encrypt(password, rolname, strlen(rolname), encrypted_md5_password)) { rc = memset_s(encrypted_md5_password, MD5_PASSWD_LEN + 1, 0, MD5_PASSWD_LEN + 1); securec_check(rc, "\0", "\0"); @@ -6052,6 +6053,7 @@ static Datum gs_calculate_encrypted_sm3_password(const char* password, const cha Datum calculate_encrypted_password(bool is_encrypted, const char* password, const char* rolname, const char* salt_string) { + /* If the password is '\0' or not exist */ if (password == NULL || password[0] == '\0') { ereport(ERROR, (errcode(ERRCODE_INVALID_PASSWORD), errmsg("The password could not be NULL."))); } @@ -6059,6 +6061,7 @@ Datum calculate_encrypted_password(bool is_encrypted, const char* password, cons char encrypted_md5_password[MD5_PASSWD_LEN + 1] = {0}; Datum datum_value; + /* If the password has encrypted */ if (!is_encrypted || isPWDENCRYPTED(password)) { return CStringGetTextDatum(password); } @@ -6068,6 +6071,7 @@ Datum calculate_encrypted_password(bool is_encrypted, const char* password, cons * if Password_encryption_type is 0, the encrypted password is md5. * if Password_encryption_type is 1, the encrypted password is sha256 + md5. * if Password_encryption_type is 2, the encrypted password is sha256. + * if Password_encryption_type is 3, the encrypted password is SM3. */ if (u_sess->attr.attr_security.Password_encryption_type == 0) { if (!pg_md5_encrypt(password, rolname, strlen(rolname), encrypted_md5_password)) {