Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
4fa8ed49
提交
4fa8ed49
authored
1月 11, 2012
作者:
Marc Olivier Chouinard
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Revert patch that shouldn't have been commited !
上级
8220e0bd
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
216 行增加
和
0 行删除
+216
-0
configure.ac
libs/iksemel/configure.ac
+3
-0
stream.c
libs/iksemel/src/stream.c
+213
-0
没有找到文件。
libs/iksemel/configure.ac
浏览文件 @
4fa8ed49
...
@@ -52,6 +52,9 @@ AC_CHECK_FUNCS(getaddrinfo)
...
@@ -52,6 +52,9 @@ AC_CHECK_FUNCS(getaddrinfo)
#AX_PATH_LIBGNUTLS(,AC_DEFINE(HAVE_GNUTLS,,"Use libgnutls"))
#AX_PATH_LIBGNUTLS(,AC_DEFINE(HAVE_GNUTLS,,"Use libgnutls"))
m4_include([openssl.m4])
SAC_OPENSSL
dnl Check -Wall flag of GCC
dnl Check -Wall flag of GCC
if test "x$GCC" = "xyes"; then
if test "x$GCC" = "xyes"; then
if test -z "`echo "$CFLAGS" | grep "\-Wall" 2> /dev/null`" ; then
if test -z "`echo "$CFLAGS" | grep "\-Wall" 2> /dev/null`" ; then
...
...
libs/iksemel/src/stream.c
浏览文件 @
4fa8ed49
...
@@ -19,6 +19,19 @@
...
@@ -19,6 +19,19 @@
#include <gnutls/gnutls.h>
#include <gnutls/gnutls.h>
#endif
#endif
#ifdef HAVE_SSL
#include <openssl/ssl.h>
#include <openssl/err.h>
#ifdef WIN32
typedef
unsigned
__int32
uint32_t
;
#else
#ifdef HAVE_SYS_SELECT_H
#include <sys/select.h>
#endif
#include <poll.h>
#endif
#endif
#define SF_FOREIGN 1
#define SF_FOREIGN 1
#define SF_TRY_SECURE 2
#define SF_TRY_SECURE 2
#define SF_SECURE 4
#define SF_SECURE 4
...
@@ -41,9 +54,63 @@ struct stream_data {
...
@@ -41,9 +54,63 @@ struct stream_data {
#ifdef HAVE_GNUTLS
#ifdef HAVE_GNUTLS
gnutls_session
sess
;
gnutls_session
sess
;
gnutls_certificate_credentials
cred
;
gnutls_certificate_credentials
cred
;
#elif HAVE_SSL
SSL
*
ssl
;
SSL_CTX
*
ssl_ctx
;
#endif
#endif
};
};
#ifdef HAVE_SSL
#ifdef WIN32
static
int
sock_read_ready
(
struct
stream_data
*
data
,
uint32_t
ms
)
{
int
r
=
0
;
fd_set
fds
;
struct
timeval
tv
;
FD_ZERO
(
&
fds
);
#ifdef WIN32
#pragma warning( push )
#pragma warning( disable : 4127 )
FD_SET
(
SSL_get_fd
(
data
->
ssl
),
&
fds
);
#pragma warning( pop )
#else
FD_SET
(
SSL_get_fd
(
data
->
ssl
),
&
fds
);
#endif
tv
.
tv_sec
=
ms
/
1000
;
tv
.
tv_usec
=
(
ms
%
1000
)
*
ms
;
r
=
select
(
SSL_get_fd
(
data
->
ssl
)
+
1
,
&
fds
,
NULL
,
NULL
,
&
tv
);
return
r
;
}
#else
static
int
sock_read_ready
(
struct
stream_data
*
data
,
int
ms
)
{
struct
pollfd
pfds
[
2
]
=
{
{
0
}
};
int
s
=
0
,
r
=
0
;
pfds
[
0
].
fd
=
SSL_get_fd
(
data
->
ssl
);
pfds
[
0
].
events
|=
POLLIN
;
s
=
poll
(
pfds
,
1
,
ms
);
if
(
s
<
0
)
{
r
=
s
;
}
else
if
(
s
>
0
)
{
if
((
pfds
[
0
].
revents
&
POLLIN
))
{
r
=
1
;
}
}
return
r
;
}
#endif
#endif
#ifdef HAVE_GNUTLS
#ifdef HAVE_GNUTLS
#ifndef WIN32
#ifndef WIN32
#include <gcrypt.h>
#include <gcrypt.h>
...
@@ -121,6 +188,86 @@ handshake (struct stream_data *data)
...
@@ -121,6 +188,86 @@ handshake (struct stream_data *data)
return
IKS_OK
;
return
IKS_OK
;
}
// HAVE_GNUTLS
}
// HAVE_GNUTLS
#elif HAVE_SSL
static
int
wait_for_data
(
struct
stream_data
*
data
,
int
ret
,
int
timeout
)
{
struct
timeval
tv
;
fd_set
fds
;
int
err
;
int
retval
=
IKS_OK
;
err
=
SSL_get_error
(
data
->
ssl
,
ret
);
switch
(
err
)
{
case
SSL_ERROR_WANT_READ
:
case
SSL_ERROR_WANT_WRITE
:
ret
=
sock_read_ready
(
data
,
timeout
*
1000
);
if
(
ret
==
-
1
)
{
retval
=
IKS_NET_TLSFAIL
;
}
break
;
default:
if
(
data
->
logHook
)
data
->
logHook
(
data
->
user_data
,
ERR_error_string
(
err
,
NULL
),
strlen
(
ERR_error_string
(
err
,
NULL
)),
1
);
retval
=
IKS_NET_TLSFAIL
;
break
;
}
ERR_clear_error
();
return
retval
;
}
static
int
handshake
(
struct
stream_data
*
data
)
{
int
ret
;
int
finished
;
SSL_library_init
();
SSL_load_error_strings
();
data
->
ssl_ctx
=
SSL_CTX_new
(
TLSv1_method
());
if
(
!
data
->
ssl_ctx
)
return
IKS_NOMEM
;
data
->
ssl
=
SSL_new
(
data
->
ssl_ctx
);
if
(
!
data
->
ssl
)
return
IKS_NOMEM
;
if
(
SSL_set_fd
(
data
->
ssl
,
(
int
)
data
->
sock
)
!=
1
)
return
IKS_NOMEM
;
/* Set both the read and write BIO's to non-blocking mode */
BIO_set_nbio
(
SSL_get_rbio
(
data
->
ssl
),
1
);
BIO_set_nbio
(
SSL_get_wbio
(
data
->
ssl
),
1
);
finished
=
0
;
do
{
ret
=
SSL_connect
(
data
->
ssl
);
if
(
ret
!=
1
)
{
if
(
wait_for_data
(
data
,
ret
,
1
)
!=
IKS_OK
)
{
finished
=
1
;
SSL_free
(
data
->
ssl
);
}
}
}
while
(
ret
!=
1
&&
finished
!=
1
);
if
(
ret
==
1
)
{
data
->
flags
&=
(
~
SF_TRY_SECURE
);
data
->
flags
|=
SF_SECURE
;
iks_send_header
(
data
->
prs
,
data
->
server
);
}
return
ret
==
1
?
IKS_OK
:
IKS_NET_TLSFAIL
;
}
#endif
#endif
static
void
static
void
...
@@ -295,6 +442,15 @@ tagHook (struct stream_data *data, char *name, char **atts, int type)
...
@@ -295,6 +442,15 @@ tagHook (struct stream_data *data, char *name, char **atts, int type)
return
IKS_NET_TLSFAIL
;
return
IKS_NET_TLSFAIL
;
}
}
}
}
#elif HAVE_SSL
if
(
data
->
flags
&
SF_TRY_SECURE
)
{
if
(
strcmp
(
name
,
"proceed"
)
==
0
)
{
err
=
handshake
(
data
);
return
err
;
}
else
if
(
strcmp
(
name
,
"failure"
)
==
0
){
return
IKS_NET_TLSFAIL
;
}
}
#endif
#endif
if
(
data
->
current
)
{
if
(
data
->
current
)
{
x
=
iks_insert
(
data
->
current
,
name
);
x
=
iks_insert
(
data
->
current
,
name
);
...
@@ -351,6 +507,11 @@ deleteHook (struct stream_data *data)
...
@@ -351,6 +507,11 @@ deleteHook (struct stream_data *data)
gnutls_deinit
(
data
->
sess
);
gnutls_deinit
(
data
->
sess
);
gnutls_certificate_free_credentials
(
data
->
cred
);
gnutls_certificate_free_credentials
(
data
->
cred
);
}
}
#elif HAVE_SSL
if
(
data
->
flags
&
SF_SECURE
)
{
if
(
SSL_shutdown
(
data
->
ssl
)
==
0
)
SSL_shutdown
(
data
->
ssl
);
SSL_free
(
data
->
ssl
);
}
#endif
#endif
if
(
data
->
trans
)
data
->
trans
->
close
(
data
->
sock
);
if
(
data
->
trans
)
data
->
trans
->
close
(
data
->
sock
);
data
->
trans
=
NULL
;
data
->
trans
=
NULL
;
...
@@ -508,12 +669,46 @@ iks_recv (iksparser *prs, int timeout)
...
@@ -508,12 +669,46 @@ iks_recv (iksparser *prs, int timeout)
struct
stream_data
*
data
=
iks_user_data
(
prs
);
struct
stream_data
*
data
=
iks_user_data
(
prs
);
int
len
,
ret
;
int
len
,
ret
;
#ifdef HAVE_SSL
int
err
;
struct
timeval
tv
;
fd_set
fds
;
#endif
while
(
1
)
{
while
(
1
)
{
#ifdef HAVE_GNUTLS
#ifdef HAVE_GNUTLS
if
(
data
->
flags
&
SF_SECURE
)
{
if
(
data
->
flags
&
SF_SECURE
)
{
len
=
gnutls_record_recv
(
data
->
sess
,
data
->
buf
,
NET_IO_BUF_SIZE
-
1
);
len
=
gnutls_record_recv
(
data
->
sess
,
data
->
buf
,
NET_IO_BUF_SIZE
-
1
);
if
(
len
==
0
)
len
=
-
1
;
if
(
len
==
0
)
len
=
-
1
;
}
else
}
else
#elif HAVE_SSL
if
(
data
->
flags
&
SF_SECURE
)
{
ret
=
sock_read_ready
(
data
,
timeout
*
1000
);
if
(
ret
==
-
1
)
{
return
IKS_NET_TLSFAIL
;
}
else
if
(
ret
==
0
)
{
return
IKS_OK
;
}
else
{
len
=
SSL_read
(
data
->
ssl
,
data
->
buf
,
NET_IO_BUF_SIZE
-
1
);
}
if
(
len
<=
0
)
{
switch
(
err
=
SSL_get_error
(
data
->
ssl
,
len
)
)
{
case
SSL_ERROR_WANT_READ
:
case
SSL_ERROR_WANT_WRITE
:
return
IKS_OK
;
break
;
default:
if
(
data
->
logHook
)
data
->
logHook
(
data
->
user_data
,
ERR_error_string
(
err
,
NULL
),
strlen
(
ERR_error_string
(
err
,
NULL
)),
1
);
return
IKS_NET_TLSFAIL
;
break
;
}
}
}
else
#endif
#endif
{
{
len
=
data
->
trans
->
recv
(
data
->
sock
,
data
->
buf
,
NET_IO_BUF_SIZE
-
1
,
timeout
);
len
=
data
->
trans
->
recv
(
data
->
sock
,
data
->
buf
,
NET_IO_BUF_SIZE
-
1
,
timeout
);
...
@@ -570,6 +765,10 @@ iks_send_raw (iksparser *prs, const char *xmlstr)
...
@@ -570,6 +765,10 @@ iks_send_raw (iksparser *prs, const char *xmlstr)
if
(
data
->
flags
&
SF_SECURE
)
{
if
(
data
->
flags
&
SF_SECURE
)
{
if
(
gnutls_record_send
(
data
->
sess
,
xmlstr
,
strlen
(
xmlstr
))
<
0
)
return
IKS_NET_RWERR
;
if
(
gnutls_record_send
(
data
->
sess
,
xmlstr
,
strlen
(
xmlstr
))
<
0
)
return
IKS_NET_RWERR
;
}
else
}
else
#elif HAVE_SSL
if
(
data
->
flags
&
SF_SECURE
)
{
if
(
SSL_write
(
data
->
ssl
,
xmlstr
,
strlen
(
xmlstr
))
<
0
)
return
IKS_NET_RWERR
;
}
else
#endif
#endif
{
{
ret
=
data
->
trans
->
send
(
data
->
sock
,
xmlstr
,
strlen
(
xmlstr
));
ret
=
data
->
trans
->
send
(
data
->
sock
,
xmlstr
,
strlen
(
xmlstr
));
...
@@ -592,6 +791,8 @@ iks_has_tls (void)
...
@@ -592,6 +791,8 @@ iks_has_tls (void)
{
{
#ifdef HAVE_GNUTLS
#ifdef HAVE_GNUTLS
return
1
;
return
1
;
#elif HAVE_SSL
return
1
;
#else
#else
return
0
;
return
0
;
#endif
#endif
...
@@ -603,6 +804,10 @@ iks_is_secure (iksparser *prs)
...
@@ -603,6 +804,10 @@ iks_is_secure (iksparser *prs)
#ifdef HAVE_GNUTLS
#ifdef HAVE_GNUTLS
struct
stream_data
*
data
=
iks_user_data
(
prs
);
struct
stream_data
*
data
=
iks_user_data
(
prs
);
return
data
->
flags
&
SF_SECURE
;
#elif HAVE_SSL
struct
stream_data
*
data
=
iks_user_data
(
prs
);
return
data
->
flags
&
SF_SECURE
;
return
data
->
flags
&
SF_SECURE
;
#else
#else
return
0
;
return
0
;
...
@@ -642,6 +847,14 @@ iks_start_tls (iksparser *prs)
...
@@ -642,6 +847,14 @@ iks_start_tls (iksparser *prs)
int
ret
;
int
ret
;
struct
stream_data
*
data
=
iks_user_data
(
prs
);
struct
stream_data
*
data
=
iks_user_data
(
prs
);
ret
=
iks_send_raw
(
prs
,
"<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>"
);
if
(
ret
)
return
ret
;
data
->
flags
|=
SF_TRY_SECURE
;
return
IKS_OK
;
#elif HAVE_SSL
int
ret
;
struct
stream_data
*
data
=
iks_user_data
(
prs
);
ret
=
iks_send_raw
(
prs
,
"<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>"
);
ret
=
iks_send_raw
(
prs
,
"<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>"
);
if
(
ret
)
return
ret
;
if
(
ret
)
return
ret
;
data
->
flags
|=
SF_TRY_SECURE
;
data
->
flags
|=
SF_TRY_SECURE
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论