Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
Stunserver
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
Stunserver
Commits
1c804606
Commit
1c804606
authored
Jan 16, 2016
by
jselbie
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'FeralInteractive-feral_warnings'
parents
84c3039a
d3b78b13
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
78 additions
and
23 deletions
+78
-23
common.inc
common.inc
+2
-2
networkutils/polling.cpp
networkutils/polling.cpp
+0
-7
server/Makefile
server/Makefile
+1
-1
server/server.cpp
server/server.cpp
+1
-1
stuncore/datastream.cpp
stuncore/datastream.cpp
+1
-1
stuncore/stunbuilder.cpp
stuncore/stunbuilder.cpp
+20
-2
stuncore/stunreader.cpp
stuncore/stunreader.cpp
+50
-1
testcode/testclientlogic.h
testcode/testclientlogic.h
+0
-3
testcode/testreader.cpp
testcode/testreader.cpp
+3
-5
No files found.
common.inc
View file @
1c804606
# 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
...
...
networkutils/polling.cpp
View file @
1c804606
...
...
@@ -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
// --------------------------------------------------------------------------
...
...
server/Makefile
View file @
1c804606
...
...
@@ -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
...
...
server/server.cpp
View file @
1c804606
...
...
@@ -16,7 +16,7 @@
#include "commonincludes.hpp"
#include <openssl/hmac.h>
//
#include <openssl/hmac.h>
#include "stuncore.h"
#include "stunsocket.h"
#include "stunsocketthread.h"
...
...
stuncore/datastream.cpp
View file @
1c804606
...
...
@@ -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
;
}
...
...
stuncore/stunbuilder.cpp
View file @
1c804606
...
...
@@ -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
);
...
...
stuncore/stunreader.cpp
View file @
1c804606
...
...
@@ -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:
...
...
testcode/testclientlogic.h
View file @
1c804606
...
...
@@ -45,9 +45,6 @@ private:
TransportAddressSet
_tsa
;
NatBehavior
_behavior
;
NatFiltering
_filtering
;
boost
::
shared_ptr
<
CStunClientLogic
>
_spClientLogic
;
...
...
testcode/testreader.cpp
View file @
1c804606
...
...
@@ -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
(
pszExpectedSoftwareAttribut
e
,
(
const
char
*
)(
spBuffer
->
GetData
()
+
attrib
.
offset
),
attrib
.
size
),
E_FAIL
);
ChkIfA
(
0
!=
::
strncmp
(
c_softwar
e
,
(
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
(
pszExpectedUserN
ame
,
(
const
char
*
)(
spBuffer
->
GetData
()
+
attrib
.
offset
),
attrib
.
size
),
E_FAIL
);
ChkIfA
(
0
!=
::
strncmp
(
c_usern
ame
,
(
const
char
*
)(
spBuffer
->
GetData
()
+
attrib
.
offset
),
attrib
.
size
),
E_FAIL
);
ChkA
(
reader
.
GetStringAttributeByType
(
STUN_ATTRIBUTE_SOFTWARE
,
szStringValue
,
ARRAYSIZE
(
szStringValue
)));
ChkIfA
(
0
!=
::
strcmp
(
pszExpectedSoftwareAttribut
e
,
szStringValue
),
E_FAIL
);
ChkIfA
(
0
!=
::
strcmp
(
c_softwar
e
,
szStringValue
),
E_FAIL
);
ChkIfA
(
reader
.
HasFingerprintAttribute
()
==
false
,
E_FAIL
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment