Skip to content

Commit

Permalink
Test server behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
ctz committed Apr 10, 2024
1 parent 0367fe2 commit 0363e48
Show file tree
Hide file tree
Showing 5 changed files with 389 additions and 8 deletions.
5 changes: 4 additions & 1 deletion rustls-libssl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ifneq (,$(TARGET))
CARGOFLAGS += --target $(TARGET)
endif

all: target/ciphers target/client target/constants target/$(PROFILE)/libssl.so.3
all: target/ciphers target/client target/constants target/server target/$(PROFILE)/libssl.so.3

test: all
${CARGO} test $(CARGOFLAGS)
Expand Down Expand Up @@ -48,6 +48,9 @@ target/client: target/client.o
target/constants: target/constants.o
$(CC) -o $@ $^ $(LDFLAGS) $(shell pkg-config --libs openssl)

target/server: target/server.o
$(CC) -o $@ $^ $(LDFLAGS) $(shell pkg-config --libs openssl)

clean:
rm -rf target

Expand Down
82 changes: 82 additions & 0 deletions rustls-libssl/test-ca/rsa/server.cert
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
-----BEGIN CERTIFICATE-----
MIIEGDCCAoCgAwIBAgICAcgwDQYJKoZIhvcNAQELBQAwLDEqMCgGA1UEAwwhcG9u
eXRvd24gUlNBIGxldmVsIDIgaW50ZXJtZWRpYXRlMB4XDTIzMTIyMTE3MjMxNVoX
DTI5MDYxMjE3MjMxNVowGTEXMBUGA1UEAwwOdGVzdHNlcnZlci5jb20wggEiMA0G
CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDDI1plwQmA+rr6Evlvn2hzIB/zYKlx
Tm14SPzomxpaf3OpzXzHuOn34yVvU1vTDijUl/YJbcnx052m0075SYeuW08VQB/p
zjhLrFp1ULSD272IddbB88T8Jq/VZ5dAxBB1q6Tm0vGBYQ8eIcmJv+fJQTbTXHKQ
KPHQRmVyqXVkwvwcgEJi9gpOcEEpJ6SDGdyGh1ck3wGnhrSpmsu+hwUVi7las+Ka
QUlvkmD+UGQKo8Ta91Xu8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H9Iw+AXwUYjCb62Gy58yzu
uk3Q+msRr3oVI9bBhmEXmZxyENYJrw305qOlI3+tHBoJLUSP6zQ214aEu4trJr5K
kmbF7DZRG9MSBXeRk7e5ojK13xI1/XCjgIOTkGxF4rEFbVwhc0B8zS/2x3zw0fkE
M4J0J+gz0QYr
-----END CERTIFICATE-----
28 changes: 28 additions & 0 deletions rustls-libssl/test-ca/rsa/server.key
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDDI1plwQmA+rr6
Evlvn2hzIB/zYKlxTm14SPzomxpaf3OpzXzHuOn34yVvU1vTDijUl/YJbcnx052m
0075SYeuW08VQB/pzjhLrFp1ULSD272IddbB88T8Jq/VZ5dAxBB1q6Tm0vGBYQ8e
IcmJv+fJQTbTXHKQKPHQRmVyqXVkwvwcgEJi9gpOcEEpJ6SDGdyGh1ck3wGnhrSp
msu+hwUVi7las+KaQUlvkmD+UGQKo8Ta91Xu8ja25QLTpjVcYxbi719rtA6I9DpX
4+3aeIy/0s1xk0XiyMXIjSl3dn47gp3IZFRCECuoTdOwOZ9+y9ENnpHvZ84jCBXd
dU09qheJAgMBAAECggEABbzZYJqPc/prWwUJzo1qXdA5AEf8U3eR4nKK9S/yU2zh
8sE3BQxb3M0SAbb6wTbuXmnlcxuGT5UAUrJt5QiTc739kktjZNWKdDcqJb7sv9/L
L+L/II7RYPSmQOkd2mqpbTxRyfOz5DD9Z85ohaNd5l4Dha13NOPvUEdxnjB7Yi4I
YbUYZ/Zq6MUosFRObS0XPBvk6d+zDI3WUZatVTNfuS7fqI1BvkXs5EkV34DQXgQs
LKb1LFAoEZoh64UnfkONIT9oG4OTbbaQ9gCbfQPpKw07GuaMdtjp0QD0yldOKvL4
V4crSZyj2f3LnPCqCjUwcz6quKSUqUgosVApH+JCcQKBgQDpaGXy3laYTK3zbauh
+eHY5Ia+7fM2ETZx4LfwAYA1K5E84T98swpO571lZVrbOKjBukpUrbHdOcEVcBRH
BTvCh1vL1AXXWR0cCvWtp/WAbu90rDqgu6mxaD+V8wGq29URTWOCRG1WA7zeNHPB
0XAZPLQVeqeSvHGLSqyPf4aoHQKBgQDWBqvl5To7P4ZT6VFl18v0EB3zgzpRuyC3
xKKz5mGw4tuvspdMU2XaOGQsRl5emMijGeII7JUweHbBdkq44S2FZ9wyn4+I+8Oi
Atu4Nce06ARnw+5RRcJlSs/LrExfOtxF3xp8EQqpL/jEO03n7G5cwcFwuWTKoVTI
0RwcuU4JXQKBgDBMCvRzb2W6UDBT3DT7GPGhcARoBnCEpUhxIH6IQPg/mKEJVvK9
tX9YUod9row4MCtOGf1lp61IOxztgTSk75W0HpmRuNezt+NKnUWewJ0f12rEDKmf
y2BLWwTzMMAjFvaqldGpyRoIUfeE0QMlDFYcioL7S1uApNoWzJgw4jM9AoGBANIk
osuLku1xphbl08JHbD4rRP1AMBbnwWwuagJxhiID3OhaVivfBvaIv/Ko9Se0o+th
EorooGODJDc4So3Uqrl+DLq36Fr7uE5uuAXa6Ec8OHcZ7flmoUSLfBPjDOnEBVul
f3+py+nq7Drgb9H0VzhEFgb0QX6jgXfbudqKJ5ERAoGAR5Q6wQEoT9VT53nuKprl
3K/6agd+4wlpVQW0W1LImdrJHRHUXO7KJe7Bo5rtjL3lw8dCl3olHlLPJKg9frMn
ZWvJ2t0zca18S76rNcsPew2BecJxNRFlGwdcE1BBA2p/yzBhsZbIO7eqfh+dK5va
rnlrPNbWDhylxMaU4/CoU7k=
-----END PRIVATE KEY-----
97 changes: 90 additions & 7 deletions rustls-libssl/tests/runner.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::io::Read;
use std::process::{Child, Command, Output, Stdio};
use std::{net, thread, time};

