Skip to content

Commit 912c4f1

Browse files
committed
Rename to osp-s2 and iOS compiling
1 parent 6b79128 commit 912c4f1

15 files changed

+128
-130
lines changed

CONTRIBUTING.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ The [example app](/example/) demonstrates usage of the library. You need to run
2323

2424
It is configured to use the local version of the library, so any changes you make to the library's source code will be reflected in the example app. Changes to the library's JavaScript code will be reflected in the example app without a rebuild, but native code changes will require a rebuild of the example app.
2525

26-
If you want to use Android Studio or XCode to edit the native code, you can open the `example/android` or `example/ios` directories respectively in those editors. To edit the Objective-C or Swift files, open `example/ios/OpSecureStorageExample.xcworkspace` in XCode and find the source files at `Pods > Development Pods > @op-engineering/op-secure-storage`.
26+
If you want to use Android Studio or XCode to edit the native code, you can open the `example/android` or `example/ios` directories respectively in those editors. To edit the Objective-C or Swift files, open `example/ios/OpSecureStorageExample.xcworkspace` in XCode and find the source files at `Pods > Development Pods > @op-engineering/op-s2`.
2727

28-
To edit the Java or Kotlin files, open `example/android` in Android studio and find the source files at `op-engineering-op-secure-storage` under `Android`.
28+
To edit the Java or Kotlin files, open `example/android` in Android studio and find the source files at `op-engineering-op-s2` under `Android`.
2929

3030
You can use various commands from the root directory to work with the project.
3131

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
# @op-engineering/op-secure-storage
1+
# @op-engineering/op-s2
22

33
Modern secure storage for React Native
44

55
## Installation
66

77
```sh
8-
npm install @op-engineering/op-secure-storage
8+
npm install @op-engineering/op-s2
99
```
1010

1111
## Usage
1212

