yeah so as a temporary measure, i'm using ssh-keygen for now.

but i'll need to natively incorporate it still.
This commit is contained in:
2021-07-03 23:01:58 -04:00
parent d7ffbea913
commit 7f98e7aa15
9 changed files with 323 additions and 19 deletions

View File

@@ -24,14 +24,14 @@ import (
"errors"
"fmt"
"net/http"
`time`
"time"
`github.com/Luzifer/go-dhparam`
"github.com/Luzifer/go-dhparam"
"golang.org/x/crypto/sha3"
)
// NewModuli returns a Moduli populated with Entry items.
func NewModuli(usePreGen ... bool) (m *Moduli, err error) {
func NewModuli(usePreGen ...bool) (m *Moduli, err error) {
var doPreGen bool
@@ -117,13 +117,13 @@ func Generate(m *Moduli) (err error) {
var e Entry
e = Entry{
Time: time.Now(),
Size: bitLen,
Time: time.Now(),
Size: bitLen,
Generator: uint8(generator),
/*
Type: 0,
Tests: 0,
Trials: 0,
Type: 0,
Tests: 0,
Trials: 0,
*/
}
@@ -143,7 +143,7 @@ func Generate(m *Moduli) (err error) {
e.Modulus = *dh.P
// TODO: https://stackoverflow.com/questions/18499352/golang-concurrency-how-to-append-to-the-same-slice-from-different-goroutines
m.Params = append(m.Params, e)
m.Groups = append(m.Groups, e)
}
}

View File

@@ -34,13 +34,12 @@ var reSkipLine, _ = regexp.Compile(`^\s*(#.*)?$`)
// Marshal returns the /etc/ssh/moduli format of m.
// Format of: Time Type Tests Tries Size Generator Modulus
// TODO: remember to write newline at end
func (m *Moduli) Marshal() (bytesOut []byte, err error) {
var b bytes.Buffer
b.Write([]byte(header))
for _, i := range m.Params {
for _, i := range m.Groups {
line, err := i.marshalEntry()
if err != nil {
return nil, err
@@ -49,6 +48,8 @@ func (m *Moduli) Marshal() (bytesOut []byte, err error) {
}
}
b.Write([]byte("\n"))
bytesOut = b.Bytes()
return
@@ -98,7 +99,7 @@ func Unmarshal(data []byte, m *Moduli) (err error) {
entries = append(entries, e)
}
m.Params = entries
m.Groups = entries
return
}
@@ -149,7 +150,7 @@ func (m *Moduli) Harden() (err error) {
var entries []Entry
for _, e := range m.Params {
for _, e := range m.Groups {
e.Time = time.Now()
@@ -157,9 +158,9 @@ func (m *Moduli) Harden() (err error) {
entries = append(entries, e)
}
}
m.Params = entries
m.Groups = entries
if len(m.Params) < recMinMod {
if len(m.Groups) < recMinMod {
err = errors.New("does not meet recommended minimum moduli")
return
}

View File

@@ -23,10 +23,10 @@ import (
"time"
)
// Moduli contains all data needed for generated /etc/ssh/moduli. of ModuliEntry entries.
// Moduli contains all data needed for generated /etc/ssh/moduli of Entry entries.
type Moduli struct {
Header string
Params []Entry
Groups []Entry
}
// Entry is a struct reflecting the format of a single /etc/ssh/moduli entry. See moduli(5) for details.