/************************************************************************* * * * SignServer: The OpenSource Automated Signing Server * * * * This software is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or any later version. * * * * See terms of license at gnu.org. * * * *************************************************************************/ package org.signserver.module.cmssigner; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.security.cert.CertSelector; import java.security.cert.CertStore; import java.security.cert.Certificate; import java.util.Collection; import org.apache.log4j.Logger; import org.bouncycastle.cms.CMSSignedData; import org.bouncycastle.cms.SignerInformation; import org.bouncycastle.jce.X509Principal; import org.bouncycastle.x509.AttributeCertificateHolder; import org.junit.After; import org.junit.Before; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runners.MethodSorters; import org.signserver.common.GenericSignRequest; import org.signserver.common.GenericSignResponse; import org.signserver.common.RequestContext; import org.signserver.common.SignServerUtil; import org.signserver.testutils.ModulesTestCase; import org.signserver.testutils.TestingSecurityManager; /** * Tests for CMSSigner. * * @author Markus KilÄs * @version $Id: CMSSignerTest.java 3522 2013-05-28 14:44:39Z anatom $ */ @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class CMSSignerTest extends ModulesTestCase { /** Logger for this class. */ private static final Logger LOG = Logger.getLogger(CMSSignerTest.class); private static final int WORKERID_ECDSA = 8000; private static final int WORKERID_DSA = 8001; @Before protected void setUp() throws Exception { SignServerUtil.installBCProvider(); } @After protected void tearDown() throws Exception { TestingSecurityManager.remove(); } @Test public void test00SetupDatabase() throws Exception { addSigner("org.signserver.module.cmssigner.CMSSigner"); } /** * Tests that the signer can produce a CMS structure and that it returns * the signer's certficate and that it is included in the structure and * that it can be used to verify the signature and that the signed content * also is included. Also test that the default signature algorithm is SHA1withRSA * @throws Exception In case of error. */ @Test public void test01BasicCMSSignRSA() throws Exception { LOG.debug(">test01BasicCMSSignRSA"); helperBasicCMSSign(getSignerIdDummy1(), null, "1.3.14.3.2.26", "1.2.840.113549.1.1.1"); LOG.debug(" signerCerts = certs.getCertificates(cs); assertEquals("One certificate included", 1, signerCerts.size()); assertEquals(signercert, signerCerts.iterator().next()); // check the signature algorithm assertEquals("Digest algorithm", expectedDigAlgOID, signer.getDigestAlgorithmID().getAlgorithm().getId()); assertEquals("Encryption algorithm", expectedEncAlgOID, signer.getEncryptionAlgOID()); } /** * Remove the workers created etc. * @throws Exception in case of error */ @Test public void test99TearDownDatabase() throws Exception { removeWorker(getSignerIdDummy1()); } }