check / check (push) Failing after 3s
A Secure Enclave unlocker add gets the long-term key before it creates the Secure Enclave key, so a wrong passphrase creates none, and deletes the key if a later step fails. macse.CreateKey finds the new key's hash right after sc_auth creates it, failing with an error naming the label if it cannot, and deletes the key if getting its public key then fails. A keychain unlocker add writes all of the unlocker's files before it stores the keychain item, and deletes the item if moving the unlocker into place then fails. A failure to delete is reported along with the original error. The Objective-C and macse_darwin.go were only read, never compiled or run; the new tests run only on a Mac. Model: opus-5-5
70 lines
3.0 KiB
C
70 lines
3.0 KiB
C
//go:build darwin
|
|
|
|
#ifndef SECURE_ENCLAVE_H
|
|
#define SECURE_ENCLAVE_H
|
|
|
|
#include <stdint.h>
|
|
|
|
// se_create_key creates a new P-256 key in the Secure Enclave via sc_auth and
|
|
// finds its identity hash. If the hash cannot be found, the key exists but
|
|
// se_create_key fails, with an error naming the label.
|
|
// label: unique identifier for the CTK identity (UTF-8 C string)
|
|
// hash_out: output buffer for the identity hash (for deletion)
|
|
// hash_out_len: size of hash_out buffer
|
|
// error_out: output buffer for error message
|
|
// error_out_len: size of error_out buffer
|
|
// Returns 0 on success, -1 on failure.
|
|
int se_create_key(const char *label,
|
|
char *hash_out, int hash_out_len,
|
|
char *error_out, int error_out_len);
|
|
|
|
// se_copy_public_key copies the public key of a CTK identity.
|
|
// label: label of the CTK identity
|
|
// pub_key_out: output buffer for the uncompressed public key (65 bytes for P-256)
|
|
// pub_key_len: on input, size of pub_key_out; on output, actual size written
|
|
// error_out: output buffer for error message
|
|
// error_out_len: size of error_out buffer
|
|
// Returns 0 on success, -1 on failure.
|
|
int se_copy_public_key(const char *label,
|
|
uint8_t *pub_key_out, int *pub_key_len,
|
|
char *error_out, int error_out_len);
|
|
|
|
// se_encrypt encrypts data using the SE-backed public key (ECIES).
|
|
// label: label of the CTK identity whose public key to use
|
|
// plaintext: data to encrypt
|
|
// plaintext_len: length of plaintext
|
|
// ciphertext_out: output buffer for the ECIES ciphertext
|
|
// ciphertext_len: on input, size of buffer; on output, actual size written
|
|
// error_out: output buffer for error message
|
|
// error_out_len: size of error_out buffer
|
|
// Returns 0 on success, -1 on failure.
|
|
int se_encrypt(const char *label,
|
|
const uint8_t *plaintext, int plaintext_len,
|
|
uint8_t *ciphertext_out, int *ciphertext_len,
|
|
char *error_out, int error_out_len);
|
|
|
|
// se_decrypt decrypts ECIES ciphertext using the SE-backed private key.
|
|
// The ECDH portion of decryption is performed inside the Secure Enclave.
|
|
// label: label of the CTK identity whose private key to use
|
|
// ciphertext: ECIES ciphertext produced by se_encrypt
|
|
// ciphertext_len: length of ciphertext
|
|
// plaintext_out: output buffer for decrypted data
|
|
// plaintext_len: on input, size of buffer; on output, actual size written
|
|
// error_out: output buffer for error message
|
|
// error_out_len: size of error_out buffer
|
|
// Returns 0 on success, -1 on failure.
|
|
int se_decrypt(const char *label,
|
|
const uint8_t *ciphertext, int ciphertext_len,
|
|
uint8_t *plaintext_out, int *plaintext_len,
|
|
char *error_out, int error_out_len);
|
|
|
|
// se_delete_key removes a CTK identity from the Secure Enclave via sc_auth.
|
|
// hash: the identity hash returned by se_create_key
|
|
// error_out: output buffer for error message
|
|
// error_out_len: size of error_out buffer
|
|
// Returns 0 on success, -1 on failure.
|
|
int se_delete_key(const char *hash,
|
|
char *error_out, int error_out_len);
|
|
|
|
#endif // SECURE_ENCLAVE_H
|