Skip to content

Commit bcead70

Browse files
authored
Merge pull request #1 from youngmonkeys/dev
Dev SSL
2 parents 541b1a4 + c280fa8 commit bcead70

32 files changed

+835
-85
lines changed

android/socket/src/main/java/com/tvd12/ezyfoxerver/client/EzyClientProxy.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@
88
import com.tvd12.ezyfoxerver.client.proxy.EzyConnectMethod;
99
import com.tvd12.ezyfoxerver.client.proxy.EzyCreateClientMethod;
1010
import com.tvd12.ezyfoxerver.client.proxy.EzyDisconnectMethod;
11+
import com.tvd12.ezyfoxerver.client.proxy.EzyGenerateKeyPairMethod;
12+
import com.tvd12.ezyfoxerver.client.proxy.EzyLogMethod;
1113
import com.tvd12.ezyfoxerver.client.proxy.EzyMethodProxy;
1214
import com.tvd12.ezyfoxerver.client.proxy.EzyReconnectMethod;
15+
import com.tvd12.ezyfoxerver.client.proxy.EzyRsaDecryptMethod;
1316
import com.tvd12.ezyfoxerver.client.proxy.EzySendMethod;
17+
import com.tvd12.ezyfoxerver.client.proxy.EzySetSessionKeyMethod;
1418
import com.tvd12.ezyfoxerver.client.proxy.EzySetStatusMethod;
1519
import com.tvd12.ezyfoxerver.client.proxy.EzyStartPingScheduleMethod;
1620
import com.tvd12.ezyfoxserver.client.socket.EzyMainEventsLoop;
@@ -92,6 +96,10 @@ private void addDefaultMethods() {
9296
addMethod(new EzySendMethod());
9397
addMethod(new EzySetStatusMethod());
9498
addMethod(new EzyStartPingScheduleMethod());
99+
addMethod(new EzyGenerateKeyPairMethod());
100+
addMethod(new EzyRsaDecryptMethod());
101+
addMethod(new EzyLogMethod());
102+
addMethod(new EzySetSessionKeyMethod());
95103
}
96104

