Skip to content

Instantly share code, notes, and snippets.

Last active June 18, 2024 13:37
Show Gist options
  • Save darconeous/2cd2de11148e3a75685940158bddf933 to your computer and use it in GitHub Desktop.
Save darconeous/2cd2de11148e3a75685940158bddf933 to your computer and use it in GitHub Desktop.
Tesla Key Card Protocol

Tesla Key Card Protocol

Researched by Robert Quattlebaum

Last updated 2020-02-03.

Image of Tesla Key Card Image of Tesla Model 3 Key Fob

IMPORTANT NOTE: The information in this document does NOT enable anyone to clone official Tesla Key Cards or otherwise unlock or start a vehicle that they didn't already have the ability to unlock or start.

This document describes the current understanding of the Tesla Key Card Protocol, as used on the Tesla Model 3. This protocol was determined from observing the pairing and authentication interactions between the Tesla Key Card (TKC) and the vehicle, as well as probing the TKC with various commands to see what would happen.

The basic working subset of commands necessary to pair and authenticate are well understood and documented here. There are several other commands that we know are present, but they are not yet well understood.

The NFC protocol for the Tesla Model 3 Key Fob (TM3KF) and Tesla smartphone app (TPK) is also covered. In general, any reference to a TKC also applies to the TM3KF and TPK unless an explicit exception is noted.

The information presented here was used to implement GaussKeyCard, an open-source Java Card applet that allows you to use a supported Java Card to unlock and start vehicles in the same way that you would with an official Tesla Key Card.


ATS: Answer To Select. This is a short string of bytes that describe to the reader how to communicate with the card.

AID: Application Identifier

APDU: Application Protocol Data Unit, name for commands sent to a smart card.

CA: Certificate Authority

ECDH: Elliptic-curve Diffie–Hellman, a key-agreement protocol.

FSCI: The part of the ATS that describes the maximum supported frame size. Tesla vehicles require an FSCI value of at least 6 (96 bytes).

TPK: Tesla Phone Key (NFC, only available on Android)

TKC: Tesla Key Card

TM3KF: Tesla Model 3 Key Fob

Token: A secure device used for authentication that is resistant to cloning.

UID: Unique Identifier


When it comes to access control, there are two related but distinct concepts: identification and authentication.

Identification simply means knowing who/what you are interacting with. With NFC, the 7-byte unique identifier is often used for identification purposes since it is defined to be unique. Sometimes even the older 4-byte UID is used for this purpose.

But this identifier is easily spoofed with easy-to-obtain and inexpensive hardware. The UID alone offers no cryptographic assurances that it the authentic, original token.

Authentication is an additional step where you cryptographically verify the identity of the token in a way that only the original token could satisfy.

General Description

TKCs use 256-bit Elliptic-Curve Cryptography to authenticate to the vehicle. The specific elliptic curve being used is the NIST P-256 curve, otherwise known as secp256r1.

The specific algorithm being used to authenticate the card is a simple challenge-response using a shared key derived using Elliptic-curve Diffie–Hellman (ECDH).

When pairing a TKC to a car, the vehicle asks the card for its public key and then performs a test authentication.

While the TKC protocol does support an attestation certificate, it does not appear to currently be used. Note that the TPK does NOT have an attestation certificate.

Each Tesla Key Card has a NFC UID, which in recent vehicle firmware versions is ignored. Testing has confirmed that two TKCs with the same ECDH key but different NFC UIDs will appear to the vehicle as two separate cards. However, testing has also confirmed that two cards with different ECDH keys but the same UID will also appear as two separate cards. Thus, it would appear that the vehicle identifies each card by both its UID and ECDH key.

Note that the vehicle does not fetch the ECDH public key from the card when authenticating, so it must be comparing the response from the TKC against the expected response from all paired TKCs with the same UID. This is pretty strange, but there isn't a lot of room for alternative explanations given the observed behavior.

UPDATE: Recent versions of the vehicle firmware now fetch the public key from the card before sending the challenge, and seem to use ONLY this information for identifying a credential. This means that it is now MUCH easier to make cloned card pairs. Note that cloning an existing card remains mostly impossible, but prior to this change it was very difficult for your average hacker to make two new key cards that would work as clones (becuase it is generally difficult to arbitrarilly change the UID of a javacard). That is now no longer the case.

Important: IEEE 14443 Type-A Only

The vehicle will apparently refuse to read 14443 Type-B cards. Only Type-A cards are compatible.

Important: Max Frame Size

The vehicle will ignore the FSCI field of the ATS, which means that it will not attempt to break up larger frames if the indicated FSCI is small (<6). Specifically, the card MUST be able to properly handle receiving the authenticate command (86 bytes) in a single frame. If a card advertises an FSCI smaller than 6 then it is unlikely to be able to satisfy this requirement.

For example, smart cards with DESFire EV1 emulation support have an FSCI of 5, and will unfortunately choke if they receive a frame larger than 64 bytes. Such cards are not able to be used as Tesla Key Cards.

NOTE: In earlier versions of this document, this behavior was confused with the NFC UID length. It just happened to be the case that most of the 4-byte UID cards the author tested also had an FCI of 5. There is no limitation of the length of the UID on the card imposed by the vehicle.

Other potentially relevant details

The Tesla Key Card, as currently sold by Tesla, has the following potentially relevant properties:

  • IEEE 14443 Type A
  • UID: 7 bytes (except TPK, which may be 01020304 or a randomly selected UID starting with the value 08)
  • ATQA: 0x4800
  • SAK: 0x20
  • ATS: 057877910200
    • FSCI: 8 (256 bytes)

The secure element itself is a chip made by NXP (P60) running a Java Card OS of some sort. It is NOT a DESFire chip, it is a real secure element.

The vehicle will go through the authentication steps for TKCs it hasn't been paired with.

Application Identifier (AID)

The primary interface that the vehicle uses to pair and authenticate TKCs is the AID 7465736c614c6f676963, or teslaLogic. This is the default selected application on official TKCs.

Note that, strictly speaking, this isn't a valid ISO 7816-5 AID, since it is not registered and it doesn't start with the nibble 0xf to indicate that it is a proprietary and unregistered AID. This is likely why the vehicle actually tries to use f465736c614c6f676963 first, which is the AID for the TPK. In any case, the use of the AID 7465736c614c6f676963 is sufficiently unique that it is unlikely to cause problems in practice.

The TPK AID f465736c614c6f676963 appears to be treated the same way as its non-7816-5-compilant cousin.

The full teslaLogic AID on official TKCs is 7465736C614C6F67696330303201, or teslaLogic002 followed by the byte 0x01. 002 is assumed to be the version. On the TM3KF, the full AID is teslaLogic005 with no trailing bytes.

No FCI is returned when the application is selected on an official TKC or TM3KF. In some cases having an FCI present causes the car to reject the card. In other cases it seems to accept the card. Additional research is needed to figure out more details.

There is also a teslaStore applet (teslaStore002 for TKC, teslaStore003 for TM3KF). However, it does not appear to be selectable.

Quick-Reference APDUs

  • Select teslaLogic AID
    • Cards/Fobs: 00a404000a 7465736c614c6f676963
    • Alternate: 00a404000a f465736c614c6f676963
  • Get Public ECDH Key (secp256r1)
    • 8004000000
  • Authentication Challenge (ECDH)
    • 8011000051 [VEHICLE-PUBLIC-KEY] [16B-CHALLENGE]
  • Get Form Factor
    • 80140000
  • Get Version Info
    • 80170000
  • Self Test?
    • 80010000

Important Commands

The following proprietary (CLA=0x80) APDU instructions are used by the vehicle during authentication or pairing, or were discovered by probing:

INS 0x04: Get Public Key

Field Value Notes
CLA 0x80
INS 0x04
P1 0x00-0x03 Key Identifier
P2 0x00
Le 0x00

This command returns a public key for one of the keys in the TKC/TM3KF. The TPK currently only supports KeyID 0.

The KeyID is a number between 0 and 3. Only 0x00 appears to be currently used by the vehicle.

No other arguments are currently known.

The observed format of the response (not including success code 9000) is:

byte 1 bytes 2-33 bytes 34-65
0x04 EC Point X EC Point Y

INS 0x06: Get Certificate

Field Value Notes
CLA 0x80
INS 0x06
P1 0x00-0x04 Certificate Identifier
P2 0x00
Le 0x000000 Extended-lenth response

