Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
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
videolan
vlc
Commits
062c2c3e
Commit
062c2c3e
authored
Jan 11, 2016
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tls: revector test
parent
ab9ea034
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
53 deletions
+63
-53
test/modules/misc/tls.c
test/modules/misc/tls.c
+63
-53
No files found.
test/modules/misc/tls.c
View file @
062c2c3e
...
...
@@ -63,18 +63,19 @@ static int question_callback(vlc_object_t *obj, const char *varname,
static
libvlc_instance_t
*
vlc
;
static
vlc_object_t
*
obj
;
static
vlc_tls_creds_t
*
server
;
static
vlc_tls_creds_t
*
client
;
static
vlc_tls_creds_t
*
server
_creds
;
static
vlc_tls_creds_t
*
client
_creds
;
static
void
*
tls_
handshake
(
void
*
data
)
static
void
*
tls_
echo
(
void
*
data
)
{
vlc_tls_t
*
tls
=
data
;
struct
pollfd
ufd
;
int
val
;
ssize_t
val
;
char
buf
[
4096
];
ufd
.
fd
=
tls
->
fd
;
while
((
val
=
vlc_tls_SessionHandshake
(
server
,
tls
))
>
0
)
while
((
val
=
vlc_tls_SessionHandshake
(
server
_creds
,
tls
))
>
0
)
{
switch
(
val
)
{
...
...
@@ -85,38 +86,47 @@ static void *tls_handshake(void *data)
poll
(
&
ufd
,
1
,
-
1
);
}
return
val
==
0
?
tls
:
NULL
;
if
(
val
<
0
)
goto
error
;
while
((
val
=
vlc_tls_Read
(
tls
,
buf
,
sizeof
(
buf
),
false
))
>
0
)
if
(
vlc_tls_Write
(
tls
,
buf
,
val
)
<
val
)
goto
error
;
if
(
val
<
0
||
vlc_tls_Shutdown
(
tls
,
false
))
goto
error
;
vlc_tls_Close
(
tls
);
return
tls
;
error:
vlc_tls_Close
(
tls
);
return
NULL
;
}
static
int
securepair
(
vlc_t
ls_t
*
securev
[
2
]
,
static
int
securepair
(
vlc_t
hread_t
*
th
,
vlc_tls_t
**
restrict
client
,
const
char
*
const
*
alpnv
[
2
],
char
**
restrict
alp
)
{
vlc_thread_t
th
;
void
*
p
;
vlc_tls_t
*
server
;
int
val
;
int
insecurev
[
2
];
val
=
tlspair
(
insecurev
);
assert
(
val
==
0
);
se
curev
[
0
]
=
vlc_tls_SessionCreate
(
server
,
insecurev
[
0
],
NULL
,
alpnv
[
0
]);
assert
(
se
curev
[
0
]
!=
NULL
);
se
rver
=
vlc_tls_SessionCreate
(
server_creds
,
insecurev
[
0
],
NULL
,
alpnv
[
0
]);
assert
(
se
rver
!=
NULL
);
val
=
vlc_clone
(
&
th
,
tls_handshake
,
securev
[
0
]
,
VLC_THREAD_PRIORITY_LOW
);
val
=
vlc_clone
(
th
,
tls_echo
,
server
,
VLC_THREAD_PRIORITY_LOW
);
assert
(
val
==
0
);
securev
[
1
]
=
vlc_tls_ClientSessionCreate
(
client
,
insecurev
[
1
],
"localhost"
,
"vlc-tls-test"
,
alpnv
[
1
],
alp
);
/* Server-side should always succeed (since client needs no credentials) */
vlc_join
(
th
,
&
p
);
assert
(
p
==
securev
[
0
]);
if
(
securev
[
1
]
==
NULL
)
*
client
=
vlc_tls_ClientSessionCreate
(
client_creds
,
insecurev
[
1
],
"localhost"
,
"vlc-tls-test"
,
alpnv
[
1
],
alp
);
if
(
*
client
==
NULL
)
{
val
=
close
(
insecurev
[
1
]);
assert
(
val
==
0
);
vlc_
tls_Close
(
securev
[
0
]
);
vlc_
join
(
*
th
,
NULL
);
return
-
1
;
}
return
0
;
...
...
@@ -127,7 +137,6 @@ static const char *const alpn[] = { "foo", "bar", NULL };
int
main
(
void
)
{
vlc_tls_t
*
securev
[
2
];
int
val
;
int
answer
=
0
;
...
...
@@ -146,37 +155,40 @@ int main(void)
assert
(
vlc
!=
NULL
);
obj
=
VLC_OBJECT
(
vlc
->
p_libvlc_int
);
server
=
vlc_tls_ServerCreate
(
obj
,
SRCDIR
"/does/not/exis
t"
,
NULL
);
assert
(
server
==
NULL
);
server
=
vlc_tls_ServerCreate
(
obj
,
SRCDIR
"/samples/empty.voc"
,
NULL
);
assert
(
server
==
NULL
);
server
=
vlc_tls_ServerCreate
(
obj
,
certpath
,
SRCDIR
"/does/not/exis
t"
);
assert
(
server
==
NULL
);
server
=
vlc_tls_ServerCreate
(
obj
,
certpath
,
NULL
);
if
(
server
==
NULL
)
server
_creds
=
vlc_tls_ServerCreate
(
obj
,
SRCDIR
"/nonexisten
t"
,
NULL
);
assert
(
server
_creds
==
NULL
);
server
_creds
=
vlc_tls_ServerCreate
(
obj
,
SRCDIR
"/samples/empty.voc"
,
NULL
);
assert
(
server
_creds
==
NULL
);
server
_creds
=
vlc_tls_ServerCreate
(
obj
,
certpath
,
SRCDIR
"/nonexisten
t"
);
assert
(
server
_creds
==
NULL
);
server
_creds
=
vlc_tls_ServerCreate
(
obj
,
certpath
,
NULL
);
if
(
server
_creds
==
NULL
)
{
libvlc_release
(
vlc
);
return
77
;
}
client
=
vlc_tls_ClientCreate
(
obj
);
assert
(
client
!=
NULL
);
client
_creds
=
vlc_tls_ClientCreate
(
obj
);
assert
(
client
_creds
!=
NULL
);
var_Create
(
obj
,
"dialog-question"
,
VLC_VAR_ADDRESS
);
var_AddCallback
(
obj
,
"dialog-question"
,
question_callback
,
&
answer
);
dialog_Register
(
obj
);
vlc_thread_t
th
;
vlc_tls_t
*
tls
;
const
char
*
const
*
alpnv
[
2
]
=
{
alpn
+
1
,
alpn
};
char
*
alp
;
void
*
p
;
/* Test unknown certificate */
answer
=
0
;
val
=
securepair
(
securev
,
alpnv
,
&
alp
);
val
=
securepair
(
&
th
,
&
tls
,
alpnv
,
&
alp
);
assert
(
val
==
-
1
);
/* Accept unknown certificate */
answer
=
2
;
val
=
securepair
(
securev
,
alpnv
,
&
alp
);
val
=
securepair
(
&
th
,
&
tls
,
alpnv
,
&
alp
);
assert
(
val
==
0
);
assert
(
alp
!=
NULL
);
assert
(
!
strcmp
(
alp
,
"bar"
));
...
...
@@ -185,46 +197,44 @@ int main(void)
/* Do some I/O */
char
buf
[
12
];
val
=
securev
[
1
]
->
recv
(
securev
[
1
]
,
buf
,
sizeof
(
buf
));
val
=
tls
->
recv
(
tls
,
buf
,
sizeof
(
buf
));
assert
(
val
==
-
1
&&
errno
==
EAGAIN
);
val
=
vlc_tls_Write
(
securev
[
0
]
,
"Hello "
,
6
);
val
=
vlc_tls_Write
(
tls
,
"Hello "
,
6
);
assert
(
val
==
6
);
val
=
vlc_tls_Write
(
securev
[
0
]
,
"world!"
,
6
);
val
=
vlc_tls_Write
(
tls
,
"world!"
,
6
);
assert
(
val
==
6
);
val
=
vlc_tls_Read
(
securev
[
1
]
,
buf
,
sizeof
(
buf
),
true
);
val
=
vlc_tls_Read
(
tls
,
buf
,
sizeof
(
buf
),
true
);
assert
(
val
==
12
);
assert
(
!
memcmp
(
buf
,
"Hello world!"
,
12
));
val
=
vlc_tls_Shutdown
(
securev
[
0
]
,
false
);
val
=
vlc_tls_Shutdown
(
tls
,
false
);
assert
(
val
==
0
);
v
al
=
vlc_tls_Read
(
securev
[
1
],
buf
,
sizeof
(
buf
),
false
);
assert
(
val
==
0
);
val
=
vlc_tls_
Shutdown
(
securev
[
1
],
tru
e
);
v
lc_join
(
th
,
&
p
);
assert
(
p
!=
NULL
);
val
=
vlc_tls_
Read
(
tls
,
buf
,
sizeof
(
buf
),
fals
e
);
assert
(
val
==
0
);
vlc_tls_Close
(
securev
[
1
]);
vlc_tls_Close
(
securev
[
0
]);
vlc_tls_Close
(
tls
);
/* Test known certificate, ignore ALPN result */
answer
=
0
;
val
=
securepair
(
securev
,
alpnv
,
NULL
);
val
=
securepair
(
&
th
,
&
tls
,
alpnv
,
NULL
);
assert
(
val
==
0
);
vlc_tls_Close
(
securev
[
1
]
);
vlc_
tls_Close
(
securev
[
0
]
);
vlc_tls_Close
(
tls
);
vlc_
join
(
th
,
NULL
);
/* Test known certificate, no ALPN */
alpnv
[
0
]
=
alpnv
[
1
]
=
NULL
;
val
=
securepair
(
securev
,
alpnv
,
NULL
);
val
=
securepair
(
&
th
,
&
tls
,
alpnv
,
NULL
);
assert
(
val
==
0
);
vlc_tls_Close
(
securev
[
1
]
);
vlc_
tls_Close
(
securev
[
0
]
);
vlc_tls_Close
(
tls
);
vlc_
join
(
th
,
NULL
);
dialog_Unregister
(
obj
);
var_DelCallback
(
obj
,
"dialog-question"
,
question_callback
,
&
answer
);
vlc_tls_Delete
(
client
);
vlc_tls_Delete
(
server
);
vlc_tls_Delete
(
client
_creds
);
vlc_tls_Delete
(
server
_creds
);
libvlc_release
(
vlc
);
if
(
!
strncmp
(
homedir
,
"/tmp/vlc-test-"
,
14
))
...
...
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