Delete Profile API
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
Sarah Jamie Lewis 2021-06-14 15:42:44 -07:00
parent 78ee588538
commit 3fc2a3fcb1
4 changed files with 30 additions and 17 deletions

View File

@ -44,7 +44,7 @@ type Application interface {
LoadProfiles(password string) LoadProfiles(password string)
CreatePeer(name string, password string) CreatePeer(name string, password string)
CreateTaggedPeer(name string, password string, tag string) CreateTaggedPeer(name string, password string, tag string)
DeletePeer(onion string) DeletePeer(onion string, currentPassword string) bool
AddPeerPlugin(onion string, pluginID plugins.PluginID) AddPeerPlugin(onion string, pluginID plugins.PluginID)
ChangePeerPassword(onion, oldpass, newpass string) ChangePeerPassword(onion, oldpass, newpass string)
LaunchPeers() LaunchPeers()
@ -142,28 +142,32 @@ func (app *application) CreatePeer(name string, password string) {
app.CreateTaggedPeer(name, password, "") app.CreateTaggedPeer(name, password, "")
} }
func (app *application) DeletePeer(onion string) { func (app *application) DeletePeer(onion string, password string) bool {
log.Infof("DeletePeer called on %v\n", onion) log.Infof("DeletePeer called on %v\n", onion)
app.appmutex.Lock() app.appmutex.Lock()
defer app.appmutex.Unlock() defer app.appmutex.Unlock()
app.appletPlugins.ShutdownPeer(onion) if app.storage[onion].CheckPassword(password) {
app.plugins.Delete(onion) app.appletPlugins.ShutdownPeer(onion)
app.plugins.Delete(onion)
app.peers[onion].Shutdown() app.peers[onion].Shutdown()
delete(app.peers, onion) delete(app.peers, onion)
app.engines[onion].Shutdown() app.engines[onion].Shutdown()
delete(app.engines, onion) delete(app.engines, onion)
app.storage[onion].Shutdown() app.storage[onion].Shutdown()
app.storage[onion].Delete() app.storage[onion].Delete()
delete(app.storage, onion) delete(app.storage, onion)
app.eventBuses[onion].Publish(event.NewEventList(event.ShutdownPeer, event.Identity, onion)) app.eventBuses[onion].Publish(event.NewEventList(event.ShutdownPeer, event.Identity, onion))
app.applicationCore.DeletePeer(onion) app.applicationCore.DeletePeer(onion)
log.Debugf("Delete peer for %v Done\n", onion) log.Debugf("Delete peer for %v Done\n", onion)
return true
}
return false
} }
func (app *application) ChangePeerPassword(onion, oldpass, newpass string) { func (app *application) ChangePeerPassword(onion, oldpass, newpass string) {

View File

@ -112,10 +112,12 @@ func (ac *applicationClient) CreateTaggedPeer(name, password, tag string) {
ac.bridge.Write(&message) ac.bridge.Write(&message)
} }
// DeletePeer messages tehe service to delete a peer // DeletePeer messages the service to delete a peer
func (ac *applicationClient) DeletePeer(onion string) { func (ac *applicationClient) DeletePeer(onion string, password string) bool {
message := event.IPCMessage{Dest: DestApp, Message: event.NewEvent(event.DeletePeer, map[event.Field]string{event.Identity: onion})} message := event.IPCMessage{Dest: DestApp, Message: event.NewEvent(event.DeletePeer, map[event.Field]string{event.Identity: onion, event.Password: password})}
ac.bridge.Write(&message) ac.bridge.Write(&message)
// This return value is a lie...
return true
} }
func (ac *applicationClient) ChangePeerPassword(onion, oldpass, newpass string) { func (ac *applicationClient) ChangePeerPassword(onion, oldpass, newpass string) {

View File

@ -22,6 +22,7 @@ type ProfileStore interface {
GetProfileCopy(timeline bool) *model.Profile GetProfileCopy(timeline bool) *model.Profile
GetNewPeerMessage() *event.Event GetNewPeerMessage() *event.Event
GetStatusMessages() []*event.Event GetStatusMessages() []*event.Event
CheckPassword(string) bool
} }
// CreateProfileWriterStore creates a profile store backed by a filestore listening for events and saving them // CreateProfileWriterStore creates a profile store backed by a filestore listening for events and saving them

View File

@ -33,6 +33,12 @@ type ProfileStoreV1 struct {
writer bool writer bool
} }
// CheckPassword returns true if the given password produces the same key as the current stored key, otherwise false.
func (ps *ProfileStoreV1) CheckPassword(checkpass string) bool {
oldkey := CreateKey(checkpass, ps.salt[:])
return oldkey == ps.key
}
func initV1Directory(directory, password string) ([32]byte, [128]byte, error) { func initV1Directory(directory, password string) ([32]byte, [128]byte, error) {
key, salt, err := CreateKeySalt(password) key, salt, err := CreateKeySalt(password)
if err != nil { if err != nil {