You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shiro.apache.org by Steinar Bang <sb...@dod.no> on 2025/04/06 17:42:00 UTC

Is the cipherkey still a constant? (get rid of remember me stack traces in the log)

I'm trying to finally get rid of annoying log messages like this (error
messages that have plagued me since I first started using shiro):
 https://gist.github.com/steinarb/7c06c116620be8460d7d9e58c9a6e6d6

I have googled and found this old thing (from mr. Shiro himself, Brian Demers):
 https://stackoverflow.com/questions/59489303/caused-by-javax-crypto-badpaddingexception-given-final-block-not-properly-padd#comment105182482_59489303

The URL linked to in the above stackoverflow reploy no longer works, but
I think this is the current version of that URL:
 https://shiro.apache.org/configuration.html#Configuration-INIConfiguration-Sections-Main-DefiningObject-SettingProperties-ByteArrayValues

So far, so good! But what I don't get is what I should put into cipherkey?

Or if this is an old answer and no longer relevant?

I think the answer may no longer be relevant because chipherkey used to
be a constant and it hasn't been a constant since Shiro 1.2.5...?
 https://www.tenable.com/plugins/nessus/159323

Back when the answer was given, I think the answer was: use any base64
coded value pulled out of a hat, as long as it isn't the default one.

But now, when I look at the securitymanager cipherkey in the debugger
there seems to be a different one on every startup...?

So what is the correct thing to currently do to lose the log message in
the first URL?

I'm currently using shiro 2.0.2, with rememberMe set to true on the
token and with a MemorySessionDAO.

I am running my web applications in OSGi in apache karaf. Session and
Realm are OSGi services that injected into servletcontext components.

The Realm OSGi service is provided by this OSGi component
 https://github.com/steinarb/authservice/blob/master/authservice/authservice.web.security.dbrealm/src/main/java/no/priv/bang/authservice/web/security/dbrealm/AuthserviceDbRealm.java#L23

The Session OSGi service is provided by this OSGi component
 https://github.com/steinarb/authservice/blob/master/authservice/authservice.web.security.memorysession/src/main/java/no/priv/bang/authservice/web/security/memorysession/MemorySession.java#L23

The shiro.ini files looks like this:
 https://github.com/steinarb/authservice/blob/master/authservice/authservice.web.security/src/main/resources/shiro.ini

The rest of the shiro setup looks like this:
 https://github.com/steinarb/authservice/blob/master/authservice/authservice.web.security/src/main/java/no/priv/bang/authservice/web/security/AuthserviceShiroFilter.java#L65

Login looks like this:
 https://github.com/steinarb/authservice/blob/master/authservice/authservice.web.security/src/main/java/no/priv/bang/authservice/web/security/resources/AuthserviceResource.java#L101

Re: Is the cipherkey still a constant? (get rid of remember me stack traces in the log)

Posted by Steinar Bang <sb...@dod.no>.
>>>>> lenny-5o6P1Tln9C5DPfheJLI6IQ@public.gmane.org:

> Probably related to this: https://github.com/apache/shiro/issues/1449

Hm... I see I have been looking at this almost a year back, but I can't
remember what it was about...?

This one maybe...?
 https://github.com/apache/shiro/issues/1500

Looks like I found a workaround? (I can read what I did but I don't
remember doing it, I never do...)

Re: Is the cipherkey still a constant? (get rid of remember me stack traces in the log)

Posted by le...@flowlogix.com.
Probably related to this: https://github.com/apache/shiro/issues/1449

> On Apr 12, 2025, at 2:22 PM, Steinar Bang <sb...@dod.no> wrote:
> 
>>>>>> Steinar Bang <sb...@public.gmane.org>:
>>>>>> lenny-5o6P1Tln9C5DPfheJLI6IQ-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org:
>>> famous last words he he :)
> 
>> I have a plan! :-)
> 
> This is what I did:
> 1. One new OSGi service to return a cipherKey
>     https://github.com/steinarb/authservice/blob/fc6c29fb5cede9d9f3e8d4212124adc815ac6cf6/authservice/authservice.definitions/src/main/java/no/priv/bang/authservice/definitions/CipherKeyService.java#L18
> 
> 2. An SCR component that checks karaf config for an existing cipherKey
>    and creates and saves the new cipherKey in config if none can be
>    found and returns the cipherKey from the service definend in 1
>     https://github.com/steinarb/authservice/blob/fc6c29fb5cede9d9f3e8d4212124adc815ac6cf6/authservice/authservice.web.security.cipherkey/src/main/java/no/priv/bang/authservice/web/security/cipherkey/ChipherKeyServiceProvider.java#L32
> 
> 3. Set the cipherkey in the shiro setup
>     https://github.com/steinarb/authservice/blob/fc6c29fb5cede9d9f3e8d4212124adc815ac6cf6/authservice/authservice.web.security/src/main/java/no/priv/bang/authservice/web/security/AuthserviceShiroFilter.java#L86
> 
> The old log error have gone away.
> 
> But now I have a new one...
> https://gist.github.com/steinarb/63621658a7c5a1529f9f56998fdf4a37
> 


shiro-lang OSGi import package loop (Was: Is the cipherkey still a constant? (get rid of remember me stack traces in the log))

Posted by Steinar Bang <sb...@dod.no>.
>>>>> Steinar Bang <sb...@public.gmane.org>:

> The old log error have gone away.

> But now I have a new one...
>  https://gist.github.com/steinarb/63621658a7c5a1529f9f56998fdf4a37

Here is the error:
 Caused by: org.apache.shiro.lang.util.UnknownClassException: Unable to load class named [org.apache.shiro.subject.SimplePrincipalCollection] from the thread context, current, or system/application ClassLoaders.  All heuristics have been exhausted.  Class could not be found.
	at org.apache.shiro.lang.io.ClassResolvingObjectInputStream.resolveClass(ClassResolvingObjectInputStream.java:55) ~[!/:2.0.2]

This class is in the shiro-lang OSGi bundle (i.e. jar file with import-package
and export-package declarations in the MANIFEST.MF).

And for a class to be loaded and, found, the package it resides
(i.e. org.apache.shiro.subject) in needs to be imported into shiro-lang.

And the package org.apache.shiro.subject is not listed in the
Import-Package declaration of the shiro-lang MANIFEST.MF (formatted for
readability): 

Import-Package:
 javax.servlet.jsp;resolution:=optional,
 java.beans,
 java.io,
 java.lang,
 java.lang.annotation,
 java.lang.invoke,
 java.lang.ref,
 java.lang.reflect,
 java.net,
 java.text,
 java.util,
 java.util.concurrent,
 java.util.concurrent.locks,
 org.apache.shiro.lang;version="[2.0,3)",
 org.apache.shiro.lang.codec;version="[2.0,3)",
 org.apache.shiro.lang.util;version="[2.0,3)",
 org.slf4j;version="[2.0,3)"

Below is the export-package of the MANIFEST.MF of shiro-core, also
reformatted for readability, and I see one obvious problem: packages in
shiro-core require packages from shiro-lang (which means shiro-lang
can't import packages from shiro-core, because then you would have a
loop).

So this requires changes to shiro to fix.

There are two ways of breaking the loop:
 1. Put everything in one huge jar (the quick and dirty and wrong way)
 2. Split out the stuff included both places into a separate bundle and
    import its packages in the bundles that need it

In any case no easy fix that can be done by changes to a bundle's
manifest. 



Export-package of the MANIFEST.MF of shiro-core, reformatted for readability:

