sslcert

package module
v0.0.0-...-246e4c8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 23, 2023 License: MIT Imports: 17 Imported by: 5

README

sslcert

License Go version Release Checks GoDoc

sslcert library generates a new tlsconfig usable within go standard library configured with a self-signed certificate generated on the fly.

Example

package main

import (
	"fmt"
	"log"
	"net/http"

	"github.com/projectdiscovery/sslcert"
)

func main() {
	tlsOptions := sslcert.DefaultOptions
	tlsOptions.Host = "example.com"

	// Create TLSConfig using options
	tlsConfig, err := sslcert.NewTLSConfig(tlsOptions)
	if err != nil {
		log.Fatal(err)
	}

	// using tlsconfig to host http server
	server := &http.Server{
		Addr:      ":8000",
		TLSConfig: tlsConfig,s
	}

	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("Hello World"))
	})

	fmt.Println("Started HTTPS server on " + server.Addr)
	fmt.Println("Check it out at https://localhost:8000/")
	if err := server.ListenAndServeTLS("", ""); err != nil {
		log.Fatal(err)
	}
}

Documentation

Overview

Package sslcert contains a reworked version of https://golang.org/src/crypto/tls/generate_cert.go

Index

Constants

This section is empty.

Variables

View Source
var DefaultOptions = Options{
	ValidFor:     time.Duration(365 * 24 * time.Hour),
	IsCA:         false,
	RSABits:      2048,
	Organization: "Acme Co",
}

Functions

func Generate

func Generate(options Options) (privateKey, publicKey []byte, err error)

func NewTLSConfig

func NewTLSConfig(options Options) (*tls.Config, error)

Types

type Options

type Options struct {
	Host         string // Comma-separated hostnames and IPs to generate a certificate for")
	Organization string
	ValidFrom    string        // Creation date formatted as Jan 1 15:04:05 2011
	ValidFor     time.Duration // 365*24*time.Hour Duration that certificate is valid for
	IsCA         bool          // whether this cert should be its own Certificate Authority
	RSABits      int           // 2048 Size of RSA key to generate. Ignored if --ecdsa-curve is set
	EcdsaCurve   string        // ECDSA curve to use to generate a key. Valid values are P224, P256 (recommended), P384, P521
	Ed25519Key   bool          // Generate an Ed25519 key
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL