/** * This action open a XML file and inspect its signatures. */ public ActionResult Index(string userfile) { // Our action only works if a userfile is given to work with. byte[] userfileContent; if (!StorageMock.TryGetFile(userfile, out userfileContent)) { return(HttpNotFound()); } // Instanciate the XmlSignatureLocator class, responsible for opening and validating the signatures // in the XML file. The signed XML content is passed as a parameter of the XmlSignatureLocator. var xmlSignatureLocator = new XmlSignatureLocator(userfileContent); // Get the list of signatures found in the XML file. var signatures = xmlSignatureLocator.GetSignatures(); // Specify the parameters for the signature validation: // Define the trust arbitrator used to validate the certificate. var trustArbitrator = Util.GetTrustArbitrator(); // Acces any valid XmlDSig signature as long as the signer certificate is trusted. var policyMapper = XmlPoliciesForValidation.GetXmlDSigBasic(trustArbitrator); // Generate a model to be shown on the page from each XmlSignature instance retrieved from // GetSignatures() method above. This class can be inspected on Models/PKi/OpenXmlSignatureModel.cs // file. In this class, we validate each signature based on the policy mapper defined above. var sigModels = signatures.Select(s => new XmlSignatureModel(s, policyMapper)).ToList(); // Render the signatures' information (see file OpenXmlSignaturePki/Index.cshtml for more // information on the information returned). return(View(new OpenXmlSignatureModel() { Signatures = sigModels })); }
private void validateXmlSignature(string filePath) { var policy = XmlPolicySpec.GetXmlDSigBasic(App.GetTrustArbitrator()); var xmlSigLocator = new XmlSignatureLocator(File.ReadAllBytes(filePath)); Signers.Clear(); foreach (var signature in xmlSigLocator.GetSignatures()) { var vr = signature.Validate(policy); Signers.Add(new SignerItem(getSignerDescription(signature, vr), vr)); } }
// GET ValidateSignature/Xml public ActionResult Xml(string id) { byte[] content; string extension; if (!Storage.TryGetFile(id, out content, out extension)) { return(HttpNotFound()); } var xmlSignatureLocator = new XmlSignatureLocator(content); var model = xmlSignatureLocator.GetSignatures(); return(View(model)); }
public IHttpActionResult Post(OpenXmlSignatureRequest request) { // This sample requires the FileId field is valid and corresponds to an existing file. if (string.IsNullOrEmpty(request.FileId)) { return(BadRequest()); } // Verifies the existence of the FileId and read its content. byte[] content; if (!Storage.TryGetFile(request.FileId, out content)) { return(NotFound()); } // Get an instance of the XmlSignatureLocator class, which is responsible to open the // signed XML. var xmlSignatureLocator = new XmlSignatureLocator(content); var signatures = xmlSignatureLocator.GetSignatures(); var validationPolicy = XmlPolicySpec.GetXmlDSigBasic(Util.GetTrustArbitrator()); var vrs = signatures.ToDictionary(s => s, s => s.Validate(validationPolicy)); return(Ok(new OpenXmlSignatureResponse(signatures, vrs))); }