mirror of
https://github.com/gopasspw/gopass.git
synced 2026-02-01 17:37:29 +00:00
Add GOPASS_DISABLE_MIME to disable writing the new native secrets format (#1530)
This change will allow users who need to stay interoperable with other password store implementations (e.g. on Mobiles) to keep using newer gopass releases. Please note that this is a temporary workaround and will eventually go away. RELEASE_NOTES=[ENHANCEMENT] Add GOPASS_DISABLE_MIME to disable new secret format. Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>
This commit is contained in:
parent
15e6d20ffe
commit
dca860e9f8
@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/textproto"
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
@ -81,8 +82,41 @@ func ParseMIME(buf []byte) (*MIME, error) {
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// bytesCompat writes a pass compatible representation
|
||||
// of the secret.
|
||||
func (s *MIME) bytesCompat() []byte {
|
||||
buf := &bytes.Buffer{}
|
||||
fmt.Fprint(buf, s.Header.Get("Password"))
|
||||
fmt.Fprintln(buf)
|
||||
|
||||
keys := make([]string, 0, len(s.Header))
|
||||
for k := range s.Header {
|
||||
if strings.ToLower(k) == "password" {
|
||||
continue
|
||||
}
|
||||
keys = append(keys, k)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
for _, k := range keys {
|
||||
vs := s.Header[k]
|
||||
sort.Strings(vs)
|
||||
for _, v := range vs {
|
||||
fmt.Fprint(buf, k)
|
||||
fmt.Fprint(buf, ": ")
|
||||
fmt.Fprint(buf, v)
|
||||
fmt.Fprint(buf, "\n")
|
||||
}
|
||||
}
|
||||
fmt.Fprint(buf, "\n")
|
||||
buf.Write(s.body.Bytes())
|
||||
return buf.Bytes()
|
||||
}
|
||||
|
||||
// Bytes serializes the secret
|
||||
func (s *MIME) Bytes() []byte {
|
||||
if compat := os.Getenv("GOPASS_DISABLE_MIME"); compat != "" {
|
||||
return s.bytesCompat()
|
||||
}
|
||||
buf := &bytes.Buffer{}
|
||||
fmt.Fprint(buf, Ident)
|
||||
fmt.Fprint(buf, "\n")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user