Двоичный токен безопасности WCF до подписи - PullRequest
0 голосов
/ 28 августа 2018

Мне дали WSDL для доступа к веб-службе SOAP 1.1. WSDL только один раз ссылается на двоичный токен безопасности. Для ожидаемого запроса требуется второй двоичный токен безопасности перед тегом подписи, но после тега ключа шифрования. Мне нужно как-то сказать WCF добавить этот дополнительный тег токена безопасности, которого нет в схеме WSDL. Странная вещь, которую я заметил в связи с моим стремлением решить эту проблему, заключается в том, что SOAPUI добавляет токен, хотя его нет в схеме WSDL. Следующая информация имеет отношение к пониманию проблемы:

Это файл конфигурации:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>  
<system.serviceModel>
    <bindings>
      <customBinding>
        <binding name="customWebRealmBinding">
          <security messageProtectionOrder="SignBeforeEncrypt" defaultAlgorithmSuite="TripleDesRsa15"     
                    authenticationMode="MutualCertificateDuplex" securityHeaderLayout="LaxTimestampLast"
                    includeTimestamp="true"
                    allowSerializedSigningTokenOnReply="true" requireDerivedKeys="false" />
          <textMessageEncoding messageVersion="Soap11WSAddressingAugust2004"></textMessageEncoding>
          <httpsTransport authenticationScheme="Basic" realm="weblogic" maxReceivedMessageSize="2147483647" 
                          requireClientCertificate="true" />
        </binding>
      </customBinding>
    </bindings>
    <client>
      <endpoint address="https://XXX/XXX/XXX/XXXService?WSDL"
        binding="customBinding" bindingConfiguration="customWebRealmBinding"
        contract="XXXService.XXXServiceType" name="XXXerviceTypeSoapPort" behaviorConfiguration="XXXBehavior">
      <identity>
        <dns value="XXXXXXX"/>
        <certificateReference findValue="XXXXX, XXXXXX, XXX, XXX XXX. XXXX, XXXX" 
          storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectDistinguishedName"/>
      </identity>
      </endpoint>
    </client>
    <behaviors>
      <endpointBehaviors>
        <behavior name="XXXBehavior">
          <callbackDebug includeExceptionDetailInFaults="true" />
          <clientCredentials>
            <clientCertificate storeLocation="LocalMachine" storeName="My" 
                              x509FindType="FindBySubjectDistinguishedName"
                              findValue="XXXXXXXXXX, XXXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX" />
            <serviceCertificate>
              <defaultCertificate storeLocation="LocalMachine" storeName="My" 
                                  x509FindType="FindBySubjectDistinguishedName" 
                                  findValue="XXXX, XXXXX, XXXX, XXXX, XXXX. XXXXX, XXXXX" />
            </serviceCertificate>
          </clientCredentials>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <services>
      <service name="NLog.LogReceiverService.LogReceiverOneWayForwardingService">
        <endpoint address="https://XXXXService?WSDL" 
         name="XXXServiceEndpoint" binding="customBinding" contract="XXXService.XXXServiceType"/>
        <host>
          <baseAddresses>
            <add baseAddress="https://XXX/XXX/XXXService?WSDL"/>
          </baseAddresses>
        </host>
      </service>
    </services>
  </system.serviceModel>

  <system.diagnostics>
    <trace autoflush="true" />
    <sources>
      <source name="System.Net" maxdatasize="1048576" tracemode="protocolonly">
        <listeners>
          <add name="MyTraceFile"/>
          <add name="MyConsole"/>
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add
        name="MyTraceFile"
        type="System.Diagnostics.TextWriterTraceListener"
        initializeData="System.Net.trace.log" />
      <add name="MyConsole" type="System.Diagnostics.ConsoleTraceListener" />
    </sharedListeners>

    <switches>
      <add name="System.Net" value="Verbose" />
    </switches>

  </system.diagnostics>

</configuration>

Это сообщение WCF, которое создается, когда я делаю это:

