Skip to content

Commit

Permalink
refactor(app): 删除无用fixSsl操作
Browse files Browse the repository at this point in the history
  • Loading branch information
Leon406 committed Dec 25, 2022
1 parent 3ded7d2 commit 491d412
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 44 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import java.time.LocalDate


group = "me.leon.tools"
version = "1.15.1.beta"
version = "1.15.2.beta"

plugins {
application
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/kotlin/me/leon/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ val REG_NUMBER = "\\d+".toRegex()
val REG_CRACK_HEADER = "\\d+ [\\w)]+(-->\\d+ )?".toRegex()

val build: String
get() = "2022/12/06"
get() = "2022/12/25"

val appVersion: String
get() = "1.15.1.beta"
get() = "1.15.2.beta"
35 changes: 1 addition & 34 deletions app/src/main/kotlin/me/leon/ToolsApp.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package me.leon

import java.io.File
import java.security.SecureRandom
import java.security.cert.X509Certificate
import java.util.Locale
import java.util.Properties
import javafx.scene.image.Image
import javax.net.ssl.*
import me.leon.ext.fx.Prefs
import me.leon.view.Home
import tornadofx.*
Expand All @@ -17,12 +14,11 @@ class ToolsApp : App(Home::class, Styles::class) {
}

companion object {
val properties: Properties = Properties()
private val properties: Properties = Properties()
init {
// for text i18n
FX.locale = if (Prefs.language == "zh") Locale.CHINESE else Locale.ENGLISH
initConfig()
fixSsl()
}
val isEnableClassical: Boolean
get() = properties["isEnableClassical"].toString().toBoolean()
Expand Down Expand Up @@ -62,34 +58,5 @@ class ToolsApp : App(Home::class, Styles::class) {

javaClass.getResourceAsStream("/top1000.txt")?.use { it.copyTo(file.outputStream()) }
}

private fun fixSsl() {
val trustManagers =
arrayOf(
object : X509TrustManager {
override fun checkClientTrusted(
chain: Array<out X509Certificate>?,
authType: String?
) {
// nop
}

override fun checkServerTrusted(
chain: Array<out X509Certificate>?,
authType: String?
) {
// nop
}

override fun getAcceptedIssuers(): Array<X509Certificate>? {
return null
}
}
)
val sc = SSLContext.getInstance("TLSv1.2")
sc.init(null, trustManagers, SecureRandom())
HttpsURLConnection.setDefaultSSLSocketFactory(sc.socketFactory)
HttpsURLConnection.setDefaultHostnameVerifier { _, _ -> true }
}
}
}
11 changes: 5 additions & 6 deletions app/src/test/kotlin/me/leon/Ocr.kt
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
package me.leon

import java.io.File
import kotlin.test.*
import me.leon.ext.ocr.BaiduOcr
import me.leon.ext.toBase64
import org.junit.Test
import java.security.SecureRandom
import java.security.cert.X509Certificate
import javax.net.ssl.HttpsURLConnection
import javax.net.ssl.SSLContext
import javax.net.ssl.X509TrustManager
import kotlin.test.*
import me.leon.ext.ocr.BaiduOcr
import me.leon.ext.toBase64
import org.junit.Test

//@Ignore
@Ignore
class Ocr {

@Test
fun urlOcr() {
fixSsl()
val data = "https://wx1.sinaimg.cn/mw2000/7736d59fly1gzpm3yc7m6j20j80ip755.jpg"
assertTrue(BaiduOcr.ocr(data).contains("你们别看我"))

}
private fun fixSsl() {
val trustManagers =
Expand Down
1 change: 0 additions & 1 deletion plugin-apipost/src/test/kotlin/me/leon/plugin/HttpTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import java.io.File
import java.util.Base64
import me.leon.toolsfx.plugin.net.*
import org.junit.Test
import java.security.Security

class HttpTest {

Expand Down

0 comments on commit 491d412

Please sign in to comment.