Convert Figma logo to code with AI

go-acme logolego

Let's Encrypt/ACME client and library written in Go

7,845
1,012
7,845
166

Top Related Projects

31,293

Certbot is EFF's tool to obtain certs from Let's Encrypt and (optionally) auto-enable HTTPS on your server. It can also act as a client for any other CA that uses the ACME protocol.

🛡️ A private certificate authority (X.509 & SSH) & ACME server for secure automated certificate management, so you can use TLS everywhere & SSO for SSH.

48,328

A simple zero-config tool to make locally trusted development certificates with any names you'd like.

56,905

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

50,061

The Cloud Native Application Proxy

Quick Overview

Lego is a Let's Encrypt client and ACME library written in Go. It provides a simple way to obtain and manage SSL/TLS certificates from Let's Encrypt and other ACME-based Certificate Authorities. Lego supports various DNS providers and challenge types, making it versatile for different deployment scenarios.

Pros

  • Supports a wide range of DNS providers for DNS-01 challenge
  • Offers both library and CLI functionality
  • Actively maintained with regular updates
  • Implements ACME v2 protocol

Cons

  • Learning curve for users new to ACME and certificate management
  • Limited documentation for some advanced use cases
  • May require additional configuration for complex network setups
  • Dependency management can be challenging in some environments

Code Examples

  1. Creating a new ACME client:
import "github.com/go-acme/lego/v4/lego"

config := lego.NewConfig(&myUser)
client, err := lego.NewClient(config)
if err != nil {
    log.Fatal(err)
}
  1. Obtaining a certificate using the HTTP-01 challenge:
import "github.com/go-acme/lego/v4/certificate"

request := certificate.ObtainRequest{
    Domains: []string{"example.com"},
    Bundle:  true,
}
certificates, err := client.Certificate.Obtain(request)
if err != nil {
    log.Fatal(err)
}
  1. Renewing an existing certificate:
import "github.com/go-acme/lego/v4/certificate"

renewRequest := certificate.RenewRequest{
    Domain:    "example.com",
    Bundle:    true,
    CertURL:   "https://acme-v02.api.letsencrypt.org/acme/cert/fa1234567890",
    PrivateKey: privateKey,
}
renewedCert, err := client.Certificate.Renew(renewRequest)
if err != nil {
    log.Fatal(err)
}

Getting Started

To use Lego in your Go project:

  1. Install the package:

    go get -u github.com/go-acme/lego/v4
    
  2. Import the required packages in your Go code:

    import (
        "github.com/go-acme/lego/v4/certificate"
        "github.com/go-acme/lego/v4/lego"
        "github.com/go-acme/lego/v4/registration"
    )
    
  3. Create a user, configure the client, and obtain a certificate:

    myUser := &MyUser{} // Implement registration.User interface
    config := lego.NewConfig(myUser)
    client, _ := lego.NewClient(config)
    
    // Use client to obtain or renew certificates
    

Remember to implement the registration.User interface and handle errors appropriately in your production code.

Competitor Comparisons

31,293

Certbot is EFF's tool to obtain certs from Let's Encrypt and (optionally) auto-enable HTTPS on your server. It can also act as a client for any other CA that uses the ACME protocol.

Pros of Certbot

  • More mature and widely adopted project with extensive documentation
  • Supports a broader range of web servers and operating systems
  • Offers automatic configuration for popular web servers like Apache and Nginx

Cons of Certbot

  • Written in Python, which may be slower compared to Go-based Lego
  • Can be more complex to set up and use in certain environments
  • Requires root access for many operations, which may be a security concern

Code Comparison

Certbot (Python):

from certbot import main

main.main()

Lego (Go):

import "github.com/go-acme/lego/v4/cmd"

cmd.Execute()

Both projects aim to simplify the process of obtaining and managing SSL/TLS certificates from Let's Encrypt. Lego is written in Go and focuses on being a lightweight, flexible library that can be easily integrated into other projects. Certbot, on the other hand, is a more comprehensive solution with additional features and broader platform support.

