qzind / qz-print

Archive for legacy qz-print versions (1.8, 1.9). See https://github.com/qzind/tray for modern versions.
Other
141 stars 101 forks source link

Add documentation to wiki for pre-signing #162

Closed tresf closed 8 years ago

tresf commented 8 years ago

This bug has been migrated to https://github.com/qzind/tray/issues/9


Explanation of the signing concern...

" [... signing each message] really complicates our installation (we'll issue a lot of print jobs from the client, and we do not want to have to round-trip with ajax to sign [every one of] these requests)"

"[...] it absolutely introduces a great deal of latency and makes our client app significantly more chatty with our application servers [...]"

This is available in 2.0 now. Here's an explanation of how the feature works works...

function presigned() {

    //Normal call
    var config = qz.configs.create("Microsoft Print to PDF");
    var sampleData = [{
        type: 'image',
        format: 'base64',
        data: "iVBORw0KGgoAAAANSUhEUgAAABgAAAAOAgMAAABIljTtAAAACVBMVEVWeSj///+62o/z2o4vAAAAQElEQVR4XmMIWzWVg" +
        "UGUIWrVUhCVGbY0NCCUYWno0lBHCMUKpkJEwVRAaChIiWNoKESDFEMYhAoNXRoaGoqVAgDQoR6enOmXAgAAAABJRU5ErkJggg=="
    }];
    qz.print(config, sampleData);

    // Pre-signed version of the above request requires a signatured hash of the print request's JSON parameters
    // JSON string -> '{"call":"print","params":{"printer":{"name":"Microsoft Print to PDF"},"options":{"color":true,"copies":1,"dpi":72,"duplex":false,"margins":0,"orientation":null,"paperThickness":null,"printerTray":null,"rotation":0,"scaleContent":true,"size":null,"altPrinting":false,"encoding":null,"endOfDoc":null,"perSpool":1},"data":[{"type":"image","format":"base64","data":"iVBORw0KGgoAAAANSUhEUgAAABgAAAAOAgMAAABIljTtAAAACVBMVEVWeSj///+62o/z2o4vAAAAQElEQVR4XmMIWzWVgUGUIWrVUhCVGbY0NCCUYWno0lBHCMUKpkJEwVRAaChIiWNoKESDFEMYhAoNXRoaGoqVAgDQoR6enOmXAgAAAABJRU5ErkJggg=="}]},"timestamp":1453732628905}'
    // SHA-256 (sign this) -> '0b54b3418c181f0ade87ab79b71e3b69b2ed96e92adc18a74e6b2a12628e296c'

    // Notes: 
    // The params.printer and params.options variables can be acquired from a JSON.stringify call of config.getPrinter and config.getOptions, respectively
    // Order of JSON string values is important for hashing and signing
    // Signatures are only valid 15 minutes from the timestamp date

    qz.print(config,
             sampleData,
             "s/kVxrdNa+dYrOMBK6Sg3oemUGHF1CT7xir40THO7Y00bsDGt8tBGwKpfqHyIyE5yioZUS78jUCF9JBE+Z/D4lh6zo2z8OuXi3Dy1PRAKEuQPu0a9BpciUbbOfTeYD05It1C6vCSixNl3WuRLjX/je5Ez0IF2mYJki/bGvHzv2yYlbdsny6zqK9raAySXAfjkIabgLilPlzu2v4eF/kT0xzuzIpgsFyq6mYf36+dsRckCYOGphxrxKDrO0yUdxicFU1+KfO16FNDSg8DJ7DQ8j71/GcIQmwXdzlYA/BfwmSwNvfT/5ZDDI7E4CMsCUzZ+rFUbgE9JAwRZ6IKsUdrIQ==",
             1453732628905);

//  $.get("/signed/print/document")
//          .done(function(resultObj) {
//      qz.print(config, resultObj.sampleData, resultObj.signature, resultObj.timestamp);
//  });

}
tresf commented 8 years ago

This bug has been migrated to https://github.com/qzind/tray/issues/9