This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Verify the integrity of the image by checking the signature using the certificate public key | |
/// </summary> | |
/// <param name="xmlFilePath">Path to the signed xml image document</param> | |
/// <param name="certificateBuffer">The public key certificate byte[] to verify the integrity of the signed xml image document</param> | |
/// <param name="certPassword">Private key certificate Password</param> | |
/// <returns>True - If image integrity is intact. False - If image has been tampered with</returns> | |
public static bool VerifyImage(string xmlFilePath, byte[] certificateBuffer, string certPassword) | |
{ | |
var certificate = new X509Certificate2(certificateBuffer, certPassword); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Verify the integrity of the signed XML document | |
/// </summary> | |
/// <param name="xmlFilePath">Path to the signed xml document</param> | |
/// <param name="certificate">X509Certificate2 Public key certificate</param> | |
/// <returns></returns> | |
private static bool VerifyXMLDocument(string xmlFilePath, X509Certificate2 certificate) | |
{ | |
var xmlDocument = ReadXMLDocumentFromPath(xmlFilePath); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Sign the image data with the given certificate and write to the xmlFilePath | |
/// </summary> | |
/// <param name="imageBuffer">Image data to sign</param> | |
/// <param name="certificateBuffer">Private key certificate byte[]</param> | |
/// <param name="certPassword">Private key certificate Password</param> | |
/// <param name="xmlFilePath">The path to save the signed XML</param> | |
public static void SignImage(byte[] imageBuffer, byte[] certificateBuffer,string certPassword, string xmlFilePath) | |
{ | |
var certificate = new X509Certificate2(certificateBuffer, certPassword); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Sign the xml image document using private key certificate | |
/// </summary> | |
/// <param name="xmlDocumentBuffer">Byte[] of the xml image document</param> | |
/// <param name="certificate">X509Certificate2 private key certificate to sign the xml document</param> | |
/// <param name="signedXMLPath">Path to save the signed xml document</param> | |
private static void SignXMLDocument(byte[] xmlDocumentBuffer, X509Certificate2 certificate, string signedXMLPath) | |
{ | |
// Load xmlDocument data in to an XML Document | |
XmlDocument xmlDocument = new XmlDocument(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Serialize an image byte[] to an XML byte[] | |
/// </summary> | |
/// <param name="imageBuffer">Byte[] of the image to be serialized into XML</param> | |
/// <returns>Byte[] of the XML</returns> | |
private static byte[] SerializeImageToXML(byte[] imageBuffer) | |
{ | |
XmlSerializer x = new XmlSerializer(typeof(byte[])); | |
using (MemoryStream myFileStream = new MemoryStream()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Security.Cryptography.X509Certificates; | |
using System.Security.Cryptography.Xml; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Xml; | |
using System.Xml.Serialization; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using GemBox.Pdf; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace SignPDF | |
{ | |
class Program |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Parameters: | |
Stage: | |
Type: String | |
ContainerPort: | |
Type: Number | |
ImageURI: | |
Type: String |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Parameters: | |
Stage: | |
Type: String | |
Default: dev | |
GithubUserName: | |
Type: String | |
Default: <USERNAME> | |
GithubRepo: | |
Type: String | |
Default: Fargate-ECSCluster-Cloudformation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TaskDefinition: | |
Type: AWS::ECS::TaskDefinition | |
Properties: | |
Memory: 1024 | |
Cpu: 512 | |
NetworkMode: awsvpc | |
RequiresCompatibilities: | |
- 'FARGATE' | |
TaskRoleArn: !Ref ExecutionRole | |
ExecutionRoleArn: !Ref ExecutionRole |