Skip to content

Commit

Permalink
Revert back to older version of libdigidocpp
Browse files Browse the repository at this point in the history
  • Loading branch information
martenrebane committed Aug 29, 2024
1 parent 63d8945 commit 7cd89f6
Show file tree
Hide file tree
Showing 15 changed files with 21 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public Single<SignedContainer> sign(Context context, Token token, SignedContaine
return Single
.fromCallable(() -> {
IdCardData data = data(token);
return container.sign(context, data.signCertificate().data(),
return container.sign(data.signCertificate().data(),
signData -> ByteString.of(token.calculateSignature(pin2,
signData.toByteArray(),
data.signCertificate().ellipticCurve())), roleData);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ee.ria.DigiDoc.android.signature.update;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.widget.Button;
Expand Down Expand Up @@ -215,11 +214,11 @@ Observable<? extends SignatureAddResponse> sign(File containerFile,
}
}

public Single<SignedContainer> sign(Context context, String signatureValue, byte[] dataToSign,
public Single<SignedContainer> sign(String signatureValue, byte[] dataToSign,
SignedContainer container,
@Nullable RoleData roleData) {
return Single
.fromCallable(() -> container.sign(context, ByteString.of(dataToSign),
.fromCallable(() -> container.sign(ByteString.of(dataToSign),
signData -> ByteString.encodeUtf8(signatureValue), roleData))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private NFCResponse onTagDiscovered(NfcAdapter adapter, Tag tag) {
r = nfc.communicateSecure(CMD_SET_ENV_SIGN, SET_ENV_SIGN);
Timber.log(Log.DEBUG, "Set ENV:%x %s", r.code, Hex.toHexString(r.data));

container.sign(navigator.activity(), cert.data(),
container.sign(cert.data(),
signData -> ByteString.of(nfc.calculateSignature(signData.toByteArray())), role);
} catch (TagLostException exc) {
Timber.log(Log.ERROR, exc.getMessage());
Expand Down
Binary file modified common-lib/libs/libdigidocpp.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
*/
package ee.ria.DigiDoc.common;

import android.content.Context;

import androidx.annotation.Nullable;

import org.bouncycastle.util.encoders.Base64;
Expand All @@ -28,21 +26,17 @@
import java.security.cert.CertificateException;

import ee.ria.libdigidocpp.Container;
import ee.ria.libdigidocpp.ExternalSigner;
import ee.ria.libdigidocpp.Signature;
import ee.ria.libdigidocpp.StringVector;

public class ContainerWrapper {

private static final String SIGNATURE_PROFILE_TS = "time-stamp";

private final Context context;
private final Container container;
private Signature signature;
private ExternalSigner signer;

public ContainerWrapper(Context context, String containerPath) {
this.context = context;
public ContainerWrapper(String containerPath) {
this.container = Container.open(containerPath, new DigidocContainerOpenCB(false));
}

Expand All @@ -51,17 +45,13 @@ public Container getContainer() {
}

public String prepareSignature(String cert, @Nullable RoleData roleData) throws CertificateException {
signer = new ExternalSigner(CertificateUtil.x509Certificate(cert).getEncoded());
signer.setProfile(SIGNATURE_PROFILE_TS);
signer.setUserAgent(UserAgentUtil.getUserAgent(context));
if (roleData != null) {
signer.setSignerRoles(new StringVector(TextUtil.removeEmptyStrings(roleData.getRoles())));
signer.setSignatureProductionPlace(roleData.getCity(), roleData.getState(),
roleData.getZip(), roleData.getCountry());
signature = container.prepareWebSignature(CertificateUtil.x509Certificate(cert).getEncoded(), SIGNATURE_PROFILE_TS,
new StringVector(TextUtil.removeEmptyStrings(roleData.getRoles())), roleData.getCity(),
roleData.getState(), roleData.getZip(), roleData.getCountry());
} else {
signature = container.prepareWebSignature(CertificateUtil.x509Certificate(cert).getEncoded(), SIGNATURE_PROFILE_TS);
}

signature = container.prepareSignature(signer);

if (signature != null) {
byte[] dataToSignBytes = Base64.encode(signature.dataToSign());
String dataToSign = new String(dataToSignBytes, StandardCharsets.UTF_8);
Expand All @@ -75,14 +65,9 @@ public void finalizeSignature(String signatureValue) {
if (signature == null) {
throw new IllegalStateException("Cannot finalize uninitialized signature");
}

if (signer == null) {
throw new IllegalStateException("Cannot finalize uninitialized signer");
}

byte[] signatureValueBytes = Base64.decode(signatureValue);
signature.setSignatureValue(signatureValueBytes);
signature.extendSignatureProfile(signer);
signature.extendSignatureProfile(SIGNATURE_PROFILE_TS);
container.save();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public Result doWork() {
if (isResponseError(responseWrapper, response, MobileCreateSignatureCertificateResponse.class)) {
return Result.failure();
}
containerWrapper = new ContainerWrapper(getApplicationContext(), request.getContainerPath());
containerWrapper = new ContainerWrapper(request.getContainerPath());
String base64Hash = containerWrapper.prepareSignature(getCertificatePem(response.getCert()), roleDataRequest);
if (base64Hash != null && !base64Hash.isEmpty()) {
Timber.log(Log.DEBUG, "Broadcasting create signature response");
Expand Down
Binary file modified sign-lib/src/debug/jniLibs/arm64-v8a/libdigidoc_java.so
Binary file not shown.
Binary file modified sign-lib/src/debug/jniLibs/armeabi-v7a/libdigidoc_java.so
Binary file not shown.
Binary file modified sign-lib/src/debug/jniLibs/x86_64/libdigidoc_java.so
Binary file not shown.
22 changes: 8 additions & 14 deletions sign-lib/src/main/java/ee/ria/DigiDoc/sign/SignedContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
import ee.ria.DigiDoc.common.FileUtil;
import ee.ria.DigiDoc.common.RoleData;
import ee.ria.DigiDoc.common.TextUtil;
import ee.ria.DigiDoc.common.UserAgentUtil;
import ee.ria.DigiDoc.common.exception.InvalidProxySettingsException;
import ee.ria.DigiDoc.common.exception.NoInternetConnectionException;
import ee.ria.DigiDoc.common.exception.SSLHandshakeException;
Expand All @@ -72,7 +71,6 @@
import ee.ria.DigiDoc.sign.utils.Function;
import ee.ria.libdigidocpp.Container;
import ee.ria.libdigidocpp.DataFiles;
import ee.ria.libdigidocpp.ExternalSigner;
import ee.ria.libdigidocpp.Signature.Validator;
import ee.ria.libdigidocpp.Signatures;
import ee.ria.libdigidocpp.StringVector;
Expand Down Expand Up @@ -207,28 +205,24 @@ public final SignedContainer addAdEsSignature(byte[] adEsSignature) throws Excep
return open(file(), false);
}

public final SignedContainer sign(Context context, ByteString certificate,
public final SignedContainer sign(ByteString certificate,
Function<ByteString, ByteString> signFunction,
@Nullable RoleData roleData) throws Exception {
try {
Container container = container(file(), false);

ExternalSigner signer = new ExternalSigner(certificate.toByteArray());
signer.setProfile(signatureProfile());
signer.setUserAgent(UserAgentUtil.getUserAgent(context));

ee.ria.libdigidocpp.Signature signature;
if (roleData != null) {
signer.setSignerRoles(new StringVector(TextUtil.removeEmptyStrings(roleData.getRoles())));
signer.setSignatureProductionPlace(roleData.getCity(), roleData.getState(),
roleData.getZip(), roleData.getCountry());
signature = container.prepareWebSignature(certificate.toByteArray(), signatureProfile(),
new StringVector(TextUtil.removeEmptyStrings(roleData.getRoles())), roleData.getCity(),
roleData.getState(), roleData.getZip(), roleData.getCountry());
} else {
signature = container.prepareWebSignature(certificate.toByteArray(), signatureProfile());
}

ee.ria.libdigidocpp.Signature signature = container.prepareSignature(signer);

if (signature != null) {
ByteString signatureData = signFunction.apply(ByteString.of(signature.dataToSign()));
signature.setSignatureValue(signatureData.toByteArray());
signature.extendSignatureProfile(signer);
signature.extendSignatureProfile(signatureProfile());
container.save();
return open(file(), false);
}
Expand Down
Binary file modified sign-lib/src/main/jniLibs/arm64-v8a/libdigidoc_java.so
Binary file not shown.
Binary file modified sign-lib/src/main/jniLibs/armeabi-v7a/libdigidoc_java.so
Binary file not shown.
Binary file modified sign-lib/src/main/jniLibs/x86_64/libdigidoc_java.so
Binary file not shown.
Binary file modified sign-lib/src/main/res/raw/schema.zip
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public Result doWork() {

Timber.log(Log.DEBUG, "Session status response: %s", sessionStatusResponse.toString());

ContainerWrapper containerWrapper = new ContainerWrapper(getApplicationContext(), request.getContainerPath());
ContainerWrapper containerWrapper = new ContainerWrapper(request.getContainerPath());
String base64Hash = containerWrapper.prepareSignature(getCertificatePem(sessionStatusResponse.getCert().getValue()), roleDataRequest);
if (base64Hash != null && !base64Hash.isEmpty()) {
Timber.log(Log.DEBUG, "Broadcasting signature challenge response");
Expand Down

0 comments on commit 7cd89f6

Please sign in to comment.