Network wrapper protocol as part of the practical master thesis
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

100 lines
2.3 KiB

#include <stdio.h>
#include <string.h>
#include <ecdaa-tpm.h>
#include "client.h"
#define ISSUERIP "127.0.0.1"
#define ISSUERPORT 6590
#define MEMBERIP "127.0.0.1"
#define MEMBERPORT 6591
#define VERIFIERIP "127.0.0.1"
#define VERIFIERPORT 6592
typedef struct member {
struct ecdaa_member_public_key_FP256BN mpk;
} member_t;
typedef enum memberstate {
ON,
JOIN,
APPEND,
JOINED,
ATTEST,
PUBLISH
}memberstate_t;
int process_member_client(int connfd);
int main() {
int err = 0;
client_t *client;
client = client_open(&process_member_client);
if (NULL == client) {
printf("listen failed, closing...\n");
}
for (; !err;) {
err = client_connect(client, ISSUERPORT, ISSUERIP);
if (1 == err) {
printf("graceful shutdown...\n");
} else if (err) {
printf("accept failed, closing...\n");
}
}
printf("shut down client\n");
client_close(client);
return 0;
}
int process_member_client(int connfd) {
char inbuf[MAX_BUFSIZE];
char outbuf[MAX_BUFSIZE];
int n = 0;
memberstate_t state = JOIN;
strncpy(outbuf, "JOIN", 4);
printf("< MEMBER: %s\n", outbuf);
write(connfd, outbuf, sizeof(outbuf));
for (;;) {
bzero(inbuf, MAX_BUFSIZE);
bzero(outbuf, MAX_BUFSIZE);
if (0 >= read(connfd, inbuf, sizeof(inbuf))) {
printf("process_issuer: cannot read from socket\n");
return -1;
}
switch(state) {
case JOIN:
state = APPEND;
break;
case APPEND:
state = JOINED;
break;
case JOINED:
state = ATTEST;
state = PUBLISH;
break;
case ATTEST:
state = JOINED;
break;
case PUBLISH:
break;
}
printf("> MEMBER: %s\n", inbuf);
strncpy(outbuf, "OK", 2);
printf("< MEMBER: %s\n", outbuf);
write(connfd, outbuf, sizeof(outbuf));
if (0 == strncmp("exit", inbuf, 4)) {
printf("process_issuer: exiting gracefully\n");
return 0;
}
if (0 == strncmp("shutdown", inbuf, 8)) {
printf("process_issuer: shutting down gracefully\n");
return 1;
}
}
}