cmd/age: grease the client-controlled plugin phases

This commit is contained in:
Filippo Valsorda
2023-08-05 14:55:16 +02:00
parent 004b544d83
commit dd733c5c0f
2 changed files with 11 additions and 0 deletions

View File

@@ -36,6 +36,8 @@ func TestMain(m *testing.M) {
scanner := bufio.NewScanner(os.Stdin)
scanner.Scan() // add-recipient
scanner.Scan() // body
scanner.Scan() // grease
scanner.Scan() // body
scanner.Scan() // wrap-file-key
scanner.Scan() // body
fileKey := scanner.Text()
@@ -51,6 +53,8 @@ func TestMain(m *testing.M) {
scanner := bufio.NewScanner(os.Stdin)
scanner.Scan() // add-identity
scanner.Scan() // body
scanner.Scan() // grease
scanner.Scan() // body
scanner.Scan() // recipient-stanza
scanner.Scan() // body
fileKey := scanner.Text()

View File

@@ -12,6 +12,7 @@ import (
"bytes"
"fmt"
"io"
"math/rand"
"os"
"strconv"
"time"
@@ -71,6 +72,9 @@ func (r *Recipient) Wrap(fileKey []byte) (stanzas []*age.Stanza, err error) {
if err := writeStanza(conn, addType, r.encoding); err != nil {
return nil, err
}
if err := writeStanza(conn, fmt.Sprintf("grease-%x", rand.Int())); err != nil {
return nil, err
}
if err := writeStanzaWithBody(conn, "wrap-file-key", fileKey); err != nil {
return nil, err
}
@@ -197,6 +201,9 @@ func (i *Identity) Unwrap(stanzas []*age.Stanza) (fileKey []byte, err error) {
if err := writeStanza(conn, "add-identity", i.encoding); err != nil {
return nil, err
}
if err := writeStanza(conn, fmt.Sprintf("grease-%x", rand.Int())); err != nil {
return nil, err
}
for _, rs := range stanzas {
s := &format.Stanza{
Type: "recipient-stanza",