42 {
46
48
49 const char *connector_url;
50
51 connector_url = getenv("DEFAULT_CONNECTOR_URL");
52 if (connector_url == NULL) {
54 }
55
58
61
64
66 sizeof(password),
false, &
session);
68
71
75
76 printf(
"Successfully established session %02d\n", session_id);
77
81
85
90
92
93 printf(
"Data to sign (%zu bytes) is: %s\n",
sizeof(data) - 1, data);
94
95 EVP_MD_CTX *
mdctx = NULL;
97 unsigned int hashed_data_len;
98
99 mdctx = EVP_MD_CTX_create();
100 assert(
mdctx != NULL);
101 EVP_DigestInit_ex(
mdctx, EVP_sha256(), NULL);
102 EVP_DigestUpdate(
mdctx, data,
sizeof(data) - 1);
103 EVP_DigestFinal_ex(
mdctx, hashed_data, &hashed_data_len);
104 EVP_MD_CTX_destroy(
mdctx);
105
106 printf(
"Hash of data (%d bytes) is:", EVP_MD_size(EVP_sha256()));
107 for (unsigned int i = 0; i < hashed_data_len; i++) {
108 printf(
" %02x", hashed_data[i]);
109 }
111
113 size_t signature_len =
sizeof(
signature);
115 hashed_data_len, signature, &signature_len);
117
118 printf(
"Signature (%zu bytes) is:", signature_len);
119 for (unsigned int i = 0; i < signature_len; i++) {
120 printf(
" %02x", signature[i]);
121 }
123
125 size_t public_key_len = sizeof(public_key);
129
130 printf(
"Public key (%zu bytes) is:", public_key_len);
131 for (unsigned int i = 0; i < public_key_len; i++) {
132 printf(
" %02x", public_key[i]);
133 }
135
136 BIGNUM *n = BN_bin2bn(public_key, public_key_len, NULL);
137 assert(n != NULL);
138
139 BIGNUM *e = BN_bin2bn((
const unsigned char *)
"\x01\x00\x01", 3, NULL);
140 assert(e != NULL);
141
142 RSA *rsa = RSA_new();
144
145 if (RSA_verify(EVP_MD_type(EVP_sha256()), hashed_data, hashed_data_len,
146 signature, signature_len, rsa) == 1) {
147 printf(
"Signature successfully verified\n");
148 } else {
149 printf(
"Unable to verify signature\n");
150 }
151
152 RSA_free(rsa);
153 rsa = NULL;
154
157
160
163
166
167 return 0;
168}
CK_SESSION_HANDLE session
#define DEFAULT_CONNECTOR_URL
LOGGING_API void printf(Category category, const char *format,...)
fc::array< char, 72 > signature
int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d)
Capabilities representation.
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_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_util_sign_pkcs1v1_5(yh_session *session, uint16_t key_id, bool hashed, const uint8_t *in, size_t in_len, uint8_t *out, size_t *out_len)
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_generate_rsa_key(yh_session *session, uint16_t *key_id, const char *label, uint16_t domains, const yh_capabilities *capabilities, yh_algorithm algorithm)
yh_rc yh_get_session_id(yh_session *session, uint8_t *sid)
@ YH_ALGO_RSA_2048
rsa2048
@ YHR_GENERIC_ERROR
Return value when encountering an unknown error.
@ YHR_SUCCESS
Returned value when function was successful.
yh_capabilities capabilities