Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AmazonS3Client(new CognitoCachingCredentialsProvider(context, config)) is deprecated #960

Closed
mbk820 opened this issue May 16, 2019 · 4 comments
Assignees
Labels
core Issues with the AWS Android Core library question General question s3 Issues with the AWS Android SDK for Simple Storage Service (S3).

Comments

@mbk820
Copy link

mbk820 commented May 16, 2019

Hey, should I use 'CredentialsProvider' with my secret key in my live application?

Anyone can decompile the APK and get my secret and access keys,
What is the right way to initialize the s3 client and use the s3 bucket storage?
Even in AWS documentation, the deprecated method is mentioned. Please guide.

Right now I am using:

AWSConfiguration config = new AWSConfiguration(context); transferUtility = TransferUtility.builder() .context(context) .awsConfiguration(config) .s3Client(new AmazonS3Client(new CognitoCachingCredentialsProvider(context, config))) .build();

By using this crash occurs on mostly KitKat devices:

Caused by java.lang.IllegalArgumentException TransferUtility has not been configured with a default bucket. Please use the corresponding method that specifies the bucket name or configure the default bucket name in construction of the object. See TransferUtility.builder().defaultBucket() or TransferUtility.builder().awsConfiguration()

But if I use this:

BasicAWSCredentials awsCreds = new BasicAWSCredentials("access_key_id", "secret_key_id"); AmazonS3Client s3Client = new AmazonS3Client(awsCreds, Region.getRegion(Regions.US_EAST_2));
Anyone can decompile the APK and get my secret and access keys.

What is the exact right way to use Transfer Utility and initializing the s3 client?

@kvasukib sir please see this.

@mutablealligator
Copy link
Contributor

@mbk820 Your concern is valid. I would recommend you to use Amazon Cognito Identity Pools which retrieves a set of temporary credentials (AWS Access and Secret Access Keys) that are valid for an hour and the SDK retrieves new credentials after the expiration.

AWSConfiguration awsConfiguration = new AWSConfiguration(getApplicationContext());
CognitoCachingCredentialsProvider awsCreds = new CognitoCachingCredentialsProvider(getApplicationContext(), awsConfiguration);
AmazonS3Client s3Client = new AmazonS3Client(awsCreds, Region.getRegion(Regions.US_EAST_2));

TransferUtility transferUtility  = TransferUtility.builder()
    .context(getApplicationContext())
    .awsConfiguration(awsConfiguration)
    .s3Client(s3Client)
    .build();

Take a look at our documentation for more details: https://aws-amplify.github.io/docs/android/storage

@mutablealligator mutablealligator self-assigned this May 16, 2019
@mutablealligator mutablealligator added s3 Issues with the AWS Android SDK for Simple Storage Service (S3). question General question pending-community-response Issue is pending response from the issue requestor closing soon Issue will auto-close if there is no additional activity within 7 days. and removed pending-community-response Issue is pending response from the issue requestor labels May 16, 2019
@mbk820
Copy link
Author

mbk820 commented May 25, 2019

@kvasukib Hi dear, Hope you are fine, We are using s3 paid services, Our app is live with a lot of users, our users are facing ANRs while initializing 'CognitoCachingCredentialsProvider' and creating 'TransferUtility' object, and some other ANRs, all are related AWS. We have to load a lot of images from s3 storage at runtime while the user scrolling the recycle view.

This is ANR stats, Please give some time, and provide a solution.

