Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork158
fix: allow to specify customsignatureKey in theconfig.ini#1024
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
a5be7b6dec684b5681091497a6400711750be54150bfcd13541e52758a608829601bc00f7a4fbd9348ca27e570e27b7ce72237ff0File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -19,6 +19,7 @@ package main | ||
| import ( | ||
| "bytes" | ||
| "crypto/rsa" | ||
| "encoding/json" | ||
| "errors" | ||
| "fmt" | ||
| @@ -79,111 +80,114 @@ type Upload struct { | ||
| var uploadStatusStr = "ProgrammerStatus" | ||
| func uploadHandler(pubKey *rsa.PublicKey) func(*gin.Context) { | ||
| return func(c *gin.Context) { | ||
| data := new(Upload) | ||
| if err := c.BindJSON(data); err != nil { | ||
| c.String(http.StatusBadRequest, fmt.Sprintf("err with the payload. %v", err.Error())) | ||
| return | ||
| } | ||
| log.Printf("%+v %+v %+v %+v %+v %+v", data.Port, data.Board, data.Rewrite, data.Commandline, data.Extra, data.Filename) | ||
| if data.Port == "" { | ||
| c.String(http.StatusBadRequest, "port is required") | ||
| return | ||
| } | ||
| if data.Board == "" { | ||
| c.String(http.StatusBadRequest, "board is required") | ||
| log.Error("board is required") | ||
| return | ||
| } | ||
| if !data.Extra.Network { | ||
| if data.Signature == "" { | ||
| c.String(http.StatusBadRequest, "signature is required") | ||
| return | ||
| } | ||
| if data.Commandline == "" { | ||
| c.String(http.StatusBadRequest, "commandline is required for local board") | ||
| return | ||
| } | ||
| err := utilities.VerifyInput(data.Commandline, data.Signature, pubKey) | ||
| if err != nil { | ||
| log.WithField("err", err).Error("Error verifying the command") | ||
| c.String(http.StatusBadRequest, "signature is invalid") | ||
| return | ||
| } | ||
| } | ||
| buffer := bytes.NewBuffer(data.Hex) | ||
| filePath,err:= utilities.SaveFileonTempDir(data.Filename, buffer) | ||
| if err != nil { | ||
| c.String(http.StatusBadRequest, err.Error()) | ||
| return | ||
| } | ||
| tmpdir, err := os.MkdirTemp("", "extrafiles") | ||
| if err != nil { | ||
| c.String(http.StatusBadRequest,err.Error()) | ||
| return | ||
| } | ||
| for _, extraFile := range data.ExtraFiles { | ||
| path, err := utilities.SafeJoin(tmpdir, extraFile.Filename) | ||
| if err != nil { | ||
| c.String(http.StatusBadRequest, err.Error()) | ||
| return | ||
| } | ||
| log.Printf("Saving %s on %s", extraFile.Filename, path) | ||
| err = os.MkdirAll(filepath.Dir(path), 0744) | ||
| ||
| if err != nil { | ||
| c.String(http.StatusBadRequest, err.Error()) | ||
| return | ||
| } | ||
| err = os.WriteFile(path, extraFile.Hex, 0644) | ||
| ||
| if err != nil { | ||
| c.String(http.StatusBadRequest, err.Error()) | ||
| return | ||
| } | ||
| } | ||
| if data.Rewrite != "" { | ||
| data.Board = data.Rewrite | ||
| } | ||
| go func() { | ||
| // Resolve commandline | ||
| commandline, err := upload.PartiallyResolve(data.Board, filePath, tmpdir, data.Commandline, data.Extra, Tools) | ||
| if err != nil { | ||
| send(map[string]string{uploadStatusStr: "Error", "Msg": err.Error()}) | ||
| return | ||
| } | ||
| l := PLogger{Verbose: true} | ||
| // Upload | ||
| if data.Extra.Network { | ||
| err = errors.New("network upload is not supported anymore, pease use OTA instead") | ||
| } else { | ||
| send(map[string]string{uploadStatusStr: "Starting", "Cmd": "Serial"}) | ||
| err = upload.Serial(data.Port, commandline, data.Extra, l) | ||
| } | ||
| // Handle result | ||
| if err != nil { | ||
| send(map[string]string{uploadStatusStr: "Error", "Msg": err.Error()}) | ||
| return | ||
| } | ||
| send(map[string]string{uploadStatusStr: "Done", "Flash": "Ok"}) | ||
| }() | ||
| c.String(http.StatusAccepted, "") | ||
| } | ||
| } | ||
| // PLogger sends the info from the upload to the websocket | ||
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.