Skip to content

Commit

Permalink
Fix missing manifest error processing
Browse files Browse the repository at this point in the history
  • Loading branch information
Serge Lysenko committed Oct 28, 2022
1 parent 845f74f commit 72a93fb
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func main() {
}

// Sign the signature
signed, err := ctx.Sign(sig)
signed, err := ctx.SignManifest(sig)
if err != nil {
panic(err)
}
Expand Down
17 changes: 15 additions & 2 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestManifestExample(t *testing.T) {
require.NoError(t, err)

// Sign the signature
signed, err := ctx.Sign(sig)
signed, err := ctx.SignManifest(sig)
require.NoError(t, err)

// Validate
Expand All @@ -82,6 +82,19 @@ func TestManifestExample(t *testing.T) {
require.NotEmpty(t, manifest)
}

func TestMissingManifest(t *testing.T) {

// Generate a key and self-signed certificate for signing
randomKeyStore := RandomKeyStoreForTest()
ctx := NewDefaultSigningContext(randomKeyStore)

sig := ctx.CreateSignature("id1234")

// Sign the signature
_, err := ctx.SignManifest(sig)
require.Error(t, err)
}

func TestRecursiveSigning(t *testing.T) {

// Generate a key and self-signed certificate for signing
Expand All @@ -95,7 +108,7 @@ func TestRecursiveSigning(t *testing.T) {
require.NoError(t, err)

// Sign the signature
signed, err := ctx.Sign(sig)
signed, err := ctx.SignManifest(sig)
require.NoError(t, err)

list := &etree.Element{Tag: "Signatures"}
Expand Down
6 changes: 3 additions & 3 deletions sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func (ctx *SigningContext) createNamespacedElement(el *etree.Element, tag string
return child
}

func (ctx *SigningContext) Sign(sig *etree.Element) (*etree.Element, error) {
func (ctx *SigningContext) SignManifest(sig *etree.Element) (*etree.Element, error) {

// First get the default context
rootNSCtx := etreeutils.DefaultNSContext
Expand All @@ -290,8 +290,8 @@ func (ctx *SigningContext) Sign(sig *etree.Element) (*etree.Element, error) {
}

man := sig.FindElementPath(ctx.manifestPath(sig))
if err != nil {
return nil, err
if man == nil {
return nil, errors.New("missing manifest element")
}

manifest, err := etreeutils.NSDetatch(sigNSCtx, man)
Expand Down
2 changes: 1 addition & 1 deletion sign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func TestSignManifest(t *testing.T) {
id := man.SelectAttr(ctx.IdAttribute)
require.NotEmpty(t, id)

signed, err := ctx.Sign(sig)
signed, err := ctx.SignManifest(sig)
require.NoError(t, err)

signedInfo := signed.FindElement("//" + SignedInfoTag)
Expand Down

0 comments on commit 72a93fb

Please sign in to comment.