10

I plan on using the AWS SDK for iOS for an upcoming project. I need to store credentials for AWS with the packed application. Where is the most secure place to place them? I know that storing them in a pList would be a bad idea. Is it better to just 'hard-code' it into a class that will be compiled? Is there any risk there?

dtuckernet
  • 7,817
  • 5
  • 39
  • 54

3 Answers3

16

I believe that completely hiding the credentials is theoretically impossible. That is, if your compiled code can read them, then in theory so can anyone with access to the compiled code. But imperfect security is still worth something. I'd guess that most attackers would just look through the binary for strings that look like secret keys, and not go to the trouble of decompiling the code and trying to interpret how it works, so one way to hide the credentials would be to store them in an encoded form, then decode them as needed. This way the decoding algorithm becomes your key, and an attacker would have to find and understand it to extract your credentials.

Here's a fairly simple way to do it using a random XOR mask. Replace the following bogus password with yours, and remember to keep the NULL terminator (\0) in place. Compile and run this code as a standalone program:

#include <stdio.h>

#define PAD_LENGTH 32

int main() {
  int i;
  char c;

  // start with the password
  char password[PAD_LENGTH] = "My AWS Password\0";

  // make a random pad to encrypt it
  printf("PAD:\n{");
  char pad[PAD_LENGTH];
  for (i = 0; i < PAD_LENGTH; i++) {
    c = arc4random() & 0xFF;
    pad[i] = c;
    printf("%#02x", c & 0xFF);
    if (i < PAD_LENGTH - 1) printf(",");
  }
  printf("}\n");

  // make an encrypted version of the password
  printf("KEY:\n{");
  for (i = 0; i < PAD_LENGTH; i++) {
    c = pad[i] ^ password[i];
    printf("%#02x", c & 0xFF);
    if (i < PAD_LENGTH - 1) printf(",");
  }
  printf("}\n");

  return(0);
}

Then copy the generated pad and key into code like this (which will actually get included with your app):

#define PAD_LENGTH 32

char pad[PAD_LENGTH] = {0x83,0x26,0x8a,0x8b,0xee,0xab,0x6,0xed,0x2e,0x99,0xff,0x23,0x7f,0xef,0xc8,0x8,0x6b,0x8e,0xa4,0x64,0x6d,0xb,0x7,0xd2,0x6a,0x39,0x60,0xa4,0xa9,0xad,0xea,0xb8};
char key[PAD_LENGTH] = {0xce,0x5f,0xaa,0xca,0xb9,0xf8,0x26,0xbd,0x4f,0xea,0x8c,0x54,0x10,0x9d,0xac,0x8,0x6b,0x8e,0xa4,0x64,0x6d,0xb,0x7,0xd2,0x6a,0x39,0x60,0xa4,0xa9,0xad,0xea,0xb8};
for (int i = 0; i < PAD_LENGTH; i++) {
  key[i] = key[i] ^ pad[i];
}
NSString *password = [NSString stringWithCString:key encoding:NSASCIIStringEncoding];

Since this is on a public forum, you might want to change a few things, like making the pads a different length, splitting them up and rejoining them with code, reordering them, etc. You could also store the pad and key in distant parts of the code. A truly skilled and dedicated attacker is going to be able to find your password no matter what, but the basic idea is that most people scanning the binary for a password will not find it as such.

Jesse Crossen
  • 6,945
  • 2
  • 31
  • 32
1

Have you looked at the Data Protection API?

What are the new "iOS data protection APIs"?

There are various options depending on your security needs.

This question may help also.

Data Protection on iOS

The video from a conference this year was useful.

http://developer.apple.com/videos/wwdc/2010

Community
  • 1
  • 1
James Black
  • 41,583
  • 10
  • 86
  • 166
  • I am researching this option. I'll mark it as the answer once I finish the research. Thanks! – dtuckernet Aug 10 '11 at 12:21
  • I'm not sure this meets my needs. I am looking for how to secure data within the application bundle that gets included with the application. This seems to apply directly to data that is generated during the use of the application. Do you know if this is true? – dtuckernet Aug 10 '11 at 17:25
  • Anything installed can be decompiled and discovered, so it depends on how much you want to protect the aws credentials, but you are correct, the data protection api doesn't help with what is in the installation file. But there are ways to have it protected, again depending on you paranoia level. – James Black Aug 11 '11 at 01:20
1

you should use AWS Identity and Access Management (IAM): http://aws.amazon.com/iam/

you can find more information about AWS Credential Management in Mobile Applications on http://aws.amazon.com/articles/4611615499399490

Deniz Mert Edincik
  • 4,336
  • 22
  • 24
  • Yes, I realize that this is the recommended solution, but this still requires a server (correct me if I am wrong). You still have to sign the requests to request the temporary security credentials. Is there anyway to securely do this without a server? – dtuckernet Aug 22 '11 at 20:39
  • hmm I guess it is impossible, and getting the key and secret from the app can be too risky. – Deniz Mert Edincik Aug 23 '11 at 21:43