Skip to content

x/crypto/openpgp: compression options are not used in Encrypt function #41213

@bytegaurav

Description

@bytegaurav

installed Golang version and architecture details :

$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/Gaurav.k/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/Gaurav.k/Projects/GoProjects/"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.12.4/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.12.4/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/4_/703g62812t39dfmzfx4l7w3r0000gp/T/go-build267975514=/tmp/go-build -gno-record-gcc-switches -fno-common"
$ go version
go version go1.12.4 darwin/amd64

What did you do?

I'm trying to replicate following gpg command with crypto/openpgp package.

gpg --armor --output <outputfile > --cipher aes256 --compress-algo zip --s2k-digest-algo SHA256 --encrypt --recipient <userkey> --sign -u <privatekeyid>  <inputfile>

I'm using crypto/openpgp package to encrypt message with a public key and sign it with my private key. I'm using the openpgp.Encrypt method and passed following config as parameter:

packetConfig := &packet.Config{
		DefaultCipher:          packet.CipherAES256,
		DefaultCompressionAlgo: packet.CompressionZIP,
		CompressionConfig: &packet.CompressionConfig{
			Level: flate.BestCompression,
		},
	}

What did you expect to see?

I'm expected to see my plain text input message to be PGP encrypted and must have ZIP compression.

What did you see instead?

Message I get from openpgp.Encrypt method, is properly signed and encrypted but not compressed.

Resolution

Upon inspecting the Encrypt function and debugging the code, found out that it's not making use of compression config passed as argument anywhere in the flow. Made a change in write.go and added compression. After this change, the messages are properly encrypted and compressed.

A PR is already raised in golang/crypto repository. golang/crypto#103. This PR and debug info is from last year when i raised it in crypto repo. Posting it here due to inactivity there.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions