corrected CMS versioning in EnvelopedData streaming generator.
import org.bouncycastle.asn1.BERSet;
import org.bouncycastle.asn1.DERSet;
import org.bouncycastle.asn1.DERTaggedObject;
+import org.bouncycastle.asn1.DLSet;
import org.bouncycastle.asn1.cms.AttributeTable;
import org.bouncycastle.asn1.cms.CMSObjectIdentifiers;
import org.bouncycastle.asn1.cms.EnvelopedData;
public class CMSEnvelopedDataStreamGenerator
extends CMSEnvelopedGenerator
{
- private ASN1Set _unprotectedAttributes = null;
private int _bufferSize;
private boolean _berEncodeRecipientSet;
@@ -74,16 +74,14 @@ public void setBEREncodeRecipients(
_berEncodeRecipientSet = berEncodeRecipientSet;
}
- private ASN1Integer getVersion()
+ private ASN1Integer getVersion(ASN1EncodableVector recipientInfos)
{
- if (originatorInfo != null || _unprotectedAttributes != null)
- {
- return new ASN1Integer(2);
- }
- else
+ if (unprotectedAttributeGenerator != null)
{
- return new ASN1Integer(0);
+ // mark unprotected attributes as non-null.
+ return new ASN1Integer(EnvelopedData.calculateVersion(originatorInfo, new DLSet(recipientInfos), new DLSet()));
}
+ return new ASN1Integer(EnvelopedData.calculateVersion(originatorInfo, new DLSet(recipientInfos), null));
}
private OutputStream doOpen(
@@ -125,7 +123,7 @@ protected OutputStream open(
//
BERSequenceGenerator envGen = new BERSequenceGenerator(cGen.getRawOutputStream(), 0, true);
- envGen.addObject(getVersion());
+ envGen.addObject(getVersion(recipientInfos));
if (originatorInfo != null)
{
@@ -185,7 +183,7 @@ protected OutputStream open(
recipients = new DERSet(recipientInfos);
}
- envGen.addObject(new ASN1Integer(EnvelopedData.calculateVersion(originatorInfo, recipients, _unprotectedAttributes)));
+ envGen.addObject(getVersion(recipientInfos));
if (originatorInfo != null)
{
