How to secure passwords over HTTP











up vote
17
down vote

favorite
5












Say my password is abc. I want to send it to the server over HTTP.



I could send it in plaintext and let the server hash it and compare it to the entries in its database, but then anyone that can see traffic over that connection would see the password in plain text.



So then I could hash it client-side and let the server just compare it without hashing since it's already hashed (or the server could even double hash, but no difference in this situation). But then again anyone that can see the traffic would see the password hashed, and then send the hashed password to the server and the server would accept it.



How do I send passwords over HTTP? Do I need to implement some encryption algorithm like RSA public key encryption? Or is this impossible?



The method should be usable in any browser.










share|improve this question









New contributor




FireCubez is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 53




    Why can't you just use TLS? There's really no other way to do it securely.
    – AndrolGenhald
    2 days ago






  • 3




    @AndrolGenhald I could, this is just a proof of concept. If there's no other way to do it securely then that's the answer I was looking for. You should post it as an answer
    – FireCubez
    2 days ago










  • You don't need native TLS - you could, theoretically, implement TLS over HTTP - but it would be nowhere near practical.
    – Solomonoff's Secret
    2 days ago






  • 3




    Is this a real problem you are facing or just a thought expirement?
    – whatsisname
    yesterday






  • 1




    @whatsisname I stated that in a previous comment, it's just an experiment
    – FireCubez
    17 hours ago















up vote
17
down vote

favorite
5












Say my password is abc. I want to send it to the server over HTTP.



I could send it in plaintext and let the server hash it and compare it to the entries in its database, but then anyone that can see traffic over that connection would see the password in plain text.



So then I could hash it client-side and let the server just compare it without hashing since it's already hashed (or the server could even double hash, but no difference in this situation). But then again anyone that can see the traffic would see the password hashed, and then send the hashed password to the server and the server would accept it.



How do I send passwords over HTTP? Do I need to implement some encryption algorithm like RSA public key encryption? Or is this impossible?



The method should be usable in any browser.










share|improve this question









New contributor




FireCubez is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 53




    Why can't you just use TLS? There's really no other way to do it securely.
    – AndrolGenhald
    2 days ago






  • 3




    @AndrolGenhald I could, this is just a proof of concept. If there's no other way to do it securely then that's the answer I was looking for. You should post it as an answer
    – FireCubez
    2 days ago










  • You don't need native TLS - you could, theoretically, implement TLS over HTTP - but it would be nowhere near practical.
    – Solomonoff's Secret
    2 days ago






  • 3




    Is this a real problem you are facing or just a thought expirement?
    – whatsisname
    yesterday






  • 1




    @whatsisname I stated that in a previous comment, it's just an experiment
    – FireCubez
    17 hours ago













up vote
17
down vote

favorite
5









up vote
17
down vote

favorite
5






5





Say my password is abc. I want to send it to the server over HTTP.



I could send it in plaintext and let the server hash it and compare it to the entries in its database, but then anyone that can see traffic over that connection would see the password in plain text.



So then I could hash it client-side and let the server just compare it without hashing since it's already hashed (or the server could even double hash, but no difference in this situation). But then again anyone that can see the traffic would see the password hashed, and then send the hashed password to the server and the server would accept it.



How do I send passwords over HTTP? Do I need to implement some encryption algorithm like RSA public key encryption? Or is this impossible?



The method should be usable in any browser.










share|improve this question









New contributor




FireCubez is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











Say my password is abc. I want to send it to the server over HTTP.



I could send it in plaintext and let the server hash it and compare it to the entries in its database, but then anyone that can see traffic over that connection would see the password in plain text.



So then I could hash it client-side and let the server just compare it without hashing since it's already hashed (or the server could even double hash, but no difference in this situation). But then again anyone that can see the traffic would see the password hashed, and then send the hashed password to the server and the server would accept it.



How do I send passwords over HTTP? Do I need to implement some encryption algorithm like RSA public key encryption? Or is this impossible?



The method should be usable in any browser.







encryption passwords hash web-browser http






share|improve this question









New contributor




FireCubez is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




FireCubez is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited yesterday









curiousguy

4,00322126




4,00322126






New contributor




FireCubez is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 days ago









FireCubez

19415




19415




New contributor




FireCubez is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





FireCubez is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






FireCubez is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 53




    Why can't you just use TLS? There's really no other way to do it securely.
    – AndrolGenhald
    2 days ago






  • 3




    @AndrolGenhald I could, this is just a proof of concept. If there's no other way to do it securely then that's the answer I was looking for. You should post it as an answer
    – FireCubez
    2 days ago










  • You don't need native TLS - you could, theoretically, implement TLS over HTTP - but it would be nowhere near practical.
    – Solomonoff's Secret
    2 days ago






  • 3




    Is this a real problem you are facing or just a thought expirement?
    – whatsisname
    yesterday






  • 1




    @whatsisname I stated that in a previous comment, it's just an experiment
    – FireCubez
    17 hours ago














  • 53




    Why can't you just use TLS? There's really no other way to do it securely.
    – AndrolGenhald
    2 days ago






  • 3




    @AndrolGenhald I could, this is just a proof of concept. If there's no other way to do it securely then that's the answer I was looking for. You should post it as an answer
    – FireCubez
    2 days ago










  • You don't need native TLS - you could, theoretically, implement TLS over HTTP - but it would be nowhere near practical.
    – Solomonoff's Secret
    2 days ago






  • 3




    Is this a real problem you are facing or just a thought expirement?
    – whatsisname
    yesterday






  • 1




    @whatsisname I stated that in a previous comment, it's just an experiment
    – FireCubez
    17 hours ago








53




53




Why can't you just use TLS? There's really no other way to do it securely.
– AndrolGenhald
2 days ago




Why can't you just use TLS? There's really no other way to do it securely.
– AndrolGenhald
2 days ago




3




3




@AndrolGenhald I could, this is just a proof of concept. If there's no other way to do it securely then that's the answer I was looking for. You should post it as an answer
– FireCubez
2 days ago




@AndrolGenhald I could, this is just a proof of concept. If there's no other way to do it securely then that's the answer I was looking for. You should post it as an answer
– FireCubez
2 days ago












You don't need native TLS - you could, theoretically, implement TLS over HTTP - but it would be nowhere near practical.
– Solomonoff's Secret
2 days ago




You don't need native TLS - you could, theoretically, implement TLS over HTTP - but it would be nowhere near practical.
– Solomonoff's Secret
2 days ago




3




3




Is this a real problem you are facing or just a thought expirement?
– whatsisname
yesterday




Is this a real problem you are facing or just a thought expirement?
– whatsisname
yesterday




1




1




@whatsisname I stated that in a previous comment, it's just an experiment
– FireCubez
17 hours ago




@whatsisname I stated that in a previous comment, it's just an experiment
– FireCubez
17 hours ago










10 Answers
10






active

oldest

votes

















up vote
67
down vote



accepted










You can't.



To securely send information over an unsecure channel, you need encryption.



Symmetric encryption is out, because you would first need to transport the key, which you can't do securely over an unsecure channel[*].



That leaves you with public key cryptography. You could of course roll your own, but you don't want to be a Dave, so that's out, which leaves you with HTTPS.



[*] You can of course try to use a secure channel to exchange the key, for example physical exchange of a key. Then you can use secret key crypto, like Kerberos.






share|improve this answer























  • Couldn't you hash it twice? Once on the client side, once on the server?
    – Nathan Merrill
    yesterday






  • 6




    @NathanMerrill - Hashing the password on the client side just makes the hash the password (absent some scheme to include extra information). However, only securing the password is worthless - you have to at least authenticate the channel, or an attacker can impersonate both ends of the conversation, even without knowing the password.
    – Clockwork-Muse
    yesterday










  • This is misleading. Yes, you can. This question asks for how to secure passwords when you can't use HTTP. A bad company policy, a misconfigured firewall can all force HTTP to be used. In situations like this, exchanging certificates (IPsec TLS SCRAM etc) through a side-channel is possible and should be the answer. Answer the question instead of giving advice that was not sought after.
    – noɥʇʎԀʎzɐɹƆ
    4 hours ago




















up vote
29
down vote













TLS is really the only way to do it.



But what if I encrypt it with JavaScript?



The attacker can change the JavaScript you send to the client, or simply inject their own JavaScript that logs all information entered.



Then I'll use CSP and SRI to prevent the addition of scripts and the modification of my own scripts.



Glad you're using modern tools to help protect your site, but SRI in a non-secure context really only protects against the compromise of an external resource. An attacker can simply modify the CSP headers and SRI tags.



There's really no way to do this without using encryption from the beginning, and the only standard way to do that is to use TLS.






