优化: Bark通道加密推送支持随机IV #688

This commit is contained in:
pppscn
2026-01-20 21:53:54 +08:00
parent 36e2b7c49b
commit 3de474f834
8 changed files with 23 additions and 14 deletions

View File

@@ -24,7 +24,7 @@ data class BarkSetting(
//加密密钥
val key: String = "",
//初始偏移向量
val iv: String = "",
var iv: String = "",
//持续提醒
val call: String = "",
//自动复制模板

View File

@@ -280,7 +280,7 @@ class BarkFragment : BaseFragment<FragmentSendersBarkBinding?>(), View.OnClickLi
} else if (transformation.startsWith("AES256") && key.length != 32) {
throw Exception(getString(R.string.bark_encryption_key_error3))
}
if (transformation.contains("CBC") && iv.length != 16) {
if (transformation.contains("CBC") && iv.isNotEmpty() && iv.length != 16) {
throw Exception(getString(R.string.bark_encryption_key_error4))
}

View File

@@ -8,6 +8,7 @@ import com.idormy.sms.forwarder.entity.MsgInfo
import com.idormy.sms.forwarder.entity.result.BarkResult
import com.idormy.sms.forwarder.entity.setting.BarkSetting
import com.idormy.sms.forwarder.utils.Log
import com.idormy.sms.forwarder.utils.RandomUtils
import com.idormy.sms.forwarder.utils.SendUtils
import com.idormy.sms.forwarder.utils.SettingUtils
import com.idormy.sms.forwarder.utils.interceptor.BasicAuthInterceptor
@@ -15,11 +16,12 @@ import com.idormy.sms.forwarder.utils.interceptor.LoggingInterceptor
import com.xuexiang.xhttp2.XHttp
import com.xuexiang.xhttp2.callback.SimpleCallBack
import com.xuexiang.xhttp2.exception.ApiException
import java.net.URLEncoder
import javax.crypto.Cipher
import javax.crypto.spec.IvParameterSpec
import javax.crypto.spec.SecretKeySpec
@Suppress("RegExpRedundantEscape", "UselessCallOnNotNull")
@Suppress("RegExpRedundantEscape", "UselessCallOnNotNull", "CanUnescapeDollarLiteral")
class BarkUtils {
companion object {
@@ -93,10 +95,15 @@ class BarkUtils {
val requestMsg: String = Gson().toJson(msgMap)
Log.i(TAG, "requestMsg:$requestMsg")
//推送加密
if (setting.transformation.isNullOrBlank() || "none" == setting.transformation || setting.key.isNullOrBlank() || setting.iv.isNullOrBlank()) {
if (setting.transformation.isNullOrBlank() || "none" == setting.transformation || setting.key.isNullOrBlank()) {
request.upJson(requestMsg)
} else {
val transformation = setting.transformation.replace("AES128", "AES").replace("AES192", "AES").replace("AES256", "AES")
if (setting.iv.isNullOrBlank()) {
// 留空则随机16字符
setting.iv = RandomUtils.getRandomNumbersAndLetters(16).toString()
request.params("iv", URLEncoder.encode(setting.iv, "UTF-8"))
}
val ciphertext = encrypt(requestMsg, transformation, setting.key, setting.iv)
//Log.d(TAG, "ciphertext: $ciphertext")
//val plainText = decrypt(ciphertext, transformation, setting.key, setting.iv)

View File

@@ -389,7 +389,8 @@
android:layout_weight="1"
android:hint="@string/bark_encryption_key_tips"
android:singleLine="true"
app:met_clearButton="true" />
app:met_clearButton="true"
app:met_passWordButton="true" />
</LinearLayout>
@@ -413,7 +414,8 @@
android:layout_weight="1"
android:hint="@string/bark_encryption_iv_tips"
android:singleLine="true"
app:met_clearButton="true" />
app:met_clearButton="true"
app:met_passWordButton="true" />
</LinearLayout>

View File

@@ -598,11 +598,11 @@
<string name="bark_encryption_key">AES Key</string>
<string name="bark_encryption_key_tips">corresponding key on bark</string>
<string name="bark_encryption_iv">AES iv</string>
<string name="bark_encryption_iv_tips">corresponding iv on bark</string>
<string name="bark_encryption_iv_tips">corresponding iv on bark or keep empty</string>
<string name="bark_encryption_key_error1">AES Key must be 16 characters</string>
<string name="bark_encryption_key_error2">AES Key must be 24 characters</string>
<string name="bark_encryption_key_error3">AES Key must be 32 characters</string>
<string name="bark_encryption_key_error4">AES iv must be 16 characters</string>
<string name="bark_encryption_key_error4">AES iv must be 16 characters or empty</string>
<string name="from_email_hint">Fill in the username before @</string>
<string name="other_mail_type">other</string>

View File

@@ -600,10 +600,10 @@
<string name="bark_encryption_key_tips">对应bark上的key</string>
<string name="bark_encryption_iv">偏移向量</string>
<string name="bark_encryption_iv_tips">对应bark上的iv</string>
<string name="bark_encryption_key_error1">加密密钥必须是16位</string>
<string name="bark_encryption_key_error1">加密密钥必须是16位 或 留空随机产生</string>
<string name="bark_encryption_key_error2">加密密钥必须是24位</string>
<string name="bark_encryption_key_error3">加密密钥必须是32位</string>
<string name="bark_encryption_key_error4">偏移向量必须是16位</string>
<string name="bark_encryption_key_error4">偏移向量必须是16位 或 留空</string>
<string name="from_email_hint">填写 @ 前面的用户名</string>
<string name="other_mail_type">其他邮箱</string>

View File

@@ -600,10 +600,10 @@
<string name="bark_encryption_key_tips">對應bark上的key</string>
<string name="bark_encryption_iv">偏移向量</string>
<string name="bark_encryption_iv_tips">對應bark上的iv</string>
<string name="bark_encryption_key_error1">加密密鑰必須是16位</string>
<string name="bark_encryption_key_error1">加密密鑰必須是16位 或 留空随机产生</string>
<string name="bark_encryption_key_error2">加密密鑰必須是24位</string>
<string name="bark_encryption_key_error3">加密密鑰必須是32位</string>
<string name="bark_encryption_key_error4">偏移向量必須是16位</string>
<string name="bark_encryption_key_error4">偏移向量必須是16位 或 留空</string>
<string name="from_email_hint">填寫 @ 前面的用戶名</string>
<string name="other_mail_type">其他郵箱</string>

View File

@@ -628,11 +628,11 @@
<string name="bark_encryption_key">加密密钥</string>
<string name="bark_encryption_key_tips">对应bark上的key</string>
<string name="bark_encryption_iv">偏移向量</string>
<string name="bark_encryption_iv_tips">对应bark上的iv</string>
<string name="bark_encryption_iv_tips">对应bark上的iv 或 留空随机产生</string>
<string name="bark_encryption_key_error1">加密密钥必须是16位</string>
<string name="bark_encryption_key_error2">加密密钥必须是24位</string>
<string name="bark_encryption_key_error3">加密密钥必须是32位</string>
<string name="bark_encryption_key_error4">偏移向量必须是16位</string>
<string name="bark_encryption_key_error4">偏移向量必须是16位 或 留空</string>
<string name="from_email_hint">填写 @ 前面的用户名</string>
<string name="other_mail_type">其他邮箱</string>