views:

72

answers:

4

Because of china Great Firewall has blocked google appengine's https port. So I want to simulate a Secure Socket Layer by javascript and python to protect my users information will not be capture by those ISP and GFW.

My plan:

  • Shake hands:

Browser request server, server generate a encrypt key k1, and decrypt key k2, send k1 to browser. Browser generate a encrypt key k3, and decrypt key k4, send k3 to server.

  • Browse:

During the session, browser encrypt data with k1 and send to server, server decrypt with k2. server encrypt data with k3 and response to browser, browser decrypt with k4.

Please figure out my mistake.

If it's right, my question is

  1. how to generate a key pair in javascript and python, are there some libraries?
  2. how to encrypt and decrypt data in javascript and python , are there some libraries?
A: 

There's a big problem, if security really is a big concern: Your algorithm is going to be transfered unsecured. Can you trust the client at all? Can the client trust the server at all?

Onkelborg
I think opensource algorithm is OK, there are some encryption, even you know the encrypt key, but you can not decrypt it, and you can't get the decrypt key from encrypt key.
guilin 桂林
No, the problem is what Marcelo says, what prevents the evil Firewall of China from being a man in the middle and throwing away a completely unprotected version to your client? Or sending their own public keys (since they have their private key they can decrypt everything.) With SSL you have a couple or root CA installed from scratch, the client uses them to ensure that the public key really, really belongs to the correct address. When you try to do this by javascript then you can't verify your counterpart anymore, and a big security hole is opened..
Onkelborg
just for my own site, not for widely use.
guilin 桂林
Yes, but that doesn't care: if you have a need to encrypt your information, then you got to make sure that the encryption is safe. If not, you might as well just skip the encryption since it won't add any protection anyway
Onkelborg
+1  A: 

You have a fundamental problem in that a JavaScript implementation of SSL would have no built-in root certificates to establish trust, which makes it impossible to prevent a man-in-the-middle attack. Any certificates you deliver from your site, including a root certificate, could be intercepted and replaced by a spy.

Note that this is a fundamental limitation, not a peculiarity of the way SSL works. All cryptographic security relies on establishing a shared secret. The root certificates deployed with mainstream browsers provide the entry points to a trust network established by certifying authorities (CAs) that enable you to establish the shared secret with a known third party. These certificates are not, AFAIK, directly accessible to JavaScript code. They are only used to establish secure (e.g., https) connections.

Marcelo Cantos
Thank you. Yes, my plan is so weak. But what I want is a little more protect, I was force to do this against my will.
guilin 桂林
There is no way to do what you want without deploying either a shared secret or CA roots via an alternate communication channel, or deploying them via the primary channel, and confirming their validity via the alternate channel (e.g., certificates have fingerprints, which can be read out over the phone for confirmation). Without these, it is almost trivial to mount a man-in-the-middle attack, assuming full access to your communication channel.
Marcelo Cantos
A: 

You can't stop the men in the middle from trapping your packets/messages, especially if they don't really care if you find out. What you can do is encrypt your messages so that trapping them does not enable them to read what you're sending and receiving. In theory that's fine, but in practice you can't do modern crypto by hand even with the keys: you need to transfer some software too, and that's where it gets much more awkward.

You want to have the client's side of the crypto software locally, or at least enough to be able to check whether a digital signature of the crypto software is correct. Digital signatures are very difficult to forge. Deliver signed code, check its signature, and if the signature validates against a public key that you trust (alas, you'll have to transfer that out of band) then you know that the code (plus any CA certificates – trust roots – sent along with it) can be trusted to work as desired. The packets can then go over plain HTTP; they'll either get to where they're meant to or be intercepted, but either way nobody but the intended recipient will be able to read them. The only advantage of SSL is that it builds virtually all of this stuff for you and makes it easy.

I have no idea how practical it is to do this all in Javascript. Obviously it can do it – it's a Turing-complete language, it has access to all the requisite syscalls – but it could be stupidly expensive. It might be easier to think in terms of using GPG…

(Hiding the fact from the government that you are communicating at all is a different problem entirely.)

Donal Fellows
A: 

The other answers here are correct: You won't be able to securely deliver the JavaScript that is going to be running on the client. However, if you just want to look into this stuff some more anyway, check out the opensource project Forge. It has an SSL/TLS implementation in JavaScript and a simple Python SSL server:

http://github.com/digitalbazaar/forge/blob/master/README

If you want to read up some more on its uses:

http://digitalbazaar.com/2010/07/20/javascript-tls-1/

http://digitalbazaar.com/2010/07/20/javascript-tls-2/

dlongley