mirror of
https://git.mills.io/saltyim/saltyim.git
synced 2024-06-28 09:41:02 +00:00
![James Mills](/assets/img/avatar_default.png)
Alternative to #177 The way this works is: Client: - Client creates a normal `net/http.Request{}` object using the `Request()` function in `utils.go`. The `http.Request{}` object is then signed using the Client's Ed25519 private key. - The HTTP Method and Path (_note this is important_) are hashed, as well as the request body (if any) using the FNV128a hashing algorithm. - This hash is then signed by the Client's's Ed25519 private key. - The resulting signature is then encoded to Base64 (_standard encoding_) and added to the HTTP headers as a `Signature:` header. - In addition the Client's Ed25519 public key is added to the HTTP headers as `Signer:` Server: - The server calculates the same FNV128a hash of the HTTP Request Method and Path and the body (if any) - The server decodes the HTTP header `Signature:` - The server then uses the Client's Ed25519 public key in the HTTP header `Signer:` to verify the signature of the `Signature:` HTTP header which gives us back the original FNV128a hash the Client calculated for the request. - The server then compares the Client's hash with the expected hash to see if they compare equally. Co-authored-by: James Mills <1290234+prologic@users.noreply.github.com> Co-authored-by: Jon Lundy <jon@xuu.cc> Reviewed-on: https://git.mills.io/saltyim/saltyim/pulls/178 Reviewed-by: xuu <xuu@noreply@mills.io>
56 lines
972 B
Go
56 lines
972 B
Go
package internal
|
|
|
|
import (
|
|
"git.mills.io/prologic/bitcask"
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
type bitcaskStore struct {
|
|
db *bitcask.Bitcask
|
|
}
|
|
|
|
func newBitcaskStore(path string) (*bitcaskStore, error) {
|
|
db, err := bitcask.Open(
|
|
path,
|
|
bitcask.WithMaxKeySize(256),
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &bitcaskStore{db: db}, nil
|
|
}
|
|
|
|
// Sync ...
|
|
func (bs *bitcaskStore) Sync() error {
|
|
return bs.db.Sync()
|
|
}
|
|
|
|
// Close ...
|
|
func (bs *bitcaskStore) Close() error {
|
|
log.Info("syncing store ...")
|
|
if err := bs.db.Sync(); err != nil {
|
|
log.WithError(err).Error("error syncing store")
|
|
return err
|
|
}
|
|
|
|
log.Info("closing store ...")
|
|
if err := bs.db.Close(); err != nil {
|
|
log.WithError(err).Error("error closing store")
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// Merge ...
|
|
func (bs *bitcaskStore) Merge() error {
|
|
log.Info("merging store ...")
|
|
if err := bs.db.Merge(); err != nil {
|
|
log.WithError(err).Error("error merging store")
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|