diff --git a/app/app.go b/app/app.go index c0c3e86..5845065 100644 --- a/app/app.go +++ b/app/app.go @@ -44,7 +44,7 @@ type Application interface { LoadProfiles(password string) CreatePeer(name string, password string) CreateTaggedPeer(name string, password string, tag string) - DeletePeer(onion string) + DeletePeer(onion string, currentPassword string) bool AddPeerPlugin(onion string, pluginID plugins.PluginID) ChangePeerPassword(onion, oldpass, newpass string) LaunchPeers() @@ -142,28 +142,32 @@ func (app *application) CreatePeer(name string, password string) { 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) app.appmutex.Lock() defer app.appmutex.Unlock() - app.appletPlugins.ShutdownPeer(onion) - app.plugins.Delete(onion) + if app.storage[onion].CheckPassword(password) { + app.appletPlugins.ShutdownPeer(onion) + app.plugins.Delete(onion) - app.peers[onion].Shutdown() - delete(app.peers, onion) + app.peers[onion].Shutdown() + delete(app.peers, onion) - app.engines[onion].Shutdown() - delete(app.engines, onion) + app.engines[onion].Shutdown() + delete(app.engines, onion) - app.storage[onion].Shutdown() - app.storage[onion].Delete() - delete(app.storage, onion) + app.storage[onion].Shutdown() + app.storage[onion].Delete() + 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) - log.Debugf("Delete peer for %v Done\n", onion) + app.applicationCore.DeletePeer(onion) + log.Debugf("Delete peer for %v Done\n", onion) + return true + } + return false } func (app *application) ChangePeerPassword(onion, oldpass, newpass string) { diff --git a/app/appClient.go b/app/appClient.go index b883942..184ce63 100644 --- a/app/appClient.go +++ b/app/appClient.go @@ -112,10 +112,12 @@ func (ac *applicationClient) CreateTaggedPeer(name, password, tag string) { ac.bridge.Write(&message) } -// DeletePeer messages tehe service to delete a peer -func (ac *applicationClient) DeletePeer(onion string) { - message := event.IPCMessage{Dest: DestApp, Message: event.NewEvent(event.DeletePeer, map[event.Field]string{event.Identity: onion})} +// DeletePeer messages the service to delete a peer +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, event.Password: password})} ac.bridge.Write(&message) + // This return value is a lie... + return true } func (ac *applicationClient) ChangePeerPassword(onion, oldpass, newpass string) { diff --git a/storage/profile_store.go b/storage/profile_store.go index de03213..a6ddae7 100644 --- a/storage/profile_store.go +++ b/storage/profile_store.go @@ -22,6 +22,7 @@ type ProfileStore interface { GetProfileCopy(timeline bool) *model.Profile GetNewPeerMessage() *event.Event GetStatusMessages() []*event.Event + CheckPassword(string) bool } // CreateProfileWriterStore creates a profile store backed by a filestore listening for events and saving them diff --git a/storage/v1/profile_store.go b/storage/v1/profile_store.go index 5e7f607..436a4a8 100644 --- a/storage/v1/profile_store.go +++ b/storage/v1/profile_store.go @@ -33,6 +33,12 @@ type ProfileStoreV1 struct { 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) { key, salt, err := CreateKeySalt(password) if err != nil {