package org.kohsuke.github.extras;

import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.OkUrlFactory;
import org.kohsuke.github.HttpConnector;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 * {@link HttpConnector} for {@link OkHttpClient}.
 *
 * Unlike {@link #DEFAULT}, OkHttp does response caching.
 * Making a conditional request against GitHubAPI and receiving a 304
 * response does not count against the rate limit.
 * See http://developer.github.com/v3/#conditional-requests
 *
 * @author Roberto Tyley
 * @author Kohsuke Kawaguchi
 */
public class OkHttpConnector implements HttpConnector {
    private final OkUrlFactory urlFactory;

    public OkHttpConnector(OkUrlFactory urlFactory) {
        this.urlFactory = urlFactory;
    }

    public HttpURLConnection connect(URL url) throws IOException {
        return urlFactory.open(url);
    }
}

@@ -29,16 +29,59 @@
 xtras;%0A%0A
+import com.squareup.okhttp.ConnectionSpec;%0A
 import c
@@ -154,16 +154,17 @@
 actory;%0A
+%0A
 import o
@@ -221,24 +221,25 @@
 OException;%0A
+%0A
 import java.
@@ -283,16 +283,231 @@
 t.URL;%0A%0A
+import java.security.KeyManagementException;%0Aimport java.security.NoSuchAlgorithmException;%0A%0Aimport java.util.Arrays;%0Aimport java.util.List;%0A%0Aimport javax.net.ssl.SSLContext;%0Aimport javax.net.ssl.SSLSocketFactory;%0A%0A
 /**%0A * %7B
@@ -1022,146 +1022,1009 @@
     
-this.urlFactory = urlFactory;%0A    %7D%0A%0A    public HttpURLConnection connect(URL url) throws IOException %7B%0A        return urlFactory.open(url
+urlFactory.client().setSslSocketFactory(TlsSocketFactory());%0A        urlFactory.client().setConnectionSpecs(TlsConnectionSpecs());%0A        this.urlFactory = urlFactory;%0A    %7D%0A%0A    public HttpURLConnection connect(URL url) throws IOException %7B%0A        return urlFactory.open(url);%0A    %7D%0A%0A    /** Returns TLSv1.2 only SSL Socket Factory. */%0A    private SSLSocketFactory TlsSocketFactory() %7B%0A        SSLContext sc;%0A        try %7B%0A            sc = SSLContext.getInstance(%22TLSv1.2%22);%0A        %7D catch (NoSuchAlgorithmException e) %7B%0A            throw new RuntimeException(e.getMessage(), e);%0A        %7D%0A        try %7B%0A            sc.init(null, null, null);%0A            return sc.getSocketFactory();%0A        %7D catch (KeyManagementException e) %7B%0A            throw new RuntimeException(e.getMessage(), e);%0A        %7D%0A    %7D%0A%0A    /** Returns connection spec with TLS v1.2 in it */%0A    private List%3CConnectionSpec%3E TlsConnectionSpecs() %7B%0A        return Arrays.asList(ConnectionSpec.MODERN_TLS, ConnectionSpec.CLEARTEXT
 );%0A 

Enforce use of TLSv1.2 to match current Github and Github Enterprise TLS support.