Skip to content
This repository has been archived by the owner on Jun 9, 2021. It is now read-only.

https proxy settings #211

Open
sintasy opened this issue Apr 5, 2017 · 10 comments
Open

https proxy settings #211

sintasy opened this issue Apr 5, 2017 · 10 comments
Labels

Comments

@sintasy
Copy link

sintasy commented Apr 5, 2017

Hi! I try use notification to https webhook trought proxy, but getting exception. Question is it possible?

  • Plugin version 2.61
  • Atlassian Bitbucket v4.9.1
  • my coniguration looks like this:
    [{"headers":[],"method":"POST","name":"Notification","postContent":"{\"text\": \":peka:\"}","projectKey":"TST","proxyPort":8080,"proxyServer":"myproxy","repositorySlug":"tst-repo","triggerIfCanMerge":"ALWAYS","triggerIgnoreStateList":[],"triggers":["COMMENTED","OPENED"],"url":"https://mywebhook","uuid":"2fe61472-0fcd-4951-bfe2-74a4b9150591","postContentEncoding":"NONE"}]
  • Exception in logs:
2017-04-05 13:43:23,272 ERROR [threadpool:thread-6] admin @1N58QFUx823x93965x2 1s0qf29 172.27.84.131 "POST /rest/api/latest/projects/TST/repos/tst-repo/pull-requests/2/comments HTTP/1.1" se.bjurr.prnfb.http.UrlInvoker
org.apache.http.conn.UnsupportedSchemeException: http protocol is not supported
        at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:108) ~[httpclient-4.5.1.jar:4.5.1]
        at org.apache.http.impl.conn.BasicHttpClientConnectionManager.connect(BasicHttpClientConnectionManager.java:338) ~[httpclient-4.5.1.jar:4.5.1]
        at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:388) ~[httpclient-4.5.1.jar:4.5.1]
        at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236) ~[httpclient-4.5.1.jar:4.5.1]
        at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184) ~[httpclient-4.5.1.jar:4.5.1]
        at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88) ~[httpclient-4.5.1.jar:4.5.1]
        at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110) ~[httpclient-4.5.1.jar:4.5.1]
        at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184) ~[httpclient-4.5.1.jar:4.5.1]
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) ~[httpclient-4.5.1.jar:4.5.1]
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107) ~[httpclient-4.5.1.jar:4.5.1]
        at se.bjurr.prnfb.http.UrlInvoker.doInvoke(UrlInvoker.java:352) [plugin.3143781675544002157.pull-request-notifier-for-bitbucket-2.61_1491330699000.jar:na]
        at se.bjurr.prnfb.http.UrlInvoker.invoke(UrlInvoker.java:164) [plugin.3143781675544002157.pull-request-notifier-for-bitbucket-2.61_1491330699000.jar:na]
        at se.bjurr.prnfb.listener.PrnfbPullRequestEventListener$1.invoke(PrnfbPullRequestEventListener.java:88) [plugin.3143781675544002157.pull-request-notifier-for-bitbucket-2.61_1491330699000.jar:na]
        at se.bjurr.prnfb.listener.PrnfbPullRequestEventListener.notify(PrnfbPullRequestEventListener.java:261) [plugin.3143781675544002157.pull-request-notifier-for-bitbucket-2.61_1491330699000.jar:na]
        at se.bjurr.prnfb.listener.PrnfbPullRequestEventListener.handleEvent(PrnfbPullRequestEventListener.java:113) [plugin.3143781675544002157.pull-request-notifier-for-bitbucket-2.61_1491330699000.jar:na]
        at se.bjurr.prnfb.listener.PrnfbPullRequestEventListener.access$000(PrnfbPullRequestEventListener.java:54) [plugin.3143781675544002157.pull-request-notifier-for-bitbucket-2.61_1491330699000.jar:na]
        at se.bjurr.prnfb.listener.PrnfbPullRequestEventListener$2.run(PrnfbPullRequestEventListener.java:129) [plugin.3143781675544002157.pull-request-notifier-for-bitbucket-2.61_1491330699000.jar:na]
        at com.atlassian.stash.internal.concurrent.StateTransferringExecutor$StateTransferringRunnable.run(StateTransferringExecutor.java:70) [bitbucket-platform-4.9.1.jar:na]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_102]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_102]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_102]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [na:1.8.0_102]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_102]
        at java.lang.Thread.run(Thread.java:745) [na:1.8.0_102]
        ... 1 frame trimmed
