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

Security: support Modular Crypt Format or its successor PHC #5667

Open
FroMage opened this issue Nov 21, 2019 · 11 comments
Open

Security: support Modular Crypt Format or its successor PHC #5667

FroMage opened this issue Nov 21, 2019 · 11 comments
Labels
area/security kind/enhancement New feature or request

Comments

@FroMage
Copy link
Member

FroMage commented Nov 21, 2019

ATM our security extensions support several sorts of algorithms:

  • security-properties says clear or HEX( MD5( username ":" realm ":" password ) )
  • security-jdbc says clear or bCrypt (but not in MCF/PHC format: all fields separated)

We should support MCF and/or its successor PHC for both options, even if we don't support all the algo types.

@FroMage FroMage added kind/enhancement New feature or request area/security labels Nov 21, 2019
@FroMage
Copy link
Member Author

FroMage commented Nov 21, 2019

https://www.npmjs.com/package/@phc/bcrypt has examples of the PHC format for bcrypt.

@FroMage
Copy link
Member Author

FroMage commented Nov 21, 2019

http://wildfly-security.github.io/wildfly-elytron/1.9.x/api-javadoc/org/wildfly/security/password/util/ModularCrypt.html has support for MCF, so it's just a matter of being able to use it.

As for PHC, we probably need to add support for it in Elytron, WDYT @dmlloyd ?

@dmlloyd
Copy link
Member

dmlloyd commented Nov 21, 2019

If PHC is, as they claim, a "well defined subset of the Modular Crypt Format" then it's just a question of adding support for whatever additional formats we are missing. The PHC document at https://github.com/P-H-C/phc-string-format/blob/master/phc-sf-spec.md mentions a few password types which are not supported presently by Elytron, specifically the "argon" group of algorithms.

/cc @darranl, @fjuma

@sberyozkin
Copy link
Member

Hey @FroMage, can you please discuss with @wowselim how to proceed here, he is interested in this enhancement, see #38634, thanks.

@FroMage
Copy link
Member Author

FroMage commented Feb 20, 2024

OK.

Though it turns out, looking at the sources of elytron-jdbc, that they appear to support MCF, given this code:

            if (saltColumn == -1 && iterationCountColumn == -1) {
                // try modular crypt
                final String s = getStringColumn(metaData, resultSet, hashColumn);
                if (s != null) {
                    final char[] chars = s.toCharArray();
                    final String identified = ModularCrypt.identifyAlgorithm(chars);
                    if (identified != null) {
                        try {
                            Password modularCryptPassword = ModularCrypt.decode(chars);
                            if (log.isTraceEnabled()) {
                                log.tracef("Key Mapper: Password credential created using Modular Crypt algorithm [%s]", identified);
                            }
                            return new PasswordCredential(modularCryptPassword);
                        } catch (InvalidKeySpecException e) {
                            log.tracef(e, "Key Mapper: Unable to identify Modular Crypt algorithm [%s]", identified);
                        }
                    }
                }
            }

And in the builder, saltColumn and iterationCountColumn both default to -1 (in PasswordKeyMapper.builder) though our config has no default, and no mention of these special values.

It's entirely possible that at least for security-jdbc we already support MCF, if quarkus.security.jdbc.principal-query.bcrypt-password-mapper.salt-index and quarkus.security.jdbc.principal-query.bcrypt-password-mapper.iteration-count-index are set to -1.

Could you test this please @wowselim and report back? If it works, then we might just have to update our config defaults and documentation.

Thanks a lot.

@wowselim
Copy link
Contributor

@FroMage you're right, it's supported indeed. Here's a project with a working test to demonstrate:

https://github.com/wowselim/quarkus-jdbc-auth-reproducer

@FroMage
Copy link
Member Author

FroMage commented Feb 21, 2024

Awesome!

So the config required is:

quarkus.security.jdbc.enabled=true
quarkus.security.jdbc.principal-query.sql=SELECT password, role FROM account WHERE email=?
quarkus.security.jdbc.principal-query.bcrypt-password-mapper.enabled=true
quarkus.security.jdbc.principal-query.bcrypt-password-mapper.password-index=1
quarkus.security.jdbc.principal-query.bcrypt-password-mapper.salt-index=-1
quarkus.security.jdbc.principal-query.bcrypt-password-mapper.iteration-count-index=-1

I think we should document this, and also make salt-index and iteration-count-index non-required and default to -1 like they do upstream.

WDYT @sberyozkin ?

@dmlloyd
Copy link
Member

dmlloyd commented Feb 21, 2024

It's probably best to change their type to OptionalInt then, and only accept -1 on a compatibility basis.

@FroMage
Copy link
Member Author

FroMage commented Feb 22, 2024

Sure.

@wowselim
Copy link
Contributor

wowselim commented Mar 1, 2024

I've created two PRs updating the documentation as well as the quickstart project. See #39122

@FroMage
Copy link
Member Author

FroMage commented Mar 12, 2024

The docs are great, but we should also fix the default values of the salt/iteration config values to simplify.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/security kind/enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants