From 278ce30593c38c49232d89a7891b127420ef1f69 Mon Sep 17 00:00:00 2001 From: DaanSelen Date: Tue, 25 Nov 2025 16:47:06 +0100 Subject: [PATCH] chore: setup workflow --- .gitea/workflows/cross-compile.yaml | 29 ++++++++++++++++++++ generator.go | 29 ++++++++++++++------ integrity.go | 7 ++--- main.go | 35 +++++++++++++++++------- scripts/compile_linux.sh | 2 ++ compile_win.sh => scripts/compile_win.sh | 0 6 files changed, 79 insertions(+), 23 deletions(-) create mode 100644 .gitea/workflows/cross-compile.yaml create mode 100644 scripts/compile_linux.sh rename compile_win.sh => scripts/compile_win.sh (100%) diff --git a/.gitea/workflows/cross-compile.yaml b/.gitea/workflows/cross-compile.yaml new file mode 100644 index 0000000..7d1f44d --- /dev/null +++ b/.gitea/workflows/cross-compile.yaml @@ -0,0 +1,29 @@ +name: Cross-Compile Binaries + +on: + workflow_dispatch: + push: + branches: + - 'main' + tags: + - '*' + +jobs: + cross-compile: + runs-on: ubuntu-latest + strategy: + fail-fast: false + steps: + - name: Checkout and pull the code + uses: actions/checkout@v5 + + - name: Setup the Go programming language + uses: actions/setup-go@v6 + with: + go-version: 'stable' + + - name: Install the Fyne cross-compile package + run: go install github.com/fyne-io/fyne-cross@latest + + - name: checkout + run: ls -l \ No newline at end of file diff --git a/generator.go b/generator.go index 83c88a9..6f80cdb 100644 --- a/generator.go +++ b/generator.go @@ -1,26 +1,37 @@ package main import ( + "crypto/rand" "crypto/x509" - "log" "software.sslmate.com/src/go-pkcs12" ) -func generatePassword(n int) string { - for i := range n { - log.Println(i) +const passChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%&*?" + +func generatePassword(n int) (string, error) { + bytes := make([]byte, n) + _, err := rand.Read(bytes) + if err != nil { + return "", err } - return "DefaultPass" + + for i, b := range bytes { + bytes[i] = passChars[int(b)%len(passChars)] + } + return string(bytes), nil } -func generatePKCS12(pKey any, cert *x509.Certificate, caCerts []*x509.Certificate) (string, []byte) { - pfxPass := generatePassword(50) +func generatePKCS12(pKey any, cert *x509.Certificate, caCerts []*x509.Certificate) (string, []byte, error) { + pfxPass, err := generatePassword(50) + if err != nil { + return "Failed to create password", nil, err + } pfxData, err := pkcs12.Modern.Encode(pKey, cert, caCerts, pfxPass) if err != nil { - return "Failed to create PFX with given data.", nil + return "Failed to create PFX with given data.", nil, err } else { - return "PKCS12 generated seemingly succesfully.", pfxData + return "PKCS generated succesfully, password: " + pfxPass, pfxData, nil } } diff --git a/integrity.go b/integrity.go index a6fd695..737f967 100644 --- a/integrity.go +++ b/integrity.go @@ -5,7 +5,6 @@ import ( "crypto/ed25519" "crypto/rsa" "crypto/x509" - "fmt" "log" ) @@ -13,11 +12,11 @@ func checkPublicKey(cert *x509.Certificate) { switch pub := cert.PublicKey.(type) { case *rsa.PublicKey: - fmt.Println("RSA key:", pub.N.BitLen(), "bits") + log.Println("RSA key:", pub.N.BitLen(), "bits") case *ecdsa.PublicKey: - fmt.Println("ECDSA key:", pub.Curve.Params().Name) + log.Println("ECDSA key:", pub.Curve.Params().Name) case ed25519.PublicKey: - fmt.Println("Ed25519 key") + log.Println("Ed25519 key") default: log.Fatal("Unsupported public key type") } diff --git a/main.go b/main.go index 39f25c0..fe0c1b2 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "crypto/x509" "encoding/pem" + "image/color" "log" "os" certpair "pkcs-generator/modules/certpairs" @@ -10,10 +11,12 @@ import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/app" + "fyne.io/fyne/v2/canvas" "fyne.io/fyne/v2/container" "fyne.io/fyne/v2/dialog" "fyne.io/fyne/v2/layout" "fyne.io/fyne/v2/storage" + "fyne.io/fyne/v2/theme" "fyne.io/fyne/v2/widget" ) @@ -26,6 +29,8 @@ var ( func main() { a := app.NewWithID("nl.systemec.pkcs-generator") + a.Settings().SetTheme(theme.DefaultTheme()) + w := a.NewWindow("Systemec PKCS-Generator") w.Resize(windowSize) @@ -86,9 +91,16 @@ func main() { }) caRadio.SetSelected("New Sectigo (2025+)") // default - // Make a text grid to display text. - grid := widget.NewTextGrid() - grid.SetText("Status will appear here.") + // Multiline entry + textLabl := widget.NewLabel("Status will appear here...") + textLabl.Selectable = true + + border := canvas.NewRectangle(color.Transparent) + border.StrokeColor = color.RGBA{255, 255, 255, 255} + border.StrokeWidth = 2 + border.CornerRadius = 5 + + statusBox := container.NewStack(border, textLabl) actionBtn := widget.NewButton("Generate", func() { files := []string{keyPath, certPath} @@ -110,7 +122,7 @@ func main() { } if !allPresent { - grid.SetText("One or more files missing!") + textLabl.SetText("One or more files missing!") log.Println("One or more files missing!") return } @@ -119,7 +131,7 @@ func main() { if pfxData == nil { log.Println(respText) - grid.SetText(respText) + textLabl.SetText(respText) return } @@ -143,10 +155,9 @@ func main() { writer.Close() - var dnText string = "PKCS file saved to: " + writer.URI().Path() + var dnText string = "PKCS file saved to: " + writer.URI().Path() + "\n" + respText - log.Println(dnText) - grid.SetText(dnText) + textLabl.SetText(dnText) }, w) svDialog.Resize(windowSize) @@ -176,7 +187,7 @@ func main() { widget.NewLabel("\n"), container.New(layout.NewGridLayout(2), radioLabel1, caRadio), layout.NewSpacer(), // optional flexible space - grid, // Add the referenced text grid container + statusBox, // Add the referenced text container widget.NewLabel(""), // Add empty line for space ) @@ -257,5 +268,9 @@ func integrityCheckAndGo(keyPath, certPath, caRootString, caCertString string) ( caCertList := []*x509.Certificate{caCert, rootCert} - return generatePKCS12(key, cert, caCertList) + msg, pfxData, err := generatePKCS12(key, cert, caCertList) + if err != nil { + return msg, nil + } + return msg, pfxData } diff --git a/scripts/compile_linux.sh b/scripts/compile_linux.sh new file mode 100644 index 0000000..2eda2b1 --- /dev/null +++ b/scripts/compile_linux.sh @@ -0,0 +1,2 @@ +#!/bin/bash +go build diff --git a/compile_win.sh b/scripts/compile_win.sh similarity index 100% rename from compile_win.sh rename to scripts/compile_win.sh