This command returns one of (up to) five X.509 certificates, one for each KeyID and one "root".

This command is not currently supported on the TPK. This command is not currently used by the vehicle during pairing or authentication.

On the Tesla Key Card, only two certificates are available via this command: 0x00 and 0x04. All five certificates are available on the Tesla Model 3 Key Fob. You can see examples of the certificates section at the end of this document.

Each certificate is larger than 256 bytes, so support for extended APDUs is required to get the entire certificate. Because support for chaining does not appear to be implemented and not all readers support extended APDUs, the full certificate may be impossible to extract on hardware that doesn't support extended APDUs.

The CertID is a value between 0 and 4. Values 0-3 presumably refer to KeyIDs 0-3. Typically only KeyID 0 has a certificate.

CertID TKC (teslaLogic002) TM3KF (teslaLogic005)
0x00 KeyID 0 Cert KeyID 0 Cert
0x01 Err 6F17 KeyID 1 Cert
0x02 Err 6F17 KeyID 2 Cert
0x03 Err 6F17 Fob Issuing CA
0x04 CA Fob Command CA
≥ 0x05 Err 6B00 Err

On the TKC, CertID 4 is some sort of root certificate, but doesn't appear to be the certificate that signed KeyID 0. You can see it and an example of a non-root certificate at the end of this document.

On the TKC, The first two bytes of the returned result represent the length of the certificate in bytes. There is no leading length word for the certificates on the TM3KF.

INS 0x07: Get Versions

Field Value Notes
CLA 0x80
INS 0x07
P1 0x00
P2 0x00
Le 0x00

Appears to return the version numbers for the teslaLogic and teslaStore, along with an additional version to an unknown component.

This command is not currently supported on the TPK.

The versions are encoded as three 16-bit big-endian numbers. The first corresponds with teslaLogic and the second corresponds with teslaStore. It is unclear what the third corresponds with.

1st 0x0002 0x0005
2nd 0x0002 0x0003
3nd 0x0002 0x0003

INS 0x11: Authentication Challenge

Field Value Notes
CLA 0x80
INS 0x11
P1 0x00-0x03 Key Identifier
P2 0x00
Lc 0x51 71 bytes in data field
Data 0x04 ... 65-byte NIST P.256 Vehicle Public Key
  ... 16-byte Challenge
Le 0x00

This is the command the vehicle uses to authenticate the TKC. The returned value is a 16-byte response.

The KeyID is a number between 0 and 3. Only 0x00 appears to be currently used by the vehicle. It is assumed that this field corresponds to the KeyID parameter from INS 0x04.


The 16-byte response is calculated as follows:

  1. Calculate the ECDH shared secret.
  2. Calculate the SHA-1 hash of the X parameter of the shared secret.
  3. Truncate the SHA-1 hash to the most significant 128 bits. The result is KEY.
  4. OPTIONAL: (TM3KF and TPK ONLY) The card writes over the first 4 bytes of the challenge with random values.
    • CHAL[0..3] = RANDDATA(4)
  5. Perform a single block encrypt operation on the provided 16-byte challenge.

To verify the credential, the car does the following:

  1. Calculate the ECDH shared secret.
  2. Calculate the SHA-1 hash of the X parameter of the shared secret.
  3. Truncate the SHA-1 hash to the most significant 128 bits. The result is KEY.
  4. Send a random challenge to the credential.
    • CHAL[0..15] = RANDDATA(16)
  5. Decrypt the response (RESP) when received.
  6. If the last 12 bytes of the challenge match the last 12 bytes of the decrypted response, the credential is authentic.
    • ASSERT CHAL[4..15] == CHECK[4..15]

INS 0x14: Get Form Factor

Field Value Notes
CLA 0x80
INS 0x14
P1 0x00
P2 0x00
Le 0x00

This command returns a two-byte form factor identifier. This command is always used by the vehicle after the authentication challenge response.

The value doesn't appear to currently change the behavior of the vehicle UI.

Description Return Value
Tesla Key Card (TKC) 0x0001
Tesla Key Fob (TM3KF) 0x0022
Tesla Phone Key (TPK) 0x0031

INS 0x1B: Set Vehicle Info

