diff options
author | Simon Beck <simon.beck@earthnet.ch> | 2022-02-08 17:59:59 +0100 |
---|---|---|
committer | Simon Beck <simon.beck@earthnet.ch> | 2022-02-10 20:51:01 +0100 |
commit | f05e41c9aad83f3d45aff620a739a116c32b4c47 (patch) | |
tree | 13c8de24260478e90419292ffd6c3035d1f95ee6 /write.go | |
parent | dbd900371466edfdc7bb7f09080c6698e4f8e647 (diff) | |
download | bottin-f05e41c9aad83f3d45aff620a739a116c32b4c47.tar.gz bottin-f05e41c9aad83f3d45aff620a739a116c32b4c47.zip |
Improve password hash handling
This adds support for more hash algorithms. Also a stored password will
be updated to SSHA512 upon a successful bind. It will also automatically
hash a cleartext password if the `userpassword` field is modified with
a cleartext one.
Hashes supported:
* SSHA
* SSHA256
* SSHA512
Diffstat (limited to 'write.go')
-rw-r--r-- | write.go | 23 |
1 files changed, 21 insertions, 2 deletions
@@ -7,8 +7,9 @@ import ( ldap "bottin/ldapserver" - consul "github.com/hashicorp/consul/api" message "bottin/goldap" + + consul "github.com/hashicorp/consul/api" ) // Generic item modification function -------- @@ -38,7 +39,7 @@ func (server *Server) putAttributes(dn string, attrs Entry) error { // Retreieve previously existing attributes, which we will use to delete // entries with the wrong case - previous_pairs, _, err := server.kv.List(prefix + "/attribute=", &server.readOpts) + previous_pairs, _, err := server.kv.List(prefix+"/attribute=", &server.readOpts) if err != nil { return err } @@ -65,6 +66,24 @@ func (server *Server) putAttributes(dn string, attrs Entry) error { } } + // if the password is not yet hashed we hash it + if k == ATTR_USERPASSWORD { + tmpValues := []string{} + for _, pw := range values { + _, err := determineHashType(pw) + if err != nil { + encodedPassword, err := SSHAEncode(pw) + if err != nil { + return err + } + tmpValues = append(tmpValues, encodedPassword) + } else { + tmpValues = append(tmpValues, pw) + } + } + values = tmpValues + } + // If we have zero values, delete associated k/v pair // Otherwise, write new values if len(values) == 0 { |