slackhq/nebula · error

error marshalling v1 certificate for handshake: %w

Error message

error marshalling v1 certificate for handshake: %w

What it means

Wrapping error in newCertState: v1.MarshalForHandshakes failed while preparing the cached wire form of the v1 certificate used during handshakes. The certificate parsed and its key pair verified, but marshalling to the handshake representation errored; the cause is preserved with %w for errors.Is.

Source

Thrown at pki.go:429

		if v1.Networks()[0] != v2.Networks()[0] {
			return nil, util.NewContextualError("v1 and v2 networks are not the same", nil, nil)
		}

		cs.initiatingVersion = dv
	}

	if v1 != nil {
		if pkcs11backed {
			//NOTE: We do not currently have a method to verify a public private key pair when the private key is in an hsm
		} else {
			if err := v1.VerifyPrivateKey(privateKeyCurve, privateKey); err != nil {
				return nil, fmt.Errorf("private key is not a pair with public key in nebula cert: %w", err)
			}
		}

		v1hs, err := v1.MarshalForHandshakes()
		if err != nil {
			return nil, fmt.Errorf("error marshalling v1 certificate for handshake: %w", err)
		}
		ncs, err := newCipherSuite(v1.Curve(), pkcs11backed, cipher, fips140.Enforced())
		if err != nil {
			return nil, err
		}
		cs.v1Cert = v1
		cs.v1Credential = handshake.NewCredential(v1, v1hs, privateKey, ncs)

		if cs.initiatingVersion == 0 {
			cs.initiatingVersion = cert.Version1
		}
	}

	if v2 != nil {
		if pkcs11backed {
			//NOTE: We do not currently have a method to verify a public private key pair when the private key is in an hsm
		} else {
			if err := v2.VerifyPrivateKey(privateKeyCurve, privateKey); err != nil {

View on GitHub (pinned to dd8f660c0a)

Solutions

  1. Re-generate the certificate with nebula-cert sign and replace pki.cert
  2. Validate the certificate with nebula-cert print -path pki.cert to see the parse error
  3. Restore pki.cert from backup or config management

Example fix

// before: hand-truncated cert file fails to marshal
// after
nebula-cert print -path pki.cert   # inspect failure
nebula-cert sign -ca-crt ca.crt -ca-key ca.key -name host1 -ip 10.0.0.1/24 -out-crt pki.cert
Defensive patterns

Strategy: validation

Validate before calling

// pre-parse the v1 cert to catch marshal problems early
func validateV1Cert(certPEM []byte) error {
    crt, _, err := cert.UnmarshalCertificateFromPEM(certPEM)
    if err != nil { return err }
    if crt.Version() == cert.Version1 {
        if _, err := crt.MarshalForHandshakes(); err != nil { return err }
    }
    return nil
}

Try / catch

if err := reloadCerts(); err != nil {
    if strings.Contains(err.Error(), "marshalling v1 certificate") {
        log.Fatalf("pki.cert is corrupt; restore or re-issue the certificate: %v", err)
    }
    return err
}

Prevention

When it happens

Trigger: newCertState: a v1 certificate passed private-key verification but v1.MarshalForHandshakes() returned an error — malformed/incomplete certificate structure in pki.cert.

Common situations: Truncated or hand-edited pki.cert; certificate built by incompatible tooling; bit rot or partial file write.

Understand the failure class

Related errors


AI-assisted analysis of slackhq/nebula@dd8f660c0a (2026-09-03). Data as JSON: /api/errors/bc45a60171190715. Report an issue: GitHub.