44 {
48
50
51 const char *connector_url;
52
53 connector_url = getenv("DEFAULT_CONNECTOR_URL");
54 if (connector_url == NULL) {
56 }
57
60
63
66
68 sizeof(password),
false, &
session);
70
73
77
78 printf(
"Successfully established session %02d\n", session_id);
79
81 assert(fp != NULL);
82
85 size_t key_material_len =
sizeof(
key);
86 if (!
read_file(fp, key, &key_material_len)) {
87 assert(false);
88 }
90 &key_material_len, false);
93
97
101
106
108
109 printf(
"Data to sign (%zu bytes) is: %s\n",
sizeof(data) - 1, data);
110
111 EVP_MD_CTX *
mdctx = NULL;
113 unsigned int hashed_data_len;
114
115 mdctx = EVP_MD_CTX_create();
116 assert(
mdctx != NULL);
117 EVP_DigestInit_ex(
mdctx, EVP_sha256(), NULL);
118 EVP_DigestUpdate(
mdctx, data,
sizeof(data) - 1);
119 EVP_DigestFinal_ex(
mdctx, hashed_data, &hashed_data_len);
120 EVP_MD_CTX_destroy(
mdctx);
121
122 printf(
"Hash of data (%d bytes) is:", EVP_MD_size(EVP_sha256()));
123 for (unsigned int i = 0; i < hashed_data_len; i++) {
124 printf(
" %02x", hashed_data[i]);
125 }
127
129 size_t signature_len =
sizeof(
signature);
131 signature, &signature_len);
133
134 printf(
"Signature (%zu bytes) is:", signature_len);
135 for (unsigned int i = 0; i < signature_len; i++) {
136 printf(
" %02x", signature[i]);
137 }
139
141 size_t public_key_len = sizeof(public_key);
145
146 printf(
"Public key (%zu bytes) is:", public_key_len);
147 for (unsigned int i = 0; i < public_key_len; i++) {
148 printf(
" %02x", public_key[i]);
149 }
151
152 EC_KEY *eckey = EC_KEY_new();
155 EC_GROUP *group = EC_GROUP_new_by_curve_name(nid);
156
157 EC_GROUP_set_asn1_flag(group, nid);
158 EC_KEY_set_group(eckey, group);
159 point = EC_POINT_new(group);
160
161 memmove(public_key + 1, public_key, public_key_len);
162 public_key[0] = 0x04;
163 public_key_len++;
164
165 EC_POINT_oct2point(group,
point, public_key, public_key_len, NULL);
166
167 EC_KEY_set_public_key(eckey,
point);
168
169 if (ECDSA_verify(0, hashed_data, hashed_data_len, signature, signature_len,
170 eckey) == 1) {
171 printf(
"Signature successfully verified\n");
172 } else {
173 printf(
"Unable to verify signature\n");
174 }
175
176 EC_POINT_free(
point);
177 EC_KEY_free(eckey);
178 EC_GROUP_free(group);
179
182
185
188
191
192 return 0;
193}
CK_SESSION_HANDLE session
#define DEFAULT_CONNECTOR_URL
const char p256_pvtkey_file[]
LOGGING_API void printf(Category category, const char *format,...)
fc::array< char, 72 > signature
Capabilities representation.
int algo2nid(yh_algorithm algo)
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_sign_ecdsa(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_string_to_capabilities(const char *capability, yh_capabilities *result)
yh_rc yh_disconnect(yh_connector *connector)
yh_rc yh_util_import_ec_key(yh_session *session, uint16_t *key_id, const char *label, uint16_t domains, const yh_capabilities *capabilities, yh_algorithm algorithm, const uint8_t *s)
yh_rc yh_get_session_id(yh_session *session, uint8_t *sid)
@ YHR_GENERIC_ERROR
Return value when encountering an unknown error.
@ YHR_SUCCESS
Returned value when function was successful.
yh_capabilities capabilities