0

I am building an app with sveltekit and I have decided to implement passkeys as a form of authentication.

So, I started researching about them and found out that in their foundation is the concept of an asymmetric key-pair (a client-side only private key that signs, and a public key stored on the server that verifies a “challenge”).

I became interested in the private key because I wanted to use it to encrypt some other data and experiment with it a bit on the client. However, after searching online and asking Claude AI it seems that it is impossible to get the private key…

So, as I mentioned my webapp is being built in SvelteKit, moreover I am using simplewebauthn/server and simplewebauthn/browser to implement the passkey authentication in my app. So is there any way I can get access to the private key as an in memory variable after calling await startRegistration(options) or await startAuthentication(options)?

Here is the code I want to work (registration example):

async function handlePasskeyRegistration() {
    const optionsResponse = await fetch(endpoint,init);
    const options = (await optionsResponse.json()).options
    const result = await startRegistration(options)
    const privateKey = somehowGetPrivateKey()
    console.log(privateKey)
}
6
  • Where do you expect the client to get the private key from? Like, how exactly do you envision your authentication workflow looking in your application?
    – Pointy
    Commented Jul 23 at 14:33
  • @Pointy Well authentication isn’t a problem here at all. The “authenticator” will provide authentication by generating a public and private key after the user provides a YubiKey or some biometric or a PIN. The public key then will be sent to the server and the private stays… with the “authenticator” I guess? I guess I need the “authenticator” to give me the private key? Like I have shown in the post I want to log it.
    – standard
    Commented Jul 23 at 14:51
  • I still don't see how that makes sense. How does the server know the public key? Sending the public key from the client is clearly not an authentication solution. The way PK authentication is supposed to work is that the server has the entity public key associated with the server-side account, so that the private key can sign a challenge to verify identity.
    – Pointy
    Commented Jul 23 at 14:52
  • Look, the above code I wrote doesn’t include that but usually what you do after getting the “result” from awaiting the “startRegistration()” function is verifying the registration. So below the start registration function you have to fetch an api endpoint and send the “result” which is of type “RegistrationResponseJSON” which includes the public key and the credential id and some other data. Basically, after registering you literally send the public key to the server and store it in a DB or something. But that is not the original question, I want to get the private key from the authenticator.
    – standard
    Commented Jul 23 at 15:02
  • 2
    In asymmetric crypto, private keys can be used for two purposes: signing data, and decrypting data. Public keys are used for verifying and encryption. Usually, when someone on SO says they want to encrypt something with a private key, they usually mean that they want to sign something, or that they're confused. Commented Jul 23 at 16:22

1 Answer 1

0

A passkey's private key is, as the name states, private, and is not accessible to relying parties.

WebAuthn is an API for authenticating a user. Raw signatures are not currently possible, although there are some proposals to add this capability. You can derive secrets using the PRF extension for some encryption use cases, but please keep in mind that this is brittle and can have a big blast radius if a user deletes a passkey.

4
  • From my understanding the RP is the server, right? I did not say that I want to use the private key on the server, I want to access it on the client during “startAuthentication()” or “startRegistration()”. I have researched about the PRF extension and I think? thats what I need. However, I don’t know if “simplewebauthn” supports this or not because there is no mention of it in their docs. simplewebauthn-docs
    – standard
    Commented Jul 25 at 12:39
  • In essence I need a private, unique and immutable 32 bytes which I can use as the secret in an AES-GCM function and my original post was about somehow getting access to the private key the authenticator generates.
    – standard
    Commented Jul 25 at 12:40
  • I am not sure why the key generated by the authenticator is that important, in the end it is just random bytes. The bytes aren't gonna be more secure in and of themselves, so you can just generate any key really. The key to the key is that the RNG is secure. It is also less secure if you start using the same key in multiple systems as suddenly someone can attack multiple places to get it, instead of just one. A big benefit of asymmetric crypto is that you never have to show anyone your private key and transferring it multiple places increases the amount of places someone might see it.
    – Asthor
    Commented Jul 25 at 13:45
  • I absolutely agree. I do not want to transfer the private key anywhere, as I stated in the comment above I just need a secret key which is private, immutable and unique. Although, I failed to mention it has to be somehow tied to a passkey beacuse of the way I am implementing my encryption. The reason I created my original post is because the first thing that came to mind with those properties is the passkey’s private key so I asked is there a way I can get access to it… If the answer is just “no”, then ok I will try other things, for example the PRF extension Tim mentioned in his answer.
    – standard
    Commented Jul 25 at 14:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.