SSLException due uploading item for Amazon service
Asked Answered
D

2

7

I upload my file to aws service from android. I configured it like this:

  AwsMetadata awsMetadata = resultData.getParcelable(Params.CommandMessage.EXTRA_MESSAGE);
        AWSCredentials awsCredentials = new BasicAWSCredentials(
                awsMetadata.getAccountId(),
                awsMetadata.getSecretKey()
        );
        // set up region
        TransferManager transferManager = new TransferManager(awsCredentials);
        Region region = Region.getRegion(Regions.fromName(awsMetadata.getRegionEndpoint()));
        transferManager.getAmazonS3Client().setRegion(region);


        final MediaItem mediaItem = datasource.get(0);
        Log.d(App.TAG, "File is exists: "
                + mediaItem.getContentUri() + " "
                + new File(mediaItem.getContentUri()).exists());

        // prepare file for upload
        PutObjectRequest putObjectRequest = new PutObjectRequest(
                awsMetadata.getBucketName(),
                awsMetadata.getSecretKey(),
                new File(mediaItem.getContentUri())
        );


        Log.d(App.TAG, "Total data: " + mediaItem.getSize());
        Upload upload = transferManager.upload(putObjectRequest, new S3ProgressListener() {

            private int totalTransfered = 0;

            @Override
            public void onPersistableTransfer(PersistableTransfer persistableTransfer) {
            }

            @Override
            public void progressChanged(ProgressEvent progressEvent) {

                Log.d(App.TAG, "Bytes are transferred: " + progressEvent.getBytesTransferred());
                totalTransfered += progressEvent.getBytesTransferred();
                long totalSize = mediaItem.getSize();
                Log.d(App.TAG, "Total transferred: " + ((totalTransfered / totalSize) * 100) + " percent");
            }
        });
    }

And I got SSLException:

  06-01 11:45:00.712    5182-5768/com.home I/AmazonHttpClient﹕ Unable to execute HTTP request: Write error: ssl=0xb4bb3600: I/O error during system call, Connection reset by peer
        javax.net.ssl.SSLException: Write error: ssl=0xb4bb3600: I/O error during system call, Connection reset by peer
                at com.android.org.conscrypt.NativeCrypto.SSL_write(Native Method)
                at com.android.org.conscrypt.OpenSSLSocketImpl$SSLOutputStream.write(OpenSSLSocketImpl.java:765)
                at com.android.okio.Okio$1.write(Okio.java:70)
                at com.android.okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:116)
                at com.android.okio.RealBufferedSink.write(RealBufferedSink.java:44)
                at com.android.okhttp.internal.http.HttpConnection$FixedLengthSink.write(HttpConnection.java:291)
                at com.android.okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:116)
                at com.android.okio.RealBufferedSink$1.write(RealBufferedSink.java:131)
                at com.amazonaws.http.UrlHttpClient.write(UrlHttpClient.java:155)
                at com.amazonaws.http.UrlHttpClient.createConnection(UrlHttpClient.java:143)
                at com.amazonaws.http.UrlHttpClient.execute(UrlHttpClient.java:60)
                at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:353)
                at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:196)
                at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:4234)
                at com.amazonaws.services.s3.AmazonS3Client.putObject(AmazonS3Client.java:1644)
                at com.amazonaws.mobileconnectors.s3.transfermanager.internal.UploadCallable.uploadInOneChunk(UploadCallable.java:134)
                at com.amazonaws.mobileconnectors.s3.transfermanager.internal.UploadCallable.call(UploadCallable.java:126)
                at com.amazonaws.mobileconnectors.s3.transfermanager.internal.UploadMonitor.upload(UploadMonitor.java:182)
                at com.amazonaws.mobileconnectors.s3.transfermanager.internal.UploadMonitor.call(UploadMonitor.java:140)
                at com.amazonaws.mobileconnectors.s3.transfermanager.internal.UploadMonitor.call(UploadMonitor.java:54)
                at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
                at java.lang.Thread.run(Thread.java:818)

Happens on Android 4.3 and 4.4

com.amazonaws.services.s3.model.AmazonS3Exception: There were headers present in the request which were not signed (Service: Amazon S3; Status Code: 403; Error Code: AccessDenied; Request ID: 06CAF94ADEFE242E), S3 Extended Request ID: ouMiu+15fshPnT9uz95T3Drj+Gea3gI1c+Rj34BhcSCzbIH2ypOeK9yvIlNCxbxt

Amazon SDK uses it's own client and it should be configured properly from the box.

What is the reason for this beahaviour?

Dionysiac answered 1/6, 2015 at 3:55 Comment(10)
You got what SSLException? The stack trace should have been included in the question.Naara
It was added. You can see it if you scroll internal scroll viewDionysiac
AWS Android SDK uses system's default SSL library. Would you please tell me about the API level, device or emulator, SDK version, and S3 region?Kautz
It is 5.1 but it should support a 4+ as wellDionysiac
The region which I use is "cn-north-1"Dionysiac
thank you for the information. I will try to reproduce it and get back to you asap.Kautz
I can't reproduce the problem. Some questions on StackOverflow said this error can be caused by shaky network. Is your device on Wifi or LTE? Have you tried to use AmazonS3Client directly?Kautz
I used WiFI, the same code for global bucket works fine. Yes, I have tried AmazonS3Client directly -- the same issueDionysiac
The issue is reproduced only for China region ( "cn-north-1"), for others buckets it works. Also the 4.3 and 4.4 versions of Android shows another exception. Please see update for original postDionysiac
We identified the root cause to that exception and we are working on a fix. Sorry about the trouble.Kautz
K
2

There is a bug in the SDK where certain headers aren't signed. It will affect S3 in some regions, e.g. Frankfurt (eu-central-1) and China (cn-north-1), where sigv4 is required.

AWS SDK for Android v2.2.2 is out http://aws.amazon.com/releasenotes/4067314458888112. This release addresses the sigv4 signing issue with S3. Check it out at http://aws.amazon.com/mobile/sdk/.

Kautz answered 3/6, 2015 at 21:7 Comment(12)
Thank you for the update. Please keep me (and a whole community informed)Dionysiac
Hi Yangfan, could you please clarify when we can expect the fix for this bug? I was told Amazon has releases on 2 weeks basis. Is it true?Dionysiac
Please also take a look on this question #30664795 I faced with issues with non-China bucket as wellDionysiac
Not strictly on 2 week basis. This fix is likely done by next week.Kautz
Hi Yangfan, do you have a progress with patch to SDK?Dionysiac
AWS SDK for Android v2.2.2 is out aws.amazon.com/releasenotes/4067314458888112. This release addresses an AWS signature version 4 signing issue with S3. Check it out at aws.amazon.com/mobile/sdk.Kautz
Thank you, it works. Could you please suggest what is the meaning of "0" as a progress event code? It looks like this constant is not covered by SDKDionysiac
You can find the meaning of event code in the source github.com/aws/aws-sdk-android/blob/master/aws-android-sdk-core/…. "0" is the default, which doesn't match to a particular event. It could mean that the ProgressEvent object hasn't been updated yet. I think it's a bit off topic now. If you have further questions, please create a new one and tag it correctly. I will continue to help. Thank you.Kautz
Please take a look on github.com/aws/aws-sdk-android/issues/46, It was uploaded on Friday but were left without any reaction on it.Dionysiac
Im having this problem too, Im using this: compile 'com.amazonaws:aws-android-sdk-core:2.+' compile 'com.amazonaws:aws-android-sdk-cognito:2.+' compile 'com.amazonaws:aws-android-sdk-s3:2.+' As you can see there is 2.* in each of the services usedSenegambia
Me again, doing a follow up, figure what the problem is, is time difference problem. After messing with the ClientConfiguration for a while I thought it could be cause I have to change the hour manually on my phone (due some energy politics there was no time change this year), so I change the hour on the phone to what it should be. It worked. So there is the problem, how can I solve it without asking every user to change the hour on their phones?Senegambia
Hi, I have the latest sdk but still i face upload fail and similar issue. Please help !!!!Karren
A
2

I was having the same problem on Android when trying to upload directly from the device to S3, and it was related to time difference issues on the devices, as cutiko said. I was using latest SDK version available (2.3.3), so the mentioned SDK fix didn't really solve my problem.

What I did to solve it:

  • Call an external service that returns the UTC time of an AWS server
  • Calculate the time difference between device time and server time, both in UTC
  • Use the s3Client.setTimeOffset() to set the time skew calculated before (in seconds)

Hope it helps.

Adinaadine answered 17/11, 2016 at 11:2 Comment(1)
Inspired by this, I changed my Android phone's Date and Time setting to Automatic Time Update and it solved my issue. Pretty sure AWS servers throw this error if there is a timestamp issue. Thank you Sir!Poultice

© 2022 - 2024 — McMap. All rights reserved.