upgrade deps; rewrite smtp session

This commit is contained in:
Aine
2024-02-19 22:55:14 +02:00
parent 10213cc7d7
commit a01720da00
277 changed files with 106832 additions and 7641 deletions

View File

@@ -3,6 +3,7 @@
Secrets generator, supported types:
* Passwords
* Random bytes
* ED25519 SSH keypairs
Simple go environment variables reader, for env-based configs
@@ -10,6 +11,8 @@ Simple go environment variables reader, for env-based configs
```go
// password
securePassword := secgen.Password(64)
// base64-encode random bytes (openssl rand -base64 replacement)
randomBytes := secgen.Base64Bytes(64)
// ssh key
publicSSHkey, privateSSHkey, err := secgen.Keypair()

22
vendor/gitlab.com/etke.cc/go/secgen/justfile generated vendored Normal file
View File

@@ -0,0 +1,22 @@
# show help by default
default:
@just --list --justfile {{ justfile() }}
# update go deps
update *flags:
go get {{flags}} .
go mod tidy
# run linter
lint:
golangci-lint run ./...
# automatically fix liter issues
lintfix:
golangci-lint run --fix ./...
# run unit tests
test:
@go test -cover -coverprofile=cover.out -coverpkg=./... -covermode=set ./...
@go tool cover -func=cover.out
-@rm -f cover.out

View File

@@ -2,6 +2,7 @@ package secgen
import (
"crypto/rand"
"encoding/base64"
"math/big"
"strings"
)
@@ -20,3 +21,10 @@ func Password(length int) string {
return password.String()
}
// Base64Bytes generates secure bytes with the given length and returns it as a base64 string
func Base64Bytes(length int) string {
randomBytes := make([]byte, length)
rand.Read(randomBytes) //nolint:errcheck // nothing could be done anyway
return base64.StdEncoding.EncodeToString(randomBytes)
}

View File

@@ -9,7 +9,7 @@ import (
// based on W3C email regex, ref: https://www.w3.org/TR/2016/REC-html51-20161101/sec-forms.html#email-state-typeemail
var domainRegex = regexp.MustCompile(`^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9]$`)
var privateSuffix = []string{".etke.host"}
var privateSuffix = []string{".etke.host", ".onmatrix.chat"}
// Domain checks if domain is valid
func (v *V) Domain(domain string) bool {