// readGroup takes a toml file name and reads the file, returning the entities within func readGroup(tomlFileName string) (*onet.Roster, error) { log.Print("Reading From File") f, err := os.Open(tomlFileName) if err != nil { return nil, err } el, err := config.ReadGroupToml(f) if err != nil { return nil, err } if len(el.List) <= 0 { return nil, errors.New("Empty or invalid group file:" + tomlFileName) } log.Lvl3(el) return el, err }
// sign takes a stream and a toml file defining the servers func sign(r io.Reader, tomlFileName string) (*s.SignatureResponse, error) { log.Lvl2("Starting signature") f, err := os.Open(tomlFileName) if err != nil { return nil, err } el, err := config.ReadGroupToml(f) if err != nil { return nil, err } if len(el.List) <= 0 { return nil, errors.New("Empty or invalid cosi group file:" + tomlFileName) } log.Lvl2("Sending signature to", el) res, err := signStatement(r, el) if err != nil { return nil, err } return res, nil }
// verify takes a file and a group-definition, calls the signature // verification and prints the result. If sigFileName is empty it // assumes to find the standard signature in fileName.sig func verify(fileName, sigFileName, groupToml string) error { // if the file hash matches the one in the signature log.Lvl4("Reading file " + fileName) b, err := ioutil.ReadFile(fileName) if err != nil { return errors.New("Couldn't open msgFile: " + err.Error()) } // Read the JSON signature file log.Lvl4("Reading signature") var sigBytes []byte if sigFileName == "" { log.Print("[+] Reading signature from standard input ...") sigBytes, err = ioutil.ReadAll(os.Stdin) } else { sigBytes, err = ioutil.ReadFile(sigFileName) } if err != nil { return err } sig := &s.SignatureResponse{} log.Lvl4("Unmarshalling signature ") if err := json.Unmarshal(sigBytes, sig); err != nil { return err } fGroup, err := os.Open(groupToml) if err != nil { return err } log.Lvl4("Reading group definition") el, err := config.ReadGroupToml(fGroup) if err != nil { return err } log.Lvl4("Verfifying signature") err = verifySignatureHash(b, sig, el) return err }