Skip to content
This repository has been archived by the owner on Apr 28, 2023. It is now read-only.

Commit

Permalink
Add jws encoding built-in functions
Browse files Browse the repository at this point in the history
fixes open-policy-agent#1174

Signed-off-by: repenno <[email protected]>
  • Loading branch information
BenderScript authored and tsandall committed Jul 16, 2019
1 parent 15725be commit a4b1a12
Show file tree
Hide file tree
Showing 50 changed files with 54 additions and 167 deletions.
2 changes: 1 addition & 1 deletion glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ import:
- package: golang.org/x/lint
subpackages:
- golint
- package: github.com/repenno/jwx-opa
-
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package jwa

import (
"crypto/elliptic"
"github.com/repenno/jwx-opa/buffer"
"github.com/open-policy-agent/opa/topdown/internal/jwx/buffer"
)

// EllipticCurve provides a indirect type to standard elliptic curve such that we can
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"crypto/elliptic"
"math/big"

"github.com/open-policy-agent/opa/topdown/internal/jwx/jwa"
"github.com/pkg/errors"
"github.com/repenno/jwx-opa/jwa"
)

func newECDSAPublicKey(key *ecdsa.PublicKey) (*ECDSAPublicKey, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import (
"crypto/rand"
"encoding/json"
"fmt"
"github.com/repenno/jwx-opa/buffer"
"github.com/open-policy-agent/opa/topdown/internal/jwx/buffer"
"github.com/open-policy-agent/opa/topdown/internal/jwx/jwa"
"github.com/open-policy-agent/opa/topdown/internal/jwx/jwk"
"reflect"
"testing"

"github.com/repenno/jwx-opa/jwa"
"github.com/repenno/jwx-opa/jwk"
)

func TestECDSA(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package jwk

import (
"github.com/open-policy-agent/opa/topdown/internal/jwx/jwa"
"github.com/pkg/errors"
"github.com/repenno/jwx-opa/jwa"
)

// Convenience constants for common JWK parameters
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package jwk_test

import (
"github.com/open-policy-agent/opa/topdown/internal/jwx/jwa"
"github.com/open-policy-agent/opa/topdown/internal/jwx/jwk"
"reflect"
"testing"

"github.com/repenno/jwx-opa/jwa"
"github.com/repenno/jwx-opa/jwk"
)

func TestHeader(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package jwk
import (
"crypto/ecdsa"
"crypto/rsa"
"github.com/repenno/jwx-opa/jwa"
"github.com/open-policy-agent/opa/topdown/internal/jwx/jwa"
)

// Set is a convenience struct to allow generating and parsing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import (
"crypto/ecdsa"
"crypto/rsa"
"encoding/json"

"github.com/open-policy-agent/opa/topdown/internal/jwx/jwa"
"github.com/pkg/errors"
"github.com/repenno/jwx-opa/jwa"
)

// GetPublicKey returns the public key based on the private key type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package jwk_test
import (
"testing"

"github.com/repenno/jwx-opa/jwk"
"github.com/open-policy-agent/opa/topdown/internal/jwx/jwk"
)

func TestNew(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const (
KeyOpDeriveBits = "deriveBits" // (derive bits not to be used as a key)
)

// Accept determines if Key Operation is valid
func (keyOperationList *KeyOperationList) Accept(v interface{}) error {
switch x := v.(type) {
case KeyOperationList:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"crypto/rsa"
"math/big"

"github.com/open-policy-agent/opa/topdown/internal/jwx/jwa"
"github.com/pkg/errors"
"github.com/repenno/jwx-opa/jwa"
)

func newRSAPublicKey(key *rsa.PublicKey) (*RSAPublicKey, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/repenno/jwx-opa/jwa"
"testing"

"github.com/repenno/jwx-opa/jwk"
"github.com/open-policy-agent/opa/topdown/internal/jwx/jwa"
"github.com/open-policy-agent/opa/topdown/internal/jwx/jwk"
)

func TestRSA(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package jwk

import (
"github.com/open-policy-agent/opa/topdown/internal/jwx/jwa"
"github.com/pkg/errors"
"github.com/repenno/jwx-opa/jwa"
)

func newSymmetricKey(key []byte) (*SymmetricKey, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"reflect"
"testing"

"github.com/repenno/jwx-opa/jwa"
"github.com/repenno/jwx-opa/jwk"
"github.com/open-policy-agent/opa/topdown/internal/jwx/jwa"
"github.com/open-policy-agent/opa/topdown/internal/jwx/jwk"
)

func TestSymmetric(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package jws

import (
"github.com/open-policy-agent/opa/topdown/internal/jwx/jwa"
"github.com/pkg/errors"
"github.com/repenno/jwx-opa/jwa"
)

// Constants for JWS Common parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package jws_test

import (
"encoding/json"
"github.com/repenno/jwx-opa/jwa"
"github.com/repenno/jwx-opa/jws"
"reflect"
"testing"

"github.com/open-policy-agent/opa/topdown/internal/jwx/jwa"
"github.com/open-policy-agent/opa/topdown/internal/jwx/jws"
)

func TestHeader(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ import (
"bytes"
"encoding/base64"
"encoding/json"
"github.com/open-policy-agent/opa/topdown/internal/jwx/jwa"
"github.com/open-policy-agent/opa/topdown/internal/jwx/jwk"
"github.com/open-policy-agent/opa/topdown/internal/jwx/jws/sign"
"github.com/open-policy-agent/opa/topdown/internal/jwx/jws/verify"
"strings"

"github.com/pkg/errors"
"github.com/repenno/jwx-opa/jwa"
"github.com/repenno/jwx-opa/jwk"
"github.com/repenno/jwx-opa/jws/sign"
"github.com/repenno/jwx-opa/jws/verify"
)

// SignLiteral generates a Signature for the given Payload and Headers, and serializes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ import (
"crypto/sha512"
"encoding/base64"
"encoding/json"
"github.com/open-policy-agent/opa/topdown/internal/jwx/jwa"
"github.com/open-policy-agent/opa/topdown/internal/jwx/jwk"
"github.com/open-policy-agent/opa/topdown/internal/jwx/jws"
"github.com/open-policy-agent/opa/topdown/internal/jwx/jws/sign"
"github.com/open-policy-agent/opa/topdown/internal/jwx/jws/verify"
"math/big"
"strings"
"testing"

"github.com/repenno/jwx-opa/jwa"
"github.com/repenno/jwx-opa/jwk"
"github.com/repenno/jwx-opa/jws"
"github.com/repenno/jwx-opa/jws/sign"
"github.com/repenno/jwx-opa/jws/verify"
)

const examplePayload = `{"iss":"joe",` + "\r\n" + ` "exp":1300819380,` + "\r\n" + ` "http://example.com/is_root":true}`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"crypto"
"crypto/ecdsa"
"crypto/rand"
"github.com/open-policy-agent/opa/topdown/internal/jwx/jwa"

"github.com/pkg/errors"
"github.com/repenno/jwx-opa/jwa"
)

var ecdsaSignFuncs = map[jwa.SignatureAlgorithm]ecdsaSignFunc{}
Expand All @@ -29,7 +29,7 @@ func makeECDSASignFunc(hash crypto.Hash) ecdsaSignFunc {
keyBytes := curveBits / 8
// Curve bits do not need to be a multiple of 8.
if curveBits%8 > 0 {
keyBytes += 1
keyBytes++
}
h := hash.New()
h.Write(payload)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package sign

import (
"github.com/repenno/jwx-opa/jwa"
"github.com/open-policy-agent/opa/topdown/internal/jwx/jwa"
"testing"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"crypto/hmac"
"crypto/sha256"
"crypto/sha512"
"github.com/open-policy-agent/opa/topdown/internal/jwx/jwa"
"hash"

"github.com/pkg/errors"
"github.com/repenno/jwx-opa/jwa"
)

var hmacSignFuncs = map[jwa.SignatureAlgorithm]hmacSignFunc{}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package sign

import (
"github.com/repenno/jwx-opa/jwa"
"github.com/open-policy-agent/opa/topdown/internal/jwx/jwa"
"testing"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ package sign
import (
"crypto/ecdsa"
"crypto/rsa"

"github.com/repenno/jwx-opa/jwa"
"github.com/open-policy-agent/opa/topdown/internal/jwx/jwa"
)

// Signer provides a common interface for supported alg signing methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"crypto"
"crypto/rand"
"crypto/rsa"
"github.com/open-policy-agent/opa/topdown/internal/jwx/jwa"

"github.com/pkg/errors"
"github.com/repenno/jwx-opa/jwa"
)

var rsaSignFuncs = map[jwa.SignatureAlgorithm]rsaSignFunc{}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package sign

import (
"github.com/open-policy-agent/opa/topdown/internal/jwx/jwa"
"github.com/pkg/errors"
"github.com/repenno/jwx-opa/jwa"
)

// New creates a signer that signs payloads using the given signature algorithm.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"crypto/ecdsa"
"math/big"

"github.com/open-policy-agent/opa/topdown/internal/jwx/jwa"
"github.com/pkg/errors"
"github.com/repenno/jwx-opa/jwa"
)

var ecdsaVerifyFuncs = map[jwa.SignatureAlgorithm]ecdsaVerifyFunc{}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package verify

import (
"github.com/repenno/jwx-opa/jwa"
"github.com/open-policy-agent/opa/topdown/internal/jwx/jwa"
"testing"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package verify

import (
"crypto/hmac"
"github.com/open-policy-agent/opa/topdown/internal/jwx/jwa"
"github.com/open-policy-agent/opa/topdown/internal/jwx/jws/sign"
"github.com/pkg/errors"
"github.com/repenno/jwx-opa/jwa"
"github.com/repenno/jwx-opa/jws/sign"
)

func newHMAC(alg jwa.SignatureAlgorithm) (*HMACVerifier, error) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package verify

import (
"github.com/repenno/jwx-opa/jwa"
"github.com/open-policy-agent/opa/topdown/internal/jwx/jwa"
"testing"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ package verify
import (
"crypto/ecdsa"
"crypto/rsa"

"github.com/repenno/jwx-opa/jws/sign"
"github.com/open-policy-agent/opa/topdown/internal/jwx/jws/sign"
)

// Verifier provides a common interface for supported alg verification methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package verify
import (
"crypto"
"crypto/rsa"
"github.com/open-policy-agent/opa/topdown/internal/jwx/jwa"

"github.com/pkg/errors"
"github.com/repenno/jwx-opa/jwa"
)

var rsaVerifyFuncs = map[jwa.SignatureAlgorithm]rsaVerifyFunc{}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package verify

import (
"github.com/repenno/jwx-opa/jwa"
"github.com/open-policy-agent/opa/topdown/internal/jwx/jwa"
"testing"
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package verify

import (
"github.com/open-policy-agent/opa/topdown/internal/jwx/jwa"
"github.com/pkg/errors"
"github.com/repenno/jwx-opa/jwa"
)

// New creates a new JWS verifier using the specified algorithm
Expand Down
4 changes: 2 additions & 2 deletions topdown/tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import (
"encoding/json"
"encoding/pem"
"fmt"
"github.com/repenno/jwx-opa/jwk"
"github.com/repenno/jwx-opa/jws"
"math/big"
"strconv"
"strings"
Expand All @@ -26,6 +24,8 @@ import (

"github.com/open-policy-agent/opa/ast"
"github.com/open-policy-agent/opa/topdown/builtins"
"github.com/open-policy-agent/opa/topdown/internal/jwx/jwk"
"github.com/open-policy-agent/opa/topdown/internal/jwx/jws"
)

var (
Expand Down
Loading

0 comments on commit a4b1a12

Please sign in to comment.