-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Closed
Labels
FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.Security
Milestone
Description
What version of Go are you using (go version)?
$ go version go version go1.11 linux/amd64 commit has for openpgp eb0de9b17e854e9b1ccd9963efafc79862359959 (Nov 27th , latest as of today, Dec 1st 2018)
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env)?
go env Output
$ go env GOARCH="amd64" GOBIN="" GOCACHE="/home/diego/.cache/go-build" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux" GOPATH="/home/diego/work/golang" GOPROXY="" GORACE="" GOROOT="/usr/local/go" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" GCCGO="gccgo" 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-build336610440=/tmp/go-build -gno-record-gcc-switches"
What did you do?
We use this function to decrypt files we get from different companies, only files from one company fail, all others decrypt fine.
func PGPDecrypt(file io.Reader) ([]byte, error) {
secretKeyring := "/path/to/gpg/secring.gpg"
passphrase := 'pgpPassphrase' // of course not haardoded on prod :)
// init some vars
var entityList openpgp.EntityList
// Open the private key file
keyringFileBuffer, err := os.Open(secretKeyring)
if err != nil {
return nil, errors.New("os.Open(secretKeyring): " + err.Error())
}
defer keyringFileBuffer.Close()
entityList, err = openpgp.ReadKeyRing(keyringFileBuffer)
if err != nil {
return nil, errors.New("openpgp.ReadKeyRing(keyringFileBuffer): " + err.Error())
}
// Get the passphrase and read the private key.
// Have not touched the encrypted string yet
passphraseByte := []byte(passphrase)
// Support a user with multiple private keys
for _, entity := range entityList {
entity.PrivateKey.Decrypt(passphraseByte)
for _, subkey := range entity.Subkeys {
subkey.PrivateKey.Decrypt(passphraseByte)
}
}
md, err := openpgp.ReadMessage(file, entityList, nil, nil)
// =========== this is where I get the error:
// tag byte does not have MSB set
if err != nil {
return nil, errors.New("openpgp.ReadMessage(file, entityList, nil, nil): " + err.Error())
}
ret, err := ioutil.ReadAll(md.UnverifiedBody)
if err != nil {
return nil, errors.New("ioutil.ReadAll(md.UnverifiedBody): " + err.Error())
}
return ret, nil
}
What did you expect to see?
No error and a decrypted zip file, which is what the command line gpg does
What did you see instead?
the error:
tag byte does not have MSB set
More details.
I brought this up on the mailing list
https://groups.google.com/d/topic/golang-nuts/-bBXt-0nVT4/discussion
but I'll paste more details here:
Part of the verbose output from gpg when it decrypts it is:
gpg --decrypt-files -vvv xyz.zip.pgp
gpg: using character set `utf-8'
gpg: armor: BEGIN PGP MESSAGE
gpg: armor header: Version: EldoS PGPBlackbox (.NET edition)
:pubkey enc packet: version 3, algo 1, keyid AFF537579B90F252
data: [4095 bits]
....
gpg: public key encrypted data: good DEK
:pubkey enc packet: version 3, algo 1, keyid <removed from paste>
data: [4095 bits]
gpg: public key is <removed from paste>
:encrypted data packet:
length: unknown
mdc_method: 2
....
:literal data packet:
mode b (62), created 1542720445, name="xyz.zip",
raw data: unknown length
gpg: original file name='xyz.zip'
gpg: decryption okay
nwoodmsft and rajatgoyal715
Metadata
Metadata
Assignees
Labels
FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.Security