summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2017-08-03 21:16:00 +0200
committerUros Majstorovic <majstor@majstor.org>2017-08-03 21:16:00 +0200
commitf33714d52452dd19781785ca3cdf3cbd2cce6212 (patch)
tree55c43e9116bcefb4915d8cd1b3ee38560294b018
parent72520c7339f04849633114d9dca644e32f85e9fb (diff)
proxy inteface removed; ctx has pack and pack_raw methods
-rw-r--r--code/core/core.c35
-rw-r--r--code/core/core.h12
-rw-r--r--code/proxy/proxy.c48
3 files changed, 45 insertions, 50 deletions
diff --git a/code/core/core.c b/code/core/core.c
index 544f896..7a24d96 100644
--- a/code/core/core.c
+++ b/code/core/core.c
@@ -33,6 +33,9 @@ int ecp_ctx_create(ECPContext *ctx) {
memset(ctx, 0, sizeof(ECPContext));
+ ctx->pack = ecp_conn_pack;
+ ctx->pack_raw = ecp_pack_raw;
+
rv = ecp_crypto_init(&ctx->cr);
if (rv) return rv;
#ifdef ECP_WITH_HTABLE
@@ -869,6 +872,12 @@ ssize_t ecp_pack(ECPContext *ctx, unsigned char *packet, size_t pkt_size, unsign
return rv+ECP_SIZE_PKT_HDR;
}
+
+ssize_t ecp_pack_raw(ECPSocket *sock, ECPConnection *proxy, ECPNetAddr *addr, unsigned char *packet, size_t pkt_size, unsigned char s_idx, unsigned char c_idx, ecp_dh_public_t *public, ecp_aead_key_t *shsec, unsigned char *nonce, ecp_seq_t seq, unsigned char *payload, size_t payload_size) {
+ ECPContext *ctx = sock->ctx;
+
+ return ecp_pack(ctx, packet, pkt_size, s_idx, c_idx, public, shsec, nonce, seq, payload, payload_size);
+}
ssize_t ecp_conn_pack(ECPConnection *conn, ECPNetAddr *addr, ecp_seq_t *seq, unsigned char *packet, size_t pkt_size, unsigned char s_idx, unsigned char c_idx, unsigned char *payload, size_t payload_size) {
ecp_aead_key_t shsec;
@@ -934,26 +943,6 @@ ssize_t ecp_conn_pack(ECPConnection *conn, ECPNetAddr *addr, ecp_seq_t *seq, uns
return _rv;
}
-ssize_t ecp_proxy_pack(ECPConnection *conn, ECPNetAddr *addr, ecp_seq_t *seq, unsigned char *packet, size_t pkt_size, unsigned char s_idx, unsigned char c_idx, unsigned char *payload, size_t payload_size) {
- ECPContext *ctx = conn->sock->ctx;
-
- if (conn->proxy && ctx->pr.init) {
- return ctx->pr.pack(conn, addr, seq, packet, pkt_size, s_idx, c_idx, payload, payload_size);
- } else {
- return ecp_conn_pack(conn, addr, seq, packet, pkt_size, s_idx, c_idx, payload, payload_size);
- }
-}
-
-ssize_t ecp_proxy_pack_raw(ECPSocket *sock, ECPConnection *proxy, ECPNetAddr *addr, unsigned char *packet, size_t pkt_size, unsigned char s_idx, unsigned char c_idx, ecp_dh_public_t *public, ecp_aead_key_t *shsec, unsigned char *nonce, ecp_seq_t seq, unsigned char *payload, size_t payload_size) {
- ECPContext *ctx = sock->ctx;
-
- if (proxy && ctx->pr.init) {
- return ctx->pr.pack_raw(proxy, addr, packet, pkt_size, s_idx, c_idx, public, shsec, nonce, seq, payload, payload_size);
- } else {
- return ecp_pack(ctx, packet, pkt_size, s_idx, c_idx, public, shsec, nonce, seq, payload, payload_size);
- }
-}
-
ssize_t ecp_pkt_handle(ECPSocket *sock, ECPNetAddr *addr, ECPConnection *proxy, unsigned char *packet, size_t pkt_size) {
unsigned char s_idx;
unsigned char c_idx;
@@ -1216,10 +1205,11 @@ ssize_t ecp_pld_send(ECPConnection *conn, unsigned char *payload, size_t payload
ssize_t ecp_pld_send_wkey(ECPConnection *conn, ecp_seq_t *seq, unsigned char s_idx, unsigned char c_idx, unsigned char *payload, size_t payload_size) {
unsigned char packet[ECP_MAX_PKT];
ECPSocket *sock = conn->sock;
+ ECPContext *ctx = sock->ctx;
ECPNetAddr addr;
ssize_t rv;
- rv = ecp_proxy_pack(conn, &addr, seq, packet, ECP_MAX_PKT, s_idx, c_idx, payload, payload_size);
+ rv = ctx->pack(conn, &addr, seq, packet, ECP_MAX_PKT, s_idx, c_idx, payload, payload_size);
if (rv < 0) return rv;
#ifdef ECP_WITH_RBUF
@@ -1233,10 +1223,11 @@ ssize_t ecp_pld_send_wkey(ECPConnection *conn, ecp_seq_t *seq, unsigned char s_i
ssize_t ecp_pld_send_raw(ECPSocket *sock, ECPConnection *proxy, ECPNetAddr *addr, unsigned char s_idx, unsigned char c_idx, ecp_dh_public_t *public, ecp_aead_key_t *shsec, unsigned char *nonce, ecp_seq_t seq, unsigned char *payload, size_t payload_size) {
unsigned char packet[ECP_MAX_PKT];
+ ECPContext *ctx = sock->ctx;
ECPNetAddr _addr;
ssize_t rv;
- rv = ecp_proxy_pack_raw(sock, proxy, &_addr, packet, ECP_MAX_PKT, s_idx, c_idx, public, shsec, nonce, seq, payload, payload_size);
+ rv = ctx->pack_raw(sock, proxy, &_addr, packet, ECP_MAX_PKT, s_idx, c_idx, public, shsec, nonce, seq, payload, payload_size);
if (rv < 0) return rv;
return ecp_pkt_send(sock, proxy ? &_addr : addr, packet, rv);
diff --git a/code/core/core.h b/code/core/core.h
index 9cf3cf2..2dd7951 100644
--- a/code/core/core.h
+++ b/code/core/core.h
@@ -163,12 +163,6 @@ typedef struct ECPTimeIface {
void (*sleep_ms) (unsigned int);
} ECPTimeIface;
-typedef struct ECPProxyIface {
- int init;
- ssize_t (*pack) (struct ECPConnection *conn, ECPNetAddr *addr, ecp_seq_t *seq, unsigned char *packet, size_t pkt_size, unsigned char s_idx, unsigned char c_idx, unsigned char *payload, size_t payload_size);
- ssize_t (*pack_raw) (struct ECPConnection *proxy, ECPNetAddr *addr, unsigned char *packet, size_t pkt_size, unsigned char s_idx, unsigned char c_idx, ecp_dh_public_t *public, ecp_aead_key_t *shsec, unsigned char *nonce, ecp_seq_t seq, unsigned char *payload, size_t payload_size);
-} ECPProxyIface;
-
typedef struct ECPDHKey {
ecp_dh_public_t public;
ecp_dh_private_t private;
@@ -220,7 +214,8 @@ typedef struct ECPContext {
ECPHTableIface ht;
ECPTransportIface tr;
ECPTimeIface tm;
- ECPProxyIface pr;
+ ssize_t (*pack) (struct ECPConnection *conn, ECPNetAddr *addr, ecp_seq_t *seq, unsigned char *packet, size_t pkt_size, unsigned char s_idx, unsigned char c_idx, unsigned char *payload, size_t payload_size);
+ ssize_t (*pack_raw) (struct ECPSocket *sock, struct ECPConnection *proxy, ECPNetAddr *addr, unsigned char *packet, size_t pkt_size, unsigned char s_idx, unsigned char c_idx, ecp_dh_public_t *public, ecp_aead_key_t *shsec, unsigned char *nonce, ecp_seq_t seq, unsigned char *payload, size_t payload_size);
ECPConnHandler *handler[ECP_MAX_CTYPE];
} ECPContext;
@@ -312,9 +307,8 @@ int ecp_conn_dhkey_new_pub(ECPConnection *conn, unsigned char idx, unsigned char
int ecp_conn_dhkey_get_curr(ECPConnection *conn, unsigned char *idx, unsigned char *public);
ssize_t ecp_pack(ECPContext *ctx, unsigned char *packet, size_t pkt_size, unsigned char s_idx, unsigned char c_idx, ecp_dh_public_t *public, ecp_aead_key_t *shsec, unsigned char *nonce, ecp_seq_t seq, unsigned char *payload, size_t payload_size);
+ssize_t ecp_pack_raw(ECPSocket *sock, ECPConnection *proxy, ECPNetAddr *addr, unsigned char *packet, size_t pkt_size, unsigned char s_idx, unsigned char c_idx, ecp_dh_public_t *public, ecp_aead_key_t *shsec, unsigned char *nonce, ecp_seq_t seq, unsigned char *payload, size_t payload_size);
ssize_t ecp_conn_pack(ECPConnection *conn, ECPNetAddr *addr, ecp_seq_t *seq, unsigned char *packet, size_t pkt_size, unsigned char s_idx, unsigned char c_idx, unsigned char *payload, size_t payload_size);
-ssize_t ecp_proxy_pack(ECPConnection *conn, ECPNetAddr *addr, ecp_seq_t *seq, unsigned char *packet, size_t pkt_size, unsigned char s_idx, unsigned char c_idx, unsigned char *payload, size_t payload_size);
-ssize_t ecp_proxy_pack_raw(ECPSocket *sock, ECPConnection *proxy, ECPNetAddr *addr, unsigned char *packet, size_t pkt_size, unsigned char s_idx, unsigned char c_idx, ecp_dh_public_t *public, ecp_aead_key_t *shsec, unsigned char *nonce, ecp_seq_t seq, unsigned char *payload, size_t payload_size);
ssize_t ecp_pkt_handle(ECPSocket *sock, ECPNetAddr *addr, ECPConnection *proxy, unsigned char *packet, size_t pkt_size);
ssize_t ecp_pkt_send(ECPSocket *sock, ECPNetAddr *addr, unsigned char *packet, size_t pkt_size);
diff --git a/code/proxy/proxy.c b/code/proxy/proxy.c
index 583445f..67d4d01 100644
--- a/code/proxy/proxy.c
+++ b/code/proxy/proxy.c
@@ -362,30 +362,41 @@ static ssize_t proxy_set_msg(ECPConnection *conn, unsigned char *pld_out, size_t
return ECP_SIZE_MSG_HDR;
}
+
static ssize_t proxy_pack(ECPConnection *conn, ECPNetAddr *addr, ecp_seq_t *seq, unsigned char *packet, size_t pkt_size, unsigned char s_idx, unsigned char c_idx, unsigned char *payload, size_t payload_size) {
ECPContext *ctx = conn->sock->ctx;
- unsigned char payload_[ECP_MAX_PLD];
- ecp_seq_t _seq;
- ssize_t rv, hdr_size = proxy_set_msg(conn->proxy, payload_, sizeof(payload_), payload, payload_size);
- if (hdr_size < 0) return hdr_size;
- rv = ecp_conn_pack(conn, NULL, &_seq, payload_+hdr_size, ECP_MAX_PLD-hdr_size, s_idx, c_idx, payload, payload_size);
- if (rv < 0) return rv;
+ if (conn->proxy) {
+ unsigned char payload_[ECP_MAX_PLD];
+ ecp_seq_t _seq;
+ ssize_t rv, hdr_size = proxy_set_msg(conn->proxy, payload_, sizeof(payload_), payload, payload_size);
+ if (hdr_size < 0) return hdr_size;
+
+ rv = ecp_conn_pack(conn, NULL, &_seq, payload_+hdr_size, ECP_MAX_PLD-hdr_size, s_idx, c_idx, payload, payload_size);
+ if (rv < 0) return rv;
- return ecp_proxy_pack(conn->proxy, addr, seq, packet, pkt_size, ECP_ECDH_IDX_INV, ECP_ECDH_IDX_INV, payload_, rv+hdr_size);
+ return proxy_pack(conn->proxy, addr, seq, packet, pkt_size, ECP_ECDH_IDX_INV, ECP_ECDH_IDX_INV, payload_, rv+hdr_size);
+ } else {
+ return ecp_conn_pack(conn, addr, seq, packet, pkt_size, s_idx, c_idx, payload, payload_size);
+ }
}
-static ssize_t proxy_pack_raw(ECPConnection *proxy, ECPNetAddr *addr, unsigned char *packet, size_t pkt_size, unsigned char s_idx, unsigned char c_idx, ecp_dh_public_t *public, ecp_aead_key_t *shsec, unsigned char *nonce, ecp_seq_t seq, unsigned char *payload, size_t payload_size) {
- ECPContext *ctx = proxy->sock->ctx;
- unsigned char payload_[ECP_MAX_PLD];
- ecp_seq_t _seq;
- ssize_t rv, hdr_size = proxy_set_msg(proxy, payload_, sizeof(payload_), payload, payload_size);
- if (hdr_size < 0) return hdr_size;
+static ssize_t proxy_pack_raw(ECPSocket *sock, ECPConnection *proxy, ECPNetAddr *addr, unsigned char *packet, size_t pkt_size, unsigned char s_idx, unsigned char c_idx, ecp_dh_public_t *public, ecp_aead_key_t *shsec, unsigned char *nonce, ecp_seq_t seq, unsigned char *payload, size_t payload_size) {
+ ECPContext *ctx = sock->ctx;
- rv = ecp_pack(ctx, payload_+hdr_size, ECP_MAX_PLD-hdr_size, s_idx, c_idx, public, shsec, nonce, seq, payload, payload_size);
- if (rv < 0) return rv;
+ if (proxy) {
+ unsigned char payload_[ECP_MAX_PLD];
+ ecp_seq_t _seq;
+ ssize_t rv, hdr_size = proxy_set_msg(proxy, payload_, sizeof(payload_), payload, payload_size);
+ if (hdr_size < 0) return hdr_size;
+
+ rv = ecp_pack(ctx, payload_+hdr_size, ECP_MAX_PLD-hdr_size, s_idx, c_idx, public, shsec, nonce, seq, payload, payload_size);
+ if (rv < 0) return rv;
- return ecp_proxy_pack(proxy, addr, &_seq, packet, pkt_size, ECP_ECDH_IDX_INV, ECP_ECDH_IDX_INV, payload_, rv+hdr_size);
+ return proxy_pack(proxy, addr, &_seq, packet, pkt_size, ECP_ECDH_IDX_INV, ECP_ECDH_IDX_INV, payload_, rv+hdr_size);
+ } else {
+ return ecp_pack(ctx, packet, pkt_size, s_idx, c_idx, public, shsec, nonce, seq, payload, payload_size);
+ }
}
int ecp_proxy_init(ECPContext *ctx) {
@@ -413,9 +424,8 @@ int ecp_proxy_init(ECPContext *ctx) {
handler_b.msg[ECP_MTYPE_RELAY] = proxyb_handle_relay;
ctx->handler[ECP_CTYPE_PROXYB] = &handler_b;
- ctx->pr.init = 1;
- ctx->pr.pack = proxy_pack;
- ctx->pr.pack_raw = proxy_pack_raw;
+ ctx->pack = proxy_pack;
+ ctx->pack_raw = proxy_pack_raw;
#ifdef ECP_WITH_PTHREAD
pthread_mutex_init(&key_perma_mutex, NULL);