-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
freeRASP 6.8.0 #137
Open
yardexx
wants to merge
70
commits into
master
Choose a base branch
from
release/6.8.0
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
freeRASP 6.8.0 #137
Changes from all commits
Commits
Show all changes
70 commits
Select commit
Hold shift + click to select a range
df9e2a3
feat: add data classes for malware (Dart)
yardexx 1ace1b8
feat: add data classes for malware (Kotlin)
yardexx 8982a58
feat: update Android configuration
yardexx 5400029
feat: update Talsec configuration
yardexx 7c35e19
feat: add Flutter method invocation
yardexx d65da87
feat: raise lib version
yardexx 8ef80c6
feat: update example app
yardexx 25cfcc9
feat: update threat callback
yardexx af634b2
feat: misc
yardexx fdb5c65
feat: add data classes for malware (Dart)
yardexx 5396bf1
feat: add data classes for malware (Kotlin)
yardexx fc03c02
feat: update Android configuration
yardexx fada932
feat: update Talsec configuration
yardexx 3158e81
feat: add Flutter method invocation
yardexx 44a66b4
feat: update example app
yardexx 566599c
feat: update threat callback
yardexx 7831d57
feat: misc
yardexx 2ea6dda
Merge remote-tracking branch 'origin/release/6.8.0' into release/6.8.0
yardexx 587dbb6
feat: so much code
yardexx d7d190c
feat: add whitelist addition
yardexx 4e592f2
feat!: raise example sdk version
yardexx 49b8262
docs: add documentation
yardexx b34c534
docs: adjust exports
yardexx 48ffe9e
feat: update example
yardexx 9fb2a5f
style: formatting
yardexx 14f6550
chore: raise android package version
yardexx 0eaaec0
feat: add data classes for malware (Dart)
yardexx 78e4542
feat: add data classes for malware (Kotlin)
yardexx fade1fb
feat: update Android configuration
yardexx e4cbbf7
feat: update Talsec configuration
yardexx ae85a3e
feat: add Flutter method invocation
yardexx 466462a
feat: update example app
yardexx 477aa3b
feat: update threat callback
yardexx d9cbb3c
feat: misc
yardexx 49cb0c4
feat: so much code
yardexx 4f8f205
feat: add whitelist addition
yardexx 6443d84
feat!: raise example sdk version
yardexx 50afd82
docs: add documentation
yardexx 9bfa6df
docs: adjust exports
yardexx b07331b
feat: update example
yardexx 4137e8b
style: formatting
yardexx a4e96f6
Merge remote-tracking branch 'origin/release/6.8.0' into release/6.8.0
yardexx 766d42a
chore: raise version + CHANGELOG
yardexx 7e1d780
fix: typo
yardexx f44814d
fix: failing tests
yardexx 98da53a
chore: update example
yardexx 445ce0c
feat: add pigeon build script
yardexx d431054
fix: CHANGELOG reformat
yardexx ffc93dd
style: version break
yardexx f0d9594
feat: raise SDK version
yardexx dbd94fe
style: resolve issues
yardexx 9cdde4c
feat: malware sheet scrollable
yardexx e45da01
feat: update parsing
yardexx 7fee0a9
feat: update models
yardexx ddb3496
feat: update example app
yardexx 84220bd
style: fix missing comma
yardexx 8e33968
Merge branch 'master' into release/6.8.0
yardexx 5cff44d
fix: update versions to compatible ones
yardexx 0ebab1a
Merge remote-tracking branch 'origin/release/6.8.0' into release/6.8.0
yardexx cd8471c
fix: CHANGELOG.md
yardexx 0685c4b
fix: extension name
yardexx 1969841
fix: remove function
yardexx f724346
fix: rename extension name
yardexx 706eb21
fix: version number
yardexx f5f1980
fix: missing docs
yardexx 0b677f3
fix: style
yardexx 8549784
fix: unused import
yardexx fdfb193
build: update dependencies
yardexx 05f60fc
chore: update tests
yardexx 2254ab2
feat: exclude null properties from json
yardexx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -1 +1,5 @@ | ||
include: package:very_good_analysis/analysis_options.3.1.0.yaml | ||
include: package:very_good_analysis/analysis_options.yaml | ||
|
||
analyzer: | ||
exclude: | ||
- '**/*.g.dart' |
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
176 changes: 176 additions & 0 deletions
176
android/src/main/kotlin/com/aheaditec/freerasp/Utils.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,176 @@ | ||
package com.aheaditec.freerasp | ||
|
||
import android.content.Context | ||
import android.graphics.Bitmap | ||
import android.graphics.Canvas | ||
import android.graphics.drawable.BitmapDrawable | ||
import android.graphics.drawable.Drawable | ||
import android.os.Build | ||
import android.util.Base64 | ||
import com.aheaditec.talsec_security.security.api.TalsecConfig | ||
import org.json.JSONArray | ||
import org.json.JSONException | ||
import org.json.JSONObject | ||
import java.io.ByteArrayOutputStream | ||
|
||
internal object Utils { | ||
@Suppress("ArrayInDataClass") | ||
data class MalwareConfig( | ||
val blocklistedPackageNames: Array<String>, | ||
val blocklistedHashes: Array<String>, | ||
val blocklistedPermissions: Array<Array<String>>, | ||
val whitelistedInstallationSources: Array<String> | ||
) | ||
|
||
fun toTalsecConfigThrowing(configJson: String?): TalsecConfig { | ||
if (configJson == null) { | ||
throw JSONException("Configuration is null") | ||
} | ||
|
||
val json = JSONObject(configJson) | ||
|
||
val watcherMail = json.getString("watcherMail") | ||
val isProd = json.getBoolean("isProd") | ||
val androidConfig = json.getJSONObject("androidConfig") | ||
val packageName = androidConfig.getString("packageName") | ||
val certificateHashes = androidConfig.extractArray<String>("signingCertHashes") | ||
val alternativeStores = androidConfig.extractArray<String>("supportedStores") | ||
val malwareConfig = parseMalwareConfig(androidConfig) | ||
|
||
return TalsecConfig.Builder(packageName, certificateHashes) | ||
.watcherMail(watcherMail) | ||
.supportedAlternativeStores(alternativeStores) | ||
.prod(isProd) | ||
.blocklistedPackageNames(malwareConfig.blocklistedPackageNames) | ||
.blocklistedHashes(malwareConfig.blocklistedHashes) | ||
.blocklistedPermissions(malwareConfig.blocklistedPermissions) | ||
.whitelistedInstallationSources(malwareConfig.whitelistedInstallationSources) | ||
.build() | ||
} | ||
|
||
private fun parseMalwareConfig(androidConfig: JSONObject): MalwareConfig { | ||
if (!androidConfig.has("malwareConfig")) { | ||
return MalwareConfig(emptyArray(), emptyArray(), emptyArray(), emptyArray()) | ||
} | ||
|
||
val malwareConfig = androidConfig.getJSONObject("malwareConfig") | ||
|
||
return MalwareConfig( | ||
malwareConfig.extractArray("blocklistedPackageNames"), | ||
malwareConfig.extractArray("blocklistedHashes"), | ||
malwareConfig.extractArray<Array<String>>("blocklistedPermissions"), | ||
malwareConfig.extractArray("whitelistedInstallationSources") | ||
) | ||
} | ||
|
||
|
||
/** | ||
* Retrieves the package name of the installer for a given app package. | ||
* | ||
* @param context The context of the application. | ||
* @param packageName The package name of the app whose installer package name is to be retrieved. | ||
* @return The package name of the installer if available, or `null` if not. | ||
*/ | ||
fun getInstallerPackageName(context: Context, packageName: String): String? { | ||
runCatching { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) | ||
return context.packageManager.getInstallSourceInfo(packageName).installingPackageName | ||
@Suppress("DEPRECATION") | ||
return context.packageManager.getInstallerPackageName(packageName) | ||
} | ||
return null | ||
} | ||
|
||
/** | ||
* Converts the application icon of the specified package into a Base64 encoded string. | ||
* | ||
* @param context The context of the application. | ||
* @param packageName The package name of the app whose icon is to be converted. | ||
* @return A Base64 encoded string representing the app icon. | ||
*/ | ||
fun parseIconBase64(context: Context, packageName: String): String? { | ||
val result = runCatching { | ||
val drawable = context.packageManager.getApplicationIcon(packageName) | ||
val bitmap = drawable.toBitmap() | ||
bitmap.toBase64() | ||
} | ||
|
||
return result.getOrNull() | ||
} | ||
|
||
/** | ||
* Creates a Bitmap from a Drawable object. | ||
* | ||
* @param drawable The Drawable to be converted. | ||
* @return A Bitmap representing the drawable. | ||
*/ | ||
private fun createBitmapFromDrawable(drawable: Drawable): Bitmap { | ||
val width = if (drawable.intrinsicWidth > 0) drawable.intrinsicWidth else 1 | ||
val height = if (drawable.intrinsicHeight > 0) drawable.intrinsicHeight else 1 | ||
val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888) | ||
val canvas = Canvas(bitmap) | ||
|
||
drawable.setBounds(0, 0, canvas.width, canvas.height) | ||
drawable.draw(canvas) | ||
|
||
return bitmap | ||
} | ||
|
||
/** | ||
* Converts a Drawable into a Bitmap. | ||
* | ||
* @receiver The Drawable to be converted. | ||
* @return A Bitmap representing the drawable. | ||
*/ | ||
private fun Drawable.toBitmap(): Bitmap { | ||
return when (this) { | ||
is BitmapDrawable -> bitmap | ||
else -> createBitmapFromDrawable(this) | ||
} | ||
} | ||
|
||
/** | ||
* Converts a Bitmap into a Base64 encoded string. | ||
* | ||
* @receiver The Bitmap to be converted. | ||
* @return A Base64 encoded string representing the bitmap. | ||
*/ | ||
private fun Bitmap.toBase64(): String { | ||
val byteArrayOutputStream = ByteArrayOutputStream() | ||
compress(Bitmap.CompressFormat.PNG, 10, byteArrayOutputStream) | ||
val byteArray = byteArrayOutputStream.toByteArray() | ||
return Base64.encodeToString(byteArray, Base64.NO_WRAP) | ||
} | ||
} | ||
|
||
private inline fun <reified T> JSONObject.extractArray(key: String): Array<T> { | ||
return this.optJSONArray(key)?.let { processArray(it) } ?: emptyArray() | ||
} | ||
|
||
private inline fun <reified T> processArray(jsonArray: JSONArray): Array<T> { | ||
val list = mutableListOf<T>() | ||
|
||
for (i in 0 until jsonArray.length()) { | ||
val element: T = when (T::class) { | ||
String::class -> jsonArray.getString(i) as T | ||
Int::class -> jsonArray.getInt(i) as T | ||
Double::class -> jsonArray.getDouble(i) as T | ||
Boolean::class -> jsonArray.getBoolean(i) as T | ||
Long::class -> jsonArray.getLong(i) as T | ||
Array<String>::class -> { | ||
// Not universal or ideal solution, but should work for our use case | ||
val nestedArray = jsonArray.getJSONArray(i) | ||
val nestedList = mutableListOf<String>() | ||
for (j in 0 until nestedArray.length()) { | ||
nestedList.add(nestedArray.getString(j)) | ||
} | ||
nestedList.toTypedArray() as T | ||
} | ||
|
||
else -> throw JSONException("Unsupported type") | ||
} | ||
list.add(element) | ||
} | ||
|
||
return list.toTypedArray() | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
applicationInfo is nullable since API34, can you fix this here? (and please validate that gitbook docs take this into accout as well)