aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Database.go34
-rw-r--r--activityPubStruct.go7
-rw-r--r--databaseschema.psql3
-rw-r--r--main.go5
-rw-r--r--verification.go4
5 files changed, 40 insertions, 13 deletions
diff --git a/Database.go b/Database.go
index f10ae12..3e890dd 100644
--- a/Database.go
+++ b/Database.go
@@ -12,7 +12,7 @@ import "sort"
func GetActorFromDB(db *sql.DB, id string) Actor {
var nActor Actor
- query :=`select type, id, name, preferedusername, inbox, outbox, following, followers, restricted, summary from actor where id=$1`
+ query :=`select type, id, name, preferedusername, inbox, outbox, following, followers, restricted, summary, publickeypem from actor where id=$1`
rows, err := db.Query(query, id)
@@ -20,19 +20,22 @@ func GetActorFromDB(db *sql.DB, id string) Actor {
return nActor
}
- defer rows.Close()
+ var publicKeyPem string
+ defer rows.Close()
for rows.Next() {
- err = rows.Scan(&nActor.Type, &nActor.Id, &nActor.Name, &nActor.PreferredUsername, &nActor.Inbox, &nActor.Outbox, &nActor.Following, &nActor.Followers, &nActor.Restricted, &nActor.Summary)
+ err = rows.Scan(&nActor.Type, &nActor.Id, &nActor.Name, &nActor.PreferredUsername, &nActor.Inbox, &nActor.Outbox, &nActor.Following, &nActor.Followers, &nActor.Restricted, &nActor.Summary, &publicKeyPem)
CheckError(err, "error with actor from db scan ")
}
+ nActor.PublicKey = GetActorPemFromDB(db, publicKeyPem)
+
return nActor
}
func GetActorByNameFromDB(db *sql.DB, name string) Actor {
var nActor Actor
- query :=`select type, id, name, preferedusername, inbox, outbox, following, followers, restricted, summary from actor where name=$1`
+ query :=`select type, id, name, preferedusername, inbox, outbox, following, followers, restricted, summary, publickeypem from actor where name=$1`
rows, err := db.Query(query, name)
@@ -40,12 +43,15 @@ func GetActorByNameFromDB(db *sql.DB, name string) Actor {
return nActor
}
+ var publicKeyPem string
defer rows.Close()
for rows.Next() {
- err = rows.Scan(&nActor.Type, &nActor.Id, &nActor.Name, &nActor.PreferredUsername, &nActor.Inbox, &nActor.Outbox, &nActor.Following, &nActor.Followers, &nActor.Restricted, &nActor.Summary)
+ err = rows.Scan(&nActor.Type, &nActor.Id, &nActor.Name, &nActor.PreferredUsername, &nActor.Inbox, &nActor.Outbox, &nActor.Following, &nActor.Followers, &nActor.Restricted, &nActor.Summary, &publicKeyPem)
CheckError(err, "error with actor from db scan ")
}
+ nActor.PublicKey = GetActorPemFromDB(db, publicKeyPem)
+
return nActor
}
@@ -1208,3 +1214,21 @@ func GetActorReportedDB(db *sql.DB, id string) []ObjectBase {
return nObj
}
+
+func GetActorPemFromDB(db *sql.DB, pemID string) PublicKeyPem {
+ query := `select id, owner, file from publickeypem where id=$1`
+ rows, err := db.Query(query, pemID)
+
+ CheckError(err, "could not get public key pem from database")
+
+ var pem PublicKeyPem
+
+ defer rows.Close()
+ rows.Next()
+ rows.Scan(&pem.Id, &pem.Owner, &pem.PublicKeyPem)
+ f, _ := os.ReadFile(pem.PublicKeyPem)
+
+ pem.PublicKeyPem = strings.ReplaceAll(string(f), "\r\n", `\n`)
+
+ return pem
+}
diff --git a/activityPubStruct.go b/activityPubStruct.go
index 0955b0c..d74ae82 100644
--- a/activityPubStruct.go
+++ b/activityPubStruct.go
@@ -74,11 +74,18 @@ type Actor struct {
Followers string `json:"followers,omitempty"`
Name string `json:"name,omitempty"`
PreferredUsername string `json:"preferredUsername,omitempty"`
+ PublicKey PublicKeyPem `json:"publicKey,omitempty"`
Summary string `json:"summary,omitempty"`
AuthRequirement []string `json:"authrequirement,omitempty"`
Restricted bool `json:"restricted"`
}
+type PublicKeyPem struct {
+ Id string `json:"id,omitempty"`
+ Owner string `json:"owner,omitempty"`
+ PublicKeyPem string `json:"publicKeyPem,omitempty"`
+}
+
type Activity struct {
AtContext
Type string `json:"type,omitempty"`
diff --git a/databaseschema.psql b/databaseschema.psql
index 686e682..a9ede23 100644
--- a/databaseschema.psql
+++ b/databaseschema.psql
@@ -212,7 +212,8 @@ ALTER TABLE cacheactivitystream ADD COLUMN IF NOT EXISTS tripcode varchar(50) de
CREATE TABLE IF NOT EXISTS publicKeyPem(
id varchar(100) UNIQUE,
+owner varchar(100),
file varchar(100)
);
-ALTER TABLE actor ADD COLUMN IF NOT EXISTS publicKeyPem varchar(100) default ''; \ No newline at end of file
+ALTER TABLE actor ADD COLUMN IF NOT EXISTS publicKeyPem varchar(100) default '';
diff --git a/main.go b/main.go
index b38531a..07c6c86 100644
--- a/main.go
+++ b/main.go
@@ -48,11 +48,6 @@ func main() {
RunDatabaseSchema(db)
- CreatePem(db, GetActorByNameFromDB(db, "main"))
-
- f, _ := os.ReadFile("./pem/board/main-public.pem")
- fmt.Println(strings.ReplaceAll(string(f), "\n", `\n`))
-
go MakeCaptchas(db, 100)
*Key = CreateClientKey()
diff --git a/verification.go b/verification.go
index ec64f63..99f5fb7 100644
--- a/verification.go
+++ b/verification.go
@@ -536,7 +536,7 @@ func StorePemToDB(db *sql.DB, actor Actor) {
CheckError(err, "error updating publicKeyPem id to actor")
file := "./pem/board/" + actor.Name + "-public.pem"
- query = "insert into publicKeyPem (id, file) values($1, $2)"
- _, err = db.Exec(query, publicKeyPem, file)
+ query = "insert into publicKeyPem (id, owner, file) values($1, $2, $3)"
+ _, err = db.Exec(query, publicKeyPem, actor.Id, file)
CheckError(err, "error creating publicKeyPem for actor ")
}