summary refs log tree commit diff
path: root/crypto/test/src/tsp
diff options
context:
space:
mode:
authorDavid Hook <dgh@bouncycastle.org>2021-05-23 12:27:29 +1000
committerDavid Hook <dgh@bouncycastle.org>2021-05-23 12:27:29 +1000
commitdf061f598d00d6b7f70cfdb31ab521027573d381 (patch)
tree041e1d7c2ef31008b613e0db2c2133b4f495411e /crypto/test/src/tsp
parentrewound case change (diff)
downloadBouncyCastle.NET-ed25519-df061f598d00d6b7f70cfdb31ab521027573d381.tar.xz
allowed for null policy OID
Diffstat (limited to 'crypto/test/src/tsp')
-rw-r--r--crypto/test/src/tsp/test/TSPTest.cs56
1 files changed, 56 insertions, 0 deletions
diff --git a/crypto/test/src/tsp/test/TSPTest.cs b/crypto/test/src/tsp/test/TSPTest.cs
index 968929b6d..4a4f2e28f 100644
--- a/crypto/test/src/tsp/test/TSPTest.cs
+++ b/crypto/test/src/tsp/test/TSPTest.cs
@@ -298,6 +298,62 @@ namespace Org.BouncyCastle.Tsp.Tests
 		}
 
 		[Test]
+		public void TestNullPolicy()
+		{
+			// null in request and token generator - should fail
+			TimeStampTokenGenerator tsTokenGen = new TimeStampTokenGenerator(
+				privateKey, cert, TspAlgorithms.Sha1, null);
+
+			tsTokenGen.SetCertificates(certs);
+
+			TimeStampRequestGenerator reqGen = new TimeStampRequestGenerator();
+
+			TimeStampRequest request = reqGen.Generate(TspAlgorithms.Sha1, new byte[20]);
+
+			TimeStampResponseGenerator tsRespGen = new TimeStampResponseGenerator(tsTokenGen, TspAlgorithms.Allowed, null);
+
+			TimeStampResponse tsResp = tsRespGen.Generate(request, BigInteger.ValueOf(23), DateTime.UtcNow);
+
+			tsResp = new TimeStampResponse(tsResp.GetEncoded());
+
+			TimeStampToken tsToken = tsResp.TimeStampToken;
+
+			if (tsToken != null)
+			{
+				Assert.Fail("badPolicy - token not null.");
+			}
+
+			PkiFailureInfo failInfo = tsResp.GetFailInfo();
+
+			if (failInfo == null)
+			{
+				Assert.Fail("badPolicy - failInfo set to null.");
+			}
+
+			if (failInfo.IntValue != PkiFailureInfo.UnacceptedPolicy)
+			{
+				Assert.Fail("badPolicy - wrong failure info returned.");
+			}
+
+			// request specifies policy, token generator doesn't - should work
+			reqGen = new TimeStampRequestGenerator();
+
+			reqGen.SetReqPolicy("1.1");
+
+			request = reqGen.Generate(TspAlgorithms.Sha1, new byte[20]);
+
+			tsRespGen = new TimeStampResponseGenerator(tsTokenGen, TspAlgorithms.Allowed, null);
+
+		    tsResp = tsRespGen.Generate(request, BigInteger.ValueOf(24), DateTime.UtcNow);
+
+			tsResp = new TimeStampResponse(tsResp.GetEncoded());
+
+			tsToken = tsResp.TimeStampToken;
+
+			Assert.AreEqual(tsToken.TimeStampInfo.Policy, "1.1"); // policy should be picked up off request
+		}
+
+		[Test]
 		public void TestCertReq()
 		{
 			TimeStampTokenGenerator tsTokenGen = new TimeStampTokenGenerator(