diff options
author | Soopyboo32 <49228220+Soopyboo32@users.noreply.github.com> | 2022-09-29 16:31:16 +0800 |
---|---|---|
committer | Soopyboo32 <49228220+Soopyboo32@users.noreply.github.com> | 2022-09-29 16:31:16 +0800 |
commit | b50b90740e873249904cc4ff780aaaa208160010 (patch) | |
tree | dc95b0391a5f0dcd838df55ab6369a7aac1306b8 /src/utils | |
parent | 996d99f533e8dcc8aa4a471097f5d6a93de894f4 (diff) | |
download | SoopyV2-b50b90740e873249904cc4ff780aaaa208160010.tar.gz SoopyV2-b50b90740e873249904cc4ff780aaaa208160010.tar.bz2 SoopyV2-b50b90740e873249904cc4ff780aaaa208160010.zip |
huh
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/certs/ISRGRootX1.cer | bin | 1391 -> 0 bytes | |||
-rw-r--r-- | src/utils/letsEncryptCerts.js | 32 | ||||
-rw-r--r-- | src/utils/networkUtils.js | 188 |
3 files changed, 0 insertions, 220 deletions
diff --git a/src/utils/certs/ISRGRootX1.cer b/src/utils/certs/ISRGRootX1.cer Binary files differdeleted file mode 100644 index 9d2132e..0000000 --- a/src/utils/certs/ISRGRootX1.cer +++ /dev/null diff --git a/src/utils/letsEncryptCerts.js b/src/utils/letsEncryptCerts.js deleted file mode 100644 index 4a639e7..0000000 --- a/src/utils/letsEncryptCerts.js +++ /dev/null @@ -1,32 +0,0 @@ -// Semisol was here -let certificates = [ - "ISRGRootX1.cer" -] // Certificate names -const - JKeyStore = Java.type("java.security.KeyStore"), - JPaths = Java.type("java.nio.file.Paths"), - JSystem = Java.type("java.lang.System"), - JFiles = Java.type("java.nio.file.Files"), - JCertificateFactory = Java.type("java.security.cert.CertificateFactory"), - JString = Java.type("java.lang.String"), - JByteArrayInputStream = Java.type("java.io.ByteArrayInputStream"), - JTrustManagerFactory = Java.type("javax.net.ssl.TrustManagerFactory"), - JSSLContext = Java.type("javax.net.ssl.SSLContext") -let keyStore = JKeyStore.getInstance(JKeyStore.getDefaultType()) -let ksPath = JPaths.get(JSystem.getProperty("java.home"), "lib", "security", "cacerts") -keyStore.load(JFiles.newInputStream(ksPath), new JString("changeit").toCharArray()) -let cf = JCertificateFactory.getInstance("X.509") -for (let i of certificates) { - let pathStr = `${Config.modulesFolder}/SoopyV2/utils/certs/${i}` - let path = JPaths.get(pathStr) - let data = JFiles.readAllBytes(path) - let cert = cf.generateCertificate(new JByteArrayInputStream(data)) - keyStore.setCertificateEntry("dev.semisol.letsencryptsupport:" + i, cert) -} -let tmf = JTrustManagerFactory.getInstance(JTrustManagerFactory.getDefaultAlgorithm()) -tmf.init(keyStore) -let sslContext = JSSLContext.getInstance("TLS") -sslContext.init(null, tmf.getTrustManagers(), null); -JSSLContext.setDefault(sslContext) -let socketFactory = sslContext.getSocketFactory() -export { socketFactory as default }; diff --git a/src/utils/networkUtils.js b/src/utils/networkUtils.js deleted file mode 100644 index 5ac95a4..0000000 --- a/src/utils/networkUtils.js +++ /dev/null @@ -1,188 +0,0 @@ -import socketFactory from "./letsEncryptCerts" - -if (!global.networkUtilsThingSoopyPromise) { - - let jURL = Java.type("java.net.URL") - let jStandardCharsets = Java.type("java.nio.charset.StandardCharsets") - let jCollectors = Java.type("java.util.stream.Collectors") - let jBufferedReader = Java.type("java.io.BufferedReader") - let jInputStreamReader = Java.type("java.io.InputStreamReader") - let jString = Java.type("java.lang.String") - var JHttpsUrlConnection = Java.type('javax.net.ssl.HttpsURLConnection'); - - function getUrlContent(theUrl, { userAgent = "Mozilla/5.0", includeConnection = false, postData = undefined } = {}) { - - if (global.soopyv2loggerthing) { - global.soopyv2loggerthing.logMessage("Loading API: " + theUrl, 4) - } - - // if(theUrl.includes("soopy.dev")){ - // throw new Error("Testing to ensure the module works when my server is down") - // } - // Thread.sleep(1000) //simulating high ping - - let conn = new jURL(theUrl).openConnection() - if (conn instanceof JHttpsUrlConnection) { - conn.setSSLSocketFactory(socketFactory); - } - conn.setRequestProperty("User-Agent", userAgent) - - if (postData) { - conn.setRequestMethod("POST"); - conn.setRequestProperty("Content-Type", "application/json"); - conn.setDoOutput(true); - - let jsonInputString = new jString(JSON.stringify(postData)) - - let os - try { - os = conn.getOutputStream() - input = jsonInputString.getBytes("utf-8"); - os.write(input, 0, input.length); - } finally { - os.close() - } - } - - let stringData - - if (conn.getResponseCode() < 400) { - stringData = new jBufferedReader( - new jInputStreamReader(conn.getInputStream(), jStandardCharsets.UTF_8)) - .lines() - .collect(jCollectors.joining("\n")); - - conn.getInputStream().close() - } else { - stringData = new jBufferedReader( - new jInputStreamReader(conn.getErrorStream(), jStandardCharsets.UTF_8)) - .lines() - .collect(jCollectors.joining("\n")); - - conn.getErrorStream().close() - } - - if (includeConnection) { - return { stringData, connection: conn } - } - - return stringData - } - - function fetch(url, options = { userAgent: "Mozilla/5.0" }) { - let loadedConnection = undefined - let loadedString = undefined - let loadedJSON = undefined - - let ret = { - loadSync() { - if (loadedString === undefined) { - options.includeConnection = true - - try { - let data = getUrlContent(url, options) - loadedString = data.stringData - loadedConnection = data.connection - } catch (e) { - errorData = e - loadedString = null - } - } - - return ret - }, - async load(_ifError = false) { - if (loadedString === undefined) { - options.includeConnection = true - - await new Promise((res, rej) => { - pendingRequests.push({ - callback: (data) => { - loadedString = data.stringData - loadedConnection = data.connection - res() - }, - errcallback: (e) => { - rej(e) - }, - url: url, - options: options - }) - }) - } - }, - textSync() { - ret.loadSync() - - return loadedString - }, - async text() { - await ret.load() - - return loadedString - }, - jsonSync() { - if (loadedJSON === undefined) { - let str = ret.textSync() - - loadedJSON = JSON.parse(str) - } - - return loadedJSON - }, - async json() { - if (loadedJSON === undefined) { - let str = await ret.text() - - loadedJSON = JSON.parse(str) - } - - return loadedJSON - }, - responseCode() { - return loadedConnection?.getResponseCode() || -1 - } - } - return ret - } - - let pendingRequests = [] - let pendingResolves = [] - let runningThread = false - - register("tick", () => { - try { - while (pendingResolves.length > 0) { - let [callback, data] = pendingResolves.shift() - - callback(data) - } - } catch (e) { - console.log(JSON.stringify(e, undefined, 2)) - console.log(e.stack) - } - - if (pendingRequests.length > 0 && !runningThread) { - runningThread = true - new Thread(() => { - while (pendingRequests.length > 0) { - let req = pendingRequests.shift() - - try { - let data = getUrlContent(req.url, req.options) - - pendingResolves.push([req.callback, data]) - } catch (e) { - pendingResolves.push([req.errcallback, e]) - } - } - - runningThread = false - }).start() - } - }) - - global.networkUtilsThingSoopyPromise = fetch -} - -export default global.networkUtilsThingSoopyPromise |