use of org.bouncycastle.asn1.tsp.TSTInfo in project gdmatrix by gdmatrix.
the class P7MUtils method recoverTSTInfo.
public static TSTInfo recoverTSTInfo(ContentInfo contentInfo) throws IOException {
SignedData sd = SignedData.getInstance(contentInfo.getContent());
ASN1Encodable content = sd.getEncapContentInfo().getContent();
// TSTInfo tstInfo = new TSTInfo((ASN1Sequence)
// new ASN1InputStream(((DEROctetString)content).getOctets()).readObject());
TSTInfo tstInfo = TSTInfo.getInstance(((ASN1OctetString) content).getOctets());
return tstInfo;
}
use of org.bouncycastle.asn1.tsp.TSTInfo in project gdmatrix by gdmatrix.
the class P7MUtils method main.
public static void main(String[] args) {
try {
P7MUtils cms = new P7MUtils();
byte[] message = "HOLA".getBytes();
String tsBase64 = cms.createBase64TimeStamp("http://psis.catcert.net/psis/catcert/tsp", message);
System.out.println(tsBase64);
// if (true)
// {
// cms.addTimeStamp("http://psis.catcert.net/psis/catcert/tsp",
// new File("c:/test3.p7m"),
// new File("c:/out.p7m"));
// }
// if (true)
// {
// cms.dumpFile(
// new File("c:/demo_out.p7s"),
// new File("c:/demo_out.txt"));
// }
//
// if (false)
// {
// ContentInfo contentInfo = cms.createTimeStamp(
// "http://psis.catcert.net/psis/catcert/tsp", "prova".getBytes());
//
// System.out.println("TimeStampResponse: " +
// contentInfo.getContentType().getId());
//
// System.out.println("recovering TST info...");
// TSTInfo tstInfo = P7MUtils.recoverTSTInfo(contentInfo);
//
// System.out.println("TST info recovered: ");
// System.out.println("TST Nonce: " + tstInfo.getNonce().getValue());
// System.out.println("TST Serial Number: " +
// Integer.toHexString(tstInfo.getSerialNumber().getValue().intValue()));
// System.out.println("TST dateTime: " +
// tstInfo.getGenTime().getTime());
// }
} catch (Exception ex) {
ex.printStackTrace();
}
}
use of org.bouncycastle.asn1.tsp.TSTInfo in project gdmatrix by gdmatrix.
the class CMSUtils method recoverTSTInfo.
public static TSTInfo recoverTSTInfo(ContentInfo contentInfo) throws IOException {
SignedData sd = SignedData.getInstance(contentInfo.getContent());
ASN1Encodable content = sd.getEncapContentInfo().getContent();
// TSTInfo tstInfo = new TSTInfo((ASN1Sequence)
// new ASN1InputStream(((DEROctetString)content).getOctets()).readObject());
TSTInfo tstInfo = TSTInfo.getInstance(((ASN1OctetString) content).getOctets());
return tstInfo;
}
use of org.bouncycastle.asn1.tsp.TSTInfo in project LinLong-Java by zhenwei1108.
the class ERSArchiveTimeStampGenerator method generateArchiveTimeStamp.
public ERSArchiveTimeStamp generateArchiveTimeStamp(TimeStampResponse tspResponse) throws TSPException, ERSException {
PartialHashtree[] reducedHashTree = getPartialHashtrees();
byte[] rootHash = rootNodeCalculator.computeRootHash(digCalc, reducedHashTree);
TSTInfo tstInfo = tspResponse.getTimeStampToken().getTimeStampInfo().toASN1Structure();
if (!tstInfo.getMessageImprint().getHashAlgorithm().equals(digCalc.getAlgorithmIdentifier())) {
throw new ERSException("time stamp imprint for wrong algorithm");
}
if (!Arrays.areEqual(tstInfo.getMessageImprint().getHashedMessage(), rootHash)) {
throw new ERSException("time stamp imprint for wrong root hash");
}
ArchiveTimeStamp ats;
if (reducedHashTree.length == 1) {
// just include the TimeStamp
ats = new ArchiveTimeStamp(null, null, tspResponse.getTimeStampToken().toCMSSignedData().toASN1Structure());
} else {
ats = new ArchiveTimeStamp(digCalc.getAlgorithmIdentifier(), reducedHashTree, tspResponse.getTimeStampToken().toCMSSignedData().toASN1Structure());
}
return new ERSArchiveTimeStamp(ats, digCalc, rootNodeCalculator);
}
use of org.bouncycastle.asn1.tsp.TSTInfo in project LinLong-Java by zhenwei1108.
the class TimeStampTokenGenerator method generate.
/**
* Generate a TimeStampToken for the passed in request and serialNumber marking it with the passed
* in genTime.
*
* @param request the originating request.
* @param serialNumber serial number for the TimeStampToken
* @param genTime token generation time.
* @param additionalExtensions extra extensions to be added to the response token.
* @return a TimeStampToken
* @throws TSPException
*/
public TimeStampToken generate(TimeStampRequest request, BigInteger serialNumber, Date genTime, Extensions additionalExtensions) throws TSPException {
AlgorithmIdentifier algID = request.getMessageImprintAlgID();
MessageImprint messageImprint = new MessageImprint(algID, request.getMessageImprintDigest());
Accuracy accuracy = null;
if (accuracySeconds > 0 || accuracyMillis > 0 || accuracyMicros > 0) {
ASN1Integer seconds = null;
if (accuracySeconds > 0) {
seconds = new ASN1Integer(accuracySeconds);
}
ASN1Integer millis = null;
if (accuracyMillis > 0) {
millis = new ASN1Integer(accuracyMillis);
}
ASN1Integer micros = null;
if (accuracyMicros > 0) {
micros = new ASN1Integer(accuracyMicros);
}
accuracy = new Accuracy(seconds, millis, micros);
}
ASN1Boolean derOrdering = null;
if (ordering) {
derOrdering = ASN1Boolean.getInstance(ordering);
}
ASN1Integer nonce = null;
if (request.getNonce() != null) {
nonce = new ASN1Integer(request.getNonce());
}
ASN1ObjectIdentifier tsaPolicy = tsaPolicyOID;
if (request.getReqPolicy() != null) {
tsaPolicy = request.getReqPolicy();
}
Extensions respExtensions = request.getExtensions();
if (additionalExtensions != null) {
ExtensionsGenerator extGen = new ExtensionsGenerator();
if (respExtensions != null) {
for (Enumeration en = respExtensions.oids(); en.hasMoreElements(); ) {
extGen.addExtension(respExtensions.getExtension(ASN1ObjectIdentifier.getInstance(en.nextElement())));
}
}
for (Enumeration en = additionalExtensions.oids(); en.hasMoreElements(); ) {
extGen.addExtension(additionalExtensions.getExtension(ASN1ObjectIdentifier.getInstance(en.nextElement())));
}
respExtensions = extGen.generate();
}
ASN1GeneralizedTime timeStampTime;
if (resolution == R_SECONDS) {
timeStampTime = (locale == null) ? new ASN1GeneralizedTime(genTime) : new ASN1GeneralizedTime(genTime, locale);
} else {
timeStampTime = createGeneralizedTime(genTime);
}
TSTInfo tstInfo = new TSTInfo(tsaPolicy, messageImprint, new ASN1Integer(serialNumber), timeStampTime, accuracy, derOrdering, nonce, tsa, respExtensions);
try {
CMSSignedDataGenerator signedDataGenerator = new CMSSignedDataGenerator();
if (request.getCertReq()) {
// TODO: do we need to check certs non-empty?
signedDataGenerator.addCertificates(new CollectionStore(certs));
signedDataGenerator.addAttributeCertificates(new CollectionStore(attrCerts));
}
signedDataGenerator.addCRLs(new CollectionStore(crls));
if (!otherRevoc.isEmpty()) {
for (Iterator it = otherRevoc.keySet().iterator(); it.hasNext(); ) {
ASN1ObjectIdentifier format = (ASN1ObjectIdentifier) it.next();
signedDataGenerator.addOtherRevocationInfo(format, new CollectionStore((Collection) otherRevoc.get(format)));
}
}
signedDataGenerator.addSignerInfoGenerator(signerInfoGen);
byte[] derEncodedTSTInfo = tstInfo.getEncoded(ASN1Encoding.DER);
CMSSignedData signedData = signedDataGenerator.generate(new CMSProcessableByteArray(PKCSObjectIdentifiers.id_ct_TSTInfo, derEncodedTSTInfo), true);
return new TimeStampToken(signedData);
} catch (CMSException cmsEx) {
throw new TSPException("Error generating time-stamp token", cmsEx);
} catch (IOException e) {
throw new TSPException("Exception encoding info", e);
}
}
Aggregations