Live data from Hacker News

Password protect a static HTML page

github.com

71–80 of 294 posts

Re: Password protect a static HTML page

#72

I'm not a cryptographer, but I'm pretty sure that CBC ( https://github.com/robinmoisson/staticrypt/blob/main/lib/cry... ) should be replaced with GCM ( https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypt... ) since this is not a stream. https://security.stackexchange.com/questions/184305/why-woul... (also, use the built-in WebCrypto API instead of the crypto-js package)

CBC is far easier to implement than GCM mode.

I bet that most programmers cannot implement a Galois Field in Javascript. Meanwhile, CBC is just "encrypt then xor".

Re: Password protect a static HTML page

#74

I'm not a cryptographer, but I'm pretty sure that CBC ( https://github.com/robinmoisson/staticrypt/blob/main/lib/cry... ) should be replaced with GCM ( https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypt... ) since this is not a stream. https://security.stackexchange.com/questions/184305/why-woul... (also, use the built-in WebCrypto API instead of the crypto-js package)

I don't know what "being a stream" has to do with anything (you should virtually always use "stream" modes of AES); the meaningful distinction between CBC and GCM is that GCM authenticates the ciphertext, so you can't tamper with it.

Re: Password protect a static HTML page

#75

Earlier quoted context omitted.

Those would be quite nice, if web browsers were good HTTP clients. The user experience with basic auth is not so good. The dialogs give little way to customize and providing information for user. No support for logout or any form of password changes.

Logout is possible: The server has to send http status 401 if I recall correctly. The browser treats this as logout.

This requires some server side handling. The web browser could have a logout button so I can end my session. Probably that should be combined with a configured target page for the user.

And well, my experience there is about 20 years old, but back then sending 401 wasn't enough. You had to send a different auth request, which then would pop up a new password dialog first. Indoubt 401 is enough today as well, as the browser can't distinguish whether a specific resource is restricted or whether the whole session should be invalidated.

Re: Password protect a static HTML page

#76

I'm not a cryptographer, but I'm pretty sure that CBC ( https://github.com/robinmoisson/staticrypt/blob/main/lib/cry... ) should be replaced with GCM ( https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypt... ) since this is not a stream. https://security.stackexchange.com/questions/184305/why-woul... (also, use the built-in WebCrypto API instead of the crypto-js package)

CBC is far easier to implement than GCM mode. I bet that most programmers cannot implement a Galois Field in Javascript. Meanwhile, CBC is just "encrypt then xor".

Nobody implements GCM themselves; they get it from a library. CBC, implemented the way you're describing, is almost always insecure.

Re: Password protect a static HTML page

#78
post #24

A more lightweight solution would be to hash the password and have a copy of that file at this url. windows.location = hash(password);

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).

Re: Password protect a static HTML page

#79

I'm not a cryptographer, but I'm pretty sure that CBC ( https://github.com/robinmoisson/staticrypt/blob/main/lib/cry... ) should be replaced with GCM ( https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypt... ) since this is not a stream. https://security.stackexchange.com/questions/184305/why-woul... (also, use the built-in WebCrypto API instead of the crypto-js package)

[deleted]

Re: Password protect a static HTML page

#80
post #76

Earlier quoted context omitted.

CBC is far easier to implement than GCM mode. I bet that most programmers cannot implement a Galois Field in Javascript. Meanwhile, CBC is just "encrypt then xor".

Nobody implements GCM themselves; they get it from a library. CBC, implemented the way you're describing, is almost always insecure.

And the library they use doesn't have GCM mode.

So now what?

https://cryptojs.gitbook.io/docs/

Because CBC mode is easier to implement, you'll find it in far more libraries. And honestly, if your underlying block-cipher is secure (that's the hard part: where your side-channels all exist), then CBC mode is really the easy part and can be safely implemented yourself. It really is that simple.

-----------------

CBC doesn't have authentication. So add on an HMAC. Done. It takes up a few more bytes but that's not a big deal these days.

Post reply on HN