@tomasbjerre
Copy link
Owner

I released 2.62. You can select HTTPS for proxy schema. Perhaps that solves it.

@tomasbjerre
Copy link
Owner

@sintasy did you try this? Can I close it?

@sintasy
Copy link
Author

sintasy commented Apr 7, 2017

Soo.. Thanks for your response. Now I have next exception:

2017-04-07 10:46:38,088 ERROR [threadpool:thread-6] admin @1QXET93x646x1575978x4 jdwbnw 172.27.84.131 "POST /rest/api/latest/projects/TST/repos/tst-repo/pull-requests/4/comments HTTP/1.1" se.bjurr.prnfb.http.UrlInvoker
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
        at sun.security.ssl.InputRecord.handleUnknownRecord(InputRecord.java:710) ~[na:1.8.0_102]
        at sun.security.ssl.InputRecord.read(InputRecord.java:527) ~[na:1.8.0_102]
        at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:973) ~[na:1.8.0_102]
        at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375) ~[na:1.8.0_102]
        at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403) ~[na:1.8.0_102]
        at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387) ~[na:1.8.0_102]
        at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:394) ~[httpclient-4.5.1.jar:4.5.1]
        at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:353) ~[httpclient-4.5.1.jar:4.5.1]
        at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:134) ~[httpclient-4.5.1.jar:4.5.1]
        at org.apache.http.impl.conn.BasicHttpClientConnectionManager.connect(BasicHttpClientConnectionManager.java:338) ~[httpclient-4.5.1.jar:4.5.1]
        at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:388) ~[httpclient-4.5.1.jar:4.5.1]
        at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236) ~[httpclient-4.5.1.jar:4.5.1]
        at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184) ~[httpclient-4.5.1.jar:4.5.1]
        at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88) ~[httpclient-4.5.1.jar:4.5.1]
        at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110) ~[httpclient-4.5.1.jar:4.5.1]
        at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184) ~[httpclient-4.5.1.jar:4.5.1]
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) ~[httpclient-4.5.1.jar:4.5.1]
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107) ~[httpclient-4.5.1.jar:4.5.1]
        at se.bjurr.prnfb.http.UrlInvoker.doInvoke(UrlInvoker.java:363) [plugin.9033394431513391254.pull-request-notifier-for-bitbucket-2.62_1491458446000.jar:na]
        at se.bjurr.prnfb.http.UrlInvoker.invoke(UrlInvoker.java:169) [plugin.9033394431513391254.pull-request-notifier-for-bitbucket-2.62_1491458446000.jar:na]
        at se.bjurr.prnfb.listener.PrnfbPullRequestEventListener$1.invoke(PrnfbPullRequestEventListener.java:88) [plugin.9033394431513391254.pull-request-notifier-for-bitbucket-2.62_1491458446000.jar:na]
        at se.bjurr.prnfb.listener.PrnfbPullRequestEventListener.notify(PrnfbPullRequestEventListener.java:261) [plugin.9033394431513391254.pull-request-notifier-for-bitbucket-2.62_1491458446000.jar:na]
        at se.bjurr.prnfb.listener.PrnfbPullRequestEventListener.handleEvent(PrnfbPullRequestEventListener.java:113) [plugin.9033394431513391254.pull-request-notifier-for-bitbucket-2.62_1491458446000.jar:na]
        at se.bjurr.prnfb.listener.PrnfbPullRequestEventListener.access$000(PrnfbPullRequestEventListener.java:54) [plugin.9033394431513391254.pull-request-notifier-for-bitbucket-2.62_1491458446000.jar:na]
        at se.bjurr.prnfb.listener.PrnfbPullRequestEventListener$2.run(PrnfbPullRequestEventListener.java:129) [plugin.9033394431513391254.pull-request-notifier-for-bitbucket-2.62_1491458446000.jar:na]
        at com.atlassian.stash.internal.concurrent.StateTransferringExecutor$StateTransferringRunnable.run(StateTransferringExecutor.java:70) [bitbucket-platform-4.9.1.jar:na]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_102]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_102]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_102]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [na:1.8.0_102]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_102]
        at java.lang.Thread.run(Thread.java:745) [na:1.8.0_102]
        ... 1 frame trimmed

