gotlsconfig

package module
v0.0.0-...-4fbeedc Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

README

gotlsconfig

import "github.com/mschneider82/gotlsconfig"

Overview

Package gotlsconfig makes it easy to get a secure *tls.Config for testing and development. It generates on the fly pub/private certificates. This mitigates the usage of static private keys in go code.

Its better to use self singed certificates instead of doing plain traffic!

Example :
config := gotlsconfig.New("localhost")

l, err := net.Listen("tcp", ":1234")
if err != nil {
    log.Fatal(err)
}
defer l.Close()

for {
    connp, err := l.Accept()
    if err != nil {
        log.Fatal(err)
    }
    conn := tls.Server(connp, config)
    go func(c net.Conn) {
        io.Copy(os.Stdout, c)
        fmt.Println()
        c.Close()
    }(conn)
}

Index

Examples
Package files

doc.go gotlsconfig.go selfsigned.go

Constants

const (
    EC256   = KeyType("P256")
    EC384   = KeyType("P384")
    RSA2048 = KeyType("2048")
    RSA4096 = KeyType("4096")
    RSA8192 = KeyType("8192")
)

Constants for all key types we support.

func New

func New(subjectNames ...string) *tls.Config

New generates a new selfsinged rsa4096 certificate for subjectNames with 10 years expiry

func NewWithConfig

func NewWithConfig(ssconfig SelfSignedConfig) (*tls.Config, error)

NewWithConfig gets a new tls.Config with custom settings

type KeyType

type KeyType string

type SelfSignedConfig

type SelfSignedConfig struct {
    SAN          []string // Subject Alternative Names
    KeyType      KeyType
    Expire       time.Time
    Organization string
}

SelfSignedConfig configures a self-signed certificate.


Generated by godoc2md

Documentation

Overview

Package gotlsconfig makes it easy to get a secure *tls.Config for testing and development. It generates on the fly pub/private certificates. This mitigates the usage of static private keys in go code.

Its better to use self singed certificates instead of doing plain traffic!

Example
package main

import (
	"crypto/tls"
	"fmt"
	"io"
	"log"
	"net"
	"os"

	"github.com/mschneider82/gotlsconfig"
)

func main() {
	config := gotlsconfig.New("localhost")

	l, err := net.Listen("tcp", ":1234")
	if err != nil {
		log.Fatal(err)
	}
	defer l.Close()

	for {
		connp, err := l.Accept()
		if err != nil {
			log.Fatal(err)
		}
		conn := tls.Server(connp, config)
		go func(c net.Conn) {
			io.Copy(os.Stdout, c)
			fmt.Println()
			c.Close()
		}(conn)
	}
}
Output:

Index

Examples

Constants

View Source
const (
	EC256   = KeyType("P256")
	EC384   = KeyType("P384")
	RSA2048 = KeyType("2048")
	RSA4096 = KeyType("4096")
	RSA8192 = KeyType("8192")
)

Constants for all key types we support.

Variables

This section is empty.

Functions

func New

func New(subjectNames ...string) *tls.Config

New generates a new selfsinged rsa4096 certificate for subjectNames with 10 years expiry

func NewWithConfig

func NewWithConfig(ssconfig SelfSignedConfig) (*tls.Config, error)

NewWithConfig gets a new tls.Config with custom settings

Types

type KeyType

type KeyType string

type SelfSignedConfig

type SelfSignedConfig struct {
	SAN          []string // Subject Alternative Names
	KeyType      KeyType
	Expire       time.Time
	Organization string
}

SelfSignedConfig configures a self-signed certificate.

Jump to

Keyboard shortcuts

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