Skip to content

Commit cddd947

Browse files
committed
use gofmt -s
1 parent 73c2fa6 commit cddd947

6 files changed

+98
-98
lines changed

identity_provider.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -86,22 +86,22 @@ func (idp *IdentityProvider) Metadata() *Metadata {
8686
IDPSSODescriptor: &IDPSSODescriptor{
8787
ProtocolSupportEnumeration: "urn:oasis:names:tc:SAML:2.0:protocol",
8888
KeyDescriptor: []KeyDescriptor{
89-
KeyDescriptor{
89+
{
9090
Use: "signing",
9191
KeyInfo: KeyInfo{
9292
Certificate: certStr,
9393
},
9494
},
95-
KeyDescriptor{
95+
{
9696
Use: "encryption",
9797
KeyInfo: KeyInfo{
9898
Certificate: certStr,
9999
},
100100
EncryptionMethods: []EncryptionMethod{
101-
EncryptionMethod{Algorithm: "http://www.w3.org/2001/04/xmlenc#aes128-cbc"},
102-
EncryptionMethod{Algorithm: "http://www.w3.org/2001/04/xmlenc#aes192-cbc"},
103-
EncryptionMethod{Algorithm: "http://www.w3.org/2001/04/xmlenc#aes256-cbc"},
104-
EncryptionMethod{Algorithm: "http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p"},
101+
{Algorithm: "http://www.w3.org/2001/04/xmlenc#aes128-cbc"},
102+
{Algorithm: "http://www.w3.org/2001/04/xmlenc#aes192-cbc"},
103+
{Algorithm: "http://www.w3.org/2001/04/xmlenc#aes256-cbc"},
104+
{Algorithm: "http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p"},
105105
},
106106
},
107107
},
@@ -345,7 +345,7 @@ func (req *IdpAuthnRequest) MakeAssertion(session *Session) error {
345345
FriendlyName: "uid",
346346
Name: "urn:oid:0.9.2342.19200300.100.1.1",
347347
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
348-
Values: []AttributeValue{AttributeValue{
348+
Values: []AttributeValue{{
349349
Type: "xs:string",
350350
Value: session.UserName,
351351
}},
@@ -357,7 +357,7 @@ func (req *IdpAuthnRequest) MakeAssertion(session *Session) error {
357357
FriendlyName: "eduPersonPrincipalName",
358358
Name: "urn:oid:1.3.6.1.4.1.5923.1.1.1.6",
359359
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
360-
Values: []AttributeValue{AttributeValue{
360+
Values: []AttributeValue{{
361361
Type: "xs:string",
362362
Value: session.UserEmail,
363363
}},
@@ -368,7 +368,7 @@ func (req *IdpAuthnRequest) MakeAssertion(session *Session) error {
368368
FriendlyName: "sn",
369369
Name: "urn:oid:2.5.4.4",
370370
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
371-
Values: []AttributeValue{AttributeValue{
371+
Values: []AttributeValue{{
372372
Type: "xs:string",
373373
Value: session.UserSurname,
374374
}},
@@ -379,7 +379,7 @@ func (req *IdpAuthnRequest) MakeAssertion(session *Session) error {
379379
FriendlyName: "givenName",
380380
Name: "urn:oid:2.5.4.42",
381381
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
382-
Values: []AttributeValue{AttributeValue{
382+
Values: []AttributeValue{{
383383
Type: "xs:string",
384384
Value: session.UserGivenName,
385385
}},
@@ -391,7 +391,7 @@ func (req *IdpAuthnRequest) MakeAssertion(session *Session) error {
391391
FriendlyName: "cn",
392392
Name: "urn:oid:2.5.4.3",
393393
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
394-
Values: []AttributeValue{AttributeValue{
394+
Values: []AttributeValue{{
395395
Type: "xs:string",
396396
Value: session.UserCommonName,
397397
}},

identity_provider_test.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ func (test *IdentityProviderTest) TestMakeAssertion(c *C) {
441441
CanonicalizationMethod: xmlsec.Method{Algorithm: "http://www.w3.org/TR/2001/REC-xml-c14n-20010315"},
442442
SignatureMethod: xmlsec.Method{Algorithm: "http://www.w3.org/2000/09/xmldsig#rsa-sha1"},
443443
ReferenceTransforms: []xmlsec.Method{
444-
xmlsec.Method{Algorithm: "http://www.w3.org/2000/09/xmldsig#enveloped-signature"},
444+
{Algorithm: "http://www.w3.org/2000/09/xmldsig#enveloped-signature"},
445445
},
446446
DigestMethod: xmlsec.Method{Algorithm: "http://www.w3.org/2000/09/xmldsig#sha1"},
447447
DigestValue: "",
@@ -478,12 +478,12 @@ func (test *IdentityProviderTest) TestMakeAssertion(c *C) {
478478
},
479479
AttributeStatement: &AttributeStatement{
480480
Attributes: []Attribute{
481-
Attribute{
481+
{
482482
FriendlyName: "uid",
483483
Name: "urn:oid:0.9.2342.19200300.100.1.1",
484484
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
485485
Values: []AttributeValue{
486-
AttributeValue{
486+
{
487487
Type: "xs:string",
488488
Value: "alice",
489489
},
@@ -513,7 +513,7 @@ func (test *IdentityProviderTest) TestMakeAssertion(c *C) {
513513
Name: "urn:oid:0.9.2342.19200300.100.1.1",
514514
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
515515
Values: []AttributeValue{
516-
AttributeValue{
516+
{
517517
Type: "xs:string",
518518
Value: "alice",
519519
},
@@ -524,7 +524,7 @@ func (test *IdentityProviderTest) TestMakeAssertion(c *C) {
524524
Name: "urn:oid:1.3.6.1.4.1.5923.1.1.1.6",
525525
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
526526
Values: []AttributeValue{
527-
AttributeValue{
527+
{
528528
Type: "xs:string",
529529
530530
},
@@ -535,7 +535,7 @@ func (test *IdentityProviderTest) TestMakeAssertion(c *C) {
535535
Name: "urn:oid:2.5.4.4",
536536
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
537537
Values: []AttributeValue{
538-
AttributeValue{
538+
{
539539
Type: "xs:string",
540540
Value: "Smith",
541541
},
@@ -546,7 +546,7 @@ func (test *IdentityProviderTest) TestMakeAssertion(c *C) {
546546
Name: "urn:oid:2.5.4.42",
547547
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
548548
Values: []AttributeValue{
549-
AttributeValue{
549+
{
550550
Type: "xs:string",
551551
Value: "Alice",
552552
},
@@ -557,7 +557,7 @@ func (test *IdentityProviderTest) TestMakeAssertion(c *C) {
557557
Name: "urn:oid:2.5.4.3",
558558
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
559559
Values: []AttributeValue{
560-
AttributeValue{
560+
{
561561
Type: "xs:string",
562562
Value: "Alice Smith",
563563
},
@@ -568,15 +568,15 @@ func (test *IdentityProviderTest) TestMakeAssertion(c *C) {
568568
Name: "urn:oid:1.3.6.1.4.1.5923.1.1.1.1",
569569
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
570570
Values: []AttributeValue{
571-
AttributeValue{
571+
{
572572
Type: "xs:string",
573573
Value: "Users",
574574
},
575-
AttributeValue{
575+
{
576576
Type: "xs:string",
577577
Value: "Administrators",
578578
},
579-
AttributeValue{
579+
{
580580
Type: "xs:string",
581581
Value: "♀",
582582
},

metadata_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func (s *MetadataTest) TestCanProduceSPMetadata(c *C) {
2121
WantAssertionsSigned: true,
2222
ProtocolSupportEnumeration: "urn:oasis:names:tc:SAML:2.0:protocol",
2323
KeyDescriptor: []KeyDescriptor{
24-
KeyDescriptor{
24+
{
2525
Use: "encryption",
2626
KeyInfo: KeyInfo{
2727
Certificate: `MIIB7zCCAVgCCQDFzbKIp7b3MTANBgkqhkiG9w0BAQUFADA8MQswCQYDVQQGEwJVUzELMAkGA1UE
@@ -35,7 +35,7 @@ TLbRZRD7Xvn1MnVBBS9hzlXiFLYOInXACMW5gcoRFfeTQLSouMM8o57h0uKjfTmuoWHLQLi6hnF+
3535
cvCsEFiJZ4AbF+DgmO6TarJ8O05t8zvnOwJlNCASPZRH/JmF8tX0hoHuAQ==`,
3636
},
3737
},
38-
KeyDescriptor{
38+
{
3939
Use: "signing",
4040
KeyInfo: KeyInfo{
4141
Certificate: `MIIB7zCCAVgCCQDFzbKIp7b3MTANBgkqhkiG9w0BAQUFADA8MQswCQYDVQQGEwJVUzELMAkGA1UE

saml.go

+42-42
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,48 @@
11
// Package saml contains a partial implementation of the SAML standard in golang.
22
// SAML is a standard for identity federation, i.e. either allowing a third party to authenticate your users or allowing third parties to rely on us to authenticate their users.
3-
//
3+
//
44
// In SAML parlance an Identity Provider (IDP) is a service that knows how to authenticate users. A Service Provider (SP) is a service that delegates authentication to an IDP. If you are building a service where users log in with someone else's credentials, then you are a Service Provider. This package supports implementing both service providers and identity providers.
5-
//
5+
//
66
// The core package contains the implementation of SAML. The package samlsp provides helper middleware suitable for use in Service Provider applications. The package samlidp provides a rudimentary IDP service that is useful for testing or as a starting point for other integrations.
7-
//
7+
//
88
// Getting Started as a Service Provider
9-
//
9+
//
1010
// Let us assume we have a simple web appliation to protect. We'll modify this application so it uses SAML to authenticate users.
11-
//
11+
//
1212
// package main
13-
//
13+
//
1414
// import "net/http"
15-
//
15+
//
1616
// func hello(w http.ResponseWriter, r *http.Request) {
1717
// fmt.Fprintf(w, "Hello, World!")
1818
// })
19-
//
19+
//
2020
// func main() {
2121
// app := http.HandlerFunc(hello)
2222
// http.Handle("/hello", app)
2323
// http.ListenAndServe(":8000", nil)
2424
// }
25-
//
25+
//
2626
// Each service provider must have an self-signed X.509 key pair established. You can generate your own with something like this:
27-
//
27+
//
2828
// openssl req -x509 -newkey rsa:2048 -keyout myservice.key -out myservice.cert -days 365 -nodes -subj "/CN=myservice.example.com"
29-
//
29+
//
3030
// We will use `samlsp.Middleware` to wrap the endpoint we want to protect. Middleware provides both an `http.Handler` to serve the SAML specific URLs and a set of wrappers to require the user to be logged in. We also provide the URL where the service provider can fetch the metadata from the IDP at startup. In our case, we'll use [testshib.org](testshib.org), an identity provider designed for testing.
31-
//
31+
//
3232
// package main
33-
//
33+
//
3434
// import (
3535
// "fmt"
3636
// "io/ioutil"
3737
// "net/http"
38-
//
38+
//
3939
// "github.com/crewjam/saml/samlsp"
4040
// )
41-
//
41+
//
4242
// func hello(w http.ResponseWriter, r *http.Request) {
4343
// fmt.Fprintf(w, "Hello, %s!", r.Header.Get("X-Saml-Cn"))
4444
// }
45-
//
45+
//
4646
// func main() {
4747
// key, _ := ioutil.ReadFile("myservice.key")
4848
// cert, _ := ioutil.ReadFile("myservice.cert")
@@ -57,57 +57,57 @@
5757
// http.Handle("/saml/", samlSP)
5858
// http.ListenAndServe(":8000", nil)
5959
// }
60-
//
61-
//
60+
//
61+
//
6262
// Next we'll have to register our service provider with the identiy provider to establish trust from the service provider to the IDP. For [testshib.org](testshib.org), you can do something like:
63-
//
63+
//
6464
// mdpath=saml-test-$USER-$HOST.xml
6565
// curl localhost:8000/saml/metadata > $mdpath
6666
// curl -i -F userfile=@$mdpath https://www.testshib.org/procupload.php
67-
//
67+
//
6868
// Now you should be able to authenticate. The flow should look like this:
69-
//
69+
//
7070
// 1. You browse to `localhost:8000/hello`
71-
//
71+
//
7272
// 2. The middleware redirects you to `https://idp.testshib.org/idp/profile/SAML2/Redirect/SSO`
73-
//
73+
//
7474
// 3. testshib.org prompts you for a username and password.
75-
//
75+
//
7676
// 4. testshib.org returns you an HTML document which contains an HTML form setup to POST to `localhost:8000/saml/acs`. The form is automatically submitted if you have javascript enabled.
77-
//
77+
//
7878
// 5. The local service validates the response, issues a session cookie, and redirects you to the original URL, `localhost:8000/hello`.
79-
//
79+
//
8080
// 6. This time when `localhost:8000/hello` is requested there is a valid session and so the main content is served.
81-
//
81+
//
8282
// Getting Started as an Identity Provider
83-
//
83+
//
8484
// Please see `examples/idp/` for a substantially complete example of how to use the library and helpers to be an identity provider.
85-
//
85+
//
8686
// Support
87-
//
87+
//
8888
// The SAML standard is huge and complex with many dark corners and strange, unused features. This package implements the most commonly used subset of these features required to provide a single sign on experience. The package supports at least the subset of SAML known as [interoperable SAML](http://saml2int.org).
89-
//
89+
//
9090
// This package supports the Web SSO profile. Message flows from the service provider to the IDP are supported using the HTTP Redirect binding and the HTTP POST binding. Message flows fromthe IDP to the service provider are supported vai the HTTP POST binding.
91-
//
91+
//
9292
// The package supports signed and encrypted SAML assertions. It does not support signed or encrypted requests.
93-
//
93+
//
9494
// RelayState
95-
//
95+
//
9696
// The *RelayState* parameter allows you to pass user state information across the authentication flow. The most common use for this is to allow a user to request a deep link into your site, be redirected through the SAML login flow, and upon successful completion, be directed to the originally requested link, rather than the root.
97-
//
97+
//
9898
// Unfortunately, *RelayState* is less useful than it could be. Firstly, it is not authenticated, so anything you supply must be signed to avoid XSS or CSRF. Secondly, it is limited to 80 bytes in length, which precludes signing. (See section 3.6.3.1 of SAMLProfiles.)
99-
//
99+
//
100100
// References
101-
//
101+
//
102102
// The SAML specification is a collection of PDFs (sadly):
103-
//
103+
//
104104
// - [SAMLCore](http://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf) defines data types.
105-
//
105+
//
106106
// - [SAMLBindings](http://docs.oasis-open.org/security/saml/v2.0/saml-bindings-2.0-os.pdf) defines the details of the HTTP requests in play.
107-
//
107+
//
108108
// - [SAMLProfiles](http://docs.oasis-open.org/security/saml/v2.0/saml-profiles-2.0-os.pdf) describes data flows.
109-
//
109+
//
110110
// - [SAMLConformance](http://docs.oasis-open.org/security/saml/v2.0/saml-conformance-2.0-os.pdf) includes a support matrix for various parts of the protocol.
111-
//
111+
//
112112
// [TestShib](http://www.testshib.org/) is a testing ground for SAML service and identity providers.
113113
package saml

service_provider.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,22 @@ func (sp *ServiceProvider) Metadata() *Metadata {
6969
WantAssertionsSigned: true,
7070
ProtocolSupportEnumeration: "urn:oasis:names:tc:SAML:2.0:protocol",
7171
KeyDescriptor: []KeyDescriptor{
72-
KeyDescriptor{
72+
{
7373
Use: "signing",
7474
KeyInfo: KeyInfo{
7575
Certificate: sp.Certificate,
7676
},
7777
},
78-
KeyDescriptor{
78+
{
7979
Use: "encryption",
8080
KeyInfo: KeyInfo{
8181
Certificate: sp.Certificate,
8282
},
8383
EncryptionMethods: []EncryptionMethod{
84-
EncryptionMethod{Algorithm: "http://www.w3.org/2001/04/xmlenc#aes128-cbc"},
85-
EncryptionMethod{Algorithm: "http://www.w3.org/2001/04/xmlenc#aes192-cbc"},
86-
EncryptionMethod{Algorithm: "http://www.w3.org/2001/04/xmlenc#aes256-cbc"},
87-
EncryptionMethod{Algorithm: "http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p"},
84+
{Algorithm: "http://www.w3.org/2001/04/xmlenc#aes128-cbc"},
85+
{Algorithm: "http://www.w3.org/2001/04/xmlenc#aes192-cbc"},
86+
{Algorithm: "http://www.w3.org/2001/04/xmlenc#aes256-cbc"},
87+
{Algorithm: "http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p"},
8888
},
8989
},
9090
},

0 commit comments

Comments
 (0)