Skip to content

Commit

Permalink
Merge pull request #4 from Hemuu/docx
Browse files Browse the repository at this point in the history
Fix minor build issues
  • Loading branch information
Hemuu authored Feb 18, 2023
2 parents a73dca8 + 70d3906 commit 1e91d88
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/main/java/fi/methics/laverca/rest/DocxSigner.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
import fi.methics.laverca.rest.docx.MssDOMXMLSignatureFactory;
import fi.methics.laverca.rest.docx.MssSignatureInfo;
import fi.methics.laverca.rest.util.DocumentSigner;
import fi.methics.laverca.rest.util.MssCertificate;
import fi.methics.laverca.rest.util.RestException;
import fi.methics.laverca.rest.util.SignatureProfile;

/**
* DOCX document signing helper class
Expand Down Expand Up @@ -58,10 +60,10 @@ public ByteArrayOutputStream signDocument(final String msisdn,
throws IOException, RestException
{

List<X509Certificate> chain = this.client.getCertificateChain(msisdn, signatureProfile);
MssCertificate cert = this.client.getCertificate(msisdn, SignatureProfile.of(signatureProfile));

SignatureConfig signatureConfig = new SignatureConfig();
signatureConfig.setSigningCertificateChain(chain);
signatureConfig.setSigningCertificateChain(cert.getCertificateChain());
signatureConfig.setIncludeEntireCertificateChain(true);
signatureConfig.setKey(new DummyPrivateKey());

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/fi/methics/laverca/rest/PdfSigner.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.cert.X509Certificate;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -38,6 +36,8 @@
import fi.methics.laverca.rest.util.DTBS;
import fi.methics.laverca.rest.util.DocumentSigner;
import fi.methics.laverca.rest.util.LavercaPAdESService;
import fi.methics.laverca.rest.util.MssCertificate;
import fi.methics.laverca.rest.util.SignatureProfile;

/**
* PDF document signing helper class
Expand Down Expand Up @@ -204,15 +204,15 @@ private void addSignatureField(final String msisdn, final PDAcroForm acroForm, f
* @return PAdES parameters
*/
private PAdESSignatureParameters createParams(String msisdn, String sigprof) {
List<X509Certificate> chain = this.client.getCertificateChain(msisdn, sigprof);
MssCertificate cert = this.client.getCertificate(msisdn, SignatureProfile.of(sigprof));
PAdESSignatureParameters parameters = new PAdESSignatureParameters();
parameters.setSignatureLevel(SignatureLevel.PAdES_BASELINE_B);
parameters.setSignaturePackaging(SignaturePackaging.ENVELOPED);
parameters.setDigestAlgorithm(DIGEST_ALG);
parameters.setSignatureSize(25600);
parameters.setArchiveTimestampParameters(new TimestampParameters(DIGEST_ALG));
parameters.setCertificateChain(chain.stream().map(CertificateToken::new).collect(Collectors.toList()));
parameters.setSigningCertificate(new CertificateToken(chain.get(0)));
parameters.setCertificateChain(cert.getCertificateChain().stream().map(CertificateToken::new).collect(Collectors.toList()));
parameters.setSigningCertificate(new CertificateToken(cert.getCertificate()));
if (this.form != null && this.sigRectangle != null) {
parameters.setSignatureFieldId(FIELD_NAME + msisdn);
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/fi/methics/laverca/rest/TestAuthentication.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void testGetCertificateChain() {
MssClient client = new MssClient.Builder().withRestUrl("https://demo.methics.fi/restapi/")
.withPassword("TestAP", "9TMzfH7EKXETOB8FT5gz")
.build();
MssCertificate cert = client.getCertificate(MSISDN, SIGPROF);
MssCertificate cert = client.getCertificate(MSISDN, SignatureProfile.of(SIGPROF));
Assertions.assertNotNull(cert, "Got certificate object");
Assertions.assertNotNull(cert.getCertificate(), "Got X509 certificate");
Assertions.assertNotNull(cert.getCertificateChain(), "Got X509 certificate chain");
Expand Down

0 comments on commit 1e91d88

Please sign in to comment.