Skip to content

Commit 749ad0d

Browse files
committed
Update license and clean-up
1 parent b626b1d commit 749ad0d

File tree

15 files changed

+576
-150
lines changed

15 files changed

+576
-150
lines changed

LICENSE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
BSD 3-Clause License
22

33
Copyright (c) 2021, James Bowes
4+
Copyright (c) 2023, Alexander Taraymovich, OffBlocks
45
All rights reserved.
56

67
Redistribution and use in source and binary forms, with or without

README.md

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,37 @@ and the request path.
3333

3434
## Usage
3535

36+
### Standalone Signing and Verification
37+
38+
To sign a request, first instantiate a `Signer` using your preferred key and signing algorithm:
39+
40+
```go
41+
// Create a signer
42+
signer := httpsig.NewSigner(httpsig.WithSignEcdsaP256Sha256("key1", privKey))
43+
44+
// Create a request
45+
req, _ := http.NewRequest("GET", "https://some-url.com", nil)
46+
47+
// Sign the request
48+
header, _ := signer.Sign(httpsig.MessageFromRequest(req))
49+
50+
// Add the signature to the request
51+
req.Header = header
52+
```
53+
54+
To verify a response, instantiate a `Verifier` using your preferred key and signing algorithm:
55+
56+
```go
57+
// Receive a response from server
58+
resp, _ := client.Post("https://some-url.com", "application/json", &buf)
59+
60+
// Create a verifier
61+
verifier := httpsig.NewVerifier(httpsig.WithVerifyEcdsaP256Sha256("key1", pubKey))
62+
63+
// Verify the response
64+
err := verifier.Verify(httpsig.MessageFromResponse(resp))
65+
```
66+
3667
### Signing HTTP Requests in Clients
3768

3869
To sign HTTP requests from a client, wrap an `http.Client`'s transport with
@@ -119,15 +150,14 @@ computation is based on version `13` of [Digest Headers][dighdr]
119150

120151
## Contributing
121152

122-
I would love your help!
153+
We would love your help!
123154

124155
`httpsig` is still a work in progress. You can help by:
125156

126157
- Opening a pull request to resolve an [open issue][issues].
127158
- Adding a feature or enhancement of your own! If it might be big, please
128159
[open an issue][enhancement] first so we can discuss it.
129160
- Improving this `README` or adding other documentation to `httpsig`.
130-
- Letting [me] know if you're using `httpsig`.
131161

132162
<!-- These are mostly for pkg.go.dev, to show up in the header -->
133163
## Links
@@ -146,5 +176,3 @@ I would love your help!
146176
[issues]: ./issues
147177
[bug]: ./issues/new?labels=bug
148178
[enhancement]: ./issues/new?labels=enhancement
149-
150-
[me]: https://twitter.com/jrbowes

base.go

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,34 @@
1+
// BSD 3-Clause License
2+
3+
// Copyright (c) 2021, James Bowes
4+
// Copyright (c) 2023, Alexander Taraymovich, OffBlocks
5+
// All rights reserved.
6+
7+
// Redistribution and use in source and binary forms, with or without
8+
// modification, are permitted provided that the following conditions are met:
9+
10+
// 1. Redistributions of source code must retain the above copyright notice, this
11+
// list of conditions and the following disclaimer.
12+
13+
// 2. Redistributions in binary form must reproduce the above copyright notice,
14+
// this list of conditions and the following disclaimer in the documentation
15+
// and/or other materials provided with the distribution.
16+
17+
// 3. Neither the name of the copyright holder nor the names of its
18+
// contributors may be used to endorse or promote products derived from
19+
// this software without specific prior written permission.
20+
21+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22+
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24+
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25+
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26+
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27+
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28+
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29+
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
132
package httpsig
233

334
import (
@@ -59,7 +90,7 @@ func createSigningParameters(config *SignConfig) *httpsfv.Params {
5990
}
6091

6192
if slices.Contains(params, ParamKeyID) {
62-
// attempt to obtain an overriden key id, otherwise use the one supplied by the key
93+
// attempt to obtain an overridden key id, otherwise use the one supplied by the key
6394
var keyID *string
6495
if config.ParamValues != nil && config.ParamValues.KeyID != nil {
6596
keyID = config.ParamValues.KeyID
@@ -71,7 +102,7 @@ func createSigningParameters(config *SignConfig) *httpsfv.Params {
71102
}
72103

73104
if slices.Contains(params, ParamAlg) {
74-
// attempt to obtain an overriden algorithm, otherwise use the one supplied by the key
105+
// attempt to obtain an overridden algorithm, otherwise use the one supplied by the key
75106
var alg *Algorithm
76107
if config.ParamValues != nil && config.ParamValues.Alg != nil {
77108
alg = config.ParamValues.Alg

canonicalise.go

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,33 @@
1-
// Copyright (c) 2021 James Bowes. All rights reserved.
2-
// Use of this source code is governed by a BSD-style
3-
// license that can be found in the LICENSE file.
1+
// BSD 3-Clause License
2+
3+
// Copyright (c) 2021, James Bowes
4+
// Copyright (c) 2023, Alexander Taraymovich, OffBlocks
5+
// All rights reserved.
6+
7+
// Redistribution and use in source and binary forms, with or without
8+
// modification, are permitted provided that the following conditions are met:
9+
10+
// 1. Redistributions of source code must retain the above copyright notice, this
11+
// list of conditions and the following disclaimer.
12+
13+
// 2. Redistributions in binary form must reproduce the above copyright notice,
14+
// this list of conditions and the following disclaimer in the documentation
15+
// and/or other materials provided with the distribution.
16+
17+
// 3. Neither the name of the copyright holder nor the names of its
18+
// contributors may be used to endorse or promote products derived from
19+
// this software without specific prior written permission.
20+
21+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22+
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24+
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25+
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26+
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27+
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28+
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29+
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
431

532
package httpsig
633

digest.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,34 @@
1+
// BSD 3-Clause License
2+
3+
// Copyright (c) 2021, James Bowes
4+
// Copyright (c) 2023, Alexander Taraymovich, OffBlocks
5+
// All rights reserved.
6+
7+
// Redistribution and use in source and binary forms, with or without
8+
// modification, are permitted provided that the following conditions are met:
9+
10+
// 1. Redistributions of source code must retain the above copyright notice, this
11+
// list of conditions and the following disclaimer.
12+
13+
// 2. Redistributions in binary form must reproduce the above copyright notice,
14+
// this list of conditions and the following disclaimer in the documentation
15+
// and/or other materials provided with the distribution.
16+
17+
// 3. Neither the name of the copyright holder nor the names of its
18+
// contributors may be used to endorse or promote products derived from
19+
// this software without specific prior written permission.
20+
21+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22+
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24+
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25+
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26+
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27+
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28+
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29+
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
132
package httpsig
233

334
import (
@@ -15,6 +46,30 @@ type DigestConfig struct {
1546
Algorithms []DigestAlgorithm
1647
}
1748

49+
type Digestor struct {
50+
*digestor
51+
}
52+
53+
// NewDigestor creates a new digestor with the given options
54+
func NewDigestor(opts ...digestOption) *Digestor {
55+
d := digestor{}
56+
57+
for _, o := range opts {
58+
o.configureDigest(&d)
59+
}
60+
61+
if len(d.config.Algorithms) == 0 {
62+
d.config.Algorithms = []DigestAlgorithm{DigestAlgorithmSha256}
63+
}
64+
65+
return &Digestor{&d}
66+
}
67+
68+
// Digest creates a digest header for the given body
69+
func (d *Digestor) Digest(body []byte) (http.Header, error) {
70+
return d.digestor.Digest(body)
71+
}
72+
1873
type digestor struct {
1974
config DigestConfig
2075
}

digest_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,34 @@
1+
// BSD 3-Clause License
2+
3+
// Copyright (c) 2021, James Bowes
4+
// Copyright (c) 2023, Alexander Taraymovich, OffBlocks
5+
// All rights reserved.
6+
7+
// Redistribution and use in source and binary forms, with or without
8+
// modification, are permitted provided that the following conditions are met:
9+
10+
// 1. Redistributions of source code must retain the above copyright notice, this
11+
// list of conditions and the following disclaimer.
12+
13+
// 2. Redistributions in binary form must reproduce the above copyright notice,
14+
// this list of conditions and the following disclaimer in the documentation
15+
// and/or other materials provided with the distribution.
16+
17+
// 3. Neither the name of the copyright holder nor the names of its
18+
// contributors may be used to endorse or promote products derived from
19+
// this software without specific prior written permission.
20+
21+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22+
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24+
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25+
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26+
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27+
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28+
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29+
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
132
package httpsig
233

334
import (

doc.go

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,33 @@
1-
// Copyright (c) 2021 James Bowes. All rights reserved.
2-
// Use of this source code is governed by a BSD-style
3-
// license that can be found in the LICENSE file.
1+
// BSD 3-Clause License
2+
3+
// Copyright (c) 2021, James Bowes
4+
// Copyright (c) 2023, Alexander Taraymovich, OffBlocks
5+
// All rights reserved.
6+
7+
// Redistribution and use in source and binary forms, with or without
8+
// modification, are permitted provided that the following conditions are met:
9+
10+
// 1. Redistributions of source code must retain the above copyright notice, this
11+
// list of conditions and the following disclaimer.
12+
13+
// 2. Redistributions in binary form must reproduce the above copyright notice,
14+
// this list of conditions and the following disclaimer in the documentation
15+
// and/or other materials provided with the distribution.
16+
17+
// 3. Neither the name of the copyright holder nor the names of its
18+
// contributors may be used to endorse or promote products derived from
19+
// this software without specific prior written permission.
20+
21+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22+
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24+
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25+
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26+
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27+
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28+
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29+
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
431

532
/*
633
Package httpsig signs and verifies HTTP requests (with body digests) according

example_test.go

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,33 @@
1-
// Copyright (c) 2021 James Bowes. All rights reserved.
2-
// Use of this source code is governed by a BSD-style
3-
// license that can be found in the LICENSE file
1+
// BSD 3-Clause License
2+
3+
// Copyright (c) 2021, James Bowes
4+
// Copyright (c) 2023, Alexander Taraymovich, OffBlocks
5+
// All rights reserved.
6+
7+
// Redistribution and use in source and binary forms, with or without
8+
// modification, are permitted provided that the following conditions are met:
9+
10+
// 1. Redistributions of source code must retain the above copyright notice, this
11+
// list of conditions and the following disclaimer.
12+
13+
// 2. Redistributions in binary form must reproduce the above copyright notice,
14+
// this list of conditions and the following disclaimer in the documentation
15+
// and/or other materials provided with the distribution.
16+
17+
// 3. Neither the name of the copyright holder nor the names of its
18+
// contributors may be used to endorse or promote products derived from
19+
// this software without specific prior written permission.
20+
21+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22+
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24+
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25+
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26+
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27+
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28+
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29+
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
431

532
package httpsig_test
633

0 commit comments

Comments
 (0)