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 {
minSdkVersion 21
targetSdkVersion 28
versionCode 13
versionName "2.5.0"
versionName "2.6.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
compileOptions {
......
......@@ -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) {
return Single.fromCallable(() -> {
byte[] fileBytes;
......
......@@ -19,11 +19,12 @@
package org.openconnectivity.otgc.domain.usecase.trustanchor;
import io.reactivex.Completable;
import org.iotivity.OCPki;
import org.openconnectivity.otgc.data.repository.CertRepository;
import org.openconnectivity.otgc.data.repository.CmsRepository;
import org.openconnectivity.otgc.data.repository.IORepository;
import java.io.InputStream;
import javax.inject.Inject;
public class StoreTrustAnchorUseCase {
......@@ -41,8 +42,8 @@ public class StoreTrustAnchorUseCase {
this.cmsRepository = cmsRepository;
}
public Completable execute(String path) {
return ioRepository.getFileAsX509Certificate(path)
public Completable execute(InputStream is) {
return ioRepository.getFileAsX509Certificate(is)
.flatMap(certRepository::x509CertificateToPemString)
.flatMapCompletable(cmsRepository::addTrustAnchor);
}
......
......@@ -42,7 +42,6 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton;
import org.openconnectivity.otgc.R;
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.view.EmptyRecyclerView;
import org.openconnectivity.otgc.utils.viewmodel.ViewModelError;
......@@ -50,12 +49,16 @@ import org.openconnectivity.otgc.viewmodel.TrustAnchorViewModel;
import org.spongycastle.jce.provider.BouncyCastleProvider;
import org.spongycastle.util.encoders.Base64;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.security.Security;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.text.SimpleDateFormat;
import java.util.Objects;
import javax.inject.Inject;
......@@ -98,8 +101,13 @@ public class TrustAnchorActivity extends AppCompatActivity implements Injectable
Uri uri = null;
if (resultData != null) {
uri = resultData.getData();
String path = FilePath.getPath(this, uri);
mViewModel.addTrustAnchor(path);
try {
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;
import org.openconnectivity.otgc.utils.viewmodel.ViewModelError;
import org.openconnectivity.otgc.utils.viewmodel.ViewModelErrorType;
import java.io.File;
import java.io.InputStream;
import javax.inject.Inject;
......@@ -85,8 +85,8 @@ public class TrustAnchorViewModel extends ViewModel {
));
}
public void addTrustAnchor(String path) {
disposable.add(storeTrustAnchorUseCase.execute(path)
public void addTrustAnchor(InputStream is) {
disposable.add(storeTrustAnchorUseCase.execute(is)
.subscribeOn(schedulersFacade.io())
.observeOn(schedulersFacade.ui())
.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