Field Value Notes
CLA 0x80
INS 0x1B
P1 0x00
P2 0x00
Lc 0x15 4 byte header + 17 byte VIN
Data 0x2a130a11 ASN.1 Header
  ... 17-digit VIN (ASCII)
Le No response data expected

This command is issued to the TPK after the normal pairing exchange. It is only issued at pairing. The exact purpose of this command is unknown, but the data sent from the vehicle is TLV-encoded (ASN.1?) and includes the 17-digit VIN:

2a130a11 + <ASCII-ENCODED-VIN>

[2a] {

It seems that the TPK does not actually parse this data as ASN.1: it simply ignores the first 3 bytes and assumes the fourth byte is the VIN length and that the VIN starts at byte 5. That behavior may change, though.

Other Unknown Commands

Through probing, we know the teslaLogic AID also supports the following APDU instructions, but we don't yet know what they do:

  • INS 0x00 -> Error 0x6f05
  • INS 0x01 -> Success? 0x9000 (Takes a long time to complete, possibly a self-test)
  • INS 0x02 -> Error 0x6f12
  • INS 0x03 -> Error 0x6f12
  • INS 0x05 -> Error 0x6f16
  • INS 0x08 -> Success? 0x9000
  • INS 0x12 -> Success? 0x9000
  • INS 0x13 -> Error 0x6f1b
  • INS 0x15 -> Error 0x6f1d
  • INS 0xA4 -> Success? 0x9000 (Tesla Phone Key Only)

None of the above commands (except INS 0xA4) are implemented on the TPK.

Authentication Process for TKC

  1. Vehicle attempts to select AID f465736c614c6f676963
    • TKC indicates no such AID.
  2. Vehicle attempts to select AID 7465736c614c6f676963, which succeeds.
    • TKC indicates success
  3. NEW: Vehicle requests the public key of the TKC using INS 4 APDU.
    • TKC responds with its public key.
  4. Vehicle sends INS 0x11 APDU with vehicle public key and a random challenge.
    • TKC verifies public key is on curve P-256
    • TKC calculates and returns the response to the challenge
  5. Vehicle sends INS 0x14 APDU.
    • TKC responds with the value 0x0001 and a successful response code.
  6. Vehicle repeatedly sends junk APDUs to determine when TKC is removed.

Pairing Process

  1. Steps 1-5 of the authentication process are performed, presumably to ensure the presented card isn't one that is already known.
  2. Vehicle sends INS 0x11 APDU with vehicle public key and challenge of all zeros.
    • TKC verifies public key is on curve P-256
    • TKC calculates and returns the response to the challenge
  3. Vehicle repeatedly sends junk APDUs to determine when TKC is removed.

Tesla Model 3 Key Fob Differences

The Tesla Key Fob also has an NFC interface. It kinda seems to implement the same protocol, but there are some differences:

  • INS 0x11 (Authenticate) doesn't seem to work the same way: the 16-byte response is different each time, due to it replacing the first four bytes of the challenge with random "salt". The documentation for INS 0x11 has been updated to reflect the changes.
  • Three of the four ECDH keys has a certificate. The CN of each of these certificates has a suffix indcating which KeyID they are associated with: - 0/- 1/- 2.
  • CertID3 seems to contain an intermediate CA: "Fob Issuing CA". It is independent of KeyID3, which seems to not have an associated certificate. The "Fob Issuing CA" is the issuing CA for CertID0, CertID1, and CertID2.
  • CertID4 has a different intermediate CA: "Fob Command CA". It is unclear what this certificate is for.
  • Both CertID3 and CertID4 are signed by a "Fob Root CA", which does not appear to be availble.
  • The certificates don't appear to be prefixed with a length, so heuristics will be required to read certificates in an automated way.
  • INS 0x07 returns 0005 0003 0003 instead of 0002 0002 0002 like on the TKC. This makes it seem likely that this command returns version information (TM3KF:teslaLogic005/teslaStore003 vs TKC:teslaLogic002/teslaStore002).
  • INS 0x14 (Get Form Factor) returns 0022 instead of 0001.
  • The 80ca2f00 trick yields the following AIDs:
    • A000000151000000 -> Global Platform ISD
    • 5465736C61444150 -> TeslaDAP
    • 7465736C6153746F7265303033 -> teslaStore003
    • 7465736C614C6F676963303035 -> teslaLogic005

The pairing process, despite the additional BTLE pairing, is exactly the same.

Tesla Phone Key Differences

The latest version of the Tesla App on Android provides a NFC key interface (Tesla Phone Key, or TPK), allowing you to use the phone just like a TKC. Pairing works the exact same way. The protocol implemented by the TPK is a limited subset of what is available on a TKC or TM3KF. Here are the differences:

  • INS (Authenticate) 0x11 includes random card-generated salt, just like the TM3KF.
  • Has only one ECDH key instead of four like the TKC and TM3KF.
  • There are no certificates.
  • The command INS 0x14 returns 0x0031 instead of 0x0001 or 0x0022.
  • It includes a new command, INS 0x1B, which the vehicle uses to tell the phone its VIN. This command seems to only be sent to the TPK and not the TKC or TM3KF, so it may be introspecting into the UID to gate the issuing of this command.
  • You must be logged into a Tesla account on the phone in order to use the NFC TPK functionality, so you can't use this feature to give someone access to your car unless they have a Tesla account. It is unclear what happens if you try to pair a phone with a vehicle on a different account. Command INS 0x1B implies that the phone might take notice and behave differently.
  • If you explicltly sign out of the app and then sign back in, the public key is preserved—so NFC key access to any vehicles that was lost when you signed out should be restored when you sign back in. It is unclear if this is true if you sign in with a different account, but seems likely. In other words, signing out doesn't wipe the NFC credential.
  • The vehicle was able to determine the name of the phone for its internal UI after pairing. This seems to imply either an in-band interaction that I missed or an out-of-band (BLE?) interaction. The vehicle seems to remember this sort of metadata even for deleted cards.


Tesla Key Cards/Fobs have X.509 certificates which can be retrieved via INS 0x06. Below are real examples of the certificates that were extracted from a TKC and a TM3KF:

Card Certificate

        Version: 3 (0x2)
        Serial Number: 72515 (0x11b43)
    Signature Algorithm: ecdsa-with-SHA256
        Issuer: CN=Key Card CA, O=Selp
            Not Before: Oct 11 16:48:35 2017 GMT
            Not After : Oct 11 16:48:35 2117 GMT
        Subject: CN=7179009621072316, OU=KEY CARD, O=Selp
        Subject Public Key Info:
            Public Key Algorithm: id-ecPublicKey
                Public-Key: (256 bit)
                ASN1 OID: prime256v1
                NIST CURVE: P-256
        X509v3 extensions:
            X509v3 Basic Constraints: critical
            X509v3 Key Usage: critical
                Digital Signature, Non Repudiation, Key Encipherment
            X509v3 Subject Key Identifier: 
            X509v3 Authority Key Identifier: 

            X509v3 Extended Key Usage: 
                TLS Web Client Authentication
    Signature Algorithm: ecdsa-with-SHA256


  • Certificate serial number appears sequential. The other card in the same two-card pack had a certificate serial number of 72513.
  • Tesla is not mentioned anywhere in the subject or issuer. Instead, the organization is listed as "Selp"; which likely referrs to the French smart-card/identity solution company Selp.
  • The CN of the subject is a 16-digit decimal number. Unlike the certificate serial number, this number appears to be randomly assigned.
  • The certificate expires a hundred years after its issue date, which isn't necessarilly bad, but there is a way to indicate that a certificate should not have an enforcable expiration date, and using an expiration date of "today + 100years" isn't it. But really I'm just splitting hairs here.
  • The key usage parameters are quite broad. It isn't clear how the current implementation of a TKC could actually perform any of them. I assume these fields are simply a misconfiguration.
  • The CA that signed this certificate (Issuer CN=Key Card CA, O=Selp) is not the root certificate that is present on the card (see below). Because we don't have a copy of the the CN=Key Card CA, O=Selp certificate, we have no way to determine if the certificate is actually valid, which seems unfortunate.

Card Root Certificate

        Version: 3 (0x2)
        Serial Number: 2 (0x2)
    Signature Algorithm: ecdsa-with-SHA256
            Not Before: Jan  9 15:37:10 2017 GMT
            Not After : Jan  9 15:37:10 2018 GMT
        Subject Public Key Info:
            Public Key Algorithm: id-ecPublicKey
                Public-Key: (256 bit)
                ASN1 OID: prime256v1
                NIST CURVE: P-256
        X509v3 extensions:
            X509v3 Basic Constraints: 
    Signature Algorithm: ecdsa-with-SHA256


  • This is not the root certificate that signed the card certificate.
  • This certificate has expired.
  • Missing "X509v3 Subject Key Identifier" field, which seems unfortunate.
  • Feels bogus, like this was a test certificate that someone forgot to replace with the real root certificate. Not sure what the story is here. Maybe this is the legit root, and CN=Key Card CA, O=Selp is just an intermediate CA?

Fob Certificate

        Version: 1 (0x0)
        Serial Number: 81646 (0x13eee)
    Signature Algorithm: ecdsa-with-SHA256
        Issuer: C=US, O=Tesla, CN=Fob Issuing CA 001
            Not Before: Sep 28 02:59:05 2019 GMT
            Not After : Sep 25 02:59:05 2029 GMT
        Subject: C=US, ST=California, O=Tesla, OU=Model3 Fobs, CN=JBL19268KBH53F - 0
        Subject Public Key Info:
            Public Key Algorithm: id-ecPublicKey
                Public-Key: (256 bit)
                ASN1 OID: prime256v1
                NIST CURVE: P-256
    Signature Algorithm: ecdsa-with-SHA256


  • Subject and issuer clearly indicate Tesla, not Selp.
  • Subject and issuer have fields reversed compared to card certificates.
  • Missing both "Subject Key Identifier" and "Authority Key Idenifier".
  • Fob is clearly indicated as being intended for Model 3.
  • Expiration date is only 10 years in the future.

Fob Issuing CA

        Version: 3 (0x2)
        Serial Number: 4096 (0x1000)
    Signature Algorithm: ecdsa-with-SHA256
        Issuer: C=US, ST=California, O=Tesla, OU=Tesla Motors, CN=Fob Root CA
            Not Before: Jul 13 01:26:07 2018 GMT
            Not After : Jan 24 01:26:07 2039 GMT
        Subject: C=US, O=Tesla, CN=Fob Issuing CA 001
        Subject Public Key Info:
            Public Key Algorithm: id-ecPublicKey
                Public-Key: (256 bit)
                ASN1 OID: prime256v1
                NIST CURVE: P-256
        X509v3 extensions:
            X509v3 Subject Key Identifier: 
            X509v3 Authority Key Identifier: 

            X509v3 Basic Constraints: critical
                CA:TRUE, pathlen:0
            X509v3 Key Usage: critical
                Digital Signature, Certificate Sign, CRL Sign
    Signature Algorithm: ecdsa-with-SHA256

Fob Command CA

        Version: 3 (0x2)
        Serial Number: 4098 (0x1002)
    Signature Algorithm: ecdsa-with-SHA256
        Issuer: C=US, ST=California, O=Tesla, OU=Tesla Motors, CN=Fob Root CA
            Not Before: Sep 22 00:06:06 2018 GMT
            Not After : Apr  5 00:06:06 2039 GMT
        Subject: C=US, O=Tesla, CN=Fob Command CA
        Subject Public Key Info:
            Public Key Algorithm: id-ecPublicKey
                Public-Key: (521 bit)
                ASN1 OID: secp521r1
                NIST CURVE: P-521
        X509v3 extensions:
            X509v3 Subject Key Identifier: 
            X509v3 Authority Key Identifier: 

            X509v3 Basic Constraints: critical
                CA:TRUE, pathlen:0
            X509v3 Key Usage: critical
                Digital Signature, Certificate Sign, CRL Sign
    Signature Algorithm: ecdsa-with-SHA256

Acknowledgements and Thanks

Copy link

Looks like the xNT supports ECC but I am new to this world - i do note AmieDD mentioning the Dangerousthings xNT before appearing to go for the acetone dissolve method for implanting.

I am going to do research and will keep you up to date here. Being very new to this world if anyone has heard of the attempts to clone to xNT before interested to hear.

Copy link

Hi All,

I would like to buy an NFC ring to use it as a Tesla key. I bought a cheap ring but it is not detected by the car to write the key. I can write URLs and so on with the phone, but it does not work with the Tesla. Do I need to buy a specific NFC chip or protocol when buying the ring? It looks like the ones that work with Tesla are expensive. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment