tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

WindowsUserChoice.h (4553B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 #ifndef SHELL_WINDOWSUSERCHOICE_H__
      7 #define SHELL_WINDOWSUSERCHOICE_H__
      8 
      9 #include <windows.h>
     10 
     11 #include "ErrorList.h"  // for nsresult
     12 #include "mozilla/UniquePtr.h"
     13 #include "nsString.h"
     14 
     15 /*
     16 * Check the UserChoice Hashes for https, http, .html, .htm
     17 *
     18 * This should be checked before attempting to set a new default browser via
     19 * the UserChoice key, to confirm our understanding of the existing hash.
     20 * If an incorrect hash is written, Windows will prompt the user to choose a
     21 * new default (or, in recent versions, it will just reset the default to Edge).
     22 *
     23 * Assuming that the existing hash value is correct (since Windows is fairly
     24 * diligent about replacing bad keys), if we can recompute it from scratch,
     25 * then we should be able to compute a correct hash for our new UserChoice key.
     26 *
     27 * @return true if we matched all the hashes, false otherwise.
     28 */
     29 bool CheckBrowserUserChoiceHashes();
     30 
     31 /*
     32 * Result from CheckUserChoiceHash()
     33 *
     34 * NOTE: Currently the only positive result is OK_V1 , but the enum
     35 * could be extended to indicate different versions of the hash.
     36 */
     37 enum class CheckUserChoiceHashResult {
     38  OK_V1,         // Matched the current version of the hash (as of Win10 20H2).
     39  ERR_MISMATCH,  // The hash did not match.
     40  ERR_OTHER,     // Error reading or generating the hash.
     41 };
     42 
     43 /*
     44 * Generate a UserChoice Hash, compare it with the one that is stored.
     45 *
     46 * See comments on CheckBrowserUserChoiceHashes(), which calls this to check
     47 * each of the browser associations.
     48 *
     49 * @param aExt      File extension or protocol association to check
     50 * @param aUserSid  String SID of the current user
     51 *
     52 * @return Result of the check, see CheckUserChoiceHashResult
     53 */
     54 CheckUserChoiceHashResult CheckUserChoiceHash(const wchar_t* aExt,
     55                                              const wchar_t* aUserSid);
     56 
     57 /*
     58 * Get the registry path for the given association, file extension or protocol.
     59 *
     60 * @return The path, or nullptr on failure.
     61 */
     62 mozilla::UniquePtr<wchar_t[]> GetAssociationKeyPath(const wchar_t* aExt);
     63 
     64 /*
     65 * Appends the registry path for the given association, file extension or
     66 * protocol to the parameter string.
     67 *
     68 * @param aExt      File extension or protocol association to return path to.
     69 * @param aOutput   String to append registry path to.
     70 */
     71 void AppendAssociationKeyPath(const wchar_t* aExt, nsAString& aOutput);
     72 
     73 /*
     74 * Get the current user's SID
     75 *
     76 * @return String SID for the user of the current process, nullptr on failure.
     77 */
     78 mozilla::UniquePtr<wchar_t[]> GetCurrentUserStringSid();
     79 
     80 /*
     81 * Generate the UserChoice Hash
     82 *
     83 * @param aExt          file extension or protocol being registered
     84 * @param aUserSid      string SID of the current user
     85 * @param aProgId       ProgId to associate with aExt
     86 * @param aTimestamp    approximate write time of the UserChoice key (within
     87 *                      the same minute)
     88 *
     89 * @return UserChoice Hash, nullptr on failure.
     90 */
     91 mozilla::UniquePtr<wchar_t[]> GenerateUserChoiceHash(const wchar_t* aExt,
     92                                                     const wchar_t* aUserSid,
     93                                                     const wchar_t* aProgId,
     94                                                     SYSTEMTIME aTimestamp);
     95 
     96 /*
     97 * Build a ProgID from a base and AUMI
     98 *
     99 * @param aProgIDBase   A base, such as FirefoxHTML or FirefoxURL
    100 * @param aAumi         The AUMI of the installation
    101 *
    102 * @return Formatted ProgID.
    103 */
    104 mozilla::UniquePtr<wchar_t[]> FormatProgID(const wchar_t* aProgIDBase,
    105                                           const wchar_t* aAumi);
    106 
    107 /*
    108 * Check that the given ProgID exists in HKCR
    109 *
    110 * @return true if it could be opened for reading, false otherwise.
    111 */
    112 bool CheckProgIDExists(const wchar_t* aProgID);
    113 
    114 /*
    115 * Get the ProgID registered by Windows for the given association.
    116 *
    117 * The MSIX `AppManifest.xml` declares supported protocols and file
    118 * type associations.  Upon installation, Windows generates
    119 * corresponding ProgIDs for them, of the form `AppX*`.  This function
    120 * retrieves those generated ProgIDs (from the Windows registry).
    121 *
    122 * @return ProgID.
    123 */
    124 nsresult GetMsixProgId(const wchar_t* assoc,
    125                       mozilla::UniquePtr<wchar_t[]>& aProgId);
    126 
    127 #endif  // SHELL_WINDOWSUSERCHOICE_H__