Skip to content

Instantly share code, notes, and snippets.

View bseddon's full-sized avatar
💭
Working hard on XBRL and XAdES signing

Bill Seddon bseddon

💭
Working hard on XBRL and XAdES signing
  • Lyquidity Solutions Limited
View GitHub Profile
@bseddon
bseddon / lyquidity.cla.md
Last active January 14, 2021 15:02
A contributor license agreement for Lyquidity repository contributions

Lyquidity Contributor License Agreement

Thank you for your interest in contributing to open source software projects (“Projects”) made available by Lyquidity Solutions Limited or its affiliates (“Lyquidity”). This Contributor License Agreement (“Agreement”) sets out the terms governing any source code, object code, bug fixes, configuration changes, tools, specifications, documentation, data, materials, feedback, information or other works of authorship that you submit or have submitted, in any form and in any manner, to Lyquidity in respect of any of the Projects (collectively “Contributions”). If you have any questions respecting this Agreement, please contact github@lyquidity. com. You agree that the following terms apply to all of your past, present and future Contributions. Except for the licenses granted in this Agreement, you retain all of your right, title and interest in and to your Contributions.

Why is a CLA necessary?

It depends on the jurisdiction but in many countries contributions are o

@bseddon
bseddon / format-date.md
Last active February 20, 2021 01:48
Format dates in JavaScript

With the Intl object JavaScript is awash with functions to format dates so why is another one needed? The functions in Intl are generic and address uses cases where it's important that dates are formatted in a way that is commonly recognized by users within a locale. But there are many cases where date formatting is needed that has nothing to do with locales. My specific case is to be able to output date information that is consistent with the XML date types:

QName Format
xs:time HH-MM-SS
xs:gYearMonth YYYY-MM
xs:gYear YYYY
xs:gMonthDay --MM-DD
xs:gDay ---DD
xs:gMonth --MM
@bseddon
bseddon / xml digital signature.md
Last active May 10, 2021 17:27
xml digital signature

When wanting to sign XML documents using a protocol such as https://www.w3.org/TR/xmldsig-core/ or https://www.w3.org/TR/xmldsig-core2/ its necessary to have a certificate and its corresponding private key. Sure, you can buy a certificate and key from a certificate authority (CA) but if the purpose of the certificate is only to generate certificates for internal consumption, for testing or when verifiers will trust a CA you provide, then creating your own certificates and keys is free.

Here's how to do it using a tool like OpenSSL. Another tool could be used as this example uses only standard public key infrastructure (PKI) techniques. Throughtout I'm using a domain in the file names. This hints that the certificate will be available online so others will be able to access it to verify any certificates it is used to sign.

Create certificate authority

