Git as Cryptographically Tamperproof File Archive using Chained RFC3161 Timestamps
By: Matthias Bühlmann
Tags: Cybersecurity, Cryptography, Git, Software Engineering, Blockchain

There are situations in which you either want — or are required — to store data in a way that allows to unequivocally prove when exactly this data has been stored or altered.

In this article I will explain what RFC3161 timestamps are and what problem they solve, and will then go on to explain why Git™ provides the perfect architecture to be used together with such timestamps in order to create a tamperproof data repository that can provide the following properties:

Authenticity: trusted, non-refutable time when data was added or changed

Integrity: protection of the timestamped data as well as the timestamps themselves from tampering without detection

Timeliness: proof that the time of digital signatures on data was in fact the actual time

An evidentiary trail of authenticity for legal sufficiency

RFC3161

RFC3161 (and its extension RFC5816) is an internet standard that defines protocols and data formats for the issuance of trusted timestamps in a public key infrastructure (PKI).

In particular, it defines a Timestamping Authority (TSA), which is a trusted third party server, from which clients can request Timestamping Tokens (TST) for data for which they want to be able to proof that it existed at a certain point in time and that it has not been changed ever since.

A timestamp token is a CMS ContentInfo object, which contains the data hash plus the timestamp (as determined by the TSA) and is signed using the private key of the TSA certificate.

Since only the hash (aka. digest) of the data is sent to the TSA, the data itself remains secret, yet it is now possible for the client to prove to anyone who trusts this particular TSA, that the data existed at the time certified by the timestamp and that it has not been tampered with ever since.

RFC3161 tokens therefore can be used to create an unequivocal proof that for example deadlines were met, that unpublished intellectual property already existed before a certain date, that some transactions took place before others, that a photograph has been taken before some event or that business records have been digitally archived at a specific time and have not been altered since.

RFC5816 is a minor extension to RFC3161. All it does is to extend the way how the token identifies the TSA certificate. In RFC3161 this is always done using the SHA1 hash of the DER encoded TSA certificate. In RFC5816 that hash algorithm can be arbitrarily chosen. It’s important to note that this is NOT the hashing algorithm used for the timestamped hash (for this purpose, SHA1 should not be considered secure enough anymore), but only the hash of the TSA certificate in order to identify it. Since any secondary pre-image certificate would need to be signed by a trusted CA as well, the crippling security of SHA1 does not open a viable attack vector there and thus RFC5816 merely generalizes the specification to not depend on any particular hashing algorithm.

Here are a couple of public TSA providers:

Example: PDF

There are defined standards (such as the PDF specification itself as well as restrictions and extensions defined in PAdES) as to how digital signatures (and timestamps) can be embedded into the PDF container format.

If a PDF document is digitally signed using a private key that has been issued by a trusted Certificate Authority (CA), then one can be sure that the document has indeed been signed by the entity indicated in the signature.

Adobe Reader will verify that the embedded signature matches the data of the PDF and display the signature properties:

It’s important to note that while the signature does include a timestamp and the document has provably not been altered after that signature has been applied, one can not trust that the indicated Signing Time indeed is the time when the signature was created. This is because the signing entity can freely choose the timestamp that should be indicated in the signature. Adobe Reader points out this fact by saying “Signing time is from the clock on the signer’s computer”.

This is where RFC3161 token come into play. By calculating a secure hash of the document including the applied signature, sending that hash to a trusted TSA and then embedding the received token into the PDF, there is now an authentic timestamp that can be trusted (so long as one trusts the issuing TSA):

Now Adobe Reader indicates that there is a trusted timestamp embedded, and the certificate this timestamp was signed with can be further checked to decide whether the TSA that issued this timestamp should be trusted or not.

For How Long Does an RFC3161 Timestamp Remain Valid?

Generally speaking, an RFC3161 Timestamp can be considered an authentic proof that the timestamped data existied at the indicated time, so long as the following conditions hold:

