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

Securely Store Location Data + Other improvements #747

Conversation

troach-sf
Copy link
Contributor

@troach-sf troach-sf commented May 1, 2020

Securely store locations in encrypted Realm db

This PR securely stores all captured Geolocation coordinates in an encrypted Realm database.

  • Secures Locations imported via Google
  • Migrates old locations to new secure storage -> deletes old on success
  • Still allows for json export
  • Fixes bug where locations stopped being captured after device restart

Linked issues:

#527
Fixes safe-paths-contrib#29

How to test

For debug builds, you can download the Realm database inside the apps storage. You can open the database using Realm Studio: https://realm.io/products/realm-studio/. Because the database is encrypted, you will need to log a hex-encoded encryption key.

Securely store locations in encrypted Realm db
@troach-sf
Copy link
Contributor Author

@tstirrat @kenpugsley Can you assign yourselves as reviewers?

@troach-sf
Copy link
Contributor Author

Encryption review is pending. Lets hold off on merging until we get an approval.

@tstirrat tstirrat added this to To do in Code reviews May 1, 2020
android/app/build.gradle Outdated Show resolved Hide resolved
Copy link
Contributor

@tstirrat tstirrat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff. I've done a quick pass on general structure. But will do a second pass later tonight.

I'd love to see some unit tests on the native code before merging.

@tstirrat tstirrat moved this from To do to In review in Code reviews May 1, 2020
@kenpugsley kenpugsley self-requested a review May 1, 2020 23:50
@tstirrat tstirrat moved this from In review to Waiting on author in Code reviews May 2, 2020
@tremblerz
Copy link
Contributor

Great work!

@Ferrumofomega
Copy link
Contributor

This is wonderful stuff @troach-sf .

@troach-sf troach-sf force-pushed the feature/secure-location-stroage branch from 51ce4b2 to f50f857 Compare May 4, 2020 20:57
tstirrat
tstirrat previously approved these changes May 5, 2020
Code reviews automation moved this from Waiting on author to Reviewer approved May 5, 2020
Code reviews automation moved this from Reviewer approved to In review May 6, 2020
.github/workflows/test.yml Outdated Show resolved Hide resolved
@troach-sf
Copy link
Contributor Author

@tstirrat, I've completed testing on both sides. Looks like there is 1 conflicting file that needs to be resolved now. I'll merge that in tomorrow morning.

@tstirrat tstirrat moved this from In review to To do in Code reviews May 6, 2020
…ation-stroage

# Conflicts:
#	app/views/LocationTracking.js
tstirrat
tstirrat previously approved these changes May 6, 2020
Code reviews automation moved this from To do to Reviewer approved May 6, 2020
@tstirrat
Copy link
Contributor

tstirrat commented May 6, 2020

Thanks! How does one run the native tests?

It would be good to encode that into 2 more jobs in the test.yml workflow.. /cc @efalkner

@troach-sf
Copy link
Contributor Author

I just wrote a document on how to manually capture encryption key for develop builds to allow for opening the database. This should help for manual tests. https://gist.github.com/troach-sf/f257bb7b80e6dddd4f3bade81b7b1410

For running the automatic tests.

Android:

cd android
../gradlew clean
../gradlew connectedAndroidTest

iOS:
Haven't tried from the command line but open the project, open the CovidSafePathsTests scheme, and click on the test icon in the sidebar and run all tests in RealmSecureStorageTest

@troach-sf
Copy link
Contributor Author

Right now Android requires a device/emulator. I don't think Realm is compatible with Robolectric for unit testing without a device. That may make it tricky to get working on GH Actions.

@kenpugsley
Copy link
Collaborator

Note to others ... I'm currently working on doing some functional testing on this, and will try to run new native tests locally.

Copy link
Collaborator

@kenpugsley kenpugsley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline comments

app/services/LocationService.js Show resolved Hide resolved
Code reviews automation moved this from Approved, needs smoke test to In review May 7, 2020
thecoder8890
thecoder8890 previously approved these changes May 7, 2020
@kenpugsley
Copy link
Collaborator

cd android
../gradlew clean
../gradlew connectedAndroidTest

