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
d3b78b13
Commit
d3b78b13
authored
Jan 16, 2016
by
jselbie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merged changed from FeralInteractive and added support for CommonCrypto on Mac
parent
8aff602e
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
73 additions
and
13 deletions
+73
-13
common.inc
common.inc
+2
-2
networkutils/polling.cpp
networkutils/polling.cpp
+0
-7
server/server.cpp
server/server.cpp
+1
-1
stuncore/stunbuilder.cpp
stuncore/stunbuilder.cpp
+20
-2
stuncore/stunreader.cpp
stuncore/stunreader.cpp
+50
-1
No files found.
common.inc
View file @
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
...
...
networkutils/polling.cpp
View file @
d3b78b13
...
...
@@ -18,13 +18,6 @@
#include "polling.h"
#include "fasthash.h"
#ifdef IS_LINUX
#ifndef HAS_EPOLL
#pragma message "polling.cpp: WARNING - EPOLL IS NOT AVAILABLE"
#endif
#endif
// --------------------------------------------------------------------------
...
...
server/server.cpp
View file @
d3b78b13
...
...
@@ -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/stunbuilder.cpp
View file @
d3b78b13
...
...
@@ -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 @
d3b78b13
...
...
@@ -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:
...
...
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