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

feat: add support for saml encrypted assertions #1752

Merged
merged 1 commit into from
Sep 2, 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
6 changes: 2 additions & 4 deletions internal/api/saml.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,14 @@ func (a *API) SAMLMetadata(w http.ResponseWriter, r *http.Request) error {
}
}

// don't advertize the encryption keys as it makes it much difficult to debug
// requests / responses, and does not increase security since assertions are
// not "private" and not necessary to be hidden from the browser
for i := range metadata.SPSSODescriptors {
spd := &metadata.SPSSODescriptors[i]

var keyDescriptors []saml.KeyDescriptor

for _, kd := range spd.KeyDescriptors {
hf marked this conversation as resolved.
Show resolved Hide resolved
if kd.Use == "signing" {
// only advertize key as usable for encryption if allowed
if kd.Use == "signing" || (a.config.SAML.AllowEncryptedAssertions && kd.Use == "encryption") {
keyDescriptors = append(keyDescriptors, kd)
}
}
Expand Down
5 changes: 5 additions & 0 deletions internal/conf/saml.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
type SAMLConfiguration struct {
Enabled bool `json:"enabled"`
PrivateKey string `json:"-" split_words:"true"`
AllowEncryptedAssertions bool `json:"allow_encrypted_assertions" split_words:"true"`
RelayStateValidityPeriod time.Duration `json:"relay_state_validity_period" split_words:"true"`

RSAPrivateKey *rsa.PrivateKey `json:"-"`
Expand Down Expand Up @@ -111,6 +112,10 @@ func (c *SAMLConfiguration) PopulateFields(externalURL string) error {
},
}

if c.AllowEncryptedAssertions {
certTemplate.KeyUsage = certTemplate.KeyUsage | x509.KeyUsageDataEncipherment
}

certDer, err := x509.CreateCertificate(nil, certTemplate, certTemplate, c.RSAPublicKey, c.RSAPrivateKey)
if err != nil {
return err
Expand Down
Loading