Skip to content

Commit

Permalink
feat: added support for encrypting events persisted in sqlite3 db (#118)
Browse files Browse the repository at this point in the history
* feat: added support for encrypting events persisted in sqlite3 db

* chore: updated pubspec.lock files across all packages w.r.t to latest dependencies

* chore: improved sample app

* chore: updated sample app to use the encryption feature

* chore: updated ios plugin to use the latest version of iOS SDK

* fix: fixed issues for encryption configuration on android platform

* refactor: moved DBEncryption to a separate class

* fix: fixed dbencryption status to be sent even if it was disabled to the native sdks

* chore: updated podfile.lock of example app

---------

Co-authored-by: Desu Sai Venkat <[email protected]>
  • Loading branch information
desusai7 and Desu Sai Venkat authored Sep 4, 2023
1 parent 2861154 commit 24175a5
Show file tree
Hide file tree
Showing 13 changed files with 291 additions and 202 deletions.
8 changes: 6 additions & 2 deletions packages/example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ apply plugin: 'com.google.gms.google-services'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 31
compileSdkVersion 33

lintOptions {
disable 'InvalidPackage'
Expand Down Expand Up @@ -63,4 +63,8 @@ flutter {

dependencies {
implementation 'com.google.android.gms:play-services-ads:19.3.0'
}

//sql-cipher
implementation "net.zetetic:android-database-sqlcipher:4.5.4"
implementation "androidx.sqlite:sqlite:2.3.1"
}
13 changes: 9 additions & 4 deletions packages/example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ PODS:
- GoogleUtilities/Logger
- GoogleUtilities/UserDefaults (7.11.5):
- GoogleUtilities/Logger
- Leanplum-iOS-SDK (4.0.0)
- MetricsReporter (1.0.0):
- RudderKit (~> 1.4.0)
- nanopb (2.30909.0):
Expand All @@ -108,7 +109,7 @@ PODS:
- nanopb/decode (2.30909.0)
- nanopb/encode (2.30909.0)
- PromisesObjC (2.3.1)
- Rudder (1.19.1):
- Rudder (1.19.2):
- MetricsReporter (= 1.0.0)
- Rudder-Adjust (1.0.0):
- Adjust
Expand Down Expand Up @@ -154,7 +155,7 @@ PODS:
- rudder_plugin_ios
- rudder_plugin_ios (0.0.1):
- Flutter
- Rudder (< 2.0.0, >= 1.9.1)
- Rudder (< 2.0.0, >= 1.19.2)
- RudderKit (1.4.0)
- SDWebImage (5.17.0):
- SDWebImage/Core (= 5.17.0)
Expand Down Expand Up @@ -183,6 +184,7 @@ SPEC REPOS:
- FirebaseInstallations
- GoogleAppMeasurement
- GoogleUtilities
- Leanplum-iOS-SDK
- MetricsReporter
- nanopb
- PromisesObjC
Expand All @@ -193,6 +195,7 @@ SPEC REPOS:
- Rudder-Appsflyer
- Rudder-Braze
- Rudder-Firebase
- Rudder-Leanplum
- RudderKit
- SDWebImage

Expand Down Expand Up @@ -227,10 +230,11 @@ SPEC CHECKSUMS:
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
GoogleAppMeasurement: c7d6fff39bf2d829587d74088d582e32d75133c3
GoogleUtilities: 13e2c67ede716b8741c7989e26893d151b2b2084
Leanplum-iOS-SDK: 8115f65d185eb94d94c4ab08176dfcb4a8b97926
MetricsReporter: 35d1a8e62cd99e1434bc8fdd06bf2baf7cb23e42
nanopb: b552cce312b6c8484180ef47159bc0f65a1f0431
PromisesObjC: c50d2056b5253dadbd6c2bea79b0674bd5a52fa4
Rudder: 187a8fc060057605b6e78fb8077b4d989943d804
Rudder: 26a9b6756628cb953f3151d835104ac9f5635861
Rudder-Adjust: 5f14011c8f7237d80a96a10655ac03ebf832bcc4
Rudder-Amplitude: f845cc125a1a58d4de6155391a2b0392815ae898
Rudder-AppCenter: 9eca9241e3707a0e9610714dd91dc8da4bae7e1f
Expand All @@ -243,7 +247,8 @@ SPEC CHECKSUMS:
rudder_integration_appsflyer_flutter: 4736dc267dd6e8b3e7321e4999ed1bb751b9ad59
rudder_integration_braze_flutter: ddc8cb4214059122d2f7f6f2aff5772d3fb2e5fd
rudder_integration_firebase_flutter: 2406b968e85e4a3175b64ccc8f8de98eca3b3d2e
rudder_plugin_ios: aa27daa46baaa91581ac5e74eb75ab1783a76690
rudder_integration_leanplum_flutter: c6e83564dc7c1a96cec8b97c6e75f9b3c1958c91
rudder_plugin_ios: 6d73f06a3c4f2f5906746790af65e697976b04bd
RudderKit: f272f9872183946452ac94cd7bb2244a71e6ca8f
SDWebImage: 750adf017a315a280c60fde706ab1e552a3ae4e9

Expand Down
28 changes: 16 additions & 12 deletions packages/example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; };
1BACAD6685BDA47D10388CC2 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 92E794076A811068DEB4791A /* Pods_Runner.framework */; };
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; };
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
Expand Down Expand Up @@ -39,42 +40,45 @@
74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = "<group>"; };
74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
829D2DB58995279B078B5E09 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = "<group>"; };
92E794076A811068DEB4791A /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; };
9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = "<group>"; };
9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = "<group>"; };
97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; };
97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
F60C5971659B706A94194B37 /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = "<group>"; };
9B7CB2D863582BA93F2E8D5D /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = "<group>"; };
C7426D6CAB52F145BF66BF1A /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
97C146EB1CF9000F007C117D /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
D5314B56906AA2F8DF6A803A /* Pods_Runner.framework in Frameworks */,
1BACAD6685BDA47D10388CC2 /* Pods_Runner.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
08192186B5154080E8A22385 /* Frameworks */ = {
0F97BFE0B72F401372A2A3B3 /* Frameworks */ = {
isa = PBXGroup;
children = (
73C9EDE32D5C23C3363B1BA9 /* Pods_Runner.framework */,
92E794076A811068DEB4791A /* Pods_Runner.framework */,
);
name = Frameworks;
sourceTree = "<group>";
};
8407D258E6E03BD7140000D2 /* Pods */ = {
isa = PBXGroup;
children = (
2921FBB6205F79E9D2E63A96 /* Pods-Runner.debug.xcconfig */,
3B915C980EF17DFB6193A6C6 /* Pods-Runner.release.xcconfig */,
F60C5971659B706A94194B37 /* Pods-Runner.profile.xcconfig */,
C7426D6CAB52F145BF66BF1A /* Pods-Runner.debug.xcconfig */,
829D2DB58995279B078B5E09 /* Pods-Runner.release.xcconfig */,
9B7CB2D863582BA93F2E8D5D /* Pods-Runner.profile.xcconfig */,
);
path = Pods;
sourceTree = "<group>";
Expand All @@ -97,7 +101,7 @@
97C146F01CF9000F007C117D /* Runner */,
97C146EF1CF9000F007C117D /* Products */,
8407D258E6E03BD7140000D2 /* Pods */,
08192186B5154080E8A22385 /* Frameworks */,
0F97BFE0B72F401372A2A3B3 /* Frameworks */,
);
sourceTree = "<group>";
};
Expand Down Expand Up @@ -131,14 +135,14 @@
isa = PBXNativeTarget;
buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */;
buildPhases = (
466EE0C8A31EECFF71D54DBF /* [CP] Check Pods Manifest.lock */,
74B5851F06D445E93A2E593A /* [CP] Check Pods Manifest.lock */,
9740EEB61CF901F6004384FC /* Run Script */,
97C146EA1CF9000F007C117D /* Sources */,
97C146EB1CF9000F007C117D /* Frameworks */,
97C146EC1CF9000F007C117D /* Resources */,
9705A1C41CF9048500538489 /* Embed Frameworks */,
3B06AD1E1E4923F5004D2608 /* Thin Binary */,
A73092A518BC468777DFD42D /* [CP] Copy Pods Resources */,
CA8095ADE98704672EFD6522 /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand Down Expand Up @@ -213,7 +217,7 @@
shellPath = /bin/sh;
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin";
};
466EE0C8A31EECFF71D54DBF /* [CP] Check Pods Manifest.lock */ = {
74B5851F06D445E93A2E593A /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
Expand Down Expand Up @@ -250,7 +254,7 @@
shellPath = /bin/sh;
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build\n";
};
A73092A518BC468777DFD42D /* [CP] Copy Pods Resources */ = {
CA8095ADE98704672EFD6522 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
Expand Down
90 changes: 50 additions & 40 deletions packages/example/lib/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,22 @@ class HomeScreenState extends State<HomeScreen> {
}

void __initialize() {
MobileConfig mc =
MobileConfig(autoCollectAdvertId: false, collectDeviceId: false);
DBEncryption dbEncryption = DBEncryption(true, "password");
MobileConfig mc = MobileConfig(
autoCollectAdvertId: false,
dbEncryption: dbEncryption,
collectDeviceId: false);
RudderConfigBuilder builder = RudderConfigBuilder();
builder.withFactory(RudderIntegrationAppcenterFlutter());
builder.withFactory(RudderIntegrationFirebaseFlutter());
builder.withFactory(RudderIntegrationBrazeFlutter());
builder.withFactory(RudderIntegrationAmplitudeFlutter());
builder.withDataPlaneUrl(
dotenv.env['DATA_PLANE_URL'] ?? "https://hosted.rudderlabs.com");
builder.withMobileConfig(mc);
builder.withLogLevel(RudderLogger.VERBOSE);
builder.withDataResidencyServer(DataResidencyServer.US);
builder
..withFactory(RudderIntegrationAppcenterFlutter())
..withFactory(RudderIntegrationFirebaseFlutter())
..withFactory(RudderIntegrationBrazeFlutter())
..withFactory(RudderIntegrationAmplitudeFlutter())
..withDataPlaneUrl(
dotenv.env['DATA_PLANE_URL'] ?? "https://hosted.rudderlabs.com")
..withMobileConfig(mc)
..withLogLevel(RudderLogger.VERBOSE)
..withDataResidencyServer(DataResidencyServer.US);
String writeKey = dotenv.env['WRITE_KEY'] ?? "INVALID_WRITE_KEY";
rudderClient.initialize(writeKey, config: builder.build(), options: null);
isInitialized = true;
Expand All @@ -58,30 +62,34 @@ class HomeScreenState extends State<HomeScreen> {

void __track() {
RudderProperty property = RudderProperty();
property.put("colour", "red");
property.put("manufacturer", "hyundai");
property.put("model", "i20");
property.put("marks", [1, 2, 3, 4]);
property.put("something nested", [
{
"nest_2": [76, 78],
"nest_2_1": {"nest_2_2": "some val"}
},
{
"string_arr": ["a", "b"]
}
]);
property
..put("colour", "red")
..put("manufacturer", "hyundai")
..put("model", "i20")
..put("marks", [1, 2, 3, 4])
..put("something nested", [
{
"nest_2": [76, 78],
"nest_2_1": {"nest_2_2": "some val"}
},
{
"string_arr": ["a", "b"]
}
]);

RudderOption options = RudderOption();
options.putIntegration("All", true);
options.putIntegration("Mixpanel", false);
options.putCustomContext("address", {
"city": "kolkata",
"pin": "700091",
"state": {"name": "West Bengal", "code": "WB"},
"country": {"name": "India", "code": "IN"},
"zone": 12,
"lat": 22.5726,
});
options
..putIntegration("All", true)
..putIntegration("Mixpanel", false)
..putCustomContext("address", {
"city": "kolkata",
"pin": "700091",
"state": {"name": "West Bengal", "code": "WB"},
"country": {"name": "India", "code": "IN"},
"zone": 12,
"lat": 22.5726,
});

rudderClient.track("Went on a drive web",
properties: property, options: options);

Expand All @@ -92,8 +100,9 @@ class HomeScreenState extends State<HomeScreen> {

void __screen() {
RudderProperty screenProperty = RudderProperty();
screenProperty.put("browser", "chrome");
screenProperty.put("device", "mac book pro");
screenProperty
..put("browser", "chrome")
..put("device", "mac book pro");
rudderClient.screen("Walmart Cart web",
category: "home", properties: screenProperty, options: null);

Expand All @@ -103,10 +112,11 @@ class HomeScreenState extends State<HomeScreen> {

void __group() {
RudderTraits groupTraits = RudderTraits();
groupTraits.put("place", "kolkata");
groupTraits.put("size", "fifteen");
groupTraits.put("details", {"domain": "SDK", "type": "flutter"});
groupTraits.putValue({"key1": "value1", "key2": "value2"});
groupTraits
..put("place", "kolkata")
..put("size", "fifteen")
..put("details", {"domain": "SDK", "type": "flutter"})
..putValue({"key1": "value1", "key2": "value2"});
rudderClient.group("Integrations-Rudder", groupTraits: groupTraits);
setOutput(
"group\n\ttraits:\n\t\tplace:kolkata\n\t\tsize:fifteen\n\tid: Integrations-Rudder");
Expand Down
7 changes: 7 additions & 0 deletions packages/example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,13 @@ packages:
relative: true
source: path
version: "2.0.6"
rudder_integration_leanplum_flutter:
dependency: "direct main"
description:
path: "../integrations/rudder_integration_leanplum_flutter"
relative: true
source: path
version: "1.0.7"
rudder_plugin_android:
dependency: "direct overridden"
description:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,21 @@ public RudderConfig getRudderConfig(Map<String, Object> configMap) {
.withTrackLifecycleEvents((Boolean) configMap.get("trackLifecycleEvents"))
.withRecordScreenViews((Boolean) configMap.get("recordScreenViews"))
.withControlPlaneUrl((String) configMap.get("controlPlaneUrl"));

String dataResidencyServer = (String) configMap.get("dataResidencyServer");
if (dataResidencyServer.equals("EU")) {
builder.withDataResidencyServer(RudderDataResidencyServer.EU);
}

Map<String, Object> dbEncryptionMap = (Map<String, Object>) configMap.get("dbEncryption");
if(dbEncryptionMap != null) {
Boolean enabled = (Boolean) dbEncryptionMap.get("enabled");
String encryptionKey = (String) dbEncryptionMap.get("key");
if(encryptionKey!=null && encryptionKey.length() > 0) {
builder.withDbEncryption(new RudderConfig.DBEncryption(enabled, encryptionKey));
}
}

if (integrationList != null) {
builder.withFactories(integrationList);
}
Expand Down
3 changes: 3 additions & 0 deletions packages/plugins/rudder_plugin_interface/lib/platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ library rudder_sdk_flutter_platform_interface;
export 'src/constants.dart';
export 'src/enums.dart';
export 'src/rudder_logger.dart';
export 'src/models/db_encryption.dart';
export 'src/models/rudder_config.dart';
export 'src/models/rudder_web_config.dart';
export 'src/models/rudder_mobile_config.dart';
export 'src/models/rudder_integration.dart';
export 'src/models/rudder_option.dart';
export 'src/models/rudder_property.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class DBEncryption {
// @param whether the SDK should encrypt the DB
final bool _enabled;

// @param key to be used for encryption
final String _key;

DBEncryption(enabled, key)
: _enabled = enabled,
_key = key;

bool get enabled => _enabled;
String get key => _key;

Map getMap() {
return {"enabled": _enabled, "key": _key};
}
}
Loading

0 comments on commit 24175a5

Please sign in to comment.