I want to display the Timestamp attribute in the certificate as shown in the picture
What should I set in the Signature?
This is my code for add sign info:
private SignerInformation signTimeStamp(SignerInformation signer) throws IOException, TSPException {
AttributeTable unsignedAttributes = signer.getUnsignedAttributes();
ASN1EncodableVector vector = new ASN1EncodableVector();
if (unsignedAttributes != null) {
vector = unsignedAttributes.toASN1EncodableVector();
}
byte[] token = this.tsaClient.getTimeStampToken(signer.getSignature());
ASN1ObjectIdentifier oid = PKCSObjectIdentifiers.id_aa_signatureTimeStampToken;
ASN1Encodable signatureTimeStamp = new Attribute(oid, new DERSet(ASN1Primitive.fromByteArray(token)));
vector.add(signatureTimeStamp);
Attributes signedAttributes = new Attributes(vector);
// replace unsignedAttributes with the signed once
return SignerInformation.replaceUnsignedAttributes(signer, new AttributeTable(signedAttributes));
}
To sum up the comments...
Inspecting your example document it became clear that the timestamp you applied is alright. In particular you should get the lower message you marked in Certificate Viewer dialog screen shot:
On the other hand your code has no influence on whether or not you get the other entry you marked in that screen shot:
That entry is an extension of the signer X.509 certificate in which the issuer of that certificate provides the address of a time stamp service that may be used for timestamping signatures created by the private key associated with that certificate.
Thus, that entry does not necessarily contain the server used to create the actual timestamp, it's merely a proposition or recommendation.
So if the box in your screen shot that connects with the two markers claims some necessary relation between the marked TSA URL and reference to a secure timestamp time, it is wrong.