1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-04 19:17:37 +08:00

feather: use startup params to decrypt password

This commit is contained in:
Ink-33 2020-11-16 22:34:05 +08:00
parent 79ba9474a3
commit 0f0f74ece8
No known key found for this signature in database
GPG Key ID: 5D8B1D036EFB0D2E

75
main.go
View File

@ -2,17 +2,16 @@ package main
import (
"bufio"
"context"
"crypto/md5"
"encoding/base64"
"encoding/json"
"fmt"
"github.com/Mrs4s/go-cqhttp/server"
"github.com/guonaihong/gout"
"github.com/tidwall/gjson"
"io"
"io/ioutil"
"net/http"
"os"
"os/exec"
"os/signal"
"path"
"runtime"
@ -20,15 +19,19 @@ import (
"strings"
"time"
"github.com/Mrs4s/go-cqhttp/server"
"github.com/guonaihong/gout"
"github.com/tidwall/gjson"
"github.com/Mrs4s/MiraiGo/binary"
"github.com/Mrs4s/MiraiGo/client"
"github.com/Mrs4s/go-cqhttp/coolq"
"github.com/Mrs4s/go-cqhttp/global"
"github.com/getlantern/go-update"
"github.com/lestrrat-go/file-rotatelogs"
rotatelogs "github.com/lestrrat-go/file-rotatelogs"
"github.com/rifflock/lfshook"
log "github.com/sirupsen/logrus"
"github.com/t-tomalak/logrus-easy-formatter"
easy "github.com/t-tomalak/logrus-easy-formatter"
)
func init() {
@ -93,13 +96,26 @@ func init() {
func main() {
console := bufio.NewReader(os.Stdin)
var strKey string
arg := os.Args
if len(arg) > 1 && arg[1] == "update" {
if len(arg) > 2 {
selfUpdate(arg[2])
} else {
selfUpdate("")
fmt.Println(arg)
if len(arg) > 1 {
for i := range arg {
switch arg[i] {
case "update":
if len(arg) > i+1 {
selfUpdate(arg[i+2])
} else {
selfUpdate("")
}
case "key":
if len(arg) > i+1 {
b := []byte(arg[i+1])
b = append(b, 13, 10)
strKey = string(b[:])
fmt.Println(b)
}
}
}
}
@ -216,8 +232,24 @@ func main() {
}
}
if conf.PasswordEncrypted != "" {
log.Infof("密码加密已启用, 请输入Key对密码进行解密以继续: (Enter 提交)")
strKey, _ := console.ReadString('\n')
if strKey == "" {
log.Infof("密码加密已启用, 请输入Key对密码进行解密以继续: (Enter 提交)")
ctx := context.Background()
go func(ctx context.Context) {
select {
case <-ctx.Done():
return
case <-time.After(time.Second * 45):
log.Infof("解密key输入超时")
time.Sleep(3 * time.Second)
os.Exit(0)
}
}(ctx)
strKey, _ = console.ReadString('\n')
ctx.Done()
} else {
log.Infof("密码加密已启用, 使用运行时传递的参数进行解密,按 Ctrl+C 取消.")
}
key := md5.Sum([]byte(strKey))
conf.Password = DecryptPwd(conf.PasswordEncrypted, key[:])
}
@ -284,10 +316,23 @@ func main() {
}
b := server.WebServer.Run(fmt.Sprintf("%s:%d", conf.WebUi.Host, conf.WebUi.WebUiPort), cli)
c := server.Console
r := server.Restart
go checkUpdate()
signal.Notify(c, os.Interrupt, os.Kill)
<-c
b.Release()
select {
case <-c:
b.Release()
case <-r:
b.Release()
cmd := &exec.Cmd{
Path: arg[0],
Args: arg[1:],
Stderr: os.Stderr,
Stdout: os.Stdout,
}
server.HttpServer.ShutDown()
cmd.Start()
}
}
func EncryptPwd(pwd string, key []byte) string {