Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify Chain of Trust #101

Open
jordan-rash opened this issue Mar 23, 2023 · 0 comments
Open

Verify Chain of Trust #101

jordan-rash opened this issue Mar 23, 2023 · 0 comments

Comments

@jordan-rash
Copy link
Contributor

In an attempt to better understand the NATs ecosystem, I wanted to programmatically verify the Chain of Trust between the operator, account, and user JWTs. I am using the code below, I am happy to open a PR if this is a valuable example

func main() {
	resolverServer := "http://localhost:9090/jwt/v1"

	claims, _ := jwt.Decode(userJWT) // userJWT provided by user
	url := fmt.Sprintf("%s/accounts/%s", accountServer, claims.Claims().Issuer)
	resp, _ := http.Get(url)
	acctJWT, _ := ioutil.ReadAll(resp.Body)
	resp.Body.Close()

	url = fmt.Sprintf("%s/operator", accountServer)
	resp, _ = http.Get(url)
	opJWT, _ := ioutil.ReadAll(resp.Body)
	resp.Body.Close()

	opc, _ := jwt.DecodeOperatorClaims(string(opJWT))

	acct, _ := jwt.Decode(string(acctJWT))
	aopc, _ := jwt.DecodeAccountClaims(string(acctJWT))
    
        // Does account JWT issuer match operator public key and did the operator public key sign the account JWT
	if aopc.Issuer == opPub && opc.DidSign(acct) { // opPub -> operator public which is const at top of file
		fmt.Println(aopc.DidSign(claims))
	} else {
		log.Fatal("chain of trust not valid")
	}
        log.Print("chain of trust verified")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant