【问题标题】:How can a verify my WCF message is signed and encrypted?如何验证我的 WCF 消息是否已签名和加密?
【发布时间】:2013-03-12 16:05:49
【问题描述】:

如何验证我的 WCF 消息是否已签名?我的设置运行正常,但需要能够检查服务器端的签名。这是怎么做到的?我正在使用 MsmqIntegrationBinding,并使用 X509Certificate2 对其进行签名。

var binding = new MsmqIntegrationBinding(MsmqIntegrationSecurityMode.Transport)
            {
                SerializationFormat = MsmqMessageSerializationFormat.Binary,
                Security = new MsmqIntegrationSecurity()
                {
                    Mode = MsmqIntegrationSecurityMode.Transport,
                    Transport = new MsmqTransportSecurity()
                    {
                        MsmqAuthenticationMode = MsmqAuthenticationMode.Certificate,
                        MsmqProtectionLevel = System.Net.Security.ProtectionLevel.Sign
                    }
                }
            };

EndpointAddress address = new EndpointAddress("myaddress");
ChannelFactory<IMyMessage> channelFactory = new ChannelFactory<IMyMessage>(binding, address);

channelFactory.Credentials.ClientCertificate.Certificate = my_x509certificate2;
IMyMessage channel = channelFactory.CreateChannel();

//create message and send using the channel

【问题讨论】:

    标签: wcf msmq x509certificate2


    【解决方案1】:

    用这个注释你的服务或你的操作:

    [OperationContract(ProtectionLevel = ProtectionLevel.EncryptAndSign)]
    

    这基本上会在服务器端强制执行/除非消息经过签名和加密,否则不会调用操作。

    如果您需要更多参考,请查看 MSDN 上的 ProtectionLevel:

    http://msdn.microsoft.com/en-us/library/aa347692.aspx

    【讨论】:

    • 好吧,可能是签名不起作用。我现在收到一个错误“请求消息必须受到保护。这是合约操作所必需的...保护必须由绑定提供('MsmqIntegrationBinding','tempuri.org/')。”
    • 这就是这个注解的作用,它需要在调用操作之前在服务器端进行签名和加密。
    • 所以,现在我必须确定为什么它没有按照我的设置方式发生。
    • 这是确保消息被签名和/或加密但不验证的方法(消息检查是我的解决方案)。
    猜你喜欢
    • 1970-01-01
    • 2010-12-16
    • 1970-01-01
    • 1970-01-01
    • 2016-08-14
    • 2011-07-24
    • 1970-01-01
    • 2013-08-29
    • 1970-01-01
    相关资源
    最近更新 更多