Skip to content
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

x/crypto/openpgp: Encrypt not compressed the payload even config already have compression enabled #46992

Closed
mustafalim opened this issue Jun 30, 2021 · 3 comments

Comments

@mustafalim
Copy link

mustafalim commented Jun 30, 2021

What version of Go are you using (go version)?

1.16.5

Does this issue reproduce with the latest release?

Not sure

What operating system and processor architecture are you using (go env)?

go env Output
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/mustafa/.cache/go-build"
GOENV="/home/mustafa/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/mustafa/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/mustafa/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16.5"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3209265659=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I want to encrypt and sign messages using Encrypt method with compression enabled

encryptedTextBuffer := new(bytes.Buffer)
encryptor, err := openpgp.Encrypt(encryptedTextBuffer, publicKeyRing, privateKeyRing[0], nil, &packet.Config{
	DefaultCipher:          packet.CipherAES256,
	DefaultHash:            crypto.SHA256,
	DefaultCompressionAlgo: packet.CompressionZIP,
	CompressionConfig:      &packet.CompressionConfig{Level: 9},
})
if err != nil {
        return "", err
}

But the PGP message is not compressed, I found that Encrypt method don't have compression in place

func Encrypt(ciphertext io.Writer, to []*Entity, signed *Entity, hints *FileHints, config *packet.Config) (plaintext io.WriteCloser, err error) {
	...

	payload, err := packet.SerializeSymmetricallyEncrypted(ciphertext, cipher, symKey, config)
	if err != nil {
		return
	}

	literaldata := payload
	if algo := config.Compression(); algo != packet.CompressionNone {
		var compConfig *packet.CompressionConfig
		if config != nil {
			compConfig = config.CompressionConfig
		}
		literaldata, err = packet.SerializeCompressed(payload, algo, compConfig)
		if err != nil {
			return
		}
	}

	return writeAndSign(literaldata, candidateHashes, signed, hints, config)
}

I think need to add compression before calling writeAndSign method, can I make a pull request to fix this problem?

What did you expect to see?

Compressed encrypted and signed PGP message

What did you see instead?

Encrypted and signed but not compressed PGP message

@gopherbot gopherbot added this to the Unreleased milestone Jun 30, 2021
@tmthrgd
Copy link
Contributor

tmthrgd commented Jun 30, 2021

The x/crypto/openpgp package is frozen and deprecated as per #44226. This is also a duplicate of #41213.

@mustafalim
Copy link
Author

Hi, sorry for the duplication, but if it's already frozen can I fork this openpgp package and modify the code because I need it for my current urgent project?

@seankhliao
Copy link
Member

Yes, see the last paragraph of the linked issue #44226

Closing as duplicate / frozen

@golang golang locked and limited conversation to collaborators Jun 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants