Masterthesis
This commit is contained in:
parent
6de476260d
commit
a21bbcca0e
9 changed files with 140 additions and 211 deletions
|
@ -9,7 +9,6 @@ import (
|
|||
|
||||
var DB *sql.DB
|
||||
|
||||
// TODO: Change DB Structure
|
||||
func InitDB(filepath string) (err error) {
|
||||
DB, err = sql.Open("sqlite3", filepath)
|
||||
if err != nil {
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"crypto/ed25519"
|
||||
"crypto/rand"
|
||||
"crypto/sha256"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"git.nutfactory.org/hoernschen/ActivityPub/config"
|
||||
)
|
||||
|
||||
func CreateToken() (err error, token string) {
|
||||
|
@ -33,7 +30,6 @@ func CreateUUID() (err error, uuid string) {
|
|||
return
|
||||
}
|
||||
|
||||
// TODO: Check if needed
|
||||
func Hash(s []byte) (err error, hashString string) {
|
||||
h := sha256.New()
|
||||
_, err = h.Write(s)
|
||||
|
@ -44,33 +40,3 @@ func Hash(s []byte) (err error, hashString string) {
|
|||
hashString = base64.StdEncoding.EncodeToString(hash)
|
||||
return
|
||||
}
|
||||
|
||||
//TODO: Signing Mechanism?
|
||||
func GenerateKeyPair() (publicKey ed25519.PublicKey, privateKey ed25519.PrivateKey, err error) {
|
||||
publicKey, privateKey, err = ed25519.GenerateKey(nil)
|
||||
return
|
||||
}
|
||||
|
||||
func Sign(message []byte) string {
|
||||
signatureBytes := ed25519.Sign(config.PrivateKey, message)
|
||||
return base64.RawStdEncoding.EncodeToString(signatureBytes)
|
||||
}
|
||||
|
||||
func SignContent(content []byte) (signatures map[string]map[string]string) {
|
||||
if !config.Signing {
|
||||
return
|
||||
}
|
||||
signatures = make(map[string]map[string]string)
|
||||
signatures[config.Homeserver] = make(map[string]string)
|
||||
signatures[config.Homeserver][config.KeyId] = Sign(content)
|
||||
return
|
||||
}
|
||||
|
||||
func VerifySignature(publicKey []byte, message []byte, signature string) bool {
|
||||
signatureBytes, err := base64.RawStdEncoding.DecodeString(signature)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
ed25519.Verify(config.PublicKey, message, signatureBytes)
|
||||
return true
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue