Skip to content

Commit

Permalink
Fix PT CC tests (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
luisgoncalves committed Nov 18, 2018
1 parent 56dee25 commit 0d4034f
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 126 deletions.
Binary file added src/test/cert/pt/GTEGlobalRoot.cer
Binary file not shown.
4 changes: 4 additions & 0 deletions src/test/cert/pt/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ Certificates in the Portuguese Government PKI. The top most CA is "GTE CyberTrus
Used to verify signatures produced with PT Citizen Cards.

Cert path is: GTE Global Root > ECRaizEstado > CC001 > ECAuthCC002 > (Personal)

======== Trust-anchors keystore =========

keytool -importcert -alias GTERoot-file "GTEGlobalRoot.cer" -keystore trustAnchor -storepass password
Binary file added src/test/cert/pt/trustAnchor
Binary file not shown.
13 changes: 3 additions & 10 deletions src/test/java/xades4j/verification/VerifierTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,8 @@ public InputStream getSignaturePolicyDocumentStream(
// Validation provider for "pt" folder. Used for signatures produced
// with the PT citizen card.
certStore = createDirectoryCertStore("pt");
try
{
ks = KeyStore.getInstance("Windows-ROOT");
ks.load(null);
validationProviderPtCc = new PKIXCertificateValidationProvider(ks, false, certStore.getStore());
} catch (Exception e)
{
// Not on windows platform...
}
ks = createAndLoadJKSKeyStore("pt/trustAnchor", "password");
validationProviderPtCc = new PKIXCertificateValidationProvider(ks, false, certStore.getStore(), gvaCRLStore.getStore());
} catch (Exception ex)
{
throw new NullPointerException("VerifierTestBase init failed: " + ex.getMessage());
Expand All @@ -107,7 +100,7 @@ protected static XAdESForm verifySignature(
return verifySignature(sigFileName, new XadesVerificationProfile(VerifierTestBase.validationProviderMySigs), options);
}

private static XAdESForm verifySignature(
protected static XAdESForm verifySignature(
String sigFileName,
XadesVerificationProfile p,
SignatureSpecificVerificationOptions options) throws Exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import java.security.KeyStore;
import org.junit.Test;
import static org.junit.Assume.assumeTrue;
import org.junit.Before;
import xades4j.providers.CannotSelectCertificateException;
import xades4j.providers.impl.PKIXCertificateValidationProvider;
Expand Down Expand Up @@ -50,7 +49,6 @@ public void testErrVerifySignedPropsIncorp() throws Exception
public void testErrVerifySignedPropsIncorpNoRefType() throws Exception
{
System.out.println("errVerifySignedPropsIncorpNoRefType");
assumeTrue(onWindowsPlatform() && null != validationProviderPtCc);

verifyBadSignature("document.signed.bes.signedpropsrefnotype.xml",
new XadesVerificationProfile(validationProviderPtCc));
Expand Down
25 changes: 13 additions & 12 deletions src/test/java/xades4j/verification/XadesVerifierImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
import java.io.File;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assume.assumeTrue;

import java.io.FileInputStream;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;

import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -98,6 +98,18 @@ public void verify(RawSignatureVerifierContext ctx) throws InvalidSignatureExcep
assertEquals(XAdESForm.BES, f);
}

@Test
public void testVerifyBESPTCC() throws Exception
{
System.out.println("verifyBESPtCC");

XAdESForm f = verifySignature(
"document.signed.bes.ptcc.xml",
new XadesVerificationProfile(validationProviderPtCc),
new SignatureSpecificVerificationOptions().setDefaultVerificationDate(new GregorianCalendar(2014, 0, 1).getTime()));
assertEquals(XAdESForm.BES, f);
}

@Test
public void testVerifyDetachedBES() throws Exception
{
Expand Down Expand Up @@ -196,17 +208,6 @@ public void testVerifyTEPES() throws Exception
assertEquals(XAdESForm.T, f);
}

@Test
public void testVerifyTPTCC() throws Exception
{
System.out.println("verifyTPtCC");
assumeTrue(onWindowsPlatform() && null != validationProviderPtCc);

XAdESForm f = verifySignature("document.signed.t.bes.ptcc.xml",
new XadesVerificationProfile(validationProviderPtCc));
assertEquals(XAdESForm.T, f);
}

@Test
public void testVerifyC() throws Exception
{
Expand Down
Loading

0 comments on commit 0d4034f

Please sign in to comment.