Something went wrong on our end
Select Git revision
createManagerKey.go 3.06 KiB
/*
Skills
Copyright (C) 2023 GérardMeunier
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package main
// Creates the key the manager must type when runSkillsC starts.
import (
F "path/filepath"
M "git.duniter.org/gerard94/util/misc"
R "git.duniter.org/gerard94/util/resources"
"crypto/aes"
"errors"
"flag"
"fmt"
"encoding/hex"
"os"
"strings"
"text/scanner"
"crypto/sha256"
)
const (
keySize = 256 / 8
keyPath = "skillsclient/managerKey.txt"
)
var (
keyP = R.FindDir(keyPath)
privKey string
masterKeyPath string
)
func getMasterKey (key *[]byte) bool {
f, err := os.Open(masterKeyPath)
if err != nil {
fmt.Fprintln(os.Stderr, "Incorrect path to Master Key (mk)")
return false
}
defer f.Close()
s := new(scanner.Scanner)
s.Init(f)
s.Error = func(s *scanner.Scanner, msg string) {M.Halt(errors.New("File " + masterKeyPath + " incorrect"), 100)}
s.Mode = scanner.ScanStrings
s.Scan()
ss := s.TokenText()
M.Assert(ss[0] == '"' && ss[len(ss) - 1] == '"', ss, 101)
k, err := hex.DecodeString(ss[1:len(ss) - 1]); M.Assert(err == nil, err, 102)
M.Assert(len(k) == keySize, "key has wrong length:", k, 103)
*key = k
return true
}
func storeKeys (key1, key2 []byte, keyPath string) bool {