Export-Package:
 org.apache.shiro;version="2.0.2";uses:="org.apache.shiro.lang,org.apache.shiro.mgt,org.apache.shiro.subject",
 org.apache.shiro.aop;version="2.0.2";uses:="org.apache.shiro.subject",org.apache.shiro.authc;version="2.0.2";uses:="org.apache.shiro.authz,org.apache.shiro.lang,org.apache.shiro.lang.util,org.apache.shiro.subject",
 org.apache.shiro.authc.credential;version="2.0.2";uses:="org.apache.shiro.authc,org.apache.shiro.crypto.hash,org.apache.shiro.crypto.hash.format,org.apache.shiro.lang.codec,org.apache.shiro.lang.util",
 org.apache.shiro.authc.pam;version="2.0.2";uses:="org.apache.shiro.authc,
 org.apache.shiro.realm,org.apache.shiro.subject",
 org.apache.shiro.authz;version="2.0.2";uses:="org.apache.shiro.authz.permission,org.apache.shiro.lang,org.apache.shiro.realm,org.apache.shiro.subject",
 org.apache.shiro.authz.annotation;version="2.0.2",
 org.apache.shiro.authz.aop;version="2.0.2";uses:="org.apache.shiro.aop,org.apache.shiro.authz",
 org.apache.shiro.authz.permission;version="2.0.2";uses:="org.apache.shiro.authz,org.apache.shiro.lang",
 org.apache.shiro.concurrent;version="2.0.2";uses:="org.apache.shiro.subject",
 org.apache.shiro.dao;version="2.0.2";uses:="org.apache.shiro.lang",org.apache.shiro.env;version="2.0.2";uses:="org.apache.shiro.config,org.apache.shiro.lang,org.apache.shiro.lang.util,org.apache.shiro.mgt",
 org.apache.shiro.ini;version="2.0.2";uses:="org.apache.shiro.config,org.apache.shiro.config.ogdl,org.apache.shiro.mgt,org.apache.shiro.realm,org.apache.shiro.util",
 org.apache.shiro.jndi;version="2.0.2";uses:="javax.naming,org.apache.shiro.lang.util",
 org.apache.shiro.ldap;version="2.0.2";uses:="org.apache.shiro.dao",
 org.apache.shiro.mgt;version="2.0.2";uses:="org.apache.shiro.authc,org.apache.shiro.authz,org.apache.shiro.cache,org.apache.shiro.crypto.cipher,org.apache.shiro.event,org.apache.shiro.lang.io,org.apache.shiro.lang.util,org.apache.shiro.realm,org.apache.shiro.session,org.apache.shiro.session.mgt,org.apache.shiro.subject",
 org.apache.shiro.realm;version="2.0.2";uses:="org.apache.shiro.authc,org.apache.shiro.authc.credential,org.apache.shiro.authz,org.apache.shiro.authz.permission,org.apache.shiro.cache,org.apache.shiro.lang.util,org.apache.shiro.subject",
 org.apache.shiro.realm.activedirectory;version="2.0.2";uses:="javax.naming,javax.naming.ldap,org.apache.shiro.authc,org.apache.shiro.authz,org.apache.shiro.realm.ldap,org.apache.shiro.subject",
 org.apache.shiro.realm.jdbc;version="2.0.2";uses:="javax.sql,org.apache.shiro.authc,org.apache.shiro.authz,org.apache.shiro.realm, org.apache.shiro.subject",
 org.apache.shiro.realm.jndi;version="2.0.2";uses:="org.apache.shiro.jndi,org.apache.shiro.realm",
 org.apache.shiro.realm.ldap;version="2.0.2";uses:="javax.naming,javax.naming.directory,javax.naming.ldap,org.apache.shiro.authc,org.apache.shiro.authz,org.apache.shiro.realm,org.apache.shiro.subject",
 org.apache.shiro.realm.text;version="2.0.2";uses:="org.apache.shiro.config,org.apache.shiro.lang.util,org.apache.shiro.realm",
 org.apache.shiro.session;version="2.0.2";uses:="org.apache.shiro.lang",
 org.apache.shiro.session.mgt;version="2.0.2";uses:="org.apache.shiro.authz,org.apache.shiro.cache,org.apache.shiro.event,org.apache.shiro.lang.util,org.apache.shiro.session,org.apache.shiro.session.mgt.eis,org.apache.shiro.util",
 org.apache.shiro.session.mgt.eis;version="2.0.2";uses:="org.apache.shiro.cache,org.apache.shiro.session",
 org.apache.shiro.subject;version="2.0.2";uses:="org.apache.shiro.authc,org.apache.shiro.authz,org.apache.shiro.lang,org.apache.shiro.mgt,org.apache.shiro.session",
 org.apache.shiro.subject.support;version="2.0.2";uses:="org.apache.shiro.authc,org.apache.shiro.authz,org.apache.shiro.mgt,org.apache.shiro.session,org.apache.shiro.session.mgt,org.apache.shiro.subject,org.apache.shiro.util",
 org.apache.shiro.util;version="2.0.2";uses:="org.apache.shiro.authz,org.apache.shiro.authz.permission,org.apache.shiro.lang.util,org.apache.shiro.mgt,org.apache.shiro.subject!"

