mirror of
https://github.com/mickael-kerjean/filestash
synced 2025-12-06 16:32:31 +01:00
fix (deps): vendoring golang deps
This commit is contained in:
parent
42770afc69
commit
a37de01b3b
141 changed files with 19628 additions and 9 deletions
4
go.mod
4
go.mod
|
|
@ -5,7 +5,7 @@ go 1.16
|
|||
require (
|
||||
github.com/aws/aws-sdk-go v1.40.41
|
||||
github.com/cretz/bine v0.1.0
|
||||
github.com/crewjam/saml v0.4.6 // indirect
|
||||
github.com/crewjam/saml v0.4.6
|
||||
github.com/go-sql-driver/mysql v1.5.0
|
||||
github.com/gorilla/mux v1.7.3
|
||||
github.com/gorilla/websocket v1.4.1
|
||||
|
|
@ -30,7 +30,7 @@ require (
|
|||
google.golang.org/api v0.15.0
|
||||
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
|
||||
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
|
||||
gopkg.in/ldap.v2 v2.5.1 // indirect
|
||||
gopkg.in/ldap.v2 v2.5.1
|
||||
gopkg.in/ldap.v3 v3.1.0
|
||||
gopkg.in/src-d/go-git.v4 v4.13.1
|
||||
)
|
||||
|
|
|
|||
7
go.sum
7
go.sum
|
|
@ -29,7 +29,6 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
|
|||
github.com/dchest/uniuri v0.0.0-20200228104902-7aecb25e1fe5/go.mod h1:GgB8SF9nRG+GqaDtLcwJZsQFhcogVCJ79j4EdT0c2V4=
|
||||
github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg=
|
||||
github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
|
||||
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ=
|
||||
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
|
||||
github.com/gliderlabs/ssh v0.2.2 h1:6zsha5zo/TWhRhwqCD3+EarCAgZ2yN28ipRnGPnwkI0=
|
||||
github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
|
||||
|
|
@ -130,16 +129,10 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P
|
|||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/tidwall/gjson v1.6.5 h1:P/K9r+1pt9AK54uap7HcoIp6T3a7AoMg3v18tUis+Cg=
|
||||
github.com/tidwall/gjson v1.6.5/go.mod h1:zeFuBCIqD4sN/gmqBzZ4j7Jd6UcA2Fc56x7QFsv+8fI=
|
||||
github.com/tidwall/gjson v1.13.0 h1:3TFY9yxOQShrvmjdM76K+jc66zJeT6D3/VFFYCGQf7M=
|
||||
github.com/tidwall/gjson v1.13.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
||||
github.com/tidwall/match v1.0.3 h1:FQUVvBImDutD8wJLN6c5eMzWtjgONK9MwIBCOrUJKeE=
|
||||
github.com/tidwall/match v1.0.3/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
|
||||
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
|
||||
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
|
||||
github.com/tidwall/pretty v1.0.2 h1:Z7S3cePv9Jwm1KwS0513MRaoUe3S01WPbLNV40pwWZU=
|
||||
github.com/tidwall/pretty v1.0.2/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
|
||||
github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
|
||||
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
|
||||
github.com/tidwall/sjson v1.0.4 h1:UcdIRXff12Lpnu3OLtZvnc03g4vH2suXDXhBwBqmzYg=
|
||||
|
|
|
|||
14
vendor/github.com/beevik/etree/.travis.yml
generated
vendored
Normal file
14
vendor/github.com/beevik/etree/.travis.yml
generated
vendored
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
language: go
|
||||
sudo: false
|
||||
|
||||
go:
|
||||
- 1.11.x
|
||||
- tip
|
||||
|
||||
matrix:
|
||||
allow_failures:
|
||||
- go: tip
|
||||
|
||||
script:
|
||||
- go vet ./...
|
||||
- go test -v ./...
|
||||
10
vendor/github.com/beevik/etree/CONTRIBUTORS
generated
vendored
Normal file
10
vendor/github.com/beevik/etree/CONTRIBUTORS
generated
vendored
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
Brett Vickers (beevik)
|
||||
Felix Geisendörfer (felixge)
|
||||
Kamil Kisiel (kisielk)
|
||||
Graham King (grahamking)
|
||||
Matt Smith (ma314smith)
|
||||
Michal Jemala (michaljemala)
|
||||
Nicolas Piganeau (npiganeau)
|
||||
Chris Brown (ccbrown)
|
||||
Earncef Sequeira (earncef)
|
||||
Gabriel de Labachelerie (wuzuf)
|
||||
24
vendor/github.com/beevik/etree/LICENSE
generated
vendored
Normal file
24
vendor/github.com/beevik/etree/LICENSE
generated
vendored
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
Copyright 2015-2019 Brett Vickers. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY COPYRIGHT HOLDER ``AS IS'' AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
205
vendor/github.com/beevik/etree/README.md
generated
vendored
Normal file
205
vendor/github.com/beevik/etree/README.md
generated
vendored
Normal file
|
|
@ -0,0 +1,205 @@
|
|||
[](https://travis-ci.org/beevik/etree)
|
||||
[](https://godoc.org/github.com/beevik/etree)
|
||||
|
||||
etree
|
||||
=====
|
||||
|
||||
The etree package is a lightweight, pure go package that expresses XML in
|
||||
the form of an element tree. Its design was inspired by the Python
|
||||
[ElementTree](http://docs.python.org/2/library/xml.etree.elementtree.html)
|
||||
module.
|
||||
|
||||
Some of the package's capabilities and features:
|
||||
|
||||
* Represents XML documents as trees of elements for easy traversal.
|
||||
* Imports, serializes, modifies or creates XML documents from scratch.
|
||||
* Writes and reads XML to/from files, byte slices, strings and io interfaces.
|
||||
* Performs simple or complex searches with lightweight XPath-like query APIs.
|
||||
* Auto-indents XML using spaces or tabs for better readability.
|
||||
* Implemented in pure go; depends only on standard go libraries.
|
||||
* Built on top of the go [encoding/xml](http://golang.org/pkg/encoding/xml)
|
||||
package.
|
||||
|
||||
### Creating an XML document
|
||||
|
||||
The following example creates an XML document from scratch using the etree
|
||||
package and outputs its indented contents to stdout.
|
||||
```go
|
||||
doc := etree.NewDocument()
|
||||
doc.CreateProcInst("xml", `version="1.0" encoding="UTF-8"`)
|
||||
doc.CreateProcInst("xml-stylesheet", `type="text/xsl" href="style.xsl"`)
|
||||
|
||||
people := doc.CreateElement("People")
|
||||
people.CreateComment("These are all known people")
|
||||
|
||||
jon := people.CreateElement("Person")
|
||||
jon.CreateAttr("name", "Jon")
|
||||
|
||||
sally := people.CreateElement("Person")
|
||||
sally.CreateAttr("name", "Sally")
|
||||
|
||||
doc.Indent(2)
|
||||
doc.WriteTo(os.Stdout)
|
||||
```
|
||||
|
||||
Output:
|
||||
```xml
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?xml-stylesheet type="text/xsl" href="style.xsl"?>
|
||||
<People>
|
||||
<!--These are all known people-->
|
||||
<Person name="Jon"/>
|
||||
<Person name="Sally"/>
|
||||
</People>
|
||||
```
|
||||
|
||||
### Reading an XML file
|
||||
|
||||
Suppose you have a file on disk called `bookstore.xml` containing the
|
||||
following data:
|
||||
|
||||
```xml
|
||||
<bookstore xmlns:p="urn:schemas-books-com:prices">
|
||||
|
||||
<book category="COOKING">
|
||||
<title lang="en">Everyday Italian</title>
|
||||
<author>Giada De Laurentiis</author>
|
||||
<year>2005</year>
|
||||
<p:price>30.00</p:price>
|
||||
</book>
|
||||
|
||||
<book category="CHILDREN">
|
||||
<title lang="en">Harry Potter</title>
|
||||
<author>J K. Rowling</author>
|
||||
<year>2005</year>
|
||||
<p:price>29.99</p:price>
|
||||
</book>
|
||||
|
||||
<book category="WEB">
|
||||
<title lang="en">XQuery Kick Start</title>
|
||||
<author>James McGovern</author>
|
||||
<author>Per Bothner</author>
|
||||
<author>Kurt Cagle</author>
|
||||
<author>James Linn</author>
|
||||
<author>Vaidyanathan Nagarajan</author>
|
||||
<year>2003</year>
|
||||
<p:price>49.99</p:price>
|
||||
</book>
|
||||
|
||||
<book category="WEB">
|
||||
<title lang="en">Learning XML</title>
|
||||
<author>Erik T. Ray</author>
|
||||
<year>2003</year>
|
||||
<p:price>39.95</p:price>
|
||||
</book>
|
||||
|
||||
</bookstore>
|
||||
```
|
||||
|
||||
This code reads the file's contents into an etree document.
|
||||
```go
|
||||
doc := etree.NewDocument()
|
||||
if err := doc.ReadFromFile("bookstore.xml"); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
```
|
||||
|
||||
You can also read XML from a string, a byte slice, or an `io.Reader`.
|
||||
|
||||
### Processing elements and attributes
|
||||
|
||||
This example illustrates several ways to access elements and attributes using
|
||||
etree selection queries.
|
||||
```go
|
||||
root := doc.SelectElement("bookstore")
|
||||
fmt.Println("ROOT element:", root.Tag)
|
||||
|
||||
for _, book := range root.SelectElements("book") {
|
||||
fmt.Println("CHILD element:", book.Tag)
|
||||
if title := book.SelectElement("title"); title != nil {
|
||||
lang := title.SelectAttrValue("lang", "unknown")
|
||||
fmt.Printf(" TITLE: %s (%s)\n", title.Text(), lang)
|
||||
}
|
||||
for _, attr := range book.Attr {
|
||||
fmt.Printf(" ATTR: %s=%s\n", attr.Key, attr.Value)
|
||||
}
|
||||
}
|
||||
```
|
||||
Output:
|
||||
```
|
||||
ROOT element: bookstore
|
||||
CHILD element: book
|
||||
TITLE: Everyday Italian (en)
|
||||
ATTR: category=COOKING
|
||||
CHILD element: book
|
||||
TITLE: Harry Potter (en)
|
||||
ATTR: category=CHILDREN
|
||||
CHILD element: book
|
||||
TITLE: XQuery Kick Start (en)
|
||||
ATTR: category=WEB
|
||||
CHILD element: book
|
||||
TITLE: Learning XML (en)
|
||||
ATTR: category=WEB
|
||||
```
|
||||
|
||||
### Path queries
|
||||
|
||||
This example uses etree's path functions to select all book titles that fall
|
||||
into the category of 'WEB'. The double-slash prefix in the path causes the
|
||||
search for book elements to occur recursively; book elements may appear at any
|
||||
level of the XML hierarchy.
|
||||
```go
|
||||
for _, t := range doc.FindElements("//book[@category='WEB']/title") {
|
||||
fmt.Println("Title:", t.Text())
|
||||
}
|
||||
```
|
||||
|
||||
Output:
|
||||
```
|
||||
Title: XQuery Kick Start
|
||||
Title: Learning XML
|
||||
```
|
||||
|
||||
This example finds the first book element under the root bookstore element and
|
||||
outputs the tag and text of each of its child elements.
|
||||
```go
|
||||
for _, e := range doc.FindElements("./bookstore/book[1]/*") {
|
||||
fmt.Printf("%s: %s\n", e.Tag, e.Text())
|
||||
}
|
||||
```
|
||||
|
||||
Output:
|
||||
```
|
||||
title: Everyday Italian
|
||||
author: Giada De Laurentiis
|
||||
year: 2005
|
||||
price: 30.00
|
||||
```
|
||||
|
||||
This example finds all books with a price of 49.99 and outputs their titles.
|
||||
```go
|
||||
path := etree.MustCompilePath("./bookstore/book[p:price='49.99']/title")
|
||||
for _, e := range doc.FindElementsPath(path) {
|
||||
fmt.Println(e.Text())
|
||||
}
|
||||
```
|
||||
|
||||
Output:
|
||||
```
|
||||
XQuery Kick Start
|
||||
```
|
||||
|
||||
Note that this example uses the FindElementsPath function, which takes as an
|
||||
argument a pre-compiled path object. Use precompiled paths when you plan to
|
||||
search with the same path more than once.
|
||||
|
||||
### Other features
|
||||
|
||||
These are just a few examples of the things the etree package can do. See the
|
||||
[documentation](http://godoc.org/github.com/beevik/etree) for a complete
|
||||
description of its capabilities.
|
||||
|
||||
### Contributing
|
||||
|
||||
This project accepts contributions. Just fork the repo and submit a pull
|
||||
request!
|
||||
109
vendor/github.com/beevik/etree/RELEASE_NOTES.md
generated
vendored
Normal file
109
vendor/github.com/beevik/etree/RELEASE_NOTES.md
generated
vendored
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
Release v1.1.0
|
||||
==============
|
||||
|
||||
**New Features**
|
||||
|
||||
* New attribute helpers.
|
||||
* Added the `Element.SortAttrs` method, which lexicographically sorts an
|
||||
element's attributes by key.
|
||||
* New `ReadSettings` properties.
|
||||
* Added `Entity` for the support of custom entity maps.
|
||||
* New `WriteSettings` properties.
|
||||
* Added `UseCRLF` to allow the output of CR-LF newlines instead of the
|
||||
default LF newlines. This is useful on Windows systems.
|
||||
* Additional support for text and CDATA sections.
|
||||
* The `Element.Text` method now returns the concatenation of all consecutive
|
||||
character data tokens immediately following an element's opening tag.
|
||||
* Added `Element.SetCData` to replace the character data immediately
|
||||
following an element's opening tag with a CDATA section.
|
||||
* Added `Element.CreateCData` to create and add a CDATA section child
|
||||
`CharData` token to an element.
|
||||
* Added `Element.CreateText` to create and add a child text `CharData` token
|
||||
to an element.
|
||||
* Added `NewCData` to create a parentless CDATA section `CharData` token.
|
||||
* Added `NewText` to create a parentless text `CharData`
|
||||
token.
|
||||
* Added `CharData.IsCData` to detect if the token contains a CDATA section.
|
||||
* Added `CharData.IsWhitespace` to detect if the token contains whitespace
|
||||
inserted by one of the document Indent functions.
|
||||
* Modified `Element.SetText` so that it replaces a run of consecutive
|
||||
character data tokens following the element's opening tag (instead of just
|
||||
the first one).
|
||||
* New "tail text" support.
|
||||
* Added the `Element.Tail` method, which returns the text immediately
|
||||
following an element's closing tag.
|
||||
* Added the `Element.SetTail` method, which modifies the text immediately
|
||||
following an element's closing tag.
|
||||
* New element child insertion and removal methods.
|
||||
* Added the `Element.InsertChildAt` method, which inserts a new child token
|
||||
before the specified child token index.
|
||||
* Added the `Element.RemoveChildAt` method, which removes the child token at
|
||||
the specified child token index.
|
||||
* New element and attribute queries.
|
||||
* Added the `Element.Index` method, which returns the element's index within
|
||||
its parent element's child token list.
|
||||
* Added the `Element.NamespaceURI` method to return the namespace URI
|
||||
associated with an element.
|
||||
* Added the `Attr.NamespaceURI` method to return the namespace URI
|
||||
associated with an element.
|
||||
* Added the `Attr.Element` method to return the element that an attribute
|
||||
belongs to.
|
||||
* New Path filter functions.
|
||||
* Added `[local-name()='val']` to keep elements whose unprefixed tag matches
|
||||
the desired value.
|
||||
* Added `[name()='val']` to keep elements whose full tag matches the desired
|
||||
value.
|
||||
* Added `[namespace-prefix()='val']` to keep elements whose namespace prefix
|
||||
matches the desired value.
|
||||
* Added `[namespace-uri()='val']` to keep elements whose namespace URI
|
||||
matches the desired value.
|
||||
|
||||
**Bug Fixes**
|
||||
|
||||
* A default XML `CharSetReader` is now used to prevent failed parsing of XML
|
||||
documents using certain encodings.
|
||||
([Issue](https://github.com/beevik/etree/issues/53)).
|
||||
* All characters are now properly escaped according to XML parsing rules.
|
||||
([Issue](https://github.com/beevik/etree/issues/55)).
|
||||
* The `Document.Indent` and `Document.IndentTabs` functions no longer insert
|
||||
empty string `CharData` tokens.
|
||||
|
||||
**Deprecated**
|
||||
|
||||
* `Element`
|
||||
* The `InsertChild` method is deprecated. Use `InsertChildAt` instead.
|
||||
* The `CreateCharData` method is deprecated. Use `CreateText` instead.
|
||||
* `CharData`
|
||||
* The `NewCharData` method is deprecated. Use `NewText` instead.
|
||||
|
||||
|
||||
Release v1.0.1
|
||||
==============
|
||||
|
||||
**Changes**
|
||||
|
||||
* Added support for absolute etree Path queries. An absolute path begins with
|
||||
`/` or `//` and begins its search from the element's document root.
|
||||
* Added [`GetPath`](https://godoc.org/github.com/beevik/etree#Element.GetPath)
|
||||
and [`GetRelativePath`](https://godoc.org/github.com/beevik/etree#Element.GetRelativePath)
|
||||
functions to the [`Element`](https://godoc.org/github.com/beevik/etree#Element)
|
||||
type.
|
||||
|
||||
**Breaking changes**
|
||||
|
||||
* A path starting with `//` is now interpreted as an absolute path.
|
||||
Previously, it was interpreted as a relative path starting from the element
|
||||
whose
|
||||
[`FindElement`](https://godoc.org/github.com/beevik/etree#Element.FindElement)
|
||||
method was called. To remain compatible with this release, all paths
|
||||
prefixed with `//` should be prefixed with `.//` when called from any
|
||||
element other than the document's root.
|
||||
* [**edit 2/1/2019**]: Minor releases should not contain breaking changes.
|
||||
Even though this breaking change was very minor, it was a mistake to include
|
||||
it in this minor release. In the future, all breaking changes will be
|
||||
limited to major releases (e.g., version 2.0.0).
|
||||
|
||||
Release v1.0.0
|
||||
==============
|
||||
|
||||
Initial release.
|
||||
1453
vendor/github.com/beevik/etree/etree.go
generated
vendored
Normal file
1453
vendor/github.com/beevik/etree/etree.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
276
vendor/github.com/beevik/etree/helpers.go
generated
vendored
Normal file
276
vendor/github.com/beevik/etree/helpers.go
generated
vendored
Normal file
|
|
@ -0,0 +1,276 @@
|
|||
// Copyright 2015-2019 Brett Vickers.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package etree
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"io"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
// A simple stack
|
||||
type stack struct {
|
||||
data []interface{}
|
||||
}
|
||||
|
||||
func (s *stack) empty() bool {
|
||||
return len(s.data) == 0
|
||||
}
|
||||
|
||||
func (s *stack) push(value interface{}) {
|
||||
s.data = append(s.data, value)
|
||||
}
|
||||
|
||||
func (s *stack) pop() interface{} {
|
||||
value := s.data[len(s.data)-1]
|
||||
s.data[len(s.data)-1] = nil
|
||||
s.data = s.data[:len(s.data)-1]
|
||||
return value
|
||||
}
|
||||
|
||||
func (s *stack) peek() interface{} {
|
||||
return s.data[len(s.data)-1]
|
||||
}
|
||||
|
||||
// A fifo is a simple first-in-first-out queue.
|
||||
type fifo struct {
|
||||
data []interface{}
|
||||
head, tail int
|
||||
}
|
||||
|
||||
func (f *fifo) add(value interface{}) {
|
||||
if f.len()+1 >= len(f.data) {
|
||||
f.grow()
|
||||
}
|
||||
f.data[f.tail] = value
|
||||
if f.tail++; f.tail == len(f.data) {
|
||||
f.tail = 0
|
||||
}
|
||||
}
|
||||
|
||||
func (f *fifo) remove() interface{} {
|
||||
value := f.data[f.head]
|
||||
f.data[f.head] = nil
|
||||
if f.head++; f.head == len(f.data) {
|
||||
f.head = 0
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
func (f *fifo) len() int {
|
||||
if f.tail >= f.head {
|
||||
return f.tail - f.head
|
||||
}
|
||||
return len(f.data) - f.head + f.tail
|
||||
}
|
||||
|
||||
func (f *fifo) grow() {
|
||||
c := len(f.data) * 2
|
||||
if c == 0 {
|
||||
c = 4
|
||||
}
|
||||
buf, count := make([]interface{}, c), f.len()
|
||||
if f.tail >= f.head {
|
||||
copy(buf[0:count], f.data[f.head:f.tail])
|
||||
} else {
|
||||
hindex := len(f.data) - f.head
|
||||
copy(buf[0:hindex], f.data[f.head:])
|
||||
copy(buf[hindex:count], f.data[:f.tail])
|
||||
}
|
||||
f.data, f.head, f.tail = buf, 0, count
|
||||
}
|
||||
|
||||
// countReader implements a proxy reader that counts the number of
|
||||
// bytes read from its encapsulated reader.
|
||||
type countReader struct {
|
||||
r io.Reader
|
||||
bytes int64
|
||||
}
|
||||
|
||||
func newCountReader(r io.Reader) *countReader {
|
||||
return &countReader{r: r}
|
||||
}
|
||||
|
||||
func (cr *countReader) Read(p []byte) (n int, err error) {
|
||||
b, err := cr.r.Read(p)
|
||||
cr.bytes += int64(b)
|
||||
return b, err
|
||||
}
|
||||
|
||||
// countWriter implements a proxy writer that counts the number of
|
||||
// bytes written by its encapsulated writer.
|
||||
type countWriter struct {
|
||||
w io.Writer
|
||||
bytes int64
|
||||
}
|
||||
|
||||
func newCountWriter(w io.Writer) *countWriter {
|
||||
return &countWriter{w: w}
|
||||
}
|
||||
|
||||
func (cw *countWriter) Write(p []byte) (n int, err error) {
|
||||
b, err := cw.w.Write(p)
|
||||
cw.bytes += int64(b)
|
||||
return b, err
|
||||
}
|
||||
|
||||
// isWhitespace returns true if the byte slice contains only
|
||||
// whitespace characters.
|
||||
func isWhitespace(s string) bool {
|
||||
for i := 0; i < len(s); i++ {
|
||||
if c := s[i]; c != ' ' && c != '\t' && c != '\n' && c != '\r' {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// spaceMatch returns true if namespace a is the empty string
|
||||
// or if namespace a equals namespace b.
|
||||
func spaceMatch(a, b string) bool {
|
||||
switch {
|
||||
case a == "":
|
||||
return true
|
||||
default:
|
||||
return a == b
|
||||
}
|
||||
}
|
||||
|
||||
// spaceDecompose breaks a namespace:tag identifier at the ':'
|
||||
// and returns the two parts.
|
||||
func spaceDecompose(str string) (space, key string) {
|
||||
colon := strings.IndexByte(str, ':')
|
||||
if colon == -1 {
|
||||
return "", str
|
||||
}
|
||||
return str[:colon], str[colon+1:]
|
||||
}
|
||||
|
||||
// Strings used by indentCRLF and indentLF
|
||||
const (
|
||||
indentSpaces = "\r\n "
|
||||
indentTabs = "\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"
|
||||
)
|
||||
|
||||
// indentCRLF returns a CRLF newline followed by n copies of the first
|
||||
// non-CRLF character in the source string.
|
||||
func indentCRLF(n int, source string) string {
|
||||
switch {
|
||||
case n < 0:
|
||||
return source[:2]
|
||||
case n < len(source)-1:
|
||||
return source[:n+2]
|
||||
default:
|
||||
return source + strings.Repeat(source[2:3], n-len(source)+2)
|
||||
}
|
||||
}
|
||||
|
||||
// indentLF returns a LF newline followed by n copies of the first non-LF
|
||||
// character in the source string.
|
||||
func indentLF(n int, source string) string {
|
||||
switch {
|
||||
case n < 0:
|
||||
return source[1:2]
|
||||
case n < len(source)-1:
|
||||
return source[1 : n+2]
|
||||
default:
|
||||
return source[1:] + strings.Repeat(source[2:3], n-len(source)+2)
|
||||
}
|
||||
}
|
||||
|
||||
// nextIndex returns the index of the next occurrence of sep in s,
|
||||
// starting from offset. It returns -1 if the sep string is not found.
|
||||
func nextIndex(s, sep string, offset int) int {
|
||||
switch i := strings.Index(s[offset:], sep); i {
|
||||
case -1:
|
||||
return -1
|
||||
default:
|
||||
return offset + i
|
||||
}
|
||||
}
|
||||
|
||||
// isInteger returns true if the string s contains an integer.
|
||||
func isInteger(s string) bool {
|
||||
for i := 0; i < len(s); i++ {
|
||||
if (s[i] < '0' || s[i] > '9') && !(i == 0 && s[i] == '-') {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
type escapeMode byte
|
||||
|
||||
const (
|
||||
escapeNormal escapeMode = iota
|
||||
escapeCanonicalText
|
||||
escapeCanonicalAttr
|
||||
)
|
||||
|
||||
// escapeString writes an escaped version of a string to the writer.
|
||||
func escapeString(w *bufio.Writer, s string, m escapeMode) {
|
||||
var esc []byte
|
||||
last := 0
|
||||
for i := 0; i < len(s); {
|
||||
r, width := utf8.DecodeRuneInString(s[i:])
|
||||
i += width
|
||||
switch r {
|
||||
case '&':
|
||||
esc = []byte("&")
|
||||
case '<':
|
||||
esc = []byte("<")
|
||||
case '>':
|
||||
if m == escapeCanonicalAttr {
|
||||
continue
|
||||
}
|
||||
esc = []byte(">")
|
||||
case '\'':
|
||||
if m != escapeNormal {
|
||||
continue
|
||||
}
|
||||
esc = []byte("'")
|
||||
case '"':
|
||||
if m == escapeCanonicalText {
|
||||
continue
|
||||
}
|
||||
esc = []byte(""")
|
||||
case '\t':
|
||||
if m != escapeCanonicalAttr {
|
||||
continue
|
||||
}
|
||||
esc = []byte("	")
|
||||
case '\n':
|
||||
if m != escapeCanonicalAttr {
|
||||
continue
|
||||
}
|
||||
esc = []byte("
")
|
||||
case '\r':
|
||||
if m == escapeNormal {
|
||||
continue
|
||||
}
|
||||
esc = []byte("
")
|
||||
default:
|
||||
if !isInCharacterRange(r) || (r == 0xFFFD && width == 1) {
|
||||
esc = []byte("\uFFFD")
|
||||
break
|
||||
}
|
||||
continue
|
||||
}
|
||||
w.WriteString(s[last : i-width])
|
||||
w.Write(esc)
|
||||
last = i
|
||||
}
|
||||
w.WriteString(s[last:])
|
||||
}
|
||||
|
||||
func isInCharacterRange(r rune) bool {
|
||||
return r == 0x09 ||
|
||||
r == 0x0A ||
|
||||
r == 0x0D ||
|
||||
r >= 0x20 && r <= 0xD7FF ||
|
||||
r >= 0xE000 && r <= 0xFFFD ||
|
||||
r >= 0x10000 && r <= 0x10FFFF
|
||||
}
|
||||
582
vendor/github.com/beevik/etree/path.go
generated
vendored
Normal file
582
vendor/github.com/beevik/etree/path.go
generated
vendored
Normal file
|
|
@ -0,0 +1,582 @@
|
|||
// Copyright 2015-2019 Brett Vickers.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package etree
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
/*
|
||||
A Path is a string that represents a search path through an etree starting
|
||||
from the document root or an arbitrary element. Paths are used with the
|
||||
Element object's Find* methods to locate and return desired elements.
|
||||
|
||||
A Path consists of a series of slash-separated "selectors", each of which may
|
||||
be modified by one or more bracket-enclosed "filters". Selectors are used to
|
||||
traverse the etree from element to element, while filters are used to narrow
|
||||
the list of candidate elements at each node.
|
||||
|
||||
Although etree Path strings are similar to XPath strings
|
||||
(https://www.w3.org/TR/1999/REC-xpath-19991116/), they have a more limited set
|
||||
of selectors and filtering options.
|
||||
|
||||
The following selectors are supported by etree Path strings:
|
||||
|
||||
. Select the current element.
|
||||
.. Select the parent of the current element.
|
||||
* Select all child elements of the current element.
|
||||
/ Select the root element when used at the start of a path.
|
||||
// Select all descendants of the current element.
|
||||
tag Select all child elements with a name matching the tag.
|
||||
|
||||
The following basic filters are supported by etree Path strings:
|
||||
|
||||
[@attrib] Keep elements with an attribute named attrib.
|
||||
[@attrib='val'] Keep elements with an attribute named attrib and value matching val.
|
||||
[tag] Keep elements with a child element named tag.
|
||||
[tag='val'] Keep elements with a child element named tag and text matching val.
|
||||
[n] Keep the n-th element, where n is a numeric index starting from 1.
|
||||
|
||||
The following function filters are also supported:
|
||||
|
||||
[text()] Keep elements with non-empty text.
|
||||
[text()='val'] Keep elements whose text matches val.
|
||||
[local-name()='val'] Keep elements whose un-prefixed tag matches val.
|
||||
[name()='val'] Keep elements whose full tag exactly matches val.
|
||||
[namespace-prefix()='val'] Keep elements whose namespace prefix matches val.
|
||||
[namespace-uri()='val'] Keep elements whose namespace URI matches val.
|
||||
|
||||
Here are some examples of Path strings:
|
||||
|
||||
- Select the bookstore child element of the root element:
|
||||
/bookstore
|
||||
|
||||
- Beginning from the root element, select the title elements of all
|
||||
descendant book elements having a 'category' attribute of 'WEB':
|
||||
//book[@category='WEB']/title
|
||||
|
||||
- Beginning from the current element, select the first descendant
|
||||
book element with a title child element containing the text 'Great
|
||||
Expectations':
|
||||
.//book[title='Great Expectations'][1]
|
||||
|
||||
- Beginning from the current element, select all child elements of
|
||||
book elements with an attribute 'language' set to 'english':
|
||||
./book/*[@language='english']
|
||||
|
||||
- Beginning from the current element, select all child elements of
|
||||
book elements containing the text 'special':
|
||||
./book/*[text()='special']
|
||||
|
||||
- Beginning from the current element, select all descendant book
|
||||
elements whose title child element has a 'language' attribute of 'french':
|
||||
.//book/title[@language='french']/..
|
||||
|
||||
- Beginning from the current element, select all book elements
|
||||
belonging to the http://www.w3.org/TR/html4/ namespace:
|
||||
.//book[namespace-uri()='http://www.w3.org/TR/html4/']
|
||||
|
||||
*/
|
||||
type Path struct {
|
||||
segments []segment
|
||||
}
|
||||
|
||||
// ErrPath is returned by path functions when an invalid etree path is provided.
|
||||
type ErrPath string
|
||||
|
||||
// Error returns the string describing a path error.
|
||||
func (err ErrPath) Error() string {
|
||||
return "etree: " + string(err)
|
||||
}
|
||||
|
||||
// CompilePath creates an optimized version of an XPath-like string that
|
||||
// can be used to query elements in an element tree.
|
||||
func CompilePath(path string) (Path, error) {
|
||||
var comp compiler
|
||||
segments := comp.parsePath(path)
|
||||
if comp.err != ErrPath("") {
|
||||
return Path{nil}, comp.err
|
||||
}
|
||||
return Path{segments}, nil
|
||||
}
|
||||
|
||||
// MustCompilePath creates an optimized version of an XPath-like string that
|
||||
// can be used to query elements in an element tree. Panics if an error
|
||||
// occurs. Use this function to create Paths when you know the path is
|
||||
// valid (i.e., if it's hard-coded).
|
||||
func MustCompilePath(path string) Path {
|
||||
p, err := CompilePath(path)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
// A segment is a portion of a path between "/" characters.
|
||||
// It contains one selector and zero or more [filters].
|
||||
type segment struct {
|
||||
sel selector
|
||||
filters []filter
|
||||
}
|
||||
|
||||
func (seg *segment) apply(e *Element, p *pather) {
|
||||
seg.sel.apply(e, p)
|
||||
for _, f := range seg.filters {
|
||||
f.apply(p)
|
||||
}
|
||||
}
|
||||
|
||||
// A selector selects XML elements for consideration by the
|
||||
// path traversal.
|
||||
type selector interface {
|
||||
apply(e *Element, p *pather)
|
||||
}
|
||||
|
||||
// A filter pares down a list of candidate XML elements based
|
||||
// on a path filter in [brackets].
|
||||
type filter interface {
|
||||
apply(p *pather)
|
||||
}
|
||||
|
||||
// A pather is helper object that traverses an element tree using
|
||||
// a Path object. It collects and deduplicates all elements matching
|
||||
// the path query.
|
||||
type pather struct {
|
||||
queue fifo
|
||||
results []*Element
|
||||
inResults map[*Element]bool
|
||||
candidates []*Element
|
||||
scratch []*Element // used by filters
|
||||
}
|
||||
|
||||
// A node represents an element and the remaining path segments that
|
||||
// should be applied against it by the pather.
|
||||
type node struct {
|
||||
e *Element
|
||||
segments []segment
|
||||
}
|
||||
|
||||
func newPather() *pather {
|
||||
return &pather{
|
||||
results: make([]*Element, 0),
|
||||
inResults: make(map[*Element]bool),
|
||||
candidates: make([]*Element, 0),
|
||||
scratch: make([]*Element, 0),
|
||||
}
|
||||
}
|
||||
|
||||
// traverse follows the path from the element e, collecting
|
||||
// and then returning all elements that match the path's selectors
|
||||
// and filters.
|
||||
func (p *pather) traverse(e *Element, path Path) []*Element {
|
||||
for p.queue.add(node{e, path.segments}); p.queue.len() > 0; {
|
||||
p.eval(p.queue.remove().(node))
|
||||
}
|
||||
return p.results
|
||||
}
|
||||
|
||||
// eval evalutes the current path node by applying the remaining
|
||||
// path's selector rules against the node's element.
|
||||
func (p *pather) eval(n node) {
|
||||
p.candidates = p.candidates[0:0]
|
||||
seg, remain := n.segments[0], n.segments[1:]
|
||||
seg.apply(n.e, p)
|
||||
|
||||
if len(remain) == 0 {
|
||||
for _, c := range p.candidates {
|
||||
if in := p.inResults[c]; !in {
|
||||
p.inResults[c] = true
|
||||
p.results = append(p.results, c)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for _, c := range p.candidates {
|
||||
p.queue.add(node{c, remain})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A compiler generates a compiled path from a path string.
|
||||
type compiler struct {
|
||||
err ErrPath
|
||||
}
|
||||
|
||||
// parsePath parses an XPath-like string describing a path
|
||||
// through an element tree and returns a slice of segment
|
||||
// descriptors.
|
||||
func (c *compiler) parsePath(path string) []segment {
|
||||
// If path ends with //, fix it
|
||||
if strings.HasSuffix(path, "//") {
|
||||
path = path + "*"
|
||||
}
|
||||
|
||||
var segments []segment
|
||||
|
||||
// Check for an absolute path
|
||||
if strings.HasPrefix(path, "/") {
|
||||
segments = append(segments, segment{new(selectRoot), []filter{}})
|
||||
path = path[1:]
|
||||
}
|
||||
|
||||
// Split path into segments
|
||||
for _, s := range splitPath(path) {
|
||||
segments = append(segments, c.parseSegment(s))
|
||||
if c.err != ErrPath("") {
|
||||
break
|
||||
}
|
||||
}
|
||||
return segments
|
||||
}
|
||||
|
||||
func splitPath(path string) []string {
|
||||
pieces := make([]string, 0)
|
||||
start := 0
|
||||
inquote := false
|
||||
for i := 0; i+1 <= len(path); i++ {
|
||||
if path[i] == '\'' {
|
||||
inquote = !inquote
|
||||
} else if path[i] == '/' && !inquote {
|
||||
pieces = append(pieces, path[start:i])
|
||||
start = i + 1
|
||||
}
|
||||
}
|
||||
return append(pieces, path[start:])
|
||||
}
|
||||
|
||||
// parseSegment parses a path segment between / characters.
|
||||
func (c *compiler) parseSegment(path string) segment {
|
||||
pieces := strings.Split(path, "[")
|
||||
seg := segment{
|
||||
sel: c.parseSelector(pieces[0]),
|
||||
filters: []filter{},
|
||||
}
|
||||
for i := 1; i < len(pieces); i++ {
|
||||
fpath := pieces[i]
|
||||
if fpath[len(fpath)-1] != ']' {
|
||||
c.err = ErrPath("path has invalid filter [brackets].")
|
||||
break
|
||||
}
|
||||
seg.filters = append(seg.filters, c.parseFilter(fpath[:len(fpath)-1]))
|
||||
}
|
||||
return seg
|
||||
}
|
||||
|
||||
// parseSelector parses a selector at the start of a path segment.
|
||||
func (c *compiler) parseSelector(path string) selector {
|
||||
switch path {
|
||||
case ".":
|
||||
return new(selectSelf)
|
||||
case "..":
|
||||
return new(selectParent)
|
||||
case "*":
|
||||
return new(selectChildren)
|
||||
case "":
|
||||
return new(selectDescendants)
|
||||
default:
|
||||
return newSelectChildrenByTag(path)
|
||||
}
|
||||
}
|
||||
|
||||
var fnTable = map[string]struct {
|
||||
hasFn func(e *Element) bool
|
||||
getValFn func(e *Element) string
|
||||
}{
|
||||
"local-name": {nil, (*Element).name},
|
||||
"name": {nil, (*Element).FullTag},
|
||||
"namespace-prefix": {nil, (*Element).namespacePrefix},
|
||||
"namespace-uri": {nil, (*Element).NamespaceURI},
|
||||
"text": {(*Element).hasText, (*Element).Text},
|
||||
}
|
||||
|
||||
// parseFilter parses a path filter contained within [brackets].
|
||||
func (c *compiler) parseFilter(path string) filter {
|
||||
if len(path) == 0 {
|
||||
c.err = ErrPath("path contains an empty filter expression.")
|
||||
return nil
|
||||
}
|
||||
|
||||
// Filter contains [@attr='val'], [fn()='val'], or [tag='val']?
|
||||
eqindex := strings.Index(path, "='")
|
||||
if eqindex >= 0 {
|
||||
rindex := nextIndex(path, "'", eqindex+2)
|
||||
if rindex != len(path)-1 {
|
||||
c.err = ErrPath("path has mismatched filter quotes.")
|
||||
return nil
|
||||
}
|
||||
|
||||
key := path[:eqindex]
|
||||
value := path[eqindex+2 : rindex]
|
||||
|
||||
switch {
|
||||
case key[0] == '@':
|
||||
return newFilterAttrVal(key[1:], value)
|
||||
case strings.HasSuffix(key, "()"):
|
||||
fn := key[:len(key)-2]
|
||||
if t, ok := fnTable[fn]; ok && t.getValFn != nil {
|
||||
return newFilterFuncVal(t.getValFn, value)
|
||||
}
|
||||
c.err = ErrPath("path has unknown function " + fn)
|
||||
return nil
|
||||
default:
|
||||
return newFilterChildText(key, value)
|
||||
}
|
||||
}
|
||||
|
||||
// Filter contains [@attr], [N], [tag] or [fn()]
|
||||
switch {
|
||||
case path[0] == '@':
|
||||
return newFilterAttr(path[1:])
|
||||
case strings.HasSuffix(path, "()"):
|
||||
fn := path[:len(path)-2]
|
||||
if t, ok := fnTable[fn]; ok && t.hasFn != nil {
|
||||
return newFilterFunc(t.hasFn)
|
||||
}
|
||||
c.err = ErrPath("path has unknown function " + fn)
|
||||
return nil
|
||||
case isInteger(path):
|
||||
pos, _ := strconv.Atoi(path)
|
||||
switch {
|
||||
case pos > 0:
|
||||
return newFilterPos(pos - 1)
|
||||
default:
|
||||
return newFilterPos(pos)
|
||||
}
|
||||
default:
|
||||
return newFilterChild(path)
|
||||
}
|
||||
}
|
||||
|
||||
// selectSelf selects the current element into the candidate list.
|
||||
type selectSelf struct{}
|
||||
|
||||
func (s *selectSelf) apply(e *Element, p *pather) {
|
||||
p.candidates = append(p.candidates, e)
|
||||
}
|
||||
|
||||
// selectRoot selects the element's root node.
|
||||
type selectRoot struct{}
|
||||
|
||||
func (s *selectRoot) apply(e *Element, p *pather) {
|
||||
root := e
|
||||
for root.parent != nil {
|
||||
root = root.parent
|
||||
}
|
||||
p.candidates = append(p.candidates, root)
|
||||
}
|
||||
|
||||
// selectParent selects the element's parent into the candidate list.
|
||||
type selectParent struct{}
|
||||
|
||||
func (s *selectParent) apply(e *Element, p *pather) {
|
||||
if e.parent != nil {
|
||||
p.candidates = append(p.candidates, e.parent)
|
||||
}
|
||||
}
|
||||
|
||||
// selectChildren selects the element's child elements into the
|
||||
// candidate list.
|
||||
type selectChildren struct{}
|
||||
|
||||
func (s *selectChildren) apply(e *Element, p *pather) {
|
||||
for _, c := range e.Child {
|
||||
if c, ok := c.(*Element); ok {
|
||||
p.candidates = append(p.candidates, c)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// selectDescendants selects all descendant child elements
|
||||
// of the element into the candidate list.
|
||||
type selectDescendants struct{}
|
||||
|
||||
func (s *selectDescendants) apply(e *Element, p *pather) {
|
||||
var queue fifo
|
||||
for queue.add(e); queue.len() > 0; {
|
||||
e := queue.remove().(*Element)
|
||||
p.candidates = append(p.candidates, e)
|
||||
for _, c := range e.Child {
|
||||
if c, ok := c.(*Element); ok {
|
||||
queue.add(c)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// selectChildrenByTag selects into the candidate list all child
|
||||
// elements of the element having the specified tag.
|
||||
type selectChildrenByTag struct {
|
||||
space, tag string
|
||||
}
|
||||
|
||||
func newSelectChildrenByTag(path string) *selectChildrenByTag {
|
||||
s, l := spaceDecompose(path)
|
||||
return &selectChildrenByTag{s, l}
|
||||
}
|
||||
|
||||
func (s *selectChildrenByTag) apply(e *Element, p *pather) {
|
||||
for _, c := range e.Child {
|
||||
if c, ok := c.(*Element); ok && spaceMatch(s.space, c.Space) && s.tag == c.Tag {
|
||||
p.candidates = append(p.candidates, c)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// filterPos filters the candidate list, keeping only the
|
||||
// candidate at the specified index.
|
||||
type filterPos struct {
|
||||
index int
|
||||
}
|
||||
|
||||
func newFilterPos(pos int) *filterPos {
|
||||
return &filterPos{pos}
|
||||
}
|
||||
|
||||
func (f *filterPos) apply(p *pather) {
|
||||
if f.index >= 0 {
|
||||
if f.index < len(p.candidates) {
|
||||
p.scratch = append(p.scratch, p.candidates[f.index])
|
||||
}
|
||||
} else {
|
||||
if -f.index <= len(p.candidates) {
|
||||
p.scratch = append(p.scratch, p.candidates[len(p.candidates)+f.index])
|
||||
}
|
||||
}
|
||||
p.candidates, p.scratch = p.scratch, p.candidates[0:0]
|
||||
}
|
||||
|
||||
// filterAttr filters the candidate list for elements having
|
||||
// the specified attribute.
|
||||
type filterAttr struct {
|
||||
space, key string
|
||||
}
|
||||
|
||||
func newFilterAttr(str string) *filterAttr {
|
||||
s, l := spaceDecompose(str)
|
||||
return &filterAttr{s, l}
|
||||
}
|
||||
|
||||
func (f *filterAttr) apply(p *pather) {
|
||||
for _, c := range p.candidates {
|
||||
for _, a := range c.Attr {
|
||||
if spaceMatch(f.space, a.Space) && f.key == a.Key {
|
||||
p.scratch = append(p.scratch, c)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
p.candidates, p.scratch = p.scratch, p.candidates[0:0]
|
||||
}
|
||||
|
||||
// filterAttrVal filters the candidate list for elements having
|
||||
// the specified attribute with the specified value.
|
||||
type filterAttrVal struct {
|
||||
space, key, val string
|
||||
}
|
||||
|
||||
func newFilterAttrVal(str, value string) *filterAttrVal {
|
||||
s, l := spaceDecompose(str)
|
||||
return &filterAttrVal{s, l, value}
|
||||
}
|
||||
|
||||
func (f *filterAttrVal) apply(p *pather) {
|
||||
for _, c := range p.candidates {
|
||||
for _, a := range c.Attr {
|
||||
if spaceMatch(f.space, a.Space) && f.key == a.Key && f.val == a.Value {
|
||||
p.scratch = append(p.scratch, c)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
p.candidates, p.scratch = p.scratch, p.candidates[0:0]
|
||||
}
|
||||
|
||||
// filterFunc filters the candidate list for elements satisfying a custom
|
||||
// boolean function.
|
||||
type filterFunc struct {
|
||||
fn func(e *Element) bool
|
||||
}
|
||||
|
||||
func newFilterFunc(fn func(e *Element) bool) *filterFunc {
|
||||
return &filterFunc{fn}
|
||||
}
|
||||
|
||||
func (f *filterFunc) apply(p *pather) {
|
||||
for _, c := range p.candidates {
|
||||
if f.fn(c) {
|
||||
p.scratch = append(p.scratch, c)
|
||||
}
|
||||
}
|
||||
p.candidates, p.scratch = p.scratch, p.candidates[0:0]
|
||||
}
|
||||
|
||||
// filterFuncVal filters the candidate list for elements containing a value
|
||||
// matching the result of a custom function.
|
||||
type filterFuncVal struct {
|
||||
fn func(e *Element) string
|
||||
val string
|
||||
}
|
||||
|
||||
func newFilterFuncVal(fn func(e *Element) string, value string) *filterFuncVal {
|
||||
return &filterFuncVal{fn, value}
|
||||
}
|
||||
|
||||
func (f *filterFuncVal) apply(p *pather) {
|
||||
for _, c := range p.candidates {
|
||||
if f.fn(c) == f.val {
|
||||
p.scratch = append(p.scratch, c)
|
||||
}
|
||||
}
|
||||
p.candidates, p.scratch = p.scratch, p.candidates[0:0]
|
||||
}
|
||||
|
||||
// filterChild filters the candidate list for elements having
|
||||
// a child element with the specified tag.
|
||||
type filterChild struct {
|
||||
space, tag string
|
||||
}
|
||||
|
||||
func newFilterChild(str string) *filterChild {
|
||||
s, l := spaceDecompose(str)
|
||||
return &filterChild{s, l}
|
||||
}
|
||||
|
||||
func (f *filterChild) apply(p *pather) {
|
||||
for _, c := range p.candidates {
|
||||
for _, cc := range c.Child {
|
||||
if cc, ok := cc.(*Element); ok &&
|
||||
spaceMatch(f.space, cc.Space) &&
|
||||
f.tag == cc.Tag {
|
||||
p.scratch = append(p.scratch, c)
|
||||
}
|
||||
}
|
||||
}
|
||||
p.candidates, p.scratch = p.scratch, p.candidates[0:0]
|
||||
}
|
||||
|
||||
// filterChildText filters the candidate list for elements having
|
||||
// a child element with the specified tag and text.
|
||||
type filterChildText struct {
|
||||
space, tag, text string
|
||||
}
|
||||
|
||||
func newFilterChildText(str, text string) *filterChildText {
|
||||
s, l := spaceDecompose(str)
|
||||
return &filterChildText{s, l, text}
|
||||
}
|
||||
|
||||
func (f *filterChildText) apply(p *pather) {
|
||||
for _, c := range p.candidates {
|
||||
for _, cc := range c.Child {
|
||||
if cc, ok := cc.(*Element); ok &&
|
||||
spaceMatch(f.space, cc.Space) &&
|
||||
f.tag == cc.Tag &&
|
||||
f.text == cc.Text() {
|
||||
p.scratch = append(p.scratch, c)
|
||||
}
|
||||
}
|
||||
}
|
||||
p.candidates, p.scratch = p.scratch, p.candidates[0:0]
|
||||
}
|
||||
78
vendor/github.com/crewjam/httperr/.golangci.yml
generated
vendored
Normal file
78
vendor/github.com/crewjam/httperr/.golangci.yml
generated
vendored
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
# Configuration file for golangci-lint
|
||||
#
|
||||
# https://github.com/golangci/golangci-lint
|
||||
#
|
||||
# fighting with false positives?
|
||||
# https://github.com/golangci/golangci-lint#nolint
|
||||
|
||||
linters:
|
||||
enable:
|
||||
- gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification [fast: true, auto-fix: true]
|
||||
- goimports # Goimports does everything that gofmt does. Additionally it checks unused imports [fast: true, auto-fix: true]
|
||||
- gosec # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases [fast: true, auto-fix: false]
|
||||
- misspell # Finds commonly misspelled English words in comments [fast: true, auto-fix: true]
|
||||
- deadcode # Finds unused code [fast: true, auto-fix: false]
|
||||
- golint # Golint differs from gofmt. Gofmt reformats Go source code, whereas golint prints out style mistakes [fast: true, auto-fix: false]
|
||||
|
||||
disable:
|
||||
# TODO(ross): fix errors reported by these checkers and enable them
|
||||
- bodyclose # checks whether HTTP response body is closed successfully [fast: false, auto-fix: false]
|
||||
- depguard # Go linter that checks if package imports are in a list of acceptable packages [fast: true, auto-fix: false]
|
||||
- dupl # Tool for code clone detection [fast: true, auto-fix: false]
|
||||
- errcheck # Inspects source code for security problems [fast: true, auto-fix: false]
|
||||
- gochecknoglobals # Checks that no globals are present in Go code [fast: true, auto-fix: false]
|
||||
- gochecknoinits # Checks that no init functions are present in Go code [fast: true, auto-fix: false]
|
||||
- goconst # Finds repeated strings that could be replaced by a constant [fast: true, auto-fix: false]
|
||||
- gocritic # The most opinionated Go source code linter [fast: true, auto-fix: false]
|
||||
- gocyclo # Computes and checks the cyclomatic complexity of functions [fast: true, auto-fix: false]
|
||||
- gosimple # Linter for Go source code that specializes in simplifying a code [fast: false, auto-fix: false]
|
||||
- govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string [fast: false, auto-fix: false]
|
||||
- ineffassign # Detects when assignments to existing variables are not used [fast: true, auto-fix: false]
|
||||
- interfacer # Linter that suggests narrower interface types [fast: false, auto-fix: false]
|
||||
- lll # Reports long lines [fast: true, auto-fix: false]
|
||||
- maligned # Tool to detect Go structs that would take less memory if their fields were sorted [fast: true, auto-fix: false]
|
||||
- nakedret # Finds naked returns in functions greater than a specified function length [fast: true, auto-fix: false]
|
||||
- prealloc # Finds slice declarations that could potentially be preallocated [fast: true, auto-fix: false]
|
||||
- scopelint # Scopelint checks for unpinned variables in go programs [fast: true, auto-fix: false]
|
||||
- staticcheck # Staticcheck is a go vet on steroids, applying a ton of static analysis checks [fast: false, auto-fix: false]
|
||||
- structcheck # Finds unused struct fields [fast: true, auto-fix: false]
|
||||
- stylecheck # Stylecheck is a replacement for golint [fast: false, auto-fix: false]
|
||||
- typecheck # Like the front-end of a Go compiler, parses and type-checks Go code [fast: true, auto-fix: false]
|
||||
- unconvert # Remove unnecessary type conversions [fast: true, auto-fix: false]
|
||||
- unparam # Reports unused function parameters [fast: false, auto-fix: false]
|
||||
- unused # Checks Go code for unused constants, variables, functions and types [fast: false, auto-fix: false]
|
||||
- varcheck # Finds unused global variables and constants [fast: true, auto-fix: false]
|
||||
linters-settings:
|
||||
goimports:
|
||||
local-prefixes: github.com/crewjam/saml
|
||||
govet:
|
||||
disable:
|
||||
- shadow
|
||||
enable:
|
||||
- asmdecl
|
||||
- assign
|
||||
- atomic
|
||||
- bools
|
||||
- buildtag
|
||||
- cgocall
|
||||
- composites
|
||||
- copylocks
|
||||
- errorsas
|
||||
- httpresponse
|
||||
- loopclosure
|
||||
- lostcancel
|
||||
- nilfunc
|
||||
- printf
|
||||
- shift
|
||||
- stdmethods
|
||||
- structtag
|
||||
- tests
|
||||
- unmarshal
|
||||
- unreachable
|
||||
- unsafeptr
|
||||
- unusedresult
|
||||
issues:
|
||||
exclude-use-default: false
|
||||
exclude:
|
||||
- G104 # 'Errors unhandled. (gosec)
|
||||
|
||||
13
vendor/github.com/crewjam/httperr/.travis.yml
generated
vendored
Normal file
13
vendor/github.com/crewjam/httperr/.travis.yml
generated
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
language: go
|
||||
|
||||
env: GO111MODULE=on
|
||||
|
||||
before_script:
|
||||
- curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(go env GOPATH)/bin v1.21.0
|
||||
|
||||
script:
|
||||
- golangci-lint run
|
||||
- go test -v ./...
|
||||
|
||||
go:
|
||||
- tip
|
||||
23
vendor/github.com/crewjam/httperr/LICENSE
generated
vendored
Normal file
23
vendor/github.com/crewjam/httperr/LICENSE
generated
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
Copyright (c) 2016, Ross Kinder
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
152
vendor/github.com/crewjam/httperr/README.md
generated
vendored
Normal file
152
vendor/github.com/crewjam/httperr/README.md
generated
vendored
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
# httperr
|
||||
|
||||
[](https://godoc.org/github.com/crewjam/httperr)
|
||||
|
||||
[](https://travis-ci.org/crewjam/httperr)
|
||||
|
||||
Package httperr provides utilities for handling error conditions in http
|
||||
clients and servers.
|
||||
|
||||
## Client
|
||||
|
||||
This package provides an http.Client that returns errors for requests that return
|
||||
a status code >= 400. It lets you turn code like this:
|
||||
|
||||
```golang
|
||||
func GetFoo() {
|
||||
req, _ := http.NewRequest("GET", "https://api.example.com/foo", nil)
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if resp.StatusCode >= 400 {
|
||||
return nil, fmt.Errorf("api call failed: %d", resp.StatusCode)
|
||||
}
|
||||
// ....
|
||||
}
|
||||
```
|
||||
|
||||
Into code like this:
|
||||
|
||||
```golang
|
||||
func GetFoo() {
|
||||
req, _ := http.NewRequest("GET", "https://api.example.com/foo", nil)
|
||||
resp, err := httperr.Client().Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// ....
|
||||
}
|
||||
```
|
||||
|
||||
Wow, three whole lines. Life changing, eh? But wait, there's more!
|
||||
|
||||
You can have the client parse structured errors returned from an API:
|
||||
|
||||
```golang
|
||||
|
||||
type APIError struct {
|
||||
Message string `json:"message"`
|
||||
Code string `json:"code"`
|
||||
}
|
||||
|
||||
func (a APIError) Error() string {
|
||||
// APIError must implement the Error interface
|
||||
return fmt.Sprintf("%s (code %d)", a.Message, a.Code)
|
||||
}
|
||||
|
||||
func GetFoo() {
|
||||
client := httperr.Client(http.DefaultClient, httperr.JSON(APIError{}))
|
||||
|
||||
req, _ := http.NewRequest("GET", "https://api.example.com/foo", nil)
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
// If the server returned a status code >= 400, and the response was valid
|
||||
// JSON for APIError, then err is an *APIErr.
|
||||
return nil, err
|
||||
}
|
||||
// ....
|
||||
}
|
||||
```
|
||||
|
||||
## Server
|
||||
|
||||
Error handling in Go's http.Handler and http.HandlerFunc can be tricky. I often found myself wishing that we could just return an `err` and be done with things.
|
||||
|
||||
This package provides an adapter function which turns:
|
||||
|
||||
```golang
|
||||
func (s *Server) getUser(w http.ResponseWriter, r *http.Request) {
|
||||
remoteUser, err := s.Auth.RequireUser(w, r)
|
||||
if err != nil {
|
||||
http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
user, err := s.Storage.Get(remoteUser.Name)
|
||||
if err != nil {
|
||||
log.Printf("ERROR: cannot fetch user: %s", err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
json.NewEncoder(w).Encode(user)
|
||||
}
|
||||
```
|
||||
|
||||
Into this:
|
||||
|
||||
```golang
|
||||
func (s *Server) getUser(w http.ResponseWriter, r *http.Request) error {
|
||||
remoteUser, err := s.Auth.RequireUser(w, r)
|
||||
if err != nil {
|
||||
return httperr.Unauthorized
|
||||
}
|
||||
|
||||
user, err := s.Storage.Get(remoteUser.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return json.NewEncoder(w).Encode(user)
|
||||
}
|
||||
```
|
||||
|
||||
Life changing? Probably not, but it seems to remove a lot of redundancy and make control flow in web servers simpler.
|
||||
|
||||
You can also wrap your calls with middleware that allow you to provide custom handling of errors that are returned from your handlers, but also >= 400 status codes issued by handlers that don't return errors.
|
||||
|
||||
```golang
|
||||
htmlErrorTmpl := template.Must(template.New("err").Parse(errorTemplate))
|
||||
handler := httperr.Middleware{
|
||||
OnError: func(w http.ResponseWriter, r *http.Request, err error) error {
|
||||
log.Printf("REQUEST ERROR: %s", err)
|
||||
if acceptHeaderContainsTextHTML(r) {
|
||||
htmlErrorTmpl.Execute(w, struct{ Error error }{Error: err})
|
||||
return nil // nil means we've handled the error
|
||||
}
|
||||
return err // fall back to the default
|
||||
},
|
||||
Handler: httperr.HandlerFunc(func(w http.ResponseWriter, r *http.Request) error {
|
||||
if r.Method != "POST" {
|
||||
return httperr.MethodNotAllowed
|
||||
}
|
||||
var reqBody RequestBody
|
||||
if err := json.NewDecoder(r.Body).Decode(&reqBody); err != nil {
|
||||
return httperr.Public{
|
||||
StatusCode: http.StatusBadRequest,
|
||||
Err: err,
|
||||
}
|
||||
}
|
||||
|
||||
if reqBody.Count <= 0 {
|
||||
// The client won't see this, instead OnError will be called with a httperr.Response containing
|
||||
// the response. The OnError function can decide to write the error, or replace it with it's own.
|
||||
w.WriteHeader(http.StatusConflict)
|
||||
fmt.Fprintln(w, "an obscure internal error happened, but the user doesn't want to see this.")
|
||||
return nil
|
||||
}
|
||||
|
||||
// ...
|
||||
return nil
|
||||
}),
|
||||
}
|
||||
```
|
||||
120
vendor/github.com/crewjam/httperr/client.go
generated
vendored
Normal file
120
vendor/github.com/crewjam/httperr/client.go
generated
vendored
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
package httperr
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
// ClientArg is an argument to Client
|
||||
type ClientArg func(xport *Transport)
|
||||
|
||||
// Client returns an http.Client that wraps client with
|
||||
// an error handling transport.
|
||||
func Client(next *http.Client, args ...ClientArg) *http.Client {
|
||||
xport := Transport{Next: next.Transport}
|
||||
for _, arg := range args {
|
||||
arg(&xport)
|
||||
}
|
||||
|
||||
rv := *next
|
||||
rv.Transport = xport
|
||||
return &rv
|
||||
}
|
||||
|
||||
// DefaultClient returns an http.Client that wraps the default
|
||||
// http.Client with an error handling transport.
|
||||
func DefaultClient() *http.Client {
|
||||
return Client(http.DefaultClient)
|
||||
}
|
||||
|
||||
var _ http.RoundTripper = Transport{}
|
||||
|
||||
// Transport is an http.RoundTripper that intercepts responses where
|
||||
// the StatusCode >= 400 and returns a Response{}.
|
||||
//
|
||||
// If ErrorFactory is specified it should return an error that can be used
|
||||
// to unmarshal a JSON error response. This is useful when a web service
|
||||
// offers structured error information. If the error structure cannot be
|
||||
// unmarshalled, then a regular Response error is returned.
|
||||
//
|
||||
// type APIError struct {
|
||||
// Code string `json:"code"`
|
||||
// Message string `json:"message"`
|
||||
// }
|
||||
//
|
||||
// func (a APIError) Error() string {
|
||||
// return fmt.Sprintf("%s (%d)", a.Message, a.Code)
|
||||
// }
|
||||
//
|
||||
// t := Transport{
|
||||
// ErrorFactory: func() error {
|
||||
// return &APIError{}
|
||||
// },
|
||||
// }
|
||||
//
|
||||
type Transport struct {
|
||||
Next http.RoundTripper
|
||||
OnError func(req *http.Request, resp *http.Response) error
|
||||
}
|
||||
|
||||
// RoundTrip implements http.RoundTripper.
|
||||
func (t Transport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
next := t.Next
|
||||
if next == nil {
|
||||
next = http.DefaultTransport
|
||||
}
|
||||
|
||||
resp, err := next.RoundTrip(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if resp.StatusCode < 400 {
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
if t.OnError != nil {
|
||||
if err := t.OnError(req, resp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return nil, Response(*resp)
|
||||
}
|
||||
|
||||
// JSON returns a ClientArg that specifies a function that
|
||||
// handles errors structured as a JSON object.
|
||||
func JSON(errStruct error) ClientArg {
|
||||
typ := reflect.TypeOf(errStruct)
|
||||
if typ.Kind() != reflect.Struct {
|
||||
panic("JSON() argument must be a structure")
|
||||
}
|
||||
|
||||
e := reflect.New(typ).Interface()
|
||||
_ = e.(error) // panic if errStruct
|
||||
|
||||
return func(xport *Transport) {
|
||||
xport.OnError = func(req *http.Request, resp *http.Response) error {
|
||||
defer resp.Body.Close()
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
resp.Body = ioutil.NopCloser(bytes.NewReader(body))
|
||||
|
||||
jsonErrValue := reflect.New(typ)
|
||||
|
||||
unmarshalErr := json.Unmarshal(body, jsonErrValue.Interface())
|
||||
if unmarshalErr == nil {
|
||||
// jsonErrValue is a *Foo if errStruct == Foo{}
|
||||
return jsonErrValue.Elem().Interface().(error)
|
||||
}
|
||||
|
||||
// we failed to unmarshal the response body, so ignore the
|
||||
// JSON error and proceed as if ErrorFactory was not provided.
|
||||
return Response(*resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
73
vendor/github.com/crewjam/httperr/codes.go
generated
vendored
Normal file
73
vendor/github.com/crewjam/httperr/codes.go
generated
vendored
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
package httperr
|
||||
|
||||
var (
|
||||
// BadRequest is an error that represents a static http.StatusBadRequest error
|
||||
BadRequest = Value{StatusCode: 400}
|
||||
// Unauthorized is an error that represents a static http.StatusUnauthorized error
|
||||
Unauthorized = Value{StatusCode: 401}
|
||||
// PaymentRequired is an error that represents a static http.StatusPaymentRequired error
|
||||
PaymentRequired = Value{StatusCode: 402}
|
||||
// Forbidden is an error that represents a static http.StatusForbidden error
|
||||
Forbidden = Value{StatusCode: 403}
|
||||
// NotFound is an error that represents a static http.StatusNotFound error
|
||||
NotFound = Value{StatusCode: 404}
|
||||
// MethodNotAllowed is an error that represents a static http.StatusMethodNotAllowed error
|
||||
MethodNotAllowed = Value{StatusCode: 405}
|
||||
// NotAcceptable is an error that represents a static http.StatusNotAcceptable error
|
||||
NotAcceptable = Value{StatusCode: 406}
|
||||
// ProxyAuthRequired is an error that represents a static http.StatusProxyAuthRequired error
|
||||
ProxyAuthRequired = Value{StatusCode: 407}
|
||||
// RequestTimeout is an error that represents a static http.StatusRequestTimeout error
|
||||
RequestTimeout = Value{StatusCode: 408}
|
||||
// Conflict is an error that represents a static http.StatusConflict error
|
||||
Conflict = Value{StatusCode: 409}
|
||||
// Gone is an error that represents a static http.StatusGone error
|
||||
Gone = Value{StatusCode: 410}
|
||||
// LengthRequired is an error that represents a static http.StatusLengthRequired error
|
||||
LengthRequired = Value{StatusCode: 411}
|
||||
// PreconditionFailed is an error that represents a static http.StatusPreconditionFailed error
|
||||
PreconditionFailed = Value{StatusCode: 412}
|
||||
// RequestEntityTooLarge is an error that represents a static http.StatusRequestEntityTooLarge error
|
||||
RequestEntityTooLarge = Value{StatusCode: 413}
|
||||
// RequestURITooLong is an error that represents a static http.StatusRequestURITooLong error
|
||||
RequestURITooLong = Value{StatusCode: 414}
|
||||
// UnsupportedMediaType is an error that represents a static http.StatusUnsupportedMediaType error
|
||||
UnsupportedMediaType = Value{StatusCode: 415}
|
||||
// RequestedRangeNotSatisfiable is an error that represents a static http.StatusRequestedRangeNotSatisfiable error
|
||||
RequestedRangeNotSatisfiable = Value{StatusCode: 416}
|
||||
// ExpectationFailed is an error that represents a static http.StatusExpectationFailed error
|
||||
ExpectationFailed = Value{StatusCode: 417}
|
||||
// Teapot is an error that represents a static http.StatusTeapot error
|
||||
Teapot = Value{StatusCode: 418}
|
||||
// TooManyRequests is an error that represents a static http.StatusTooManyRequests error
|
||||
TooManyRequests = Value{StatusCode: 429}
|
||||
// InternalServerError is an error that represents a static http.StatusInternalServerError error
|
||||
InternalServerError = Value{StatusCode: 500}
|
||||
// NotImplemented is an error that represents a static http.StatusNotImplemented error
|
||||
NotImplemented = Value{StatusCode: 501}
|
||||
// BadGateway is an error that represents a static http.StatusBadGateway error
|
||||
BadGateway = Value{StatusCode: 502}
|
||||
// ServiceUnavailable is an error that represents a static http.StatusServiceUnavailable error
|
||||
ServiceUnavailable = Value{StatusCode: 503}
|
||||
// GatewayTimeout is an error that represents a static http.StatusGatewayTimeout error
|
||||
GatewayTimeout = Value{StatusCode: 504}
|
||||
// HTTPVersionNotSupported is an error that represents a static http.StatusHTTPVersionNotSupported error
|
||||
HTTPVersionNotSupported = Value{StatusCode: 505}
|
||||
)
|
||||
|
||||
// New returns a new http error wrapping err with status statusCode.
|
||||
func New(statusCode int, err error) error {
|
||||
return Value{
|
||||
StatusCode: statusCode,
|
||||
Err: err,
|
||||
}
|
||||
}
|
||||
|
||||
// Public returns a new public http error wrapping err with status statusCode.
|
||||
func Public(statusCode int, err error) error {
|
||||
return Value{
|
||||
Public: true,
|
||||
StatusCode: statusCode,
|
||||
Err: err,
|
||||
}
|
||||
}
|
||||
8
vendor/github.com/crewjam/httperr/go.mod
generated
vendored
Normal file
8
vendor/github.com/crewjam/httperr/go.mod
generated
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
module github.com/crewjam/httperr
|
||||
|
||||
go 1.13
|
||||
|
||||
require (
|
||||
github.com/pkg/errors v0.8.1
|
||||
github.com/stretchr/testify v1.4.0
|
||||
)
|
||||
13
vendor/github.com/crewjam/httperr/go.sum
generated
vendored
Normal file
13
vendor/github.com/crewjam/httperr/go.sum
generated
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
20
vendor/github.com/crewjam/httperr/handler.go
generated
vendored
Normal file
20
vendor/github.com/crewjam/httperr/handler.go
generated
vendored
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
package httperr
|
||||
|
||||
import "net/http"
|
||||
|
||||
// The HandlerFunc type is an adapter to allow the use of
|
||||
// ordinary functions as HTTP handlers. If f is a function
|
||||
// with the appropriate signature, HandlerFunc(f) is a
|
||||
// Handler object that calls f.
|
||||
type HandlerFunc func(http.ResponseWriter, *http.Request) error
|
||||
|
||||
// ServeHTTP calls f(w, r).
|
||||
func (f HandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
if err := f(w, r); err != nil {
|
||||
if v := r.Context().Value(onErrorIndex); v != nil {
|
||||
v.(func(error))(err)
|
||||
} else {
|
||||
Write(w, r, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
56
vendor/github.com/crewjam/httperr/httperr.go
generated
vendored
Normal file
56
vendor/github.com/crewjam/httperr/httperr.go
generated
vendored
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
// Package httperr implements an error object that speaks HTTP.
|
||||
package httperr
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
pkgerrors "github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type statusCodeAndTexter interface {
|
||||
StatusCodeAndText() (int, string)
|
||||
}
|
||||
|
||||
// StatusCodeAndText returns the status code and text of the error
|
||||
func StatusCodeAndText(err error) (int, string) {
|
||||
if err == nil {
|
||||
return http.StatusOK, http.StatusText(http.StatusOK)
|
||||
}
|
||||
|
||||
err = pkgerrors.Cause(err)
|
||||
|
||||
var scater statusCodeAndTexter
|
||||
if errors.As(err, &scater) {
|
||||
return scater.StatusCodeAndText()
|
||||
}
|
||||
|
||||
return http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
// Writer is an interface for things that know how to write themselves
|
||||
// to an error response. This interface is implemented by Private and
|
||||
// Public to provide default error pages.
|
||||
type Writer interface {
|
||||
error
|
||||
WriteError(w http.ResponseWriter, r *http.Request)
|
||||
}
|
||||
|
||||
// Write writes the specified error to w. If err is a Writer, then
|
||||
// it's WriteError method is invoked to produce the response.
|
||||
// Otherwise a generic "500 Internal Server Error" is written.
|
||||
func Write(w http.ResponseWriter, r *http.Request, err error) {
|
||||
err = pkgerrors.Cause(err)
|
||||
|
||||
var errWriter Writer
|
||||
if errors.As(err, &errWriter) {
|
||||
errWriter.WriteError(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
genericErr := Value{
|
||||
Err: err,
|
||||
StatusCode: http.StatusInternalServerError,
|
||||
}
|
||||
genericErr.WriteError(w, r)
|
||||
}
|
||||
62
vendor/github.com/crewjam/httperr/middleware.go
generated
vendored
Normal file
62
vendor/github.com/crewjam/httperr/middleware.go
generated
vendored
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
package httperr
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type onErrorIndexType int
|
||||
|
||||
const onErrorIndex onErrorIndexType = iota
|
||||
|
||||
// Middleware wraps the provided handler with middleware that captures errors which
|
||||
// are returned from HandlerFunc, or reported via ReportError, and invokes the provided
|
||||
// callback to render them. If the handler returns a status code >= 400, the response is
|
||||
// captured and passed to OnError as a Response.
|
||||
//
|
||||
type Middleware struct {
|
||||
// OnError is a function that is called then a request fails with an error. If this function
|
||||
// returns nil, then the error is assumed to be handled. If it returns a non-nil error, then
|
||||
// that error is written to the client with Write()
|
||||
OnError func(w http.ResponseWriter, r *http.Request, err error) error
|
||||
|
||||
// Handler is the next handler
|
||||
Handler http.Handler
|
||||
}
|
||||
|
||||
func (m Middleware) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
var unwrappedWriter = w
|
||||
var wrappedWriter *basicWriter
|
||||
if m.OnError != nil {
|
||||
wrappedWriter, w = wrapWriter(w)
|
||||
}
|
||||
|
||||
var didCallOnError bool
|
||||
r = r.WithContext(context.WithValue(r.Context(), onErrorIndex, func(err error) {
|
||||
if m.OnError != nil {
|
||||
didCallOnError = true
|
||||
handlerErr := m.OnError(unwrappedWriter, r, err)
|
||||
if handlerErr != nil {
|
||||
Write(unwrappedWriter, r, handlerErr)
|
||||
}
|
||||
}
|
||||
}))
|
||||
|
||||
m.Handler.ServeHTTP(w, r)
|
||||
|
||||
if wrappedWriter != nil && wrappedWriter.statusCode >= 400 && !didCallOnError {
|
||||
err := Response(*wrappedWriter.copy)
|
||||
handlerErr := m.OnError(unwrappedWriter, r, err)
|
||||
if handlerErr != nil {
|
||||
Write(unwrappedWriter, r, handlerErr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ReportError reports the error to the function given in
|
||||
// OnError.
|
||||
func ReportError(r *http.Request, err error) {
|
||||
if v := r.Context().Value(onErrorIndex); v != nil {
|
||||
v.(func(error))(err)
|
||||
}
|
||||
}
|
||||
42
vendor/github.com/crewjam/httperr/response.go
generated
vendored
Normal file
42
vendor/github.com/crewjam/httperr/response.go
generated
vendored
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
package httperr
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Response is an alias for http.Response that implements
|
||||
// the error interface. Example:
|
||||
//
|
||||
// resp, err := http.Get("http://www.example.com")
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// if resp.StatusCode != http.StatusOK {
|
||||
// return httperr.Response(*resp)
|
||||
// }
|
||||
// // ...
|
||||
//
|
||||
type Response http.Response
|
||||
|
||||
func (re Response) Error() string {
|
||||
statusText := re.Status
|
||||
if statusText == "" {
|
||||
statusText = http.StatusText(re.StatusCode)
|
||||
}
|
||||
return statusText
|
||||
}
|
||||
|
||||
// WriteError copies the Response to the ResponseWriter.
|
||||
func (re Response) WriteError(w http.ResponseWriter, r *http.Request) {
|
||||
for k, vv := range re.Header {
|
||||
for _, v := range vv {
|
||||
w.Header().Add(k, v)
|
||||
}
|
||||
}
|
||||
w.WriteHeader(re.StatusCode)
|
||||
io.Copy(w, re.Body)
|
||||
}
|
||||
|
||||
var _ error = Response{}
|
||||
var _ Writer = Response{}
|
||||
67
vendor/github.com/crewjam/httperr/value.go
generated
vendored
Normal file
67
vendor/github.com/crewjam/httperr/value.go
generated
vendored
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
// Package httperr implements an error object that speaks HTTP.
|
||||
package httperr
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Value is an Error that returns that status and code
|
||||
// provided, and reveals the underlying wrapper error to
|
||||
// the caller. The text of the error is rendered to the
|
||||
// client in the body of the response, as well as in
|
||||
// the X-Error header.
|
||||
type Value struct {
|
||||
Err error // the underlying error
|
||||
StatusCode int // the HTTP status code. If not supplied, http.StatusInternalServerError is used.
|
||||
Status string // the HTTP status text. If not supplied, http.StatusText(http.StatusCode) is used.
|
||||
Public bool
|
||||
Header http.Header // extra headers to add to the response (optional)
|
||||
}
|
||||
|
||||
// StatusCodeAndText returns the status code and text of the error
|
||||
func (e Value) StatusCodeAndText() (int, string) {
|
||||
if e.StatusCode == 0 {
|
||||
e.StatusCode = http.StatusInternalServerError
|
||||
}
|
||||
|
||||
if e.Status == "" {
|
||||
if e.Err != nil && e.Public {
|
||||
e.Status = e.Err.Error()
|
||||
} else {
|
||||
e.Status = http.StatusText(e.StatusCode)
|
||||
}
|
||||
}
|
||||
|
||||
return e.StatusCode, e.Status
|
||||
}
|
||||
|
||||
func (e Value) Error() string {
|
||||
statusCode, statusText := StatusCodeAndText(e)
|
||||
if e.Public {
|
||||
return fmt.Sprintf("%d %s", statusCode, statusText)
|
||||
}
|
||||
return fmt.Sprintf("%d %s: %s", statusCode, statusText, e.Err.Error())
|
||||
}
|
||||
|
||||
// WriteError writes an error response to w using the specified status code.
|
||||
func (e Value) WriteError(w http.ResponseWriter, r *http.Request) {
|
||||
for key, values := range e.Header {
|
||||
w.Header().Del(key) // overwrite headers already in the response with the ones specified
|
||||
for _, value := range values {
|
||||
w.Header().Add(key, value)
|
||||
}
|
||||
}
|
||||
|
||||
code, message := e.StatusCodeAndText()
|
||||
http.Error(w, message, code)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the Value error and returns the underlying error`
|
||||
func (e Value) Unwrap() error {
|
||||
return e.Err
|
||||
}
|
||||
|
||||
var _ error = Value{}
|
||||
var _ Writer = Value{}
|
||||
var _ statusCodeAndTexter = Value{}
|
||||
119
vendor/github.com/crewjam/httperr/writer.go
generated
vendored
Normal file
119
vendor/github.com/crewjam/httperr/writer.go
generated
vendored
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
package httperr
|
||||
|
||||
// Note: The writer proxies in this file are a heavily modified version of
|
||||
// code bearing the following message:
|
||||
//
|
||||
// Copyright (c) 2014, 2015, 2016 Carl Jackson (carl@avtok.com)
|
||||
//
|
||||
// MIT License
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
// this software and associated documentation files (the "Software"), to deal in
|
||||
// the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
// the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// wrapWriter wraps an http.ResponseWriter, returning a proxy that
|
||||
// tracks the response.
|
||||
func wrapWriter(w http.ResponseWriter) (*basicWriter, http.ResponseWriter) {
|
||||
_, isCloseNotifier := w.(http.CloseNotifier)
|
||||
_, isFlusher := w.(http.Flusher)
|
||||
_, isHijacker := w.(http.Hijacker)
|
||||
|
||||
bw := basicWriter{ResponseWriter: w}
|
||||
if isCloseNotifier && isFlusher && isHijacker {
|
||||
rv := fancyWriter{bw}
|
||||
return &rv.basicWriter, &rv
|
||||
}
|
||||
if isFlusher {
|
||||
rv := flushWriter{bw}
|
||||
return &rv.basicWriter, &rv
|
||||
}
|
||||
return &bw, &bw
|
||||
}
|
||||
|
||||
type basicWriter struct {
|
||||
http.ResponseWriter
|
||||
|
||||
statusCode int
|
||||
copy *http.Response
|
||||
body *bytes.Buffer
|
||||
}
|
||||
|
||||
func (b *basicWriter) WriteHeader(code int) {
|
||||
b.statusCode = code
|
||||
if code < 400 {
|
||||
b.ResponseWriter.WriteHeader(code)
|
||||
return
|
||||
}
|
||||
|
||||
b.copy = &http.Response{
|
||||
StatusCode: code,
|
||||
Header: b.ResponseWriter.Header(),
|
||||
}
|
||||
}
|
||||
|
||||
func (b *basicWriter) Write(buf []byte) (int, error) {
|
||||
if b.copy == nil {
|
||||
return b.ResponseWriter.Write(buf)
|
||||
}
|
||||
|
||||
if b.body == nil {
|
||||
b.body = &bytes.Buffer{}
|
||||
b.copy.Body = ioutil.NopCloser(b.body)
|
||||
}
|
||||
return b.body.Write(buf)
|
||||
}
|
||||
|
||||
type fancyWriter struct {
|
||||
basicWriter
|
||||
}
|
||||
|
||||
func (f *fancyWriter) CloseNotify() <-chan bool {
|
||||
cn := f.basicWriter.ResponseWriter.(http.CloseNotifier)
|
||||
return cn.CloseNotify()
|
||||
}
|
||||
|
||||
func (f *fancyWriter) Flush() {
|
||||
fl := f.basicWriter.ResponseWriter.(http.Flusher)
|
||||
fl.Flush()
|
||||
}
|
||||
|
||||
func (f *fancyWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
||||
hj := f.basicWriter.ResponseWriter.(http.Hijacker)
|
||||
return hj.Hijack()
|
||||
}
|
||||
|
||||
var _ http.CloseNotifier = &fancyWriter{}
|
||||
var _ http.Flusher = &fancyWriter{}
|
||||
var _ http.Hijacker = &fancyWriter{}
|
||||
|
||||
type flushWriter struct {
|
||||
basicWriter
|
||||
}
|
||||
|
||||
func (f *flushWriter) Flush() {
|
||||
fl := f.basicWriter.ResponseWriter.(http.Flusher)
|
||||
fl.Flush()
|
||||
}
|
||||
|
||||
var _ http.Flusher = &flushWriter{}
|
||||
7
vendor/github.com/crewjam/saml/.gitignore
generated
vendored
Normal file
7
vendor/github.com/crewjam/saml/.gitignore
generated
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
coverage.out
|
||||
coverage.html
|
||||
vendor/
|
||||
|
||||
# IDE-specific settings
|
||||
.idea
|
||||
.vscode
|
||||
78
vendor/github.com/crewjam/saml/.golangci.yml
generated
vendored
Normal file
78
vendor/github.com/crewjam/saml/.golangci.yml
generated
vendored
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
# Configuration file for golangci-lint
|
||||
#
|
||||
# https://github.com/golangci/golangci-lint
|
||||
#
|
||||
# fighting with false positives?
|
||||
# https://github.com/golangci/golangci-lint#nolint
|
||||
|
||||
linters:
|
||||
enable:
|
||||
- gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification [fast: true, auto-fix: true]
|
||||
- goimports # Goimports does everything that gofmt does. Additionally it checks unused imports [fast: true, auto-fix: true]
|
||||
- gosec # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases [fast: true, auto-fix: false]
|
||||
- misspell # Finds commonly misspelled English words in comments [fast: true, auto-fix: true]
|
||||
- deadcode # Finds unused code [fast: true, auto-fix: false]
|
||||
- revive # Golint differs from gofmt. Gofmt reformats Go source code, whereas golint prints out style mistakes [fast: true, auto-fix: false]
|
||||
- unconvert # Remove unnecessary type conversions [fast: true, auto-fix: false]
|
||||
|
||||
disable:
|
||||
# TODO(ross): fix errors reported by these checkers and enable them
|
||||
- bodyclose # checks whether HTTP response body is closed successfully [fast: false, auto-fix: false]
|
||||
- depguard # Go linter that checks if package imports are in a list of acceptable packages [fast: true, auto-fix: false]
|
||||
- dupl # Tool for code clone detection [fast: true, auto-fix: false]
|
||||
- errcheck # Inspects source code for security problems [fast: true, auto-fix: false]
|
||||
- gochecknoglobals # Checks that no globals are present in Go code [fast: true, auto-fix: false]
|
||||
- gochecknoinits # Checks that no init functions are present in Go code [fast: true, auto-fix: false]
|
||||
- goconst # Finds repeated strings that could be replaced by a constant [fast: true, auto-fix: false]
|
||||
- gocritic # The most opinionated Go source code linter [fast: true, auto-fix: false]
|
||||
- gocyclo # Computes and checks the cyclomatic complexity of functions [fast: true, auto-fix: false]
|
||||
- gosimple # Linter for Go source code that specializes in simplifying a code [fast: false, auto-fix: false]
|
||||
- govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string [fast: false, auto-fix: false]
|
||||
- ineffassign # Detects when assignments to existing variables are not used [fast: true, auto-fix: false]
|
||||
- interfacer # Linter that suggests narrower interface types [fast: false, auto-fix: false]
|
||||
- lll # Reports long lines [fast: true, auto-fix: false]
|
||||
- maligned # Tool to detect Go structs that would take less memory if their fields were sorted [fast: true, auto-fix: false]
|
||||
- nakedret # Finds naked returns in functions greater than a specified function length [fast: true, auto-fix: false]
|
||||
- prealloc # Finds slice declarations that could potentially be preallocated [fast: true, auto-fix: false]
|
||||
- scopelint # Scopelint checks for unpinned variables in go programs [fast: true, auto-fix: false]
|
||||
- staticcheck # Staticcheck is a go vet on steroids, applying a ton of static analysis checks [fast: false, auto-fix: false]
|
||||
- structcheck # Finds unused struct fields [fast: true, auto-fix: false]
|
||||
- stylecheck # Stylecheck is a replacement for golint [fast: false, auto-fix: false]
|
||||
- typecheck # Like the front-end of a Go compiler, parses and type-checks Go code [fast: true, auto-fix: false]
|
||||
- unparam # Reports unused function parameters [fast: false, auto-fix: false]
|
||||
- unused # Checks Go code for unused constants, variables, functions and types [fast: false, auto-fix: false]
|
||||
- varcheck # Finds unused global variables and constants [fast: true, auto-fix: false]
|
||||
linters-settings:
|
||||
goimports:
|
||||
local-prefixes: github.com/crewjam/saml
|
||||
govet:
|
||||
disable:
|
||||
- shadow
|
||||
enable:
|
||||
- asmdecl
|
||||
- assign
|
||||
- atomic
|
||||
- bools
|
||||
- buildtag
|
||||
- cgocall
|
||||
- composites
|
||||
- copylocks
|
||||
- errorsas
|
||||
- httpresponse
|
||||
- loopclosure
|
||||
- lostcancel
|
||||
- nilfunc
|
||||
- printf
|
||||
- shift
|
||||
- stdmethods
|
||||
- structtag
|
||||
- tests
|
||||
- unmarshal
|
||||
- unreachable
|
||||
- unsafeptr
|
||||
- unusedresult
|
||||
issues:
|
||||
exclude-use-default: false
|
||||
exclude:
|
||||
- G104 # 'Errors unhandled. (gosec)
|
||||
|
||||
23
vendor/github.com/crewjam/saml/LICENSE
generated
vendored
Normal file
23
vendor/github.com/crewjam/saml/LICENSE
generated
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
Copyright (c) 2015, Ross Kinder
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
157
vendor/github.com/crewjam/saml/README.md
generated
vendored
Normal file
157
vendor/github.com/crewjam/saml/README.md
generated
vendored
Normal file
|
|
@ -0,0 +1,157 @@
|
|||
# SAML
|
||||
|
||||
[](http://godoc.org/github.com/crewjam/saml)
|
||||
|
||||

|
||||
|
||||
Package saml contains a partial implementation of the SAML standard in golang.
|
||||
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.
|
||||
|
||||
## Introduction
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
## Getting Started as a Service Provider
|
||||
|
||||
Let us assume we have a simple web application to protect. We'll modify this application so it uses SAML to authenticate users.
|
||||
|
||||
```golang
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func hello(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintf(w, "Hello, World!")
|
||||
}
|
||||
|
||||
func main() {
|
||||
app := http.HandlerFunc(hello)
|
||||
http.Handle("/hello", app)
|
||||
http.ListenAndServe(":8000", nil)
|
||||
}
|
||||
```
|
||||
|
||||
Each service provider must have an self-signed X.509 key pair established. You can generate your own with something like this:
|
||||
|
||||
openssl req -x509 -newkey rsa:2048 -keyout myservice.key -out myservice.cert -days 365 -nodes -subj "/CN=myservice.example.com"
|
||||
|
||||
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 [samltest.id](https://samltest.id/), an identity provider designed for testing.
|
||||
|
||||
```golang
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/rsa"
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/crewjam/saml/samlsp"
|
||||
)
|
||||
|
||||
func hello(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintf(w, "Hello, %s!", samlsp.AttributeFromContext(r.Context(), "cn"))
|
||||
}
|
||||
|
||||
func main() {
|
||||
keyPair, err := tls.LoadX509KeyPair("myservice.cert", "myservice.key")
|
||||
if err != nil {
|
||||
panic(err) // TODO handle error
|
||||
}
|
||||
keyPair.Leaf, err = x509.ParseCertificate(keyPair.Certificate[0])
|
||||
if err != nil {
|
||||
panic(err) // TODO handle error
|
||||
}
|
||||
|
||||
idpMetadataURL, err := url.Parse("https://samltest.id/saml/idp")
|
||||
if err != nil {
|
||||
panic(err) // TODO handle error
|
||||
}
|
||||
idpMetadata, err := samlsp.FetchMetadata(context.Background(), http.DefaultClient,
|
||||
*idpMetadataURL)
|
||||
if err != nil {
|
||||
panic(err) // TODO handle error
|
||||
}
|
||||
|
||||
rootURL, err := url.Parse("http://localhost:8000")
|
||||
if err != nil {
|
||||
panic(err) // TODO handle error
|
||||
}
|
||||
|
||||
samlSP, _ := samlsp.New(samlsp.Options{
|
||||
URL: *rootURL,
|
||||
Key: keyPair.PrivateKey.(*rsa.PrivateKey),
|
||||
Certificate: keyPair.Leaf,
|
||||
IDPMetadata: idpMetadata,
|
||||
})
|
||||
app := http.HandlerFunc(hello)
|
||||
http.Handle("/hello", samlSP.RequireAccount(app))
|
||||
http.Handle("/saml/", samlSP)
|
||||
http.ListenAndServe(":8000", nil)
|
||||
}
|
||||
```
|
||||
|
||||
Next we'll have to register our service provider with the identity provider to establish trust from the service provider to the IDP. For [samltest.id](https://samltest.id/), you can do something like:
|
||||
|
||||
mdpath=saml-test-$USER-$HOST.xml
|
||||
curl localhost:8000/saml/metadata > $mdpath
|
||||
|
||||
Navigate to https://samltest.id/upload.php and upload the file you fetched.
|
||||
|
||||
Now you should be able to authenticate. The flow should look like this:
|
||||
|
||||
1. You browse to `localhost:8000/hello`
|
||||
|
||||
1. The middleware redirects you to `https://samltest.id/idp/profile/SAML2/Redirect/SSO`
|
||||
|
||||
1. samltest.id prompts you for a username and password.
|
||||
|
||||
1. samltest.id 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.
|
||||
|
||||
1. The local service validates the response, issues a session cookie, and redirects you to the original URL, `localhost:8000/hello`.
|
||||
|
||||
1. This time when `localhost:8000/hello` is requested there is a valid session and so the main content is served.
|
||||
|
||||
## Getting Started as an Identity Provider
|
||||
|
||||
Please see `example/idp/` for a substantially complete example of how to use the library and helpers to be an identity provider.
|
||||
|
||||
## Support
|
||||
|
||||
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](https://kantarainitiative.github.io/SAMLprofiles/saml2int.html).
|
||||
|
||||
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 from the IDP to the service provider are supported via the **HTTP POST** binding.
|
||||
|
||||
The package can produce signed SAML assertions, and can validate both signed and encrypted SAML assertions. It does not support signed or encrypted requests.
|
||||
|
||||
## RelayState
|
||||
|
||||
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.
|
||||
|
||||
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.)
|
||||
|
||||
## References
|
||||
|
||||
The SAML specification is a collection of PDFs (sadly):
|
||||
|
||||
- [SAMLCore](http://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf) defines data types.
|
||||
|
||||
- [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.
|
||||
|
||||
- [SAMLProfiles](http://docs.oasis-open.org/security/saml/v2.0/saml-profiles-2.0-os.pdf) describes data flows.
|
||||
|
||||
- [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.
|
||||
|
||||
[SAMLtest](https://samltest.id/) is a testing ground for SAML service and identity providers.
|
||||
|
||||
## Security Issues
|
||||
|
||||
Please do not report security issues in the issue tracker. Rather, please contact me directly at ross@kndr.org ([PGP Key `78B6038B3B9DFB88`](https://keybase.io/crewjam)). If your issue is *not* a security issue, please use the issue tracker so other contributors can help.
|
||||
128
vendor/github.com/crewjam/saml/duration.go
generated
vendored
Normal file
128
vendor/github.com/crewjam/saml/duration.go
generated
vendored
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
package saml
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Duration is a time.Duration that uses the xsd:duration format for text
|
||||
// marshalling and unmarshalling.
|
||||
type Duration time.Duration
|
||||
|
||||
// MarshalText implements the encoding.TextMarshaler interface.
|
||||
func (d Duration) MarshalText() ([]byte, error) {
|
||||
if d == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
out := "PT"
|
||||
if d < 0 {
|
||||
d *= -1
|
||||
out = "-" + out
|
||||
}
|
||||
|
||||
h := time.Duration(d) / time.Hour
|
||||
m := time.Duration(d) % time.Hour / time.Minute
|
||||
s := time.Duration(d) % time.Minute / time.Second
|
||||
ns := time.Duration(d) % time.Second
|
||||
if h > 0 {
|
||||
out += fmt.Sprintf("%dH", h)
|
||||
}
|
||||
if m > 0 {
|
||||
out += fmt.Sprintf("%dM", m)
|
||||
}
|
||||
if s > 0 || ns > 0 {
|
||||
out += fmt.Sprintf("%d", s)
|
||||
if ns > 0 {
|
||||
out += strings.TrimRight(fmt.Sprintf(".%09d", ns), "0")
|
||||
}
|
||||
out += "S"
|
||||
}
|
||||
|
||||
return []byte(out), nil
|
||||
}
|
||||
|
||||
const (
|
||||
day = 24 * time.Hour
|
||||
month = 30 * day // Assumed to be 30 days.
|
||||
year = 365 * day // Assumed to be non-leap year.
|
||||
)
|
||||
|
||||
var (
|
||||
durationRegexp = regexp.MustCompile(`^(-?)P(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)D)?(?:T(.+))?$`)
|
||||
durationTimeRegexp = regexp.MustCompile(`^(?:(\d+)H)?(?:(\d+)M)?(?:(\d+(?:\.\d+)?)S)?$`)
|
||||
)
|
||||
|
||||
// UnmarshalText implements the encoding.TextUnmarshaler interface.
|
||||
func (d *Duration) UnmarshalText(text []byte) error {
|
||||
if text == nil {
|
||||
*d = 0
|
||||
return nil
|
||||
}
|
||||
|
||||
var (
|
||||
out time.Duration
|
||||
sign time.Duration = 1
|
||||
)
|
||||
match := durationRegexp.FindStringSubmatch(string(text))
|
||||
if match == nil || strings.Join(match[2:6], "") == "" {
|
||||
return fmt.Errorf("invalid duration (%s)", text)
|
||||
}
|
||||
if match[1] == "-" {
|
||||
sign = -1
|
||||
}
|
||||
if match[2] != "" {
|
||||
y, err := strconv.Atoi(match[2])
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid duration years (%s): %s", text, err)
|
||||
}
|
||||
out += time.Duration(y) * year
|
||||
}
|
||||
if match[3] != "" {
|
||||
m, err := strconv.Atoi(match[3])
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid duration months (%s): %s", text, err)
|
||||
}
|
||||
out += time.Duration(m) * month
|
||||
}
|
||||
if match[4] != "" {
|
||||
d, err := strconv.Atoi(match[4])
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid duration days (%s): %s", text, err)
|
||||
}
|
||||
out += time.Duration(d) * day
|
||||
}
|
||||
if match[5] != "" {
|
||||
match := durationTimeRegexp.FindStringSubmatch(match[5])
|
||||
if match == nil {
|
||||
return fmt.Errorf("invalid duration (%s)", text)
|
||||
}
|
||||
if match[1] != "" {
|
||||
h, err := strconv.Atoi(match[1])
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid duration hours (%s): %s", text, err)
|
||||
}
|
||||
out += time.Duration(h) * time.Hour
|
||||
}
|
||||
if match[2] != "" {
|
||||
m, err := strconv.Atoi(match[2])
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid duration minutes (%s): %s", text, err)
|
||||
}
|
||||
out += time.Duration(m) * time.Minute
|
||||
}
|
||||
if match[3] != "" {
|
||||
s, err := strconv.ParseFloat(match[3], 64)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid duration seconds (%s): %s", text, err)
|
||||
}
|
||||
out += time.Duration(s * float64(time.Second))
|
||||
}
|
||||
}
|
||||
|
||||
*d = Duration(sign * out)
|
||||
return nil
|
||||
}
|
||||
20
vendor/github.com/crewjam/saml/go.mod
generated
vendored
Normal file
20
vendor/github.com/crewjam/saml/go.mod
generated
vendored
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
module github.com/crewjam/saml
|
||||
|
||||
go 1.13
|
||||
|
||||
require (
|
||||
github.com/beevik/etree v1.1.0
|
||||
github.com/crewjam/httperr v0.2.0
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/dchest/uniuri v0.0.0-20200228104902-7aecb25e1fe5
|
||||
github.com/golang-jwt/jwt/v4 v4.1.0
|
||||
github.com/google/go-cmp v0.5.6
|
||||
github.com/kr/pretty v0.3.0
|
||||
github.com/mattermost/xml-roundtrip-validator v0.1.0
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/russellhaering/goxmldsig v1.1.1
|
||||
github.com/zenazn/goji v1.0.1
|
||||
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
|
||||
gotest.tools v2.2.0+incompatible
|
||||
)
|
||||
64
vendor/github.com/crewjam/saml/go.sum
generated
vendored
Normal file
64
vendor/github.com/crewjam/saml/go.sum
generated
vendored
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
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/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
github.com/crewjam/httperr v0.2.0 h1:b2BfXR8U3AlIHwNeFFvZ+BV1LFvKLlzMjzaTnZMybNo=
|
||||
github.com/crewjam/httperr v0.2.0/go.mod h1:Jlz+Sg/XqBQhyMjdDiC+GNNRzZTD7x39Gu3pglZ5oH4=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dchest/uniuri v0.0.0-20200228104902-7aecb25e1fe5 h1:RAV05c0xOkJ3dZGS0JFybxFKZ2WMLabgx3uXnd7rpGs=
|
||||
github.com/dchest/uniuri v0.0.0-20200228104902-7aecb25e1fe5/go.mod h1:GgB8SF9nRG+GqaDtLcwJZsQFhcogVCJ79j4EdT0c2V4=
|
||||
github.com/golang-jwt/jwt/v4 v4.1.0 h1:XUgk2Ex5veyVFVeLm0xhusUTQybEbexJXrvPNOKkSY0=
|
||||
github.com/golang-jwt/jwt/v4 v4.1.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg=
|
||||
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
|
||||
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/jonboulle/clockwork v0.2.2 h1:UOGuzwb1PwsrDAObMuhUnj0p5ULPj8V/xJ7Kx9qUBdQ=
|
||||
github.com/jonboulle/clockwork v0.2.2/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
|
||||
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/mattermost/xml-roundtrip-validator v0.1.0 h1:RXbVD2UAl7A7nOTR4u7E3ILa4IbtvKBHw64LDsmu9hU=
|
||||
github.com/mattermost/xml-roundtrip-validator v0.1.0/go.mod h1:qccnGMcpgwcNaBnxqpJpWWUiPNr5H3O8eDgGV9gT5To=
|
||||
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
|
||||
github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
|
||||
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
|
||||
github.com/russellhaering/goxmldsig v1.1.1 h1:vI0r2osGF1A9PLvsGdPUAGwEIrKa4Pj5sesSBsebIxM=
|
||||
github.com/russellhaering/goxmldsig v1.1.1/go.mod h1:gM4MDENBQf7M+V824SGfyIUVFWydB7n0KkEubVJl+Tw=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/zenazn/goji v1.0.1 h1:4lbD8Mx2h7IvloP7r2C0D6ltZP6Ufip8Hn0wmSK5LR8=
|
||||
github.com/zenazn/goji v1.0.1/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
|
||||
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 h1:It14KIkyBFYkHkwZ7k45minvA9aorojkyjGk9KJ5B/w=
|
||||
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
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=
|
||||
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
|
||||
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
|
||||
1050
vendor/github.com/crewjam/saml/identity_provider.go
generated
vendored
Normal file
1050
vendor/github.com/crewjam/saml/identity_provider.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
31
vendor/github.com/crewjam/saml/logger/logger.go
generated
vendored
Normal file
31
vendor/github.com/crewjam/saml/logger/logger.go
generated
vendored
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
package logger
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Interface provides the minimal logging interface
|
||||
type Interface interface {
|
||||
// Printf prints to the logger using the format.
|
||||
Printf(format string, v ...interface{})
|
||||
// Print prints to the logger.
|
||||
Print(v ...interface{})
|
||||
// Println prints new line.
|
||||
Println(v ...interface{})
|
||||
// Fatal is equivalent to Print() followed by a call to os.Exit(1).
|
||||
Fatal(v ...interface{})
|
||||
// Fatalf is equivalent to Printf() followed by a call to os.Exit(1).
|
||||
Fatalf(format string, v ...interface{})
|
||||
// Fatalln is equivalent to Println() followed by a call to os.Exit(1).
|
||||
Fatalln(v ...interface{})
|
||||
// Panic is equivalent to Print() followed by a call to panic().
|
||||
Panic(v ...interface{})
|
||||
// Panicf is equivalent to Printf() followed by a call to panic().
|
||||
Panicf(format string, v ...interface{})
|
||||
// Panicln is equivalent to Println() followed by a call to panic().
|
||||
Panicln(v ...interface{})
|
||||
}
|
||||
|
||||
// DefaultLogger logs messages to os.Stdout
|
||||
var DefaultLogger = log.New(os.Stdout, "", log.LstdFlags)
|
||||
303
vendor/github.com/crewjam/saml/metadata.go
generated
vendored
Normal file
303
vendor/github.com/crewjam/saml/metadata.go
generated
vendored
Normal file
|
|
@ -0,0 +1,303 @@
|
|||
package saml
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"time"
|
||||
|
||||
"github.com/beevik/etree"
|
||||
)
|
||||
|
||||
// HTTPPostBinding is the official URN for the HTTP-POST binding (transport)
|
||||
const HTTPPostBinding = "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
|
||||
|
||||
// HTTPRedirectBinding is the official URN for the HTTP-Redirect binding (transport)
|
||||
const HTTPRedirectBinding = "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect"
|
||||
|
||||
// HTTPArtifactBinding is the official URN for the HTTP-Artifact binding (transport)
|
||||
const HTTPArtifactBinding = "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Artifact"
|
||||
|
||||
// SOAPBinding is the official URN for the SOAP binding (transport)
|
||||
const SOAPBinding = "urn:oasis:names:tc:SAML:2.0:bindings:SOAP"
|
||||
|
||||
// EntitiesDescriptor represents the SAML object of the same name.
|
||||
//
|
||||
// See http://docs.oasis-open.org/security/saml/v2.0/saml-metadata-2.0-os.pdf §2.3.1
|
||||
type EntitiesDescriptor struct {
|
||||
XMLName xml.Name `xml:"urn:oasis:names:tc:SAML:2.0:metadata EntitiesDescriptor"`
|
||||
ID *string `xml:",attr,omitempty"`
|
||||
ValidUntil *time.Time `xml:"validUntil,attr,omitempty"`
|
||||
CacheDuration *time.Duration `xml:"cacheDuration,attr,omitempty"`
|
||||
Name *string `xml:",attr,omitempty"`
|
||||
Signature *etree.Element
|
||||
EntitiesDescriptors []EntitiesDescriptor `xml:"urn:oasis:names:tc:SAML:2.0:metadata EntitiesDescriptor"`
|
||||
EntityDescriptors []EntityDescriptor `xml:"urn:oasis:names:tc:SAML:2.0:metadata EntityDescriptor"`
|
||||
}
|
||||
|
||||
// Metadata as been renamed to EntityDescriptor
|
||||
//
|
||||
// This change was made to be consistent with the rest of the API which uses names
|
||||
// from the SAML specification for types.
|
||||
//
|
||||
// This is a tombstone to help you discover this fact. You should update references
|
||||
// to saml.Metadata to be saml.EntityDescriptor.
|
||||
var Metadata = struct{}{}
|
||||
|
||||
// EntityDescriptor represents the SAML EntityDescriptor object.
|
||||
//
|
||||
// See http://docs.oasis-open.org/security/saml/v2.0/saml-metadata-2.0-os.pdf §2.3.2
|
||||
type EntityDescriptor struct {
|
||||
XMLName xml.Name `xml:"urn:oasis:names:tc:SAML:2.0:metadata EntityDescriptor"`
|
||||
EntityID string `xml:"entityID,attr"`
|
||||
ID string `xml:",attr,omitempty"`
|
||||
ValidUntil time.Time `xml:"validUntil,attr,omitempty"`
|
||||
CacheDuration time.Duration `xml:"cacheDuration,attr,omitempty"`
|
||||
Signature *etree.Element
|
||||
RoleDescriptors []RoleDescriptor `xml:"RoleDescriptor"`
|
||||
IDPSSODescriptors []IDPSSODescriptor `xml:"IDPSSODescriptor"`
|
||||
SPSSODescriptors []SPSSODescriptor `xml:"SPSSODescriptor"`
|
||||
AuthnAuthorityDescriptors []AuthnAuthorityDescriptor `xml:"AuthnAuthorityDescriptor"`
|
||||
AttributeAuthorityDescriptors []AttributeAuthorityDescriptor `xml:"AttributeAuthorityDescriptor"`
|
||||
PDPDescriptors []PDPDescriptor `xml:"PDPDescriptor"`
|
||||
AffiliationDescriptor *AffiliationDescriptor
|
||||
Organization *Organization
|
||||
ContactPerson *ContactPerson
|
||||
AdditionalMetadataLocations []string `xml:"AdditionalMetadataLocation"`
|
||||
}
|
||||
|
||||
// MarshalXML implements xml.Marshaler
|
||||
func (m EntityDescriptor) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
|
||||
type Alias EntityDescriptor
|
||||
aux := &struct {
|
||||
ValidUntil RelaxedTime `xml:"validUntil,attr,omitempty"`
|
||||
CacheDuration Duration `xml:"cacheDuration,attr,omitempty"`
|
||||
*Alias
|
||||
}{
|
||||
ValidUntil: RelaxedTime(m.ValidUntil),
|
||||
CacheDuration: Duration(m.CacheDuration),
|
||||
Alias: (*Alias)(&m),
|
||||
}
|
||||
return e.Encode(aux)
|
||||
}
|
||||
|
||||
// UnmarshalXML implements xml.Unmarshaler
|
||||
func (m *EntityDescriptor) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||
type Alias EntityDescriptor
|
||||
aux := &struct {
|
||||
ValidUntil RelaxedTime `xml:"validUntil,attr,omitempty"`
|
||||
CacheDuration Duration `xml:"cacheDuration,attr,omitempty"`
|
||||
*Alias
|
||||
}{
|
||||
Alias: (*Alias)(m),
|
||||
}
|
||||
if err := d.DecodeElement(aux, &start); err != nil {
|
||||
return err
|
||||
}
|
||||
m.ValidUntil = time.Time(aux.ValidUntil)
|
||||
m.CacheDuration = time.Duration(aux.CacheDuration)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Organization represents the SAML Organization object.
|
||||
//
|
||||
// See http://docs.oasis-open.org/security/saml/v2.0/saml-metadata-2.0-os.pdf §2.3.2.1
|
||||
type Organization struct {
|
||||
OrganizationNames []LocalizedName `xml:"OrganizationName"`
|
||||
OrganizationDisplayNames []LocalizedName `xml:"OrganizationDisplayName"`
|
||||
OrganizationURLs []LocalizedURI `xml:"OrganizationURL"`
|
||||
}
|
||||
|
||||
// LocalizedName represents the SAML type localizedNameType.
|
||||
//
|
||||
// See http://docs.oasis-open.org/security/saml/v2.0/saml-metadata-2.0-os.pdf §2.2.4
|
||||
type LocalizedName struct {
|
||||
Lang string `xml:"http://www.w3.org/XML/1998/namespace lang,attr"`
|
||||
Value string `xml:",chardata"`
|
||||
}
|
||||
|
||||
// LocalizedURI represents the SAML type localizedURIType.
|
||||
//
|
||||
// See http://docs.oasis-open.org/security/saml/v2.0/saml-metadata-2.0-os.pdf §2.2.5
|
||||
type LocalizedURI struct {
|
||||
Lang string `xml:"http://www.w3.org/XML/1998/namespace lang,attr"`
|
||||
Value string `xml:",chardata"`
|
||||
}
|
||||
|
||||
// ContactPerson represents the SAML element ContactPerson.
|
||||
//
|
||||
// See http://docs.oasis-open.org/security/saml/v2.0/saml-metadata-2.0-os.pdf §2.3.2.2
|
||||
type ContactPerson struct {
|
||||
ContactType string `xml:"contactType,attr"`
|
||||
Company string
|
||||
GivenName string
|
||||
SurName string
|
||||
EmailAddresses []string `xml:"EmailAddress"`
|
||||
TelephoneNumbers []string `xml:"TelephoneNumber"`
|
||||
}
|
||||
|
||||
// RoleDescriptor represents the SAML element RoleDescriptor.
|
||||
//
|
||||
// See http://docs.oasis-open.org/security/saml/v2.0/saml-metadata-2.0-os.pdf §2.4.1
|
||||
type RoleDescriptor struct {
|
||||
ID string `xml:",attr,omitempty"`
|
||||
ValidUntil *time.Time `xml:"validUntil,attr,omitempty"`
|
||||
CacheDuration time.Duration `xml:"cacheDuration,attr,omitempty"`
|
||||
ProtocolSupportEnumeration string `xml:"protocolSupportEnumeration,attr"`
|
||||
ErrorURL string `xml:"errorURL,attr,omitempty"`
|
||||
Signature *etree.Element
|
||||
KeyDescriptors []KeyDescriptor `xml:"KeyDescriptor,omitempty"`
|
||||
Organization *Organization `xml:"Organization,omitempty"`
|
||||
ContactPeople []ContactPerson `xml:"ContactPerson,omitempty"`
|
||||
}
|
||||
|
||||
// KeyDescriptor represents the XMLSEC object of the same name
|
||||
type KeyDescriptor struct {
|
||||
Use string `xml:"use,attr"`
|
||||
KeyInfo KeyInfo `xml:"http://www.w3.org/2000/09/xmldsig# KeyInfo"`
|
||||
EncryptionMethods []EncryptionMethod `xml:"EncryptionMethod"`
|
||||
}
|
||||
|
||||
// EncryptionMethod represents the XMLSEC object of the same name
|
||||
type EncryptionMethod struct {
|
||||
Algorithm string `xml:"Algorithm,attr"`
|
||||
}
|
||||
|
||||
// KeyInfo represents the XMLSEC object of the same name
|
||||
type KeyInfo struct {
|
||||
XMLName xml.Name `xml:"http://www.w3.org/2000/09/xmldsig# KeyInfo"`
|
||||
X509Data X509Data `xml:"X509Data"`
|
||||
}
|
||||
|
||||
// X509Data represents the XMLSEC object of the same name
|
||||
type X509Data struct {
|
||||
XMLName xml.Name `xml:"http://www.w3.org/2000/09/xmldsig# X509Data"`
|
||||
X509Certificates []X509Certificate `xml:"X509Certificate"`
|
||||
}
|
||||
|
||||
// X509Certificate represents the XMLSEC object of the same name
|
||||
type X509Certificate struct {
|
||||
XMLName xml.Name `xml:"http://www.w3.org/2000/09/xmldsig# X509Certificate"`
|
||||
Data string `xml:",chardata"`
|
||||
}
|
||||
|
||||
// Endpoint represents the SAML EndpointType object.
|
||||
//
|
||||
// See http://docs.oasis-open.org/security/saml/v2.0/saml-metadata-2.0-os.pdf §2.2.2
|
||||
type Endpoint struct {
|
||||
Binding string `xml:"Binding,attr"`
|
||||
Location string `xml:"Location,attr"`
|
||||
ResponseLocation string `xml:"ResponseLocation,attr,omitempty"`
|
||||
}
|
||||
|
||||
// IndexedEndpoint represents the SAML IndexedEndpointType object.
|
||||
//
|
||||
// See http://docs.oasis-open.org/security/saml/v2.0/saml-metadata-2.0-os.pdf §2.2.3
|
||||
type IndexedEndpoint struct {
|
||||
Binding string `xml:"Binding,attr"`
|
||||
Location string `xml:"Location,attr"`
|
||||
ResponseLocation *string `xml:"ResponseLocation,attr,omitempty"`
|
||||
Index int `xml:"index,attr"`
|
||||
IsDefault *bool `xml:"isDefault,attr"`
|
||||
}
|
||||
|
||||
// SSODescriptor represents the SAML complex type SSODescriptor
|
||||
//
|
||||
// See http://docs.oasis-open.org/security/saml/v2.0/saml-metadata-2.0-os.pdf §2.4.2
|
||||
type SSODescriptor struct {
|
||||
RoleDescriptor
|
||||
ArtifactResolutionServices []IndexedEndpoint `xml:"ArtifactResolutionService"`
|
||||
SingleLogoutServices []Endpoint `xml:"SingleLogoutService"`
|
||||
ManageNameIDServices []Endpoint `xml:"ManageNameIDService"`
|
||||
NameIDFormats []NameIDFormat `xml:"NameIDFormat"`
|
||||
}
|
||||
|
||||
// IDPSSODescriptor represents the SAML IDPSSODescriptorType object.
|
||||
//
|
||||
// See http://docs.oasis-open.org/security/saml/v2.0/saml-metadata-2.0-os.pdf §2.4.3
|
||||
type IDPSSODescriptor struct {
|
||||
XMLName xml.Name `xml:"urn:oasis:names:tc:SAML:2.0:metadata IDPSSODescriptor"`
|
||||
SSODescriptor
|
||||
WantAuthnRequestsSigned *bool `xml:",attr"`
|
||||
|
||||
SingleSignOnServices []Endpoint `xml:"SingleSignOnService"`
|
||||
ArtifactResolutionServices []Endpoint `xml:"ArtifactResolutionService"`
|
||||
NameIDMappingServices []Endpoint `xml:"NameIDMappingService"`
|
||||
AssertionIDRequestServices []Endpoint `xml:"AssertionIDRequestService"`
|
||||
AttributeProfiles []string `xml:"AttributeProfile"`
|
||||
Attributes []Attribute `xml:"Attribute"`
|
||||
}
|
||||
|
||||
// SPSSODescriptor represents the SAML SPSSODescriptorType object.
|
||||
//
|
||||
// See http://docs.oasis-open.org/security/saml/v2.0/saml-metadata-2.0-os.pdf §2.4.2
|
||||
type SPSSODescriptor struct {
|
||||
XMLName xml.Name `xml:"urn:oasis:names:tc:SAML:2.0:metadata SPSSODescriptor"`
|
||||
SSODescriptor
|
||||
AuthnRequestsSigned *bool `xml:",attr"`
|
||||
WantAssertionsSigned *bool `xml:",attr"`
|
||||
AssertionConsumerServices []IndexedEndpoint `xml:"AssertionConsumerService"`
|
||||
AttributeConsumingServices []AttributeConsumingService `xml:"AttributeConsumingService"`
|
||||
}
|
||||
|
||||
// AttributeConsumingService represents the SAML AttributeConsumingService object.
|
||||
//
|
||||
// See http://docs.oasis-open.org/security/saml/v2.0/saml-metadata-2.0-os.pdf §2.4.4.1
|
||||
type AttributeConsumingService struct {
|
||||
Index int `xml:"index,attr"`
|
||||
IsDefault *bool `xml:"isDefault,attr"`
|
||||
ServiceNames []LocalizedName `xml:"ServiceName"`
|
||||
ServiceDescriptions []LocalizedName `xml:"ServiceDescription"`
|
||||
RequestedAttributes []RequestedAttribute `xml:"RequestedAttribute"`
|
||||
}
|
||||
|
||||
// RequestedAttribute represents the SAML RequestedAttribute object.
|
||||
//
|
||||
// See http://docs.oasis-open.org/security/saml/v2.0/saml-metadata-2.0-os.pdf §2.4.4.2
|
||||
type RequestedAttribute struct {
|
||||
Attribute
|
||||
IsRequired *bool `xml:"isRequired,attr"`
|
||||
}
|
||||
|
||||
// AuthnAuthorityDescriptor represents the SAML AuthnAuthorityDescriptor object.
|
||||
//
|
||||
// See http://docs.oasis-open.org/security/saml/v2.0/saml-metadata-2.0-os.pdf §2.4.5
|
||||
type AuthnAuthorityDescriptor struct {
|
||||
RoleDescriptor
|
||||
AuthnQueryServices []Endpoint `xml:"AuthnQueryService"`
|
||||
AssertionIDRequestServices []Endpoint `xml:"AssertionIDRequestService"`
|
||||
NameIDFormats []NameIDFormat `xml:"NameIDFormat"`
|
||||
}
|
||||
|
||||
// PDPDescriptor represents the SAML PDPDescriptor object.
|
||||
//
|
||||
// See http://docs.oasis-open.org/security/saml/v2.0/saml-metadata-2.0-os.pdf §2.4.6
|
||||
type PDPDescriptor struct {
|
||||
RoleDescriptor
|
||||
AuthzServices []Endpoint `xml:"AuthzService"`
|
||||
AssertionIDRequestServices []Endpoint `xml:"AssertionIDRequestService"`
|
||||
NameIDFormats []NameIDFormat `xml:"NameIDFormat"`
|
||||
}
|
||||
|
||||
// AttributeAuthorityDescriptor represents the SAML AttributeAuthorityDescriptor object.
|
||||
//
|
||||
// See http://docs.oasis-open.org/security/saml/v2.0/saml-metadata-2.0-os.pdf §2.4.7
|
||||
type AttributeAuthorityDescriptor struct {
|
||||
RoleDescriptor
|
||||
AttributeServices []Endpoint `xml:"AttributeService"`
|
||||
AssertionIDRequestServices []Endpoint `xml:"AssertionIDRequestService"`
|
||||
NameIDFormats []NameIDFormat `xml:"NameIDFormat"`
|
||||
AttributeProfiles []string `xml:"AttributeProfile"`
|
||||
Attributes []Attribute `xml:"Attribute"`
|
||||
}
|
||||
|
||||
// AffiliationDescriptor represents the SAML AffiliationDescriptor object.
|
||||
//
|
||||
// See http://docs.oasis-open.org/security/saml/v2.0/saml-metadata-2.0-os.pdf §2.5
|
||||
type AffiliationDescriptor struct {
|
||||
AffiliationOwnerID string `xml:"affiliationOwnerID,attr"`
|
||||
ID string `xml:",attr"`
|
||||
ValidUntil time.Time `xml:"validUntil,attr,omitempty"`
|
||||
CacheDuration time.Duration `xml:"cacheDuration,attr"`
|
||||
Signature *etree.Element
|
||||
AffiliateMembers []string `xml:"AffiliateMember"`
|
||||
KeyDescriptors []KeyDescriptor `xml:"KeyDescriptor"`
|
||||
}
|
||||
171
vendor/github.com/crewjam/saml/saml.go
generated
vendored
Normal file
171
vendor/github.com/crewjam/saml/saml.go
generated
vendored
Normal file
|
|
@ -0,0 +1,171 @@
|
|||
// Package saml contains a partial implementation of the SAML standard in golang.
|
||||
// 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.
|
||||
//
|
||||
// Introduction
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// Breaking Changes
|
||||
//
|
||||
// Version 0.4.0 introduces a few breaking changes to the _samlsp_ package in order to make the package more extensible, and to clean up the interfaces a bit. The default behavior remains the same, but you can now provide interface implementations of _RequestTracker_ (which tracks pending requests), _Session_ (which handles maintaining a session) and _OnError_ which handles reporting errors.
|
||||
//
|
||||
// Public fields of _samlsp.Middleware_ have changed, so some usages may require adjustment. See [issue 231](https://github.com/crewjam/saml/issues/231) for details.
|
||||
//
|
||||
// The option to provide an IDP metadata URL has been deprecated. Instead, we recommend that you use the `FetchMetadata()` function, or fetch the metadata yourself and use the new `ParseMetadata()` function, and pass the metadata in _samlsp.Options.IDPMetadata_.
|
||||
//
|
||||
// Similarly, the _HTTPClient_ field is now deprecated because it was only used for fetching metdata, which is no longer directly implemented.
|
||||
//
|
||||
// The fields that manage how cookies are set are deprecated as well. To customize how cookies are managed, provide custom implementation of _RequestTracker_ and/or _Session_, perhaps by extending the default implementations.
|
||||
//
|
||||
// The deprecated fields have not been removed from the Options structure, but will be in future.
|
||||
//
|
||||
// In particular we have deprecated the following fields in
|
||||
// _samlsp.Options_:
|
||||
//
|
||||
// - `Logger` - This was used to emit errors while validating, which is an anti-pattern.
|
||||
// - `IDPMetadataURL` - Instead use `FetchMetadata()`
|
||||
// - `HTTPClient` - Instead pass httpClient to FetchMetadata
|
||||
// - `CookieMaxAge` - Instead assign a custom CookieRequestTracker or CookieSessionProvider
|
||||
// - `CookieName` - Instead assign a custom CookieRequestTracker or CookieSessionProvider
|
||||
// - `CookieDomain` - Instead assign a custom CookieRequestTracker or CookieSessionProvider
|
||||
// - `CookieDomain` - Instead assign a custom CookieRequestTracker or CookieSessionProvider
|
||||
//
|
||||
// Getting Started as a Service Provider
|
||||
//
|
||||
// Let us assume we have a simple web application to protect. We'll modify this application so it uses SAML to authenticate users.
|
||||
//
|
||||
// ```golang
|
||||
// package main
|
||||
//
|
||||
// import (
|
||||
// "fmt"
|
||||
// "net/http"
|
||||
// )
|
||||
//
|
||||
// func hello(w http.ResponseWriter, r *http.Request) {
|
||||
// fmt.Fprintf(w, "Hello, World!")
|
||||
// }
|
||||
//
|
||||
// func main() {
|
||||
// app := http.HandlerFunc(hello)
|
||||
// http.Handle("/hello", app)
|
||||
// http.ListenAndServe(":8000", nil)
|
||||
// }
|
||||
// ```
|
||||
//
|
||||
// Each service provider must have an self-signed X.509 key pair established. You can generate your own with something like this:
|
||||
//
|
||||
// openssl req -x509 -newkey rsa:2048 -keyout myservice.key -out myservice.cert -days 365 -nodes -subj "/CN=myservice.example.com"
|
||||
//
|
||||
// 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 [samltest.id](https://samltest.id/), an identity provider designed for testing.
|
||||
//
|
||||
// ```golang
|
||||
// package main
|
||||
//
|
||||
// import (
|
||||
// "crypto/rsa"
|
||||
// "crypto/tls"
|
||||
// "crypto/x509"
|
||||
// "fmt"
|
||||
// "net/http"
|
||||
// "net/url"
|
||||
//
|
||||
// "github.com/crewjam/saml/samlsp"
|
||||
// )
|
||||
//
|
||||
// func hello(w http.ResponseWriter, r *http.Request) {
|
||||
// fmt.Fprintf(w, "Hello, %s!", samlsp.Token(r.Context()).Attributes.Get("cn"))
|
||||
// }
|
||||
//
|
||||
// func main() {
|
||||
// keyPair, err := tls.LoadX509KeyPair("myservice.cert", "myservice.key")
|
||||
// if err != nil {
|
||||
// panic(err) // TODO handle error
|
||||
// }
|
||||
// keyPair.Leaf, err = x509.ParseCertificate(keyPair.Certificate[0])
|
||||
// if err != nil {
|
||||
// panic(err) // TODO handle error
|
||||
// }
|
||||
//
|
||||
// idpMetadataURL, err := url.Parse("https://samltest.id/saml/idp")
|
||||
// if err != nil {
|
||||
// panic(err) // TODO handle error
|
||||
// }
|
||||
//
|
||||
// rootURL, err := url.Parse("http://localhost:8000")
|
||||
// if err != nil {
|
||||
// panic(err) // TODO handle error
|
||||
// }
|
||||
//
|
||||
// samlSP, _ := samlsp.New(samlsp.Options{
|
||||
// URL: *rootURL,
|
||||
// Key: keyPair.PrivateKey.(*rsa.PrivateKey),
|
||||
// Certificate: keyPair.Leaf,
|
||||
// IDPMetadataURL: idpMetadataURL,
|
||||
// })
|
||||
// app := http.HandlerFunc(hello)
|
||||
// http.Handle("/hello", samlSP.RequireAccount(app))
|
||||
// http.Handle("/saml/", samlSP)
|
||||
// http.ListenAndServe(":8000", nil)
|
||||
// }
|
||||
// ```
|
||||
//
|
||||
// Next we'll have to register our service provider with the identity provider to establish trust from the service provider to the IDP. For [samltest.id](https://samltest.id/), you can do something like:
|
||||
//
|
||||
// mdpath=saml-test-$USER-$HOST.xml
|
||||
// curl localhost:8000/saml/metadata > $mdpath
|
||||
//
|
||||
// Navigate to https://samltest.id/upload.php and upload the file you fetched.
|
||||
//
|
||||
// Now you should be able to authenticate. The flow should look like this:
|
||||
//
|
||||
// 1. You browse to `localhost:8000/hello`
|
||||
//
|
||||
// 1. The middleware redirects you to `https://samltest.id/idp/profile/SAML2/Redirect/SSO`
|
||||
//
|
||||
// 1. samltest.id prompts you for a username and password.
|
||||
//
|
||||
// 1. samltest.id 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.
|
||||
//
|
||||
// 1. The local service validates the response, issues a session cookie, and redirects you to the original URL, `localhost:8000/hello`.
|
||||
//
|
||||
// 1. This time when `localhost:8000/hello` is requested there is a valid session and so the main content is served.
|
||||
//
|
||||
// Getting Started as an Identity Provider
|
||||
//
|
||||
// Please see `example/idp/` for a substantially complete example of how to use the library and helpers to be an identity provider.
|
||||
//
|
||||
// Support
|
||||
//
|
||||
// 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).
|
||||
//
|
||||
// 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 from the IDP to the service provider are supported via the HTTP POST binding.
|
||||
//
|
||||
// The package can produce signed SAML assertions, and can validate both signed and encrypted SAML assertions. It does not support signed or encrypted requests.
|
||||
//
|
||||
// RelayState
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// 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.)
|
||||
//
|
||||
// References
|
||||
//
|
||||
// The SAML specification is a collection of PDFs (sadly):
|
||||
//
|
||||
// - [SAMLCore](http://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf) defines data types.
|
||||
//
|
||||
// - [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.
|
||||
//
|
||||
// - [SAMLProfiles](http://docs.oasis-open.org/security/saml/v2.0/saml-profiles-2.0-os.pdf) describes data flows.
|
||||
//
|
||||
// - [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.
|
||||
//
|
||||
// [SAMLtest](https://samltest.id/) is a testing ground for SAML service and identity providers.
|
||||
//
|
||||
// Security Issues
|
||||
//
|
||||
// Please do not report security issues in the issue tracker. Rather, please contact me directly at ross@kndr.org ([PGP Key `78B6038B3B9DFB88`](https://keybase.io/crewjam)).
|
||||
package saml
|
||||
3
vendor/github.com/crewjam/saml/saml_gen.go
generated
vendored
Normal file
3
vendor/github.com/crewjam/saml/saml_gen.go
generated
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
package saml
|
||||
|
||||
//go:generate bash -c "(cat README.md | grep -E -v '^# SAML' | sed 's|^## ||g' | sed 's|\\*\\*||g' | sed 's|^|// |g'; echo 'package saml') > saml.go"
|
||||
25
vendor/github.com/crewjam/saml/samlsp/error.go
generated
vendored
Normal file
25
vendor/github.com/crewjam/saml/samlsp/error.go
generated
vendored
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
package samlsp
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/crewjam/saml"
|
||||
)
|
||||
|
||||
// ErrorFunction is a callback that is invoked to return an error to the
|
||||
// web user.
|
||||
type ErrorFunction func(w http.ResponseWriter, r *http.Request, err error)
|
||||
|
||||
// DefaultOnError is the default ErrorFunction implementation. It prints
|
||||
// an message via the standard log package and returns a simple text
|
||||
// "Forbidden" message to the user.
|
||||
func DefaultOnError(w http.ResponseWriter, r *http.Request, err error) {
|
||||
if parseErr, ok := err.(*saml.InvalidResponseError); ok {
|
||||
log.Printf("WARNING: received invalid saml response: %s (now: %s) %s",
|
||||
parseErr.Response, parseErr.Now, parseErr.PrivateErr)
|
||||
} else {
|
||||
log.Printf("ERROR: %s", err)
|
||||
}
|
||||
http.Error(w, http.StatusText(http.StatusForbidden), http.StatusForbidden)
|
||||
}
|
||||
75
vendor/github.com/crewjam/saml/samlsp/fetch_metadata.go
generated
vendored
Normal file
75
vendor/github.com/crewjam/saml/samlsp/fetch_metadata.go
generated
vendored
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
package samlsp
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/crewjam/httperr"
|
||||
xrv "github.com/mattermost/xml-roundtrip-validator"
|
||||
|
||||
"github.com/crewjam/saml"
|
||||
)
|
||||
|
||||
// ParseMetadata parses arbitrary SAML IDP metadata.
|
||||
//
|
||||
// Note: this is needed because IDP metadata is sometimes wrapped in
|
||||
// an <EntitiesDescriptor>, and sometimes the top level element is an
|
||||
// <EntityDescriptor>.
|
||||
func ParseMetadata(data []byte) (*saml.EntityDescriptor, error) {
|
||||
entity := &saml.EntityDescriptor{}
|
||||
|
||||
if err := xrv.Validate(bytes.NewBuffer(data)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err := xml.Unmarshal(data, entity)
|
||||
|
||||
// this comparison is ugly, but it is how the error is generated in encoding/xml
|
||||
if err != nil && err.Error() == "expected element type <EntityDescriptor> but have <EntitiesDescriptor>" {
|
||||
entities := &saml.EntitiesDescriptor{}
|
||||
if err := xml.Unmarshal(data, entities); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for i, e := range entities.EntityDescriptors {
|
||||
if len(e.IDPSSODescriptors) > 0 {
|
||||
return &entities.EntityDescriptors[i], nil
|
||||
}
|
||||
}
|
||||
return nil, errors.New("no entity found with IDPSSODescriptor")
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return entity, nil
|
||||
}
|
||||
|
||||
// FetchMetadata returns metadata from an IDP metadata URL.
|
||||
func FetchMetadata(ctx context.Context, httpClient *http.Client, metadataURL url.URL) (*saml.EntityDescriptor, error) {
|
||||
req, err := http.NewRequest("GET", metadataURL.String(), nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req = req.WithContext(ctx)
|
||||
|
||||
resp, err := httpClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode >= 400 {
|
||||
return nil, httperr.Response(*resp)
|
||||
}
|
||||
|
||||
data, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ParseMetadata(data)
|
||||
}
|
||||
234
vendor/github.com/crewjam/saml/samlsp/middleware.go
generated
vendored
Normal file
234
vendor/github.com/crewjam/saml/samlsp/middleware.go
generated
vendored
Normal file
|
|
@ -0,0 +1,234 @@
|
|||
package samlsp
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"net/http"
|
||||
|
||||
"github.com/crewjam/saml"
|
||||
)
|
||||
|
||||
// Middleware implements middleware than allows a web application
|
||||
// to support SAML.
|
||||
//
|
||||
// It implements http.Handler so that it can provide the metadata and ACS endpoints,
|
||||
// typically /saml/metadata and /saml/acs, respectively.
|
||||
//
|
||||
// It also provides middleware RequireAccount which redirects users to
|
||||
// the auth process if they do not have session credentials.
|
||||
//
|
||||
// When redirecting the user through the SAML auth flow, the middleware assigns
|
||||
// a temporary cookie with a random name beginning with "saml_". The value of
|
||||
// the cookie is a signed JSON Web Token containing the original URL requested
|
||||
// and the SAML request ID. The random part of the name corresponds to the
|
||||
// RelayState parameter passed through the SAML flow.
|
||||
//
|
||||
// When validating the SAML response, the RelayState is used to look up the
|
||||
// correct cookie, validate that the SAML request ID, and redirect the user
|
||||
// back to their original URL.
|
||||
//
|
||||
// Sessions are established by issuing a JSON Web Token (JWT) as a session
|
||||
// cookie once the SAML flow has succeeded. The JWT token contains the
|
||||
// authenticated attributes from the SAML assertion.
|
||||
//
|
||||
// When the middleware receives a request with a valid session JWT it extracts
|
||||
// the SAML attributes and modifies the http.Request object adding a Context
|
||||
// object to the request context that contains attributes from the initial
|
||||
// SAML assertion.
|
||||
//
|
||||
// When issuing JSON Web Tokens, a signing key is required. Because the
|
||||
// SAML service provider already has a private key, we borrow that key
|
||||
// to sign the JWTs as well.
|
||||
type Middleware struct {
|
||||
ServiceProvider saml.ServiceProvider
|
||||
OnError func(w http.ResponseWriter, r *http.Request, err error)
|
||||
Binding string // either saml.HTTPPostBinding or saml.HTTPRedirectBinding
|
||||
ResponseBinding string // either saml.HTTPPostBinding or saml.HTTPArtifactBinding
|
||||
RequestTracker RequestTracker
|
||||
Session SessionProvider
|
||||
}
|
||||
|
||||
// ServeHTTP implements http.Handler and serves the SAML-specific HTTP endpoints
|
||||
// on the URIs specified by m.ServiceProvider.MetadataURL and
|
||||
// m.ServiceProvider.AcsURL.
|
||||
func (m *Middleware) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path == m.ServiceProvider.MetadataURL.Path {
|
||||
m.ServeMetadata(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
if r.URL.Path == m.ServiceProvider.AcsURL.Path {
|
||||
m.ServeACS(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
http.NotFoundHandler().ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
// ServeMetadata handles requests for the SAML metadata endpoint.
|
||||
func (m *Middleware) ServeMetadata(w http.ResponseWriter, r *http.Request) {
|
||||
buf, _ := xml.MarshalIndent(m.ServiceProvider.Metadata(), "", " ")
|
||||
w.Header().Set("Content-Type", "application/samlmetadata+xml")
|
||||
w.Write(buf)
|
||||
return
|
||||
}
|
||||
|
||||
// ServeACS handles requests for the SAML ACS endpoint.
|
||||
func (m *Middleware) ServeACS(w http.ResponseWriter, r *http.Request) {
|
||||
r.ParseForm()
|
||||
|
||||
possibleRequestIDs := []string{}
|
||||
if m.ServiceProvider.AllowIDPInitiated {
|
||||
possibleRequestIDs = append(possibleRequestIDs, "")
|
||||
}
|
||||
|
||||
trackedRequests := m.RequestTracker.GetTrackedRequests(r)
|
||||
for _, tr := range trackedRequests {
|
||||
possibleRequestIDs = append(possibleRequestIDs, tr.SAMLRequestID)
|
||||
}
|
||||
|
||||
assertion, err := m.ServiceProvider.ParseResponse(r, possibleRequestIDs)
|
||||
if err != nil {
|
||||
m.OnError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
m.CreateSessionFromAssertion(w, r, assertion, m.ServiceProvider.DefaultRedirectURI)
|
||||
return
|
||||
}
|
||||
|
||||
// RequireAccount is HTTP middleware that requires that each request be
|
||||
// associated with a valid session. If the request is not associated with a valid
|
||||
// session, then rather than serve the request, the middleware redirects the user
|
||||
// to start the SAML auth flow.
|
||||
func (m *Middleware) RequireAccount(handler http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
session, err := m.Session.GetSession(r)
|
||||
if session != nil {
|
||||
r = r.WithContext(ContextWithSession(r.Context(), session))
|
||||
handler.ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
if err == ErrNoSession {
|
||||
m.HandleStartAuthFlow(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
m.OnError(w, r, err)
|
||||
return
|
||||
})
|
||||
}
|
||||
|
||||
// HandleStartAuthFlow is called to start the SAML authentication process.
|
||||
func (m *Middleware) HandleStartAuthFlow(w http.ResponseWriter, r *http.Request) {
|
||||
// If we try to redirect when the original request is the ACS URL we'll
|
||||
// end up in a loop. This is a programming error, so we panic here. In
|
||||
// general this means a 500 to the user, which is preferable to a
|
||||
// redirect loop.
|
||||
if r.URL.Path == m.ServiceProvider.AcsURL.Path {
|
||||
panic("don't wrap Middleware with RequireAccount")
|
||||
}
|
||||
|
||||
var binding, bindingLocation string
|
||||
if m.Binding != "" {
|
||||
binding = m.Binding
|
||||
bindingLocation = m.ServiceProvider.GetSSOBindingLocation(binding)
|
||||
} else {
|
||||
binding = saml.HTTPRedirectBinding
|
||||
bindingLocation = m.ServiceProvider.GetSSOBindingLocation(binding)
|
||||
if bindingLocation == "" {
|
||||
binding = saml.HTTPPostBinding
|
||||
bindingLocation = m.ServiceProvider.GetSSOBindingLocation(binding)
|
||||
}
|
||||
}
|
||||
|
||||
authReq, err := m.ServiceProvider.MakeAuthenticationRequest(bindingLocation, binding, m.ResponseBinding)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
// relayState is limited to 80 bytes but also must be integrity protected.
|
||||
// this means that we cannot use a JWT because it is way to long. Instead
|
||||
// we set a signed cookie that encodes the original URL which we'll check
|
||||
// against the SAML response when we get it.
|
||||
relayState, err := m.RequestTracker.TrackRequest(w, r, authReq.ID)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
if binding == saml.HTTPRedirectBinding {
|
||||
redirectURL, err := authReq.Redirect(relayState, &m.ServiceProvider)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Header().Add("Location", redirectURL.String())
|
||||
w.WriteHeader(http.StatusFound)
|
||||
return
|
||||
}
|
||||
if binding == saml.HTTPPostBinding {
|
||||
w.Header().Add("Content-Security-Policy", ""+
|
||||
"default-src; "+
|
||||
"script-src 'sha256-AjPdJSbZmeWHnEc5ykvJFay8FTWeTeRbs9dutfZ0HqE='; "+
|
||||
"reflected-xss block; referrer no-referrer;")
|
||||
w.Header().Add("Content-type", "text/html")
|
||||
w.Write([]byte(`<!DOCTYPE html><html><body>`))
|
||||
w.Write(authReq.Post(relayState))
|
||||
w.Write([]byte(`</body></html>`))
|
||||
return
|
||||
}
|
||||
panic("not reached")
|
||||
}
|
||||
|
||||
// CreateSessionFromAssertion is invoked by ServeHTTP when we have a new, valid SAML assertion.
|
||||
func (m *Middleware) CreateSessionFromAssertion(w http.ResponseWriter, r *http.Request, assertion *saml.Assertion, redirectURI string) {
|
||||
if trackedRequestIndex := r.Form.Get("RelayState"); trackedRequestIndex != "" {
|
||||
trackedRequest, err := m.RequestTracker.GetTrackedRequest(r, trackedRequestIndex)
|
||||
if err != nil {
|
||||
m.OnError(w, r, err)
|
||||
return
|
||||
}
|
||||
m.RequestTracker.StopTrackingRequest(w, r, trackedRequestIndex)
|
||||
|
||||
redirectURI = trackedRequest.URI
|
||||
}
|
||||
|
||||
if err := m.Session.CreateSession(w, r, assertion); err != nil {
|
||||
m.OnError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
http.Redirect(w, r, redirectURI, http.StatusFound)
|
||||
}
|
||||
|
||||
// RequireAttribute returns a middleware function that requires that the
|
||||
// SAML attribute `name` be set to `value`. This can be used to require
|
||||
// that a remote user be a member of a group. It relies on the Claims assigned
|
||||
// to to the context in RequireAccount.
|
||||
//
|
||||
// For example:
|
||||
//
|
||||
// goji.Use(m.RequireAccount)
|
||||
// goji.Use(RequireAttributeMiddleware("eduPersonAffiliation", "Staff"))
|
||||
//
|
||||
func RequireAttribute(name, value string) func(http.Handler) http.Handler {
|
||||
return func(handler http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if session := SessionFromContext(r.Context()); session != nil {
|
||||
// this will panic if we have the wrong type of Session, and that is OK.
|
||||
sessionWithAttributes := session.(SessionWithAttributes)
|
||||
attributes := sessionWithAttributes.GetAttributes()
|
||||
if values, ok := attributes[name]; ok {
|
||||
for _, v := range values {
|
||||
if v == value {
|
||||
handler.ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
http.Error(w, http.StatusText(http.StatusForbidden), http.StatusForbidden)
|
||||
})
|
||||
}
|
||||
}
|
||||
139
vendor/github.com/crewjam/saml/samlsp/new.go
generated
vendored
Normal file
139
vendor/github.com/crewjam/saml/samlsp/new.go
generated
vendored
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
// Package samlsp provides helpers that can be used to protect web services using SAML.
|
||||
package samlsp
|
||||
|
||||
import (
|
||||
"crypto/rsa"
|
||||
"crypto/x509"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
dsig "github.com/russellhaering/goxmldsig"
|
||||
|
||||
"github.com/crewjam/saml"
|
||||
)
|
||||
|
||||
// Options represents the parameters for creating a new middleware
|
||||
type Options struct {
|
||||
EntityID string
|
||||
URL url.URL
|
||||
Key *rsa.PrivateKey
|
||||
Certificate *x509.Certificate
|
||||
Intermediates []*x509.Certificate
|
||||
AllowIDPInitiated bool
|
||||
DefaultRedirectURI string
|
||||
IDPMetadata *saml.EntityDescriptor
|
||||
SignRequest bool
|
||||
UseArtifactResponse bool
|
||||
ForceAuthn bool // TODO(ross): this should be *bool
|
||||
CookieSameSite http.SameSite
|
||||
RelayStateFunc func(w http.ResponseWriter, r *http.Request) string
|
||||
}
|
||||
|
||||
// DefaultSessionCodec returns the default SessionCodec for the provided options,
|
||||
// a JWTSessionCodec configured to issue signed tokens.
|
||||
func DefaultSessionCodec(opts Options) JWTSessionCodec {
|
||||
return JWTSessionCodec{
|
||||
SigningMethod: defaultJWTSigningMethod,
|
||||
Audience: opts.URL.String(),
|
||||
Issuer: opts.URL.String(),
|
||||
MaxAge: defaultSessionMaxAge,
|
||||
Key: opts.Key,
|
||||
}
|
||||
}
|
||||
|
||||
// DefaultSessionProvider returns the default SessionProvider for the provided options,
|
||||
// a CookieSessionProvider configured to store sessions in a cookie.
|
||||
func DefaultSessionProvider(opts Options) CookieSessionProvider {
|
||||
return CookieSessionProvider{
|
||||
Name: defaultSessionCookieName,
|
||||
Domain: opts.URL.Host,
|
||||
MaxAge: defaultSessionMaxAge,
|
||||
HTTPOnly: true,
|
||||
Secure: opts.URL.Scheme == "https",
|
||||
SameSite: opts.CookieSameSite,
|
||||
Codec: DefaultSessionCodec(opts),
|
||||
}
|
||||
}
|
||||
|
||||
// DefaultTrackedRequestCodec returns a new TrackedRequestCodec for the provided
|
||||
// options, a JWTTrackedRequestCodec that uses a JWT to encode TrackedRequests.
|
||||
func DefaultTrackedRequestCodec(opts Options) JWTTrackedRequestCodec {
|
||||
return JWTTrackedRequestCodec{
|
||||
SigningMethod: defaultJWTSigningMethod,
|
||||
Audience: opts.URL.String(),
|
||||
Issuer: opts.URL.String(),
|
||||
MaxAge: saml.MaxIssueDelay,
|
||||
Key: opts.Key,
|
||||
}
|
||||
}
|
||||
|
||||
// DefaultRequestTracker returns a new RequestTracker for the provided options,
|
||||
// a CookieRequestTracker which uses cookies to track pending requests.
|
||||
func DefaultRequestTracker(opts Options, serviceProvider *saml.ServiceProvider) CookieRequestTracker {
|
||||
return CookieRequestTracker{
|
||||
ServiceProvider: serviceProvider,
|
||||
NamePrefix: "saml_",
|
||||
Codec: DefaultTrackedRequestCodec(opts),
|
||||
MaxAge: saml.MaxIssueDelay,
|
||||
RelayStateFunc: opts.RelayStateFunc,
|
||||
SameSite: opts.CookieSameSite,
|
||||
}
|
||||
}
|
||||
|
||||
// DefaultServiceProvider returns the default saml.ServiceProvider for the provided
|
||||
// options.
|
||||
func DefaultServiceProvider(opts Options) saml.ServiceProvider {
|
||||
metadataURL := opts.URL.ResolveReference(&url.URL{Path: "saml/metadata"})
|
||||
acsURL := opts.URL.ResolveReference(&url.URL{Path: "saml/acs"})
|
||||
sloURL := opts.URL.ResolveReference(&url.URL{Path: "saml/slo"})
|
||||
|
||||
var forceAuthn *bool
|
||||
if opts.ForceAuthn {
|
||||
forceAuthn = &opts.ForceAuthn
|
||||
}
|
||||
signatureMethod := dsig.RSASHA1SignatureMethod
|
||||
if !opts.SignRequest {
|
||||
signatureMethod = ""
|
||||
}
|
||||
|
||||
if opts.DefaultRedirectURI == "" {
|
||||
opts.DefaultRedirectURI = "/"
|
||||
}
|
||||
|
||||
return saml.ServiceProvider{
|
||||
EntityID: opts.EntityID,
|
||||
Key: opts.Key,
|
||||
Certificate: opts.Certificate,
|
||||
Intermediates: opts.Intermediates,
|
||||
MetadataURL: *metadataURL,
|
||||
AcsURL: *acsURL,
|
||||
SloURL: *sloURL,
|
||||
IDPMetadata: opts.IDPMetadata,
|
||||
ForceAuthn: forceAuthn,
|
||||
SignatureMethod: signatureMethod,
|
||||
AllowIDPInitiated: opts.AllowIDPInitiated,
|
||||
DefaultRedirectURI: opts.DefaultRedirectURI,
|
||||
}
|
||||
}
|
||||
|
||||
// New creates a new Middleware with the default providers for the
|
||||
// given options.
|
||||
//
|
||||
// You can customize the behavior of the middleware in more detail by
|
||||
// replacing and/or changing Session, RequestTracker, and ServiceProvider
|
||||
// in the returned Middleware.
|
||||
func New(opts Options) (*Middleware, error) {
|
||||
m := &Middleware{
|
||||
ServiceProvider: DefaultServiceProvider(opts),
|
||||
Binding: "",
|
||||
ResponseBinding: saml.HTTPPostBinding,
|
||||
OnError: DefaultOnError,
|
||||
Session: DefaultSessionProvider(opts),
|
||||
}
|
||||
m.RequestTracker = DefaultRequestTracker(opts, &m.ServiceProvider)
|
||||
if opts.UseArtifactResponse {
|
||||
m.ResponseBinding = saml.HTTPArtifactBinding
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
46
vendor/github.com/crewjam/saml/samlsp/request_tracker.go
generated
vendored
Normal file
46
vendor/github.com/crewjam/saml/samlsp/request_tracker.go
generated
vendored
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
package samlsp
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// RequestTracker tracks pending authentication requests.
|
||||
//
|
||||
// There are two main reasons for this:
|
||||
//
|
||||
// 1. When the middleware initiates an authentication request it must track the original URL
|
||||
// in order to redirect the user to the right place after the authentication completes.
|
||||
//
|
||||
// 2. After the authentication completes, we want to ensure that the user presenting the
|
||||
// assertion is actually the one the request it, to mitigate request forgeries.
|
||||
type RequestTracker interface {
|
||||
// TrackRequest starts tracking the SAML request with the given ID. It returns an
|
||||
// `index` that should be used as the RelayState in the SAMl request flow.
|
||||
TrackRequest(w http.ResponseWriter, r *http.Request, samlRequestID string) (index string, err error)
|
||||
|
||||
// StopTrackingRequest stops tracking the SAML request given by index, which is a string
|
||||
// previously returned from TrackRequest
|
||||
StopTrackingRequest(w http.ResponseWriter, r *http.Request, index string) error
|
||||
|
||||
// GetTrackedRequests returns all the pending tracked requests
|
||||
GetTrackedRequests(r *http.Request) []TrackedRequest
|
||||
|
||||
// GetTrackedRequest returns a pending tracked request.
|
||||
GetTrackedRequest(r *http.Request, index string) (*TrackedRequest, error)
|
||||
}
|
||||
|
||||
// TrackedRequest holds the data we store for each pending request.
|
||||
type TrackedRequest struct {
|
||||
Index string `json:"-"`
|
||||
SAMLRequestID string `json:"id"`
|
||||
URI string `json:"uri"`
|
||||
}
|
||||
|
||||
// TrackedRequestCodec handles encoding and decoding of a TrackedRequest.
|
||||
type TrackedRequestCodec interface {
|
||||
// Encode returns an encoded string representing the TrackedRequest.
|
||||
Encode(value TrackedRequest) (string, error)
|
||||
|
||||
// Decode returns a Tracked request from an encoded string.
|
||||
Decode(signed string) (*TrackedRequest, error)
|
||||
}
|
||||
111
vendor/github.com/crewjam/saml/samlsp/request_tracker_cookie.go
generated
vendored
Normal file
111
vendor/github.com/crewjam/saml/samlsp/request_tracker_cookie.go
generated
vendored
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
package samlsp
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/crewjam/saml"
|
||||
)
|
||||
|
||||
var _ RequestTracker = CookieRequestTracker{}
|
||||
|
||||
// CookieRequestTracker tracks requests by setting a uniquely named
|
||||
// cookie for each request.
|
||||
type CookieRequestTracker struct {
|
||||
ServiceProvider *saml.ServiceProvider
|
||||
NamePrefix string
|
||||
Codec TrackedRequestCodec
|
||||
MaxAge time.Duration
|
||||
RelayStateFunc func(w http.ResponseWriter, r *http.Request) string
|
||||
SameSite http.SameSite
|
||||
}
|
||||
|
||||
// TrackRequest starts tracking the SAML request with the given ID. It returns an
|
||||
// `index` that should be used as the RelayState in the SAMl request flow.
|
||||
func (t CookieRequestTracker) TrackRequest(w http.ResponseWriter, r *http.Request, samlRequestID string) (string, error) {
|
||||
trackedRequest := TrackedRequest{
|
||||
Index: base64.RawURLEncoding.EncodeToString(randomBytes(42)),
|
||||
SAMLRequestID: samlRequestID,
|
||||
URI: r.URL.String(),
|
||||
}
|
||||
|
||||
if t.RelayStateFunc != nil {
|
||||
relayState := t.RelayStateFunc(w, r)
|
||||
if relayState != "" {
|
||||
trackedRequest.Index = relayState
|
||||
}
|
||||
}
|
||||
|
||||
signedTrackedRequest, err := t.Codec.Encode(trackedRequest)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
http.SetCookie(w, &http.Cookie{
|
||||
Name: t.NamePrefix + trackedRequest.Index,
|
||||
Value: signedTrackedRequest,
|
||||
MaxAge: int(t.MaxAge.Seconds()),
|
||||
HttpOnly: true,
|
||||
SameSite: t.SameSite,
|
||||
Secure: t.ServiceProvider.AcsURL.Scheme == "https",
|
||||
Path: t.ServiceProvider.AcsURL.Path,
|
||||
})
|
||||
|
||||
return trackedRequest.Index, nil
|
||||
}
|
||||
|
||||
// StopTrackingRequest stops tracking the SAML request given by index, which is a string
|
||||
// previously returned from TrackRequest
|
||||
func (t CookieRequestTracker) StopTrackingRequest(w http.ResponseWriter, r *http.Request, index string) error {
|
||||
cookie, err := r.Cookie(t.NamePrefix + index)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cookie.Value = ""
|
||||
cookie.Domain = t.ServiceProvider.AcsURL.Hostname()
|
||||
cookie.Expires = time.Unix(1, 0) // past time as close to epoch as possible, but not zero time.Time{}
|
||||
http.SetCookie(w, cookie)
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetTrackedRequests returns all the pending tracked requests
|
||||
func (t CookieRequestTracker) GetTrackedRequests(r *http.Request) []TrackedRequest {
|
||||
rv := []TrackedRequest{}
|
||||
for _, cookie := range r.Cookies() {
|
||||
if !strings.HasPrefix(cookie.Name, t.NamePrefix) {
|
||||
continue
|
||||
}
|
||||
|
||||
trackedRequest, err := t.Codec.Decode(cookie.Value)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
index := strings.TrimPrefix(cookie.Name, t.NamePrefix)
|
||||
if index != trackedRequest.Index {
|
||||
continue
|
||||
}
|
||||
|
||||
rv = append(rv, *trackedRequest)
|
||||
}
|
||||
return rv
|
||||
}
|
||||
|
||||
// GetTrackedRequest returns a pending tracked request.
|
||||
func (t CookieRequestTracker) GetTrackedRequest(r *http.Request, index string) (*TrackedRequest, error) {
|
||||
cookie, err := r.Cookie(t.NamePrefix + index)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
trackedRequest, err := t.Codec.Decode(cookie.Value)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if trackedRequest.Index != index {
|
||||
return nil, fmt.Errorf("expected index %q, got %q", index, trackedRequest.Index)
|
||||
}
|
||||
return trackedRequest, nil
|
||||
}
|
||||
75
vendor/github.com/crewjam/saml/samlsp/request_tracker_jwt.go
generated
vendored
Normal file
75
vendor/github.com/crewjam/saml/samlsp/request_tracker_jwt.go
generated
vendored
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
package samlsp
|
||||
|
||||
import (
|
||||
"crypto/rsa"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/golang-jwt/jwt/v4"
|
||||
|
||||
"github.com/crewjam/saml"
|
||||
)
|
||||
|
||||
var defaultJWTSigningMethod = jwt.SigningMethodRS256
|
||||
|
||||
// JWTTrackedRequestCodec encodes TrackedRequests as signed JWTs
|
||||
type JWTTrackedRequestCodec struct {
|
||||
SigningMethod jwt.SigningMethod
|
||||
Audience string
|
||||
Issuer string
|
||||
MaxAge time.Duration
|
||||
Key *rsa.PrivateKey
|
||||
}
|
||||
|
||||
var _ TrackedRequestCodec = JWTTrackedRequestCodec{}
|
||||
|
||||
// JWTTrackedRequestClaims represents the JWT claims for a tracked request.
|
||||
type JWTTrackedRequestClaims struct {
|
||||
jwt.StandardClaims
|
||||
TrackedRequest
|
||||
SAMLAuthnRequest bool `json:"saml-authn-request"`
|
||||
}
|
||||
|
||||
// Encode returns an encoded string representing the TrackedRequest.
|
||||
func (s JWTTrackedRequestCodec) Encode(value TrackedRequest) (string, error) {
|
||||
now := saml.TimeNow()
|
||||
claims := JWTTrackedRequestClaims{
|
||||
StandardClaims: jwt.StandardClaims{
|
||||
Audience: s.Audience,
|
||||
ExpiresAt: now.Add(s.MaxAge).Unix(),
|
||||
IssuedAt: now.Unix(),
|
||||
Issuer: s.Issuer,
|
||||
NotBefore: now.Unix(), // TODO(ross): correct for clock skew
|
||||
Subject: value.Index,
|
||||
},
|
||||
TrackedRequest: value,
|
||||
SAMLAuthnRequest: true,
|
||||
}
|
||||
token := jwt.NewWithClaims(s.SigningMethod, claims)
|
||||
return token.SignedString(s.Key)
|
||||
}
|
||||
|
||||
// Decode returns a Tracked request from an encoded string.
|
||||
func (s JWTTrackedRequestCodec) Decode(signed string) (*TrackedRequest, error) {
|
||||
parser := jwt.Parser{
|
||||
ValidMethods: []string{s.SigningMethod.Alg()},
|
||||
}
|
||||
claims := JWTTrackedRequestClaims{}
|
||||
_, err := parser.ParseWithClaims(signed, &claims, func(*jwt.Token) (interface{}, error) {
|
||||
return s.Key.Public(), nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !claims.VerifyAudience(s.Audience, true) {
|
||||
return nil, fmt.Errorf("expected audience %q, got %q", s.Audience, claims.Audience)
|
||||
}
|
||||
if !claims.VerifyIssuer(s.Issuer, true) {
|
||||
return nil, fmt.Errorf("expected issuer %q, got %q", s.Issuer, claims.Issuer)
|
||||
}
|
||||
if claims.SAMLAuthnRequest != true {
|
||||
return nil, fmt.Errorf("expected saml-authn-request")
|
||||
}
|
||||
claims.TrackedRequest.Index = claims.Subject
|
||||
return &claims.TrackedRequest, nil
|
||||
}
|
||||
89
vendor/github.com/crewjam/saml/samlsp/session.go
generated
vendored
Normal file
89
vendor/github.com/crewjam/saml/samlsp/session.go
generated
vendored
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
package samlsp
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/crewjam/saml"
|
||||
)
|
||||
|
||||
// Session is an interface implemented to contain a session.
|
||||
type Session interface{}
|
||||
|
||||
// SessionWithAttributes is a session that can expose the
|
||||
// attributes provided by the SAML identity provider.
|
||||
type SessionWithAttributes interface {
|
||||
Session
|
||||
GetAttributes() Attributes
|
||||
}
|
||||
|
||||
// ErrNoSession is the error returned when the remote user does not have a session
|
||||
var ErrNoSession = errors.New("saml: session not present")
|
||||
|
||||
// SessionProvider is an interface implemented by types that can track
|
||||
// the active session of a user. The default implementation is CookieSessionProvider
|
||||
type SessionProvider interface {
|
||||
// CreateSession is called when we have received a valid SAML assertion and
|
||||
// should create a new session and modify the http response accordingly, e.g. by
|
||||
// setting a cookie.
|
||||
CreateSession(w http.ResponseWriter, r *http.Request, assertion *saml.Assertion) error
|
||||
|
||||
// DeleteSession is called to modify the response such that it removed the current
|
||||
// session, e.g. by deleting a cookie.
|
||||
DeleteSession(w http.ResponseWriter, r *http.Request) error
|
||||
|
||||
// GetSession returns the current Session associated with the request, or
|
||||
// ErrNoSession if there is no valid session.
|
||||
GetSession(r *http.Request) (Session, error)
|
||||
}
|
||||
|
||||
// SessionCodec is an interface to convert SAML assertions to a
|
||||
// Session. The default implementation uses JWTs, JWTSessionCodec.
|
||||
type SessionCodec interface {
|
||||
// New creates a Session from the SAML assertion.
|
||||
New(assertion *saml.Assertion) (Session, error)
|
||||
|
||||
// Encode returns a serialized version of the Session.
|
||||
//
|
||||
// Note: When implementing this function, it is reasonable to expect that
|
||||
// Session is of the exact type returned by New(), and panic if it is not.
|
||||
Encode(s Session) (string, error)
|
||||
|
||||
// Decode parses the serialized session that may have been returned by Encode
|
||||
// and returns a Session.
|
||||
Decode(string) (Session, error)
|
||||
}
|
||||
|
||||
type indexType int
|
||||
|
||||
const sessionIndex indexType = iota
|
||||
|
||||
// SessionFromContext returns the session associated with ctx, or nil
|
||||
// if no session are associated
|
||||
func SessionFromContext(ctx context.Context) Session {
|
||||
v := ctx.Value(sessionIndex)
|
||||
if v == nil {
|
||||
return nil
|
||||
}
|
||||
return v.(Session)
|
||||
}
|
||||
|
||||
// ContextWithSession returns a new context with session associated
|
||||
func ContextWithSession(ctx context.Context, session Session) context.Context {
|
||||
return context.WithValue(ctx, sessionIndex, session)
|
||||
}
|
||||
|
||||
// AttributeFromContext is a convenience method that returns the named attribute
|
||||
// from the session, if available.
|
||||
func AttributeFromContext(ctx context.Context, name string) string {
|
||||
s := SessionFromContext(ctx)
|
||||
if s == nil {
|
||||
return ""
|
||||
}
|
||||
sa, ok := s.(SessionWithAttributes)
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
return sa.GetAttributes().Get(name)
|
||||
}
|
||||
99
vendor/github.com/crewjam/saml/samlsp/session_cookie.go
generated
vendored
Normal file
99
vendor/github.com/crewjam/saml/samlsp/session_cookie.go
generated
vendored
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
package samlsp
|
||||
|
||||
import (
|
||||
"net"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/crewjam/saml"
|
||||
)
|
||||
|
||||
const defaultSessionCookieName = "token"
|
||||
|
||||
var _ SessionProvider = CookieSessionProvider{}
|
||||
|
||||
// CookieSessionProvider is an implementation of SessionProvider that stores
|
||||
// session tokens in an HTTP cookie.
|
||||
type CookieSessionProvider struct {
|
||||
Name string
|
||||
Domain string
|
||||
HTTPOnly bool
|
||||
Secure bool
|
||||
SameSite http.SameSite
|
||||
MaxAge time.Duration
|
||||
Codec SessionCodec
|
||||
}
|
||||
|
||||
// CreateSession is called when we have received a valid SAML assertion and
|
||||
// should create a new session and modify the http response accordingly, e.g. by
|
||||
// setting a cookie.
|
||||
func (c CookieSessionProvider) CreateSession(w http.ResponseWriter, r *http.Request, assertion *saml.Assertion) error {
|
||||
// Cookies should not have the port attached to them so strip it off
|
||||
if domain, _, err := net.SplitHostPort(c.Domain); err == nil {
|
||||
c.Domain = domain
|
||||
}
|
||||
|
||||
session, err := c.Codec.New(assertion)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
value, err := c.Codec.Encode(session)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
http.SetCookie(w, &http.Cookie{
|
||||
Name: c.Name,
|
||||
Domain: c.Domain,
|
||||
Value: value,
|
||||
MaxAge: int(c.MaxAge.Seconds()),
|
||||
HttpOnly: c.HTTPOnly,
|
||||
Secure: c.Secure || r.URL.Scheme == "https",
|
||||
SameSite: c.SameSite,
|
||||
Path: "/",
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteSession is called to modify the response such that it removed the current
|
||||
// session, e.g. by deleting a cookie.
|
||||
func (c CookieSessionProvider) DeleteSession(w http.ResponseWriter, r *http.Request) error {
|
||||
// Cookies should not have the port attached to them so strip it off
|
||||
if domain, _, err := net.SplitHostPort(c.Domain); err == nil {
|
||||
c.Domain = domain
|
||||
}
|
||||
|
||||
cookie, err := r.Cookie(c.Name)
|
||||
|
||||
if err == http.ErrNoCookie {
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cookie.Value = ""
|
||||
cookie.Expires = time.Unix(1, 0) // past time as close to epoch as possible, but not zero time.Time{}
|
||||
cookie.Path = "/"
|
||||
cookie.Domain = c.Domain
|
||||
http.SetCookie(w, cookie)
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetSession returns the current Session associated with the request, or
|
||||
// ErrNoSession if there is no valid session.
|
||||
func (c CookieSessionProvider) GetSession(r *http.Request) (Session, error) {
|
||||
cookie, err := r.Cookie(c.Name)
|
||||
if err == http.ErrNoCookie {
|
||||
return nil, ErrNoSession
|
||||
} else if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
session, err := c.Codec.Decode(cookie.Value)
|
||||
if err != nil {
|
||||
return nil, ErrNoSession
|
||||
}
|
||||
return session, nil
|
||||
}
|
||||
143
vendor/github.com/crewjam/saml/samlsp/session_jwt.go
generated
vendored
Normal file
143
vendor/github.com/crewjam/saml/samlsp/session_jwt.go
generated
vendored
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
package samlsp
|
||||
|
||||
import (
|
||||
"crypto/rsa"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/golang-jwt/jwt/v4"
|
||||
|
||||
"github.com/crewjam/saml"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultSessionMaxAge = time.Hour
|
||||
claimNameSessionIndex = "SessionIndex"
|
||||
)
|
||||
|
||||
// JWTSessionCodec implements SessionCoded to encode and decode Sessions from
|
||||
// the corresponding JWT.
|
||||
type JWTSessionCodec struct {
|
||||
SigningMethod jwt.SigningMethod
|
||||
Audience string
|
||||
Issuer string
|
||||
MaxAge time.Duration
|
||||
Key *rsa.PrivateKey
|
||||
}
|
||||
|
||||
var _ SessionCodec = JWTSessionCodec{}
|
||||
|
||||
// New creates a Session from the SAML assertion.
|
||||
//
|
||||
// The returned Session is a JWTSessionClaims.
|
||||
func (c JWTSessionCodec) New(assertion *saml.Assertion) (Session, error) {
|
||||
now := saml.TimeNow()
|
||||
claims := JWTSessionClaims{}
|
||||
claims.SAMLSession = true
|
||||
claims.Audience = c.Audience
|
||||
claims.Issuer = c.Issuer
|
||||
claims.IssuedAt = now.Unix()
|
||||
claims.ExpiresAt = now.Add(c.MaxAge).Unix()
|
||||
claims.NotBefore = now.Unix()
|
||||
|
||||
if sub := assertion.Subject; sub != nil {
|
||||
if nameID := sub.NameID; nameID != nil {
|
||||
claims.Subject = nameID.Value
|
||||
}
|
||||
}
|
||||
|
||||
claims.Attributes = map[string][]string{}
|
||||
|
||||
for _, attributeStatement := range assertion.AttributeStatements {
|
||||
for _, attr := range attributeStatement.Attributes {
|
||||
claimName := attr.FriendlyName
|
||||
if claimName == "" {
|
||||
claimName = attr.Name
|
||||
}
|
||||
for _, value := range attr.Values {
|
||||
claims.Attributes[claimName] = append(claims.Attributes[claimName], value.Value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add SessionIndex to claims Attributes
|
||||
for _, authnStatement := range assertion.AuthnStatements {
|
||||
claims.Attributes[claimNameSessionIndex] = append(claims.Attributes[claimNameSessionIndex],
|
||||
authnStatement.SessionIndex)
|
||||
}
|
||||
|
||||
return claims, nil
|
||||
}
|
||||
|
||||
// Encode returns a serialized version of the Session.
|
||||
//
|
||||
// The provided session must be a JWTSessionClaims, otherwise this
|
||||
// function will panic.
|
||||
func (c JWTSessionCodec) Encode(s Session) (string, error) {
|
||||
claims := s.(JWTSessionClaims) // this will panic if you pass the wrong kind of session
|
||||
|
||||
token := jwt.NewWithClaims(c.SigningMethod, claims)
|
||||
signedString, err := token.SignedString(c.Key)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return signedString, nil
|
||||
}
|
||||
|
||||
// Decode parses the serialized session that may have been returned by Encode
|
||||
// and returns a Session.
|
||||
func (c JWTSessionCodec) Decode(signed string) (Session, error) {
|
||||
parser := jwt.Parser{
|
||||
ValidMethods: []string{c.SigningMethod.Alg()},
|
||||
}
|
||||
claims := JWTSessionClaims{}
|
||||
_, err := parser.ParseWithClaims(signed, &claims, func(*jwt.Token) (interface{}, error) {
|
||||
return c.Key.Public(), nil
|
||||
})
|
||||
// TODO(ross): check for errors due to bad time and return ErrNoSession
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !claims.VerifyAudience(c.Audience, true) {
|
||||
return nil, fmt.Errorf("expected audience %q, got %q", c.Audience, claims.Audience)
|
||||
}
|
||||
if !claims.VerifyIssuer(c.Issuer, true) {
|
||||
return nil, fmt.Errorf("expected issuer %q, got %q", c.Issuer, claims.Issuer)
|
||||
}
|
||||
if claims.SAMLSession != true {
|
||||
return nil, errors.New("expected saml-session")
|
||||
}
|
||||
return claims, nil
|
||||
}
|
||||
|
||||
// JWTSessionClaims represents the JWT claims in the encoded session
|
||||
type JWTSessionClaims struct {
|
||||
jwt.StandardClaims
|
||||
Attributes Attributes `json:"attr"`
|
||||
SAMLSession bool `json:"saml-session"`
|
||||
}
|
||||
|
||||
var _ Session = JWTSessionClaims{}
|
||||
|
||||
// GetAttributes implements SessionWithAttributes. It returns the SAMl attributes.
|
||||
func (c JWTSessionClaims) GetAttributes() Attributes {
|
||||
return c.Attributes
|
||||
}
|
||||
|
||||
// Attributes is a map of attributes provided in the SAML assertion
|
||||
type Attributes map[string][]string
|
||||
|
||||
// Get returns the first attribute named `key` or an empty string if
|
||||
// no such attributes is present.
|
||||
func (a Attributes) Get(key string) string {
|
||||
if a == nil {
|
||||
return ""
|
||||
}
|
||||
v := a[key]
|
||||
if len(v) == 0 {
|
||||
return ""
|
||||
}
|
||||
return v[0]
|
||||
}
|
||||
16
vendor/github.com/crewjam/saml/samlsp/util.go
generated
vendored
Normal file
16
vendor/github.com/crewjam/saml/samlsp/util.go
generated
vendored
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
package samlsp
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"github.com/crewjam/saml"
|
||||
)
|
||||
|
||||
func randomBytes(n int) []byte {
|
||||
rv := make([]byte, n)
|
||||
|
||||
if _, err := io.ReadFull(saml.RandReader, rv); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return rv
|
||||
}
|
||||
1304
vendor/github.com/crewjam/saml/schema.go
generated
vendored
Normal file
1304
vendor/github.com/crewjam/saml/schema.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
1574
vendor/github.com/crewjam/saml/service_provider.go
generated
vendored
Normal file
1574
vendor/github.com/crewjam/saml/service_provider.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
52
vendor/github.com/crewjam/saml/time.go
generated
vendored
Normal file
52
vendor/github.com/crewjam/saml/time.go
generated
vendored
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
package saml
|
||||
|
||||
import "time"
|
||||
|
||||
// RelaxedTime is a version of time.Time that supports the time format
|
||||
// found in SAML documents.
|
||||
type RelaxedTime time.Time
|
||||
|
||||
const timeFormat = "2006-01-02T15:04:05.999Z07:00"
|
||||
|
||||
// MarshalText implements encoding.TextMarshaler
|
||||
func (m RelaxedTime) MarshalText() ([]byte, error) {
|
||||
// According to section 1.2.2 of the OASIS SAML 1.1 spec, we can't trust
|
||||
// other applications to handle time resolution finer than a millisecond.
|
||||
//
|
||||
// The time MUST be expressed in UTC.
|
||||
return []byte(m.String()), nil
|
||||
}
|
||||
|
||||
func (m RelaxedTime) String() string {
|
||||
return time.Time(m).Round(time.Millisecond).UTC().Format(timeFormat)
|
||||
}
|
||||
|
||||
// UnmarshalText implements encoding.TextUnmarshaler
|
||||
func (m *RelaxedTime) UnmarshalText(text []byte) error {
|
||||
if len(text) == 0 {
|
||||
*m = RelaxedTime(time.Time{})
|
||||
return nil
|
||||
}
|
||||
t, err1 := time.Parse(time.RFC3339, string(text))
|
||||
if err1 == nil {
|
||||
t = t.Round(time.Millisecond)
|
||||
*m = RelaxedTime(t)
|
||||
return nil
|
||||
}
|
||||
|
||||
t, err2 := time.Parse(time.RFC3339Nano, string(text))
|
||||
if err2 == nil {
|
||||
t = t.Round(time.Millisecond)
|
||||
*m = RelaxedTime(t)
|
||||
return nil
|
||||
}
|
||||
|
||||
t, err2 = time.Parse("2006-01-02T15:04:05.999999999", string(text))
|
||||
if err2 == nil {
|
||||
t = t.Round(time.Millisecond)
|
||||
*m = RelaxedTime(t)
|
||||
return nil
|
||||
}
|
||||
|
||||
return err1
|
||||
}
|
||||
31
vendor/github.com/crewjam/saml/util.go
generated
vendored
Normal file
31
vendor/github.com/crewjam/saml/util.go
generated
vendored
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
package saml
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"io"
|
||||
"time"
|
||||
|
||||
dsig "github.com/russellhaering/goxmldsig"
|
||||
)
|
||||
|
||||
// TimeNow is a function that returns the current time. The default
|
||||
// value is time.Now, but it can be replaced for testing.
|
||||
var TimeNow = func() time.Time { return time.Now().UTC() }
|
||||
|
||||
// Clock is assigned to dsig validation and signing contexts if it is
|
||||
// not nil, otherwise the default clock is used.
|
||||
var Clock *dsig.Clock
|
||||
|
||||
// RandReader is the io.Reader that produces cryptographically random
|
||||
// bytes when they are need by the library. The default value is
|
||||
// rand.Reader, but it can be replaced for testing.
|
||||
var RandReader = rand.Reader
|
||||
|
||||
func randomBytes(n int) []byte {
|
||||
rv := make([]byte, n)
|
||||
|
||||
if _, err := io.ReadFull(RandReader, rv); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return rv
|
||||
}
|
||||
187
vendor/github.com/crewjam/saml/xmlenc/cbc.go
generated
vendored
Normal file
187
vendor/github.com/crewjam/saml/xmlenc/cbc.go
generated
vendored
Normal file
|
|
@ -0,0 +1,187 @@
|
|||
package xmlenc
|
||||
|
||||
import (
|
||||
"crypto/aes"
|
||||
"crypto/cipher"
|
||||
"crypto/des" // nolint: gas
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/beevik/etree"
|
||||
)
|
||||
|
||||
// CBC implements Decrypter and Encrypter for block ciphers in CBC mode
|
||||
type CBC struct {
|
||||
keySize int
|
||||
algorithm string
|
||||
cipher func([]byte) (cipher.Block, error)
|
||||
}
|
||||
|
||||
// KeySize returns the length of the key required.
|
||||
func (e CBC) KeySize() int {
|
||||
return e.keySize
|
||||
}
|
||||
|
||||
// Algorithm returns the name of the algorithm, as will be found
|
||||
// in an xenc:EncryptionMethod element.
|
||||
func (e CBC) Algorithm() string {
|
||||
return e.algorithm
|
||||
}
|
||||
|
||||
// Encrypt encrypts plaintext with key, which should be a []byte of length KeySize().
|
||||
// It returns an xenc:EncryptedData element.
|
||||
func (e CBC) Encrypt(key interface{}, plaintext []byte, nonce []byte) (*etree.Element, error) {
|
||||
keyBuf, ok := key.([]byte)
|
||||
if !ok {
|
||||
return nil, ErrIncorrectKeyType("[]byte")
|
||||
}
|
||||
if len(keyBuf) != e.keySize {
|
||||
return nil, ErrIncorrectKeyLength(e.keySize)
|
||||
}
|
||||
|
||||
block, err := e.cipher(keyBuf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
encryptedDataEl := etree.NewElement("xenc:EncryptedData")
|
||||
encryptedDataEl.CreateAttr("xmlns:xenc", "http://www.w3.org/2001/04/xmlenc#")
|
||||
{
|
||||
randBuf := make([]byte, 16)
|
||||
if _, err := RandReader.Read(randBuf); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
encryptedDataEl.CreateAttr("Id", fmt.Sprintf("_%x", randBuf))
|
||||
}
|
||||
|
||||
em := encryptedDataEl.CreateElement("xenc:EncryptionMethod")
|
||||
em.CreateAttr("Algorithm", e.algorithm)
|
||||
em.CreateAttr("xmlns:xenc", "http://www.w3.org/2001/04/xmlenc#")
|
||||
|
||||
plaintext = appendPadding(plaintext, block.BlockSize())
|
||||
|
||||
iv := make([]byte, block.BlockSize())
|
||||
if _, err := RandReader.Read(iv); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
mode := cipher.NewCBCEncrypter(block, iv)
|
||||
ciphertext := make([]byte, len(plaintext))
|
||||
mode.CryptBlocks(ciphertext, plaintext)
|
||||
ciphertext = append(iv, ciphertext...)
|
||||
|
||||
cd := encryptedDataEl.CreateElement("xenc:CipherData")
|
||||
cd.CreateAttr("xmlns:xenc", "http://www.w3.org/2001/04/xmlenc#")
|
||||
cd.CreateElement("xenc:CipherValue").SetText(base64.StdEncoding.EncodeToString(ciphertext))
|
||||
return encryptedDataEl, nil
|
||||
}
|
||||
|
||||
// Decrypt decrypts an encrypted element with key. If the ciphertext contains an
|
||||
// EncryptedKey element, then the type of `key` is determined by the registered
|
||||
// Decryptor for the EncryptedKey element. Otherwise, `key` must be a []byte of
|
||||
// length KeySize().
|
||||
func (e CBC) Decrypt(key interface{}, ciphertextEl *etree.Element) ([]byte, error) {
|
||||
// If the key is encrypted, decrypt it.
|
||||
if encryptedKeyEl := ciphertextEl.FindElement("./KeyInfo/EncryptedKey"); encryptedKeyEl != nil {
|
||||
var err error
|
||||
key, err = Decrypt(key, encryptedKeyEl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
keyBuf, ok := key.([]byte)
|
||||
if !ok {
|
||||
return nil, ErrIncorrectKeyType("[]byte")
|
||||
}
|
||||
if len(keyBuf) != e.KeySize() {
|
||||
return nil, ErrIncorrectKeyLength(e.KeySize())
|
||||
}
|
||||
|
||||
block, err := e.cipher(keyBuf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ciphertext, err := getCiphertext(ciphertextEl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(ciphertext) < block.BlockSize() {
|
||||
return nil, errors.New("ciphertext too short")
|
||||
}
|
||||
|
||||
iv := ciphertext[:aes.BlockSize]
|
||||
ciphertext = ciphertext[aes.BlockSize:]
|
||||
|
||||
mode := cipher.NewCBCDecrypter(block, iv)
|
||||
plaintext := make([]byte, len(ciphertext))
|
||||
mode.CryptBlocks(plaintext, ciphertext) // decrypt in place
|
||||
|
||||
plaintext, err = stripPadding(plaintext)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return plaintext, nil
|
||||
}
|
||||
|
||||
var (
|
||||
// AES128CBC implements AES128-CBC symetric key mode for encryption and decryption
|
||||
AES128CBC BlockCipher = CBC{
|
||||
keySize: 16,
|
||||
algorithm: "http://www.w3.org/2001/04/xmlenc#aes128-cbc",
|
||||
cipher: aes.NewCipher,
|
||||
}
|
||||
|
||||
// AES192CBC implements AES192-CBC symetric key mode for encryption and decryption
|
||||
AES192CBC BlockCipher = CBC{
|
||||
keySize: 24,
|
||||
algorithm: "http://www.w3.org/2001/04/xmlenc#aes192-cbc",
|
||||
cipher: aes.NewCipher,
|
||||
}
|
||||
|
||||
// AES256CBC implements AES256-CBC symetric key mode for encryption and decryption
|
||||
AES256CBC BlockCipher = CBC{
|
||||
keySize: 32,
|
||||
algorithm: "http://www.w3.org/2001/04/xmlenc#aes256-cbc",
|
||||
cipher: aes.NewCipher,
|
||||
}
|
||||
|
||||
// TripleDES implements 3DES in CBC mode for encryption and decryption
|
||||
TripleDES BlockCipher = CBC{
|
||||
keySize: 8,
|
||||
algorithm: "http://www.w3.org/2001/04/xmlenc#tripledes-cbc",
|
||||
cipher: des.NewCipher,
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
RegisterDecrypter(AES128CBC)
|
||||
RegisterDecrypter(AES192CBC)
|
||||
RegisterDecrypter(AES256CBC)
|
||||
RegisterDecrypter(TripleDES)
|
||||
}
|
||||
|
||||
func appendPadding(buf []byte, blockSize int) []byte {
|
||||
paddingBytes := blockSize - (len(buf) % blockSize)
|
||||
padding := make([]byte, paddingBytes)
|
||||
padding[len(padding)-1] = byte(paddingBytes)
|
||||
return append(buf, padding...)
|
||||
}
|
||||
|
||||
func stripPadding(buf []byte) ([]byte, error) {
|
||||
if len(buf) < 1 {
|
||||
return nil, errors.New("buffer is too short for padding")
|
||||
}
|
||||
paddingBytes := int(buf[len(buf)-1])
|
||||
if paddingBytes > len(buf)-1 {
|
||||
return nil, errors.New("buffer is too short for padding")
|
||||
}
|
||||
if paddingBytes < 1 {
|
||||
return nil, errors.New("padding must be at least one byte")
|
||||
}
|
||||
return buf[:len(buf)-paddingBytes], nil
|
||||
}
|
||||
115
vendor/github.com/crewjam/saml/xmlenc/decrypt.go
generated
vendored
Normal file
115
vendor/github.com/crewjam/saml/xmlenc/decrypt.go
generated
vendored
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
package xmlenc
|
||||
|
||||
import (
|
||||
|
||||
// nolint: gas
|
||||
"crypto/rsa"
|
||||
"crypto/x509"
|
||||
"encoding/base64"
|
||||
"encoding/pem"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"strings"
|
||||
|
||||
"github.com/beevik/etree"
|
||||
)
|
||||
|
||||
// ErrAlgorithmNotImplemented is returned when encryption used is not
|
||||
// supported.
|
||||
type ErrAlgorithmNotImplemented string
|
||||
|
||||
func (e ErrAlgorithmNotImplemented) Error() string {
|
||||
return "algorithm is not implemented: " + string(e)
|
||||
}
|
||||
|
||||
// ErrCannotFindRequiredElement is returned by Decrypt when a required
|
||||
// element cannot be found.
|
||||
type ErrCannotFindRequiredElement string
|
||||
|
||||
func (e ErrCannotFindRequiredElement) Error() string {
|
||||
return "cannot find required element: " + string(e)
|
||||
}
|
||||
|
||||
// ErrIncorrectTag is returned when Decrypt is passed an element which
|
||||
// is neither an EncryptedType nor an EncryptedKey
|
||||
var ErrIncorrectTag = fmt.Errorf("tag must be an EncryptedType or EncryptedKey")
|
||||
|
||||
// ErrIncorrectKeyLength is returned when the fixed length key is not
|
||||
// of the required length.
|
||||
type ErrIncorrectKeyLength int
|
||||
|
||||
func (e ErrIncorrectKeyLength) Error() string {
|
||||
return fmt.Sprintf("expected key to be %d bytes", int(e))
|
||||
}
|
||||
|
||||
// ErrIncorrectKeyType is returned when the key is not the correct type
|
||||
type ErrIncorrectKeyType string
|
||||
|
||||
func (e ErrIncorrectKeyType) Error() string {
|
||||
return fmt.Sprintf("expected key to be %s", string(e))
|
||||
}
|
||||
|
||||
// Decrypt decrypts the encrypted data using the provided key. If the
|
||||
// data are encrypted using AES or 3DEC, then the key should be a []byte.
|
||||
// If the data are encrypted with PKCS1v15 or RSA-OAEP-MGF1P then key should
|
||||
// be a *rsa.PrivateKey.
|
||||
func Decrypt(key interface{}, ciphertextEl *etree.Element) ([]byte, error) {
|
||||
encryptionMethodEl := ciphertextEl.FindElement("./EncryptionMethod")
|
||||
if encryptionMethodEl == nil {
|
||||
return nil, ErrCannotFindRequiredElement("EncryptionMethod")
|
||||
}
|
||||
algorithm := encryptionMethodEl.SelectAttrValue("Algorithm", "")
|
||||
decrypter, ok := decrypters[algorithm]
|
||||
if !ok {
|
||||
return nil, ErrAlgorithmNotImplemented(algorithm)
|
||||
}
|
||||
return decrypter.Decrypt(key, ciphertextEl)
|
||||
}
|
||||
|
||||
func getCiphertext(encryptedKey *etree.Element) ([]byte, error) {
|
||||
ciphertextEl := encryptedKey.FindElement("./CipherData/CipherValue")
|
||||
if ciphertextEl == nil {
|
||||
return nil, fmt.Errorf("cannot find CipherData element containing a CipherValue element")
|
||||
}
|
||||
ciphertext, err := base64.StdEncoding.DecodeString(strings.TrimSpace(ciphertextEl.Text()))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ciphertext, nil
|
||||
}
|
||||
|
||||
func validateRSAKeyIfPresent(key interface{}, encryptedKey *etree.Element) (*rsa.PrivateKey, error) {
|
||||
rsaKey, ok := key.(*rsa.PrivateKey)
|
||||
if !ok {
|
||||
return nil, errors.New("expected key to be a *rsa.PrivateKey")
|
||||
}
|
||||
|
||||
// extract and verify that the public key matches the certificate
|
||||
// this section is included to either let the service know up front
|
||||
// if the key will work, or let the service provider know which key
|
||||
// to use to decrypt the message. Either way, verification is not
|
||||
// security-critical.
|
||||
if el := encryptedKey.FindElement("./KeyInfo/X509Data/X509Certificate"); el != nil {
|
||||
certPEMbuf := el.Text()
|
||||
certPEMbuf = "-----BEGIN CERTIFICATE-----\n" + certPEMbuf + "\n-----END CERTIFICATE-----\n"
|
||||
certPEM, _ := pem.Decode([]byte(certPEMbuf))
|
||||
if certPEM == nil {
|
||||
return nil, fmt.Errorf("invalid certificate")
|
||||
}
|
||||
cert, err := x509.ParseCertificate(certPEM.Bytes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pubKey, ok := cert.PublicKey.(*rsa.PublicKey)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("expected certificate to be an *rsa.PublicKey")
|
||||
}
|
||||
if rsaKey.N.Cmp(pubKey.N) != 0 || rsaKey.E != pubKey.E {
|
||||
return nil, fmt.Errorf("certificate does not match provided key")
|
||||
}
|
||||
} else if el = encryptedKey.FindElement("./KeyInfo/X509Data/X509IssuerSerial"); el != nil {
|
||||
// TODO: determine how to validate the issuer serial information
|
||||
}
|
||||
return rsaKey, nil
|
||||
}
|
||||
56
vendor/github.com/crewjam/saml/xmlenc/digest.go
generated
vendored
Normal file
56
vendor/github.com/crewjam/saml/xmlenc/digest.go
generated
vendored
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
package xmlenc
|
||||
|
||||
import (
|
||||
"crypto/sha1" //nolint:gosec // required for protocol support
|
||||
"crypto/sha256"
|
||||
"crypto/sha512"
|
||||
"hash"
|
||||
|
||||
"golang.org/x/crypto/ripemd160"
|
||||
)
|
||||
|
||||
type digestMethod struct {
|
||||
algorithm string
|
||||
hash func() hash.Hash
|
||||
}
|
||||
|
||||
func (dm digestMethod) Algorithm() string {
|
||||
return dm.algorithm
|
||||
}
|
||||
|
||||
func (dm digestMethod) Hash() hash.Hash {
|
||||
return dm.hash()
|
||||
}
|
||||
|
||||
var (
|
||||
// SHA1 implements the SHA-1 digest method (which is considered insecure)
|
||||
SHA1 = digestMethod{
|
||||
algorithm: "http://www.w3.org/2000/09/xmldsig#sha1",
|
||||
hash: sha1.New,
|
||||
}
|
||||
|
||||
// SHA256 implements the SHA-256 digest method
|
||||
SHA256 = digestMethod{
|
||||
algorithm: "http://www.w3.org/2000/09/xmldsig#sha256",
|
||||
hash: sha256.New,
|
||||
}
|
||||
|
||||
// SHA512 implements the SHA-512 digest method
|
||||
SHA512 = digestMethod{
|
||||
algorithm: "http://www.w3.org/2000/09/xmldsig#sha512",
|
||||
hash: sha512.New,
|
||||
}
|
||||
|
||||
// RIPEMD160 implements the RIPEMD160 digest method
|
||||
RIPEMD160 = digestMethod{
|
||||
algorithm: "http://www.w3.org/2000/09/xmldsig#ripemd160",
|
||||
hash: ripemd160.New,
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
RegisterDigestMethod(SHA1)
|
||||
RegisterDigestMethod(SHA256)
|
||||
RegisterDigestMethod(SHA512)
|
||||
RegisterDigestMethod(RIPEMD160)
|
||||
}
|
||||
49
vendor/github.com/crewjam/saml/xmlenc/fuzz.go
generated
vendored
Normal file
49
vendor/github.com/crewjam/saml/xmlenc/fuzz.go
generated
vendored
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
package xmlenc
|
||||
|
||||
import (
|
||||
"crypto/rsa"
|
||||
"crypto/x509"
|
||||
"encoding/pem"
|
||||
|
||||
"github.com/beevik/etree"
|
||||
)
|
||||
|
||||
var testKey = func() *rsa.PrivateKey {
|
||||
const keyStr = `-----BEGIN RSA PRIVATE KEY-----
|
||||
MIICXQIBAAKBgQDkXTUsWzRVpUHjbDpWCfYDfXmQ/q4LkaioZoTpu4ut1Q3eQC5t
|
||||
gD14agJhgT8yzeY5S/YNlwCyuVkjuFyoyTHFX2IOPpz7jnh4KnQ+B1IH9fY/+kmk
|
||||
zHJgxSUDJsdUMPgGpKt5hnEn7ziXAWXLc2udFbnHwhi9TXXwRHGi9wZ4YwIDAQAB
|
||||
AoGBALNTnlXeqRI4W61DZ+v4ln/XIIeD9xiOoWrcVrNU2zL+g41ryQmkEqFkXcpD
|
||||
vGUg2xFTXTz+v0WZ1y39sIW6uKFRYUfaNsF6iVfGAyx1VWK/jgtPnCWDQy26Eby0
|
||||
BqpbZRy1a6MLYVEG/5bvZE01CDV4XttpTrNX91WWcYGduJxBAkEA6ED1ZOqIzBpu
|
||||
c2KAo+bWmroCH8+cSDk0gVq6bnRB+EEhRCmo/VgvndWLxfexdGmDIOAIisB06N5a
|
||||
GzBSCaEY/QJBAPu2cNvuuBNLwrlxPCwOEpIHYT4gJq8UMtg6O6N+u++nYCGhK6uo
|
||||
VCmrKY+UewyNIcsLZF0jsNI2qJjiU1vQxN8CQQDfQJnigMQwlfO3/Ga1po6Buu2R
|
||||
0IpkroB3G1R8GkrTrR+iGv2zUdKrwHsUOC2fPlFrB4+OeMOomRw6aG9jjDStAkB1
|
||||
ztiZhuvuVAoKIv5HnDqC0CNqIUAZtzlozDB3f+xT6SFr+/Plfn4Nlod4JMVGhZNo
|
||||
ZaeOlBLBAEX+cAcVtOs/AkBicZOAPv84ABmFfyhXhYaAuacaJLq//jg+t+URUOg+
|
||||
XZS9naRmawEQxOkZQVoMeKgvu05+V4MniFqdQBINIkr5
|
||||
-----END RSA PRIVATE KEY-----`
|
||||
b, _ := pem.Decode([]byte(keyStr))
|
||||
k, err := x509.ParsePKCS1PrivateKey(b.Bytes)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return k
|
||||
}()
|
||||
|
||||
// Fuzz is the go-fuzz fuzzing function
|
||||
func Fuzz(data []byte) int {
|
||||
doc := etree.NewDocument()
|
||||
if err := doc.ReadFromBytes(data); err != nil {
|
||||
return 0
|
||||
}
|
||||
if doc.Root() == nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
if _, err := Decrypt(testKey, doc.Root()); err != nil {
|
||||
return 0
|
||||
}
|
||||
return 1
|
||||
}
|
||||
143
vendor/github.com/crewjam/saml/xmlenc/gcm.go
generated
vendored
Normal file
143
vendor/github.com/crewjam/saml/xmlenc/gcm.go
generated
vendored
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
package xmlenc
|
||||
|
||||
import (
|
||||
"crypto/aes"
|
||||
"crypto/cipher"
|
||||
"crypto/rand"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/beevik/etree"
|
||||
)
|
||||
|
||||
// GCM implements Decrypter and Encrypter for block ciphers in struct mode
|
||||
type GCM struct {
|
||||
keySize int
|
||||
algorithm string
|
||||
cipher func([]byte) (cipher.Block, error)
|
||||
}
|
||||
|
||||
// KeySize returns the length of the key required.
|
||||
func (e GCM) KeySize() int {
|
||||
return e.keySize
|
||||
}
|
||||
|
||||
// Algorithm returns the name of the algorithm, as will be found
|
||||
// in an xenc:EncryptionMethod element.
|
||||
func (e GCM) Algorithm() string {
|
||||
return e.algorithm
|
||||
}
|
||||
|
||||
// Encrypt encrypts plaintext with key and nonce
|
||||
func (e GCM) Encrypt(key interface{}, plaintext []byte, nonce []byte) (*etree.Element, error) {
|
||||
keyBuf, ok := key.([]byte)
|
||||
if !ok {
|
||||
return nil, ErrIncorrectKeyType("[]byte")
|
||||
}
|
||||
if len(keyBuf) != e.keySize {
|
||||
return nil, ErrIncorrectKeyLength(e.keySize)
|
||||
}
|
||||
|
||||
block, err := e.cipher(keyBuf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
encryptedDataEl := etree.NewElement("xenc:EncryptedData")
|
||||
encryptedDataEl.CreateAttr("xmlns:xenc", "http://www.w3.org/2001/04/xmlenc#")
|
||||
{
|
||||
randBuf := make([]byte, 16)
|
||||
if _, err := RandReader.Read(randBuf); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
encryptedDataEl.CreateAttr("Id", fmt.Sprintf("_%x", randBuf))
|
||||
}
|
||||
|
||||
em := encryptedDataEl.CreateElement("xenc:EncryptionMethod")
|
||||
em.CreateAttr("Algorithm", e.algorithm)
|
||||
em.CreateAttr("xmlns:xenc", "http://www.w3.org/2001/04/xmlenc#")
|
||||
|
||||
plaintext = appendPadding(plaintext, block.BlockSize())
|
||||
|
||||
aesgcm, err := cipher.NewGCM(block)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if nonce == nil {
|
||||
// generate random nonce when it's nil
|
||||
nonce := make([]byte, aesgcm.NonceSize())
|
||||
if _, err := io.ReadFull(rand.Reader, nonce); err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
ciphertext := make([]byte, len(plaintext))
|
||||
text := aesgcm.Seal(nil, nonce, ciphertext, nil)
|
||||
|
||||
cd := encryptedDataEl.CreateElement("xenc:CipherData")
|
||||
cd.CreateAttr("xmlns:xenc", "http://www.w3.org/2001/04/xmlenc#")
|
||||
cd.CreateElement("xenc:CipherValue").SetText(base64.StdEncoding.EncodeToString(text))
|
||||
return encryptedDataEl, nil
|
||||
}
|
||||
|
||||
// Decrypt decrypts an encrypted element with key. If the ciphertext contains an
|
||||
// EncryptedKey element, then the type of `key` is determined by the registered
|
||||
// Decryptor for the EncryptedKey element. Otherwise, `key` must be a []byte of
|
||||
// length KeySize().
|
||||
func (e GCM) Decrypt(key interface{}, ciphertextEl *etree.Element) ([]byte, error) {
|
||||
if encryptedKeyEl := ciphertextEl.FindElement("./KeyInfo/EncryptedKey"); encryptedKeyEl != nil {
|
||||
var err error
|
||||
key, err = Decrypt(key, encryptedKeyEl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
keyBuf, ok := key.([]byte)
|
||||
|
||||
if !ok {
|
||||
return nil, ErrIncorrectKeyType("[]byte")
|
||||
}
|
||||
if len(keyBuf) != e.KeySize() {
|
||||
return nil, ErrIncorrectKeyLength(e.KeySize())
|
||||
}
|
||||
|
||||
block, err := e.cipher(keyBuf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
aesgcm, err := cipher.NewGCM(block)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ciphertext, err := getCiphertext(ciphertextEl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
nonce := ciphertext[:aesgcm.NonceSize()]
|
||||
text := ciphertext[aesgcm.NonceSize():]
|
||||
|
||||
plainText, err := aesgcm.Open(nil, nonce, text, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return plainText, nil
|
||||
}
|
||||
|
||||
var (
|
||||
// AES128GCM implements AES128-GCM mode for encryption and decryption
|
||||
AES128GCM BlockCipher = GCM{
|
||||
keySize: 16,
|
||||
algorithm: "http://www.w3.org/2009/xmlenc11#aes128-gcm",
|
||||
cipher: aes.NewCipher,
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
RegisterDecrypter(AES128GCM)
|
||||
}
|
||||
162
vendor/github.com/crewjam/saml/xmlenc/pubkey.go
generated
vendored
Normal file
162
vendor/github.com/crewjam/saml/xmlenc/pubkey.go
generated
vendored
Normal file
|
|
@ -0,0 +1,162 @@
|
|||
package xmlenc
|
||||
|
||||
import (
|
||||
"crypto/rsa"
|
||||
"crypto/x509"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
|
||||
"github.com/beevik/etree"
|
||||
)
|
||||
|
||||
// RSA implements Encrypter and Decrypter using RSA public key encryption.
|
||||
//
|
||||
// Use function like OAEP(), or PKCS1v15() to get an instance of this type ready
|
||||
// to use.
|
||||
type RSA struct {
|
||||
BlockCipher BlockCipher
|
||||
DigestMethod DigestMethod // only for OAEP
|
||||
|
||||
algorithm string
|
||||
keyEncrypter func(e RSA, pubKey *rsa.PublicKey, plaintext []byte) ([]byte, error)
|
||||
keyDecrypter func(e RSA, privKey *rsa.PrivateKey, ciphertext []byte) ([]byte, error)
|
||||
}
|
||||
|
||||
// Algorithm returns the name of the algorithm
|
||||
func (e RSA) Algorithm() string {
|
||||
return e.algorithm
|
||||
}
|
||||
|
||||
// Encrypt implements encrypter. certificate must be a []byte containing the ASN.1 bytes
|
||||
// of certificate containing an RSA public key.
|
||||
func (e RSA) Encrypt(certificate interface{}, plaintext []byte, nonce []byte) (*etree.Element, error) {
|
||||
cert, ok := certificate.(*x509.Certificate)
|
||||
if !ok {
|
||||
return nil, ErrIncorrectKeyType("*x.509 certificate")
|
||||
}
|
||||
|
||||
pubKey, ok := cert.PublicKey.(*rsa.PublicKey)
|
||||
if !ok {
|
||||
return nil, ErrIncorrectKeyType("x.509 certificate with an RSA public key")
|
||||
}
|
||||
|
||||
// generate a key
|
||||
key := make([]byte, e.BlockCipher.KeySize())
|
||||
if _, err := RandReader.Read(key); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
keyInfoEl := etree.NewElement("ds:KeyInfo")
|
||||
keyInfoEl.CreateAttr("xmlns:ds", "http://www.w3.org/2000/09/xmldsig#")
|
||||
|
||||
encryptedKey := keyInfoEl.CreateElement("xenc:EncryptedKey")
|
||||
{
|
||||
randBuf := make([]byte, 16)
|
||||
if _, err := RandReader.Read(randBuf); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
encryptedKey.CreateAttr("Id", fmt.Sprintf("_%x", randBuf))
|
||||
}
|
||||
encryptedKey.CreateAttr("xmlns:xenc", "http://www.w3.org/2001/04/xmlenc#")
|
||||
|
||||
encryptionMethodEl := encryptedKey.CreateElement("xenc:EncryptionMethod")
|
||||
encryptionMethodEl.CreateAttr("Algorithm", e.algorithm)
|
||||
encryptionMethodEl.CreateAttr("xmlns:xenc", "http://www.w3.org/2001/04/xmlenc#")
|
||||
if e.DigestMethod != nil {
|
||||
dm := encryptionMethodEl.CreateElement("ds:DigestMethod")
|
||||
dm.CreateAttr("Algorithm", e.DigestMethod.Algorithm())
|
||||
dm.CreateAttr("xmlns:ds", "http://www.w3.org/2000/09/xmldsig#")
|
||||
}
|
||||
{
|
||||
innerKeyInfoEl := encryptedKey.CreateElement("ds:KeyInfo")
|
||||
x509data := innerKeyInfoEl.CreateElement("ds:X509Data")
|
||||
x509data.CreateElement("ds:X509Certificate").SetText(
|
||||
base64.StdEncoding.EncodeToString(cert.Raw),
|
||||
)
|
||||
}
|
||||
|
||||
buf, err := e.keyEncrypter(e, pubKey, key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cd := encryptedKey.CreateElement("xenc:CipherData")
|
||||
cd.CreateAttr("xmlns:xenc", "http://www.w3.org/2001/04/xmlenc#")
|
||||
cd.CreateElement("xenc:CipherValue").SetText(base64.StdEncoding.EncodeToString(buf))
|
||||
encryptedDataEl, err := e.BlockCipher.Encrypt(key, plaintext, nonce)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
encryptedDataEl.InsertChildAt(encryptedDataEl.FindElement("./CipherData").Index(), keyInfoEl)
|
||||
|
||||
return encryptedDataEl, nil
|
||||
}
|
||||
|
||||
// Decrypt implements Decryptor. `key` must be an *rsa.PrivateKey.
|
||||
func (e RSA) Decrypt(key interface{}, ciphertextEl *etree.Element) ([]byte, error) {
|
||||
rsaKey, err := validateRSAKeyIfPresent(key, ciphertextEl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ciphertext, err := getCiphertext(ciphertextEl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
{
|
||||
digestMethodEl := ciphertextEl.FindElement("./EncryptionMethod/DigestMethod")
|
||||
if digestMethodEl == nil {
|
||||
e.DigestMethod = SHA1
|
||||
} else {
|
||||
hashAlgorithmStr := digestMethodEl.SelectAttrValue("Algorithm", "")
|
||||
digestMethod, ok := digestMethods[hashAlgorithmStr]
|
||||
if !ok {
|
||||
return nil, ErrAlgorithmNotImplemented(hashAlgorithmStr)
|
||||
}
|
||||
e.DigestMethod = digestMethod
|
||||
}
|
||||
}
|
||||
|
||||
return e.keyDecrypter(e, rsaKey, ciphertext)
|
||||
}
|
||||
|
||||
// OAEP returns a version of RSA that implements RSA in OAEP-MGF1P mode. By default
|
||||
// the block cipher used is AES-256 CBC and the digest method is SHA-256. You can
|
||||
// specify other ciphers and digest methods by assigning to BlockCipher or
|
||||
// DigestMethod.
|
||||
func OAEP() RSA {
|
||||
return RSA{
|
||||
BlockCipher: AES256CBC,
|
||||
DigestMethod: SHA256,
|
||||
algorithm: "http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p",
|
||||
keyEncrypter: func(e RSA, pubKey *rsa.PublicKey, plaintext []byte) ([]byte, error) {
|
||||
return rsa.EncryptOAEP(e.DigestMethod.Hash(), RandReader, pubKey, plaintext, nil)
|
||||
},
|
||||
keyDecrypter: func(e RSA, privKey *rsa.PrivateKey, ciphertext []byte) ([]byte, error) {
|
||||
return rsa.DecryptOAEP(e.DigestMethod.Hash(), RandReader, privKey, ciphertext, nil)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// PKCS1v15 returns a version of RSA that implements RSA in PKCS1v15 mode. By default
|
||||
// the block cipher used is AES-256 CBC. The DigestMethod field is ignored because PKCS1v15
|
||||
// does not use a digest function.
|
||||
func PKCS1v15() RSA {
|
||||
return RSA{
|
||||
BlockCipher: AES256CBC,
|
||||
DigestMethod: nil,
|
||||
algorithm: "http://www.w3.org/2001/04/xmlenc#rsa-1_5",
|
||||
keyEncrypter: func(e RSA, pubKey *rsa.PublicKey, plaintext []byte) ([]byte, error) {
|
||||
return rsa.EncryptPKCS1v15(RandReader, pubKey, plaintext)
|
||||
},
|
||||
keyDecrypter: func(e RSA, privKey *rsa.PrivateKey, ciphertext []byte) ([]byte, error) {
|
||||
return rsa.DecryptPKCS1v15(RandReader, privKey, ciphertext)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
RegisterDecrypter(OAEP())
|
||||
RegisterDecrypter(PKCS1v15())
|
||||
}
|
||||
62
vendor/github.com/crewjam/saml/xmlenc/xmlenc.go
generated
vendored
Normal file
62
vendor/github.com/crewjam/saml/xmlenc/xmlenc.go
generated
vendored
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
// Package xmlenc is a partial implementation of the xmlenc standard
|
||||
// as described in https://www.w3.org/TR/2002/REC-xmlenc-core-20021210/Overview.html.
|
||||
// The purpose of this implementation is to support encrypted SAML assertions.
|
||||
package xmlenc
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"hash"
|
||||
|
||||
"github.com/beevik/etree"
|
||||
)
|
||||
|
||||
// RandReader is a thunk that allows test to replace the source of randomness used by
|
||||
// this package. By default it is Reader from crypto/rand.
|
||||
var RandReader = rand.Reader
|
||||
|
||||
// Encrypter is an interface that encrypts things. Given a plaintext it returns an
|
||||
// XML EncryptedData or EncryptedKey element. The required type of `key` varies
|
||||
// depending on the implementation.
|
||||
type Encrypter interface {
|
||||
Encrypt(key interface{}, plaintext []byte, nonce []byte) (*etree.Element, error)
|
||||
}
|
||||
|
||||
// Decrypter is an interface that decrypts things. The Decrypt() method returns the
|
||||
// plaintext version of the EncryptedData or EncryptedKey element passed.
|
||||
//
|
||||
// You probably don't have to use this interface directly, instead you may call
|
||||
// Decrypt() and it will examine the element to determine which Decrypter to use.
|
||||
type Decrypter interface {
|
||||
Algorithm() string
|
||||
Decrypt(key interface{}, ciphertextEl *etree.Element) ([]byte, error)
|
||||
}
|
||||
|
||||
// DigestMethod represents a digest method such as SHA1, etc.
|
||||
type DigestMethod interface {
|
||||
Algorithm() string
|
||||
Hash() hash.Hash
|
||||
}
|
||||
|
||||
var (
|
||||
decrypters = map[string]Decrypter{}
|
||||
digestMethods = map[string]DigestMethod{}
|
||||
)
|
||||
|
||||
// RegisterDecrypter registers the specified decrypter to that it can be
|
||||
// used with Decrypt().
|
||||
func RegisterDecrypter(d Decrypter) {
|
||||
decrypters[d.Algorithm()] = d
|
||||
}
|
||||
|
||||
// RegisterDigestMethod registers the specified digest method to that it can be
|
||||
// used with Decrypt().
|
||||
func RegisterDigestMethod(dm DigestMethod) {
|
||||
digestMethods[dm.Algorithm()] = dm
|
||||
}
|
||||
|
||||
// BlockCipher implements a cipher with a fixed size key like AES or 3DES.
|
||||
type BlockCipher interface {
|
||||
Encrypter
|
||||
Decrypter
|
||||
KeySize() int
|
||||
}
|
||||
4
vendor/github.com/golang-jwt/jwt/v4/.gitignore
generated
vendored
Normal file
4
vendor/github.com/golang-jwt/jwt/v4/.gitignore
generated
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
.DS_Store
|
||||
bin
|
||||
.idea/
|
||||
|
||||
9
vendor/github.com/golang-jwt/jwt/v4/LICENSE
generated
vendored
Normal file
9
vendor/github.com/golang-jwt/jwt/v4/LICENSE
generated
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
Copyright (c) 2012 Dave Grijalva
|
||||
Copyright (c) 2021 golang-jwt maintainers
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
22
vendor/github.com/golang-jwt/jwt/v4/MIGRATION_GUIDE.md
generated
vendored
Normal file
22
vendor/github.com/golang-jwt/jwt/v4/MIGRATION_GUIDE.md
generated
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
## Migration Guide (v4.0.0)
|
||||
|
||||
Starting from [v4.0.0](https://github.com/golang-jwt/jwt/releases/tag/v4.0.0), the import path will be:
|
||||
|
||||
"github.com/golang-jwt/jwt/v4"
|
||||
|
||||
The `/v4` version will be backwards compatible with existing `v3.x.y` tags in this repo, as well as
|
||||
`github.com/dgrijalva/jwt-go`. For most users this should be a drop-in replacement, if you're having
|
||||
troubles migrating, please open an issue.
|
||||
|
||||
You can replace all occurrences of `github.com/dgrijalva/jwt-go` or `github.com/golang-jwt/jwt` with `github.com/golang-jwt/jwt/v4`, either manually or by using tools such as `sed` or `gofmt`.
|
||||
|
||||
And then you'd typically run:
|
||||
|
||||
```
|
||||
go get github.com/golang-jwt/jwt/v4
|
||||
go mod tidy
|
||||
```
|
||||
|
||||
## Older releases (before v3.2.0)
|
||||
|
||||
The original migration guide for older releases can be found at https://github.com/dgrijalva/jwt-go/blob/master/MIGRATION_GUIDE.md.
|
||||
114
vendor/github.com/golang-jwt/jwt/v4/README.md
generated
vendored
Normal file
114
vendor/github.com/golang-jwt/jwt/v4/README.md
generated
vendored
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
# jwt-go
|
||||
|
||||
[](https://github.com/golang-jwt/jwt/actions/workflows/build.yml)
|
||||
[](https://pkg.go.dev/github.com/golang-jwt/jwt/v4)
|
||||
|
||||
A [go](http://www.golang.org) (or 'golang' for search engine friendliness) implementation of [JSON Web Tokens](https://datatracker.ietf.org/doc/html/rfc7519).
|
||||
|
||||
Starting with [v4.0.0](https://github.com/golang-jwt/jwt/releases/tag/v4.0.0) this project adds Go module support, but maintains backwards compatibility with older `v3.x.y` tags and upstream `github.com/dgrijalva/jwt-go`.
|
||||
See the [`MIGRATION_GUIDE.md`](./MIGRATION_GUIDE.md) for more information.
|
||||
|
||||
> After the original author of the library suggested migrating the maintenance of `jwt-go`, a dedicated team of open source maintainers decided to clone the existing library into this repository. See [dgrijalva/jwt-go#462](https://github.com/dgrijalva/jwt-go/issues/462) for a detailed discussion on this topic.
|
||||
|
||||
|
||||
**SECURITY NOTICE:** Some older versions of Go have a security issue in the crypto/elliptic. Recommendation is to upgrade to at least 1.15 See issue [dgrijalva/jwt-go#216](https://github.com/dgrijalva/jwt-go/issues/216) for more detail.
|
||||
|
||||
**SECURITY NOTICE:** It's important that you [validate the `alg` presented is what you expect](https://auth0.com/blog/critical-vulnerabilities-in-json-web-token-libraries/). This library attempts to make it easy to do the right thing by requiring key types match the expected alg, but you should take the extra step to verify it in your usage. See the examples provided.
|
||||
|
||||
### Supported Go versions
|
||||
|
||||
Our support of Go versions is aligned with Go's [version release policy](https://golang.org/doc/devel/release#policy).
|
||||
So we will support a major version of Go until there are two newer major releases.
|
||||
We no longer support building jwt-go with unsupported Go versions, as these contain security vulnerabilities
|
||||
which will not be fixed.
|
||||
|
||||
## What the heck is a JWT?
|
||||
|
||||
JWT.io has [a great introduction](https://jwt.io/introduction) to JSON Web Tokens.
|
||||
|
||||
In short, it's a signed JSON object that does something useful (for example, authentication). It's commonly used for `Bearer` tokens in Oauth 2. A token is made of three parts, separated by `.`'s. The first two parts are JSON objects, that have been [base64url](https://datatracker.ietf.org/doc/html/rfc4648) encoded. The last part is the signature, encoded the same way.
|
||||
|
||||
The first part is called the header. It contains the necessary information for verifying the last part, the signature. For example, which encryption method was used for signing and what key was used.
|
||||
|
||||
The part in the middle is the interesting bit. It's called the Claims and contains the actual stuff you care about. Refer to [RFC 7519](https://datatracker.ietf.org/doc/html/rfc7519) for information about reserved keys and the proper way to add your own.
|
||||
|
||||
## What's in the box?
|
||||
|
||||
This library supports the parsing and verification as well as the generation and signing of JWTs. Current supported signing algorithms are HMAC SHA, RSA, RSA-PSS, and ECDSA, though hooks are present for adding your own.
|
||||
|
||||
## Examples
|
||||
|
||||
See [the project documentation](https://pkg.go.dev/github.com/golang-jwt/jwt) for examples of usage:
|
||||
|
||||
* [Simple example of parsing and validating a token](https://pkg.go.dev/github.com/golang-jwt/jwt#example-Parse-Hmac)
|
||||
* [Simple example of building and signing a token](https://pkg.go.dev/github.com/golang-jwt/jwt#example-New-Hmac)
|
||||
* [Directory of Examples](https://pkg.go.dev/github.com/golang-jwt/jwt#pkg-examples)
|
||||
|
||||
## Extensions
|
||||
|
||||
This library publishes all the necessary components for adding your own signing methods. Simply implement the `SigningMethod` interface and register a factory method using `RegisterSigningMethod`.
|
||||
|
||||
Here's an example of an extension that integrates with multiple Google Cloud Platform signing tools (AppEngine, IAM API, Cloud KMS): https://github.com/someone1/gcp-jwt-go
|
||||
|
||||
## Compliance
|
||||
|
||||
This library was last reviewed to comply with [RFC 7519](https://datatracker.ietf.org/doc/html/rfc7519) dated May 2015 with a few notable differences:
|
||||
|
||||
* In order to protect against accidental use of [Unsecured JWTs](https://datatracker.ietf.org/doc/html/rfc7519#section-6), tokens using `alg=none` will only be accepted if the constant `jwt.UnsafeAllowNoneSignatureType` is provided as the key.
|
||||
|
||||
## Project Status & Versioning
|
||||
|
||||
This library is considered production ready. Feedback and feature requests are appreciated. The API should be considered stable. There should be very few backwards-incompatible changes outside of major version updates (and only with good reason).
|
||||
|
||||
This project uses [Semantic Versioning 2.0.0](http://semver.org). Accepted pull requests will land on `main`. Periodically, versions will be tagged from `main`. You can find all the releases on [the project releases page](https://github.com/golang-jwt/jwt/releases).
|
||||
|
||||
**BREAKING CHANGES:***
|
||||
A full list of breaking changes is available in `VERSION_HISTORY.md`. See `MIGRATION_GUIDE.md` for more information on updating your code.
|
||||
|
||||
## Usage Tips
|
||||
|
||||
### Signing vs Encryption
|
||||
|
||||
A token is simply a JSON object that is signed by its author. this tells you exactly two things about the data:
|
||||
|
||||
* The author of the token was in the possession of the signing secret
|
||||
* The data has not been modified since it was signed
|
||||
|
||||
It's important to know that JWT does not provide encryption, which means anyone who has access to the token can read its contents. If you need to protect (encrypt) the data, there is a companion spec, `JWE`, that provides this functionality. JWE is currently outside the scope of this library.
|
||||
|
||||
### Choosing a Signing Method
|
||||
|
||||
There are several signing methods available, and you should probably take the time to learn about the various options before choosing one. The principal design decision is most likely going to be symmetric vs asymmetric.
|
||||
|
||||
Symmetric signing methods, such as HSA, use only a single secret. This is probably the simplest signing method to use since any `[]byte` can be used as a valid secret. They are also slightly computationally faster to use, though this rarely is enough to matter. Symmetric signing methods work the best when both producers and consumers of tokens are trusted, or even the same system. Since the same secret is used to both sign and validate tokens, you can't easily distribute the key for validation.
|
||||
|
||||
Asymmetric signing methods, such as RSA, use different keys for signing and verifying tokens. This makes it possible to produce tokens with a private key, and allow any consumer to access the public key for verification.
|
||||
|
||||
### Signing Methods and Key Types
|
||||
|
||||
Each signing method expects a different object type for its signing keys. See the package documentation for details. Here are the most common ones:
|
||||
|
||||
* The [HMAC signing method](https://pkg.go.dev/github.com/golang-jwt/jwt#SigningMethodHMAC) (`HS256`,`HS384`,`HS512`) expect `[]byte` values for signing and validation
|
||||
* The [RSA signing method](https://pkg.go.dev/github.com/golang-jwt/jwt#SigningMethodRSA) (`RS256`,`RS384`,`RS512`) expect `*rsa.PrivateKey` for signing and `*rsa.PublicKey` for validation
|
||||
* The [ECDSA signing method](https://pkg.go.dev/github.com/golang-jwt/jwt#SigningMethodECDSA) (`ES256`,`ES384`,`ES512`) expect `*ecdsa.PrivateKey` for signing and `*ecdsa.PublicKey` for validation
|
||||
* The [EdDSA signing method](https://pkg.go.dev/github.com/golang-jwt/jwt#SigningMethodEd25519) (`Ed25519`) expect `ed25519.PrivateKey` for signing and `ed25519.PublicKey` for validation
|
||||
|
||||
### JWT and OAuth
|
||||
|
||||
It's worth mentioning that OAuth and JWT are not the same thing. A JWT token is simply a signed JSON object. It can be used anywhere such a thing is useful. There is some confusion, though, as JWT is the most common type of bearer token used in OAuth2 authentication.
|
||||
|
||||
Without going too far down the rabbit hole, here's a description of the interaction of these technologies:
|
||||
|
||||
* OAuth is a protocol for allowing an identity provider to be separate from the service a user is logging in to. For example, whenever you use Facebook to log into a different service (Yelp, Spotify, etc), you are using OAuth.
|
||||
* OAuth defines several options for passing around authentication data. One popular method is called a "bearer token". A bearer token is simply a string that _should_ only be held by an authenticated user. Thus, simply presenting this token proves your identity. You can probably derive from here why a JWT might make a good bearer token.
|
||||
* Because bearer tokens are used for authentication, it's important they're kept secret. This is why transactions that use bearer tokens typically happen over SSL.
|
||||
|
||||
### Troubleshooting
|
||||
|
||||
This library uses descriptive error messages whenever possible. If you are not getting the expected result, have a look at the errors. The most common place people get stuck is providing the correct type of key to the parser. See the above section on signing methods and key types.
|
||||
|
||||
## More
|
||||
|
||||
Documentation can be found [on pkg.go.dev](https://pkg.go.dev/github.com/golang-jwt/jwt).
|
||||
|
||||
The command line utility included in this project (cmd/jwt) provides a straightforward example of token creation and parsing as well as a useful tool for debugging your own integration. You'll also find several implementation examples in the documentation.
|
||||
135
vendor/github.com/golang-jwt/jwt/v4/VERSION_HISTORY.md
generated
vendored
Normal file
135
vendor/github.com/golang-jwt/jwt/v4/VERSION_HISTORY.md
generated
vendored
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
## `jwt-go` Version History
|
||||
|
||||
#### 4.0.0
|
||||
|
||||
* Introduces support for Go modules. The `v4` version will be backwards compatible with `v3.x.y`.
|
||||
|
||||
#### 3.2.2
|
||||
|
||||
* Starting from this release, we are adopting the policy to support the most 2 recent versions of Go currently available. By the time of this release, this is Go 1.15 and 1.16 ([#28](https://github.com/golang-jwt/jwt/pull/28)).
|
||||
* Fixed a potential issue that could occur when the verification of `exp`, `iat` or `nbf` was not required and contained invalid contents, i.e. non-numeric/date. Thanks for @thaJeztah for making us aware of that and @giorgos-f3 for originally reporting it to the formtech fork ([#40](https://github.com/golang-jwt/jwt/pull/40)).
|
||||
* Added support for EdDSA / ED25519 ([#36](https://github.com/golang-jwt/jwt/pull/36)).
|
||||
* Optimized allocations ([#33](https://github.com/golang-jwt/jwt/pull/33)).
|
||||
|
||||
#### 3.2.1
|
||||
|
||||
* **Import Path Change**: See MIGRATION_GUIDE.md for tips on updating your code
|
||||
* Changed the import path from `github.com/dgrijalva/jwt-go` to `github.com/golang-jwt/jwt`
|
||||
* Fixed type confusing issue between `string` and `[]string` in `VerifyAudience` ([#12](https://github.com/golang-jwt/jwt/pull/12)). This fixes CVE-2020-26160
|
||||
|
||||
#### 3.2.0
|
||||
|
||||
* Added method `ParseUnverified` to allow users to split up the tasks of parsing and validation
|
||||
* HMAC signing method returns `ErrInvalidKeyType` instead of `ErrInvalidKey` where appropriate
|
||||
* Added options to `request.ParseFromRequest`, which allows for an arbitrary list of modifiers to parsing behavior. Initial set include `WithClaims` and `WithParser`. Existing usage of this function will continue to work as before.
|
||||
* Deprecated `ParseFromRequestWithClaims` to simplify API in the future.
|
||||
|
||||
#### 3.1.0
|
||||
|
||||
* Improvements to `jwt` command line tool
|
||||
* Added `SkipClaimsValidation` option to `Parser`
|
||||
* Documentation updates
|
||||
|
||||
#### 3.0.0
|
||||
|
||||
* **Compatibility Breaking Changes**: See MIGRATION_GUIDE.md for tips on updating your code
|
||||
* Dropped support for `[]byte` keys when using RSA signing methods. This convenience feature could contribute to security vulnerabilities involving mismatched key types with signing methods.
|
||||
* `ParseFromRequest` has been moved to `request` subpackage and usage has changed
|
||||
* The `Claims` property on `Token` is now type `Claims` instead of `map[string]interface{}`. The default value is type `MapClaims`, which is an alias to `map[string]interface{}`. This makes it possible to use a custom type when decoding claims.
|
||||
* Other Additions and Changes
|
||||
* Added `Claims` interface type to allow users to decode the claims into a custom type
|
||||
* Added `ParseWithClaims`, which takes a third argument of type `Claims`. Use this function instead of `Parse` if you have a custom type you'd like to decode into.
|
||||
* Dramatically improved the functionality and flexibility of `ParseFromRequest`, which is now in the `request` subpackage
|
||||
* Added `ParseFromRequestWithClaims` which is the `FromRequest` equivalent of `ParseWithClaims`
|
||||
* Added new interface type `Extractor`, which is used for extracting JWT strings from http requests. Used with `ParseFromRequest` and `ParseFromRequestWithClaims`.
|
||||
* Added several new, more specific, validation errors to error type bitmask
|
||||
* Moved examples from README to executable example files
|
||||
* Signing method registry is now thread safe
|
||||
* Added new property to `ValidationError`, which contains the raw error returned by calls made by parse/verify (such as those returned by keyfunc or json parser)
|
||||
|
||||
#### 2.7.0
|
||||
|
||||
This will likely be the last backwards compatible release before 3.0.0, excluding essential bug fixes.
|
||||
|
||||
* Added new option `-show` to the `jwt` command that will just output the decoded token without verifying
|
||||
* Error text for expired tokens includes how long it's been expired
|
||||
* Fixed incorrect error returned from `ParseRSAPublicKeyFromPEM`
|
||||
* Documentation updates
|
||||
|
||||
#### 2.6.0
|
||||
|
||||
* Exposed inner error within ValidationError
|
||||
* Fixed validation errors when using UseJSONNumber flag
|
||||
* Added several unit tests
|
||||
|
||||
#### 2.5.0
|
||||
|
||||
* Added support for signing method none. You shouldn't use this. The API tries to make this clear.
|
||||
* Updated/fixed some documentation
|
||||
* Added more helpful error message when trying to parse tokens that begin with `BEARER `
|
||||
|
||||
#### 2.4.0
|
||||
|
||||
* Added new type, Parser, to allow for configuration of various parsing parameters
|
||||
* You can now specify a list of valid signing methods. Anything outside this set will be rejected.
|
||||
* You can now opt to use the `json.Number` type instead of `float64` when parsing token JSON
|
||||
* Added support for [Travis CI](https://travis-ci.org/dgrijalva/jwt-go)
|
||||
* Fixed some bugs with ECDSA parsing
|
||||
|
||||
#### 2.3.0
|
||||
|
||||
* Added support for ECDSA signing methods
|
||||
* Added support for RSA PSS signing methods (requires go v1.4)
|
||||
|
||||
#### 2.2.0
|
||||
|
||||
* Gracefully handle a `nil` `Keyfunc` being passed to `Parse`. Result will now be the parsed token and an error, instead of a panic.
|
||||
|
||||
#### 2.1.0
|
||||
|
||||
Backwards compatible API change that was missed in 2.0.0.
|
||||
|
||||
* The `SignedString` method on `Token` now takes `interface{}` instead of `[]byte`
|
||||
|
||||
#### 2.0.0
|
||||
|
||||
There were two major reasons for breaking backwards compatibility with this update. The first was a refactor required to expand the width of the RSA and HMAC-SHA signing implementations. There will likely be no required code changes to support this change.
|
||||
|
||||
The second update, while unfortunately requiring a small change in integration, is required to open up this library to other signing methods. Not all keys used for all signing methods have a single standard on-disk representation. Requiring `[]byte` as the type for all keys proved too limiting. Additionally, this implementation allows for pre-parsed tokens to be reused, which might matter in an application that parses a high volume of tokens with a small set of keys. Backwards compatibilty has been maintained for passing `[]byte` to the RSA signing methods, but they will also accept `*rsa.PublicKey` and `*rsa.PrivateKey`.
|
||||
|
||||
It is likely the only integration change required here will be to change `func(t *jwt.Token) ([]byte, error)` to `func(t *jwt.Token) (interface{}, error)` when calling `Parse`.
|
||||
|
||||
* **Compatibility Breaking Changes**
|
||||
* `SigningMethodHS256` is now `*SigningMethodHMAC` instead of `type struct`
|
||||
* `SigningMethodRS256` is now `*SigningMethodRSA` instead of `type struct`
|
||||
* `KeyFunc` now returns `interface{}` instead of `[]byte`
|
||||
* `SigningMethod.Sign` now takes `interface{}` instead of `[]byte` for the key
|
||||
* `SigningMethod.Verify` now takes `interface{}` instead of `[]byte` for the key
|
||||
* Renamed type `SigningMethodHS256` to `SigningMethodHMAC`. Specific sizes are now just instances of this type.
|
||||
* Added public package global `SigningMethodHS256`
|
||||
* Added public package global `SigningMethodHS384`
|
||||
* Added public package global `SigningMethodHS512`
|
||||
* Renamed type `SigningMethodRS256` to `SigningMethodRSA`. Specific sizes are now just instances of this type.
|
||||
* Added public package global `SigningMethodRS256`
|
||||
* Added public package global `SigningMethodRS384`
|
||||
* Added public package global `SigningMethodRS512`
|
||||
* Moved sample private key for HMAC tests from an inline value to a file on disk. Value is unchanged.
|
||||
* Refactored the RSA implementation to be easier to read
|
||||
* Exposed helper methods `ParseRSAPrivateKeyFromPEM` and `ParseRSAPublicKeyFromPEM`
|
||||
|
||||
#### 1.0.2
|
||||
|
||||
* Fixed bug in parsing public keys from certificates
|
||||
* Added more tests around the parsing of keys for RS256
|
||||
* Code refactoring in RS256 implementation. No functional changes
|
||||
|
||||
#### 1.0.1
|
||||
|
||||
* Fixed panic if RS256 signing method was passed an invalid key
|
||||
|
||||
#### 1.0.0
|
||||
|
||||
* First versioned release
|
||||
* API stabilized
|
||||
* Supports creating, signing, parsing, and validating JWT tokens
|
||||
* Supports RS256 and HS256 signing methods
|
||||
267
vendor/github.com/golang-jwt/jwt/v4/claims.go
generated
vendored
Normal file
267
vendor/github.com/golang-jwt/jwt/v4/claims.go
generated
vendored
Normal file
|
|
@ -0,0 +1,267 @@
|
|||
package jwt
|
||||
|
||||
import (
|
||||
"crypto/subtle"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Claims must just have a Valid method that determines
|
||||
// if the token is invalid for any supported reason
|
||||
type Claims interface {
|
||||
Valid() error
|
||||
}
|
||||
|
||||
// RegisteredClaims are a structured version of the JWT Claims Set,
|
||||
// restricted to Registered Claim Names, as referenced at
|
||||
// https://datatracker.ietf.org/doc/html/rfc7519#section-4.1
|
||||
//
|
||||
// This type can be used on its own, but then additional private and
|
||||
// public claims embedded in the JWT will not be parsed. The typical usecase
|
||||
// therefore is to embedded this in a user-defined claim type.
|
||||
//
|
||||
// See examples for how to use this with your own claim types.
|
||||
type RegisteredClaims struct {
|
||||
// the `iss` (Issuer) claim. See https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.1
|
||||
Issuer string `json:"iss,omitempty"`
|
||||
|
||||
// the `sub` (Subject) claim. See https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.2
|
||||
Subject string `json:"sub,omitempty"`
|
||||
|
||||
// the `aud` (Audience) claim. See https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.3
|
||||
Audience ClaimStrings `json:"aud,omitempty"`
|
||||
|
||||
// the `exp` (Expiration Time) claim. See https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.4
|
||||
ExpiresAt *NumericDate `json:"exp,omitempty"`
|
||||
|
||||
// the `nbf` (Not Before) claim. See https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.5
|
||||
NotBefore *NumericDate `json:"nbf,omitempty"`
|
||||
|
||||
// the `iat` (Issued At) claim. See https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.6
|
||||
IssuedAt *NumericDate `json:"iat,omitempty"`
|
||||
|
||||
// the `jti` (JWT ID) claim. See https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.7
|
||||
ID string `json:"jti,omitempty"`
|
||||
}
|
||||
|
||||
// Valid validates time based claims "exp, iat, nbf".
|
||||
// There is no accounting for clock skew.
|
||||
// As well, if any of the above claims are not in the token, it will still
|
||||
// be considered a valid claim.
|
||||
func (c RegisteredClaims) Valid() error {
|
||||
vErr := new(ValidationError)
|
||||
now := TimeFunc()
|
||||
|
||||
// The claims below are optional, by default, so if they are set to the
|
||||
// default value in Go, let's not fail the verification for them.
|
||||
if !c.VerifyExpiresAt(now, false) {
|
||||
delta := now.Sub(c.ExpiresAt.Time)
|
||||
vErr.Inner = fmt.Errorf("token is expired by %v", delta)
|
||||
vErr.Errors |= ValidationErrorExpired
|
||||
}
|
||||
|
||||
if !c.VerifyIssuedAt(now, false) {
|
||||
vErr.Inner = fmt.Errorf("token used before issued")
|
||||
vErr.Errors |= ValidationErrorIssuedAt
|
||||
}
|
||||
|
||||
if !c.VerifyNotBefore(now, false) {
|
||||
vErr.Inner = fmt.Errorf("token is not valid yet")
|
||||
vErr.Errors |= ValidationErrorNotValidYet
|
||||
}
|
||||
|
||||
if vErr.valid() {
|
||||
return nil
|
||||
}
|
||||
|
||||
return vErr
|
||||
}
|
||||
|
||||
// VerifyAudience compares the aud claim against cmp.
|
||||
// If required is false, this method will return true if the value matches or is unset
|
||||
func (c *RegisteredClaims) VerifyAudience(cmp string, req bool) bool {
|
||||
return verifyAud(c.Audience, cmp, req)
|
||||
}
|
||||
|
||||
// VerifyExpiresAt compares the exp claim against cmp (cmp <= exp).
|
||||
// If req is false, it will return true, if exp is unset.
|
||||
func (c *RegisteredClaims) VerifyExpiresAt(cmp time.Time, req bool) bool {
|
||||
if c.ExpiresAt == nil {
|
||||
return verifyExp(nil, cmp, req)
|
||||
}
|
||||
|
||||
return verifyExp(&c.ExpiresAt.Time, cmp, req)
|
||||
}
|
||||
|
||||
// VerifyIssuedAt compares the iat claim against cmp (cmp >= iat).
|
||||
// If req is false, it will return true, if iat is unset.
|
||||
func (c *RegisteredClaims) VerifyIssuedAt(cmp time.Time, req bool) bool {
|
||||
if c.IssuedAt == nil {
|
||||
return verifyIat(nil, cmp, req)
|
||||
}
|
||||
|
||||
return verifyIat(&c.IssuedAt.Time, cmp, req)
|
||||
}
|
||||
|
||||
// VerifyNotBefore compares the nbf claim against cmp (cmp >= nbf).
|
||||
// If req is false, it will return true, if nbf is unset.
|
||||
func (c *RegisteredClaims) VerifyNotBefore(cmp time.Time, req bool) bool {
|
||||
if c.NotBefore == nil {
|
||||
return verifyNbf(nil, cmp, req)
|
||||
}
|
||||
|
||||
return verifyNbf(&c.NotBefore.Time, cmp, req)
|
||||
}
|
||||
|
||||
// StandardClaims are a structured version of the JWT Claims Set, as referenced at
|
||||
// https://datatracker.ietf.org/doc/html/rfc7519#section-4. They do not follow the
|
||||
// specification exactly, since they were based on an earlier draft of the
|
||||
// specification and not updated. The main difference is that they only
|
||||
// support integer-based date fields and singular audiences. This might lead to
|
||||
// incompatibilities with other JWT implementations. The use of this is discouraged, instead
|
||||
// the newer RegisteredClaims struct should be used.
|
||||
//
|
||||
// Deprecated: Use RegisteredClaims instead for a forward-compatible way to access registered claims in a struct.
|
||||
type StandardClaims struct {
|
||||
Audience string `json:"aud,omitempty"`
|
||||
ExpiresAt int64 `json:"exp,omitempty"`
|
||||
Id string `json:"jti,omitempty"`
|
||||
IssuedAt int64 `json:"iat,omitempty"`
|
||||
Issuer string `json:"iss,omitempty"`
|
||||
NotBefore int64 `json:"nbf,omitempty"`
|
||||
Subject string `json:"sub,omitempty"`
|
||||
}
|
||||
|
||||
// Valid validates time based claims "exp, iat, nbf". There is no accounting for clock skew.
|
||||
// As well, if any of the above claims are not in the token, it will still
|
||||
// be considered a valid claim.
|
||||
func (c StandardClaims) Valid() error {
|
||||
vErr := new(ValidationError)
|
||||
now := TimeFunc().Unix()
|
||||
|
||||
// The claims below are optional, by default, so if they are set to the
|
||||
// default value in Go, let's not fail the verification for them.
|
||||
if !c.VerifyExpiresAt(now, false) {
|
||||
delta := time.Unix(now, 0).Sub(time.Unix(c.ExpiresAt, 0))
|
||||
vErr.Inner = fmt.Errorf("token is expired by %v", delta)
|
||||
vErr.Errors |= ValidationErrorExpired
|
||||
}
|
||||
|
||||
if !c.VerifyIssuedAt(now, false) {
|
||||
vErr.Inner = fmt.Errorf("token used before issued")
|
||||
vErr.Errors |= ValidationErrorIssuedAt
|
||||
}
|
||||
|
||||
if !c.VerifyNotBefore(now, false) {
|
||||
vErr.Inner = fmt.Errorf("token is not valid yet")
|
||||
vErr.Errors |= ValidationErrorNotValidYet
|
||||
}
|
||||
|
||||
if vErr.valid() {
|
||||
return nil
|
||||
}
|
||||
|
||||
return vErr
|
||||
}
|
||||
|
||||
// VerifyAudience compares the aud claim against cmp.
|
||||
// If required is false, this method will return true if the value matches or is unset
|
||||
func (c *StandardClaims) VerifyAudience(cmp string, req bool) bool {
|
||||
return verifyAud([]string{c.Audience}, cmp, req)
|
||||
}
|
||||
|
||||
// VerifyExpiresAt compares the exp claim against cmp (cmp <= exp).
|
||||
// If req is false, it will return true, if exp is unset.
|
||||
func (c *StandardClaims) VerifyExpiresAt(cmp int64, req bool) bool {
|
||||
if c.ExpiresAt == 0 {
|
||||
return verifyExp(nil, time.Unix(cmp, 0), req)
|
||||
}
|
||||
|
||||
t := time.Unix(c.ExpiresAt, 0)
|
||||
return verifyExp(&t, time.Unix(cmp, 0), req)
|
||||
}
|
||||
|
||||
// VerifyIssuedAt compares the iat claim against cmp (cmp >= iat).
|
||||
// If req is false, it will return true, if iat is unset.
|
||||
func (c *StandardClaims) VerifyIssuedAt(cmp int64, req bool) bool {
|
||||
if c.IssuedAt == 0 {
|
||||
return verifyIat(nil, time.Unix(cmp, 0), req)
|
||||
}
|
||||
|
||||
t := time.Unix(c.IssuedAt, 0)
|
||||
return verifyIat(&t, time.Unix(cmp, 0), req)
|
||||
}
|
||||
|
||||
// VerifyNotBefore compares the nbf claim against cmp (cmp >= nbf).
|
||||
// If req is false, it will return true, if nbf is unset.
|
||||
func (c *StandardClaims) VerifyNotBefore(cmp int64, req bool) bool {
|
||||
if c.NotBefore == 0 {
|
||||
return verifyNbf(nil, time.Unix(cmp, 0), req)
|
||||
}
|
||||
|
||||
t := time.Unix(c.NotBefore, 0)
|
||||
return verifyNbf(&t, time.Unix(cmp, 0), req)
|
||||
}
|
||||
|
||||
// VerifyIssuer compares the iss claim against cmp.
|
||||
// If required is false, this method will return true if the value matches or is unset
|
||||
func (c *StandardClaims) VerifyIssuer(cmp string, req bool) bool {
|
||||
return verifyIss(c.Issuer, cmp, req)
|
||||
}
|
||||
|
||||
// ----- helpers
|
||||
|
||||
func verifyAud(aud []string, cmp string, required bool) bool {
|
||||
if len(aud) == 0 {
|
||||
return !required
|
||||
}
|
||||
// use a var here to keep constant time compare when looping over a number of claims
|
||||
result := false
|
||||
|
||||
var stringClaims string
|
||||
for _, a := range aud {
|
||||
if subtle.ConstantTimeCompare([]byte(a), []byte(cmp)) != 0 {
|
||||
result = true
|
||||
}
|
||||
stringClaims = stringClaims + a
|
||||
}
|
||||
|
||||
// case where "" is sent in one or many aud claims
|
||||
if len(stringClaims) == 0 {
|
||||
return !required
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func verifyExp(exp *time.Time, now time.Time, required bool) bool {
|
||||
if exp == nil {
|
||||
return !required
|
||||
}
|
||||
return now.Before(*exp)
|
||||
}
|
||||
|
||||
func verifyIat(iat *time.Time, now time.Time, required bool) bool {
|
||||
if iat == nil {
|
||||
return !required
|
||||
}
|
||||
return now.After(*iat) || now.Equal(*iat)
|
||||
}
|
||||
|
||||
func verifyNbf(nbf *time.Time, now time.Time, required bool) bool {
|
||||
if nbf == nil {
|
||||
return !required
|
||||
}
|
||||
return now.After(*nbf) || now.Equal(*nbf)
|
||||
}
|
||||
|
||||
func verifyIss(iss string, cmp string, required bool) bool {
|
||||
if iss == "" {
|
||||
return !required
|
||||
}
|
||||
if subtle.ConstantTimeCompare([]byte(iss), []byte(cmp)) != 0 {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
4
vendor/github.com/golang-jwt/jwt/v4/doc.go
generated
vendored
Normal file
4
vendor/github.com/golang-jwt/jwt/v4/doc.go
generated
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
// Package jwt is a Go implementation of JSON Web Tokens: http://self-issued.info/docs/draft-jones-json-web-token.html
|
||||
//
|
||||
// See README.md for more info.
|
||||
package jwt
|
||||
142
vendor/github.com/golang-jwt/jwt/v4/ecdsa.go
generated
vendored
Normal file
142
vendor/github.com/golang-jwt/jwt/v4/ecdsa.go
generated
vendored
Normal file
|
|
@ -0,0 +1,142 @@
|
|||
package jwt
|
||||
|
||||
import (
|
||||
"crypto"
|
||||
"crypto/ecdsa"
|
||||
"crypto/rand"
|
||||
"errors"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
var (
|
||||
// Sadly this is missing from crypto/ecdsa compared to crypto/rsa
|
||||
ErrECDSAVerification = errors.New("crypto/ecdsa: verification error")
|
||||
)
|
||||
|
||||
// SigningMethodECDSA implements the ECDSA family of signing methods.
|
||||
// Expects *ecdsa.PrivateKey for signing and *ecdsa.PublicKey for verification
|
||||
type SigningMethodECDSA struct {
|
||||
Name string
|
||||
Hash crypto.Hash
|
||||
KeySize int
|
||||
CurveBits int
|
||||
}
|
||||
|
||||
// Specific instances for EC256 and company
|
||||
var (
|
||||
SigningMethodES256 *SigningMethodECDSA
|
||||
SigningMethodES384 *SigningMethodECDSA
|
||||
SigningMethodES512 *SigningMethodECDSA
|
||||
)
|
||||
|
||||
func init() {
|
||||
// ES256
|
||||
SigningMethodES256 = &SigningMethodECDSA{"ES256", crypto.SHA256, 32, 256}
|
||||
RegisterSigningMethod(SigningMethodES256.Alg(), func() SigningMethod {
|
||||
return SigningMethodES256
|
||||
})
|
||||
|
||||
// ES384
|
||||
SigningMethodES384 = &SigningMethodECDSA{"ES384", crypto.SHA384, 48, 384}
|
||||
RegisterSigningMethod(SigningMethodES384.Alg(), func() SigningMethod {
|
||||
return SigningMethodES384
|
||||
})
|
||||
|
||||
// ES512
|
||||
SigningMethodES512 = &SigningMethodECDSA{"ES512", crypto.SHA512, 66, 521}
|
||||
RegisterSigningMethod(SigningMethodES512.Alg(), func() SigningMethod {
|
||||
return SigningMethodES512
|
||||
})
|
||||
}
|
||||
|
||||
func (m *SigningMethodECDSA) Alg() string {
|
||||
return m.Name
|
||||
}
|
||||
|
||||
// Verify implements token verification for the SigningMethod.
|
||||
// For this verify method, key must be an ecdsa.PublicKey struct
|
||||
func (m *SigningMethodECDSA) Verify(signingString, signature string, key interface{}) error {
|
||||
var err error
|
||||
|
||||
// Decode the signature
|
||||
var sig []byte
|
||||
if sig, err = DecodeSegment(signature); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Get the key
|
||||
var ecdsaKey *ecdsa.PublicKey
|
||||
switch k := key.(type) {
|
||||
case *ecdsa.PublicKey:
|
||||
ecdsaKey = k
|
||||
default:
|
||||
return ErrInvalidKeyType
|
||||
}
|
||||
|
||||
if len(sig) != 2*m.KeySize {
|
||||
return ErrECDSAVerification
|
||||
}
|
||||
|
||||
r := big.NewInt(0).SetBytes(sig[:m.KeySize])
|
||||
s := big.NewInt(0).SetBytes(sig[m.KeySize:])
|
||||
|
||||
// Create hasher
|
||||
if !m.Hash.Available() {
|
||||
return ErrHashUnavailable
|
||||
}
|
||||
hasher := m.Hash.New()
|
||||
hasher.Write([]byte(signingString))
|
||||
|
||||
// Verify the signature
|
||||
if verifystatus := ecdsa.Verify(ecdsaKey, hasher.Sum(nil), r, s); verifystatus {
|
||||
return nil
|
||||
}
|
||||
|
||||
return ErrECDSAVerification
|
||||
}
|
||||
|
||||
// Sign implements token signing for the SigningMethod.
|
||||
// For this signing method, key must be an ecdsa.PrivateKey struct
|
||||
func (m *SigningMethodECDSA) Sign(signingString string, key interface{}) (string, error) {
|
||||
// Get the key
|
||||
var ecdsaKey *ecdsa.PrivateKey
|
||||
switch k := key.(type) {
|
||||
case *ecdsa.PrivateKey:
|
||||
ecdsaKey = k
|
||||
default:
|
||||
return "", ErrInvalidKeyType
|
||||
}
|
||||
|
||||
// Create the hasher
|
||||
if !m.Hash.Available() {
|
||||
return "", ErrHashUnavailable
|
||||
}
|
||||
|
||||
hasher := m.Hash.New()
|
||||
hasher.Write([]byte(signingString))
|
||||
|
||||
// Sign the string and return r, s
|
||||
if r, s, err := ecdsa.Sign(rand.Reader, ecdsaKey, hasher.Sum(nil)); err == nil {
|
||||
curveBits := ecdsaKey.Curve.Params().BitSize
|
||||
|
||||
if m.CurveBits != curveBits {
|
||||
return "", ErrInvalidKey
|
||||
}
|
||||
|
||||
keyBytes := curveBits / 8
|
||||
if curveBits%8 > 0 {
|
||||
keyBytes += 1
|
||||
}
|
||||
|
||||
// We serialize the outputs (r and s) into big-endian byte arrays
|
||||
// padded with zeros on the left to make sure the sizes work out.
|
||||
// Output must be 2*keyBytes long.
|
||||
out := make([]byte, 2*keyBytes)
|
||||
r.FillBytes(out[0:keyBytes]) // r is assigned to the first half of output.
|
||||
s.FillBytes(out[keyBytes:]) // s is assigned to the second half of output.
|
||||
|
||||
return EncodeSegment(out), nil
|
||||
} else {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
69
vendor/github.com/golang-jwt/jwt/v4/ecdsa_utils.go
generated
vendored
Normal file
69
vendor/github.com/golang-jwt/jwt/v4/ecdsa_utils.go
generated
vendored
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
package jwt
|
||||
|
||||
import (
|
||||
"crypto/ecdsa"
|
||||
"crypto/x509"
|
||||
"encoding/pem"
|
||||
"errors"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrNotECPublicKey = errors.New("key is not a valid ECDSA public key")
|
||||
ErrNotECPrivateKey = errors.New("key is not a valid ECDSA private key")
|
||||
)
|
||||
|
||||
// ParseECPrivateKeyFromPEM parses a PEM encoded Elliptic Curve Private Key Structure
|
||||
func ParseECPrivateKeyFromPEM(key []byte) (*ecdsa.PrivateKey, error) {
|
||||
var err error
|
||||
|
||||
// Parse PEM block
|
||||
var block *pem.Block
|
||||
if block, _ = pem.Decode(key); block == nil {
|
||||
return nil, ErrKeyMustBePEMEncoded
|
||||
}
|
||||
|
||||
// Parse the key
|
||||
var parsedKey interface{}
|
||||
if parsedKey, err = x509.ParseECPrivateKey(block.Bytes); err != nil {
|
||||
if parsedKey, err = x509.ParsePKCS8PrivateKey(block.Bytes); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
var pkey *ecdsa.PrivateKey
|
||||
var ok bool
|
||||
if pkey, ok = parsedKey.(*ecdsa.PrivateKey); !ok {
|
||||
return nil, ErrNotECPrivateKey
|
||||
}
|
||||
|
||||
return pkey, nil
|
||||
}
|
||||
|
||||
// ParseECPublicKeyFromPEM parses a PEM encoded PKCS1 or PKCS8 public key
|
||||
func ParseECPublicKeyFromPEM(key []byte) (*ecdsa.PublicKey, error) {
|
||||
var err error
|
||||
|
||||
// Parse PEM block
|
||||
var block *pem.Block
|
||||
if block, _ = pem.Decode(key); block == nil {
|
||||
return nil, ErrKeyMustBePEMEncoded
|
||||
}
|
||||
|
||||
// Parse the key
|
||||
var parsedKey interface{}
|
||||
if parsedKey, err = x509.ParsePKIXPublicKey(block.Bytes); err != nil {
|
||||
if cert, err := x509.ParseCertificate(block.Bytes); err == nil {
|
||||
parsedKey = cert.PublicKey
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
var pkey *ecdsa.PublicKey
|
||||
var ok bool
|
||||
if pkey, ok = parsedKey.(*ecdsa.PublicKey); !ok {
|
||||
return nil, ErrNotECPublicKey
|
||||
}
|
||||
|
||||
return pkey, nil
|
||||
}
|
||||
85
vendor/github.com/golang-jwt/jwt/v4/ed25519.go
generated
vendored
Normal file
85
vendor/github.com/golang-jwt/jwt/v4/ed25519.go
generated
vendored
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
package jwt
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"crypto"
|
||||
"crypto/ed25519"
|
||||
"crypto/rand"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrEd25519Verification = errors.New("ed25519: verification error")
|
||||
)
|
||||
|
||||
// SigningMethodEd25519 implements the EdDSA family.
|
||||
// Expects ed25519.PrivateKey for signing and ed25519.PublicKey for verification
|
||||
type SigningMethodEd25519 struct{}
|
||||
|
||||
// Specific instance for EdDSA
|
||||
var (
|
||||
SigningMethodEdDSA *SigningMethodEd25519
|
||||
)
|
||||
|
||||
func init() {
|
||||
SigningMethodEdDSA = &SigningMethodEd25519{}
|
||||
RegisterSigningMethod(SigningMethodEdDSA.Alg(), func() SigningMethod {
|
||||
return SigningMethodEdDSA
|
||||
})
|
||||
}
|
||||
|
||||
func (m *SigningMethodEd25519) Alg() string {
|
||||
return "EdDSA"
|
||||
}
|
||||
|
||||
// Verify implements token verification for the SigningMethod.
|
||||
// For this verify method, key must be an ed25519.PublicKey
|
||||
func (m *SigningMethodEd25519) Verify(signingString, signature string, key interface{}) error {
|
||||
var err error
|
||||
var ed25519Key ed25519.PublicKey
|
||||
var ok bool
|
||||
|
||||
if ed25519Key, ok = key.(ed25519.PublicKey); !ok {
|
||||
return ErrInvalidKeyType
|
||||
}
|
||||
|
||||
if len(ed25519Key) != ed25519.PublicKeySize {
|
||||
return ErrInvalidKey
|
||||
}
|
||||
|
||||
// Decode the signature
|
||||
var sig []byte
|
||||
if sig, err = DecodeSegment(signature); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Verify the signature
|
||||
if !ed25519.Verify(ed25519Key, []byte(signingString), sig) {
|
||||
return ErrEd25519Verification
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Sign implements token signing for the SigningMethod.
|
||||
// For this signing method, key must be an ed25519.PrivateKey
|
||||
func (m *SigningMethodEd25519) Sign(signingString string, key interface{}) (string, error) {
|
||||
var ed25519Key crypto.Signer
|
||||
var ok bool
|
||||
|
||||
if ed25519Key, ok = key.(crypto.Signer); !ok {
|
||||
return "", ErrInvalidKeyType
|
||||
}
|
||||
|
||||
if _, ok := ed25519Key.Public().(ed25519.PublicKey); !ok {
|
||||
return "", ErrInvalidKey
|
||||
}
|
||||
|
||||
// Sign the string and return the encoded result
|
||||
// ed25519 performs a two-pass hash as part of its algorithm. Therefore, we need to pass a non-prehashed message into the Sign function, as indicated by crypto.Hash(0)
|
||||
sig, err := ed25519Key.Sign(rand.Reader, []byte(signingString), crypto.Hash(0))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return EncodeSegment(sig), nil
|
||||
}
|
||||
64
vendor/github.com/golang-jwt/jwt/v4/ed25519_utils.go
generated
vendored
Normal file
64
vendor/github.com/golang-jwt/jwt/v4/ed25519_utils.go
generated
vendored
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
package jwt
|
||||
|
||||
import (
|
||||
"crypto"
|
||||
"crypto/ed25519"
|
||||
"crypto/x509"
|
||||
"encoding/pem"
|
||||
"errors"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrNotEdPrivateKey = errors.New("key is not a valid Ed25519 private key")
|
||||
ErrNotEdPublicKey = errors.New("key is not a valid Ed25519 public key")
|
||||
)
|
||||
|
||||
// ParseEdPrivateKeyFromPEM parses a PEM-encoded Edwards curve private key
|
||||
func ParseEdPrivateKeyFromPEM(key []byte) (crypto.PrivateKey, error) {
|
||||
var err error
|
||||
|
||||
// Parse PEM block
|
||||
var block *pem.Block
|
||||
if block, _ = pem.Decode(key); block == nil {
|
||||
return nil, ErrKeyMustBePEMEncoded
|
||||
}
|
||||
|
||||
// Parse the key
|
||||
var parsedKey interface{}
|
||||
if parsedKey, err = x509.ParsePKCS8PrivateKey(block.Bytes); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var pkey ed25519.PrivateKey
|
||||
var ok bool
|
||||
if pkey, ok = parsedKey.(ed25519.PrivateKey); !ok {
|
||||
return nil, ErrNotEdPrivateKey
|
||||
}
|
||||
|
||||
return pkey, nil
|
||||
}
|
||||
|
||||
// ParseEdPublicKeyFromPEM parses a PEM-encoded Edwards curve public key
|
||||
func ParseEdPublicKeyFromPEM(key []byte) (crypto.PublicKey, error) {
|
||||
var err error
|
||||
|
||||
// Parse PEM block
|
||||
var block *pem.Block
|
||||
if block, _ = pem.Decode(key); block == nil {
|
||||
return nil, ErrKeyMustBePEMEncoded
|
||||
}
|
||||
|
||||
// Parse the key
|
||||
var parsedKey interface{}
|
||||
if parsedKey, err = x509.ParsePKIXPublicKey(block.Bytes); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var pkey ed25519.PublicKey
|
||||
var ok bool
|
||||
if pkey, ok = parsedKey.(ed25519.PublicKey); !ok {
|
||||
return nil, ErrNotEdPublicKey
|
||||
}
|
||||
|
||||
return pkey, nil
|
||||
}
|
||||
59
vendor/github.com/golang-jwt/jwt/v4/errors.go
generated
vendored
Normal file
59
vendor/github.com/golang-jwt/jwt/v4/errors.go
generated
vendored
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
package jwt
|
||||
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
// Error constants
|
||||
var (
|
||||
ErrInvalidKey = errors.New("key is invalid")
|
||||
ErrInvalidKeyType = errors.New("key is of invalid type")
|
||||
ErrHashUnavailable = errors.New("the requested hash function is unavailable")
|
||||
)
|
||||
|
||||
// The errors that might occur when parsing and validating a token
|
||||
const (
|
||||
ValidationErrorMalformed uint32 = 1 << iota // Token is malformed
|
||||
ValidationErrorUnverifiable // Token could not be verified because of signing problems
|
||||
ValidationErrorSignatureInvalid // Signature validation failed
|
||||
|
||||
// Standard Claim validation errors
|
||||
ValidationErrorAudience // AUD validation failed
|
||||
ValidationErrorExpired // EXP validation failed
|
||||
ValidationErrorIssuedAt // IAT validation failed
|
||||
ValidationErrorIssuer // ISS validation failed
|
||||
ValidationErrorNotValidYet // NBF validation failed
|
||||
ValidationErrorId // JTI validation failed
|
||||
ValidationErrorClaimsInvalid // Generic claims validation error
|
||||
)
|
||||
|
||||
// NewValidationError is a helper for constructing a ValidationError with a string error message
|
||||
func NewValidationError(errorText string, errorFlags uint32) *ValidationError {
|
||||
return &ValidationError{
|
||||
text: errorText,
|
||||
Errors: errorFlags,
|
||||
}
|
||||
}
|
||||
|
||||
// ValidationError represents an error from Parse if token is not valid
|
||||
type ValidationError struct {
|
||||
Inner error // stores the error returned by external dependencies, i.e.: KeyFunc
|
||||
Errors uint32 // bitfield. see ValidationError... constants
|
||||
text string // errors that do not have a valid error just have text
|
||||
}
|
||||
|
||||
// Error is the implementation of the err interface.
|
||||
func (e ValidationError) Error() string {
|
||||
if e.Inner != nil {
|
||||
return e.Inner.Error()
|
||||
} else if e.text != "" {
|
||||
return e.text
|
||||
} else {
|
||||
return "token is invalid"
|
||||
}
|
||||
}
|
||||
|
||||
// No errors
|
||||
func (e *ValidationError) valid() bool {
|
||||
return e.Errors == 0
|
||||
}
|
||||
3
vendor/github.com/golang-jwt/jwt/v4/go.mod
generated
vendored
Normal file
3
vendor/github.com/golang-jwt/jwt/v4/go.mod
generated
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
module github.com/golang-jwt/jwt/v4
|
||||
|
||||
go 1.15
|
||||
0
vendor/github.com/golang-jwt/jwt/v4/go.sum
generated
vendored
Normal file
0
vendor/github.com/golang-jwt/jwt/v4/go.sum
generated
vendored
Normal file
95
vendor/github.com/golang-jwt/jwt/v4/hmac.go
generated
vendored
Normal file
95
vendor/github.com/golang-jwt/jwt/v4/hmac.go
generated
vendored
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
package jwt
|
||||
|
||||
import (
|
||||
"crypto"
|
||||
"crypto/hmac"
|
||||
"errors"
|
||||
)
|
||||
|
||||
// SigningMethodHMAC implements the HMAC-SHA family of signing methods.
|
||||
// Expects key type of []byte for both signing and validation
|
||||
type SigningMethodHMAC struct {
|
||||
Name string
|
||||
Hash crypto.Hash
|
||||
}
|
||||
|
||||
// Specific instances for HS256 and company
|
||||
var (
|
||||
SigningMethodHS256 *SigningMethodHMAC
|
||||
SigningMethodHS384 *SigningMethodHMAC
|
||||
SigningMethodHS512 *SigningMethodHMAC
|
||||
ErrSignatureInvalid = errors.New("signature is invalid")
|
||||
)
|
||||
|
||||
func init() {
|
||||
// HS256
|
||||
SigningMethodHS256 = &SigningMethodHMAC{"HS256", crypto.SHA256}
|
||||
RegisterSigningMethod(SigningMethodHS256.Alg(), func() SigningMethod {
|
||||
return SigningMethodHS256
|
||||
})
|
||||
|
||||
// HS384
|
||||
SigningMethodHS384 = &SigningMethodHMAC{"HS384", crypto.SHA384}
|
||||
RegisterSigningMethod(SigningMethodHS384.Alg(), func() SigningMethod {
|
||||
return SigningMethodHS384
|
||||
})
|
||||
|
||||
// HS512
|
||||
SigningMethodHS512 = &SigningMethodHMAC{"HS512", crypto.SHA512}
|
||||
RegisterSigningMethod(SigningMethodHS512.Alg(), func() SigningMethod {
|
||||
return SigningMethodHS512
|
||||
})
|
||||
}
|
||||
|
||||
func (m *SigningMethodHMAC) Alg() string {
|
||||
return m.Name
|
||||
}
|
||||
|
||||
// Verify implements token verification for the SigningMethod. Returns nil if the signature is valid.
|
||||
func (m *SigningMethodHMAC) Verify(signingString, signature string, key interface{}) error {
|
||||
// Verify the key is the right type
|
||||
keyBytes, ok := key.([]byte)
|
||||
if !ok {
|
||||
return ErrInvalidKeyType
|
||||
}
|
||||
|
||||
// Decode signature, for comparison
|
||||
sig, err := DecodeSegment(signature)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Can we use the specified hashing method?
|
||||
if !m.Hash.Available() {
|
||||
return ErrHashUnavailable
|
||||
}
|
||||
|
||||
// This signing method is symmetric, so we validate the signature
|
||||
// by reproducing the signature from the signing string and key, then
|
||||
// comparing that against the provided signature.
|
||||
hasher := hmac.New(m.Hash.New, keyBytes)
|
||||
hasher.Write([]byte(signingString))
|
||||
if !hmac.Equal(sig, hasher.Sum(nil)) {
|
||||
return ErrSignatureInvalid
|
||||
}
|
||||
|
||||
// No validation errors. Signature is good.
|
||||
return nil
|
||||
}
|
||||
|
||||
// Sign implements token signing for the SigningMethod.
|
||||
// Key must be []byte
|
||||
func (m *SigningMethodHMAC) Sign(signingString string, key interface{}) (string, error) {
|
||||
if keyBytes, ok := key.([]byte); ok {
|
||||
if !m.Hash.Available() {
|
||||
return "", ErrHashUnavailable
|
||||
}
|
||||
|
||||
hasher := hmac.New(m.Hash.New, keyBytes)
|
||||
hasher.Write([]byte(signingString))
|
||||
|
||||
return EncodeSegment(hasher.Sum(nil)), nil
|
||||
}
|
||||
|
||||
return "", ErrInvalidKeyType
|
||||
}
|
||||
148
vendor/github.com/golang-jwt/jwt/v4/map_claims.go
generated
vendored
Normal file
148
vendor/github.com/golang-jwt/jwt/v4/map_claims.go
generated
vendored
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
package jwt
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"time"
|
||||
// "fmt"
|
||||
)
|
||||
|
||||
// MapClaims is a claims type that uses the map[string]interface{} for JSON decoding.
|
||||
// This is the default claims type if you don't supply one
|
||||
type MapClaims map[string]interface{}
|
||||
|
||||
// VerifyAudience Compares the aud claim against cmp.
|
||||
// If required is false, this method will return true if the value matches or is unset
|
||||
func (m MapClaims) VerifyAudience(cmp string, req bool) bool {
|
||||
var aud []string
|
||||
switch v := m["aud"].(type) {
|
||||
case string:
|
||||
aud = append(aud, v)
|
||||
case []string:
|
||||
aud = v
|
||||
case []interface{}:
|
||||
for _, a := range v {
|
||||
vs, ok := a.(string)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
aud = append(aud, vs)
|
||||
}
|
||||
}
|
||||
return verifyAud(aud, cmp, req)
|
||||
}
|
||||
|
||||
// VerifyExpiresAt compares the exp claim against cmp (cmp <= exp).
|
||||
// If req is false, it will return true, if exp is unset.
|
||||
func (m MapClaims) VerifyExpiresAt(cmp int64, req bool) bool {
|
||||
cmpTime := time.Unix(cmp, 0)
|
||||
|
||||
v, ok := m["exp"]
|
||||
if !ok {
|
||||
return !req
|
||||
}
|
||||
|
||||
switch exp := v.(type) {
|
||||
case float64:
|
||||
if exp == 0 {
|
||||
return verifyExp(nil, cmpTime, req)
|
||||
}
|
||||
|
||||
return verifyExp(&newNumericDateFromSeconds(exp).Time, cmpTime, req)
|
||||
case json.Number:
|
||||
v, _ := exp.Float64()
|
||||
|
||||
return verifyExp(&newNumericDateFromSeconds(v).Time, cmpTime, req)
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// VerifyIssuedAt compares the exp claim against cmp (cmp >= iat).
|
||||
// If req is false, it will return true, if iat is unset.
|
||||
func (m MapClaims) VerifyIssuedAt(cmp int64, req bool) bool {
|
||||
cmpTime := time.Unix(cmp, 0)
|
||||
|
||||
v, ok := m["iat"]
|
||||
if !ok {
|
||||
return !req
|
||||
}
|
||||
|
||||
switch iat := v.(type) {
|
||||
case float64:
|
||||
if iat == 0 {
|
||||
return verifyIat(nil, cmpTime, req)
|
||||
}
|
||||
|
||||
return verifyIat(&newNumericDateFromSeconds(iat).Time, cmpTime, req)
|
||||
case json.Number:
|
||||
v, _ := iat.Float64()
|
||||
|
||||
return verifyIat(&newNumericDateFromSeconds(v).Time, cmpTime, req)
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// VerifyNotBefore compares the nbf claim against cmp (cmp >= nbf).
|
||||
// If req is false, it will return true, if nbf is unset.
|
||||
func (m MapClaims) VerifyNotBefore(cmp int64, req bool) bool {
|
||||
cmpTime := time.Unix(cmp, 0)
|
||||
|
||||
v, ok := m["nbf"]
|
||||
if !ok {
|
||||
return !req
|
||||
}
|
||||
|
||||
switch nbf := v.(type) {
|
||||
case float64:
|
||||
if nbf == 0 {
|
||||
return verifyNbf(nil, cmpTime, req)
|
||||
}
|
||||
|
||||
return verifyNbf(&newNumericDateFromSeconds(nbf).Time, cmpTime, req)
|
||||
case json.Number:
|
||||
v, _ := nbf.Float64()
|
||||
|
||||
return verifyNbf(&newNumericDateFromSeconds(v).Time, cmpTime, req)
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// VerifyIssuer compares the iss claim against cmp.
|
||||
// If required is false, this method will return true if the value matches or is unset
|
||||
func (m MapClaims) VerifyIssuer(cmp string, req bool) bool {
|
||||
iss, _ := m["iss"].(string)
|
||||
return verifyIss(iss, cmp, req)
|
||||
}
|
||||
|
||||
// Valid validates time based claims "exp, iat, nbf".
|
||||
// There is no accounting for clock skew.
|
||||
// As well, if any of the above claims are not in the token, it will still
|
||||
// be considered a valid claim.
|
||||
func (m MapClaims) Valid() error {
|
||||
vErr := new(ValidationError)
|
||||
now := TimeFunc().Unix()
|
||||
|
||||
if !m.VerifyExpiresAt(now, false) {
|
||||
vErr.Inner = errors.New("Token is expired")
|
||||
vErr.Errors |= ValidationErrorExpired
|
||||
}
|
||||
|
||||
if !m.VerifyIssuedAt(now, false) {
|
||||
vErr.Inner = errors.New("Token used before issued")
|
||||
vErr.Errors |= ValidationErrorIssuedAt
|
||||
}
|
||||
|
||||
if !m.VerifyNotBefore(now, false) {
|
||||
vErr.Inner = errors.New("Token is not valid yet")
|
||||
vErr.Errors |= ValidationErrorNotValidYet
|
||||
}
|
||||
|
||||
if vErr.valid() {
|
||||
return nil
|
||||
}
|
||||
|
||||
return vErr
|
||||
}
|
||||
52
vendor/github.com/golang-jwt/jwt/v4/none.go
generated
vendored
Normal file
52
vendor/github.com/golang-jwt/jwt/v4/none.go
generated
vendored
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
package jwt
|
||||
|
||||
// SigningMethodNone implements the none signing method. This is required by the spec
|
||||
// but you probably should never use it.
|
||||
var SigningMethodNone *signingMethodNone
|
||||
|
||||
const UnsafeAllowNoneSignatureType unsafeNoneMagicConstant = "none signing method allowed"
|
||||
|
||||
var NoneSignatureTypeDisallowedError error
|
||||
|
||||
type signingMethodNone struct{}
|
||||
type unsafeNoneMagicConstant string
|
||||
|
||||
func init() {
|
||||
SigningMethodNone = &signingMethodNone{}
|
||||
NoneSignatureTypeDisallowedError = NewValidationError("'none' signature type is not allowed", ValidationErrorSignatureInvalid)
|
||||
|
||||
RegisterSigningMethod(SigningMethodNone.Alg(), func() SigningMethod {
|
||||
return SigningMethodNone
|
||||
})
|
||||
}
|
||||
|
||||
func (m *signingMethodNone) Alg() string {
|
||||
return "none"
|
||||
}
|
||||
|
||||
// Only allow 'none' alg type if UnsafeAllowNoneSignatureType is specified as the key
|
||||
func (m *signingMethodNone) Verify(signingString, signature string, key interface{}) (err error) {
|
||||
// Key must be UnsafeAllowNoneSignatureType to prevent accidentally
|
||||
// accepting 'none' signing method
|
||||
if _, ok := key.(unsafeNoneMagicConstant); !ok {
|
||||
return NoneSignatureTypeDisallowedError
|
||||
}
|
||||
// If signing method is none, signature must be an empty string
|
||||
if signature != "" {
|
||||
return NewValidationError(
|
||||
"'none' signing method with non-empty signature",
|
||||
ValidationErrorSignatureInvalid,
|
||||
)
|
||||
}
|
||||
|
||||
// Accept 'none' signing method.
|
||||
return nil
|
||||
}
|
||||
|
||||
// Only allow 'none' signing if UnsafeAllowNoneSignatureType is specified as the key
|
||||
func (m *signingMethodNone) Sign(signingString string, key interface{}) (string, error) {
|
||||
if _, ok := key.(unsafeNoneMagicConstant); ok {
|
||||
return "", nil
|
||||
}
|
||||
return "", NoneSignatureTypeDisallowedError
|
||||
}
|
||||
148
vendor/github.com/golang-jwt/jwt/v4/parser.go
generated
vendored
Normal file
148
vendor/github.com/golang-jwt/jwt/v4/parser.go
generated
vendored
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
package jwt
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Parser struct {
|
||||
ValidMethods []string // If populated, only these methods will be considered valid
|
||||
UseJSONNumber bool // Use JSON Number format in JSON decoder
|
||||
SkipClaimsValidation bool // Skip claims validation during token parsing
|
||||
}
|
||||
|
||||
// Parse parses, validates, and returns a token.
|
||||
// keyFunc will receive the parsed token and should return the key for validating.
|
||||
// If everything is kosher, err will be nil
|
||||
func (p *Parser) Parse(tokenString string, keyFunc Keyfunc) (*Token, error) {
|
||||
return p.ParseWithClaims(tokenString, MapClaims{}, keyFunc)
|
||||
}
|
||||
|
||||
func (p *Parser) ParseWithClaims(tokenString string, claims Claims, keyFunc Keyfunc) (*Token, error) {
|
||||
token, parts, err := p.ParseUnverified(tokenString, claims)
|
||||
if err != nil {
|
||||
return token, err
|
||||
}
|
||||
|
||||
// Verify signing method is in the required set
|
||||
if p.ValidMethods != nil {
|
||||
var signingMethodValid = false
|
||||
var alg = token.Method.Alg()
|
||||
for _, m := range p.ValidMethods {
|
||||
if m == alg {
|
||||
signingMethodValid = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !signingMethodValid {
|
||||
// signing method is not in the listed set
|
||||
return token, NewValidationError(fmt.Sprintf("signing method %v is invalid", alg), ValidationErrorSignatureInvalid)
|
||||
}
|
||||
}
|
||||
|
||||
// Lookup key
|
||||
var key interface{}
|
||||
if keyFunc == nil {
|
||||
// keyFunc was not provided. short circuiting validation
|
||||
return token, NewValidationError("no Keyfunc was provided.", ValidationErrorUnverifiable)
|
||||
}
|
||||
if key, err = keyFunc(token); err != nil {
|
||||
// keyFunc returned an error
|
||||
if ve, ok := err.(*ValidationError); ok {
|
||||
return token, ve
|
||||
}
|
||||
return token, &ValidationError{Inner: err, Errors: ValidationErrorUnverifiable}
|
||||
}
|
||||
|
||||
vErr := &ValidationError{}
|
||||
|
||||
// Validate Claims
|
||||
if !p.SkipClaimsValidation {
|
||||
if err := token.Claims.Valid(); err != nil {
|
||||
|
||||
// If the Claims Valid returned an error, check if it is a validation error,
|
||||
// If it was another error type, create a ValidationError with a generic ClaimsInvalid flag set
|
||||
if e, ok := err.(*ValidationError); !ok {
|
||||
vErr = &ValidationError{Inner: err, Errors: ValidationErrorClaimsInvalid}
|
||||
} else {
|
||||
vErr = e
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Perform validation
|
||||
token.Signature = parts[2]
|
||||
if err = token.Method.Verify(strings.Join(parts[0:2], "."), token.Signature, key); err != nil {
|
||||
vErr.Inner = err
|
||||
vErr.Errors |= ValidationErrorSignatureInvalid
|
||||
}
|
||||
|
||||
if vErr.valid() {
|
||||
token.Valid = true
|
||||
return token, nil
|
||||
}
|
||||
|
||||
return token, vErr
|
||||
}
|
||||
|
||||
// ParseUnverified parses the token but doesn't validate the signature.
|
||||
//
|
||||
// WARNING: Don't use this method unless you know what you're doing.
|
||||
//
|
||||
// It's only ever useful in cases where you know the signature is valid (because it has
|
||||
// been checked previously in the stack) and you want to extract values from it.
|
||||
func (p *Parser) ParseUnverified(tokenString string, claims Claims) (token *Token, parts []string, err error) {
|
||||
parts = strings.Split(tokenString, ".")
|
||||
if len(parts) != 3 {
|
||||
return nil, parts, NewValidationError("token contains an invalid number of segments", ValidationErrorMalformed)
|
||||
}
|
||||
|
||||
token = &Token{Raw: tokenString}
|
||||
|
||||
// parse Header
|
||||
var headerBytes []byte
|
||||
if headerBytes, err = DecodeSegment(parts[0]); err != nil {
|
||||
if strings.HasPrefix(strings.ToLower(tokenString), "bearer ") {
|
||||
return token, parts, NewValidationError("tokenstring should not contain 'bearer '", ValidationErrorMalformed)
|
||||
}
|
||||
return token, parts, &ValidationError{Inner: err, Errors: ValidationErrorMalformed}
|
||||
}
|
||||
if err = json.Unmarshal(headerBytes, &token.Header); err != nil {
|
||||
return token, parts, &ValidationError{Inner: err, Errors: ValidationErrorMalformed}
|
||||
}
|
||||
|
||||
// parse Claims
|
||||
var claimBytes []byte
|
||||
token.Claims = claims
|
||||
|
||||
if claimBytes, err = DecodeSegment(parts[1]); err != nil {
|
||||
return token, parts, &ValidationError{Inner: err, Errors: ValidationErrorMalformed}
|
||||
}
|
||||
dec := json.NewDecoder(bytes.NewBuffer(claimBytes))
|
||||
if p.UseJSONNumber {
|
||||
dec.UseNumber()
|
||||
}
|
||||
// JSON Decode. Special case for map type to avoid weird pointer behavior
|
||||
if c, ok := token.Claims.(MapClaims); ok {
|
||||
err = dec.Decode(&c)
|
||||
} else {
|
||||
err = dec.Decode(&claims)
|
||||
}
|
||||
// Handle decode error
|
||||
if err != nil {
|
||||
return token, parts, &ValidationError{Inner: err, Errors: ValidationErrorMalformed}
|
||||
}
|
||||
|
||||
// Lookup signature method
|
||||
if method, ok := token.Header["alg"].(string); ok {
|
||||
if token.Method = GetSigningMethod(method); token.Method == nil {
|
||||
return token, parts, NewValidationError("signing method (alg) is unavailable.", ValidationErrorUnverifiable)
|
||||
}
|
||||
} else {
|
||||
return token, parts, NewValidationError("signing method (alg) is unspecified.", ValidationErrorUnverifiable)
|
||||
}
|
||||
|
||||
return token, parts, nil
|
||||
}
|
||||
101
vendor/github.com/golang-jwt/jwt/v4/rsa.go
generated
vendored
Normal file
101
vendor/github.com/golang-jwt/jwt/v4/rsa.go
generated
vendored
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
package jwt
|
||||
|
||||
import (
|
||||
"crypto"
|
||||
"crypto/rand"
|
||||
"crypto/rsa"
|
||||
)
|
||||
|
||||
// SigningMethodRSA implements the RSA family of signing methods.
|
||||
// Expects *rsa.PrivateKey for signing and *rsa.PublicKey for validation
|
||||
type SigningMethodRSA struct {
|
||||
Name string
|
||||
Hash crypto.Hash
|
||||
}
|
||||
|
||||
// Specific instances for RS256 and company
|
||||
var (
|
||||
SigningMethodRS256 *SigningMethodRSA
|
||||
SigningMethodRS384 *SigningMethodRSA
|
||||
SigningMethodRS512 *SigningMethodRSA
|
||||
)
|
||||
|
||||
func init() {
|
||||
// RS256
|
||||
SigningMethodRS256 = &SigningMethodRSA{"RS256", crypto.SHA256}
|
||||
RegisterSigningMethod(SigningMethodRS256.Alg(), func() SigningMethod {
|
||||
return SigningMethodRS256
|
||||
})
|
||||
|
||||
// RS384
|
||||
SigningMethodRS384 = &SigningMethodRSA{"RS384", crypto.SHA384}
|
||||
RegisterSigningMethod(SigningMethodRS384.Alg(), func() SigningMethod {
|
||||
return SigningMethodRS384
|
||||
})
|
||||
|
||||
// RS512
|
||||
SigningMethodRS512 = &SigningMethodRSA{"RS512", crypto.SHA512}
|
||||
RegisterSigningMethod(SigningMethodRS512.Alg(), func() SigningMethod {
|
||||
return SigningMethodRS512
|
||||
})
|
||||
}
|
||||
|
||||
func (m *SigningMethodRSA) Alg() string {
|
||||
return m.Name
|
||||
}
|
||||
|
||||
// Verify implements token verification for the SigningMethod
|
||||
// For this signing method, must be an *rsa.PublicKey structure.
|
||||
func (m *SigningMethodRSA) Verify(signingString, signature string, key interface{}) error {
|
||||
var err error
|
||||
|
||||
// Decode the signature
|
||||
var sig []byte
|
||||
if sig, err = DecodeSegment(signature); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var rsaKey *rsa.PublicKey
|
||||
var ok bool
|
||||
|
||||
if rsaKey, ok = key.(*rsa.PublicKey); !ok {
|
||||
return ErrInvalidKeyType
|
||||
}
|
||||
|
||||
// Create hasher
|
||||
if !m.Hash.Available() {
|
||||
return ErrHashUnavailable
|
||||
}
|
||||
hasher := m.Hash.New()
|
||||
hasher.Write([]byte(signingString))
|
||||
|
||||
// Verify the signature
|
||||
return rsa.VerifyPKCS1v15(rsaKey, m.Hash, hasher.Sum(nil), sig)
|
||||
}
|
||||
|
||||
// Sign implements token signing for the SigningMethod
|
||||
// For this signing method, must be an *rsa.PrivateKey structure.
|
||||
func (m *SigningMethodRSA) Sign(signingString string, key interface{}) (string, error) {
|
||||
var rsaKey *rsa.PrivateKey
|
||||
var ok bool
|
||||
|
||||
// Validate type of key
|
||||
if rsaKey, ok = key.(*rsa.PrivateKey); !ok {
|
||||
return "", ErrInvalidKey
|
||||
}
|
||||
|
||||
// Create the hasher
|
||||
if !m.Hash.Available() {
|
||||
return "", ErrHashUnavailable
|
||||
}
|
||||
|
||||
hasher := m.Hash.New()
|
||||
hasher.Write([]byte(signingString))
|
||||
|
||||
// Sign the string and return the encoded bytes
|
||||
if sigBytes, err := rsa.SignPKCS1v15(rand.Reader, rsaKey, m.Hash, hasher.Sum(nil)); err == nil {
|
||||
return EncodeSegment(sigBytes), nil
|
||||
} else {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
142
vendor/github.com/golang-jwt/jwt/v4/rsa_pss.go
generated
vendored
Normal file
142
vendor/github.com/golang-jwt/jwt/v4/rsa_pss.go
generated
vendored
Normal file
|
|
@ -0,0 +1,142 @@
|
|||
// +build go1.4
|
||||
|
||||
package jwt
|
||||
|
||||
import (
|
||||
"crypto"
|
||||
"crypto/rand"
|
||||
"crypto/rsa"
|
||||
)
|
||||
|
||||
// SigningMethodRSAPSS implements the RSAPSS family of signing methods signing methods
|
||||
type SigningMethodRSAPSS struct {
|
||||
*SigningMethodRSA
|
||||
Options *rsa.PSSOptions
|
||||
// VerifyOptions is optional. If set overrides Options for rsa.VerifyPPS.
|
||||
// Used to accept tokens signed with rsa.PSSSaltLengthAuto, what doesn't follow
|
||||
// https://tools.ietf.org/html/rfc7518#section-3.5 but was used previously.
|
||||
// See https://github.com/dgrijalva/jwt-go/issues/285#issuecomment-437451244 for details.
|
||||
VerifyOptions *rsa.PSSOptions
|
||||
}
|
||||
|
||||
// Specific instances for RS/PS and company.
|
||||
var (
|
||||
SigningMethodPS256 *SigningMethodRSAPSS
|
||||
SigningMethodPS384 *SigningMethodRSAPSS
|
||||
SigningMethodPS512 *SigningMethodRSAPSS
|
||||
)
|
||||
|
||||
func init() {
|
||||
// PS256
|
||||
SigningMethodPS256 = &SigningMethodRSAPSS{
|
||||
SigningMethodRSA: &SigningMethodRSA{
|
||||
Name: "PS256",
|
||||
Hash: crypto.SHA256,
|
||||
},
|
||||
Options: &rsa.PSSOptions{
|
||||
SaltLength: rsa.PSSSaltLengthEqualsHash,
|
||||
},
|
||||
VerifyOptions: &rsa.PSSOptions{
|
||||
SaltLength: rsa.PSSSaltLengthAuto,
|
||||
},
|
||||
}
|
||||
RegisterSigningMethod(SigningMethodPS256.Alg(), func() SigningMethod {
|
||||
return SigningMethodPS256
|
||||
})
|
||||
|
||||
// PS384
|
||||
SigningMethodPS384 = &SigningMethodRSAPSS{
|
||||
SigningMethodRSA: &SigningMethodRSA{
|
||||
Name: "PS384",
|
||||
Hash: crypto.SHA384,
|
||||
},
|
||||
Options: &rsa.PSSOptions{
|
||||
SaltLength: rsa.PSSSaltLengthEqualsHash,
|
||||
},
|
||||
VerifyOptions: &rsa.PSSOptions{
|
||||
SaltLength: rsa.PSSSaltLengthAuto,
|
||||
},
|
||||
}
|
||||
RegisterSigningMethod(SigningMethodPS384.Alg(), func() SigningMethod {
|
||||
return SigningMethodPS384
|
||||
})
|
||||
|
||||
// PS512
|
||||
SigningMethodPS512 = &SigningMethodRSAPSS{
|
||||
SigningMethodRSA: &SigningMethodRSA{
|
||||
Name: "PS512",
|
||||
Hash: crypto.SHA512,
|
||||
},
|
||||
Options: &rsa.PSSOptions{
|
||||
SaltLength: rsa.PSSSaltLengthEqualsHash,
|
||||
},
|
||||
VerifyOptions: &rsa.PSSOptions{
|
||||
SaltLength: rsa.PSSSaltLengthAuto,
|
||||
},
|
||||
}
|
||||
RegisterSigningMethod(SigningMethodPS512.Alg(), func() SigningMethod {
|
||||
return SigningMethodPS512
|
||||
})
|
||||
}
|
||||
|
||||
// Verify implements token verification for the SigningMethod.
|
||||
// For this verify method, key must be an rsa.PublicKey struct
|
||||
func (m *SigningMethodRSAPSS) Verify(signingString, signature string, key interface{}) error {
|
||||
var err error
|
||||
|
||||
// Decode the signature
|
||||
var sig []byte
|
||||
if sig, err = DecodeSegment(signature); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var rsaKey *rsa.PublicKey
|
||||
switch k := key.(type) {
|
||||
case *rsa.PublicKey:
|
||||
rsaKey = k
|
||||
default:
|
||||
return ErrInvalidKey
|
||||
}
|
||||
|
||||
// Create hasher
|
||||
if !m.Hash.Available() {
|
||||
return ErrHashUnavailable
|
||||
}
|
||||
hasher := m.Hash.New()
|
||||
hasher.Write([]byte(signingString))
|
||||
|
||||
opts := m.Options
|
||||
if m.VerifyOptions != nil {
|
||||
opts = m.VerifyOptions
|
||||
}
|
||||
|
||||
return rsa.VerifyPSS(rsaKey, m.Hash, hasher.Sum(nil), sig, opts)
|
||||
}
|
||||
|
||||
// Sign implements token signing for the SigningMethod.
|
||||
// For this signing method, key must be an rsa.PrivateKey struct
|
||||
func (m *SigningMethodRSAPSS) Sign(signingString string, key interface{}) (string, error) {
|
||||
var rsaKey *rsa.PrivateKey
|
||||
|
||||
switch k := key.(type) {
|
||||
case *rsa.PrivateKey:
|
||||
rsaKey = k
|
||||
default:
|
||||
return "", ErrInvalidKeyType
|
||||
}
|
||||
|
||||
// Create the hasher
|
||||
if !m.Hash.Available() {
|
||||
return "", ErrHashUnavailable
|
||||
}
|
||||
|
||||
hasher := m.Hash.New()
|
||||
hasher.Write([]byte(signingString))
|
||||
|
||||
// Sign the string and return the encoded bytes
|
||||
if sigBytes, err := rsa.SignPSS(rand.Reader, rsaKey, m.Hash, hasher.Sum(nil), m.Options); err == nil {
|
||||
return EncodeSegment(sigBytes), nil
|
||||
} else {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
105
vendor/github.com/golang-jwt/jwt/v4/rsa_utils.go
generated
vendored
Normal file
105
vendor/github.com/golang-jwt/jwt/v4/rsa_utils.go
generated
vendored
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
package jwt
|
||||
|
||||
import (
|
||||
"crypto/rsa"
|
||||
"crypto/x509"
|
||||
"encoding/pem"
|
||||
"errors"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrKeyMustBePEMEncoded = errors.New("invalid key: Key must be a PEM encoded PKCS1 or PKCS8 key")
|
||||
ErrNotRSAPrivateKey = errors.New("key is not a valid RSA private key")
|
||||
ErrNotRSAPublicKey = errors.New("key is not a valid RSA public key")
|
||||
)
|
||||
|
||||
// ParseRSAPrivateKeyFromPEM parses a PEM encoded PKCS1 or PKCS8 private key
|
||||
func ParseRSAPrivateKeyFromPEM(key []byte) (*rsa.PrivateKey, error) {
|
||||
var err error
|
||||
|
||||
// Parse PEM block
|
||||
var block *pem.Block
|
||||
if block, _ = pem.Decode(key); block == nil {
|
||||
return nil, ErrKeyMustBePEMEncoded
|
||||
}
|
||||
|
||||
var parsedKey interface{}
|
||||
if parsedKey, err = x509.ParsePKCS1PrivateKey(block.Bytes); err != nil {
|
||||
if parsedKey, err = x509.ParsePKCS8PrivateKey(block.Bytes); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
var pkey *rsa.PrivateKey
|
||||
var ok bool
|
||||
if pkey, ok = parsedKey.(*rsa.PrivateKey); !ok {
|
||||
return nil, ErrNotRSAPrivateKey
|
||||
}
|
||||
|
||||
return pkey, nil
|
||||
}
|
||||
|
||||
// ParseRSAPrivateKeyFromPEMWithPassword parses a PEM encoded PKCS1 or PKCS8 private key protected with password
|
||||
//
|
||||
// Deprecated: This function is deprecated and should not be used anymore. It uses the deprecated x509.DecryptPEMBlock
|
||||
// function, which was deprecated since RFC 1423 is regarded insecure by design. Unfortunately, there is no alternative
|
||||
// in the Go standard library for now. See https://github.com/golang/go/issues/8860.
|
||||
func ParseRSAPrivateKeyFromPEMWithPassword(key []byte, password string) (*rsa.PrivateKey, error) {
|
||||
var err error
|
||||
|
||||
// Parse PEM block
|
||||
var block *pem.Block
|
||||
if block, _ = pem.Decode(key); block == nil {
|
||||
return nil, ErrKeyMustBePEMEncoded
|
||||
}
|
||||
|
||||
var parsedKey interface{}
|
||||
|
||||
var blockDecrypted []byte
|
||||
if blockDecrypted, err = x509.DecryptPEMBlock(block, []byte(password)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if parsedKey, err = x509.ParsePKCS1PrivateKey(blockDecrypted); err != nil {
|
||||
if parsedKey, err = x509.ParsePKCS8PrivateKey(blockDecrypted); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
var pkey *rsa.PrivateKey
|
||||
var ok bool
|
||||
if pkey, ok = parsedKey.(*rsa.PrivateKey); !ok {
|
||||
return nil, ErrNotRSAPrivateKey
|
||||
}
|
||||
|
||||
return pkey, nil
|
||||
}
|
||||
|
||||
// ParseRSAPublicKeyFromPEM parses a PEM encoded PKCS1 or PKCS8 public key
|
||||
func ParseRSAPublicKeyFromPEM(key []byte) (*rsa.PublicKey, error) {
|
||||
var err error
|
||||
|
||||
// Parse PEM block
|
||||
var block *pem.Block
|
||||
if block, _ = pem.Decode(key); block == nil {
|
||||
return nil, ErrKeyMustBePEMEncoded
|
||||
}
|
||||
|
||||
// Parse the key
|
||||
var parsedKey interface{}
|
||||
if parsedKey, err = x509.ParsePKIXPublicKey(block.Bytes); err != nil {
|
||||
if cert, err := x509.ParseCertificate(block.Bytes); err == nil {
|
||||
parsedKey = cert.PublicKey
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
var pkey *rsa.PublicKey
|
||||
var ok bool
|
||||
if pkey, ok = parsedKey.(*rsa.PublicKey); !ok {
|
||||
return nil, ErrNotRSAPublicKey
|
||||
}
|
||||
|
||||
return pkey, nil
|
||||
}
|
||||
35
vendor/github.com/golang-jwt/jwt/v4/signing_method.go
generated
vendored
Normal file
35
vendor/github.com/golang-jwt/jwt/v4/signing_method.go
generated
vendored
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
package jwt
|
||||
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
var signingMethods = map[string]func() SigningMethod{}
|
||||
var signingMethodLock = new(sync.RWMutex)
|
||||
|
||||
// SigningMethod can be used add new methods for signing or verifying tokens.
|
||||
type SigningMethod interface {
|
||||
Verify(signingString, signature string, key interface{}) error // Returns nil if signature is valid
|
||||
Sign(signingString string, key interface{}) (string, error) // Returns encoded signature or error
|
||||
Alg() string // returns the alg identifier for this method (example: 'HS256')
|
||||
}
|
||||
|
||||
// RegisterSigningMethod registers the "alg" name and a factory function for signing method.
|
||||
// This is typically done during init() in the method's implementation
|
||||
func RegisterSigningMethod(alg string, f func() SigningMethod) {
|
||||
signingMethodLock.Lock()
|
||||
defer signingMethodLock.Unlock()
|
||||
|
||||
signingMethods[alg] = f
|
||||
}
|
||||
|
||||
// GetSigningMethod retrieves a signing method from an "alg" string
|
||||
func GetSigningMethod(alg string) (method SigningMethod) {
|
||||
signingMethodLock.RLock()
|
||||
defer signingMethodLock.RUnlock()
|
||||
|
||||
if methodF, ok := signingMethods[alg]; ok {
|
||||
method = methodF()
|
||||
}
|
||||
return
|
||||
}
|
||||
1
vendor/github.com/golang-jwt/jwt/v4/staticcheck.conf
generated
vendored
Normal file
1
vendor/github.com/golang-jwt/jwt/v4/staticcheck.conf
generated
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
checks = ["all", "-ST1000", "-ST1003", "-ST1016", "-ST1023"]
|
||||
110
vendor/github.com/golang-jwt/jwt/v4/token.go
generated
vendored
Normal file
110
vendor/github.com/golang-jwt/jwt/v4/token.go
generated
vendored
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
package jwt
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// TimeFunc provides the current time when parsing token to validate "exp" claim (expiration time).
|
||||
// You can override it to use another time value. This is useful for testing or if your
|
||||
// server uses a different time zone than your tokens.
|
||||
var TimeFunc = time.Now
|
||||
|
||||
// Keyfunc will be used by the Parse methods as a callback function to supply
|
||||
// the key for verification. The function receives the parsed,
|
||||
// but unverified Token. This allows you to use properties in the
|
||||
// Header of the token (such as `kid`) to identify which key to use.
|
||||
type Keyfunc func(*Token) (interface{}, error)
|
||||
|
||||
// Token represents a JWT Token. Different fields will be used depending on whether you're
|
||||
// creating or parsing/verifying a token.
|
||||
type Token struct {
|
||||
Raw string // The raw token. Populated when you Parse a token
|
||||
Method SigningMethod // The signing method used or to be used
|
||||
Header map[string]interface{} // The first segment of the token
|
||||
Claims Claims // The second segment of the token
|
||||
Signature string // The third segment of the token. Populated when you Parse a token
|
||||
Valid bool // Is the token valid? Populated when you Parse/Verify a token
|
||||
}
|
||||
|
||||
// New creates a new Token. Takes a signing method
|
||||
func New(method SigningMethod) *Token {
|
||||
return NewWithClaims(method, MapClaims{})
|
||||
}
|
||||
|
||||
func NewWithClaims(method SigningMethod, claims Claims) *Token {
|
||||
return &Token{
|
||||
Header: map[string]interface{}{
|
||||
"typ": "JWT",
|
||||
"alg": method.Alg(),
|
||||
},
|
||||
Claims: claims,
|
||||
Method: method,
|
||||
}
|
||||
}
|
||||
|
||||
// SignedString retrieves the complete, signed token
|
||||
func (t *Token) SignedString(key interface{}) (string, error) {
|
||||
var sig, sstr string
|
||||
var err error
|
||||
if sstr, err = t.SigningString(); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if sig, err = t.Method.Sign(sstr, key); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return strings.Join([]string{sstr, sig}, "."), nil
|
||||
}
|
||||
|
||||
// SigningString generates the signing string. This is the
|
||||
// most expensive part of the whole deal. Unless you
|
||||
// need this for something special, just go straight for
|
||||
// the SignedString.
|
||||
func (t *Token) SigningString() (string, error) {
|
||||
var err error
|
||||
parts := make([]string, 2)
|
||||
for i := range parts {
|
||||
var jsonValue []byte
|
||||
if i == 0 {
|
||||
if jsonValue, err = json.Marshal(t.Header); err != nil {
|
||||
return "", err
|
||||
}
|
||||
} else {
|
||||
if jsonValue, err = json.Marshal(t.Claims); err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
||||
parts[i] = EncodeSegment(jsonValue)
|
||||
}
|
||||
return strings.Join(parts, "."), nil
|
||||
}
|
||||
|
||||
// Parse parses, validates, and returns a token.
|
||||
// keyFunc will receive the parsed token and should return the key for validating.
|
||||
// If everything is kosher, err will be nil
|
||||
func Parse(tokenString string, keyFunc Keyfunc) (*Token, error) {
|
||||
return new(Parser).Parse(tokenString, keyFunc)
|
||||
}
|
||||
|
||||
func ParseWithClaims(tokenString string, claims Claims, keyFunc Keyfunc) (*Token, error) {
|
||||
return new(Parser).ParseWithClaims(tokenString, claims, keyFunc)
|
||||
}
|
||||
|
||||
// EncodeSegment encodes a JWT specific base64url encoding with padding stripped
|
||||
//
|
||||
// Deprecated: In a future release, we will demote this function to a non-exported function, since it
|
||||
// should only be used internally
|
||||
func EncodeSegment(seg []byte) string {
|
||||
return base64.RawURLEncoding.EncodeToString(seg)
|
||||
}
|
||||
|
||||
// DecodeSegment decodes a JWT specific base64url encoding with padding stripped
|
||||
//
|
||||
// Deprecated: In a future release, we will demote this function to a non-exported function, since it
|
||||
// should only be used internally
|
||||
func DecodeSegment(seg string) ([]byte, error) {
|
||||
return base64.RawURLEncoding.DecodeString(seg)
|
||||
}
|
||||
125
vendor/github.com/golang-jwt/jwt/v4/types.go
generated
vendored
Normal file
125
vendor/github.com/golang-jwt/jwt/v4/types.go
generated
vendored
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
package jwt
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
// TimePrecision sets the precision of times and dates within this library.
|
||||
// This has an influence on the precision of times when comparing expiry or
|
||||
// other related time fields. Furthermore, it is also the precision of times
|
||||
// when serializing.
|
||||
//
|
||||
// For backwards compatibility the default precision is set to seconds, so that
|
||||
// no fractional timestamps are generated.
|
||||
var TimePrecision = time.Second
|
||||
|
||||
// MarshalSingleStringAsArray modifies the behaviour of the ClaimStrings type, especially
|
||||
// its MarshalJSON function.
|
||||
//
|
||||
// If it is set to true (the default), it will always serialize the type as an
|
||||
// array of strings, even if it just contains one element, defaulting to the behaviour
|
||||
// of the underlying []string. If it is set to false, it will serialize to a single
|
||||
// string, if it contains one element. Otherwise, it will serialize to an array of strings.
|
||||
var MarshalSingleStringAsArray = true
|
||||
|
||||
// NumericDate represents a JSON numeric date value, as referenced at
|
||||
// https://datatracker.ietf.org/doc/html/rfc7519#section-2.
|
||||
type NumericDate struct {
|
||||
time.Time
|
||||
}
|
||||
|
||||
// NewNumericDate constructs a new *NumericDate from a standard library time.Time struct.
|
||||
// It will truncate the timestamp according to the precision specified in TimePrecision.
|
||||
func NewNumericDate(t time.Time) *NumericDate {
|
||||
return &NumericDate{t.Truncate(TimePrecision)}
|
||||
}
|
||||
|
||||
// newNumericDateFromSeconds creates a new *NumericDate out of a float64 representing a
|
||||
// UNIX epoch with the float fraction representing non-integer seconds.
|
||||
func newNumericDateFromSeconds(f float64) *NumericDate {
|
||||
return NewNumericDate(time.Unix(0, int64(f*float64(time.Second))))
|
||||
}
|
||||
|
||||
// MarshalJSON is an implementation of the json.RawMessage interface and serializes the UNIX epoch
|
||||
// represented in NumericDate to a byte array, using the precision specified in TimePrecision.
|
||||
func (date NumericDate) MarshalJSON() (b []byte, err error) {
|
||||
f := float64(date.Truncate(TimePrecision).UnixNano()) / float64(time.Second)
|
||||
|
||||
return []byte(strconv.FormatFloat(f, 'f', -1, 64)), nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON is an implementation of the json.RawMessage interface and deserializses a
|
||||
// NumericDate from a JSON representation, i.e. a json.Number. This number represents an UNIX epoch
|
||||
// with either integer or non-integer seconds.
|
||||
func (date *NumericDate) UnmarshalJSON(b []byte) (err error) {
|
||||
var (
|
||||
number json.Number
|
||||
f float64
|
||||
)
|
||||
|
||||
if err = json.Unmarshal(b, &number); err != nil {
|
||||
return fmt.Errorf("could not parse NumericData: %w", err)
|
||||
}
|
||||
|
||||
if f, err = number.Float64(); err != nil {
|
||||
return fmt.Errorf("could not convert json number value to float: %w", err)
|
||||
}
|
||||
|
||||
n := newNumericDateFromSeconds(f)
|
||||
*date = *n
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ClaimStrings is basically just a slice of strings, but it can be either serialized from a string array or just a string.
|
||||
// This type is necessary, since the "aud" claim can either be a single string or an array.
|
||||
type ClaimStrings []string
|
||||
|
||||
func (s *ClaimStrings) UnmarshalJSON(data []byte) (err error) {
|
||||
var value interface{}
|
||||
|
||||
if err = json.Unmarshal(data, &value); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var aud []string
|
||||
|
||||
switch v := value.(type) {
|
||||
case string:
|
||||
aud = append(aud, v)
|
||||
case []string:
|
||||
aud = ClaimStrings(v)
|
||||
case []interface{}:
|
||||
for _, vv := range v {
|
||||
vs, ok := vv.(string)
|
||||
if !ok {
|
||||
return &json.UnsupportedTypeError{Type: reflect.TypeOf(vv)}
|
||||
}
|
||||
aud = append(aud, vs)
|
||||
}
|
||||
case nil:
|
||||
return nil
|
||||
default:
|
||||
return &json.UnsupportedTypeError{Type: reflect.TypeOf(v)}
|
||||
}
|
||||
|
||||
*s = aud
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (s ClaimStrings) MarshalJSON() (b []byte, err error) {
|
||||
// This handles a special case in the JWT RFC. If the string array, e.g. used by the "aud" field,
|
||||
// only contains one element, it MAY be serialized as a single string. This may or may not be
|
||||
// desired based on the ecosystem of other JWT library used, so we make it configurable by the
|
||||
// variable MarshalSingleStringAsArray.
|
||||
if len(s) == 1 && !MarshalSingleStringAsArray {
|
||||
return json.Marshal(s[0])
|
||||
}
|
||||
|
||||
return json.Marshal([]string(s))
|
||||
}
|
||||
12
vendor/github.com/jonboulle/clockwork/.editorconfig
generated
vendored
Normal file
12
vendor/github.com/jonboulle/clockwork/.editorconfig
generated
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
indent_size = 4
|
||||
indent_style = space
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.go]
|
||||
indent_style = tab
|
||||
27
vendor/github.com/jonboulle/clockwork/.gitignore
generated
vendored
Normal file
27
vendor/github.com/jonboulle/clockwork/.gitignore
generated
vendored
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/.idea/
|
||||
|
||||
# Compiled Object files, Static and Dynamic libs (Shared Objects)
|
||||
*.o
|
||||
*.a
|
||||
*.so
|
||||
|
||||
# Folders
|
||||
_obj
|
||||
_test
|
||||
|
||||
# Architecture specific extensions/prefixes
|
||||
*.[568vq]
|
||||
[568vq].out
|
||||
|
||||
*.cgo1.go
|
||||
*.cgo2.c
|
||||
_cgo_defun.c
|
||||
_cgo_gotypes.go
|
||||
_cgo_export.*
|
||||
|
||||
_testmain.go
|
||||
|
||||
*.exe
|
||||
*.test
|
||||
|
||||
*.swp
|
||||
201
vendor/github.com/jonboulle/clockwork/LICENSE
generated
vendored
Normal file
201
vendor/github.com/jonboulle/clockwork/LICENSE
generated
vendored
Normal file
|
|
@ -0,0 +1,201 @@
|
|||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright {yyyy} {name of copyright owner}
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
80
vendor/github.com/jonboulle/clockwork/README.md
generated
vendored
Normal file
80
vendor/github.com/jonboulle/clockwork/README.md
generated
vendored
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
# clockwork
|
||||
|
||||
[](https://github.com/avelino/awesome-go#utilities)
|
||||
|
||||
[](https://github.com/jonboulle/clockwork/actions?query=workflow%3ACI)
|
||||
[](https://goreportcard.com/report/github.com/jonboulle/clockwork)
|
||||

|
||||
[](https://pkg.go.dev/mod/github.com/jonboulle/clockwork)
|
||||
|
||||
**A simple fake clock for Go.**
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
Replace uses of the `time` package with the `clockwork.Clock` interface instead.
|
||||
|
||||
For example, instead of using `time.Sleep` directly:
|
||||
|
||||
```go
|
||||
func myFunc() {
|
||||
time.Sleep(3 * time.Second)
|
||||
doSomething()
|
||||
}
|
||||
```
|
||||
|
||||
Inject a clock and use its `Sleep` method instead:
|
||||
|
||||
```go
|
||||
func myFunc(clock clockwork.Clock) {
|
||||
clock.Sleep(3 * time.Second)
|
||||
doSomething()
|
||||
}
|
||||
```
|
||||
|
||||
Now you can easily test `myFunc` with a `FakeClock`:
|
||||
|
||||
```go
|
||||
func TestMyFunc(t *testing.T) {
|
||||
c := clockwork.NewFakeClock()
|
||||
|
||||
// Start our sleepy function
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
myFunc(c)
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
// Ensure we wait until myFunc is sleeping
|
||||
c.BlockUntil(1)
|
||||
|
||||
assertState()
|
||||
|
||||
// Advance the FakeClock forward in time
|
||||
c.Advance(3 * time.Second)
|
||||
|
||||
// Wait until the function completes
|
||||
wg.Wait()
|
||||
|
||||
assertState()
|
||||
}
|
||||
```
|
||||
|
||||
and in production builds, simply inject the real clock instead:
|
||||
|
||||
```go
|
||||
myFunc(clockwork.NewRealClock())
|
||||
```
|
||||
|
||||
See [example_test.go](example_test.go) for a full example.
|
||||
|
||||
|
||||
# Credits
|
||||
|
||||
clockwork is inspired by @wickman's [threaded fake clock](https://gist.github.com/wickman/3840816), and the [Golang playground](https://blog.golang.org/playground#TOC_3.1.)
|
||||
|
||||
|
||||
## License
|
||||
|
||||
Apache License, Version 2.0. Please see [License File](LICENSE) for more information.
|
||||
195
vendor/github.com/jonboulle/clockwork/clockwork.go
generated
vendored
Normal file
195
vendor/github.com/jonboulle/clockwork/clockwork.go
generated
vendored
Normal file
|
|
@ -0,0 +1,195 @@
|
|||
package clockwork
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Clock provides an interface that packages can use instead of directly
|
||||
// using the time module, so that chronology-related behavior can be tested
|
||||
type Clock interface {
|
||||
After(d time.Duration) <-chan time.Time
|
||||
Sleep(d time.Duration)
|
||||
Now() time.Time
|
||||
Since(t time.Time) time.Duration
|
||||
NewTicker(d time.Duration) Ticker
|
||||
}
|
||||
|
||||
// FakeClock provides an interface for a clock which can be
|
||||
// manually advanced through time
|
||||
type FakeClock interface {
|
||||
Clock
|
||||
// Advance advances the FakeClock to a new point in time, ensuring any existing
|
||||
// sleepers are notified appropriately before returning
|
||||
Advance(d time.Duration)
|
||||
// BlockUntil will block until the FakeClock has the given number of
|
||||
// sleepers (callers of Sleep or After)
|
||||
BlockUntil(n int)
|
||||
}
|
||||
|
||||
// NewRealClock returns a Clock which simply delegates calls to the actual time
|
||||
// package; it should be used by packages in production.
|
||||
func NewRealClock() Clock {
|
||||
return &realClock{}
|
||||
}
|
||||
|
||||
// NewFakeClock returns a FakeClock implementation which can be
|
||||
// manually advanced through time for testing. The initial time of the
|
||||
// FakeClock will be an arbitrary non-zero time.
|
||||
func NewFakeClock() FakeClock {
|
||||
// use a fixture that does not fulfill Time.IsZero()
|
||||
return NewFakeClockAt(time.Date(1984, time.April, 4, 0, 0, 0, 0, time.UTC))
|
||||
}
|
||||
|
||||
// NewFakeClockAt returns a FakeClock initialised at the given time.Time.
|
||||
func NewFakeClockAt(t time.Time) FakeClock {
|
||||
return &fakeClock{
|
||||
time: t,
|
||||
}
|
||||
}
|
||||
|
||||
type realClock struct{}
|
||||
|
||||
func (rc *realClock) After(d time.Duration) <-chan time.Time {
|
||||
return time.After(d)
|
||||
}
|
||||
|
||||
func (rc *realClock) Sleep(d time.Duration) {
|
||||
time.Sleep(d)
|
||||
}
|
||||
|
||||
func (rc *realClock) Now() time.Time {
|
||||
return time.Now()
|
||||
}
|
||||
|
||||
func (rc *realClock) Since(t time.Time) time.Duration {
|
||||
return rc.Now().Sub(t)
|
||||
}
|
||||
|
||||
func (rc *realClock) NewTicker(d time.Duration) Ticker {
|
||||
return &realTicker{time.NewTicker(d)}
|
||||
}
|
||||
|
||||
type fakeClock struct {
|
||||
sleepers []*sleeper
|
||||
blockers []*blocker
|
||||
time time.Time
|
||||
|
||||
l sync.RWMutex
|
||||
}
|
||||
|
||||
// sleeper represents a caller of After or Sleep
|
||||
type sleeper struct {
|
||||
until time.Time
|
||||
done chan time.Time
|
||||
}
|
||||
|
||||
// blocker represents a caller of BlockUntil
|
||||
type blocker struct {
|
||||
count int
|
||||
ch chan struct{}
|
||||
}
|
||||
|
||||
// After mimics time.After; it waits for the given duration to elapse on the
|
||||
// fakeClock, then sends the current time on the returned channel.
|
||||
func (fc *fakeClock) After(d time.Duration) <-chan time.Time {
|
||||
fc.l.Lock()
|
||||
defer fc.l.Unlock()
|
||||
now := fc.time
|
||||
done := make(chan time.Time, 1)
|
||||
if d.Nanoseconds() <= 0 {
|
||||
// special case - trigger immediately
|
||||
done <- now
|
||||
} else {
|
||||
// otherwise, add to the set of sleepers
|
||||
s := &sleeper{
|
||||
until: now.Add(d),
|
||||
done: done,
|
||||
}
|
||||
fc.sleepers = append(fc.sleepers, s)
|
||||
// and notify any blockers
|
||||
fc.blockers = notifyBlockers(fc.blockers, len(fc.sleepers))
|
||||
}
|
||||
return done
|
||||
}
|
||||
|
||||
// notifyBlockers notifies all the blockers waiting until the
|
||||
// given number of sleepers are waiting on the fakeClock. It
|
||||
// returns an updated slice of blockers (i.e. those still waiting)
|
||||
func notifyBlockers(blockers []*blocker, count int) (newBlockers []*blocker) {
|
||||
for _, b := range blockers {
|
||||
if b.count == count {
|
||||
close(b.ch)
|
||||
} else {
|
||||
newBlockers = append(newBlockers, b)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Sleep blocks until the given duration has passed on the fakeClock
|
||||
func (fc *fakeClock) Sleep(d time.Duration) {
|
||||
<-fc.After(d)
|
||||
}
|
||||
|
||||
// Time returns the current time of the fakeClock
|
||||
func (fc *fakeClock) Now() time.Time {
|
||||
fc.l.RLock()
|
||||
t := fc.time
|
||||
fc.l.RUnlock()
|
||||
return t
|
||||
}
|
||||
|
||||
// Since returns the duration that has passed since the given time on the fakeClock
|
||||
func (fc *fakeClock) Since(t time.Time) time.Duration {
|
||||
return fc.Now().Sub(t)
|
||||
}
|
||||
|
||||
func (fc *fakeClock) NewTicker(d time.Duration) Ticker {
|
||||
ft := &fakeTicker{
|
||||
c: make(chan time.Time, 1),
|
||||
stop: make(chan bool, 1),
|
||||
clock: fc,
|
||||
period: d,
|
||||
}
|
||||
ft.runTickThread()
|
||||
return ft
|
||||
}
|
||||
|
||||
// Advance advances fakeClock to a new point in time, ensuring channels from any
|
||||
// previous invocations of After are notified appropriately before returning
|
||||
func (fc *fakeClock) Advance(d time.Duration) {
|
||||
fc.l.Lock()
|
||||
defer fc.l.Unlock()
|
||||
end := fc.time.Add(d)
|
||||
var newSleepers []*sleeper
|
||||
for _, s := range fc.sleepers {
|
||||
if end.Sub(s.until) >= 0 {
|
||||
s.done <- end
|
||||
} else {
|
||||
newSleepers = append(newSleepers, s)
|
||||
}
|
||||
}
|
||||
fc.sleepers = newSleepers
|
||||
fc.blockers = notifyBlockers(fc.blockers, len(fc.sleepers))
|
||||
fc.time = end
|
||||
}
|
||||
|
||||
// BlockUntil will block until the fakeClock has the given number of sleepers
|
||||
// (callers of Sleep or After)
|
||||
func (fc *fakeClock) BlockUntil(n int) {
|
||||
fc.l.Lock()
|
||||
// Fast path: current number of sleepers is what we're looking for
|
||||
if len(fc.sleepers) == n {
|
||||
fc.l.Unlock()
|
||||
return
|
||||
}
|
||||
// Otherwise, set up a new blocker
|
||||
b := &blocker{
|
||||
count: n,
|
||||
ch: make(chan struct{}),
|
||||
}
|
||||
fc.blockers = append(fc.blockers, b)
|
||||
fc.l.Unlock()
|
||||
<-b.ch
|
||||
}
|
||||
3
vendor/github.com/jonboulle/clockwork/go.mod
generated
vendored
Normal file
3
vendor/github.com/jonboulle/clockwork/go.mod
generated
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
module github.com/jonboulle/clockwork
|
||||
|
||||
go 1.13
|
||||
72
vendor/github.com/jonboulle/clockwork/ticker.go
generated
vendored
Normal file
72
vendor/github.com/jonboulle/clockwork/ticker.go
generated
vendored
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
package clockwork
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// Ticker provides an interface which can be used instead of directly
|
||||
// using the ticker within the time module. The real-time ticker t
|
||||
// provides ticks through t.C which becomes now t.Chan() to make
|
||||
// this channel requirement definable in this interface.
|
||||
type Ticker interface {
|
||||
Chan() <-chan time.Time
|
||||
Stop()
|
||||
}
|
||||
|
||||
type realTicker struct{ *time.Ticker }
|
||||
|
||||
func (rt *realTicker) Chan() <-chan time.Time {
|
||||
return rt.C
|
||||
}
|
||||
|
||||
type fakeTicker struct {
|
||||
c chan time.Time
|
||||
stop chan bool
|
||||
clock FakeClock
|
||||
period time.Duration
|
||||
}
|
||||
|
||||
func (ft *fakeTicker) Chan() <-chan time.Time {
|
||||
return ft.c
|
||||
}
|
||||
|
||||
func (ft *fakeTicker) Stop() {
|
||||
ft.stop <- true
|
||||
}
|
||||
|
||||
// runTickThread initializes a background goroutine to send the tick time to the ticker channel
|
||||
// after every period. Tick events are discarded if the underlying ticker channel does not have
|
||||
// enough capacity.
|
||||
func (ft *fakeTicker) runTickThread() {
|
||||
nextTick := ft.clock.Now().Add(ft.period)
|
||||
next := ft.clock.After(ft.period)
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case <-ft.stop:
|
||||
return
|
||||
case <-next:
|
||||
// We send the time that the tick was supposed to occur at.
|
||||
tick := nextTick
|
||||
// Before sending the tick, we'll compute the next tick time and star the clock.After call.
|
||||
now := ft.clock.Now()
|
||||
// First, figure out how many periods there have been between "now" and the time we were
|
||||
// supposed to have trigged, then advance over all of those.
|
||||
skipTicks := (now.Sub(tick) + ft.period - 1) / ft.period
|
||||
nextTick = nextTick.Add(skipTicks * ft.period)
|
||||
// Now, keep advancing until we are past now. This should happen at most once.
|
||||
for !nextTick.After(now) {
|
||||
nextTick = nextTick.Add(ft.period)
|
||||
}
|
||||
// Figure out how long between now and the next scheduled tick, then wait that long.
|
||||
remaining := nextTick.Sub(now)
|
||||
next = ft.clock.After(remaining)
|
||||
// Finally, we can actually send the tick.
|
||||
select {
|
||||
case ft.c <- tick:
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
201
vendor/github.com/mattermost/xml-roundtrip-validator/LICENSE.txt
generated
vendored
Normal file
201
vendor/github.com/mattermost/xml-roundtrip-validator/LICENSE.txt
generated
vendored
Normal file
|
|
@ -0,0 +1,201 @@
|
|||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
73
vendor/github.com/mattermost/xml-roundtrip-validator/README.md
generated
vendored
Normal file
73
vendor/github.com/mattermost/xml-roundtrip-validator/README.md
generated
vendored
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
# xml-roundtrip-validator
|
||||
|
||||
The Go module `github.com/mattermost/xml-roundtrip-validator` implements mitigations for multiple security issues in Go's `encoding/xml`. Applications that use `encoding/xml` for security-critical operations, such as XML signature validation and SAML, may use the `Validate` and `ValidateAll` functions to avoid impact from malicious XML inputs.
|
||||
|
||||
## Usage
|
||||
|
||||
### Validate
|
||||
|
||||
```Go
|
||||
import (
|
||||
"strings"
|
||||
|
||||
xrv "github.com/mattermost/xml-roundtrip-validator"
|
||||
)
|
||||
|
||||
func DoStuffWithXML(input string) {
|
||||
if err := xrv.Validate(strings.NewReader(input)); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// validation succeeded, input is safe
|
||||
actuallyDoStuffWithXML(input)
|
||||
}
|
||||
```
|
||||
|
||||
### ValidateAll
|
||||
|
||||
```Go
|
||||
import (
|
||||
"strings"
|
||||
|
||||
xrv "github.com/mattermost/xml-roundtrip-validator"
|
||||
)
|
||||
|
||||
func DoStuffWithXML(input string) {
|
||||
if errs := xrv.ValidateAll(strings.NewReader(input)); len(errs) != 0 {
|
||||
for err := range errs {
|
||||
// here you can log each error individually if you like
|
||||
}
|
||||
return
|
||||
}
|
||||
// validation succeeded, input is safe
|
||||
actuallyDoStuffWithXML(input)
|
||||
}
|
||||
```
|
||||
|
||||
### CLI
|
||||
|
||||
Compiling:
|
||||
|
||||
```
|
||||
$ go build cmd/xrv.go
|
||||
```
|
||||
|
||||
Running:
|
||||
|
||||
```
|
||||
$ ./xrv good.xml
|
||||
Document validated without errors
|
||||
$ ./xrv bad.xml
|
||||
validator: in token starting at 2:5: roundtrip error: expected {{ :Element} []}, observed {{ Element} []}
|
||||
$ ./xrv -all bad.xml
|
||||
validator: in token starting at 2:5: roundtrip error: expected {{ :Element} []}, observed {{ Element} []}
|
||||
validator: in token starting at 3:5: roundtrip error: expected {{ Element} [{{ :attr} z}]}, observed {{ Element} [{{ attr} z}]}
|
||||
```
|
||||
|
||||
## Go vulnerabilities addressed
|
||||
|
||||
Descriptions of the Go vulnerabilities addressed by this module can be found in the advisories directory. Specifically, the issues addressed are:
|
||||
|
||||
- [Element namespace prefix instability](./advisories/unstable-elements.md)
|
||||
- [Attribute namespace prefix instability](./advisories/unstable-attributes.md)
|
||||
- [Directive comment instability](./advisories/unstable-directives.md)
|
||||
- Any other similar roundtrip issues we may not know about
|
||||
25
vendor/github.com/mattermost/xml-roundtrip-validator/SECURITY.md
generated
vendored
Normal file
25
vendor/github.com/mattermost/xml-roundtrip-validator/SECURITY.md
generated
vendored
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
Security
|
||||
========
|
||||
|
||||
Safety and data security is of the utmost priority for the Mattermost community. If you are a security researcher and have discovered a security vulnerability in our codebase, we would appreciate your help in disclosing it to us in a responsible manner.
|
||||
|
||||
Reporting security issues
|
||||
-------------------------
|
||||
|
||||
**Please do not use GitHub issues for security-sensitive communication.**
|
||||
|
||||
Security issues in the community test server, any of the open source codebases maintained by Mattermost, or any of our commercial offerings should be reported via email to [responsibledisclosure@mattermost.com](mailto:responsibledisclosure@mattermost.com). Mattermost is committed to working together with researchers and keeping them updated throughout the patching process. Researchers who responsibly report valid security issues will be publicly credited for their efforts (if they so choose).
|
||||
|
||||
For a more detailed description of the disclosure process and a list of researchers who have previously contributed to the disclosure program, see [Report a Security Vulnerability](https://mattermost.com/security-vulnerability-report/) on the Mattermost website.
|
||||
|
||||
Security updates
|
||||
----------------
|
||||
|
||||
Mattermost has a mandatory upgrade policy, and updates are only provided for the latest 3 releases and the current Extended Support Release (ESR). Critical updates are delivered as dot releases. Details on security updates are announced 30 days after the availability of the update.
|
||||
|
||||
For more details about the security content of past releases, see the [Security Updates](https://mattermost.com/security-updates/) page on the Mattermost website. For timely notifications about new security updates, subscribe to the [Security Bulletins Mailing List](https://about.mattermost.com/security-bulletin).
|
||||
|
||||
Contributing to this policy
|
||||
---------------------------
|
||||
|
||||
If you have feedback or suggestions on improving this policy document, please [create an issue](https://github.com/mattermost/mattermost-server/issues/new).
|
||||
5
vendor/github.com/mattermost/xml-roundtrip-validator/go.mod
generated
vendored
Normal file
5
vendor/github.com/mattermost/xml-roundtrip-validator/go.mod
generated
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
module github.com/mattermost/xml-roundtrip-validator
|
||||
|
||||
go 1.14
|
||||
|
||||
require github.com/stretchr/testify v1.6.1
|
||||
12
vendor/github.com/mattermost/xml-roundtrip-validator/go.sum
generated
vendored
Normal file
12
vendor/github.com/mattermost/xml-roundtrip-validator/go.sum
generated
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
292
vendor/github.com/mattermost/xml-roundtrip-validator/validator.go
generated
vendored
Normal file
292
vendor/github.com/mattermost/xml-roundtrip-validator/validator.go
generated
vendored
Normal file
|
|
@ -0,0 +1,292 @@
|
|||
package validator
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
// XMLRoundtripError is returned when a round-trip token doesn't match the original
|
||||
type XMLRoundtripError struct {
|
||||
Expected, Observed xml.Token
|
||||
Overflow []byte
|
||||
}
|
||||
|
||||
func (err XMLRoundtripError) Error() string {
|
||||
if len(err.Overflow) == 0 {
|
||||
return fmt.Sprintf("roundtrip error: expected %v, observed %v", err.Expected, err.Observed)
|
||||
}
|
||||
return fmt.Sprintf("roundtrip error: unexpected overflow after token: %s", err.Overflow)
|
||||
}
|
||||
|
||||
// XMLValidationError is returned when validating an XML document fails
|
||||
type XMLValidationError struct {
|
||||
Start, End, Line, Column int64
|
||||
err error
|
||||
}
|
||||
|
||||
func (err XMLValidationError) Error() string {
|
||||
return fmt.Sprintf("validator: in token starting at %d:%d: %s", err.Line, err.Column, err.err.Error())
|
||||
}
|
||||
|
||||
func (err XMLValidationError) Unwrap() error {
|
||||
return err.err
|
||||
}
|
||||
|
||||
// Validate makes sure the given XML bytes survive round trips through encoding/xml without mutations
|
||||
func Validate(xmlReader io.Reader) error {
|
||||
xmlBuffer := &bytes.Buffer{}
|
||||
xmlReader = &byteReader{io.TeeReader(xmlReader, xmlBuffer)}
|
||||
decoder := xml.NewDecoder(xmlReader)
|
||||
decoder.Strict = false
|
||||
decoder.CharsetReader = func(charset string, input io.Reader) (io.Reader, error) { return input, nil }
|
||||
offset := int64(0)
|
||||
for {
|
||||
token, err := decoder.RawToken()
|
||||
if err == io.EOF {
|
||||
return nil
|
||||
} else if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := CheckToken(token); err != nil {
|
||||
xmlBytes := xmlBuffer.Bytes()
|
||||
line := bytes.Count(xmlBytes[0:offset], []byte{'\n'}) + 1
|
||||
lineStart := int64(bytes.LastIndexByte(xmlBytes[0:offset], '\n')) + 1
|
||||
column := offset - lineStart + 1
|
||||
return XMLValidationError{
|
||||
Start: offset,
|
||||
End: decoder.InputOffset(),
|
||||
Line: int64(line),
|
||||
Column: column,
|
||||
err: err,
|
||||
}
|
||||
}
|
||||
offset = decoder.InputOffset()
|
||||
}
|
||||
}
|
||||
|
||||
// ValidateAll is like Validate, but instead of returning after the first error,
|
||||
// it accumulates errors and validates the entire document
|
||||
func ValidateAll(xmlReader io.Reader) []error {
|
||||
xmlBuffer := &bytes.Buffer{}
|
||||
xmlReader = io.TeeReader(xmlReader, xmlBuffer)
|
||||
errs := []error{}
|
||||
offset := int64(0)
|
||||
line := int64(1)
|
||||
column := int64(1)
|
||||
for {
|
||||
err := Validate(xmlReader)
|
||||
if err == nil {
|
||||
// reached the end with no additional errors
|
||||
break
|
||||
}
|
||||
validationError := XMLValidationError{}
|
||||
if errors.As(err, &validationError) {
|
||||
// validation errors contain line numbers and offsets, but
|
||||
// these offsets are based on the offset where Validate
|
||||
// was called, so they need to be adjusted to accordingly
|
||||
validationError.Start += offset
|
||||
validationError.End += offset
|
||||
if validationError.Line == 1 {
|
||||
validationError.Column += column - 1
|
||||
}
|
||||
validationError.Line += line - 1
|
||||
errs = append(errs, validationError)
|
||||
xmlBytes := xmlBuffer.Bytes()
|
||||
offset += int64(len(xmlBytes))
|
||||
newLines := int64(bytes.Count(xmlBytes, []byte("\n")))
|
||||
line += newLines
|
||||
if newLines > 0 {
|
||||
column = int64(len(xmlBytes) - bytes.LastIndex(xmlBytes, []byte("\n")))
|
||||
} else {
|
||||
column += int64(len(xmlBytes))
|
||||
}
|
||||
xmlBuffer.Reset()
|
||||
} else {
|
||||
// this was not a validation error, but likely
|
||||
// completely unparseable XML instead; no point
|
||||
// in trying to continue
|
||||
errs = append(errs, err)
|
||||
break
|
||||
}
|
||||
}
|
||||
return errs
|
||||
}
|
||||
|
||||
// bufio implements a ByteReader but we explicitly don't want any buffering
|
||||
type byteReader struct {
|
||||
r io.Reader
|
||||
}
|
||||
|
||||
func (r *byteReader) ReadByte() (byte, error) {
|
||||
var p [1]byte
|
||||
n, err := r.r.Read(p[:])
|
||||
|
||||
// The doc for the io.ByteReader interface states:
|
||||
// If ReadByte returns an error, no input byte was consumed, and the returned byte value is undefined.
|
||||
// So if a byte is actually extracted from the reader, and we want to return it, we mustn't return the error.
|
||||
if n > 0 {
|
||||
// this byteReader is only used in the context of the Validate() function,
|
||||
// we deliberately choose to completely ignore the error in this case.
|
||||
// return the byte extracted from the reader
|
||||
return p[0], nil
|
||||
}
|
||||
|
||||
return 0, err
|
||||
}
|
||||
|
||||
func (r *byteReader) Read(p []byte) (int, error) {
|
||||
return r.r.Read(p)
|
||||
}
|
||||
|
||||
// CheckToken computes a round trip for a given xml.Token and returns an
|
||||
// error if the newly calculated token differs from the original
|
||||
func CheckToken(before xml.Token) error {
|
||||
buffer := &bytes.Buffer{}
|
||||
encoder := xml.NewEncoder(buffer)
|
||||
|
||||
switch t := before.(type) {
|
||||
case xml.EndElement:
|
||||
// xml.Encoder expects matching StartElements for all EndElements
|
||||
if err := encoder.EncodeToken(xml.StartElement{Name: t.Name}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := encoder.EncodeToken(before); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := encoder.Flush(); err != nil {
|
||||
return err
|
||||
}
|
||||
encoded := buffer.Bytes()
|
||||
decoder := xml.NewDecoder(bytes.NewReader(encoded))
|
||||
decoder.CharsetReader = func(charset string, input io.Reader) (io.Reader, error) { return input, nil }
|
||||
|
||||
switch before.(type) {
|
||||
case xml.EndElement:
|
||||
// throw away the StartElement we added above
|
||||
if _, err := decoder.RawToken(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
after, err := decoder.RawToken()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !tokenEquals(before, after) {
|
||||
return XMLRoundtripError{before, after, nil}
|
||||
}
|
||||
offset := decoder.InputOffset()
|
||||
if offset != int64(len(encoded)) {
|
||||
// this is likely unreachable, but just in case
|
||||
return XMLRoundtripError{before, after, encoded[offset:]}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func tokenEquals(before, after xml.Token) bool {
|
||||
switch t1 := before.(type) {
|
||||
|
||||
case xml.CharData:
|
||||
t2, ok := after.(xml.CharData)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
return bytes.Equal(t1, t2)
|
||||
|
||||
case xml.Comment:
|
||||
t2, ok := after.(xml.Comment)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
return bytes.Equal(t1, t2)
|
||||
|
||||
case xml.Directive:
|
||||
t2, ok := after.(xml.Directive)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
return bytes.Equal(t1, t2)
|
||||
|
||||
case xml.EndElement:
|
||||
t2, ok := after.(xml.EndElement)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
// local name should equal; namespace prefixes get erased
|
||||
return t1.Name.Local == t2.Name.Local && t2.Name.Space == ""
|
||||
|
||||
case xml.ProcInst:
|
||||
t2, ok := after.(xml.ProcInst)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
return t1.Target == t2.Target && bytes.Equal(t1.Inst, t2.Inst)
|
||||
|
||||
case xml.StartElement:
|
||||
t2, ok := after.(xml.StartElement)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
// encoding/xml messes up namespace prefixes on both tag and attribute names;
|
||||
// they need adjusting to make the comparison possible
|
||||
fixNamespacePrefixes(&t1, &t2)
|
||||
if t1.Name != t2.Name {
|
||||
return false
|
||||
}
|
||||
if len(t1.Attr) != len(t2.Attr) {
|
||||
return false
|
||||
}
|
||||
// after the call to fixNamespacePrefixes, all attributes should match;
|
||||
// ordering is preserved
|
||||
for i, attr := range t1.Attr {
|
||||
if attr != t2.Attr[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func fixNamespacePrefixes(before, after *xml.StartElement) {
|
||||
// if the after token has more attributes than the before token,
|
||||
// the round trip likely introduced new xmlns attributes
|
||||
if len(after.Attr) > len(before.Attr) {
|
||||
|
||||
// handle erased tag prefixes; the corresponding xmlns attribute is always the first one
|
||||
if (before.Name.Space != "" && after.Name.Space == "" && after.Attr[0].Name == xml.Name{Local: "xmlns"}) {
|
||||
after.Name.Space = after.Attr[0].Value
|
||||
after.Attr = after.Attr[1:]
|
||||
}
|
||||
|
||||
// handle attribute prefixes; the xmlns attribute always comes immediately before the prefixed attribute
|
||||
for len(after.Attr) > len(before.Attr) && len(after.Attr) > 1 {
|
||||
var xmlns *xml.Attr
|
||||
i := 1
|
||||
for ; i < len(after.Attr); i++ {
|
||||
if after.Attr[i-1].Name.Space == "xmlns" && after.Attr[i-1].Name.Local == after.Attr[i].Name.Space {
|
||||
xmlns = &after.Attr[i-1]
|
||||
break
|
||||
}
|
||||
}
|
||||
if xmlns == nil {
|
||||
break
|
||||
}
|
||||
prefix := xmlns.Name.Local
|
||||
space := xmlns.Value
|
||||
copy(after.Attr[i-1:], after.Attr[i:])
|
||||
after.Attr = after.Attr[:len(after.Attr)-1]
|
||||
for j := range after.Attr {
|
||||
if after.Attr[j].Name.Space == prefix {
|
||||
after.Attr[j].Name.Space = space
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
1
vendor/github.com/russellhaering/goxmldsig/.gitignore
generated
vendored
Normal file
1
vendor/github.com/russellhaering/goxmldsig/.gitignore
generated
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
*.test
|
||||
11
vendor/github.com/russellhaering/goxmldsig/.travis.yml
generated
vendored
Normal file
11
vendor/github.com/russellhaering/goxmldsig/.travis.yml
generated
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
arch:
|
||||
- amd64
|
||||
- ppc64le
|
||||
|
||||
language: go
|
||||
|
||||
go:
|
||||
- "1.14.x"
|
||||
- "1.15.x"
|
||||
- "1.17.x"
|
||||
- master
|
||||
175
vendor/github.com/russellhaering/goxmldsig/LICENSE
generated
vendored
Normal file
175
vendor/github.com/russellhaering/goxmldsig/LICENSE
generated
vendored
Normal file
|
|
@ -0,0 +1,175 @@
|
|||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
90
vendor/github.com/russellhaering/goxmldsig/README.md
generated
vendored
Normal file
90
vendor/github.com/russellhaering/goxmldsig/README.md
generated
vendored
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
# goxmldsig
|
||||
|
||||
[](https://travis-ci.org/russellhaering/goxmldsig)
|
||||
[](https://godoc.org/github.com/russellhaering/goxmldsig)
|
||||
|
||||
XML Digital Signatures implemented in pure Go.
|
||||
|
||||
## Installation
|
||||
|
||||
Install `goxmldsig` using `go get`:
|
||||
|
||||
```
|
||||
$ go get github.com/russellhaering/goxmldsig
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Signing
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/beevik/etree"
|
||||
"github.com/russellhaering/goxmldsig"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Generate a key and self-signed certificate for signing
|
||||
randomKeyStore := dsig.RandomKeyStoreForTest()
|
||||
ctx := dsig.NewDefaultSigningContext(randomKeyStore)
|
||||
elementToSign := &etree.Element{
|
||||
Tag: "ExampleElement",
|
||||
}
|
||||
elementToSign.CreateAttr("ID", "id1234")
|
||||
|
||||
// Sign the element
|
||||
signedElement, err := ctx.SignEnveloped(elementToSign)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Serialize the signed element. It is important not to modify the element
|
||||
// after it has been signed - even pretty-printing the XML will invalidate
|
||||
// the signature.
|
||||
doc := etree.NewDocument()
|
||||
doc.SetRoot(signedElement)
|
||||
str, err := doc.WriteToString()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
println(str)
|
||||
}
|
||||
```
|
||||
|
||||
### Signature Validation
|
||||
|
||||
```go
|
||||
// Validate an element against a root certificate
|
||||
func validate(root *x509.Certificate, el *etree.Element) {
|
||||
// Construct a signing context with one or more roots of trust.
|
||||
ctx := dsig.NewDefaultValidationContext(&dsig.MemoryX509CertificateStore{
|
||||
Roots: []*x509.Certificate{root},
|
||||
})
|
||||
|
||||
// It is important to only use the returned validated element.
|
||||
// See: https://www.w3.org/TR/xmldsig-bestpractices/#check-what-is-signed
|
||||
validated, err := ctx.Validate(el)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
doc := etree.NewDocument()
|
||||
doc.SetRoot(validated)
|
||||
str, err := doc.WriteToString()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
println(str)
|
||||
}
|
||||
```
|
||||
|
||||
## Limitations
|
||||
|
||||
This library was created in order to [implement SAML 2.0](https://github.com/russellhaering/gosaml2)
|
||||
without needing to execute a command line tool to create and validate signatures. It currently
|
||||
only implements the subset of relevant standards needed to support that implementation, but
|
||||
I hope to make it more complete over time. Contributions are welcome.
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue