@@ -187,18 +187,25 @@ function create_access_key_auth(req) {
187187 }
188188
189189 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- }
190+ return acc . access_keys && acc . access_keys . length > 0 &&
191+ acc . access_keys . some ( key =>
192+ key . access_key . unwrap ( ) . toString ( ) === access_key . toString ( )
193+ ) ;
195194 } ) ;
196195
197196 if ( ! account || account . deleted ) {
198197 throw new RpcError ( 'UNAUTHORIZED' , 'account not found' ) ;
199198 }
200199
201- const secret = account . access_keys [ 0 ] . secret_key . unwrap ( ) . toString ( ) ;
200+ const key_pair = account . access_keys . find ( key =>
201+ key . access_key . unwrap ( ) . toString ( ) === access_key . toString ( )
202+ ) ;
203+
204+ if ( key_pair . deactivated ) {
205+ throw new RpcError ( 'UNAUTHORIZED' , 'access key is deactivated' ) ;
206+ }
207+
208+ const secret = key_pair . secret_key . unwrap ( ) . toString ( ) ;
202209 const signature_test = signature_utils . get_signature_from_auth_token ( { string_to_sign : string_to_sign } , secret ) ;
203210 if ( signature_test !== signature ) {
204211 throw new RpcError ( 'UNAUTHORIZED' , 'signature error' ) ;
@@ -316,14 +323,24 @@ function _authorize_signature_token(req) {
316323 const auth_token_obj = req . auth_token ;
317324
318325 const account = _ . find ( system_store . data . accounts , function ( acc ) {
319- return acc . access_keys &&
320- acc . access_keys [ 0 ] . access_key . unwrap ( ) ===
321- auth_token_obj . access_key ;
326+ return acc . access_keys && acc . access_keys . length > 0 &&
327+ acc . access_keys . some ( key =>
328+ key . access_key . unwrap ( ) === auth_token_obj . access_key
329+ ) ;
322330 } ) ;
323331 if ( ! account || account . deleted ) {
324332 throw new RpcError ( 'UNAUTHORIZED' , 'account not found' ) ;
325333 }
326- const secret_key = account . access_keys [ 0 ] . secret_key ;
334+
335+ const key_pair = account . access_keys . find ( key =>
336+ key . access_key . unwrap ( ) === auth_token_obj . access_key
337+ ) ;
338+
339+ if ( key_pair . deactivated ) {
340+ throw new RpcError ( 'UNAUTHORIZED' , 'access key is deactivated' ) ;
341+ }
342+
343+ const secret_key = key_pair . secret_key ;
327344
328345 const role = _ . find ( system_store . data . roles , function ( r ) {
329346 return r . account . _id . toString ( ) === account . _id . toString ( ) ;
0 commit comments