|
@ -4,19 +4,18 @@ import ( |
|
|
"encoding/base64" |
|
|
"encoding/base64" |
|
|
|
|
|
|
|
|
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Database" |
|
|
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Database" |
|
|
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Models" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/gofrs/uuid" |
|
|
"github.com/gofrs/uuid" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
func seedMessage( |
|
|
func seedMessage( |
|
|
primaryUser, secondaryUser Models.User, |
|
|
|
|
|
|
|
|
primaryUser, secondaryUser Database.User, |
|
|
primaryUserAssociationKey, secondaryUserAssociationKey string, |
|
|
primaryUserAssociationKey, secondaryUserAssociationKey string, |
|
|
i int, |
|
|
i int, |
|
|
) error { |
|
|
) error { |
|
|
var ( |
|
|
var ( |
|
|
message Models.Message |
|
|
|
|
|
messageData Models.MessageData |
|
|
|
|
|
|
|
|
message Database.Message |
|
|
|
|
|
messageData Database.MessageData |
|
|
key, userKey AesKey |
|
|
key, userKey AesKey |
|
|
keyCiphertext []byte |
|
|
keyCiphertext []byte |
|
|
plaintext string |
|
|
plaintext string |
|
@ -61,13 +60,13 @@ func seedMessage( |
|
|
panic(err) |
|
|
panic(err) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
messageData = Models.MessageData{ |
|
|
|
|
|
|
|
|
messageData = Database.MessageData{ |
|
|
Data: base64.StdEncoding.EncodeToString(dataCiphertext), |
|
|
Data: base64.StdEncoding.EncodeToString(dataCiphertext), |
|
|
SenderID: base64.StdEncoding.EncodeToString(senderIDCiphertext), |
|
|
SenderID: base64.StdEncoding.EncodeToString(senderIDCiphertext), |
|
|
SymmetricKey: base64.StdEncoding.EncodeToString(keyCiphertext), |
|
|
SymmetricKey: base64.StdEncoding.EncodeToString(keyCiphertext), |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
message = Models.Message{ |
|
|
|
|
|
|
|
|
message = Database.Message{ |
|
|
MessageData: messageData, |
|
|
MessageData: messageData, |
|
|
SymmetricKey: base64.StdEncoding.EncodeToString( |
|
|
SymmetricKey: base64.StdEncoding.EncodeToString( |
|
|
EncryptWithPublicKey(userKey.Key, decodedPublicKey), |
|
|
EncryptWithPublicKey(userKey.Key, decodedPublicKey), |
|
@ -75,12 +74,12 @@ func seedMessage( |
|
|
AssociationKey: primaryUserAssociationKey, |
|
|
AssociationKey: primaryUserAssociationKey, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
err = Database.CreateMessage(&message) |
|
|
|
|
|
|
|
|
err = (&message).CreateMessage() |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return err |
|
|
return err |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
message = Models.Message{ |
|
|
|
|
|
|
|
|
message = Database.Message{ |
|
|
MessageData: messageData, |
|
|
MessageData: messageData, |
|
|
SymmetricKey: base64.StdEncoding.EncodeToString( |
|
|
SymmetricKey: base64.StdEncoding.EncodeToString( |
|
|
EncryptWithPublicKey(userKey.Key, decodedPublicKey), |
|
|
EncryptWithPublicKey(userKey.Key, decodedPublicKey), |
|
@ -88,12 +87,12 @@ func seedMessage( |
|
|
AssociationKey: secondaryUserAssociationKey, |
|
|
AssociationKey: secondaryUserAssociationKey, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return Database.CreateMessage(&message) |
|
|
|
|
|
|
|
|
return (&message).CreateMessage() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func seedConversationDetail(key AesKey) (Models.ConversationDetail, error) { |
|
|
|
|
|
|
|
|
func seedConversationDetail(key AesKey) (Database.ConversationDetail, error) { |
|
|
var ( |
|
|
var ( |
|
|
conversationDetail Models.ConversationDetail |
|
|
|
|
|
|
|
|
conversationDetail Database.ConversationDetail |
|
|
name string |
|
|
name string |
|
|
nameCiphertext []byte |
|
|
nameCiphertext []byte |
|
|
falseCiphertext []byte |
|
|
falseCiphertext []byte |
|
@ -118,7 +117,7 @@ func seedConversationDetail(key AesKey) (Models.ConversationDetail, error) { |
|
|
panic(err) |
|
|
panic(err) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
conversationDetail = Models.ConversationDetail{ |
|
|
|
|
|
|
|
|
conversationDetail = Database.ConversationDetail{ |
|
|
Name: base64.StdEncoding.EncodeToString(nameCiphertext), |
|
|
Name: base64.StdEncoding.EncodeToString(nameCiphertext), |
|
|
TwoUser: base64.StdEncoding.EncodeToString(falseCiphertext), |
|
|
TwoUser: base64.StdEncoding.EncodeToString(falseCiphertext), |
|
|
AdminAddMembers: base64.StdEncoding.EncodeToString(trueCiphertext), |
|
|
AdminAddMembers: base64.StdEncoding.EncodeToString(trueCiphertext), |
|
@ -126,17 +125,17 @@ func seedConversationDetail(key AesKey) (Models.ConversationDetail, error) { |
|
|
AdminSendMessages: base64.StdEncoding.EncodeToString(falseCiphertext), |
|
|
AdminSendMessages: base64.StdEncoding.EncodeToString(falseCiphertext), |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
err = Database.CreateConversationDetail(&conversationDetail) |
|
|
|
|
|
|
|
|
err = (&conversationDetail).CreateConversationDetail() |
|
|
return conversationDetail, err |
|
|
return conversationDetail, err |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func seedUserConversation( |
|
|
func seedUserConversation( |
|
|
user Models.User, |
|
|
|
|
|
|
|
|
user Database.User, |
|
|
threadID uuid.UUID, |
|
|
threadID uuid.UUID, |
|
|
key AesKey, |
|
|
key AesKey, |
|
|
) (Models.UserConversation, error) { |
|
|
|
|
|
|
|
|
) (Database.UserConversation, error) { |
|
|
var ( |
|
|
var ( |
|
|
messageThreadUser Models.UserConversation |
|
|
|
|
|
|
|
|
messageThreadUser Database.UserConversation |
|
|
conversationDetailIDCiphertext []byte |
|
|
conversationDetailIDCiphertext []byte |
|
|
adminCiphertext []byte |
|
|
adminCiphertext []byte |
|
|
err error |
|
|
err error |
|
@ -152,7 +151,7 @@ func seedUserConversation( |
|
|
return messageThreadUser, err |
|
|
return messageThreadUser, err |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
messageThreadUser = Models.UserConversation{ |
|
|
|
|
|
|
|
|
messageThreadUser = Database.UserConversation{ |
|
|
UserID: user.ID, |
|
|
UserID: user.ID, |
|
|
ConversationDetailID: base64.StdEncoding.EncodeToString(conversationDetailIDCiphertext), |
|
|
ConversationDetailID: base64.StdEncoding.EncodeToString(conversationDetailIDCiphertext), |
|
|
Admin: base64.StdEncoding.EncodeToString(adminCiphertext), |
|
|
Admin: base64.StdEncoding.EncodeToString(adminCiphertext), |
|
@ -161,19 +160,19 @@ func seedUserConversation( |
|
|
), |
|
|
), |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
err = Database.CreateUserConversation(&messageThreadUser) |
|
|
|
|
|
|
|
|
err = (&messageThreadUser).CreateUserConversation() |
|
|
return messageThreadUser, err |
|
|
return messageThreadUser, err |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func seedConversationDetailUser( |
|
|
func seedConversationDetailUser( |
|
|
user Models.User, |
|
|
|
|
|
conversationDetail Models.ConversationDetail, |
|
|
|
|
|
|
|
|
user Database.User, |
|
|
|
|
|
conversationDetail Database.ConversationDetail, |
|
|
associationKey uuid.UUID, |
|
|
associationKey uuid.UUID, |
|
|
admin bool, |
|
|
admin bool, |
|
|
key AesKey, |
|
|
key AesKey, |
|
|
) (Models.ConversationDetailUser, error) { |
|
|
|
|
|
|
|
|
) (Database.ConversationDetailUser, error) { |
|
|
var ( |
|
|
var ( |
|
|
conversationDetailUser Models.ConversationDetailUser |
|
|
|
|
|
|
|
|
conversationDetailUser Database.ConversationDetailUser |
|
|
|
|
|
|
|
|
userIDCiphertext []byte |
|
|
userIDCiphertext []byte |
|
|
usernameCiphertext []byte |
|
|
usernameCiphertext []byte |
|
@ -215,7 +214,7 @@ func seedConversationDetailUser( |
|
|
return conversationDetailUser, err |
|
|
return conversationDetailUser, err |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
conversationDetailUser = Models.ConversationDetailUser{ |
|
|
|
|
|
|
|
|
conversationDetailUser = Database.ConversationDetailUser{ |
|
|
ConversationDetailID: conversationDetail.ID, |
|
|
ConversationDetailID: conversationDetail.ID, |
|
|
UserID: base64.StdEncoding.EncodeToString(userIDCiphertext), |
|
|
UserID: base64.StdEncoding.EncodeToString(userIDCiphertext), |
|
|
Username: base64.StdEncoding.EncodeToString(usernameCiphertext), |
|
|
Username: base64.StdEncoding.EncodeToString(usernameCiphertext), |
|
@ -224,7 +223,7 @@ func seedConversationDetailUser( |
|
|
PublicKey: base64.StdEncoding.EncodeToString(publicKeyCiphertext), |
|
|
PublicKey: base64.StdEncoding.EncodeToString(publicKeyCiphertext), |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
err = Database.CreateConversationDetailUser(&conversationDetailUser) |
|
|
|
|
|
|
|
|
err = (&conversationDetailUser).CreateConversationDetailUser() |
|
|
|
|
|
|
|
|
return conversationDetailUser, err |
|
|
return conversationDetailUser, err |
|
|
} |
|
|
} |
|
@ -232,11 +231,11 @@ func seedConversationDetailUser( |
|
|
// SeedMessages seeds messages & conversations for testing
|
|
|
// SeedMessages seeds messages & conversations for testing
|
|
|
func SeedMessages() { |
|
|
func SeedMessages() { |
|
|
var ( |
|
|
var ( |
|
|
conversationDetail Models.ConversationDetail |
|
|
|
|
|
|
|
|
conversationDetail Database.ConversationDetail |
|
|
key AesKey |
|
|
key AesKey |
|
|
primaryUser Models.User |
|
|
|
|
|
|
|
|
primaryUser Database.User |
|
|
primaryUserAssociationKey uuid.UUID |
|
|
primaryUserAssociationKey uuid.UUID |
|
|
secondaryUser Models.User |
|
|
|
|
|
|
|
|
secondaryUser Database.User |
|
|
secondaryUserAssociationKey uuid.UUID |
|
|
secondaryUserAssociationKey uuid.UUID |
|
|
i int |
|
|
i int |
|
|
err error |
|
|
err error |
|
|