share|improve this answer




























    up vote
    18
    down vote













    While I agree that you should use HTTPS, you can make it even more secure by using the Salted Challenge Response Authentication Mechanism (SCRAM, see RFC 5802) for the actual authentication exchange.



    It's not trivial to implement, but the gist of it is that, rather than send the password to the server, you send proof to the server that you know the password. Since deriving the proof uses a nonce from the client and server, it's not something that can be reused by an attacker (like sending the hash itself would be).



    This has a few added benefits to using HTTPS with the basic authentication you describe:




    1. The server never actually sees your password as you log in. If someone has managed to insert malicious code onto the server, they still won't know what your password is.

    2. If there is a bug in the HTTPS implementation (think Heartbleed), attackers still won't be able to acquire your password. Because, even once TLS is bypassed, the password isn't available.

    3. If, for some reason, you can't use HTTPS, this is better than sending the password in the clear. An attacker will not be able to guess your password based on the exchange. That said, you should still use HTTPS, because defense in depth is better.


    Please note that this is only secure if the client is able to perform the SCRAM computations without downloading code from the server. You could provide a fat client, or users may be able to write their own code that they control. Downloading the SCRAM code over HTTP would give an attacker an opportunity to modify the SCRAM code to send the password in cleartext, or otherwise expose it. Thank you to Zoltan for the clarification.






    share|improve this answer










    New contributor




    Melanie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.














    • 7




      You can safely do this with a fat client (a desktop or mobile application) that is distributed in a safe manner. However, with an in-browser thin client, the client code itself is delivered over HTTP as well, and as @AndrolGenhald pointed out, attackers in the middle can intercept and change it to send the password to them.
      – Zoltan
      2 days ago






    • 2




      @Zoltan That's very true, thank you for the clarification. The original question doesn't specify whether they need a thin or fat client, so my answer wouldn't apply in all cases. But even over HTTP, I think this provides some additional security. The attack has gone from just snooping traffic to modifying code. Nothing insurmountable, so it wouldn't be secure, but maybe less bad? And I think having both HTTPS and SCRAM is very beneficial.
      – Melanie
      2 days ago










    • If you agree, you may consider mentioning this restriction in your answer. Otherwise I really like your answer as challange-response was my first thought too and none of the other answers mentioned it.
      – Zoltan
      2 days ago










    • Thank you, I've updated my answer. Let me know if you think it could use further clarifications!
      – Melanie
      2 days ago






    • 1




      @Melanie You are absolutely correct that even with just HTTP it's better. There are attackers only capable of passive attacks. That being said, there's no reason not to use HTTPS nowadays when it's free.
      – Duncan X Simpson
      2 days ago




















    up vote
    5
    down vote













    You should definitely deploy TLS in this case.



    If you decide to try to invent a transport security system over HTTP, ultimately you're going to end up implementing a susbset of the TLS functionality anyway. There are many pitfalls to be aware of when designing and implementing such a system, which are further amplified when you choose to try to implement the system with a language that doesn't offer many safety features.



    Even if you did implement a correct implementation of a cryptographic protocol in JavaScript (which is already a big challenge) you can't rely upon that implementation being resistant to timing attacks, and the whole thing breaks if someone has scripts disabled (e.g. with NoScript).



    As a general rule you should choose the implementation that consists of the most simple, well-understood, trusted components that require you to write the least amount of security-critical code. To quote Andrew Tannenbaum:




    A substantial number of the problems (in application security) are caused by buggy software, which occurs because vendors keep adding more and more features to their programs, which inevitably means more code and thus more bugs.







    share|improve this answer




























      up vote
      4
      down vote














      Do I need to implement some encryption algorithm like RSA public key encryption?




      If you're considering trying that, you may as well just go the full mile and use HTTPS. Since you don't seem to be an expert, "rolling your own" encryption will undoubtedly have misimplementations that render it insecure.






      share|improve this answer




























        up vote
        2
        down vote













        It is actually quite possible.



        Password has to be hashed on the client side, but not with a static function. The following method uses two steps, and is inspired by the Digest access authentication:



        NOTE: The server keeps a HMAC of the Password and the corresponding Key (Digest);




        1. The client starts by requesting a nonce to the server, the server returns the Key and the Nonce;

        2. Client calculates: HMAC( HMAC( Password, Key ), Nonce) and sends it to the server;

        3. Server calculates: HMAC( Digest, Nonce ) and compares it to the received value.


        This protects you against replay.



        The main interest I see is not a protection against eavesdropping, but to be completely sure that the plaintext password will not be store on the server, not even in a system log (see Twitter or GitHub).



        Note: HMAC can be replaced by PBKDF2.






        share|improve this answer










        New contributor




        Pierre del Perugia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.














        • 1




          Then some attacker can inject some code to get the password directly from the <input>. A crazy idea: "Sadly it's just a little bit hard to support HTTPS on Reserved IP addresses. Please run this code on your terminal and paste the result HMAC were." (of course disable copy pasting to prevent pastejacking in the long run).
          – Gustavo Rodrigues
          yesterday


















        up vote
        1
        down vote













        There is actually a way to authenticate a user over an insecure connection: Secure Remote Password (SRP) protocol. SRP is specifically designed to allow a client to authenticate itself to a server without a Man-in-the-Middle attacker being able to capture the client's password, or even replay the authentication to later impersonate the client, whether the authentication succeeded or not. Furthermore, successful authentication with SRP creates a shared secret key that both the client and the server know, but a MitM does not. This secret key could be used for symmetric encryption and/or HMACs.



        However, there are a number of limitations of SRP:




        1. The user must have registered in some secure fashion, as the registration process does require transmitting password-equivalent material (though the server does not need to store it).

        2. Although it is safe to attempt an SRP login with an untrusted server (that is, it won't expose your password to that server, and you'll be able to tell that the server didn't have your password in its database), It's not safe to load a login web page from an untrusted server (it could send down a page that captures your every keystroke and sends it off somewhere).

        3. Although successful authentication via SRP generates a secure shared secret key, the code to actually use this key in a web app would need to be loaded from a server, and an attacker could tamper with that code to steal the symmetric key and make changes to the requests and responses.


        In other words, while SRP can be useful in situations where you have a trusted client that doesn't need to download its code over the insecure connection and also you have some other secure way to register the user(s), SRP is not suitable for a web application. Web apps always download their code from the server, so if the connection to the server isn't secure, a MitM (or other network attacker, for example somebody spoofing DNS) can inject malicious code into the web app and there's nothing that you, the victim, can do about it. Once that code is there, it can capture any password or other data you enter, steal any key that is generated, and tamper with any requests you send or responses you receive without you even knowing.






        share|improve this answer




























          up vote
          0
          down vote













          An alternative would be to set up a secure VPN to the destination server, and perform a HTTP login from there. A malicious man in the middle will therefore have to break the encryption on the VPN channel in order to attack the connection and retrieve the passwords.



          However, in terms of end user usability, it's still not as good as HTTPS, since it requires them to setup and use a different channel with a different set of credentials.






          share|improve this answer





















          • How is the DNS resolution protected? (1) Is the DNS resolver (a) local? (b) reachable by a secure link? (2)(a) Does resolution happen over the VPN? Is the authoritative DNS server reachable by the resolver by a secure link? (b) What happens if the DNS resolution occurs before the VPN is set-up? (c) Can false DNS results obtained before the VPN is set-up be cached? (3)(a) Does the resolver use DNSSEC? (b) How is validation failure treated by the resolver? DNS resolution can be secured, by it isn't trivial.
            – curiousguy
            yesterday










          • @curiousguy The same can be said for HTTPS though, unless you manually verify the certificate.
            – March Ho
            7 hours ago


















          up vote
          0
          down vote













          It is certainly possible to send a password securely using HTTP. There is even a standard for it. It's called HTTP-Digest and it's defined in RFC 7616. It's been a part of the HTTP spec for quite a while. It was originally designed to use only the MD5 message-digest ("hashing") algorithm, but later revisions of the standard allow the client and server to negotiate which algorithm to use.



          Unfortunately, there are many problems with HTTP-digest and the most glaring of them is that the server needs to have the password in cleartext. So while it's possible to communicate passwords securely using HTTP, it's not possible to securely-store passwords on the server while using it. So basically, it's not useful.



          As others have said, it would be better to implement TLS because it solves multiple problems all at the same time, and it's fairly forward-compatible.






          share|improve this answer




























            up vote
            -1
            down vote













            You need the recipient to send you his key. You can't randomly send someone encrypted info without them first providing you with their personal public key.






            share|improve this answer





















              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "162"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              convertImagesToLinks: false,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              noCode: true, onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });






              FireCubez is a new contributor. Be nice, and check out our Code of Conduct.










               

              draft saved


              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsecurity.stackexchange.com%2fquestions%2f197330%2fhow-to-secure-passwords-over-http%23new-answer', 'question_page');
              }
              );

              Post as a guest
































              10 Answers
              10






              active

              oldest

              votes








              10 Answers
              10






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              67
              down vote



              accepted










              You can't.



              To securely send information over an unsecure channel, you need encryption.



              Symmetric encryption is out, because you would first need to transport the key, which you can't do securely over an unsecure channel[*].



              That leaves you with public key cryptography. You could of course roll your own, but you don't want to be a Dave, so that's out, which leaves you with HTTPS.



              [*] You can of course try to use a secure channel to exchange the key, for example physical exchange of a key. Then you can use secret key crypto, like Kerberos.






              share|improve this answer























              • Couldn't you hash it twice? Once on the client side, once on the server?
                – Nathan Merrill
                yesterday






              • 6




                @NathanMerrill - Hashing the password on the client side just makes the hash the password (absent some scheme to include extra information). However, only securing the password is worthless - you have to at least authenticate the channel, or an attacker can impersonate both ends of the conversation, even without knowing the password.
                – Clockwork-Muse
                yesterday










              • This is misleading. Yes, you can. This question asks for how to secure passwords when you can't use HTTP. A bad company policy, a misconfigured firewall can all force HTTP to be used. In situations like this, exchanging certificates (IPsec TLS SCRAM etc) through a side-channel is possible and should be the answer. Answer the question instead of giving advice that was not sought after.
                – noɥʇʎԀʎzɐɹƆ
                4 hours ago

















              up vote
              67
              down vote



              accepted










              You can't.



              To securely send information over an unsecure channel, you need encryption.



              Symmetric encryption is out, because you would first need to transport the key, which you can't do securely over an unsecure channel[*].



              That leaves you with public key cryptography. You could of course roll your own, but you don't want to be a Dave, so that's out, which leaves you with HTTPS.



              [*] You can of course try to use a secure channel to exchange the key, for example physical exchange of a key. Then you can use secret key crypto, like Kerberos.






              share|improve this answer























              • Couldn't you hash it twice? Once on the client side, once on the server?
                – Nathan Merrill
                yesterday






              • 6




                @NathanMerrill - Hashing the password on the client side just makes the hash the password (absent some scheme to include extra information). However, only securing the password is worthless - you have to at least authenticate the channel, or an attacker can impersonate both ends of the conversation, even without knowing the password.
                – Clockwork-Muse
                yesterday










              • This is misleading. Yes, you can. This question asks for how to secure passwords when you can't use HTTP. A bad company policy, a misconfigured firewall can all force HTTP to be used. In situations like this, exchanging certificates (IPsec TLS SCRAM etc) through a side-channel is possible and should be the answer. Answer the question instead of giving advice that was not sought after.
                – noɥʇʎԀʎzɐɹƆ
                4 hours ago















              up vote
              67
              down vote



              accepted







              up vote
              67
              down vote



              accepted






              You can't.



              To securely send information over an unsecure channel, you need encryption.



              Symmetric encryption is out, because you would first need to transport the key, which you can't do securely over an unsecure channel[*].



              That leaves you with public key cryptography. You could of course roll your own, but you don't want to be a Dave, so that's out, which leaves you with HTTPS.



              [*] You can of course try to use a secure channel to exchange the key, for example physical exchange of a key. Then you can use secret key crypto, like Kerberos.






              share|improve this answer














              You can't.



              To securely send information over an unsecure channel, you need encryption.



              Symmetric encryption is out, because you would first need to transport the key, which you can't do securely over an unsecure channel[*].



              That leaves you with public key cryptography. You could of course roll your own, but you don't want to be a Dave, so that's out, which leaves you with HTTPS.



              [*] You can of course try to use a secure channel to exchange the key, for example physical exchange of a key. Then you can use secret key crypto, like Kerberos.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited 2 days ago









              timothywalter

              332




              332










              answered 2 days ago









              tim

              22.4k55991




              22.4k55991












              • Couldn't you hash it twice? Once on the client side, once on the server?
                – Nathan Merrill
                yesterday






              • 6




                @NathanMerrill - Hashing the password on the client side just makes the hash the password (absent some scheme to include extra information). However, only securing the password is worthless - you have to at least authenticate the channel, or an attacker can impersonate both ends of the conversation, even without knowing the password.
                – Clockwork-Muse
                yesterday










              • This is misleading. Yes, you can. This question asks for how to secure passwords when you can't use HTTP. A bad company policy, a misconfigured firewall can all force HTTP to be used. In situations like this, exchanging certificates (IPsec TLS SCRAM etc) through a side-channel is possible and should be the answer. Answer the question instead of giving advice that was not sought after.
                – noɥʇʎԀʎzɐɹƆ
                4 hours ago




















              • Couldn't you hash it twice? Once on the client side, once on the server?
                – Nathan Merrill
                yesterday






              • 6




                @NathanMerrill - Hashing the password on the client side just makes the hash the password (absent some scheme to include extra information). However, only securing the password is worthless - you have to at least authenticate the channel, or an attacker can impersonate both ends of the conversation, even without knowing the password.
                – Clockwork-Muse
                yesterday










              • This is misleading. Yes, you can. This question asks for how to secure passwords when you can't use HTTP. A bad company policy, a misconfigured firewall can all force HTTP to be used. In situations like this, exchanging certificates (IPsec TLS SCRAM etc) through a side-channel is possible and should be the answer. Answer the question instead of giving advice that was not sought after.
                – noɥʇʎԀʎzɐɹƆ
                4 hours ago


















              Couldn't you hash it twice? Once on the client side, once on the server?
              – Nathan Merrill
              yesterday




              Couldn't you hash it twice? Once on the client side, once on the server?
              – Nathan Merrill
              yesterday




              6




              6




              @NathanMerrill - Hashing the password on the client side just makes the hash the password (absent some scheme to include extra information). However, only securing the password is worthless - you have to at least authenticate the channel, or an attacker can impersonate both ends of the conversation, even without knowing the password.
              – Clockwork-Muse
              yesterday




              @NathanMerrill - Hashing the password on the client side just makes the hash the password (absent some scheme to include extra information). However, only securing the password is worthless - you have to at least authenticate the channel, or an attacker can impersonate both ends of the conversation, even without knowing the password.
              – Clockwork-Muse
              yesterday












              This is misleading. Yes, you can. This question asks for how to secure passwords when you can't use HTTP. A bad company policy, a misconfigured firewall can all force HTTP to be used. In situations like this, exchanging certificates (IPsec TLS SCRAM etc) through a side-channel is possible and should be the answer. Answer the question instead of giving advice that was not sought after.
              – noɥʇʎԀʎzɐɹƆ
              4 hours ago






              This is misleading. Yes, you can. This question asks for how to secure passwords when you can't use HTTP. A bad company policy, a misconfigured firewall can all force HTTP to be used. In situations like this, exchanging certificates (IPsec TLS SCRAM etc) through a side-channel is possible and should be the answer. Answer the question instead of giving advice that was not sought after.
              – noɥʇʎԀʎzɐɹƆ
              4 hours ago














              up vote
              29
              down vote













              TLS is really the only way to do it.



              But what if I encrypt it with JavaScript?



              The attacker can change the JavaScript you send to the client, or simply inject their own JavaScript that logs all information entered.



              Then I'll use CSP and SRI to prevent the addition of scripts and the modification of my own scripts.



              Glad you're using modern tools to help protect your site, but SRI in a non-secure context really only protects against the compromise of an external resource. An attacker can simply modify the CSP headers and SRI tags.



              There's really no way to do this without using encryption from the beginning, and the only standard way to do that is to use TLS.






              share|improve this answer

























                up vote
                29
                down vote













                TLS is really the only way to do it.



                But what if I encrypt it with JavaScript?



                The attacker can change the JavaScript you send to the client, or simply inject their own JavaScript that logs all information entered.



                Then I'll use CSP and SRI to prevent the addition of scripts and the modification of my own scripts.



                Glad you're using modern tools to help protect your site, but SRI in a non-secure context really only protects against the compromise of an external resource. An attacker can simply modify the CSP headers and SRI tags.



                There's really no way to do this without using encryption from the beginning, and the only standard way to do that is to use TLS.






                share|improve this answer























                  up vote
                  29
                  down vote










                  up vote
                  29
                  down vote









                  TLS is really the only way to do it.



                  But what if I encrypt it with JavaScript?



                  The attacker can change the JavaScript you send to the client, or simply inject their own JavaScript that logs all information entered.



                  Then I'll use CSP and SRI to prevent the addition of scripts and the modification of my own scripts.



                  Glad you're using modern tools to help protect your site, but SRI in a non-secure context really only protects against the compromise of an external resource. An attacker can simply modify the CSP headers and SRI tags.



                  There's really no way to do this without using encryption from the beginning, and the only standard way to do that is to use TLS.






                  share|improve this answer












                  TLS is really the only way to do it.



                  But what if I encrypt it with JavaScript?



                  The attacker can change the JavaScript you send to the client, or simply inject their own JavaScript that logs all information entered.



                  Then I'll use CSP and SRI to prevent the addition of scripts and the modification of my own scripts.



                  Glad you're using modern tools to help protect your site, but SRI in a non-secure context really only protects against the compromise of an external resource. An attacker can simply modify the CSP headers and SRI tags.



                  There's really no way to do this without using encryption from the beginning, and the only standard way to do that is to use TLS.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 2 days ago









                  AndrolGenhald

                  8,58841830




                  8,58841830






















                      up vote
                      18
                      down vote













                      While I agree that you should use HTTPS, you can make it even more secure by using the Salted Challenge Response Authentication Mechanism (SCRAM, see RFC 5802) for the actual authentication exchange.



                      It's not trivial to implement, but the gist of it is that, rather than send the password to the server, you send proof to the server that you know the password. Since deriving the proof uses a nonce from the client and server, it's not something that can be reused by an attacker (like sending the hash itself would be).



                      This has a few added benefits to using HTTPS with the basic authentication you describe:




                      1. The server never actually sees your password as you log in. If someone has managed to insert malicious code onto the server, they still won't know what your password is.

                      2. If there is a bug in the HTTPS implementation (think Heartbleed), attackers still won't be able to acquire your password. Because, even once TLS is bypassed, the password isn't available.

                      3. If, for some reason, you can't use HTTPS, this is better than sending the password in the clear. An attacker will not be able to guess your password based on the exchange. That said, you should still use HTTPS, because defense in depth is better.


                      Please note that this is only secure if the client is able to perform the SCRAM computations without downloading code from the server. You could provide a fat client, or users may be able to write their own code that they control. Downloading the SCRAM code over HTTP would give an attacker an opportunity to modify the SCRAM code to send the password in cleartext, or otherwise expose it. Thank you to Zoltan for the clarification.






                      share|improve this answer










                      New contributor




                      Melanie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.














                      • 7




                        You can safely do this with a fat client (a desktop or mobile application) that is distributed in a safe manner. However, with an in-browser thin client, the client code itself is delivered over HTTP as well, and as @AndrolGenhald pointed out, attackers in the middle can intercept and change it to send the password to them.
                        – Zoltan
                        2 days ago






                      • 2




                        @Zoltan That's very true, thank you for the clarification. The original question doesn't specify whether they need a thin or fat client, so my answer wouldn't apply in all cases. But even over HTTP, I think this provides some additional security. The attack has gone from just snooping traffic to modifying code. Nothing insurmountable, so it wouldn't be secure, but maybe less bad? And I think having both HTTPS and SCRAM is very beneficial.
                        – Melanie
                        2 days ago










                      • If you agree, you may consider mentioning this restriction in your answer. Otherwise I really like your answer as challange-response was my first thought too and none of the other answers mentioned it.
                        – Zoltan
                        2 days ago










                      • Thank you, I've updated my answer. Let me know if you think it could use further clarifications!
                        – Melanie
                        2 days ago






                      • 1




                        @Melanie You are absolutely correct that even with just HTTP it's better. There are attackers only capable of passive attacks. That being said, there's no reason not to use HTTPS nowadays when it's free.
                        – Duncan X Simpson
                        2 days ago

















                      up vote
                      18
                      down vote













                      While I agree that you should use HTTPS, you can make it even more secure by using the Salted Challenge Response Authentication Mechanism (SCRAM, see RFC 5802) for the actual authentication exchange.



                      It's not trivial to implement, but the gist of it is that, rather than send the password to the server, you send proof to the server that you know the password. Since deriving the proof uses a nonce from the client and server, it's not something that can be reused by an attacker (like sending the hash itself would be).



                      This has a few added benefits to using HTTPS with the basic authentication you describe:




                      1. The server never actually sees your password as you log in. If someone has managed to insert malicious code onto the server, they still won't know what your password is.

                      2. If there is a bug in the HTTPS implementation (think Heartbleed), attackers still won't be able to acquire your password. Because, even once TLS is bypassed, the password isn't available.

                      3. If, for some reason, you can't use HTTPS, this is better than sending the password in the clear. An attacker will not be able to guess your password based on the exchange. That said, you should still use HTTPS, because defense in depth is better.


                      Please note that this is only secure if the client is able to perform the SCRAM computations without downloading code from the server. You could provide a fat client, or users may be able to write their own code that they control. Downloading the SCRAM code over HTTP would give an attacker an opportunity to modify the SCRAM code to send the password in cleartext, or otherwise expose it. Thank you to Zoltan for the clarification.






                      share|improve this answer










                      New contributor




                      Melanie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.














                      • 7




                        You can safely do this with a fat client (a desktop or mobile application) that is distributed in a safe manner. However, with an in-browser thin client, the client code itself is delivered over HTTP as well, and as @AndrolGenhald pointed out, attackers in the middle can intercept and change it to send the password to them.
                        – Zoltan
                        2 days ago






                      • 2




                        @Zoltan That's very true, thank you for the clarification. The original question doesn't specify whether they need a thin or fat client, so my answer wouldn't apply in all cases. But even over HTTP, I think this provides some additional security. The attack has gone from just snooping traffic to modifying code. Nothing insurmountable, so it wouldn't be secure, but maybe less bad? And I think having both HTTPS and SCRAM is very beneficial.
                        – Melanie
                        2 days ago










                      • If you agree, you may consider mentioning this restriction in your answer. Otherwise I really like your answer as challange-response was my first thought too and none of the other answers mentioned it.
                        – Zoltan
                        2 days ago










                      • Thank you, I've updated my answer. Let me know if you think it could use further clarifications!
                        – Melanie
                        2 days ago






                      • 1




                        @Melanie You are absolutely correct that even with just HTTP it's better. There are attackers only capable of passive attacks. That being said, there's no reason not to use HTTPS nowadays when it's free.
                        – Duncan X Simpson
                        2 days ago















                      up vote
                      18
                      down vote










                      up vote
                      18
                      down vote









                      While I agree that you should use HTTPS, you can make it even more secure by using the Salted Challenge Response Authentication Mechanism (SCRAM, see RFC 5802) for the actual authentication exchange.



                      It's not trivial to implement, but the gist of it is that, rather than send the password to the server, you send proof to the server that you know the password. Since deriving the proof uses a nonce from the client and server, it's not something that can be reused by an attacker (like sending the hash itself would be).



                      This has a few added benefits to using HTTPS with the basic authentication you describe:




                      1. The server never actually sees your password as you log in. If someone has managed to insert malicious code onto the server, they still won't know what your password is.

                      2. If there is a bug in the HTTPS implementation (think Heartbleed), attackers still won't be able to acquire your password. Because, even once TLS is bypassed, the password isn't available.

                      3. If, for some reason, you can't use HTTPS, this is better than sending the password in the clear. An attacker will not be able to guess your password based on the exchange. That said, you should still use HTTPS, because defense in depth is better.


                      Please note that this is only secure if the client is able to perform the SCRAM computations without downloading code from the server. You could provide a fat client, or users may be able to write their own code that they control. Downloading the SCRAM code over HTTP would give an attacker an opportunity to modify the SCRAM code to send the password in cleartext, or otherwise expose it. Thank you to Zoltan for the clarification.






                      share|improve this answer










                      New contributor




                      Melanie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.









                      While I agree that you should use HTTPS, you can make it even more secure by using the Salted Challenge Response Authentication Mechanism (SCRAM, see RFC 5802) for the actual authentication exchange.



                      It's not trivial to implement, but the gist of it is that, rather than send the password to the server, you send proof to the server that you know the password. Since deriving the proof uses a nonce from the client and server, it's not something that can be reused by an attacker (like sending the hash itself would be).



                      This has a few added benefits to using HTTPS with the basic authentication you describe:




                      1. The server never actually sees your password as you log in. If someone has managed to insert malicious code onto the server, they still won't know what your password is.

                      2. If there is a bug in the HTTPS implementation (think Heartbleed), attackers still won't be able to acquire your password. Because, even once TLS is bypassed, the password isn't available.

                      3. If, for some reason, you can't use HTTPS, this is better than sending the password in the clear. An attacker will not be able to guess your password based on the exchange. That said, you should still use HTTPS, because defense in depth is better.


                      Please note that this is only secure if the client is able to perform the SCRAM computations without downloading code from the server. You could provide a fat client, or users may be able to write their own code that they control. Downloading the SCRAM code over HTTP would give an attacker an opportunity to modify the SCRAM code to send the password in cleartext, or otherwise expose it. Thank you to Zoltan for the clarification.







                      share|improve this answer










                      New contributor




                      Melanie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.









                      share|improve this answer



                      share|improve this answer








                      edited 2 days ago





















                      New contributor




                      Melanie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.









                      answered 2 days ago









                      Melanie

                      1814




                      1814




                      New contributor




                      Melanie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.





                      New contributor





                      Melanie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.






                      Melanie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.








                      • 7




                        You can safely do this with a fat client (a desktop or mobile application) that is distributed in a safe manner. However, with an in-browser thin client, the client code itself is delivered over HTTP as well, and as @AndrolGenhald pointed out, attackers in the middle can intercept and change it to send the password to them.
                        – Zoltan
                        2 days ago






                      • 2




                        @Zoltan That's very true, thank you for the clarification. The original question doesn't specify whether they need a thin or fat client, so my answer wouldn't apply in all cases. But even over HTTP, I think this provides some additional security. The attack has gone from just snooping traffic to modifying code. Nothing insurmountable, so it wouldn't be secure, but maybe less bad? And I think having both HTTPS and SCRAM is very beneficial.
                        – Melanie
                        2 days ago










                      • If you agree, you may consider mentioning this restriction in your answer. Otherwise I really like your answer as challange-response was my first thought too and none of the other answers mentioned it.
                        – Zoltan
                        2 days ago










                      • Thank you, I've updated my answer. Let me know if you think it could use further clarifications!
                        – Melanie
                        2 days ago






                      • 1




                        @Melanie You are absolutely correct that even with just HTTP it's better. There are attackers only capable of passive attacks. That being said, there's no reason not to use HTTPS nowadays when it's free.
                        – Duncan X Simpson
                        2 days ago
















                      • 7




                        You can safely do this with a fat client (a desktop or mobile application) that is distributed in a safe manner. However, with an in-browser thin client, the client code itself is delivered over HTTP as well, and as @AndrolGenhald pointed out, attackers in the middle can intercept and change it to send the password to them.
                        – Zoltan
                        2 days ago






                      • 2




                        @Zoltan That's very true, thank you for the clarification. The original question doesn't specify whether they need a thin or fat client, so my answer wouldn't apply in all cases. But even over HTTP, I think this provides some additional security. The attack has gone from just snooping traffic to modifying code. Nothing insurmountable, so it wouldn't be secure, but maybe less bad? And I think having both HTTPS and SCRAM is very beneficial.
                        – Melanie
                        2 days ago










                      • If you agree, you may consider mentioning this restriction in your answer. Otherwise I really like your answer as challange-response was my first thought too and none of the other answers mentioned it.
                        – Zoltan
                        2 days ago










                      • Thank you, I've updated my answer. Let me know if you think it could use further clarifications!
                        – Melanie
                        2 days ago






                      • 1




                        @Melanie You are absolutely correct that even with just HTTP it's better. There are attackers only capable of passive attacks. That being said, there's no reason not to use HTTPS nowadays when it's free.
                        – Duncan X Simpson
                        2 days ago










                      7




                      7




                      You can safely do this with a fat client (a desktop or mobile application) that is distributed in a safe manner. However, with an in-browser thin client, the client code itself is delivered over HTTP as well, and as @AndrolGenhald pointed out, attackers in the middle can intercept and change it to send the password to them.
                      – Zoltan
                      2 days ago




                      You can safely do this with a fat client (a desktop or mobile application) that is distributed in a safe manner. However, with an in-browser thin client, the client code itself is delivered over HTTP as well, and as @AndrolGenhald pointed out, attackers in the middle can intercept and change it to send the password to them.
                      – Zoltan
                      2 days ago




                      2




                      2




                      @Zoltan That's very true, thank you for the clarification. The original question doesn't specify whether they need a thin or fat client, so my answer wouldn't apply in all cases. But even over HTTP, I think this provides some additional security. The attack has gone from just snooping traffic to modifying code. Nothing insurmountable, so it wouldn't be secure, but maybe less bad? And I think having both HTTPS and SCRAM is very beneficial.
                      – Melanie
                      2 days ago




                      @Zoltan That's very true, thank you for the clarification. The original question doesn't specify whether they need a thin or fat client, so my answer wouldn't apply in all cases. But even over HTTP, I think this provides some additional security. The attack has gone from just snooping traffic to modifying code. Nothing insurmountable, so it wouldn't be secure, but maybe less bad? And I think having both HTTPS and SCRAM is very beneficial.
                      – Melanie
                      2 days ago












                      If you agree, you may consider mentioning this restriction in your answer. Otherwise I really like your answer as challange-response was my first thought too and none of the other answers mentioned it.
                      – Zoltan
                      2 days ago




                      If you agree, you may consider mentioning this restriction in your answer. Otherwise I really like your answer as challange-response was my first thought too and none of the other answers mentioned it.
                      – Zoltan
                      2 days ago












                      Thank you, I've updated my answer. Let me know if you think it could use further clarifications!
                      – Melanie
                      2 days ago




                      Thank you, I've updated my answer. Let me know if you think it could use further clarifications!
                      – Melanie
                      2 days ago




                      1




                      1




                      @Melanie You are absolutely correct that even with just HTTP it's better. There are attackers only capable of passive attacks. That being said, there's no reason not to use HTTPS nowadays when it's free.
                      – Duncan X Simpson
                      2 days ago






                      @Melanie You are absolutely correct that even with just HTTP it's better. There are attackers only capable of passive attacks. That being said, there's no reason not to use HTTPS nowadays when it's free.
                      – Duncan X Simpson
                      2 days ago












                      up vote
                      5
                      down vote













                      You should definitely deploy TLS in this case.



                      If you decide to try to invent a transport security system over HTTP, ultimately you're going to end up implementing a susbset of the TLS functionality anyway. There are many pitfalls to be aware of when designing and implementing such a system, which are further amplified when you choose to try to implement the system with a language that doesn't offer many safety features.



                      Even if you did implement a correct implementation of a cryptographic protocol in JavaScript (which is already a big challenge) you can't rely upon that implementation being resistant to timing attacks, and the whole thing breaks if someone has scripts disabled (e.g. with NoScript).



                      As a general rule you should choose the implementation that consists of the most simple, well-understood, trusted components that require you to write the least amount of security-critical code. To quote Andrew Tannenbaum:




                      A substantial number of the problems (in application security) are caused by buggy software, which occurs because vendors keep adding more and more features to their programs, which inevitably means more code and thus more bugs.







                      share|improve this answer

























                        up vote
                        5
                        down vote













                        You should definitely deploy TLS in this case.



                        If you decide to try to invent a transport security system over HTTP, ultimately you're going to end up implementing a susbset of the TLS functionality anyway. There are many pitfalls to be aware of when designing and implementing such a system, which are further amplified when you choose to try to implement the system with a language that doesn't offer many safety features.



                        Even if you did implement a correct implementation of a cryptographic protocol in JavaScript (which is already a big challenge) you can't rely upon that implementation being resistant to timing attacks, and the whole thing breaks if someone has scripts disabled (e.g. with NoScript).



                        As a general rule you should choose the implementation that consists of the most simple, well-understood, trusted components that require you to write the least amount of security-critical code. To quote Andrew Tannenbaum:




                        A substantial number of the problems (in application security) are caused by buggy software, which occurs because vendors keep adding more and more features to their programs, which inevitably means more code and thus more bugs.







                        share|improve this answer























                          up vote
                          5
                          down vote










                          up vote
                          5
                          down vote









                          You should definitely deploy TLS in this case.



                          If you decide to try to invent a transport security system over HTTP, ultimately you're going to end up implementing a susbset of the TLS functionality anyway. There are many pitfalls to be aware of when designing and implementing such a system, which are further amplified when you choose to try to implement the system with a language that doesn't offer many safety features.



                          Even if you did implement a correct implementation of a cryptographic protocol in JavaScript (which is already a big challenge) you can't rely upon that implementation being resistant to timing attacks, and the whole thing breaks if someone has scripts disabled (e.g. with NoScript).



                          As a general rule you should choose the implementation that consists of the most simple, well-understood, trusted components that require you to write the least amount of security-critical code. To quote Andrew Tannenbaum:




                          A substantial number of the problems (in application security) are caused by buggy software, which occurs because vendors keep adding more and more features to their programs, which inevitably means more code and thus more bugs.







                          share|improve this answer












                          You should definitely deploy TLS in this case.



                          If you decide to try to invent a transport security system over HTTP, ultimately you're going to end up implementing a susbset of the TLS functionality anyway. There are many pitfalls to be aware of when designing and implementing such a system, which are further amplified when you choose to try to implement the system with a language that doesn't offer many safety features.



                          Even if you did implement a correct implementation of a cryptographic protocol in JavaScript (which is already a big challenge) you can't rely upon that implementation being resistant to timing attacks, and the whole thing breaks if someone has scripts disabled (e.g. with NoScript).



                          As a general rule you should choose the implementation that consists of the most simple, well-understood, trusted components that require you to write the least amount of security-critical code. To quote Andrew Tannenbaum:




                          A substantial number of the problems (in application security) are caused by buggy software, which occurs because vendors keep adding more and more features to their programs, which inevitably means more code and thus more bugs.








                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered 2 days ago









                          Polynomial

                          95.7k29241325




                          95.7k29241325






















                              up vote
                              4
                              down vote














                              Do I need to implement some encryption algorithm like RSA public key encryption?




                              If you're considering trying that, you may as well just go the full mile and use HTTPS. Since you don't seem to be an expert, "rolling your own" encryption will undoubtedly have misimplementations that render it insecure.






                              share|improve this answer

























                                up vote
                                4
                                down vote














                                Do I need to implement some encryption algorithm like RSA public key encryption?




                                If you're considering trying that, you may as well just go the full mile and use HTTPS. Since you don't seem to be an expert, "rolling your own" encryption will undoubtedly have misimplementations that render it insecure.






                                share|improve this answer























                                  up vote
                                  4
                                  down vote










                                  up vote
                                  4
                                  down vote










                                  Do I need to implement some encryption algorithm like RSA public key encryption?




                                  If you're considering trying that, you may as well just go the full mile and use HTTPS. Since you don't seem to be an expert, "rolling your own" encryption will undoubtedly have misimplementations that render it insecure.






                                  share|improve this answer













                                  Do I need to implement some encryption algorithm like RSA public key encryption?




                                  If you're considering trying that, you may as well just go the full mile and use HTTPS. Since you don't seem to be an expert, "rolling your own" encryption will undoubtedly have misimplementations that render it insecure.







                                  share|improve this answer












                                  share|improve this answer



                                  share|improve this answer










                                  answered 2 days ago









                                  Brian Williams

                                  1764




                                  1764






















                                      up vote
                                      2
                                      down vote













                                      It is actually quite possible.



                                      Password has to be hashed on the client side, but not with a static function. The following method uses two steps, and is inspired by the Digest access authentication:



                                      NOTE: The server keeps a HMAC of the Password and the corresponding Key (Digest);




                                      1. The client starts by requesting a nonce to the server, the server returns the Key and the Nonce;

                                      2. Client calculates: HMAC( HMAC( Password, Key ), Nonce) and sends it to the server;

                                      3. Server calculates: HMAC( Digest, Nonce ) and compares it to the received value.


                                      This protects you against replay.



                                      The main interest I see is not a protection against eavesdropping, but to be completely sure that the plaintext password will not be store on the server, not even in a system log (see Twitter or GitHub).



                                      Note: HMAC can be replaced by PBKDF2.






                                      share|improve this answer










                                      New contributor




                                      Pierre del Perugia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                      Check out our Code of Conduct.














                                      • 1




                                        Then some attacker can inject some code to get the password directly from the <input>. A crazy idea: "Sadly it's just a little bit hard to support HTTPS on Reserved IP addresses. Please run this code on your terminal and paste the result HMAC were." (of course disable copy pasting to prevent pastejacking in the long run).
                                        – Gustavo Rodrigues
                                        yesterday















                                      up vote
                                      2
                                      down vote













                                      It is actually quite possible.



                                      Password has to be hashed on the client side, but not with a static function. The following method uses two steps, and is inspired by the Digest access authentication:



                                      NOTE: The server keeps a HMAC of the Password and the corresponding Key (Digest);




                                      1. The client starts by requesting a nonce to the server, the server returns the Key and the Nonce;

                                      2. Client calculates: HMAC( HMAC( Password, Key ), Nonce) and sends it to the server;

                                      3. Server calculates: HMAC( Digest, Nonce ) and compares it to the received value.


                                      This protects you against replay.



                                      The main interest I see is not a protection against eavesdropping, but to be completely sure that the plaintext password will not be store on the server, not even in a system log (see Twitter or GitHub).



                                      Note: HMAC can be replaced by PBKDF2.






                                      share|improve this answer










                                      New contributor




                                      Pierre del Perugia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                      Check out our Code of Conduct.














                                      • 1




                                        Then some attacker can inject some code to get the password directly from the <input>. A crazy idea: "Sadly it's just a little bit hard to support HTTPS on Reserved IP addresses. Please run this code on your terminal and paste the result HMAC were." (of course disable copy pasting to prevent pastejacking in the long run).
                                        – Gustavo Rodrigues
                                        yesterday













                                      up vote
                                      2
                                      down vote










                                      up vote
                                      2
                                      down vote









                                      It is actually quite possible.



                                      Password has to be hashed on the client side, but not with a static function. The following method uses two steps, and is inspired by the Digest access authentication:



                                      NOTE: The server keeps a HMAC of the Password and the corresponding Key (Digest);




                                      1. The client starts by requesting a nonce to the server, the server returns the Key and the Nonce;

                                      2. Client calculates: HMAC( HMAC( Password, Key ), Nonce) and sends it to the server;

                                      3. Server calculates: HMAC( Digest, Nonce ) and compares it to the received value.


                                      This protects you against replay.



                                      The main interest I see is not a protection against eavesdropping, but to be completely sure that the plaintext password will not be store on the server, not even in a system log (see Twitter or GitHub).



                                      Note: HMAC can be replaced by PBKDF2.






                                      share|improve this answer










                                      New contributor




                                      Pierre del Perugia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                      Check out our Code of Conduct.









                                      It is actually quite possible.



                                      Password has to be hashed on the client side, but not with a static function. The following method uses two steps, and is inspired by the Digest access authentication:



                                      NOTE: The server keeps a HMAC of the Password and the corresponding Key (Digest);




                                      1. The client starts by requesting a nonce to the server, the server returns the Key and the Nonce;

                                      2. Client calculates: HMAC( HMAC( Password, Key ), Nonce) and sends it to the server;

                                      3. Server calculates: HMAC( Digest, Nonce ) and compares it to the received value.


                                      This protects you against replay.



                                      The main interest I see is not a protection against eavesdropping, but to be completely sure that the plaintext password will not be store on the server, not even in a system log (see Twitter or GitHub).



                                      Note: HMAC can be replaced by PBKDF2.







                                      share|improve this answer










                                      New contributor




                                      Pierre del Perugia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                      Check out our Code of Conduct.









                                      share|improve this answer



                                      share|improve this answer








                                      edited yesterday









                                      emory

                                      1,4881013




                                      1,4881013






                                      New contributor




                                      Pierre del Perugia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                      Check out our Code of Conduct.









                                      answered yesterday









                                      Pierre del Perugia

                                      211




                                      211




                                      New contributor




                                      Pierre del Perugia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                      Check out our Code of Conduct.





                                      New contributor





                                      Pierre del Perugia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                      Check out our Code of Conduct.






                                      Pierre del Perugia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                      Check out our Code of Conduct.








                                      • 1




                                        Then some attacker can inject some code to get the password directly from the <input>. A crazy idea: "Sadly it's just a little bit hard to support HTTPS on Reserved IP addresses. Please run this code on your terminal and paste the result HMAC were." (of course disable copy pasting to prevent pastejacking in the long run).
                                        – Gustavo Rodrigues
                                        yesterday














                                      • 1




                                        Then some attacker can inject some code to get the password directly from the <input>. A crazy idea: "Sadly it's just a little bit hard to support HTTPS on Reserved IP addresses. Please run this code on your terminal and paste the result HMAC were." (of course disable copy pasting to prevent pastejacking in the long run).
                                        – Gustavo Rodrigues
                                        yesterday








                                      1




                                      1




                                      Then some attacker can inject some code to get the password directly from the <input>. A crazy idea: "Sadly it's just a little bit hard to support HTTPS on Reserved IP addresses. Please run this code on your terminal and paste the result HMAC were." (of course disable copy pasting to prevent pastejacking in the long run).
                                      – Gustavo Rodrigues
                                      yesterday




                                      Then some attacker can inject some code to get the password directly from the <input>. A crazy idea: "Sadly it's just a little bit hard to support HTTPS on Reserved IP addresses. Please run this code on your terminal and paste the result HMAC were." (of course disable copy pasting to prevent pastejacking in the long run).
                                      – Gustavo Rodrigues
                                      yesterday










                                      up vote
                                      1
                                      down vote













                                      There is actually a way to authenticate a user over an insecure connection: Secure Remote Password (SRP) protocol. SRP is specifically designed to allow a client to authenticate itself to a server without a Man-in-the-Middle attacker being able to capture the client's password, or even replay the authentication to later impersonate the client, whether the authentication succeeded or not. Furthermore, successful authentication with SRP creates a shared secret key that both the client and the server know, but a MitM does not. This secret key could be used for symmetric encryption and/or HMACs.



                                      However, there are a number of limitations of SRP:




                                      1. The user must have registered in some secure fashion, as the registration process does require transmitting password-equivalent material (though the server does not need to store it).

                                      2. Although it is safe to attempt an SRP login with an untrusted server (that is, it won't expose your password to that server, and you'll be able to tell that the server didn't have your password in its database), It's not safe to load a login web page from an untrusted server (it could send down a page that captures your every keystroke and sends it off somewhere).

                                      3. Although successful authentication via SRP generates a secure shared secret key, the code to actually use this key in a web app would need to be loaded from a server, and an attacker could tamper with that code to steal the symmetric key and make changes to the requests and responses.


                                      In other words, while SRP can be useful in situations where you have a trusted client that doesn't need to download its code over the insecure connection and also you have some other secure way to register the user(s), SRP is not suitable for a web application. Web apps always download their code from the server, so if the connection to the server isn't secure, a MitM (or other network attacker, for example somebody spoofing DNS) can inject malicious code into the web app and there's nothing that you, the victim, can do about it. Once that code is there, it can capture any password or other data you enter, steal any key that is generated, and tamper with any requests you send or responses you receive without you even knowing.






                                      share|improve this answer

























                                        up vote
                                        1
                                        down vote













                                        There is actually a way to authenticate a user over an insecure connection: Secure Remote Password (SRP) protocol. SRP is specifically designed to allow a client to authenticate itself to a server without a Man-in-the-Middle attacker being able to capture the client's password, or even replay the authentication to later impersonate the client, whether the authentication succeeded or not. Furthermore, successful authentication with SRP creates a shared secret key that both the client and the server know, but a MitM does not. This secret key could be used for symmetric encryption and/or HMACs.



                                        However, there are a number of limitations of SRP:




                                        1. The user must have registered in some secure fashion, as the registration process does require transmitting password-equivalent material (though the server does not need to store it).

                                        2. Although it is safe to attempt an SRP login with an untrusted server (that is, it won't expose your password to that server, and you'll be able to tell that the server didn't have your password in its database), It's not safe to load a login web page from an untrusted server (it could send down a page that captures your every keystroke and sends it off somewhere).

                                        3. Although successful authentication via SRP generates a secure shared secret key, the code to actually use this key in a web app would need to be loaded from a server, and an attacker could tamper with that code to steal the symmetric key and make changes to the requests and responses.


                                        In other words, while SRP can be useful in situations where you have a trusted client that doesn't need to download its code over the insecure connection and also you have some other secure way to register the user(s), SRP is not suitable for a web application. Web apps always download their code from the server, so if the connection to the server isn't secure, a MitM (or other network attacker, for example somebody spoofing DNS) can inject malicious code into the web app and there's nothing that you, the victim, can do about it. Once that code is there, it can capture any password or other data you enter, steal any key that is generated, and tamper with any requests you send or responses you receive without you even knowing.






                                        share|improve this answer























                                          up vote
                                          1
                                          down vote










                                          up vote
                                          1
                                          down vote









                                          There is actually a way to authenticate a user over an insecure connection: Secure Remote Password (SRP) protocol. SRP is specifically designed to allow a client to authenticate itself to a server without a Man-in-the-Middle attacker being able to capture the client's password, or even replay the authentication to later impersonate the client, whether the authentication succeeded or not. Furthermore, successful authentication with SRP creates a shared secret key that both the client and the server know, but a MitM does not. This secret key could be used for symmetric encryption and/or HMACs.



                                          However, there are a number of limitations of SRP:




                                          1. The user must have registered in some secure fashion, as the registration process does require transmitting password-equivalent material (though the server does not need to store it).

                                          2. Although it is safe to attempt an SRP login with an untrusted server (that is, it won't expose your password to that server, and you'll be able to tell that the server didn't have your password in its database), It's not safe to load a login web page from an untrusted server (it could send down a page that captures your every keystroke and sends it off somewhere).

                                          3. Although successful authentication via SRP generates a secure shared secret key, the code to actually use this key in a web app would need to be loaded from a server, and an attacker could tamper with that code to steal the symmetric key and make changes to the requests and responses.


                                          In other words, while SRP can be useful in situations where you have a trusted client that doesn't need to download its code over the insecure connection and also you have some other secure way to register the user(s), SRP is not suitable for a web application. Web apps always download their code from the server, so if the connection to the server isn't secure, a MitM (or other network attacker, for example somebody spoofing DNS) can inject malicious code into the web app and there's nothing that you, the victim, can do about it. Once that code is there, it can capture any password or other data you enter, steal any key that is generated, and tamper with any requests you send or responses you receive without you even knowing.






                                          share|improve this answer












                                          There is actually a way to authenticate a user over an insecure connection: Secure Remote Password (SRP) protocol. SRP is specifically designed to allow a client to authenticate itself to a server without a Man-in-the-Middle attacker being able to capture the client's password, or even replay the authentication to later impersonate the client, whether the authentication succeeded or not. Furthermore, successful authentication with SRP creates a shared secret key that both the client and the server know, but a MitM does not. This secret key could be used for symmetric encryption and/or HMACs.



                                          However, there are a number of limitations of SRP:




                                          1. The user must have registered in some secure fashion, as the registration process does require transmitting password-equivalent material (though the server does not need to store it).

                                          2. Although it is safe to attempt an SRP login with an untrusted server (that is, it won't expose your password to that server, and you'll be able to tell that the server didn't have your password in its database), It's not safe to load a login web page from an untrusted server (it could send down a page that captures your every keystroke and sends it off somewhere).

                                          3. Although successful authentication via SRP generates a secure shared secret key, the code to actually use this key in a web app would need to be loaded from a server, and an attacker could tamper with that code to steal the symmetric key and make changes to the requests and responses.


                                          In other words, while SRP can be useful in situations where you have a trusted client that doesn't need to download its code over the insecure connection and also you have some other secure way to register the user(s), SRP is not suitable for a web application. Web apps always download their code from the server, so if the connection to the server isn't secure, a MitM (or other network attacker, for example somebody spoofing DNS) can inject malicious code into the web app and there's nothing that you, the victim, can do about it. Once that code is there, it can capture any password or other data you enter, steal any key that is generated, and tamper with any requests you send or responses you receive without you even knowing.







                                          share|improve this answer












                                          share|improve this answer



                                          share|improve this answer










                                          answered yesterday









                                          CBHacking

                                          9,01711527




                                          9,01711527






















                                              up vote
                                              0
                                              down vote













                                              An alternative would be to set up a secure VPN to the destination server, and perform a HTTP login from there. A malicious man in the middle will therefore have to break the encryption on the VPN channel in order to attack the connection and retrieve the passwords.



                                              However, in terms of end user usability, it's still not as good as HTTPS, since it requires them to setup and use a different channel with a different set of credentials.






                                              share|improve this answer





















                                              • How is the DNS resolution protected? (1) Is the DNS resolver (a) local? (b) reachable by a secure link? (2)(a) Does resolution happen over the VPN? Is the authoritative DNS server reachable by the resolver by a secure link? (b) What happens if the DNS resolution occurs before the VPN is set-up? (c) Can false DNS results obtained before the VPN is set-up be cached? (3)(a) Does the resolver use DNSSEC? (b) How is validation failure treated by the resolver? DNS resolution can be secured, by it isn't trivial.
                                                – curiousguy
                                                yesterday










                                              • @curiousguy The same can be said for HTTPS though, unless you manually verify the certificate.
                                                – March Ho
                                                7 hours ago















                                              up vote
                                              0
                                              down vote













                                              An alternative would be to set up a secure VPN to the destination server, and perform a HTTP login from there. A malicious man in the middle will therefore have to break the encryption on the VPN channel in order to attack the connection and retrieve the passwords.



                                              However, in terms of end user usability, it's still not as good as HTTPS, since it requires them to setup and use a different channel with a different set of credentials.






                                              share|improve this answer





















                                              • How is the DNS resolution protected? (1) Is the DNS resolver (a) local? (b) reachable by a secure link? (2)(a) Does resolution happen over the VPN? Is the authoritative DNS server reachable by the resolver by a secure link? (b) What happens if the DNS resolution occurs before the VPN is set-up? (c) Can false DNS results obtained before the VPN is set-up be cached? (3)(a) Does the resolver use DNSSEC? (b) How is validation failure treated by the resolver? DNS resolution can be secured, by it isn't trivial.
                                                – curiousguy
                                                yesterday










                                              • @curiousguy The same can be said for HTTPS though, unless you manually verify the certificate.
                                                – March Ho
                                                7 hours ago













                                              up vote
                                              0
                                              down vote










                                              up vote
                                              0
                                              down vote









                                              An alternative would be to set up a secure VPN to the destination server, and perform a HTTP login from there. A malicious man in the middle will therefore have to break the encryption on the VPN channel in order to attack the connection and retrieve the passwords.



                                              However, in terms of end user usability, it's still not as good as HTTPS, since it requires them to setup and use a different channel with a different set of credentials.






                                              share|improve this answer












                                              An alternative would be to set up a secure VPN to the destination server, and perform a HTTP login from there. A malicious man in the middle will therefore have to break the encryption on the VPN channel in order to attack the connection and retrieve the passwords.



                                              However, in terms of end user usability, it's still not as good as HTTPS, since it requires them to setup and use a different channel with a different set of credentials.







                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered 2 days ago









                                              March Ho

                                              8631713




                                              8631713












                                              • How is the DNS resolution protected? (1) Is the DNS resolver (a) local? (b) reachable by a secure link? (2)(a) Does resolution happen over the VPN? Is the authoritative DNS server reachable by the resolver by a secure link? (b) What happens if the DNS resolution occurs before the VPN is set-up? (c) Can false DNS results obtained before the VPN is set-up be cached? (3)(a) Does the resolver use DNSSEC? (b) How is validation failure treated by the resolver? DNS resolution can be secured, by it isn't trivial.
                                                – curiousguy
                                                yesterday










                                              • @curiousguy The same can be said for HTTPS though, unless you manually verify the certificate.
                                                – March Ho
                                                7 hours ago


















                                              • How is the DNS resolution protected? (1) Is the DNS resolver (a) local? (b) reachable by a secure link? (2)(a) Does resolution happen over the VPN? Is the authoritative DNS server reachable by the resolver by a secure link? (b) What happens if the DNS resolution occurs before the VPN is set-up? (c) Can false DNS results obtained before the VPN is set-up be cached? (3)(a) Does the resolver use DNSSEC? (b) How is validation failure treated by the resolver? DNS resolution can be secured, by it isn't trivial.
                                                – curiousguy
                                                yesterday










                                              • @curiousguy The same can be said for HTTPS though, unless you manually verify the certificate.
                                                – March Ho
                                                7 hours ago
















                                              How is the DNS resolution protected? (1) Is the DNS resolver (a) local? (b) reachable by a secure link? (2)(a) Does resolution happen over the VPN? Is the authoritative DNS server reachable by the resolver by a secure link? (b) What happens if the DNS resolution occurs before the VPN is set-up? (c) Can false DNS results obtained before the VPN is set-up be cached? (3)(a) Does the resolver use DNSSEC? (b) How is validation failure treated by the resolver? DNS resolution can be secured, by it isn't trivial.
                                              – curiousguy
                                              yesterday




                                              How is the DNS resolution protected? (1) Is the DNS resolver (a) local? (b) reachable by a secure link? (2)(a) Does resolution happen over the VPN? Is the authoritative DNS server reachable by the resolver by a secure link? (b) What happens if the DNS resolution occurs before the VPN is set-up? (c) Can false DNS results obtained before the VPN is set-up be cached? (3)(a) Does the resolver use DNSSEC? (b) How is validation failure treated by the resolver? DNS resolution can be secured, by it isn't trivial.
                                              – curiousguy
                                              yesterday












                                              @curiousguy The same can be said for HTTPS though, unless you manually verify the certificate.
                                              – March Ho
                                              7 hours ago




                                              @curiousguy The same can be said for HTTPS though, unless you manually verify the certificate.
                                              – March Ho
                                              7 hours ago










                                              up vote
                                              0
                                              down vote













                                              It is certainly possible to send a password securely using HTTP. There is even a standard for it. It's called HTTP-Digest and it's defined in RFC 7616. It's been a part of the HTTP spec for quite a while. It was originally designed to use only the MD5 message-digest ("hashing") algorithm, but later revisions of the standard allow the client and server to negotiate which algorithm to use.



                                              Unfortunately, there are many problems with HTTP-digest and the most glaring of them is that the server needs to have the password in cleartext. So while it's possible to communicate passwords securely using HTTP, it's not possible to securely-store passwords on the server while using it. So basically, it's not useful.



                                              As others have said, it would be better to implement TLS because it solves multiple problems all at the same time, and it's fairly forward-compatible.






                                              share|improve this answer

























                                                up vote
                                                0
                                                down vote













                                                It is certainly possible to send a password securely using HTTP. There is even a standard for it. It's called HTTP-Digest and it's defined in RFC 7616. It's been a part of the HTTP spec for quite a while. It was originally designed to use only the MD5 message-digest ("hashing") algorithm, but later revisions of the standard allow the client and server to negotiate which algorithm to use.



                                                Unfortunately, there are many problems with HTTP-digest and the most glaring of them is that the server needs to have the password in cleartext. So while it's possible to communicate passwords securely using HTTP, it's not possible to securely-store passwords on the server while using it. So basically, it's not useful.



                                                As others have said, it would be better to implement TLS because it solves multiple problems all at the same time, and it's fairly forward-compatible.






                                                share|improve this answer























                                                  up vote
                                                  0
                                                  down vote










                                                  up vote
                                                  0
                                                  down vote









                                                  It is certainly possible to send a password securely using HTTP. There is even a standard for it. It's called HTTP-Digest and it's defined in RFC 7616. It's been a part of the HTTP spec for quite a while. It was originally designed to use only the MD5 message-digest ("hashing") algorithm, but later revisions of the standard allow the client and server to negotiate which algorithm to use.



                                                  Unfortunately, there are many problems with HTTP-digest and the most glaring of them is that the server needs to have the password in cleartext. So while it's possible to communicate passwords securely using HTTP, it's not possible to securely-store passwords on the server while using it. So basically, it's not useful.



                                                  As others have said, it would be better to implement TLS because it solves multiple problems all at the same time, and it's fairly forward-compatible.






                                                  share|improve this answer












                                                  It is certainly possible to send a password securely using HTTP. There is even a standard for it. It's called HTTP-Digest and it's defined in RFC 7616. It's been a part of the HTTP spec for quite a while. It was originally designed to use only the MD5 message-digest ("hashing") algorithm, but later revisions of the standard allow the client and server to negotiate which algorithm to use.



                                                  Unfortunately, there are many problems with HTTP-digest and the most glaring of them is that the server needs to have the password in cleartext. So while it's possible to communicate passwords securely using HTTP, it's not possible to securely-store passwords on the server while using it. So basically, it's not useful.



                                                  As others have said, it would be better to implement TLS because it solves multiple problems all at the same time, and it's fairly forward-compatible.







                                                  share|improve this answer












                                                  share|improve this answer



                                                  share|improve this answer










                                                  answered yesterday









                                                  Christopher Schultz

                                                  1978




                                                  1978






















                                                      up vote
                                                      -1
                                                      down vote













                                                      You need the recipient to send you his key. You can't randomly send someone encrypted info without them first providing you with their personal public key.






                                                      share|improve this answer

























                                                        up vote
                                                        -1
                                                        down vote













                                                        You need the recipient to send you his key. You can't randomly send someone encrypted info without them first providing you with their personal public key.






                                                        share|improve this answer























                                                          up vote
                                                          -1
                                                          down vote










                                                          up vote
                                                          -1
                                                          down vote









                                                          You need the recipient to send you his key. You can't randomly send someone encrypted info without them first providing you with their personal public key.






                                                          share|improve this answer












                                                          You need the recipient to send you his key. You can't randomly send someone encrypted info without them first providing you with their personal public key.







                                                          share|improve this answer












                                                          share|improve this answer



                                                          share|improve this answer










                                                          answered yesterday









                                                          Tomachi

                                                          1042




                                                          1042






















                                                              FireCubez is a new contributor. Be nice, and check out our Code of Conduct.










                                                               

                                                              draft saved


                                                              draft discarded


















                                                              FireCubez is a new contributor. Be nice, and check out our Code of Conduct.













                                                              FireCubez is a new contributor. Be nice, and check out our Code of Conduct.












                                                              FireCubez is a new contributor. Be nice, and check out our Code of Conduct.















                                                               


                                                              draft saved


                                                              draft discarded














                                                              StackExchange.ready(
                                                              function () {
                                                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsecurity.stackexchange.com%2fquestions%2f197330%2fhow-to-secure-passwords-over-http%23new-answer', 'question_page');
                                                              }
                                                              );

                                                              Post as a guest




















































































                                                              Popular posts from this blog

                                                              Full-time equivalent

                                                              さくらももこ

                                                              13 indicted, 8 arrested in Calif. drug cartel investigation