Re: Is the cipherkey still a constant? (get rid of remember me stack traces in the log)

Posted by Steinar Bang <sb...@dod.no>.
>>>>> Steinar Bang <sb...@public.gmane.org>:
>>>>> lenny-5o6P1Tln9C5DPfheJLI6IQ-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org:
>> famous last words he he :)

> I have a plan! :-)

This is what I did:
 1. One new OSGi service to return a cipherKey
     https://github.com/steinarb/authservice/blob/fc6c29fb5cede9d9f3e8d4212124adc815ac6cf6/authservice/authservice.definitions/src/main/java/no/priv/bang/authservice/definitions/CipherKeyService.java#L18

 2. An SCR component that checks karaf config for an existing cipherKey
    and creates and saves the new cipherKey in config if none can be
    found and returns the cipherKey from the service definend in 1
     https://github.com/steinarb/authservice/blob/fc6c29fb5cede9d9f3e8d4212124adc815ac6cf6/authservice/authservice.web.security.cipherkey/src/main/java/no/priv/bang/authservice/web/security/cipherkey/ChipherKeyServiceProvider.java#L32

 3. Set the cipherkey in the shiro setup
     https://github.com/steinarb/authservice/blob/fc6c29fb5cede9d9f3e8d4212124adc815ac6cf6/authservice/authservice.web.security/src/main/java/no/priv/bang/authservice/web/security/AuthserviceShiroFilter.java#L86

The old log error have gone away.

But now I have a new one...
 https://gist.github.com/steinarb/63621658a7c5a1529f9f56998fdf4a37

Re: Is the cipherkey still a constant? (get rid of remember me stack traces in the log)

Posted by Steinar Bang <sb...@dod.no>.
>>>>> lenny-5o6P1Tln9C5DPfheJLI6IQ@public.gmane.org:

> famous last words he he :)

I have a plan! :-)

On a side note: while grepping through the code to find the appropriate
place to hook in to set the cipherKey in code I noticed this:
 https://github.com/apache/shiro/blob/main/core/src/main/java/org/apache/shiro/mgt/AbstractRememberMeManager.java#L100

The downcast is further down that it has to be: generateNewKey() is
defined on AbstractSymmetricCipherService which is two levels up from
AesCipherService.

AesCipherService extends DefaultBlockCipherService which extends
AbstractSymmetricCipherService where generateNewKey() is defined.

(I was wondering if replacing the cipherService was the way to go and
figure "probably not", mainly because of that downcast and because the
interesting methods weren't defined on the CipherService interface)

Re: Is the cipherkey still a constant? (get rid of remember me stack traces in the log)

Posted by le...@flowlogix.com.
famous last words he he :)

> On Apr 10, 2025, at 11:47 AM, Steinar Bang <sb...@dod.no> wrote:
> 
>>>>>> lenny-5o6P1Tln9C5DPfheJLI6IQ@public.gmane.org:
> 
>> No, no.
>> The cipher key should not be anywhere near your build process, maven, shiro.ini, etc.
>> None of that is secure.
> 
> (just small hobby applications... not banking software...)
> 


Re: Is the cipherkey still a constant? (get rid of remember me stack traces in the log)

Posted by Steinar Bang <sb...@dod.no>.
>>>>> Steinar Bang <sb...@public.gmane.org>:
>>>>> lenny-5o6P1Tln9C5DPfheJLI6IQ-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org:

>> No, no.
>> The cipher key should not be anywhere near your build process, maven, shiro.ini, etc.
>> None of that is secure.

> (just small hobby applications... not banking software...)

But I think I have an idea if I can set the value in code instead of
setting it in shiro.ini (an OSGi component that generates a key the
first time it starts and saves the key in karaf config, and then returns
the same key on all restarts).

I will look at your first URL.

Re: Is the cipherkey still a constant? (get rid of remember me stack traces in the log)

