diff options
author | David Hook <dgh@bouncycastle.org> | 2021-05-23 12:27:29 +1000 |
---|---|---|
committer | David Hook <dgh@bouncycastle.org> | 2021-05-23 12:27:29 +1000 |
commit | df061f598d00d6b7f70cfdb31ab521027573d381 (patch) | |
tree | 041e1d7c2ef31008b613e0db2c2133b4f495411e /crypto/test | |
parent | rewound case change (diff) | |
download | BouncyCastle.NET-ed25519-df061f598d00d6b7f70cfdb31ab521027573d381.tar.xz |
allowed for null policy OID
Diffstat (limited to 'crypto/test')
-rw-r--r-- | crypto/test/src/tsp/test/TSPTest.cs | 56 |
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( |