1313
```js
14-
import { multiply } from '@op-engineering/op-secure-storage';
14+
import { multiply } from '@op-engineering/op-s2';
1515

1616
// ...
1717

android/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ set (CMAKE_CXX_STANDARD 11)
55

66
add_library(cpp
77
SHARED
8-
../cpp/op-engineering-op-secure-storage.cpp
8+
../cpp/op-engineering-op-s2.cpp
99
cpp-adapter.cpp
1010
)
1111

android/cpp-adapter.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include <jni.h>
2-
#include "op-engineering-op-secure-storage.h"
2+
#include "op-engineering-op-s2.h"
33

44
extern "C"
55
JNIEXPORT jdouble JNICALL

bindings.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// bindings.m
3-
// op-engineering-op-secure-storage
3+
// op-engineering-op-s2
44
//
55
// Created by Oscar Franco on 19/11/23.
66
//

bindings.mm

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// bindings.m
3-
// op-engineering-op-secure-storage
3+
// op-engineering-op-s2
44
//
55
// Created by Oscar Franco on 19/11/23.
66
//

example/ios/Podfile.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ PODS:
1515
- hermes-engine/Pre-built (= 0.72.7)
1616
- hermes-engine/Pre-built (0.72.7)
1717
- libevent (2.1.12)
18-
- op-engineering-op-secure-storage (0.1.0):
18+
- op-s2 (0.1.0):
1919
- React
2020
- React-callinvoker
2121
- React-Core
@@ -440,7 +440,7 @@ DEPENDENCIES:
440440
- glog (from `../node_modules/react-native/third-party-podspecs/glog.podspec`)
441441
- hermes-engine (from `../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec`)
442442
- libevent (~> 2.1.12)
443-
- op-engineering-op-secure-storage (from `../..`)
443+
- op-s2 (from `../..`)
444444
- RCT-Folly (from `../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec`)
445445
- RCTRequired (from `../node_modules/react-native/Libraries/RCTRequired`)
446446
- RCTTypeSafety (from `../node_modules/react-native/Libraries/TypeSafety`)
@@ -496,7 +496,7 @@ EXTERNAL SOURCES:
496496
hermes-engine:
497497
:podspec: "../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec"
498498
:tag: hermes-2023-08-07-RNv0.72.4-813b2def12bc9df02654b3e3653ae4a68d0572e0
499-
op-engineering-op-secure-storage:
499+
op-s2:
500500
:path: "../.."
501501
RCT-Folly:
502502
:podspec: "../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec"
@@ -574,7 +574,7 @@ SPEC CHECKSUMS:
574574
glog: 04b94705f318337d7ead9e6d17c019bd9b1f6b1b
575575
hermes-engine: 9180d43df05c1ed658a87cc733dc3044cf90c00a
576576
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
577-
op-engineering-op-secure-storage: ef870bfb97322b24e7d840135cf82b346a672ad0
577+
op-s2: 33a609d9c229139086c89a1adfd25015da16af96
578578
RCT-Folly: 424b8c9a7a0b9ab2886ffe9c3b041ef628fd4fb1
579579
RCTRequired: 83bca1c184feb4d2e51c72c8369b83d641443f95
580580
RCTTypeSafety: 13c4a87a16d7db6cd66006ce9759f073402ef85b

example/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@op-engineering/op-secure-storage-example",
2+
"name": "@op-engineering/op-s2-example",
33
"version": "0.0.1",
44
"private": true,
55
"scripts": {

example/src/App.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22

33
import { StyleSheet, View, Text } from 'react-native';
4-
import { multiply } from '@op-engineering/op-secure-storage';
4+
import { multiply } from '@op-engineering/op-s2';
55

66
export default function App() {
77
const [result, setResult] = React.useState<number | undefined>();

ios/bindings.mm

+100-102
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ SecAccessControlRef getBioSecAccessControl() {
3737
nil); // Error pointer
3838
}
3939

40-
NSMutableDictionary* newDefaultDictionary(NSString *key) {
40+
NSMutableDictionary* newDefaultDictionary(std::string key) {
4141
NSMutableDictionary* queryDictionary = [[NSMutableDictionary alloc] init];
4242
[queryDictionary setObject:(id)kSecClassGenericPassword forKey:(id)kSecClass];
43-
NSData *encodedIdentifier = [key dataUsingEncoding:NSUTF8StringEncoding];
43+
NSData *encodedIdentifier = [NSData dataWithBytes:key.data() length:key.length()];
4444
[queryDictionary setObject:encodedIdentifier forKey:(id)kSecAttrGeneric];
4545
[queryDictionary setObject:encodedIdentifier forKey:(id)kSecAttrAccount];
4646
[queryDictionary setObject:[[NSBundle mainBundle] bundleIdentifier] forKey:(id)kSecAttrService];
@@ -72,7 +72,7 @@ CFStringRef getAccessibilityValue(int accessibility) {
7272
void _delete(std::string &key, bool withBiometrics) {
7373
NSMutableDictionary *dict = newDefaultDictionary(key);
7474
if(withBiometrics) {
75-
[dict setObject:(__bridge id)[self getBioSecAccessControl] forKey:(id)kSecAttrAccessControl];
75+
// [dict setObject:(__bridge id)[self getBioSecAccessControl] forKey:(id)kSecAttrAccessControl];
7676
}
7777
SecItemDelete((CFDictionaryRef)dict);
7878
}
@@ -112,135 +112,133 @@ void install(jsi::Runtime &rt, std::shared_ptr<react::CallInvoker> jsCallInvoker
112112

113113
bool withBiometrics = false;
114114

115-
if(params.hasProperty(rt, "biometricAuthentication")) {
116-
withBiometrics = params.getProperty(rt, "biometricAuthentication").asBool();
115+
if(params.hasProperty(rt, "withBiometrics")) {
116+
withBiometrics = params.getProperty(rt, "withBiometrics").asBool();
117117
}
118118

119-
120119
_delete(key, withBiometrics);
121120

122-
NSMutableDictionary *dict = [self newDefaultDictionary:key];
121+
NSMutableDictionary *dict = newDefaultDictionary(key);
123122

124123
// kSecAttrAccessControl is mutually excluse with kSecAttrAccessible
125124
// https://mobile-security.gitbook.io/mobile-security-testing-guide/ios-testing-guide/0x06f-testing-local-authentication
126125
if(withBiometrics) {
127-
[dict setObject:(__bridge_transfer id)[self getBioSecAccessControl] forKey:(id)kSecAttrAccessControl];
126+
[dict setObject:(__bridge_transfer id)getBioSecAccessControl() forKey:(id)kSecAttrAccessControl];
128127
} else {
129128
[dict setObject:(__bridge id)accessibility forKey:(id)kSecAttrAccessible];
130129
}
131130

132-
NSData* valueData = [value dataUsingEncoding:NSUTF8StringEncoding];
133-
[dict setObject:valueData forKey:(id)kSecValueData];
131+
// NSData* valueData = [value dataUsingEncoding:NSUTF8StringEncoding];
132+
NSData* data = [NSData dataWithBytes:val.data() length:val.length()];
133+
[dict setObject:data forKey:(id)kSecValueData];
134134

135135
OSStatus status = SecItemAdd((CFDictionaryRef)dict, NULL);
136136

137+
auto res = jsi::Object(rt);
138+
137139
if (status == noErr) {
138-
return @{};
140+
return res;
139141
}
142+
143+
auto errorStr = jsi::String::createFromUtf8(rt, "op-s2 could not set value, error code: " + std::to_string(status));
144+
145+
res.setProperty(rt, "error", errorStr);
146+
147+
return res;
148+
});
140149

141-
return @{
142-
@"error": @"Could not save value",
143-
};
144-
return {};
150+
auto get = HOSTFN("get", 1) {
151+
if(count < 1) {
152+
throw jsi::JSError(rt, "Params object is missing");
153+
}
154+
155+
if(!args[0].isObject()) {
156+
throw jsi::JSError(rt, "Params must be an object with key and value");
157+
}
158+
159+
jsi::Object params = args[0].asObject(rt);
160+
161+
if(!params.hasProperty(rt, "key")) {
162+
throw jsi::JSError(rt, "key property is missing");
163+
}
164+
165+
std::string key = params.getProperty(rt, "key").asString(rt).utf8(rt);
166+
167+
bool withBiometrics = false;
168+
169+
if(params.hasProperty(rt, "withBiometrics")) {
170+
withBiometrics = params.getProperty(rt, "withBiometrics").asBool();
171+
}
172+
173+
NSMutableDictionary *dict = newDefaultDictionary(key);
174+
175+
[dict setObject:(id)kSecMatchLimitOne forKey:(id)kSecMatchLimit];
176+
[dict setObject:(id)kCFBooleanTrue forKey:(id)kSecReturnData];
177+
178+
auto res = jsi::Object(rt);
179+
180+
if(withBiometrics) {
181+
BiometricsState biometricsState = getBiometricsState();
182+
LAContext *authContext = [[LAContext alloc] init];
183+
184+
// If device has no passcode/faceID/touchID then wallet-core cannot read the value from memory
185+
if(biometricsState == kBiometricsStateNotAvailable) {
186+
auto errorStr = jsi::String::createFromUtf8(rt, "Biometrics not available");
187+
188+
res.setProperty(rt, "error", errorStr);
189+
190+
return res;
191+
}
192+
193+
if(biometricsState == kBiometricsStateLocked) {
194+
195+
// TODO receiving a localized string might be necessary if this is happening on production
196+
[authContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
197+
localizedReason:@"You need to unlock your device"
198+
reply:^(BOOL success, NSError *error) {
199+
if (!success) {
200+
// Edge case when device might locked out after too many password attempts
201+
// User has failed to authenticate, but due to this being a callback cannot interrupt upper lexical scope
202+
// We should somehow prompt/tell the user that it has failed to authenticate
203+
// and wallet could not be loaded
204+
}
205+
}];
206+
}
207+
208+
[dict setObject:(__bridge id) getBioSecAccessControl() forKey:(id)kSecAttrAccessControl];
209+
}
210+
211+
CFDataRef dataResult = nil;
212+
OSStatus status = SecItemCopyMatching((CFDictionaryRef)dict, (CFTypeRef*) &dataResult);
213+
214+
215+
if (status == noErr) {
216+
NSData* result = (__bridge NSData*) dataResult;
217+
// std::string val = std::string(static_cast<const char*>(result.bytes), result.length);
218+
NSString* returnString = [[NSString alloc] initWithData:result encoding:NSUTF8StringEncoding];
219+
res.setProperty(rt, "value", [returnString UTF8String]);
220+
return res;
221+
}
222+
223+
auto errorStr = jsi::String::createFromUtf8(rt, "op-s2 could not set value, error code: " + std::to_string(status));
224+
225+
res.setProperty(rt, "error", errorStr);
226+
227+
return res;
145228
});
146229

147230
jsi::Object module = jsi::Object(rt);
148231

149232
module.setProperty(rt, "set", std::move(set));
233+
module.setProperty(rt, "get", std::move(get));
150234

151235
rt.global().setProperty(rt, "__OPSecureStoreProxy", std::move(module));
152236
}
153237
}
154238

155239

156240
//
157-
//- (NSDictionary *)setItem:(NSString *)key value:(NSString *)value options:(JS::NativeTurboSecureStorage::SpecSetItemOptions &)options
158-
//{
159-
// CFStringRef accessibility = kSecAttrAccessibleAfterFirstUnlock;
160-
//
161-
// if(options.accessibility()) {
162-
// accessibility = [self getAccessibilityValue:options.accessibility()];
163-
// }
164-
//
165-
// bool withBiometrics = options.biometricAuthentication().value();
166-
//
167-
// [self innerDelete:key withBiometrics:withBiometrics];
168-
//
169-
// NSMutableDictionary *dict = [self newDefaultDictionary:key];
170-
//
171-
// // kSecAttrAccessControl is mutually excluse with kSecAttrAccessible
172-
// // https://mobile-security.gitbook.io/mobile-security-testing-guide/ios-testing-guide/0x06f-testing-local-authentication
173-
// if(withBiometrics) {
174-
// [dict setObject:(__bridge_transfer id)[self getBioSecAccessControl] forKey:(id)kSecAttrAccessControl];
175-
// } else {
176-
// [dict setObject:(__bridge id)accessibility forKey:(id)kSecAttrAccessible];
177-
// }
178-
//
179-
// NSData* valueData = [value dataUsingEncoding:NSUTF8StringEncoding];
180-
// [dict setObject:valueData forKey:(id)kSecValueData];
181-
//
182-
// OSStatus status = SecItemAdd((CFDictionaryRef)dict, NULL);
183-
//
184-
// if (status == noErr) {
185-
// return @{};
186-
// }
187-
//
188-
// return @{
189-
// @"error": @"Could not save value",
190-
// };
191-
//}
192-
//
193-
//- (NSDictionary *)getItem:(NSString *)key options:(JS::NativeTurboSecureStorage::SpecGetItemOptions &)options {
194-
// NSMutableDictionary *dict = [self newDefaultDictionary:key];
195-
//
196-
// [dict setObject:(id)kSecMatchLimitOne forKey:(id)kSecMatchLimit];
197-
// [dict setObject:(id)kCFBooleanTrue forKey:(id)kSecReturnData];
198-
//
199-
// if(options.biometricAuthentication()) {
200-
// BiometricsState biometricsState = getBiometricsState();
201-
// LAContext *authContext = [[LAContext alloc] init];
202-
//
203-
// // If device has no passcode/faceID/touchID then wallet-core cannot read the value from memory
204-
// if(biometricsState == kBiometricsStateNotAvailable) {
205-
// return @{
206-
// @"error": @"Biometrics not available"
207-
// };
208-
// }
209-
//
210-
// if(biometricsState == kBiometricsStateLocked) {
211-
//
212-
// // TODO receiving a localized string might be necessary if this is happening on production
213-
// [authContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
214-
// localizedReason:@"You need to unlock your device"
215-
// reply:^(BOOL success, NSError *error) {
216-
// if (!success) {
217-
// // Edge case when device might locked out after too many password attempts
218-
// // User has failed to authenticate, but due to this being a callback cannot interrupt upper lexical scope
219-
// // We should somehow prompt/tell the user that it has failed to authenticate
220-
// // and wallet could not be loaded
221-
// }
222-
// }];
223-
// }
224-
//
225-
// [dict setObject:(__bridge id)[self getBioSecAccessControl] forKey:(id)kSecAttrAccessControl];
226-
// }
227-
//
228-
// CFDataRef dataResult = nil;
229-
// OSStatus status = SecItemCopyMatching((CFDictionaryRef)dict, (CFTypeRef*) &dataResult);
230-
//
231-
// if (status == noErr) {
232-
// NSData* result = (__bridge NSData*) dataResult;
233-
// NSString* returnString = [[NSString alloc] initWithData:result encoding:NSUTF8StringEncoding];
234-
//
235-
// return @{
236-
// @"value": returnString
237-
// };
238-
// }
239-
//
240-
// return @{
241-
// @"error": @"Could not get value"
242-
// };
243-
//}
241+
244242

245243
//
246244
//- (NSDictionary *)deleteItem:(NSString *)key options:(JS::NativeTurboSecureStorage::SpecDeleteItemOptions &)options {

op-engineering-op-secure-storage.podspec op-s2.podspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
44
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
55

66
Pod::Spec.new do |s|
7-
s.name = "op-engineering-op-secure-storage"
7+
s.name = "op-s2"
88
s.version = package["version"]
99
s.summary = package["description"]
1010
s.homepage = package["homepage"]
1111
s.license = package["license"]
1212
s.authors = package["author"]
1313

1414
s.platforms = { :ios => "12.0" }
15-
s.source = { :git => "https://github.com/OP-Engineering/op-secure-storage.git", :tag => "#{s.version}" }
15+
s.source = { :git => "https://github.com/OP-Engineering/op-s2.git", :tag => "#{s.version}" }
1616

1717
s.pod_target_xcconfig = {
1818
:WARNING_CFLAGS => "-Wno-shorten-64-to-32 -Wno-comma -Wno-unreachable-code -Wno-conditional-uninitialized -Wno-deprecated-declarations",

0 commit comments

Comments
 (0)