-
Notifications
You must be signed in to change notification settings - Fork 21
#199 test fix for uploaded files #201
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ import ( | |
| "io" | ||
|
|
||
| "github.com/ProtonMail/go-crypto/openpgp" | ||
| "github.com/ProtonMail/go-crypto/openpgp/armor" | ||
| "github.com/ProtonMail/go-crypto/openpgp/packet" | ||
| "golang.org/x/crypto/pbkdf2" | ||
| ) | ||
|
|
@@ -63,3 +64,32 @@ func (p *Package) Encrypt(unencryptedFilePart io.Reader) (*bytes.Buffer, error) | |
| passphrase := p.Info.ServerSecret + p.Uploader.ClientSecret | ||
| return encrypt([]byte(passphrase), unencryptedFilePart) | ||
| } | ||
|
|
||
| func EncryptKeycode(keyCode string, publicKeyArmored string) (string, error) { | ||
| keyRing, err := openpgp.ReadArmoredKeyRing(bytes.NewBufferString(publicKeyArmored)) | ||
| if err != nil { | ||
| return "", fmt.Errorf("failed to read public key: %w", err) | ||
| } | ||
|
|
||
| var encryptConfig packet.Config | ||
| encryptConfig.DefaultCipher = packet.CipherAES256 | ||
| encryptConfig.DefaultHash = crypto.SHA256 | ||
|
|
||
| buf := new(bytes.Buffer) | ||
| armorWriter, err := armor.Encode(buf, "PGP MESSAGE", nil) | ||
| if err != nil { | ||
| return "", fmt.Errorf("failed to create armor encoder: %w", err) | ||
| } | ||
|
|
||
| w, err := openpgp.Encrypt(armorWriter, keyRing, nil, nil, &encryptConfig) | ||
| if err != nil { | ||
| return "", fmt.Errorf("failed to create PGP encryptor: %w", err) | ||
| } | ||
| if _, err := io.WriteString(w, keyCode); err != nil { | ||
| return "", fmt.Errorf("failed to write keycode: %w", err) | ||
| } | ||
| w.Close() | ||
|
Contributor
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.
|
||
| armorWriter.Close() | ||
|
|
||
| return buf.String(), 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.
Not a blocker: wondering whether a keycode upload failure should be fatal here. If SendSafely has no PGP public keys configured for this package (empty
PublicKeysslice),UploadKeycodesreturnsniland we proceed to finalize. That seems right. But if there are recipients and all keycodes fail, we abort beforeFinalizePackage. Is that the intended behavior, or would it be better to finalize anyway and let the caller decide? I don't know the SendSafely semantics well enough to say.