Building 70 Projects ranging from beginner to advanced so anyone can — learn from, build upon, use as a reference, or even copy directly. Owned by my cybersecurity company đŸ‘‡
Go aicertificationcloud-engineeringcybercybersecuritycybersecurity-analystcybersecurity-certificationcybersecurity-certificationscybersecurity-educationcybersecurity-jobscybersecurity-portfoliocybersecurity-projectscybersecurity-toolsgrchackinglearningpentestingproject-repositoryprojetcspython
feat(khaos): the two tls. faults that were missing, and a bug in khaos's own client
CarterPerez-dev5078027df29b
diff --git a/PROJECTS/intermediate/chaos-engineering-tool/cmd/khaos-range/tlsgateway.go b/PROJECTS/intermediate/chaos-engineering-tool/cmd/khaos-range/tlsgateway.goindex 59a5814f..9cecb097 100644--- a/PROJECTS/intermediate/chaos-engineering-tool/cmd/khaos-range/tlsgateway.go+++ b/PROJECTS/intermediate/chaos-engineering-tool/cmd/khaos-range/tlsgateway.go@@ -5,6 +5,7 @@ package mainimport ("context"+ "crypto/tls""crypto/x509""io""net/http"@@ -55,6 +56,12 @@ type tlsGateway struct {authorityBase stringcertHost stringfailMode string++ // One cache for the gateway's whole lifetime. Resumption is the only thing+ // that makes the policy-in-peer-callback defect reachable, and a cache that+ // did not outlive a request would make that mode indistinguishable from a+ // correct one.+ sessions tls.ClientSessionCache}func newTLSGateway(@@ -77,7 +84,31 @@ func newTLSGateway(authorityBase: authorityBase,certHost: certHost,failMode: failMode,+ sessions: tls.NewLRUClientSessionCache(0),+ }+}++// identity fetches the client certificate khaos is currently issuing this+// gateway, or nil when it is issuing none.+//+// Nil is NOT a failure. khaos withholding the identity is the+// client-cert-absent fault, and a gateway that refused to connect without one+// would be making khaos's point for it: the finding is whether it connects+// anyway and whether it notices being refused.+func (g *tlsGateway) identity(ctx context.Context) *tls.Certificate {+ body, ok := g.fetch(ctx, pki.RouteIdentity)+ if !ok {+ return nil}++ // One PEM bundle carrying both blocks, so the same bytes are handed to+ // X509KeyPair twice.+ pair, err := tls.X509KeyPair(body, body)+ if err != nil {+ return nil+ }++ return &pair}// dialAddress reduces a dependency URL to the host:port a dialer wants, and@@ -108,6 +139,15 @@ func (g *tlsGateway) client(ctx context.Context) *tlsclient.Client {Host: g.certHost,Roots: g.trustStore(ctx),Timeout: dependencyTimeout,++ // Fetched per request like the trust store, because khaos can withdraw+ // or expire it mid-run and a gateway holding one from boot could not+ // experience either fault.+ Identity: g.identity(ctx),++ // SHARED across requests, which is the whole precondition for the+ // resumption hole: a cache built per connection resumes nothing.+ Sessions: g.sessions,})}@@ -196,40 +236,56 @@ func (g *tlsGateway) protected(w http.ResponseWriter, r *http.Request) {func (g *tlsGateway) trustStore(ctx context.Context) *x509.CertPool {pool := x509.NewCertPool()+ der, ok := g.fetch(ctx, pki.RouteRoot)+ if !ok {+ return pool+ }++ cert, err := x509.ParseCertificate(der)+ if err != nil {+ return pool+ }++ pool.AddCert(cert)++ return pool+}++// fetch reads one of khaos's own endpoints. A failure is reported as false+// rather than as an error, because every caller's honest response to "khaos is+// not answering" is to proceed with nothing and let the BASELINE fail, which+// voids the run instead of making a fault's measurement quietly wrong.+func (g *tlsGateway) fetch(+ ctx context.Context,+ route string,+) ([]byte, bool) {request, err := http.NewRequestWithContext(ctx,http.MethodGet,- strings.TrimSuffix(g.authorityBase, "/")+pki.RouteRoot,+ strings.TrimSuffix(g.authorityBase, "/")+route,nil,)if err != nil {- return pool+ return nil, false}client := &http.Client{Timeout: dependencyTimeout}response, err := client.Do(request)if err != nil {- return pool+ return nil, false}defer func() { _ = response.Body.Close() }()if response.StatusCode != http.StatusOK {- return pool+ return nil, false}- der, err := io.ReadAll(io.LimitReader(response.Body, maxRootBytes))+ body, err := io.ReadAll(io.LimitReader(response.Body, maxRootBytes))if err != nil {- return pool+ return nil, false}- cert, err := x509.ParseCertificate(der)- if err != nil {- return pool- }-- pool.AddCert(cert)-- return pool+ return body, true}diff --git a/PROJECTS/intermediate/chaos-engineering-tool/internal/experiment/tls.go b/PROJECTS/intermediate/chaos-engineering-tool/internal/experiment/tls.goindex 4bebbc13..b21b0e1b 100644--- a/PROJECTS/intermediate/chaos-engineering-tool/internal/experiment/tls.go+++ b/PROJECTS/intermediate/chaos-engineering-tool/internal/experiment/tls.go@@ -59,6 +59,14 @@ const (NameStapleAbsent = "tls.staple_absent"NameCASwap = "tls.ca_swap"++ NameClientCertExpired = "tls.mtls_client_expired"+ NameClientCertAbsent = "tls.mtls_client_absent"++ // Shares the revoked-via-crl TRAP, because the fault khaos injects really+ // is revocation. What differs is the finding: whether a session established+ // before the revocation outlives it.+ NameResumptionAfterRevocation = "tls.resumption_after_revocation")const (@@ -101,6 +109,11 @@ const (sumStapleAbsent = "omit the stapled response entirely, which finds an application that reads no staple as good instead of asking the responder itself"sumCASwap = "replace the root the target trusts with one khaos controls and serve a chain that is valid under it, which NOTHING in a TLS client can detect; the only defences are pinning and certificate transparency, and this experiment exists to show that acceptance here is not a bug in the client"++ sumClientExpired = "require mutual TLS and issue the target an expired client identity, which khaos's server then refuses; under TLS 1.3 the target's tls.Dial SUCCEEDS anyway and the refusal only surfaces on the first read, so this finds a client that treats a completed dial as a working connection"+ sumClientAbsent = "require mutual TLS and issue the target no client identity at all, which is what a failed rotation and a bypassed sidecar look like; an attacker does not present a bad certificate, they present nothing"++ sumResumption = "establish a session while the certificate is good and revoke it afterwards, which a resumed connection never notices: crypto/tls does not run VerifyPeerCertificate on a resumed handshake, so an application whose pinning or revocation check lives in that hook enforces it once and skips it for the ticket's lifetime, which Go caps at seven days")// caSwapPolarity is the one experiment in the family whose acceptance is not a@@ -127,6 +140,7 @@ func init() {chainExperiments(),policyExperiments(),revocationExperiments(),+ mutualExperiments(),}for _, group := range groups {@@ -371,3 +385,42 @@ func revocationExperiments() []Definition {}),}}++// mutualExperiments are the two faults in the TARGET's own identity, plus the+// one whose finding is about a session rather than a certificate.+//+// The mutual TLS pair does not test khaos's server, which refuses both+// correctly. It tests whether the target NOTICES being refused, and under TLS+// 1.3 that comes down to whether it reads: research 04 measured every row of+// the ClientAuth matrix returning a successful tls.Dial even where the server+// served nothing at all.+func mutualExperiments() []Definition {+ return []Definition{+ tlsDefinition(tlsSpec{+ name: NameClientCertExpired,+ summary: sumClientExpired,+ trap: pki.ClientCertExpired,+ extra: []Param{certWindowParam},+ }),+ tlsDefinition(tlsSpec{+ name: NameClientCertAbsent,+ summary: sumClientAbsent,+ trap: pki.ClientCertAbsent,+ }),++ // The SAME trap as tls.revoked_via_crl, deliberately. khaos injects+ // revocation either way; this experiment exists because the question+ // "does a session established beforehand outlive it" is a different+ // finding from "does the target check revocation at all", and a target+ // can pass the first and fail this one.+ //+ // It declares the endpoint for the same reason the revocation group+ // does: a target that never asks has no check to skip on resumption.+ tlsDefinition(tlsSpec{+ name: NameResumptionAfterRevocation,+ summary: sumResumption,+ trap: pki.RevokedViaCRL,+ consults: ConsultsCRL,+ }),+ }+}diff --git a/PROJECTS/intermediate/chaos-engineering-tool/internal/pki/authority.go b/PROJECTS/intermediate/chaos-engineering-tool/internal/pki/authority.goindex a6f3f8f6..5bedd660 100644--- a/PROJECTS/intermediate/chaos-engineering-tool/internal/pki/authority.go+++ b/PROJECTS/intermediate/chaos-engineering-tool/internal/pki/authority.go@@ -109,6 +109,14 @@ type Authority struct {trap Traparmed *Chain+ // clientID is the identity khaos has issued to the TARGET, for the mutual+ // TLS traps, and mutual is whether khaos demands one. Both are minted and+ // set at arm time like everything else the authority serves, so an inert+ // authority keeps handing out the honest identity and keeps not demanding+ // anything.+ clientID *pair+ mutual bool+// swapped is BUILT state, not derived from the trap, and the distinction is// what makes the confirmation oracle honest.//@@ -297,12 +305,20 @@ func (a *Authority) Arm(trap Trap) error {return err}+ identity, err := a.mintClientIdentity(trap, a.clock())+ if err != nil {+ return err+ }+a.mu.Lock()defer a.mu.Unlock()a.trap = trapa.armed = chaina.swapped = trap.Kind == CASwap+ a.clientID = identity+ a.mutual = trap.Kind == ClientCertExpired ||+ trap.Kind == ClientCertAbsentreturn nil}@@ -316,12 +332,22 @@ func (a *Authority) Disarm() error {return err}+ identity, err := a.mintClientIdentity(+ Trap{Kind: PassThrough},+ a.clock(),+ )+ if err != nil {+ return err+ }+a.mu.Lock()defer a.mu.Unlock()a.trap = Trap{}a.armed = honesta.swapped = false+ a.clientID = identity+ a.mutual = falsereturn nil}diff --git a/PROJECTS/intermediate/chaos-engineering-tool/internal/pki/catalog.go b/PROJECTS/intermediate/chaos-engineering-tool/internal/pki/catalog.goindex 0acf0f72..a29421de 100644--- a/PROJECTS/intermediate/chaos-engineering-tool/internal/pki/catalog.go+++ b/PROJECTS/intermediate/chaos-engineering-tool/internal/pki/catalog.go@@ -125,6 +125,9 @@ func Kinds() []string {string(StapleAbsent),string(CASwap),++ string(ClientCertExpired),+ string(ClientCertAbsent),}}@@ -154,6 +157,13 @@ func GoAccepts(kind Kind) bool {StapleGarbage, StapleAbsent, CASwap:return true+ case ClientCertExpired, ClientCertAbsent:+ // The DEPENDENCY's certificate is impeccable for both of these, so+ // crypto/x509 has no objection to it: the defect is in the target's own+ // identity and the rejection happens on khaos's side of the connection.+ // Go accepts the chain, and then the server refuses the client.+ return true+case PassThrough, LeafExpired, LeafNotYetValid, IntermediateExpired,WrongSAN, CommonNameOnly, NoIPSAN,SelfSigned, UntrustedCA, MissingIntermediate, IssuerNotCA,@@ -187,6 +197,12 @@ func (t Trap) Describe(target string) string {CASwap:return t.describePolicy(target)+ case ClientCertExpired:+ return fmt.Sprintf(describeClientExpired, target, t.window())++ case ClientCertAbsent:+ return fmt.Sprintf(describeClientAbsent, target)+case PassThrough:return ""diff --git a/PROJECTS/intermediate/chaos-engineering-tool/internal/pki/mint.go b/PROJECTS/intermediate/chaos-engineering-tool/internal/pki/mint.goindex 28c8bc6e..964b2459 100644--- a/PROJECTS/intermediate/chaos-engineering-tool/internal/pki/mint.go+++ b/PROJECTS/intermediate/chaos-engineering-tool/internal/pki/mint.go@@ -44,6 +44,18 @@ type pair struct {key crypto.Signer}+// rsaKeyOf recovers the concrete RSA key from a pair. Every key this package+// mints is RSA, so a failed assertion is a bug in this file rather than+// something a caller can cause.+func rsaKeyOf(p *pair) *rsa.PrivateKey {+ key, ok := p.key.(*rsa.PrivateKey)+ if !ok {+ return nil+ }++ return key+}+func newKey(bits int) (*rsa.PrivateKey, error) {key, err := rsa.GenerateKey(rand.Reader, bits)if err != nil {diff --git a/PROJECTS/intermediate/chaos-engineering-tool/internal/pki/mutual.go b/PROJECTS/intermediate/chaos-engineering-tool/internal/pki/mutual.gonew file mode 100644index 00000000..9e4abd97--- /dev/null+++ b/PROJECTS/intermediate/chaos-engineering-tool/internal/pki/mutual.go@@ -0,0 +1,189 @@+// ©AngelaMos | 2026+// mutual.go++package pki++import (+ "crypto/x509"+ "crypto/x509/pkix"+ "encoding/pem"+ "net/http"+ "time"+)++const (+ // RouteIdentity serves the CLIENT certificate and key khaos has issued to+ // the target, as PEM.+ //+ // khaos issues the target's identity because khaos is the CA for both ends,+ // which is how a service mesh actually works and the only arrangement in+ // which khaos can make that identity wrong. A target holding a certificate+ // khaos did not issue is a target khaos cannot inject an mTLS fault into.+ RouteIdentity = "/identity"++ nameClient = "khaos range client"++ blockCertificate = "CERTIFICATE"+ blockKey = "RSA PRIVATE KEY"++ mimePEM = "application/x-pem-file"+)++// RequiresMutualTLS reports whether the armed trap makes khaos demand a client+// certificate.+//+// It is read per handshake rather than fixed at bind time, through+// GetConfigForClient, because arming a trap has to take effect on the next+// connection without the listener moving. A ClientAuth fixed at bind time would+// mean the mTLS traps could only be armed before the range was pointed at+// khaos, which is not when an experiment arms anything.+func (a *Authority) RequiresMutualTLS() bool {+ a.mu.RLock()+ defer a.mu.RUnlock()++ // BUILT state, not read off the trap. An inert authority -- one that+ // records a trap and builds nothing -- would otherwise report that it+ // demands mutual TLS and is issuing no identity, which is both halves of+ // the client-cert-absent observable satisfied by a fault that never+ // happened. The oracle's negative control caught exactly that, for the+ // second time in this package and for the identical reason.+ return a.mutual+}++// ClientIdentity is the certificate and key khaos has issued to the target+// right now, or false when it is issuing none.+//+// Withholding it IS the ClientCertAbsent fault. Research 04 is explicit that+// this is the more dangerous of the two: an attacker does not present a bad+// certificate, they present nothing, and the ClientAuth mode that rejects a bad+// one while accepting none reads as secure and fails completely open.+func (a *Authority) ClientIdentity() (*pair, bool) {+ a.mu.RLock()+ defer a.mu.RUnlock()++ // Built state again. Withholding the identity is expressed by there BEING+ // no identity, not by a flag consulted at serve time, so an authority that+ // built nothing keeps handing out the honest one.+ return a.clientID, a.clientID != nil+}++// mintClientIdentity issues the target's own certificate. It is called at arm+// time like everything else the authority serves, so an inert authority -- one+// that records a trap and builds nothing -- keeps serving the honest identity+// and the oracle's negative control holds.+func (a *Authority) mintClientIdentity(+ trap Trap,+ now time.Time,+) (*pair, error) {+ // NOTHING, which is the whole of the absent fault. A nil identity here is+ // how "khaos issues the target none" is represented, so it cannot be+ // confused with an authority that simply has not built one yet.+ if trap.Kind == ClientCertAbsent {+ return nil, nil+ }++ number, err := serial()+ if err != nil {+ return nil, err+ }++ from := now.Add(-clockSlack)+ until := now.AddDate(0, 0, DefaultLeafDays)++ if trap.Kind == ClientCertExpired {+ // Moved TOGETHER, so the identity is expired and nothing else. One that+ // was also not-yet-valid would be refused for either reason and khaos+ // could not say which.+ window := trap.window()+ from = now.Add(-window - DefaultWindow)+ until = now.Add(-window)+ }++ template := &x509.Certificate{+ SerialNumber: number,+ Subject: pkix.Name{CommonName: nameClient},+ NotBefore: from,+ NotAfter: until,+ KeyUsage: x509.KeyUsageDigitalSignature,++ // clientAuth, not serverAuth. An identity presented as a client has to+ // be permitted for it, or khaos's own server refuses it for the wrong+ // reason and the fault is unattributable.+ ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth},+ BasicConstraintsValid: true,+ }++ key, err := newKey(StrongBits)+ if err != nil {+ return nil, err+ }++ return issue(template, a.inter, key)+}++// serveIdentity hands the target its own certificate and key.+//+// Serving a private key over plain HTTP is indefensible in anything but a+// fixture whose whole purpose is to be broken, and it is what makes the mTLS+// faults injectable at all: khaos has to be able to change the identity the+// target presents, which means khaos has to be the one handing it over.+func (a *Authority) serveIdentity(w http.ResponseWriter, _ *http.Request) {+ identity, issuing := a.ClientIdentity()+ if !issuing {+ // Not an error. khaos is deliberately issuing nothing, and a target+ // that treats "no identity available" as a reason to connect anyway is+ // exactly what this fault is looking for.+ w.WriteHeader(http.StatusNotFound)++ return+ }++ w.Header().Set(headerType, mimePEM)+ w.WriteHeader(http.StatusOK)++ _ = pem.Encode(w, &pem.Block{+ Type: blockCertificate,+ Bytes: identity.der,+ })++ _ = pem.Encode(w, &pem.Block{+ Type: blockKey,+ Bytes: x509.MarshalPKCS1PrivateKey(rsaKeyOf(identity)),+ })+}++// observeMutual confirms the two mutual TLS faults.+//+// BOTH halves, every time. khaos has to be demanding a client certificate AND+// the identity it issued has to be wrong, because either alone is not the+// fault: a server that does not require mTLS rejects nobody, and a bad identity+// nobody is asked for is never presented.+func (a *Authority) observeMutual(trap Trap) (string, bool, error) {+ if !a.RequiresMutualTLS() {+ return "", false, nil+ }++ identity, issuing := a.ClientIdentity()++ if trap.Kind == ClientCertAbsent {+ if issuing {+ return "", false, nil+ }++ return observedNoIdentity, true, nil+ }++ if !issuing {+ return "", false, nil+ }++ now := a.clock()+ if !identity.cert.NotAfter.Before(now) {+ return "", false, nil+ }++ return sprintf(+ observedClientExpired,+ now.Sub(identity.cert.NotAfter).Round(time.Second),+ ), true, nil+}diff --git a/PROJECTS/intermediate/chaos-engineering-tool/internal/pki/observe.go b/PROJECTS/intermediate/chaos-engineering-tool/internal/pki/observe.goindex 79c9cd98..3e951f11 100644--- a/PROJECTS/intermediate/chaos-engineering-tool/internal/pki/observe.go+++ b/PROJECTS/intermediate/chaos-engineering-tool/internal/pki/observe.go@@ -51,6 +51,9 @@ const (observedNoOCSP = "the served leaf names no OCSP responder, and still names a CRL at %s"observedStapleBad = "the handshake staples %d bytes that are not an OCSP response"observedNoStaple = "the handshake carries no stapled response, where an honest one carries %d bytes"++ observedClientExpired = "khaos requires mutual TLS and the client identity it issued expired %s ago"+ observedNoIdentity = "khaos requires mutual TLS and is issuing no client identity at all")// Observe confirms khaos's own fault landed, by reading back what the authority@@ -108,6 +111,9 @@ func (a *Authority) Observe(case StapleGarbage, StapleAbsent, NoOCSPServer:return a.observeStaple(armed, chain, honest)+ case ClientCertExpired, ClientCertAbsent:+ return a.observeMutual(armed)+case RevokedViaCRL, StaleCRL, CRLUnreachable, OCSPRevoked, OCSPUnknown,OCSPTryLater, OCSPUnreachable, OCSPStale, OCSPWrongSerial,OCSPWrongSigner:diff --git a/PROJECTS/intermediate/chaos-engineering-tool/internal/pki/revocation_test.go b/PROJECTS/intermediate/chaos-engineering-tool/internal/pki/revocation_test.goindex 4ca2cda9..f4766d0d 100644--- a/PROJECTS/intermediate/chaos-engineering-tool/internal/pki/revocation_test.go+++ b/PROJECTS/intermediate/chaos-engineering-tool/internal/pki/revocation_test.go@@ -95,6 +95,12 @@ func countRevocationKinds() int {ExcessiveLifetime: true,KeyUsageWithoutDigitalSignature: true,CASwap: true,++ // Accepted by crypto/x509 like the rest of this group, but about the+ // TARGET's identity rather than about revocation. They have their own+ // two-sided observable in mutual.go.+ ClientCertExpired: true,+ ClientCertAbsent: true,}count := 0diff --git a/PROJECTS/intermediate/chaos-engineering-tool/internal/pki/routes.go b/PROJECTS/intermediate/chaos-engineering-tool/internal/pki/routes.goindex 08764702..d9e19c65 100644--- a/PROJECTS/intermediate/chaos-engineering-tool/internal/pki/routes.go+++ b/PROJECTS/intermediate/chaos-engineering-tool/internal/pki/routes.go@@ -31,6 +31,7 @@ func (a *Authority) routes() http.Handler {mux.HandleFunc(RouteOCSP, a.serveOCSP)mux.HandleFunc(RouteHealth, a.serveHealth)mux.HandleFunc(RouteRoot, a.serveRoot)+ mux.HandleFunc(RouteIdentity, a.serveIdentity)return mux}diff --git a/PROJECTS/intermediate/chaos-engineering-tool/internal/pki/server.go b/PROJECTS/intermediate/chaos-engineering-tool/internal/pki/server.goindex 8400945a..db65077b 100644--- a/PROJECTS/intermediate/chaos-engineering-tool/internal/pki/server.go+++ b/PROJECTS/intermediate/chaos-engineering-tool/internal/pki/server.go@@ -5,6 +5,7 @@ package pkiimport ("crypto/tls"+ "crypto/x509""errors""fmt""net"@@ -155,6 +156,13 @@ func (a *Authority) ListenTLS(addr string) error {TLSConfig: &tls.Config{MinVersion: tls.VersionTLS12,GetCertificate: a.getCertificate,++ // Per handshake, so arming an mTLS trap takes effect on the next+ // connection without the listener moving. ClientAuth fixed at bind+ // time would mean those traps could only be armed before the target+ // was ever pointed at khaos, which is not when an experiment arms+ // anything.+ GetConfigForClient: a.configForClient,},}@@ -172,6 +180,44 @@ func (a *Authority) ListenTLS(addr string) error {return nil}+// configForClient decides, per handshake, whether khaos demands a client+// certificate.+//+// RequireAndVerifyClientCert specifically, and not VerifyClientCertIfGiven.+// Research 04 measured the whole matrix and that mode is the fail-open trap: it+// rejects a BAD certificate and accepts NONE, so it reads as secure while its+// failure mode is a total authentication bypass. khaos's own server must not be+// the thing being wrong here -- the fault is in the identity it ISSUED, and a+// server that let an identity-less client through would make both mTLS traps+// unobservable.+func (a *Authority) configForClient(+ *tls.ClientHelloInfo,+) (*tls.Config, error) {+ cfg := &tls.Config{+ MinVersion: tls.VersionTLS12,+ GetCertificate: a.getCertificate,+ }++ if a.RequiresMutualTLS() {+ cfg.ClientAuth = tls.RequireAndVerifyClientCert+ cfg.ClientCAs = a.issuingPool()+ }++ return cfg, nil+}++// issuingPool is the CA that signed the target's identity, which is what khaos+// verifies that identity against. It is the real intermediate rather than+// whatever TrustedRoot currently reports, because a CA swap changes what the+// TARGET trusts and has nothing to do with who issued the client.+func (a *Authority) issuingPool() *x509.CertPool {+ pool := x509.NewCertPool()+ pool.AddCert(a.inter.cert)+ pool.AddCert(a.root.cert)++ return pool+}+// getCertificate resolves the armed chain per handshake.//// A handshake that arrives with nothing armed is served the honest chain ratherdiff --git a/PROJECTS/intermediate/chaos-engineering-tool/internal/pki/trap.go b/PROJECTS/intermediate/chaos-engineering-tool/internal/pki/trap.goindex c1f26c01..f517f0ca 100644--- a/PROJECTS/intermediate/chaos-engineering-tool/internal/pki/trap.go+++ b/PROJECTS/intermediate/chaos-engineering-tool/internal/pki/trap.go@@ -163,6 +163,28 @@ const (// detect this, which is the point: it is the CA-compromise scenario, and the// only defences are pinning or certificate transparency. Row F24.CASwap Kind = "ca-swap"++ // ClientCertExpired and ClientCertAbsent are the two MUTUAL TLS faults, and+ // they are the only traps that act on the target's own identity rather than+ // on the dependency's.+ //+ // khaos is the server here, so it is khaos that demands a client+ // certificate and khaos that issues the one the target presents. The fault+ // is in that issued identity: expired, or withheld entirely, which is what+ // a failed rotation and a bypassed sidecar actually look like.+ //+ // What they catch is NOT the rejection -- khaos's server rejects correctly+ // either way. It is whether the target NOTICES. Research 04 section 7.2+ // measured the whole ClientAuth matrix and under TLS 1.3 every single row+ // returned a successful tls.Dial, including the rows where the server+ // refused the identity and served nothing at all; the error arrives on the+ // first read. Under TLS 1.2 the same case fails at Dial. So a client that+ // dials and does not read reports a healthy dependency that refused it, and+ // the defect is invisible on the older protocol and total on the newer one.+ //+ // Rows F27 and F26.+ ClientCertExpired Kind = "client-cert-expired"+ ClientCertAbsent Kind = "client-cert-absent")const (@@ -205,6 +227,9 @@ const (describeStapleAbsent = "omit the stapled revocation response from %s's handshake entirely"describeCASwap = "replace the root %s trusts with one khaos controls, and serve a chain that is valid under it"++ describeClientExpired = "require mutual TLS of %s and issue it a client identity that expired %s ago"+ describeClientAbsent = "require mutual TLS of %s and issue it no client identity at all")const (diff --git a/PROJECTS/intermediate/chaos-engineering-tool/internal/pki/verify_test.go b/PROJECTS/intermediate/chaos-engineering-tool/internal/pki/verify_test.goindex c93b82d8..c287f046 100644--- a/PROJECTS/intermediate/chaos-engineering-tool/internal/pki/verify_test.go+++ b/PROJECTS/intermediate/chaos-engineering-tool/internal/pki/verify_test.go@@ -164,6 +164,14 @@ func faultTable() []expectation {// chain is genuinely valid under what the target now trusts. Nothing in// a client can detect this.{CASwap, accepted, 0, "", ""},++ // Mutual TLS. Accepted because the DEPENDENCY's certificate is+ // impeccable for both: the defect is in the target's own identity and+ // the rejection happens on khaos's side of the connection, which+ // Certificate.Verify knows nothing about. What a client sees depends on+ // the protocol version, and under TLS 1.3 it sees a successful Dial.+ {ClientCertExpired, accepted, 0, "", ""},+ {ClientCertAbsent, accepted, 0, "", ""},}}diff --git a/PROJECTS/intermediate/chaos-engineering-tool/internal/tlsclient/client.go b/PROJECTS/intermediate/chaos-engineering-tool/internal/tlsclient/client.goindex f3940617..19504b37 100644--- a/PROJECTS/intermediate/chaos-engineering-tool/internal/tlsclient/client.go+++ b/PROJECTS/intermediate/chaos-engineering-tool/internal/tlsclient/client.go@@ -8,6 +8,7 @@ import ("crypto/tls""crypto/x509""errors"+ "io""net""net/http""time"@@ -30,6 +31,11 @@ const (// client with no timeout cannot distinguish a slow responder from a dead// one, and that distinction is a fault in its own right.DefaultTimeout = 5 * time.Second++ // probeRequest is the smallest thing that makes a server answer. The+ // RESPONSE is not inspected at all: the point is only whether the server+ // was willing to send one.+ probeRequest = "GET / HTTP/1.1\r\nHost: khaos.probe\r\nConnection: close\r\n\r\n")const (@@ -69,6 +75,17 @@ type Config struct {// Now overrides the clock, so a freshness assertion does not race a real// one.Now func() time.Time++ // Identity is the CLIENT certificate this client presents, for a+ // dependency that requires mutual TLS. Nil means none, which is itself a+ // fault khaos can inject by withholding it.+ Identity *tls.Certificate++ // Sessions is the TLS session cache, and it has to be SHARED across+ // connections or there is no resumption to test. A cache created per+ // connection resumes nothing, which would make the+ // policy-in-peer-callback mode indistinguishable from a correct one.+ Sessions tls.ClientSessionCache}// Client is khaos's reference TLS client: what a correct consumer of a@@ -84,6 +101,9 @@ type Client struct {timeout time.Durationclock func() time.Time+ identity *tls.Certificate+ sessions tls.ClientSessionCache+http *http.Client}@@ -92,11 +112,13 @@ type Client struct {// that can decide anything.func New(cfg Config) *Client {c := &Client{- mode: cfg.Mode,- host: cfg.Host,- roots: cfg.Roots,- timeout: cfg.Timeout,- clock: cfg.Now,+ mode: cfg.Mode,+ host: cfg.Host,+ roots: cfg.Roots,+ timeout: cfg.Timeout,+ clock: cfg.Now,+ identity: cfg.Identity,+ sessions: cfg.Sessions,}if c.mode == "" {@@ -135,6 +157,13 @@ type Decision struct {// one that asked and was satisfied, and only these fields separate them.AskedCRL boolAskedOCSP bool++ // Resumed is whether this connection reused a TLS session instead of+ // performing a full handshake. It is recorded because the resumption fault+ // is otherwise unattributable: an acceptance on a resumed connection and an+ // acceptance on a fresh one are the same observation until you know which+ // happened.+ Resumed bool}// Decide connects to addr and reports whether this client was willing to use@@ -190,11 +219,53 @@ func (c *Client) handshake(return tls.ConnectionState{}, errors.New("not a TLS connection")}- // The handshake has already completed by the time DialContext returns, but- // under TLS 1.3 a server's rejection of a CLIENT certificate surfaces only- // on the first read. khaos does not use client certificates here, so this- // state is final; research 04 section 7.2 covers the case where it is not.- return tlsConn.ConnectionState(), nil+ state := tlsConn.ConnectionState()++ // EVERY probe reads, and this is not optional politeness.+ //+ // Under TLS 1.3 a server's rejection of the client certificate does NOT+ // surface at Dial. Research 04 section 7.2 measured the whole ClientAuth+ // matrix and every single row returned a successful DialContext, including+ // the rows where the server rejected the identity and served no bytes at+ // all; the error arrives on the first read. Under TLS 1.2 the same case+ // fails at Dial.+ //+ // So a dial-only probe reports GREEN against a server that refused it. That+ // was this client's behaviour until the mTLS traps were built -- the+ // previous comment here reasoned it away on the grounds that khaos used no+ // client certificates, which stopped being true -- and it is now the+ // DialOnly mode's declared defect rather than a property of the correct+ // one.+ if c.mode.reads() {+ if err := readOnce(tlsConn, c.timeout); err != nil {+ return tls.ConnectionState{}, err+ }+ }++ return state, nil+}++// readOnce writes a trivial request and waits for the first byte back, which is+// the cheapest way to find out whether the server is actually willing to talk.+func readOnce(conn *tls.Conn, timeout time.Duration) error {+ if err := conn.SetDeadline(time.Now().Add(timeout)); err != nil {+ return err+ }++ if _, err := io.WriteString(conn, probeRequest); err != nil {+ return err+ }++ buffer := make([]byte, 1)++ // io.EOF is NOT accepted as success. A server that rejected the handshake+ // and closed looks like a clean EOF to a reader that treats any completed+ // read as proof of life, and that is the same fail-open one level down.+ if _, err := conn.Read(buffer); err != nil {+ return err+ }++ return nil}func (c *Client) tlsConfig() *tls.Config {@@ -204,6 +275,17 @@ func (c *Client) tlsConfig() *tls.Config {MinVersion: tls.VersionTLS12,}+ if c.identity != nil {+ cfg.Certificates = []tls.Certificate{*c.identity}+ }++ // Sessions are only cached for a mode that declares it reuses them.+ // Resumption is otherwise a property every mode would share, and the one+ // defect it enables would be unattributable.+ if c.mode.resumes() && c.sessions != nil {+ cfg.ClientSessionCache = c.sessions+ }+if !c.mode.checksChain() {// InsecureSkipVerify in one assignment turns off the chain, the name// and the validity window together. That breadth is the reason it isdiff --git a/PROJECTS/intermediate/chaos-engineering-tool/internal/tlsclient/matrix_test.go b/PROJECTS/intermediate/chaos-engineering-tool/internal/tlsclient/matrix_test.goindex ec40aa26..aecab41e 100644--- a/PROJECTS/intermediate/chaos-engineering-tool/internal/tlsclient/matrix_test.go+++ b/PROJECTS/intermediate/chaos-engineering-tool/internal/tlsclient/matrix_test.go@@ -5,6 +5,9 @@ package tlsclient_testimport ("context"+ "crypto/tls"+ "io"+ "net/http""testing""time"@@ -83,6 +86,17 @@ const (// a hard-failing client treats as a refusal.byAvailability+ // byReading is the mutual TLS group, and it is the only guard that is not+ // about a check the client performs at all.+ //+ // khaos's server rejects these handshakes itself, correctly, whatever the+ // client verifies. The only question is whether the client FINDS OUT, and+ // under TLS 1.3 that depends entirely on whether it reads: research 04+ // measured every row of the ClientAuth matrix returning a successful+ // tls.Dial even where the server served nothing. So every mode catches+ // these except the one that never reads a byte.+ byReading+// byNothing is a trap no client-side check can catch. CASwap is the only// one, and that is the finding rather than a gap: once the anchor is// replaced the chain is genuinely valid, and only pinning or certificate@@ -169,6 +183,9 @@ func catches(mode tlsclient.Mode, by guard) bool {mode != tlsclient.NoRevocationCheck &&mode != tlsclient.SoftFailOCSP+ case byReading:+ return mode != tlsclient.DialOnly+case byNothing:return false@@ -261,6 +278,9 @@ func guardFor(kind pki.Kind) guard {case pki.CRLUnreachable, pki.OCSPUnreachable, pki.OCSPTryLater:return byAvailability+ case pki.ClientCertExpired, pki.ClientCertAbsent:+ return byReading+case pki.CASwap, pki.NoOCSPServer, pki.StapleAbsent:// NoOCSPServer and StapleAbsent are not caught by a refusal at all. A// correct client falls back to the other revocation channel and@@ -358,11 +378,51 @@ func decide(Host: asking,Roots: a.TrustedPool(),Now: a.Now,++ // The identity khaos is currently issuing, fetched the way the range's+ // gateway fetches it. Without this every mutual TLS row would be+ // refused because the client presented NOTHING, which is one of the two+ // faults, so the expired row would pass for the absent row's reason.+ Identity: identityFrom(t, a),})return client.Decide(ctx, addr)}+// identityFrom fetches the client certificate khaos is issuing, or nil when it+// is issuing none. Nil is not a failure: it is the client-cert-absent fault.+func identityFrom(t *testing.T, a *pki.Authority) *tls.Certificate {+ t.Helper()++ base, err := a.Addr()+ if err != nil {+ return nil+ }++ response, err := http.Get("http://" + base + pki.RouteIdentity)+ if err != nil {+ return nil+ }++ defer func() { _ = response.Body.Close() }()++ if response.StatusCode != http.StatusOK {+ return nil+ }++ body, err := io.ReadAll(response.Body)+ if err != nil {+ return nil+ }++ identity, err := tls.X509KeyPair(body, body)+ if err != nil {+ return nil+ }++ return &identity+}+func TestEveryTrapAgainstEveryReferenceClient(t *testing.T) {kinds := pki.Kinds()modes := tlsclient.Modes()diff --git a/PROJECTS/intermediate/chaos-engineering-tool/internal/tlsclient/mode.go b/PROJECTS/intermediate/chaos-engineering-tool/internal/tlsclient/mode.goindex 1830ddd3..accf06d0 100644--- a/PROJECTS/intermediate/chaos-engineering-tool/internal/tlsclient/mode.go+++ b/PROJECTS/intermediate/chaos-engineering-tool/internal/tlsclient/mode.go@@ -89,6 +89,35 @@ const (NoKeyFloor Mode = "no-key-floor"NoLifetimePolicy Mode = "no-lifetime-policy"NoKeyUsagePolicy Mode = "no-key-usage-policy"++ // DialOnly completes the handshake and never reads a byte.+ //+ // Research 04 section 7.2 calls this the most operationally dangerous+ // finding in the whole TLS surface, and it is measured: under TLS 1.3 every+ // row of the ClientAuth matrix returned a SUCCESSFUL tls.Dial, including+ // the rows where the server rejected the client certificate and served+ // nothing. The error arrives on the first read. Under TLS 1.2 the same case+ // fails at Dial, so this defect is invisible on the older protocol and+ // total on the newer one.+ //+ // A client in this mode reports a healthy dependency it was refused by.+ DialOnly Mode = "dial-only"++ // PolicyInPeerCallback puts its revocation policy in+ // VerifyPeerCertificate and reuses TLS sessions.+ //+ // crypto/tls is explicit that VerifyPeerCertificate does NOT run on a+ // resumed handshake and that VerifyConnection should be used instead+ // (common.go:645-677). So an application whose pinning, staple validation+ // or key floor lives in that hook has a policy that is checked on the first+ // handshake and silently skipped for every resumption afterwards.+ //+ // Go's client does re-verify the cached chain for expiry and chain validity+ // before offering a ticket, so an EXPIRED identity cannot survive+ // resumption. Revocation can: nothing anywhere checks it, and the ticket+ // lifetime ceiling is seven days (common.go:983-985). That is the hole this+ // mode exists to demonstrate.+ PolicyInPeerCallback Mode = "policy-in-peer-callback")const (@@ -115,6 +144,8 @@ func Modes() []string {string(NoKeyFloor),string(NoLifetimePolicy),string(NoKeyUsagePolicy),+ string(DialOnly),+ string(PolicyInPeerCallback),}}@@ -199,3 +230,25 @@ func (m Mode) checksLifetime() bool {func (m Mode) checksKeyUsage() bool {return m != SkipVerify && m != NoKeyUsagePolicy}++// reads reports whether the mode waits for a byte from the server. Only+// DialOnly does not, and under TLS 1.3 that is the difference between finding+// out you were refused and reporting success.+func (m Mode) reads() bool {+ return m != DialOnly+}++// resumes reports whether the mode reuses TLS sessions, which is the+// precondition for the resumption hole: there is nothing to skip a check on+// unless a session is actually resumed.+func (m Mode) resumes() bool {+ return m == PolicyInPeerCallback+}++// rechecksPerConnection reports whether the mode's policy runs on EVERY+// connection rather than only on a full handshake. A mode whose policy lives in+// VerifyPeerCertificate does not, because crypto/tls skips that callback on a+// resumed handshake.+func (m Mode) rechecksPerConnection() bool {+ return m != PolicyInPeerCallback+}diff --git a/PROJECTS/intermediate/chaos-engineering-tool/internal/tlsclient/resumption_test.go b/PROJECTS/intermediate/chaos-engineering-tool/internal/tlsclient/resumption_test.gonew file mode 100644index 00000000..f08dded1--- /dev/null+++ b/PROJECTS/intermediate/chaos-engineering-tool/internal/tlsclient/resumption_test.go@@ -0,0 +1,211 @@+// ©AngelaMos | 2026+// resumption_test.go++package tlsclient_test++import (+ "crypto/tls"+ "testing"++ "github.com/CarterPerez-dev/khaos/internal/pki"+ "github.com/CarterPerez-dev/khaos/internal/tlsclient"+)++// The resumption hole, which does not fit the matrix because it is not a+// property of one connection.+//+// crypto/tls is explicit that VerifyPeerCertificate does NOT run on a resumed+// handshake, and its doc comment tells you to use VerifyConnection or disable+// tickets instead (common.go:645-677). So an application whose pinning, staple+// validation or revocation check lives in that hook has a policy enforced on+// the FIRST handshake and skipped on every resumption afterwards, for as long+// as the ticket lives -- which Go caps at seven days (common.go:983-985).+//+// Expiry cannot survive it. Go's client re-verifies the cached chain for+// NotAfter and chain validity before offering a ticket and drops the entry if+// it fails, which research 04 section 7.4 measured. REVOCATION survives,+// because nothing anywhere checks it.+//+// The sequence this asserts is the one khaos's own phases produce: establish a+// session while the certificate is good, then revoke it, then connect again.++// session stands up an authority and returns a dialable address plus a SHARED+// session cache. The cache has to be shared or nothing resumes, and a test+// whose client cached nothing would pass while proving the opposite.+func session(t *testing.T) (*pki.Authority, string, tls.ClientSessionCache) {+ t.Helper()++ a, addr := armed(t, pki.PassThrough)++ return a, addr, tls.NewLRUClientSessionCache(0)+}++func resuming(+ t *testing.T,+ a *pki.Authority,+ cache tls.ClientSessionCache,+ mode tlsclient.Mode,+) *tlsclient.Client {+ t.Helper()++ return tlsclient.New(tlsclient.Config{+ Mode: mode,+ Host: host,+ Roots: a.TrustedPool(),+ Now: a.Now,+ Sessions: cache,+ })+}++// The control for the whole file. A session has to be ESTABLISHED and then+// actually RESUMED, or every assertion below is about a full handshake and the+// hole is never reached.+func TestASessionIsEstablishedAndThenResumed(t *testing.T) {+ a, addr, cache := session(t)++ client := resuming(t, a, cache, tlsclient.PolicyInPeerCallback)++ first := client.Decide(t.Context(), addr)+ if !first.Accepted {+ t.Fatalf("the first connection was refused: %s", first.Reason)+ }++ if first.Resumed {+ t.Fatal(+ "the FIRST connection reported itself resumed, so this test cannot tell a full handshake from a resumption",+ )+ }++ second := client.Decide(t.Context(), addr)+ if !second.Accepted {+ t.Fatalf("the second connection was refused: %s", second.Reason)+ }++ if !second.Resumed {+ t.Fatal(+ "the second connection did not resume, so nothing below exercises the resumption hole at all",+ )+ }+}++// THE fault. A policy that lives in VerifyPeerCertificate is skipped on+// resumption, so a certificate revoked after the session was established keeps+// being used.+func TestARevokedCertificateSurvivesResumption(t *testing.T) {+ a, addr, cache := session(t)++ client := resuming(t, a, cache, tlsclient.PolicyInPeerCallback)++ // Establish and cache while the certificate is good, which is what khaos's+ // baseline phase does.+ if first := client.Decide(t.Context(), addr); !first.Accepted {+ t.Fatalf("the baseline connection was refused: %s", first.Reason)+ }++ // Revoke it, which is what arming the fault does.+ if err := a.Arm(pki.Trap{+ Kind: pki.RevokedViaCRL,+ Host: host,+ }); err != nil {+ t.Fatalf("arm: %v", err)+ }++ after := client.Decide(t.Context(), addr)++ if !after.Resumed {+ t.Fatal(+ "the connection after revocation did not resume, so this proves nothing about resumption",+ )+ }++ if !after.Accepted {+ t.Fatal(+ "the resumed connection was refused, so this client re-checks revocation on resumption and the fault is not expressible against it",+ )+ }+}++// The other half, and the one that makes the finding a finding. A client whose+// policy runs per connection catches the same revocation on the same shared+// cache, so the hole is the HOOK and not resumption itself.+func TestACorrectClientCatchesRevocationDespiteResumption(t *testing.T) {+ a, addr, cache := session(t)++ client := resuming(t, a, cache, tlsclient.Correct)++ if first := client.Decide(t.Context(), addr); !first.Accepted {+ t.Fatalf("the baseline connection was refused: %s", first.Reason)+ }++ if err := a.Arm(pki.Trap{+ Kind: pki.RevokedViaCRL,+ Host: host,+ }); err != nil {+ t.Fatalf("arm: %v", err)+ }++ after := client.Decide(t.Context(), addr)++ if after.Accepted {+ t.Fatal(+ "the correct client used a revoked certificate, so putting the policy in the peer callback is not what made the other client vulnerable",+ )+ }+}++// The hole is WIDER than revocation, and this measures how wide.+//+// A resumed handshake does not re-send the certificate, so the chain the server+// is serving NOW is irrelevant to it. For a client whose policy lives in+// VerifyPeerCertificate that means every certificate fault is invisible for the+// ticket's lifetime, not only the ones nothing checks: an expired leaf, which+// crypto/x509 refuses outright on a full handshake, is accepted here.+//+// This is NOT the case research 04 section 7.4 measured, and the first version+// of this test confused the two. There, the CACHED certificate itself expired+// while time passed, and Go's client correctly re-verified the cached chain for+// NotAfter, dropped the entry and fell back to a full handshake that failed+// closed. That behaviour is real and is not what happens when the server swaps+// to a different, expired certificate underneath a live ticket.+func TestAResumedSessionIgnoresWhatTheServerNowServes(t *testing.T) {+ a, addr, cache := session(t)++ client := resuming(t, a, cache, tlsclient.PolicyInPeerCallback)++ if first := client.Decide(t.Context(), addr); !first.Accepted {+ t.Fatalf("the baseline connection was refused: %s", first.Reason)+ }++ if err := a.Arm(pki.Trap{+ Kind: pki.LeafExpired,+ Host: host,+ Window: pki.DefaultWindow,+ }); err != nil {+ t.Fatalf("arm: %v", err)+ }++ after := client.Decide(t.Context(), addr)++ if !after.Resumed {+ t.Fatal(+ "the connection did not resume, so this says nothing about what a resumed session ignores",+ )+ }++ if !after.Accepted {+ t.Fatal(+ "the resumed connection was refused, so this client does notice a swapped certificate and the hole is narrower than it looks",+ )+ }++ // And the contrast: a client that does NOT reuse sessions sees the expired+ // certificate and refuses it, so the acceptance above is the resumption and+ // not something about the chain khaos minted.+ fresh := resuming(t, a, cache, tlsclient.Correct)++ if direct := fresh.Decide(t.Context(), addr); direct.Accepted {+ t.Fatal(+ "a client doing a full handshake also accepted the expired certificate, so the resumed acceptance proves nothing",+ )+ }+}diff --git a/PROJECTS/intermediate/chaos-engineering-tool/internal/tlsclient/revocation.go b/PROJECTS/intermediate/chaos-engineering-tool/internal/tlsclient/revocation.goindex e7b58960..0c107eae 100644--- a/PROJECTS/intermediate/chaos-engineering-tool/internal/tlsclient/revocation.go+++ b/PROJECTS/intermediate/chaos-engineering-tool/internal/tlsclient/revocation.go@@ -37,7 +37,23 @@ func (c *Client) revocation(return Decision{Accepted: true}}- decision := Decision{Accepted: true}+ // THE RESUMPTION HOLE, stated exactly as crypto/tls documents it.+ //+ // VerifyPeerCertificate does NOT run on a resumed handshake, and the doc+ // comment says to use VerifyConnection or disable tickets instead+ // (common.go:645-677). So an application whose pinning, staple validation+ // or revocation check lives in that hook has a policy that is enforced on+ // the first handshake and skipped on every resumption for the ticket's+ // lifetime, which Go caps at seven days (common.go:983-985).+ //+ // Expiry cannot survive this: Go's client re-verifies the cached chain for+ // NotAfter and chain validity before offering a ticket, and drops the entry+ // if it fails. REVOCATION survives, because nothing anywhere checks it.+ if state.DidResume && !c.mode.rechecksPerConnection() {+ return Decision{Accepted: true, Resumed: true}+ }++ decision := Decision{Accepted: true, Resumed: state.DidResume}if reason, ok := c.fromStaple(state, leaf, issuer, &decision); !ok {return Decision{Reason: reason, AskedOCSP: decision.AskedOCSP}diff --git a/PROJECTS/intermediate/chaos-engineering-tool/scripts/tls.sh b/PROJECTS/intermediate/chaos-engineering-tool/scripts/tls.shindex f6b4d35b..460f59f8 100755--- a/PROJECTS/intermediate/chaos-engineering-tool/scripts/tls.sh+++ b/PROJECTS/intermediate/chaos-engineering-tool/scripts/tls.sh@@ -246,6 +246,70 @@ if start_range skip-verify; thenfifi+echo "== mutual TLS: the client has to NOTICE being refused =="++# khaos's server rejects both of these correctly, whatever the client verifies.+# The finding is whether the client finds out, and under TLS 1.3 that comes down+# to whether it reads: research 04 section 7.2 measured every row of the+# ClientAuth matrix returning a successful tls.Dial even where the server served+# nothing at all.+if start_range dial-only; then+ for experiment in tls.mtls_client_expired tls.mtls_client_absent; do+ run_experiment "$experiment"+ assert_confirmed "$experiment"+ assert_verdict "${experiment} vs a client that never reads" "passed / HELD"+ assert_exit "${experiment} vs a client that never reads" 2++ if grep -qE 'to be the defect for this control' <<<"$report"; then+ pass "${experiment} is a defect against a dial-only client"+ else+ fail "${experiment} was not called a defect although the target reported a healthy dependency that refused it"+ fi+ done+fi++if start_range closed; then+ # THE CONTRAST. The same fault against a client that reads is correctly+ # DENIED, which is what proves the defect above belongs to the client's+ # behaviour rather than to khaos's server.+ for experiment in tls.mtls_client_expired tls.mtls_client_absent; do+ run_experiment "$experiment"+ assert_verdict "${experiment} vs a client that reads" "deviated / DENIED"+ assert_exit "${experiment} vs a client that reads" 0+ done+fi++echo "== resumption outlives the revocation it was established before =="++# crypto/tls does not run VerifyPeerCertificate on a resumed handshake and its+# own doc comment says to use VerifyConnection instead. So a policy living in+# that hook is enforced on the first handshake and skipped for the ticket's+# lifetime, which Go caps at seven days.+#+# Expiry cannot survive it -- Go re-verifies the cached chain for NotAfter+# before offering a ticket -- but revocation can, because nothing anywhere+# checks revocation.+if start_range policy-in-peer-callback; then+ run_experiment tls.resumption_after_revocation+ assert_confirmed "resumption-after-revocation"+ assert_verdict "resumption vs a peer-callback policy" "passed / HELD"+ assert_exit "resumption vs a peer-callback policy" 2++ if grep -qE 'to be the defect for this control' <<<"$report"; then+ pass "a revoked certificate surviving resumption is a defect"+ else+ fail "a session that outlived its certificate's revocation was not called a defect"+ fi+fi++if start_range closed; then+ # The contrast again: a policy that runs per connection catches the same+ # revocation, so the hole is the HOOK rather than resumption itself.+ run_experiment tls.resumption_after_revocation+ assert_verdict "resumption vs a per-connection policy" "deviated / DENIED"+ assert_exit "resumption vs a per-connection policy" 0+fi+if [[ "$failures" -gt 0 ]]; thenecho "tls: ${failures} assertion(s) failed"exit 1