identity in config to allow save from everywhere

This commit is contained in:
ycc 2023-01-08 22:57:17 +01:00
parent 5ac92ce3a8
commit 61958593a1
3 changed files with 18 additions and 8 deletions

View File

@ -11,6 +11,7 @@ type Config struct {
SavePassword bool `json:"save_password,omitempty"`
SavedPassword string `json:"saved_password,omitempty"`
// Technical
IdentityFile string `json:"identity_file,omitempty"`
StoragePath string `json:"storage_path,omitempty"`
MaxIdsPerUser int `json:"max_ids_per_user,omitempty"`
MsgDbRollingPeriod int `json:"msg_db_rolling_period,omitempty"`
@ -29,10 +30,10 @@ type Config struct {
PrivateChatNotifiactions bool `json:"private_chat_notifiactions,omitempty"`
GroupChatNotifiactions bool `json:"group_chat_notifiactions,omitempty"`
ChannelNotifications bool `json:"channel_notifications,omitempty"`
// Inner
memoryPassword string
additionalPasswords []string
identityFile string
me *Identity
}

View File

@ -115,7 +115,7 @@ func (id *Identity) FinalizeInvitation(ReceivedContact *meowlib.ContactCard) err
func LoadIdentity(filename string, password string) (*Identity, error) {
var id Identity
GetConfig().memoryPassword = password
GetConfig().identityFile = filename
GetConfig().IdentityFile = filename
indata, err := os.ReadFile(filename)
if err != nil {
return nil, err
@ -135,6 +135,6 @@ func (id *Identity) Save() error {
if err != nil {
return err
}
err = os.WriteFile(GetConfig().identityFile, []byte(armor), 0600)
err = os.WriteFile(GetConfig().IdentityFile, []byte(armor), 0600)
return err
}

View File

@ -8,6 +8,7 @@ import (
"forge.redroom.link/yves/meowlib"
"github.com/google/uuid"
_ "github.com/mattn/go-sqlite3"
"google.golang.org/protobuf/proto"
)
func StoreMessage(peer *Peer, usermessage *meowlib.UserMessage, password string) error {
@ -34,11 +35,11 @@ func StoreMessage(peer *Peer, usermessage *meowlib.UserMessage, password string)
// Open Db
db, _ := sql.Open("sqlite3", filepath.Join(GetConfig().StoragePath, dbid)) // Open the created SQLite File
defer db.Close()
// TODO Detach Files
// Detach Files
if len(usermessage.Files) > 0 {
for _, f := range usermessage.Files {
hiddenFilename := uuid.NewString()
// TODO cypher file
// Cypher file
encData, err := meowlib.SymEncrypt(password, f.Data)
if err != nil {
return err
@ -48,14 +49,22 @@ func StoreMessage(peer *Peer, usermessage *meowlib.UserMessage, password string)
f.Data = []byte(hiddenFilename)
}
}
// TODO Encrypt message
// Inser message
// Encrypt message
out, err := proto.Marshal(usermessage)
if err != nil {
return err
}
encData, err := meowlib.SymEncrypt(password, out)
if err != nil {
return err
}
// Insert message
insertMessageSQL := `INSERT INTO message(m) VALUES (?)`
statement, err := db.Prepare(insertMessageSQL) // Prepare statement.
if err != nil {
return err
}
_, err = statement.Exec(usermessage)
_, err = statement.Exec(encData)
if err != nil {
return err
}