cipher_close(&c->outcipher);
digest_close(&c->outdigest);
- stop_sptps(&c->sptps);
+ sptps_stop(&c->sptps);
ecdsa_free(&c->ecdsa);
rsa_free(&c->rsa);
c->name, c->hostname);
if(c->protocol_minor >= 2)
- return send_record(&c->sptps, 0, buffer, length);
+ return sptps_send_record(&c->sptps, 0, buffer, length);
/* Add our data to buffer */
if(c->status.encryptout) {
do {
if(c->protocol_minor >= 2) {
logger(LOG_DEBUG, "Receiving %d bytes of SPTPS data", inlen);
- return receive_data(&c->sptps, bufp, inlen);
+ return sptps_receive_data(&c->sptps, bufp, inlen);
}
if(!c->status.decryptin) {
else
snprintf(label, sizeof label, "tinc TCP key expansion %s %s", c->name, myself->name);
- return start_sptps(&c->sptps, c, c->outgoing, myself->connection->ecdsa, c->ecdsa, label, sizeof label, send_meta_sptps, receive_meta_sptps);
+ return sptps_start(&c->sptps, c, c->outgoing, myself->connection->ecdsa, c->ecdsa, label, sizeof label, send_meta_sptps, receive_meta_sptps);
} else {
return send_metakey(c);
}
}
// Send an application record.
-bool send_record(sptps_t *s, uint8_t type, const char *data, uint16_t len) {
+bool sptps_send_record(sptps_t *s, uint8_t type, const char *data, uint16_t len) {
// Sanity checks: application cannot send data before handshake is finished,
// and only record types 0..127 are allowed.
if(!s->outstate)
}
// Force another Key EXchange (for testing purposes).
-bool force_kex(sptps_t *s) {
+bool sptps_force_kex(sptps_t *s) {
if(!s->outstate || s->state != SPTPS_SECONDARY_KEX)
return error(s, EINVAL, "Cannot force KEX in current state");
}
// Receive incoming data. Check if it contains a complete record, if so, handle it.
-bool receive_data(sptps_t *s, const char *data, size_t len) {
+bool sptps_receive_data(sptps_t *s, const char *data, size_t len) {
while(len) {
// First read the 2 length bytes.
if(s->buflen < 6) {
}
// Start a SPTPS session.
-bool start_sptps(sptps_t *s, void *handle, bool initiator, ecdsa_t mykey, ecdsa_t hiskey, const char *label, size_t labellen, send_data_t send_data, receive_record_t receive_record) {
+bool sptps_start(sptps_t *s, void *handle, bool initiator, ecdsa_t mykey, ecdsa_t hiskey, const char *label, size_t labellen, send_data_t send_data, receive_record_t receive_record) {
// Initialise struct sptps
memset(s, 0, sizeof *s);
}
// Stop a SPTPS session.
-bool stop_sptps(sptps_t *s) {
+bool sptps_stop(sptps_t *s) {
// Clean up any resources.
ecdh_free(&s->ecdh);
free(s->inbuf);
receive_record_t receive_record;
} sptps_t;
-extern bool start_sptps(sptps_t *s, void *handle, bool initiator, ecdsa_t mykey, ecdsa_t hiskey, const char *label, size_t labellen, send_data_t send_data, receive_record_t receive_record);
-extern bool stop_sptps(sptps_t *s);
-extern bool send_record(sptps_t *s, uint8_t type, const char *data, uint16_t len);
-extern bool receive_data(sptps_t *s, const char *data, size_t len);
-extern bool force_kex(sptps_t *s);
+extern bool sptps_start(sptps_t *s, void *handle, bool initiator, ecdsa_t mykey, ecdsa_t hiskey, const char *label, size_t labellen, send_data_t send_data, receive_record_t receive_record);
+extern bool sptps_stop(sptps_t *s);
+extern bool sptps_send_record(sptps_t *s, uint8_t type, const char *data, uint16_t len);
+extern bool sptps_receive_data(sptps_t *s, const char *data, size_t len);
+extern bool sptps_force_kex(sptps_t *s);
#endif
fprintf(stderr, "Keys loaded\n");
sptps_t s;
- if(!start_sptps(&s, &sock, initiator, mykey, hiskey, "sptps_test", 10, send_data, receive_record))
+ if(!sptps_start(&s, &sock, initiator, mykey, hiskey, "sptps_test", 10, send_data, receive_record))
return 1;
while(true) {
if(len == 0)
break;
if(buf[0] == '^')
- send_record(&s, SPTPS_HANDSHAKE, NULL, 0);
+ sptps_send_record(&s, SPTPS_HANDSHAKE, NULL, 0);
else if(buf[0] == '$')
- force_kex(&s);
+ sptps_force_kex(&s);
else
- if(!send_record(&s, buf[0] == '!' ? 1 : 0, buf, buf[0] == '\n' ? 0 : buf[0] == '*' ? sizeof buf : len))
+ if(!sptps_send_record(&s, buf[0] == '!' ? 1 : 0, buf, buf[0] == '\n' ? 0 : buf[0] == '*' ? sizeof buf : len))
return 1;
}
char hex[len * 2 + 1];
bin2hex(buf, hex, len);
fprintf(stderr, "Received %zd bytes of data:\n%s\n", len, hex);
- if(!receive_data(&s, buf, len))
+ if(!sptps_receive_data(&s, buf, len))
return 1;
}
}
+ if(!sptps_stop(&s))
+ return 1;
+
return 0;
}