A certificate authority is just the owner of a certificate and public key where the [subject](https://en.wikipedia.org/wi

@bseddon
bseddon / signing an xml document.md
Last active May 10, 2021 19:30
Signing an XML document

Protocols such as https://www.w3.org/TR/xmldsig-core/ or https://www.w3.org/TR/xmldsig-core2/ define how to sign an XML document using a PKI certificate (gist XML Digital Signature describes how such a certificate can be generated using OpenSSL).

An XML document cannot be signed by manually adding information even with a certificate. Instead an application is needed to apply the certificate and sign the document using the private key associated with a certificate. However, when a suitable application is used then the XML document:

<?xml version="1.0" encoding="UTF-8"?>
<root>
	<someElement>Ipso facto...</someElement>
</root> 
@bseddon
bseddon / subtle-sign-verify-x509.md
Last active September 13, 2023 08:05
Using crypto.subtle to sign text and verify a signature using an external asymmetric key pair

Subtle is the modern way to perform cryptographic task in JavaScript. However, examples provided in the Mozilla documentation or in their GitHub pages only show how to use the subtle functions to sign text and verify signatures using a key pair generated by subtle.

In my use case the key pair MUST be generated a recognised authority so how can the CryptoKey required by the subtle Sign and Verify functions be created from an external source. On this the documentation and examples are not very helpful so this gist provides a worked example showing how to do it.

Use case

In my case a signature is to be added to a document in the manner specified by XAdES which is defined by ETSI on behalf of the EU commission. The public key of the key pair used MUST be pa

@bseddon
bseddon / zmq.md
Last active October 15, 2022 23:29
Building ZeroMQ on Windows

The Zero MQ extension for PHP is not available as a Windows PECL package for PHP versions later than 7.2. So for later PHP versions it's necessary to build the extension. That also means building libzmq. The Zero MQ team have dropped the Visual Studio solutions files in favour using CMake. So how do users on Windows build Zero MQ? Here's how (and it's not hard).

Install Visual Studio. While installing, opt to install C++ and make sure the option to install the CMake tools for C++ is selected.

If VS is already installed because you use it for another project type, then use the Visual Studio Installer tool (available from the start menu) to modify the installation to add C++ and the CMake tools. Note tha in Visual Studio Installer the CMake tools will appears an option in the 'individual packages' (you'll know what I mean when you get there).

Download the ZeroMQ zip from GitHub and extract it. In whatever folder you chose to extract the zip file there will be a file called CMakeFiles.txt. Edit this f

Building the PHP ZeroMQ extension (php-zmq) for Windows

Because there is no pre-compiled PHP ZMQ extension after PHP version 7.2 it's necessary to build your own. This is a short review of the process. The PHP ZMQ extension is a wrapper around libzmq which also needs to be built. The steps needed to build libzmq are covered in another gist.

Extensions are PHP version specific as the PHP internals vary from release to release. While it's not necessary to build PHP to build an extension an extension build requires some files from the build of a version of PHP. Because its not difficult to build PHP, why not? By building a version of PHP you can build the extension at the same time.

The steps needed to build PHP are listed in the PHP SDK GitHub repository. For the purposes of this page, after following the steps the working folder will be something like:

.\php-sdk\sdk\php-8.2\vs16\x6
@bseddon
bseddon / dbi-page-structure.md
Last active October 21, 2022 09:07
Dundas BI pages structure

The listing below provides a canonical view of a page generated by Dundas BI. The structure of the page is the same whether it's for a frontend view or an administrator. The difference is the latter has extra files for JavaScript, CSS and localization.

The listing uses comments to describe the various sections that will appear and example tags where relevant.

There is nothing unusual about the structure used which is similar to that found in any web-based application.

From a the point of view of understanding how backend features translate into web page content, the interesting things are how items from the settings uun Setup -> app styling -> CssStyleOverride (and others like HTML Override) appear in the page content.

Note that the amount of code in the global overrides is not going to haveany material impact on the speed of page rendering for two reasons. The first is that they are static. That is, once they are read, the browser will cache the content until either the cache is removed (eg ctrl-f5)

@bseddon
bseddon / dbi-page-processing.md
Last active October 21, 2022 11:16
Dundas BI page rendering process

Once the page HTML is downloaded and the scripts start executing the page is created dynamically. This process is the same for all pages. The bulk of the work is done by the DBI built-in scripts especially base.js and extrastrict.js. Where these files can be found in the page is covered in the gist about the DBI page structure.

The screenshots included in this article are of the developer console in Chrome. It looks pretty much the same in Edge or Firefox or Safari.

Processing involves repreated calls to DBI REST endpoints exposed by the DBI server. This begins with a call to getsession. The server returns session information relating to the current page and user.

web-page-1

One of the bits of information in the returned object is the id of the project. This is used as a key to retrieve details of the project.

@bseddon
bseddon / querying-with-dundas-bi.md
Last active November 17, 2022 15:16
How to create a data request in Dundas BI with selections set using view parameters

Data presented on a dashboard is mediated by one or more metric sets. A metric set defines some data set with rows and columns. A user needs only to drag a metric set onto a dashboard to begin using that data. But what happens behind the scenes? What if you want to use a metric set in code? Read on.

Get data

When the Dundas UI needs data it retrieves it using the REST API call for GetData. This REST call uses a POST request. The request body is a JSON array of one or more DataRequest objects. More about these in a moment.

If successful, the response will be an array of DataResponse objects. There should be a response object for every request object.

Request obje