What causes urn:acme:error:unauthorized 403 error in golang's acme/autocert? - go

The full error message is:
403 urn:acme:error:unauthorized: Account creation on ACMEv1 is
disabled. Please upgrade your ACME client to a version that supports
ACMEv2 / RFC 8555. See
https://community.letsencrypt.org/t/end-of-life-plan-for-acmev1/88430
for details
And I've googled this and reviewed that link, but I'm just using:
golang.org/x/crypto/acme/autocert
package in a very normal way:
package main
import (
"crypto/tls"
"net/http"
"github.com/gin-gonic/gin"
"golang.org/x/crypto/acme/autocert"
)
func main() {
router := gin.Default()
hosts := []string{"yourdomain.com"}
certManager := autocert.Manager{
Prompt: autocert.AcceptTOS,
HostPolicy: autocert.HostWhitelist(hosts...),
Cache: autocert.DirCache("/certs"),
}
server := &http.Server{
Addr: ":https",
Handler: router,
TLSConfig: &tls.Config{
GetCertificate: certManager.GetCertificate,
},
}
server.ListenAndServeTLS("", "")
}
In fact this code has been running and working fine for the last 6 months. But just today I switched the server it was on and now get the above message.
I tried getting the very latest version of golang, but still same problem.
I changed my DNS for my hosts to this new server's ip and the hostname of the server is correct.
Far as I can tell, it's 100% identical to the previous working server but with a new IP.
Is golang's acme/autocert really this out of date and not using ACMEv2?

This statement:
In fact this code has been running and working fine for the last 6 months. But just today I switched the server it was on and now get the above message.
Might indicate that you're building against an older version of golang.org/x/crypto - check your go.mod file and ensure you're using a fairly recent version. I completed a project recently that uses almost identical code. The require in my go.mod looks like this:
golang.org/x/crypto v0.0.0-20200602180216-279210d13fed

Related

go get returns unrecognized import path

I have a go program which imports a custom module hosted internally
import (
"fmt"
"log"
...
"gitlab.org.myteam.com/teamrepo/project1"
)
When I do go build I get following errors:
main.go:15:2: no required module provides package gitlab.org.myteam.com/teamrepo/project1; to add it:
go get gitlab.org.myteam.com/teamrepo/project1
As directed when I do go get I get following errors:
go: downloading gitlab.org.myteam.com/teamrepo/project1 v1.0.1
go: gitlab.org.myteam.com/teamrepo/project1#v1.0.1: verifying module: gitlab.org.myteam.com/teamrepo/project1#v1.0.1: reading https://sum.golang.org/lookup/gitlab.org.myteam.com/teamrepo/project1#v1.0.1: 404 Not Found
server response: not found: gitlab.org.myteam.com/teamrepo/project1#v1.0.1: unrecognized import path "gitlab.org.myteam.com/teamrepo/project1": https fetch: Get "https://gitlab.org.myteam.com/teamrepo/project1?go-get=1": dial tcp 10.xx.xx.xxx:443: connect: connection refused

I am not sure what I am doing wrong here. git clone on this repository works fine, so it is accessible.
Further, two things that I find confusing in the errors are:

Why go is trying to read the path reading https://sum.golang.org/lookup/gitlab.org.myteam.com/teamrepo/project1#v1.0.1: 404 Not Found

And, how it decided to fetch version v1.0.1 as I haven’t explicitly specified this version anywhere.
go version go1.19.4 darwin/amd64

How to fix: Chromedriver Page Immediately Closes

