From 922f1a56b3ef4f59b7c582bfb3ebf771ed81f1df Mon Sep 17 00:00:00 2001 From: Heikki Hannikainen Date: Wed, 26 Jun 2013 00:57:54 +0300 Subject: [PATCH] A little initial work at sending a server signature in an IS2 protocol --- src/Makefile.in | 2 +- src/aprsis2.c | 30 ++++++++++++++++++++++++++++++ src/aprsis2.h | 10 ++++++++++ src/aprsis2.proto | 11 ++++++++--- src/config.c | 3 +++ src/uplink.c | 4 +++- src/version.c | 1 + src/version.h | 1 + src/worker.c | 10 +++++++--- src/worker.h | 1 + 10 files changed, 65 insertions(+), 8 deletions(-) create mode 100644 src/aprsis2.c create mode 100644 src/aprsis2.h diff --git a/src/Makefile.in b/src/Makefile.in index 11911b7..64d3b6c 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -171,7 +171,7 @@ OBJS = aprsc.o accept.o worker.o errno_aprsc.o \ filter.o cellmalloc.o historydb.o \ counterdata.o status.o cJSON.o \ http.o tls.o sctp.o version.o \ - aprsis2.pb-c.o \ + aprsis2.pb-c.o aprsis2.o \ @LIBOBJS@ clean: diff --git a/src/aprsis2.c b/src/aprsis2.c new file mode 100644 index 0000000..40cf222 --- /dev/null +++ b/src/aprsis2.c @@ -0,0 +1,30 @@ + +#include "hmalloc.h" +#include "worker.h" +#include "aprsis2.h" +#include "aprsis2.pb-c.h" +#include "version.h" + +int is2_out_server_signature(struct worker_t *self, struct client_t *c) +{ + ServerSignature sig = SERVER_SIGNATURE__INIT; + void *buf; // Buffer to store serialized data + unsigned len; // Length of serialized data + + sig.app_name = verstr_progname; + sig.app_version = version_build; + len = server_signature__get_packed_size(&sig); + buf = hmalloc(len); + server_signature__pack(&sig, buf); + + c->write(self, c, buf, len); + + hfree(buf); + + return 0; +} + +int is2_in_server_signature(struct worker_t *self, struct client_t *c) +{ + return 0; +} diff --git a/src/aprsis2.h b/src/aprsis2.h new file mode 100644 index 0000000..136530e --- /dev/null +++ b/src/aprsis2.h @@ -0,0 +1,10 @@ + +#ifndef APRSIS2_H +#define APRSIS2_H + +#include "worker.h" + +extern int is2_out_server_signature(struct worker_t *self, struct client_t *c); + +#endif + diff --git a/src/aprsis2.proto b/src/aprsis2.proto index 09adc32..e99cf3b 100644 --- a/src/aprsis2.proto +++ b/src/aprsis2.proto @@ -1,4 +1,9 @@ +message ServerSignature { + required string app_name = 3; + required string app_version = 4; +} + message LoginRequest { required string username = 1; // callsign-SSID optional string password = 2; @@ -9,9 +14,9 @@ message LoginRequest { enum VerificationStatus { NONE = 0; - PASSCODE = 1; - PASSWORD = 2; - CERT = 3; + WEAK = 1; + MEDIUM = 2; + STRONG = 3; } enum LoginResult { diff --git a/src/config.c b/src/config.c index 13260e2..1e2045b 100644 --- a/src/config.c +++ b/src/config.c @@ -950,6 +950,9 @@ int do_listen(struct listen_config_t **lq, int argc, char **argv) clflags |= CLFLAGS_IGATE; } else if (strcasecmp(argv[2], "fullfeed") == 0) { clflags |= CLFLAGS_FULLFEED; + } else if (strcasecmp(argv[2], "is2") == 0) { + clflags |= CLFLAGS_IGATE; + clflags |= CLFLAGS_IS2; } else if (strcasecmp(argv[2], "dupefeed") == 0) { clflags |= CLFLAGS_DUPEFEED; } else if (strcasecmp(argv[2], "clientonly") == 0) { diff --git a/src/uplink.c b/src/uplink.c index 781beee..50ba217 100644 --- a/src/uplink.c +++ b/src/uplink.c @@ -296,7 +296,9 @@ int uplink_login_handler(struct worker_t *self, struct client_t *c, int l4proto, int rc; int argc; char *argv[256]; - + + //if (is2_in_server_signature(self, c, l4proto, s, len) + hlog_packet(LOG_INFO, s, len, "%s: Uplink server software: ", c->addr_rem); #ifdef USE_SSL diff --git a/src/version.c b/src/version.c index ee7619d..be79d18 100644 --- a/src/version.c +++ b/src/version.c @@ -6,6 +6,7 @@ #include "xpoll.h" #include "tls.h" +const char verstr_progname[] = PROGNAME; const char version_build[] = VERSION "-" SRCVERSION VERSION_BRANCH; const char verstr[] = PROGNAME " " VERSION "-" SRCVERSION VERSION_BRANCH; const char verstr_aprsis[] = PROGNAME " " VERSION "-" SRCVERSION VERSION_BRANCH; diff --git a/src/version.h b/src/version.h index 3d9771a..a928211 100644 --- a/src/version.h +++ b/src/version.h @@ -15,6 +15,7 @@ #define APRSC_TOCALL "APSC20" +extern const char verstr_progname[]; extern const char version_build[]; extern const char verstr[]; extern const char verstr_aprsis[]; diff --git a/src/worker.c b/src/worker.c index 7fc6fe7..be2a5b9 100644 --- a/src/worker.c +++ b/src/worker.c @@ -37,7 +37,7 @@ #include "version.h" #include "status.h" #include "sctp.h" - +#include "aprsis2.h" time_t now; /* current time, updated by the main thread, MAY be spun around by NTP */ time_t tick; /* monotonous clock, may or may not be wallclock */ @@ -1584,8 +1584,12 @@ static void collect_new_clients(struct worker_t *self) * In case of a live upgrade, this should maybe be skipped, but * I'll leave it in for now. */ - if (c->flags & CLFLAGS_INPORT) - client_printf(self, c, "# %s\r\n", (fake_version) ? fake_version : verstr_aprsis); + if (c->flags & CLFLAGS_INPORT) { + if (c->flags & CLFLAGS_IS2) + is2_out_server_signature(self, c); + else + client_printf(self, c, "# %s\r\n", (fake_version) ? fake_version : verstr_aprsis); + } /* If the write failed immediately, c is already invalid at this point. Don't touch it. */ } diff --git a/src/worker.h b/src/worker.h index 2f2f3ed..1857589 100644 --- a/src/worker.h +++ b/src/worker.h @@ -344,6 +344,7 @@ struct client_t { #define CLFLAGS_CLIENTONLY 0x800 /* Client connected on client-only port */ #define CLFLAGS_IGATE 0x1000 /* Igate port */ #define CLFLAGS_UPLINKMULTI 0x2000 /* Allow multiple parallel outgoing connections */ +#define CLFLAGS_IS2 0x4000 /* IS2 Protocol Buffers */ #define VALIDATED_WEAK 1 /* client validated with passcode */ #define VALIDATED_STRONG 3 /* client validated with SSL certificate */