diff --git a/srtcore/core.cpp b/srtcore/core.cpp index 02b0ea1b1..e6da157a5 100644 --- a/srtcore/core.cpp +++ b/srtcore/core.cpp @@ -2629,6 +2629,9 @@ bool srt::CUDT::interpretSrtHandshake(const CHandShake& hs, { // Cryptographic modes mismatch. Not acceptable at all. m_RejectReason = SRT_REJ_CRYPTO; + LOGC(cnlog.Error, + log << CONID() + << "interpretSrtHandshake: KMREQ result: Bad crypto mode - rejecting"); return false; } #endif @@ -3682,11 +3685,23 @@ void srt::CUDT::startConnect(const sockaddr_any& serv_addr, int32_t forced_isn) cst = processRendezvous(&response, serv_addr, RST_OK, (reqpkt)); if (cst == CONN_CONTINUE) continue; - break; + + // Just in case it wasn't set, set this as a fallback + if (m_RejectReason == SRT_REJ_UNKNOWN) + m_RejectReason = SRT_REJ_ROGUE; + + // rejection or erroneous code. + reqpkt.setLength(m_iMaxSRTPayloadSize); + reqpkt.setControl(UMSG_HANDSHAKE); + sendRendezvousRejection(serv_addr, (reqpkt)); } if (cst == CONN_REJECT) + { + HLOGC(cnlog.Debug, + log << CONID() << "startConnect: REJECTED by processConnectResponse - sending SHUTDOWN"); sendCtrl(UMSG_SHUTDOWN); + } if (cst != CONN_CONTINUE && cst != CONN_CONFUSED) break; // --> OUTSIDE-LOOP @@ -3873,6 +3888,11 @@ bool srt::CUDT::processAsyncConnectRequest(EReadStatus rst, LOGC(cnlog.Warn, log << CONID() << "processAsyncConnectRequest: REJECT reported from processRendezvous, not processing further."); + + if (m_RejectReason == SRT_REJ_UNKNOWN) + m_RejectReason = SRT_REJ_ROGUE; + + sendRendezvousRejection(serv_addr, (request)); status = false; } } @@ -3925,6 +3945,24 @@ bool srt::CUDT::processAsyncConnectRequest(EReadStatus rst, return status; } +void srt::CUDT::sendRendezvousRejection(const sockaddr_any& serv_addr, CPacket& r_rsppkt) +{ + // We can reuse m_ConnReq because we are about to abandon the connection process. + m_ConnReq.m_iReqType = URQFailure(m_RejectReason); + + // Assumed that r_rsppkt refers to a packet object that was already prepared + // to be used for storing the handshake there. + size_t size = r_rsppkt.getLength(); + m_ConnReq.store_to((r_rsppkt.m_pcData), (size)); + r_rsppkt.setLength(size); + + HLOGC(cnlog.Debug, log << CONID() << "sendRendezvousRejection: using code=" << m_ConnReq.m_iReqType + << " for reject reason code " << m_RejectReason << " (" << srt_rejectreason_str(m_RejectReason) << ")"); + + setPacketTS(r_rsppkt, steady_clock::now()); + m_pSndQueue->sendto(serv_addr, r_rsppkt, m_SourceAddr); +} + void srt::CUDT::cookieContest() { if (m_SrtHsSide != HSD_DRAW) @@ -4427,7 +4465,25 @@ EConnectStatus srt::CUDT::processConnectResponse(const CPacket& response, CUDTEx << "processConnectResponse: CONFUSED: expected UMSG_HANDSHAKE as connection not yet established, " "got: " << MessageTypeStr(response.getType(), response.getExtendedType())); + + if (response.getType() == UMSG_SHUTDOWN) + { + LOGC(cnlog.Error, + log << CONID() << "processConnectResponse: UMSG_SHUTDOWN received, rejecting connection."); + return CONN_REJECT; + } } + + if (m_config.bRendezvous) + { + // In rendezvous mode we expect that both sides are known + // to the service operator (unlike a listener, which may + // operate connections from unknown sources). This means that + // the connection process should be terminated anyway, on + // whichever side it would happen. + return CONN_REJECT; + } + return CONN_CONFUSED; } diff --git a/srtcore/core.h b/srtcore/core.h index d508c4f7d..ce0e53958 100644 --- a/srtcore/core.h +++ b/srtcore/core.h @@ -485,6 +485,7 @@ class CUDT /// @param rst Current read status to know if the HS packet was freshly received from the peer, or this is only a periodic update (RST_AGAIN) SRT_ATR_NODISCARD SRT_ATTR_REQUIRES(m_ConnectionLock) EConnectStatus processRendezvous(const CPacket* response, const sockaddr_any& serv_addr, EReadStatus, CPacket& reqpkt); + void sendRendezvousRejection(const sockaddr_any& serv_addr, CPacket& request); /// Create the CryptoControl object based on the HS packet. Allocates sender and receiver buffers and loss lists. SRT_ATR_NODISCARD SRT_ATTR_REQUIRES(m_ConnectionLock) diff --git a/srtcore/crypto.cpp b/srtcore/crypto.cpp index eec141ed4..fdd643f22 100644 --- a/srtcore/crypto.cpp +++ b/srtcore/crypto.cpp @@ -57,6 +57,9 @@ std::string KmStateStr(SRT_KM_STATE state) TAKE(SECURING); TAKE(NOSECRET); TAKE(BADSECRET); +#ifdef ENABLE_AEAD_API_PREVIEW + TAKE(BADCRYPTOMODE); +#endif #undef TAKE default: { diff --git a/testing/testmedia.cpp b/testing/testmedia.cpp index fe4b1ef41..34d2bdc9b 100755 --- a/testing/testmedia.cpp +++ b/testing/testmedia.cpp @@ -144,7 +144,7 @@ class FileTarget: public virtual Target { ofile.write(data.payload.data(), data.payload.size()); #ifdef PLEASE_LOG - applog.Debug() << "FileTarget::Write: " << data.size() << " written to a file"; + applog.Debug() << "FileTarget::Write: " << data.payload.size() << " written to a file"; #endif } @@ -1316,7 +1316,8 @@ void SrtCommon::ConnectClient(string host, int port) { int reason = srt_getrejectreason(m_sock); #if PLEASE_LOG - LOGP(applog.Error, "ERROR reported by srt_connect - closing socket @", m_sock); + LOGP(applog.Error, "ERROR reported by srt_connect - closing socket @", m_sock, + " reject reason: ", reason, ": ", srt_rejectreason_str(reason)); #endif if (transmit_retry_connect && (transmit_retry_always || reason == SRT_REJ_TIMEOUT)) { @@ -2379,7 +2380,7 @@ MediaPacket SrtSource::Read(size_t chunk) #if PLEASE_LOG extern srt_logging::Logger applog; LOGC(applog.Debug, log << "recv: #" << mctrl.msgno << " %" << mctrl.pktseq << " " - << BufferStamp(data.data(), stat) << " BELATED: " << ((CTimer::getTime()-mctrl.srctime)/1000.0) << "ms"); + << BufferStamp(data.data(), stat) << " BELATED: " << ((srt_time_now()-mctrl.srctime)/1000.0) << "ms"); #endif Verb() << "(#" << mctrl.msgno << " %" << mctrl.pktseq << " " << BufferStamp(data.data(), stat) << ") " << VerbNoEOL;