Comments (19)
Thanks for answering - and no problem about time.
One difference i see so far is the fixed keylength (24) booth other projects use to generate the key:
Your library uses differnet sizes depnding on algorithm used (but never 24)jpmens "np" tool:
and same inside the nodejs module to create compatible hashes or compare them:
But even setting the keylen to 24 at your code and recompiling it does not generate a match on comparing hashes created with jpmens or nodejs and your plugin....
Maybe handling of the password strings resp. hashes is different? Does Go interpret them as UTF-8 or something else?Thanks for looking into it.
Hello @sseide
I also had problems generating compatible hashes with Mosquitto Go Auth but I could solve it. I implemented an algorithm quite similar to @iegomez but in PHP.
It may come handy for you so I'll quote it here:
function generar_hash($password)
{
//Salt size (16 bytes)
$saltSize = 16;
//Iterations
$iterations = 100000;
//Algorithm
$algorithm = "sha512";
//Generates a random salt value of 128 bits (saltSize* 8)
$salt = random_bytes($saltSize);
return hashWithSalt($password, $salt, $iterations, $algorithm);
}
function hashWithSalt($password, $salt, $iterations, $algorithm)
{
if($algorithm == "sha512")
{
//This is important. Size must be 64 for sha512
$size = 64;
}
//sha256
else
{ //For sha256 it must be 32 (Haven't tested this one though, but I checked golang documentation
$size = 32;
}
//The TRUE parameter is also important. You can check what it does with more detail within PHP'S documentation website
$hash = hash_pbkdf2($algorithm,$password,$salt,$iterations,$size,TRUE);
//Concantenate the data to generate the same string hash as Mosquitto Go Auth
$hashGenerada = "PBKDF2$";
$hashGenerada = $hashGenerada . "$algorithm$";
$hashGenerada = $hashGenerada . $iterations;
$hashGenerada = $hashGenerada . "$";
$hashGenerada = $hashGenerada . base64_encode($salt); //Encodes to base64
$hashGenerada = $hashGenerada . "$";
$hashGenerada = $hashGenerada . base64_encode($hash); //Encodes to base64
return $hashGenerada;
}
I hope this code helps you implementing a similar solution in your language. Cheers.
from mosquitto-go-auth.
@sseide I have a temporary branch that I'm currently testing that will work with jpmens plugin-generated/ compatible hashes: https://github.com/coldfire84/mosquitto-go-auth/tree/pr-mosquitto-auth-plug-compat - it would be great if you could feedback on the functionality in your environment.
The only change you'll need to make if you use this is to include an additional option in the mosquitto config file (if you omit this the hash check will remain as is):
auth_opt_<back end>_salt_encoding utf-8
Note, if you build from docker image, you'll need to change the Docker file plugin source to use this branch.
This option changes the way the salt is converted to bytes and will result in a successful hash comparison.
@iegomez I will write tests for this and look to submit a PR.
from mosquitto-go-auth.
Hi, Stefan!
I'm sorry for not responding earlier. I don't have an answer right now but I'll look into it during the week. It does seem weird as before writing this plugin I also used jpemns'
one and I made sure that passwords were compatible on switching, so maybe something changed later and I didn't notice it. So thanks for reporting the issue and I'll look into it as soon as possible.
from mosquitto-go-auth.
Thanks for answering - and no problem about time.
One difference i see so far is the fixed keylength (24) booth other projects use to generate the key:
Your library uses differnet sizes depnding on algorithm used (but never 24)
jpmens "np" tool:
and same inside the nodejs module to create compatible hashes or compare them:
But even setting the keylen to 24 at your code and recompiling it does not generate a match on comparing hashes created with jpmens or nodejs and your plugin....
Maybe handling of the password strings resp. hashes is different? Does Go interpret them as UTF-8 or something else?
Thanks for looking into it.
from mosquitto-go-auth.
Again, haven't had a chance to take a proper look, but I remembered that in order to be compatible with the formerly known as LoRaServer project (from which the PBKDF" implementation is taken, as this plugin was intended to be used with that project originally), you had to pass the -DRAW_SALT
to jpmen's
plugin on compilation for it to work. You can check why in the Passwords
subsection of the Files backend:
Note that the salt by default will be taken as-is (thus it will not be base64 decoded before the validation). In case your own implementation uses the raw bytes when hashing the password and base64 is only used for display purpose, compile this project with the -DRAW_SALT flag (you could add this in the config.mk file to CFG_CFLAGS).
As said, I haven't looked at the NodeJS implementation, but maybe it has the same different salt treatment.
from mosquitto-go-auth.
I have not compiled via RAW_SALT, seen this flag inside jpmens code bot not looked into it deeper.
This would explain the differences - I'll check.
The NodeJs implementation does not allow this config-change AFAIR. Will have a look there too and may patch it if i find a working solution...
from mosquitto-go-auth.
I'm in a similar situation to @sseide, I have ~1200 users with mosquitto-auth-plug compatible PBKDF2 passwords, using the default configuration (i.e. no RAW SALT flag). Database encoding for salt and hash fields is base64 (as set via 'encoding' option in passport-local-mongoose).
Accepting you may not want to change this generally, if I were to fork the project do you have any idea how the hashing comparison function needs to be modified for base64/ non-RAW salt and hash?
Or would it be possible to have this as an option in the plugin itself?
from mosquitto-go-auth.
Have done some further testing tonight, and even with passport-local-mongoose salt and hash field encoding set to 'hex' (and resetting user password to regenerate PBKDF2$ string) the comparison still fails (using the supplied pw-utility)/ authentication fails via mosquitto-go-auth.
from mosquitto-go-auth.
fun fact @coldfire84 : due to the compatibility problems with this go modules we had switched to your fork of jpmens repo with the fixes for mosquitto 1.6 (https://github.com/coldfire84/mosquitto-auth-plug.git)... Therefor did not invest any further time on how to get the go version running (i'm no go programmer).
But it seems this is only a temporal solution?
from mosquitto-go-auth.
But it seems this is only a temporal solution?
The reality is that jpmens plugin is no longer being developed, so in my opinion, it is only a matter of time before this becomes an issue.
we had switched to your fork of jpmens repo with the fixes for mosquitto 1.6
I recently tested/ updated my own service to Mosquitto 1.6.8, so this isn't an immediate problem though.
from mosquitto-go-auth.
So I've made some progress with this, but identified an issue/ required development elsewhere.
I discovered that passport-local-mongoose wasn't using raw salt when generating password hashes, which explains the pw utility test issues I was having. I've raised a PR to address the identified issue: saintedlama/passport-local-mongoose#298
With the change to raw salt, the password hashes match.
Now, this leaves me with another problem that I'll create a separate issue for.
from mosquitto-go-auth.
Guys, I'm closing this issue so we can continue any discussion on the PR comments, but please feel free to reopen it if you need.
from mosquitto-go-auth.
Hi, i am sorry to come back to this issue again. I am currently also having the problem that i cannot manage to get the passwords that were accepted and valid by the old mosquitto-auth-plug plugin to be hashed correctly with this plugin. Did anyone proceed in getting this to work with a specific configuration ?
This is the code that was used for encoding and that played well with the old pluging ruby):
# implementation from mqtt auth plugin
def self.compute_pbkdf2_hmac_sha256(plaintext, salt_length: 12 }, iterations = 901, key_length = 24)
the_salt = SecureRandom.base64(salt_length)
hash = OpenSSL::PKCS5.pbkdf2_hmac(plaintext, the_salt, iterations, key_length, OpenSSL::Digest::SHA256.new)
encoded_hash = Base64.strict_encode64(hash)
"PBKDF2$sha256$#{iterations}$#{the_salt}$#{encoded_hash}"
end
I currently tried to configure the hashing of this plugin using the following values:
auth_opt_pg_hasher PBKDF2
auth_opt_pg_hasher_algorithm sha256
auth_opt_pg_hasher_keylen 24
auth_opt_pg_hasher_salt_size 12
auth_opt_pg_hasher_iterations 901
auth_opt_pg_hasher_salt-encoding base64
Any hints what i could configure differently ?
from mosquitto-go-auth.
Hi, @jklimke! The first thing that comes to mind is a typo in the salt encoding option, where you have a dash instead of an underscore:
auth_opt_pg_hasher_salt-encoding base64
from mosquitto-go-auth.
@iegomez Thanks for your response, but fixing this (embarrassing) typo. But unfortunately nothing changed. I also tried to switch between base64 and utf-8 encoding of the salt. Is there a set of configuration parameters that is know to be compatible with the old authentication plugin ?
from mosquitto-go-auth.
Config I use/ has been working for some time, directly migrated from jpmens plugin - albeit with some re-jigging/ re-mapping of user attributes in my database. Most importantly I continued to use the PBKDF2 hashes and users were unaware of the change.
# Cache config
auth_opt_cache true
auth_opt_cache_reset true
auth_opt_cache_host redis
auth_opt_cache_port 6379
auth_opt_cache_db 3
auth_opt_auth_cache_seconds 30
auth_opt_acl_cache_seconds 30
# Hasher Config
auth_opt_hasher pbkdf2
auth_opt_hasher_salt_size <size>
auth_opt_hasher_iterations <iterations>
auth_opt_hasher_keylen <key length>
auth_opt_hasher_algorithm <algorithm>
auth_opt_hasher_salt_encoding utf-8
# Mongo Config
auth_opt_backends mongo
auth_opt_mongo_host mongodb
auth_opt_mongo_port 27017
auth_opt_mongo_dbname users
auth_opt_mongo_authsource admin
auth_opt_mongo_username <username>
auth_opt_mongo_password <password>
auth_opt_mongo_salt_encoding utf-8
auth_opt_mongo_users accounts
auth_opt_mongo_acls acls
from mosquitto-go-auth.
I tried this and it worked when configuring the overall hasher configuration. It seems that postgres dependent hasher config is not applied to the backend as it does not work when specifying auth_opt_pg_hasher_* options only.
from mosquitto-go-auth.
Thanks @coldfire84 and @jklimke, I'll look into any issues regarding specific backend hasher options.
from mosquitto-go-auth.
@coldfire84 @jklimke Indeed I found a bug: I was passing postgres
instead of pg
as the prefix to build the hasher from specific options.
I'll have to check other backends ang get some time to do the fix, so here's an issue documenting this in the meantime: #95
from mosquitto-go-auth.
Related Issues (20)
- Files backend issue HOT 7
- Implementing mosquitto_psk_key_get for certificate whitelisting HOT 8
- JWT backend JS mode not working HOT 1
- How to check if a client is disconnected from the broker HOT 2
- MongoDB is broken in test Docker image HOT 4
- Not authenticating with mysql db
- The plugin cannot be built HOT 1
- Request: Help in setting up Allow/Deny Access Control Rules based on Client ID HOT 4
- TARGETPLATFORM does not include linux/amd64 in Dockerfile HOT 2
- http backend: superuser check is made for every single acl check HOT 6
- Make order of plugin execution configurable
- Update/Fix dependencies with active vulnerabilities HOT 1
- error compiling on raspberry pi HOT 1
- Hasher configuration alway defaults to Base64 HOT 1
- the doc should specify which auth methods support TCP and Websocket connections HOT 1
- Container image on Dockerhub is outdated
- Inconsistent rw Permission Behavior Not Matching Documentation HOT 4
- JWT RS256 public key verification "jwt parse error: key is of invalid type"
- Backend register error: couldn't initialize js backend with error Javascript backend error: missing options: js_acl_script_path.
- Allow for clientId to be passed to postgres GetUser backend password check HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mosquitto-go-auth.