How does Firefox 67 determine install hash?

Discuss various technical topics not related to Mozilla.
Locked
barbaz
Posts: 1504
Joined: October 1st, 2014, 3:25 pm

How does Firefox 67 determine install hash?

Post by barbaz »

For an installation of Firefox 67 at /opt/test/firefox (where the Firefox binary is at /opt/test/firefox/firefox), Firefox uses this install hash in profiles.ini and installs.ini -

Code: Select all

CA44EF10692C8B1C
How is it getting that?

I'm looking to reproduce that result externally. Some digging through Firefox source code suggests Firefox is computing the CityHash64 of the canonical path to the Firefox binary. So I tried creating a simple C++ program that directly uses the Mozilla code for CityHash, but it gets wildly different result from Firefox.

Code: Select all

#include <iostream>
#include <string.h>

// CityHash implementation from Firefox:
// other-licenses/nsis/Contrib/CityHash/cityhash
#include "cityhash/city.h"

using namespace std;

int main(int argc, char* argv[]) {
  if (argc == 2 && strcmp(argv[1], "--help") != 0) {
    printf("%lX\n", CityHash64(argv[1], strlen(argv[1])));
    return 0;
  }

  printf("usage: %s <string>\n", argv[0]);
  return 1;
}

Code: Select all

$ ./cityhash64 /opt/test/firefox/firefox
A1D6C94BC1323C0A
(I don't know C++ well at all, so maybe I just didn't write the program correctly?)
Brummelchen
Posts: 4480
Joined: March 19th, 2005, 10:51 am

Re: How does Firefox 67 determine install hash?

Post by Brummelchen »

why is it important for you? hash here is different each time firefox writes installs.ini from scratch. its just an random identifier like the token in profile path.
barbaz
Posts: 1504
Joined: October 1st, 2014, 3:25 pm

Re: How does Firefox 67 determine install hash?

Post by barbaz »

Brummelchen wrote:why is it important for you?
Mainly for updating my custom script for setting up Firefox and pre-seeding Firefox profiles in disposable testing environment.

(For other users, and to spare the inevitable reply - I emphasize the word "testing" above. For a production environment, I would best just handle this from within Firefox itself.)
Brummelchen wrote:hash here is different each time firefox writes installs.ini from scratch. its just an random identifier like the token in profile path.
Maybe this is different on different OS? I'm on Linux, and the install hashes are consistent and depends on where the Firefox tarball is extracted.
barbaz
Posts: 1504
Joined: October 1st, 2014, 3:25 pm

Re: How does Firefox 67 determine install hash?

Post by barbaz »

I asked on irc and was told my program needs to hash char16_t of the path, not char.

So reading the Mozilla code more carefully and doing some Internet searching, I now have this -

Code: Select all

#include <iostream>
#include <string.h>
#include <locale>
#include <codecvt>

// CityHash implementation from Firefox:
// other-licenses/nsis/Contrib/CityHash/cityhash
#include "cityhash/city.h"

using namespace std;

int main(int argc, char* argv[]) {
  if (argc == 2 && strcmp(argv[1], "--help") != 0) {
    u16string u16_conv = wstring_convert<codecvt_utf8_utf16<char16_t>, char16_t>{}.from_bytes(argv[1]);
    const char16_t* a1 = u16_conv.c_str();
    size_t len = char_traits<char16_t>::length(a1) * sizeof(*a1);
    printf("%lX\n", CityHash64(reinterpret_cast<const char*>(a1), len));
    return 0;
  }

  printf("usage: %s <string>\n", argv[0]);
  return 1;
}
But apparently I'm still doing something wrong -

Code: Select all

$ ./cityhash64 /opt/test/firefox/firefox
47D27EEBD60E2FED
henrikoz
Posts: 1
Joined: December 22nd, 2020, 3:20 am

Re: How does Firefox 67 determine install hash?

Post by henrikoz »

Over a year late. Probably too late. I know. But it might help someone.

The second code is working. What is wrong is the assumption that a complete path to the executable shall be provided. Only the folder path is expected.

Code: Select all

$ ./cityhash64 /opt/test/firefox
CA44EF10692C8B1C
barbaz
Posts: 1504
Joined: October 1st, 2014, 3:25 pm

Re: How does Firefox 67 determine install hash?

Post by barbaz »

henrikoz wrote:Over a year late. Probably too late. I know. But it might help someone.

The second code is working. What is wrong is the assumption that a complete path to the executable shall be provided. Only the folder path is expected.

Code: Select all

$ ./cityhash64 /opt/test/firefox
CA44EF10692C8B1C
Ha! Just happened on this site today and found your post. Thanks! :D
Locked