ProtonMail/gopenpgp

Issues building

sister-bael opened this issue · 0 comments

When I attempt to build my module which includes gopenpgp, I cannot

Here's my go.mod:

module decrypt-gopher

go 1.17

require (
	github.com/ProtonMail/gopenpgp/v2 v2.0.1
	github.com/aws/aws-lambda-go v1.19.1
	github.com/aws/aws-sdk-go v1.30.7
	github.com/imdario/mergo v0.3.9
)

// go mime indirect manually added per https://github.com/ProtonMail/gopenpgp/issues/30#issuecomment-557079122
require (
	github.com/konsorten/go-windows-terminal-sequences v1.0.1 // indirect
	github.com/pkg/errors v0.9.1 // indirect
	github.com/sirupsen/logrus v1.4.2 // indirect
	github.com/stretchr/testify v1.7.0 // indirect
	golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 // indirect
	golang.org/x/text v0.3.2 // indirect
	github.com/ProtonMail/go-mime v0.0.0-20190923161245-9b5a4261663a // indirect
	github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
	github.com/go-redis/redis/v7 v7.2.0 // indirect
	github.com/google/uuid v1.1.1 // indirect
	github.com/jmespath/go-jmespath v0.3.0 // indirect
	github.com/opentracing/opentracing-go v1.1.0 // indirect
	golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
)

// per https://github.com/ProtonMail/gopenpgp/issues/8#issuecomment-496557881
replace golang.org/x/crypto => github.com/ProtonMail/crypto v0.0.0-20190427044656-efb430e751f2

if I attempt to build my project, I get this error:

env GOOS=linux go build -ldflags="-s -w" -o bin/decrypt-gopher main.go
# github.com/ProtonMail/gopenpgp/v2/crypto
../../go/pkg/mod/github.com/!proton!mail/gopenpgp/v2@v2.0.1/crypto/key.go:187:20: key.entity.SerializePrivateWithoutSigning undefined (type *openpgp.Entity has no field or method SerializePrivateWithoutSigning)
../../go/pkg/mod/github.com/!proton!mail/gopenpgp/v2@v2.0.1/crypto/key.go:233:22: key.entity.EncryptionKey undefined (type *openpgp.Entity has no field or method EncryptionKey)
../../go/pkg/mod/github.com/!proton!mail/gopenpgp/v2@v2.0.1/crypto/key.go:351:9: pk.SerializeForHash undefined (type *packet.PublicKey has no field or method SerializeForHash)
../../go/pkg/mod/github.com/!proton!mail/gopenpgp/v2@v2.0.1/crypto/keyring.go:198:17: entity.SerializePrivateWithoutSigning undefined (type *openpgp.Entity has no field or method SerializePrivateWithoutSigning)
../../go/pkg/mod/github.com/!proton!mail/gopenpgp/v2@v2.0.1/crypto/keyring_session.go:59:29: e.EncryptionKey undefined (type *openpgp.Entity has no field or method EncryptionKey)
make: *** [Makefile:10: build] Error 1

here's the kinda decontextualized main.go i modded to just build this:

package main

import (
	"context"
	"encoding/json"

	// "encoding/json"

	"fmt"
	"os"
	"strings"

	"github.com/aws/aws-lambda-go/events"

	"github.com/ProtonMail/gopenpgp/v2/helper"
	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/aws/session"
	"github.com/aws/aws-sdk-go/service/s3"
	"github.com/aws/aws-sdk-go/service/s3/s3manager"
)

func init() {
}

func handler(ctx context.Context, sqsEvent events.SQSEvent) {
	privateKey := (os.Getenv("PRIVATE_KEY"))
	passphrase := []byte(os.Getenv("PASSPHRASE"))
	//s3Dest := os.Getenv("S3_DEST")

	message := ""
	error := false

	if privateKey == "" {
		message += "PRIVATE_KEY env var does not exist"
		error = true
	}
	if passphrase == "" {
		message += "PASSPHRASE env var does not exist"
		error = true
	}
	if error {
		panic(message)
	}
	armor := ""
	decrypted, _ := helper.DecryptMessageArmored(privateKey, passphrase, armor)
	fmt.Println(decrypted)
	sess, _ := session.NewSession(&aws.Config{
		Region: aws.String("us-west-2")},
	)

	downloader := s3manager.NewDownloader(sess)

	for _, sqsRecord := range sqsEvent.Records {
		s3Event := &events.S3Event{}
		err := json.Unmarshal([]byte(sqsRecord.Body), s3Event)
		panic(err)
	}

	for _, record := range s3Event.Records {
		s3RecordMetadata := record.S3

		splitKey := strings.Split(s3RecordMetadata.Object.Key, "/")
		fmt.Println(splitKey)
		file := splitKey[len(splitKey)-1]

		destinationFile, err := client.Create(file)
		if err != nil {
			panic(err)
		}
		defer destinationFile.Close()

		_, err = downloader.Download(destinationFile,
			&s3.GetObjectInput{
				Bucket: aws.String(s3RecordMetadata.Bucket.Name),
				Key:    aws.String(s3RecordMetadata.Object.Key),
			})
		if err != nil {
			panic(err)
		}

	}
}