48 {
52
54
55 const char *connector_url;
56
57 connector_url = getenv("DEFAULT_CONNECTOR_URL");
58 if (connector_url == NULL) {
60 }
61
64
67
70
72 sizeof(password),
false, &
session);
74
77
81
82 printf(
"Successfully established session %02d\n", session_id);
83
85 assert(fp != NULL);
86
89 size_t key_material_len =
sizeof(
key);
90 if (!
read_file(fp, key, &key_material_len)) {
91 assert(false);
92 }
94 &key_material_len, false);
95 assert(ret2 == true);
97
101
105
109 key + (key_material_len / 2));
111
113
115 size_t public_key_len = sizeof(public_key);
119
120 printf(
"Public key (%zu bytes) is:", public_key_len);
121 for (unsigned int i = 0; i < public_key_len; i++) {
122 printf(
" %02x", public_key[i]);
123 }
125
126 BIGNUM *n = BN_bin2bn(public_key, public_key_len, NULL);
127 assert(n != NULL);
128
129 BIGNUM *e = BN_bin2bn((
const unsigned char *)
"\x01\x00\x01", 3, NULL);
130 assert(e != NULL);
131
132 RSA *rsa = RSA_new();
134
137 RSA_public_encrypt(sizeof(data), data, encrypted, rsa, RSA_PKCS1_PADDING);
138 assert(
ret == RSA_size(rsa));
139
141 size_t decrypted_len = sizeof(decrypted);
143 &decrypted_len);
145
146 assert(memcmp(data, decrypted, decrypted_len) == 0);
147
148 printf(
"PKCS1v1.5 decrypted data matches\n");
149
150 ret = RSA_public_encrypt(
sizeof(data), data, encrypted, rsa,
151 RSA_PKCS1_OAEP_PADDING);
152 assert(
ret == RSA_size(rsa));
153
154 decrypted_len = sizeof(decrypted);
160
161 assert(memcmp(data, decrypted, decrypted_len) == 0);
162
163 printf(
"OAEP decrypted data matches\n");
164
165 RSA_free(rsa);
166 rsa = NULL;
167
170
173
176
179
180 return 0;
181}
#define DEFAULT_CONNECTOR_URL
const uint8_t sha1_empty_string[]
const char rsa2048_pvtkey_file[]
CK_SESSION_HANDLE session
LOGGING_API void printf(Category category, const char *format,...)
int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d)
Capabilities representation.
bool read_file(FILE *fp, uint8_t *buf, size_t *buf_len)
bool read_private_key(uint8_t *buf, size_t len, yh_algorithm *algo, uint8_t *bytes, size_t *bytes_len, bool internal_repr)
yh_rc yh_destroy_session(yh_session **session)
yh_rc yh_create_session_derived(yh_connector *connector, uint16_t authkey_id, const uint8_t *password, size_t password_len, bool recreate, yh_session **session)
yh_rc yh_util_decrypt_pkcs1v1_5(yh_session *session, uint16_t key_id, const uint8_t *in, size_t in_len, uint8_t *out, size_t *out_len)
yh_rc yh_util_close_session(yh_session *session)
yh_rc yh_authenticate_session(yh_session *session)
yh_rc yh_string_to_domains(const char *domains, uint16_t *result)
yh_rc yh_init_connector(const char *url, yh_connector **connector)
yh_rc yh_connect(yh_connector *connector, int timeout)
yh_rc yh_util_get_public_key(yh_session *session, uint16_t id, uint8_t *data, size_t *data_len, yh_algorithm *algorithm)
yh_rc yh_util_decrypt_oaep(yh_session *session, uint16_t key_id, const uint8_t *in, size_t in_len, uint8_t *out, size_t *out_len, const uint8_t *label, size_t label_len, yh_algorithm mgf1Algo)
yh_rc yh_string_to_capabilities(const char *capability, yh_capabilities *result)
yh_rc yh_util_import_rsa_key(yh_session *session, uint16_t *key_id, const char *label, uint16_t domains, const yh_capabilities *capabilities, yh_algorithm algorithm, const uint8_t *p, const uint8_t *q)
yh_rc yh_disconnect(yh_connector *connector)
yh_rc yh_get_session_id(yh_session *session, uint8_t *sid)
@ YH_ALGO_RSA_2048
rsa2048
@ YH_ALGO_MGF1_SHA1
mgf1-sha1
@ YHR_GENERIC_ERROR
Return value when encountering an unknown error.
@ YHR_SUCCESS
Returned value when function was successful.
yh_capabilities capabilities