feat: seal peer sync with X25519 + XChaCha20-Poly1305 (0.9.17)
Encrypt parliament context sync after Realm mutual auth without pulling in OpenSSL. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include <assert.h>
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef struct {
|
||||
@@ -16,6 +17,8 @@ typedef struct {
|
||||
uint8_t realm_pk[32];
|
||||
int ok;
|
||||
char remote_id[64];
|
||||
unsigned long got_rev;
|
||||
char got_ctx[128];
|
||||
} srv_t;
|
||||
|
||||
static void *server_main(void *p) {
|
||||
@@ -26,6 +29,18 @@ static void *server_main(void *p) {
|
||||
5000, &sess, err, sizeof(err)) == 0;
|
||||
if (s->ok) {
|
||||
snprintf(s->remote_id, sizeof(s->remote_id), "%s", sess.remote.instance_id);
|
||||
assert(sess.sealed);
|
||||
cst_peer_sync_bundle_t local = {0};
|
||||
local.revision = 1;
|
||||
snprintf(local.parliament_id, sizeof(local.parliament_id), "parl-s");
|
||||
snprintf(local.project_id, sizeof(local.project_id), "proj");
|
||||
snprintf(local.chair_instance, sizeof(local.chair_instance), "peer-b");
|
||||
local.context = strdup("server-old");
|
||||
assert(cst_peer_sync(&sess, &local, 5000, err, sizeof(err)) == 0);
|
||||
s->got_rev = local.revision;
|
||||
snprintf(s->got_ctx, sizeof(s->got_ctx), "%s",
|
||||
local.context ? local.context : "");
|
||||
free(local.context);
|
||||
cst_peer_close(&sess);
|
||||
}
|
||||
return NULL;
|
||||
@@ -57,10 +72,24 @@ int main(void) {
|
||||
assert(cst_peer_dial("127.0.0.1", port, &ca, ska, realm.pk, 5000, &sess, err,
|
||||
sizeof(err)) == 0);
|
||||
assert(!strcmp(sess.remote.instance_id, "peer-b"));
|
||||
assert(sess.sealed);
|
||||
cst_peer_sync_bundle_t local = {0};
|
||||
local.revision = 9;
|
||||
snprintf(local.parliament_id, sizeof(local.parliament_id), "parl-c");
|
||||
snprintf(local.project_id, sizeof(local.project_id), "proj");
|
||||
snprintf(local.chair_instance, sizeof(local.chair_instance), "peer-a");
|
||||
local.context = strdup("client-wins-secret");
|
||||
assert(cst_peer_sync(&sess, &local, 5000, err, sizeof(err)) == 0);
|
||||
/* Client already has higher rev; stays. */
|
||||
assert(local.revision == 9);
|
||||
assert(strstr(local.context, "client-wins-secret"));
|
||||
free(local.context);
|
||||
cst_peer_close(&sess);
|
||||
pthread_join(th, NULL);
|
||||
assert(srv.ok);
|
||||
assert(!strcmp(srv.remote_id, "peer-a"));
|
||||
assert(srv.got_rev == 9);
|
||||
assert(strstr(srv.got_ctx, "client-wins-secret"));
|
||||
|
||||
/* Foreign realm must fail. */
|
||||
cst_realm_keys_t other;
|
||||
|
||||
Reference in New Issue
Block a user