aboutsummaryrefslogtreecommitdiff
path: root/rpc_client.c
diff options
context:
space:
mode:
Diffstat (limited to 'rpc_client.c')
-rw-r--r--rpc_client.c449
1 files changed, 236 insertions, 213 deletions
diff --git a/rpc_client.c b/rpc_client.c
index d58cb92..5903895 100644
--- a/rpc_client.c
+++ b/rpc_client.c
@@ -37,6 +37,7 @@
#include "hal.h"
#include "hal_internal.h"
+#include "xdr_internal.h"
/*
* RPC calls.
@@ -46,6 +47,27 @@
#define pad(n) (((n) + 3) & ~3)
+#if RPC_CLIENT != RPC_CLIENT_LOCAL
+
+static hal_error_t get_version(uint32_t *version)
+{
+ uint8_t outbuf[4], *optr = outbuf, *olimit = outbuf + sizeof(outbuf);
+ uint8_t inbuf[8], *iptr = inbuf, *ilimit = inbuf + sizeof(inbuf);
+ size_t ilen = sizeof(inbuf);
+ hal_error_t ret, rpc_ret;
+
+ check(hal_xdr_encode_int(&optr, olimit, RPC_FUNC_GET_VERSION));
+ check(hal_rpc_send(outbuf, optr - outbuf));
+
+ check(hal_rpc_recv(inbuf, &ilen));
+ assert(ilen <= sizeof(inbuf));
+ check(hal_xdr_decode_int(&iptr, ilimit, &rpc_ret));
+ if (rpc_ret == HAL_OK) {
+ check(hal_xdr_decode_int(&iptr, ilimit, version));
+ }
+ return rpc_ret;
+}
+
static hal_error_t get_random(void *buffer, const size_t length)
{
uint8_t outbuf[8], *optr = outbuf, *olimit = outbuf + sizeof(outbuf);
@@ -54,15 +76,15 @@ static hal_error_t get_random(void *buffer, const size_t length)
uint32_t rcvlen = length;
hal_error_t ret, rpc_ret;
- check(rpc_encode_int(&optr, olimit, RPC_FUNC_GET_RANDOM));
- check(rpc_encode_int(&optr, olimit, (uint32_t)length));
- check(rpc_send(outbuf, optr - outbuf));
+ check(hal_xdr_encode_int(&optr, olimit, RPC_FUNC_GET_RANDOM));
+ check(hal_xdr_encode_int(&optr, olimit, (uint32_t)length));
+ check(hal_rpc_send(outbuf, optr - outbuf));
- check(rpc_recv(inbuf, &ilen));
+ check(hal_rpc_recv(inbuf, &ilen));
assert(ilen <= sizeof(inbuf));
- check(rpc_decode_int(&iptr, ilimit, &rpc_ret));
+ check(hal_xdr_decode_int(&iptr, ilimit, &rpc_ret));
if (rpc_ret == HAL_OK) {
- check(rpc_decode_buffer(&iptr, ilimit, buffer, &rcvlen));
+ check(hal_xdr_decode_buffer(&iptr, ilimit, buffer, &rcvlen));
// XXX check rcvlen vs length
}
return rpc_ret;
@@ -77,15 +99,15 @@ static hal_error_t set_pin(const hal_client_handle_t client,
size_t ilen = sizeof(inbuf);
hal_error_t ret, rpc_ret;
- check(rpc_encode_int(&optr, olimit, RPC_FUNC_SET_PIN));
- check(rpc_encode_int(&optr, olimit, client.handle));
- check(rpc_encode_int(&optr, olimit, user));
- check(rpc_encode_buffer(&optr, olimit, (const uint8_t *)pin, pin_len));
- check(rpc_send(outbuf, optr - outbuf));
+ check(hal_xdr_encode_int(&optr, olimit, RPC_FUNC_SET_PIN));
+ check(hal_xdr_encode_int(&optr, olimit, client.handle));
+ check(hal_xdr_encode_int(&optr, olimit, user));
+ check(hal_xdr_encode_buffer(&optr, olimit, (const uint8_t *)pin, pin_len));
+ check(hal_rpc_send(outbuf, optr - outbuf));
- check(rpc_recv(inbuf, &ilen));
+ check(hal_rpc_recv(inbuf, &ilen));
assert(ilen <= sizeof(inbuf));
- check(rpc_decode_int(&iptr, ilimit, &rpc_ret));
+ check(hal_xdr_decode_int(&iptr, ilimit, &rpc_ret));
return rpc_ret;
}
@@ -112,15 +134,15 @@ static hal_error_t login(const hal_client_handle_t client,
size_t ilen = sizeof(inbuf);
hal_error_t ret, rpc_ret;
- check(rpc_encode_int(&optr, olimit, RPC_FUNC_LOGIN));
- check(rpc_encode_int(&optr, olimit, client.handle));
- check(rpc_encode_int(&optr, olimit, user));
- check(rpc_encode_buffer(&optr, olimit, (const uint8_t *)pin, pin_len));
- check(rpc_send(outbuf, optr - outbuf));
+ check(hal_xdr_encode_int(&optr, olimit, RPC_FUNC_LOGIN));
+ check(hal_xdr_encode_int(&optr, olimit, client.handle));
+ check(hal_xdr_encode_int(&optr, olimit, user));
+ check(hal_xdr_encode_buffer(&optr, olimit, (const uint8_t *)pin, pin_len));
+ check(hal_rpc_send(outbuf, optr - outbuf));
- check(rpc_recv(inbuf, &ilen));
+ check(hal_rpc_recv(inbuf, &ilen));
assert(ilen <= sizeof(inbuf));
- check(rpc_decode_int(&iptr, ilimit, &rpc_ret));
+ check(hal_xdr_decode_int(&iptr, ilimit, &rpc_ret));
return rpc_ret;
}
@@ -131,13 +153,13 @@ static hal_error_t logout(const hal_client_handle_t client)
size_t ilen = sizeof(inbuf);
hal_error_t ret, rpc_ret;
- check(rpc_encode_int(&optr, olimit, RPC_FUNC_LOGOUT));
- check(rpc_encode_int(&optr, olimit, client.handle));
- check(rpc_send(outbuf, optr - outbuf));
+ check(hal_xdr_encode_int(&optr, olimit, RPC_FUNC_LOGOUT));
+ check(hal_xdr_encode_int(&optr, olimit, client.handle));
+ check(hal_rpc_send(outbuf, optr - outbuf));
- check(rpc_recv(inbuf, &ilen));
+ check(hal_rpc_recv(inbuf, &ilen));
assert(ilen <= sizeof(inbuf));
- check(rpc_decode_int(&iptr, ilimit, &rpc_ret));
+ check(hal_xdr_decode_int(&iptr, ilimit, &rpc_ret));
return rpc_ret;
}
@@ -148,12 +170,12 @@ static hal_error_t logout_all(void)
size_t ilen = sizeof(inbuf);
hal_error_t ret, rpc_ret;
- check(rpc_encode_int(&optr, olimit, RPC_FUNC_LOGOUT_ALL));
- check(rpc_send(outbuf, optr - outbuf));
+ check(hal_xdr_encode_int(&optr, olimit, RPC_FUNC_LOGOUT_ALL));
+ check(hal_rpc_send(outbuf, optr - outbuf));
- check(rpc_recv(inbuf, &ilen));
+ check(hal_rpc_recv(inbuf, &ilen));
assert(ilen <= sizeof(inbuf));
- check(rpc_decode_int(&iptr, ilimit, &rpc_ret));
+ check(hal_xdr_decode_int(&iptr, ilimit, &rpc_ret));
return rpc_ret;
}
@@ -165,14 +187,14 @@ static hal_error_t is_logged_in(const hal_client_handle_t client,
size_t ilen = sizeof(inbuf);
hal_error_t ret, rpc_ret;
- check(rpc_encode_int(&optr, olimit, RPC_FUNC_IS_LOGGED_IN));
- check(rpc_encode_int(&optr, olimit, client.handle));
- check(rpc_encode_int(&optr, olimit, user));
- check(rpc_send(outbuf, optr - outbuf));
+ check(hal_xdr_encode_int(&optr, olimit, RPC_FUNC_IS_LOGGED_IN));
+ check(hal_xdr_encode_int(&optr, olimit, client.handle));
+ check(hal_xdr_encode_int(&optr, olimit, user));
+ check(hal_rpc_send(outbuf, optr - outbuf));
- check(rpc_recv(inbuf, &ilen));
+ check(hal_rpc_recv(inbuf, &ilen));
assert(ilen <= sizeof(inbuf));
- check(rpc_decode_int(&iptr, ilimit, &rpc_ret));
+ check(hal_xdr_decode_int(&iptr, ilimit, &rpc_ret));
return rpc_ret;
}
@@ -184,15 +206,15 @@ static hal_error_t hash_get_digest_len(const hal_digest_algorithm_t alg, size_t
uint32_t len32;
hal_error_t ret, rpc_ret;
- check(rpc_encode_int(&optr, olimit, RPC_FUNC_HASH_GET_DIGEST_LEN));
- check(rpc_encode_int(&optr, olimit, alg));
- check(rpc_send(outbuf, optr - outbuf));
+ check(hal_xdr_encode_int(&optr, olimit, RPC_FUNC_HASH_GET_DIGEST_LEN));
+ check(hal_xdr_encode_int(&optr, olimit, alg));
+ check(hal_rpc_send(outbuf, optr - outbuf));
- check(rpc_recv(inbuf, &ilen));
+ check(hal_rpc_recv(inbuf, &ilen));
assert(ilen <= sizeof(inbuf));
- check(rpc_decode_int(&iptr, ilimit, &rpc_ret));
+ check(hal_xdr_decode_int(&iptr, ilimit, &rpc_ret));
if (rpc_ret == HAL_OK) {
- check(rpc_decode_int(&iptr, ilimit, &len32));
+ check(hal_xdr_decode_int(&iptr, ilimit, &len32));
*length = (size_t)len32;
}
return rpc_ret;
@@ -207,16 +229,16 @@ static hal_error_t hash_get_digest_algorithm_id(const hal_digest_algorithm_t alg
uint32_t len32 = len_max;
hal_error_t ret, rpc_ret;
- check(rpc_encode_int(&optr, olimit, RPC_FUNC_HASH_GET_DIGEST_LEN));
- check(rpc_encode_int(&optr, olimit, alg));
- check(rpc_encode_int(&optr, olimit, len_max));
- check(rpc_send(outbuf, optr - outbuf));
+ check(hal_xdr_encode_int(&optr, olimit, RPC_FUNC_HASH_GET_DIGEST_LEN));
+ check(hal_xdr_encode_int(&optr, olimit, alg));
+ check(hal_xdr_encode_int(&optr, olimit, len_max));
+ check(hal_rpc_send(outbuf, optr - outbuf));
- check(rpc_recv(inbuf, &ilen));
+ check(hal_rpc_recv(inbuf, &ilen));
assert(ilen <= sizeof(inbuf));
- check(rpc_decode_int(&iptr, ilimit, &rpc_ret));
+ check(hal_xdr_decode_int(&iptr, ilimit, &rpc_ret));
if (rpc_ret == HAL_OK) {
- check(rpc_decode_buffer(&iptr, ilimit, id, &len32));
+ check(hal_xdr_decode_buffer(&iptr, ilimit, id, &len32));
*len = len32;
}
return rpc_ret;
@@ -230,15 +252,15 @@ static hal_error_t hash_get_algorithm(const hal_hash_handle_t hash, hal_digest_a
uint32_t alg32;
hal_error_t ret, rpc_ret;
- check(rpc_encode_int(&optr, olimit, RPC_FUNC_HASH_GET_ALGORITHM));
- check(rpc_encode_int(&optr, olimit, hash.handle));
- check(rpc_send(outbuf, optr - outbuf));
+ check(hal_xdr_encode_int(&optr, olimit, RPC_FUNC_HASH_GET_ALGORITHM));
+ check(hal_xdr_encode_int(&optr, olimit, hash.handle));
+ check(hal_rpc_send(outbuf, optr - outbuf));
- check(rpc_recv(inbuf, &ilen));
+ check(hal_rpc_recv(inbuf, &ilen));
assert(ilen <= sizeof(inbuf));
- check(rpc_decode_int(&iptr, ilimit, &rpc_ret));
+ check(hal_xdr_decode_int(&iptr, ilimit, &rpc_ret));
if (rpc_ret == HAL_OK) {
- check(rpc_decode_int(&iptr, ilimit, &alg32));
+ check(hal_xdr_decode_int(&iptr, ilimit, &alg32));
*alg = (hal_digest_algorithm_t)alg32;
}
return rpc_ret;
@@ -255,18 +277,18 @@ static hal_error_t hash_initialize(const hal_client_handle_t client,
size_t ilen = sizeof(inbuf);
hal_error_t ret, rpc_ret;
- check(rpc_encode_int(&optr, olimit, RPC_FUNC_HASH_INITIALIZE));
- check(rpc_encode_int(&optr, olimit, client.handle));
- check(rpc_encode_int(&optr, olimit, session.handle));
- check(rpc_encode_int(&optr, olimit, alg));
- check(rpc_encode_buffer(&optr, olimit, key, key_len));
- check(rpc_send(outbuf, optr - outbuf));
+ check(hal_xdr_encode_int(&optr, olimit, RPC_FUNC_HASH_INITIALIZE));
+ check(hal_xdr_encode_int(&optr, olimit, client.handle));
+ check(hal_xdr_encode_int(&optr, olimit, session.handle));
+ check(hal_xdr_encode_int(&optr, olimit, alg));
+ check(hal_xdr_encode_buffer(&optr, olimit, key, key_len));
+ check(hal_rpc_send(outbuf, optr - outbuf));
- check(rpc_recv(inbuf, &ilen));
+ check(hal_rpc_recv(inbuf, &ilen));
assert(ilen <= sizeof(inbuf));
- check(rpc_decode_int(&iptr, ilimit, &rpc_ret));
+ check(hal_xdr_decode_int(&iptr, ilimit, &rpc_ret));
if (rpc_ret == HAL_OK) {
- check(rpc_decode_int(&iptr, ilimit, &hash->handle));
+ check(hal_xdr_decode_int(&iptr, ilimit, &hash->handle));
}
return rpc_ret;
}
@@ -279,14 +301,14 @@ static hal_error_t hash_update(const hal_hash_handle_t hash,
size_t ilen = sizeof(inbuf);
hal_error_t ret, rpc_ret;
- check(rpc_encode_int(&optr, olimit, RPC_FUNC_HASH_UPDATE));
- check(rpc_encode_int(&optr, olimit, hash.handle));
- check(rpc_encode_buffer(&optr, olimit, data, length));
- check(rpc_send(outbuf, optr - outbuf));
+ check(hal_xdr_encode_int(&optr, olimit, RPC_FUNC_HASH_UPDATE));
+ check(hal_xdr_encode_int(&optr, olimit, hash.handle));
+ check(hal_xdr_encode_buffer(&optr, olimit, data, length));
+ check(hal_rpc_send(outbuf, optr - outbuf));
- check(rpc_recv(inbuf, &ilen));
+ check(hal_rpc_recv(inbuf, &ilen));
assert(ilen <= sizeof(inbuf));
- check(rpc_decode_int(&iptr, ilimit, &rpc_ret));
+ check(hal_xdr_decode_int(&iptr, ilimit, &rpc_ret));
return rpc_ret;
}
@@ -299,16 +321,16 @@ static hal_error_t hash_finalize(const hal_hash_handle_t hash,
uint32_t digest_len = length;
hal_error_t ret, rpc_ret;
- check(rpc_encode_int(&optr, olimit, RPC_FUNC_HASH_FINALIZE));
- check(rpc_encode_int(&optr, olimit, hash.handle));
- check(rpc_encode_int(&optr, olimit, length));
- check(rpc_send(outbuf, optr - outbuf));
+ check(hal_xdr_encode_int(&optr, olimit, RPC_FUNC_HASH_FINALIZE));
+ check(hal_xdr_encode_int(&optr, olimit, hash.handle));
+ check(hal_xdr_encode_int(&optr, olimit, length));
+ check(hal_rpc_send(outbuf, optr - outbuf));
- check(rpc_recv(inbuf, &ilen));
+ check(hal_rpc_recv(inbuf, &ilen));
assert(ilen <= sizeof(inbuf));
- check(rpc_decode_int(&iptr, ilimit, &rpc_ret));
+ check(hal_xdr_decode_int(&iptr, ilimit, &rpc_ret));
if (rpc_ret == HAL_OK) {
- check(rpc_decode_buffer(&iptr, ilimit, digest, &digest_len));
+ check(hal_xdr_decode_buffer(&iptr, ilimit, digest, &digest_len));
/* XXX check digest_len vs length */
}
return rpc_ret;
@@ -328,21 +350,21 @@ static hal_error_t pkey_load(const hal_client_handle_t client,
size_t ilen = sizeof(inbuf);
hal_error_t ret, rpc_ret;
- check(rpc_encode_int(&optr, olimit, RPC_FUNC_PKEY_LOAD));
- check(rpc_encode_int(&optr, olimit, client.handle));
- check(rpc_encode_int(&optr, olimit, session.handle));
- check(rpc_encode_int(&optr, olimit, type));
- check(rpc_encode_int(&optr, olimit, curve));
- check(rpc_encode_buffer(&optr, olimit, name, name_len));
- check(rpc_encode_buffer(&optr, olimit, der, der_len));
- check(rpc_encode_int(&optr, olimit, flags));
- check(rpc_send(outbuf, optr - outbuf));
-
- check(rpc_recv(inbuf, &ilen));
+ check(hal_xdr_encode_int(&optr, olimit, RPC_FUNC_PKEY_LOAD));
+ check(hal_xdr_encode_int(&optr, olimit, client.handle));
+ check(hal_xdr_encode_int(&optr, olimit, session.handle));
+ check(hal_xdr_encode_int(&optr, olimit, type));
+ check(hal_xdr_encode_int(&optr, olimit, curve));
+ check(hal_xdr_encode_buffer(&optr, olimit, name, name_len));
+ check(hal_xdr_encode_buffer(&optr, olimit, der, der_len));
+ check(hal_xdr_encode_int(&optr, olimit, flags));
+ check(hal_rpc_send(outbuf, optr - outbuf));
+
+ check(hal_rpc_recv(inbuf, &ilen));
assert(ilen <= sizeof(inbuf));
- check(rpc_decode_int(&iptr, ilimit, &rpc_ret));
+ check(hal_xdr_decode_int(&iptr, ilimit, &rpc_ret));
if (rpc_ret == HAL_OK)
- check(rpc_decode_int(&iptr, ilimit, &pkey->handle));
+ check(hal_xdr_decode_int(&iptr, ilimit, &pkey->handle));
return rpc_ret;
}
@@ -358,18 +380,18 @@ static hal_error_t pkey_find(const hal_client_handle_t client,
size_t ilen = sizeof(inbuf);
hal_error_t ret, rpc_ret;
- check(rpc_encode_int(&optr, olimit, RPC_FUNC_PKEY_FIND));
- check(rpc_encode_int(&optr, olimit, client.handle));
- check(rpc_encode_int(&optr, olimit, session.handle));
- check(rpc_encode_int(&optr, olimit, type));
- check(rpc_encode_buffer(&optr, olimit, name, name_len));
- check(rpc_send(outbuf, optr - outbuf));
+ check(hal_xdr_encode_int(&optr, olimit, RPC_FUNC_PKEY_FIND));
+ check(hal_xdr_encode_int(&optr, olimit, client.handle));
+ check(hal_xdr_encode_int(&optr, olimit, session.handle));
+ check(hal_xdr_encode_int(&optr, olimit, type));
+ check(hal_xdr_encode_buffer(&optr, olimit, name, name_len));
+ check(hal_rpc_send(outbuf, optr - outbuf));
- check(rpc_recv(inbuf, &ilen));
+ check(hal_rpc_recv(inbuf, &ilen));
assert(ilen <= sizeof(inbuf));
- check(rpc_decode_int(&iptr, ilimit, &rpc_ret));
+ check(hal_xdr_decode_int(&iptr, ilimit, &rpc_ret));
if (rpc_ret == HAL_OK)
- check(rpc_decode_int(&iptr, ilimit, &pkey->handle));
+ check(hal_xdr_decode_int(&iptr, ilimit, &pkey->handle));
return rpc_ret;
}
@@ -387,20 +409,20 @@ static hal_error_t pkey_generate_rsa(const hal_client_handle_t client,
size_t ilen = sizeof(inbuf);
hal_error_t ret, rpc_ret;
- check(rpc_encode_int(&optr, olimit, RPC_FUNC_PKEY_GENERATE_RSA));
- check(rpc_encode_int(&optr, olimit, client.handle));
- check(rpc_encode_int(&optr, olimit, session.handle));
- check(rpc_encode_buffer(&optr, olimit, name, name_len));
- check(rpc_encode_int(&optr, olimit, key_len));
- check(rpc_encode_buffer(&optr, olimit, exp, exp_len));
- check(rpc_encode_int(&optr, olimit, flags));
- check(rpc_send(outbuf, optr - outbuf));
+ check(hal_xdr_encode_int(&optr, olimit, RPC_FUNC_PKEY_GENERATE_RSA));
+ check(hal_xdr_encode_int(&optr, olimit, client.handle));
+ check(hal_xdr_encode_int(&optr, olimit, session.handle));
+ check(hal_xdr_encode_buffer(&optr, olimit, name, name_len));
+ check(hal_xdr_encode_int(&optr, olimit, key_len));
+ check(hal_xdr_encode_buffer(&optr, olimit, exp, exp_len));
+ check(hal_xdr_encode_int(&optr, olimit, flags));
+ check(hal_rpc_send(outbuf, optr - outbuf));
- check(rpc_recv(inbuf, &ilen));
+ check(hal_rpc_recv(inbuf, &ilen));
assert(ilen <= sizeof(inbuf));
- check(rpc_decode_int(&iptr, ilimit, &rpc_ret));
+ check(hal_xdr_decode_int(&iptr, ilimit, &rpc_ret));
if (rpc_ret == HAL_OK)
- check(rpc_decode_int(&iptr, ilimit, &pkey->handle));
+ check(hal_xdr_decode_int(&iptr, ilimit, &pkey->handle));
return rpc_ret;
}
@@ -417,19 +439,19 @@ static hal_error_t pkey_generate_ec(const hal_client_handle_t client,
size_t ilen = sizeof(inbuf);
hal_error_t ret, rpc_ret;
- check(rpc_encode_int(&optr, olimit, RPC_FUNC_PKEY_GENERATE_EC));
- check(rpc_encode_int(&optr, olimit, client.handle));
- check(rpc_encode_int(&optr, olimit, session.handle));
- check(rpc_encode_buffer(&optr, olimit, name, name_len));
- check(rpc_encode_int(&optr, olimit, curve));
- check(rpc_encode_int(&optr, olimit, flags));
- check(rpc_send(outbuf, optr - outbuf));
+ check(hal_xdr_encode_int(&optr, olimit, RPC_FUNC_PKEY_GENERATE_EC));
+ check(hal_xdr_encode_int(&optr, olimit, client.handle));
+ check(hal_xdr_encode_int(&optr, olimit, session.handle));
+ check(hal_xdr_encode_buffer(&optr, olimit, name, name_len));
+ check(hal_xdr_encode_int(&optr, olimit, curve));
+ check(hal_xdr_encode_int(&optr, olimit, flags));
+ check(hal_rpc_send(outbuf, optr - outbuf));
- check(rpc_recv(inbuf, &ilen));
+ check(hal_rpc_recv(inbuf, &ilen));
assert(ilen <= sizeof(inbuf));
- check(rpc_decode_int(&iptr, ilimit, &rpc_ret));
+ check(hal_xdr_decode_int(&iptr, ilimit, &rpc_ret));
if (rpc_ret == HAL_OK)
- check(rpc_decode_int(&iptr, ilimit, &pkey->handle));
+ check(hal_xdr_decode_int(&iptr, ilimit, &pkey->handle));
return rpc_ret;
}
@@ -441,13 +463,13 @@ static hal_error_t pkey_close(const hal_pkey_handle_t pkey)
size_t ilen = sizeof(inbuf);
hal_error_t ret, rpc_ret;
- check(rpc_encode_int(&optr, olimit, RPC_FUNC_PKEY_CLOSE));
- check(rpc_encode_int(&optr, olimit, pkey.handle));
- check(rpc_send(outbuf, optr - outbuf));
+ check(hal_xdr_encode_int(&optr, olimit, RPC_FUNC_PKEY_CLOSE));
+ check(hal_xdr_encode_int(&optr, olimit, pkey.handle));
+ check(hal_rpc_send(outbuf, optr - outbuf));
- check(rpc_recv(inbuf, &ilen));
+ check(hal_rpc_recv(inbuf, &ilen));
assert(ilen <= sizeof(inbuf));
- check(rpc_decode_int(&iptr, ilimit, &rpc_ret));
+ check(hal_xdr_decode_int(&iptr, ilimit, &rpc_ret));
return rpc_ret;
}
@@ -458,13 +480,13 @@ static hal_error_t pkey_delete(const hal_pkey_handle_t pkey)
size_t ilen = sizeof(inbuf);
hal_error_t ret, rpc_ret;
- check(rpc_encode_int(&optr, olimit, RPC_FUNC_PKEY_DELETE));
- check(rpc_encode_int(&optr, olimit, pkey.handle));
- check(rpc_send(outbuf, optr - outbuf));
+ check(hal_xdr_encode_int(&optr, olimit, RPC_FUNC_PKEY_DELETE));
+ check(hal_xdr_encode_int(&optr, olimit, pkey.handle));
+ check(hal_rpc_send(outbuf, optr - outbuf));
- check(rpc_recv(inbuf, &ilen));
+ check(hal_rpc_recv(inbuf, &ilen));
assert(ilen <= sizeof(inbuf));
- check(rpc_decode_int(&iptr, ilimit, &rpc_ret));
+ check(hal_xdr_decode_int(&iptr, ilimit, &rpc_ret));
return rpc_ret;
}
@@ -477,15 +499,15 @@ static hal_error_t pkey_get_key_type(const hal_pkey_handle_t pkey,
uint32_t type32;
hal_error_t ret, rpc_ret;
- check(rpc_encode_int(&optr, olimit, RPC_FUNC_PKEY_GET_KEY_TYPE));
- check(rpc_encode_int(&optr, olimit, pkey.handle));
- check(rpc_send(outbuf, optr - outbuf));
+ check(hal_xdr_encode_int(&optr, olimit, RPC_FUNC_PKEY_GET_KEY_TYPE));
+ check(hal_xdr_encode_int(&optr, olimit, pkey.handle));
+ check(hal_rpc_send(outbuf, optr - outbuf));
- check(rpc_recv(inbuf, &ilen));
+ check(hal_rpc_recv(inbuf, &ilen));
assert(ilen <= sizeof(inbuf));
- check(rpc_decode_int(&iptr, ilimit, &rpc_ret));
+ check(hal_xdr_decode_int(&iptr, ilimit, &rpc_ret));
if (rpc_ret == HAL_OK) {
- check(rpc_decode_int(&iptr, ilimit, &type32));
+ check(hal_xdr_decode_int(&iptr, ilimit, &type32));
*type = (hal_key_type_t)type32;
}
return rpc_ret;
@@ -500,15 +522,15 @@ static hal_error_t pkey_get_key_flags(const hal_pkey_handle_t pkey,
uint32_t flags32;
hal_error_t ret, rpc_ret;
- check(rpc_encode_int(&optr, olimit, RPC_FUNC_PKEY_GET_KEY_FLAGS));
- check(rpc_encode_int(&optr, olimit, pkey.handle));
- check(rpc_send(outbuf, optr - outbuf));
+ check(hal_xdr_encode_int(&optr, olimit, RPC_FUNC_PKEY_GET_KEY_FLAGS));
+ check(hal_xdr_encode_int(&optr, olimit, pkey.handle));
+ check(hal_rpc_send(outbuf, optr - outbuf));
- check(rpc_recv(inbuf, &ilen));
+ check(hal_rpc_recv(inbuf, &ilen));
assert(ilen <= sizeof(inbuf));
- check(rpc_decode_int(&iptr, ilimit, &rpc_ret));
+ check(hal_xdr_decode_int(&iptr, ilimit, &rpc_ret));
if (rpc_ret == HAL_OK) {
- check(rpc_decode_int(&iptr, ilimit, &flags32));
+ check(hal_xdr_decode_int(&iptr, ilimit, &flags32));
*flags = (hal_key_flags_t)flags32;
}
return rpc_ret;
@@ -522,15 +544,15 @@ static size_t pkey_get_public_key_len(const hal_pkey_handle_t pkey)
uint32_t len32;
hal_error_t ret, rpc_ret;
- check(rpc_encode_int(&optr, olimit, RPC_FUNC_PKEY_GET_PUBLIC_KEY_LEN));
- check(rpc_encode_int(&optr, olimit, pkey.handle));
- check(rpc_send(outbuf, optr - outbuf));
+ check(hal_xdr_encode_int(&optr, olimit, RPC_FUNC_PKEY_GET_PUBLIC_KEY_LEN));
+ check(hal_xdr_encode_int(&optr, olimit, pkey.handle));
+ check(hal_rpc_send(outbuf, optr - outbuf));
- check(rpc_recv(inbuf, &ilen));
+ check(hal_rpc_recv(inbuf, &ilen));
assert(ilen <= sizeof(inbuf));
- check(rpc_decode_int(&iptr, ilimit, &rpc_ret));
+ check(hal_xdr_decode_int(&iptr, ilimit, &rpc_ret));
if (rpc_ret == HAL_OK) {
- check(rpc_decode_int(&iptr, ilimit, &len32));
+ check(hal_xdr_decode_int(&iptr, ilimit, &len32));
return (size_t)len32;
}
else
@@ -546,16 +568,16 @@ static hal_error_t pkey_get_public_key(const hal_pkey_handle_t pkey,
uint32_t dlen32 = der_max;
hal_error_t ret, rpc_ret;
- check(rpc_encode_int(&optr, olimit, RPC_FUNC_PKEY_GET_PUBLIC_KEY));
- check(rpc_encode_int(&optr, olimit, pkey.handle));
- check(rpc_encode_int(&optr, olimit, der_max));
- check(rpc_send(outbuf, optr - outbuf));
+ check(hal_xdr_encode_int(&optr, olimit, RPC_FUNC_PKEY_GET_PUBLIC_KEY));
+ check(hal_xdr_encode_int(&optr, olimit, pkey.handle));
+ check(hal_xdr_encode_int(&optr, olimit, der_max));
+ check(hal_rpc_send(outbuf, optr - outbuf));
- check(rpc_recv(inbuf, &ilen));
+ check(hal_rpc_recv(inbuf, &ilen));
assert(ilen <= sizeof(inbuf));
- check(rpc_decode_int(&iptr, ilimit, &rpc_ret));
+ check(hal_xdr_decode_int(&iptr, ilimit, &rpc_ret));
if (rpc_ret == HAL_OK) {
- check(rpc_decode_buffer(&iptr, ilimit, der, &dlen32));
+ check(hal_xdr_decode_buffer(&iptr, ilimit, der, &dlen32));
*der_len = (size_t)dlen32;
}
return rpc_ret;
@@ -573,19 +595,19 @@ static hal_error_t pkey_remote_sign(const hal_session_handle_t session,
uint32_t slen32 = signature_max;
hal_error_t ret, rpc_ret;
- check(rpc_encode_int(&optr, olimit, RPC_FUNC_PKEY_REMOTE_SIGN));
- check(rpc_encode_int(&optr, olimit, session.handle));
- check(rpc_encode_int(&optr, olimit, pkey.handle));
- check(rpc_encode_int(&optr, olimit, hash.handle));
- check(rpc_encode_buffer(&optr, olimit, input, input_len));
- check(rpc_encode_int(&optr, olimit, signature_max));
- check(rpc_send(outbuf, optr - outbuf));
+ check(hal_xdr_encode_int(&optr, olimit, RPC_FUNC_PKEY_REMOTE_SIGN));
+ check(hal_xdr_encode_int(&optr, olimit, session.handle));
+ check(hal_xdr_encode_int(&optr, olimit, pkey.handle));
+ check(hal_xdr_encode_int(&optr, olimit, hash.handle));
+ check(hal_xdr_encode_buffer(&optr, olimit, input, input_len));
+ check(hal_xdr_encode_int(&optr, olimit, signature_max));
+ check(hal_rpc_send(outbuf, optr - outbuf));
- check(rpc_recv(inbuf, &ilen));
+ check(hal_rpc_recv(inbuf, &ilen));
assert(ilen <= sizeof(inbuf));
- check(rpc_decode_int(&iptr, ilimit, &rpc_ret));
+ check(hal_xdr_decode_int(&iptr, ilimit, &rpc_ret));
if (rpc_ret == HAL_OK) {
- check(rpc_decode_buffer(&iptr, ilimit, signature, &slen32));
+ check(hal_xdr_decode_buffer(&iptr, ilimit, signature, &slen32));
*signature_len = (size_t)slen32;
}
return rpc_ret;
@@ -602,29 +624,29 @@ static hal_error_t pkey_remote_verify(const hal_session_handle_t session,
size_t ilen = sizeof(inbuf);
hal_error_t ret, rpc_ret;
- check(rpc_encode_int(&optr, olimit, RPC_FUNC_PKEY_REMOTE_VERIFY));
- check(rpc_encode_int(&optr, olimit, session.handle));
- check(rpc_encode_int(&optr, olimit, pkey.handle));
- check(rpc_encode_int(&optr, olimit, hash.handle));
- check(rpc_encode_buffer(&optr, olimit, input, input_len));
- check(rpc_encode_buffer(&optr, olimit, signature, signature_len));
- check(rpc_send(outbuf, optr - outbuf));
+ check(hal_xdr_encode_int(&optr, olimit, RPC_FUNC_PKEY_REMOTE_VERIFY));
+ check(hal_xdr_encode_int(&optr, olimit, session.handle));
+ check(hal_xdr_encode_int(&optr, olimit, pkey.handle));
+ check(hal_xdr_encode_int(&optr, olimit, hash.handle));
+ check(hal_xdr_encode_buffer(&optr, olimit, input, input_len));
+ check(hal_xdr_encode_buffer(&optr, olimit, signature, signature_len));
+ check(hal_rpc_send(outbuf, optr - outbuf));
- check(rpc_recv(inbuf, &ilen));
+ check(hal_rpc_recv(inbuf, &ilen));
assert(ilen <= sizeof(inbuf));
- check(rpc_decode_int(&iptr, ilimit, &rpc_ret));
+ check(hal_xdr_decode_int(&iptr, ilimit, &rpc_ret));
return rpc_ret;
}
-static hal_error_t rpc_decode_pkey_info(uint8_t **iptr, const uint8_t * const ilimit, hal_pkey_info_t *info)
+static hal_error_t hal_xdr_decode_pkey_info(uint8_t **iptr, const uint8_t * const ilimit, hal_pkey_info_t *info)
{
uint32_t i32;
hal_error_t ret;
- check(rpc_decode_int(iptr, ilimit, &i32)); info->type = i32;
- check(rpc_decode_int(iptr, ilimit, &i32)); info->curve = i32;
- check(rpc_decode_int(iptr, ilimit, &i32)); info->flags = i32;
- check(rpc_decode_buffer(iptr, ilimit, (uint8_t *)&info->name[0], &i32)); info->name_len = i32;
+ check(hal_xdr_decode_int(iptr, ilimit, &i32)); info->type = i32;
+ check(hal_xdr_decode_int(iptr, ilimit, &i32)); info->curve = i32;
+ check(hal_xdr_decode_int(iptr, ilimit, &i32)); info->flags = i32;
+ check(hal_xdr_decode_buffer(iptr, ilimit, (uint8_t *)&info->name[0], &i32)); info->name_len = i32;
return HAL_OK;
}
@@ -638,19 +660,19 @@ static hal_error_t pkey_list(hal_pkey_info_t *result,
uint32_t len;
hal_error_t ret, rpc_ret;
- check(rpc_encode_int(&optr, olimit, RPC_FUNC_PKEY_LIST));
- check(rpc_encode_int(&optr, olimit, result_max));
- check(rpc_send(outbuf, optr - outbuf));
+ check(hal_xdr_encode_int(&optr, olimit, RPC_FUNC_PKEY_LIST));
+ check(hal_xdr_encode_int(&optr, olimit, result_max));
+ check(hal_rpc_send(outbuf, optr - outbuf));
- check(rpc_recv(inbuf, &ilen));
+ check(hal_rpc_recv(inbuf, &ilen));
assert(ilen <= sizeof(inbuf));
- check(rpc_decode_int(&iptr, ilimit, &rpc_ret));
+ check(hal_xdr_decode_int(&iptr, ilimit, &rpc_ret));
if (rpc_ret == HAL_OK) {
int i;
- check(rpc_decode_int(&iptr, ilimit, &len));
+ check(hal_xdr_decode_int(&iptr, ilimit, &len));
*result_len = len;
for (i = 0; i < len; ++i) {
- if ((ret = rpc_decode_pkey_info(&iptr, ilimit, &result[i])) != HAL_OK) {
+ if ((ret = hal_xdr_decode_pkey_info(&iptr, ilimit, &result[i])) != HAL_OK) {
*result_len = 0;
return ret;
}
@@ -726,7 +748,7 @@ static hal_error_t pkey_mixed_verify(const hal_session_handle_t session,
*/
const hal_rpc_misc_dispatch_t hal_rpc_remote_misc_dispatch = {
- set_pin, login, logout, logout_all, is_logged_in, get_random
+ set_pin, login, logout, logout_all, is_logged_in, get_random, get_version
};
const hal_rpc_hash_dispatch_t hal_rpc_remote_hash_dispatch = {
@@ -748,37 +770,38 @@ const hal_rpc_pkey_dispatch_t hal_rpc_mixed_pkey_dispatch = {
pkey_list
};
-const hal_rpc_misc_dispatch_t * hal_rpc_misc_dispatch;
-const hal_rpc_hash_dispatch_t * hal_rpc_hash_dispatch;
-const hal_rpc_pkey_dispatch_t * hal_rpc_pkey_dispatch;
-
-hal_error_t rpc_client_init(rpc_locality_t locality)
+#endif
+
+#if RPC_CLIENT == RPC_CLIENT_LOCAL
+const hal_rpc_misc_dispatch_t * hal_rpc_misc_dispatch = &hal_rpc_local_misc_dispatch;
+const hal_rpc_hash_dispatch_t * hal_rpc_hash_dispatch = &hal_rpc_local_hash_dispatch;
+const hal_rpc_pkey_dispatch_t * hal_rpc_pkey_dispatch = &hal_rpc_local_pkey_dispatch;
+#elif RPC_CLIENT == RPC_CLIENT_REMOTE
+const hal_rpc_misc_dispatch_t * hal_rpc_misc_dispatch = &hal_rpc_remote_misc_dispatch;
+const hal_rpc_hash_dispatch_t * hal_rpc_hash_dispatch = &hal_rpc_remote_hash_dispatch;
+const hal_rpc_pkey_dispatch_t * hal_rpc_pkey_dispatch = &hal_rpc_remote_pkey_dispatch;
+#elif RPC_CLIENT == RPC_CLIENT_MIXED
+const hal_rpc_misc_dispatch_t * hal_rpc_misc_dispatch = &hal_rpc_remote_misc_dispatch;
+const hal_rpc_hash_dispatch_t * hal_rpc_hash_dispatch = &hal_rpc_remote_hash_dispatch; //mixed?
+const hal_rpc_pkey_dispatch_t * hal_rpc_pkey_dispatch = &hal_rpc_mixed_pkey_dispatch;
+#endif
+
+hal_error_t hal_rpc_client_init(void)
{
- switch (locality) {
- case RPC_LOCAL:
- hal_rpc_misc_dispatch = &hal_rpc_local_misc_dispatch;
- hal_rpc_hash_dispatch = &hal_rpc_local_hash_dispatch;
- hal_rpc_pkey_dispatch = &hal_rpc_local_pkey_dispatch;
- break;
- case RPC_REMOTE:
- hal_rpc_misc_dispatch = &hal_rpc_remote_misc_dispatch;
- hal_rpc_hash_dispatch = &hal_rpc_remote_hash_dispatch;
- hal_rpc_pkey_dispatch = &hal_rpc_remote_pkey_dispatch;
- break;
- case RPC_MIXED:
- hal_rpc_misc_dispatch = &hal_rpc_remote_misc_dispatch;
- hal_rpc_hash_dispatch = &hal_rpc_remote_hash_dispatch;
- hal_rpc_pkey_dispatch = &hal_rpc_mixed_pkey_dispatch;
- break;
- default:
- return HAL_ERROR_BAD_ARGUMENTS;
- }
- return rpc_client_transport_init();
+#if RPC_CLIENT == RPC_CLIENT_LOCAL
+ return HAL_OK;
+#else
+ return hal_rpc_client_transport_init();
+#endif
}
-hal_error_t rpc_client_close(void)
+hal_error_t hal_rpc_client_close(void)
{
- return rpc_client_transport_close();
+#if RPC_CLIENT == RPC_CLIENT_LOCAL
+ return HAL_OK;
+#else
+ return hal_rpc_client_transport_close();
+#endif
}