in jvm/src/main/kotlin/com/jetbrains/signatureverifier/bouncycastle/tsp/TSPUtil.kt [81:114]
fun getSignatureTimestamps(signerInfo: SignerInformation, digCalcProvider: DigestCalculatorProvider): Collection<*> {
val timestamps = mutableListOf<TimeStampToken>()
val unsignedAttrs = signerInfo.unsignedAttributes
if (unsignedAttrs != null) {
val allTSAttrs = unsignedAttrs.getAll(
PKCSObjectIdentifiers.id_aa_signatureTimeStampToken
)
for (i in 0 until allTSAttrs.size()) {
val tsAttr = allTSAttrs[i] as Attribute
val tsAttrValues = tsAttr.attrValues
for (j in 0 until tsAttrValues.size()) {
try {
val contentInfo = ContentInfo.getInstance(tsAttrValues.getObjectAt(j))
val timeStampToken = TimeStampToken(contentInfo)
val tstInfo = timeStampToken.timeStampInfo
val digCalc = digCalcProvider[tstInfo.hashAlgorithm]
val dOut = digCalc.outputStream
dOut.write(signerInfo.signature)
dOut.close()
val expectedDigest = digCalc.digest
if (!Arrays.constantTimeAreEqual(expectedDigest, tstInfo.messageImprintDigest)) {
throw TSPValidationException("Incorrect digest in message imprint")
}
timestamps.add(timeStampToken)
} catch (e: OperatorCreationException) {
throw TSPValidationException("Unknown hash algorithm specified in timestamp")
} catch (e: Exception) {
throw TSPValidationException("Timestamp could not be parsed")
}
}
}
}
return timestamps
}