diff --git a/attest/attest.go b/attest/attest.go index 80014e89..0f9857b2 100644 --- a/attest/attest.go +++ b/attest/attest.go @@ -7,6 +7,7 @@ import ( "time" "github.com/fxamacker/cbor/v2" + log "github.com/sirupsen/logrus" "github.com/veraison/go-cose" ) @@ -91,27 +92,38 @@ func verifyCertChain(cert *x509.Certificate, cabundle [][]byte) error { } func Attest(attestation []byte) (*AttestationDoc, error) { + log.Debugf("\n* Verifying Attestation Document") + log.Debugf("\t* Creating sign1 from attestation bytes") msg, err := createSign1(attestation) if err != nil { return nil, err } doc := &AttestationDoc{} + log.Debugf("\t* Unmarshalling cbor document") err = cbor.Unmarshal(msg.Payload, doc) if err != nil { + log.Errorf("Error unmarshalling cbor document: %v", err) return nil, err } + log.Debugf("\t* Generated attestation document") + log.Debugf("\t* Parsing x509 certificates") cert, err := x509.ParseCertificate(doc.Certificate) if err != nil { return nil, err } + log.Debugf("\t* Verifying signature") if err := verifySignature(cert, msg); err != nil { + log.Errorf("Error verifying signature: %v", err) return nil, err } + log.Debugf("\t* Verifying certificate chain (Country: %s, Organization: %s, Locality: %s, Province: %s, Common Name: %s)", + cert.Issuer.Country, cert.Issuer.Organization, cert.Issuer.Locality, cert.Issuer.Province, cert.Issuer.CommonName) if err := verifyCertChain(cert, doc.Cabundle); err != nil { + log.Errorf("Error verifying certificate chain: %v", err) return nil, err } diff --git a/capetest/capetest.go b/capetest/capetest.go index e5371b83..1505e45c 100644 --- a/capetest/capetest.go +++ b/capetest/capetest.go @@ -6,9 +6,8 @@ import ( "fmt" "net/http" - log "github.com/sirupsen/logrus" - "github.com/gorilla/websocket" + log "github.com/sirupsen/logrus" "github.com/capeprivacy/cli/attest" "github.com/capeprivacy/cli/crypto" @@ -48,7 +47,19 @@ func websocketDial(url string, insecure bool) (*websocket.Conn, *http.Response, } } - return websocket.DefaultDialer.Dial(url, nil) + str := fmt.Sprintf("* Dialing %s", url) + if insecure { + str += " (insecure)" + } + + log.Debug(str) + c, r, err := websocket.DefaultDialer.Dial(url, nil) + if err != nil { + return nil, nil, err + } + + log.Debugf("* Websocket connection established") + return c, r, nil } func CapeTest(testReq TestRequest, endpoint string, insecure bool) (*RunResults, error) { @@ -77,6 +88,7 @@ func CapeTest(testReq TestRequest, endpoint string, insecure bool) (*RunResults, AuthToken: testReq.AuthToken, Nonce: nonce, } + log.Debug("> Start Request") if err := conn.WriteJSON(startReq); err != nil { return nil, err } @@ -86,6 +98,7 @@ func CapeTest(testReq TestRequest, endpoint string, insecure bool) (*RunResults, return nil, err } + log.Debug("< Attestation document") doc, err := runAttestation(attestation.Message) if err != nil { return nil, err @@ -101,10 +114,12 @@ func CapeTest(testReq TestRequest, endpoint string, insecure bool) (*RunResults, return nil, err } + log.Debug("> Encrypted function") if err := conn.WriteMessage(websocket.BinaryMessage, encFn); err != nil { return nil, err } + log.Debug("> Encrypted input") if err := conn.WriteMessage(websocket.BinaryMessage, encInput); err != nil { return nil, err } @@ -113,6 +128,7 @@ func CapeTest(testReq TestRequest, endpoint string, insecure bool) (*RunResults, if err := conn.ReadJSON(&res); err != nil { return nil, err } + log.Debug("< Test Response", res) return &res, nil } diff --git a/cmd/cape/cmd/deploy.go b/cmd/cape/cmd/deploy.go index a5606749..f949e50b 100644 --- a/cmd/cape/cmd/deploy.go +++ b/cmd/cape/cmd/deploy.go @@ -9,12 +9,8 @@ import ( "io" "net/http" "os" - "os/signal" "path/filepath" - "syscall" - "time" - "github.com/briandowns/spinner" "github.com/gorilla/websocket" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" @@ -89,7 +85,7 @@ func deploy(cmd *cobra.Command, args []string) error { return err } - fmt.Printf("Success! Deployed function to Cape\nFunction ID ➜ %s\n", dID) + log.Infof("Success! Deployed function to Cape\nFunction ID ➜ %s\n", dID) return nil } @@ -164,18 +160,8 @@ func Deploy(url string, functionInput string, functionName string, insecure bool func doDeploy(url string, name string, reader io.Reader, insecure bool) (string, error) { endpoint := fmt.Sprintf("%s/v1/deploy", url) - s := spinner.New(spinner.CharSets[26], 300*time.Millisecond) - defer s.Stop() - - c := make(chan os.Signal, 1) - signal.Notify(c, os.Interrupt, syscall.SIGTERM) - go func() { - <-c - s.Stop() - os.Exit(1) - }() - s.Prefix = "Deploying function to Cape " - s.Start() + + log.Info("Deploying function to Cape ...") conn, res, err := websocketDial(endpoint, insecure) if err != nil { @@ -204,12 +190,15 @@ func doDeploy(url string, name string, reader io.Reader, insecure bool) (string, } req := DeployRequest{Nonce: nonce, AuthToken: token} + log.Debug("\n> Sending Nonce and Auth Token") err = conn.WriteJSON(req) if err != nil { log.Error("error writing deploy request") return "", err } + log.Debug("* Waiting for attestation document...") + var msg Message err = conn.ReadJSON(&msg) if err != nil { @@ -217,6 +206,7 @@ func doDeploy(url string, name string, reader io.Reader, insecure bool) (string, return "", err } + log.Debug("< Attestation document") doc, err := attest.Attest(msg.Message) if err != nil { log.Error("error attesting") @@ -235,15 +225,19 @@ func doDeploy(url string, name string, reader io.Reader, insecure bool) (string, return "", err } + log.Debug("\n> Deploying Encrypted Function") err = writeFunction(conn, bytes.NewBuffer(ciphertext)) if err != nil { return "", err } + log.Debug("* Waiting for deploy response...") + resData := DeployResponse{} if err := conn.ReadJSON(&resData); err != nil { return "", err } + log.Debugf("< Received Deploy Response %v", resData) return resData.ID, nil } @@ -255,13 +249,25 @@ func websocketDial(url string, insecure bool) (*websocket.Conn, *http.Response, } } - return websocket.DefaultDialer.Dial(url, nil) + str := fmt.Sprintf("* Dialing %s", url) + if insecure { + str += " (insecure)" + } + + log.Debug(str) + c, r, err := websocket.DefaultDialer.Dial(url, nil) + if err != nil { + return nil, nil, err + } + + log.Debugf("* Websocket connection established") + return c, r, nil } func writeFunction(conn *websocket.Conn, reader io.Reader) error { writer, err := conn.NextWriter(websocket.BinaryMessage) if err != nil { - log.Println("error getting writer for function") + log.Errorf("error getting writer for function: %v", err) return err } defer writer.Close() @@ -284,5 +290,8 @@ func getAuthToken() (string, error) { if t == "" { return "", fmt.Errorf("empty access token (did you run 'cape login'?): %v", err) } + + log.Debug("* Retrieved Auth Token") + return t, nil } diff --git a/cmd/cape/cmd/root.go b/cmd/cape/cmd/root.go index f26953d1..af26ebee 100644 --- a/cmd/cape/cmd/root.go +++ b/cmd/cape/cmd/root.go @@ -15,14 +15,33 @@ import ( var C config.Config var version = "unknown" - var cfgFile string +type PlainFormatter struct { +} + +func (f *PlainFormatter) Format(entry *log.Entry) ([]byte, error) { + return []byte(fmt.Sprintf("%s\n", entry.Message)), nil +} + // rootCmd represents the base command when called without any subcommands var rootCmd = &cobra.Command{ Use: "cape", Short: "Cape command", Long: `Cape commandline tool`, + PersistentPreRunE: func(cmd *cobra.Command, args []string) error { + log.SetFormatter(&PlainFormatter{}) + v, err := cmd.Flags().GetBool("verbose") + if err != nil { + return err + } + + if v { + log.SetLevel(log.DebugLevel) + } + + return nil + }, } // ExecuteCLI adds all child commands to the root command and sets flags appropriately. @@ -37,6 +56,8 @@ func init() { rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.config/capeprivacy/cape.yaml)") rootCmd.PersistentFlags().StringP("url", "u", "https://newdemo.capeprivacy.com", "Cape Cloud URL") rootCmd.PersistentFlags().Bool("insecure", false, "!!! For development only !!! Disable TLS certificate verification.") + rootCmd.PersistentFlags().BoolP("verbose", "v", false, "verbose output") + if err := rootCmd.PersistentFlags().MarkHidden("insecure"); err != nil { log.Error("flag not found") cobra.CheckErr(err) diff --git a/cmd/cape/cmd/run.go b/cmd/cape/cmd/run.go index f27713fb..cbb493ef 100644 --- a/cmd/cape/cmd/run.go +++ b/cmd/cape/cmd/run.go @@ -6,9 +6,9 @@ import ( "fmt" "io" "io/ioutil" - "os" "github.com/gorilla/websocket" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" @@ -105,7 +105,7 @@ func run(cmd *cobra.Command, args []string) error { return fmt.Errorf("error processing data: %w", err) } - fmt.Fprintf(os.Stderr, "Success! Results from your function:\n") + log.Infof("Success! Results from your function:\n") fmt.Println(string(results)) return nil } @@ -139,12 +139,14 @@ func doRun(url string, functionID string, data []byte, insecure bool) ([]byte, e } req := RunRequest{Nonce: nonce, AuthToken: token} + log.Debug("\n> Sending Nonce and Auth Token") err = c.WriteJSON(req) if err != nil { - log.Println("error writing deploy request") - return nil, err + return nil, errors.Wrap(err, "error writing run request") } + log.Debug("* Waiting for attestation document...") + var msg Message err = c.ReadJSON(&msg) if err != nil { @@ -152,6 +154,7 @@ func doRun(url string, functionID string, data []byte, insecure bool) ([]byte, e return nil, err } + log.Debug("< Auth Completed. Received Attestation Document") doc, err := attest.Attest(msg.Message) if err != nil { log.Println("error attesting") @@ -164,16 +167,20 @@ func doRun(url string, functionID string, data []byte, insecure bool) ([]byte, e return nil, err } + log.Debug("\n> Sending Encrypted Inputs") err = writeData(c, encryptedData) if err != nil { return nil, err } + log.Debug("* Waiting for function results...") + resData := &RunResponse{} err = c.ReadJSON(&resData) if err != nil { return nil, err } + log.Debugf("< Received Function Results.") return resData.Message, nil } diff --git a/cmd/cape/cmd/test.go b/cmd/cape/cmd/test.go index c582c493..ff7ac466 100644 --- a/cmd/cape/cmd/test.go +++ b/cmd/cape/cmd/test.go @@ -8,6 +8,8 @@ import ( "github.com/spf13/cobra" + log "github.com/sirupsen/logrus" + "github.com/capeprivacy/cli/capetest" czip "github.com/capeprivacy/cli/zip" ) @@ -90,6 +92,7 @@ func Test(cmd *cobra.Command, args []string) error { return err } + log.Info() return nil } diff --git a/crypto/enclave_encrypt.go b/crypto/enclave_encrypt.go index c8672c87..58eb0e00 100644 --- a/crypto/enclave_encrypt.go +++ b/crypto/enclave_encrypt.go @@ -5,35 +5,86 @@ import ( "fmt" "github.com/cloudflare/circl/hpke" + log "github.com/sirupsen/logrus" "github.com/capeprivacy/cli/attest" ) +const ( + kemID = hpke.KEM_X25519_HKDF_SHA256 + kdfID = hpke.KDF_HKDF_SHA256 + aeadID = hpke.AEAD_ChaCha20Poly1305 +) + +func LogHPKE() { + log.Debugf("\t** Key Encapsulation Mechanism (KEM): ") + switch kemID { + case hpke.KEM_X25519_HKDF_SHA256: + log.Debugf("\t*** X25519 Diffie-Hellman function") + case hpke.KEM_P256_HKDF_SHA256: + case hpke.KEM_P384_HKDF_SHA384: + case hpke.KEM_P521_HKDF_SHA512: + case hpke.KEM_X448_HKDF_SHA512: + default: + log.Debugf("\t*** Unknown") + } + + log.Debugf("\t** Key Derivation Function (KDF): ") + switch kdfID { + case hpke.KDF_HKDF_SHA256: + log.Debugf("\t*** HMAC-based key derivation function (HKDF) with SHA-256") + case hpke.KDF_HKDF_SHA384: + case hpke.KDF_HKDF_SHA512: + default: + log.Debugf("\t*** Unknown") + } + + log.Debugf("\t** Authenticated Encryption with Additional Data (AEAD): ") + switch aeadID { + case hpke.AEAD_ChaCha20Poly1305: + log.Debugf("\t*** ChaCha20 stream cipher and Poly1305 MAC") + case hpke.AEAD_AES128GCM: + case hpke.AEAD_AES256GCM: + default: + log.Debugf("\t*** Unknown") + } +} + func LocalEncrypt(doc attest.AttestationDoc, plaintext []byte) ([]byte, error) { - kemID := hpke.KEM_X25519_HKDF_SHA256 - kdfID := hpke.KDF_HKDF_SHA256 - aeadID := hpke.AEAD_ChaCha20Poly1305 + log.Debug("\n* Encrypting Inputs") + log.Debugf("\t* Loading Public Key from Attestation Document") + publicKey := doc.PublicKey + log.Debugf("\t** Retrieved Public Key: %s", publicKey) + + log.Debugf("\t* Configuring Hybrid Public Key Encryption (HPKE): ") suite := hpke.NewSuite(kemID, kdfID, aeadID) + LogHPKE() - kemPublicKey, err := kemID.Scheme().UnmarshalBinaryPublicKey(doc.PublicKey) + kemPublicKey, err := kemID.Scheme().UnmarshalBinaryPublicKey(publicKey) if err != nil { fmt.Println(err) } sender, err := suite.NewSender(kemPublicKey, nil) + if err != nil { return nil, fmt.Errorf("unable to encrypt %s", err) } + log.Debugf("\t* Generating Encapsulated Key") + log.Debugf("\t** Generating random bytes...") encapsulatedKey, sealer, err := sender.Setup(rand.Reader) if err != nil { return nil, fmt.Errorf("unable to encrypt %s", err) } + log.Debugf("\t** Encapsulated Key: %s", encapsulatedKey) + log.Debugf("\t* Generating Ciphertext") ciphertext, err := sealer.Seal(plaintext, nil) if err != nil { return nil, fmt.Errorf("unable to encrypt %s", err) } + log.Debugf("\t** Complete.") return append(encapsulatedKey, ciphertext...), nil } diff --git a/crypto/nonce.go b/crypto/nonce.go index 2169ced4..f0e9bbe8 100644 --- a/crypto/nonce.go +++ b/crypto/nonce.go @@ -4,6 +4,8 @@ import ( "crypto/rand" "encoding/base64" "fmt" + + log "github.com/sirupsen/logrus" ) func GetNonce() (string, error) { @@ -13,5 +15,7 @@ func GetNonce() (string, error) { return "", fmt.Errorf("failed to get nonce: %v", err) } - return base64.StdEncoding.EncodeToString(buf), nil + nonce := base64.StdEncoding.EncodeToString(buf) + log.Debugf("* Generated Nonce: %s", nonce) + return nonce, nil } diff --git a/go.mod b/go.mod index 32f75fc3..6b0d7dcd 100644 --- a/go.mod +++ b/go.mod @@ -4,25 +4,22 @@ go 1.18 require ( github.com/avast/retry-go v3.0.0+incompatible - github.com/briandowns/spinner v1.18.1 github.com/capeprivacy/go-kit v0.0.0-20220420152147-667383169b7a github.com/cloudflare/circl v1.2.0 github.com/fxamacker/cbor/v2 v2.4.0 github.com/google/tink/go v1.6.1 github.com/jedib0t/go-pretty/v6 v6.3.1 + github.com/pkg/errors v0.9.1 github.com/spf13/cobra v1.4.0 ) require ( - github.com/fatih/color v1.13.0 // indirect github.com/fsnotify/fsnotify v1.5.1 // indirect github.com/golang/protobuf v1.5.2 // indirect github.com/google/uuid v1.3.0 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/kr/text v0.2.0 // indirect github.com/magiconair/properties v1.8.6 // indirect - github.com/mattn/go-colorable v0.1.12 // indirect - github.com/mattn/go-isatty v0.0.14 // indirect github.com/mattn/go-runewidth v0.0.13 // indirect github.com/mitchellh/mapstructure v1.4.3 // indirect github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect diff --git a/go.sum b/go.sum index 85bd462d..5d3b793d 100644 --- a/go.sum +++ b/go.sum @@ -44,8 +44,6 @@ github.com/avast/retry-go v3.0.0+incompatible h1:4SOWQ7Qs+oroOTQOYnAHqelpCO0biHS github.com/avast/retry-go v3.0.0+incompatible/go.mod h1:XtSnn+n/sHqQIpZ10K1qAevBhOOCWBLXXy3hyiqqBrY= github.com/aws/aws-sdk-go v1.36.29/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= -github.com/briandowns/spinner v1.18.1 h1:yhQmQtM1zsqFsouh09Bk/jCjd50pC3EOGsh28gLVvwY= -github.com/briandowns/spinner v1.18.1/go.mod h1:mQak9GHqbspjC/5iUx3qMlIho8xBS/ppAL/hX5SmPJU= github.com/bwesterb/go-ristretto v1.2.1/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= github.com/capeprivacy/go-kit v0.0.0-20220420152147-667383169b7a h1:d0C9zbqj8swi59Ggj/G2bpKtSKLan7aU385bl4OEQYQ= github.com/capeprivacy/go-kit v0.0.0-20220420152147-667383169b7a/go.mod h1:OptX4dMqL/8r+LhanI9Eoif5Tf6sQPqiIcpx955QhTo= @@ -71,8 +69,6 @@ github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5y github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= -github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= -github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= github.com/fsnotify/fsnotify v1.5.1 h1:mZcQUHVQUQWoPXXtuf9yuEXKudkV2sx1E06UadKWpgI= github.com/fsnotify/fsnotify v1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5Ai1i3InKU= @@ -193,15 +189,7 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo= github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= -github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= -github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= -github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40= -github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= -github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= -github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= -github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= @@ -223,6 +211,7 @@ github.com/pelletier/go-toml v1.9.4/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCko github.com/pelletier/go-toml/v2 v2.0.0-beta.8 h1:dy81yyLYJDwMTifq24Oi/IslOslRrDSb3jwDggjz3Z0= github.com/pelletier/go-toml/v2 v2.0.0-beta.8/go.mod h1:r9LEWfGN8R5k0VXJ+0BkIe7MYkRdwZOjgMj2KwnJFUo= github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/profile v1.6.0/go.mod h1:qBsxPvzyUincmltOk6iyRVxHYg4adc0OFOv72ZdLa18= github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg= @@ -376,7 +365,6 @@ golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190129075346-302c3dd5f1cc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -390,7 +378,6 @@ golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -414,7 +401,6 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220315194320-039c03cc5b86/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220412211240-33da011f77ad h1:ntjMns5wyP/fN65tdBD4g8J5w8n015+iIIs9rtjXkY0= golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/progress/progress.go b/progress/progress.go deleted file mode 100644 index f2946bb2..00000000 --- a/progress/progress.go +++ /dev/null @@ -1,19 +0,0 @@ -package progress - -import "io" - -type Reader struct { - io.Reader - Size int64 - Reporter func(progress float64) - - b int64 -} - -func (pr *Reader) Read(p []byte) (n int, err error) { - n, err = pr.Reader.Read(p) - pr.b += int64(n) - progress := float64(pr.b) / float64(pr.Size) - pr.Reporter(progress) - return -} diff --git a/progress/progress_test.go b/progress/progress_test.go deleted file mode 100644 index 05cf2e23..00000000 --- a/progress/progress_test.go +++ /dev/null @@ -1,56 +0,0 @@ -package progress - -import ( - "net/http" - "net/http/httptest" - "os" - "testing" -) - -func TestProgress(t *testing.T) { - s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - // force everything to be read to fill progress - buf := make([]byte, 1024) - for { - _, err := r.Body.Read(buf) - if err != nil { - if err.Error() == "EOF" { - break - } - } - } - - w.WriteHeader(http.StatusCreated) - })) - defer s.Close() - - f, err := os.Open("./testdata/isprime.zip") - if err != nil { - t.Error(err) - } - - fi, err := f.Stat() - if err != nil { - t.Error(err) - } - - size := fi.Size() - - var progress float64 - pr := &Reader{Reader: f, Size: size, Reporter: func(p float64) { - if p < progress { - t.Errorf("progress should increase towards 1, got %f, previous: %f", p, progress) - } - - progress = p - }} - - _, err = http.Post(s.URL, "application/zip", pr) - if err != nil { - t.Error(err) - } - - if progress != 1 { - t.Errorf("progress didn't end up at 1: %f", progress) - } -} diff --git a/progress/testdata/isprime.zip b/progress/testdata/isprime.zip deleted file mode 100644 index 4c04eedc..00000000 Binary files a/progress/testdata/isprime.zip and /dev/null differ