javascriptprintingqz-tray

Suppress "localhost wants to access connected printers Untrusted Website" when accessing Printers - QZ-tray


How to properly Suppress the

localhost wants to access connected printers Untrusted Website

modal when accessing printers?

I've tried to create a certificate through this OpenSSL command:

openssl req -new -newkey rsa:2048 -sha256 -days 365 -nodes -x509 -keyout server.key -out server.crt

Then addeed the override like this:

authcert.override=server.crt

in the qz-tray.properties file.

However it is still the same the dialog box is not suppressed. What could be wrong?

This is the complete cert properties file:

authcert.override=C:\\Program Files\\QZ Tray\\auth\\server.crt
wss.alias=qz-tray
wss.keypass=keypass
wss.storepass=storepass
wss.host=0.0.0.0

Solution

  • The qz-tray.properties override will be introduced with version 2.0.2 and at the time of writing this, 2.0.1 is the latest stable release.

    Possible options:

    Since the latter option requires modification of the QZ Tray desktop launcher, this will ultimately lead to non-obvious issues when auto-start is enabled (e.g. auto-start on Windows is triggered by qz-tray.exe which will launch without the -DtrustedRootCert parameter).

    This is why the 2.0.2 feature of providing the certificate permanently in qz-tray.properties is much preferred. Note, compiling the latest QZ Tray is a few quick steps.

    But this is only half of the battle. To suppress the security warnings, each message must be digitally signed. This is where the server.key comes into play. We call this private-key.pem in our examples.

    Signing is generally done server-side although can be done client-side with risk of key leakage. This process is explained best in the sign-messages wiki.

    Signing Messages

    PHP Signing Example:

    <? // sign-message.php
    
    $KEY = 'private-key.pem'; // or 'server.key', etc
    $req = $_GET['request'];  // i.e. 'toSign' from JS
    $privateKey = openssl_get_privatekey(file_get_contents($KEY));
    $signature = null;
    openssl_sign($req, $signature, $privateKey);
    if ($signature) {
        header("Content-type: text/plain");
        echo base64_encode($signature);
        exit(0);
    }
    echo '<h1>Error signing message</h1>';
    exit(1);
    
    ?>
    

    JavaScript:

    qz.security.setSignaturePromise(function(toSign) {
        return function(resolve, reject) {
           $.ajax("/foo/bar/sign-message.php?request=" + toSign).then(resolve, reject);
        };
    });
    
    qz.security.setCertificatePromise(function(resolve, reject) {
        $.ajax("/foo/bar/digital-certificate.txt").then(resolve, reject); // or `server.crt`, etc
    });
    

    Note: To prevent key leakage, the private key should always be kept in a directory inaccessible by a web browser.