Expand Down Expand Up @@ -30,7 +31,7 @@ use std::{net, thread, time};
#[test]
#[ignore]
fn client_unauthenticated() {
let _server = KillOnDrop(
let _server = KillOnDrop(Some(
Command::new("openssl")
.args([
"s_server",
Expand All @@ -49,7 +50,7 @@ fn client_unauthenticated() {
.env("LD_LIBRARY_PATH", "")
.spawn()
.expect("failed to start openssl s_server"),
);
));

wait_for_port(4443);

Expand Down Expand Up @@ -125,7 +126,7 @@ fn client_unauthenticated() {
#[test]
#[ignore]
fn client_auth() {
let _server = KillOnDrop(
let _server = KillOnDrop(Some(
Command::new("openssl")
.args([
"s_server",
Expand All @@ -148,7 +149,7 @@ fn client_auth() {
.env("LD_LIBRARY_PATH", "")
.spawn()
.expect("failed to start openssl s_server"),
);
));

wait_for_port(4444);

Expand Down Expand Up @@ -269,12 +270,77 @@ fn ciphers() {
assert_eq!(openssl_output, rustls_output);
}

struct KillOnDrop(Child);
#[test]
#[ignore]
fn server() {
fn curl() {
Command::new("curl")
.env("LD_LIBRARY_PATH", "")
.args([
"-v",
"--cacert",
"test-ca/rsa/ca.cert",
"https://localhost:5555/",
])
.stdout(Stdio::piped())
.output()
.map(print_output)
.unwrap();
}

let mut openssl_server = KillOnDrop(Some(
Command::new("tests/maybe-valgrind.sh")
.env("LD_LIBRARY_PATH", "")
.args([
"target/server",
"5555",
"test-ca/rsa/server.key",
"test-ca/rsa/server.cert",
"unauth",
])
.stdout(Stdio::piped())
.spawn()
.unwrap(),
));
wait_for_stdout(openssl_server.0.as_mut().unwrap(), b"listening\n");
curl();

let openssl_output = print_output(openssl_server.take_inner().wait_with_output().unwrap());

let mut rustls_server = KillOnDrop(Some(
Command::new("tests/maybe-valgrind.sh")
.args([
"target/server",
"5555",
"test-ca/rsa/server.key",
"test-ca/rsa/server.cert",
"unauth",
])
.stdout(Stdio::piped())
.spawn()
.unwrap(),
));
wait_for_stdout(rustls_server.0.as_mut().unwrap(), b"listening\n");
curl();

let rustls_output = print_output(rustls_server.take_inner().wait_with_output().unwrap());
assert_eq!(openssl_output, rustls_output);
}

struct KillOnDrop(Option<Child>);

impl KillOnDrop {
fn take_inner(&mut self) -> Child {
self.0.take().unwrap()
}
}

impl Drop for KillOnDrop {
fn drop(&mut self) {
self.0.kill().expect("failed to kill subprocess");
self.0.wait().expect("failed to wait for killed subprocess");
if let Some(mut child) = self.0.take() {
child.kill().expect("failed to kill subprocess");
child.wait().expect("failed to wait for killed subprocess");
}
}
}

Expand Down Expand Up @@ -306,3 +372,20 @@ fn wait_for_port(port: u16) -> Option<()> {
}
}
}

fn wait_for_stdout(stream: &mut Child, expected: &[u8]) {
let stdout = stream.stdout.as_mut().unwrap();

let mut buffer = Vec::with_capacity(1024);

loop {
let mut input = [0u8];
let new = stdout.read(&mut input).unwrap();
assert_eq!(new, 1);
buffer.push(input[0]);

if buffer.ends_with(expected) {
return;
}
}
}
Loading

0 comments on commit 0363e48

Please sign in to comment.