Rusty Well-Known Member Licensed User Longtime User Feb 11, 2014 #1 Erel, We have been using the Release Obfuscated to compile our .apk's. One of my staff, decompiled the .apk and was readily able to read ALL of the code including "secret" keys. I am very concerned about this. In our code (for example) we store encryption keys: Code: Code: Sub Class_GlobalsDim Keys AsList Keys.Initialize Keys.add(ArrayAsByte(...,...,...)) Keys.add(ArrayAsByte(...,...,...)) Keys.add(ArrayAsByte(...,...,...))End Sub We compile it obfuscated... We use Dex2Jar on classes.dex; This creates a jar file; Then we use JD-gui to de-compile the jar; the results are: Code: Code: publicString _class_globals() throws Exception { this._vv1 = new List(); this._vv1.Initialize(); this._vv1.Add(new byte[] { ...,...,...}); this._vv1.Add(new byte[] { ...,...,... }); this._vv1.Add(new byte[] { ...,...,... });return""; } Is there anything we can do to hide this further? Alternatively, is there a process to "share" encryption keys from tablet to PC server that might be more secure? Thanks, Rusty
Erel, We have been using the Release Obfuscated to compile our .apk's. One of my staff, decompiled the .apk and was readily able to read ALL of the code including "secret" keys. I am very concerned about this. In our code (for example) we store encryption keys: Code: Code: Sub Class_GlobalsDim Keys AsList Keys.Initialize Keys.add(ArrayAsByte(...,...,...)) Keys.add(ArrayAsByte(...,...,...)) Keys.add(ArrayAsByte(...,...,...))End Sub We compile it obfuscated... We use Dex2Jar on classes.dex; This creates a jar file; Then we use JD-gui to de-compile the jar; the results are: Code: Code: publicString _class_globals() throws Exception { this._vv1 = new List(); this._vv1.Initialize(); this._vv1.Add(new byte[] { ...,...,...}); this._vv1.Add(new byte[] { ...,...,... }); this._vv1.Add(new byte[] { ...,...,... });return""; } Is there anything we can do to hide this further? Alternatively, is there a process to "share" encryption keys from tablet to PC server that might be more secure? Thanks, Rusty
eps Expert Licensed User Longtime User Feb 11, 2014 #2 Have you read this? http://www.b4x.com/android/forum/threads/android-code-obfuscation.13773/ Upvote 0
Rusty Well-Known Member Licensed User Longtime User Feb 11, 2014 #3 yes, did i miss something? I don't have an _ in the variables, they are global (to a class, is that a problem?) Upvote 0
yes, did i miss something? I don't have an _ in the variables, they are global (to a class, is that a problem?)
eps Expert Licensed User Longtime User Feb 11, 2014 #4 What are you expecting the obfuscator to do that it's not doing? I think it's mostly obvious, but if you are placing 'secret' keys in your code I don't think that this is a good practice. I also don't think that the obfuscator would touch those, it will only touch the variable names. This bit? Strings obfuscation Any string written in Process_Globals sub (and only in this sub) will be obfuscated, making it much harder to extract important keys. The strings are defuscated at runtime. Upvote 0
What are you expecting the obfuscator to do that it's not doing? I think it's mostly obvious, but if you are placing 'secret' keys in your code I don't think that this is a good practice. I also don't think that the obfuscator would touch those, it will only touch the variable names. This bit? Strings obfuscation Any string written in Process_Globals sub (and only in this sub) will be obfuscated, making it much harder to extract important keys. The strings are defuscated at runtime.
Rusty Well-Known Member Licensed User Longtime User Feb 11, 2014 #5 I guess I was expecting a lower level (like binary/machine code on a pc). It appears the android "compiles/interprets" source code when apps are running. If this is so, then anyone can hack the source code of an app...correct? I assume if I move the variables to the PROCESS_GLOBAL instead of CLASS_GLOBAL, the obfuscation will improve (from you last statement above). Given, obfuscation won't accomplish the security of keys embedded within, what is the proper way to handle encryption keys? e.g. Tablet encrypts data, sends to server (on pc), the server needs to be able to decrypt ... how can we share keys given the code; calculations; encryhption keys are viewable by anyone with those programs? Thanks, Rusty Upvote 0
I guess I was expecting a lower level (like binary/machine code on a pc). It appears the android "compiles/interprets" source code when apps are running. If this is so, then anyone can hack the source code of an app...correct? I assume if I move the variables to the PROCESS_GLOBAL instead of CLASS_GLOBAL, the obfuscation will improve (from you last statement above). Given, obfuscation won't accomplish the security of keys embedded within, what is the proper way to handle encryption keys? e.g. Tablet encrypts data, sends to server (on pc), the server needs to be able to decrypt ... how can we share keys given the code; calculations; encryhption keys are viewable by anyone with those programs? Thanks, Rusty
Erel B4X founder Staff member Licensed User Longtime User Feb 11, 2014 #6 I assume if I move the variables to the PROCESS_GLOBAL instead of CLASS_GLOBAL, the obfuscation will improve (from you last statement above). Click to expand... Only if the keys are strings. Otherwise they will remain as is (only the variable will be renamed). Upvote 0
I assume if I move the variables to the PROCESS_GLOBAL instead of CLASS_GLOBAL, the obfuscation will improve (from you last statement above). Click to expand... Only if the keys are strings. Otherwise they will remain as is (only the variable will be renamed).
Rusty Well-Known Member Licensed User Longtime User Feb 11, 2014 #7 Thanks Erel. I think I'm getting it...I hope instead of using byte arrays, if I use strings (string arrays ok?) to store the keys, AND they are in PROCESS_GLOBALS, they'll be obfuscated, right? Rusty Upvote 0
Thanks Erel. I think I'm getting it...I hope instead of using byte arrays, if I use strings (string arrays ok?) to store the keys, AND they are in PROCESS_GLOBALS, they'll be obfuscated, right? Rusty
Erel B4X founder Staff member Licensed User Longtime User Feb 11, 2014 #8 Yes. Any string that appears in Process_Globals sub will be obfuscated. Code: Sub Process_Globals Dim Keys() As String = Array As String("These", "strings", "will", "be", "obfuscated") Dim k As String = "This will also be obfuscated" Dim b() As Byte = "this too".GetBytes("UTF8") Upvote 0
Yes. Any string that appears in Process_Globals sub will be obfuscated. Code: Sub Process_Globals Dim Keys() As String = Array As String("These", "strings", "will", "be", "obfuscated") Dim k As String = "This will also be obfuscated" Dim b() As Byte = "this too".GetBytes("UTF8")
Rusty Well-Known Member Licensed User Longtime User Feb 11, 2014 #9 Thank you for putting up with me. It took me a bit to understand. I'll give this a try and report back if there are still issues. Thanks Erel. Rusty Upvote 0
Thank you for putting up with me. It took me a bit to understand. I'll give this a try and report back if there are still issues. Thanks Erel. Rusty
Rusty Well-Known Member Licensed User Longtime User Feb 11, 2014 #10 One last question. If I follow your above guidelines; move my CLASS_GLOBAL variables to the PROCESS_GLOBAL in the MAIN of my class definition as strings (instead of byte array), will the variables be obfuscated in the resultant class .jar? Rusty Upvote 0
One last question. If I follow your above guidelines; move my CLASS_GLOBAL variables to the PROCESS_GLOBAL in the MAIN of my class definition as strings (instead of byte array), will the variables be obfuscated in the resultant class .jar? Rusty
Erel B4X founder Staff member Licensed User Longtime User Feb 11, 2014 #11 will the variables be obfuscated in the resultant class .jar? Click to expand... Sorry but I'm not sure that I understand the question. Upvote 0
will the variables be obfuscated in the resultant class .jar? Click to expand... Sorry but I'm not sure that I understand the question.
Rusty Well-Known Member Licensed User Longtime User Feb 11, 2014 #12 Sorry, What I meant was: When I create a library (class), there is a MAIN required for it to be compiled. The Class, of course, is a "module" attached to the project. If I move the keys list or table to the MAIN module in the class project, then "compile to library", will the resultant .jar file (library) have the table obfuscated or will I need to move the key data into each application that uses the library (.jar file)? Rusty Upvote 0
Sorry, What I meant was: When I create a library (class), there is a MAIN required for it to be compiled. The Class, of course, is a "module" attached to the project. If I move the keys list or table to the MAIN module in the class project, then "compile to library", will the resultant .jar file (library) have the table obfuscated or will I need to move the key data into each application that uses the library (.jar file)? Rusty
Erel B4X founder Staff member Licensed User Longtime User Feb 11, 2014 #13 The string in the main activity will not be included in the compiled library. You cannot obfuscate strings in libraries. You will need to put the string in one of the project modules. Upvote 0
The string in the main activity will not be included in the compiled library. You cannot obfuscate strings in libraries. You will need to put the string in one of the project modules.
Rusty Well-Known Member Licensed User Longtime User Feb 11, 2014 #14 Ok. Thanks. I really appreciate your help on this. Rusty Upvote 0