The WebCrypto API
The World Wide Web Consortium (W3C) is developing a JavaScript API that encompasses a number of useful cryptographic operations for use in situations ranging from signature verification to end-to-end data encryption. Called the Web Cryptography API (or WebCrypto for short), the standard is currently at "Last Call" working draft status with the Web Cryptography Working Group. There are a few lingering issues that may still result in some changes before the API advances to the next stage in the W3C recommendation process, but WebCrypto also faces fundamental criticisms; for instance, that it does not specify those elements on which users actually need standardization—namely, algorithms. And there is always the concern that such an API is risky because the security functions it offers may be inherently untrustable in precisely those scenarios where they are most needed.
The most recent draft of WebCrypto is available in raw form from the W3C version control system. This version reflects some changes since the Last Call was was made on March 25. The Last Call resulted in a number of new issues being created; at this point the working group appears to be aiming at resolving all of those by the middle of July.
The WebCrypto draft begins by setting out its anticipated use cases, most of which are standard web application concerns: client-to-server authentication, sending and storing encrypted files (including those encrypted by the server and those encrypted on the client side), plus making and checking digital signatures. These standard operations are the type of functions that web applications already implement, but with each implementor reinventing the wheel in its own JavaScript code. If browsers offer key generation, signature checking, and data encryption, the thinking goes, there will less duplication of effort and (hopefully) higher-quality code.
Derived from its basic use cases, the draft defines four main APIs and an algorithm dictionary that, together, address the essential cryptographic primitives needed by those use cases. The APIs are RandomSource, which exposes a cryptographically strong pseudorandom number generator (PRNG); CryptoKey, which is an abstraction covering various types of cryptographic keys (including public, private, and shared secret keys, of a variety of algorithms); SubtleCrypto, which is the low-level API for accessing functionality like encryption, decryption, key generation, hash generation, and verification; and WorkerCrypto, which is the interface for Web Worker background scripts. A higher-level Crypto API is also defined, which wraps together SubtleCrypto and RandomSource. The Algorithm dictionary stores the list of supported algorithms available in the browser for various functions.
From an interface standpoint, tracking the keys on the system is a relatively straightforward affair. Each public/private key pair, for instance, is represented by a pair of CryptoKey objects and an entry in the CryptoKeyPair dictionary indicating that the two go together. The specification allows each key to be designated for certain operations (e.g., encryption, decryption, signatures, verification). There is also a boolean attribute, extractable, that allows the user agent to designate that the key's raw material may be exported (for example, to back up the key elsewhere, perhaps even offline).
In contrast, the SubtleCrypto interface occupies the larger portion of the specification, encompassing a dozen operations. But even these "low-level" cryptographic methods ultimately fall back on the underlying algorithms for meaning; after all, calling the digest() method to check the integrity of a block of data is risky if one specifies a broken hash function (like SHA-1) as a parameter. Therein lies the source of many of the complaints about WebCrypto: the working group is explicitly not setting out to recommend a set of safe, reliable algorithms to use. Rather, it is attempting to define an API for calling and working with those algorithms.
As a result, WebCrypto includes a sizable list of algorithm descriptions, but none of them are mandatory to implement. Worse yet, according to some critics, the specification does not provide implementors with guidelines as to what options and parameters are safe to use. There are, for instance, known practical attacks [PDF] against some older algorithms such as RSA PKCS#1 v1.5. WebCrypto includes RSA PKCS#1 v1.5 in its list of supported algorithms, even including a basic mapping of the algorithm onto WebCrypto's methods and attributes.
Several working group members also expressed dissatisfaction at the absence of some newer algorithms, such as Daniel J. Bernstein's Curve25519. But WebCrypto co-editor Ryan Sleevi argues that the specification's role should be limited to describing the functionality that is already available in web browsers, rather than blessing algorithms that, while mathematically desirable, have yet to be implemented.
Curve25519, he notes, is not something that a web application developer can count on being available:
As noted, the cryptographic libraries of two major implementors are presently tied to major OS releases. The two cryptographic libraries in use by the other implementors (NSS and OpenSSL) equally lack implementations of Curve25519.
There is no specification of Curve25519. The IETF has made talks of it, but has yet to actually make headway. It is simply "The code speaks for itself". While there are many implementations of Curve25519, for different platforms, they are all based on the same djb initial code and still re-use aspects of it.
Of course, deciding on a suite of recommended cryptographic algorithms would be a difficult task for any standards body, since it is difficult to agree on what constitutes "safe" algorithms and parameters. For instance, when the Edward Snowden leaks demonstrated that the Dual_EC_DRBG PRNG from the National Institute of Standards and Technology (NIST) had been compromised with an NSA backdoor, some felt that other NIST recommendations, such as its elliptic curves, were surely compromised as well. But that has yet to be proven.
At present, the working group seems ready to compromise on the Curve25519 issue by drafting a complementary specification that describes Curve25519 (as well as another option promoted by Microsoft, known as the "MSR" curves) that could later be merged into an update to WebCrypto. That approach would allow the current WebCrypto specification to continue its progress through the W3C recommendation process.
There are, however, also lingering criticisms of WebCrypto that take issue with a more fundamental facet of the specification: the fact that it describes cryptography that will ultimately be implemented in JavaScript. As Tony Arcieri put it in a blog post, "the convenience of the web stems from the fact it’s a frictionless application delivery platform. Unfortunately, it does not rely on a comprehensive cryptographically secure signature system to determine content is authentic, but instead just trusts whatever is sitting around on the server at the time you access it.
"
In other words, web-based cryptography should not be trusted to protect the user's interests. It may be useful for web application developers, but the browser is not a trustworthy execution environment for end-to-end encryption of users' secrets. While there are valid uses for WebCrypto, Arcieri says, he fears that it will also be used to implement applications that ostensibly protect the user's data. For instance, he notes the possibility of secure-storage services akin to MEGA, which advertise features like cryptographically secure cloud storage, but are in actuality susceptible to multiple attack vectors.
One might answer Arcieri's charge by pointing out that services like MEGA exist already, and that existing services simply implement their own encryption stack rather than relying on a standard, hopefully well-vetted API. But the underlying concern remains: application code that is delivered to the browser over the web should not be treated with the same level of trust as locally installed and verified packages. A web application that uses the WebCrypto APIs may indeed be free from man-in-the-middle attackers; the risk is simply that the user cannot know one way or other for certain. Regardless of the algorithms employed, that lack of verification places an upper bound on how much trust should be extended.
[Thanks to Paul Wise.]
| Index entries for this article | |
|---|---|
| Security | Cryptography |
| Security | Web |
