Skip to content

Commit 189d384

Browse files
committedMay 18, 2022
Enable ED25519 E2E tests
OpenSSL finally caught up. Closes: #11
1 parent ba33f3d commit 189d384

File tree

4 files changed

+101
-89
lines changed

4 files changed

+101
-89
lines changed
 

‎e2e/e2e_openssl_test.go

+55-7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"net"
1313
"os"
1414
"os/exec"
15+
"regexp"
1516
"strings"
1617
"testing"
1718
"time"
@@ -167,19 +168,22 @@ func clientOpenSSL(c *comm) {
167168
func ciphersOpenSSL(cfg *dtls.Config) string {
168169
// See https://tls.mbed.org/supported-ssl-ciphersuites
169170
translate := map[dtls.CipherSuiteID]string{
170-
dtls.TLS_ECDHE_ECDSA_WITH_AES_128_CCM: "ECDHE-ECDSA-AES128-CCM",
171-
dtls.TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8: "ECDHE-ECDSA-AES128-CCM8",
171+
dtls.TLS_ECDHE_ECDSA_WITH_AES_128_CCM: "ECDHE-ECDSA-AES128-CCM",
172+
dtls.TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8: "ECDHE-ECDSA-AES128-CCM8",
173+
172174
dtls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256: "ECDHE-ECDSA-AES128-GCM-SHA256",
173-
dtls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256: "ECDHE-RSA-AES128-GCM-SHA256",
174175
dtls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384: "ECDHE-ECDSA-AES256-GCM-SHA384",
175-
dtls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384: "ECDHE-RSA-AES256-GCM-SHA384",
176+
177+
dtls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256: "ECDHE-RSA-AES128-GCM-SHA256",
178+
dtls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384: "ECDHE-RSA-AES256-GCM-SHA384",
176179

177180
dtls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA: "ECDHE-ECDSA-AES256-SHA",
178181
dtls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA: "ECDHE-RSA-AES256-SHA",
179182

180-
dtls.TLS_PSK_WITH_AES_128_CCM: "PSK-AES128-CCM",
181-
dtls.TLS_PSK_WITH_AES_128_CCM_8: "PSK-AES128-CCM8",
182-
dtls.TLS_PSK_WITH_AES_256_CCM_8: "PSK-AES256-CCM8",
183+
dtls.TLS_PSK_WITH_AES_128_CCM: "PSK-AES128-CCM",
184+
dtls.TLS_PSK_WITH_AES_128_CCM_8: "PSK-AES128-CCM8",
185+
dtls.TLS_PSK_WITH_AES_256_CCM_8: "PSK-AES256-CCM8",
186+
183187
dtls.TLS_PSK_WITH_AES_128_GCM_SHA256: "PSK-AES128-GCM-SHA256",
184188

185189
dtls.TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256: "ECDHE-PSK-AES128-CBC-SHA256",
@@ -228,6 +232,38 @@ func writeTempPEM(cfg *dtls.Config) (string, string, error) {
228232
return certOut.Name(), keyOut.Name(), nil
229233
}
230234

235+
func minimumOpenSSLVersion(t *testing.T) bool {
236+
t.Helper()
237+
238+
cmd := exec.Command("openssl", "version")
239+
allOut, err := cmd.CombinedOutput()
240+
if err != nil {
241+
t.Log("Cannot determine OpenSSL version: ", err)
242+
return false
243+
}
244+
verMatch := regexp.MustCompile(`(?i)^OpenSSL\s(?P<version>(\d+\.)?(\d+\.)?(\*|\d+)(\w)?).+$`)
245+
match := verMatch.FindStringSubmatch(strings.TrimSpace(string(allOut)))
246+
params := map[string]string{}
247+
for i, name := range verMatch.SubexpNames() {
248+
if i > 0 && i <= len(match) {
249+
params[name] = match[i]
250+
}
251+
}
252+
var ver string
253+
if val, ok := params["version"]; !ok {
254+
t.Log("Could not extract OpenSSL version")
255+
return false
256+
} else {
257+
ver = val
258+
}
259+
260+
cmp := strings.Compare(ver, "3.0.0")
261+
if cmp == -1 {
262+
return false
263+
}
264+
return true
265+
}
266+
231267
func TestPionOpenSSLE2ESimple(t *testing.T) {
232268
t.Run("OpenSSLServer", func(t *testing.T) {
233269
testPionE2ESimple(t, serverOpenSSL, clientPion)
@@ -254,3 +290,15 @@ func TestPionOpenSSLE2EMTUs(t *testing.T) {
254290
testPionE2EMTUs(t, serverPion, clientOpenSSL)
255291
})
256292
}
293+
294+
func TestPionOpenSSLE2ESimpleED25519(t *testing.T) {
295+
t.Run("OpenSSLServer", func(t *testing.T) {
296+
if !minimumOpenSSLVersion(t) {
297+
t.Skip("Cannot use OpenSSL < 3.0 as a DTLS server with ED25519 keys")
298+
testPionE2ESimpleED25519(t, serverOpenSSL, clientPion)
299+
}
300+
})
301+
t.Run("OpenSSLClient", func(t *testing.T) {
302+
testPionE2ESimpleED25519(t, serverPion, clientOpenSSL)
303+
})
304+
}

‎e2e/e2e_openssl_v113_test.go

-18
This file was deleted.

‎e2e/e2e_test.go

+46
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ package e2e
55

66
import (
77
"context"
8+
"crypto/ed25519"
9+
"crypto/rand"
810
"crypto/tls"
911
"errors"
1012
"fmt"
@@ -320,6 +322,46 @@ func testPionE2EMTUs(t *testing.T, server, client func(*comm)) {
320322
}
321323
}
322324

325+
func testPionE2ESimpleED25519(t *testing.T, server, client func(*comm)) {
326+
lim := test.TimeOut(time.Second * 30)
327+
defer lim.Stop()
328+
329+
report := test.CheckRoutines(t)
330+
defer report()
331+
332+
for _, cipherSuite := range []dtls.CipherSuiteID{
333+
dtls.TLS_ECDHE_ECDSA_WITH_AES_128_CCM,
334+
dtls.TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8,
335+
dtls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
336+
dtls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
337+
dtls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA,
338+
} {
339+
cipherSuite := cipherSuite
340+
t.Run(cipherSuite.String(), func(t *testing.T) {
341+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
342+
defer cancel()
343+
344+
_, key, err := ed25519.GenerateKey(rand.Reader)
345+
if err != nil {
346+
t.Fatal(err)
347+
}
348+
cert, err := selfsign.SelfSign(key)
349+
if err != nil {
350+
t.Fatal(err)
351+
}
352+
353+
cfg := &dtls.Config{
354+
Certificates: []tls.Certificate{cert},
355+
CipherSuites: []dtls.CipherSuiteID{cipherSuite},
356+
InsecureSkipVerify: true,
357+
}
358+
serverPort := randomPort(t)
359+
comm := newComm(ctx, cfg, cfg, serverPort, server, client)
360+
comm.assert(t)
361+
})
362+
}
363+
}
364+
323365
func TestPionE2ESimple(t *testing.T) {
324366
testPionE2ESimple(t, serverPion, clientPion)
325367
}
@@ -331,3 +373,7 @@ func TestPionE2ESimplePSK(t *testing.T) {
331373
func TestPionE2EMTUs(t *testing.T) {
332374
testPionE2EMTUs(t, serverPion, clientPion)
333375
}
376+
377+
func TestPionE2ESimpleED25519(t *testing.T) {
378+
testPionE2ESimpleED25519(t, serverPion, clientPion)
379+
}

‎e2e/e2e_v113_test.go

-64
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.