bugfixes from android testing
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
Sarah Jamie Lewis 2021-04-26 15:58:46 -07:00
parent a99a7c659e
commit 3d2c8c9fbf
3 changed files with 20 additions and 6 deletions

View File

@ -97,12 +97,14 @@ func (gf *GroupFunctionality) HandleImportString(peer peer.CwtchPeer, importStri
if strings.HasPrefix(importString, tofuBundlePrefix) { if strings.HasPrefix(importString, tofuBundlePrefix) {
bundle := strings.Split(importString, "||") bundle := strings.Split(importString, "||")
err := gf.HandleImportString(peer, bundle[0][len(tofuBundlePrefix):]) if len(bundle) == 2 {
// if the server import failed then abort the whole process.. err := gf.HandleImportString(peer, bundle[0][len(tofuBundlePrefix):])
if strings.HasSuffix(err.Error(), "success") == false { // if the server import failed then abort the whole process..
return features.ConstructResponse(importBundlePrefix, err.Error()) if strings.HasSuffix(err.Error(), "success") == false {
return features.ConstructResponse(importBundlePrefix, err.Error())
}
return gf.HandleImportString(peer, bundle[1])
} }
return gf.HandleImportString(peer, bundle[1])
} else if strings.HasPrefix(importString, serverPrefix) { } else if strings.HasPrefix(importString, serverPrefix) {
// Server Key Bundles are prefixed with // Server Key Bundles are prefixed with
bundle, err := base64.StdEncoding.DecodeString(importString[len(serverPrefix):]) bundle, err := base64.StdEncoding.DecodeString(importString[len(serverPrefix):])

2
lib.go
View File

@ -52,6 +52,8 @@ func StartCwtch(appDir string, torPath string) {
// Exclude Tapir wire Messages (We need a TRACE level) // Exclude Tapir wire Messages (We need a TRACE level)
log.ExcludeFromPattern("service.go") log.ExcludeFromPattern("service.go")
// Ensure that the application directory exists...and then initialize settings..
os.MkdirAll(path.Join(appDir), 0700)
utils.InitGlobalSettingsFile(appDir, "be gay do crime") utils.InitGlobalSettingsFile(appDir, "be gay do crime")
log.Infof("Loading Cwtch Directory %v and tor path: %v", appDir, torPath) log.Infof("Loading Cwtch Directory %v and tor path: %v", appDir, torPath)

View File

@ -46,14 +46,17 @@ func InitGlobalSettingsFile(directory string, password string) error {
var key [32]byte var key [32]byte
salt, err := ioutil.ReadFile(path.Join(directory, saltFile)) salt, err := ioutil.ReadFile(path.Join(directory, saltFile))
if err != nil { if err != nil {
log.Infof("Could not find salt file: %v (creating a new settings file)", err)
var newSalt [128]byte var newSalt [128]byte
key, newSalt, err = v1.CreateKeySalt(password) key, newSalt, err = v1.CreateKeySalt(password)
if err != nil { if err != nil {
log.Errorf("Could not initialize salt: %v", err)
return err return err
} }
os.Mkdir(directory, 0700) os.Mkdir(directory, 0700)
err := ioutil.WriteFile(path.Join(directory, saltFile), newSalt[:], 0600) err := ioutil.WriteFile(path.Join(directory, saltFile), newSalt[:], 0600)
if err != nil { if err != nil {
log.Errorf("Could not write salt file: %v", err)
return err return err
} }
} else { } else {
@ -61,21 +64,28 @@ func InitGlobalSettingsFile(directory string, password string) error {
} }
GlobalSettingsFile = v1.NewFileStore(directory, GlobalSettingsFilename, key) GlobalSettingsFile = v1.NewFileStore(directory, GlobalSettingsFilename, key)
log.Infof("initialized global settings file: %v", GlobalSettingsFile)
return nil return nil
} }
func ReadGlobalSettings() *GlobalSettings { func ReadGlobalSettings() *GlobalSettings {
settings := DefaultGlobalSettings settings := DefaultGlobalSettings
if GlobalSettingsFile == nil {
log.Errorf("Global Settings File was not Initialized Properly")
return &settings
}
settingsBytes, err := GlobalSettingsFile.Read() settingsBytes, err := GlobalSettingsFile.Read()
if err != nil { if err != nil {
log.Errorf("Could not read global ui settings: %v\n", err) log.Infof("Could not read global ui settings: %v (assuming this is a first time app deployment...)", err)
return &settings //firstTime = true return &settings //firstTime = true
} }
err = json.Unmarshal(settingsBytes, &settings) err = json.Unmarshal(settingsBytes, &settings)
if err != nil { if err != nil {
log.Errorf("Could not parse global ui settings: %v\n", err) log.Errorf("Could not parse global ui settings: %v\n", err)
// TODO if settings is corrupted, we probably want to alert the UI.
return &settings //firstTime = true return &settings //firstTime = true
} }