Просмотр исходного кода

Guard against uploading empty feedbacks

mirokuratczyk 5 лет назад
Родитель
Сommit
534e57e64c
2 измененных файлов с 13 добавлено и 5 удалено
  1. 5 1
      ConsoleClient/main.go
  2. 8 4
      psiphon/feedback.go

+ 5 - 1
ConsoleClient/main.go

@@ -467,7 +467,11 @@ func (f *FeedbackWorker) Run(ctx context.Context) error {
 	// TODO: cancel blocking read when worker context cancelled?
 	// TODO: cancel blocking read when worker context cancelled?
 	diagnostics, err := ioutil.ReadAll(os.Stdin)
 	diagnostics, err := ioutil.ReadAll(os.Stdin)
 	if err != nil {
 	if err != nil {
-		return errors.Trace(err)
+		return errors.TraceMsg(err, "FeedbackUpload: read stdin failed")
+	}
+
+	if len(diagnostics) == 0 {
+		return errors.TraceNew("FeedbackUpload: error zero bytes of diagnostics read from stdin")
 	}
 	}
 
 
 	err = psiphon.SendFeedback(ctx, f.config, string(diagnostics), f.feedbackUploadPath)
 	err = psiphon.SendFeedback(ctx, f.config, string(diagnostics), f.feedbackUploadPath)

+ 8 - 4
psiphon/feedback.go

@@ -56,13 +56,13 @@ type secureFeedback struct {
 
 
 // Encrypt and marshal feedback into secure json structure utilizing the
 // Encrypt and marshal feedback into secure json structure utilizing the
 // Encrypt-then-MAC paradigm (https://tools.ietf.org/html/rfc7366#section-3).
 // Encrypt-then-MAC paradigm (https://tools.ietf.org/html/rfc7366#section-3).
-func encryptFeedback(diagnosticsJson, b64EncodedPublicKey string) ([]byte, error) {
+func encryptFeedback(diagnostics, b64EncodedPublicKey string) ([]byte, error) {
 	publicKey, err := base64.StdEncoding.DecodeString(b64EncodedPublicKey)
 	publicKey, err := base64.StdEncoding.DecodeString(b64EncodedPublicKey)
 	if err != nil {
 	if err != nil {
 		return nil, errors.Trace(err)
 		return nil, errors.Trace(err)
 	}
 	}
 
 
-	iv, encryptionKey, diagnosticsCiphertext, err := encryptAESCBC([]byte(diagnosticsJson))
+	iv, encryptionKey, diagnosticsCiphertext, err := encryptAESCBC([]byte(diagnostics))
 	if err != nil {
 	if err != nil {
 		return nil, err
 		return nil, err
 	}
 	}
@@ -98,7 +98,11 @@ func encryptFeedback(diagnosticsJson, b64EncodedPublicKey string) ([]byte, error
 
 
 // Encrypt feedback and upload to server. If upload fails
 // Encrypt feedback and upload to server. If upload fails
 // the routine will sleep and retry multiple times.
 // the routine will sleep and retry multiple times.
-func SendFeedback(ctx context.Context, config *Config, diagnosticsJson, uploadPath string) error {
+func SendFeedback(ctx context.Context, config *Config, diagnostics, uploadPath string) error {
+
+	if len(diagnostics) == 0 {
+		return errors.TraceNew("error diagnostics empty")
+	}
 
 
 	// Get tactics, may update client parameters
 	// Get tactics, may update client parameters
 	p := config.GetParameters().Get()
 	p := config.GetParameters().Get()
@@ -145,7 +149,7 @@ func SendFeedback(ctx context.Context, config *Config, diagnosticsJson, uploadPa
 			b64PublicKey = config.FeedbackEncryptionPublicKey
 			b64PublicKey = config.FeedbackEncryptionPublicKey
 		}
 		}
 
 
-		secureFeedback, err := encryptFeedback(diagnosticsJson, b64PublicKey)
+		secureFeedback, err := encryptFeedback(diagnostics, b64PublicKey)
 		if err != nil {
 		if err != nil {
 			return errors.Trace(err)
 			return errors.Trace(err)
 		}
 		}