I've try to find root cause of this in my proxy, but so far unsuccessfully.

@tomasbjerre
Copy link
Owner

@sintasy
Copy link
Author

sintasy commented Apr 12, 2017

As I understand in my case http proxy used as https. Bitbucket java_opts contains:
-Dhttp.proxyHost=myproxyip -Dhttp.proxyPort=8080 -Dhttps.proxyHost=myproxyip -Dhttps.proxyPort=8080
I've try run next code under scriptunner console from Bitbucket:

import org.apache.http.*
import javax.net.ssl.*
import java.security.cert.X509Certificate;
import java.security.SecureRandom;
import org.apache.log4j.Logger;
import org.apache.log4j.Level;
log.setLevel(Level.DEBUG)

SSLContext sslContext = SSLContext.getInstance("SSL");

TrustManager[] t = new X509TrustManager() {
    public X509Certificate[] getAcceptedIssuers() {
        return null;
    }

    public void checkClientTrusted(X509Certificate[] certs,
            String authType) {
    }

    public void checkServerTrusted(X509Certificate[] certs,
            String authType) {
    }
}
sslContext.init(null, t , new SecureRandom());

HttpsURLConnection.setDefaultSSLSocketFactory(
        sslContext.getSocketFactory());

HttpsURLConnection
        .setDefaultHostnameVerifier(new HostnameVerifier() {
            public boolean verify(String arg0, SSLSession arg1) {
                return true;
            }
        });

URL url = new URL("https://mytargeturl");
URLConnection conn = url.openConnection();
conn.setRequestMethod("POST")
conn.doOutput = true
OutputStreamWriter writer = new OutputStreamWriter(conn.outputStream)
writer.write("payload")
writer.flush()
writer.close()
conn.getInputStream()

