41 const char* c_pszAuthorizedUser =
"AuthorizedUser";
45 if (0 == strcmp(pAuthAttributes->
szUser, c_pszAuthorizedUser))
50 else if (pAuthAttributes->
szUser[0] ==
'\0')
65 bool fIsKnownUser =
false;
67 strcpy(pResponse->
szRealm,
"MyRealm");
68 strcpy(pResponse->
szNonce,
"NewNonce");
72 fIsKnownUser = !strcmp(pAuthAttributes->
szUser,
"AuthorizedUser");
119 InitTransportAddressSet(tas,
true,
true,
true,
true);
121 builderRequest.
GetResult(&spBufferRequest);
150 addr.sin_family = AF_INET;
151 addr.sin_port = htons(port);
153 result = ::inet_pton(AF_INET, pszIP, &addr.sin_addr);
253 InitTransportAddressSet(tas,
true,
true,
true,
true);
255 ChkA(InitBindingRequest(builder));
288 ChkA(ValidateResponseOriginAddress(reader, _addrServerPP));
292 ChkA(ValidateMappedAddress(reader, _addrMapped,
false));
294 ChkA(ValidateOtherAddress(reader, _addrServerAA));
311 uint16_t responsePort = 2222;
317 InitTransportAddressSet(tas,
true,
true,
true,
true);
320 InitBindingRequest(builder);
346 state = reader.
AddBytes(spBufferOut->GetData(), spBufferOut->GetSize());
352 ChkA(ValidateResponseOriginAddress(reader, _addrServerAA));
355 addrDestExpected = _addrMapped;
356 addrDestExpected.
SetPort(responsePort);
360 ChkA(ValidateMappedAddress(reader, _addrMapped,
false));
363 ChkA(ValidateOtherAddress(reader, _addrServerAA));
381 uint16_t errorcode = 0;
388 ChkA(InitBindingRequest(builder1));
393 ChkA(SendHelper(builder1, &readerResponse, _spAuthShort));
399 readerResponse.
Reset();
400 InitBindingRequest(builder2);
405 ChkA(SendHelper(builder2, &readerResponse, _spAuthShort))
413 readerResponse.
Reset();
414 ChkA(InitBindingRequest(builder3));
416 ChkA(SendHelper(builder3, &readerResponse, _spAuthShort));
435 uint16_t errorcode = 0;
442 InitBindingRequest(builder1);
445 ChkA(SendHelper(builder1, &readerResponse, _spAuthLong));
458 readerResponse.
Reset();
459 InitBindingRequest(builder2);
466 ChkA(SendHelper(builder2, &readerResponse, _spAuthLong));
const uint32_t MAX_STUN_MESSAGE_SIZE
AuthResponseType responseType
const uint16_t STUN_ATTRIBUTE_USERNAME
char szUser[MAX_STUN_AUTH_STRING_SIZE+1]
HRESULT AddStringAttribute(uint16_t attribType, const char *pstr)
uint16_t GetMessageType()
HRESULT AddRandomTransactionId(StunTransactionId *pTransId)
HRESULT AddRealm(const char *pszRealm)
const uint16_t STUN_ERROR_UNAUTHORIZED
bool IsSameIP_and_Port(const CSocketAddress &other) const
HRESULT ValidateMessageIntegrityLong(const char *pszUser, const char *pszRealm, const char *pszPassword)
static HRESULT CreateInstanceNoInit(X **ppInstance)
static const uint16_t c_portServerPrimary
bool fMessageIntegrityPresent
HRESULT ValidateMappedAddress(CStunMessageReader &reader, const CSocketAddress &addrExpected, bool fLegacyOnly)
static const char * c_szIPLocal
static const uint16_t c_portLocal
const uint16_t STUN_ATTRIBUTE_REALM
HRESULT GetMappedAddress(CSocketAddress *pAddress)
AuthCredentialMechanism authCredMech
#define UNREFERENCED_VARIABLE(unrefparam)
const uint16_t STUN_ATTRIBUTE_NONCE
#define ChkIf(expr, hrerror)
ReaderParseState AddBytes(const uint8_t *pData, uint32_t size)
const uint16_t STUN_ERROR_BADREQUEST
HRESULT GetOtherAddress(CSocketAddress *pAddress)
HRESULT SendHelper(CStunMessageBuilder &builderRequest, CStunMessageReader *pReaderResponse, IStunAuth *pAuth)
CSocketAddress addrRemote
What local IP address the message was received on (useful if the socket binded to INADDR_ANY) ...
CSocketAddress addrLocal
which socket id did the message arrive on
HRESULT InitBindingRequest(CStunMessageBuilder &builder)
static const uint16_t c_portMapped
char szPassword[MAX_STUN_AUTH_STRING_SIZE+1]
const uint32_t MAX_STUN_AUTH_STRING_SIZE
HRESULT AddHeader(StunMessageType msgType, StunMessageClass msgClass)
HRESULT AddMessageIntegrityLongTerm(const char *pszUserName, const char *pszRealm, const char *pszPassword)
void ToAddr(const char *pszIP, uint16_t port, CSocketAddress *pAddr)
HRESULT GetErrorCode(uint16_t *pErrorNumber)
HRESULT ValidateMessageIntegrityShort(const char *pszPassword)
char szNonce[MAX_STUN_AUTH_STRING_SIZE+1]
HRESULT AddNonce(const char *pszNonce)
static const char * c_szIPServerAlternate
HRESULT AddResponsePort(uint16_t port)
HRESULT GetResult(CRefCountedBuffer *pspBuffer)
virtual HRESULT DoAuthCheck(AuthAttributes *pAuthAttributes, AuthResponse *pResponse)
HRESULT AddMessageIntegrityShortTerm(const char *pszPassword)
HRESULT AddChangeRequest(const StunChangeRequestAttribute &changeAttrib)
HRESULT ValidateResponseOriginAddress(CStunMessageReader &reader, const CSocketAddress &addrExpected)
CStunMessageReader * pReader
the address of the node that sent us the message
static const char * c_szIPServerPrimary
StunMessageClass GetMessageClass()
HRESULT ValidateOtherAddress(CStunMessageReader &reader, const CSocketAddress &addrExpected)
static HRESULT ProcessRequest(const StunMessageIn &msgIn, StunMessageOut &msgOut, TransportAddressSet *pAddressSet, IStunAuth *pAuth)
static const char * c_szIPMapped
CRefCountedBuffer spBufferOut
char szRealm[MAX_STUN_AUTH_STRING_SIZE+1]
boost::shared_ptr< CBuffer > CRefCountedBuffer
HRESULT GetStringAttributeByType(uint16_t attributeType, char *pszValue, size_t size)
static const uint16_t c_portServerAlternate
virtual HRESULT DoAuthCheck(AuthAttributes *pAuthAttributes, AuthResponse *pResponse)
#define ChkIfA(expr, hrerror)
HRESULT GetXorMappedAddress(CSocketAddress *pAddress)
HRESULT AddUserName(const char *pszUserName)
bool fConnectionOriented
reader containing a valid stun message
void InitTransportAddressSet(TransportAddressSet &tas, bool fRolePP, bool fRolePA, bool fRoleAP, bool fRoleAA)
HRESULT GetResponseOriginAddress(CSocketAddress *pAddress)