X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fsptps.c;h=eeaf833ece81de30f3b5f3ed5d5b2ca4ded11456;hb=c33dd41c07c4c4578f546798264b7f467d6a7866;hp=93a7ad3ff1e9037d9846ecbd56dfae66813589e5;hpb=f6e87ab476a0faf8b124ecaaa27f967d825e6457;p=tinc diff --git a/src/sptps.c b/src/sptps.c index 93a7ad3f..eeaf833e 100644 --- a/src/sptps.c +++ b/src/sptps.c @@ -51,9 +51,16 @@ unsigned int sptps_replaywin = 16; */ void sptps_log_quiet(sptps_t *s, int s_errno, const char *format, va_list ap) { + (void)s; + (void)s_errno; + (void)format; + (void)ap; } void sptps_log_stderr(sptps_t *s, int s_errno, const char *format, va_list ap) { + (void)s; + (void)s_errno; + vfprintf(stderr, format, ap); fputc('\n', stderr); } @@ -62,6 +69,9 @@ void (*sptps_log)(sptps_t *s, int s_errno, const char *format, va_list ap) = spt // Log an error message. static bool error(sptps_t *s, int s_errno, const char *format, ...) { + (void)s; + (void)s_errno; + if(format) { va_list ap; va_start(ap, format); @@ -244,6 +254,8 @@ static bool send_ack(sptps_t *s) { // Receive an ACKnowledgement record. static bool receive_ack(sptps_t *s, const char *data, uint16_t len) { + (void)data; + if(len) { return error(s, EIO, "Invalid ACK record length"); } @@ -287,7 +299,11 @@ static bool receive_kex(sptps_t *s, const char *data, uint16_t len) { memcpy(s->hiskex, data, len); - return send_sig(s); + if(s->initiator) { + return send_sig(s); + } else { + return true; + } } // Receive a SIGnature record, verify it, if it passed, compute the shared secret and calculate the session keys. @@ -327,6 +343,10 @@ static bool receive_sig(sptps_t *s, const char *data, uint16_t len) { return false; } + if(!s->initiator && !send_sig(s)) { + return false; + } + free(s->mykex); free(s->hiskex); @@ -373,6 +393,7 @@ static bool receive_handshake(sptps_t *s, const char *data, uint16_t len) { return false; } + // Fall through case SPTPS_KEX: // We have sent our KEX request, we expect our peer to sent one as well. @@ -458,7 +479,7 @@ static bool sptps_check_seqno(sptps_t *s, uint32_t seqno, bool update_state) { } } else if(update_state) { // We missed some packets. Mark them in the bitmap as being late. - for(int i = s->inseqno; i < seqno; i++) { + for(uint32_t i = s->inseqno; i < seqno; i++) { s->late[(i / 8) % s->replaywin] |= 1 << i % 8; } } @@ -487,11 +508,12 @@ static bool sptps_check_seqno(sptps_t *s, uint32_t seqno, bool update_state) { } // Check datagram for valid HMAC -bool sptps_verify_datagram(sptps_t *s, const void *data, size_t len) { +bool sptps_verify_datagram(sptps_t *s, const void *vdata, size_t len) { if(!s->instate || len < 21) { return error(s, EIO, "Received short packet"); } + const char *data = vdata; uint32_t seqno; memcpy(&seqno, data, 4); seqno = ntohl(seqno); @@ -576,7 +598,8 @@ static bool sptps_receive_data_datagram(sptps_t *s, const char *data, size_t len } // Receive incoming data. Check if it contains a complete record, if so, handle it. -size_t sptps_receive_data(sptps_t *s, const void *data, size_t len) { +size_t sptps_receive_data(sptps_t *s, const void *vdata, size_t len) { + const char *data = vdata; size_t total_read = 0; if(!s->state) {