Skip to content
This repository has been archived by the owner on Apr 11, 2023. It is now read-only.

Commit

Permalink
Update main.go
Browse files Browse the repository at this point in the history
  • Loading branch information
pedroalbanese authored Jan 12, 2023
1 parent 40bb095 commit f441c82
Showing 1 changed file with 25 additions and 27 deletions.
52 changes: 25 additions & 27 deletions cmd/engine/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/pedroalbanese/gogost/gost3412128"
"github.com/pedroalbanese/gogost/gost341264"
"github.com/pedroalbanese/gogost/mgm"
"github.com/pedroalbanese/gopass"
"github.com/pedroalbanese/randomart"
)

Expand Down Expand Up @@ -113,8 +114,23 @@ func main() {
os.Exit(0)
}

Files := strings.Join(flag.Args(), " ")
var inputfile io.Reader
var inputdesc string
var err error
if Files == "-" || Files == "" || strings.Contains(Files, "*") {
inputfile = os.Stdin
inputdesc = "stdin"
} else {
inputfile, err = os.Open(flag.Arg(0))
if err != nil {
log.Fatalf("failed opening file: %s", err)
}
inputdesc = flag.Arg(0)
}

if *encode == "enc" || *encode == "encode" {
b, err := ioutil.ReadAll(os.Stdin)
b, err := ioutil.ReadAll(inputfile)
if len(b) == 0 {
os.Exit(0)
}
Expand All @@ -130,7 +146,7 @@ func main() {
if *encode == "dec" || *encode == "decode" {
var err error
buf := bytes.NewBuffer(nil)
data := os.Stdin
data := inputfile
io.Copy(buf, data)
b := strings.TrimSuffix(string(buf.Bytes()), "\r\n")
b = strings.TrimSuffix(string(b), "\n")
Expand All @@ -154,30 +170,13 @@ func main() {

if *encode == "dump" {
buf := bytes.NewBuffer(nil)
data := os.Stdin
data := inputfile
io.Copy(buf, data)
b := strings.TrimSuffix(string(buf.Bytes()), "\r\n")
b = strings.TrimSuffix(string(b), "\n")
dump := hex.Dump([]byte(b))
dump := hex.Dump(buf.Bytes())
os.Stdout.Write([]byte(dump))
os.Exit(0)
}

Files := strings.Join(flag.Args(), " ")
var inputfile io.Reader
var inputdesc string
var err error
if Files == "-" || Files == "" || strings.Contains(Files, "*") {
inputfile = os.Stdin
inputdesc = "stdin"
} else {
inputfile, err = os.Open(flag.Arg(0))
if err != nil {
log.Fatalf("failed opening file: %s", err)
}
inputdesc = flag.Arg(0)
}

if (*crypt == "enc" || *crypt == "dec") && strings.ToUpper(*mode) == "MGM" {
var keyHex string
var keyRaw []byte
Expand Down Expand Up @@ -553,14 +552,14 @@ func main() {
*pwd = scanner.Text()
}

if (*pkey == "certgen" || *pkey == "keygen" || *pkey == "text" || *pkey == "modulus" || *tcpip == "server" || *tcpip == "client" || *pkey == "derive") && *key != "" && *pwd == "" {
if (*pkey == "sign" || *pkey == "decrypt" || *pkey == "derive" || *pkey == "certgen" || *pkey == "text" || *pkey == "modulus" || *tcpip == "server" || *tcpip == "client") && *key != "" && *pwd == "" {
file, err := os.Open(*key)
if err != nil {
log.Println(err)
log.Fatal(err)
}
info, err := file.Stat()
if err != nil {
log.Println(err)
log.Fatal(err)
}
buf := make([]byte, info.Size())
file.Read(buf)
Expand All @@ -570,10 +569,9 @@ func main() {
errors.New("no valid private key found")
}
if IsEncryptedPEMBlock(block) {
scanner := bufio.NewScanner(os.Stdin)
print("Password: ")
scanner.Scan()
*pwd = scanner.Text()
pass, _ := gopass.GetPasswd()
*pwd = string(pass)
}
}

Expand Down

0 comments on commit f441c82

Please sign in to comment.