This doesn't work for me. It's failing in the geolocation tests ... any ideas?
> Task :@mauron85_react-native-background-geolocation:connectedDebugAndroidTest 12:47:08 V/ddms: execute: running am get-config 12:47:09 V/ddms: execute 'am get-config' on 'emulator-5554' : EOF hit. Read: -1 12:47:09 V/ddms: execute: returning 12:47:09 D/@mauron85_react-native-background-geolocation-debug-androidTest.apk: Uploading @mauron85_react-native-background-geolocation-debug-androidTest.apk onto device 'emulator-5554' 12:47:09 D/Device: Uploading file onto device 'emulator-5554' 12:47:09 D/ddms: Reading file permision of /Users/ken/code/covid-safe-paths/node_modules/@mauron85/react-native-background-geolocation/android/lib/build/outputs/apk/androidTest/debug/@mauron85_react-native-background-geolocation-debug-androidTest.apk as: rw-r--r-- 12:47:09 V/ddms: execute: running pm install -r -t "/data/local/tmp/@mauron85_react-native-background-geolocation-debug-androidTest.apk" 12:47:12 V/ddms: execute 'pm install -r -t "/data/local/tmp/@mauron85_react-native-background-geolocation-debug-androidTest.apk"' on 'emulator-5554' : EOF hit. Read: -1 12:47:12 V/ddms: execute: returning 12:47:12 V/ddms: execute: running rm "/data/local/tmp/@mauron85_react-native-background-geolocation-debug-androidTest.apk" 12:47:13 V/ddms: execute 'rm "/data/local/tmp/@mauron85_react-native-background-geolocation-debug-androidTest.apk"' on 'emulator-5554' : EOF hit. Read: -1 12:47:13 V/ddms: execute: returning 12:47:13 I/RemoteAndroidTest: Running am instrument -w -r com.marianhello.bgloc.react.test/android.support.test.runner.AndroidJUnitRunner on Nexus_4_API_27(AVD) - 8.1.0 12:47:13 V/ddms: execute: running am instrument -w -r com.marianhello.bgloc.react.test/android.support.test.runner.AndroidJUnitRunner 12:47:13 V/InstrumentationResultParser: INSTRUMENTATION_RESULT: shortMsg=Process crashed. 12:47:13 I/InstrumentationResultParser: test run failed: 'Instrumentation run failed due to 'Process crashed.''

@troach-sf
Copy link
Contributor Author

@kenpugsley ah sorry, run :app:androidConnectedTest to limit to just our own tests. Good eye on the backfill. I discussed this with @Ferrumofomega and @tremblerz that we would only store real locations in the db. It would be easy enough to add backfilling in on the js layer when pulling locations. After discussing that a bit, I believe we came to an agreement that if there is a delay we shouldn't make assumptions someone stayed in one spot if the previous location had barely changed. I'll leave that up to you all to decide, but if we add it back in, rather than throwing assumed locations in the db, we should only add during processing.

@kenpugsley
Copy link
Collaborator

kenpugsley commented May 7, 2020

we should only add during processing.

I think that logic applies to the intersection, but this also have effects on the flow of data to safe paths. I see the point about not wanting location data that is inferred stored, but this will be a breaking change to the "contract" (not that there is one explicitly) with Safe Places. If we don't store the points in the local db, then in both the intersection as well as the data export we have to remember to backfill the gaps. Seems like a service layer thing to me.

@troach-sf troach-sf dismissed stale reviews from thecoder8890 and tstirrat via 4764eef May 7, 2020 20:44
@kenpugsley kenpugsley self-requested a review May 7, 2020 20:52
Copy link
Collaborator

@kenpugsley kenpugsley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved. Based on thread in slack, going to look at the backfill separately.

Code reviews automation moved this from In review to Approved, needs smoke test May 7, 2020
@tstirrat
Copy link
Contributor

tstirrat commented May 9, 2020

Closing this in favor of #788 where we are automating tests and merging conflicts.

@tstirrat tstirrat closed this May 9, 2020
Code reviews automation moved this from Approved, needs smoke test to Done May 9, 2020
@AdamLeonSmith
Copy link

I just wrote a document on how to manually capture encryption key for develop builds to allow for opening the database. This should help for manual tests. https://gist.github.com/troach-sf/f257bb7b80e6dddd4f3bade81b7b1410

I'm getting compilation errors (Android) when I add this immediately after SecureRandom().nextBytes(newKey) in getEncryptionKey()

@troach-sf
Copy link
Contributor Author

@AdamLeonSmith, I have updated the gist. There was a missing ")".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

Implement on-device encryption for Location Tracking data
8 participants