Take the 2-minute tour ×
Information Security Stack Exchange is a question and answer site for Information security professionals. It's 100% free, no registration required.

If I were to write a web application using openpgp.js (http://openpgpjs.org/) for creating PGP encrypted/signed messages and if I stored the user's private key in localStorage, would this be vulnerable to the same complaints about JavaScript cryptography on Matasano's webpage (http://www.matasano.com/articles/javascript-cryptography/)?

As far as I can tell, the main points outline by Matasano are:

  • "Secure delivery of Javascript to browsers is a chicken-egg problem." (This could be fixed by using HTTPS)
  • JavaScript isn't well suited to cryptography
  • Browsers are too complex for cryptography since they have the potential to contain multiple attack vectors.

If localStorage isn't the best place to store something sensitive like a private key, what would be a better place?

share|improve this question

2 Answers 2

up vote 7 down vote accepted

HTTPS is still an absolute requirement, and Matasano's main point is that JavaScript can never replace HTTPS. A MITM attack could deliver a custom JavaScript payload that could read any secrets in localstorage, and an XSS payload could also compromise this data.

Matasano is wrong in regards to random number generators in JavaScript. Most browsers provide a very secure random number generator window.crypto.getRandomValues(). I guess Matasano hasn't read the w3c Cryptography API for JavaScript. This API contains a random number generator that uses the operating system's entropy pool.

share|improve this answer
1  
Didn't the Matasano article come out before the W3C crypto spec? –  Polynomial Jun 30 '13 at 17:07
1  
Key management is also a problem, there is nothing in javascript to make it possible to deliberately write to a specific section of memory, meaning keys may remain in active memory long after they are no longer required. –  ewanm89 Jun 30 '13 at 17:54
    
@Polynomial Not sure, the Matasano article isn't dated. In any case, they should update it. –  Rook Jun 30 '13 at 17:56
    
@ewanm89 that is a good point, you can't disable swap like you can in C/C++. –  Rook Jun 30 '13 at 17:57
2  
archive.org visited the article first time on 2011-09-25, which about a year before the W3C recommendation. –  Jens Erat Jun 30 '13 at 21:34

If you do decide to store the secret in localStorage, you will want to make sure you never store the cleartext session key there. I'm not familiar with openpgpjs, but it probably facilitates secure storage of keys (some form of keyring class I guess).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.