@@ -18,11 +18,20 @@ import app.utils.RepoHelper
18
18
import app.utils.UiHelper
19
19
import com.beust.jcommander.JCommander
20
20
import com.beust.jcommander.MissingCommandException
21
+ import java.security.GeneralSecurityException
22
+ import javax.net.ssl.TrustManager
23
+ import javax.net.ssl.X509TrustManager
24
+ import java.security.cert.X509Certificate
25
+ import javax.net.ssl.HttpsURLConnection
26
+ import javax.net.ssl.SSLContext
21
27
22
28
fun main (argv : Array <String >) {
23
29
Thread .setDefaultUncaughtExceptionHandler { _, e: Throwable ->
24
30
Logger .error(e, " Uncaught exception" )
25
31
}
32
+ if (BuildConfig .ENV != " production" ) {
33
+ disableSslChecks()
34
+ }
26
35
Main (argv)
27
36
}
28
37
@@ -147,3 +156,26 @@ class Main(argv: Array<String>) {
147
156
jc.usage() // Will show detailed info about usage based on annotations.
148
157
}
149
158
}
159
+
160
+ fun disableSslChecks () {
161
+ // Create a trust manager that does not validate certificate chains.
162
+ val trustAllCerts = arrayOf<TrustManager >(object : X509TrustManager {
163
+ override fun getAcceptedIssuers (): Array <X509Certificate > {
164
+ return arrayOf()
165
+ }
166
+ override fun checkClientTrusted (certs : Array <X509Certificate >,
167
+ authType : String ) {}
168
+ override fun checkServerTrusted (certs : Array <X509Certificate >,
169
+ authType : String ) {}
170
+ })
171
+
172
+ // Install the all-trusting trust manager.
173
+ try {
174
+ val sc = SSLContext .getInstance(" SSL" )
175
+ sc.init (null , trustAllCerts, java.security.SecureRandom ())
176
+ HttpsURLConnection .setDefaultSSLSocketFactory(sc.getSocketFactory())
177
+ } catch (e: GeneralSecurityException ) {}
178
+
179
+ // Skip server name checking.
180
+ HttpsURLConnection .setDefaultHostnameVerifier { _, _ -> true }
181
+ }
0 commit comments