One trusts the TSA that issued the token (or any entity higher up in the trust chain of the TSA certificate)

The hash contained in the signed part of the token matches the hash of the timestamped data

The hashing algorithm used is still considered secure (for example, SHA1 should not be considered secure anymore, especially for timestamping purposes)

The private key of the TSA certificate (or any entity higher up in the trust chain) did not get compromised

The last point is critical:

While a timestamp can be considered valid long beyond the expiration date of the TSA certificate that signed it, if that signing cetificate gets compromised at any point, all signed token cannot be trusted anymore and lose their validity, including all token already issued (that is, if they haven’t been additionally protected, see below).

This in turn means that one can only trust a timestamp token for as long as one can check the revocation status of the TSA certificate (which, if revoked, must contain the reasonCode extension and be one of four defined ‘acceptable’ reasons of revocation defined in chapter 4.1 of the RFC3161 specification). If the TSA ceases to exist or its CA otherwise stops to publish the certificate revocation status (in the form of CRLs or OCSPs), one can not trust the issued timestamp anymore.

So, for how long beyond the expiration date of a TSA certificate will the CA provide revocation status? That depends on the TSA.

For example, the four nationally recognized issuers of certification services in Switzerland (Swisscom AG, QuoVadis Trustlink Schweiz AG, SwissSign AG as well as Bundesamt für Informatik und Telekommunikation), which are also certified to act as Qualified Timestamping Authorities (QTSA), are required by Swiss law (Art.9 Abs.3 VZertES) to provide revocation status of these TSA certificates for at least 11 years beyond the expiration of each respective TSA certificate.

But this of course is a legislative solution to the problem, not a technological one. What happens after these 11 years? What if the TSA you want to use is not bound by similar laws? What if the government is overthrown tomorrow and with it all its laws? What good does it do to add a cryptographically secure, trusted timestamp to your data if you can’t rely on being able to prove its authenticity in a couple of years from now?

The technological answer to this problem is called Long Term Validation.

LTV: Long Term Validation

There are different flavors of LTV in different cryptographic standards, but the general idea is the following:

A digital PKI signature can only be considered valid for as long as the certificate that was used to create it is valid. If the signing certificate expires or gets revoked, the signature becomes invalid (since it’s possible that the certificate got compromised and now anyone in possession of the private key could forge the signature).

However, if one “LTV enables” the signature by retrieving a proof of validity for that signature while it is still considered valid, and then timestamps the signature together with that proof using a trusted timestamp, the signature can be considered authentic for as long as the timestamp can be trusted, even if the signing certificate expires or gets revoked at a later date.

By embedding LTV data — in particular the entire certificate chain plus a currently valid CRL or OCSP response for the signing certificate — into a PDF BEFORE timestamping it, the signature becomes “LTV enabled”:

It’s important to note that the signature’s lifetime however is only extended to the lifetime of the timestamp token. If the token loses its validity and the signature is past its expiration, then the signature won’t be valid anymore either.

So, How Does One LTV Enable a Timestamp?

Answer: By timestamping it.

If one has a document with a timestamp token that is currently considered valid, retrieves proof of the timestamp’s validity (in the form of currently valid CRLs or OCSPs for the TSA certificate and its trust chain) and then timestamps the document (or even just the older timestamp token itself) together with that LTV data using a new timestamp token, then that older timestamp’s lifetime gets extended to whatever the lifetime of this new timestamp is.

If both timestamp token are signed by the same TSA certificate, nothing is gained. However, since TSA’s change their signing certificate every now and then, or a different TSA can be used for the new timestamp, the old timestamp gets protected from becoming invalid once it is timestamped with a new trusted timestamp that is signed by a different TSA certificate, meaning that even if the private key of that older timestamp’s TSA certificate would leak, it could still be trusted so long as the newer timestamp can be trusted (which, as you probably see, becomes a transitive property).

