Code Monkey home page Code Monkey logo

autotls's Introduction

autotls

Run Tests Go Report Card GoDoc

Support Let's Encrypt for a Go server application.

example

example for 1-line LetsEncrypt HTTPS servers.

package main

import (
  "log"
  "net/http"

  "github.com/gin-gonic/autotls"
  "github.com/gin-gonic/gin"
)

func main() {
  r := gin.Default()

  // Ping handler
  r.GET("/ping", func(c *gin.Context) {
    c.String(http.StatusOK, "pong")
  })

  log.Fatal(autotls.Run(r, "example1.com", "example2.com"))
}

example for custom autocert manager.

package main

import (
  "log"
  "net/http"

  "github.com/gin-gonic/autotls"
  "github.com/gin-gonic/gin"
  "golang.org/x/crypto/acme/autocert"
)

func main() {
  r := gin.Default()

  // Ping handler
  r.GET("/ping", func(c *gin.Context) {
    c.String(http.StatusOK, "pong")
  })

  m := autocert.Manager{
    Prompt:     autocert.AcceptTOS,
    HostPolicy: autocert.HostWhitelist("example1.com", "example2.com"),
    Cache:      autocert.DirCache("/var/www/.cache"),
  }

  log.Fatal(autotls.RunWithManager(r, &m))
}

example usage for graceful shutdown with custom context.

package main

import (
  "context"
  "log"
  "net/http"
  "os/signal"
  "syscall"

  "github.com/gin-gonic/autotls"
  "github.com/gin-gonic/gin"
)

func main() {
  // Create context that listens for the interrupt signal from the OS.
  ctx, stop := signal.NotifyContext(
    context.Background(),
    syscall.SIGINT,
    syscall.SIGTERM,
  )
  defer stop()

  r := gin.Default()

  // Ping handler
  r.GET("/ping", func(c *gin.Context) {
    c.String(http.StatusOK, "pong")
  })

  log.Fatal(autotls.RunWithContext(ctx, r, "example1.com", "example2.com"))
}

autotls's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

autotls's Issues

Only auto upgrading one path

Hello,
When I include multiple roots like:
log.Fatal(autotls.Run(r, "www.site.com", "site.com", "site2.com", "www.site2.com"))
I am only seeing site.com being auto-upgraded. site2.com is being served at :443 but not getting redirected from :80. Am I doing something wrong?

How to configure listening ports and universal domains in gins that have already used this framework?

Excuse me?
After this framework automatically implements stl, how do I configure the listening port for the service? Can I only use 80 as the listening port by default?
Also, how should this framework configure universal domain names, such as *. xxx.com, which matches all by default.
I haven't found a solution to these two problems yet. Can someone tell me?
I'm in a hurry and waiting for your response online. If you can, see if you can help me write a demo for the above two questions. thank you!

adding autotls causes build to fail

The moment I add autotls to gin gonic, I get this:

build asdasd: cannot load github.com/ugorji/go/codec: ambiguous import: found github.com/ugorji/go/codec in multiple modules:
	github.com/ugorji/go v1.1.4 (/home/gunix/.go/pkg/mod/github.com/ugorji/[email protected]/codec)
	github.com/ugorji/go/codec v0.0.0-20181209151446-772ced7fd4c2 (/home/gunix/.go/pkg/mod/github.com/ugorji/go/[email protected])

Seems to be the same issue as this one, however it appears only if I add github.com/gin-gonic/autotls to the project.

tls-sni disabled on LetsEncrypt

http: TLS handshake error from 82.34.xxx.xxx:55065: acme/autocert: unable to authorize "xxx.xxx.xxx"; tried ["tls-sni-02" "tls-sni-01"]

Why I can not get the response "pong" while I run the example1?

main.go:

package main

import (
	"log"
	"net/http"

	"github.com/gin-gonic/autotls"
	"github.com/gin-gonic/gin"
)

func main() {
	r := gin.Default()

	// Ping handler
	r.GET("/ping", func(c *gin.Context) {
		c.String(http.StatusOK, "pong")
	})

	log.Fatal(autotls.Run(r, "example1.com", "example2.com"))
}

After running the main.go,I typed https://localhost:443/ping in browser, I just get "ERR_SSL_PROTOCOL_ERROR" wrong message.

And the console shows the error messages as below:

2023/01/22 17:58:05 http: TLS handshake error from [::1]:51238: acme/autocert: server name component count invalid
2023/01/22 17:58:05 http: TLS handshake error from [::1]:51239: acme/autocert: server name component count invalid
2023/01/22 17:58:05 http: TLS handshake error from [::1]:51240: acme/autocert: server name component count invalid
2023/01/22 17:58:06 http: TLS handshake error from [::1]:51241: acme/autocert: server name component count invalid

I don't know what happens. Who can tell me why?

not working

golang/go#21890

acme/autocert: unable to authorize ""; tried ["tls-sni-02" "tls-sni-01"]

disabled ["tls-sni-02" "tls-sni-01"]

Tag releases

Recommend tagging a new release now, and then after each cycle.

Not having the last release tagged caused problems vendoring autotls via the dep tool.

Turns out this project has a single outdated tagged release which the dep tool defaults to over the latest master branch.

Work-around to enable vendoring is to manually set the constraint in Gopakg.toml to:

[[constraint]]
  branch = "master"
  name = "github.com/gin-gonic/autotls"

Missing server name for localhost

Hi I am trying to whitelist my localhost for development. I am running into this error.

http: TLS handshake error from 127.0.0.1:2072: acme/autocert: missing server name

Here is my run command

log.Fatal(autotls.Run(router, "192.168.99.100","127.0.0.1"))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.