MozillaZine

How does Firefox 67 determine install hash?

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

Post Posted May 24th, 2019, 12:43 pm

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?)
*Always* check the changelogs BEFORE updating that important software!

Brummelchen
 
Posts: 4312
Joined: March 19th, 2005, 10:51 am

Post Posted May 26th, 2019, 2:24 am

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: 1686
Joined: October 1st, 2014, 3:25 pm

Post Posted May 26th, 2019, 10:12 am

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.
*Always* check the changelogs BEFORE updating that important software!

barbaz
 
Posts: 1686
Joined: October 1st, 2014, 3:25 pm

Post Posted May 28th, 2019, 10:55 am

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
*Always* check the changelogs BEFORE updating that important software!

Return to MozillaZine Tech


Who is online

Users browsing this forum: No registered users and 2 guests