Skip to content

Fix wrong scrape of Root Certificates #216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions certificates/certutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ func ScrapeRootCertificatesFromURL(URL string) (*x509.Certificate, error) {
return nil, err
}

peerCertificates := conn.ConnectionState().PeerCertificates
if len(peerCertificates) == 0 {
err = fmt.Errorf("no peer certificates found at %s", URL)
logrus.Error(err)
return nil, err
chains := conn.ConnectionState().VerifiedChains
if len(chains) == 0 {
return nil, fmt.Errorf("no certificates found at %s", URL)
}

rootCertificate := peerCertificates[len(peerCertificates)-1]
return rootCertificate, nil
rootCertificate := chains[len(chains)-1]
if len(rootCertificate) == 0 {
return nil, fmt.Errorf("no certificates found at %s", URL)
}
return rootCertificate[len(rootCertificate)-1], nil
}

// LoadCertificatesFromFile read certificates from the given file. PEM and CER formats
Expand Down
14 changes: 14 additions & 0 deletions certificates/certutils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package certificates_test

import (
"testing"

"github.com/arduino/arduino-fwuploader/certificates"
"github.com/stretchr/testify/require"
)

func TestScrapeRootCertificatesFromURL(t *testing.T) {
cert, err := certificates.ScrapeRootCertificatesFromURL("www.arduino.cc:443")
require.NoError(t, err)
require.Equal(t, cert.Issuer, cert.Subject)
}
7 changes: 2 additions & 5 deletions docs/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,8 @@ Error: reboot mode: upload commands sketch: setting DTR to OFF

#### I flashed the certificates, but I am unable to reach the host

The **whole certificate chain** is needed to make it work. Using
[`-u` flags](commands/arduino-fwuploader_certificates_flash.md#options) (ex: `-u www.arduino.cc:443`) won’t work because
it only downloads the root certificates. The solution is to use only the
[`-f` flag](commands/arduino-fwuploader_certificates_flash.md#options) and provide a pem certificate containing the
whole chain.
There was a bug in the arduino-fwuploader prior `2.4.1` which didn't pick the actual root certificate. Upgrading to the
latest version solves the problem.

#### My antivirus says that `espflash` is a threat

Expand Down