Skip to content

Commit

Permalink
[api] Socket Options: do not allow AES GCM if TSBPD is disabled.
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsharabayko committed Dec 8, 2022
1 parent 72d135d commit 27e7d8d
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions srtcore/socketconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,17 @@ struct CSrtConfigSetter<SRTO_TSBPDMODE>
{
static void set(CSrtConfig& co, const void* optval, int optlen)
{
co.bTSBPD = cast_optval<bool>(optval, optlen);
const bool val = cast_optval<bool>(optval, optlen);
#ifdef SRT_ENABLE_ENCRYPTION
if (val == false && co.iCryptoMode == CSrtConfig::CIPHER_MODE_AES_GCM)
{
using namespace srt_logging;
LOGC(aclog.Error, log << "Can't disable TSBPD as long as AES GCM is enabled.");
throw CUDTException(MJ_NOTSUP, MN_INVAL, 0);
}
#endif

co.bTSBPD = val;
}
};
template<>
Expand Down Expand Up @@ -888,20 +898,30 @@ struct CSrtConfigSetter<SRTO_CRYPTOMODE>
{
static void set(CSrtConfig& co, const void* optval, int optlen)
{
using namespace srt_logging;
const int val = cast_optval<int>(optval, optlen);
#ifdef SRT_ENABLE_ENCRYPTION
if (val < CSrtConfig::CIPHER_MODE_AUTO || val > CSrtConfig::CIPHER_MODE_AES_GCM)
throw CUDTException(MJ_NOTSUP, MN_INVAL, 0);

#ifdef SRT_ENABLE_ENCRYPTION
if (val == CSrtConfig::CIPHER_MODE_AES_GCM && !HaiCrypt_IsAESGCM_Supported())
{
using namespace srt_logging;
LOGC(aclog.Error, log << "AES GCM is not supported by the crypto provider.");
throw CUDTException(MJ_NOTSUP, MN_INVAL, 0);
}
#endif

if (val == CSrtConfig::CIPHER_MODE_AES_GCM && !co.bTSBPD)
{
LOGC(aclog.Error, log << "Enable TSBPD to use AES GCM.");
throw CUDTException(MJ_NOTSUP, MN_INVAL, 0);
}

co.iCryptoMode = val;
#else
LOGC(aclog.Error, log << "SRT was built without crypto module.");
throw CUDTException(MJ_NOTSUP, MN_INVAL, 0);
#endif

}
};

Expand Down

0 comments on commit 27e7d8d

Please sign in to comment.