So the answer is to timestamp again (wile also including LTV data for the older timestamp) so long as it is still valid.

This can become very cumbersome however if one has thousands of documents that would all need to be individually timestamped again now and then just to keep them validatable. Also, while such a document has provably existed already at the timestamped time and has not been tampered with since, it’s still possible to “lose” that timestamped document (so timestamping in that manner doesn’t really prevent the unnoticed removal of data if it happens in chunks of entire documents).

The solution to this logistics challenge is to use a Merkle tree.

Merkle Tree

A Merkle tree is a tree structure (not necessirly a binary tree as in the graphic below) where each node is labeled with a hash that is derived from the hashes of its child nodes.

It is possible to timestamp multiple documents with a single timestamp by creating a Merkle tree of the documents hashes.

For example, if L1-L4 are different documents and one retrieves now a timestamp for the Top Hash, this timestamp can now be used to proof the existence of all 4 documents at the time of the timestamp. It also means that the timestamp proves that no documents have been removed from the archive.

Some care must be given to how the hash values are generated in order to not allow for a second pre-image attack on the structure, but if this is done, an arbitrary amount of documents can be securely timestamped with a single trusted timestamp, which also means that only a single timestamp must be re-stamped now and then to extend its lifetime, which is a lot less cumbersome than re-stamping every document in a huge archive individually.

Leveraging Git’s Merkle Tree Design

Finally we get to the point of this article: Git

Understanding the significance of Merkle trees for timestamps makes it clear why Git is the perfect candidate for a timestamped, tamperproof data archive, because a Git repository is inherently designed as a Merkle-tree-like structure where version hashes depend on ALL data and ALL previous changes to that data.

Originally, Git hasn’t been designed as a full fledged SCM system, but the focus was more on creating a revisioned filesystem in which all data that is put into it would be bit-perfectly preserved, and not a single bit could flip unnoticed.

In many ways you can just see git as a filesystem - it’s content-addressable, and it has a notion of versioning, but I really really designed it coming at the problem from the viewpoint of a _filesystem_ person (hey, kernels is what I do), and I actually have absolutely _zero_ interest in creating a traditional SCM system. -- Linus Torvalds

That’s also why the command git fsck is called that way, fsck being the UNIX system tool for filesystem check. Git implements a revisioned filesystem, in which its merkle tree structure allows the detection of any bitflip in any revision of the data.

The Git history is stored in such a way that the ID/hash of a particular version (a commit in Git terms) depends upon the complete development history leading up to that commit. Once it is published, it is not possible to change the old versions without it being noticed. The structure is similar to a Merkle tree, but with additional data at the nodes as well as the leaves.

The property that not a single bit in the stored data (or the history of the changes to that data) can be changed without completely altering all subsequent commit hashes is exactly the property that makes it interesting for a timestamped data archive.

Instead of (or in addition to) publishing the data by pushing it to a public repository, we can retrieve an RFC3161 token from a trusted TSA to timestamp a commit hash and then store that token in the Git repository.

If we additionally also retrieve LTV data for the previous timestamp and add it to a commit before calculating the hash for the new timestamp, this iteratively extends the lifetime of timestamps arbitrarily into the future, meaning that as long as a new timestamped commit is added to the repository while the last timestamp can still be validated (which is usually for many years after it was issued), all older timestamps’ lifetime get extended to the lifetime of the new timestamp token.

By using more than one trusted TSA, it’s also possible to protect the repository against the eventuality of the newest timestamps becoming invalid (in the unlikely case that the TSA’s private key should leak and the certificate get revoked).

The timestamp token can be directly embedded in commit messages using PEM encoding . LTV data could also be embedded in the commit message, but since this data usually does not change that often, it is better to commit the LTV data as revisioned files into the repository and reference them from the commit.

The following schematic visualizes the Merkle tree stucture of the Git repository and shows how the timestamping data can be embedded: