Skip to content

Commit

Permalink
update ssl
Browse files Browse the repository at this point in the history
  • Loading branch information
tvd12 committed Jul 23, 2021
1 parent c280fa8 commit b69ab2b
Show file tree
Hide file tree
Showing 14 changed files with 137 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Podfile.lock
# Miscellaneous
*.class
*.log
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

flutter client for [ezyfox server](https://github.com/youngmonkeys/ezyfox-server)

# Architecture

<img src="https://raw.githubusercontent.com/youngmonkeys/ezyfox-server-flutter-client/master/images/flutter-sdk.png" />

# Prepare

1. Download and install [JDK 8](https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html)
Expand All @@ -24,16 +28,16 @@ [email protected]:youngmonkeys/ezyfox-server-flutter-client.git
git submodule update --remote --recursive
```

### 3. Import source code:
### 3. Import source code

- To IntelliJ IDE: for all
- To Xcode: for iOS
- To Android studio: for Android

### 4. You can run:
### 4. You can run

- [main.dart](https://github.com/youngmonkeys/ezyfox-server-flutter-client/blob/master/lib/main.dart) on Intellij
- Build and Run on Xcode for iOS
- Build and Run on Xcode for iOS, don't for get run `pod install`
- Build and run on Android Studio for Android

### 5. Where need I click?
Expand Down
Binary file added images/flutter-sdk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions ios/Flutter/Debug.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include "Generated.xcconfig"
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
1 change: 1 addition & 0 deletions ios/Flutter/Release.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include "Generated.xcconfig"
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
12 changes: 12 additions & 0 deletions ios/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

target 'Runner' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!

# Pods for Runner

pod 'OpenSSL-Universal'

end
62 changes: 61 additions & 1 deletion ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 50;
objectVersion = 51;
objects = {

/* Begin PBXBuildFile section */
Expand All @@ -13,6 +13,7 @@
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; };
97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; };
D44C6451496F39C9524E09C3 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 30425E68A0587C2952C7A950 /* Pods_Runner.framework */; };
F17E4714269A6C4F00668CED /* EzyNativeDataSerializer.mm in Sources */ = {isa = PBXBuildFile; fileRef = F17E4657269A6C4E00668CED /* EzyNativeDataSerializer.mm */; };
F17E4715269A6C4F00668CED /* EzyClientConfigSerializer.mm in Sources */ = {isa = PBXBuildFile; fileRef = F17E4658269A6C4E00668CED /* EzyClientConfigSerializer.mm */; };
F17E4716269A6C4F00668CED /* EzyNativeDataDeserializer.mm in Sources */ = {isa = PBXBuildFile; fileRef = F17E465B269A6C4E00668CED /* EzyNativeDataDeserializer.mm */; };
Expand Down Expand Up @@ -109,9 +110,12 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
03332054315A3AE09980408C /* 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>"; };
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
30425E68A0587C2952C7A950 /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; };
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
6B2CC68C51353B6B50C55957 /* 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>"; };
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>"; };
Expand All @@ -122,6 +126,7 @@
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>"; };
B461B3840AFCB3A8BABC2A51 /* 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>"; };
F17E4657269A6C4E00668CED /* EzyNativeDataSerializer.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = EzyNativeDataSerializer.mm; sourceTree = "<group>"; };
F17E4658269A6C4E00668CED /* EzyClientConfigSerializer.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = EzyClientConfigSerializer.mm; sourceTree = "<group>"; };
F17E4659269A6C4E00668CED /* EzyNativeDataDeserializer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EzyNativeDataDeserializer.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -291,12 +296,23 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
D44C6451496F39C9524E09C3 /* Pods_Runner.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
2EE83825BB93B668DB4A8852 /* Pods */ = {
isa = PBXGroup;
children = (
B461B3840AFCB3A8BABC2A51 /* Pods-Runner.debug.xcconfig */,
6B2CC68C51353B6B50C55957 /* Pods-Runner.release.xcconfig */,
03332054315A3AE09980408C /* Pods-Runner.profile.xcconfig */,
);
path = Pods;
sourceTree = "<group>";
};
9740EEB11CF90186004384FC /* Flutter */ = {
isa = PBXGroup;
children = (
Expand All @@ -315,6 +331,7 @@
97C146F01CF9000F007C117D /* Runner */,
97C146EF1CF9000F007C117D /* Products */,
F17E46512699D40000668CED /* Frameworks */,
2EE83825BB93B668DB4A8852 /* Pods */,
);
sourceTree = "<group>";
};
Expand Down Expand Up @@ -345,6 +362,7 @@
F17E46512699D40000668CED /* Frameworks */ = {
isa = PBXGroup;
children = (
30425E68A0587C2952C7A950 /* Pods_Runner.framework */,
);
name = Frameworks;
sourceTree = "<group>";
Expand Down Expand Up @@ -765,12 +783,14 @@
isa = PBXNativeTarget;
buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */;
buildPhases = (
EC309B84265F1B993387303B /* [CP] Check Pods Manifest.lock */,
9740EEB61CF901F6004384FC /* Run Script */,
97C146EA1CF9000F007C117D /* Sources */,
97C146EB1CF9000F007C117D /* Frameworks */,
97C146EC1CF9000F007C117D /* Resources */,
9705A1C41CF9048500538489 /* Embed Frameworks */,
3B06AD1E1E4923F5004D2608 /* Thin Binary */,
25531C6403BEB076D77D440D /* [CP] Embed Pods Frameworks */,
);
buildRules = (
);
Expand Down Expand Up @@ -845,6 +865,23 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
25531C6403BEB076D77D440D /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Embed Pods Frameworks";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -873,6 +910,28 @@
shellPath = /bin/sh;
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build";
};
EC309B84265F1B993387303B /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
"${PODS_ROOT}/Manifest.lock",
);
name = "[CP] Check Pods Manifest.lock";
outputFileListPaths = (
);
outputPaths = (
"$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
Expand Down Expand Up @@ -1091,6 +1150,7 @@
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"EZY_SSL_ENABLE=1",
"$(inherited)",
);
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
Expand Down
3 changes: 3 additions & 0 deletions ios/Runner.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions ios/client/proxy/EzyMethodProxy.mm
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,10 @@ - (NSObject *)invoke:(NSDictionary *)params {
EzyClient* client = getClient(params);
NSString* cmd = [request objectForKey:@"command"];
NSArray* data = [request objectForKey:@"data"];
NSNumber* encrypted = [request objectForKey:@"encrypted"];
EzyArray* array = (EzyArray*)[EzyNativeSerializers fromReadableArray:data];
EzyCommand command = sNativeCommandIds[[cmd UTF8String]];
client->send(command, array);
client->send(command, array, [encrypted boolValue]);
return [NSNumber numberWithBool:TRUE];
}

Expand Down Expand Up @@ -348,10 +349,10 @@ @implementation EzyGenerateKeyPairMethod

- (NSObject *)invoke:(NSDictionary *)params {
EzyKeyPairProxy* keyPair = [[EzyRSAProxy getInstance] generateKeyPair];
NSData* publicKey = [[keyPair publicKey] dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:NO];
NSString* publicKey = [keyPair publicKey];
NSData* privateKey = [[keyPair privateKey] dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:NO];
NSDictionary* answer = [NSMutableDictionary dictionary];
[answer setValue:[FlutterStandardTypedData typedDataWithBytes:publicKey] forKey:@"publicKey"];
[answer setValue:publicKey forKey:@"publicKey"];
[answer setValue:[FlutterStandardTypedData typedDataWithBytes:privateKey] forKey:@"privateKey"];
return answer;
}
Expand Down
36 changes: 36 additions & 0 deletions ios/client/serializer/EzyNativeDataDeserializer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,42 @@ - (void)deserializeToArray:(EzyArray*)output value:(NSObject*)value {
NSData* realData = [data data];
output->addByteArray(std::string((char*)[realData bytes], [realData length]));
}
else if(dataType == FlutterStandardDataTypeInt32) {
EzyArray *array = new EzyArray();
NSData* realData = [data data];
int32_t* int32Array = (int32_t*)[realData bytes];
for(int i = 0 ; i < [realData length] ; ++i) {
array->addInt(int32Array[i]);
}
output->addArray(array);
}
else if(dataType == FlutterStandardDataTypeInt64) {
EzyArray *array = new EzyArray();
NSData* realData = [data data];
int64_t* int64Array = (int64_t*)[realData bytes];
for(int i = 0 ; i < [realData length] ; ++i) {
array->addInt(int64Array[i]);
}
output->addArray(array);
}
else if(dataType == FlutterStandardDataTypeFloat32) {
EzyArray *array = new EzyArray();
NSData* realData = [data data];
float* floatArray = (float*)[realData bytes];
for(int i = 0 ; i < [realData length] ; ++i) {
array->addFloat(floatArray[i]);
}
output->addArray(array);
}
else {
EzyArray *array = new EzyArray();
NSData* realData = [data data];
double* doubleArray = (double*)[realData bytes];
for(int i = 0 ; i < [realData length] ; ++i) {
array->addDouble(doubleArray[i]);
}
output->addArray(array);
}
}
else {
@throw [NSException exceptionWithName:@"NSInvalidArgumentException"
Expand Down
3 changes: 3 additions & 0 deletions ios/client/serializer/EzyNativeDataSerializer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ -(NSObject*)serializeValue:(EzyValue*)value {
return [NSNumber numberWithUnsignedLong:((EzyPrimitive*)value)->getUInt()];
case TypeString:
return [NSString stringWithUTF8String:((EzyString*)value)->getString().c_str()];
case TypeByteArray:
return [NSData dataWithBytes:((EzyByteArray*)value)->getData().c_str()
length:((EzyByteArray*)value)->getData().length()];
case TypeDict:
return [self toWritableMap:value];
case TypeArray:
Expand Down
6 changes: 2 additions & 4 deletions lib/ezyclient/ezy_codec.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import 'dart:typed_data';

import 'ezy_logger.dart';

import 'ezy_proxy.dart';

class EzyKeyPairProxy {
late Uint8List publicKey;
late String publicKey;
late Uint8List privateKey;

EzyKeyPairProxy(Uint8List publicKey, Uint8List privateKey) {
EzyKeyPairProxy(String publicKey, Uint8List privateKey) {
this.publicKey = publicKey;
this.privateKey = privateKey;
}
Expand Down
9 changes: 5 additions & 4 deletions lib/ezyclient/ezy_handlers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class EzyConnectionSuccessHandler extends EzyAbstractEventHandler {
});
}

List newHandshakeRequest(Uint8List? clientKey) {
List newHandshakeRequest(String? clientKey) {
var clientId = this.getClientId();
var token = this.getStoredToken();
var request = [];
Expand All @@ -69,7 +69,7 @@ class EzyConnectionSuccessHandler extends EzyAbstractEventHandler {
return request;
}

bool _isEnableSSL(Uint8List? clientKey) {
bool _isEnableSSL(String? clientKey) {
if(client.enableSSL &&
client.enableDebug &&
(clientKey == null || clientKey.isEmpty)) {
Expand All @@ -79,12 +79,12 @@ class EzyConnectionSuccessHandler extends EzyAbstractEventHandler {
}

void _onKeyPairGenerated(
EzyKeyPairProxy keyPair, Function(Uint8List?) callback) {
EzyKeyPairProxy keyPair, Function(String?) callback) {
client.privateKey = keyPair.privateKey;
callback(keyPair.publicKey);
}

void generateClientKey(Function(Uint8List?) callback) {
void generateClientKey(Function(String?) callback) {
if(client.enableSSL) {
EzyRSAProxy.getInstance().generateKeyPair((keyPair) =>
{
Expand Down Expand Up @@ -218,6 +218,7 @@ class EzyHandshakeHandler extends EzyAbstractDataHandler {

void decryptSessionKey(
Uint8List? encryptedSessionKey, Function(Uint8List?, bool) callback) {
EzyLogger.info("encryptedSessionKey: $encryptedSessionKey");
if(encryptedSessionKey == null) {
if(client.enableDebug) {
callback(null, true);
Expand Down
1 change: 1 addition & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class _MyHomePageState extends State<MyHomePage> {
});
}));
client.connect("tvd12.com", 3005);
// client.connect("127.0.0.1", 3005);
}

void _incrementCounter() {
Expand Down

0 comments on commit b69ab2b

Please sign in to comment.