-
Notifications
You must be signed in to change notification settings - Fork 18
feat(config): add optional system assertions to TDFConfig #2316
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
Changes from 3 commits
539a641
91ca316
ee84532
57806f5
6ccf7e3
f202235
c144d24
37a5684
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ import ( | |
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"runtime" | ||
"time" | ||
|
||
"github.com/gowebpki/jcs" | ||
"github.com/lestrrat-go/jwx/v2/jwa" | ||
|
@@ -283,3 +285,37 @@ func (k AssertionVerificationKeys) Get(assertionID string) (AssertionKey, error) | |
func (k AssertionVerificationKeys) IsEmpty() bool { | ||
return k.DefaultKey.IsEmpty() && len(k.Keys) == 0 | ||
} | ||
|
||
// GetDefaultAssertionConfig returns a default assertion configuration with predefined values. | ||
func GetDefaultAssertionConfig() AssertionConfig { | ||
// Define the JSON structure | ||
type Metadata struct { | ||
TDFSpecVersion string `json:"TDFSpecVersion"` | ||
CreationDate string `json:"creationDate"` | ||
OS string `json:"OS"` | ||
SDKLang string `json:"sdk"` | ||
} | ||
|
||
// Populate the metadata | ||
metadata := Metadata{ | ||
TDFSpecVersion: TDFSpecVersion, | ||
CreationDate: time.Now().Format(time.RFC3339), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wait, do we not have a GetMetadata function? Which maybe also could error out... |
||
OS: runtime.GOOS, | ||
SDKLang: "Go", | ||
sujankota marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
// Marshal the metadata to JSON | ||
metadataJSON, _ := json.Marshal(metadata) | ||
|
||
return AssertionConfig{ | ||
ID: "default-assertion", | ||
Type: BaseAssertion, | ||
Scope: Paylaod, | ||
AppliesToState: Unencrypted, | ||
Statement: Statement{ | ||
Format: "json", | ||
Schema: "metadata", | ||
Value: string(metadataJSON), | ||
}, | ||
} | ||
Comment on lines
+308
to
+320
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error returned by Consider handling the error by, for example, logging it and defaulting to a valid empty JSON object string like metadataBytes, err := json.Marshal(metadata)
if err != nil {
// It's crucial to log this error for visibility, as it indicates an unexpected issue
// with marshalling a known-simple struct. This could point to deeper system problems
// or future incompatibilities if the Metadata struct evolves.
// e.g., log.Printf("Error marshalling default assertion metadata: %v", err) // Replace with actual logging mechanism
// Defaulting to an empty JSON object to maintain a valid assertion structure.
metadataBytes = []byte("{}")
}
return AssertionConfig{
ID: "default-assertion",
Type: BaseAssertion,
Scope: Paylaod, // This uses the existing constant `Paylaod`
AppliesToState: Unencrypted,
Statement: Statement{
Format: "json",
Schema: "metadata",
Value: string(metadataBytes),
},
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing constexpr. Yeah, if this fails, you should panic IMO. MustMarshall was declined as an extension: golang/go#38519 |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,6 +79,7 @@ type TDFConfig struct { | |
keyType ocrypto.KeyType | ||
useHex bool | ||
excludeVersionFromManifest bool | ||
addDefaultAssertion bool | ||
} | ||
|
||
func newTDFConfig(opt ...TDFOption) (*TDFConfig, error) { | ||
|
@@ -90,6 +91,7 @@ func newTDFConfig(opt ...TDFOption) (*TDFConfig, error) { | |
integrityAlgorithm: HS256, | ||
segmentIntegrityAlgorithm: GMAC, | ||
keyType: ocrypto.RSA2048Key, // default to RSA | ||
addDefaultAssertion: false, | ||
} | ||
|
||
for _, o := range opt { | ||
|
@@ -217,6 +219,14 @@ func WithSegmentSize(size int64) TDFOption { | |
} | ||
} | ||
|
||
// WithDefaultAssertion returns an Option that adds a default assertion to the TDF. | ||
func WithDefaultAssertion() TDFOption { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From the ticket,
So we probably need to allow adding one or more, and also it should be a list or set
strantalis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return func(c *TDFConfig) error { | ||
c.addDefaultAssertion = true | ||
return nil | ||
} | ||
} | ||
|
||
// WithAssertions returns an Option that add assertions to TDF. | ||
func WithAssertions(assertionList ...AssertionConfig) TDFOption { | ||
return func(c *TDFConfig) error { | ||
|
Uh oh!
There was an error while loading. Please reload this page.