summary refs log tree commit diff
path: root/crypto/src/cms/CMSUtils.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/cms/CMSUtils.cs')
-rw-r--r--crypto/src/cms/CMSUtils.cs52
1 files changed, 49 insertions, 3 deletions
diff --git a/crypto/src/cms/CMSUtils.cs b/crypto/src/cms/CMSUtils.cs
index 6800c1d2a..1a1577c4e 100644
--- a/crypto/src/cms/CMSUtils.cs
+++ b/crypto/src/cms/CMSUtils.cs
@@ -4,6 +4,7 @@ using System.IO;
 
 using Org.BouncyCastle.Asn1;
 using Org.BouncyCastle.Asn1.Cms;
+using Org.BouncyCastle.Asn1.Ocsp;
 using Org.BouncyCastle.Asn1.X509;
 using Org.BouncyCastle.Utilities.Collections;
 using Org.BouncyCastle.Utilities.IO;
@@ -112,12 +113,46 @@ namespace Org.BouncyCastle.Cms
                 foreach (var crl in crlStore.EnumerateMatches(null))
                 {
                     result.Add(crl.CertificateList);
-                }
+				}
 			}
 			return result;
 		}
 
-		internal static Asn1Set CreateBerSetFromList(IEnumerable<Asn1Encodable> elements)
+        internal static List<Asn1TaggedObject> GetOtherRevocationInfosFromStore(
+			IStore<OtherRevocationInfoFormat> otherRevocationInfoStore)
+        {
+            var result = new List<Asn1TaggedObject>();
+            if (otherRevocationInfoStore != null)
+            {
+                foreach (var otherRevocationInfo in otherRevocationInfoStore.EnumerateMatches(null))
+                {
+                    ValidateOtherRevocationInfo(otherRevocationInfo);
+
+                    result.Add(new DerTaggedObject(false, 1, otherRevocationInfo));
+                }
+            }
+            return result;
+        }
+
+        internal static List<DerTaggedObject> GetOtherRevocationInfosFromStore(IStore<Asn1Encodable> otherRevInfoStore,
+            DerObjectIdentifier otherRevInfoFormat)
+        {
+			var result = new List<DerTaggedObject>();
+			if (otherRevInfoStore != null && otherRevInfoFormat != null)
+			{
+				foreach (var otherRevInfo in otherRevInfoStore.EnumerateMatches(null))
+				{
+                    var otherRevocationInfo = new OtherRevocationInfoFormat(otherRevInfoFormat, otherRevInfo);
+
+                    ValidateOtherRevocationInfo(otherRevocationInfo);
+
+                    result.Add(new DerTaggedObject(false, 1, otherRevocationInfo));
+				}
+			}
+			return result;
+        }
+
+        internal static Asn1Set CreateBerSetFromList(IEnumerable<Asn1Encodable> elements)
 		{
 			Asn1EncodableVector v = new Asn1EncodableVector();
 
@@ -157,5 +192,16 @@ namespace Org.BouncyCastle.Cms
 			TbsCertificateStructure tbsCert = GetTbsCertificateStructure(cert);
 			return new IssuerAndSerialNumber(tbsCert.Issuer, tbsCert.SerialNumber.Value);
 		}
-	}
+
+        internal static void ValidateOtherRevocationInfo(OtherRevocationInfoFormat otherRevocationInfo)
+        {
+            if (CmsObjectIdentifiers.id_ri_ocsp_response.Equals(otherRevocationInfo.InfoFormat))
+			{
+				OcspResponse ocspResponse = OcspResponse.GetInstance(otherRevocationInfo.Info);
+
+                if (OcspResponseStatus.Successful != ocspResponse.ResponseStatus.IntValueExact)
+                    throw new ArgumentException("cannot add unsuccessful OCSP response to CMS SignedData");
+            }
+        }
+    }
 }