Lego's Go-based implementation may offer better performance and easier cross-platform compilation, while Certbot's Python codebase might be more accessible to a wider range of developers. The choice between the two often depends on specific project requirements, existing infrastructure, and developer preferences.

🛡️ A private certificate authority (X.509 & SSH) & ACME server for secure automated certificate management, so you can use TLS everywhere & SSO for SSH.

Pros of certificates

  • More comprehensive PKI solution, offering a complete certificate authority and management system
  • Supports advanced features like SSH certificate authority and single sign-on (SSO) integration
  • Provides a user-friendly CLI tool for certificate management

Cons of certificates

  • Steeper learning curve due to its more complex and feature-rich nature
  • May be overkill for simple ACME certificate issuance use cases
  • Less focused on ACME protocol implementation compared to lego

Code comparison

certificates:

cert, err := ca.Sign(&x509.Certificate{
    Subject:     pkix.Name{CommonName: "example.com"},
    DNSNames:    []string{"example.com", "www.example.com"},
    KeyUsage:    x509.KeyUsageDigitalSignature | x509.KeyUsageKeyEncipherment,
    ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
})

lego:

client, err := lego.NewClient(config)
request := certificate.ObtainRequest{
    Domains: []string{"example.com", "www.example.com"},
    Bundle:  true,
}
certificates, err := client.Certificate.Obtain(request)

The code snippets demonstrate that certificates offers more granular control over certificate properties, while lego provides a simpler interface for obtaining certificates through ACME.

48,328

A simple zero-config tool to make locally trusted development certificates with any names you'd like.

Pros of mkcert

  • Simpler to use for local development and testing
  • Creates locally-trusted certificates without external dependencies
  • Supports a wide range of operating systems and browsers

Cons of mkcert

  • Limited to local development; not suitable for production environments
  • Doesn't support automatic certificate renewal
  • Lacks advanced features for complex certificate management

Code Comparison

mkcert:

mkcert.Install()
cert, key, err := mkcert.CreateCert("example.com", "*.example.com")

lego:

client, _ := lego.NewClient(config)
request := certificate.ObtainRequest{
    Domains: []string{"example.com"},
    Bundle:  true,
}
certificates, err := client.Certificate.Obtain(request)

mkcert focuses on simplicity for local development, while lego provides a more comprehensive solution for production-grade certificate management. mkcert is ideal for developers who need quick, locally-trusted certificates, whereas lego is better suited for applications requiring automated ACME-based certificate issuance and renewal in production environments.

56,905

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Pros of Caddy

  • Full-featured web server with built-in automatic HTTPS
  • User-friendly configuration with a simple Caddyfile syntax
  • Extensive plugin ecosystem for additional functionality

Cons of Caddy

  • Larger footprint and resource usage compared to Lego
  • May be overkill for simple ACME client needs
  • Less flexibility for integrating into existing applications

Code Comparison

Caddy configuration (Caddyfile):

example.com {
    respond "Hello, World!"
}

Lego usage (Go):

client, _ := lego.NewClient(config)
certificate, _ := client.Certificate.Obtain(request)

Summary

Caddy is a comprehensive web server with built-in ACME support, offering a user-friendly configuration and extensive features. Lego, on the other hand, is a lightweight ACME client library focused on certificate management. Caddy is ideal for those seeking an all-in-one solution, while Lego is better suited for developers who need to integrate ACME functionality into existing applications or require more granular control over the certificate issuance process.

50,061

The Cloud Native Application Proxy

Pros of Traefik

  • Full-featured reverse proxy and load balancer, offering more comprehensive functionality
  • Dynamic configuration with automatic service discovery
  • Integrates seamlessly with container orchestration platforms like Kubernetes and Docker Swarm

Cons of Traefik

  • Steeper learning curve due to its broader feature set
  • Higher resource consumption compared to Lego's focused ACME client functionality
  • May be overkill for simple SSL certificate management tasks

Code Comparison

Lego (ACME client configuration):

