protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //Retrieve the content string signResponse = Request.Form.Get("SignResponse"); //Retrieve the session DsspSession session = (DsspSession)Session["dsspSession"]; // verify whether DsspSession is serializable BinaryFormatter binaryFormatter = new BinaryFormatter(); MemoryStream memoryStream = new MemoryStream(); binaryFormatter.Serialize(memoryStream, session); memoryStream.Seek(0, SeekOrigin.Begin); session = (DsspSession)binaryFormatter.Deserialize(memoryStream); Document signedDocument; try { //Check if the content is valid, this isn't required but strongly advised. NameIdentifierType newSigner = session.ValidateSignResponse(signResponse); //Remove the DSS-P Session from the HTTP Session Session.Remove("dsspSession"); //download the signed document signedDocument = dsspClient.DownloadDocument(session); //You should save the signed document about here... Session["signedDocument"] = signedDocument; //For demo purposes, lets validate the signature. This is purely optional SecurityInfo securityInfo = dsspClient.Verify(signedDocument); //Display some interesting info about the signed document this.msg.Text = "signed document with timestamp valid until " + securityInfo.TimeStampValidity; foreach (SignatureInfo signature in securityInfo.Signatures) { if (signature.SignerSubject == newSigner.Value) { this.signatures.Items.Add("New: Signed by " + signature.Signer.Subject + " on " + signature.SigningTime); } else { this.signatures.Items.Add("Signed by " + signature.Signer.Subject + " on " + signature.SigningTime); } } this.view.Enabled = true; } catch (AuthorizationError error) { //Failed, lets display the error this.msg.Text = "authorization error: " + error.AttemptedSigner.Value; this.view.Enabled = false; return; } catch (RequestError error) { //Failed, lets display the error this.msg.Text = "signing error: " + error.Message; this.view.Enabled = false; return; } } }
public async Task <HttpResponseMessage> Post(string id, [FromBody] FormDataCollection formData) { NameIdentifierType newSigner = null; try { foreach (KeyValuePair <String, String> formField in formData) { if (formField.Key == "SignResponse") { try { //check if the sign response is correct, keep the signer newSigner = sessions[id].ValidateSignResponse(formField.Value); docs[id].Alert = new Alert() { Message = "New signature by " + newSigner.Value, Type = "success" }; //get the session and remove it from the store DsspSession session = sessions.Remove(id); //Download the signed document. Document doc = await dsspClient.DownloadDocumentAsync(session); docs[id].Content = doc.Content; //You should save the signed document about here... //For demo purposes, lets validate the signature. This is purely optional SecurityInfo securityInfo = await dsspClient.VerifyAsync(doc); //Keep some interesting info about the signed document docs[id].TimeStampValidity = securityInfo.TimeStampValidity; docs[id].Signatures = new List <SignInfo>(); foreach (SignatureInfo info in securityInfo.Signatures) { SignInfo i = new SignInfo(); i.Signer = info.SignerSubject; i.SignedOn = info.SigningTime; i.Location = info.SignatureProductionPlace; i.Role = info.SignerRole; docs[id].Signatures.Add(i); } } catch (AuthorizationError ae) { newSigner = ae.AttemptedSigner; docs[id].Alert = new Alert() { Message = "Failed signature attempt by " + ae.AttemptedSigner.Value, Type = "warning" }; sessions.Remove(id); //we can remove now, it is no longer valid } } } if (newSigner == null) { docs[id].Alert = new Alert() { Message = "No new signature found", Type = "danger" }; } } catch (Exception e) { docs[id].Alert = new Alert() { Message = "Internal error: " + e.Message, Type = "danger" }; } //Redirecting back to the main site (via HTML to make sure "Get" is used instead of POST) return(RedirectBack()); }
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 ((String)Session["Visible"] == "Photo") { visibleSignature = new ImageVisibleSignature() { Page = (int)Session["Page"], X = (int)Session["X"], Y = (int)Session["Y"] }; } else if ((String)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("591591588049"); //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 ); }