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

Empty Disclosure Fix #27

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions sd-jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/MichaelFraser99/go-sd-jwt/disclosure"
e "github.com/MichaelFraser99/go-sd-jwt/internal/error"
"github.com/MichaelFraser99/go-sd-jwt/internal/utils"
"github.com/MichaelFraser99/go-sd-jwt/kbjwt"
"hash"
"slices"
"strings"
"time"

"github.com/MichaelFraser99/go-sd-jwt/disclosure"
e "github.com/MichaelFraser99/go-sd-jwt/internal/error"
"github.com/MichaelFraser99/go-sd-jwt/internal/utils"
"github.com/MichaelFraser99/go-sd-jwt/kbjwt"
)

// SdJwt this object represents a valid SD-JWT. Created using the FromToken function which performs the required validation.
Expand Down Expand Up @@ -247,9 +248,10 @@ func (s *SdJwt) GetDisclosedClaims() (map[string]any, error) {
h.Reset()
}

if len(indexesFound) == 0 {
if len(indexesFound) == 0 && len(disclosuresToCheck) > 0 {
return nil, fmt.Errorf("no matching digest found for: %v", utils.StringifyDisclosures(disclosuresToCheck))
}

slices.Sort(indexesFound)
slices.Reverse(indexesFound)
for _, i := range indexesFound {
Expand Down
22 changes: 20 additions & 2 deletions sd-jwt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"os"
"testing"

"github.com/MichaelFraser99/go-jose/jws"
"github.com/MichaelFraser99/go-jose/model"
go_sd_jwt "github.com/MichaelFraser99/go-sd-jwt"
"github.com/MichaelFraser99/go-sd-jwt/disclosure"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"os"
"testing"
)

func TestMain(m *testing.M) {
Expand Down Expand Up @@ -653,3 +654,20 @@ func TestNew_AllDuplicateDigestScenarios(t *testing.T) {
}
}
}

func TestSDJwtWithoutSD(t *testing.T) {
testJwt := "eyJ0eXAiOiJzZCtqd3QiLCJhbGciOiJFUzI1NiJ9.eyJmaXJzdG5hbWUiOiJKb2huIiwibGFzdG5hbWUiOiJEb2UiLCJzc24iOiIxMjMtNDUtNjc4OSIsImlkIjoiMTIzNCIsIl9zZF9hbGciOiJTSEEtMjU2In0.sUA_aYeA4YNQ1Paxna30VLAce1KdxvYMPEIduCwSD6X_Z56ZrBY5fbUBM5JVQ3vceS86CCghr8wkemdhQYRdfA~"
sdJwt, err := go_sd_jwt.New(testJwt)

if err != nil {
t.Log("Token not parseable")
}

_, err = sdJwt.GetDisclosedClaims()

if err != nil {
t.Log("Token cant survive without Selective Discloures")
t.Error("The token has empty selective disclosure but fails in parsing.")
}

}
Loading