Skip to content

Commit 5a390be

Browse files
authored
feat: support React Native 0.83 (#14)
1 parent a6b8483 commit 5a390be

20 files changed

Lines changed: 2684 additions & 1436 deletions

File tree

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
blank_issues_enabled: false
22
contact_links:
33
- name: Feature Request 💡
4-
url: https://github.com/diegolmello/rocket.chat-mobile-crypto/discussions/new?category=ideas
4+
url: https://github.com/RocketChat/rocket.chat-mobile-crypto/discussions/new?category=ideas
55
about: If you have a feature request, please create a new discussion on GitHub.
66
- name: Discussions on GitHub 💬
7-
url: https://github.com/diegolmello/rocket.chat-mobile-crypto/discussions
7+
url: https://github.com/RocketChat/rocket.chat-mobile-crypto/discussions
88
about: If this library works as promised but you need help, please ask questions there.

CONTEXT.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# @rocket.chat/mobile-crypto
2+
3+
A first-party React Native TurboModule that provides the native cryptographic
4+
primitives (SHA, HMAC, PBKDF2, AES, RSA, secure random) the Rocket.Chat mobile
5+
app relies on. It is a published, maintained package — not an abandoned fork
6+
pinned at a commit.
7+
8+
## Language
9+
10+
**Mobile Crypto**:
11+
This library — the native crypto provider consumed by the Rocket.Chat mobile app.
12+
_Avoid_: "the fork", "the pinned lib" (it is first-party and published).
13+
14+
**E2E encryption**:
15+
Rocket.Chat end-to-end message and file encryption — the downstream feature that
16+
consumes Mobile Crypto's primitives. The reason byte-level output compatibility matters.
17+
_Avoid_: "E2E" unqualified (collides with end-to-end *testing*), "encryption" alone.
18+
19+
**Known-answer harness**:
20+
The example app (`example/src/App.tsx`) — exercises every primitive with fixed
21+
`expected:` values for deterministic ops and round-trip checks for randomized ones.
22+
It is the conformance gate that proves a rebuild preserved behavior.
23+
_Avoid_: "the test app", "the demo".
24+
25+
**Byte-compatible**:
26+
Produces output identical to the previously shipped version for deterministic
27+
operations (SHA, HMAC, PBKDF2, AES-CBC with fixed IV). Randomized operations
28+
(RSA-OAEP, RSA-PSS) are validated by round-trip instead, since byte-equality is
29+
not achievable for them.
30+
31+
## Relationships
32+
33+
- **E2E encryption** depends on **Mobile Crypto** producing **byte-compatible** output.
34+
- The **Known-answer harness** verifies **Mobile Crypto** is **byte-compatible** after a rebuild.
35+
36+
## Flagged ambiguities
37+
38+
- "E2E" was ambiguous between end-to-end *encryption* (this project's domain) and
39+
end-to-end *testing* — resolved: in this repo "E2E" means encryption.
40+
- "fork" (from the originating ticket) implied an abandoned pinned dependency —
41+
resolved: this is a maintained first-party package.

MobileCrypto.podspec

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,22 @@ Pod::Spec.new do |s|
1111
s.authors = package["author"]
1212

1313
s.platforms = { :ios => min_ios_version_supported }
14-
s.source = { :git => "https://github.com/diegolmello/rocket.chat-mobile-crypto.git", :tag => "#{s.version}" }
14+
s.source = { :git => "https://github.com/RocketChat/rocket.chat-mobile-crypto.git", :tag => "#{s.version}" }
1515

1616
s.source_files = "ios/**/*.{h,m,mm,cpp,swift}"
1717
s.public_header_files = "ios/algorithms/AESCrypto.h", "ios/algorithms/RSACrypto.h", "ios/algorithms/CryptoUtils.h", "ios/algorithms/RandomUtils.h", "ios/algorithms/HMACCrypto.h", "ios/algorithms/PBKDF2Crypto.h", "ios/algorithms/SHACrypto.h", "ios/algorithms/FileUtils.h"
1818
s.private_header_files = "ios/MobileCrypto.h"
1919
s.swift_version = "5.0"
2020
s.requires_arc = true
2121

22-
# Minimal module configuration
22+
# Module config — exposes the Swift-generated ObjC compat header so that
23+
# AESCrypto.m can find "MobileCrypto-Swift.h" via double-quoted import.
24+
# OBJECT_FILE_DIR_normal/$(CURRENT_ARCH) is where swiftc writes the header
25+
# in static-lib (non-use_frameworks!) builds; add it to the search path.
2326
s.pod_target_xcconfig = {
2427
'DEFINES_MODULE' => 'YES',
25-
'SWIFT_OBJC_INTERFACE_HEADER_NAME' => 'MobileCrypto-Swift.h'
28+
'SWIFT_OBJC_INTERFACE_HEADER_NAME' => 'MobileCrypto-Swift.h',
29+
'HEADER_SEARCH_PATHS' => '$(inherited) $(PODS_TARGET_SRCROOT)/ios/algorithms $(OBJECT_FILE_DIR_normal)/$(CURRENT_ARCH)'
2630
}
2731

2832
# Ensure Swift files are properly compiled and linked

android/build.gradle

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ buildscript {
99
}
1010

1111
dependencies {
12-
classpath "com.android.tools.build:gradle:8.7.2"
12+
classpath "com.android.tools.build:gradle:8.12.0"
1313
// noinspection DifferentKotlinGradleVersion
1414
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
1515
}
@@ -50,8 +50,12 @@ android {
5050
}
5151

5252
compileOptions {
53-
sourceCompatibility JavaVersion.VERSION_1_8
54-
targetCompatibility JavaVersion.VERSION_1_8
53+
sourceCompatibility JavaVersion.VERSION_17
54+
targetCompatibility JavaVersion.VERSION_17
55+
}
56+
57+
kotlinOptions {
58+
jvmTarget = "17"
5559
}
5660

5761
sourceSets {

android/gradle.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
MobileCrypto_kotlinVersion=2.0.21
1+
MobileCrypto_kotlinVersion=2.1.20
22
MobileCrypto_minSdkVersion=24
3-
MobileCrypto_targetSdkVersion=34
4-
MobileCrypto_compileSdkVersion=35
3+
MobileCrypto_targetSdkVersion=36
4+
MobileCrypto_compileSdkVersion=36
55
MobileCrypto_ndkVersion=27.1.12297006

android/src/main/java/chat/rocket/mobilecrypto/algorithms/RSACrypto.kt

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,7 @@ object RSACrypto {
183183
* @return True if signature is valid
184184
*/
185185
fun verify(signatureBase64: String, message: String, publicKeyPem: String, hashAlgorithm: String? = null): Boolean {
186-
val publicKeyBytes = pemToKey(publicKeyPem)
187-
val keySpec = X509EncodedKeySpec(publicKeyBytes)
188-
val keyFactory = KeyFactory.getInstance("RSA")
189-
val publicKey = keyFactory.generatePublic(keySpec)
190-
186+
val publicKey = createPublicKeyFromPem(publicKeyPem)
191187
val signature = Signature.getInstance(getSignatureAlgorithm(hashAlgorithm))
192188
signature.initVerify(publicKey)
193189
signature.update(CryptoUtils.stringToUtf8Bytes(message))
@@ -205,11 +201,7 @@ object RSACrypto {
205201
* @return True if signature is valid
206202
*/
207203
fun verifyBase64(signatureBase64: String, messageBase64: String, publicKeyPem: String, hashAlgorithm: String? = null): Boolean {
208-
val publicKeyBytes = pemToKey(publicKeyPem)
209-
val keySpec = X509EncodedKeySpec(publicKeyBytes)
210-
val keyFactory = KeyFactory.getInstance("RSA")
211-
val publicKey = keyFactory.generatePublic(keySpec)
212-
204+
val publicKey = createPublicKeyFromPem(publicKeyPem)
213205
val signature = Signature.getInstance(getSignatureAlgorithm(hashAlgorithm))
214206
signature.initVerify(publicKey)
215207
val messageBytes = CryptoUtils.decodeBase64(messageBase64)

example/android/app/src/debug/AndroidManifest.xml

Lines changed: 0 additions & 9 deletions
This file was deleted.

example/android/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
android:roundIcon="@mipmap/ic_launcher_round"
1010
android:allowBackup="false"
1111
android:theme="@style/AppTheme"
12+
android:usesCleartextTraffic="${usesCleartextTraffic}"
1213
android:supportsRtl="true">
1314
<activity
1415
android:name=".MainActivity"

example/android/app/src/main/java/rocketchat/mobilecrypto/example/MainApplication.kt

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,24 @@ import android.app.Application
44
import com.facebook.react.PackageList
55
import com.facebook.react.ReactApplication
66
import com.facebook.react.ReactHost
7-
import com.facebook.react.ReactNativeHost
8-
import com.facebook.react.ReactPackage
9-
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load
7+
import com.facebook.react.ReactNativeApplicationEntryPoint.loadReactNative
108
import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
11-
import com.facebook.react.defaults.DefaultReactNativeHost
12-
import com.facebook.soloader.SoLoader
13-
import com.facebook.react.soloader.OpenSourceMergedSoMapping
149

1510
class MainApplication : Application(), ReactApplication {
1611

17-
override val reactNativeHost: ReactNativeHost =
18-
object : DefaultReactNativeHost(this) {
19-
override fun getPackages(): List<ReactPackage> =
20-
PackageList(this).packages.apply {
21-
// Packages that cannot be autolinked yet can be added manually here, for example:
22-
// add(MyReactNativePackage())
23-
}
24-
25-
override fun getJSMainModuleName(): String = "index"
26-
27-
override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG
28-
29-
override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
30-
override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED
31-
}
32-
33-
override val reactHost: ReactHost
34-
get() = getDefaultReactHost(applicationContext, reactNativeHost)
12+
override val reactHost: ReactHost by lazy {
13+
getDefaultReactHost(
14+
context = applicationContext,
15+
packageList =
16+
PackageList(this).packages.apply {
17+
// Packages that cannot be autolinked yet can be added manually here, for example:
18+
// add(MyReactNativePackage())
19+
},
20+
)
21+
}
3522

3623
override fun onCreate() {
3724
super.onCreate()
38-
SoLoader.init(this, OpenSourceMergedSoMapping)
39-
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
40-
load()
41-
}
25+
loadReactNative(this)
4226
}
4327
}

example/android/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
buildscript {
22
ext {
3-
buildToolsVersion = "35.0.0"
3+
buildToolsVersion = "36.0.0"
44
minSdkVersion = 24
5-
compileSdkVersion = 35
6-
targetSdkVersion = 35
5+
compileSdkVersion = 36
6+
targetSdkVersion = 36
77
ndkVersion = "27.1.12297006"
8-
kotlinVersion = "2.0.21"
8+
kotlinVersion = "2.1.20"
99
}
1010
repositories {
1111
google()

0 commit comments

Comments
 (0)