Posted by Steinar Bang <sb...@dod.no>.
>>>>> lenny-5o6P1Tln9C5DPfheJLI6IQ@public.gmane.org:

> No, no.
> The cipher key should not be anywhere near your build process, maven, shiro.ini, etc.
> None of that is secure.

(just small hobby applications... not banking software...)

Re: Is the cipherkey still a constant? (get rid of remember me stack traces in the log)

Posted by le...@flowlogix.com.
No, no.

The cipher key should not be anywhere near your build process, maven, shiro.ini, etc.
None of that is secure.

> On Apr 9, 2025, at 12:50 PM, Steinar Bang <sb...@dod.no> wrote:
> 
>>>>>> lenny-5o6P1Tln9C5DPfheJLI6IQ@public.gmane.org:
> 
>> a. No. It’s a Hex string with no prefix or encoding
>> b. No. There is no encoding of the key in the URL, otherwise it’ll be insecure. CipherKey is used to decrypt the rememberMe cookie.
>> c. Yes
> 
> Thanks!
> 
> (Actually, reading through the stuff you wrote above about "must be
> fixed", probably "b. Yes." also (I possibly confused things with the
> stuff in parentheses)
> 
> I have to think about the best way to set the fixed value.
> 
> I think maybe have it in ~/.m2/settings.xml and expand the value in
> shiro.ini files or default with the current behaviour when the maven
> property value is missing?
> 


Re: Is the cipherkey still a constant? (get rid of remember me stack traces in the log)

Posted by Steinar Bang <sb...@dod.no>.
>>>>> lenny-5o6P1Tln9C5DPfheJLI6IQ@public.gmane.org:

> a. No. It’s a Hex string with no prefix or encoding
> b. No. There is no encoding of the key in the URL, otherwise it’ll be insecure. CipherKey is used to decrypt the rememberMe cookie.
> c. Yes

Thanks!

(Actually, reading through the stuff you wrote above about "must be
fixed", probably "b. Yes." also (I possibly confused things with the
stuff in parentheses)

I have to think about the best way to set the fixed value.

I think maybe have it in ~/.m2/settings.xml and expand the value in
shiro.ini files or default with the current behaviour when the maven
property value is missing?

Re: Is the cipherkey still a constant? (get rid of remember me stack traces in the log)

Posted by le...@flowlogix.com.
Sorry, your interpretation is incorrect.
The default behavior is to have a new cipher key, this is why you get this error.
Cipher key needs to be “fixed”, i.e. the same between application starts.

Is *not* base64 encoding. This is exactly the hex string openssl command gives you. No “0x” in front or anything else.
% openssl enc -aes-128-cbc -k secret -P -md sha256 

*** WARNING : deprecated key derivation used.
Using -iter or -pbkdf2 would be better.
salt=51F8F0583B98F93F
*** USE THIS VALUE *** key=5AA466288411D3ABE5F03BF57CB14C4A
iv =365E61874A97ED0281234E6933CB049D

You need to use the “key” value: “5AA466288411D3ABE5F03BF57CB14C4A” (without quotes)

a. No. It’s a Hex string with no prefix or encoding
b. No. There is no encoding of the key in the URL, otherwise it’ll be insecure. CipherKey is used to decrypt the rememberMe cookie.
c. Yes

*** DO NOT *** put the cipher key into shiro.ini. This is horribly insecure.
You have to guard the cipher key with your “life” because if it gets out, all rememberMe sessions are vulnerable to hijack attack.

Best practice is to put it into environment variable, and make sure that no one gets to it.

In my example,
https://github.com/lprimak/apps/blob/549f2926233ea3da52126103dc4960090fe95157/emailmanager/src/main/java/com/flowlogix/website/ui/Constants.java#L53
injects the cipherKey via Microprofile Config from environment variable, while https://github.com/lprimak/apps/blob/main/emailmanager/src/main/java/com/flowlogix/website/security/CipherKeySource.java
is the Shiro integration that provides it to Shiro itself.

Hope this helps!

