use of org.bouncycastle.asn1.tsp.TimeStampResp in project gdmatrix by gdmatrix.
the class P7MUtils method createTimeStamp.
public static ContentInfo createTimeStamp(String serviceURI, byte[] message) throws Exception {
String nonce = String.valueOf((int) (Math.random() * 1000000));
// es crea la peticio a la TSA
TimeStampReq timeStampRequest = createTimeStampRequest(// message
message, // nonce
nonce, // requireCert
true, // extensions
null, // digestAlgorithm identifier
"1.3.14.3.2.26", // timestampPolicy
"0.4.0.2023.1.1");
// s'envia la peticio creada
TimeStampResp timeStampResponse = sendTimestampRequest(timeStampRequest, serviceURI);
ContentInfo contentInfo = timeStampResponse.getTimeStampToken();
return contentInfo;
}
use of org.bouncycastle.asn1.tsp.TimeStampResp in project gdmatrix by gdmatrix.
the class CMSUtils method sendData.
private static TimeStampResp sendData(InputStream dataToBeSent, String serviceURI) throws Exception {
URL url = new URL(serviceURI);
URLConnection conn = url.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
// post request data
OutputStream os = conn.getOutputStream();
byte[] buffer = new byte[4096];
int numRead = dataToBeSent.read(buffer);
while (numRead > 0) {
os.write(buffer, 0, numRead);
numRead = dataToBeSent.read(buffer);
}
os.flush();
// read response
InputStream response = conn.getInputStream();
ASN1InputStream asn1Is = new ASN1InputStream(response);
// TimeStampResp tspResp = new TimeStampResp((ASN1Sequence)asn1Is.readObject());
Enumeration e = ((ASN1Sequence) asn1Is.readObject()).getObjects();
PKIStatusInfo pkiStatusInfo = PKIStatusInfo.getInstance(e.nextElement());
ContentInfo timeStampToken = null;
if (e.hasMoreElements()) {
timeStampToken = ContentInfo.getInstance(e.nextElement());
}
TimeStampResp tspResp = new TimeStampResp(pkiStatusInfo, timeStampToken);
return tspResp;
}
use of org.bouncycastle.asn1.tsp.TimeStampResp in project LinLong-Java by zhenwei1108.
the class TimeStampResponseGenerator method generateFailResponse.
/**
* Generate a non-granted TimeStampResponse with chosen status and FailInfoField.
*
* @param status the PKIStatus to set.
* @param failInfoField the FailInfoField to set.
* @param statusString an optional string describing the failure.
* @return a TimeStampResponse with a failInfoField and optional statusString
* @throws TSPException in case the response could not be created
*/
public TimeStampResponse generateFailResponse(int status, int failInfoField, String statusString) throws TSPException {
this.status = status;
this.statusStrings = new ASN1EncodableVector();
this.setFailInfoField(failInfoField);
if (statusString != null) {
this.addStatusString(statusString);
}
PKIStatusInfo pkiStatusInfo = getPKIStatusInfo();
TimeStampResp resp = new TimeStampResp(pkiStatusInfo, null);
try {
return new TimeStampResponse(resp);
} catch (IOException e) {
throw new TSPException("created badly formatted response!");
}
}
use of org.bouncycastle.asn1.tsp.TimeStampResp in project X-Road by nordic-institute.
the class TimestamperUtil method getTimestampResponse.
static TimeStampResponse getTimestampResponse(InputStream in) throws Exception {
TimeStampResp response = TimeStampResp.getInstance(new ASN1InputStream(in).readObject());
if (response == null) {
throw new RuntimeException("Could not read time-stamp response");
}
BigInteger status = response.getStatus().getStatus();
log.trace("getTimestampDer() - TimeStampResp.status: {}", status);
if (!PKIStatus.granted.getValue().equals(status) && !PKIStatus.grantedWithMods.getValue().equals(status)) {
PKIFreeText statusString = response.getStatus().getStatusString();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < statusString.size(); i++) {
if (i > 0) {
sb.append(", ");
}
sb.append("\"" + statusString.getStringAt(i) + "\"");
}
log.error("getTimestampDer() - TimeStampResp.status is not " + "\"granted\" neither \"grantedWithMods\": {}, {}", status, sb);
throw new RuntimeException("TimeStampResp.status: " + status + ", .statusString: " + sb);
}
return new TimeStampResponse(response);
}
use of org.bouncycastle.asn1.tsp.TimeStampResp in project gdmatrix by gdmatrix.
the class P7MUtils method sendData.
private static TimeStampResp sendData(InputStream dataToBeSent, String serviceURI) throws Exception {
URL url = new URL(serviceURI);
URLConnection conn = url.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
// post request data
OutputStream os = conn.getOutputStream();
byte[] buffer = new byte[4096];
int numRead = dataToBeSent.read(buffer);
while (numRead > 0) {
os.write(buffer, 0, numRead);
numRead = dataToBeSent.read(buffer);
}
os.flush();
// read response
InputStream response = conn.getInputStream();
ASN1InputStream asn1Is = new ASN1InputStream(response);
Enumeration e = ((ASN1Sequence) asn1Is.readObject()).getObjects();
PKIStatusInfo pkiStatusInfo = PKIStatusInfo.getInstance(e.nextElement());
ContentInfo timeStampToken = null;
if (e.hasMoreElements()) {
timeStampToken = ContentInfo.getInstance(e.nextElement());
}
TimeStampResp tspResp = new TimeStampResp(pkiStatusInfo, timeStampToken);
return tspResp;
}
Aggregations