@@ -31,14 +31,10 @@ var HTTPDigestAuthentication = (function () {
31
31
} ) ;
32
32
} ;
33
33
var authHeader = arg . findHeader ( 'Authorization' ) ;
34
- if ( ! authHeader ) {
35
- onError ( Errors_1 . Errors . MissingAuthorisationHeader ) ;
36
- return ;
37
- }
38
- if ( ! / ^ D i g e s t ( \s * [ a - z A - Z ] + \s * = \s * ( ( " ( \\ " | [ ^ " ] ) + " ) | ( [ ^ , \s ] + ) ) \s * ( , | $ ) ) + $ / . test ( authHeader ) ) {
39
- onError ( Errors_1 . Errors . WrongHeaderFormat ) ;
40
- return ;
41
- }
34
+ if ( ! authHeader )
35
+ return onError ( Errors_1 . Errors . MissingAuthorisationHeader ) ;
36
+ if ( ! / ^ D i g e s t ( \s * [ a - z A - Z ] + \s * = \s * ( ( " ( \\ " | [ ^ " ] ) + " ) | ( [ ^ , \s ] + ) ) ? \s * ( , | $ ) ) + $ / . test ( authHeader ) )
37
+ return onError ( Errors_1 . Errors . WrongHeaderFormat ) ;
42
38
authHeader = authHeader . substring ( authHeader . indexOf ( ' ' ) + 1 ) ; // remove the authentication type from the string
43
39
var authProps = { } ;
44
40
var rex = / ( [ a - z A - Z ] + ) \s * = \s * (?: (?: " ( (?: \\ " | [ ^ " ] ) + ) " ) | ( [ ^ , \s ] + ) ) / g;
@@ -47,18 +43,26 @@ var HTTPDigestAuthentication = (function () {
47
43
authProps [ match [ 1 ] ] = match [ 3 ] ? match [ 3 ] : match [ 2 ] ;
48
44
match = rex . exec ( authHeader ) ;
49
45
}
50
- if ( ! ( authProps . username && authProps . nonce && authProps . nc && authProps . cnonce && authProps . qop && authProps . response ) ) {
51
- onError ( Errors_1 . Errors . AuenticationPropertyMissing ) ;
52
- return ;
53
- }
46
+ if ( ! ( authProps . username && authProps . nonce && authProps . response ) )
47
+ return onError ( Errors_1 . Errors . AuenticationPropertyMissing ) ;
48
+ if ( ! authProps . algorithm )
49
+ authProps . algorithm = 'MD5' ;
54
50
userManager . getUserByName ( authProps . username , function ( e , user ) {
55
- if ( e ) {
56
- onError ( e ) ;
57
- return ;
58
- }
51
+ if ( e )
52
+ return onError ( e ) ;
59
53
var ha1 = md5 ( authProps . username + ':' + _this . realm + ':' + ( user . password ? user . password : '' ) ) ;
60
- var ha2 = md5 ( arg . request . method . toString ( ) . toUpperCase ( ) + ':' + arg . uri ) ;
61
- var result = md5 ( ha1 + ':' + authProps . nonce + ':' + authProps . nc + ':' + authProps . cnonce + ':' + authProps . qop + ':' + ha2 ) ;
54
+ if ( authProps . algorithm === 'MD5-sess' )
55
+ ha1 = md5 ( ha1 + ':' + authProps . nonce + ':' + authProps . cnonce ) ;
56
+ var ha2 ;
57
+ if ( authProps . qop === 'auth-int' )
58
+ return onError ( Errors_1 . Errors . WrongHeaderFormat ) ; // ha2 = md5(ctx.request.method.toString().toUpperCase() + ':' + ctx.requested.uri + ':' + md5(...));
59
+ else
60
+ ha2 = md5 ( arg . request . method . toString ( ) . toUpperCase ( ) + ':' + arg . uri ) ;
61
+ var result ;
62
+ if ( authProps . qop === 'auth-int' || authProps . qop === 'auth' )
63
+ result = md5 ( ha1 + ':' + authProps . nonce + ':' + authProps . nc + ':' + authProps . cnonce + ':' + authProps . qop + ':' + ha2 ) ;
64
+ else
65
+ result = md5 ( ha1 + ':' + authProps . nonce + ':' + ha2 ) ;
62
66
if ( result . toLowerCase ( ) === authProps . response . toLowerCase ( ) )
63
67
callback ( Errors_1 . Errors . None , user ) ;
64
68
else
0 commit comments