Example usage for org.bouncycastle.tsp TimeStampRequestGenerator addExtension

List of usage examples for org.bouncycastle.tsp TimeStampRequestGenerator addExtension

Introduction

In this page you can find the example usage for org.bouncycastle.tsp TimeStampRequestGenerator addExtension.

Prototype

public void addExtension(ASN1ObjectIdentifier oid, boolean isCritical, byte[] value) 

Source Link

Document

add a given extension field for the standard extensions tag The value parameter becomes the contents of the octet string associated with the extension.

Usage

From source file:org.signserver.module.tsa.TimeStampSignerUnitTest.java

License:Open Source License

/**
 * Tests that a request including an extension not listed will cause a
 * rejection.//from  w w  w  . j av a 2  s . c o  m
 * @throws Exception
 */
@Test
public void testNotAcceptedExtensionPrevented() throws Exception {
    LOG.info("testNotAcceptedExtensionPrevented");
    TimeStampRequestGenerator timeStampRequestGenerator = new TimeStampRequestGenerator();
    timeStampRequestGenerator.addExtension(new ASN1ObjectIdentifier("1.2.7.9"), false,
            new DEROctetString("Value".getBytes("UTF-8")));
    TimeStampRequest timeStampRequest = timeStampRequestGenerator.generate(TSPAlgorithms.SHA1, new byte[20],
            BigInteger.valueOf(100));
    byte[] requestBytes = timeStampRequest.getEncoded();
    GenericSignRequest signRequest = new GenericSignRequest(100, requestBytes);
    final RequestContext requestContext = new RequestContext();
    final GenericSignResponse res = (GenericSignResponse) workerSession.process(WORKER2, signRequest,
            requestContext);

    final TimeStampResponse timeStampResponse = new TimeStampResponse((byte[]) res.getProcessedData());
    timeStampResponse.validate(timeStampRequest);
    assertEquals("rejection", PKIStatus.REJECTION, timeStampResponse.getStatus());
    assertEquals("unacceptedExtension", PKIFailureInfo.unacceptedExtension,
            timeStampResponse.getFailInfo().intValue());
}

From source file:org.signserver.module.tsa.TimeStampSignerUnitTest.java

License:Open Source License

/**
 * Tests that a request including an extension listed will accept
 * the extension./*from   ww w  .java2s . com*/
 * @throws Exception
 */
@Test
public void testAcceptedExtensions() throws Exception {
    LOG.info("testAcceptedExtensions");
    TimeStampRequestGenerator timeStampRequestGenerator = new TimeStampRequestGenerator();
    timeStampRequestGenerator.addExtension(new ASN1ObjectIdentifier("1.2.7.2"), false,
            new DEROctetString("Value".getBytes("UTF-8")));
    TimeStampRequest timeStampRequest = timeStampRequestGenerator.generate(TSPAlgorithms.SHA1, new byte[20],
            BigInteger.valueOf(100));
    byte[] requestBytes = timeStampRequest.getEncoded();
    GenericSignRequest signRequest = new GenericSignRequest(100, requestBytes);
    final RequestContext requestContext = new RequestContext();
    final GenericSignResponse res = (GenericSignResponse) workerSession.process(WORKER2, signRequest,
            requestContext);

    final TimeStampResponse timeStampResponse = new TimeStampResponse((byte[]) res.getProcessedData());
    timeStampResponse.validate(timeStampRequest);
    assertEquals("granted", PKIStatus.GRANTED, timeStampResponse.getStatus());
    assertEquals("extensions in token",
            Arrays.toString(new ASN1ObjectIdentifier[] { new ASN1ObjectIdentifier("1.2.7.2") }),
            Arrays.toString(timeStampResponse.getTimeStampToken().getTimeStampInfo().toASN1Structure()
                    .getExtensions().getExtensionOIDs()));
}

From source file:org.signserver.module.tsa.TimeStampSignerUnitTest.java

License:Open Source License

/**
 * Tests that a request including an extension listed will accept
 * the extension also when ACCEPTEDEXTENSIONS contains spaces.
 * @throws Exception//  w  ww . ja v  a 2  s .  co m
 */
@Test
public void testAcceptedExtensionsWithSpaces() throws Exception {
    LOG.info("testAcceptedExtensionsWithSpaces");
    TimeStampRequestGenerator timeStampRequestGenerator = new TimeStampRequestGenerator();
    timeStampRequestGenerator.addExtension(new ASN1ObjectIdentifier("1.2.7.2"), false,
            new DEROctetString("Value".getBytes("UTF-8")));
    TimeStampRequest timeStampRequest = timeStampRequestGenerator.generate(TSPAlgorithms.SHA1, new byte[20],
            BigInteger.valueOf(100));
    byte[] requestBytes = timeStampRequest.getEncoded();
    GenericSignRequest signRequest = new GenericSignRequest(100, requestBytes);
    final RequestContext requestContext = new RequestContext();
    final GenericSignResponse res = (GenericSignResponse) workerSession.process(WORKER4, signRequest,
            requestContext);

    final TimeStampResponse timeStampResponse = new TimeStampResponse((byte[]) res.getProcessedData());
    timeStampResponse.validate(timeStampRequest);
    assertEquals("granted", PKIStatus.GRANTED, timeStampResponse.getStatus());
    assertEquals("extensions in token",
            Arrays.toString(new ASN1ObjectIdentifier[] { new ASN1ObjectIdentifier("1.2.7.2") }),
            Arrays.toString(timeStampResponse.getTimeStampToken().getTimeStampInfo().toASN1Structure()
                    .getExtensions().getExtensionOIDs()));
}

From source file:org.signserver.module.tsa.TimeStampSignerUnitTest.java

License:Open Source License

/**
 * Tests that a request including an extension not listed will cause a
 * rejection also when the list of extensions is empty.
 * @throws Exception/*www.j  a va2 s. co  m*/
 */
@Test
public void testEmptyAcceptedExtensionsPreventsExtension() throws Exception {
    LOG.info("testEmptyAcceptedExtensionsPreventsExtension");
    TimeStampRequestGenerator timeStampRequestGenerator = new TimeStampRequestGenerator();
    timeStampRequestGenerator.addExtension(new ASN1ObjectIdentifier("1.2.7.9"), false,
            new DEROctetString("Value".getBytes("UTF-8")));
    TimeStampRequest timeStampRequest = timeStampRequestGenerator.generate(TSPAlgorithms.SHA1, new byte[20],
            BigInteger.valueOf(100));
    byte[] requestBytes = timeStampRequest.getEncoded();
    GenericSignRequest signRequest = new GenericSignRequest(100, requestBytes);
    final RequestContext requestContext = new RequestContext();
    final GenericSignResponse res = (GenericSignResponse) workerSession.process(WORKER3, signRequest,
            requestContext);

    final TimeStampResponse timeStampResponse = new TimeStampResponse((byte[]) res.getProcessedData());
    timeStampResponse.validate(timeStampRequest);
    assertEquals("rejection", PKIStatus.REJECTION, timeStampResponse.getStatus());
    assertEquals("unacceptedExtension", PKIFailureInfo.unacceptedExtension,
            timeStampResponse.getFailInfo().intValue());
}