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

Draft: Some changes #15

Draft
wants to merge 37 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
11b44b1
renewed expired Example SP certificate
davide-perego-runtime Jul 29, 2021
f3ec6da
Added Organization struct to SP metadata
davide-perego-runtime Sep 27, 2021
68b3818
Update module
nicolasvac Oct 28, 2021
6c7c001
Add dynamic contact person in SP structure
nicolasvac Oct 28, 2021
212e14e
Only add extensions if populated
nicolasvac Oct 28, 2021
90221d0
Use if not instead of if !=
nicolasvac Oct 28, 2021
1948a53
Use eq instead of ==
nicolasvac Oct 28, 2021
6d28fa6
Bugfix
nicolasvac Oct 28, 2021
85ee99a
Bugfix
nicolasvac Oct 28, 2021
4a9118e
Bugfix
nicolasvac Oct 28, 2021
61d5c93
Bugfix
nicolasvac Oct 28, 2021
d74e967
Add xmlns:spid
nicolasvac Oct 29, 2021
d1dbad6
Add xmlns:fpa
nicolasvac Oct 29, 2021
c84a117
Add IsPrivateFullAggregator, IsPublicFullAggregator
nicolasvac Oct 29, 2021
f75cffe
Add randomly generated request ids
nicolasvac Oct 29, 2021
69e73e7
Add Signature tag
nicolas-ristocloud Nov 3, 2021
2538d7e
Bugfix _key instead of Key()
nicolas-ristocloud Nov 3, 2021
2b6cd01
Add cert subject
nicolas-ristocloud Nov 3, 2021
1c08609
Bugfix missing _ in requestID and added # on URI=
nicolas-ristocloud Nov 3, 2021
4a55a44
Add isPublic, isPrivate to ContactPerson
nicolas-ristocloud Nov 3, 2021
7e55ca3
Bugfix IsPublic
nicolas-ristocloud Nov 3, 2021
bd70c53
Try adding contact persons dinamically
nicolasvac Nov 3, 2021
73ef362
Bugfix contact persons
nicolasvac Nov 3, 2021
293a3fd
Add PKCS8 Key Support
nicolasvac Nov 4, 2021
11d6a36
Remove redundant cast
nicolasvac Nov 4, 2021
6b203a3
Add verification of IDP XML Signature
nicolasvac Nov 4, 2021
ba8b09e
Add complete error to idp signature verification
nicolasvac Nov 4, 2021
8f64100
Fix Reading XML from bytes
nicolasvac Nov 4, 2021
59ec60d
Remove IDP metadata XML verification
nicolasvac Nov 4, 2021
1335fdb
Save XML document to IDP.XML
nicolasvac Nov 10, 2021
c40e389
Optional sign mechanism
nicolasvac Nov 10, 2021
00d6add
Optional sign mechanism in xml template
nicolasvac Nov 10, 2021
0dd1c29
Sign authnrequest_out.go
nicolasvac Nov 10, 2021
f2c055b
Remove button.go
nicolasvac Nov 10, 2021
4717194
test
nicolasvac Nov 10, 2021
e07b5cb
Bugfix spazi saml:Issuer
nicolas-ristocloud Nov 12, 2021
697beab
Fix SpidL format
nicolas-ristocloud Nov 17, 2021
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
Prev Previous commit
Next Next commit
Try adding contact persons dinamically
  • Loading branch information
nicolasvac committed Nov 3, 2021
commit bd70c53970c622160af8a0798f803660fdaaa85f
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@
example/example

.vscode
/.idea/.gitignore
/.idea/dbnavigator.xml
/.idea/modules.xml
/.idea/spid-go.iml
/.idea/vcs.xml
6 changes: 4 additions & 2 deletions spidsaml/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ module github.com/nicolasvac/spid-go/spidsaml
go 1.17

require (
github.com/beevik/etree v1.0.1
github.com/beevik/etree v1.1.0
github.com/crewjam/go-xmlsec v0.0.0-20170116132012-1aa2f9374afa
github.com/ma314smith/signedxml v0.0.0-20210628192057-abc5b481ae1c
)

require (
github.com/crewjam/errset v0.0.0-20160219153700-f78d65de925c // indirect
github.com/ma314smith/signedxml v0.0.0-20210628192057-abc5b481ae1c // indirect
github.com/smartystreets/goconvey v1.7.2 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
)
22 changes: 22 additions & 0 deletions spidsaml/go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
github.com/beevik/etree v1.0.1 h1:lWzdj5v/Pj1X360EV7bUudox5SRipy4qZLjY0rhb0ck=
github.com/beevik/etree v1.0.1/go.mod h1:r8Aw8JqVegEf0w2fDnATrX9VpkMcyFeM0FhwO62wh+A=
github.com/beevik/etree v1.1.0 h1:T0xke/WvNtMoCqgzPhkX2r4rjY3GDZFi+FjpRZY2Jbs=
github.com/beevik/etree v1.1.0/go.mod h1:r8Aw8JqVegEf0w2fDnATrX9VpkMcyFeM0FhwO62wh+A=
github.com/crewjam/errset v0.0.0-20160219153700-f78d65de925c h1:dCJ9oZ0VgnzJHR5BjkSrwkXA1USu483qlxBd0u29P8s=
github.com/crewjam/errset v0.0.0-20160219153700-f78d65de925c/go.mod h1:XhiWL7J86xoqJ8+x2OA+AM2l9skQP2DZ0UOXQYVg7uI=
github.com/crewjam/go-xmlsec v0.0.0-20170116132012-1aa2f9374afa h1:P3H7u0mfn9zEniDEKN50Yos1m60AM2PNOcyrInUjRFM=
github.com/crewjam/go-xmlsec v0.0.0-20170116132012-1aa2f9374afa/go.mod h1:M9eHnKpImgRwzOFdlFQnbgJRqFwW/eX1cKAVobv03uE=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/ma314smith/signedxml v0.0.0-20210628192057-abc5b481ae1c h1:UPJygtyk491bJJ/DnRJFuzcq9Dl9NSeFrJ7VdiRzMxc=
github.com/ma314smith/signedxml v0.0.0-20210628192057-abc5b481ae1c/go.mod h1:KEgVcb43+f5KFUH/x6Vd3NROG0AIL2CuKMrIqYsmx6E=
github.com/smartystreets/assertions v1.2.0 h1:42S6lae5dvLc7BrLu/0ugRtcFVjoJNMC/N3yZFZkDFs=
github.com/smartystreets/assertions v1.2.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo=
github.com/smartystreets/goconvey v1.7.2 h1:9RBaZCeXEQ3UselpuwUQHltGVXvdwm6cv1hgR6gDIPg=
github.com/smartystreets/goconvey v1.7.2/go.mod h1:Vw0tHAZW6lzCRk3xgdin6fKYcG+G3Pg9vgXWeJpQFMM=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
119 changes: 75 additions & 44 deletions spidsaml/spid.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"encoding/base64"
"encoding/pem"
"errors"
"github.com/beevik/etree"
"io/ioutil"
"math/big"
"text/template"
Expand Down Expand Up @@ -37,20 +38,20 @@ type SPOrganization struct {
OrganizationURL string
}

