views:

174

answers:

2

Hello,

Im making an application in cocoa and wanted to see if some strings in it were easily accessible so I ran OTX on it and sadly all of my code was found. Is there a method I can use to make my code more "secure" or at least encrypt/hide the strings? The reason I want to encrypt the string is it's a password for a server. I don'd need it really secure I just don't want the password to be so easy to find.

Thanks for any help

+5  A: 

1. Avoid ObjC in secure code.

Because ObjC's class system depends heavily on runtime reflection, the whole interface needs to be included alongside the executable. This allows tools like class-dump to easily recover the source @interface of the binary.

Therefore, the secure code functions should be written as a C function, not an ObjC method.

2. Use strip.

By default the compiler will keep all the private symbols (which allows stack trace to be more readable). You can use strip to delete all these symbols.

3. Obfuscation.

The above steps can only hide the code logic. But if the password is a constant string, it is immediately visible using the strings utility. You may obfuscate this by constructing the password in runtime (e.g. store the password encoded in ROT-13 in the file.)

4. Or just change your design.

No matter how good your protection system is, as the hacker have total control on their machine, given enough time, they always win. It's better to revise your design, like why the password must come with the executable? Or why a global password even needed?

KennyTM
Thanks for the reply. I'm not a very experienced programer but how would I change it to a C function?
happyCoding25
@happy: Like instead of using `+(NSString*)getPassword;`, you create a `static NSString* getPassword(void);` outside of the class.
KennyTM
+7  A: 

You should never put a password into an executable.

This is like putting the password on a sticky note next to the monitor. If a malicious hacker has your application they can eventually extract the password regardless of what language or API you use to write it.

For example, if I know that your application connects to a password protected server but the application never ask for a password, then I know you've made the mistake of including the password. To find the password, I need only monitor the operation of the program to see what areas of code are active around the time it connects to the server. This will tell me where to focus the search for the password regardless of how big your application is. Then it is only a matter of time until I track the password down. Encrypting the password does no good because the encryption algorithm must also be in the app and I can unravel that as well.

Remember that there are many people out there who can unravel your code using only the raw machine code. For those people it doesn't matter what language or API you use because they all distill to machine code in the end. Those people are the scary skilled gods of programming and they laugh at mere mortals such as you or I. Unfortunately, some of them are evil.

Did I mention that you should never put a password into an executable? If I didn't, let me repeat that you should never put a password into an executable.

In your particular case, as novice programmer, you have no hope of hiding of the password from someone with even a little bit more experience than yourself. This is yet another good reason why you should never put a password into an executable.

TechZen
Thanks for the reply. The only reason theres a password in it is its just for a few friends and won't be distributed.
happyCoding25
Friends? Then why do you want to encrypt it? :-)
Joshua Nozzi