// MakeSignedToken encrypts a timestamp and a random number with the users GPG key // to use as an auth token with the API func (cli Client) MakeSignedToken() (token string, err error) { defer func() { if e := recover(); e != nil { err = fmt.Errorf("MakeSignedToken() -> %v", e) } }() tokenVersion := 1 str := fmt.Sprintf("%d;%s;%.0f", tokenVersion, time.Now().UTC().Format(time.RFC3339), mig.GenID()) secringFile, err := os.Open(cli.Conf.GPG.Home + "/secring.gpg") if err != nil { panic(err) } defer secringFile.Close() sig, err := pgp.Sign(str+"\n", cli.Conf.GPG.KeyID, secringFile) if err != nil { panic(err) } token = str + ";" + sig return }
// Sign computes and returns the GPG signature of a MIG action in its stringified form func (a Action) Sign(keyid string, secring io.Reader) (sig string, err error) { defer func() { if e := recover(); e != nil { err = fmt.Errorf("Sign() -> %v", e) } }() filename, err := a.ToTempFile() if err != nil { panic(err) } a2, err := ActionFromFile(filename) if err != nil { panic(err) } str, err := a2.String() if err != nil { panic(err) } sig, err = pgp.Sign(str, keyid, secring) if err != nil { panic(err) } return }
// Sign a manifest record func (m *ManifestRecord) Sign(keyid string, secring io.Reader) (sig string, err error) { defer func() { if e := recover(); e != nil { err = fmt.Errorf("Sign() -> %v", e) } }() // Convert the record into entry format, and strip existing signatures // before signing. me, err := m.ManifestResponse() if err != nil { panic(err) } me.Signatures = make([]string, 0) buf, err := json.Marshal(me) if err != nil { panic(err) } sig, err = pgp.Sign(string(buf), keyid, secring) if err != nil { panic(err) } return }