23#ifndef CW_SECURECHANNEL_H
24#define CW_SECURECHANNEL_H
30#define CW_PAIRING_DATA "Cryptnox Basic CommonPairingData"
31#define CW_PAIRING_DATA_BYTES (sizeof(CW_PAIRING_DATA) - 1U)
131 uint8_t* cardEphemeralPubKey,
132 uint8_t* fullEphemeralPubKey65 = NULL);
152 uint8_t* clientPublicKey,
153 uint8_t* clientPrivateKey,
185 uint8_t* clientPublicKey,
186 const uint8_t* clientPrivateKey,
188 const uint8_t* cardEphemeralPubKey);
270 const uint8_t apdu[], uint16_t apduLength,
271 const uint8_t data[], uint16_t dataLength,
272 uint8_t* decryptedOutput = NULL,
273 uint16_t* decryptedOutputLength = NULL);
295 uint8_t* response,
size_t responseLen,
297 uint8_t* decryptedOutput = NULL,
298 uint16_t* decryptedOutputLength = NULL);
310 uint8_t sw1Expected, uint8_t sw2Expected);
328 const uint8_t* message, uint16_t msgLen,
329 const uint8_t* derSig, uint8_t derSigLen);
332 friend struct DerFuzzTarget;
Abstract cryptographic primitives interface.
Shared constants, error codes, and session state for the SDK.
#define CW_CERT_NONCE_SIZE
Abstract logging interface.
Abstract NFC transport interface.
Abstract interface for cryptographic operations used by CW_SecureChannel.
Abstract interface for serial/debug output.
Abstract interface for NFC transport operations.
CW_SecureChannel(CW_NfcTransport &driver, CW_Logger &logger, CW_CryptoProvider &crypto, CW_Platform &platform)
Construct a CW_SecureChannel.
CW_SecureChannel & operator=(const CW_SecureChannel &)=delete
static bool parseDerSigToRaw(const uint8_t *der, uint8_t derLen, uint8_t *raw64)
CW_Logger & _logger
Logging interface.
bool openSecureChannel(uint8_t *salt, uint8_t *clientPublicKey, uint8_t *clientPrivateKey, CW_Curve sessionCurve)
Send OPEN SECURE CHANNEL and retrieve the session salt.
CW_NfcTransport & _driver
NFC transport for APDU exchange.
bool mutuallyAuthenticate(CW_SecureSession &session, const uint8_t *salt, uint8_t *clientPublicKey, const uint8_t *clientPrivateKey, CW_Curve sessionCurve, const uint8_t *cardEphemeralPubKey)
Perform ECDH derivation and MUTUALLY AUTHENTICATE with the card.
bool aesCbcEncrypt(CW_SecureSession &session, const uint8_t apdu[], uint16_t apduLength, const uint8_t data[], uint16_t dataLength, uint8_t *decryptedOutput=NULL, uint16_t *decryptedOutputLength=NULL)
AES-CBC encrypt + MAC, send APDU, and decrypt response.
bool inListPassiveTarget()
Detect a passive NFC target (ISO-DEP card).
bool aesCbcDecrypt(const CW_SecureSession &session, uint8_t *response, size_t responseLen, uint8_t *macValue, uint8_t *decryptedOutput=NULL, uint16_t *decryptedOutputLength=NULL)
Verify MAC and decrypt an encrypted APDU response.
bool begin()
Initialize the NFC transport module.
bool verifyEcdsaSha256(const uint8_t *pubKey64, const uint8_t *message, uint16_t msgLen, const uint8_t *derSig, uint8_t derSigLen)
bool checkStatusWord(const uint8_t *response, uint16_t responseLength, uint8_t sw1Expected, uint8_t sw2Expected)
Verify the SW1/SW2 status word at the end of an APDU response.
bool preFetchManufacturerCert()
Fetch and cache the manufacturer certificate before getCardCertificate().
bool getCardCertificate(uint8_t *cardCertificate, uint8_t &cardCertificateLength)
Retrieve the card's ephemeral public key via GET CARD CERTIFICATE.
CW_SecureChannel(const CW_SecureChannel &)=delete
uint16_t _cachedMfCertLen
Non-zero when s_mfCertBuf holds a valid pre-fetched manufacturer certificate.
bool selectApdu()
Send the SELECT APDU to activate the Cryptnox application.
CW_Platform & _platform
Platform abstraction (sleep_ms).
uint8_t verifyCertificateChain(const uint8_t *cardCert, uint8_t cardCertLen)
Verify the full card certificate chain against the trusted CA.
void resetReader()
Reset the NFC reader hardware.
uint8_t _lastNonce[CW_CERT_NONCE_SIZE]
Nonce sent in the last getCardCertificate() call; checked in verifyCertificateChain().
bool extractCardEphemeralKey(const uint8_t *cardCertificate, uint8_t *cardEphemeralPubKey, uint8_t *fullEphemeralPubKey65=NULL)
Extract the card's ephemeral EC P-256 public key from a certificate.
CW_CryptoProvider & _crypto
Crypto operations (AES, SHA, ECDH, RNG).
bool getManufacturerCertificate(uint8_t *cert, uint16_t &certLen)
Retrieve the manufacturer certificate stored in card flash.
bool printFirmwareVersion()
Print the NFC reader firmware version to the logger.
CW_Curve
Portable curve identifier used throughout the SDK.
Holds cryptographic session state for reentrant secure channel operations.