add workaround for ssl errors
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
f9029bf1c3
commit
36acf1a00a
|
@ -0,0 +1,4 @@
|
|||
FROM openjdk:11
|
||||
ARG JAR_FILE=build/libs/*.jar
|
||||
COPY ${JAR_FILE} thecitadelofricks.jar
|
||||
ENTRYPOINT ["java","-jar","/thecitadelofricks.jar"]
|
|
@ -6,7 +6,7 @@ plugins {
|
|||
}
|
||||
|
||||
group 'org.mosad'
|
||||
version '1.2.3'
|
||||
version '1.2.4'
|
||||
|
||||
repositories {
|
||||
jcenter()
|
||||
|
|
|
@ -48,7 +48,7 @@ class APIController {
|
|||
|
||||
companion object {
|
||||
const val apiVersion = "1.2.0"
|
||||
const val softwareVersion = "1.2.3"
|
||||
const val softwareVersion = "1.2.4"
|
||||
val startTime = System.currentTimeMillis() / 1000
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,13 @@ import org.jsoup.Jsoup
|
|||
import org.mosad.thecitadelofricks.Course
|
||||
import org.slf4j.LoggerFactory
|
||||
import java.net.SocketTimeoutException
|
||||
import java.security.KeyManagementException
|
||||
import java.security.cert.CertificateException
|
||||
import java.security.cert.X509Certificate
|
||||
import javax.net.ssl.SSLContext
|
||||
import javax.net.ssl.SSLSocketFactory
|
||||
import javax.net.ssl.TrustManager
|
||||
import javax.net.ssl.X509TrustManager
|
||||
|
||||
class CourseListParser {
|
||||
|
||||
|
@ -39,7 +46,7 @@ class CourseListParser {
|
|||
fun getCourseLinks(courseListURL: String): HashMap<String, Course>? {
|
||||
val courseLinkList = HashMap<String, Course>()
|
||||
try {
|
||||
val courseHTML = Jsoup.connect(courseListURL).get()
|
||||
val courseHTML = Jsoup.connect(courseListURL).sslSocketFactory(socketFactory()).get()
|
||||
|
||||
courseHTML.select("ul.index-group").select("li.Class").select("a[href]").forEachIndexed { _, element ->
|
||||
courseLinkList[element.text()] = Course(
|
||||
|
@ -57,4 +64,34 @@ class CourseListParser {
|
|||
|
||||
return courseLinkList
|
||||
}
|
||||
|
||||
// Hack to ignore ssl errors while reading
|
||||
private fun socketFactory(): SSLSocketFactory {
|
||||
val trustAllCerts = arrayOf<TrustManager>(object : X509TrustManager {
|
||||
@Throws(CertificateException::class)
|
||||
override fun checkClientTrusted(chain: Array<X509Certificate>, authType: String) {
|
||||
}
|
||||
|
||||
@Throws(CertificateException::class)
|
||||
override fun checkServerTrusted(chain: Array<X509Certificate>, authType: String) {
|
||||
}
|
||||
|
||||
override fun getAcceptedIssuers(): Array<X509Certificate> {
|
||||
return arrayOf()
|
||||
}
|
||||
})
|
||||
|
||||
try {
|
||||
val sslContext = SSLContext.getInstance("TLS")
|
||||
sslContext.init(null, trustAllCerts, java.security.SecureRandom())
|
||||
return sslContext.socketFactory
|
||||
} catch (e: Exception) {
|
||||
when (e) {
|
||||
is RuntimeException, is KeyManagementException -> {
|
||||
throw RuntimeException("Failed to create a SSL socket factory", e)
|
||||
}
|
||||
else -> throw e
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -27,6 +27,13 @@ import org.jsoup.nodes.Document
|
|||
import org.mosad.thecitadelofricks.Lesson
|
||||
import org.mosad.thecitadelofricks.TimetableWeek
|
||||
import org.slf4j.LoggerFactory
|
||||
import java.security.KeyManagementException
|
||||
import java.security.cert.CertificateException
|
||||
import java.security.cert.X509Certificate
|
||||
import javax.net.ssl.SSLContext
|
||||
import javax.net.ssl.SSLSocketFactory
|
||||
import javax.net.ssl.TrustManager
|
||||
import javax.net.ssl.X509TrustManager
|
||||
|
||||
class TimetableParser {
|
||||
private var logger: org.slf4j.Logger = LoggerFactory.getLogger(TimetableParser::class.java)
|
||||
|
@ -40,7 +47,7 @@ class TimetableParser {
|
|||
*/
|
||||
fun getTimeTable(timetableURL: String): TimetableWeek {
|
||||
return try {
|
||||
parseTimeTable(Jsoup.connect(timetableURL).get())
|
||||
parseTimeTable(Jsoup.connect(timetableURL).sslSocketFactory(socketFactory()).get())
|
||||
} catch (gex: Exception) {
|
||||
logger.error("general TimetableParser error", gex)
|
||||
TimetableWeek()
|
||||
|
@ -122,7 +129,7 @@ class TimetableParser {
|
|||
*/
|
||||
fun getWeekNumberYear(timetableURL: String): Int {
|
||||
return try {
|
||||
parseWeekNumberYear(Jsoup.connect(timetableURL).get())
|
||||
parseWeekNumberYear(Jsoup.connect(timetableURL).sslSocketFactory(socketFactory()).get())
|
||||
} catch (gex: Exception) {
|
||||
logger.error("general TimetableParser error", gex)
|
||||
0
|
||||
|
@ -181,4 +188,34 @@ class TimetableParser {
|
|||
|
||||
println(" \n")
|
||||
}
|
||||
|
||||
// Hack to ignore ssl errors while reading
|
||||
private fun socketFactory(): SSLSocketFactory {
|
||||
val trustAllCerts = arrayOf<TrustManager>(object : X509TrustManager {
|
||||
@Throws(CertificateException::class)
|
||||
override fun checkClientTrusted(chain: Array<X509Certificate>, authType: String) {
|
||||
}
|
||||
|
||||
@Throws(CertificateException::class)
|
||||
override fun checkServerTrusted(chain: Array<X509Certificate>, authType: String) {
|
||||
}
|
||||
|
||||
override fun getAcceptedIssuers(): Array<X509Certificate> {
|
||||
return arrayOf()
|
||||
}
|
||||
})
|
||||
|
||||
try {
|
||||
val sslContext = SSLContext.getInstance("TLS")
|
||||
sslContext.init(null, trustAllCerts, java.security.SecureRandom())
|
||||
return sslContext.socketFactory
|
||||
} catch (e: Exception) {
|
||||
when (e) {
|
||||
is RuntimeException, is KeyManagementException -> {
|
||||
throw RuntimeException("Failed to create a SSL socket factory", e)
|
||||
}
|
||||
else -> throw e
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue