certy

package module
v1.0.13 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2025 License: MIT Imports: 18 Imported by: 0

README

Certy

Certy

Go Report Card

GoDoc

License

Certy is a Go package that automates the process of obtaining SSL certificates from Let's Encrypt using the ACME protocol. It handles the entire process from generating the account key, registering an ACME account, handling the HTTP-01 challenge, and issuing the certificate.

Installation

To install Certy, use go get:

go get github.com/kintsdev/certy

Usage

Here is an example of how to use Certy to issue a Let's Encrypt certificate for a domain:

Import the package
import "github.com/kintsdev/certy"
package main

import (
    "github.com/kintsdev/certy"
    "log"
    "os"
)

func main() {
    email := "your-email@example.com"
    domain := "yourdomain.com"
    location := "/path/to/save/certificates"

    if err := os.Setenv("ACME_ENV", "staging"); err != nil {
        log.Fatalf("Failed to set environment variable: %v", err)
    }

    certy.IssueLetsEncryptCert(email, domain, location)
}

Environment Variables
  • ACME_ENV: Set this environment variable to "staging" to use the Let's Encrypt staging server. This is useful for testing. If this environment variable is not set, the production server will be used.

Files Generated

The IssueLetsEncryptCert function will generate the following files in the current directory:

  • location/yourdomain.com/yourdomain.com-cert.pem: The certificate.
  • location/yourdomain.com/yourdomain.com-key.pem: The private key.
  • location/yourdomain.com/yourdomain.com-acme.json: The ACME registration information.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any bugs or enhancements.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DomainAcme

type DomainAcme struct {
	Sans       []string        `json:"sans"`
	IssuerData IssuerData      `json:"issuer_data"`
	AccountKey *rsa.PrivateKey `json:"account_key"`
	CertFile   string          `json:"cert_file"`
	KeyFile    string          `json:"key_file"`
	ExpireDate time.Time       `json:"expire_date"`
	IssueDate  time.Time       `json:"issue_date"`
	CustomCert bool            `json:"custom_cert"`
}

DomainAcme is a struct for domain acme data

func (*DomainAcme) Expired added in v0.0.9

func (d *DomainAcme) Expired() bool

Expired is a method for checking certificate is expired or not

func (*DomainAcme) IsNull added in v0.0.9

func (d *DomainAcme) IsNull() bool

func (*DomainAcme) RenewRequired added in v0.0.13

func (d *DomainAcme) RenewRequired() bool

Check is need renew certificate or not

type IssuerData

type IssuerData struct {
	URL            string `json:"url"`
	Ca             string `json:"ca"`
	ChallengeToken string `json:"challenge_token"`
}

IssuerData is a struct for issuer data

type Manager

type Manager struct {
	Email    string
	Location string
	Staging  bool
}

Manager is a struct for managing certificates

func NewManager

func NewManager(email, location string, staging bool) *Manager

NewManager is a constructor for Manager struct email: email for letsencrypt account location: location to store acme data and certificates

func (*Manager) AddCustomCert added in v0.0.16

func (m *Manager) AddCustomCert(domain, certFileData, keyfileData string)

func (*Manager) GetAcmeFileData added in v0.0.5

func (m *Manager) GetAcmeFileData(domain string) (*DomainAcme, error)

GetAcmeFileData is a method for getting acme file data

func (*Manager) GetCert

func (m *Manager) GetCert(hello *tls.ClientHelloInfo) (*tls.Certificate, error)

GetCert is a method for getting tls certificate

func (*Manager) GetChallengeToken

func (m *Manager) GetChallengeToken(domain string) string

GetChallengeToken is a method for getting challenge token

func (*Manager) HTTPHandler

func (m *Manager) HTTPHandler(fallback http.Handler) http.Handler

HTTPHandler is a http handler for serving acme challenge

func (*Manager) IssueCert

func (m *Manager) IssueCert(domain string)

IssueCert is a method for issuing letsencrypt certificate

Jump to

Keyboard shortcuts

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