QZ Tray 2.0 - attempting to use my own certificate

1,077 views
Skip to first unread message

Chris

unread,
Aug 10, 2016, 1:30:47 PM8/10/16
to qz-print
I have followed the instructions on this site to create my own certificates:

https://blog.didierstevens.com/2015/03/30/howto-make-your-own-cert-with-openssl-on-windows/

The only way in which I've deviated was to use 2048 bit instead of 4096, per your docs.

I launch QZ Tray with -DtrustedRootCert pointing to the ca.crt file generated by OpenSSL.

I have tested using both the ca.crt/ca.key and the ia.crt/ia.key files but I believe I still have a signing issue. I do get my certificate to show up in Site Manager after allowing it once and remembering that. It shows up with a Fingerprint.

I'm using the sign-message.php script via ajax, and I'm confirming that it is returning a signature, but I'm assuming somehow it isn't the correct signature. My app does NOT show any of the java alerts, however nothing prints. It seems to hang, when I give up and try to leave my page I get the error "connection closed before response received."

Any insight on this? Is it possible I need to use any different parameters on the OpenSSL steps?

Thanks!

ch...@cledwards.net

unread,
Aug 10, 2016, 3:05:19 PM8/10/16
to qz-print, ch...@cledwards.net
I should also have mentioned, I'm using the connectAndPrint option from here:
https://gist.github.com/tresf/42a8f25124840a6c496b

Maybe this needs some modification to work with signed messages?

I had connectAndPrint working with the prompts.

Tres Finocchiaro

unread,
Aug 10, 2016, 3:14:42 PM8/10/16
to Chris, qz-print

The signature promise and cert promise calls must be first.

Not sure why base64 is returned but hangs on your page.  Can you modify sample.html and see if it happens there too?

ch...@cledwards.net

unread,
Aug 10, 2016, 3:42:16 PM8/10/16
to qz-print, ch...@cledwards.net
On Wednesday, August 10, 2016 at 12:14:42 PM UTC-7, Tres Finocchiaro wrote:
> The signature promise and cert promise calls must be first.
>
> Not sure why base64 is returned but hangs on your page.  Can you modify sample.html and see if it happens there too?

Yes, if I modify sample.html it works fine. So my certificate and signing must be OK. I'll work on adapting my code based on the functions from sample.html instead of the connectAndPrint version. Thanks.

Tres Finocchiaro

unread,
Aug 10, 2016, 4:01:06 PM8/10/16
to Chris, qz-print
If that's the case, we'll reproduce and get back to you, thanks for reporting.

--
You received this message because you are subscribed to the Google Groups "qz-print" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qz-print+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kyle La Barge

unread,
Aug 10, 2016, 5:31:36 PM8/10/16
to Tres Finocchiaro, Chris, qz-print
Hi Chris,

I have just confirmed that signing should work perfectly fine with using the connectAndPrint(); function in https://gist.github.com/tresf/42a8f25124840a6c496b

Perhaps something else is breaking signing.  Can you provide us with your code snippet so we can reproduce on our end?  As Tres already mentioned, the setCertificatePromise and setSignaturePromise must be made first.



Regards,
Kyle

ch...@cledwards.net

unread,
Aug 10, 2016, 6:15:14 PM8/10/16
to qz-print, tres.fin...@gmail.com, kdla...@gmail.com
On Wednesday, August 10, 2016 at 2:31:36 PM UTC-7, Kyle La Barge wrote:
> Hi Chris,
>
>
> I have just confirmed that signing should work perfectly fine with using the connectAndPrint(); function in https://gist.github.com/tresf/42a8f25124840a6c496b
>
>
> Perhaps something else is breaking signing.  Can you provide us with your code snippet so we can reproduce on our end?  As Tres already mentioned, the setCertificatePromise and setSignaturePromise must be made first.
>
>
>
>
>
>
>
>
> Regards,
> Kyle
>

Kyle, I had an offline exchange with Tres. I'm using ajax to retrieve the data to be printed, so I guess I'm breaking something in the promise chain. Tres gave me another example that I'll try to follow. I basically just had a call to connectAndPrint in the callback from a pre-existing ajax call, which worked OK without the signing but doesn't work with the signing. But I think I have enough to go on, thanks both of you for your time.

Kyle La Barge

unread,
Aug 10, 2016, 8:22:18 PM8/10/16
to Chris, qz-print, Tres Finocchiaro
Hi Chris,

Thanks for the update.  If you require further assistance let us know.

Regards,
Kyle

Tres Finocchiaro

unread,
Aug 10, 2016, 10:04:07 PM8/10/16
to Chris, qz-p...@googlegroups.com

Putting the list back on CC.

On Aug 10, 2016 5:07 PM, "Tres Finocchiaro" <tres.fin...@gmail.com> wrote:
No, connectAndPrint cannot be used in that manner.

The purpose of connectAndPrint was to illustrate how a asynchronous promise chain can be implemented.

By injecting an asynchronous process (ajax) into the mix, you've broken it.

The general design is:

Promise()
.then(promise)
.then(promise)
.then(...)

Generally speaking, $.ajax implements the Promise interface "well enough".

var config = "qz.configs.create("zebra zp 500 (zpl)");

qz.websocket.connect()
.then($.ajax("/my/url1/..."))
.then(function(data) {
    qz.print(, data);})
.then($.ajax("/my/url2/..."))
.then(function(data) {
    qz.print("qz.configs.create("zebra zp 500 (zpl)"), data);})
.catch(function(err) {
    console.error(err);
});

If you are unsure about how many times you will be calling $.ajax, we recommend you use a custom Promise job instead.  Here's a sample:



On Wed, Aug 10, 2016 at 4:13 PM, Chris Edwards <ch...@cledwards.net> wrote:

I don’t know if this is a factor, but I make an ajax call that retrieves ZPL, and then I’m trying to send that to the printer. So it results in 2 ajax calls in a row. I have this stripped down to the basics:

 

·         qz.security.setCertificatePromise

·         qz.security.setSignaturePromise

·         qz.websocket.connect();

 

This is all on the page load, and seems to work, the log shows “allowed My Cert Name to connect to QZ”

 

Then this function:

 

function printLabel(zpl) {

    var printer = "zebra zp 500 (zpl)";

    var config = qz.configs.create(printer);

                var data = [{ type: 'raw', data: zpl }];

 

    qz.print(config, data);

}

 

I make my ajax call that returns ZPL then I call printLabel with response from that. My console shows my zpl ajax call, then the one to sign the message. Nothing appears on the QZ logs when I attempt to print.  So this still may be something I’m missing on my end, it is possible I am oversimplifying and missing a critical step.

ch...@cledwards.net

unread,
Aug 11, 2016, 9:32:56 AM8/11/16
to qz-print, ch...@cledwards.net
I'm sorry, I realize this is more of a jquery issue at this point than a QZ issue, but I'm trying to use the syntax you suggested:

qz.websocket.connect()
.then($.ajax('/my/url?params'))
.then(function(data) {
console.log(data);
qz.print(qz.configs.create("zebra zp 500 (zpl)"), data);
})
.catch(function(err) {
console.error(err);
});

but "data" is undefined when it gets into the function. This is with jquery 1.11.3. The ajax call is being made but the response is not being passed along. My console shows Established Connection with QZ Tray and then TypeError: data is undefined. Can you tell what I'm missing?

Thanks,
Chris

Tres Finocchiaro

unread,
Aug 11, 2016, 3:07:52 PM8/11/16
to Chris, qz-print
You can add an onerror callback in your AJAX.  If data is undefined, the problem is likely to stem from the AJAX call.

Chris

unread,
Aug 11, 2016, 3:46:14 PM8/11/16
to qz-print
On Thursday, August 11, 2016 at 12:07:52 PM UTC-7, Tres Finocchiaro wrote:
> You can add an onerror callback in your AJAX.  If data is undefined, the problem is likely to stem from the AJAX call.

From watching my console it appears that it’s not waiting. It goes into function(data) before the ajax call has completed and returned it’s data. I’ll keep experimenting, sounds like it’s my issue not yours at this point. Thanks again for the help.

Chris

unread,
Aug 11, 2016, 4:22:30 PM8/11/16
to qz-print, ch...@cledwards.net
I think I finally got it, if I do my ajax call first, I can get it to work like this:

$.post('/my/url', 'my=params', function(data) {
var zpl = [ data ];
qz.websocket.connect().then(function() {
qz.print(qz.configs.create("zebra zp 500 (zpl)"), zpl);
});
});

Reply all
Reply to author
Forward
0 new messages