#define CHECK_HANDSHAKE_STATE(context, n, limit) { if (context->hs_messages[n] >= limit) { DEBUG_PRINT("* UNEXPECTED MESSAGE (%i)\n", (int)n); payload_res = TLS_UNEXPECTED_MESSAGE; break; } context->hs_messages[n]++; }
+//#define MARK fprintf(stderr, "%s %s:%d\n", __FILE__, __func__, __LINE__)
+#define MARK
typedef enum {
KEA_dhe_dss,
KEA_dhe_rsa,
}
int tls_established(struct TLSContext *context) {
- if (context) {
- if (context->critical_error) {
- return -1;
- }
-
- if (context->connection_status == TLS_CONNECTED) {
- return 1;
- }
- }
- return 0;
+ return context && context->connection_status == TLS_CONNECTED;
}
void tls_read_clear(struct TLSContext *context) {
int res;
ssize_t read_size;
- if (!context || context->fd <= 0 || context->critical_error) {
+ MARK;
+ if (!context || context->fd < 0 || context->critical_error) {
+ if (!context) {
+ MARK;
+ } else if (context->fd < 0) {
+ MARK;
+ } else {
+ MARK;
+ }
+
return TLS_GENERIC_ERROR;
}
+ MARK;
if (context->is_server) {
return TLS_UNEXPECTED_MESSAGE;
}
+ MARK;
res = tls_queue_packet(tls_build_client_hello(context));
+ MARK;
if (res < 0) {
return res;
}
+ MARK;
res = tls_fsync(context);
+ MARK;
if (res < 0) {
return res;
}
return res;
}
}
+ MARK;
if (tls_established(context)) {
return 1;
}
+ MARK;
if (context->critical_error) {
+ fprintf(stderr, "critical error: %d\n",
+ context->critical_error);
return TLS_GENERIC_ERROR;
}
}
+ MARK;
return read_size;
}
return TLS_GENERIC_ERROR;
}
- if (tls_established(context) != 1) {
+ if (!tls_established(context)) {
return TLS_GENERIC_ERROR;
}