A simple TLS configuration generator using ECDSA keys and self-signed certificates for Go applications.
- Easy-to-use TLS configuration generator
- Uses ECDSA keys with P-256 curve
- Self-signed certificate generation
- One-year validity period
- Custom organization name
- Automatic random serial number generation
go get github.com/NodePassProject/cert
package main
import (
"github.com/NodePassProject/cert"
"log"
"net/http"
)
func main() {
// Create a new TLS configuration with organization name
tlsConfig, err := cert.NewTLSConfig("My Application")
if err != nil {
log.Fatalf("Failed to create TLS config: %v", err)
}
// Create a new HTTP server with TLS
server := &http.Server{
Addr: ":8443",
TLSConfig: tlsConfig,
Handler: yourHandler(),
}
// Start the server with TLS
log.Printf("Starting secure server on https://localhost:8443")
log.Fatal(server.ListenAndServeTLS("", ""))
}
func yourHandler() http.Handler {
// Your HTTP handler implementation
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Secure server is running!"))
})
}
The TLS configuration returned by NewTLSConfig
is a standard *tls.Config
object that can be further customized:
tlsConfig, err := cert.NewTLSConfig("My Application")
if err != nil {
log.Fatalf("Failed to create TLS config: %v", err)
}
// Customize the TLS configuration
tlsConfig.MinVersion = tls.VersionTLS12
tlsConfig.CipherSuites = []uint16{
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
}
Copyright (c) 2025, NodePassProject. Licensed under the BSD 3-Clause License. See the LICENSE file for details.