public async Task <ActionResult> Index() { // Instantiate the XmlElementSignatureStarter class, responsible for receiving the signature // elements and start the signature process. var signatureStarter = new XmlElementSignatureStarter(Util.GetRestPkiClient()); // Set the XML to be signed, a sample Brazilian contract pre-generated. signatureStarter.SetXml(StorageMock.GetSampleContractPath()); // Set the ID of the element to be signed. signatureStarter.SetToSignElementId("P601005727531"); // Set the signature policy. signatureStarter.SetSignaturePolicy(StandardXmlSignaturePolicies.PkiBrazil.XadesAdrBasica); // Set the security context to be used to determine trust in the certificate chain. We have // encapsulated the security context choice on Util.cs. signatureStarter.SetSecurityContext(Util.GetSecurityContextId()); // Call the StartWithWebPki() method, which initiates the signature. This yields the token, // a 43-character case-sensitive URL-safe string, which identifies this signature process. We'll // use this value to call the signWithRestPki() method on the Web PKI component (see // signature-form.js) and also to complete the signature on the POST action below (this should // not be mistaken with the API access token). var token = await signatureStarter.StartWithWebPkiAsync(); // The token acquired above can only be used for a single signature attempt. In order to retry // the signature it is necessary to get a new token. This can be a problem if the user uses the // back button of the browser, since the browser might show a cached page that we rendered // previously, with a now stale token. To prevent this from happening, we call the method // SetNoCacheHeaders() (in BaseController) which sets HTTP headers to prevent caching of the // page. base.SetNoCacheHeaders(); // Render the signature page with the token obtained from REST PKI. return(View(new SignatureModel() { Token = token })); }
public ActionResult SampleContract() { var fileContent = StorageMock.Read(StorageMock.GetSampleContractPath()); return(File(fileContent, "text/xml", "SampleContract.xml")); }