Encrypted messaging app
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
2.0 KiB

package Seeder
import (
"encoding/base64"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Api/Auth"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Database"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
)
var userNames = []string{
"assuredcoot",
"quotesteeve",
"blueberriessiemens",
"eliteexaggerate",
"twotrice",
"moderagged",
"duleelderly",
"stringdetailed",
"nodesanymore",
"sacredpolitical",
"pajamasenergy",
}
func createUser(username string) (Models.User, error) {
var (
userData Models.User
key aesKey
publicUserData Models.Friend
password string
usernameCiphertext []byte
err error
)
password, err = Auth.HashPassword("password")
if err != nil {
return Models.User{}, err
}
key, err = generateAesKey()
if err != nil {
return Models.User{}, err
}
usernameCiphertext, err = key.aesEncrypt([]byte(username))
if err != nil {
return Models.User{}, err
}
publicUserData = Models.Friend{
Username: base64.StdEncoding.EncodeToString(usernameCiphertext),
AsymmetricPublicKey: publicKey,
}
err = Database.CreateFriend(&publicUserData)
if err != nil {
return userData, err
}
userData = Models.User{
Username: username,
Password: password,
AsymmetricPrivateKey: encryptedPrivateKey,
AsymmetricPublicKey: publicKey,
FriendID: base64.StdEncoding.EncodeToString(
encryptWithPublicKey(
[]byte(publicUserData.ID.String()),
decodedPublicKey,
),
),
FriendSymmetricKey: base64.StdEncoding.EncodeToString(
encryptWithPublicKey(key.Key, decodedPublicKey),
),
}
err = Database.CreateUser(&userData)
return userData, err
}
func SeedUsers() {
var (
i int
err error
)
// Seed users used for conversation seeding
_, err = createUser("testUser")
if err != nil {
panic(err)
}
_, err = createUser("ATestUser2")
if err != nil {
panic(err)
}
for i = 0; i <= 10; i++ {
_, err = createUser(userNames[i])
if err != nil {
panic(err)
}
}
}