Live data from Hacker News

Password protect a static HTML page

github.com

121–130 of 294 posts

Re: Password protect a static HTML page

#121
post #78
post #24

Earlier quoted context omitted.

Client side decryption has the benefit that no machine or router in the middle can view or cache the decrypted page without the password.

You mean, unless they tamper with the Javascript to capture the password (or the derived key).

I designed a similar tool with that threat model in mind: the resulting HTML/JS is as minimal as possible so it’s possible to inspect before entering the password. Of course assumes safe browser and client machine.. https://github.com/dividuum/html-vault

Re: Password protect a static HTML page

#122
post #84
post #55

Earlier quoted context omitted.

Not going to pretend that I know what the most of the stuff mean, or if it is even safe enough, but I've followed the MDN articles and put together this TypeScript snippet [1]. Maybe somebody could comment on it? Also sorry for the long link. Is there any accepted way to post a shorted URL? Edit: added a corrected version [2] [1]: https://www.typescriptlang.org/play?#code/DYUwLgBAbiDGYHsBOE... [2]: https://www.typesc…

If you call "encrypt" more than once in that code, you'll leak the authentication key. Every invocation of GCM encryption needs a unique nonce. Cryptography nerds will chastise you for using a random nonce (there theoretically isn't enough room in the GCM nonce space to safely encrypt large numbers of message with random nonces), but the alternative (using a counter) is even more hazardous. This problem motivates a l…

Oh yes! Thank you for the feedback. I've added a new version where the `iv` and the `salt` is random. Maybe a followup question: Because you need both the `iv` and `salt` to decrypt the message is it ok in an E2E scenario to send all three: `iv`, `salt` and the encrypted message?

Re: Password protect a static HTML page

#124
post #122
post #84

Earlier quoted context omitted.

If you call "encrypt" more than once in that code, you'll leak the authentication key. Every invocation of GCM encryption needs a unique nonce. Cryptography nerds will chastise you for using a random nonce (there theoretically isn't enough room in the GCM nonce space to safely encrypt large numbers of message with random nonces), but the alternative (using a counter) is even more hazardous. This problem motivates a l…

Oh yes! Thank you for the feedback. I've added a new version where the `iv` and the `salt` is random. Maybe a followup question: Because you need both the `iv` and `salt` to decrypt the message is it ok in an E2E scenario to send all three: `iv`, `salt` and the encrypted message?

I didn't look to see what "salt" means in your design, but the idiom for using GCM in message encryption is to send ciphertexts that take the form `nonce || ciphertext`, and to decrypt by reading the nonce off the front of the message.

Re: Password protect a static HTML page

#126
I saw a super simple example of this back in the 90s when I was first leaning web development (was in Web Development for Dummies or some such).

The page prompted the user for the password, and then used the password to generate the URL for the hidden page and redirected the user there. Of course this wasn’t over HTTPS, and you got a 404 if you entered the wrong password, but it was still a neat hobbyist trick for the era. I think the author even wagered that readers couldn’t defeat it.

Re: Password protect a static HTML page

#127
post #77

[flagged]

If that's wrong, so is the name of every "static site generator". Also: please don't make the same point in two separate top-level comments.

A static site generator can be used to create an .html file that's dependent on the user to execute a javscript web application to show the content. That makes that generated page dynamic. It doesn't change the nature of the static site generator.

Re: Password protect a static HTML page

#128

Gad! I have spent all morning trying to --- password protect a static html page. How in the hell does HN have a story about the exact topic I've been struggling with appear just a dozen or so hours after I started working on it. Wow. I was _extremely_ happy to see this posted. However when I click the link I am taken to the library I had initially tried and had to reject. Without getting into the crypto side of thing…

Something similar has been posted before some time ago: https://news.ycombinator.com/item?id=34083366

Re: Password protect a static HTML page

#130
post #84
post #55

Earlier quoted context omitted.

Not going to pretend that I know what the most of the stuff mean, or if it is even safe enough, but I've followed the MDN articles and put together this TypeScript snippet [1]. Maybe somebody could comment on it? Also sorry for the long link. Is there any accepted way to post a shorted URL? Edit: added a corrected version [2] [1]: https://www.typescriptlang.org/play?#code/DYUwLgBAbiDGYHsBOE... [2]: https://www.typesc…

If you call "encrypt" more than once in that code, you'll leak the authentication key. Every invocation of GCM encryption needs a unique nonce. Cryptography nerds will chastise you for using a random nonce (there theoretically isn't enough room in the GCM nonce space to safely encrypt large numbers of message with random nonces), but the alternative (using a counter) is even more hazardous. This problem motivates a l…

From what I shallowly researched; GCM's nonce seems limited to 12 bytes by convention only. That nonce reuse is so fatal seems absurd to me.

Would "salting" the key safely tackle the problem?

Put explicitly;

  send  decrypt(ciphertext, nonce, pbkdf(pass) || salt)
[edit: apply salt outside of the kdf]
Post reply on HN