Over plain HTTP, every request except status and challenge is signed with the key. The key itself never travels.
How to sign
- Get a challenge and add it to the request as
c=. - Send the content, and while sending it compute HMAC-SHA256 (RFC 2104 with SHA-256) with the key over the signed text below.
- After the content, send the signature as 64 lowercase hexadecimal digits.
Content-Lengthis thereforeSIZE+ 64.
8tml-publish/1 LF
OP LF
ID LF
CHALLENGE LF
NAME LF
SIZE LF
CONTENT
LF is byte 10. NAME is empty for list. SIZE is the content’s length in decimal without leading zeros (0 when there is no content). CONTENT is the file’s bytes exactly as sent.
The endpoint checks the challenge and uses it up, checks that the body is SIZE + 64 bytes long, computes the same HMAC with its copy of the key and compares the two in constant time. Only then does it carry out the operation.
What it protects
- The key never travels.
- A request can’t be sent again by someone else: each challenge works once.
- Nobody on the way can change the content or the parameters without the signature failing.
- The content is not encrypted: anyone on the way can read it. Pages are public anyway.
On 8-bit machines
- Because the signature comes after the content, the client hashes each byte as it sends it. It needs no second pass and no copy of the content.
- The hash states after the key blocks (key XOR
ipadand key XORopad) can be computed once per key and reused for every request. - SHA-256 in 6502 assembly takes about 81,000-95,000 cycles per 64 bytes, about 1.3 seconds per kilobyte at 1 MHz. That keeps up with a 9600-baud connection; on faster ones it adds that much time.
- A client that can’t sign can publish over HTTPS through a proxy instead.
Test vector
Key 000102...1f (the bytes 0 to 31), id test-1, challenge 00112233445566778899aabbccddeeff:
putofindex.8tmlwith the 24 bytes---LF8tml: 1LF---LF# HelloLF givesf61702e908e31462519ef7a1a89b5fa9b723524deb5e7d20806dbc5a257e62dblistgives91b810d221b4176e501565e1fb910f1cba860000a74e6fc5d6db218d6166d512
Example
A client replaces news.8tml (1874 bytes) over plain HTTP:
POST /publish?op=challenge&id=anna-1 HTTP/1.0
Host: example.com
Content-Length: 0
HTTP/1.0 200 OK
Content-Type: text/plain; charset=us-ascii
status: ok
challenge: 9b1c0e5d2f7a4468b03e51c6d8a7f210
expires: 120
POST /publish?op=put&id=anna-1&name=news.8tml&size=1874&c=9b1c0e5d2f7a4468b03e51c6d8a7f210 HTTP/1.0
Host: example.com
Content-Length: 1938
(1874 bytes of news.8tml)(64-digit signature)
HTTP/1.0 200 OK
Content-Type: text/plain; charset=us-ascii
status: ok
name: news.8tml
size: 1874
url: http://example.com/news.8tml