ci / test (push) Canceled after 0s
ci / cross-build (amd64, darwin) (push) Canceled after 0s
ci / cross-build (amd64, linux) (push) Canceled after 0s
ci / cross-build (amd64, windows) (push) Canceled after 0s
ci / cross-build (arm64, darwin) (push) Canceled after 0s
ci / cross-build (arm64, linux) (push) Canceled after 0s
ci / cross-build (arm64, windows) (push) Canceled after 0s
- archive: use Docker's own patternmatcher for .dockerignore/.gitignore/.gyignore + hard secret/VCS/build-output exclusions - crypto: AES-256-CTR encrypt the source archive before upload (key/IV to gateway via HTTPS) - deploy: --max-upload / GY_MAX_UPLOAD (default 500 MB) - Makefile + CI matrix: cross-compile linux/darwin/windows x amd64/arm64 - tests: crypto round-trip + ignore rules
50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
package source
|
|
|
|
import (
|
|
"crypto/aes"
|
|
"crypto/cipher"
|
|
"crypto/rand"
|
|
"encoding/hex"
|
|
"io"
|
|
"os"
|
|
)
|
|
|
|
// EncryptFile encrypts srcPath to dstPath with AES-256-CTR and returns the key
|
|
// and IV as hex. CTR is a stream cipher, so the ciphertext is exactly the same
|
|
// length as the plaintext. The key/IV travel to the gateway over HTTPS and are
|
|
// injected into the ephemeral build container, which decrypts with openssl.
|
|
func EncryptFile(srcPath, dstPath string) (keyHex, ivHex string, err error) {
|
|
src, err := os.Open(srcPath)
|
|
if err != nil {
|
|
return "", "", err
|
|
}
|
|
defer src.Close()
|
|
|
|
dst, err := os.Create(dstPath)
|
|
if err != nil {
|
|
return "", "", err
|
|
}
|
|
defer dst.Close()
|
|
|
|
key := make([]byte, 32)
|
|
iv := make([]byte, 16)
|
|
if _, err := io.ReadFull(rand.Reader, key); err != nil {
|
|
return "", "", err
|
|
}
|
|
if _, err := io.ReadFull(rand.Reader, iv); err != nil {
|
|
return "", "", err
|
|
}
|
|
|
|
block, err := aes.NewCipher(key)
|
|
if err != nil {
|
|
return "", "", err
|
|
}
|
|
stream := cipher.NewCTR(block, iv)
|
|
w := &cipher.StreamWriter{S: stream, W: dst}
|
|
if _, err := io.Copy(w, src); err != nil {
|
|
return "", "", err
|
|
}
|
|
|
|
return hex.EncodeToString(key), hex.EncodeToString(iv), nil
|
|
}
|