Add CLI support for restore endpoint.

+ Add the relevant parts to the command line tool and the client
  package.
+ Small improvements to cryptor's restore function:
  + Don't try to restore if the store is already active.
  + Flush the persistence key cache once the restoration occurs.
+ The redoctober program now explicitly mentions that a config file is
  invalid when that's the case.
This commit is contained in:
Kyle Isom
2016-08-16 15:00:40 -07:00
parent 4d7d8257e7
commit 4da501264a
4 changed files with 50 additions and 0 deletions

View File

@@ -742,6 +742,11 @@ var ErrRestoreDelegations = errors.New("cryptor: need more delegations")
// enough delegations are present to restore the cache, the current
// Red October key cache is replaced with the persisted one.
func (c *Cryptor) Restore(name, password string, uses int, slot, durationString string) error {
// If the persistence store is already active, don't proceed.
if st := c.persist.Status(); st != nil && st.State == persist.Active {
return nil
}
record, ok := c.records.GetRecord(name)
if !ok {
return errors.New("Missing user on disk")
@@ -774,6 +779,7 @@ func (c *Cryptor) Restore(name, password string, uses int, slot, durationString
c.cache = keycache.NewFrom(uk)
c.persist.Persist()
c.persist.Cache().Flush()
return nil
}