Пример #1
0
        public static AS4Message SignWithCertificate(AS4Message message, X509Certificate2 certificate)
        {
            var config = new CalculateSignatureConfig(certificate,
                                                      X509ReferenceType.BSTReference,
                                                      Constants.SignAlgorithms.Sha256,
                                                      Constants.HashFunctions.Sha256);

            message.Sign(config);

            return(message);
        }
Пример #2
0
        private string SaveAS4MessageUnit(MessageUnit unit, bool signed)
        {
            AS4Message as4Message = AS4Message.Create(unit);

            if (signed)
            {
                var config = new CalculateSignatureConfig(
                    new X509Certificate2(
                        holodeck_partya_certificate,
                        certificate_password,
                        X509KeyStorageFlags.Exportable));

                as4Message.Sign(config);
            }

            return(_bodyStore.SaveAS4Message("not used location", as4Message));
        }
Пример #3
0
 private static void SignAS4Message(CalculateSignatureConfig settings, AS4Message message)
 {
     try
     {
         message.Sign(settings);
     }
     catch (Exception exception)
     {
         Logger.Error(exception.Message);
         if (exception.InnerException != null)
         {
             Logger.Error(exception.InnerException.Message);
         }
         Logger.Trace(exception.StackTrace);
         throw;
     }
 }
Пример #4
0
        private static AS4Message SignedEncryptedAS4UserMessage(AS4Component msh, string ebmsMessageId)
        {
            string attachmentId = "attachment-" + Guid.NewGuid();

            var user = new UserMessage(
                ebmsMessageId,
                new CollaborationInfo(
                    agreement: new AgreementReference(
                        value: "http://agreements.europa.org/agreement",
                        pmodeId: DefaultPModeId),
                    service: new Service(
                        value: "getting:started",
                        type: "eu:europa:services"),
                    action: "eu:sample:01",
                    conversationId: "eu:europe:conversation"),
                Party.DefaultFrom,
                Party.DefaultTo,
                new [] { new PartInfo("cid:" + attachmentId) },
                Enumerable.Empty <MessageProperty>());

            AS4Message m = AS4Message.Create(user);

            m.AddAttachment(
                new Attachment(
                    id: attachmentId,
                    content: new MemoryStream(Properties.Resources.payload),
                    contentType: "image/jpg"));

            var certRepo = new CertificateRepository(msh.GetConfiguration());

            X509Certificate2 signingCert = certRepo.GetCertificate(X509FindType.FindBySubjectName, "AccessPointA");

            m.Sign(new CalculateSignatureConfig(signingCert));

            X509Certificate2 encryptCert = certRepo.GetCertificate(X509FindType.FindBySubjectName, "AccessPointB");

            m.Encrypt(new KeyEncryptionConfiguration(encryptCert), DataEncryptionConfiguration.Default);

            return(m);
        }
        private static AS4Message CreateSignedAS4Message(string ebmsMessageId, IConfig configuration)
        {
            var userMessage = new UserMessage(
                ebmsMessageId,
                new CollaborationInfo(
                    agreement: new AgreementReference(
                        value: "http://agreements.europa.org/agreement",
                        pmodeId: "Forward_Push"),
                    service: new Service(
                        value: "Forward_Push_Service",
                        type: "eu:europa:services"),
                    action: "Forward_Push_Action",
                    conversationId: "eu:europe:conversation"));

            AS4Message tobeForwarded = AS4Message.Create(userMessage);

            var certificateRepo = new CertificateRepository(configuration);
            X509Certificate2 signingCertificate =
                certificateRepo.GetCertificate(X509FindType.FindBySubjectName, "AccessPointA");

            tobeForwarded.Sign(new CalculateSignatureConfig(signingCertificate));

            return(tobeForwarded);
        }