certificate

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2023 License: GPL-3.0 Imports: 8 Imported by: 0

README

Certificate

This package lets you create a valid x509 certificate for a local web server so that you can access it from another computer using the same certificate imported in the browser.

Examples

There are some settings we need to provide, in the same order, to be able to generate the certificate:

  • serial: The serial number of the certificate.
  • country: The country the certificate is issued from.
  • organization: The organization that is issuing the certificate.
  • commonName: The common name of the certificate.
  • expire: When the certificate is due to expire.
  • localIP: The local IP of the future web server, pass nil if it should be automatically gathered from GetLocalIP().
package main

import (
    "fmt"
    "github.com/kkrypt0nn/swiss-army-knife/certificate"
    "time"
)

func main() {
    privateKey, certificate := certificate.GenerateCertificate(1337, "CH", "Krypton", "My Certificate", time.Now().AddDate(7, 7, 7), nil)
    fmt.Printf("%s\n", privateKey)
    fmt.Printf("%s\n", certificate)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateCertificate

func GenerateCertificate(serial int64, country string, organization string, commonName string, expire time.Time, localIP net.IP) ([]byte, []byte)

GenerateCertificate generates a self-signed certificate for the given host and returns the private RSA key and the generated certificate PEM encoded.

func GetLocalIP

func GetLocalIP() net.IP

GetLocalIP returns the non loopback local IP of the host.

Types

This section is empty.

Jump to

Keyboard shortcuts

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