And server send request through proxy without errors(I'am sure because in the network level server have access only to proxy).
I try to resolve this in se.bjurr.prnfb.http.UrlInvoker, but currently connection way is so difficult and I could't found how to change current conntection method to something like in my example.

@tomasbjerre
Copy link
Owner

Looks like you start the server with proxy properties and then invoke "mytargeturl". And that invocation will be through the proxy from the properties. Correct?

If you avoid specifying a proxy in the plugin, and instead start the server with the properties, perhaps that will give the same results?

@sintasy
Copy link
Author

sintasy commented Apr 13, 2017

Nope, it's first thing that I've try. Just getting timeout. As I understand httpclient doesn't use proxy settings from java_opts or system environment.

2017-04-13 08:58:00,155 ERROR [threadpool:thread-4] admin @1QXET93x537x9502035x2 1ogx2rd 172.27.84.131 "POST /rest/api/latest/projects/TST/repos/tst-repo/pull-requests/3/comments HTTP/1.1" se.bjurr.prnfb.http.UrlInvoker
org.apache.http.conn.ConnectTimeoutException: Connect to mytargeturl:443 [mytargeturl/mytargetip] failed: Connection timed out
        at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:149) ~[httpclient-4.5.1.jar:4.5.1]
        at org.apache.http.impl.conn.BasicHttpClientConnectionManager.connect(BasicHttpClientConnectionManager.java:338) ~[httpclient-4.5.1.jar:4.5.1]
        at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380) ~[httpclient-4.5.1.jar:4.5.1]
        at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236) ~[httpclient-4.5.1.jar:4.5.1]
        at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184) ~[httpclient-4.5.1.jar:4.5.1]
        at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88) ~[httpclient-4.5.1.jar:4.5.1]
        at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110) ~[httpclient-4.5.1.jar:4.5.1]
        at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184) ~[httpclient-4.5.1.jar:4.5.1]
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) ~[httpclient-4.5.1.jar:4.5.1]
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107) ~[httpclient-4.5.1.jar:4.5.1]
        at se.bjurr.prnfb.http.UrlInvoker.doInvoke(UrlInvoker.java:363) [plugin.9033394431513391254.pull-request-notifier-for-bitbucket-2.62_1491458446000.jar:na]
        at se.bjurr.prnfb.http.UrlInvoker.invoke(UrlInvoker.java:169) [plugin.9033394431513391254.pull-request-notifier-for-bitbucket-2.62_1491458446000.jar:na]
        at se.bjurr.prnfb.listener.PrnfbPullRequestEventListener$1.invoke(PrnfbPullRequestEventListener.java:88) [plugin.9033394431513391254.pull-request-notifier-for-bitbucket-2.62_1491458446000.jar:na]
        at se.bjurr.prnfb.listener.PrnfbPullRequestEventListener.notify(PrnfbPullRequestEventListener.java:261) [plugin.9033394431513391254.pull-request-notifier-for-bitbucket-2.62_1491458446000.jar:na]
        at se.bjurr.prnfb.listener.PrnfbPullRequestEventListener.handleEvent(PrnfbPullRequestEventListener.java:113) [plugin.9033394431513391254.pull-request-notifier-for-bitbucket-2.62_1491458446000.jar:na]
        at se.bjurr.prnfb.listener.PrnfbPullRequestEventListener.access$000(PrnfbPullRequestEventListener.java:54) [plugin.9033394431513391254.pull-request-notifier-for-bitbucket-2.62_1491458446000.jar:na]
        at se.bjurr.prnfb.listener.PrnfbPullRequestEventListener$2.run(PrnfbPullRequestEventListener.java:129) [plugin.9033394431513391254.pull-request-notifier-for-bitbucket-2.62_1491458446000.jar:na]
        at com.atlassian.stash.internal.concurrent.StateTransferringExecutor$StateTransferringRunnable.run(StateTransferringExecutor.java:70) [bitbucket-platform-4.9.1.jar:na]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_102]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_102]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_102]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [na:1.8.0_102]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_102]
        at java.lang.Thread.run(Thread.java:745) [na:1.8.0_102]
        ... 1 frame trimmed
Caused by: java.net.ConnectException: Connection timed out
        at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.8.0_102]
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[na:1.8.0_102]
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0_102]
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_102]
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_102]
        at java.net.Socket.connect(Socket.java:589) ~[na:1.8.0_102]
        at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:337) ~[httpclient-4.5.1.jar:4.5.1]
        at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:134) ~[httpclient-4.5.1.jar:4.5.1]
        ... 24 common frames omitted

You can reproduce this case if run Bitbucket with java_opts (-Dhttp/s.proxyHost and -Dhttp/s.proxyPort) setting to any non-existent proxy server that must return a timeout. After that try to send any request through Pull request notifications plugin. This request will be successfully delivered, without timeout. It will mean you don't use proxy settings from java_opts.

@rounakpr
Copy link

Hello,

We are also facing the same problem with Unrecognized SSL message error 👎
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
at sun.security.ssl.InputRecord.handleUnknownRecord(InputRecord.java:710)
at sun.security.ssl.InputRecord.read(InputRecord.java:527)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:973)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:394)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:353)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:134)
at org.apache.http.impl.conn.BasicHttpClientConnectionManager.connect(BasicHttpClientConnectionManager.java:338)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:388)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)

Can you please help how to solve this, we have installed v3.15 of pull-request notifier plugin over bitbucket v5.1.5.

@snoopotic
Copy link

Hi. We have the same issue.
We only have one http proxy also proxying destination URLs running via https.

It seems the used httpclient-4.5.1 does not like calling https-URLs via an http-proxy. But it should :)

@Kamforka
Copy link

It's definitely a bug, if I change the endpoint url from https:// to http:// and also change the proxy scheme to http:// it works, otherwise it fails.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants