Discover WebAuthn's use of asymetric encryption algorithms and pubKeyCredParams in passkey auth and the role of credentialPublicKey, CBOR and COSE.
Vincent
Created: May 2, 2024
Updated: August 19, 2024
Our mission is to make the Internet a safer place, and the new login standard passkeys provides a superior solution to achieve that. That's why we want to help you understand passkeys and its characteristics better.
2.1 How Does Public-Key Cryptography Work?
2.2 Common Types of Public-Key Cryptography Algorithms
2.3 Increasing Adoption of ECC-based Public Cryptography
4.1 Which COSE Algorithms are Relevant for WebAuthn?
4.2 Defining pubKeyCredParams-Array in pubKeyCredParams
5.1 Overview: What is the attestationObject?
5.2 What is Concise Binary Object Representation (CBOR)?
5.4 Decoding and Parsing the attestationObject
In digital security, passkeys are the new passwordless standard. At the heart of passkeys lies public-key cryptography, utilized within the WebAuthn protocol on which passkeys are based. Understanding how public-key cryptography is used in WebAuthn, particularly in creating, extracting, managing and storing passkeys, is crucial when designing or using passkey authentication. The public key is stored on the server of the relying party (RP), which is the backend of the website that wants to authenticate a user via passkeys, and the private key is securely stored in a Hardware Security Module depending on the operating system Secure Enclave (iOS), TEE (Android) or a TPM (Windows).
In this blog post, we will go quickly over the basics of public-key cryptography used in passkeys. The following questions should be answered by the end of the blog post:
To understand how public-key cryptography works within WebAuthn, we will take a quick look into how it works in general and what the common types of algorithms are.
Recent Articles
📖
WebAuthn Cross-Device-Authentication: Passkeys via Mobile-First Strategy
📖
WebAuthn User ID, User Handle, User Name and Credential ID
⚙️
Passkeys E2E Playwright Testing via WebAuthn Virtual Authenticator
📖
WebAuthn Passkey QR Codes & Bluetooth: Hybrid Transport
📖
WebAuthn Relying Party ID (rpID) & Passkeys: Domains & Native Apps
Public-key cryptography, also known as asymmetric cryptography, stands in contrast to symmetric cryptography where the same key is used for both encryption and decryption. Asymmetric cryptography employs two distinct keys – a public key, which can be shared openly, and a private key, which is kept secret by the owner.
Taken from: https://en.wikipedia.org/wiki/Public-key_cryptography
This method enables not only the encryption of data to secure its confidentiality but also allows to sign messages. Signing verifies the sender's identity and ensures that the message has not been tampered with, thereby confirming its authenticity and integrity.
Subscribe to our Passkeys Substack for the latest news, insights and strategies.
SubscribeHere's an overview of some common types of algorithms used in public key cryptography:
Category | RSA | DSA | ECDSA | EdDSA |
---|---|---|---|---|
Invention Date | 1977 | 1991 | 1999 | 2011 |
Algorithm Type | Asymmetric public key cryptography | Digital signature algorithm | Elliptic curve digital signature | Edwards-curve digital signature |
Main Use | Secure data transmission | Signing electronic documents | Secure transactions & signatures | Secure transactions & signatures |
Comon Key Sizes | 1024 to 15360 bits | 1024 to 3072 bits | 160 to 512 bits | 256 bits |
Performance | Slower due to large key size | Faster than RSA for signing | Faster computations with small keys | Optimized for speed and security |
Popularity | Widely used historically | Less common than RSA | Increasingly popular | Gaining popularity quickly |
Efficiency for mobile devices | Less efficient on mobile | Moderately efficient | High efficiency on mobile devices | Maximum efficiency |
Storage Requirements for Keys | High due to large key sizes | Moderate | Low storage space required | Minimal storage needs |
Battery Usage | Higher consumption | Moderate consumption | Lower power consumption | Optimal for battery preservation |
Suitability for Mobile | Less suitable due to size and power | Moderately suitable | Highly suitable | Highly suitable |
Adoption in Stand | Widely adopted (TLS, SSH) | Less widely adopted | Widely adopted in modern protocols (TLS, SSH) | Gaining adoption in newer protocols (TLS, SSH) |
Resistance to Future Threats | Vulnerable to quantum attacks | Vulnerable to quantum attacks | Potentially resistant to quantum attacks | Potentially resistant to quantum attacks |
Versatility | High versatility across platforms | Limited to specific use cases | High versatility | High versatility |
Patent Status | Not under patent | Not under patent | Not under patent | Not under patent |
The mathematical foundation of elliptic curve cryptography (ECC), including ECDSA and EdDSA, involves the properties of elliptic curves which we will not cover in this article. But it is obvious from the table above, that there are advantages that drive their adoption. We will go through the most important ones in the next section.
Become part of our Passkeys Community for updates and support.
JoinElliptic curve cryptography has been widely adopted for mobile devices as they benefit from the smaller key sizes, which brings the following advantages:
Security Level (bits) | RSA Key Size (bits) | ECDSA/EdDSA Key Size (bits) |
---|---|---|
80 | 1024 | 160-223 |
112 | 2048 | 224-255 |
128 | 3072 | 256-383 |
256 | 15360 | 512+ |
The term security level in this context refers to the strength of the cryptographic system, specifically the level of difficulty for an attacker to defeat the security measures. It is generally measured in bits and represents the amount of work (the number of operations) that would be required to break the encryption or forge a signature. With increasing security level, the size advantages become obvious up to key ratio sizes of 1:30.
Algorithm | Key Size | Sign-Operation | Sign/s |
---|---|---|---|
RSA | 2048 | 0.001012s | 987 |
ECDSA | 256 | 0.000046s | 21565 (x20) |
These factors make ECC particularly suitable for mobile environments, where the optimization of storage, processing speed, and power consumption is essential. As a result, ECC is increasingly favored in mobile computing for its ability to provide robust security without compromising device performance. Nevertheless, up to today a lot of older versions of widespread protocols like TLS (used for HTTPS, FTPS or SMTPS), SSH or IPsec exist that still support RSA but have started to offer ECC-based variants to clients that support them.
The WebAuthn standard is not an encryption standard, but rather a security protocol that provides strong, public-key-based authentication for web applications, enabling users to log in using biometrics, mobile devices, or hardware security keys (e.g. YubiKeys) instead of passwords. Therefore, WebAuthn is intentionally agnostic which underlying which public-key based cryptography is actually used, let’s take a look how this is accomplished.
The WebAuthn security protocol facilitates the cryptographic secure authentication between the User and the Relying Party. In technical terms this means that the Relying Party (a website that wants to use passkeys with its users) needs to exchange keys over the browser with the user and his authenticator which then stores the private key in the specific hardware security module (HSM).
For sign-up / registration of passkeys, there are three important steps:
PublicKeyCredentialCreationOptions.pubKeyCredParams
together with the other PublicKeyCredentialCreationOptions
.pubKeyCredParams
list
for encryption algorithms that it supports and creates a key-pair alongside with a unique Credential ID. It stores the
private key within the HSM and then returns the public-key and the used encryption-algorithm to the browser. Then, the
browser sends a POST request to the Relying Party backend with the attestationObject in the “authData” section. In
case there is no match of the supported encryption algorithms, the create ceremony will fail.attestationObject
from
the browser. It parses the authData.credentialPublicKey
section and extracts the public-key. Together with the
public-key also information about the used encryption algorithm and the Credential ID is sent back to the relying
party.For subsequent login / authentication with passkeys, the following steps are necessary (details simplified):
By looking at both cases, we can see that only for sign-up / registration of passkeys public-key and encryption algorithm information are transported between the actors.
For subsequent login / authentication events with passkeys, only the challenge and the signature are part of the transmitted data.
The WebAuthn standard uses the IANA COSE Algorithm IDs to identify the encryption algorithms used. The COSE Algorithm IDs are both used for signaling the supported algorithms in pubKeyCredParams and to transmit the actually created key-pair type in credentialPublicKey. We will focus on their implementation in the next two sections.
The COSE Algorithms list of IANA includes over 75 algorithms that could theoretically be used with the WebAuthn Standard. Most of the algorithms with negative ID are asymmetric public-key and most of the positive symmetric, but this is rather a convention as there are exceptions to that
As we have pointed out before, the encryption algorithm needs to be supported by the Authenticator and the Relying Party backend in order be used in the WebAuthn ceremony. As most relying parties use existing WebAuthn libraries that have access to a wide range of encryption algorithms, it is more important to look at which algorithms are supported by which authenticators:
Name | ID | Description | Apple | Android | Windows 10 | Windows 11+ | Security keys |
---|---|---|---|---|---|---|---|
RS256 | -257 | RSASSA-PKCS1-v1_5 using SHA-256 | ❌ | ❌ | ✅ | ✅ | ✅ |
EdDSA | -8 | EdDSA | ❌ | ❌ | ❌ | ❌ | ✅ (*) |
ES256 | -7 | ECDSA w/ SHA-256 (also known as NIST P-256) | ✅ | ✅ | ❌ | ✅ | ✅ |
(*) = Small portion of security keys (e.g. Yubikeys 5+, Solokey or Nitrokey)
Excerpt from IANA Table: See full list here
As you can see from this table, to support all important authenticators RS256 and ES256 are sufficient. There are some parts of the community that recommend integrating also EdDSA to further improve security. On the other side, the Credential IDs that also need to be stored seem to be significantly longer for EdDSA keys. As of today, the W3C Editor’s draft on the upcoming Level 3 WebAuthn Standard suggest all three algorithms.
Configuring the supported encryption algorithms for the passkey creation is done via the PublicKeyCredentialCreationOptions
:
The example shows how the algorithms are specified within: pubKeyCredParams by alg
for the ID and adding public-key
as type of the algorithm. In line 29/30, the PublicKeyCredentialCreationOptions are passed to the authenticator via the
WebAuthn API of the browser. Removing support for ES256 or RS256 will produce errors and is strictly not recommended.
As a working example, we will run the following PublicKeyCredentialCreationOptions
on a Mac in the Passkeys Debugger.
The response produced by the authenticator is sent to the relying party (as attestation) and looks like:
In the next session, we will see how the public keys and the used encryption algorithm can be extracted from the response.
First of all, we need to examine how the actual attestationObject
is constructed, because as we see above it is not
transported in JSON to the Relying Party.
The attestationObject plays an important role in the WebAuthn registration process, serving as a container for the attestation statement provided by the authenticator. This object provides a lot of information necessary for the Relying Party (RP) to verify the origin and integrity of the newly created public key credential.
At its core, the attestationObject is a complex structure. It is mostly encoded in CBOR (Concise Binary Object Representation) format, which then at the end is encoded with Base64URL encoding. It encapsulates the authenticator data along with an attestation statement that verifies the information's authenticity. Because passkeys are created with attestation “none” and therefore do not carry an attestation statement, we will not cover this in this article. As a side note: We wrote mostly CBOR because there are also non-standard CBOR prefixes involved due to the variable lengths that are needed for the optional extensions. We will not dive deeper into that, a discussion about the complexities can be found here.
Taken from the WebAuthn specification
Within the authenticator data (authData), the newly generated public key, alongside user’s credential ID, are securely stored and can be retrieved by the relying party. As developers must approach the task of extracting the public key from the attestationObject in any WebAuthn-based system, understanding its architecture is important.
CBOR (Concise Binary Object Representation) is a data format designed to encode data in a compact, efficient, and extensible manner. It is binary, which makes it smaller and faster to parse than its text-based role-model JSON. The following example illustrates how JSON and CBOR are different (Text vs. Binary):
JSON Text | CBOR Binary Data | CBOR decoded |
---|---|---|
{Name:Corbado} | A1 64 4E 61 6D 65 67 43 6F 72 62 61 64 6F | A1 # map(1) with one entry 64 # text(4) 4E616D65 # Name; 67 # text(7) 436F726261646F # Corbado |
Bold is Name. Italic is Corbado. (more information can be found on https://cbor.io/)
In the context of WebAuthn, CBOR is used for several reasons:
The use of CBOR is especially fitting for encoding the public keys and the attestationObject because it needs to handle the different formats and lengths we discussed above. For instance, an RSA key would have different attributes and sizes compared to an ECDSA key. Within the attestationObject, public keys are stored in COSE Key format, which is based on CBOR.
A COSE Key structure is built on a CBOR map object. It defines a structured way for key representation, encompassing various key types and their corresponding parameters, such as the RSA modulus and exponent, or the elliptic curve public key coordinates. This standardized format allows keys to be serialized and deserialized in a consistent manner, irrespective of their underlying cryptographic algorithm, in addition to the encryption algorithm ID we have discussed above.
By leveraging CBOR and the COSE Key format, WebAuthn can facilitate a wide range of cryptographic operations while ensuring the payload remains as small as possible, and remain adaptable for future updates in cryptographic technology. This choice aligns with the goals of WebAuthn to provide a secure, efficient, and forward-compatible protocol for web authentication.
When it comes to decoding the attestationObject within WebAuthn, developers are faced with an important decision: develop a custom solution or leverage an established library. The complexity and critical nature of this process cannot be overstated. Manual implementation of Base64URL and CBOR decoding, while technically feasible, introduces the risk of subtle errors that can compromise the integrity of the authentication process.
To ensure the cryptographic verification of the signature, as well as the accuracy of all other validation steps, it is strongly advised to utilize a well-tested and widely adopted WebAuthn library. Such libraries are built with encryption expertise to handle the details of decoding and validating the attestationObject, including:
By relying on a reputable library, developers not only save time and resources but also gain peace of mind. The public key, once extracted and verified through these reliable tools, can then be safely stored in the database, ready to be used for secure authentication sessions. This approach ensures adherence to the protocol’s specifications and maintains the security posture expected in WebAuthn implementations. For simplicity, we will use the SimpleWebauthn Debugger which returns a completely decoded version with CBOR fields being converted into exploded JSON:
The SimpleWebAuthn library is used to decode the complete attestationObject. As we can see, all information is now readable. All cryptographic information are part of credentialPublicKey which is part of the authData-part. which the library has exploded into the parsedCredentialPublicKey statement. In the specification, there are several examples how COSE Key Format looks like.
This output showcases all the cryptographic elements of the credentialPublicKey neatly parsed into human-readable form. This particular instance reveals an EC2 key for the ES256 algorithm, as indicated by the algorithm parameter and the presence of x and y coordinates.
In contrast the output of a Windows 10 system looks as follows:
Here, the algorithm ID is -257, corresponding to RS256, and we can discern that the attributes characterizing this public key diverge significantly from those of an ECDSA key. The COSE Key format allows for specifying unique attributes per type:
Attribute/Type | ECDSA | RSA |
---|---|---|
Key Type | EC2 (Elliptic Curve 2) | RSA (3) |
Algorithm | ES256 (-7) | RS256 (-257) |
Unique attributes | Curve X-coordinate Y-coordinate | Modulus Exponent |
Also, the RSA modulus is substantially longer than the elliptic curve coordinates used in the ES256 key, underscoring our previous discussion regarding the differences in key sizes and the inherent requirements of different cryptographic algorithms.
After going through the basics of public-key cryptography and understanding how it is incorporated into the WebAuthn / FIDO2 standard, we have two major recommendations for relying parties:
It's crucial not to reinvent the wheel: leverage the collective knowledge embedded within established libraries. Custom implementation risks introducing errors and security flaws that could undermine the authentication's effectiveness and the system's overall security.
In this blog post, we have investigated the basics of public-key cryptography to answer the initial three core questions:
Besides, we have highlighted the WebAuthn protocol's independence from specific encryption algorithms, which significantly enhances its flexibility and future-proofing against emerging cryptographic methods. We hope this article also helps other developers when debugging and understanding concepts / issues related to public-key cryptography in WebAuthn.
Table of Contents
Enjoyed this read?
🤝 Join our Passkeys Community
Share passkeys implementation tips and get support to free the world from passwords.
🚀 Subscribe to Substack
Get the latest news, strategies, and insights about passkeys sent straight to your inbox.
We provide UI components, SDKs and guides to help you add passkeys to your app in <1 hour
Start for free
Recent Articles
WebAuthn Conditional UI (Passkeys Autofill) Technical Explanation
Vincent - October 20, 2023
WebAuthn Relying Party ID (rpID) & Passkeys: Domains & Native Apps
Vincent - September 21, 2023
WebAuthn Resident Key: Discoverable Credentials as Passkeys
Vincent - September 28, 2023