mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
fixed decryption
This commit is contained in:
parent
e20e3dcfd3
commit
b3abf1e45f
2 changed files with 12 additions and 14 deletions
|
@ -88,21 +88,17 @@ object M3u8Helper2 {
|
|||
}
|
||||
}
|
||||
|
||||
private val defaultIvGen = sequence {
|
||||
var initial = 1
|
||||
|
||||
while (true) {
|
||||
yield(toBytes16Big(initial))
|
||||
++initial
|
||||
private fun defaultIv(index: Int) : ByteArray {
|
||||
return toBytes16Big(index+1)
|
||||
}
|
||||
}.iterator()
|
||||
|
||||
fun getDecrypter(
|
||||
fun getDecrypted(
|
||||
secretKey: ByteArray,
|
||||
data: ByteArray,
|
||||
iv: ByteArray = "".toByteArray()
|
||||
iv: ByteArray = byteArrayOf(),
|
||||
index : Int,
|
||||
): ByteArray {
|
||||
val ivKey = if (iv.isEmpty()) defaultIvGen.next() else iv
|
||||
val ivKey = if (iv.isEmpty()) defaultIv(index) else iv
|
||||
val c = Cipher.getInstance("AES/CBC/PKCS5Padding")
|
||||
val skSpec = SecretKeySpec(secretKey, "AES")
|
||||
val ivSpec = IvParameterSpec(ivKey)
|
||||
|
@ -234,7 +230,7 @@ object M3u8Helper2 {
|
|||
if (tsData.isEmpty()) throw ErrorLoadingException("no data")
|
||||
|
||||
return if (isEncrypted) {
|
||||
getDecrypter(encryptionData, tsData, encryptionIv)
|
||||
getDecrypted(encryptionData, tsData, encryptionIv, index)
|
||||
} else {
|
||||
tsData
|
||||
}
|
||||
|
@ -272,13 +268,13 @@ object M3u8Helper2 {
|
|||
val match =
|
||||
ENCRYPTION_URL_IV_REGEX.find(m3u8Response)!!.groupValues
|
||||
|
||||
var encryptionUri = match[1]
|
||||
var encryptionUri = match[2]
|
||||
|
||||
if (isNotCompleteUrl(encryptionUri)) {
|
||||
encryptionUri = "${getParentLink(secondSelection.streamUrl)}/$encryptionUri"
|
||||
}
|
||||
|
||||
encryptionIv = match[2].toByteArray()
|
||||
encryptionIv = match[3].toByteArray()
|
||||
val encryptionKeyResponse = app.get(encryptionUri, headers = headers, verify = false)
|
||||
encryptionData = encryptionKeyResponse.body.bytes()
|
||||
}
|
||||
|
|
|
@ -803,6 +803,8 @@ object VideoDownloadManager {
|
|||
bytesDownloaded = 0
|
||||
hlsWrittenProgress = 0
|
||||
hlsProgress = 0
|
||||
if (id != null)
|
||||
downloadDeleteEvent(id)
|
||||
|
||||
//internalType = DownloadType.IsStopped
|
||||
notify()
|
||||
|
|
Loading…
Reference in a new issue