> On Apr 8, 2025, at 12:18 PM, Steinar Bang <sb...@dod.no> wrote:
> 
>>>>>> lenny-5o6P1Tln9C5DPfheJLI6IQ@public.gmane.org:
> 
>> The only thing I can think of is to give you some examples from my application:
>> https://github.com/lprimak/apps/blob/main/emailmanager/src/main/java/com/flowlogix/website/security/CipherKeySource.java
> 
> Just seeing if I'm interpreting this correctly: this is base64-encoding
> of the cipher key that's autogenerated every time the app starts?
> 
>> https://github.com/lprimak/apps/blob/main/emailmanager/hope-website/WEB-INF/shiro.ini
> 
> Hm... I see no setting of the cipherkey in here?
> 
> What I tried to do was
> 1. to take the openssl command you sent me and run it
> 2. that created several hex values
> 3. I took the "key" value and prefixed it with "0x" and used it as the
>    value of the remembermeManager.cipherKey property in shiro.ini
> 
> I wasn't sure what the exact problem was:
> a. That the cipherKey was a binary value stored as a string, without
>    being base64 encoded or 0x prefix on a hex encoding of the value?
> b. That I did reloads of the server which caused a new AES chipher key
>    (the one you base64 encode in the first URL?) to be generated, and
>    not match the chipherKey used to encode the rememberme cookies?
> c. That I used the same Realm and Session across multiple applications,
>    and thus needed the same cipherKey for all of them?
> d. Something completely unrelated to the above?
> 
> I tried to cure all of a., b. and c., by adding the same constant value
> to all shiro.ini files.  I haven't pushed any of the commits (since they
> didn't get rid of the error in the logs), but here is one of the
> shiro.ini files with the setting added:
> https://gist.github.com/steinarb/d16acbdc6cc35e5cb599f9b4121f6af1#file-shiro-ini-L5
> 
> Of course if the reason for the problem is "d." then I have been barking
> up the wrong tree...? :-)
> 
> 


Re: Is the cipherkey still a constant? (get rid of remember me stack traces in the log)

Posted by Steinar Bang <sb...@dod.no>.
>>>>> lenny-5o6P1Tln9C5DPfheJLI6IQ@public.gmane.org:

> The only thing I can think of is to give you some examples from my application:
> https://github.com/lprimak/apps/blob/main/emailmanager/src/main/java/com/flowlogix/website/security/CipherKeySource.java

Just seeing if I'm interpreting this correctly: this is base64-encoding
of the cipher key that's autogenerated every time the app starts?

> https://github.com/lprimak/apps/blob/main/emailmanager/hope-website/WEB-INF/shiro.ini

Hm... I see no setting of the cipherkey in here?

What I tried to do was
 1. to take the openssl command you sent me and run it
 2. that created several hex values
 3. I took the "key" value and prefixed it with "0x" and used it as the
    value of the remembermeManager.cipherKey property in shiro.ini

I wasn't sure what the exact problem was:
 a. That the cipherKey was a binary value stored as a string, without
    being base64 encoded or 0x prefix on a hex encoding of the value?
 b. That I did reloads of the server which caused a new AES chipher key
    (the one you base64 encode in the first URL?) to be generated, and
    not match the chipherKey used to encode the rememberme cookies?
 c. That I used the same Realm and Session across multiple applications,
    and thus needed the same cipherKey for all of them?
 d. Something completely unrelated to the above?

I tried to cure all of a., b. and c., by adding the same constant value
to all shiro.ini files.  I haven't pushed any of the commits (since they
didn't get rid of the error in the logs), but here is one of the
shiro.ini files with the setting added:
 https://gist.github.com/steinarb/d16acbdc6cc35e5cb599f9b4121f6af1#file-shiro-ini-L5

Of course if the reason for the problem is "d." then I have been barking
up the wrong tree...? :-)
 

Re: Is the cipherkey still a constant? (get rid of remember me stack traces in the log)

Posted by le...@flowlogix.com.
The only thing I can think of is to give you some examples from my application:
https://github.com/lprimak/apps/blob/main/emailmanager/src/main/java/com/flowlogix/website/security/CipherKeySource.java
apps/emailmanager/src/main/java/com/flowlogix/website/security/CipherKeySource.java at main · lprimak/apps
github.com


https://github.com/lprimak/apps/blob/main/emailmanager/hope-website/WEB-INF/shiro.ini
apps/emailmanager/hope-website/WEB-INF/shiro.ini at main · lprimak/apps
github.com


> On Apr 7, 2025, at 1:28 PM, Steinar Bang <sb...@dod.no> wrote:
> 
>>>>>> lenny-5o6P1Tln9C5DPfheJLI6IQ@public.gmane.org:
>>> On Apr 6, 2025, at 2:19 PM, Steinar Bang <sb...@public.gmane.org> wrote:
> 
>>> Thanks, this means setting cipherkey to a constant is still the fix in 2.0.2?
> 
>> Yes, nothing changed there.
> 
> So far I've been unable to make it work.
> 
> I have multiple web application that share the same Realm and Session
> and as I read your advice it struck me that this may be the reason I'm
> getting the error, and having the same cipherKey in all applications
> might fix the issue...?
> 
> But so far I have been unsuccessful in making the rememberMe errors go
> away from the log.
> 
> Here is what I've done:
> 1. I have added the following to shiro.ini of all applications
>      securityManager.rememberMeManager.cipherKey = 0x15FC281159A0AB85212D0EFF32D5219F
> 2. I have rebuilt all applications with "mvn clean install" (to get
>    fresh local snapshots)
> 3. I have cleared all application data for all applications (cleared
>    existing JSESSIONID and rememberme cookies)
> 4. I have reloaded all applications from their most recent snapshots by
>    loading the apache karaf myapps feature
>     https://github.com/steinarb/myapps
> 5. I have logged into all web applications to create fresh rememberme
>    cookies
> 6. I have stopped karaf, deleted the data directory (basically cleared
>    the karaf instance) and reinstalled the myapps karaf feature
> 7. I have then reloaded the applications with rememberme cookies and
>    the error message reappear i the karaf.log once for each reloaded
>    application with rememberme cookies
> 
> I have gone through rebuilding all applications one extra time to be
> sure I have the shiro.ini chages in the newest SNAPSHOT, and cleared all
> cookies, logged in, and cleared karaf and reloaded the applications in
> karaf.
> 
> But the problem persists.
> 


Re: Is the cipherkey still a constant? (get rid of remember me stack traces in the log)

Posted by Steinar Bang <sb...@dod.no>.
>>>>> lenny-5o6P1Tln9C5DPfheJLI6IQ@public.gmane.org:
>> On Apr 6, 2025, at 2:19 PM, Steinar Bang <sb...@public.gmane.org> wrote:

>> Thanks, this means setting cipherkey to a constant is still the fix in 2.0.2?

> Yes, nothing changed there.

So far I've been unable to make it work.

I have multiple web application that share the same Realm and Session
and as I read your advice it struck me that this may be the reason I'm
getting the error, and having the same cipherKey in all applications
might fix the issue...?

But so far I have been unsuccessful in making the rememberMe errors go
away from the log.

Here is what I've done:
 1. I have added the following to shiro.ini of all applications
      securityManager.rememberMeManager.cipherKey = 0x15FC281159A0AB85212D0EFF32D5219F
 2. I have rebuilt all applications with "mvn clean install" (to get
    fresh local snapshots)
 3. I have cleared all application data for all applications (cleared
    existing JSESSIONID and rememberme cookies)
 4. I have reloaded all applications from their most recent snapshots by
    loading the apache karaf myapps feature
     https://github.com/steinarb/myapps
 5. I have logged into all web applications to create fresh rememberme
    cookies
 6. I have stopped karaf, deleted the data directory (basically cleared
    the karaf instance) and reinstalled the myapps karaf feature
 7. I have then reloaded the applications with rememberme cookies and
    the error message reappear i the karaf.log once for each reloaded
    application with rememberme cookies

I have gone through rebuilding all applications one extra time to be
sure I have the shiro.ini chages in the newest SNAPSHOT, and cleared all
cookies, logged in, and cleared karaf and reloaded the applications in
karaf.

But the problem persists.

Re: Is the cipherkey still a constant? (get rid of remember me stack traces in the log)

Posted by le...@flowlogix.com.
Yes, nothing changed there.

> On Apr 6, 2025, at 2:19 PM, Steinar Bang <sb...@dod.no> wrote:
> 
>>>>>> lenny-5o6P1Tln9C5DPfheJLI6IQ@public.gmane.org:
> 
>> Hi, Sterinar,
>> This is what I use to generate the key:
>> openssl enc -aes-128-cbc -k secret -P -md sha256
> 
>> Let me know if that works for you
> 
> Thanks, this means setting cipherkey to a constant is still the fix in 2.0.2?
> 
> Ok, will try!  And will report back!
> 


Re: Is the cipherkey still a constant? (get rid of remember me stack traces in the log)

Posted by Steinar Bang <sb...@dod.no>.
>>>>> lenny-5o6P1Tln9C5DPfheJLI6IQ@public.gmane.org:

> Hi, Sterinar,
> This is what I use to generate the key:
> openssl enc -aes-128-cbc -k secret -P -md sha256 

> Let me know if that works for you

Thanks, this means setting cipherkey to a constant is still the fix in 2.0.2?

Ok, will try!  And will report back!

Re: Is the cipherkey still a constant? (get rid of remember me stack traces in the log)

Posted by le...@flowlogix.com.
Hi, Sterinar,

This is what I use to generate the key:
openssl enc -aes-128-cbc -k secret -P -md sha256 

Let me know if that works for you

> On Apr 6, 2025, at 12:42 PM, Steinar Bang <sb...@dod.no> wrote:
> 
> I'm trying to finally get rid of annoying log messages like this (error
> messages that have plagued me since I first started using shiro):
> https://gist.github.com/steinarb/7c06c116620be8460d7d9e58c9a6e6d6
> 
> I have googled and found this old thing (from mr. Shiro himself, Brian Demers):
> https://stackoverflow.com/questions/59489303/caused-by-javax-crypto-badpaddingexception-given-final-block-not-properly-padd#comment105182482_59489303
> 
> The URL linked to in the above stackoverflow reploy no longer works, but
> I think this is the current version of that URL:
> https://shiro.apache.org/configuration.html#Configuration-INIConfiguration-Sections-Main-DefiningObject-SettingProperties-ByteArrayValues
> 
> So far, so good! But what I don't get is what I should put into cipherkey?
> 
> Or if this is an old answer and no longer relevant?
> 
> I think the answer may no longer be relevant because chipherkey used to
> be a constant and it hasn't been a constant since Shiro 1.2.5...?
> https://www.tenable.com/plugins/nessus/159323
> 
> Back when the answer was given, I think the answer was: use any base64
> coded value pulled out of a hat, as long as it isn't the default one.
> 
> But now, when I look at the securitymanager cipherkey in the debugger
> there seems to be a different one on every startup...?
> 
> So what is the correct thing to currently do to lose the log message in
> the first URL?
> 
> I'm currently using shiro 2.0.2, with rememberMe set to true on the
> token and with a MemorySessionDAO.
> 
> I am running my web applications in OSGi in apache karaf. Session and
> Realm are OSGi services that injected into servletcontext components.
> 
> The Realm OSGi service is provided by this OSGi component
> https://github.com/steinarb/authservice/blob/master/authservice/authservice.web.security.dbrealm/src/main/java/no/priv/bang/authservice/web/security/dbrealm/AuthserviceDbRealm.java#L23
> 
> The Session OSGi service is provided by this OSGi component
> https://github.com/steinarb/authservice/blob/master/authservice/authservice.web.security.memorysession/src/main/java/no/priv/bang/authservice/web/security/memorysession/MemorySession.java#L23
> 
> The shiro.ini files looks like this:
> https://github.com/steinarb/authservice/blob/master/authservice/authservice.web.security/src/main/resources/shiro.ini
> 
> The rest of the shiro setup looks like this:
> https://github.com/steinarb/authservice/blob/master/authservice/authservice.web.security/src/main/java/no/priv/bang/authservice/web/security/AuthserviceShiroFilter.java#L65
> 
> Login looks like this:
> https://github.com/steinarb/authservice/blob/master/authservice/authservice.web.security/src/main/java/no/priv/bang/authservice/web/security/resources/AuthserviceResource.java#L101
>