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

MITM: recreating private/public keys all the time #368

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
22 changes: 22 additions & 0 deletions signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ import (
"net"
"sort"
"time"
"github.com/zond/gotomic"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do that without introducing another depdendency?

)


func hashSorted(lst []string) []byte {
c := make([]string, len(lst))
copy(c, lst)
Expand All @@ -38,8 +40,26 @@ func hashSortedBigInt(lst []string) *big.Int {
var goproxySignerVersion = ":goroxy1"
var certprivRSA crypto.Signer
var certprivECDSA crypto.Signer
var crtCache = gotomic.NewHash()

func signHost(ca tls.Certificate, hosts []string) (cert *tls.Certificate, err error) {

value, exist := crtCache.Get(gotomic.StringKey(hosts[0]))
if exist {
cert = value.(*tls.Certificate)
return
}

cert, err = generateCertificate(ca, hosts)

for _, host := range hosts {
crtCache.Put(gotomic.StringKey(host), cert)
}

return
}

func generateCertificate(ca tls.Certificate, hosts []string) (cert *tls.Certificate, err error) {
var x509ca *x509.Certificate

// Use the provided ca and not the global GoproxyCa for certificate generation.
Expand Down Expand Up @@ -77,6 +97,7 @@ func signHost(ca tls.Certificate, hosts []string) (cert *tls.Certificate, err er
}

var certpriv crypto.Signer

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we put the whitespace changes in a different commit?

switch ca.PrivateKey.(type) {
case *rsa.PrivateKey:
certpriv = certprivRSA
Expand All @@ -90,6 +111,7 @@ func signHost(ca tls.Certificate, hosts []string) (cert *tls.Certificate, err er
if derBytes, err = x509.CreateCertificate(rand.Reader, &template, x509ca, certpriv.Public(), ca.PrivateKey); err != nil {
return
}

return &tls.Certificate{
Certificate: [][]byte{derBytes, ca.Certificate[0]},
PrivateKey: certpriv,
Expand Down