Skip to content

Commit c1a7f79

Browse files
authored
Merge pull request #68 from Geod24/add-ci
Add sslecho example, a missing const, and a CI script with multiple versions
2 parents b3b6a71 + 1cb16f6 commit c1a7f79

File tree

9 files changed

+505
-5
lines changed

9 files changed

+505
-5
lines changed

.github/workflows/ci.yml

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# Test the bindings using various OpenSSL versions
2+
#
3+
# For Linux / Windows, we cannot rely on the package manager,
4+
# as each new release will come with a specific OpenSSL version,
5+
# and we don't have control over this.
6+
#
7+
# Instead, this workflow installs an explicit version, builds it,
8+
# and test the tls package with it.
9+
name: CI
10+
11+
on: [push, pull_request]
12+
13+
jobs:
14+
deps:
15+
strategy:
16+
matrix:
17+
os: [ ubuntu-latest ]
18+
openssl:
19+
- version: 1.0.2u
20+
link: https://www.openssl.org/source/old/1.0.2/openssl-1.0.2u.tar.gz
21+
- version: 1.1.0l
22+
link: https://www.openssl.org/source/old/1.1.0/openssl-1.1.0l.tar.gz
23+
- version: 1.1.1o
24+
link: https://www.openssl.org/source/openssl-1.1.1o.tar.gz
25+
- version: 3.0.3
26+
link: https://www.openssl.org/source/openssl-3.0.3.tar.gz
27+
28+
runs-on: ${{ matrix.os }}
29+
timeout-minutes: 15
30+
31+
# Build the OpenSSL version if not already cached
32+
steps:
33+
- name: 'Looking up cache'
34+
id: cache-openssl
35+
uses: actions/cache@v1
36+
with:
37+
path: ${{ github.workspace }}/openssl/
38+
key: ${{ runner.os }}-${{ runner.arch }}-${{ matrix.openssl.version }}
39+
40+
- name: 'Download and build OpenSSL ${{ matrix.openssl.version }}'
41+
if: steps.cache-openssl.outputs.cache-hit != 'true'
42+
run: |
43+
mkdir -p ${{ github.workspace }}/openssl/
44+
pushd ${{ github.workspace }}/openssl/
45+
wget -O download.tar.gz ${{ matrix.openssl.link }}
46+
tar -xf download.tar.gz
47+
pushd openssl-${{ matrix.openssl.version }}/
48+
./config --prefix=${{ github.workspace }}/openssl/install/
49+
make install
50+
echo "OpenSSL ${{ matrix.openssl.version }} has been installed in: ${{ github.workspace }}/openssl/install/"
51+
52+
# The previous job was separated to avoid a build once per matrix row,
53+
# as opposed to once per platform / version as we want.
54+
test:
55+
needs: deps
56+
strategy:
57+
fail-fast: false
58+
matrix:
59+
os: [ ubuntu-latest ]
60+
dc:
61+
- dmd-latest
62+
- ldc-latest
63+
openssl:
64+
- version: 1.0.2u
65+
lib-dir: lib
66+
- version: 1.1.0l
67+
lib-dir: lib
68+
- version: 1.1.1o
69+
lib-dir: lib
70+
- version: 3.0.3
71+
lib-dir: lib64
72+
73+
runs-on: ${{ matrix.os }}
74+
timeout-minutes: 60
75+
76+
steps:
77+
- uses: actions/checkout@v2
78+
79+
- name: Prepare compiler
80+
uses: dlang-community/setup-dlang@v1
81+
with:
82+
compiler: ${{ matrix.dc }}
83+
84+
# Restore or install build openssl version
85+
- name: 'Restore openssl from cache'
86+
id: lookup-openssl
87+
uses: actions/cache@v1
88+
with:
89+
path: ${{ github.workspace }}/openssl/
90+
key: ${{ matrix.os }}-${{ matrix.openssl.version }}
91+
92+
- name: 'Make sure OpenSSL was loaded from cache'
93+
if: steps.lookup-openssl.outputs.cache-hit != 'true'
94+
run: exit 1
95+
96+
- name: 'Remove OpenSSL package, export env variables'
97+
run: |
98+
sudo apt-get remove -y libssl-dev
99+
echo "PKG_CONFIG_PATH=${{ github.workspace }}/openssl/install/${{ matrix.openssl.lib-dir }}/pkgconfig/" >> $GITHUB_ENV
100+
echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${{ github.workspace }}/openssl/install/${{ matrix.openssl.lib-dir }}/" >> $GITHUB_ENV
101+
102+
- name: 'Run tests'
103+
run: |
104+
echo "pkg-config uses: $(pkg-config --modversion openssl)"
105+
if [ `pkg-config --modversion openssl` != "${{ matrix.openssl.version }}" ]; then
106+
echo "Expected version '${{ matrix.openssl.version }}' but got `pkg-config --modversion openssl`"
107+
exit 1
108+
fi
109+
cd examples/sslecho/
110+
${{ github.workspace }}/openssl/install/bin/openssl req -batch -newkey rsa:4096 -x509 -sha256 -days 3650 -subj "/C=GB/CN=localhost" -nodes -out cert.pem -keyout key.pem
111+
dub build
112+
# TODO: FIXME: This currently does not work because certificate verification fails (works on my machine).
113+
# But at least it links, which is a good starting point.
114+
#$DC -run test.d

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@
55
/.dub/
66
/openssl
77
/*-test-library
8+
9+
/examples/sslecho/sslecho
10+
/examples/sslecho/test

examples/sslecho/.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.dub
2+
docs.json
3+
__dummy.html
4+
docs/
5+
/sslecho
6+
sslecho.so
7+
sslecho.dylib
8+
sslecho.dll
9+
sslecho.a
10+
sslecho.lib
11+
sslecho-test-*
12+
*.exe
13+
*.o
14+
*.obj
15+
*.lst

examples/sslecho/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# sslecho: A simple echo server
2+
3+
This example was ported from [the official OpenSSL repository](https://github.com/openssl/openssl/tree/ef8040bce02758de86fc55412ee4ac9102f9ffab/demos/sslecho).
4+
The certificates can be generated using:
5+
```shell
6+
openssl req -batch -newkey rsa:4096 -x509 -sha256 -days 3650 -subj "/C=FR/CN=localhost" -nodes -out cert.pem -keyout key.pem
7+
```
8+
And 'localhost' was used as domain.
9+
10+
The server and client need to be called with the following commands (respectively):
11+
```shell
12+
$ ./sslecho s # Starts the server
13+
$ ./sslecho c localhost
14+
```
15+
Note that using `127.0.0.1` will not work.

examples/sslecho/dub.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "sslecho",
3+
"description": "Port of OpenSSL demo of the same name",
4+
5+
"dependencies": {
6+
"openssl": {
7+
"path": "../../"
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)