<?xml version="1.0"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:a="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
  <s:Header>
    <a:Action s:mustUnderstand="1" u:Id="_3"/>
    <a:MessageID u:Id="_4">urn:uuid:</a:MessageID>
    <a:ReplyTo u:Id="_5">
      <a:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:Address>
    </a:ReplyTo>
    <a:To s:mustUnderstand="1" u:Id="_6">https:XXXXXXXXX?WSDL</a:To>
    <o:Security xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" s:mustUnderstand="1">
      <u:Timestamp u:Id="uuid-XXXX">
        <u:Created>2018-08-28T13:32:45.912Z</u:Created>
        <u:Expires>2018-08-28T13:37:45.912Z</u:Expires>
      </u:Timestamp>
      <o:BinarySecurityToken u:Id="uuid-4fcc794b-4898-4bd2-b842-1bb0b98b800d-3" ValueType="http://docs.oasis-
        open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3">TOKEN NUMBERS=</o:BinarySecurityToken>
      <e:EncryptedKey xmlns:e="http://www.w3.org/2001/04/xmlenc#" Id="_0">
        <e:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5"/>
        <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
          <o:SecurityTokenReference>
            <o:KeyIdentifier ValueType="http://docs.oasis-open.org/wss/oasis-wss-soap-message-security-
                             1.1#ThumbprintSHA1">agOMixYQcvcrttth/vzpcgfGaRg=</o:KeyIdentifier>
          </o:SecurityTokenReference>
        </KeyInfo>
        <e:CipherData>
          <e:CipherValue>CYPHER NUMBERS AND LETTERS</e:CipherValue>
        </e:CipherData>
        <e:ReferenceList>
          <e:DataReference URI="#_2"/>
        </e:ReferenceList>
      </e:EncryptedKey>
      <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
        <SignedInfo>
          <CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
          <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
          <Reference URI="#_1">
            <Transforms>
              <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
            </Transforms>
            <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
            <DigestValue>VALUES</DigestValue>
          </Reference>
          <Reference URI="#_3">
            <Transforms>
              <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
            </Transforms>
            <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
            <DigestValue>VALUES</DigestValue>
          </Reference>
          <Reference URI="#_4">
            <Transforms>
              <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
            </Transforms>
            <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
            <DigestValue>VALUES</DigestValue>
          </Reference>
          <Reference URI="#_5">
            <Transforms>
              <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
            </Transforms>
            <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
            <DigestValue>VALUES</DigestValue>
          </Reference>
          <Reference URI="#_6">
            <Transforms>
              <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
            </Transforms>
            <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
            <DigestValue>A/VzEXRgimkP4p4nf6geYy68axI=</DigestValue>
          </Reference>
          <Reference URI="#uuid-XXXXXXX">
            <Transforms>
              <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
            </Transforms>
            <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
            <DigestValue>XXXXXXXXXXXXX</DigestValue>
          </Reference>
        </SignedInfo>
        <SignatureValue>XXXXXXXXXXXXXXXXXX</SignatureValue>
        <KeyInfo>
          <o:SecurityTokenReference>
            <o:Reference URI="#uuid-XXXXXXXXXXX"/>
          </o:SecurityTokenReference>
        </KeyInfo>
      </Signature>
    </o:Security>
  </s:Header>
  <s:Body u:Id="_1">
    <e:EncryptedData xmlns:e="http://www.w3.org/2001/04/xmlenc#" Id="_2" 
                     Type="http://www.w3.org/2001/04/xmlenc#Content">
      <e:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc"/>
      <e:CipherData>
        <e:CipherValue>XXXXXXXXXXX</e:CipherValue>
      </e:CipherData>
    </e:EncryptedData>
  </s:Body>
</s:Envelope>

Я хочу, чтобы он выглядел так же, как и выше, но мне нужен еще один двоичный токен безопасности между конечным тегом EncryptedKey и перед началом тега подписи. Программно я на самом деле просто устанавливаю имя пользователя, пароль и значения сертификата и вызываю службу.

Любая помощь будет отличной! Спасибо!

...