`
"main" prio=5 tid=1 Native
| group="main" sCount=1 dsCount=0 flags=1 obj=0x74b64f70 self=0xadabb000
| sysTid=1445 nice=-10 cgrp=default sched=0/0 handle=0xb2136494
| state=S schedstat=( 5851335831 555704094 4259 ) utm=467 stm=116 core=5 HZ=100
| stack=0xbe09b000-0xbe09d000 stackSize=8MB
| held mutexes=
#00 pc 000000000005377c /system/lib/libc.so (__ioctl+8)
#1 pc 00000000000219f3 /system/lib/libc.so (ioctl+30)
#2 pc 000000000003d451 /system/lib/libbinder.so (android::IPCThreadState::talkWithDriver(bool)+168)
#3 pc 000000000003ddff /system/lib/libbinder.so (android::IPCThreadState::waitForResponse(android::Parcel*, int*)+26)
#4 pc 00000000000371bd /system/lib/libbinder.so (android::BpBinder::transact(unsigned int, android::Parcel const&, android::Parcel*, unsigned int)+36)
#5 pc 00000000000c3fe7 /system/lib/libandroid_runtime.so (android_os_BinderProxy_transact(_JNIEnv*, _jobject*, int, _jobject*, _jobject*, int)+82)
at android.os.BinderProxy.transactNative (Native method)
at android.os.BinderProxy.transact (Binder.java:1136)
at android.security.IKeystoreService$Stub$Proxy.finish (IKeystoreService.java:1404)
at android.security.KeyStore.finish (KeyStore.java:581)
at android.security.keystore.KeyStoreCryptoOperationChunkedStreamer$MainDataStream.finish (KeyStoreCryptoOperationChunkedStreamer.java:338)
at android.security.keystore.KeyStoreCryptoOperationChunkedStreamer.doFinal (KeyStoreCryptoOperationChunkedStreamer.java:220)
at android.security.keystore.AndroidKeyStoreAuthenticatedAESCipherSpi$BufferAllOutputUntilDoFinalStreamer.doFinal (AndroidKeyStoreAuthenticatedAESCipherSpi.java:373)
at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineDoFinal (AndroidKeyStoreCipherSpiBase.java:506)
at javax.crypto.Cipher.doFinal (Cipher.java:2055)
at com.amazonaws.internal.keyvaluestore.AWSKeyValueStore.decrypt (AWSKeyValueStore.java:360)
at com.amazonaws.internal.keyvaluestore.AWSKeyValueStore.get (AWSKeyValueStore.java:207)

  • locked <0x018d2329> (a com.amazonaws.internal.keyvaluestore.AWSKeyValueStore)
    at com.amazonaws.auth.CognitoCachingCredentialsProvider.loadCachedCredentials (CognitoCachingCredentialsProvider.java:606)
    at com.amazonaws.auth.CognitoCachingCredentialsProvider.initialize (CognitoCachingCredentialsProvider.java:430)
    at com.amazonaws.auth.CognitoCachingCredentialsProvider. (CognitoCachingCredentialsProvider.java:230)
    at com.example.yasir.logomakerwithcollageview.Templates.S3Downloader. (S3Downloader.java:55)
    at com.example.yasir.logomakerwithcollageview.Templates.TemplatesCatSubAdapter. (TemplatesCatSubAdapter.java:111)
    at com.example.yasir.logomakerwithcollageview.Templates.TemplatesCatsAdapter.onBindViewHolder (TemplatesCatsAdapter.java:177)
    at com.example.yasir.logomakerwithcollageview.Templates.TemplatesCatsAdapter.onBindViewHolder (TemplatesCatsAdapter.java:27)
    at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder (RecyclerView.java:6673)
    at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder (RecyclerView.java:6714)
    at android.support.v7.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline (RecyclerView.java:5647)
    at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline (RecyclerView.java:5913)
    at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition (RecyclerView.java:5752)
    at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition (RecyclerView.java:5748)
    at android.support.v7.widget.LinearLayoutManager$LayoutState.next (LinearLayoutManager.java:2232)
    at android.support.v7.widget.LinearLayoutManager.layoutChunk (LinearLayoutManager.java:1559)
    at android.support.v7.widget.LinearLayoutManager.fill (LinearLayoutManager.java:1519)
    at android.support.v7.widget.LinearLayoutManager.scrollBy (LinearLayoutManager.java:1333)
    at android.support.v7.widget.LinearLayoutManager.scrollVerticallyBy (LinearLayoutManager.java:1077)
    at android.support.v7.widget.RecyclerView.scrollByInternal (RecyclerView.java:1815)
    at android.support.v7.widget.RecyclerView.onTouchEvent (RecyclerView.java:3076)
    at android.view.View.dispatchTouchEvent (View.java:12516)
    at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3026)
    at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2705)
    at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3032)
    at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2719)
    at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3032)
    at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2719)
    at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3032)
    at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2719)
    at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3032)
    at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2719)
    at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3032)
    at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2719)
    at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3032)
    at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2719)
    at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3032)
    at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2719)
    at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3032)
    at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2719)
    at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3032)
    at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2719)
    at com.android.internal.policy.DecorView.superDispatchTouchEvent (DecorView.java:479)
    at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent (PhoneWindow.java:1836)
    at android.app.Activity.dispatchTouchEvent (Activity.java:3408)
    at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent (WindowCallbackWrapper.java:68)
    at com.android.internal.policy.DecorView.dispatchTouchEvent (DecorView.java:437)
    at android.view.View.dispatchPointerEvent (View.java:12755)
    at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent (ViewRootImpl.java:5151)
    at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess (ViewRootImpl.java:4954)
    at android.view.ViewRootImpl$InputStage.deliver (ViewRootImpl.java:4471)
    at android.view.ViewRootImpl$InputStage.onDeliverToNext (ViewRootImpl.java:4524)
    at android.view.ViewRootImpl$InputStage.forward (ViewRootImpl.java:4490)
    at android.view.ViewRootImpl$AsyncInputStage.forward (ViewRootImpl.java:4630)
    at android.view.ViewRootImpl$InputStage.apply (ViewRootImpl.java:4498)
    at android.view.ViewRootImpl$AsyncInputStage.apply (ViewRootImpl.java:4687)
    at android.view.ViewRootImpl$InputStage.deliver (ViewRootImpl.java:4471)
    at android.view.ViewRootImpl$InputStage.onDeliverToNext (ViewRootImpl.java:4524)
    at android.view.ViewRootImpl$InputStage.forward (ViewRootImpl.java:4490)
    at android.view.ViewRootImpl$InputStage.apply (ViewRootImpl.java:4498)
    at android.view.ViewRootImpl$InputStage.deliver (ViewRootImpl.java:4471)
    at android.view.ViewRootImpl.deliverInputEvent (ViewRootImpl.java:7197)
    at android.view.ViewRootImpl.doProcessInputEvents (ViewRootImpl.java:7131)
    at android.view.ViewRootImpl.enqueueInputEvent (ViewRootImpl.java:7092)
    at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent (ViewRootImpl.java:7300)
    at android.view.InputEventReceiver.dispatchInputEvent (InputEventReceiver.java:193)
    at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents (Native method)
    at android.view.InputEventReceiver.consumeBatchedInputEvents (InputEventReceiver.java:184)
    at android.view.ViewRootImpl.doConsumeBatchedInput (ViewRootImpl.java:7271)
    at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run (ViewRootImpl.java:7323)
    at android.view.Choreographer$CallbackRecord.run (Choreographer.java:949)
    at android.view.Choreographer.doCallbacks (Choreographer.java:761)
    at android.view.Choreographer.doFrame (Choreographer.java:690)
    at android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:935)
    at android.os.Handler.handleCallback (Handler.java:873)
    at android.os.Handler.dispatchMessage (Handler.java:99)
    at android.os.Looper.loop (Looper.java:193)
    at android.app.ActivityThread.main (ActivityThread.java:6923)
    at java.lang.reflect.Method.invoke (Native method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:870)
    `

@stale stale bot removed the closing soon Issue will auto-close if there is no additional activity within 7 days. label May 25, 2019
@minbi minbi added the core Issues with the AWS Android Core library label May 29, 2019
@minbi
Copy link
Contributor

minbi commented May 29, 2019

Thanks for the update. @kvasukib Can you make a note of this crash?

@mutablealligator
Copy link
Contributor

@mbk820 Thank you for the bug report. I will track this crash as part of #937 issue. Closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Issues with the AWS Android Core library question General question s3 Issues with the AWS Android SDK for Simple Storage Service (S3).
Projects
None yet
Development

No branches or pull requests

3 participants