Package org.bouncycastle.tsp

Examples of org.bouncycastle.tsp.TimeStampResponse


        TimeStampRequest request = tsaGenerator.generate(oid, hash, BigInteger.valueOf(nonce));

        // get TSA response
        byte[] tsaResponse = getTSAResponse(request.getEncoded());

        TimeStampResponse response;
        try
        {
            response = new TimeStampResponse(tsaResponse);
            response.validate(request);
        }
        catch (TSPException e)
        {
            throw new IOException(e);
        }
       
        TimeStampToken token = response.getTimeStampToken();
        if (token == null)
        {
            throw new IOException("Response does not have a time stamp token");
        }
View Full Code Here


           
            // Call the communications layer
            respBytes = getTSAResponse(requestBytes);
           
            // Handle the TSA response
            TimeStampResponse response = new TimeStampResponse(respBytes);
           
            // validate communication level attributes (RFC 3161 PKIStatus)
            response.validate(request);
            PKIFailureInfo failure = response.getFailInfo();
            int value = (failure == null) ? 0 : failure.intValue();
            if (value != 0) {
                // @todo: Translate value of 15 error codes defined by PKIFailureInfo to string
                throw new IOException(MessageLocalization.getComposedMessage("invalid.tsa.1.response.code.2", tsaURL, String.valueOf(value)));
            }
            // @todo: validate the time stap certificate chain (if we want
            //        assure we do not sign using an invalid timestamp).
           
            // extract just the time stamp token (removes communication status info)
            TimeStampToken  tsToken = response.getTimeStampToken();
            if (tsToken == null) {
                throw new IOException(MessageLocalization.getComposedMessage("tsa.1.failed.to.return.time.stamp.token.2", tsaURL, response.getStatusString()));
            }
            TimeStampTokenInfo tsTokenInfo = tsToken.getTimeStampInfo(); // to view details
            byte[] encoded = tsToken.getEncoded();

            LOGGER.info("Timestamp generated: " + tsTokenInfo.getGenTime());
View Full Code Here

        }
      }

      if (replyBytes != null) {
        try {
          TimeStampResponse timeStampResponse = new TimeStampResponse(replyBytes);
          timeStampResponse.validate(timeStampRequest);
        } catch (TSPValidationException e) {
          LogLog.error("TimeStampResponse validation failed.", e);
          e.printStackTrace();
        } catch (TSPException e) {
          LogLog.error("TimeStampResponse failed.", e);
View Full Code Here

           
            // Call the communications layer
            respBytes = getTSAResponse(requestBytes);
           
            // Handle the TSA response
            TimeStampResponse response = new TimeStampResponse(respBytes);
           
            // validate communication level attributes (RFC 3161 PKIStatus)
            response.validate(request);
            PKIFailureInfo failure = response.getFailInfo();
            int value = (failure == null) ? 0 : failure.intValue();
            if (value != 0) {
                // @todo: Translate value of 15 error codes defined by PKIFailureInfo to string
                throw new IOException(MessageLocalization.getComposedMessage("invalid.tsa.1.response.code.2", tsaURL, String.valueOf(value)));
            }
            // @todo: validate the time stap certificate chain (if we want
            //        assure we do not sign using an invalid timestamp).
           
            // extract just the time stamp token (removes communication status info)
            TimeStampToken  tsToken = response.getTimeStampToken();
            if (tsToken == null) {
                throw new IOException(MessageLocalization.getComposedMessage("tsa.1.failed.to.return.time.stamp.token.2", tsaURL, response.getStatusString()));
            }
            TimeStampTokenInfo tsTokenInfo = tsToken.getTimeStampInfo(); // to view details
            byte[] encoded = tsToken.getEncoded();

            LOGGER.info("Timestamp generated: " + tsTokenInfo.getGenTime());
View Full Code Here

    try {
      TimeStampRequest request = this.getTimeStampRequest(data);

      byte[] response = this.processor.getBinaryResponse(request.getEncoded());

      TimeStampResponse timeStampResponse = new TimeStampResponse(response);

      TimeStampToken timeStampToken = timeStampResponse.getTimeStampToken();

      if (timeStampToken == null) {
        throw new IllegalStateException("TimeStampToken not found in response");
      }
View Full Code Here

        this.saveRequest(timeStampRequest, dir, id);
      }

      byte[] responseBytes = this.sendRequest(timeStampRequest);

      TimeStampResponse response = this.getTimeStampResponse(timeStampRequest, responseBytes);

      if (this.debug) {
        this.saveResponse(response, dir, id);
      }

      return response.getEncoded();
    } catch (Exception e) {
      throw new TimeStampException(e);
    }
  }
View Full Code Here

      throw new TimeStampException(e);
    }
  }

  protected TimeStampResponse getTimeStampResponse(final TimeStampRequest request, final byte[] responseBytes) throws IOException, TSPException {
    TimeStampResponse response = new TimeStampResponse(responseBytes);

    response.validate(request);
    PKIFailureInfo failure = response.getFailInfo();

    if ((failure != null) && (failure.intValue() != 0)) {
      throw new IllegalStateException("Failure Status " + failure.intValue());
    }

    TimeStampToken timeStampToken = response.getTimeStampToken();
    if (timeStampToken == null) {
      throw new IllegalStateException("TimeStampToken not found in response");
    }
    return response;
  }
View Full Code Here

  @Override
  public byte[] getTimeStamp(final byte[] request) {
    try {
      TimeStampRequest timeStampRequest = new TimeStampRequest(request);
      TimeStampResponseGenerator timeStampResponseGenerator = new TimeStampResponseGenerator(this.timeStampTokenGenerator, TSPAlgorithms.ALLOWED);
      TimeStampResponse timeStampResponse = timeStampResponseGenerator.generate(timeStampRequest, this.getSerialNumber(), new Date());

      timeStampResponse.validate(timeStampRequest);

      return timeStampResponse.getEncoded();
    } catch (Exception e) {
      throw new TimeStampException(e);
    }
  }
View Full Code Here

        log.error("could not read timestamp request", e);
        resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "could not read timestamp request");
        return;
      }
      log.debug(String.format("TS Request received from %s", req.getRemoteAddr()));
      TimeStampResponse stampResponse = stamper.timestamp(rq);
      if (stampResponse == null) {
        log.warn(String.format("TS Request received from %s is not acceptable",
            req.getRemoteAddr()));
        resp.sendError(HttpServletResponse.SC_NOT_ACCEPTABLE, "Could not generate timestamp response");
        return;
      }
      if (stampResponse.getTimeStampToken() == null) {
        log.warn(String.format("TS Request received from %s is not acceptable",
            req.getRemoteAddr()));
        resp.sendError(HttpServletResponse.SC_NOT_ACCEPTABLE, "Could not generate timestamp response");
        return;
      }
     
     
      byte[] response = stampResponse.getEncoded();
      if (isBase64(req)) {
        resp.setHeader(TRANSFER_ENCODING_HEADER, TRANSFER_ENCODING_BASE64);
        response = Base64.encode(response);
          log.debug(String.format("Responding to %s is in base64", req.getRemoteAddr()));
      } else {
View Full Code Here

   
    byte[] responseBytes = new byte[(int)responseEntity.getContentLength()];
    responseEntity.getContent().read(responseBytes);
   
    Assert.assertNotNull("Response content", responseBytes);
    TimeStampResponse tsresponse = new TimeStampResponse(responseBytes);
    tsresponse.validate(timeStampRequest);
  }
View Full Code Here

TOP

Related Classes of org.bouncycastle.tsp.TimeStampResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.