#include <utility>
#include <vector>
+#include "ktls.h"
#include "tlse.h"
#include "acceptor.h"
change_epoll_events(client, EPOLLOUT | EPOLLET | EPOLLRDHUP);
}
+namespace {
+
template<class T>
void delete_from(vector<T> *v, T elem)
{
typename vector<T>::iterator new_end = remove(v->begin(), v->end(), elem);
v->erase(new_end, v->end());
}
+
+void send_ktls_close(int sock)
+{
+ uint8_t record_type = 21; // Alert.
+ uint8_t body[] = {
+ 1, // Warning level (but still fatal!).
+ 0, // close_notify.
+ };
+
+ int cmsg_len = sizeof(record_type);
+ char buf[CMSG_SPACE(cmsg_len)];
+
+ msghdr msg = {0};
+ msg.msg_control = buf;
+ msg.msg_controllen = sizeof(buf);
+ cmsghdr *cmsg = CMSG_FIRSTHDR(&msg);
+ cmsg->cmsg_level = SOL_TLS;
+ cmsg->cmsg_type = TLS_SET_RECORD_TYPE;
+ cmsg->cmsg_len = CMSG_LEN(cmsg_len);
+ *CMSG_DATA(cmsg) = record_type;
+ msg.msg_controllen = cmsg->cmsg_len;
+
+ iovec msg_iov;
+ msg_iov.iov_base = body;
+ msg_iov.iov_len = sizeof(body);
+ msg.msg_iov = &msg_iov;
+ msg.msg_iovlen = 1;
+
+ int err;
+ do {
+ err = sendmsg(sock, &msg, 0);
+ } while (err == -1 && errno == EINTR); // Ignore all other errors.
+}
+
+} // namespace
void Server::close_client(Client *client)
{
}
if (client->tls_context) {
+ if (client->in_ktls_mode) {
+ // Keep GnuTLS happy.
+ send_ktls_close(client->sock);
+ }
tls_destroy_context(client->tls_context);
}