fix issue#10

This commit is contained in:
ginuerzh
2022-02-13 20:40:37 +08:00
parent a8804ea02d
commit edca3e0a55
5 changed files with 41 additions and 17 deletions

View File

@ -34,8 +34,15 @@ func buildConfigFromCmd(services, nodes stringList) (*config.Config, error) {
if v := os.Getenv("GOST_PROFILING"); v != "" {
cfg.Profiling = &config.ProfilingConfig{
Addr: v,
Enabled: true,
Addr: v,
Enable: true,
}
}
if v := os.Getenv("GOST_METRICS"); v != "" {
cfg.Metrics = &config.MetricsConfig{
Addr: v,
Path: "/metrics",
Enable: true,
}
}

View File

@ -80,7 +80,7 @@ func main() {
os.Exit(0)
}
if cfg.Profiling != nil && cfg.Profiling.Enabled {
if cfg.Profiling != nil && cfg.Profiling.Enable {
go func() {
addr := cfg.Profiling.Addr
if addr == "" {

View File

@ -72,12 +72,15 @@ func generateKeyPair() (rawCert, rawKey []byte, err error) {
notBefore := time.Now()
notAfter := notBefore.Add(validFor)
serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
serialNumber, _ := rand.Int(rand.Reader, serialNumberLimit)
serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
if err != nil {
return
}
template := x509.Certificate{
SerialNumber: serialNumber,
Subject: pkix.Name{
Organization: []string{"gost"},
CommonName: "gost.run",
},
NotBefore: notBefore,
NotAfter: notAfter,
@ -86,13 +89,19 @@ func generateKeyPair() (rawCert, rawKey []byte, err error) {
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
BasicConstraintsValid: true,
}
template.DNSNames = append(template.DNSNames, "gost.run")
derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
if err != nil {
return
}
rawCert = pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: derBytes})
rawKey = pem.EncodeToMemory(&pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(priv)})
privBytes, err := x509.MarshalPKCS8PrivateKey(priv)
if err != nil {
return
}
rawKey = pem.EncodeToMemory(&pem.Block{Type: "PRIVATE KEY", Bytes: privBytes})
return
}