]> git.meshlink.io Git - meshlink/blobdiff - src/sptps.c
meshlink_start() now fails when the listening socket could not be opened.
[meshlink] / src / sptps.c
index 917b1e209c45cb641e8aa72ef4176b675497199c..ab883027ba79edf75e22db8fce3959681344529d 100644 (file)
@@ -27,7 +27,7 @@
 #include "prf.h"
 #include "sptps.h"
 
-unsigned int sptps_replaywin = 16;
+unsigned int sptps_replaywin = 32;
 
 /*
    Nonce MUST be exchanged first (done)
@@ -371,8 +371,11 @@ static bool receive_handshake(sptps_t *s, const char *data, uint16_t len) {
 
 // Check datagram for valid HMAC
 bool sptps_verify_datagram(sptps_t *s, const void *data, size_t len) {
-       if(!s->instate || len < 21)
-               return error(s, EIO, "Received short packet");
+       if (!s->instate)
+               return error(s, EIO, "SPTPS state not ready to verify this datagram");
+
+       if(len < 21)
+               return error(s, EIO, "Received short packet in sptps_verify_datagram");
 
        uint32_t seqno;
        memcpy(&seqno, data, 4);
@@ -389,7 +392,7 @@ static bool sptps_receive_data_datagram(sptps_t *s, const void *vdata, size_t le
        const char *data = vdata;
 
        if(len < (s->instate ? 21 : 5))
-               return error(s, EIO, "Received short packet");
+               return error(s, EIO, "Received short packet in sptps_receive_data_datagram");
 
        uint32_t seqno;
        memcpy(&seqno, data, 4);
@@ -562,6 +565,9 @@ bool sptps_receive_data(sptps_t *s, const void *data, size_t len) {
 
 // Start a SPTPS session.
 bool sptps_start(sptps_t *s, void *handle, bool initiator, bool datagram, ecdsa_t *mykey, ecdsa_t *hiskey, const char *label, size_t labellen, send_data_t send_data, receive_record_t receive_record) {
+       if(!s || !mykey || !hiskey || !label || !labellen || !send_data || !receive_record)
+               return error(s, EINVAL, "Invalid argument to sptps_start()");
+
        // Initialise struct sptps
        memset(s, 0, sizeof *s);