97105
private void addMethod(EzyMethodProxy method) {

android/socket/src/main/java/com/tvd12/ezyfoxerver/client/EzyMethodNames.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ public final class EzyMethodNames {
1313
public static final String METHOD_RECONNECT = "reconnect";
1414
public static final String METHOD_SET_STATUS = "setStatus";
1515
public static final String METHOD_START_PING_SCHEDULE = "startPingSchedule";
16+
public static final String METHOD_GENERATE_KEY_PAIR = "generateKeyPair";
17+
public static final String METHOD_RSA_DECRYPT = "rsaDecrypt";
18+
public static final String METHOD_LOG = "log";
19+
public static final String METHOD_SET_SESSION_KEY = "setSessionKey";
1620

1721
private EzyMethodNames() {
1822
}

android/socket/src/main/java/com/tvd12/ezyfoxerver/client/proxy/EzyCreateClientMethod.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ private EzyClientConfig newConfig(Map params) {
5858
configBuilder.clientName((String) params.get("clientName"));
5959
if(params.containsKey("zoneName"))
6060
configBuilder.zoneName((String) params.get("zoneName"));
61+
if(params.containsKey("enableSSL"))
62+
configBuilder.enableSSL((Boolean) params.get("enableSSL"));
63+
if(params.containsKey("enableDebug"))
64+
configBuilder.enableDebug((Boolean) params.get("enableDebug"));
6165
if(params.containsKey("reconnect")) {
6266
Map reconnect = (Map) params.get("reconnect");
6367
EzyReconnectConfig.Builder reconnectConfigBuilder = configBuilder.reconnectConfigBuilder();
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.tvd12.ezyfoxerver.client.proxy;
2+
3+
import com.tvd12.ezyfoxerver.client.EzyMethodNames;
4+
import com.tvd12.ezyfoxserver.client.EzyClient;
5+
import com.tvd12.ezyfoxserver.client.constant.EzyConnectionStatus;
6+
import com.tvd12.ezyfoxserver.client.sercurity.EzyKeysGenerator;
7+
8+
import java.security.KeyPair;
9+
import java.util.HashMap;
10+
import java.util.Map;
11+
12+
/**
13+
* Created by tavandung12 on 10/25/18.
14+
*/
15+
16+
public class EzyGenerateKeyPairMethod extends EzyMethodProxy {
17+
@Override
18+
public Object invoke(Map params) {
19+
KeyPair keyPair = EzyKeysGenerator.builder()
20+
.build()
21+
.generate();
22+
byte[] publicKey = keyPair.getPublic().getEncoded();
23+
byte[] privateKey = keyPair.getPrivate().getEncoded();
24+
Map<String, byte[]> answer = new HashMap<>();
25+
answer.put("publicKey", publicKey);
26+
answer.put("privateKey", privateKey);
27+
return answer;
28+
}
29+
30+
@Override
31+
public String getName() {
32+
return EzyMethodNames.METHOD_GENERATE_KEY_PAIR;
33+
}
34+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.tvd12.ezyfoxerver.client.proxy;
2+
3+
import com.tvd12.ezyfoxerver.client.EzyMethodNames;
4+
import com.tvd12.ezyfoxserver.client.logger.EzyLogger;
5+
import com.tvd12.ezyfoxserver.client.sercurity.EzyAsyCrypt;
6+
7+
import java.util.Map;
8+
9+
/**
10+
* Created by tavandung12 on 10/25/18.
11+
*/
12+
13+
public class EzyLogMethod extends EzyMethodProxy {
14+
@Override
15+
public Object invoke(Map params) throws Exception {
16+
String level = (String)params.getOrDefault("level", "i");
17+
String message = (String)params.get("message");
18+
if(level.equals("w")) {
19+
EzyLogger.warn(message);
20+
}
21+
else if(level.equals("e")) {
22+
EzyLogger.error(message);
23+
}
24+
else if(level.equals("d")) {
25+
EzyLogger.debug(message);
26+
}
27+
else {
28+
EzyLogger.info(message);
29+
}
30+
return Boolean.TRUE;
31+
}
32+
33+
@Override
34+
public String getName() {
35+
return EzyMethodNames.METHOD_LOG;
36+
}
37+
}

android/socket/src/main/java/com/tvd12/ezyfoxerver/client/proxy/EzyMethodProxy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public abstract class EzyMethodProxy {
1313

1414
protected EzyClients clients = EzyClients.getInstance();
1515

16-
public abstract Object invoke(Map params);
16+
public abstract Object invoke(Map params) throws Exception;
1717
public abstract String getName();
1818

1919
public void validate(Map params) {}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.tvd12.ezyfoxerver.client.proxy;
2+
3+
import com.tvd12.ezyfoxerver.client.EzyMethodNames;
4+
import com.tvd12.ezyfoxserver.client.sercurity.EzyAsyCrypt;
5+
import com.tvd12.ezyfoxserver.client.sercurity.EzyKeysGenerator;
6+
7+
import java.security.KeyPair;
8+
import java.util.HashMap;
9+
import java.util.Map;
10+
11+
/**
12+
* Created by tavandung12 on 10/25/18.
13+
*/
14+
15+
public class EzyRsaDecryptMethod extends EzyMethodProxy {
16+
@Override
17+
public Object invoke(Map params) throws Exception {
18+
byte[] message = (byte[])params.get("message");
19+
byte[] privateKey = (byte[])params.get("privateKey");
20+
return EzyAsyCrypt.builder()
21+
.privateKey(privateKey)
22+
.build()
23+
.decrypt(message);
24+
}
25+
26+
@Override
27+
public String getName() {
28+
return EzyMethodNames.METHOD_RSA_DECRYPT;
29+
}
30+
}

android/socket/src/main/java/com/tvd12/ezyfoxerver/client/proxy/EzySendMethod.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ public Object invoke(Map params) {
2626
Map request = (Map) params.get("request");
2727
String cmd = (String) request.get("command");
2828
List data = (List) request.get("data");
29+
boolean encrypted = (Boolean)request.getOrDefault("encrypted", false);
2930
EzyArray array = EzyNativeSerializers.fromList(data);
30-
client.send(EzyCommand.valueOf(cmd), array);
31+
client.send(EzyCommand.valueOf(cmd), array, encrypted);
3132
return Boolean.TRUE;
3233
}
3334

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.tvd12.ezyfoxerver.client.proxy;
2+
3+
import com.tvd12.ezyfoxerver.client.EzyMethodNames;
4+
import com.tvd12.ezyfoxserver.client.EzyClient;
5+
import com.tvd12.ezyfoxserver.client.logger.EzyLogger;
6+
7+
import java.util.Map;
8+
9+
/**
10+
* Created by tavandung12 on 10/25/18.
11+
*/
12+
13+
public class EzySetSessionKeyMethod extends EzyMethodProxy {
14+
@Override
15+
public Object invoke(Map params) throws Exception {
16+
EzyClient client = getClient(params);
17+
byte[] sessionKey = (byte[])params.get("sessionKey");
18+
client.setSessionKey(sessionKey);
19+
return Boolean.TRUE;
20+
}
21+
22+
@Override
23+
public String getName() {
24+
return EzyMethodNames.METHOD_SET_SESSION_KEY;
25+
}
26+
}

ios/Runner.xcodeproj/project.pbxproj

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@
8080
F17E475F269A6C4F00668CED /* EzyUTSocketClient.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F17E470D269A6C4F00668CED /* EzyUTSocketClient.cpp */; };
8181
F17E4760269A6C4F00668CED /* EzyUdpSocketClient.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F17E470E269A6C4F00668CED /* EzyUdpSocketClient.cpp */; };
8282
F17E4761269A6C4F00668CED /* EzySocketWriter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F17E470F269A6C4F00668CED /* EzySocketWriter.cpp */; };
83+
F17E476726A2BFF700668CED /* NSByArray.m in Sources */ = {isa = PBXBuildFile; fileRef = F17E476626A2BFF700668CED /* NSByArray.m */; };
84+
F17E476B26A2C00300668CED /* EzyEncryptionProxy.mm in Sources */ = {isa = PBXBuildFile; fileRef = F17E476A26A2C00300668CED /* EzyEncryptionProxy.mm */; };
85+
F17E476F26A2C01500668CED /* EzyNSNumber.m in Sources */ = {isa = PBXBuildFile; fileRef = F17E476D26A2C01500668CED /* EzyNSNumber.m */; };
8386
/* End PBXBuildFile section */
8487

8588
/* Begin PBXContainerItemProxy section */
@@ -275,6 +278,12 @@
275278
F17E470E269A6C4F00668CED /* EzyUdpSocketClient.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EzyUdpSocketClient.cpp; sourceTree = "<group>"; };
276279
F17E470F269A6C4F00668CED /* EzySocketWriter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EzySocketWriter.cpp; sourceTree = "<group>"; };
277280
F17E4710269A6C4F00668CED /* EzyMainEventsLoop.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EzyMainEventsLoop.h; sourceTree = "<group>"; };
281+
F17E476426A2BFF700668CED /* NSByteArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSByteArray.h; sourceTree = "<group>"; };
282+
F17E476626A2BFF700668CED /* NSByArray.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSByArray.m; sourceTree = "<group>"; };
283+
F17E476926A2C00300668CED /* EzyEncryptionProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EzyEncryptionProxy.h; sourceTree = "<group>"; };
284+
F17E476A26A2C00300668CED /* EzyEncryptionProxy.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = EzyEncryptionProxy.mm; sourceTree = "<group>"; };
285+
F17E476D26A2C01500668CED /* EzyNSNumber.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EzyNSNumber.m; sourceTree = "<group>"; };
286+
F17E476E26A2C01500668CED /* EzyNSNumber.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EzyNSNumber.h; sourceTree = "<group>"; };
278287
/* End PBXFileReference section */
279288

280289
/* Begin PBXFrameworksBuildPhase section */
@@ -343,16 +352,18 @@
343352
F17E4655269A6C4E00668CED /* client */ = {
344353
isa = PBXGroup;
345354
children = (
355+
F17E476C26A2C01500668CED /* math */,
356+
F17E476826A2C00300668CED /* codec */,
346357
F17E4656269A6C4E00668CED /* serializer */,
347358
F17E4662269A6C4E00668CED /* proxy */,
348359
F17E4665269A6C4E00668CED /* util */,
349-
F17E4668269A6C4E00668CED /* EzyMethodNames.h */,
350360
F17E4669269A6C4E00668CED /* Prefix.pch */,
351361
F17E466B269A6C4E00668CED /* EzyClientProxy.mm */,
362+
F17E4671269A6C4E00668CED /* EzyClientProxy.h */,
352363
F17E466C269A6C4E00668CED /* AppConfigDefine.h */,
353364
F17E466D269A6C4E00668CED /* EzyMethodNames.mm */,
365+
F17E4668269A6C4E00668CED /* EzyMethodNames.h */,
354366
F17E466E269A6C4E00668CED /* exception */,
355-
F17E4671269A6C4E00668CED /* EzyClientProxy.h */,
356367
F17E4672269A6C4E00668CED /* socket */,
357368
);
358369
path = client;
@@ -389,6 +400,8 @@
389400
children = (
390401
F17E4666269A6C4E00668CED /* EzyNativeStrings.mm */,
391402
F17E4667269A6C4E00668CED /* EzyNativeStrings.h */,
403+
F17E476626A2BFF700668CED /* NSByArray.m */,
404+
F17E476426A2BFF700668CED /* NSByteArray.h */,
392405
);
393406
path = util;
394407
sourceTree = "<group>";
@@ -727,6 +740,24 @@
727740
path = socket;
728741
sourceTree = "<group>";
729742
};
743+
F17E476826A2C00300668CED /* codec */ = {
744+
isa = PBXGroup;
745+
children = (
746+
F17E476926A2C00300668CED /* EzyEncryptionProxy.h */,
747+
F17E476A26A2C00300668CED /* EzyEncryptionProxy.mm */,
748+
);
749+
path = codec;
750+
sourceTree = "<group>";
751+
};
752+
F17E476C26A2C01500668CED /* math */ = {
753+
isa = PBXGroup;
754+
children = (
755+
F17E476D26A2C01500668CED /* EzyNSNumber.m */,
756+
F17E476E26A2C01500668CED /* EzyNSNumber.h */,
757+
);
758+
path = math;
759+
sourceTree = "<group>";
760+
};
730761
/* End PBXGroup section */
731762

732763
/* Begin PBXNativeTarget section */
@@ -756,7 +787,7 @@
756787
97C146E61CF9000F007C117D /* Project object */ = {
757788
isa = PBXProject;
758789
attributes = {
759-
LastUpgradeCheck = 1020;
790+
LastUpgradeCheck = 1250;
760791
ORGANIZATIONNAME = "";
761792
TargetAttributes = {
762793
97C146ED1CF9000F007C117D = {
@@ -862,6 +893,7 @@
862893
F17E4740269A6C4F00668CED /* EzyDataDecoder.cpp in Sources */,
863894
F17E475D269A6C4F00668CED /* EzySocketPool.cpp in Sources */,
864895
F17E472A269A6C4F00668CED /* EzyDataHandlers.cpp in Sources */,
896+
F17E476B26A2C00300668CED /* EzyEncryptionProxy.mm in Sources */,
865897
F17E4750269A6C4F00668CED /* EzyReleasePool.cpp in Sources */,
866898
F17E472E269A6C4F00668CED /* EzyPluginDataHandler.cpp in Sources */,
867899
F17E473F269A6C4F00668CED /* EzyMessage.cpp in Sources */,
@@ -874,6 +906,7 @@
874906
F17E4752269A6C4F00668CED /* EzyRequest.cpp in Sources */,
875907
F17E472D269A6C4F00668CED /* EzyPluginDataHandlers.cpp in Sources */,
876908
F17E473D269A6C4F00668CED /* EzyUser.cpp in Sources */,
909+
F17E476F26A2C01500668CED /* EzyNSNumber.m in Sources */,
877910
F17E4714269A6C4F00668CED /* EzyNativeDataSerializer.mm in Sources */,
878911
F17E4736269A6C4F00668CED /* EzyZone.cpp in Sources */,
879912
F17E4749269A6C4F00668CED /* EzyPingManager.cpp in Sources */,
@@ -906,6 +939,7 @@
906939
F17E4757269A6C4F00668CED /* EzyTcpSocketClient.cpp in Sources */,
907940
F17E4746269A6C4F00668CED /* EzyPluginManager.cpp in Sources */,
908941
F17E471E269A6C4F00668CED /* EzyMethodCallException.mm in Sources */,
942+
F17E476726A2BFF700668CED /* NSByArray.m in Sources */,
909943
F17E472B269A6C4F00668CED /* EzyEventHandler.cpp in Sources */,
910944
F17E4739269A6C4F00668CED /* EzyNull.cpp in Sources */,
911945
F17E4747269A6C4F00668CED /* EzyAppManager.cpp in Sources */,
@@ -966,6 +1000,7 @@
9661000
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
9671001
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
9681002
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
1003+
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
9691004
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
9701005
CLANG_WARN_STRICT_PROTOTYPES = YES;
9711006
CLANG_WARN_SUSPICIOUS_MOVE = YES;
@@ -984,7 +1019,7 @@
9841019
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
9851020
GCC_WARN_UNUSED_FUNCTION = YES;
9861021
GCC_WARN_UNUSED_VARIABLE = YES;
987-
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
1022+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
9881023
MTL_ENABLE_DEBUG_INFO = NO;
9891024
SDKROOT = iphoneos;
9901025
SUPPORTED_PLATFORMS = iphoneos;
@@ -1039,6 +1074,7 @@
10391074
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
10401075
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
10411076
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
1077+
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
10421078
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
10431079
CLANG_WARN_STRICT_PROTOTYPES = YES;
10441080
CLANG_WARN_SUSPICIOUS_MOVE = YES;
@@ -1063,7 +1099,7 @@
10631099
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
10641100
GCC_WARN_UNUSED_FUNCTION = YES;
10651101
GCC_WARN_UNUSED_VARIABLE = YES;
1066-
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
1102+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
10671103
MTL_ENABLE_DEBUG_INFO = YES;
10681104
ONLY_ACTIVE_ARCH = YES;
10691105
SDKROOT = iphoneos;
@@ -1094,6 +1130,7 @@
10941130
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
10951131
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
10961132
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
1133+
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
10971134
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
10981135
CLANG_WARN_STRICT_PROTOTYPES = YES;
10991136
CLANG_WARN_SUSPICIOUS_MOVE = YES;
@@ -1112,7 +1149,7 @@
11121149
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
11131150
GCC_WARN_UNUSED_FUNCTION = YES;
11141151
GCC_WARN_UNUSED_VARIABLE = YES;
1115-
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
1152+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
11161153
MTL_ENABLE_DEBUG_INFO = NO;
11171154
SDKROOT = iphoneos;
11181155
SUPPORTED_PLATFORMS = iphoneos;

0 commit comments

Comments
 (0)