Skip to content
GitLab
菜单
为什么选择 GitLab
定价
联系销售
探索
为什么选择 GitLab
定价
联系销售
探索
登录
获取免费试用
主导航
搜索或转到…
项目
M
mbedtls
管理
动态
成员
标记
计划
议题
议题看板
里程碑
迭代
Wiki
代码
合并请求
仓库
分支
提交
标签
仓库图
比较修订版本
代码片段
锁定的文件
构建
流水线
作业
流水线计划
产物
部署
发布
Package registry
容器镜像库
模型注册表
运维
环境
Terraform 模块
监控
事件
服务台
分析
价值流分析
贡献者分析
CI/CD 分析
仓库分析
代码评审分析
议题分析
模型实验
效能分析
帮助
帮助
支持
GitLab 文档
比较 GitLab 各版本
社区论坛
为极狐GitLab 提交贡献
提交反馈
隐私声明
快捷键
?
新增功能
4
代码片段
群组
项目
显示更多面包屑
esp-mirror
Mbed-TLS
mbedtls
提交
4d6f1783
提交
4d6f1783
编辑于
9 years ago
作者:
Manuel Pégourié-Gonnard
浏览文件
操作
下载
补丁
差异文件
Add support for SNI CA and authmode in ssl_server2
上级
cdc26ae0
No related branches found
分支 包含提交
No related tags found
标签 包含提交
无相关合并请求
变更
2
隐藏空白变更内容
行内
左右并排
显示
2 个更改的文件
programs/ssl/ssl_server2.c
+74
-25
74 个添加, 25 个删除
programs/ssl/ssl_server2.c
tests/ssl-opt.sh
+3
-3
3 个添加, 3 个删除
tests/ssl-opt.sh
有
77 个添加
和
28 个删除
programs/ssl/ssl_server2.c
+
74
−
25
浏览文件 @
4d6f1783
...
...
@@ -210,8 +210,8 @@ int main( void )
#if defined(SNI_OPTION)
#define USAGE_SNI \
" sni=%%s name1,cert1,key1
[,name2,cert2,key2
[,...]
]
\n" \
"
default: disabled\n"
" sni=%%s name1,cert1,key1
,ca1,crl1,auth1
[,...]\n" \
" default: disabled\n"
#else
#define USAGE_SNI ""
#endif
/* SNI_OPTION */
...
...
@@ -436,6 +436,21 @@ static int my_send( void *ctx, const unsigned char *buf, size_t len )
return
(
ret
);
}
/*
* Return authmode from string, or -1 on error
*/
static
int
get_auth_mode
(
const
char
*
s
)
{
if
(
strcmp
(
s
,
"none"
)
==
0
)
return
(
MBEDTLS_SSL_VERIFY_NONE
);
if
(
strcmp
(
s
,
"optional"
)
==
0
)
return
(
MBEDTLS_SSL_VERIFY_OPTIONAL
);
if
(
strcmp
(
s
,
"required"
)
==
0
)
return
(
MBEDTLS_SSL_VERIFY_REQUIRED
);
return
(
-
1
);
}
/*
* Used by sni_parse and psk_parse to handle coma-separated lists
*/
...
...
@@ -453,6 +468,9 @@ struct _sni_entry {
const
char
*
name
;
mbedtls_x509_crt
*
cert
;
mbedtls_pk_context
*
key
;
mbedtls_x509_crt
*
ca
;
mbedtls_x509_crl
*
crl
;
int
authmode
;
sni_entry
*
next
;
};
...
...
@@ -468,6 +486,12 @@ void sni_free( sni_entry *head )
mbedtls_pk_free
(
cur
->
key
);
mbedtls_free
(
cur
->
key
);
mbedtls_x509_crt_free
(
cur
->
ca
);
mbedtls_free
(
cur
->
ca
);
mbedtls_x509_crl_free
(
cur
->
crl
);
mbedtls_free
(
cur
->
crl
);
next
=
cur
->
next
;
mbedtls_free
(
cur
);
cur
=
next
;
...
...
@@ -475,8 +499,9 @@ void sni_free( sni_entry *head )
}
/*
* Parse a string of triplets name1,crt1,key1[,name2,crt2,key2[,...]]
* into a usable sni_entry list.
* Parse a string of sextuples name1,crt1,key1,ca1,crl1,auth1[,...]
* into a usable sni_entry list. For ca1, crl1, auth1, the special value
* '-' means unset. If ca1 is unset, then crl1 is ignored too.
*
* Modifies the input string! This is not production quality!
*/
...
...
@@ -485,7 +510,7 @@ sni_entry *sni_parse( char *sni_string )
sni_entry
*
cur
=
NULL
,
*
new
=
NULL
;
char
*
p
=
sni_string
;
char
*
end
=
p
;
char
*
crt_file
,
*
key_file
;
char
*
crt_file
,
*
key_file
,
*
ca_file
,
*
crl_file
,
*
auth_str
;
while
(
*
end
!=
'\0'
)
++
end
;
...
...
@@ -499,30 +524,54 @@ sni_entry *sni_parse( char *sni_string )
return
(
NULL
);
}
memset
(
new
,
0
,
sizeof
(
sni_entry
)
);
GET_ITEM
(
new
->
name
);
GET_ITEM
(
crt_file
);
GET_ITEM
(
key_file
);
GET_ITEM
(
ca_file
);
GET_ITEM
(
crl_file
);
GET_ITEM
(
auth_str
);
if
(
(
new
->
cert
=
mbedtls_calloc
(
1
,
sizeof
(
mbedtls_x509_crt
)
)
)
==
NULL
||
(
new
->
key
=
mbedtls_calloc
(
1
,
sizeof
(
mbedtls_pk_context
)
)
)
==
NULL
)
{
mbedtls_free
(
new
->
cert
);
mbedtls_free
(
new
);
sni_free
(
cur
);
return
(
NULL
);
}
goto
error
;
mbedtls_x509_crt_init
(
new
->
cert
);
mbedtls_pk_init
(
new
->
key
);
GET_ITEM
(
new
->
name
);
GET_ITEM
(
crt_file
);
GET_ITEM
(
key_file
);
if
(
mbedtls_x509_crt_parse_file
(
new
->
cert
,
crt_file
)
!=
0
||
mbedtls_pk_parse_keyfile
(
new
->
key
,
key_file
,
""
)
!=
0
)
{
goto
error
;
if
(
strcmp
(
ca_file
,
"-"
)
!=
0
)
{
if
(
(
new
->
ca
=
mbedtls_calloc
(
1
,
sizeof
(
mbedtls_x509_crt
)
)
)
==
NULL
)
goto
error
;
mbedtls_x509_crt_init
(
new
->
ca
);
if
(
mbedtls_x509_crt_parse_file
(
new
->
ca
,
ca_file
)
!=
0
)
goto
error
;
}
if
(
strcmp
(
crl_file
,
"-"
)
!=
0
)
{
if
(
(
new
->
crl
=
mbedtls_calloc
(
1
,
sizeof
(
mbedtls_x509_crl
)
)
)
==
NULL
)
goto
error
;
mbedtls_x509_crl_init
(
new
->
crl
);
if
(
mbedtls_x509_crl_parse_file
(
new
->
crl
,
crl_file
)
!=
0
)
goto
error
;
}
if
(
strcmp
(
auth_str
,
"-"
)
!=
0
)
{
if
(
(
new
->
authmode
=
get_auth_mode
(
auth_str
)
)
<
0
)
goto
error
;
}
else
new
->
authmode
=
DFL_AUTH_MODE
;
new
->
next
=
cur
;
cur
=
new
;
}
...
...
@@ -541,13 +590,19 @@ error:
int
sni_callback
(
void
*
p_info
,
mbedtls_ssl_context
*
ssl
,
const
unsigned
char
*
name
,
size_t
name_len
)
{
sni_entry
*
cur
=
(
sni_entry
*
)
p_info
;
const
sni_entry
*
cur
=
(
const
sni_entry
*
)
p_info
;
while
(
cur
!=
NULL
)
{
if
(
name_len
==
strlen
(
cur
->
name
)
&&
memcmp
(
name
,
cur
->
name
,
name_len
)
==
0
)
{
if
(
cur
->
ca
!=
NULL
)
mbedtls_ssl_set_hs_ca_chain
(
ssl
,
cur
->
ca
,
cur
->
crl
);
if
(
cur
->
authmode
!=
DFL_AUTH_MODE
)
mbedtls_ssl_set_hs_authmode
(
ssl
,
cur
->
authmode
);
return
(
mbedtls_ssl_set_hs_own_cert
(
ssl
,
cur
->
cert
,
cur
->
key
)
);
}
...
...
@@ -1055,13 +1110,7 @@ int main( int argc, char *argv[] )
}
else
if
(
strcmp
(
p
,
"auth_mode"
)
==
0
)
{
if
(
strcmp
(
q
,
"none"
)
==
0
)
opt
.
auth_mode
=
MBEDTLS_SSL_VERIFY_NONE
;
else
if
(
strcmp
(
q
,
"optional"
)
==
0
)
opt
.
auth_mode
=
MBEDTLS_SSL_VERIFY_OPTIONAL
;
else
if
(
strcmp
(
q
,
"required"
)
==
0
)
opt
.
auth_mode
=
MBEDTLS_SSL_VERIFY_REQUIRED
;
else
if
(
(
opt
.
auth_mode
=
get_auth_mode
(
q
)
)
<
0
)
goto
usage
;
}
else
if
(
strcmp
(
p
,
"max_frag_len"
)
==
0
)
...
...
此差异已折叠。
点击以展开。
tests/ssl-opt.sh
+
3
−
3
浏览文件 @
4d6f1783
...
...
@@ -1758,7 +1758,7 @@ run_test "SNI: no SNI callback" \
run_test
"SNI: matching cert 1"
\
"
$P_SRV
debug_level=3
\
crt_file=data_files/server5.crt key_file=data_files/server5.key
\
sni=localhost,data_files/server2.crt,data_files/server2.key,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key"
\
sni=localhost,data_files/server2.crt,data_files/server2.key,
-,-,-,
polarssl.example,data_files/server1-nospace.crt,data_files/server1.key
,-,-,-
"
\
"
$P_CLI
server_name=localhost"
\
0
\
-s
"parse ServerName extension"
\
...
...
@@ -1768,7 +1768,7 @@ run_test "SNI: matching cert 1" \
run_test
"SNI: matching cert 2"
\
"
$P_SRV
debug_level=3
\
crt_file=data_files/server5.crt key_file=data_files/server5.key
\
sni=localhost,data_files/server2.crt,data_files/server2.key,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key"
\
sni=localhost,data_files/server2.crt,data_files/server2.key,
-,-,-,
polarssl.example,data_files/server1-nospace.crt,data_files/server1.key
,-,-,-
"
\
"
$P_CLI
server_name=polarssl.example"
\
0
\
-s
"parse ServerName extension"
\
...
...
@@ -1778,7 +1778,7 @@ run_test "SNI: matching cert 2" \
run_test
"SNI: no matching cert"
\
"
$P_SRV
debug_level=3
\
crt_file=data_files/server5.crt key_file=data_files/server5.key
\
sni=localhost,data_files/server2.crt,data_files/server2.key,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key"
\
sni=localhost,data_files/server2.crt,data_files/server2.key,
-,-,-,
polarssl.example,data_files/server1-nospace.crt,data_files/server1.key
,-,-,-
"
\
"
$P_CLI
server_name=nonesuch.example"
\
1
\
-s
"parse ServerName extension"
\
...
...
此差异已折叠。
点击以展开。
预览
0%
加载中
请重试
或
添加新附件
.
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
保存评论
取消
想要评论请
注册
或
登录