Importing PHP crypt MD5 passwords into Google Cloud Identity Platform?

Viewed 220

I'm trying to import existing users from another application into Google Cloud Identity Platform using passwords that were hashed using PHP's crypt function with an MD5 output.

This is an example of the hashed password being used in PHP:

$hashed_password = '$1$AT$JGYIRSP7xIYmg1XSoJmvB1';
$user_input = 'test123';

if (hash_equals($hashed_password, crypt($user_input, $hashed_password))) {
   echo "Password verified!";
}

I've tried all sorts of combinations for importing the user and their password, but no combination seems to work. This is the NodeJS import script I'm using:


var admin = require('firebase-admin');

var app = admin.initializeApp({
  credential: admin.credential.applicationDefault()
});

admin
  .auth()
  .importUsers(
    [
      {
        uid: '31',
        email: 'user31@test.test',
        // Must be provided in a byte buffer.
        passwordHash: Buffer.from('$1$AT$JGYIRSP7xIYmg1XSoJmvB1'),
        // Must be provided in a byte buffer.
        passwordSalt: Buffer.from('$1$AT$'),
      },
    ],
    {
      hash: {
        algorithm: 'MD5',
        rounds: 0,
      },
    }
  )
  .then((results) => {
    console.log(results);

    results.errors.forEach((indexedError) => {
      console.log(`Error importing user ${indexedError.index}`);
    });
  })
  .catch((error) => {
    console.log('Error importing users :', error);
  });

As mentioned above, I've tried just about every combination of hash and passwordSalt I could think of. I've tried:

  • passing no passwordSalt
  • passing a passwordSalt of AT
  • passing a passwordSalt of AT$
  • passing a passwordSalt of $AT
  • passing a passwordSalt of $AT$
  • all of the above but with a hash algorithm of BCRYPT

I can see the user getting imported. If I change the hash to something like a regular MD5 hash, I'm able to authenticate as that user, so I know the import process is working correctly.

Does GCP Identity Platform simply not support these hashes? Am I passing the salt incorrectly or passing an incorrect number of rounds? Am I passing the wrong hash algorithm? I'm a little surprised, as I would've thought passwords hashed using PHP's crypt function would've been supported.

1 Answers

4 points:

1.- You are mentioning that you are trying to import existing users and their passwords from another application into Google Cloud Identity Platform. Also, you mentioned that you are using a NodeJS import script focused on MD5. Based on that, and using the same official GCP documentation that you quoted Migrating users from an existing app vs the NodeJS’s script you posted, it seems that you didn’t use the code sample that is posted in that documentation, exactly in the way it should be used, unless that you are the owner of the domain "@test.test":


    getAuth()
  .importUsers(
    [
      {
        uid: 'some-uid',
        email: 'user@example.com',
        // Must be provided in a byte buffer.
        passwordHash: Buffer.from('password-hash'),
        // Must be provided in a byte buffer.
        passwordSalt: Buffer.from('salt'),
      },
    ],
    {
      hash: {
        algorithm: 'PBKDF2_SHA256',
        rounds: 100000,
      },
    }
  )
  .then((results) => {
    results.errors.forEach((indexedError) => {
      console.log(`Error importing user ${indexedError.index}`);
    });
  })
  .catch((error) => {
    console.log('Error importing users :', error);
  });

2.- Are we sure you have the required admin rights or role over IAM in your GCP’s Organization? You can use the following official GCP documentation for understanding roles Understanding roles

3.- How are you figuring out that it is not working? Are you facing any of the following errors? Error codes. Is there any particular behavior after the importing process finishes or any log that you can share here editing your original post? Or is it only because you see that once the users are imported to IAM, they are not able to authenticate?

4.- I suggest you by now to follow (Method: users.insert) as stated here Method: users.insert first, this way you are going to review the hash formats that are supported. Finally, you need to do this test with the domains that you have verified in Cloud Identity.

Related