Create a SHA1 dovecot digest using bash or python or another linux command line tool

Our dovecot server and mail server authenticate users using the SHA1 digest. We cannot change the current digest because we have so many users and we do not want them to recreate all their passwords.

We need an easier way to create a digest for entering into the database for our users (and, ultimately, create a web interface so that they can change it themselves).

We are currently creating a digest using the linux command:

dovecotpw -s SHA1 

We want to switch because dovecotpw is not scriptable (at least not without using the expected or something similar). However, everything I tried (sha1sum, mysql sha1, python hashlib.sha1), everything produces something very different from the dovecotpw command.

Below is the output of various commands for the word: password

 dovecotpw -> W6ph5Mm5Pz8GgiULbPgzG37mj9g= sha1sum -> 5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8 python hashlib.sha1() -> 5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8 mysql sha1() -> 5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8 

So, dovecot seems to be the one who does things differently. Unfortunately, this is the one I need to create.

Any idea how I can get dovecot sha1 from a script command?

Thanks.

+4
source share
2 answers

You need base64 to encode the binary digest in order to get it in its own format.

 >>> import hashlib >>> import base64 >>> p = hashlib.sha1('password') >>> base64.b64encode(p.digest()) 'W6ph5Mm5Pz8GgiULbPgzG37mj9g=' 

EDIT: By the way, if you prefer to do this from a terminal / bash script, you can do

 $ echo -n 'password' | openssl sha1 -binary | base64 W6ph5Mm5Pz8GgiULbPgzG37mj9g= 

In addition, you can say that dovecotpw no longer gave a hash hexagon because it has more characters, not all hexidecimal [0-9a-f]. Using the characters [A-Za-z0-9 + /] with an ending = implies that this was a base64 hash conversion.

+7
source

The output of dovecotpw is base64 encoded.

+1
source

All Articles