-
Notifications
You must be signed in to change notification settings - Fork 191
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
[#185] update documentation on shiro2 #186
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -439,40 +439,33 @@ Each line in the [users] section must conform to the following format: | |
[#Configuration-INIConfiguration-Sections-users-EncryptingPasswords] | ||
===== Encrypting Passwords | ||
|
||
If you don't want the [users] section passwords to be in plain-text, you can encrypt them using your favorite hash algorithm (MD5, Sha1, Sha256, etc.) however you like and use the resulting string as the password value. By default, the password string is expected to be Hex encoded, but can be configured to be Base64 encoded instead (see below). | ||
Since Shiro 2.0, the `[users]` section cannot contain plain-text passwords. | ||
You can encrypt them using https://en.wikipedia.org/wiki/Key_derivation_function[key derivation functions]. | ||
Shiro provides implementations for bcrypt and argon2. | ||
If unsure, use argon2 derived passwords. | ||
|
||
The algorithms from Shiro 1 (e.g. md5, SHA1, SHA256, etc.) are long deemed insecure and not supported anymore. | ||
There is neither a direct migration path nor backward compatibility. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is technically not true since Shiro 2 can encrypt / decrypt Shiro 1.x passwords. There is forward-and-backward path for compatibility as I tested this recently. This is a good thing IMHO. |
||
|
||
|
||
[NOTE] | ||
==== | ||
.Easy Secure Passwords | ||
To save time and use best-practices, you might want to use Shiro's link:command-line-hasher.html[Command Line Hasher], which will hash passwords as well as any other type of resource. It is especially convenient for encrypting INI `[users]` passwords. | ||
To save time and use best-practices, you might want to use Shiro's link:command-line-hasher.html[Command Line Hasher], which will apply one of the secure KDFs to a given password as well as any other type of resources. | ||
It is especially convenient for encrypting INI `[users]` passwords. | ||
==== | ||
|
||
Once you've specified the hashed text password values, you have to tell Shiro that these are encrypted. You do that by configuring the implicitly created `iniRealm` in the [main] section to use an appropriate `CredentialsMatcher` implementation corresponding to the hash algorithm you've specified: | ||
Once you've specified the derived text password values, you have to tell Shiro that these are encrypted. | ||
You do that by configuring the implicitly created `iniRealm` in the [main] section to use an appropriate `CredentialsMatcher` implementation corresponding to the hash algorithm you've specified: | ||
|
||
[source,ini] | ||
---- | ||
[main] | ||
... | ||
sha256Matcher = org.apache.shiro.authc.credential.Sha256CredentialsMatcher | ||
... | ||
iniRealm.credentialsMatcher = $sha256Matcher | ||
... | ||
# Shiro2CryptFormat | ||
|
||
[users] | ||
# user1 = sha256-hashed-hex-encoded password, role1, role2, ... | ||
user1 = 2bb80d537b1da3e38bd30361aa855686bde0eacd7162fef6a25fe97bf527a25b, role1, role2, ... | ||
---- | ||
|
||
You can configure any properties on the `CredentialsMatcher` like any other object to reflect your hashing strategy, for example, to specify if salting is used or how many hash iterations to execute. See the link:static/current/apidocs/org/apache/shiro/authc/credential/HashedCredentialsMatcher.html[`org.apache.shiro.authc.credential.HashedCredentialsMatcher`] JavaDoc to better understand hashing strategies and if they might be useful to you. | ||
|
||
For example, if your users' password strings were Base64 encoded instead of the default Hex, you could specify: | ||
|
||
[source,ini] | ||
---- | ||
[main] | ||
... | ||
# true = hex, false = base64: | ||
sha256Matcher.storedCredentialsHexEncoded = false | ||
user1 = $shiro2$argon2id$v=19$t=1,m=65536,p=4$H5z81Jpr4ntZr3MVtbOUBw$fJDgZCLZjMC6A2HhnSpxULMmvVdW3su+/GCU3YbxfFQ, role1, role2, ... | ||
---- | ||
|
||
[#Configuration-INIConfiguration-Sections-roles] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
[#CommandLineHasher-CommandLineHasher] | ||
= Command Line Hasher | ||
:jbake-date: 2010-03-18 00:00:00 | ||
:jbake-type: page | ||
:jbake-status: published | ||
:jbake-tags: documentation, hashes, command-line, cli, hasher, tool | ||
:idprefix: | ||
:icons: font | ||
:toc: | ||
|
||
Shiro 2.0.0 and later provides a command line program that can hash strings and resources (files, URLs, classpath entries) of almost any type. | ||
To use it, you must have a Java Virtual Machine installed and the 'java' command must be accessible in your `$PATH` environment variable. | ||
|
||
[CAUTION] | ||
==== | ||
Do not use the hashes provided in the link:../command-line-hasher.html[command line hasher v1.x] versions anymore! | ||
They are outdated and all considered insecure! | ||
==== | ||
|
||
[#CommandLineHasher-Usage] | ||
== Usage | ||
|
||
Ensure you have access to the `shiro-tools-hasher-${versions.latestRelease}-cli.jar` file. | ||
You can either find this in a source build in the _buildroot_`/tools/hasher/target` directory or via download through Maven. | ||
|
||
[source,bash] | ||
---- | ||
# Use the following to download from Maven Central into | ||
# ~/.m2/repository/org/apache/shiro/tools/shiro-tools-hasher/${versions.latestRelease}/shiro-tools-hasher-${versions.latestRelease}-cli.jar | ||
$ mvn dependency:get -DgroupId=org.apache.shiro.tools -DartifactId=shiro-tools-hasher -Dclassifier=cli -Dversion=${versions.latestRelease} | ||
|
||
---- | ||
|
||
Once you have access to the jar, you can run the following command: | ||
|
||
[source,bash] | ||
---- | ||
$ java -jar shiro-tools-hasher-${versions.latestRelease}-cli.jar | ||
---- | ||
|
||
This will print all available options for standard (argon2, bcrypt) and less secure hashing scenarios. | ||
|
||
[#CommandLineHasher-CommonScenarios] | ||
== Common Scenarios | ||
|
||
Please read the printed instructions for the above command. | ||
It will provide an exhaustive list of instructions which will help you use the hasher depending on your needs. | ||
However, we've provided some quick reference usages/scenarios below for convenience. | ||
|
||
[#CommandLineHasher-shiro.iniUserPasswords] | ||
=== `shiro.ini` User Passwords | ||
|
||
It is best to keep user passwords in the `shiro.ini` `[users]` section secure. To add a new user account line, use the above command with the `**-p**` (or `--password`) option: | ||
|
||
[source,bash] | ||
---- | ||
$ java -jar shiro-tools-hasher-${versions.latestRelease}-cli.jar -p | ||
---- | ||
|
||
It will then ask you to enter the password and then confirm it: | ||
|
||
[source,bash] | ||
---- | ||
Password to hash: | ||
Password to hash (confirm): | ||
---- | ||
|
||
When this command executes, it will print out the securely-salted-iterated-and-hashed password. | ||
For example: | ||
|
||
[source,bash] | ||
---- | ||
[INFO ] $shiro2$argon2id$v=19$t=1,m=65536,p=4$H5z81Jpr4ntZr3MVtbOUBw$fJDgZCLZjMC6A2HhnSpxULMmvVdW3su+/GCU3YbxfFQ | ||
---- | ||
|
||
Take this value and place it as the password in the user definition line (followed by any optional roles) as defined in the link:/configuration.html#Configuration-INIConfiguration-Sections-users[INI Users Configuration] documentation. For example: | ||
|
||
[source,ini] | ||
---- | ||
[users] | ||
... | ||
user1 = $shiro2$argon2id$v=19$t=1,m=65536,p=4$H5z81Jpr4ntZr3MVtbOUBw$fJDgZCLZjMC6A2HhnSpxULMmvVdW3su+/GCU3YbxfFQ | ||
---- | ||
|
||
You will also need to ensure that the implicit `iniRealm` uses a `CredentialsMatcher` that knows how to perform secure hashed password comparisons. | ||
So configure this in the `[main]` section as well: | ||
|
||
[source,ini] | ||
---- | ||
[main] | ||
... | ||
passwordMatcher = org.apache.shiro.authc.credential.PasswordMatcher | ||
iniRealm.credentialsMatcher = $passwordMatcher | ||
... | ||
---- | ||
|
||
[#CommandLineHasher-MD5checksum] | ||
=== MD5 checksum | ||
|
||
Although you can perform any hash with any algorithm supported on the JVM, the default hashing algorithm is MD5, common for file checksums. Just use the `**-r**` (or `--resource`) option to indicate the following value is a resource location (and not text you wish hashed): | ||
|
||
[source,bash] | ||
---- | ||
$ java -jar shiro-tools-hasher-X.X.X-cli.jar -r RESOURCE_PATH | ||
---- | ||
|
||
By default `RESOURCE_PATH` is expected to be a file path, but you may specify classpath or URL resources by using the `classpath:` or `url:` prefix respectively. | ||
|
||
Some examples: | ||
|
||
[source,bash] | ||
---- | ||
<command> -r fileInCurrentDirectory.txt | ||
<command> -r ../../relativePathFile.xml | ||
<command> -r ~/documents/myfile.pdf | ||
<command> -r /usr/local/logs/absolutePathFile.log | ||
<command> -r url:http://foo.com/page.html <command> -r classpath:/WEB-INF/lib/something.jar | ||
---- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this actually true? I seem to remember this plain-text passwords work in shiro 2 at the moment