// SPContactPerson ContactPerson metadata about sp full
// SPContactPerson ContactPerson metadata
type SPContactPerson struct {
ContactType string
EntityType string
IpaCode string
VatNumber string
FiscalCode string
Company string
EmailAddress string
TelephoneNumber string
IsPrivate bool
IsPublic bool
IsPrivateFullAggregator bool
IsPublicFullAggregator bool
ContactType string
Company string
EmailAddress string
TelephoneNumber string
Extensions []SPContactPersonExtension
}

// SPContactPersonExtension extensions for contact person
type SPContactPersonExtension struct {
Tag string
Value string
Extensions []SPContactPersonExtension
}

// SP represents our Service Provider
Expand Down Expand Up @@ -229,37 +230,6 @@ func (sp *SP) Metadata() string {
<md:OrganizationURL xml:lang="it">{{ .Organization.OrganizationURL }}</md:OrganizationURL>
</md:Organization>

{{ range $index, $contact := .ContactPersons }}
<md:ContactPerson contactType="{{ $contact.ContactType }}" spid:entityType="{{ $contact.EntityType }}">
<md:Extensions>
{{ if ne $contact.IpaCode "" }}
<spid:IPACode>{{ $contact.IpaCode }}</spid:IPACode>
{{ end }}
{{ if ne $contact.VatNumber "" }}
<spid:VATNumber>{{ $contact.VatNumber }}</spid:VATNumber>
{{ end }}
{{ if ne $contact.FiscalCode "" }}
<spid:FiscalCode>{{ $contact.FiscalCode }}</spid:FiscalCode>
{{ end }}
{{ if $contact.IsPrivate }}
<spid:Private/>
{{ end }}
{{ if $contact.IsPublic }}
<spid:Public/>
{{ end }}
{{ if $contact.IsPublicFullAggregator }}
<spid:PublicServicesFullOperator/>
{{ end }}
{{ if $contact.IsPrivateFullAggregator }}
<spid:PrivateServicesFullAggregator/>
{{ end }}
</md:Extensions>
<md:Company>{{ $contact.Company }}</md:Company>
<md:EmailAddress>{{ $contact.EmailAddress }}</md:EmailAddress>
<md:TelephoneNumber>{{ $contact.TelephoneNumber }}</md:TelephoneNumber>
</md:ContactPerson>
{{ end }}

</md:EntityDescriptor>
`
aux := struct {
Expand Down Expand Up @@ -295,5 +265,66 @@ func (sp *SP) Metadata() string {
return ""
}

completeXML, err = addContactPersons(completeXML, sp.ContactPersons)

if err != nil {
return ""
}

return completeXML
}

func addContactPersons(signedXML string, persons []SPContactPerson) (string, error) {
xmlDoc := etree.NewDocument()

if xmlDoc.ReadFromString(signedXML) != nil {
return "", nil
}

// Get the basic entity descriptor element
entityDescriptor := xmlDoc.FindElement("EntityDescriptor")

for _, contactPerson := range persons {
// Create basic contact person element
contactPersonXML := entityDescriptor.CreateElement("md:ContactPerson")
// Add the specified contact type
contactPersonXML.CreateAttr("contactType", contactPerson.ContactType)

// Add company data
if contactPerson.Company != "" {
contactPersonXML.CreateElement("md:Company").CreateText(contactPerson.Company)
}

// Add email address data
if contactPerson.EmailAddress != "" {
contactPersonXML.CreateElement("md:EmailAddress").CreateText(contactPerson.EmailAddress)
}

// Add telephone number data
if contactPerson.TelephoneNumber != "" {
contactPersonXML.CreateElement("md:TelephoneNumber").CreateText(contactPerson.TelephoneNumber)
}

// Add extensions data
contactPersonExtensionsXML := contactPersonXML.CreateElement("md:Extensions")

addContactPersonExtensions(contactPersonExtensionsXML, contactPerson.Extensions)
}

return xmlDoc.WriteToString()
}

func addContactPersonExtensions(xml *etree.Element, extensions []SPContactPersonExtension) {

for _, extension := range extensions {
xmlElement := xml.CreateElement(extension.Tag)

if extension.Value != "" {
xmlElement.CreateText(extension.Value)
}

if len(extension.Extensions) > 0 {
addContactPersonExtensions(xmlElement, extension.Extensions)
}
}
}