@@ -178,27 +178,25 @@ function unauthorized_error(reason) {
178178 *
179179 */
180180function create_access_key_auth ( req ) {
181- const access_key = req . rpc_params . access_key . unwrap ( ) ;
181+ const access_key = req . rpc_params . access_key ;
182182 const string_to_sign = req . rpc_params . string_to_sign ;
183183 const signature = req . rpc_params . signature ;
184184
185185 if ( _ . isUndefined ( string_to_sign ) || _ . isUndefined ( signature ) ) {
186186 throw new RpcError ( 'UNAUTHORIZED' , 'signature error' ) ;
187187 }
188188
189- const account = _ . find ( system_store . data . accounts , function ( acc ) {
190- if ( acc . access_keys ) {
191- return acc . access_keys [ 0 ] . access_key . unwrap ( ) . toString ( ) === access_key . toString ( ) ;
192- } else {
193- return false ;
194- }
195- } ) ;
189+ const account = system_store . get_account_by_access_key ( access_key ) ;
196190
197191 if ( ! account || account . deleted ) {
198192 throw new RpcError ( 'UNAUTHORIZED' , 'account not found' ) ;
199193 }
200194
201- const secret = account . access_keys [ 0 ] . secret_key . unwrap ( ) . toString ( ) ;
195+ const key_pair = account . access_keys . find ( key =>
196+ key . access_key . unwrap ( ) === access_key . unwrap ( )
197+ ) ;
198+
199+ const secret = key_pair . secret_key . unwrap ( ) ;
202200 const signature_test = signature_utils . get_signature_from_auth_token ( { string_to_sign : string_to_sign } , secret ) ;
203201 if ( signature_test !== signature ) {
204202 throw new RpcError ( 'UNAUTHORIZED' , 'signature error' ) ;
@@ -315,15 +313,16 @@ function _authorize_jwt_token(req) {
315313function _authorize_signature_token ( req ) {
316314 const auth_token_obj = req . auth_token ;
317315
318- const account = _ . find ( system_store . data . accounts , function ( acc ) {
319- return acc . access_keys && acc . access_keys . length > 0 &&
320- acc . access_keys [ 0 ] . access_key . unwrap ( ) ===
321- auth_token_obj . access_key ;
322- } ) ;
316+ const account = system_store . get_account_by_access_key ( new SensitiveString ( auth_token_obj . access_key ) ) ;
323317 if ( ! account || account . deleted ) {
324318 throw new RpcError ( 'UNAUTHORIZED' , 'account not found' ) ;
325319 }
326- const secret_key = account . access_keys [ 0 ] . secret_key ;
320+
321+ const key_pair = account . access_keys . find ( key =>
322+ key . access_key . unwrap ( ) === auth_token_obj . access_key
323+ ) ;
324+
325+ const secret_key = key_pair . secret_key ;
327326
328327 const role = _ . find ( system_store . data . roles , function ( r ) {
329328 return r . account . _id . toString ( ) === account . _id . toString ( ) ;
0 commit comments