Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
M
mediasoup
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
聂卓夫
mediasoup
Commits
c559b958
提交
c559b958
authored
4月 03, 2022
作者:
Nazar Mokrynskyi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update to OpenSSL 3.0 API
上级
30ed8d41
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
24 行增加
和
57 行删除
+24
-57
Utils.hpp
worker/include/Utils.hpp
+3
-2
DtlsTransport.cpp
worker/src/RTC/DtlsTransport.cpp
+3
-45
Crypto.cpp
worker/src/Utils/Crypto.cpp
+18
-10
没有找到文件。
worker/include/Utils.hpp
浏览文件 @
c559b958
...
...
@@ -2,7 +2,7 @@
#define MS_UTILS_HPP
#include "common.hpp"
#include <openssl/
hmac
.h>
#include <openssl/
evp
.h>
#include <cmath>
#include <cstring> // std::memcmp(), std::memcpy()
#include <nlohmann/json.hpp>
...
...
@@ -255,7 +255,8 @@ namespace Utils
private
:
thread_local
static
uint32_t
seed
;
thread_local
static
HMAC_CTX
*
hmacSha1Ctx
;
thread_local
static
EVP_MAC
*
mac
;
thread_local
static
EVP_MAC_CTX
*
hmacSha1Ctx
;
thread_local
static
uint8_t
hmacSha1Buffer
[];
static
const
uint32_t
crc32Table
[
256
];
};
...
...
worker/src/RTC/DtlsTransport.cpp
浏览文件 @
c559b958
...
...
@@ -6,11 +6,8 @@
#include "MediaSoupErrors.hpp"
#include "Settings.hpp"
#include "Utils.hpp"
#include <openssl/asn1.h>
#include <openssl/bn.h>
#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/rsa.h>
#include <uv.h>
#include <cstdio> // std::sprintf(), std::fopen()
#include <cstring> // std::memcpy(), std::strcmp()
...
...
@@ -157,56 +154,20 @@ namespace RTC
MS_TRACE
();
int
ret
{
0
};
EC_KEY
*
ecKey
{
nullptr
};
X509_NAME
*
certName
{
nullptr
};
std
::
string
subject
=
std
::
string
(
"mediasoup"
)
+
std
::
to_string
(
Utils
::
Crypto
::
GetRandomUInt
(
100000
,
999999
));
// Create key with curve.
ecKey
=
EC_KEY_new_by_curve_name
(
NID_X9_62_prime256v1
);
if
(
!
ecKey
)
{
LOG_OPENSSL_ERROR
(
"EC_KEY_new_by_curve_name() failed"
);
goto
error
;
}
EC_KEY_set_asn1_flag
(
ecKey
,
OPENSSL_EC_NAMED_CURVE
);
// NOTE: This can take some time.
ret
=
EC_KEY_generate_key
(
ecKey
);
if
(
ret
==
0
)
{
LOG_OPENSSL_ERROR
(
"EC_KEY_generate_key() failed"
);
goto
error
;
}
// Create a private key object.
DtlsTransport
::
privateKey
=
EVP_PKEY_new
();
DtlsTransport
::
privateKey
=
EVP_EC_gen
(
SN_X9_62_prime256v1
);
if
(
!
DtlsTransport
::
privateKey
)
{
LOG_OPENSSL_ERROR
(
"EVP_PKEY_new() failed"
);
goto
error
;
}
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
ret
=
EVP_PKEY_assign_EC_KEY
(
DtlsTransport
::
privateKey
,
ecKey
);
if
(
ret
==
0
)
{
LOG_OPENSSL_ERROR
(
"EVP_PKEY_assign_EC_KEY() failed"
);
LOG_OPENSSL_ERROR
(
"EVP_EC_gen() failed"
);
goto
error
;
}
// The EC key now belongs to the private key, so don't clean it up separately.
ecKey
=
nullptr
;
// Create the X509 certificate.
DtlsTransport
::
certificate
=
X509_new
();
...
...
@@ -278,11 +239,8 @@ namespace RTC
error
:
if
(
ecKey
)
EC_KEY_free
(
ecKey
);
if
(
DtlsTransport
::
privateKey
)
EVP_PKEY_free
(
DtlsTransport
::
privateKey
);
// NOTE: This also frees the EC key.
EVP_PKEY_free
(
DtlsTransport
::
privateKey
);
if
(
DtlsTransport
::
certificate
)
X509_free
(
DtlsTransport
::
certificate
);
...
...
worker/src/Utils/Crypto.cpp
浏览文件 @
c559b958
...
...
@@ -10,7 +10,8 @@ namespace Utils
/* Static variables. */
thread_local
uint32_t
Crypto
::
seed
;
thread_local
HMAC_CTX
*
Crypto
::
hmacSha1Ctx
{
nullptr
};
thread_local
EVP_MAC
*
Crypto
::
mac
{
nullptr
};
thread_local
EVP_MAC_CTX
*
Crypto
::
hmacSha1Ctx
{
nullptr
};
thread_local
uint8_t
Crypto
::
hmacSha1Buffer
[
SHA_DIGEST_LENGTH
];
// clang-format off
const
uint32_t
Crypto
::
crc32Table
[]
=
...
...
@@ -61,7 +62,8 @@ namespace Utils
Crypto
::
seed
=
static_cast
<
uint32_t
>
(
reinterpret_cast
<
uintptr_t
>
(
std
::
addressof
(
Crypto
::
seed
)));
// Create an OpenSSL HMAC_CTX context for HMAC SHA1 calculation.
Crypto
::
hmacSha1Ctx
=
HMAC_CTX_new
();
Crypto
::
mac
=
EVP_MAC_fetch
(
nullptr
,
"HMAC"
,
nullptr
);
Crypto
::
hmacSha1Ctx
=
EVP_MAC_CTX_new
(
mac
);
}
void
Crypto
::
ClassDestroy
()
...
...
@@ -69,7 +71,10 @@ namespace Utils
MS_TRACE
();
if
(
Crypto
::
hmacSha1Ctx
!=
nullptr
)
HMAC_CTX_free
(
Crypto
::
hmacSha1Ctx
);
EVP_MAC_CTX_free
(
Crypto
::
hmacSha1Ctx
);
if
(
Crypto
::
mac
!=
nullptr
)
EVP_MAC_free
(
Crypto
::
mac
);
}
const
uint8_t
*
Crypto
::
GetHmacSha1
(
const
std
::
string
&
key
,
const
uint8_t
*
data
,
size_t
len
)
...
...
@@ -78,26 +83,29 @@ namespace Utils
int
ret
;
ret
=
HMAC_Init_ex
(
Crypto
::
hmacSha1Ctx
,
key
.
c_str
(),
key
.
length
(),
EVP_sha1
(),
nullptr
);
OSSL_PARAM
sha1
[]
=
{
{
"digest"
,
OSSL_PARAM_UTF8_STRING
,
(
void
*
)
"sha1"
,
4
,
0
},
OSSL_PARAM_END
};
ret
=
EVP_MAC_init
(
Crypto
::
hmacSha1Ctx
,
reinterpret_cast
<
const
unsigned
char
*>
(
key
.
c_str
()),
key
.
length
(),
sha1
);
MS_ASSERT
(
ret
==
1
,
"OpenSSL
HMAC_Init_ex
() failed with key '%s'"
,
key
.
c_str
());
MS_ASSERT
(
ret
==
1
,
"OpenSSL
EVP_MAC_init
() failed with key '%s'"
,
key
.
c_str
());
ret
=
HMAC_Update
(
Crypto
::
hmacSha1Ctx
,
data
,
static_cast
<
int
>
(
len
)
);
ret
=
EVP_MAC_update
(
Crypto
::
hmacSha1Ctx
,
data
,
len
);
MS_ASSERT
(
ret
==
1
,
"OpenSSL
HMAC_U
pdate() failed with key '%s' and data length %zu bytes"
,
"OpenSSL
EVP_MAC_u
pdate() failed with key '%s' and data length %zu bytes"
,
key
.
c_str
(),
len
);
uint32
_t
resultLen
;
size
_t
resultLen
;
ret
=
HMAC_Final
(
Crypto
::
hmacSha1Ctx
,
(
uint8_t
*
)
Crypto
::
hmacSha1Buffer
,
&
resultLen
);
ret
=
EVP_MAC_final
(
Crypto
::
hmacSha1Ctx
,
Crypto
::
hmacSha1Buffer
,
&
resultLen
,
SHA_DIGEST_LENGTH
);
MS_ASSERT
(
ret
==
1
,
"OpenSSL HMAC_Final() failed with key '%s' and data length %zu bytes"
,
key
.
c_str
(),
len
);
MS_ASSERT
(
resultLen
==
SHA_DIGEST_LENGTH
,
"OpenSSL HMAC_Final() resultLen is %u instead of 20"
,
resultLen
);
resultLen
==
SHA_DIGEST_LENGTH
,
"OpenSSL HMAC_Final() resultLen is %
z
u instead of 20"
,
resultLen
);
return
Crypto
::
hmacSha1Buffer
;
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论