Storing My Amazon Credentials in C# Desktop App

前端 未结 4 1654
耶瑟儿~
耶瑟儿~ 2021-02-02 16:23

I\'m Looking at using Amazon S3 and simpleDB in a desktop application.

The main issue I have is that I either need to store my aws credentials in the application or use

相关标签:
4条回答
  • 2021-02-02 16:51

    Tim, you're indeed hitting on the two key approaches:

    1. NOT GOOD ENOUGH: store the secret key "secretly" in the app. There is indeed a grave risk of someone just picking it out of the app code. Some mitigations might be to (a) use the DPAPI to store the key outside the app binary, or (b) obtain the key over the wire from your web service each time you need it (over SSL), but never store it locally. No mitigation can really slow down a competent attacker with a debugger, as the cleartext key must end up in the app's RAM.

    2. BETTER: Push the content that needs to be protected to your web service and sign it there. The good news is that only the request name and timestamp need to be signed -- not all the uploaded bits (I guess Amazon doesn't want to spend the cycles on verifying all those bits either!). Below are the relevant code lines from Amazon's own "Introduction to AWS for C# Developers". Notice how Aws_GetSignature gets called only with "PutObject" and a timestamp? You could definitely implement the signature on your own web service without having to send the whole file and without compromising your key. In case you're wondering, Aws_GetSignature is a 9-line function that does a SHA1 hash on a concatenation of the constant string "AmazonS3", the operation name, and the RFC822 representation of the timestamp -- using your secret key.

      DateTime timestamp = Aws_GetDatestamp();
      string signature = Aws_GetSignature( "PutObject", timestamp );
      byte[] data = UnicodeEncoding.ASCII.GetBytes( content );
      service.PutObjectInline( "MainBucket", cAWSSecretKey, metadata,
              data, content.Length, null,
              StorageClass.STANDARD, true,
              cAWSAccessKeyId, timestamp, true,
              signature, null );
      

    EDIT: note that while you can keep the secret key portion of your Amazon identity hidden, the access key ID portion needs to be embedded in the request. Unless you send the file through your own web service, you'll have to embed it in the app.

    0 讨论(0)
  • 2021-02-02 16:59

    You can encrypt the config file and/or use ProtectedData. Here's my blog post on both.

    UPDATE: You might be a be to encrypt your app.config as part of an install step. Sample here: http://www.codeproject.com/KB/security/encryptstrings.aspx. Not great, but the best I've found so far.

    0 讨论(0)
  • 2021-02-02 17:03

    The main issue I have is that I either need to store my aws credentials in the application or use some other scheme.

    Does Windows have a system-wide service similar to Apple's Keychain Manager? If so, put your credentials there. If not, perhaps you can build a watered-down version of it for storing a strongly-encrypted version of your AWS credentials.

    Does the signature require all the data from a file thats being uploaded?

    The HMAC SHA-1 signature is an encoded encryption of the HTTP request headers. This signature is a hash value and will be very short relative to your data, only 20 bytes long.

    0 讨论(0)
  • 2021-02-02 17:12

    Will you let anyone that gets a hold of a copy of your program access the data on S3/SimpleDB? If not, you will need your own authentication scheme that's independent from AWS security.

    In that case, you could implement a web service that accepts the credentials that you give your customers (a username/password for example, a digital certificate, etc) and then performs the S3/SimpleDB operations that your program requires. That way, the AWS credentials never leave AWS. If a particular user's credentials are compromised, you can cancel those credentials in your web service.

    0 讨论(0)
提交回复
热议问题