davla
07/07/2023, 9:49 AMbox install totp
into my application (non-coldbox) and when viewing the index.cfm file the QR code is a broken image. I am running locally on CommandBox with Lucee 5.4.0.80. Further investigation reveals that the generateQRCode method isn’t returning a base64 encoded string of the image but an <img/>
tag. So in the index.cfm this code:
<figure class="flex flex-col mb-4 w-64 h-64">
<img class="mx-auto w-64 h-64" src="data:image/png;base64,#toBase64(application.totpConfig.qrCode)#" alt="#application.totpConfig.url#" />
<figcaption class="text-gray-400 text-sm">#application.totpConfig.url#</figcaption>
</figure>
results in the attached screenshot showing the broken image. If I simply change the <figure/>
code to this:
<figure class="flex flex-col mb-4 w-64 h-64">
#application.totpConfig.qrCode#
<figcaption class="text-gray-400 text-sm">#application.totpConfig.url#</figcaption>
</figure>
the qr code is displayed as application.totpConfig.qrcode appears to be an <img/>
tag. Barcode.cfc returns this: _return_ imageNew( local_._imageBuffer );
.
Is there a way to fix this? I am guessing the totp component is expecting the qrcode returned from barcode.cfc to be something that can be encoded to base64.davla
07/07/2023, 9:51 AMdavla
07/07/2023, 10:13 AMreturn imageNew( local.imageBuffer );
to this:
return local.imageBuffer;
and changing generateQRCode (in totp.cfc) from this:
return variables.barcodeService.getBarcodeImage(
contents = arguments.authenticatorUrl,
type = "QR_CODE",
width = arguments.width,
height = arguments.height
);
to this:
var cfmlImage = variables.barcodeService.getBarcodeImage(
contents = arguments.authenticatorUrl,
type = "QR_CODE",
width = arguments.width,
height = arguments.height
);
return toBase64(cfmlImage);
I also commented out line 41 in the generate method of totp.cfc:
//toBase64( config[ "qrCode" ] );
then works with this in index.cfm:
<figure class="flex flex-col mb-4 w-64 h-64">
<img class="mx-auto w-64 h-64" src="data:image/png;base64,#application.totpConfig.qrCode#" alt="#application.totpConfig.url#" />
<figcaption class="text-gray-400 text-sm">#application.totpConfig.url#</figcaption>
</figure>
bdw429s
07/07/2023, 5:39 PMelpete
07/07/2023, 5:42 PMelpete
07/07/2023, 5:43 PMtoBase64
call you commented out was needed in Lucee 5.3 and earlier due to a Lucee bug.davla
07/07/2023, 6:17 PMelpete
07/07/2023, 6:44 PMbdw429s
07/07/2023, 6:44 PMelpete
07/07/2023, 6:44 PMtoBase64(imageGetBufferedImage(application.totpConfig.qrCode))
with the latest extension.elpete
07/07/2023, 6:44 PMelpete
07/07/2023, 6:45 PMqrCode
key in the struct because it’s now a Java object, not the CFML image struct.bdw429s
07/07/2023, 6:45 PMelpete
07/07/2023, 6:45 PMtoBase64(imageGetBufferedImage(application.totpConfig.qrCode))
snippet instead.elpete
07/07/2023, 6:51 PMdavla
07/07/2023, 6:51 PMelpete
07/07/2023, 6:52 PMimageReadBase64
and then writes it out again using toBase64
. The values are not the same.davla
07/10/2023, 2:05 PMtoBase64( config[ "qrCode" ] );
The following (with @elpete change applied) seems to work:
<figure class="flex flex-col mb-4 w-64 h-64">
<img class="mx-auto w-64 h-64" src="data:image/png;base64,#toBase64( imageReadBase64( application.totpConfig.qrCode ) )#" alt="#application.totpConfig.url#" />
<figcaption class="text-gray-400 text-sm">#application.totpConfig.url#</figcaption>
</figure>
Note the addtion of the imageReadBase64
applied to the application_._totpConfig_._qrCode
value in the img tag.