public void ExtendStaticWithoutSignatureWithPublicationDataTest() { Ksi ksi = GetStaticKsi(Resources.KsiService_ExtendResponsePdu_RequestId_1043101455, 1043101455); ArgumentNullException ex = Assert.Throws <ArgumentNullException>(delegate { ksi.Extend(null, new PublicationData(123456789, new DataHash(Base16.Decode("0111A700B0C8066C47ECBA05ED37BC14DCADB238552D86C659342D1D7E87B8772D")))); }); Assert.AreEqual("signature", ex.ParamName); }
public void ExtendStaticWithoutSignatureTest() { Ksi ksi = GetStaticKsi(Resources.KsiService_ExtendResponsePdu_RequestId_1043101455, 1043101455); ArgumentNullException ex = Assert.Throws <ArgumentNullException>(delegate { ksi.Extend(null); }); Assert.AreEqual("signature", ex.ParamName); }
public void ExtendStaticWithPublicationRecordInSignatureNullTest() { Ksi ksi = GetStaticKsi(Resources.KsiService_ExtendResponsePdu_RequestId_1043101455, 1043101455); ArgumentNullException ex = Assert.Throws <ArgumentNullException>(delegate { ksi.Extend(new TestKsiSignature(), (PublicationRecordInSignature)null); }); Assert.AreEqual("publicationRecord", ex.ParamName); }
public void LegacyExtendStaticWithNonZeroPayloadStatusTest() { IKsiSignature signature = new KsiSignatureFactory().Create(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiSignature_Ok))); Ksi ksi = GetStaticKsi(Resources.KsiService_LegacyExtendResponsePdu_NonZeroPayloadStatus, 768278381, null, PduVersion.v1); KsiServiceException ex = Assert.Throws <KsiServiceException>(delegate { ksi.Extend(signature); }); Assert.That(ex.Message.StartsWith("Server responded with error message. Status: 17; Message: No error."), "Unexpected exception message: " + ex.Message); }
public void ExtendStaticResponseHasOnlyUnknownNonCriticalPayloadTest() { IKsiSignature signature = new KsiSignatureFactory().Create(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiSignature_Ok))); Ksi ksi = GetStaticKsi(Resources.KsiService_ExtenderResponseUnkownNonCriticalPayload, 1234567890); KsiServiceException ex = Assert.Throws <KsiServiceException>(delegate { ksi.Extend(signature); }); Assert.That(ex.Message.StartsWith("Could not parse response message"), "Unexpected exception message: " + ex.Message); }
public void ExtendStaticResponseWithWrongRequestIdTest() { IKsiSignature signature = new KsiSignatureFactory().Create(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiSignature_Ok))); Ksi ksi = GetStaticKsi(Resources.KsiService_ExtendResponsePdu_RequestId_1043101455, 1234567890); KsiServiceException ex = Assert.Throws <KsiServiceException>(delegate { ksi.Extend(signature); }); Assert.That(ex.Message.StartsWith("Invalid response PDU. Could not find a valid payload."), "Unexpected exception message: " + ex.Message); }
public void ExtendStaticInvalidPduResponseVersionTest() { IKsiSignature signature = new KsiSignatureFactory().Create(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiSignature_Ok))); Ksi ksi = GetStaticKsi(Resources.KsiService_ExtendResponsePdu_RequestId_1043101455, 1043101455, null, PduVersion.v1); KsiServiceUnexpectedResponseFormatException ex = Assert.Throws <KsiServiceUnexpectedResponseFormatException>(delegate { ksi.Extend(signature); }); Assert.That(ex.Message.StartsWith("Received PDU v2 response to PDU v1 request."), "Unexpected exception message: " + ex.Message); }
public void ExtendStaticMultiPayloadsResponseIncludingErrorPayloadTest() { IKsiSignature signature = new KsiSignatureFactory().Create(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiSignature_Ok))); Ksi ksi = GetStaticKsi(Resources.KsiService_ExtendResponsePdu_Multi_Payloads_Including_ErrorPayload); KsiServiceException ex = Assert.Throws <KsiServiceException>(delegate { ksi.Extend(signature); }); Assert.That(ex.Message.StartsWith("Server responded with error message. Status: 418464624128; Message: anon"), "Unexpected inner exception message: " + ex.Message); }
public void LegacyExtendStaticInvalidRequestIdTest() { IKsiSignature signature = new KsiSignatureFactory().Create(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiSignature_Ok))); Ksi ksi = GetStaticKsi(Resources.KsiService_LegacyExtendResponsePdu, 0, null, PduVersion.v1); KsiServiceException ex = Assert.Throws <KsiServiceException>(delegate { ksi.Extend(signature); }); Assert.That(ex.Message.StartsWith("Unknown request ID:"), "Unexpected exception message: " + ex.Message); }
public void TcpExtendWithInvalidPortTest(Ksi ksi) { Exception ex = Assert.Throws <KsiServiceProtocolException>(delegate { ksi.Extend(TestUtil.GetSignature()); }); Assert.That(ex.Message.StartsWith("Completing connection failed"), "Unexpected exception message: " + ex.Message); Assert.IsNotNull(ex.InnerException, "Inner exception should not be null"); Assert.That(ex.InnerException.Message.StartsWith("No connection could be made because the target machine actively refused it"), "Unexpected inner exception message: " + ex.InnerException.Message); }
public void HAExtendWithTcpAndHttpServicesAndNoPublicationsFileTest() { Ksi ksi = new Ksi(new HAKsiService(null, ExtendingServices, null)); IKsiSignature ksiSignature = TestUtil.GetSignature(); Exception ex = Assert.Throws <HAKsiServiceException>(delegate { ksi.Extend(ksiSignature); }); Assert.IsFalse(ksiSignature.IsExtended); Assert.That(ex.Message.StartsWith("Publications file service is missing"), "Unexpected exception message: " + ex.Message); }
public void LegacyExtendStaticInvalidMacAlgorithmTest() { IKsiSignature signature = new KsiSignatureFactory().Create(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiSignature_Ok))); Ksi ksi = GetStaticKsi(Resources.KsiService_LegacyExtendResponsePdu, 3491956840, null, PduVersion.v1, null, HashAlgorithm.Sha2512); KsiServiceException ex = Assert.Throws <KsiServiceException>(delegate { ksi.Extend(signature); }); Assert.That(ex.Message.StartsWith("HMAC algorithm mismatch."), "Unexpected exception message: " + ex.Message); }
public void ExtendStaticNoSuitablePublicationYetTest() { IKsiSignature signature = TestUtil.GetSignature(Resources.KsiSignature_Ok_New); Ksi ksi = GetStaticKsi(Resources.KsiService_ExtendResponsePdu_RequestId_1043101455, 1043101455); KsiException ex = Assert.Throws <KsiException>(delegate { ksi.Extend(signature); }); Assert.That(ex.Message.StartsWith("No suitable publication yet"), "Unexpected exception message: " + ex.Message); }
public void ExtendStaticErrorPayloadTest() { IKsiSignature signature = new KsiSignatureFactory().Create(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiSignature_Ok))); Ksi ksi = GetStaticKsi(Resources.KsiService_ExtenderResponsePdu_ErrorPayload); KsiServiceException ex = Assert.Throws <KsiServiceException>(delegate { ksi.Extend(signature); }); Assert.That(ex.Message.StartsWith("Server responded with error message. Status: 258; Message: The request could not be authenticated."), "Unexpected exception message: " + ex.Message); }
public void ExtendStaticInvalidCalendarHashChainTest() { IKsiSignature signature = new KsiSignatureFactory().Create(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiSignature_Ok_Only_Aggregtion_Chains))); Ksi ksi = GetStaticKsi(Resources.KsiService_ExtendResponsePdu_Invalid_Signature, 1207047688); KsiSignatureInvalidContentException ex = Assert.Throws <KsiSignatureInvalidContentException>(delegate { ksi.Extend(signature); }); Assert.That(ex.Message.StartsWith("Signature verification failed"), "Unexpected exception message: " + ex.Message); Assert.IsNotNull(ex.Signature); Assert.AreEqual(VerificationError.Int03.Code, ex.VerificationResult.VerificationError.Code); }
public void ExtendAndVerifyToUserProvidedPublicationTest(Ksi ksi) { PublicationBasedVerificationPolicy rule = new PublicationBasedVerificationPolicy(); PublicationData publicationData = new PublicationData("AAAAAA-CW45II-AAKWRK-F7FBNM-KB6FNV-DYYFW7-PJQN6F-JKZWBQ-3OQYZO-HCB7RA-YNYAGA-ODRL2V"); IKsiSignature extendedSignature = ksi.Extend(TestUtil.GetSignature(), publicationData); VerificationContext context = new VerificationContext(extendedSignature) { UserPublication = publicationData }; VerificationResult verificationResult = rule.Verify(context); Assert.AreEqual(VerificationResultCode.Ok, verificationResult.ResultCode); }
public void LegacyExtendStaticInvalidSignatureTest() { IKsiSignature signature = new KsiSignatureFactory(new EmptyVerificationPolicy()).Create( File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiSignature_Ok_Only_Aggregtion_Chains))); Ksi ksi = GetStaticKsi(Resources.KsiService_LegacyExtendResponsePdu, 3491956840, null, PduVersion.v1); KsiSignatureInvalidContentException ex = Assert.Throws <KsiSignatureInvalidContentException>(delegate { ksi.Extend(signature); }); Assert.That(ex.Message.StartsWith("Signature verification failed"), "Unexpected exception message: " + ex.Message); Assert.IsNotNull(ex.Signature); Assert.AreEqual(VerificationError.Int03.Code, ex.VerificationResult.VerificationError.Code); }
public void ExtendAndVerifyToUserProvidedPublicationNotInPublicationsFileTest(Ksi ksi) { PublicationBasedVerificationPolicy rule = new PublicationBasedVerificationPolicy(); // publication data that is not included in publications file. Time: 2016-07-12 00:00:00 UTC PublicationData publicationData = new PublicationData("AAAAAA-CXQQZQ-AAPGJF-HGNMUN-DXEIQW-NJZZOE-J76OK4-BV3FKY-AEAWIP-KSPZPW-EJKVAI-JPOOR7"); IKsiSignature extendedSignature = ksi.Extend(TestUtil.GetSignature(), publicationData); VerificationContext context = new VerificationContext(extendedSignature) { UserPublication = publicationData }; VerificationResult verificationResult = rule.Verify(context); Assert.AreEqual(VerificationResultCode.Ok, verificationResult.ResultCode); }
public void ExtendAndVerifySignatureWithAggregationChainsOnly(Ksi ksi) { PublicationBasedVerificationPolicy rule = new PublicationBasedVerificationPolicy(); // signature contains only aggregation chains IKsiSignature ksiSignature = TestUtil.GetSignature(Resources.KsiSignature_Ok_Only_Aggregtion_Chains); IKsiSignature extendedSignature = ksi.Extend(ksiSignature); PublicationData publicationData = ksi.GetPublicationsFile().GetNearestPublicationRecord(ksiSignature.AggregationTime).PublicationData; VerificationContext context = new VerificationContext(extendedSignature) { UserPublication = publicationData }; VerificationResult verificationResult = rule.Verify(context); Assert.AreEqual(VerificationResultCode.Ok, verificationResult.ResultCode); }
public void ExtendAndVerifyTest(Ksi ksi) { PublicationBasedVerificationPolicy policy = new PublicationBasedVerificationPolicy(); IKsiSignature ksiSignature = TestUtil.GetSignature(); IKsiSignature extendedSignature = ksi.Extend(ksiSignature); PublicationData publicationData = ksi.GetPublicationsFile().GetNearestPublicationRecord(ksiSignature.AggregationTime).PublicationData; VerificationContext context = new VerificationContext(extendedSignature) { UserPublication = publicationData, KsiService = GetHttpKsiService() }; VerificationResult verificationResult = policy.Verify(context); Assert.AreEqual(VerificationResultCode.Ok, verificationResult.ResultCode); }
public void ParallelExtendingTest(Ksi ksi) { ManualResetEvent waitHandle = new ManualResetEvent(false); int doneCount = 0; int runCount = 10; string errorMessage = null; MemoryStream ms = new MemoryStream(); using (FileStream stream = new FileStream(Path.Combine(TestSetup.LocalPath, Resources.KsiSignature_Ok), FileMode.Open)) { stream.CopyTo(ms); } for (int i = 0; i < runCount; i++) { Console.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " Start " + i); int k = i; MemoryStream s = new MemoryStream(); ms.Seek(0, SeekOrigin.Begin); ms.CopyTo(s); s.Seek(0, SeekOrigin.Begin); Task.Run(() => { long start = DateTime.Now.Ticks; Console.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " Start extending " + k); try { IKsiSignature ksiSignature = new KsiSignatureFactory().Create(s); IKsiSignature extendedToNearest = ksi.Extend(ksiSignature); s.Close(); Assert.AreEqual(1455494400, extendedToNearest.PublicationRecord.PublicationData.PublicationTime); } catch (Exception ex) { Console.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " Error " + k + ". " + ex); if (errorMessage == null) { errorMessage = ex.ToString(); } } finally { Console.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + "\t Done! " + k + "\t It took: " + (DateTime.Now.Ticks - start) / 10000 + " ms"); doneCount++; if (doneCount == runCount) { waitHandle.Set(); } } }); } Console.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " Waiting ..."); Assert.IsTrue(waitHandle.WaitOne(20000), "Wait handle timed out."); if (errorMessage != null) { Assert.Fail("ERROR: " + errorMessage); } Console.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " All done."); }