This commit is contained in:
Horis
2025-04-09 19:12:27 +08:00
parent c4b3b33ff3
commit 9193cc099b
7 changed files with 23 additions and 12 deletions
@@ -9,7 +9,7 @@ import io.legado.app.constant.AppLog
import io.legado.app.data.entities.rule.RowUi import io.legado.app.data.entities.rule.RowUi
import io.legado.app.help.CacheManager import io.legado.app.help.CacheManager
import io.legado.app.help.JsExtensions import io.legado.app.help.JsExtensions
import io.legado.app.help.SymmetricCryptoAndroid import io.legado.app.help.crypto.SymmetricCryptoAndroid
import io.legado.app.help.config.AppConfig import io.legado.app.help.config.AppConfig
import io.legado.app.help.http.CookieStore import io.legado.app.help.http.CookieStore
import io.legado.app.help.source.getShareScope import io.legado.app.help.source.getShareScope
@@ -6,6 +6,7 @@ import cn.hutool.crypto.digest.HMac
import cn.hutool.crypto.symmetric.SymmetricCrypto import cn.hutool.crypto.symmetric.SymmetricCrypto
import io.legado.app.help.crypto.AsymmetricCrypto import io.legado.app.help.crypto.AsymmetricCrypto
import io.legado.app.help.crypto.Sign import io.legado.app.help.crypto.Sign
import io.legado.app.help.crypto.SymmetricCryptoAndroid
import io.legado.app.utils.MD5Utils import io.legado.app.utils.MD5Utils
@@ -333,8 +333,8 @@ interface JsExtensions : JsEncodeUtils {
* @return 相对路径 * @return 相对路径
*/ */
@Deprecated( @Deprecated(
"Depreted", "Deprecated",
ReplaceWith("downloadFile(url: String)") ReplaceWith("downloadFile(url)")
) )
fun downloadFile(content: String, url: String): String { fun downloadFile(content: String, url: String): String {
val type = AnalyzeUrl(url, source = getSource(), coroutineContext = context).type val type = AnalyzeUrl(url, source = getSource(), coroutineContext = context).type
@@ -560,7 +560,11 @@ interface JsExtensions : JsEncodeUtils {
} else { } else {
cachePath + File.separator + path cachePath + File.separator + path
} }
return File(aPath) val file = File(aPath)
if (!file.canonicalPath.startsWith(cachePath)) {
throw SecurityException("非法路径")
}
return file
} }
fun readFile(path: String): ByteArray? { fun readFile(path: String): ByteArray? {
@@ -780,6 +784,10 @@ interface JsExtensions : JsEncodeUtils {
/** /**
* 解析字体Base64数据,返回字体解析类 * 解析字体Base64数据,返回字体解析类
*/ */
@Deprecated(
"Deprecated",
ReplaceWith("queryTTF(data)")
)
fun queryBase64TTF(data: String?): QueryTTF? { fun queryBase64TTF(data: String?): QueryTTF? {
log("queryBase64TTF(String)方法已过时,并将在未来删除;请无脑使用queryTTF(Any)替代,新方法支持传入 url、本地文件、base64、ByteArray 自动判断&自动缓存,特殊情况需禁用缓存请传入第二可选参数false:Boolean") log("queryBase64TTF(String)方法已过时,并将在未来删除;请无脑使用queryTTF(Any)替代,新方法支持传入 url、本地文件、base64、ByteArray 自动判断&自动缓存,特殊情况需禁用缓存请传入第二可选参数false:Boolean")
return queryTTF(data) return queryTTF(data)
@@ -1,11 +1,13 @@
package io.legado.app.help.crypto package io.legado.app.help.crypto
import androidx.annotation.Keep
import cn.hutool.crypto.KeyUtil import cn.hutool.crypto.KeyUtil
import cn.hutool.crypto.asymmetric.KeyType import cn.hutool.crypto.asymmetric.KeyType
import io.legado.app.utils.EncoderUtils import io.legado.app.utils.EncoderUtils
import java.io.InputStream import java.io.InputStream
import cn.hutool.crypto.asymmetric.AsymmetricCrypto as HutoolAsymmetricCrypto import cn.hutool.crypto.asymmetric.AsymmetricCrypto as HutoolAsymmetricCrypto
@Keep
@Suppress("unused") @Suppress("unused")
class AsymmetricCrypto(algorithm: String) : HutoolAsymmetricCrypto(algorithm) { class AsymmetricCrypto(algorithm: String) : HutoolAsymmetricCrypto(algorithm) {
@@ -1,24 +1,22 @@
package io.legado.app.help.crypto package io.legado.app.help.crypto
import androidx.annotation.Keep
import cn.hutool.crypto.KeyUtil import cn.hutool.crypto.KeyUtil
import cn.hutool.crypto.asymmetric.Sign as HutoolSign import cn.hutool.crypto.asymmetric.Sign as HutoolSign
@Keep
@Suppress("unused") @Suppress("unused")
class Sign(algorithm: String): HutoolSign(algorithm) { class Sign(algorithm: String): HutoolSign(algorithm) {
fun setPrivateKey(key: ByteArray): Sign { fun setPrivateKey(key: ByteArray): Sign {
setPrivateKey( setPrivateKey(KeyUtil.generatePrivateKey(algorithm, key))
KeyUtil.generatePrivateKey(this.algorithm, key)
)
return this return this
} }
fun setPrivateKey(key: String): Sign = setPrivateKey(key.encodeToByteArray()) fun setPrivateKey(key: String): Sign = setPrivateKey(key.encodeToByteArray())
fun setPublicKey(key: ByteArray): Sign { fun setPublicKey(key: ByteArray): Sign {
setPublicKey( setPublicKey(KeyUtil.generatePublicKey(algorithm, key))
KeyUtil.generatePublicKey(this.algorithm, key)
)
return this return this
} }
@@ -1,10 +1,12 @@
package io.legado.app.help package io.legado.app.help.crypto
import androidx.annotation.Keep
import cn.hutool.crypto.symmetric.SymmetricCrypto import cn.hutool.crypto.symmetric.SymmetricCrypto
import io.legado.app.utils.EncoderUtils import io.legado.app.utils.EncoderUtils
import java.io.InputStream import java.io.InputStream
import java.nio.charset.Charset import java.nio.charset.Charset
@Keep
class SymmetricCryptoAndroid( class SymmetricCryptoAndroid(
algorithm: String, algorithm: String,
key: ByteArray?, key: ByteArray?,
@@ -112,7 +112,7 @@ object Restore {
if (ignoreLocalBook && book.isLocal) { if (ignoreLocalBook && book.isLocal) {
return@forEach return@forEach
} }
if (appDb.bookDao.has(book.bookUrl) == true) { if (appDb.bookDao.has(book.bookUrl)) {
updateBooks.add(book) updateBooks.add(book)
} else { } else {
newBooks.add(book) newBooks.add(book)