Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
jami-daemon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
jami-daemon
Commits
61f5b133
Commit
61f5b133
authored
13 years ago
by
Tristan Matthews
Browse files
Options
Downloads
Patches
Plain Diff
* #9641: audiosrtpsession: fixed memory leak, simplified memory management
parent
3bdfb413
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
daemon/src/audio/audiortp/audio_srtp_session.cpp
+78
-85
78 additions, 85 deletions
daemon/src/audio/audiortp/audio_srtp_session.cpp
daemon/src/audio/audiortp/audio_srtp_session.h
+0
-10
0 additions, 10 deletions
daemon/src/audio/audiortp/audio_srtp_session.h
with
78 additions
and
95 deletions
daemon/src/audio/audiortp/audio_srtp_session.cpp
+
78
−
85
View file @
61f5b133
...
...
@@ -42,6 +42,78 @@
namespace
sfl
{
namespace
{
std
::
string
encodeBase64
(
unsigned
char
*
input
,
int
length
)
{
// init decoder
BIO
*
b64
=
BIO_new
(
BIO_f_base64
());
BIO_set_flags
(
b64
,
BIO_FLAGS_BASE64_NO_NL
);
// init internal buffer
BIO
*
bmem
=
BIO_new
(
BIO_s_mem
());
// create decoder chain
b64
=
BIO_push
(
b64
,
bmem
);
BIO_write
(
b64
,
input
,
length
);
// BIO_flush (b64);
// get pointer to data
BUF_MEM
*
bptr
=
0
;
BIO_get_mem_ptr
(
b64
,
&
bptr
);
std
::
string
output
(
bptr
->
data
,
bptr
->
length
);
BIO_free_all
(
bmem
);
return
output
;
}
std
::
vector
<
char
>
decodeBase64
(
unsigned
char
*
input
,
int
length
)
{
BIO
*
b64
,
*
bmem
;
// init decoder and read-only BIO buffer
b64
=
BIO_new
(
BIO_f_base64
());
BIO_set_flags
(
b64
,
BIO_FLAGS_BASE64_NO_NL
);
// init internal buffer
bmem
=
BIO_new_mem_buf
(
input
,
length
);
// create encoder chain
bmem
=
BIO_push
(
b64
,
bmem
);
std
::
vector
<
char
>
buffer
(
length
,
0
);
BIO_read
(
bmem
,
&
(
*
buffer
.
begin
()),
length
);
BIO_free_all
(
bmem
);
return
buffer
;
}
// Fills the array dest with length random bytes
void
buffer_fill
(
unsigned
char
dest
[],
size_t
length
)
{
DEBUG
(
"AudioSrtp: Init local master key"
);
// @TODO key may have different length depending on cipher suite
// Allocate memory for key
std
::
vector
<
unsigned
char
>
random_key
(
length
);
// Generate ryptographically strong pseudo-random bytes
int
err
;
if
((
err
=
RAND_bytes
(
&
(
*
random_key
.
begin
()),
length
))
!=
1
)
DEBUG
(
"Error occured while generating cryptographically strong pseudo-random key"
);
assert
((
sizeof
dest
/
sizeof
dest
[
0
])
<=
length
);
memcpy
(
dest
,
&
(
*
random_key
.
begin
()),
length
);
}
}
AudioSrtpSession
::
AudioSrtpSession
(
SIPCall
&
call
)
:
AudioSymmetricRtpSession
(
call
),
remoteCryptoCtx_
(
NULL
),
...
...
@@ -133,41 +205,18 @@ void AudioSrtpSession::setRemoteCryptoInfo(sfl::SdesNegotiator& nego)
void
AudioSrtpSession
::
initializeLocalMasterKey
()
{
DEBUG
(
"AudioSrtp: Init local master key"
);
// @TODO key may have different length depending on cipher suite
localMasterKeyLength_
=
sfl
::
CryptoSuites
[
localCryptoSuite_
].
masterKeyLength
/
8
;
DEBUG
(
"AudioSrtp: Local master key length %d"
,
localMasterKeyLength_
);
// Allocate memory for key
unsigned
char
*
random_key
=
new
unsigned
char
[
localMasterKeyLength_
];
// Generate ryptographically strong pseudo-random bytes
int
err
;
if
((
err
=
RAND_bytes
(
random_key
,
localMasterKeyLength_
))
!=
1
)
DEBUG
(
"Error occured while generating cryptographically strong pseudo-random key"
);
memcpy
(
localMasterKey_
,
random_key
,
localMasterKeyLength_
);
buffer_fill
(
localMasterKey_
,
localMasterKeyLength_
);
}
void
AudioSrtpSession
::
initializeLocalMasterSalt
()
{
// @TODO key may have different length depending on cipher suite
localMasterSaltLength_
=
sfl
::
CryptoSuites
[
localCryptoSuite_
].
masterSaltLength
/
8
;
// Allocate memory for key
unsigned
char
*
random_key
=
new
unsigned
char
[
localMasterSaltLength_
];
DEBUG
(
"AudioSrtp: Local master salt length %d"
,
localMasterSaltLength_
);
// Generate ryptographically strong pseudo-random bytes
int
err
;
if
((
err
=
RAND_bytes
(
random_key
,
localMasterSaltLength_
))
!=
1
)
DEBUG
(
"Error occured while generating cryptographically strong pseudo-random key"
);
memcpy
(
localMasterSalt_
,
random_key
,
localMasterSaltLength_
);
buffer_fill
(
localMasterSalt_
,
localMasterSaltLength_
);
}
std
::
string
AudioSrtpSession
::
getBase64ConcatenatedKeys
()
...
...
@@ -198,13 +247,11 @@ void AudioSrtpSession::unBase64ConcatenatedKeys(std::string base64keys)
char
*
dataptr
=
(
char
*
)
base64keys
.
data
();
// decode concatenated binary keys
char
*
output
=
decodeBase64
((
unsigned
char
*
)
dataptr
,
strlen
(
dataptr
));
std
::
vector
<
char
>
output
(
decodeBase64
((
unsigned
char
*
)
dataptr
,
strlen
(
dataptr
))
)
;
// copy master and slt respectively
memcpy
((
void
*
)
remoteMasterKey_
,
(
void
*
)
output
,
remoteMasterKeyLength_
);
memcpy
((
void
*
)
remoteMasterSalt_
,
(
void
*
)(
output
+
remoteMasterKeyLength_
),
remoteMasterSaltLength_
);
delete
[]
output
;
memcpy
((
void
*
)
remoteMasterKey_
,
&
(
*
output
.
begin
()),
remoteMasterKeyLength_
);
memcpy
((
void
*
)
remoteMasterSalt_
,
&
(
*
output
.
begin
())
+
remoteMasterKeyLength_
,
remoteMasterSaltLength_
);
}
void
AudioSrtpSession
::
initializeRemoteCryptoContext
()
...
...
@@ -240,10 +287,8 @@ void AudioSrtpSession::initializeLocalCryptoContext()
CryptoSuiteDefinition
crypto
=
sfl
::
CryptoSuites
[
localCryptoSuite_
];
if
(
localCryptoCtx_
)
{
if
(
localCryptoCtx_
)
delete
localCryptoCtx_
;
localCryptoCtx_
=
NULL
;
}
localCryptoCtx_
=
new
ost
::
CryptoContext
(
OutgoingDataQueue
::
getLocalSSRC
(),
0
,
// roc,
...
...
@@ -266,56 +311,4 @@ void AudioSrtpSession::restoreCryptoContext(ost::CryptoContext *localContext, os
setOutQueueCryptoContext
(
localContext
);
}
std
::
string
AudioSrtpSession
::
encodeBase64
(
unsigned
char
*
input
,
int
length
)
{
BIO
*
b64
,
*
bmem
;
BUF_MEM
*
bptr
;
// init decoder
b64
=
BIO_new
(
BIO_f_base64
());
BIO_set_flags
(
b64
,
BIO_FLAGS_BASE64_NO_NL
);
// init internal buffer
bmem
=
BIO_new
(
BIO_s_mem
());
// create decoder chain
b64
=
BIO_push
(
b64
,
bmem
);
BIO_write
(
b64
,
input
,
length
);
// BIO_flush (b64);
// get pointer to data
BIO_get_mem_ptr
(
b64
,
&
bptr
);
std
::
string
output
(
bptr
->
data
,
bptr
->
length
);
BIO_free_all
(
bmem
);
return
output
;
}
char
*
AudioSrtpSession
::
decodeBase64
(
unsigned
char
*
input
,
int
length
)
{
BIO
*
b64
,
*
bmem
;
// init decoder and read-only BIO buffer
b64
=
BIO_new
(
BIO_f_base64
());
BIO_set_flags
(
b64
,
BIO_FLAGS_BASE64_NO_NL
);
// init internal buffer
bmem
=
BIO_new_mem_buf
(
input
,
length
);
// create encoder chain
bmem
=
BIO_push
(
b64
,
bmem
);
char
*
buffer
=
new
char
[
length
];
memset
(
buffer
,
0
,
length
);
BIO_read
(
bmem
,
buffer
,
length
);
BIO_free_all
(
bmem
);
return
buffer
;
}
}
This diff is collapsed.
Click to expand it.
daemon/src/audio/audiortp/audio_srtp_session.h
+
0
−
10
View file @
61f5b133
...
...
@@ -143,16 +143,6 @@ class AudioSrtpSession : public AudioSymmetricRtpSession {
*/
void
unBase64ConcatenatedKeys
(
std
::
string
base64keys
);
/**
* Encode input data as base64
*/
std
::
string
encodeBase64
(
unsigned
char
*
input
,
int
length
);
/**
* Decode base64 data
*/
char
*
decodeBase64
(
unsigned
char
*
input
,
int
length
);
/** Default local crypto suite is AES_CM_128_HMAC_SHA1_80*/
int
localCryptoSuite_
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment