Commit bf2d3be8 authored by jan.koester's avatar jan.koester
Browse files

test

parent 274aa379
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -30,3 +30,7 @@ server_output_aes256.txt
server_output.txt
server_output.txt
server_output.txt
test_aes_ecb
test_quic_keys
test_quic_keys.cpp
test_aes_ecb.cpp
+0 −6
Original line number Diff line number Diff line
@@ -114,12 +114,6 @@ std::vector<uint8_t> HKDF_SHA256::expand_label(const std::vector<uint8_t>& secre
    info.push_back(uint8_t(context.size()));
    info.insert(info.end(), context.begin(), context.end());

    auto out = expand(secret, info, outLen);
    dumpHex("HKDF secret", secret.data(), secret.size(), 64);
    dumpHex("HKDF info", info.data(), info.size(), 64);
    dumpHex("HKDF out", out.data(), out.size(), 64);
    return out;

    return expand(secret, info, outLen);
}

+0 −15
Original line number Diff line number Diff line
@@ -257,10 +257,8 @@ namespace netplus {
        // IO handling (NO DEADLOCK!)
        // ------------------------------------------------------------
        void IoEventHandler(int fd, int events, const int tid, ULONG_PTR args) override {
            std::cerr << "[EPOLL] ===== IoEventHandler called! fd=" << fd << " events=" << events << " EPOLLIN=" << (events & EPOLLIN) << std::endl;
            std::shared_ptr<con> c = getConByFd(fd);
            if (!c || !c->csock) {
                std::cerr << "[EPOLL] No connection found!" << std::endl;
                return;
            }

@@ -277,13 +275,9 @@ namespace netplus {
                try {
                    // Peer closed?
                    if (events & (EPOLLRDHUP | EPOLLHUP | EPOLLERR)) {
                        std::cerr << "[EPOLL] Peer closed: events=" << events << std::endl;
                        needClose = true;
                    }
                    else {
                        std::cerr << "[EPOLL] Event: events=" << events << " EPOLLIN=" << (events & EPOLLIN) 
                                  << " handshakeDone=" << c->csock->getHandshakeDone() << std::endl;
                        
                        // Step 1: If handshake not done and EPOLLIN, read raw TCP data into TLS buffer
                        if ((events & EPOLLIN) && !c->csock->getHandshakeDone() && !needClose) {
                            buffer buf(BLOCKSIZE);
@@ -318,12 +312,10 @@ namespace netplus {

                            // Flush any pending write data
                            if (c->csock->hasPendingWrite()) {
                                std::cerr << "[EPOLL] Flushing pending write data" << std::endl;
                                try {
                                    c->csock->flush_out();
                                } catch (NetException& e) {
                                    if (e.getErrorType() == NetException::Note) {
                                        std::cerr << "[EPOLL] flush_out threw Note, re-arming for write" << std::endl;
                                        setpollEventsFd(fd, EPOLLOUT | EPOLLRDHUP | EPOLLONESHOT);
                                    } else {
                                        throw;
@@ -333,7 +325,6 @@ namespace netplus {

                            // Process any buffered TLS data left in socket buffer
                            while (!c->csock->getHandshakeDone() && c->csock->hasBufferedData()) {
                                std::cerr << "[EPOLL] Processing buffered TLS data" << std::endl;
                                try {
                                    c->csock->handshake_after_accept();
                                } catch (NetException& e) {
@@ -449,11 +440,8 @@ namespace netplus {
                    }

                } catch (NetException& e) {
                    std::cerr << "[EPOLL] Caught NetException: type=" << e.getErrorType() 
                              << " msg=" << e.what() << std::endl;
                    if (e.getErrorType() == NetException::Note){
                        // Only set EPOLLOUT if there's actually pending write data
                        std::cerr << "[EPOLL] It's a Note, re-arming socket" << std::endl;
                        int ev = EPOLLIN | EPOLLRDHUP | EPOLLONESHOT;
                        if (c->csock->hasPendingWrite() || !c->SendData.empty())
                            ev |= EPOLLOUT;
@@ -461,16 +449,13 @@ namespace netplus {
                        setpollEventsFd(fd, ev);
                        return;
                    }
                    std::cerr << "[EPOLL] Exception is not Note, will close" << std::endl;
                    needClose = true;
                } catch (...) {
                    std::cerr << "[EPOLL] Caught unknown exception" << std::endl;
                    needClose = true;
                }
            } // unlock event_mutex

            if (needClose) {
                std::cerr << "[EPOLL] Closing connection" << std::endl;
                rearm.disarm();
                CloseEventHandler(fd, tid, args);
            }
+336 −53

File changed.

Preview size limit exceeded, changes collapsed.

+14 −0
Original line number Diff line number Diff line
@@ -790,6 +790,11 @@ namespace netplus {
		size_t recvData(buffer& data, int flags = 0) override;
		void close() override;
		
		// Handshake handling (for event loop integration)
		void handshake_after_accept() override;
		void pushReceivedData(const uint8_t* data, size_t len) override;
		bool hasBufferedData() const override { return !_recv_buffer.empty(); }

		// QUIC-specific methods
		void setVersion(uint32_t version) { _version = version; }
		uint32_t getVersion() const { return _version; }
@@ -937,6 +942,7 @@ namespace netplus {
		std::vector<uint8_t> _tls_transcript;
		std::vector<uint8_t> _client_random;
		std::vector<uint8_t> _server_random;
		std::vector<uint8_t> _client_session_id;  // Session ID from ClientHello (for echo)
		std::vector<uint8_t> _ecdhe_private;
		std::vector<uint8_t> _ecdhe_public;
		std::vector<uint8_t> _ecdhe_shared;
@@ -948,6 +954,10 @@ namespace netplus {
		std::vector<uint8_t> _crypto_send_initial;
		std::vector<uint8_t> _crypto_send_handshake;

		// Current encryption level for frame processing
		enum class EncryptionLevel { Initial, Handshake, Application };
		EncryptionLevel _current_enc_level = EncryptionLevel::Initial;

		// Streams
		std::map<uint64_t, Stream> _streams;
		uint64_t _next_stream_id_bidi = 0;
@@ -980,6 +990,10 @@ namespace netplus {
		std::map<std::string, ssl::CertificateBundle> _cert_map;
		ssl::CertificateBundle* _selected_cert = nullptr;
		
		// Connection tracking for server mode (maps DCID to child quic*)
		std::map<std::vector<uint8_t>, quic*> _child_connections;
		quic* _parent = nullptr;  // For child connections, pointer to parent listening socket

		// Mutex for thread safety
		mutable std::mutex _quic_mutex;