2017-05-09 00:43:48 +00:00
|
|
|
package sso
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/base64"
|
|
|
|
"encoding/xml"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
dsig "github.com/russellhaering/goxmldsig"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
var testMetadata = `
|
|
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<md:EntityDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata" entityID="https://kolide-dev-ed.my.salesforce.com" validUntil="2027-04-29T19:22:40.750Z" xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
|
|
|
|
<md:IDPSSODescriptor WantAuthnRequestsSigned="false" protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
|
|
|
|
<md:KeyDescriptor use="signing">
|
|
|
|
<ds:KeyInfo>
|
|
|
|
<ds:X509Data>
|
|
|
|
<ds:X509Certificate>MIIErDCCA5SgAwIBAgIOAVuhH3WkAAAAAB5NpvIwDQYJKoZIhvcNAQELBQAwgZAxKDAmBgNVBAMMH1NlbGZTaWduZWRDZXJ0XzI0QXByMjAxN18xODAwNDQxGDAWBgNVBAsMDzAwRDZBMDAwMDAwMTd0ODEXMBUGA1UECgwOU2FsZXNmb3JjZS5jb20xFjAUBgNVBAcMDVNhbiBGcmFuY2lzY28xCzAJBgNVBAgMAkNBMQwwCgYDVQQGEwNVU0EwHhcNMTcwNDI0MTgwMDQ1WhcNMTgwNDI0MTIwMDAwWjCBkDEoMCYGA1UEAwwfU2VsZlNpZ25lZENlcnRfMjRBcHIyMDE3XzE4MDA0NDEYMBYGA1UECwwPMDBENkEwMDAwMDAxN3Q4MRcwFQYDVQQKDA5TYWxlc2ZvcmNlLmNvbTEWMBQGA1UEBwwNU2FuIEZyYW5jaXNjbzELMAkGA1UECAwCQ0ExD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0N7s/MxqCvJCwGA8eJGvOO56I321vhWHQ6ZSJDWUqQFM/Ze7A</ds:X509Certificate>
|
|
|
|
</ds:X509Data>
|
|
|
|
</ds:KeyInfo>
|
|
|
|
</md:KeyDescriptor>
|
|
|
|
<md:NameIDFormat>urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified</md:NameIDFormat>
|
|
|
|
<md:SingleSignOnService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" Location="https://kolide-dev-ed.my.salesforce.com/idp/endpoint/HttpPost"/>
|
|
|
|
<md:SingleSignOnService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect" Location="https://kolide-dev-ed.my.salesforce.com/idp/endpoint/HttpRedirect"/>
|
|
|
|
</md:IDPSSODescriptor>
|
|
|
|
</md:EntityDescriptor>
|
|
|
|
`
|
|
|
|
|
|
|
|
func TestNewValidator(t *testing.T) {
|
|
|
|
v, err := NewValidator(testMetadata)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.NotNil(t, v)
|
|
|
|
}
|
|
|
|
|
|
|
|
var testResponse = `PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48c2FtbHA6UmVzcG9uc2UgeG1sbnM6c2FtbHA9InVybjpvYXNpczpuYW1lczp0YzpTQU1MOjIuMDpwcm90b2NvbCIgRGVzdGluYXRpb249Imh0dHBzOi8vbG9jYWxob3N0OjgwODAvYXBpL3YxL2tvbGlkZS9zc28vY2FsbGJhY2siIElEPSJfYzgyMWM1MmUzZDJkN2NhMjFiMmJlNmJlOTQ4Y2RiYjAxNDkzNTkwMTA2NjM1IiBJblJlc3BvbnNlVG89IjM5MTY5NzllLTNhZTItNGU4My04N2I0LWZlMmViODg0Yjg5MSIgSXNzdWVJbnN0YW50PSIyMDE3LTA0LTMwVDIyOjA4OjI2LjYzNVoiIFZlcnNpb249IjIuMCI+PHNhbWw6SXNzdWVyIHhtbG5zOnNhbWw9InVybjpvYXNpczpuYW1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RGJLaGdaYWtnWk13Z1pBeEtEQW1CZ05WQkFNTUgxTmxiR1pUYVdkdVpXUkRaWEowWHpJMFFYQnlNakF4Ck4xOHhPREF3TkRReEdEQVdCZ05WQkFzTUR6QXdSRFpCTURBd01EQXdNVGQwT0RFWE1CVUdBMVVFQ2d3T1UyRnNaWE5tYjNKalpTNWoKYjIweEZqQVVCZ05WQkFjTURWTmhiaUJHY21GdVkybHpZMjh4Q3pBSkJnTlZCQWdNQWtOQk1Rd3dDZ1lEVlFRR0V3TlZVMEdDRGdGYgpvUjkxcEFBQUFBQWVUYWJ5TUEwR0NTcUdTSWIzRFFFQkN3VUFBNElCQVFBVmhZQnY1R0p2aGx0a3MyajdaYzl3ZEZIVzd5QjQvaFBGCm8wNXkweWlPZjcxdExqT2xCdWNTeXh0bVhMUGpyRUNKdkl
|
|
|
|
|
|
|
|
func TestValidate(t *testing.T) {
|
|
|
|
tm, err := time.Parse(time.UnixDate, "Sun Apr 30 22:10:00 UTC 2017")
|
|
|
|
require.Nil(t, err)
|
2019-11-11 17:42:31 +00:00
|
|
|
|
2017-05-09 00:43:48 +00:00
|
|
|
clock := dsig.NewFakeClockAt(tm)
|
|
|
|
validator, err := NewValidator(testMetadata, Clock(clock))
|
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, validator)
|
2019-11-11 17:42:31 +00:00
|
|
|
|
2017-05-09 00:43:48 +00:00
|
|
|
auth, err := DecodeAuthResponse(testResponse)
|
2019-11-11 17:42:31 +00:00
|
|
|
require.Nil(t, err)
|
|
|
|
|
2017-05-09 00:43:48 +00:00
|
|
|
signed, err := validator.ValidateSignature(auth)
|
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, signed)
|
|
|
|
|
|
|
|
err = validator.ValidateResponse(auth)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func tamperedResponse(original string) (string, error) {
|
|
|
|
decoded, err := base64.StdEncoding.DecodeString(original)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
var resp Response
|
|
|
|
rdr := bytes.NewBuffer(decoded)
|
|
|
|
err = xml.NewDecoder(rdr).Decode(&resp)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
// change name
|
|
|
|
resp.Assertion.Subject.NameID.Value = "bob@kolide.co"
|
|
|
|
var wrtr bytes.Buffer
|
|
|
|
err = xml.NewEncoder(&wrtr).Encode(resp)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
return base64.StdEncoding.EncodeToString(wrtr.Bytes()), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestVerfiyValidTamperedWithDocFails(t *testing.T) {
|
|
|
|
tampered, err := tamperedResponse(testResponse)
|
|
|
|
require.Nil(t, err)
|
2019-11-11 17:42:31 +00:00
|
|
|
|
2017-05-09 00:43:48 +00:00
|
|
|
tm, err := time.Parse(time.UnixDate, "Sun Apr 30 22:10:00 UTC 2017")
|
|
|
|
require.Nil(t, err)
|
2019-11-11 17:42:31 +00:00
|
|
|
|
2017-05-09 00:43:48 +00:00
|
|
|
clock := dsig.NewFakeClockAt(tm)
|
|
|
|
validator, err := NewValidator(testMetadata, Clock(clock))
|
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, validator)
|
2019-11-11 17:42:31 +00:00
|
|
|
|
2017-05-09 00:43:48 +00:00
|
|
|
auth, err := DecodeAuthResponse(tampered)
|
2019-11-11 17:42:31 +00:00
|
|
|
require.Nil(t, err)
|
|
|
|
|
2017-05-09 00:43:48 +00:00
|
|
|
_, err = validator.ValidateSignature(auth)
|
|
|
|
require.NotNil(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Message hasn't been tampered with but is stale
|
|
|
|
func TestVerfiyStaleMessageFails(t *testing.T) {
|
|
|
|
tm, err := time.Parse(time.UnixDate, "Sun Apr 30 22:14:00 UTC 2017")
|
|
|
|
require.Nil(t, err)
|
|
|
|
clock := dsig.NewFakeClockAt(tm)
|
|
|
|
validator, err := NewValidator(testMetadata, Clock(clock))
|
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, validator)
|
2019-11-11 17:42:31 +00:00
|
|
|
|
2017-05-09 00:43:48 +00:00
|
|
|
auth, err := DecodeAuthResponse(testResponse)
|
2019-11-11 17:42:31 +00:00
|
|
|
require.Nil(t, err)
|
|
|
|
|
2017-05-09 00:43:48 +00:00
|
|
|
signed, err := validator.ValidateSignature(auth)
|
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, signed)
|
|
|
|
|
|
|
|
err = validator.ValidateResponse(auth)
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
}
|
2017-07-18 20:28:35 +00:00
|
|
|
|
|
|
|
var testGoogleMetadata = `
|
|
|
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
|
|
<md:EntityDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata" entityID="https://accounts.google.com/o/saml2?idpid=C0171bstf" validUntil="2022-07-16T20:07:43.000Z">
|
|
|
|
<md:IDPSSODescriptor WantAuthnRequestsSigned="false" protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
|
|
|
|
<md:KeyDescriptor use="signing">
|
|
|
|
<ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
|
|
|
|
<ds:X509Data>
|
|
|
|
<ds:X509Certificate>MIIDdDCCAlygAwIBAgIGAV1SKeijMA0GCSqGSIb3DQEBCwUAMHsxFDASBgNVBAoTC0dvb2dsZSBJ
|
|
|
|
bmMuMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MQ8wDQYDVQQDEwZHb29nbGUxGDAWBgNVBAsTD0dv
|
|
|
|
b2dsZSBGb3IgV29yazELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWEwHhcNMTcwNzE3
|
|
|
|
MjAwNzQzWhcNMjIwNzE2MjAwNzQzWjB7MRQwEgYD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|
|
|
|
</md:KeyDescriptor>
|
|
|
|
<md:NameIDFormat>urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress</md:NameIDFormat>
|
|
|
|
<md:SingleSignOnService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect" Location="https://accounts.google.com/o/saml2/idp?idpid=C0171bstf"/>
|
|
|
|
<md:SingleSignOnService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" Location="https://accounts.google.com/o/saml2/idp?idpid=C0171bstf"/>
|
|
|
|
</md:IDPSSODescriptor>
|
|
|
|
</md:EntityDescriptor>
|
|
|
|
|
|
|
|
`
|
|
|
|
|
|
|
|
func TestVerifyValidGoogleResponse(t *testing.T) {
|
|
|
|
samlResponse :=
|
|
|
|
`PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+PHNhbWwycDpSZXNwb25zZSB4bWxuczpzYW1sMnA9InVybjpvYXNpczpuYW1lczp0YzpTQU1MOjIuMDpwcm90b2NvbCIgRGVzdGluYXRpb249Imh0dHBzOi8vbG9jYWxob3N0OjgwODAvYXBpL3YxL2tvbGlkZS9zc28vY2FsbGJhY2siIElEPSJfODM1NzlhOTAwOGVmNzI2Zjg3YzUyYWFkNGI2ZGNjMDQiIEluUmVzcG9uc2VUbz0iU0dKaGkxZzVENC9ucE93WGF3OHQ2QT09IiBJc3N1ZUluc3RhbnQ9IjIwMTctMDctMThUMTQ6NDc6MDguMDM1WiIgVmVyc2lvbj0iMi4wIj48c2FtbDI6SXNzdWVyIHhtbG5zOnNhbWwyPSJ1cm46b2FzaXM6bmFtZXM6dGM6U0FNTDoyLjA6YXNzZXJ0aW9uIj5odHRwczovL2FjY291bnRzLmdvb2dsZS5jb20vby9zYW1sMj9pZHBpZD1DMDE3MWJzdGY8L3NhbWwyOklzc3Vlcj48c2FtbDJwOlN0YXR1cz48c2FtbDJwOlN0YXR1c0NvZGUgVmFsdWU9InVyb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5YTGRLOTZNL2RvOW5HUzVRM3hWZ0EydXhUem0vNnFOa0FmT1NHU2s4T2NMcnBwUG9uYm9oa2VaCldWbk5CNVZaWmF2YTREb1NaNk9ac3ZLYzFGTTB3S3ZQSmQ4M0tVYjdTeWsxYlY3VGtUOERQRWNsZnNMbm41czVnMG9IbGhzcWtObHkKMFdQRlRBb0dIWFl5T0tHRUFSUG9DL28rWmZnZnZvTU55WmtTUUhpUmJvVlZQMmNUMWNrSnQ0aUNBNjVoTkdYdGUyOWhTR21u
|
|
|
|
tm, err := time.Parse(time.RFC3339, "2017-07-18T14:47:08.035Z")
|
|
|
|
require.Nil(t, err)
|
|
|
|
clock := dsig.NewFakeClockAt(tm)
|
|
|
|
validator, err := NewValidator(testGoogleMetadata, Clock(clock))
|
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, validator)
|
|
|
|
auth, err := DecodeAuthResponse(samlResponse)
|
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, auth)
|
|
|
|
signed, err := validator.ValidateSignature(auth)
|
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, signed)
|
|
|
|
err = validator.ValidateResponse(auth)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestVerifyInvalidSignatureGoogleResponse(t *testing.T) {
|
|
|
|
samlResponse :=
|
|
|
|
`PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+PHNhbWwycDpSZXNwb25zZSB4bWxuczpzYW1sMnA9InVybjpvYXNpczpuYW1lczp0YzpTQU1MOjIuMDpwcm90b2NvbCIgRGVzdGluYXRpb249Imh0dHBzOi8vbG9jYWxob3N0OjgwODAvYXBpL3YxL2tvbGlkZS9zc28vY2FsbGJhY2siIElEPSJfODM1NzlhOTAwOGVmNzI2Zjg3YzUyYWFkNGI2ZGNjMDQiIEluUmVzcG9uc2VUbz0iU0dKaGkxZzVENC9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VsSHV6SkV6QllzZHR2TThUL1BDbEJ4aUxYUk5ibmpvdHpsZUZxYjI1dzNYUmZheU9aZzVHZFFQZUVtY2VXWERCaENhCmVReUVQT3JVVForLy9wWlhTdUtuT3lhRmZFU05GTmd2UUpsWVFRdWtqbmhQdGY2NzRlV1Q2T2RnWkh5cThFQmJaS2ZFaHM1K0tpQU4KVTQzYkRoOXJwVEpDQjdyQUtrMUJGQVczcjcycGdnd045Wi9zZnAvQzVCN3VLQU01aHdJREFRQUJNQTBHQ1NxR1NJYjNEUUVCQ3dVQQpBNElCQVFBWlh5cGlrYmJSemljaE5YTGRLOTZNL2RvOW5HUzVRM3hWZ0EydXhUem0vNnFOa0FmT1NHU2s4T2NMcnBwUG9uYm9oa2VaCldWbk5CNVZaWmF2YTREb1NaNk9ac3ZLYzFGTTB3S3ZQSmQ4M0tVYjdTeWsxYlY3VGtUOERQRWNsZnNMbm41czVnMG9IbGhzcWtObHkKMFdQRlRBb0dIWFl5T0tHRUFSUG9DL28rWmZnZnZvTU55WmtTUUhpUmJvVlZQMmNUMWNrSnQ0aUNBNjVoTkdYdGUyOWhTR21u
|
|
|
|
tm, err := time.Parse(time.RFC3339, "2017-07-18T14:47:08.035Z")
|
|
|
|
require.Nil(t, err)
|
|
|
|
clock := dsig.NewFakeClockAt(tm)
|
|
|
|
validator, err := NewValidator(testGoogleMetadata, Clock(clock))
|
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, validator)
|
|
|
|
auth, err := DecodeAuthResponse(samlResponse)
|
|
|
|
require.Nil(t, err)
|
|
|
|
require.NotNil(t, auth)
|
|
|
|
_, err = validator.ValidateSignature(auth)
|
|
|
|
require.NotNil(t, err)
|
|
|
|
}
|
2017-08-01 02:48:42 +00:00
|
|
|
|
|
|
|
// validate id's are unique and that I didn't screw up my maths
|
|
|
|
func TestIDGenerator(t *testing.T) {
|
|
|
|
idTable := make(map[string]struct{})
|
|
|
|
for i := 0; i < 100; i++ {
|
|
|
|
id, err := generateSAMLValidID()
|
|
|
|
require.Nil(t, err)
|
|
|
|
assert.Subset(t, []byte(idAlphabet), []byte(id))
|
|
|
|
_, ok := idTable[id]
|
|
|
|
assert.False(t, ok)
|
|
|
|
idTable[id] = struct{}{}
|
|
|
|
}
|
|
|
|
}
|
2019-05-16 20:51:42 +00:00
|
|
|
|
|
|
|
func TestIDPrefix(t *testing.T) {
|
|
|
|
// Ensure ID comes with the appropriate prefix
|
|
|
|
id, err := generateSAMLValidID()
|
|
|
|
require.Nil(t, err)
|
|
|
|
assert.Equal(t, idPrefix, id[:2])
|
|
|
|
}
|