I run a program that tries to open a webpage using agouti/chromedriver in go, but as soon as it calls the new page, it closes the page. Subsequent attempts to access the page result in an "invalid session id" error. How can I get the page to stay open?
This is using Go (version 1.13.3 darwin/amd64) on Mac (version 10.14.5), with chromedriver (version 76.0.3809.68). I have the latest version of Google Chrome installed as well. I have tried updating chrome and agouti to no improved results. I have quit and restarted Chrome, uninstalled and reinstalled Chrome, and restarted my computer, none of which have worked. I have run with several chromedriver options (seen below), and run without them. I have tried with (seen below) and without time.Sleep() between functions. My regular chrome browser works fine.
package main
import (
"fmt"
"time"
"github.com/sclevine/agouti"
)
func main() {
driver := agouti.ChromeDriver(
agouti.ChromeOptions("args", []string{
"--headless",
"--no-sandbox",
"--disable-dev-shm-usage",
"--disable-gpu",
"--whitelisted-ips",
"--detach",
}),
agouti.Debug,
)
fmt.Println("start")
err := driver.Start()
if err != nil {
fmt.Println("Error starting driver: " + err.Error())
return
}
page, err := driver.NewPage(agouti.Browser("chrome"))
if err != nil {
fmt.Println("Error creating new page: " + err.Error())
return
}
time.Sleep(1 * time.Second)
err = page.Navigate("https://www.google.com")
if err != nil {
fmt.Println("Error navigating to job post link: " + err.Error())
return
}
time.Sleep(1 * time.Second)
fmt.Println("end")
}
When not using the --headless tag, I can see the browser window open and close in less than a second.
Expected output:
start
Starting ChromeDriver 76.0.3809.68 (420c9498db8ce8fcd190a954d51297672c1515d5-refs/branch-heads/3809#{#864}) on port 53489
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
end
Actual Output:
start
Starting ChromeDriver 76.0.3809.68 (420c9498db8ce8fcd190a954d51297672c1515d5-refs/branch-heads/3809#{#864}) on port 53489
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
Error navigating to job post link: failed to navigate: request unsuccessful: invalid session id
I found the solution; turns out I needed to reinstall chromedriver. Looking back through my logs, the issue occurred due to Chrome automatically updating overnight, and no longer working with my previous version of chromedriver.

Unable to create online web-page

I am trying to create Golang web-pages...
Progress:
Ubuntu 18.04 installed both locally and on a Linode VPS.
Created and compiled a local Golang "Hello World" script that renders OK both locally and online.
Created a net/http Golang script that works OK when called locally http://localhost:8080/testing to see if it works
Uploaded the script to the Linode server and initial status messages appear but when calling http:123.456.789.32:8080/testing to see if it works the browser freezes.
//
// Golang - main.go
//
package main
import (
"net/http"
)
func sayHello(w http.ResponseWriter, r *http.Request) {
message := r.URL.Path
message = "Hello " + message
w.Write([]byte(message))
}
func main() {
http.HandleFunc("/", sayHello)
if err := http.ListenAndServe(":8080", nil); err != nil {
panic(err)
}
}
There are no errors or warnings rendered and unable to find any log references.
Can error and warnings similar to PHP error_reporting(-1), declare(strict_types=1) etc be logged or rendered?
A quick check with Nmap showed this result:
nmap -sV -p 8080 <yourIP>
Starting Nmap 7.70 ( https://nmap.org ) at 2019-07-04 07:45 CEST
Nmap scan report for <your-domain>.com (<yourIP>)
Host is up (0.032s latency).
PORT STATE SERVICE VERSION
8080/tcp filtered http-proxy
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 0.90 seconds
The state of "filtered" actually means that there was no response on that port as opposed to an outright rejection of the request.
Check the output of iptables -L -n. Presumably, you have a firewall running and blocking port 8080. Do not simply deactivate the firewall, but read up on how to open port 8080 in the firewall product you are using. Linode has guides for the commonly used/preinstalled firewalls of various Linux distributions.
If you plan to go into production, please have someone help you to ensure security and availability of your deployment.

http.ListenAndServe handler function executed twice on port 80 [duplicate]

This question already has answers here:
HandleFunc being called twice
(4 answers)
Why this simple web server is called even number times?
(1 answer)
Closed 5 years ago.
If I run the following simple http server code on port 8080 everything works as expected. If I run the same code on port 80, by just changing the port, the handler function is executed twice with each request. Why, and how to fix it?
// httptest project main.go
package main
import (
"net/http"
"log"
"fmt"
"html"
)
var count int
func defaultHandler(w http.ResponseWriter, r *http.Request) {
count++
fmt.Fprintf(w, "Hello, %q count=%d", html.EscapeString(r.URL.Path), count)
fmt.Println(count,r.RemoteAddr)
}
func main() {
http.HandleFunc("/", defaultHandler)
log.Fatal(http.ListenAndServe(":8080", nil))
}
If I enter localhost:8080 in the browser, I get a response with a count starting at 1 and increased by 1 with each new request.
If I change the code to port 80 and enter just localhost or localhost:80 in the browser, I get a first response with a count starting at 1 but increased by two with each following request. At the same time the print statement for the console output is executed twice.
Terminal console when running on port 80 with 3 requests:
>go run main.go
1 [::1]:51335
2 [::1]:51335
3 [::1]:51335
4 [::1]:51335
5 [::1]:51335
6 [::1]:51335
The responses in the browser are Hello, "/" count=1, Hello, "/" count=3 and Hello, "/" count=5.
I've been running this locally on Windows 10 with Go version go1.9.2 windows/amd64 and the latest Google Chrome Browser.
However, I detected the issue in a simple web application on a remote Linux server where the code has been compiled with go version go1.9.1 linux/amd64.
i just tried it on my pc with Fiddler open
I noticed when navigating to the url using Google Chrome, the browser makes 2 request
GET / HTTP/1.1
GET /favicon.ico HTTP/1.1
the request for the favicon also gets handled by the defaultHandler, which causes the count to increment
I also tried with firefox and it doesn't send another request for the favicon
Try to log requests. Possibly browser is calling /favicon.ico

Get golang http server working with rerun

I'm trying to use rerun to relaunch a go http server when the source files change, but the restart always fails to launch.
Simple server
package main
import (
"net/http"
"fmt"
"log"
"html"
)
func main() {
http.HandleFunc("/hello", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
})
log.Fatal(http.ListenAndServe(":8080", nil))
}
Command line output
$ rerun -p "**/*.{go,html}" go run my_server.go
16:49:24 [rerun] Rerun_test launched
16:49:26 [rerun] Watching . for **/*.{go,html} using Darwin adapter
16:50:17 [rerun] Change detected: 1 modified
16:50:17 [rerun] Sending signal TERM to 75688
16:50:17 [rerun] Rerun_test restarted
2014/07/15 16:50:17 listen tcp :8080: bind: address already in use
exit status 1
16:50:19 [rerun] Rerun_test Launch Failed
How can I get this working, or why can't the server bind to the port when it is relaunched?
Also, I am using OSX 10.9.
A process already running on port 8080 that's why it cannot re-run, go to your activity monitor find the process in your case it may be named as (my_server), and quit it.

Resources