public void SignAsyncAuthZViaCardNr() { DsspClient dsspClient = new DsspClient("https://www.e-contract.be/dss-ws/dss"); dsspClient.Application.X509.Certificate = new X509Certificate2("certificate.p12", ""); DsspSession s; using (Stream i = File.OpenRead("Blank.pdf")) { Document id = new Document("application/pdf", i); s = dsspClient.UploadDocument(id); } String correct = "591591588049"; Authorization authz = Authorization.AllowDssSignIfMatchCardNumber(correct); String signResponse = emulateBrowser( s.GeneratePendingRequest(new Uri("http://localhost/dssp"), "EN", authz), "View Document"); try { using (Stream i = File.OpenRead("Blank.pdf")) { Document id = new Document("application/pdf", i); s = dsspClient.UploadDocument(id); } authz = Authorization.DenyDssSignIfMatchCardNumber(correct); signResponse = emulateBrowser( s.GeneratePendingRequest(new Uri("http://localhost/dssp"), "EN", authz), "View Document"); Assert.Fail("should fail with wrong"); } catch (InvalidOperationException) { } try { using (Stream i = File.OpenRead("Blank.pdf")) { Document id = new Document("application/pdf", i); s = dsspClient.UploadDocument(id); } authz = Authorization.AllowDssSignIfMatchCardNumber("591-3291070-59"); signResponse = emulateBrowser( s.GeneratePendingRequest(new Uri("http://localhost/dssp"), "EN", authz), "View Document"); Assert.Fail("should fail with wrong"); } catch (InvalidOperationException) { } }
public void SignAsyncAuthZViaSubject() { DsspClient dsspClient = new DsspClient("https://www.e-contract.be/dss-ws/dss"); dsspClient.Application.X509.Certificate = new X509Certificate2("certificate.p12", ""); DsspSession s; using (Stream i = File.OpenRead("Blank.pdf")) { Document id = new Document("application/pdf", i); s = dsspClient.UploadDocument(id); } String correct = "SERIALNUMBER=79021802145, GIVENNAME=Bryan Eduard, SURNAME=Brouckaert, CN=Bryan Brouckaert (Signature), C=BE"; Authorization authz = Authorization.AllowDssSignIfMatchSubject(correct); String signResponse = emulateBrowser( s.GeneratePendingRequest(new Uri("http://localhost/dssp"), "EN", authz), "View Document"); try { using (Stream i = File.OpenRead("Blank.pdf")) { Document id = new Document("application/pdf", i); s = dsspClient.UploadDocument(id); } authz = Authorization.DenyDssSignIfMatchSubject(correct); signResponse = emulateBrowser( s.GeneratePendingRequest(new Uri("http://localhost/dssp"), "EN", authz), "View Document"); Assert.Fail("should fail with wrong"); } catch (InvalidOperationException) { } try { using (Stream i = File.OpenRead("Blank.pdf")) { Document id = new Document("application/pdf", i); s = dsspClient.UploadDocument(id); } authz = Authorization.AllowDssSignIfMatchSubject("SERIALNUMBER=00000000000, GIVENNAME=Bryan Eduard, SURNAME=Brouckaert, CN=Bryan Brouckaert (Signature), C=BE"); signResponse = emulateBrowser( s.GeneratePendingRequest(new Uri("http://localhost/dssp"), "EN", authz), "View Document"); Assert.Fail("should fail with wrong"); } catch (InvalidOperationException) { } }
public void SignAsyncNoLangInvisibleNoProps() { DsspClient dsspClient = new DsspClient("https://www.e-contract.be/dss-ws/dss"); dsspClient.Application.X509.Certificate = new X509Certificate2("certificate.p12", ""); DsspSession s; using (Stream i = File.OpenRead("Blank.pdf")) { Document id = new Document("application/pdf", i); s = dsspClient.UploadDocument(id); } String signResponse = emulateBrowser( s.GeneratePendingRequest("http://localhost/dssp"), "View Document"); NameIdentifierType signer = s.ValidateSignResponse(signResponse); Assert.AreEqual("SERIALNUMBER=79021802145, GIVENNAME=Bryan Eduard, SURNAME=Brouckaert, CN=Bryan Brouckaert (Signature), C=BE", signer.Value); Document od = dsspClient.DownloadDocument(s); using (Stream o = File.OpenWrite("Output.pdf")) { od.Content.CopyTo(o); } od.Content.Seek(0, SeekOrigin.Current); Verify(od, null, null); }
protected void Page_Load(object sender, EventArgs e) { Document document = new Document(); document.MimeType = "application/pdf"; document.Content = File.OpenRead(Path.Combine(HostingEnvironment.ApplicationPhysicalPath, @"App_Data\dssp-specs.pdf")); DsspClient dsspClient = new DsspClient("https://www.e-contract.be/dss-ws/dss"); dsspClient.ApplicationName = Settings.Default.AppName; dsspClient.ApplicationPassword = Settings.Default.AppPwd; DsspSession dsspSession = dsspClient.UploadDocument(document); Session["dsspSession"] = dsspSession; VisibleSignatureProperties visibleSignature = null; if (Session["Visible"] == "Photo") { visibleSignature = new ImageVisibleSignature() { Page = (int) Session["Page"], X = (int) Session["X"], Y = (int) Session["Y"] }; } else if (Session["Visible"] == "Photo and Signer Info") { visibleSignature = new ImageVisibleSignature() { Page = (int)Session["Page"], X = (int)Session["X"], Y = (int)Session["Y"], ValueUri = "urn:be:e-contract:dssp:1.0:vs:si:eid-photo:signer-info", CustomText = (string)Session["CustomText"] }; } // verify whether DsspSession is serializable BinaryFormatter binaryFormatter = new BinaryFormatter(); MemoryStream memoryStream = new MemoryStream(); binaryFormatter.Serialize(memoryStream, dsspSession); memoryStream.Seek(0, SeekOrigin.Begin); dsspSession = (DsspSession) binaryFormatter.Deserialize(memoryStream); Authorization authorization = new Authorization(); //authorization.AddAuthorizedCardNumber("591937284531"); //authorization.AddAuthorizedSubjectName("SERIALNUMBER=79102520991, GIVENNAME=Frank Henri, SURNAME=Cornelis, CN=Frank Cornelis (Signature), C=BE"); //authorization.AddNonAuthorizedSubjectName("SERIALNUMBER=79102520991, GIVENNAME=Frank Henri, SURNAME=Cornelis, CN=Frank Cornelis (Signature), C=BE"); this.PendingRequest.Value = dsspSession.GeneratePendingRequest( new Uri(Request.Url, ResolveUrl("~/Signed.aspx")), Settings.Default.Language, new SignatureRequestProperties() { SignerRole = (string)Session["Role"], SignatureProductionPlace = (string)Session["Location"], VisibleSignature = visibleSignature }, authorization ); }
public void SignAsyncNLVisiblePropsMultiText() { DsspClient dsspClient = new DsspClient("https://www.e-contract.be/dss-ws/dss"); dsspClient.Application.UT.Name = "egelke"; dsspClient.Application.UT.Password = "******"; DsspSession s; using (Stream i = File.OpenRead("Blank.pdf")) { Document id = new Document("application/pdf", i); s = dsspClient.UploadDocument(id); } SignatureRequestProperties props = new SignatureRequestProperties() { SignerRole = "Developer", SignatureProductionPlace = "Oost-Vlaanderen", VisibleSignature = new ImageVisibleSignature() { CustomText = "Custom", CustomText2 = "Custom2", CustomText3 = "Custom3", CustomText4 = "Custom4", CustomText5 = "Custom5", ValueUri = "urn:be:e-contract:dssp:1.0:vs:si:eid-photo:signer-info", Page = 1, X = 500, Y = 700 } }; String signResponse = emulateBrowser( s.GeneratePendingRequest(new Uri("http://localhost/dssp"), "NL", props), "Document bekijken"); NameIdentifierType signer = s.ValidateSignResponse(signResponse); Assert.AreEqual("SERIALNUMBER=79021802145, GIVENNAME=Bryan Eduard, SURNAME=Brouckaert, CN=Bryan Brouckaert (Signature), C=BE", signer.Value); Document od = dsspClient.DownloadDocument(s); using (Stream o = File.OpenWrite("Output.pdf")) { od.Content.CopyTo(o); } od.Content.Seek(0, SeekOrigin.Current); Verify(od, "Developer", "Oost-Vlaanderen"); }