Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 49 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ field out.
is kept whole. The command names the host twice, so scanned without `--sni`
a host name of more than 195 to 200 characters, depending on the key exchange
and the port, made it longer than 500 bytes on its own, and its end was still
cut. Such a command now connects to the IP address the scan resolved the host
name to and names the host once, after `-servername`.
cut. Such a command now connects to the IP address the scan reached and names
the host once, after `-servername`.
- The same Fix no longer quotes pure ML-KEM key exchange as a way to raise the
score without saying that this version cannot detect it. The scanner never
offers a pure ML-KEM group, because Go's TLS stack defines none, so a server
Expand All @@ -103,6 +103,21 @@ field out.
Fix now says, for example, "pure ML-KEM key exchange would reach 80, but this
version cannot detect it and would still report 64", and `docs/policies.md`
says the same.
- The `ip` field of a report, and the quantum score Fix's `openssl s_client`
command when it connects by address, name the address the scan's connections
reached, not the first address the host name resolved to. A name can resolve
to several addresses and a connection moves on to the next when one refuses
it, so the two differed: a TLS 1.3 server listening on 127.0.0.1 only,
scanned under `cnsa-2.0-2030` as a 213-character `.localhost` name that
resolves to `::1` and then `127.0.0.1`, was measured over 127.0.0.1,
reported `"ip": "::1"`, and its Fix ended with `-connect '[::1]:52144'`, an
address the server was not listening on. The same scan now reports
`"ip": "127.0.0.1"`, the text report's IP line says the same, and the
498-byte Fix ends with `-connect 127.0.0.1:50983 -servername <the name>
-groups X25519MLKEM768 </dev/null`; run as printed, that command reached
the server and received its handshake failure alert for the group it does
not offer. When the connections of one scan reached more than one address,
a scan coverage note names them and `ip` is the one reached first.
- The text report now heads a policy evaluation with the same verdict as the
HTML report, SARIF and CBOM. An evaluation that skipped a rule and found no
violation was printed as `✓ COMPLIANT` in the text report while the other
Expand Down Expand Up @@ -213,6 +228,25 @@ field out.
a host name or an IPv4 address is printed as before. The quotes add 4 bytes:
against that server the message for a five-digit port is 390 bytes, so an
IPv6 address and port of up to 47 characters fit.
- **When the `openssl s_client` commands in that error do not all fit, it still
names each key exchange group this scanner does not offer.** Each command
repeats the address, and the CLI prints up to 500 bytes of a scan error, so a
long address pushed the last command past that limit, and its group was named
nowhere else. Measured with Go 1.26.3 against a local server on `::1`: run
with `GODEBUG=fips140=on,tlsmlkem=0`, where the scanner offers none of the
three hybrid groups, the error for `scanner-target-example.localhost` on a
five-digit port ended in `-groups SecP256r1MLKEM768 and openssl s_client
-connect sca...`, and without that setting the error for a 51-character host
name on a five-digit port lost `SecP384r1MLKEM1024` the same way. Such an
error now names the groups straight after its first sentence and gives only
the commands that fit whole, which for both of those host names is the
command for the first group. An error whose commands fit is unchanged:
against `127.0.0.1` and `::1` on a five-digit port it is byte for byte the
same as before, 398 and 390 bytes, and so is the 467-byte error against
`127.0.0.1` with the setting above. A test builds the error for every host
name length the scanner accepts, at ports 443 and 65535, and for the longest
name after each of the 256 TLS alert values, and finds each group named
within the 500 bytes.
- **A port that is not a number from 1 to 65535 is refused without quoting it.**
The error used to repeat the text after the colon, which on a `key: value` line
is the value.
Expand All @@ -231,6 +265,19 @@ field out.
and now names `[::1]:1`. A zone-scoped address keeps its brackets the same
way: `[fe80::1%lo0]:9` was written `fe80::1%lo0:9`. `127.0.0.1:1` and
`localhost:1` are written as before.
- **The service endpoint in `--format cbom` output writes an IPv6 address in
brackets.** Against a local server on `::1`, `tlsanalyzer '[::1]:8443'
--format cbom` listed the endpoint `https://::1:8443`, where the port reads as
part of the address, and now lists `https://[::1]:8443`. A zone-scoped address
is bracketed the same way, and the `%` before its zone is written `%25`, the
form RFC 6874 gives a zone in a URI: `fe80::1%lo0` on port 9 is written
`https://[fe80::1%25lo0]:9`, where it was `https://fe80::1%lo0:9`. Go's
`net/url` refuses the form with a bare `%`, `https://[fe80::1%lo0]:9`, with
`invalid URL escape "%lo"`. A host name or an IPv4 address is written as
before, for example `https://localhost:8443` and `https://127.0.0.1:8443`.
- **The README header no longer shows the Go Report Card badge.** goreportcard.com
has retired its service, and the badge rendered "go report: retired" instead
of a grade. The CI, Go Reference and License badges remain.

