Skip to content

Introducing plugins system #173

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 40 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
6121b9b
Removed useless 'required' tag
cmaglie Jul 4, 2023
d8d03b1
Added fields for plugin system
cmaglie Jul 4, 2023
3c1307a
Made LatestFirmware a method of BoardIndex
cmaglie Jul 4, 2023
d77ecbe
Fixed some linter warnings
cmaglie Jul 4, 2023
dec7b9e
Tools required for plugins are now downloaded
cmaglie Jul 4, 2023
5fe6c36
Created infrastructure for plugin based get-version
cmaglie Jul 4, 2023
da10654
Added FwPlugin object to ease access to fwuploader-plugins
cmaglie Jul 4, 2023
1636708
get-version now supports fwuploader-plugins
cmaglie Jul 4, 2023
38bc5e6
Added license cache
cmaglie Jul 4, 2023
19ec7b7
Better recording of errors from plugins
cmaglie Jul 5, 2023
b8f346a
Extracted function to exec fwuploader plugins
cmaglie Jul 5, 2023
085b9ac
Small cosmetic changes
cmaglie Jul 5, 2023
45b1d58
Another cosmetic change
cmaglie Jul 5, 2023
e0e924a
Prepared scaffolding for flash-firmware command using plugins
cmaglie Jul 5, 2023
23fc8be
Implemented plugin-based firmware upload
cmaglie Jul 5, 2023
3ac9d73
Using packagemanager to handle package_index downloads
cmaglie Jul 6, 2023
78eef25
Added additional index URLx flags to ease plugin development
cmaglie Jul 6, 2023
44a0256
Added missing license data
cmaglie Jul 6, 2023
ccb8eac
Allow file paths as additional 'urls'
cmaglie Jul 6, 2023
802e6f4
Verify signarure only on offical indexes
cmaglie Jul 6, 2023
56e830d
Improve error messages and avoid panic in case of missing tool
cmaglie Jul 6, 2023
aaef115
Avoid double buffering of command output in getFirmwareVersion
cmaglie Jul 7, 2023
29a8d33
Allow merging with overwrite
cmaglie Jul 7, 2023
a3c0204
Added plugin-based firmware index
cmaglie Jul 7, 2023
a921bce
add support for https://github.com/arduino/fwuploader-plugin-helper/p…
umbynos Jul 13, 2023
133ad28
Created scaffolding to implement certificate upload via plugin
cmaglie Jul 7, 2023
a1b45b5
Removed useless variable
cmaglie Jul 7, 2023
62bbbba
Avoid globals arguemnts in flash-certificate
cmaglie Jul 13, 2023
9da4115
Factored function to scrape TLS certs from webserver
cmaglie Jul 13, 2023
10aa952
Factored function to read certificates
cmaglie Jul 13, 2023
dc68681
Small refactoring in cert building subroutines
cmaglie Jul 13, 2023
37cd1e7
Factored function to encode certs as PEM
cmaglie Jul 13, 2023
8f5a4d7
Added certificate flash support for plugins
cmaglie Jul 13, 2023
37eafa4
fix licensed
umbynos Jul 13, 2023
ae313c9
Make board override less strict
cmaglie Jul 13, 2023
9ea4c5e
Do not consider LICENSE files in plugins archive
cmaglie Jul 13, 2023
4a0bed3
Fixed PEM decoding... :facepalm:
cmaglie Jul 13, 2023
f9bcf2f
pass `-v` and `--log-level` to plugin (#175)
umbynos Jul 13, 2023
37a0b46
Update cli/common/common.go
cmaglie Jul 13, 2023
3cc7c51
Renamed variable for clarity
cmaglie Jul 14, 2023
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
43 changes: 43 additions & 0 deletions certificates/certutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ package certificates
import (
"crypto/tls"
"crypto/x509"
"encoding/pem"
"fmt"

"github.com/arduino/go-paths-helper"
"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -53,3 +55,44 @@ func ScrapeRootCertificatesFromURL(URL string) (*x509.Certificate, error) {
rootCertificate := peerCertificates[len(peerCertificates)-1]
return rootCertificate, nil
}

// LoadCertificatesFromFile read certificates from the given file. PEM and CER formats
// are supported.
func LoadCertificatesFromFile(certificateFile *paths.Path) ([]*x509.Certificate, error) {
data, err := certificateFile.ReadFile()
if err != nil {
logrus.Error(err)
return nil, err
}
var res []*x509.Certificate
switch certificateFile.Ext() {
case ".cer":
cert, err := x509.ParseCertificate(data)
if err != nil {
logrus.Error(err)
}
res = append(res, cert)
return res, err

case ".pem":
for {
block, rest := pem.Decode(data)
if block == nil && len(rest) > 0 {
return nil, fmt.Errorf("invalid .pem data")
}
if block == nil {
return res, nil
}
cert, err := x509.ParseCertificate(block.Bytes)
if err != nil {
return nil, fmt.Errorf("failed to parse certificate: %w", err)
}
res = append(res, cert)
if len(rest) == 0 {
return res, nil
}
}
default:
return nil, fmt.Errorf("cert format %s not supported, please use .pem or .cer", certificateFile.Ext())
}
}
31 changes: 5 additions & 26 deletions flasher/nina.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package flasher
import (
"bytes"
"crypto/md5"
"crypto/x509"
"encoding/binary"
"encoding/pem"
"fmt"
Expand Down Expand Up @@ -102,11 +101,14 @@ func (f *NinaFlasher) FlashCertificates(certificatePaths *paths.PathList, URLs [
logrus.Infof("Converting and flashing certificate %s", certPath)
flasherOut.Write([]byte(fmt.Sprintf("Converting and flashing certificate %s\n", certPath)))

data, err := f.certificateFromFile(certPath)
certs, err := certificates.LoadCertificatesFromFile(certPath)
if err != nil {
return err
}
certificatesData = append(certificatesData, data...)
for _, cert := range certs {
data := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: cert.Raw})
certificatesData = append(certificatesData, data...)
}
}

for _, URL := range URLs {
Expand Down Expand Up @@ -141,29 +143,6 @@ func (f *NinaFlasher) FlashCertificates(certificatePaths *paths.PathList, URLs [
return nil
}

func (f *NinaFlasher) certificateFromFile(certificateFile *paths.Path) ([]byte, error) {
data, err := certificateFile.ReadFile()
if err != nil {
logrus.Error(err)
return nil, err
}
switch certificateFile.Ext() {
case ".cer":
// the data needs to be formatted in PEM format
cert, err := x509.ParseCertificate(data)
if err != nil {
logrus.Error(err)
return nil, err
}
return pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: cert.Raw}), nil
case ".pem":
// the data is already encoded in pem format and we do not need to parse it.
return data, nil
default:
return nil, fmt.Errorf("cert format %s not supported, please use .pem or .cer", certificateFile.Ext())
}
}

func (f *NinaFlasher) certificateFromURL(URL string) ([]byte, error) {
rootCertificate, err := certificates.ScrapeRootCertificatesFromURL(URL)
if err != nil {
Expand Down
32 changes: 8 additions & 24 deletions flasher/winc.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,17 @@ func (f *WincFlasher) FlashCertificates(certificatePaths *paths.PathList, URLs [
logrus.Infof("Converting and flashing certificate %s", certPath)
flasherOut.Write([]byte(fmt.Sprintf("Converting and flashing certificate %s\n", certPath)))

data, err := f.certificateFromFile(certPath)
certs, err := certificates.LoadCertificatesFromFile(certPath)
if err != nil {
return err
}
certificatesData = append(certificatesData, data...)
for _, cert := range certs {
data, err := f.getCertificateData(cert)
if err != nil {
return err
}
certificatesData = append(certificatesData, data...)
}
}

for _, URL := range URLs {
Expand All @@ -110,28 +116,6 @@ func (f *WincFlasher) FlashCertificates(certificatePaths *paths.PathList, URLs [
return nil
}

func (f *WincFlasher) certificateFromFile(certificateFile *paths.Path) ([]byte, error) {
data, err := certificateFile.ReadFile()
if err != nil {
logrus.Error(err)
return nil, err
}
switch certificateFile.Ext() {
case ".cer":
cert, err := x509.ParseCertificate(data)
if err != nil {
logrus.Error(err)
return nil, err
}
return f.getCertificateData(cert)
case ".pem":
// the data is already encoded in pem format and we do not need to parse it.
return data, nil
default:
return nil, fmt.Errorf("cert format %s not supported, please use .pem or .cer", certificateFile.Ext())
}
}

func (f *WincFlasher) certificateFromURL(URL string) ([]byte, error) {
rootCertificate, err := certificates.ScrapeRootCertificatesFromURL(URL)
if err != nil {
Expand Down