Commit 1c804606 authored by jselbie's avatar jselbie

Merge branch 'FeralInteractive-feral_warnings'

parents 84c3039a d3b78b13
# BOOST_INCLUDE := -I/home/jselbie/boost_1_57_0
# OPENSSL_INCLUDE := -I/home/jselbie/lib/openssl
BOOST_INCLUDE := -I/Users/jselbie/boost_1_52_0
#OPENSSL_INCLUDE := -I/Users/jselbie/openssl/include
DEFINES := -DNDEBUG
......
......@@ -18,13 +18,6 @@
#include "polling.h"
#include "fasthash.h"
#ifdef __GNUC__
#ifndef HAS_EPOLL
#pragma message "polling.cpp: WARNING - EPOLL IS NOT AVAILABLE"
#endif
#endif
// --------------------------------------------------------------------------
......
......@@ -3,7 +3,7 @@ include ../common.inc
PROJECT_TARGET := stunserver
PROJECT_OBJS := main.o server.o stunconnection.o stunsocketthread.o tcpserver.o
INCLUDES := $(BOOST_INCLUDE) -I../common -I../stuncore -I../networkutils -I../resources
INCLUDES := $(BOOST_INCLUDE) $(OPENSSL_INCLUDE) -I../common -I../stuncore -I../networkutils -I../resources
LIB_PATH := -L../common -L../stuncore -L../networkutils
LIBS := -lnetworkutils -lstuncore -lcommon -pthread -lcrypto
......
......@@ -16,7 +16,7 @@
#include "commonincludes.hpp"
#include <openssl/hmac.h>
//#include <openssl/hmac.h>
#include "stuncore.h"
#include "stunsocket.h"
#include "stunsocketthread.h"
......
......@@ -191,7 +191,7 @@ HRESULT CDataStream::SeekDirect(size_t pos)
// seeking is allowed anywhere between 0 and stream size
if ((pos >= 0) && (pos <= currentSize))
if (pos <= currentSize)
{
_pos = pos;
}
......
......@@ -24,8 +24,15 @@
#include "stunbuilder.h"
#include <boost/crc.hpp>
#ifndef __APPLE__
#include <openssl/md5.h>
#include <openssl/hmac.h>
#else
#define COMMON_DIGEST_FOR_OPENSSL
#include <CommonCrypto/CommonCrypto.h>
#endif
#include "stunauth.h"
......@@ -498,11 +505,17 @@ HRESULT CStunMessageBuilder::AddMessageIntegrityImpl(uint8_t* key, size_t keysiz
// now do a little pointer math so that HMAC can write exactly to where the hash bytes will appear
pDstBuf = ((uint8_t*)pData) + length + 4;
pHashResult = HMAC(EVP_sha1(), key, keysize, (uint8_t*)pData, length, pDstBuf, &resultlength);
#ifndef __APPLE__
pHashResult = HMAC(EVP_sha1(), key, keysize, (uint8_t*)pData, length, pDstBuf, &resultlength);
ASSERT(resultlength == 20);
ASSERT(pHashResult != NULL);
Cleanup:
#else
CCHmac(kCCHmacAlgSHA1, key, keysize,(uint8_t*)pData, length, pDstBuf);
UNREFERENCED_VARIABLE(resultlength);
#endif
Cleanup:
return hr;
}
......@@ -557,7 +570,12 @@ HRESULT CStunMessageBuilder::AddMessageIntegrityLongTerm(const char* pszUserName
ASSERT((pDst-key) == lenTotal);
#ifndef __APPLE__
pResult = MD5(key, lenTotal, hash);
#else
pResult = CC_MD5(key, lenTotal, hash);
#endif
ASSERT(pResult != NULL);
hr= AddMessageIntegrityImpl(hash, MD5_DIGEST_LENGTH);
......
......@@ -22,9 +22,16 @@
#include "stunutils.h"
#include "socketaddress.h"
#include <boost/crc.hpp>
#ifndef __APPLE__
#include <openssl/evp.h>
#include <openssl/hmac.h>
#include <openssl/md5.h>
#else
#define COMMON_DIGEST_FOR_OPENSSL
#include <CommonCrypto/CommonCrypto.h>
#endif
#include "stunauth.h"
#include "fasthash.h"
......@@ -145,7 +152,11 @@ HRESULT CStunMessageReader::ValidateMessageIntegrity(uint8_t* key, size_t keylen
const size_t c_hmacsize = 20;
uint8_t hmaccomputed[c_hmacsize] = {}; // zero-init
unsigned int hmaclength = c_hmacsize;
#ifndef __APPLE__
HMAC_CTX ctx = {};
#else
CCHmacContext ctx = {};
#endif
uint32_t chunk32;
uint16_t chunk16;
size_t len, nChunks;
......@@ -182,13 +193,21 @@ HRESULT CStunMessageReader::ValidateMessageIntegrity(uint8_t* key, size_t keylen
stream.Attach(spBuffer, false);
// Here comes the fun part. If there is a fingerprint attribute, we have to adjust the length header in computing the hash
#ifndef __APPLE__
HMAC_CTX_init(&ctx);
fContextInit = true;
HMAC_Init(&ctx, key, keylength, EVP_sha1());
#else
CCHmacInit(&ctx, kCCHmacAlgSHA1, key, keylength);
#endif
fContextInit = true;
// message type
Chk(stream.ReadUint16(&chunk16));
#ifndef __APPLE__
HMAC_Update(&ctx, (unsigned char*)&chunk16, sizeof(chunk16));
#else
CCHmacUpdate(&ctx, &chunk16, sizeof(chunk16));
#endif
// message length
Chk(stream.ReadUint16(&chunk16));
......@@ -203,7 +222,12 @@ HRESULT CStunMessageReader::ValidateMessageIntegrity(uint8_t* key, size_t keylen
chunk16 = htons(adjustedlengthHeader);
}
#ifndef __APPLE__
HMAC_Update(&ctx, (unsigned char*)&chunk16, sizeof(chunk16));
#else
CCHmacUpdate(&ctx, &chunk16, sizeof(chunk16));
#endif
// now include everything up to the hash attribute itself.
len = pAttribIntegrity->offset;
......@@ -217,10 +241,19 @@ HRESULT CStunMessageReader::ValidateMessageIntegrity(uint8_t* key, size_t keylen
for (size_t count = 0; count < nChunks; count++)
{
Chk(stream.ReadUint32(&chunk32));
#ifndef __APPLE__
HMAC_Update(&ctx, (unsigned char*)&chunk32, sizeof(chunk32));
#else
CCHmacUpdate(&ctx, &chunk32, sizeof(chunk32));
#endif
}
#ifndef __APPLE__
HMAC_Final(&ctx, hmaccomputed, &hmaclength);
#else
CCHmacFinal(&ctx, hmaccomputed);
#endif
// now compare the bytes
cmp = memcmp(hmaccomputed, spBuffer->GetData() + pAttribIntegrity->offset, c_hmacsize);
......@@ -230,7 +263,11 @@ HRESULT CStunMessageReader::ValidateMessageIntegrity(uint8_t* key, size_t keylen
Cleanup:
if (fContextInit)
{
#ifndef __APPLE__
HMAC_CTX_cleanup(&ctx);
#else
UNREFERENCED_VARIABLE(fContextInit);
#endif
}
return hr;
......@@ -289,7 +326,19 @@ HRESULT CStunMessageReader::ValidateMessageIntegrityLong(const char* pszUser, co
ASSERT((pDst-key) == totallength);
#ifndef __APPLE__
ChkIfA(NULL == MD5(key, totallength, hash), E_FAIL);
#else
{
CC_MD5_CTX context = {};
CC_MD5_Init(&context);
CC_MD5_Update(&context, key, totallength);
CC_MD5_Final(hash, &context);
}
#endif
Chk(ValidateMessageIntegrity(hash, ARRAYSIZE(hash)));
Cleanup:
......
......@@ -45,9 +45,6 @@ private:
TransportAddressSet _tsa;
NatBehavior _behavior;
NatFiltering _filtering;
boost::shared_ptr<CStunClientLogic> _spClientLogic;
......
......@@ -62,8 +62,6 @@ HRESULT CTestReader::Test1()
HRESULT hr = S_OK;
StunAttribute attrib;
const char* pszExpectedSoftwareAttribute = "STUN test client";
const char* pszExpectedUserName = "evtj:h6vY";
CRefCountedBuffer spBuffer;
char szStringValue[100];
......@@ -92,17 +90,17 @@ HRESULT CTestReader::Test1()
ChkIfA(attrib.attributeType != STUN_ATTRIBUTE_SOFTWARE, E_FAIL);
ChkIfA(0 != ::strncmp(pszExpectedSoftwareAttribute, (const char*)(spBuffer->GetData() + attrib.offset), attrib.size), E_FAIL);
ChkIfA(0 != ::strncmp(c_software, (const char*)(spBuffer->GetData() + attrib.offset), attrib.size), E_FAIL);
ChkA(reader.GetAttributeByType(STUN_ATTRIBUTE_USERNAME, &attrib));
ChkIfA(attrib.attributeType != STUN_ATTRIBUTE_USERNAME, E_FAIL);
ChkIfA(0 != ::strncmp(pszExpectedUserName, (const char*)(spBuffer->GetData() + attrib.offset), attrib.size), E_FAIL);
ChkIfA(0 != ::strncmp(c_username, (const char*)(spBuffer->GetData() + attrib.offset), attrib.size), E_FAIL);
ChkA(reader.GetStringAttributeByType(STUN_ATTRIBUTE_SOFTWARE, szStringValue, ARRAYSIZE(szStringValue)));
ChkIfA(0 != ::strcmp(pszExpectedSoftwareAttribute, szStringValue), E_FAIL);
ChkIfA(0 != ::strcmp(c_software, szStringValue), E_FAIL);
ChkIfA(reader.HasFingerprintAttribute() == false, E_FAIL);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment