Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1048: Solved base64 problem with remember me cookie. #1049

Merged
merged 1 commit into from
Sep 3, 2023

Conversation

JaapD
Copy link

@JaapD JaapD commented Aug 24, 2023

Issue 1048

The cookie value sometimes got too much '=' characters at the end.
I created a test to make the method fail, then I solved the problem. That fixed the test and made the RememberMe work again.

@lprimak
Copy link
Contributor

lprimak commented Aug 25, 2023

Thanks for your contribution!
Looks like org.apache.shiro.web.mgt.CookieRememberMeManagerTest.getRememberedPrincipalsDecryptionError is failing

Error
Unable to correctly extract the Initialization Vector or ciphertext.
Stacktrace
org.apache.shiro.crypto.CryptoException: Unable to correctly extract the Initialization Vector or ciphertext.
	at org.apache.shiro.crypto.cipher.JcaCipherService.decryptInternal(JcaCipherService.java:383)
	at org.apache.shiro.crypto.cipher.SimpleByteSourceBroker.getClonedBytes(SimpleByteSourceBroker.java:60)
	at org.apache.shiro.mgt.AbstractRememberMeManager.decrypt(AbstractRememberMeManager.java:496)
	at org.apache.shiro.mgt.AbstractRememberMeManager.convertBytesToPrincipals(AbstractRememberMeManager.java:432)
	at org.apache.shiro.mgt.AbstractRememberMeManager.getRememberedPrincipals(AbstractRememberMeManager.java:397)
	at org.apache.shiro.web.mgt.CookieRememberMeManagerTest.getRememberedPrincipalsDecryptionError(CookieRememberMeManagerTest.java:216)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
Caused by: java.lang.ArrayIndexOutOfBoundsException: arraycopy: last source index 16 out of bounds for byte[5]
	at java.base/java.lang.System.arraycopy(Native Method)
	at org.apache.shiro.crypto.cipher.JcaCipherService.decryptInternal(JcaCipherService.java:375)
	... 8 more
Standard Output
19:19:57.425 [main] WARN  org.apache.shiro.mgt.AbstractRememberMeManager - There was a failure while trying to retrieve remembered principals.  This could be due to a configuration problem or corrupted principals.  This could also be due to a recently changed encryption key, if you are using a shiro.ini file, this property would be 'securityManager.rememberMeManager.cipherKey' see: http://shiro.apache.org/web.html#Web-RememberMeServices. The remembered identity will be forgotten and not used for this request.
@JaapD
Copy link
Author

JaapD commented Aug 27, 2023

It looks like the failing test tested the wrong situation. I split it in two tests: one that discovers a Base64 string that is invalid and another one that discovers the Base64 string does not contain encrypted information.

@fpapon
Copy link
Member

fpapon commented Sep 1, 2023

@JaapD thanks for your contribution! Can you squash the commits please?
After that, it will be ok for merge.

Copy link
Member

@fpapon fpapon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you squash the commits please?

 Make tests to work with an unvalid Base64 string and a Base64 string without encrypted content.

1048: Solved base64 problem with remember me cookie.
@JaapD JaapD force-pushed the 1048-rememberme-does-not-remember-me branch 2 times, most recently from 9c2d333 to 67250bb Compare September 1, 2023 13:52
@JaapD
Copy link
Author

JaapD commented Sep 1, 2023

@fpapon I squashed the commits. I struggled a bit with squashing, but I think it is OK now.

@lprimak lprimak requested a review from fpapon September 3, 2023 06:10
Copy link
Member

@fpapon fpapon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lprimak lprimak merged commit 711ffe3 into apache:main Sep 3, 2023
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants