-
Notifications
You must be signed in to change notification settings - Fork 20k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
crypto: signing builds with signify/minisign #21798
Changes from 14 commits
419369d
20331e9
ea463a2
0028e1d
d875837
9fb07a8
c4fee15
5eb3540
80d45d0
3e1f47c
f035c15
80c928c
951d75c
68f8638
6726a72
76886da
3fe9eb6
dfac93a
b2cf7c6
76db596
f92a450
6fa7fc6
40b8b5f
698af71
b22cdb2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
// Copyright 2020 The go-ethereum Authors | ||
// This file is part of the go-ethereum library. | ||
// | ||
// The go-ethereum library is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// The go-ethereum library is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
// signFile reads the contents of an input file and signs it (in armored format) | ||
// with the key provided, placing the signature into the output file. | ||
|
||
package crypto | ||
|
||
import ( | ||
"encoding/base64" | ||
"errors" | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"strings" | ||
|
||
"crypto/ed25519" | ||
) | ||
|
||
var ( | ||
errInvalidKeyHeader = errors.New("Incorrect key header") | ||
errInvalidKeyLength = errors.New("invalid, key length != 104") | ||
) | ||
|
||
func readSKey(key []byte) (ed25519.PrivateKey, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe you could turn this into |
||
if len(key) != 104 { | ||
return nil, errInvalidKeyLength | ||
} | ||
|
||
if string(key[:2]) != "Ed" { | ||
return nil, errInvalidKeyHeader | ||
} | ||
|
||
return ed25519.PrivateKey(key[40:]), nil | ||
|
||
} | ||
|
||
func isCommentOnlyOneLine(comment string) bool { | ||
firstCRIndex := strings.IndexByte(comment, 13) | ||
firstLFIndex := strings.IndexByte(comment, 10) | ||
return (firstCRIndex >= 0 && firstCRIndex < len(comment)-1) || (firstLFIndex >= 0 && firstLFIndex < len(comment)-1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Afaict, this allows arbitrarily many There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the code is correct, it's the function name that is wrong. It should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The go-minisign verifier does this:
So it totally ignores There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it's not true in Go, but There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On unix-systems, If they allow "lalalal \r lolo \r foo bar\n" then we should do that too There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
this is what I said, and MacOS only uses There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh right, yes, a C program in windows will require There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Agreed
No, you said that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Someone doesn't refresh before posting :D There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yup, I hate that -- sometimes GH just plops in whatever new content there is, and sometimes you have to manually reload pages. Solly |
||
} | ||
|
||
// SignifySignFile creates a signature of the input file. | ||
func SignifySignFile(input string, output string, key string, unTrustedComment string, trustedComment string) error { | ||
in, err := os.Open(input) | ||
if err != nil { | ||
return err | ||
} | ||
defer in.Close() | ||
|
||
out, err := os.Create(output) | ||
if err != nil { | ||
return err | ||
} | ||
defer out.Close() | ||
|
||
keydata, err := base64.StdEncoding.DecodeString(key) | ||
if err != nil { | ||
return err | ||
} | ||
skey, err := readSKey(keydata) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
filedata, err := ioutil.ReadAll(in) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
rawSig := ed25519.Sign(skey, filedata) | ||
header := keydata[:2] | ||
keyNum := keydata[32:40] | ||
|
||
var sigdata []byte | ||
sigdata = append(sigdata, header...) | ||
sigdata = append(sigdata, keyNum...) | ||
sigdata = append(sigdata, rawSig...) | ||
|
||
// Check that the trusted comment fits in one line | ||
if isCommentOnlyOneLine(unTrustedComment) { | ||
return errors.New("untrusted comment must fit on a single line") | ||
} | ||
|
||
out.WriteString(fmt.Sprintf("untrusted comment: %s\n%s\n", unTrustedComment, base64.StdEncoding.EncodeToString(sigdata))) | ||
|
||
// Add the trusted comment if available (minisign only) | ||
if trustedComment != "" { | ||
// Check that the trusted comment fits in one line | ||
if isCommentOnlyOneLine(trustedComment) { | ||
return errors.New("trusted comment must fit on a single line") | ||
} | ||
|
||
var sigAndComment []byte | ||
sigAndComment = append(sigAndComment, rawSig...) | ||
sigAndComment = append(sigAndComment, []byte(trustedComment)...) | ||
out.WriteString(fmt.Sprintf("trusted comment: %s\n%s\n", trustedComment, base64.StdEncoding.EncodeToString(ed25519.Sign(skey, sigAndComment)))) | ||
gballet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix those lines up.