if (unsignedAttributes != null) vector = unsignedAttributes.toASN1EncodableVector(); ASN1Encodable signatureTimeStamp = new Attribute(oid, new DERSet(ASN1Primitive.fromByteArray(token))); Attributes signedAttributes = new Attributes(vector); return SignerInformation.replaceUnsignedAttributes(signer, new AttributeTable(signedAttributes));
private TimeStampToken extractTimeStampTokenFromSignerInformation(SignerInformation signerInformation) throws CMSException, IOException, TSPException { if (signerInformation.getUnsignedAttributes() == null) { return null; } AttributeTable unsignedAttributes = signerInformation.getUnsignedAttributes(); // https://stackoverflow.com/questions/1647759/how-to-validate-if-a-signed-jar-contains-a-timestamp Attribute attribute = unsignedAttributes.get( PKCSObjectIdentifiers.id_aa_signatureTimeStampToken); if (attribute == null) { return null; } ASN1Object obj = (ASN1Object) attribute.getAttrValues().getObjectAt(0); CMSSignedData signedTSTData = new CMSSignedData(obj.getEncoded()); return new TimeStampToken(signedTSTData); }
DERSet set = new DERSet(new RecipientInfo(recipientInfo)); new EncryptedContentInfo(PKCSObjectIdentifiers.data, algorithmId, new DEROctetString(bytes)); EnvelopedData enveloped = new EnvelopedData(null, set, encryptedInfo, (ASN1Set) null); ContentInfo contentInfo = new ContentInfo(PKCSObjectIdentifiers.envelopedData, enveloped); return contentInfo.toASN1Primitive();
private KeyTransRecipientInfo computeRecipientInfo(X509Certificate x509certificate, byte[] abyte0) throws IOException, CertificateEncodingException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException { TBSCertificate certificate; try (ASN1InputStream input = new ASN1InputStream(x509certificate.getTBSCertificate())) { certificate = TBSCertificate.getInstance(input.readObject()); } AlgorithmIdentifier algorithmId = certificate.getSubjectPublicKeyInfo().getAlgorithm(); IssuerAndSerialNumber serial = new IssuerAndSerialNumber( certificate.getIssuer(), certificate.getSerialNumber().getValue()); Cipher cipher; try { cipher = Cipher.getInstance(algorithmId.getAlgorithm().getId(), SecurityProvider.getProvider()); } catch (NoSuchAlgorithmException | NoSuchPaddingException e) { // should never happen, if this happens throw IOException instead throw new RuntimeException("Could not find a suitable javax.crypto provider", e); } cipher.init(1, x509certificate.getPublicKey()); DEROctetString octets = new DEROctetString(cipher.doFinal(abyte0)); RecipientIdentifier recipientId = new RecipientIdentifier(serial); return new KeyTransRecipientInfo(recipientId, algorithmId, octets); }
public byte[] getEncoded() throws IOException { final DERObjectIdentifier contentType = PKCSObjectIdentifiers.signedData; final ContentInfo contentInfo = new ContentInfo(contentType, signedData); return contentInfo.getEncoded(); }
private AttributeTable getAttributeTable() { return new AttributeTable(signerInfo.getAuthenticatedAttributes()); }
public AttributeTable( ASN1EncodableVector v) { for (int i = 0; i != v.size(); i++) { Attribute a = Attribute.getInstance(v.get(i)); addAttribute(a.getAttrType(), a); } }
public AttributeTable( Attribute attr) { addAttribute(attr.getAttrType(), attr); }
public Attributes toASN1Structure() { return new Attributes(this.toASN1EncodableVector()); }
public ASN1Primitive toASN1Primitive() { if (genTime != null) { return genTime; } if (timeStampToken != null) { return timeStampToken.toASN1Primitive(); } return null; }
public AttributeTable( Hashtable attrs) { attributes = copyTable(attrs); }
protected void engineInit(byte[] params) throws IOException { gcmParams = GCMParameters.getInstance(params); }
protected byte[] engineGetEncoded() throws IOException { return gcmParams.getEncoded(); }
protected byte[] engineGetEncoded() throws IOException { return ccmParams.getEncoded(); }
.get(PKCSObjectIdentifiers.id_aa_signatureTimeStampToken); if (tsAttribute.getAttrValues() instanceof DERSet) DERSet tsSet = (DERSet) tsAttribute.getAttrValues(); tsSet.getEncoded("DER"); DERSequence tsSeq = (DERSequence) tsSet.getObjectAt(0);
public AttributeTable( Attribute attr) { addAttribute(attr.getAttrType(), attr); }
public Attributes toASN1Structure() { return new Attributes(this.toASN1EncodableVector()); }
public ASN1Primitive toASN1Primitive() { if (genTime != null) { return genTime; } else { return timeStampToken.toASN1Primitive(); } }
protected byte[] engineGetEncoded() throws IOException { return ccmParams.getEncoded(); }
Attribute signingTime = signerInformation.getSignedAttributes().get(CMSAttributes.signingTime); if (signingTime != null) Time timeInstance = Time.getInstance(signingTime.getAttrValues().getObjectAt(0)); try