Skip to content

This plugin reads username & password from a property file and allows access to HiveMQ only for MQTT clients with correct credentials.

License

Notifications You must be signed in to change notification settings

hivemq/file-auth-plugin

Repository files navigation

File Authentication Plugin

Description

The File Authentication Plugin is the first plugin, which adds the capability of client authentication to HiveMQ. In the case of this plugin the credentials consist of username and password and are read from a file.

How to use the plugin with sample configuration

  1. Copy the jar file to your <HIVEMQ_HOME>/plugins folder

  2. Copy configuration files

    1. sample-configuration/fileAuthConfiguration.properties into your <HIVEMQ_HOME>/conf folder

    2. sample-configuration/credentials.properties into your <HIVEMQ_HOME>/conf folder

  3. Run HiveMQ

  4. Connect with a MQTT client of your choice using username: hivemq-user1 and password: user1

  5. Done!

Note
This sample installation shows a simple and quick way to get started with the plugin. Therefore the pre-configuration uses no hashing for the passwords and has predefined username/password combinations. If you are using this plugin in production a more secure setup is essential. The various configuration options are explained in the following.

Configuration Options

The plugin can be configured with the fileAuthConfiguration.properties file, which needs to be placed in the conf folder.

Table 1. Configuration Options
Name Default Description

filename

credentials.properties

This property specifies the name of the file, which contains the credentials of the users. Please notice that the file has to be in the conf folder of HiveMQ.

reloadCredentialsInterval.seconds

10

Returns the interval after which the credentials file is checked, if new credentials were added.

passwordHashing.enabled

false

Specifies if the password is stored in plaintext or as hash. If this is set to false all other configuration properties except filename and reloadCredentialsInterval.seconds are ignored.

passwordHashing.algorithm

SHA-512

Here the hashing algorithm used during the creation of the passwords can be declared. HiveMQ is supporting all hashing algorithms provided by the Java Virtual Maschine (MD2, MD5, SHA, SHA-256, SHA-384, SHA-512). Recommended for use is SHA-256 and above, because the others are not considered secure.

passwordHashing.iterations

100

Customizes the number of hashing iterations used.

passwordHashingSalt.enabled

true

Configures if a salt has been used during the hash generation. If this is set to false the following options are ignored.

passwordHashingSalt.separationChar

$

Defines the character used in the credential file to separate the salt from the hash.

passwordHashingSalt.isFirst

true

Specifies the order of hash and salt. If this is set to true, the salt is in front of the hash (salt$hash), if this option is false the salt is placed after the hash (hash$salt)

cachingTime.seconds

600

Maximum cache entry lifetime in seconds for failed and successful login credentials (changing this value resets the cache)

cacheSize

10000

Maximum amount of cached login credentials (changing this value resets the cache)

Credentials

The second file needed for the plugin to work successfully is the credentials file, which is a Java Property File. So in each line one username/password combination can be specified. Depending on the configuration options a line looks like one of the following:

  • username:plaintextpassword

  • username:hashedpassword

  • username:hashedpassword[separator][salt]

  • username:[salt][separator]hashedpassword

Note
It is not possible to specify different formats for passwords of different users in one file, therefore all lines must contain the same format.

Production-ready Configuration

The displayed configuration shows a production-ready implementation, which uses SHA 512, 1 million iterations and salting.

Using strong hashing parameters
passwordHashing.enabled=true
passwordHashing.algorithm=SHA-512
passwordHashing.iterations=100
passwordHashingSalt.enabled=true
passwordHashingSalt.isFirst=true

Create and Modify the credential file

After having copied this configuration into the fileAuthConfiguration.properties, the credential file has to be improved, too. Now as hashing and salting is enabled the passwords have to be stored in same format.

This can be done easily with our provided utility. For more information see the GitHub repo.

Contributing

If you want to contribute to HiveMQ File Auth Plugin, see the contribution guidelines.

License

HiveMQ File Auth Plugin is licensed under the APACHE LICENSE, VERSION 2.0. A copy of the license can be found here.

About

This plugin reads username & password from a property file and allows access to HiveMQ only for MQTT clients with correct credentials.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages