fix(S3): switch to Android SDK

This commit is contained in:
Manuel Jenny 2021-04-22 10:35:49 +02:00
parent 76f757293a
commit 2a8e635177
No known key found for this signature in database
GPG Key ID: 1C80FE62B2BEAA18
3 changed files with 18 additions and 9 deletions

View File

@ -51,6 +51,7 @@ ext {
// do not update to 1.4.0 until minsdk is 7.x (or desugaring works better) otherwise it will crash on 6.x
cryptolibVersion = '1.3.0'
awsAndroidSdkS3 = '2.22.6'
awsS3Sdk = '1.11.999'
dropboxVersion = '4.0.0'
@ -103,7 +104,7 @@ ext {
androidxViewpager : "androidx.viewpager:viewpager:${androidxViewpagerVersion}",
androidxSwiperefresh : "androidx.swiperefreshlayout:swiperefreshlayout:${androidxSwiperefreshVersion}",
androidxPreference : "androidx.preference:preference:${androidxPreferenceVersion}",
awsS3 : "com.amazonaws:aws-java-sdk-s3:${awsS3Sdk}",
awsAndroidS3 : "com.amazonaws:aws-android-sdk-s3:${awsAndroidSdkS3}",
documentFile : "androidx.documentfile:documentfile:${androidxDocumentfileVersion}",
recyclerView : "androidx.recyclerview:recyclerview:${androidxRecyclerViewVersion}",
androidxTestCore : "androidx.test:core:${androidxTestCoreVersion}",

View File

@ -99,7 +99,7 @@ dependencies {
annotationProcessor dependencies.daggerCompiler
implementation dependencies.dagger
// cloud
implementation dependencies.awsS3
implementation dependencies.awsAndroidS3
implementation dependencies.dropbox
implementation dependencies.msgraph

View File

@ -2,12 +2,12 @@ package org.cryptomator.data.cloud.s3;
import android.content.Context;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.client.builder.AwsClientBuilder;
import com.amazonaws.regions.Region;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.S3ClientOptions;
import org.cryptomator.domain.S3Cloud;
import org.cryptomator.util.crypto.CredentialCryptor;
@ -24,13 +24,21 @@ class S3ClientFactory {
}
private AmazonS3 createApiClient(S3Cloud cloud, Context context) {
AwsClientBuilder.EndpointConfiguration endpointConfiguration = new AwsClientBuilder.EndpointConfiguration(cloud.s3Endpoint(), cloud.s3Region());
Region region = Region.getRegion(cloud.s3Region());
AWSCredentials credentials = new BasicAWSCredentials(cloud.accessKey(), decrypt(cloud.secretKey(), context));
S3ClientOptions.Builder s3ClientOptionsBuilder = S3ClientOptions.builder();
if (region == null) {
region = Region.getRegion(Regions.DEFAULT_REGION);
s3ClientOptionsBuilder.setPayloadSigningEnabled(false);
}
return AmazonS3ClientBuilder.standard().withEndpointConfiguration(endpointConfiguration).withCredentials(new AWSStaticCredentialsProvider(credentials)).build();
AmazonS3Client client = new AmazonS3Client(new BasicAWSCredentials(decrypt(cloud.accessKey(), context), decrypt(cloud.secretKey(), context)), region);
client.setEndpoint(cloud.s3Endpoint());
client.setS3ClientOptions(s3ClientOptionsBuilder.build());
return client;
}
private String decrypt(String password, Context context) {
return CredentialCryptor //
.getInstance(context) //