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

SP: Add capability to provide intermediate certs #178

Merged
merged 2 commits into from
Oct 29, 2019
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
2 changes: 2 additions & 0 deletions samlsp/samlsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Options struct {
Key *rsa.PrivateKey
Logger logger.Interface
Certificate *x509.Certificate
Intermediates []*x509.Certificate
AllowIDPInitiated bool
IDPMetadata *saml.EntityDescriptor
IDPMetadataURL *url.URL
Expand Down Expand Up @@ -57,6 +58,7 @@ func New(opts Options) (*Middleware, error) {
Key: opts.Key,
Logger: logr,
Certificate: opts.Certificate,
Intermediates: opts.Intermediates,
MetadataURL: *metadataURL,
AcsURL: *acsURL,
IDPMetadata: opts.IDPMetadata,
Expand Down
9 changes: 7 additions & 2 deletions service_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type ServiceProvider struct {

// Certificate is the RSA public part of Key.
Certificate *x509.Certificate
Intermediates []*x509.Certificate

// MetadataURL is the full URL to the metadata endpoint on this host,
// i.e. https://example.com/saml/metadata
Expand Down Expand Up @@ -112,6 +113,10 @@ func (sp *ServiceProvider) Metadata() *EntityDescriptor {
authnRequestsSigned := false
wantAssertionsSigned := true
validUntil := TimeNow().Add(validDuration)
certBytes := sp.Certificate.Raw
for _, intermediate := range sp.Intermediates {
certBytes = append(certBytes, intermediate.Raw...)
}
return &EntityDescriptor{
EntityID: sp.MetadataURL.String(),
ValidUntil: validUntil,
Expand All @@ -125,13 +130,13 @@ func (sp *ServiceProvider) Metadata() *EntityDescriptor {
{
Use: "signing",
KeyInfo: KeyInfo{
Certificate: base64.StdEncoding.EncodeToString(sp.Certificate.Raw),
Certificate: base64.StdEncoding.EncodeToString(certBytes),
},
},
{
Use: "encryption",
KeyInfo: KeyInfo{
Certificate: base64.StdEncoding.EncodeToString(sp.Certificate.Raw),
Certificate: base64.StdEncoding.EncodeToString(certBytes),
},
EncryptionMethods: []EncryptionMethod{
{Algorithm: "http://www.w3.org/2001/04/xmlenc#aes128-cbc"},
Expand Down