Skip to content
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

Migrate cryptography to rust #74

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,7 @@ config.json

**/*.AppImage*

.fvm
.fvm

# Rust stuff
native/target
30 changes: 27 additions & 3 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ if (keystorePropertiesFile.exists()) {

android {
compileSdkVersion 31
ndkVersion "22.1.7171670"

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand Down Expand Up @@ -64,7 +65,7 @@ android {
productFlavors {
def debugSigning = signingConfigs.debug
def releaseSigning = signingConfigs.release

dev {
signingConfig debugSigning
applicationId = "com.potatoproject.notes.dev"
Expand All @@ -73,7 +74,7 @@ android {
label: "Leaflet Dev",
]
}

ci {
signingConfig debugSigning
applicationId = "com.potatoproject.notes.ci"
Expand All @@ -82,7 +83,7 @@ android {
label: "Leaflet CI",
]
}

production {
signingConfig releaseSigning
applicationId = "com.potatoproject.notes"
Expand All @@ -103,3 +104,26 @@ dependencies {
implementation 'androidx.core:core-ktx:1.6.0-alpha02'
implementation 'androidx.annotation:annotation:1.2.0'
}

[
new Tuple2('Debug', 'debug'),
new Tuple2('Profile', 'release'),
new Tuple2('Release', 'release')
].each {
def taskPostfix = it.first
def profileMode = it.second

tasks.whenTaskAdded { task ->
if (task.name == "javaPreCompileDev$taskPostfix"
|| task.name == "javaPreCompileCi$taskPostfix"
|| task.name == "javaPreCompileProduction$taskPostfix") {
task.dependsOn "cargoBuild$taskPostfix"
}
}

tasks.register("cargoBuild$taskPostfix", Exec) {
// Until https://github.com/bbqsrc/cargo-ndk/pull/13 is merged,
// this workaround is necessary.
commandLine 'just', '-d', '../..', '--justfile', '../../justfile', "android-native-$profileMode"
}
}
1 change: 1 addition & 0 deletions android/app/src/main/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
jniLibs
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,5 @@ public static void registerWith(@NonNull FlutterEngine flutterEngine) {
} catch(Exception e) {
Log.e(TAG, "Error registering plugin url_launcher_android, io.flutter.plugins.urllauncher.UrlLauncherPlugin", e);
}
try {
flutterEngine.getPlugins().add(new com.example.webcrypto.WebcryptoPlugin());
} catch(Exception e) {
Log.e(TAG, "Error registering plugin webcrypto, com.example.webcrypto.WebcryptoPlugin", e);
}
}
}
4 changes: 2 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
buildscript {
ext.kotlin_version = '1.4.32'
ext.kotlin_version = '1.6.10'
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:4.2.0'
classpath 'com.android.tools.build:gradle:7.3.0-alpha02'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
4 changes: 2 additions & 2 deletions android/local.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
sdk.dir=C:\\bin
sdk.dir=C:\\Users\\akshi\\AppData\\Local\\Android\\sdk
flutter.sdk=C:\\Users\\akshi\\fvm\\versions\\stable
flutter.buildMode=debug
flutter.buildMode=release
flutter.versionName=2.0.1
flutter.versionCode=21
10 changes: 10 additions & 0 deletions docs/how-it-works.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# How it works

## File format

| 2 bytes | JSON metadata | 16 bytes | 12 bytes | 16 bytes | Payload |
| --------------------------------------- | ------------- | ------------ | ------------------------- | ----------- | ------- |
| length of JSON metadata (little endian) | string | PBKDF2 nonce | AES initialization vector | AES-GCM tag | binary |

The binary payload is a zip encrypted with AES-256-GCM using a key derived using
PBKDF2 with 100,000 iterations and SHA-512 hash.
33 changes: 33 additions & 0 deletions docs/how-to-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# How to build

## Requirements

- [Flutter](https://flutter.dev) with its dependencies for the respective platform
- [just](https://just.systems), our build system
- [rustup](https://rustup.sh) with its nightly toolchain
- [flutter_rust_bridge](https://fzyzcjy.github.io/flutter_rust_bridge/)'s dependencies for your platform

## Windows

Run `flutter build windows`. This will automatically compile the rust
project and generate the bridge bindings.

## Android

Run `flutter build apk`. This will automatically compile the rust project and
generate the bridge bindings.

## Linux

Run `flutter build linux`. This will automatically compile the rust
project and generate the bridge bindings.

## macOS

Run `flutter build macos`. This will compile the rust project but won't generate
the bridge bindings. Manually run `just gen` to generate the bindings.

## iOS

Run `flutter build ios`. This will compile the rust project but won't generate
the bridge bindings. Manually run `just gen` to generate the bindings.
2 changes: 1 addition & 1 deletion ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>8.0</string>
<string>9.0</string>
</dict>
</plist>
52 changes: 26 additions & 26 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ PODS:
- Flutter
- package_info_plus (0.4.5):
- Flutter
- path_provider (0.0.1):
- path_provider_ios (0.0.1):
- Flutter
- quick_actions (0.0.1):
- Flutter
Expand All @@ -60,21 +60,21 @@ PODS:
- SDWebImage/Core (5.8.1)
- share_plus (0.0.1):
- Flutter
- shared_preferences (0.0.1):
- shared_preferences_ios (0.0.1):
- Flutter
- sqflite (0.0.2):
- Flutter
- FMDB (>= 2.7.5)
- SQLCipher (4.4.3):
- SQLCipher/standard (= 4.4.3)
- SQLCipher/common (4.4.3)
- SQLCipher/standard (4.4.3):
- SQLCipher (4.5.1):
- SQLCipher/standard (= 4.5.1)
- SQLCipher/common (4.5.1)
- SQLCipher/standard (4.5.1):
- SQLCipher/common
- sqlcipher_flutter_libs (0.0.1):
- Flutter
- SQLCipher (~> 4.4.3)
- SQLCipher (~> 4.5.0)
- SwiftyGif (5.4.0)
- url_launcher (0.0.1):
- url_launcher_ios (0.0.1):
- Flutter

DEPENDENCIES:
Expand All @@ -87,13 +87,13 @@ DEPENDENCIES:
- local_auth (from `.symlinks/plugins/local_auth/ios`)
- loggy (from `.symlinks/plugins/loggy/ios`)
- package_info_plus (from `.symlinks/plugins/package_info_plus/ios`)
- path_provider (from `.symlinks/plugins/path_provider/ios`)
- path_provider_ios (from `.symlinks/plugins/path_provider_ios/ios`)
- quick_actions (from `.symlinks/plugins/quick_actions/ios`)
- share_plus (from `.symlinks/plugins/share_plus/ios`)
- shared_preferences (from `.symlinks/plugins/shared_preferences/ios`)
- shared_preferences_ios (from `.symlinks/plugins/shared_preferences_ios/ios`)
- sqflite (from `.symlinks/plugins/sqflite/ios`)
- sqlcipher_flutter_libs (from `.symlinks/plugins/sqlcipher_flutter_libs/ios`)
- url_launcher (from `.symlinks/plugins/url_launcher/ios`)
- url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`)

SPEC REPOS:
trunk:
Expand Down Expand Up @@ -123,44 +123,44 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/loggy/ios"
package_info_plus:
:path: ".symlinks/plugins/package_info_plus/ios"
path_provider:
:path: ".symlinks/plugins/path_provider/ios"
path_provider_ios:
:path: ".symlinks/plugins/path_provider_ios/ios"
quick_actions:
:path: ".symlinks/plugins/quick_actions/ios"
share_plus:
:path: ".symlinks/plugins/share_plus/ios"
shared_preferences:
:path: ".symlinks/plugins/shared_preferences/ios"
shared_preferences_ios:
:path: ".symlinks/plugins/shared_preferences_ios/ios"
sqflite:
:path: ".symlinks/plugins/sqflite/ios"
sqlcipher_flutter_libs:
:path: ".symlinks/plugins/sqlcipher_flutter_libs/ios"
url_launcher:
:path: ".symlinks/plugins/url_launcher/ios"
url_launcher_ios:
:path: ".symlinks/plugins/url_launcher_ios/ios"

SPEC CHECKSUMS:
biometric_storage: 1400f1382af3a4cc2bf05340e13c3d8de873ceb9
DKImagePickerController: b5eb7f7a388e4643264105d648d01f727110fc3d
DKPhotoGallery: fdfad5125a9fdda9cc57df834d49df790dbb4179
file_picker: 3e6c3790de664ccf9b882732d9db5eaf6b8d4eb1
Flutter: 434fef37c0980e73bb6479ef766c45957d4b510c
Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a
flutter_keyboard_visibility: 0339d06371254c3eb25eeb90ba8d17dca8f9c069
flutter_local_notifications: 0c0b1ae97e741e1521e4c1629a459d04b9aec743
FMDB: 2ce00b547f966261cd18927a3ddb07cb6f3db82a
image_picker: 50e7c7ff960e5f58faa4d1f4af84a771c671bc4a
local_auth: 25938960984c3a7f6e3253e3f8d962fdd16852bd
image_picker: 541dcbb3b9cf32d87eacbd957845d8651d6c62c3
local_auth: ef62030a2731330b95df7ef1331bd15f6a64b8a6
loggy: 3dc4ef725f5bbe5961a7515c079385f8e9f21b80
package_info_plus: 6c92f08e1f853dc01228d6f553146438dafcd14e
path_provider: abfe2b5c733d04e238b0d8691db0cfd63a27a93c
quick_actions: 6cb2390c4dab0e737c94573c27e18d9666710720
path_provider_ios: 7d7ce634493af4477d156294792024ec3485acd5
quick_actions: cd83314083fa994182e6cd9e7516167a215a4f83
SDWebImage: e3eae2eda88578db0685a0c88597fdadd9433f05
share_plus: 056a1e8ac890df3e33cb503afffaf1e9b4fbae68
shared_preferences: af6bfa751691cdc24be3045c43ec037377ada40d
shared_preferences_ios: 548a61f8053b9b8a49ac19c1ffbc8b92c50d68ad
sqflite: 6d358c025f5b867b29ed92fc697fd34924e11904
SQLCipher: 155ffeafc9ac102e5c9b68e3e9a1297a98a27096
sqlcipher_flutter_libs: eae301083f1a44f7afea4c4593dd546ca6f16651
SQLCipher: 712e8416685e8e575b9b0706ffee71678b2fdcf8
sqlcipher_flutter_libs: 87686ab669dda991b2f384e4bcbb04b93e19c8fe
SwiftyGif: 5d4af95df24caf1c570dbbcb32a3b8a0763bc6d7
url_launcher: 6fef411d543ceb26efce54b05a0a40bfd74cbbef
url_launcher_ios: 839c58cdb4279282219f5e248c3321761ff3c4de

PODFILE CHECKSUM: 3efef3e4c4241ddf19165efb8229df7447127bfd

Expand Down
Loading