Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add tls WithKeyLogWriter option #2750

Merged
merged 1 commit into from
Mar 23, 2024
Merged
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
15 changes: 15 additions & 0 deletions p2p/security/tls/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"encoding/asn1"
"errors"
"fmt"
"io"
"math/big"
"os"
"runtime/debug"
Expand Down Expand Up @@ -41,6 +42,7 @@ type Identity struct {
// IdentityConfig is used to configure an Identity
type IdentityConfig struct {
CertTemplate *x509.Certificate
KeyLogWriter io.Writer
}

// IdentityOption transforms an IdentityConfig to apply optional settings.
Expand All @@ -53,6 +55,18 @@ func WithCertTemplate(template *x509.Certificate) IdentityOption {
}
}

// WithKeyLogWriter optionally specifies a destination for TLS master secrets
// in NSS key log format that can be used to allow external programs
// such as Wireshark to decrypt TLS connections.
// See https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSS/Key_Log_Format.
// Use of KeyLogWriter compromises security and should only be
// used for debugging.
func WithKeyLogWriter(w io.Writer) IdentityOption {
return func(c *IdentityConfig) {
c.KeyLogWriter = w
}
}

// NewIdentity creates a new identity
func NewIdentity(privKey ic.PrivKey, opts ...IdentityOption) (*Identity, error) {
config := IdentityConfig{}
Expand Down Expand Up @@ -83,6 +97,7 @@ func NewIdentity(privKey ic.PrivKey, opts ...IdentityOption) (*Identity, error)
},
NextProtos: []string{alpn},
SessionTicketsDisabled: true,
KeyLogWriter: config.KeyLogWriter,
},
}, nil
}
Expand Down
Loading