good morning!!!!

Skip to content
Snippets Groups Projects
Select Git revision
  • e837c9ab3fc94979dd79df9b70a3e7fda74263b9
  • master default protected
  • v0.2.16-candidate
  • shivam/rpcAddBorTx
  • default-cli-config
  • shivam/minerRecommitFix
  • vcastellm/pos-296-bump-go-version-in-bor-and-heimdall
  • shivam/ethstats-backend-fix
  • v0.2.16-beta1-candidate
  • v0.2.15-beta3-candidate
  • shivam/newCli-IPC
  • v0.3.0-dev
  • checkpoint-whitelist-master
  • shivam/codecov
  • jdkanani/fix-typo-log
  • shivam/hardcoded-spans-v0.2.14
  • shivam/hardcoded-spans
  • shivam/fast-state-sync
  • shivam/fast-state-sync-master
  • gethv1.10.15-merge
  • fix-txpool-2
  • v0.2.14-tmp-span-hotfix
  • v0.2.15-beta2
  • v0.2.15-beta1
  • v0.3.0-beta3
  • v0.3.0-beta2
  • v0.3.0-beta1
  • v0.2.14
  • v0.2.13
  • v0.2.13-beta2
  • v0.2.13-beta1
  • v0.2.12
  • v0.2.12-beta3
  • v0.2.12-beta1
  • v0.2.12-beta2
  • v0.2.11
  • v0.2.10
  • v0.2.10-beta2
  • v0.2.9
  • v0.2.9-beta1
  • v0.2.8
41 results

ethereum.go

Blame
  • Forked from github / maticnetwork / bor
    Source project has a limited visibility.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    module.go 2.30 KiB
    package ssl_endpoint
    
    import (
    	"crypto/rand"
    	"crypto/rsa"
    	"crypto/tls"
    	"crypto/x509"
    	"crypto/x509/pkix"
    	"math/big"
    	"net"
    	"time"
    
    	"tuxpa.in/a/zlog/log"
    
    	"pggat/lib/gat"
    	"pggat/lib/util/strutil"
    )
    
    type Module struct {
    	config *tls.Config
    }
    
    func NewModule() (*Module, error) {
    	return &Module{}, nil
    }
    
    func (T *Module) generateKeys() error {
    	// generate private key
    	priv, err := rsa.GenerateKey(rand.Reader, 2048)
    	if err != nil {
    		return err
    	}
    
    	keyUsage := x509.KeyUsageDigitalSignature | x509.KeyUsageKeyEncipherment
    
    	notBefore := time.Now()
    	notAfter := notBefore.Add(3 * 30 * 24 * time.Hour)
    
    	serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
    	serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
    	if err != nil {
    		return err
    	}
    
    	template := x509.Certificate{
    		SerialNumber: serialNumber,
    		Subject: pkix.Name{
    			Organization: []string{"GFX Labs"},
    		},
    		NotBefore: notBefore,
    		NotAfter:  notAfter,
    
    		KeyUsage:              keyUsage,
    		ExtKeyUsage:           []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
    		BasicConstraintsValid: true,
    	}
    
    	// TODO(garet)
    	template.IPAddresses = append(template.IPAddresses, net.ParseIP("192.168.1.1"))
    
    	derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
    	if err != nil {
    		return err
    	}
    
    	var cert tls.Certificate
    	cert.PrivateKey = priv
    	cert.Certificate = append(cert.Certificate, derBytes)
    
    	T.config = &tls.Config{
    		Certificates: []tls.Certificate{
    			cert,
    		},
    	}
    	return nil
    }
    
    func (T *Module) GatModule() {}
    
    func (T *Module) Endpoints() []gat.Endpoint {
    	if T.config == nil {
    		if err := T.generateKeys(); err != nil {
    			log.Printf("failed to generate ssl certificate: %v", err)
    		}
    	}
    
    	return []gat.Endpoint{
    		{
    			Network: "tcp",
    			Address: ":5432",
    			AcceptOptions: gat.FrontendAcceptOptions{
    				SSLRequired: false,
    				SSLConfig:   T.config,
    				AllowedStartupOptions: []strutil.CIString{
    					strutil.MakeCIString("client_encoding"),
    					strutil.MakeCIString("datestyle"),
    					strutil.MakeCIString("timezone"),
    					strutil.MakeCIString("standard_conforming_strings"),
    					strutil.MakeCIString("application_name"),
    					strutil.MakeCIString("extra_float_digits"),
    					strutil.MakeCIString("options"),
    				},
    			},
    		},
    	}
    }
    
    var _ gat.Module = (*Module)(nil)
    var _ gat.Listener = (*Module)(nil)