forked from bluesky-social/indigo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
handle repository signatures, was more of an adventure than i initial…
…ly thought
- Loading branch information
1 parent
7c05947
commit ab83a33
Showing
23 changed files
with
285 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package indexer | ||
|
||
import ( | ||
"context" | ||
"crypto" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/bluesky-social/indigo/plc" | ||
did "github.com/whyrusleeping/go-did" | ||
) | ||
|
||
type KeyManager struct { | ||
didr plc.PLCClient | ||
|
||
signingKey *did.PrivKey | ||
} | ||
|
||
func NewKeyManager(didr plc.PLCClient, k *did.PrivKey) *KeyManager { | ||
return &KeyManager{ | ||
didr: didr, | ||
signingKey: k, | ||
} | ||
} | ||
|
||
type cachedKey struct { | ||
cachedAt time.Time | ||
pub crypto.PublicKey | ||
} | ||
|
||
func (km *KeyManager) VerifyUserSignature(ctx context.Context, did string, sig []byte, msg []byte) error { | ||
k, err := km.getKey(ctx, did) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return k.Verify(msg, sig) | ||
} | ||
|
||
func (km *KeyManager) getKey(ctx context.Context, did string) (*did.PubKey, error) { | ||
// TODO: caching should be done at the DID document level, that way we can | ||
// have a thing that subscribes to plc updates for cache busting | ||
doc, err := km.didr.GetDocument(ctx, did) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
pubk, err := doc.GetPublicKey("#signingKey") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return pubk, nil | ||
} | ||
|
||
func (km *KeyManager) SignForUser(ctx context.Context, did string, msg []byte) ([]byte, error) { | ||
if km.signingKey == nil { | ||
return nil, fmt.Errorf("key manager does not have a signing key, cannot sign") | ||
} | ||
|
||
return km.signingKey.Sign(msg) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.