Documentation
¶
Overview ¶
Package replidentity provides verification utilities for Repl Identity tokens.
Example ¶
identity := os.Getenv("REPL_IDENTITY") if identity == "" { fmt.Println("Sorry, this repl does not yet have an identity (anonymous run?).") return } identityKey := os.Getenv("REPL_IDENTITY_KEY") if identity == "" { fmt.Println("Sorry, this repl does not yet have an identity (anonymous run?).") return } // This should be set to the Repl ID of the repl you want to prove your // identity to. targetRepl := "target_repl" // Create a signing authority that is authorized to emit tokens for the // current repl. signingAuthority, err := replidentity.NewSigningAuthority( string(identityKey), identity, os.Getenv("REPL_ID"), replidentity.ReadPublicKeyFromEnv, ) if err != nil { panic(err) } signedToken, err := signingAuthority.Sign(targetRepl) if err != nil { panic(err) } // Verify the signed token, pretending we are the target repl. replIdentity, err := replidentity.VerifyIdentity( signedToken, targetRepl, replidentity.ReadPublicKeyFromEnv, ) if err != nil { panic(err) } fmt.Println() fmt.Printf("The identity in the repl's token (%d bytes) is:\n", len(identity)) fmt.Printf( "repl id: %s\n user: %s\n slug: %s audience: %s\n", replIdentity.Replid, replIdentity.User, replIdentity.Slug, replIdentity.Aud, )
Output:
Index ¶
- func CreateIdentityTokenAddressedTo(audience string) (string, error)
- func ReadPublicKeyFromEnv(keyid, issuer string) (ed25519.PublicKey, error)
- func VerifyIdentity(message string, audience string, getPubKey PubKeySource) (*api.GovalReplIdentity, error)
- func VerifyIdentityWithSource(message string, audience string, sourceReplid string, getPubKey PubKeySource) (*api.GovalReplIdentity, error)
- type MessageClaims
- type PubKeySource
- type SigningAuthority
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateIdentityTokenAddressedTo ¶ added in v0.0.2
CreateIdentityTokenAddressedTo returns a Replit identity token that proves this Repl's identity that includes an audience claim to restrict forwarding. It creates a new signing authority each time, which can be slow. If you plan on signing multiple tokens, use CreateIdentityTokenSigningAuthority() to create an authority to sign with.
func ReadPublicKeyFromEnv ¶
ReadPublicKeyFromEnv provides a PubKeySource that reads public keys from the `REPL_PUBKEYS` environment variable that is present in all repls.
func VerifyIdentity ¶
func VerifyIdentity(message string, audience string, getPubKey PubKeySource) (*api.GovalReplIdentity, error)
VerifyIdentity verifies that the given `REPL_IDENTITY` value is in fact signed by Goval's chain of authority, and addressed to the provided audience (the `REPL_ID` of the recipient).
func VerifyIdentityWithSource ¶ added in v0.0.5
func VerifyIdentityWithSource(message string, audience string, sourceReplid string, getPubKey PubKeySource) (*api.GovalReplIdentity, error)
VerifyIdentityWithSource verifies that the given `REPL_IDENTITY` value is in fact signed by Goval's chain of authority, and addressed to the provided audience (the `REPL_ID` of the recipient). It also verifies that the identity's origin replID matches the given source, if present. This can be used to enforce specific clients in servers when verifying identities.
Types ¶
type MessageClaims ¶
type MessageClaims struct { Repls map[string]struct{} Users map[string]struct{} Clusters map[string]struct{} Flags map[api.FlagClaim]struct{} }
MessageClaims is a collection of indexable claims that are made by a certificate.
type PubKeySource ¶
PubKeySource provides an interface for looking up an [ed25519.PublicKey] from some external source.
type SigningAuthority ¶
type SigningAuthority struct {
// contains filtered or unexported fields
}
SigningAuthority can generate tokens that prove the identity of one repl (your own) against another repl (the audience). Use this to prevent the target repl from spoofing your own identity by forwarding the token.
func CreateIdentityTokenSigningAuthority ¶ added in v0.0.2
func CreateIdentityTokenSigningAuthority() (*SigningAuthority, error)
CreateIdentityTokenSigningAuthority creates a signing authority with this repl's identity key.
func NewSigningAuthority ¶
func NewSigningAuthority( marshaledPrivateKey, marshaledIdentity string, replid string, getPubKey PubKeySource, ) (*SigningAuthority, error)
NewSigningAuthority returns a new SigningAuthority given the marshaled private key (obtained from the `REPL_IDENTITY_KEY` environment variable), the identity token (obtained from the `REPL_IDENTITY` environment variable), the current Repl ID (obtained from the `REPL_ID` environment varaible), and the source of public keys (typically ReadPublicKeyFromEnv).
func (*SigningAuthority) Sign ¶
func (a *SigningAuthority) Sign(audience string) (string, error)
Sign generates a new token that can be given to the provided audience, and is resistant against forwarding, so that the recipient cannot forward this token to another repl and claim it came directly from you.
Directories
¶
Path | Synopsis |
---|---|
Package paserk contains implementations of [PASERK](https://github.com/paseto-standard/paserk), an extension to PASETO that allows for key sharing.
|
Package paserk contains implementations of [PASERK](https://github.com/paseto-standard/paserk), an extension to PASETO that allows for key sharing. |