1

Trying to create user using from golang using library "google.golang.org/api/admin/directory/v1"

As docs sad here https://developers.google.com/admin-sdk/directory/reference/rest/v1/users#User hashFunction could be MD5, DES, SHA2-256, SHA2-512, so i'm writing code:

hash := sha512.Sum512([]byte("random password value))
encoded := hex.EncodeToString(hash[:])

payload := &admin.User{
    Password:     "$6$" + encoded,
    HashFunction: "SHA2-512"
}

This results: googleapi: Error 400: Invalid Hash Function Name, invalid

So how to understand, whats wrong with hash function name ?

2 Answers 2

1

So, i found here https://developers.google.com/resources/api-libraries/documentation/admin/directory_v1/python/latest/admin_directory_v1.users.html#insert that right now only supported SHA-1, crypt and MD5, so documentation is wrong, and for SHA2 hashes use string "crypt" as hashFunction value and add to password corresponding crypt prefix ( for example for SHA2-512 add $6$ to hex encoded value )

0

For me, I had to also include a salt, for the backend to accept the password (not sure if this is dependent on the domain). Otherwise I got the error "googleapi: Error 400: Invalid Password, invalid" when trying to call users.insert.

For example, if using SHA-256, the crypt format is:

$5$salt$hash

Pseudo-code example:

salt := "some random string"
password := "I'm a password <= 100 chars"
hash = sha256sum(passsword + salt)

crypt := "$5$" + hexEncode(salt) + "$" + hexEncode(password)

The magic number$5$ depends on the hash function used.

  • Use $1$ for DES, or MD5
  • Use $5$ for SHA-256
  • Use $6$ for SHA-512

Then the hashFunction is set to crypt.

From: https://developers.google.com/admin-sdk/directory/reference/rest/v1/users#User

More about the c crypt lib (not to be confused with the Unix utility of the same name), with valid hash examples that can be tested: https://en.wikipedia.org/wiki/Crypt_%28C%29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.