cloudsoft / winrm4j

Apache License 2.0
94 stars 53 forks source link

winrm4j https connect failed #167

Closed ahaudeng closed 1 year ago

ahaudeng commented 1 year ago

I am use winrm4j 0.12.3, try to use https connect to remote windows and exec a command. code : WinRmTool.Builder builder = WinRmTool.Builder.builder("windows serverip", userName, password); WinRmClientContext context = WinRmClientContext.newInstance(); builder.setAuthenticationScheme(AuthSchemes.NTLM); builder.port(5986); builder.useHttps(true); builder.disableCertificateChecks(true); builder.context(context); WinRmTool tool = builder.build(); tool.executePs(commands);

when i just only use winrm4j for test, it run ok. But when i add winrm4j as part in the project, made an error.

error: 16:11:40.178 [I/O dispatcher 1] DEBUG org.apache.http.headers - http-outgoing-0 >> Host: 10.12.1.175:5986 16:11:40.178 [I/O dispatcher 1] DEBUG org.apache.http.headers - http-outgoing-0 >> Connection: Keep-Alive 16:11:40.182 [I/O dispatcher 1] DEBUG org.apache.http.impl.nio.conn.ManagedNHttpClientConnectionImpl - http-outgoing-0 10.14.1.123:63751<->10.12.1.175:5986[ACTIVE][rw:][ACTIVE][rw][NEED_UNWRAP][0][0][251]: Event set [w] 16:11:40.224 [I/O dispatcher 1] DEBUG org.apache.http.impl.nio.client.InternalIODispatch - http-outgoing-0 [ACTIVE] Exception javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at sun.security.ssl.Alert.createSSLException(Alert.java:131) at sun.security.ssl.TransportContext.fatal(TransportContext.java:370) at sun.security.ssl.TransportContext.fatal(TransportContext.java:313) at sun.security.ssl.TransportContext.fatal(TransportContext.java:308) at sun.security.ssl.CertificateMessage$T12CertificateConsumer.checkServerCerts(CertificateMessage.java:652) at sun.security.ssl.CertificateMessage$T12CertificateConsumer.onCertificate(CertificateMessage.java:471) at sun.security.ssl.CertificateMessage$T12CertificateConsumer.consume(CertificateMessage.java:367) at sun.security.ssl.SSLHandshake.consume(SSLHandshake.java:376) at sun.security.ssl.HandshakeContext.dispatch(HandshakeContext.java:479) at sun.security.ssl.SSLEngineImpl$DelegatedTask$DelegatedAction.run(SSLEngineImpl.java:990) at sun.security.ssl.SSLEngineImpl$DelegatedTask$DelegatedAction.run(SSLEngineImpl.java:977) at java.security.AccessController.doPrivileged(Native Method) at sun.security.ssl.SSLEngineImpl$DelegatedTask.run(SSLEngineImpl.java:924) at org.apache.http.nio.reactor.ssl.SSLIOSession.doRunTask(SSLIOSession.java:288) at org.apache.http.nio.reactor.ssl.SSLIOSession.doHandshake(SSLIOSession.java:356) at org.apache.http.nio.reactor.ssl.SSLIOSession.isAppInputReady(SSLIOSession.java:547) at org.apache.http.impl.nio.reactor.AbstractIODispatch.inputReady(AbstractIODispatch.java:120) at org.apache.http.impl.nio.reactor.BaseIOReactor.readable(BaseIOReactor.java:162) at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:337) at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:315) at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:276) at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:104) at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor

I set disableCertificateChecks(true), but it seems to check the cert also. anyone an give help? thanks a lot.

ahaudeng commented 1 year ago

The issue is solved. It not run correct with httpasyncclient:4.1.5. Use httpasyncclient:4.1.4 instead then it run success.