Es mi primera pregunta en la web. Espero que tenga sentido.Firma de mensajes SOAP utilizando el certificado X.509 del servicio WCF al servicio web Java
He visto varios blogs relacionados con este tema en la Web, y he intentado algunas de las ideas presentadas en ellos sin éxito. Aquí está mi situación:
Tengo una aplicación web llamando a un servicio web WCF que luego llama a un servicio web Java. Todos están en diferentes servidores. La llamada entre el servicio web de WCF al servicio web de Java no supera el https, ya que el certificado será suficiente para identificar al que llama (por lo tanto, la seguridad del mensaje).
- servicio web Java (cuadro negro)
El servicio web Java requiere que recibió un mensaje firmado y trabaja según abajo:
Antes de cada solicitud se procesa un manejador intercepta todos los mensajes entrantes y realiza las siguientes reglas de validación:
1. ¿El mensaje contiene un encabezado de seguridad
2. El mensaje contiene el ID de encabezado de seguridad correcto
3. ¿Es el mensaje ha firmado correctamente
4. ¿El mensaje contiene un certificado X.509 KeyInfo
5. ¿Es el certificado emitido por una CA de confianza - configuración basada
6. ¿El certificado válido (no caducado, revocado)
7. ¿El certificado contiene la política correcta OID
Una vez que se hayan confirmado todos estos pasos, el mensaje puede procesarse; si falla algún paso, se devolverá una excepción de mensaje de jabón.
El encabezado de seguridad SOAP debe validar contra xxx ... w3.org/TR/SOAP-dsig/ especificación de firma digital.
La descripción más completa se puede encontrar aquí xxx ... ibm.com/developerworks/webservices/library/ws-security.html este artículo de IBM enumera los detalles de cada encabezado de WS-Security, además de un mensaje SOAP firmado de muestra ha sido proporcionado.
Al firmar el mensaje SOAP, también debe agregar el certificado x.509 en el mensaje KeyInfo, que es necesario para la validación del certificado.
Solicitud SOAP debería desea:
<?xml version="1.0" encoding="UTF-8"?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Header>
<ds:Signature xmlns:ds="xxx...w3.org/2000/09/xmldsig#" Id="Signature001">
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm="xxx...w3.org/TR/2001/REC-xml-c14n-20010315"/>
<ds:SignatureMethod Algorithm="xxx...w3.org/2000/09/xmldsig#rsa-sha1"/>
<ds:Reference URI="">
<ds:Transforms>
<ds:Transform Algorithm="xxx...w3.org/2000/09/xmldsig#enveloped-signature"/>
</ds:Transforms>
<ds:DigestMethod Algorithm="xxx...w3.org/2000/09/xmldsig#sha1"/>
<ds:DigestValue>soe1PnaGXVGrsauC61JSHD+uqGw=</ds:DigestValue>
</ds:Reference>
<ds:Reference URI="#KeyInfo001">
<ds:DigestMethod Algorithm="xxx...w3.org/2000/09/xmldsig#sha1"/>
<ds:DigestValue>Y9SRPQ9TcDu+GazO3LFwodEdhaA=</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue>jBX/8XkY2aCte7qgXEp1sbNWmQcK/90iVL58sAvwYAEcBABGzOk2agxR0HvWrNa6ixkocAQ205lggwOxnxZJvoVozVYAAjcLtayPBOUYrnSEBFrwKWP/vxgvUDRIdXeIuw5GLY87NrTQMm1Ehf/HvMX9hTBJn4Nm8RdDiUmPcIo=</ds:SignatureValue>
<ds:KeyInfo Id="KeyInfo001">
<ds:X509Data>
<ds:X509Certificate>MIIEbZCCA1WgAwIBAgIES1XpMjANBgkqhkiG9w0BAQUFADBYMRUwEwYKCZImiZPyLGQBGRYFbG9jYWwxFzAVBgoJkiaJk/IsZAEZFgdlbnRydXN0MRIwEAYDVQQDEwllbnRydXN0U00xEjAQBgNVBAMTCWVudHJ1c3RDQTAeFw0xMDA0MjIxMDQ4MDBaFw0xMzA0MjIxMTE4MDBaMGoxFTATBgoJkiaJk/IsZAEZFgVsb2NhbDEXMBUGCgmSJomT8ixkARkWB2VudHJ1c3QxEjAQBgNVBAMTCWVudHJ1c3RTTTESMBAGA1UEAxMJZW50cnVzdENBMRAwDgYDVQQDEwdSYnMgUmJzMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDMf88L2JjLPG1hNmTA/KBiC53WVwS2WU9Jh3lC1Rob6RMzOojomZ/dNrvSRB6nzWeXJpZXwik4XFrsAq24By2SZpLTO4p8Vcq71mTAfDu33cnO49Au2pw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Id="ABC">
<ns2:createUser xmlns:ns2="http://webservice.rbs.emea.ps.entrust.com/" xmlns:ns3="http://webservice.rbs.emea.ps.entrust.com/types/CertificateException" xmlns:ns4="http://webservice.rbs.emea.ps.entrust.com/types/UserException">
<userID>0061020051</userID>
</ns2:createUser>
</S:Body>
</S:Envelope>
- servicio web WCF
Tengo un certificado de servidor (formato p7b de una CA de confianza) que he instalado en mi WCF Web la estación de trabajo de servicio (dev) está utilizando el complemento de certificado mmc (en este momento cert está en los editores de confianza). No creo que necesite otro certificado en el servidor Java, ya que la respuesta debe ser clara (ni firmada ni encriptada). Todavía estoy un poco confundido con este certificado, y con los certificados en general, ya que parece contener solo una clave pública.
Aquí está la aplicación.config de mi proyecto de prueba:
<client>
<endpoint address="http://entrust-user-certification-uat.fm.rbsgrp.net/rbs/WebAS"
behaviorConfiguration="endpointCredentialsBehavior" binding="wsHttpBinding"
bindingConfiguration="WebAsServicePortTypeBinding" contract="IWebAsServicePortType"
name="WebAsServicePortType">
<!--<identity>
<dns value="entrust-user-certification-uat.fm.rbsgrp.net" />
</identity>-->
</endpoint>
</client>
<bindings>
<wsHttpBinding>
<binding name="WebAsServicePortTypeBinding" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="Message">
<message clientCredentialType="Certificate" negotiateServiceCredential="false"
establishSecurityContext="false" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="endpointCredentialsBehavior">
<clientCredentials>
<clientCertificate findValue="entrust-user-certification-uat.fm.rbsgrp.net"
storeLocation="LocalMachine" storeName="TrustedPublisher"
x509FindType="FindBySubjectName"></clientCertificate>
<serviceCertificate>
<!--
Setting the certificateValidationMode to PeerOrChainTrust means that if the certificate
is in the user's Trusted People store, then it will be trusted without performing a
validation of the certificate's issuer chain. This setting is used here for convenience so that the
sample can be run without having to have certificates issued by a certificate authority (CA).
This setting is less secure than the default, ChainTrust. The security implications of this
setting should be carefully considered before using PeerOrChainTrust in production code.
-->
<authentication certificateValidationMode="None" revocationMode="NoCheck" trustedStoreLocation="LocalMachine"/>
</serviceCertificate>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
Cuando me encontré con una prueba sencilla:
WebAS entrustService = new WebAS();
ActivationCodes certCodes = entrustService.createUser ("testNomad");
Tengo el error:
fallidos: System.Web.Services.Protocols.SoapException: javax.xml.soap.SOAPException: Ningún elemento de la firma que se encuentra en el mensaje de jabón
Cómo podría ¿Forzo el proceso de firma de cada mensaje? Estaba pensando que podría hacerlo a través de la configuración de WCF con bastante facilidad. ¡Cualquier ayuda sería muy apreciada!
Hola Nomadefv, Cómo hacer que, en el IClientMessageInspector/BeforeSendReques inyectar su cadena XML devuelto en la solicitud? AJR –
Lo sentimos. Un poco fuera de las últimas dos semanas. Puede intentar: – Nomadefv
'public object BeforeSendRequest (ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel) '{// ... obtener la var diferente de configuración de configuración segura ' // Cargar el certificado del almacén de certificados. 'X509Certificate2 cert = GetCertificateBySubject (certificateSubjectName, certificateStoreName, certificateStoreLocation); '// Firmar la solicitud ' string signedSoapMessage = SignRequest (request.ToString(), cert, signatureId, keyInfoRefId, bodyId); – Nomadefv