PHP, newAccount request, parse error reading JWS

It's a hacky way of transforming DER byte strings. DER (Distinguished Encoding Rules) is a binary encoding for data structures described by ASN.1 (Abstract Syntax Notation One).

The OpenSSL output produced is in this ASN.1/DER format. However, the signature expected by RFC 7518 Section 3.4 is not in ASN.1 format: It expects the ECDSA signature values (called R and S, two 256/384/521-bit integers) to be encoded as a single big-endian unsigned integer concatenating the two. The PHP function above "searches through" the ASN.1/DER sequence to look for the bytes representing R and S respectively (they're within the DER sequence, but DER also has lots of control information in it as well). It then extracts the bytes representing R and S from the DER sequence, concatenating them into a single byte string as described by the above RFC. It's basically a really basic DER parser, designed only for a very specific ASN.1 sequence.

5 Likes