public void InvalidExtendAndVerifyToUserProvidedPublicationFromTestCoreTest(Ksi ksi) { // publication data from Test core, not included in publications file. Time: 2016-07-12 00:00:00 UTC PublicationData publicationData = new PublicationData("AAAAAA-CXQQZQ-AAOSZH-ONCB4K-TFGPBW-R6S6TF-6EW4DU-4QMP7X-GI2VCO-TNGAZM-EV6AZR-464IOA"); KsiSignatureInvalidContentException ex = Assert.Throws <KsiSignatureInvalidContentException>(delegate { ksi.Extend(TestUtil.GetSignature(), publicationData); }); Assert.AreEqual(VerificationError.Int09.Code, ex.VerificationResult.VerificationError.Code, "Invalid result code"); }
public void InvalidExtendToUserProvidedPublicationTest(Ksi ksi) { // publication data with modified hash PublicationData publicationData = new PublicationData("AAAAAA-CW45II-AAIYPA-UJ4GRT-HXMFBE-OTB4AB-XH3PT3-KNIKGV-PYCJXU-HL2TN4-RG6SCA-ZP3ZLX"); KsiSignatureInvalidContentException ex = Assert.Throws <KsiSignatureInvalidContentException>(delegate { ksi.Extend(TestUtil.GetSignature(), publicationData); }); Assert.AreEqual(VerificationError.Int09.Code, ex.VerificationResult.VerificationError.Code, "Unexpected result code"); }
public void ExtendInvalidSignatureTest(Ksi ksi) { KsiSignatureInvalidContentException ex = Assert.Throws <KsiSignatureInvalidContentException>(delegate { ksi.Extend(TestUtil.GetSignature(Resources.KsiSignature_Invalid_Aggregation_Chain_Input_Hash)); }); Assert.That(ex.Message.StartsWith("Signature verification failed"), "Unexpected exception message: " + ex.Message); Assert.IsNotNull(ex.Signature); Assert.IsTrue(ex.Signature.IsExtended); }
public void TestKsiSignatureExtendWithInvalidCalendarHashChain() { IKsiSignature signature = GetKsiSignatureFromFile(Resources.KsiSignature_Ok_AggregationHashChain_Only); KsiSignatureInvalidContentException ex = Assert.Throws <KsiSignatureInvalidContentException>(delegate { signature.Extend(GetCalendarHashChain()); }); Assert.That(ex.Message, Does.StartWith("Signature verification failed")); Assert.AreEqual(VerificationError.Int03, ex.VerificationResult.VerificationError, "Unexpected verificaton code"); }
public void CreateFromStreamAndVerifyInvalidSignatureTest() { using (FileStream stream = new FileStream(Path.Combine(TestSetup.LocalPath, Resources.KsiSignature_Invalid_Aggregation_Chain_Input_Hash), FileMode.Open)) { KsiSignatureInvalidContentException ex = Assert.Throws <KsiSignatureInvalidContentException>(delegate { new KsiSignatureFactory().Create(stream); }); Assert.That(ex.Message.StartsWith("Signature verification failed"), "Unexpected exception message: " + ex.Message); Assert.IsNotNull(ex.Signature); } }
public void LegacySignStaticInvalidSignatureTest() { Ksi ksi = GetStaticKsi(Resources.KsiService_LegacyAggregationResponsePdu, 318748698, null, PduVersion.v1); KsiSignatureInvalidContentException ex = Assert.Throws <KsiSignatureInvalidContentException>(delegate { ksi.Sign(new DataHash(Base16.Decode("01A1A700B0C8066C47ECBA05ED37BC14DCADB238552D86C659342D1D7E87B8772D"))); }); Assert.That(ex.Message.StartsWith("Signature verification failed"), "Unexpected exception message: " + ex.Message); Assert.IsNotNull(ex.Signature); Assert.AreEqual(VerificationError.Gen01.Code, ex.VerificationResult.VerificationError.Code); }
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 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 CreateFromStreamAndVerifyWithPolicyInvalidTest() { KsiSignatureFactory signatureFactory = new KsiSignatureFactory(new PublicationBasedVerificationPolicy(), new TestVerificationContext() { UserPublication = new PublicationData("AAAAAA-CVZ2AQ-AANGVK-SV7GJL-36LN65-AVJYZR-6XRZSL-HIMRH3-6GU7WR-YNRY7C-X2XECY-WFQXRB") }); KsiSignatureInvalidContentException ex = Assert.Throws <KsiSignatureInvalidContentException>(delegate { // Check invalid signature using (FileStream stream = new FileStream(Path.Combine(TestSetup.LocalPath, Resources.KsiSignature_Ok_With_Publication_Record), FileMode.Open)) { signatureFactory.Create(stream); } }); Assert.AreEqual(VerificationError.Pub04.Code, ex.VerificationResult.VerificationError.Code, "Unexpected result code"); }
public void BlockSignerCustomSignatureFactoryTest(Ksi ksi) { BlockSigner blockSigner = new BlockSigner(GetHttpKsiService(), null, new KsiSignatureFactory( new PublicationBasedVerificationPolicy(), new TestVerificationContext() { UserPublication = new PublicationData("AAAAAA-CVZ2AQ-AANGVK-SV7GJL-36LN65-AVJYZR-6XRZSL-HIMRH3-6GU7WR-YNRY7C-X2XECY-WFQXRB") })); IdentityMetadata metadata = new IdentityMetadata("test client id"); DataHash documentHash = new DataHash(Base16.Decode("01580192B0D06E48884432DFFC26A67C6C685BEAF0252B9DD2A0B4B05D1724C5F2")); blockSigner.Add(documentHash, metadata); KsiSignatureInvalidContentException ex = Assert.Throws <KsiSignatureInvalidContentException>(delegate { blockSigner.Sign().GetEnumerator().MoveNext(); }, "Automatic verification should fail."); Assert.That(ex.Message, Does.StartWith("Signature verification failed")); }