client, err := lego.NewClient(config)
request := certificate.ObtainRequest{
    Domains: []string{"example.com"},
    Bundle:  true,
}
certificates, err := client.Certificate.Obtain(request)

Traefik (SSL configuration in YAML):

tls:
  certificates:
    - certFile: /path/to/cert.pem
      keyFile: /path/to/key.pem
  stores:
    default:
      defaultCertificate:
        certFile: /path/to/cert.pem
        keyFile: /path/to/key.pem

While Lego focuses on ACME client functionality for obtaining SSL certificates, Traefik provides a more comprehensive reverse proxy solution with built-in SSL management capabilities. Lego is better suited for developers needing a lightweight ACME client, while Traefik offers a full-featured proxy with additional benefits for complex deployments.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

lego logo

Automatic Certificates and HTTPS for everyone.

Lego

Let's Encrypt client and ACME library written in Go.

Go Reference Build Status Docker Pulls

Features

  • ACME v2 RFC 8555
    • Support RFC 8737: TLS Application‑Layer Protocol Negotiation (ALPN) Challenge Extension
    • Support RFC 8738: certificates for IP addresses
    • Support draft-ietf-acme-ari-03: Renewal Information (ARI) Extension
  • Register with CA
  • Obtain certificates, both from scratch or with an existing CSR
  • Renew certificates
  • Revoke certificates
  • Robust implementation of all ACME challenges
    • HTTP (http-01)
    • DNS (dns-01)
    • TLS (tls-alpn-01)
  • SAN certificate support
  • CNAME support by default
  • Comes with multiple optional DNS providers
  • Custom challenge solvers
  • Certificate bundling
  • OCSP helper function

Installation

How to install.

Usage

Documentation

Documentation is hosted live at https://go-acme.github.io/lego/.

DNS providers

Detailed documentation is available here.

Akamai EdgeDNSAlibaba Cloud DNSall-inklAmazon Lightsail
Amazon Route 53ArvanCloudAurora DNSAutodns
Azure (deprecated)Azure DNSBindmanBluecat
BranditBunnyCheckdomainCivo
Cloud.ruCloudDNSCloudflareClouDNS
CloudXNSConoHaConstellixCPanel/WHM
Derak ClouddeSEC.ioDesignate DNSaaS for OpenstackDigital Ocean
DirectAdminDNS Made EasydnsHome.deDNSimple
DNSPod (deprecated)Domain Offensive (do.de)DomeneshopDreamHost
Duck DNSDynDynuEasyDNS
Efficient IPEpikExoscaleExternal program
freemyip.comG-CoreGandi Live DNS (v5)Gandi
GlesysGo DaddyGoogle CloudGoogle Domains
HetznerHosting.deHosttechHTTP request
http.netHuawei CloudHurricane Electric DNSHyperOne
IBM Cloud (SoftLayer)IIJ DNS Platform ServiceInfobloxInfomaniak
Internet Initiative JapanInternet.bsINWXIonos
IPv64iwantmynameJokerJoohoi's ACME-DNS
LiaraLima-CityLinode (v4)Liquid Web
LoopiaLuaDNSMail-in-a-BoxManual
Metanamemijn.hostMittwaldMyDNS.jp
MythicBeastsName.comNamecheapNamesilo
NearlyFreeSpeech.NETNetcupNetlifyNicmanager
NIFCloudNjallaNodionNS1
Open Telekom CloudOracle CloudOVHplesk.com
PorkbunPowerDNSRackspaceRcodeZero
reg.ruRFC2136RimuHostingSakura Cloud
ScalewaySelectel v2SelectelServercow
ShellrentSimply.comSonicStackpath
Tencent Cloud DNSTransIPUKFast SafeDNSUltradns
VariomediaVegaDNSVercelVersio.[nl/eu/uk]
VinylDNSVK CloudVscaleVultr
WebnamesWebsupportWEDOSYandex 360
Yandex CloudYandex PDDZone.eeZonomi

If your DNS provider is not supported, please open an issue.