-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
got changes to a point of no errors - need to test functionality with
witness Signed-off-by: chaosinthecrd <[email protected]>
- Loading branch information
1 parent
23519fa
commit 3a873b2
Showing
6 changed files
with
112 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,58 @@ | ||
package dsse | ||
|
||
import ( | ||
"crypto" | ||
"fmt" | ||
|
||
"github.com/in-toto/go-witness/cryptoutil" | ||
"github.com/in-toto/go-witness/signature/envelope" | ||
|
||
// Eventually we will migrate to using github.com/securesystemslab/dsse | ||
// but for now it doesn't support timestamps and intermediates | ||
idsse "github.com/in-toto/go-witness/dsse" | ||
) | ||
|
||
type DSSEEnvelope struct { | ||
type Envelope struct { | ||
Envelope *idsse.Envelope | ||
} | ||
|
||
func (e *DSSEEnvelope) Sign(signer *crypto.Signer, opts ...cryptoutil.SignerOption) (interface{}, error) { | ||
func (e *Envelope) Sign(signer *cryptoutil.Signer) error { | ||
if e.Envelope.PayloadType == "" || e.Envelope.Payload == "" { | ||
return nil, fmt.Errorf("PayloadType and Payload not populated correctly") | ||
return fmt.Errorf("PayloadType and Payload not populated correctly") | ||
} | ||
|
||
s, err := cryptoutil.NewSigner(signer, opts...) | ||
se, err := idsse.Sign(e.Envelope.PayloadType, []byte(e.Envelope.Payload), idsse.SignWithSigners(*signer)) | ||
if err != nil { | ||
return nil, err | ||
return err | ||
} | ||
|
||
se, err := idsse.Sign(e.Envelope.PayloadType, []byte(e.Envelope.Payload), idsse.SignWithSigners(s)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
e.Envelope = &se | ||
|
||
return se, nil | ||
return nil | ||
} | ||
|
||
func (e *DSSEEnvelope) Verify(pub *crypto.PublicKey, opts ...cryptoutil.VerifierOption) (interface{}, error) { | ||
v, err := cryptoutil.NewVerifier(pub, opts...) | ||
func (e *Envelope) Verify(v *cryptoutil.Verifier) error { | ||
_, err := e.Envelope.Verify(idsse.VerifyWithVerifiers(*v)) | ||
if err != nil { | ||
return nil, err | ||
return err | ||
} | ||
|
||
ve, err := e.Envelope.Verify(idsse.VerifyWithVerifiers(v)) | ||
if err != nil { | ||
return nil, err | ||
return nil | ||
} | ||
|
||
func (e *Envelope) Content() (*envelope.EnvelopeContent, error) { | ||
env := envelope.EnvelopeContent{} | ||
env.Payload = e.Envelope.Payload | ||
env.PayloadType = e.Envelope.PayloadType | ||
for _, sig := range e.Envelope.Signatures { | ||
s := envelope.SignatureInfo{ | ||
KeyID: sig.KeyID, | ||
Signature: sig.Signature, | ||
Certificate: sig.Certificate, | ||
Intermediates: sig.Intermediates, | ||
} | ||
|
||
env.Signatures = append(env.Signatures, s) | ||
} | ||
|
||
return ve, nil | ||
return &env, nil | ||
} | ||
|
||
func (e *DSSEEnvelope) Content() (interface{}, error) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters