Unverified Commit 7c289f07 authored by Javier Guerra's avatar Javier Guerra Committed by GitHub

Merge pull request #18 from openconnectivity/develop

Merge develop into master
parents 27cb6c9f 1812f987
...@@ -30,7 +30,7 @@ android { ...@@ -30,7 +30,7 @@ android {
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 28 targetSdkVersion 28
versionCode 13 versionCode 13
versionName "2.5.0" versionName "2.6.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
compileOptions { compileOptions {
......
...@@ -154,6 +154,15 @@ public class IORepository { ...@@ -154,6 +154,15 @@ public class IORepository {
}); });
} }
public Single<X509Certificate> getFileAsX509Certificate(InputStream is) {
return Single.create(emitter -> {
Security.addProvider(new BouncyCastleProvider());
CertificateFactory factory = CertificateFactory.getInstance("X.509", BouncyCastleProvider.PROVIDER_NAME);
X509Certificate caCert = (X509Certificate) factory.generateCertificate(is);
emitter.onSuccess(caCert);
});
}
public Single<byte[]> getBytesFromFile(String path) { public Single<byte[]> getBytesFromFile(String path) {
return Single.fromCallable(() -> { return Single.fromCallable(() -> {
byte[] fileBytes; byte[] fileBytes;
......
...@@ -19,11 +19,12 @@ ...@@ -19,11 +19,12 @@
package org.openconnectivity.otgc.domain.usecase.trustanchor; package org.openconnectivity.otgc.domain.usecase.trustanchor;
import io.reactivex.Completable; import io.reactivex.Completable;
import org.iotivity.OCPki;
import org.openconnectivity.otgc.data.repository.CertRepository; import org.openconnectivity.otgc.data.repository.CertRepository;
import org.openconnectivity.otgc.data.repository.CmsRepository; import org.openconnectivity.otgc.data.repository.CmsRepository;
import org.openconnectivity.otgc.data.repository.IORepository; import org.openconnectivity.otgc.data.repository.IORepository;
import java.io.InputStream;
import javax.inject.Inject; import javax.inject.Inject;
public class StoreTrustAnchorUseCase { public class StoreTrustAnchorUseCase {
...@@ -41,8 +42,8 @@ public class StoreTrustAnchorUseCase { ...@@ -41,8 +42,8 @@ public class StoreTrustAnchorUseCase {
this.cmsRepository = cmsRepository; this.cmsRepository = cmsRepository;
} }
public Completable execute(String path) { public Completable execute(InputStream is) {
return ioRepository.getFileAsX509Certificate(path) return ioRepository.getFileAsX509Certificate(is)
.flatMap(certRepository::x509CertificateToPemString) .flatMap(certRepository::x509CertificateToPemString)
.flatMapCompletable(cmsRepository::addTrustAnchor); .flatMapCompletable(cmsRepository::addTrustAnchor);
} }
......
...@@ -42,7 +42,6 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton; ...@@ -42,7 +42,6 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton;
import org.openconnectivity.otgc.R; import org.openconnectivity.otgc.R;
import org.openconnectivity.otgc.domain.model.resource.secure.cred.OcCredential; import org.openconnectivity.otgc.domain.model.resource.secure.cred.OcCredential;
import org.openconnectivity.otgc.utils.FilePath;
import org.openconnectivity.otgc.utils.di.Injectable; import org.openconnectivity.otgc.utils.di.Injectable;
import org.openconnectivity.otgc.utils.view.EmptyRecyclerView; import org.openconnectivity.otgc.utils.view.EmptyRecyclerView;
import org.openconnectivity.otgc.utils.viewmodel.ViewModelError; import org.openconnectivity.otgc.utils.viewmodel.ViewModelError;
...@@ -50,12 +49,16 @@ import org.openconnectivity.otgc.viewmodel.TrustAnchorViewModel; ...@@ -50,12 +49,16 @@ import org.openconnectivity.otgc.viewmodel.TrustAnchorViewModel;
import org.spongycastle.jce.provider.BouncyCastleProvider; import org.spongycastle.jce.provider.BouncyCastleProvider;
import org.spongycastle.util.encoders.Base64; import org.spongycastle.util.encoders.Base64;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader;
import java.security.Security; import java.security.Security;
import java.security.cert.CertificateFactory; import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Objects;
import javax.inject.Inject; import javax.inject.Inject;
...@@ -98,8 +101,13 @@ public class TrustAnchorActivity extends AppCompatActivity implements Injectable ...@@ -98,8 +101,13 @@ public class TrustAnchorActivity extends AppCompatActivity implements Injectable
Uri uri = null; Uri uri = null;
if (resultData != null) { if (resultData != null) {
uri = resultData.getData(); uri = resultData.getData();
String path = FilePath.getPath(this, uri); try {
mViewModel.addTrustAnchor(path); mViewModel.addTrustAnchor(getContentResolver().openInputStream(uri));
} catch (Exception e) {
int errorId = R.string.trust_anchor_create_error;
Toast.makeText(this, errorId, Toast.LENGTH_SHORT).show();
}
} }
} }
} }
......
...@@ -14,7 +14,7 @@ import org.openconnectivity.otgc.utils.rx.SchedulersFacade; ...@@ -14,7 +14,7 @@ import org.openconnectivity.otgc.utils.rx.SchedulersFacade;
import org.openconnectivity.otgc.utils.viewmodel.ViewModelError; import org.openconnectivity.otgc.utils.viewmodel.ViewModelError;
import org.openconnectivity.otgc.utils.viewmodel.ViewModelErrorType; import org.openconnectivity.otgc.utils.viewmodel.ViewModelErrorType;
import java.io.File; import java.io.InputStream;
import javax.inject.Inject; import javax.inject.Inject;
...@@ -85,8 +85,8 @@ public class TrustAnchorViewModel extends ViewModel { ...@@ -85,8 +85,8 @@ public class TrustAnchorViewModel extends ViewModel {
)); ));
} }
public void addTrustAnchor(String path) { public void addTrustAnchor(InputStream is) {
disposable.add(storeTrustAnchorUseCase.execute(path) disposable.add(storeTrustAnchorUseCase.execute(is)
.subscribeOn(schedulersFacade.io()) .subscribeOn(schedulersFacade.io())
.observeOn(schedulersFacade.ui()) .observeOn(schedulersFacade.ui())
.subscribe( .subscribe(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment