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)
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) {

View File

@ -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) {

View File

@ -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

View File

@ -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 {