7 ms·
Encrypt a file so that only a SSL site's private key can decrypt
- Confusion 16y agoA script without context or explanation of what it is useful for. Why did you submit this?
- patio11 16y agoThat's a neat hack. I once had call to send banking details to a client. It was very annoying - eventually settled on encrypting an emailed zip file and sending password out of band. This, on the other hand, turns any web developer's SSL cert into their PGP key without their advance cooperation. (They don't have to have one, understand why they need one, or create one and publish the public key. They just have to have an https site, like all my clients already do.) Limited utility, since decrypting is impossible for regular people and larger corps would have that private key locked down like crazy, but a very neat hack. I could actually see myself using it, too, for secure geek-2-geek transmissions.
- k00k 16y agoFriends of mine have created http://lockify.com/ http://lockify.com/ exactly for the purpose you outline with the banking details.
- deleted 16y ago[deleted]
- inaequitas 16y agoZed Shaw wrote this (https://twitter.com/#!/zedshaw/status/54434747652390912 https://twitter.com/#!/zedshaw/status/54434747652390912) and then him and Dan Kaminski had a good talk on Twitter about it.
- zwp 16y agoGreat I think that got most of it (validation!) but revocation checking worries me and a skim of the OpenSSL (0.9.8o) sources doesn't leave me with the warm'n'fuzzies. s_client.c calls SSL_CTX_set_verify() (the default verifier). Results from that can be obtained from SSL_get_verify_result() and are documented in verify(1). All of the CRL/revocation-related return codes there are marked "unused". There is no mention of OCSP. I found found a "crl_check/crl_check_all" option for verify(1). Command line help mentions an "ocsphelper". OpenSSL does have a separate OCSP client. But I don't think any of this machinery is activated by default.
- bigiain 16y agoI thought it was a fabulous (tho limited utility) hack around the key distribution problem.
- deleted 16y ago[deleted]
- bluppy2 16y agoSince the RSA algorithm for public/private key algorithm can only encrypt payloads as large as the (public)key, this is the only way to safely encrypt files. That's why PHP provides the openssl_seal function can do exactly the same (and more) as the given code. (http://php.net/manual/en/function.openssl-seal.php http://php.net/manual/en/function.openssl-seal.php) When you Google for it there are also implementations for other languages available.
- iuguy 16y agoPGP/GPG?
- tptacek 16y agoIt's not the RSA key size that prevents you from using RSA for arbitrary message lengths. Notice that block ciphers used for bulk encryption are similarly constrained by their block length (which are far shorter than an RSA key). In both RSA and AES, you can use a chaining construction to encrypt arbitrary-length messages. The things that keep you from doing this in the real world with RSA are security and speed. It's first of all much slower to perform a single RSA operation than it is to perform the AES block transform. AES involves no bignum math at all, let alone bignum modular multiplication. Secondly and more importantly, RSA encryption is fundamentally volatile and dangerous. As an exercise, go implement it in Python or Ruby (you're going to find it's remarkably easy, since both those languages automatically promote to bignums). RSA is just a simple formula. As a result, there are a variety of pitfalls to using it safely. Among the important ones is the fact that you can't safely encrypt related messages, and that messages require a certain proportion of random padding.
- asharp 16y agoWhy don't you use the standard openssl RSA encryption function to encrypt the entire file, rather then encrypt a plaintext passphrase? I don't know of an implementation that uses RSA encryption that doesn't use RSA to encrypt a (heavily padded, very random) key which they then use to encrypt the final payload using say AES or IDEA (in the original PGP).
- asymptotic 16y agoSpeed, because cryptanalysis via cipher-text only attacks becomes easier as you get more and more ciphertext associated with a given key, and because if someone attempts to analyse a memory core dump or the memory space of your computer hopefully the only data available is the session key, rather than the full decrypted RSA private key. See: https://secure.wikimedia.org/wikipedia/en/wiki/Session_key https://secure.wikimedia.org/wikipedia/en/wiki/Session_key https://secure.wikimedia.org/wikipedia/en/wiki/Ciphertext-only_attack https://secure.wikimedia.org/wikipedia/en/wiki/Ciphertext-on... http://academic.csuohio.edu/zhao_w/teaching/Old/EEC693-S07/lecture6.ppt http://academic.csuohio.edu/zhao_w/teaching/Old/EEC693-S07/l...
- asharp 16y agoThat makes no sense. You create some random key K. You encrypt k using the public key of the recipient, ie. e(k). You encrypt the message using K. You send both of those to the recipient. A cyphertext only attack can recover K from your message M. It is not then possible to recover a private key from K. In neither case do you ever have the private key, as such it cannot ever be recovered from a core dump. In this script it seems like they are simply doing this twice, for some unknown reason.
- asymptotic 16y agoSorry, there seems to have been a misunderstanding; I completely agree with you. I thought you were asking "Why bother using sessions keys, rather than encrypt the whole message using RSA?". My bad.
- iuguy 16y agoSo it appears that this site has the perceived advantage of turning a web developer's SSL cert into key for encryption, which at first sounds like a good idea. If on the other hand you don't exclusively communicate with SSL-using web developers, you're better off using a PGP implementation. Unfortunately Symantec bought PGP Corporation, but GPG4Win[1] is free, as are GPG-based PGP implementations for almost every other platform. Worried about it being hard? It really isn't. In fact it's easy to get up and running with encrypting your Gmail in Firefox[2] even if you have a Mac or something else[3]. [1] - http://www.gpg4win.org/ http://www.gpg4win.org/ [2] - http://www.instructables.com/id/Send-and-Receive-Encrypted-E-mail-in-Gmail/ http://www.instructables.com/id/Send-and-Receive-Encrypted-E... [3] - http://www.instructables.com/id/Encrypt-your-Gmail-Email/ http://www.instructables.com/id/Encrypt-your-Gmail-Email/
- adamtj 16y agoHere's what he's using it for: http://vulnarb.com/ http://vulnarb.com/ It's not for communicating with web developers. It's for publicly and provably, but responsibly exposing vulnerabilities in software. The people/entities who write such software are likely to have a public website with SSL. If they don't, it's unlikely to be very important or widely used software. In that context, PGP makes no sense.
- defen 16y agoIf you use the Firefox Gmail extension, watch out for the autosave drafts feature of Gmail, which will put a bunch of copies of your unfinished unencrypted email on Google's servers.
- jevinskie 16y agoCan you point me to a site that discusses the best practices for generating and securing my keypair? I don't have enough faith in an Instructable to get all the details right. How would I go about becoming part of this "web of trust" that I keep hearing about in relation to PGP.
- tptacek 16y agoWhile there are Internet services that purport to realize an actual "web of trust", the "web of trust" concept is really notional. It's more an idea than a thing. The idea is, instead of having a central authority that vouches for every key, you get your keys directly from your acquaintances, verify them directly with your acquaintances, and in turn vouch for those keys with your peers.
- jojo1 16y agoUsing /dev/urandom as password source is a very bad idea.
- asymptotic 16y agoAgreed. /dev/urandom should be mixed with other sources of entropy (system statistics, epoch, low-level counters, cryptographic PRNGs like Yarrow) and then "combined" using a cryptographic hash. Such a principle is used in e.g. Fortuna. See: https://secure.wikimedia.org/wikipedia/en/wiki/Fortuna_%28PRNG%29 https://secure.wikimedia.org/wikipedia/en/wiki/Fortuna_%28PR...
- jojo1 16y agoOr just use /dev/random :)
- getsat 16y agoReads from /dev/random will block when the entropy pool is empty. You can see the number of bits of entropy available on a Linux systems via: $ cat /proc/sys/kernel/random/entropy_avail If you need more, better randomness, check out the Entropy Key: http://www.entropykey.co.uk/ http://www.entropykey.co.uk/
- chalst 16y agoBlocking /dev/random when entropy is low is the correct behaviour, but it is a system-dependent behaviour. Darwin (Mac OSX) has the two sources behave identically. The Darwin man page justifies this behaviour saying: /dev/urandom is a compatibility nod to Linux. On Linux, /dev/urandom will produce lower quality output if the entropy pool drains, while /dev/random will prefer to block and wait for additional entropy to be collected. With Yarrow, this choice and distinction is not necessary, and the two devices behave identically. You may use either. and then contradicts itself later by saying: Yarrow is a fairly resilient algorithm, and is believed to be resistant to non-root. The quality of its output is however dependent on regular addition of appropriate entropy.
- asymptotic 16y agoIt goes without saying that you shouldn't do a simple "rm" on the password file. I'm not going to put on my tin-foil hat and start gibbering about magnetic alignment and electron tunnel microscopy but this is just "one of those things" that everyone knows to avoid.
- jvdongen 16y agoWhile it is a nice idea, I do not see any practical applications. It requires a receiver who is a) knowledgeable enough to decrypt it using something like openssl and b) have access to the actual private key. If that's the case it is highly likely that this person is either capable of using something like PGP or facilitate a file upload form on the apparently available website. Both of which are at least as secure and a whole lot more convenient. Something related to this I would be really interested in would be a way to encrypt a file client-side, in the browser using javascript prior to uploading it (without the need for the user to do special tricks beyond picking a password). So far this only seems remotely possible using something like flash or silverlight.
- hendler 16y agoI could see it being useful if you aren't sure how to get an encrypted message to some one. Much encryption can be done in javascript. https://ziyan.info/2008/10/javascript-rsa/ https://ziyan.info/2008/10/javascript-rsa/ http://www-cs-students.stanford.edu/~tjw/jsbn/ http://www-cs-students.stanford.edu/~tjw/jsbn/ http://www.beanizer.org/site/index.php/en/Articles/Practical-uses-of-client-side-encryption.html http://www.beanizer.org/site/index.php/en/Articles/Practical...
- bigmac 16y agoJavascript is too hostile an environment for crypto. How do you know your js crypto code wasn't modified in transit? You use SSL. Now that you're using SSL why do you need encryption in the js at all?
- Lennie 16y agoWhoever thinks someone didn't change the code on the server might also be kidding himself...
- pnathan 16y agoI suggest you patch the call to rm with a call to srm: http://en.wikipedia.org/wiki/Srm_(Unix) http://en.wikipedia.org/wiki/Srm_(Unix)
- apgwoz 16y ago...or at least use shred(1) and then rm(1)
- pnathan 16y agoSix of one, half a dozen of the other? Also note that there are interesting complications in relation to file data long-term storage on SSD drives. It should be investigated.
- koenigdavidmj 16y agoOr journaling file systems.
- AdmiralBeotch 16y agoBetter to mount /dev/ram0 and do your encryption there. Then shred; rm -rf; umount for the win.
- jrockway 16y agoInstead of 'echo "QUIT" | openssl ...', why not 'openssl ... < /dev/null'?