@@ -195,7 +195,8 @@ pg_be_scram_init(const char *username, const char *shadow_pass)
195
195
* The password looked like a SCRAM verifier, but could not be
196
196
* parsed.
197
197
*/
198
- elog (LOG , "invalid SCRAM verifier for user \"%s\"" , username );
198
+ ereport (LOG ,
199
+ (errmsg ("invalid SCRAM verifier for user \"%s\"" , username )));
199
200
got_verifier = false;
200
201
}
201
202
}
@@ -283,11 +284,13 @@ pg_be_scram_exchange(void *opaq, char *input, int inputlen,
283
284
if (inputlen == 0 )
284
285
ereport (ERROR ,
285
286
(errcode (ERRCODE_PROTOCOL_VIOLATION ),
286
- (errmsg ("malformed SCRAM message (empty message)" ))));
287
+ errmsg ("malformed SCRAM message" ),
288
+ errdetail ("The message is empty." )));
287
289
if (inputlen != strlen (input ))
288
290
ereport (ERROR ,
289
291
(errcode (ERRCODE_PROTOCOL_VIOLATION ),
290
- (errmsg ("malformed SCRAM message (length mismatch)" ))));
292
+ errmsg ("malformed SCRAM message" ),
293
+ errdetail ("Message length does not match input length." )));
291
294
292
295
switch (state -> state )
293
296
{
@@ -319,7 +322,8 @@ pg_be_scram_exchange(void *opaq, char *input, int inputlen,
319
322
if (!verify_final_nonce (state ))
320
323
ereport (ERROR ,
321
324
(errcode (ERRCODE_PROTOCOL_VIOLATION ),
322
- (errmsg ("invalid SCRAM response (nonce mismatch)" ))));
325
+ errmsg ("invalid SCRAM response" ),
326
+ errdetail ("Nonce does not match." )));
323
327
324
328
/*
325
329
* Now check the final nonce and the client proof.
@@ -391,14 +395,9 @@ pg_be_scram_build_verifier(const char *password)
391
395
392
396
/* Generate random salt */
393
397
if (!pg_backend_random (saltbuf , SCRAM_DEFAULT_SALT_LEN ))
394
- {
395
- ereport (LOG ,
398
+ ereport (ERROR ,
396
399
(errcode (ERRCODE_INTERNAL_ERROR ),
397
400
errmsg ("could not generate random salt" )));
398
- if (prep_password )
399
- pfree (prep_password );
400
- return NULL ;
401
- }
402
401
403
402
result = scram_build_verifier (saltbuf , SCRAM_DEFAULT_SALT_LEN ,
404
403
SCRAM_DEFAULT_ITERATIONS , password );
@@ -435,15 +434,17 @@ scram_verify_plain_password(const char *username, const char *password,
435
434
/*
436
435
* The password looked like a SCRAM verifier, but could not be parsed.
437
436
*/
438
- elog (LOG , "invalid SCRAM verifier for user \"%s\"" , username );
437
+ ereport (LOG ,
438
+ (errmsg ("invalid SCRAM verifier for user \"%s\"" , username )));
439
439
return false;
440
440
}
441
441
442
442
salt = palloc (pg_b64_dec_len (strlen (encoded_salt )));
443
443
saltlen = pg_b64_decode (encoded_salt , strlen (encoded_salt ), salt );
444
444
if (saltlen == -1 )
445
445
{
446
- elog (LOG , "invalid SCRAM verifier for user \"%s\"" , username );
446
+ ereport (LOG ,
447
+ (errmsg ("invalid SCRAM verifier for user \"%s\"" , username )));
447
448
return false;
448
449
}
449
450
@@ -582,14 +583,16 @@ read_attr_value(char **input, char attr)
582
583
if (* begin != attr )
583
584
ereport (ERROR ,
584
585
(errcode (ERRCODE_PROTOCOL_VIOLATION ),
585
- (errmsg ("malformed SCRAM message (attribute '%c' expected, %s found)" ,
586
- attr , sanitize_char (* begin )))));
586
+ errmsg ("malformed SCRAM message" ),
587
+ errdetail ("Expected attribute '%c' but found %s." ,
588
+ attr , sanitize_char (* begin ))));
587
589
begin ++ ;
588
590
589
591
if (* begin != '=' )
590
592
ereport (ERROR ,
591
593
(errcode (ERRCODE_PROTOCOL_VIOLATION ),
592
- (errmsg ("malformed SCRAM message (expected = in attr %c)" , attr ))));
594
+ errmsg ("malformed SCRAM message" ),
595
+ errdetail ("Expected character = for attribute %c." , attr )));
593
596
begin ++ ;
594
597
595
598
end = begin ;
@@ -669,16 +672,18 @@ read_any_attr(char **input, char *attr_p)
669
672
(attr >= 'a' && attr <= 'z' )))
670
673
ereport (ERROR ,
671
674
(errcode (ERRCODE_PROTOCOL_VIOLATION ),
672
- (errmsg ("malformed SCRAM message (attribute expected, invalid char %s found)" ,
673
- sanitize_char (attr )))));
675
+ errmsg ("malformed SCRAM message" ),
676
+ errdetail ("Attribute expected, but found invalid character %s." ,
677
+ sanitize_char (attr ))));
674
678
if (attr_p )
675
679
* attr_p = attr ;
676
680
begin ++ ;
677
681
678
682
if (* begin != '=' )
679
683
ereport (ERROR ,
680
684
(errcode (ERRCODE_PROTOCOL_VIOLATION ),
681
- (errmsg ("malformed SCRAM message (expected = in attr %c)" , attr ))));
685
+ errmsg ("malformed SCRAM message" ),
686
+ errdetail ("Expected character = for attribute %c." , attr )));
682
687
begin ++ ;
683
688
684
689
end = begin ;
@@ -795,14 +800,16 @@ read_client_first_message(scram_state *state, char *input)
795
800
default :
796
801
ereport (ERROR ,
797
802
(errcode (ERRCODE_PROTOCOL_VIOLATION ),
798
- (errmsg ("malformed SCRAM message (unexpected channel-binding flag %s)" ,
799
- sanitize_char (* input )))));
803
+ errmsg ("malformed SCRAM message" ),
804
+ errdetail ("Unexpected channel-binding flag %s." ,
805
+ sanitize_char (* input ))));
800
806
}
801
807
if (* input != ',' )
802
808
ereport (ERROR ,
803
809
(errcode (ERRCODE_PROTOCOL_VIOLATION ),
804
- errmsg ("malformed SCRAM message (comma expected, got %s)" ,
805
- sanitize_char (* input ))));
810
+ errmsg ("malformed SCRAM message" ),
811
+ errdetail ("Comma expected, but found character %s." ,
812
+ sanitize_char (* input ))));
806
813
input ++ ;
807
814
808
815
/*
@@ -815,8 +822,9 @@ read_client_first_message(scram_state *state, char *input)
815
822
if (* input != ',' )
816
823
ereport (ERROR ,
817
824
(errcode (ERRCODE_PROTOCOL_VIOLATION ),
818
- errmsg ("malformed SCRAM message (unexpected attribute %s in client-first-message)" ,
819
- sanitize_char (* input ))));
825
+ errmsg ("malformed SCRAM message" ),
826
+ errdetail ("Unexpected attribute %s in client-first-message." ,
827
+ sanitize_char (* input ))));
820
828
input ++ ;
821
829
822
830
state -> client_first_message_bare = pstrdup (input );
@@ -831,7 +839,7 @@ read_client_first_message(scram_state *state, char *input)
831
839
if (* input == 'm' )
832
840
ereport (ERROR ,
833
841
(errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
834
- errmsg ("client requires mandatory SCRAM extension" )));
842
+ errmsg ("client requires an unsupported SCRAM extension" )));
835
843
836
844
/*
837
845
* Read username. Note: this is ignored. We use the username from the
@@ -960,7 +968,7 @@ build_server_first_message(scram_state *state)
960
968
int encoded_len ;
961
969
962
970
if (!pg_backend_random (raw_nonce , SCRAM_RAW_NONCE_LEN ))
963
- ereport (COMMERROR ,
971
+ ereport (ERROR ,
964
972
(errcode (ERRCODE_INTERNAL_ERROR ),
965
973
errmsg ("could not generate random nonce" )));
966
974
@@ -1044,14 +1052,16 @@ read_client_final_message(scram_state *state, char *input)
1044
1052
if (pg_b64_decode (value , strlen (value ), client_proof ) != SCRAM_KEY_LEN )
1045
1053
ereport (ERROR ,
1046
1054
(errcode (ERRCODE_PROTOCOL_VIOLATION ),
1047
- (errmsg ("malformed SCRAM message (malformed proof in client-final-message" ))));
1055
+ errmsg ("malformed SCRAM message" ),
1056
+ errdetail ("Malformed proof in client-final-message." )));
1048
1057
memcpy (state -> ClientProof , client_proof , SCRAM_KEY_LEN );
1049
1058
pfree (client_proof );
1050
1059
1051
1060
if (* p != '\0' )
1052
1061
ereport (ERROR ,
1053
1062
(errcode (ERRCODE_PROTOCOL_VIOLATION ),
1054
- (errmsg ("malformed SCRAM message (garbage at end of client-final-message)" ))));
1063
+ errmsg ("malformed SCRAM message" ),
1064
+ errdetail ("Garbage found at the end of client-final-message." )));
1055
1065
1056
1066
state -> client_final_message_without_proof = palloc (proof - begin + 1 );
1057
1067
memcpy (state -> client_final_message_without_proof , input , proof - begin );
0 commit comments