-
Notifications
You must be signed in to change notification settings - Fork 758
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add content scanner APIs * Move to content scanner matrix SDK to FOSS * Update file service * Refactoring * Replace matrix callbacks by coroutines * Fix lint errors * Add changelog Co-authored-by: yostyle <[email protected]>
- Loading branch information
Showing
34 changed files
with
1,321 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Add content scanner API from MSC1453 | ||
API documentation : https://github.com/matrix-org/matrix-content-scanner#api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...id/src/main/java/org/matrix/android/sdk/api/session/contentscanner/ContentScannerError.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2021 The Matrix.org Foundation C.I.C. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.matrix.android.sdk.api.session.contentscanner | ||
|
||
import com.squareup.moshi.Json | ||
import com.squareup.moshi.JsonClass | ||
|
||
@JsonClass(generateAdapter = true) | ||
data class ContentScannerError( | ||
@Json(name = "info") val info: String? = null, | ||
@Json(name = "reason") val reason: String? = null | ||
) { | ||
companion object { | ||
// 502 The server failed to request media from the media repo. | ||
const val REASON_MCS_MEDIA_REQUEST_FAILED = "MCS_MEDIA_REQUEST_FAILED" | ||
|
||
/* 400 The server failed to decrypt the encrypted media downloaded from the media repo.*/ | ||
const val REASON_MCS_MEDIA_FAILED_TO_DECRYPT = "MCS_MEDIA_FAILED_TO_DECRYPT" | ||
|
||
/* 403 The server scanned the downloaded media but the antivirus script returned a non-zero exit code.*/ | ||
const val REASON_MCS_MEDIA_NOT_CLEAN = "MCS_MEDIA_NOT_CLEAN" | ||
|
||
/* 403 The provided encrypted_body could not be decrypted. The client should request the public key of the server and then retry (once).*/ | ||
const val REASON_MCS_BAD_DECRYPTION = "MCS_BAD_DECRYPTION" | ||
|
||
/* 400 The request body contains malformed JSON.*/ | ||
const val REASON_MCS_MALFORMED_JSON = "MCS_MALFORMED_JSON" | ||
} | ||
} | ||
|
||
class ScanFailure(val error: ContentScannerError, val httpCode: Int, cause: Throwable? = null) : Throwable(cause = cause) | ||
|
||
// For Glide, which deals with Exception and not with Throwable | ||
fun ScanFailure.toException() = Exception(this) | ||
fun Throwable.toScanFailure() = this.cause as? ScanFailure |
40 changes: 40 additions & 0 deletions
40
.../src/main/java/org/matrix/android/sdk/api/session/contentscanner/ContentScannerService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright 2021 The Matrix.org Foundation C.I.C. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.matrix.android.sdk.api.session.contentscanner | ||
|
||
import androidx.lifecycle.LiveData | ||
import org.matrix.android.sdk.api.util.Optional | ||
import org.matrix.android.sdk.internal.crypto.attachments.ElementToDecrypt | ||
|
||
interface ContentScannerService { | ||
|
||
val serverPublicKey: String? | ||
|
||
fun getContentScannerServer(): String? | ||
fun setScannerUrl(url: String?) | ||
fun enableScanner(enabled: Boolean) | ||
fun isScannerEnabled(): Boolean | ||
fun getLiveStatusForFile(mxcUrl: String, fetchIfNeeded: Boolean = true, fileInfo: ElementToDecrypt? = null): LiveData<Optional<ScanStatusInfo>> | ||
fun getCachedScanResultForFile(mxcUrl: String): ScanStatusInfo? | ||
|
||
/** | ||
* Get the current public curve25519 key that the AV server is advertising. | ||
* @param callback on success callback containing the server public key | ||
*/ | ||
suspend fun getServerPublicKey(forceDownload: Boolean = false): String? | ||
suspend fun getScanResultForAttachment(mxcUrl: String, fileInfo: ElementToDecrypt? = null): ScanStatusInfo | ||
} |
30 changes: 30 additions & 0 deletions
30
...-sdk-android/src/main/java/org/matrix/android/sdk/api/session/contentscanner/ScanState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright 2021 The Matrix.org Foundation C.I.C. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.matrix.android.sdk.api.session.contentscanner | ||
|
||
enum class ScanState { | ||
TRUSTED, | ||
INFECTED, | ||
UNKNOWN, | ||
IN_PROGRESS | ||
} | ||
|
||
data class ScanStatusInfo( | ||
val state: ScanState, | ||
val scanDateTimestamp: Long?, | ||
val humanReadableMessage: String? | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.