Использование стороннего веб-сервиса с использованием сертификата хранилища ключей WSDL и pkcs12 при использовании DotNet - PullRequest
0 голосов
/ 13 февраля 2020

Мне нужно использовать сторонний веб-сервис. У меня есть файл WSDL и файл .pkcs12 Keystore и пароль. Используя этот файл WSDL, я добавил веб-ссылку в проект. прочитайте файл Keystore. Создан новый экземпляр класса X509certificate2 и импортирован сертификат после добавления в класс обслуживания. Я пытаюсь вызвать метод в моем сервисе

            service.mymethod(param1)--> (At this line its throwing error stating that ws-security header not found)

, прибегнув к поиску ошибки, которую я нашел StackOverflow ссылка для добавления заголовка безопасности после перехода по этой ссылке здесь полный код

                //reading PCKS12 certificate
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
                var path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Content\\myKeyStoreFile.pkcs12");
                var data = System.IO.File.ReadAllBytes(path);
                //Importing Certificate
                X509Certificate2 certificate = new X509Certificate2();
                certificate.Import(data, "password", X509KeyStorageFlags.DefaultKeySet);
                //adding WS-Security Headers
                UsernameToken token = new UsernameToken("keyname", "password", PasswordOption.SendHashed);
                service.RequestSoapContext.Security.Tokens.Add(token);
                //adding certificate to service
                service.ClientCertificates.Add(certificate);
                //calling proxy class(service method)
                service.methodname(param1);-->(its throwing System.web.service.protocols.soapheaderexception:'nested exception is org.apache.wss4j.common.ext.WSSSecurityException Original Exception was javax.security.auth.callback.unsupportedcallbackexception)

У меня есть java код (реализован в весенней загрузке) для справки. Wss4jSecurityInterceptor securityInterceptor = new Wss4jSecurityInterceptor ();

    //crypto varible contains .pkcs12 file path and password properties
    Crypto crypto = null;
    try {
        crypto = CryptoFactory.getInstance(cryptoPropertyFile);
    }catch(WSSecurityException e) {
        e.printStackTrace();}
    securityInterceptor.setSecurementActions("Encrypt Signature");
    securityInterceptor.setSecurementEncryptionUser(trustedCertKeyAlias);
    securityInterceptor.setSecurementEncryptionCrypto(crypto);
    securityInterceptor.setSecurementEncryptionParts("{Content {http://schemas.xmlsoap.org/soap/envelope/}Body");
    securityInterceptor.setSecurementUsername(privateKeyAlias);
    securityInterceptor.setSecurementPassword(privateKeyPassword);
    securityInterceptor.setSecurementSignatureCrypto(crypto);
securityInterceptor.setSecurementSignatureKeyIdentifier("DirectReference");
    securityInterceptor.setSecurementSignatureUser(privateKeyAlias);
    securityInterceptor.setSecurementSignatureParts("{Content}{http://schemas.xmlsoap.org/soap/envelope/}Body");        
    securityInterceptor.setValidationActions("Encrypt");
    securityInterceptor.setValidationDecryptionCrypto(crypto);
    KeyStoreCallbackHandler keyStoreCallbackHandler = new KeyStoreCallbackHandler();
    keyStoreCallbackHandler.setPrivateKeyPassword(privateKeyPassword);
securityInterceptor.setValidationCallbackHandler(keyStoreCallbackHandler);
    LogHttpHeaderClientInterceptor logHttpHeaderClientInterceptor = new LogHttpHeaderClientInterceptor();
    ClientInterceptor[] interceptors = {securityInterceptor, logHttpHeaderClientInterceptor};
    template.setInterceptors(interceptors);

Может кто-нибудь, пожалуйста, дайте мне знать, как добавить перехватчики в do tnet. Я провел некоторое исследование, но не смог найти никакого решения. Есть ли что-то, что смазывает Wss4jSecurityInterceptor в do tnet.

...