## [0.4.1] - 2026-08-05

Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

<p align="center">
<a href="https://github.com/csnp/qramm-tls-analyzer/actions"><img src="https://github.com/csnp/qramm-tls-analyzer/workflows/CI/badge.svg" alt="CI Status"></a>
<a href="https://goreportcard.com/report/github.com/csnp/qramm-tls-analyzer"><img src="https://goreportcard.com/badge/github.com/csnp/qramm-tls-analyzer?v=2" alt="Go Report Card"></a>
<a href="https://pkg.go.dev/github.com/csnp/qramm-tls-analyzer"><img src="https://pkg.go.dev/badge/github.com/csnp/qramm-tls-analyzer.svg" alt="Go Reference"></a>
<a href="LICENSE"><img src="https://img.shields.io/badge/License-MIT-blue.svg" alt="License"></a>
</p>
Expand Down
32 changes: 32 additions & 0 deletions cmd/tlsanalyzer/readme_badges_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main

import (
"os"
"path/filepath"
"strings"
"testing"
)

// TestReadmeBadgesComeFromServicesThatAnswer keeps the README header free of
// badges whose service has shut down.
//
// goreportcard.com retired its service: fetched on 2026-10-17, its badge for
// this module rendered the text "go report: retired" instead of a grade, so the
// README header showed a broken badge to every visitor.
func TestReadmeBadgesComeFromServicesThatAnswer(t *testing.T) {
path := filepath.Join("..", "..", "README.md")
body, err := os.ReadFile(path)
if err != nil {
t.Fatalf("reading %s: %v", path, err)
}

retired := []string{"goreportcard.com"}
for i, line := range strings.Split(string(body), "\n") {
for _, host := range retired {
if strings.Contains(line, host) {
t.Errorf("README.md:%d links to %s, which has retired its service: %s",
i+1, host, strings.TrimSpace(line))
}
}
}
}
7 changes: 5 additions & 2 deletions docs/policies.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,11 @@ last, and the command is kept whole. The command names the host twice, after
when the scan used no `--sni` and the host name is longer than 196 characters
for a server with classical key exchange, or 200 for one with hybrid key
exchange, on port 443 (one fewer on a five-digit port). Then the command
connects to the IP address the scan resolved the host name to and names the
host once, after `-servername`, and the sentences are fitted beside it again.
connects to the IP address the scan's connections reached, which the JSON
report carries as `ip`, and names the host once, after `-servername`, and the
sentences are fitted beside it again. A host name can resolve to several
addresses, and a connection moves on to the next when one refuses it, so that
address is not always the first one the name resolved to.
In the tests, with an IPv4 address and with the longest IPv6 address text, at
ports 443 and 65535, that kept the command whole for every host name length
from 1 to 254 characters, with no `--sni` name and with a different 253-character
Expand Down
4 changes: 2 additions & 2 deletions internal/analyzer/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -1691,8 +1691,8 @@ var (
// on certificate availability, which the report's Recommended Action line also
// carries once the key exchange is hybrid or pure ML-KEM. A Verify that is
// longer than the cap on its own is replaced by one that connects to the
// address the scan resolved the host to, so a long host name is written once,
// after -servername, rather than also after -connect.
// address the scan's connections reached, the result's IP, so a long host name
// is written once, after -servername, rather than also after -connect.
func (e *PolicyEvaluator) quantumScoreRemediation(result *types.ScanResult, minimum int) string {
hasHybrid, hasPure := false, false
for _, ke := range result.KeyExchanges {
Expand Down
2 changes: 1 addition & 1 deletion internal/analyzer/policy_quantum_fix_address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
// classical server and 201 for a hybrid one. Scanned end to end as a
// 213-character name resolving to ::1, a classical server's Fix was 500 bytes
// ending "aaaa.local...". Such a Verify now connects to the address the scan
// resolved the host to and names the host once, as the -servername.
// reached, the result's IP, and names the host once, as the -servername.

// longestIPv6Text is the longest text an IPv6 address prints as. In -connect it
// also takes brackets and, for the brackets, quotes.
Expand Down
2 changes: 1 addition & 1 deletion internal/analyzer/policy_quantum_fix_fits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type fixCase struct {
port int
host string
serverName string // empty: the scan sent the host itself
ip string // the address the scan resolved the host to; empty: none recorded
ip string // the address the scan reached; empty: none recorded
}

// fixFor evaluates the case and returns its quantum.minQuantumScore Fix, or ok
Expand Down
143 changes: 143 additions & 0 deletions internal/analyzer/policy_quantum_fix_reached_address_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
package analyzer

import (
"context"
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"crypto/tls"
"crypto/x509"
"crypto/x509/pkix"
"math/big"
"net"
"strconv"
"strings"
"testing"
"time"

"github.com/csnp/qramm-tls-analyzer/internal/scanner"
)

// TestQuantumScoreFixConnectsToTheAddressTheScanReached is the reproduction of
// "Quantum score Fix's address-form Verify can connect to an address the scan
// did not reach": a TLS 1.3 server offering X25519 and P-256, listening on one
// loopback address only, scanned under cnsa-2.0-2030 as a 213-character
// .localhost name. The scan's dials move on from an address that refuses the
// connection, so the scan completed over the listening address, while the
// result's IP, and the Verify built from it because the host name is too long
// to be written twice, named the first address the name resolved to.
//
// The name has to resolve to two or more loopback addresses on the machine
// running the test, as a .localhost name does on macOS (::1, then 127.0.0.1);
// otherwise the test is skipped. The server listens on the last of them, and
// nothing may be listening at the first on the same port.
func TestQuantumScoreFixConnectsToTheAddressTheScanReached(t *testing.T) {
host := strings.Repeat(strings.Repeat("a", 50)+".", 4) + "localhost"
ips, err := net.LookupIP(host)
if err != nil {
t.Skipf("%s does not resolve here: %v", host, err)
}
if len(ips) < 2 {
t.Skipf("the .localhost name resolves to %v here; the test needs two loopback addresses", ips)
}
for _, ip := range ips {
if !ip.IsLoopback() {
t.Skipf("the .localhost name resolves to %v here, not only to loopback addresses", ips)
}
}
first, last := ips[0], ips[len(ips)-1]
if first.Equal(last) {
t.Skipf("the .localhost name resolves to %v here, with the same first and last address", ips)
}

ln, err := tls.Listen("tcp", net.JoinHostPort(last.String(), "0"), &tls.Config{
Certificates: []tls.Certificate{selfSignedFor(t, host)},
MinVersion: tls.VersionTLS13,
CurvePreferences: []tls.CurveID{tls.X25519, tls.CurveP256},
})
if err != nil {
t.Skipf("cannot listen on %s: %v", last, err)
}
t.Cleanup(func() { _ = ln.Close() })
go func() {
for {
conn, err := ln.Accept()
if err != nil {
return
}
go func(c net.Conn) {
defer func() { _ = c.Close() }()
if tc, ok := c.(*tls.Conn); ok {
_ = tc.HandshakeContext(context.Background())
}
}(conn)
}
}()
port := ln.Addr().(*net.TCPAddr).Port
if c, err := net.DialTimeout("tcp", net.JoinHostPort(first.String(), strconv.Itoa(port)),
time.Second); err == nil {
_ = c.Close()
t.Skipf("something accepts connections at %s on port %d", first, port)
}

ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()
result, err := scanner.New(scanner.DefaultConfig()).Scan(ctx,
net.JoinHostPort(host, strconv.Itoa(port)))
if err != nil {
t.Fatalf("scan: %v", err)
}
if result.IP != last.String() {
t.Errorf("the result's IP is %q; the scan's connections reached %s, and nothing "+
"listens at %s on port %d", result.IP, last, first, port)
}

e := NewPolicyEvaluator()
policy, found := e.GetPolicy("cnsa-2.0-2030")
if !found {
t.Fatal("built-in policy cnsa-2.0-2030 not found")
}
var fix string
for _, v := range e.Evaluate(result, policy).Violations {
if v.Rule == "quantum.minQuantumScore" {
fix = v.Remediation
}
}
if fix == "" {
t.Fatal("no quantum.minQuantumScore violation for a server with classical key exchange")
}
connect := net.JoinHostPort(last.String(), strconv.Itoa(port))
if strings.Contains(connect, "[") {
connect = "'" + connect + "'"
}
verify := "Verify hybrid ML-KEM support: openssl s_client -connect " + connect +
" -servername " + host + " -groups X25519MLKEM768 </dev/null"
if !strings.HasSuffix(fix, verify) {
t.Errorf("the Fix does not end with the Verify that connects to %s, the address the "+
"scan reached:\n%s", last, fix)
}
}

// selfSignedFor issues a self-signed ECDSA P-256 certificate for name, valid
// for a day.
func selfSignedFor(t *testing.T, name string) tls.Certificate {
t.Helper()
key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
if err != nil {
t.Fatalf("generate key: %v", err)
}
template := &x509.Certificate{
SerialNumber: big.NewInt(1),
Subject: pkix.Name{CommonName: "quantum score fix test"},
DNSNames: []string{name},
NotBefore: time.Now().Add(-time.Hour),
NotAfter: time.Now().Add(24 * time.Hour),
KeyUsage: x509.KeyUsageDigitalSignature,
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
}
der, err := x509.CreateCertificate(rand.Reader, template, template, &key.PublicKey, key)
if err != nil {
t.Fatalf("issue certificate: %v", err)
}
return tls.Certificate{Certificate: [][]byte{der}, PrivateKey: key}
}
10 changes: 8 additions & 2 deletions internal/reporter/cbom.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package reporter
import (
"fmt"
"io"
"net"
"net/url"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -65,12 +67,16 @@ func (r *CBOMReporter) generateCBOM(result *types.ScanResult) types.CryptoBOM {
return cbom
}

// Add service
// Add service. The endpoint is a URL: net.JoinHostPort puts an IPv6 address
// in brackets, and url.URL writes the % before a zone as %25. Written from
// host and port with "https://%s:%d", ::1 came out as https://::1:8443,
// where the port reads as part of the address.
endpoint := url.URL{Scheme: "https", Host: net.JoinHostPort(result.Host, strconv.Itoa(result.Port))}
cbom.Services = []types.CryptoService{
{
BOMRef: "service-" + result.Target,
Name: result.Target,
Endpoints: []string{fmt.Sprintf("https://%s:%d", result.Host, result.Port)},
Endpoints: []string{endpoint.String()},
Description: "TLS-enabled service",
},
}
Expand Down
Loading
Loading