BlueGit

timfa bluegit

Files

bluegit / internal / sshd / kex_test.go

kex_test.go

feat: bied mlkem768x25519-sha256 als SSH-kex
timfa project_87923614_bot_3aff574f6f98414b945a8799374f9092 · pushed by timfa · 3 weeks ago
4308aabf History
kex_test.go 1.2 KiB Download Raw
1package sshd
2
3import (
4 "strings"
5 "testing"
6)
7
8func TestKeyExchangePreference(t *testing.T) {
9 got := keyExchanges()
10 if kexSupported(kexMLKEM) && (len(got) == 0 || got[0] != kexMLKEM) {
11 t.Fatalf("mlkem hoort vooraan: %v", got)
12 }
13 curve := indexOf(got, kexCurve)
14 libssh := indexOf(got, kexLibSSH)
15 if curve < 0 || libssh < 0 || libssh < curve {
16 t.Fatalf("curve25519 hoort als fallback: %v", got)
17 }
18 for _, name := range []string{kexMLKEM, "sntrup761x25519-sha512", "sntrup761x25519-sha512@openssh.com"} {
19 has := indexOf(got, name) >= 0
20 if kexSupported(name) != has {
21 t.Fatalf("%s ondersteund=%v aangeboden=%v in %v", name, kexSupported(name), has, got)
22 }
23 if has && indexOf(got, name) > curve {
24 t.Fatalf("%s hoort voor curve25519: %v", name, got)
25 }
26 }
27 if strings.Join(got, ",") != strings.Join(unique(got), ",") {
28 t.Fatalf("dubbele namen: %v", got)
29 }
30}
31
32func indexOf(list []string, want string) int {
33 for i, name := range list {
34 if name == want {
35 return i
36 }
37 }
38 return -1
39}
40
41func unique(list []string) []string {
42 seen := map[string]bool{}
43 var out []string
44 for _, name := range list {
45 if seen[name] {
46 continue
47 }
48 seen[name] = true
49 out = append(out, name)
50 }
51 return out
52}