Search code examples
authentication-flows

authentication-flows email URL's do not work after web server reset


I have been playing around with authentication-flows and noticed that when I restart the web server the URL's no longer work, they are all invalid. I walked through debugging but I am still a bit lost as to exactly why, though I have a lot of good reasons why it should happen (and I am sure you do also).

I want to make a service which will be distributed to multiple containers and when a request comes in any of them could serve it. As the solution stands right now, it looks like I will have to make modifications to make possible.

What exactly is making the URL invalid? and what changes could I make to make my proposed solution possible?

Thank you in advance.


In response to Ohard's comment:

1. Why the URL is invalid

Let me tell you how I get the error. I deploy the war, submit forgot password. Receive the email to reset my password then stop the war. When that happens my reset password page extracts the enc. I then stop and redeploy the war. After isend a rest request with the enc and a new password to the /rest/setNewPassword mapping, then receive:

09 Jan 2016 03:50:48,799 [http-nio-8082-exec-1] ERROR web.rest.UserActionRestController - Failed to decrypt URL content aX8uaOWkqAUQN2xOzlPAOHJjPZaxBwho7.yoMeUtMnJA

in ohadr\crypto\service\CryptoService.java there is an exception on line 261:

throw new CryptoException("Failed to decrypt URL content " + based64EncryptedContent, e);

which I then use a break point to find:

java aes javax.crypto.BadPaddingException: Given final block not properly padded

I am sure if you try to reproduce this issue, you will find the same results...

Note: when I do this without the re-deploy everything works great!

2. How to make auth-flows work as SaaS

There are three use cases I want this service to fulfil:

  1. Currently, If I host a service and it goes down without a fail-over, people who have URL's will be unable to use their links when it comes back up. I want them to be able to use the links regardless.

  2. (untested -- but will be soon) Similar to the second, If I host this service on multiple docker containers I believe that it will not be able to receive link that did not orginially come from its container, therefore containers could not share unsorted loads. It should be able to read any of the enc's and process it.


EDIT:

1. Why the URL is invalid

An even easier way to test this is just to submit a forgotten password, get the email and then stop the war. Redeploy it, then click the link. I got this stack trace:

https://drive.google.com/file/d/0Bwa-JXbjFUDueXVMWWJibjY2Zm8/view?usp=sharing

Don't worry about csrf it is not enabled.


Solution

  • @EdiZ is right.

    To be more accurate, every time your web-app loads, Spring loads all the beans. Among them are Crypto's library beans, such as CryptoUtil and CryptoProvider, and if you look carefully you will notice on DefaultCryptoProvider.loadMasterKeys() that a new key is generated.

    I believe that explains the behavior you see.

    Currently, If I host a service and it goes down without a fail-over, people who have URL's will be unable to use their links when it comes back up. I want them to be able to use the links regardless

    It seems to be a duplication of your first question; I think that the first issue will have to be resolved in order to make it work as you wish. If the server reboots, all the links become invalid - the users will have to click again on "forget password" (for example) and get a new link - it is for you to decide how big this deal is.

    If I host this service and I do have a failover I assume the failover will not be able to read URL that is not from it originally. It should be able to read any of the enc's and process it.

    I assume that you have to develop some more persistence, so the server can decrypt URLs that were not generated by it...

    Hope that helps.