mirror of
https://git.asonix.dog/asonix/http-signature-normalization.git
synced 2024-06-02 21:39:34 +00:00
Compare commits
42 commits
http-signa
...
main
Author | SHA1 | Date | |
---|---|---|---|
3d7b620bc0 | |||
07413815d5 | |||
c38072e65d | |||
47d28c6f47 | |||
47d07e7f1f | |||
b89acf7918 | |||
bf8e0e5f69 | |||
369a1e8a96 | |||
6e0a6fa3a2 | |||
f0dc14d5f1 | |||
92a73f0313 | |||
e8588efda7 | |||
6acd291315 | |||
ef266eed95 | |||
c1d36000dd | |||
ec73fe55c9 | |||
ff0290a488 | |||
ce2d14824e | |||
bbafc22d08 | |||
8750783667 | |||
ea964decc8 | |||
1f23b72140 | |||
e526699c87 | |||
cb198f6922 | |||
40ace55619 | |||
5de17a130b | |||
ac25b1d951 | |||
c7cb3ce602 | |||
85bbcb0bae | |||
b53c88fc2e | |||
356c801dac | |||
3e2639670e | |||
1224b3201c | |||
3734b8201f | |||
ca4e9e8b9c | |||
aae38f490d | |||
c8f1489ad9 | |||
2fdd82e949 | |||
953b75a22d | |||
69e607bf7a | |||
deec774ffc | |||
19d3c28116 |
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -2,3 +2,5 @@
|
|||
/target
|
||||
**/*.rs.bk
|
||||
Cargo.lock
|
||||
/.direnv
|
||||
/.envrc
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
[package]
|
||||
name = "http-signature-normalization"
|
||||
description = "An HTTP Signatures library that leaves the signing to you"
|
||||
version = "0.6.0"
|
||||
version = "0.7.0"
|
||||
authors = ["asonix <asonix@asonix.dog>"]
|
||||
license-file = "LICENSE"
|
||||
license = "AGPL-3.0"
|
||||
readme = "README.md"
|
||||
repository = "https://git.asonix.dog/Aardwolf/http-signature-normalization"
|
||||
keywords = ["http", "signatures", "digest"]
|
||||
|
|
20
README.md
20
README.md
|
@ -41,19 +41,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
```
|
||||
|
||||
### Contributing
|
||||
Unless otherwise stated, all contributions to this project will be licensed under the CSL with
|
||||
the exceptions listed in the License section of this file.
|
||||
Feel free to open issues for anything you find an issue with. Please note that any contributed code will be licensed under the AGPLv3.
|
||||
|
||||
### License
|
||||
This work is licensed under the Cooperative Software License. This is not a Free Software
|
||||
License, but may be considered a "source-available License." For most hobbyists, self-employed
|
||||
developers, worker-owned companies, and cooperatives, this software can be used in most
|
||||
projects so long as this software is distributed under the terms of the CSL. For more
|
||||
information, see the provided LICENSE file. If none exists, the license can be found online
|
||||
[here](https://lynnesbian.space/csl/). If you are a free software project and wish to use this
|
||||
software under the terms of the GNU Affero General Public License, please contact me at
|
||||
[asonix@asonix.dog](mailto:asonix@asonix.dog) and we can sort that out. If you wish to use this
|
||||
project under any other license, especially in proprietary software, the answer is likely no.
|
||||
Copyright © 2022 Riley Trautman
|
||||
|
||||
Http Signature Normalization is currently licensed under the AGPL to the Lemmy project, found
|
||||
at [github.com/LemmyNet/lemmy](https://github.com/LemmyNet/lemmy)
|
||||
HTTP Signature Normalization is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
HTTP Signature Normalization is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. This file is part of HTTP Signature Normalization.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with HTTP Signature Normalization. If not, see [http://www.gnu.org/licenses/](http://www.gnu.org/licenses/).
|
||||
|
|
|
@ -1,6 +1,13 @@
|
|||
[package]
|
||||
name = "http-signature-normalization-actix-extractor"
|
||||
version = "0.1.0"
|
||||
description = "An HTTP Signatures library that leaves the signing to you"
|
||||
version = "0.2.0"
|
||||
authors = ["asonix <asonix@asonix.dog>"]
|
||||
license = "AGPL-3.0"
|
||||
readme = "README.md"
|
||||
repository = "https://git.asonix.dog/asonix/http-signature-normalization"
|
||||
documentation = "https://docs.rs/http-signature-normalization-actix-extractor"
|
||||
keywords = ["http", "signatures", "digest", "actix"]
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
@ -13,10 +20,11 @@ base64 = { version = "0.13", optional = true }
|
|||
actix-web = { version = "4", default-features = false }
|
||||
actix-web-lab = "0.18.5"
|
||||
async-trait = "0.1.58"
|
||||
http-signature-normalization = { version = "0.6", path = "../" }
|
||||
http-signature-normalization = { version = "0.7", path = "../" }
|
||||
sha2 = { version = "0.10", optional = true }
|
||||
subtle = { version = "2.4.1", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
actix-web = { version = "4", features = ["macros"] }
|
||||
openssl = { version = "0.10.43", features = ["vendored"] }
|
||||
thiserror = "1"
|
||||
|
|
661
actix-extractor/LICENSE
Normal file
661
actix-extractor/LICENSE
Normal file
|
@ -0,0 +1,661 @@
|
|||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3, 19 November 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU Affero General Public License is a free, copyleft license for
|
||||
software and other kinds of works, specifically designed to ensure
|
||||
cooperation with the community in the case of network server software.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
our General Public Licenses are intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
Developers that use our General Public Licenses protect your rights
|
||||
with two steps: (1) assert copyright on the software, and (2) offer
|
||||
you this License which gives you legal permission to copy, distribute
|
||||
and/or modify the software.
|
||||
|
||||
A secondary benefit of defending all users' freedom is that
|
||||
improvements made in alternate versions of the program, if they
|
||||
receive widespread use, become available for other developers to
|
||||
incorporate. Many developers of free software are heartened and
|
||||
encouraged by the resulting cooperation. However, in the case of
|
||||
software used on network servers, this result may fail to come about.
|
||||
The GNU General Public License permits making a modified version and
|
||||
letting the public access it on a server without ever releasing its
|
||||
source code to the public.
|
||||
|
||||
The GNU Affero General Public License is designed specifically to
|
||||
ensure that, in such cases, the modified source code becomes available
|
||||
to the community. It requires the operator of a network server to
|
||||
provide the source code of the modified version running there to the
|
||||
users of that server. Therefore, public use of a modified version, on
|
||||
a publicly accessible server, gives the public access to the source
|
||||
code of the modified version.
|
||||
|
||||
An older license, called the Affero General Public License and
|
||||
published by Affero, was designed to accomplish similar goals. This is
|
||||
a different license, not a version of the Affero GPL, but Affero has
|
||||
released a new version of the Affero GPL which permits relicensing under
|
||||
this license.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, if you modify the
|
||||
Program, your modified version must prominently offer all users
|
||||
interacting with it remotely through a computer network (if your version
|
||||
supports such interaction) an opportunity to receive the Corresponding
|
||||
Source of your version by providing access to the Corresponding Source
|
||||
from a network server at no charge, through some standard or customary
|
||||
means of facilitating copying of software. This Corresponding Source
|
||||
shall include the Corresponding Source for any work covered by version 3
|
||||
of the GNU General Public License that is incorporated pursuant to the
|
||||
following paragraph.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the work with which it is combined will remain governed by version
|
||||
3 of the GNU General Public License.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU Affero General Public License from time to time. Such new versions
|
||||
will be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU Affero General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU Affero General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU Affero General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published
|
||||
by the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If your software can interact with users remotely through a computer
|
||||
network, you should also make sure that it provides a way for users to
|
||||
get its source. For example, if your program is a web application, its
|
||||
interface could display a "Source" link that leads users to an archive
|
||||
of the code. There are many ways you could offer source, and different
|
||||
solutions will be better for different programs; see section 13 for the
|
||||
specific requirements.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
123
actix-extractor/README.md
Normal file
123
actix-extractor/README.md
Normal file
|
@ -0,0 +1,123 @@
|
|||
# Http Signature Normalization Actix-Web Extractor
|
||||
_Experimental Extractor for request signatures_
|
||||
|
||||
- [crates.io](https://crates.io/crates/http-signature-normalization-actix-extractor)
|
||||
- [docs.rs](https://docs.rs/http-signature-normalization-actix-extractor)
|
||||
- [Hit me up on Mastodon](https://masto.asonix.dog/@asonix)
|
||||
|
||||
Http Signature Normalization is a minimal-dependency crate for producing HTTP Signatures with user-provided signing and verification. The API is simple; there's a series of steps for creation and verification with types that ensure reasonable usage. This library takes a different approach from the other implementation, which prefers Middlewares.
|
||||
|
||||
## Usage
|
||||
|
||||
This crate provides extensions the ClientRequest type from Actix Web, and provides middlewares for verifying HTTP Signatures, and optionally, Digest headers
|
||||
|
||||
#### First, add this crate to your dependencies
|
||||
```toml
|
||||
actix-rt = "2.7.0"
|
||||
actix-web = "4.0.0"
|
||||
thiserror = "1"
|
||||
http-signature-normalization-actix-extractor = "0.1.0"
|
||||
sha2 = "0.10"
|
||||
```
|
||||
|
||||
#### Then, use it in your client
|
||||
|
||||
```rust
|
||||
use actix_web::{http::StatusCode, web, App, HttpRequest, HttpResponse, HttpServer, ResponseError};
|
||||
use http_signature_normalization_actix_extractor::{
|
||||
Algorithm, Config, ConfigGenerator, DeprecatedAlgorithm, Signed, VerifyKey,
|
||||
};
|
||||
use sha2::Sha256;
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
HttpServer::new(|| App::new().route("/", web::post().to(protected)))
|
||||
.bind("127.0.0.1:8010")?
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
|
||||
async fn protected(signed_request: Signed<String, Cfg, Sha256, Key>) -> &'static str {
|
||||
let (value, signature) = signed_request.into_parts();
|
||||
|
||||
println!("{}", value);
|
||||
println!("{:#?}", signature);
|
||||
|
||||
"hewwo, mr obama"
|
||||
}
|
||||
|
||||
pub struct Cfg;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Key;
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum VerifyError {
|
||||
#[error("Unsupported algorithm")]
|
||||
Algorithm,
|
||||
|
||||
#[error("Couldn't decode signature")]
|
||||
Decode,
|
||||
|
||||
#[error("Invalid key")]
|
||||
Key,
|
||||
}
|
||||
|
||||
impl ConfigGenerator for Cfg {
|
||||
fn config() -> Config {
|
||||
Config::new().require_header("accept")
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl VerifyKey for Key {
|
||||
type Error = VerifyError;
|
||||
|
||||
async fn init(
|
||||
_: &HttpRequest,
|
||||
key_id: &str,
|
||||
algorithm: Option<&Algorithm>,
|
||||
) -> Result<Self, Self::Error> {
|
||||
match algorithm {
|
||||
Some(Algorithm::Hs2019 | Algorithm::Deprecated(DeprecatedAlgorithm::RsaSha256)) => (),
|
||||
_ => return Err(VerifyError::Algorithm),
|
||||
};
|
||||
|
||||
if key_id != "my-key-id" {
|
||||
return Err(VerifyError::Key);
|
||||
}
|
||||
|
||||
Ok(Key)
|
||||
}
|
||||
|
||||
fn verify(&mut self, signature: &str, signing_string: &str) -> Result<bool, Self::Error> {
|
||||
use subtle::ConstantTimeEq;
|
||||
|
||||
let decoded = base64::decode(&signature).map_err(|_| VerifyError::Decode)?;
|
||||
|
||||
Ok(decoded.ct_eq(signing_string.as_bytes()).into())
|
||||
}
|
||||
}
|
||||
|
||||
impl ResponseError for VerifyError {
|
||||
fn status_code(&self) -> StatusCode {
|
||||
StatusCode::BAD_REQUEST
|
||||
}
|
||||
|
||||
fn error_response(&self) -> HttpResponse {
|
||||
HttpResponse::BadRequest().finish()
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Contributing
|
||||
Feel free to open issues for anything you find an issue with. Please note that any contributed code will be licensed under the AGPLv3.
|
||||
|
||||
### License
|
||||
Copyright © 2022 Riley Trautman
|
||||
|
||||
HTTP Signature Normalization Actix Extractor is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
HTTP Signature Normalization Actix Extractor is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. This file is part of HTTP Signature Normalization Actix Extractor.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with HTTP Signature Normalization Actix Extractor. If not, see [http://www.gnu.org/licenses/](http://www.gnu.org/licenses/).
|
|
@ -27,7 +27,7 @@ pub struct Cfg;
|
|||
pub struct Key;
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum MyError {
|
||||
pub enum VerifyError {
|
||||
#[error("Unsupported algorithm")]
|
||||
Algorithm,
|
||||
|
||||
|
@ -46,7 +46,7 @@ impl ConfigGenerator for Cfg {
|
|||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl VerifyKey for Key {
|
||||
type Error = MyError;
|
||||
type Error = VerifyError;
|
||||
|
||||
async fn init(
|
||||
_: &HttpRequest,
|
||||
|
@ -55,11 +55,11 @@ impl VerifyKey for Key {
|
|||
) -> Result<Self, Self::Error> {
|
||||
match algorithm {
|
||||
Some(Algorithm::Hs2019 | Algorithm::Deprecated(DeprecatedAlgorithm::RsaSha256)) => (),
|
||||
_ => return Err(MyError::Algorithm),
|
||||
_ => return Err(VerifyError::Algorithm),
|
||||
};
|
||||
|
||||
if key_id != "my-key-id" {
|
||||
return Err(MyError::Key);
|
||||
return Err(VerifyError::Key);
|
||||
}
|
||||
|
||||
Ok(Key)
|
||||
|
@ -68,16 +68,13 @@ impl VerifyKey for Key {
|
|||
fn verify(&mut self, signature: &str, signing_string: &str) -> Result<bool, Self::Error> {
|
||||
use subtle::ConstantTimeEq;
|
||||
|
||||
let decoded = match base64::decode(&signature) {
|
||||
Ok(decoded) => decoded,
|
||||
Err(_) => return Err(MyError::Decode),
|
||||
};
|
||||
let decoded = base64::decode(&signature).map_err(|_| VerifyError::Decode)?;
|
||||
|
||||
Ok(decoded.ct_eq(signing_string.as_bytes()).into())
|
||||
}
|
||||
}
|
||||
|
||||
impl ResponseError for MyError {
|
||||
impl ResponseError for VerifyError {
|
||||
fn status_code(&self) -> StatusCode {
|
||||
StatusCode::BAD_REQUEST
|
||||
}
|
||||
|
|
|
@ -1,72 +1,140 @@
|
|||
// #![deny(missing_docs)]
|
||||
#![deny(missing_docs)]
|
||||
|
||||
//! Experimental Extractor for request signatures
|
||||
//! # Http Signature Normalization Actix Extractor
|
||||
//! _Experimental Extractor for request signatures_
|
||||
//!
|
||||
//! This library takes a different approach from the other implementation, which prefers
|
||||
//! Middlewares.
|
||||
//!
|
||||
//! ```rust
|
||||
//! use actix_web::{http::StatusCode, web, App, HttpRequest, HttpResponse, HttpServer, ResponseError};
|
||||
//! use http_signature_normalization_actix_extractor::{
|
||||
//! Algorithm, Config, ConfigGenerator, DeprecatedAlgorithm, Signed, VerifyKey,
|
||||
//! };
|
||||
//! use sha2::Sha256;
|
||||
//!
|
||||
//! #[actix_web::main]
|
||||
//! async fn main() -> std::io::Result<()> {
|
||||
//! /*
|
||||
//! HttpServer::new(|| App::new().route("/", web::post().to(protected)))
|
||||
//! .bind("127.0.0.1:8010")?
|
||||
//! .run()
|
||||
//! .await
|
||||
//! */
|
||||
//! Ok(())
|
||||
//! }
|
||||
//!
|
||||
//! async fn protected(signed_request: Signed<String, Cfg, Sha256, Key>) -> &'static str {
|
||||
//! let (value, signature) = signed_request.into_parts();
|
||||
//!
|
||||
//! println!("{}", value);
|
||||
//! println!("{:#?}", signature);
|
||||
//!
|
||||
//! "hewwo, mr obama"
|
||||
//! }
|
||||
//!
|
||||
//! pub struct Cfg;
|
||||
//!
|
||||
//! #[derive(Debug)]
|
||||
//! pub struct Key;
|
||||
//!
|
||||
//! #[derive(Debug, thiserror::Error)]
|
||||
//! pub enum VerifyError {
|
||||
//! #[error("Unsupported algorithm")]
|
||||
//! Algorithm,
|
||||
//!
|
||||
//! #[error("Couldn't decode signature")]
|
||||
//! Decode,
|
||||
//!
|
||||
//! #[error("Invalid key")]
|
||||
//! Key,
|
||||
//! }
|
||||
//!
|
||||
//! impl ConfigGenerator for Cfg {
|
||||
//! fn config() -> Config {
|
||||
//! Config::new().require_header("accept")
|
||||
//! }
|
||||
//! }
|
||||
//!
|
||||
//! #[async_trait::async_trait(?Send)]
|
||||
//! impl VerifyKey for Key {
|
||||
//! type Error = VerifyError;
|
||||
//!
|
||||
//! async fn init(
|
||||
//! _: &HttpRequest,
|
||||
//! key_id: &str,
|
||||
//! algorithm: Option<&Algorithm>,
|
||||
//! ) -> Result<Self, Self::Error> {
|
||||
//! match algorithm {
|
||||
//! Some(Algorithm::Hs2019 | Algorithm::Deprecated(DeprecatedAlgorithm::RsaSha256)) => (),
|
||||
//! _ => return Err(VerifyError::Algorithm),
|
||||
//! };
|
||||
//!
|
||||
//! if key_id != "my-key-id" {
|
||||
//! return Err(VerifyError::Key);
|
||||
//! }
|
||||
//!
|
||||
//! Ok(Key)
|
||||
//! }
|
||||
//!
|
||||
//! fn verify(&mut self, signature: &str, signing_string: &str) -> Result<bool, Self::Error> {
|
||||
//! use subtle::ConstantTimeEq;
|
||||
//!
|
||||
//! let decoded = base64::decode(&signature).map_err(|_| VerifyError::Decode)?;
|
||||
//!
|
||||
//! Ok(decoded.ct_eq(signing_string.as_bytes()).into())
|
||||
//! }
|
||||
//! }
|
||||
//!
|
||||
//! impl ResponseError for VerifyError {
|
||||
//! fn status_code(&self) -> StatusCode {
|
||||
//! StatusCode::BAD_REQUEST
|
||||
//! }
|
||||
//!
|
||||
//! fn error_response(&self) -> HttpResponse {
|
||||
//! HttpResponse::BadRequest().finish()
|
||||
//! }
|
||||
//! }
|
||||
//! ```
|
||||
|
||||
pub use actix_web_lab::extract::RequestSignature;
|
||||
pub use http_signature_normalization::{
|
||||
verify::{Algorithm, DeprecatedAlgorithm},
|
||||
Config,
|
||||
Config, PrepareVerifyError,
|
||||
};
|
||||
|
||||
/// An alias to simplify extracting a signed request
|
||||
/// ```rust,ignore
|
||||
/// async fn protected(_: Signed<String, (), (), Key>) -> &'static str {
|
||||
/// "hewwo, mr obama"
|
||||
/// }
|
||||
/// ```
|
||||
pub type Signed<Extractor, Config, Digest, VerifyKey> =
|
||||
RequestSignature<Extractor, SignatureScheme<Config, Digest, VerifyKey>>;
|
||||
RequestSignature<Extractor, SignedRequest<Config, Digest, VerifyKey>>;
|
||||
|
||||
#[cfg(feature = "sha-2")]
|
||||
mod sha2_digest;
|
||||
|
||||
#[derive(Debug)]
|
||||
/// Errors produced by the Extractor
|
||||
pub enum Error {
|
||||
/// The provided Digest header was invalid
|
||||
Digest,
|
||||
|
||||
/// The provided Signature or Authorization header was invalid
|
||||
Signature,
|
||||
|
||||
/// Another header required for verifying the signature is invalid
|
||||
InvalidHeaderValue,
|
||||
PrepareVerify(http_signature_normalization::PrepareVerifyError),
|
||||
|
||||
/// There was an error preparing for verification
|
||||
PrepareVerify(PrepareVerifyError),
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::Digest => write!(f, "Digest is inavlid"),
|
||||
Self::Signature => write!(f, "Signature is invalid"),
|
||||
Self::InvalidHeaderValue => write!(f, "Invalid header value"),
|
||||
Self::PrepareVerify(_) => write!(f, "Error preparint verification"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for Error {
|
||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||
match self {
|
||||
Self::PrepareVerify(ref e) => Some(e),
|
||||
Self::Digest => None,
|
||||
Self::Signature => None,
|
||||
Self::InvalidHeaderValue => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl actix_web::ResponseError for Error {
|
||||
fn status_code(&self) -> actix_web::http::StatusCode {
|
||||
actix_web::http::StatusCode::BAD_REQUEST
|
||||
}
|
||||
|
||||
fn error_response(&self) -> actix_web::HttpResponse<actix_web::body::BoxBody> {
|
||||
actix_web::HttpResponse::build(self.status_code()).finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<http_signature_normalization::PrepareVerifyError> for Error {
|
||||
fn from(e: http_signature_normalization::PrepareVerifyError) -> Self {
|
||||
Error::PrepareVerify(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<actix_web::http::header::ToStrError> for Error {
|
||||
fn from(_: actix_web::http::header::ToStrError) -> Self {
|
||||
Error::InvalidHeaderValue
|
||||
}
|
||||
}
|
||||
|
||||
pub struct SignatureScheme<C, D, K> {
|
||||
/// The SignedRequest Signature scheme
|
||||
///
|
||||
/// This implements SignatureScheme to allow extracing a signed request
|
||||
pub struct SignedRequest<C, D, K> {
|
||||
config_generator: std::marker::PhantomData<C>,
|
||||
key: std::marker::PhantomData<K>,
|
||||
digest_verifier: Option<D>,
|
||||
|
@ -74,12 +142,17 @@ pub struct SignatureScheme<C, D, K> {
|
|||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
/// A parsed part of a Digest header
|
||||
pub struct DigestPart {
|
||||
/// The Algorithm this digest was computed with
|
||||
pub algorithm: String,
|
||||
|
||||
/// The base64-encoded digest
|
||||
pub digest: String,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
/// All the required pieces for validating a request signature
|
||||
pub struct Signature<D, K> {
|
||||
key: K,
|
||||
unverified: http_signature_normalization::verify::Unverified,
|
||||
|
@ -87,37 +160,174 @@ pub struct Signature<D, K> {
|
|||
digest_parts: Option<Vec<DigestPart>>,
|
||||
}
|
||||
|
||||
pub trait DigestName {
|
||||
const NAME: &'static str;
|
||||
}
|
||||
|
||||
/// Injects a customized [`Config`] type for signature verification
|
||||
///
|
||||
/// If you don't need to customize the `Config`, you can use `()`
|
||||
///
|
||||
/// ```rust
|
||||
/// use http_signature_normalization_actix_extractor::{Config, ConfigGenerator};
|
||||
///
|
||||
/// struct Gen;
|
||||
///
|
||||
/// impl ConfigGenerator for Gen {
|
||||
/// fn config() -> Config {
|
||||
/// Config::new()
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
pub trait ConfigGenerator {
|
||||
/// Produce a new `Config`
|
||||
fn config() -> Config;
|
||||
}
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
/// Extracts a key from the request
|
||||
///
|
||||
/// ```rust
|
||||
/// use actix_web::{http::StatusCode, web::Data, HttpRequest, HttpResponse, ResponseError};
|
||||
/// use http_signature_normalization_actix_extractor::{Algorithm, DeprecatedAlgorithm, VerifyKey};
|
||||
/// use openssl::{hash::MessageDigest, pkey::{PKey, Public}, sign::Verifier};
|
||||
///
|
||||
/// pub struct OpenSSLPublicKey(PKey<Public>);
|
||||
///
|
||||
/// #[async_trait::async_trait(?Send)]
|
||||
/// impl VerifyKey for OpenSSLPublicKey {
|
||||
/// type Error = VerifyError;
|
||||
///
|
||||
/// async fn init(
|
||||
/// req: &HttpRequest,
|
||||
/// key_id: &str,
|
||||
/// algorithm: Option<&Algorithm>,
|
||||
/// ) -> Result<Self, Self::Error> {
|
||||
/// match algorithm {
|
||||
/// Some(Algorithm::Hs2019 | Algorithm::Deprecated(DeprecatedAlgorithm::RsaSha256)) => (),
|
||||
/// _ => return Err(VerifyError::Algorithm),
|
||||
/// };
|
||||
///
|
||||
/// if key_id != "my-key-id" {
|
||||
/// return Err(VerifyError::Key);
|
||||
/// }
|
||||
///
|
||||
/// let key = req.app_data::<Data<PKey<Public>>>().expect("Key loaded").as_ref().clone();
|
||||
///
|
||||
/// Ok(OpenSSLPublicKey(key))
|
||||
/// }
|
||||
///
|
||||
/// fn verify(&mut self, signature: &str, signing_string: &str) -> Result<bool, Self::Error> {
|
||||
/// let decoded = openssl::base64::decode_block(&signature).map_err(|_| VerifyError::Decode)?;
|
||||
///
|
||||
/// let verifier = Verifier::new(MessageDigest::sha256(), &self.0).map_err(|_| VerifyError::Verifier)?;
|
||||
///
|
||||
/// verifier.verify(&decoded).map_err(|_| VerifyError::Verify)
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
/// #[derive(Debug, thiserror::Error)]
|
||||
/// pub enum VerifyError {
|
||||
/// #[error("Unsupported algorithm")]
|
||||
/// Algorithm,
|
||||
///
|
||||
/// #[error("Couldn't decode signature")]
|
||||
/// Decode,
|
||||
///
|
||||
/// #[error("Invalid key")]
|
||||
/// Key,
|
||||
///
|
||||
/// #[error("Failed to create Verifier from key")]
|
||||
/// Verifier,
|
||||
///
|
||||
/// #[error("Failed to verify signature")]
|
||||
/// Verify,
|
||||
/// }
|
||||
///
|
||||
/// impl ResponseError for VerifyError {
|
||||
/// fn status_code(&self) -> StatusCode {
|
||||
/// StatusCode::BAD_REQUEST
|
||||
/// }
|
||||
///
|
||||
/// fn error_response(&self) -> HttpResponse {
|
||||
/// HttpResponse::BadRequest().finish()
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
pub trait VerifyKey: Sized + Send {
|
||||
/// Errors that can happen when extracting keys or verifying the signature
|
||||
type Error: Into<actix_web::Error>;
|
||||
|
||||
/// Extract the key from the request, given the key_id and algorithm
|
||||
async fn init(
|
||||
req: &actix_web::HttpRequest,
|
||||
key_id: &str,
|
||||
algorithm: Option<&Algorithm>,
|
||||
) -> Result<Self, Self::Error>;
|
||||
|
||||
/// Verify the signature with the given signing string
|
||||
fn verify(&mut self, signature: &str, signing_string: &str) -> Result<bool, Self::Error>;
|
||||
}
|
||||
|
||||
/// Verifies the Digest header from the request
|
||||
///
|
||||
/// For endpoints that do not accept request bodies, `()` can be used as the verifier
|
||||
///
|
||||
/// ### Example:
|
||||
/// ```rust
|
||||
/// use http_signature_normalization_actix_extractor::{DigestPart, VerifyDigest};
|
||||
/// use openssl::sha::Sha256;
|
||||
///
|
||||
/// struct OpenSSLSha256(Option<Sha256>);
|
||||
///
|
||||
/// impl Default for OpenSSLSha256 {
|
||||
/// fn default() -> Self {
|
||||
/// Self::new()
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
/// impl OpenSSLSha256 {
|
||||
/// fn new() -> Self {
|
||||
/// Self(Some(Sha256::new()))
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
/// impl VerifyDigest for OpenSSLSha256 {
|
||||
/// fn update(&mut self, bytes: &[u8]) {
|
||||
/// self.0.as_mut().expect("Update called after verify").update(bytes);
|
||||
/// }
|
||||
///
|
||||
/// fn verify(&mut self, parts: &[DigestPart]) -> bool {
|
||||
/// if let Some(decoded) = parts.iter().find_map(|p| {
|
||||
/// if p.algorithm.to_lowercase() == "sha-256" {
|
||||
/// openssl::base64::decode_block(&p.digest).ok()
|
||||
/// } else {
|
||||
/// None
|
||||
/// }
|
||||
/// }) {
|
||||
/// return openssl::memcmp::eq(
|
||||
/// &self.0.take().expect("verify called more than once").finish(),
|
||||
/// &decoded,
|
||||
/// );
|
||||
/// }
|
||||
///
|
||||
/// false
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
pub trait VerifyDigest: Default + Send + 'static {
|
||||
/// Whether to run this verifier
|
||||
const REQUIRED: bool = true;
|
||||
|
||||
/// Update the verifier with th eprovided bytes
|
||||
fn update(&mut self, bytes: &[u8]);
|
||||
|
||||
/// Given a slice of parts, verify that the one matching the current verifier is valid
|
||||
fn verify(&mut self, parts: &[DigestPart]) -> bool;
|
||||
}
|
||||
|
||||
trait DigestName {
|
||||
const NAME: &'static str;
|
||||
}
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl<C, D, K> actix_web_lab::extract::RequestSignatureScheme for SignatureScheme<C, D, K>
|
||||
impl<C, D, K> actix_web_lab::extract::RequestSignatureScheme for SignedRequest<C, D, K>
|
||||
where
|
||||
C: ConfigGenerator,
|
||||
D: VerifyDigest,
|
||||
|
@ -137,7 +347,7 @@ where
|
|||
req.headers(),
|
||||
)?;
|
||||
|
||||
Ok(SignatureScheme {
|
||||
Ok(SignedRequest {
|
||||
config_generator: std::marker::PhantomData,
|
||||
key: std::marker::PhantomData,
|
||||
digest_verifier: Some(D::default()),
|
||||
|
@ -283,3 +493,47 @@ impl VerifyDigest for () {
|
|||
true
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::Digest => write!(f, "Digest is inavlid"),
|
||||
Self::Signature => write!(f, "Signature is invalid"),
|
||||
Self::InvalidHeaderValue => write!(f, "Invalid header value"),
|
||||
Self::PrepareVerify(_) => write!(f, "Error preparint verification"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for Error {
|
||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||
match self {
|
||||
Self::PrepareVerify(ref e) => Some(e),
|
||||
Self::Digest => None,
|
||||
Self::Signature => None,
|
||||
Self::InvalidHeaderValue => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl actix_web::ResponseError for Error {
|
||||
fn status_code(&self) -> actix_web::http::StatusCode {
|
||||
actix_web::http::StatusCode::BAD_REQUEST
|
||||
}
|
||||
|
||||
fn error_response(&self) -> actix_web::HttpResponse<actix_web::body::BoxBody> {
|
||||
actix_web::HttpResponse::build(self.status_code()).finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PrepareVerifyError> for Error {
|
||||
fn from(e: PrepareVerifyError) -> Self {
|
||||
Error::PrepareVerify(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<actix_web::http::header::ToStrError> for Error {
|
||||
fn from(_: actix_web::http::header::ToStrError) -> Self {
|
||||
Error::InvalidHeaderValue
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
[package]
|
||||
name = "http-signature-normalization-actix"
|
||||
description = "An HTTP Signatures library that leaves the signing to you"
|
||||
version = "0.6.2"
|
||||
version = "0.11.1"
|
||||
authors = ["asonix <asonix@asonix.dog>"]
|
||||
license-file = "LICENSE"
|
||||
license = "AGPL-3.0"
|
||||
readme = "README.md"
|
||||
repository = "https://git.asonix.dog/Aardwolf/http-signature-normalization"
|
||||
keywords = ["http", "signatures", "digest", "actix"]
|
||||
|
@ -12,30 +12,33 @@ edition = "2021"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
[features]
|
||||
default = ["server", "sha-2", "sha-3"]
|
||||
client = ["awc"]
|
||||
digest = ["base64"]
|
||||
server = ["actix-web"]
|
||||
sha-2 = ["digest", "sha2"]
|
||||
sha-3 = ["digest", "sha3"]
|
||||
client = ["dep:awc"]
|
||||
digest = ["dep:base64"]
|
||||
server = ["dep:actix-web"]
|
||||
sha-2 = ["digest", "dep:sha2"]
|
||||
sha-3 = ["digest", "dep:sha3"]
|
||||
ring = ["digest", "dep:ring"]
|
||||
|
||||
[[example]]
|
||||
name = "server"
|
||||
required-features = ["server", "sha-2"]
|
||||
required-features = ["server", "ring"]
|
||||
|
||||
[[example]]
|
||||
name = "client"
|
||||
required-features = ["client", "sha-2"]
|
||||
required-features = ["client", "ring"]
|
||||
|
||||
[dependencies]
|
||||
actix-http = { version = "3.0.2", default-features = false }
|
||||
actix-rt = "2.6.0"
|
||||
actix-web = { version = "4.0.0", default-features = false, optional = true }
|
||||
awc = { version = "3.0.0", default-features = false, optional = true }
|
||||
base64 = { version = "0.13", optional = true }
|
||||
futures-util = { version = "0.3", default-features = false }
|
||||
http-signature-normalization = { version = "0.6.0", path = ".." }
|
||||
base64 = { version = "0.22", optional = true }
|
||||
futures-core = "0.3.28"
|
||||
http-signature-normalization = { version = "0.7.0", path = ".." }
|
||||
ring = { version = "0.17.5", optional = true }
|
||||
sha2 = { version = "0.10", optional = true }
|
||||
sha3 = { version = "0.10", optional = true }
|
||||
streem = "0.2.0"
|
||||
thiserror = "1.0"
|
||||
tokio = { version = "1", default-features = false, features = ["sync"] }
|
||||
tracing = "0.1"
|
||||
|
@ -44,7 +47,7 @@ tracing-futures = "0.2"
|
|||
|
||||
[dev-dependencies]
|
||||
actix-rt = "2.6.0"
|
||||
tracing-actix-web = { version = "0.6.0" }
|
||||
tracing-actix-web = { version = "0.7.0" }
|
||||
tracing-subscriber = { version = "0.3", features = ["env-filter", "fmt"] }
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
|
|
968
actix/LICENSE
968
actix/LICENSE
File diff suppressed because it is too large
Load diff
|
@ -1,4 +1,4 @@
|
|||
# HTTP Signature Normaliztion Actix
|
||||
# HTTP Signature Normalization Actix
|
||||
_An HTTP Signatures library that leaves the signing to you_
|
||||
|
||||
- [crates.io](https://crates.io/crates/http-signature-normalization-actix)
|
||||
|
@ -16,7 +16,7 @@ This crate provides extensions the ClientRequest type from Actix Web, and provid
|
|||
actix-rt = "2.6.0"
|
||||
actix-web = "4.0.0"
|
||||
thiserror = "0.1"
|
||||
http-signature-normalization-actix = { version = "0.6.0", default-features = false, features = ["sha-2"] }
|
||||
http-signature-normalization-actix = { version = "0.8.0", default-features = false, features = ["sha-2"] }
|
||||
sha2 = "0.9"
|
||||
```
|
||||
|
||||
|
@ -91,7 +91,8 @@ impl SignatureVerify for MyVerify {
|
|||
}
|
||||
|
||||
async fn index(
|
||||
(_, sig_verified): (DigestVerified, SignatureVerified),
|
||||
_: DigestVerified,
|
||||
sig_verified: SignatureVerified,
|
||||
req: HttpRequest,
|
||||
_body: web::Bytes,
|
||||
) -> &'static str {
|
||||
|
@ -116,7 +117,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
HttpServer::new(move || {
|
||||
App::new()
|
||||
.wrap(VerifyDigest::new(Sha256::new()).optional())
|
||||
.wrap(VerifySignature::new(MyVerify, config.clone()).optional())
|
||||
.wrap(VerifySignature::new(MyVerify, config.clone()))
|
||||
.wrap(TracingLogger::default())
|
||||
.route("/", web::post().to(index))
|
||||
})
|
||||
|
@ -154,19 +155,13 @@ impl ResponseError for MyError {
|
|||
```
|
||||
|
||||
### Contributing
|
||||
Unless otherwise stated, all contributions to this project will be licensed under the CSL with
|
||||
the exceptions listed in the License section of this file.
|
||||
Feel free to open issues for anything you find an issue with. Please note that any contributed code will be licensed under the AGPLv3.
|
||||
|
||||
### License
|
||||
This work is licensed under the Cooperative Software License. This is not a Free Software
|
||||
License, but may be considered a "source-available License." For most hobbyists, self-employed
|
||||
developers, worker-owned companies, and cooperatives, this software can be used in most
|
||||
projects so long as this software is distributed under the terms of the CSL. For more
|
||||
information, see the provided LICENSE file. If none exists, the license can be found online
|
||||
[here](https://lynnesbian.space/csl/). If you are a free software project and wish to use this
|
||||
software under the terms of the GNU Affero General Public License, please contact me at
|
||||
[asonix@asonix.dog](mailto:asonix@asonix.dog) and we can sort that out. If you wish to use this
|
||||
project under any other license, especially in proprietary software, the answer is likely no.
|
||||
Copyright © 2022 Riley Trautman
|
||||
|
||||
Http Signature Normalization Actix is currently licensed under the AGPL to the Lemmy project, found
|
||||
at [github.com/LemmyNet/lemmy](https://github.com/LemmyNet/lemmy)
|
||||
HTTP Signature Normalization Actix is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
HTTP Signature Normalization Actix is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. This file is part of HTTP Signature Normalization Actix.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with HTTP Signature Normalization Actix. If not, see [http://www.gnu.org/licenses/](http://www.gnu.org/licenses/).
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use actix_rt::task::JoinError;
|
||||
use awc::Client;
|
||||
use http_signature_normalization_actix::prelude::*;
|
||||
use sha2::{Digest, Sha256};
|
||||
use base64::{engine::general_purpose::STANDARD, Engine};
|
||||
use http_signature_normalization_actix::{digest::ring::Sha256, prelude::*, Canceled};
|
||||
use tracing::{error, info};
|
||||
use tracing_error::ErrorLayer;
|
||||
use tracing_subscriber::{layer::SubscriberExt, EnvFilter};
|
||||
|
@ -15,7 +15,7 @@ async fn request(config: Config) -> Result<(), Box<dyn std::error::Error>> {
|
|||
.append_header(("Accept", "text/plain"))
|
||||
.signature_with_digest(config, "my-key-id", digest, "Hewwo-owo", |s| {
|
||||
info!("Signing String\n{}", s);
|
||||
Ok(base64::encode(s)) as Result<_, MyError>
|
||||
Ok(STANDARD.encode(s)) as Result<_, MyError>
|
||||
})
|
||||
.await?
|
||||
.send()
|
||||
|
@ -45,7 +45,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
|
||||
tracing::subscriber::set_global_default(subscriber)?;
|
||||
|
||||
let config = Config::default().require_header("accept").require_digest();
|
||||
let config = Config::new().require_header("accept").require_digest();
|
||||
|
||||
request(config.clone()).await?;
|
||||
request(config.mastodon_compat()).await?;
|
||||
|
@ -75,3 +75,9 @@ impl From<JoinError> for MyError {
|
|||
MyError::Canceled
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Canceled> for MyError {
|
||||
fn from(_: Canceled) -> Self {
|
||||
MyError::Canceled
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use actix_web::{http::StatusCode, web, App, HttpRequest, HttpResponse, HttpServer, ResponseError};
|
||||
use http_signature_normalization_actix::prelude::*;
|
||||
use sha2::{Digest, Sha256};
|
||||
use base64::{engine::general_purpose::STANDARD, Engine};
|
||||
use http_signature_normalization_actix::{digest::ring::Sha256, prelude::*};
|
||||
use std::future::{ready, Ready};
|
||||
use tracing::info;
|
||||
use tracing_actix_web::TracingLogger;
|
||||
|
@ -30,7 +30,7 @@ impl SignatureVerify for MyVerify {
|
|||
return ready(Err(MyError::Key));
|
||||
}
|
||||
|
||||
let decoded = match base64::decode(&signature) {
|
||||
let decoded = match STANDARD.decode(&signature) {
|
||||
Ok(decoded) => decoded,
|
||||
Err(_) => return ready(Err(MyError::Decode)),
|
||||
};
|
||||
|
@ -42,7 +42,8 @@ impl SignatureVerify for MyVerify {
|
|||
}
|
||||
|
||||
async fn index(
|
||||
(_, sig_verified): (DigestVerified, SignatureVerified),
|
||||
_: DigestVerified,
|
||||
sig_verified: SignatureVerified,
|
||||
req: HttpRequest,
|
||||
_body: web::Bytes,
|
||||
) -> &'static str {
|
||||
|
@ -62,12 +63,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
|
||||
tracing::subscriber::set_global_default(subscriber)?;
|
||||
|
||||
let config = Config::default().require_header("accept").require_digest();
|
||||
let config = Config::new().require_header("accept").require_digest();
|
||||
|
||||
HttpServer::new(move || {
|
||||
App::new()
|
||||
.wrap(VerifyDigest::new(Sha256::new()).optional())
|
||||
.wrap(VerifySignature::new(MyVerify, config.clone()).optional())
|
||||
.wrap(VerifySignature::new(MyVerify, config.clone()))
|
||||
.wrap(TracingLogger::default())
|
||||
.route("/", web::post().to(index))
|
||||
})
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
//! Types for setting up Digest middleware verification
|
||||
|
||||
use crate::{Canceled, DefaultSpawner, Spawn};
|
||||
|
||||
use super::{DigestPart, DigestVerify};
|
||||
use actix_web::{
|
||||
body::MessageBody,
|
||||
|
@ -8,16 +10,14 @@ use actix_web::{
|
|||
http::{header::HeaderValue, StatusCode},
|
||||
web, FromRequest, HttpMessage, HttpRequest, HttpResponse, ResponseError,
|
||||
};
|
||||
use futures_util::{
|
||||
future::LocalBoxFuture,
|
||||
stream::{Stream, StreamExt},
|
||||
};
|
||||
use futures_core::{future::LocalBoxFuture, Stream};
|
||||
use std::{
|
||||
future::{ready, Ready},
|
||||
pin::Pin,
|
||||
task::{Context, Poll},
|
||||
};
|
||||
use tokio::sync::mpsc;
|
||||
use streem::{from_fn::Yielder, IntoStreamer};
|
||||
use tokio::sync::{mpsc, oneshot};
|
||||
use tracing::{debug, Span};
|
||||
use tracing_error::SpanTrace;
|
||||
|
||||
|
@ -42,23 +42,23 @@ pub struct DigestVerified;
|
|||
/// .route("/unprotected", web::post().to(|| "No verification required"))
|
||||
/// })
|
||||
/// ```
|
||||
pub struct VerifyDigest<T>(bool, T);
|
||||
pub struct VerifyDigest<T, Spawner = DefaultSpawner>(Spawner, bool, T);
|
||||
|
||||
#[doc(hidden)]
|
||||
pub struct VerifyMiddleware<T, S>(S, bool, T);
|
||||
pub struct VerifyMiddleware<T, Spawner, S>(S, Spawner, bool, T);
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
#[error("Error verifying digest")]
|
||||
#[doc(hidden)]
|
||||
pub struct VerifyError {
|
||||
context: SpanTrace,
|
||||
context: String,
|
||||
kind: VerifyErrorKind,
|
||||
}
|
||||
|
||||
impl VerifyError {
|
||||
fn new(span: &Span, kind: VerifyErrorKind) -> Self {
|
||||
span.in_scope(|| VerifyError {
|
||||
context: SpanTrace::capture(),
|
||||
context: SpanTrace::capture().to_string(),
|
||||
kind,
|
||||
})
|
||||
}
|
||||
|
@ -85,10 +85,10 @@ enum VerifyErrorKind {
|
|||
struct RxStream<T>(mpsc::Receiver<T>);
|
||||
|
||||
impl<T> Stream for RxStream<T> {
|
||||
type Item = T;
|
||||
type Item = Result<T, PayloadError>;
|
||||
|
||||
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
||||
Pin::new(&mut self.0).poll_recv(cx)
|
||||
Pin::new(&mut self.0).poll_recv(cx).map(|opt| opt.map(Ok))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -98,7 +98,22 @@ where
|
|||
{
|
||||
/// Produce a new VerifyDigest with a user-provided [`Digestverify`] type
|
||||
pub fn new(verify_digest: T) -> Self {
|
||||
VerifyDigest(true, verify_digest)
|
||||
VerifyDigest(DefaultSpawner, true, verify_digest)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, Spawner> VerifyDigest<T, Spawner>
|
||||
where
|
||||
T: DigestVerify + Clone,
|
||||
{
|
||||
/// Set the spawner used for verifying bytes in the request
|
||||
///
|
||||
/// By default this value uses `actix_web::web::block`
|
||||
pub fn spawner<NewSpawner>(self, spawner: NewSpawner) -> VerifyDigest<T, NewSpawner>
|
||||
where
|
||||
NewSpawner: Spawn,
|
||||
{
|
||||
VerifyDigest(spawner, self.1, self.2)
|
||||
}
|
||||
|
||||
/// Mark verifying the Digest as optional
|
||||
|
@ -106,53 +121,68 @@ where
|
|||
/// If a digest is present in the request, it will be verified, but it is not required to be
|
||||
/// present
|
||||
pub fn optional(self) -> Self {
|
||||
VerifyDigest(false, self.1)
|
||||
VerifyDigest(self.0, false, self.2)
|
||||
}
|
||||
}
|
||||
|
||||
struct VerifiedReceiver {
|
||||
rx: Option<oneshot::Receiver<()>>,
|
||||
}
|
||||
|
||||
impl FromRequest for DigestVerified {
|
||||
type Error = VerifyError;
|
||||
type Future = Ready<Result<Self, Self::Error>>;
|
||||
type Future = LocalBoxFuture<'static, Result<Self, Self::Error>>;
|
||||
|
||||
fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future {
|
||||
let res = req
|
||||
.extensions()
|
||||
.get::<Self>()
|
||||
.copied()
|
||||
.extensions_mut()
|
||||
.get_mut::<VerifiedReceiver>()
|
||||
.and_then(|r| r.rx.take())
|
||||
.ok_or_else(|| VerifyError::new(&Span::current(), VerifyErrorKind::Extension));
|
||||
|
||||
if res.is_err() {
|
||||
debug!("Failed to fetch DigestVerified from request");
|
||||
}
|
||||
|
||||
ready(res)
|
||||
Box::pin(async move {
|
||||
res?.await
|
||||
.map_err(|_| VerifyError::new(&Span::current(), VerifyErrorKind::Dropped))
|
||||
.map(|()| DigestVerified)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, S, B> Transform<S, ServiceRequest> for VerifyDigest<T>
|
||||
impl<T, Spawner, S, B> Transform<S, ServiceRequest> for VerifyDigest<T, Spawner>
|
||||
where
|
||||
T: DigestVerify + Clone + Send + 'static,
|
||||
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = actix_web::Error> + 'static,
|
||||
S::Error: 'static,
|
||||
B: MessageBody + 'static,
|
||||
Spawner: Spawn + Clone + 'static,
|
||||
{
|
||||
type Response = ServiceResponse<B>;
|
||||
type Error = actix_web::Error;
|
||||
type Transform = VerifyMiddleware<T, S>;
|
||||
type Transform = VerifyMiddleware<T, Spawner, S>;
|
||||
type InitError = ();
|
||||
type Future = Ready<Result<Self::Transform, Self::InitError>>;
|
||||
|
||||
fn new_transform(&self, service: S) -> Self::Future {
|
||||
ready(Ok(VerifyMiddleware(service, self.0, self.1.clone())))
|
||||
ready(Ok(VerifyMiddleware(
|
||||
service,
|
||||
self.0.clone(),
|
||||
self.1,
|
||||
self.2.clone(),
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, S, B> Service<ServiceRequest> for VerifyMiddleware<T, S>
|
||||
impl<T, Spawner, S, B> Service<ServiceRequest> for VerifyMiddleware<T, Spawner, S>
|
||||
where
|
||||
T: DigestVerify + Clone + Send + 'static,
|
||||
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = actix_web::Error> + 'static,
|
||||
S::Error: 'static,
|
||||
B: MessageBody + 'static,
|
||||
Spawner: Spawn + Clone + 'static,
|
||||
{
|
||||
type Response = ServiceResponse<B>;
|
||||
type Error = actix_web::Error;
|
||||
|
@ -165,7 +195,7 @@ where
|
|||
fn call(&self, mut req: ServiceRequest) -> Self::Future {
|
||||
let span = tracing::info_span!(
|
||||
"Verify digest",
|
||||
digest.required = tracing::field::display(&self.1),
|
||||
digest.required = tracing::field::display(&self.2),
|
||||
);
|
||||
|
||||
if let Some(digest) = req.headers().get("Digest") {
|
||||
|
@ -177,23 +207,24 @@ where
|
|||
)));
|
||||
}
|
||||
};
|
||||
|
||||
let spawner = self.1.clone();
|
||||
let digest = self.3.clone();
|
||||
let (verify_tx, verify_rx) = oneshot::channel();
|
||||
|
||||
let payload = req.take_payload();
|
||||
|
||||
let (tx, rx) = mpsc::channel(1);
|
||||
let f1 = span.in_scope(|| verify_payload(vec, self.2.clone(), payload, tx));
|
||||
|
||||
let payload: Pin<Box<dyn Stream<Item = Result<web::Bytes, PayloadError>> + 'static>> =
|
||||
Box::pin(RxStream(rx).map(Ok));
|
||||
Box::pin(streem::try_from_fn(|yielder| async move {
|
||||
verify_payload(yielder, spawner, vec, digest, payload, verify_tx).await
|
||||
}));
|
||||
req.set_payload(payload.into());
|
||||
req.extensions_mut().insert(DigestVerified);
|
||||
|
||||
let f2 = self.0.call(req);
|
||||
req.extensions_mut().insert(VerifiedReceiver {
|
||||
rx: Some(verify_rx),
|
||||
});
|
||||
|
||||
Box::pin(async move {
|
||||
let (_, res) = futures_util::future::join(f1, f2).await;
|
||||
res
|
||||
})
|
||||
} else if self.1 {
|
||||
Box::pin(self.0.call(req))
|
||||
} else if self.2 {
|
||||
Box::pin(ready(Err(VerifyError::new(
|
||||
&span,
|
||||
VerifyErrorKind::MissingDigest,
|
||||
|
@ -205,37 +236,79 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument(name = "Verify Payload", skip(verify_digest, payload, tx))]
|
||||
async fn verify_payload<T>(
|
||||
fn canceled_error(error: Canceled) -> PayloadError {
|
||||
PayloadError::Io(std::io::Error::new(std::io::ErrorKind::Other, error))
|
||||
}
|
||||
|
||||
fn verified_error(error: VerifyError) -> PayloadError {
|
||||
PayloadError::Io(std::io::Error::new(std::io::ErrorKind::Other, error))
|
||||
}
|
||||
|
||||
async fn verify_payload<T, Spawner>(
|
||||
yielder: Yielder<Result<web::Bytes, PayloadError>>,
|
||||
spawner: Spawner,
|
||||
vec: Vec<DigestPart>,
|
||||
mut verify_digest: T,
|
||||
mut payload: Payload,
|
||||
tx: mpsc::Sender<web::Bytes>,
|
||||
) -> Result<(), actix_web::Error>
|
||||
payload: Payload,
|
||||
verify_tx: oneshot::Sender<()>,
|
||||
) -> Result<(), PayloadError>
|
||||
where
|
||||
T: DigestVerify + Clone + Send + 'static,
|
||||
Spawner: Spawn,
|
||||
{
|
||||
while let Some(res) = payload.next().await {
|
||||
let bytes = res?;
|
||||
let bytes2 = bytes.clone();
|
||||
verify_digest = web::block(move || {
|
||||
verify_digest.update(bytes2.as_ref());
|
||||
Ok(verify_digest) as Result<T, VerifyError>
|
||||
})
|
||||
.await??;
|
||||
let mut payload = payload.into_streamer();
|
||||
|
||||
tx.send(bytes)
|
||||
.await
|
||||
.map_err(|_| VerifyError::new(&Span::current(), VerifyErrorKind::Dropped))?;
|
||||
let mut error = None;
|
||||
|
||||
while let Some(bytes) = payload.try_next().await? {
|
||||
if error.is_none() {
|
||||
let bytes2 = bytes.clone();
|
||||
let mut verify_digest2 = verify_digest.clone();
|
||||
|
||||
let task = spawner.spawn_blocking(move || {
|
||||
verify_digest2.update(bytes2.as_ref());
|
||||
Ok(verify_digest2) as Result<T, VerifyError>
|
||||
});
|
||||
|
||||
yielder.yield_ok(bytes).await;
|
||||
|
||||
match task.await {
|
||||
Ok(Ok(digest)) => {
|
||||
verify_digest = digest;
|
||||
}
|
||||
Ok(Err(e)) => {
|
||||
error = Some(verified_error(e));
|
||||
}
|
||||
Err(e) => {
|
||||
error = Some(canceled_error(e));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
yielder.yield_ok(bytes).await;
|
||||
}
|
||||
}
|
||||
|
||||
let verified =
|
||||
web::block(move || Ok(verify_digest.verify(&vec)) as Result<_, VerifyError>).await??;
|
||||
if let Some(error) = error {
|
||||
return Err(error);
|
||||
}
|
||||
|
||||
let verified = spawner
|
||||
.spawn_blocking(move || Ok(verify_digest.verify(&vec)) as Result<_, VerifyError>)
|
||||
.await
|
||||
.map_err(canceled_error)?
|
||||
.map_err(verified_error)?;
|
||||
|
||||
if verified {
|
||||
if verify_tx.send(()).is_err() {
|
||||
debug!("handler dropped");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
} else {
|
||||
Err(VerifyError::new(&Span::current(), VerifyErrorKind::Verify).into())
|
||||
Err(verified_error(VerifyError::new(
|
||||
&Span::current(),
|
||||
VerifyErrorKind::Verify,
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
|
||||
#[cfg(feature = "server")]
|
||||
pub mod middleware;
|
||||
#[cfg(feature = "ring")]
|
||||
pub mod ring;
|
||||
#[cfg(feature = "sha-2")]
|
||||
mod sha2;
|
||||
#[cfg(feature = "sha-3")]
|
||||
|
@ -26,7 +28,7 @@ pub trait DigestName {
|
|||
|
||||
#[cfg(feature = "client")]
|
||||
mod client {
|
||||
use crate::{Config, PrepareSignError, Sign};
|
||||
use crate::{Config, PrepareSignError, Sign, Spawn};
|
||||
use actix_http::header::InvalidHeaderValue;
|
||||
use actix_rt::task::JoinError;
|
||||
use awc::{ClientRequest, SendClientRequest};
|
||||
|
@ -47,9 +49,9 @@ mod client {
|
|||
/// a malicious entity
|
||||
pub trait SignExt: Sign {
|
||||
/// Set the Digest and Authorization headers on the request
|
||||
fn authorization_signature_with_digest<F, E, K, D, V>(
|
||||
fn authorization_signature_with_digest<F, E, K, S, D, V>(
|
||||
self,
|
||||
config: Config,
|
||||
config: Config<S>,
|
||||
key_id: K,
|
||||
digest: D,
|
||||
v: V,
|
||||
|
@ -59,19 +61,21 @@ mod client {
|
|||
F: FnOnce(&str) -> Result<String, E> + Send + 'static,
|
||||
E: From<JoinError>
|
||||
+ From<PrepareSignError>
|
||||
+ From<crate::Canceled>
|
||||
+ From<InvalidHeaderValue>
|
||||
+ std::fmt::Debug
|
||||
+ Send
|
||||
+ 'static,
|
||||
K: Display + 'static,
|
||||
S: Spawn + 'static,
|
||||
D: DigestCreate + Send + 'static,
|
||||
V: AsRef<[u8]> + Send + 'static,
|
||||
Self: Sized;
|
||||
|
||||
/// Set the Digest and Signature headers on the request
|
||||
fn signature_with_digest<F, E, K, D, V>(
|
||||
fn signature_with_digest<F, E, K, S, D, V>(
|
||||
self,
|
||||
config: Config,
|
||||
config: Config<S>,
|
||||
key_id: K,
|
||||
digest: D,
|
||||
v: V,
|
||||
|
@ -81,11 +85,13 @@ mod client {
|
|||
F: FnOnce(&str) -> Result<String, E> + Send + 'static,
|
||||
E: From<JoinError>
|
||||
+ From<PrepareSignError>
|
||||
+ From<crate::Canceled>
|
||||
+ From<InvalidHeaderValue>
|
||||
+ std::fmt::Debug
|
||||
+ Send
|
||||
+ 'static,
|
||||
K: Display + 'static,
|
||||
S: Spawn + 'static,
|
||||
D: DigestCreate + Send + 'static,
|
||||
V: AsRef<[u8]> + Send + 'static,
|
||||
Self: Sized;
|
||||
|
|
198
actix/src/digest/ring.rs
Normal file
198
actix/src/digest/ring.rs
Normal file
|
@ -0,0 +1,198 @@
|
|||
//! Types for creating digests with the `ring` cryptography library
|
||||
|
||||
use crate::digest::DigestName;
|
||||
|
||||
/// A Sha256 digest backed by ring
|
||||
#[derive(Clone)]
|
||||
pub struct Sha256 {
|
||||
ctx: ring::digest::Context,
|
||||
}
|
||||
|
||||
/// A Sha384 digest backed by ring
|
||||
#[derive(Clone)]
|
||||
pub struct Sha384 {
|
||||
ctx: ring::digest::Context,
|
||||
}
|
||||
|
||||
/// A Sha512 digest backed by ring
|
||||
#[derive(Clone)]
|
||||
pub struct Sha512 {
|
||||
ctx: ring::digest::Context,
|
||||
}
|
||||
|
||||
impl Sha256 {
|
||||
/// Create a new empty digest
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
/// Extract the context
|
||||
pub fn into_inner(self) -> ring::digest::Context {
|
||||
self.ctx
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Sha256 {
|
||||
fn default() -> Self {
|
||||
Sha256 {
|
||||
ctx: ring::digest::Context::new(&ring::digest::SHA256),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Sha384 {
|
||||
/// Create a new empty digest
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
/// Extract the context
|
||||
pub fn into_inner(self) -> ring::digest::Context {
|
||||
self.ctx
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Sha384 {
|
||||
fn default() -> Self {
|
||||
Sha384 {
|
||||
ctx: ring::digest::Context::new(&ring::digest::SHA384),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Sha512 {
|
||||
/// Create a new empty digest
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
/// Extract the context
|
||||
pub fn into_inner(self) -> ring::digest::Context {
|
||||
self.ctx
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Sha512 {
|
||||
fn default() -> Self {
|
||||
Sha512 {
|
||||
ctx: ring::digest::Context::new(&ring::digest::SHA512),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl DigestName for Sha256 {
|
||||
const NAME: &'static str = "SHA-256";
|
||||
}
|
||||
|
||||
impl DigestName for Sha384 {
|
||||
const NAME: &'static str = "SHA-384";
|
||||
}
|
||||
|
||||
impl DigestName for Sha512 {
|
||||
const NAME: &'static str = "SHA-512";
|
||||
}
|
||||
|
||||
#[cfg(feature = "client")]
|
||||
mod client {
|
||||
use super::*;
|
||||
use crate::digest::DigestCreate;
|
||||
use base64::prelude::*;
|
||||
|
||||
fn create(mut context: ring::digest::Context, input: &[u8]) -> String {
|
||||
context.update(input);
|
||||
let digest = context.finish();
|
||||
BASE64_STANDARD.encode(digest.as_ref())
|
||||
}
|
||||
|
||||
impl DigestCreate for Sha256 {
|
||||
fn compute(&mut self, input: &[u8]) -> String {
|
||||
create(self.ctx.clone(), input)
|
||||
}
|
||||
}
|
||||
|
||||
impl DigestCreate for Sha384 {
|
||||
fn compute(&mut self, input: &[u8]) -> String {
|
||||
create(self.ctx.clone(), input)
|
||||
}
|
||||
}
|
||||
|
||||
impl DigestCreate for Sha512 {
|
||||
fn compute(&mut self, input: &[u8]) -> String {
|
||||
create(self.ctx.clone(), input)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "server")]
|
||||
mod server {
|
||||
use super::*;
|
||||
use crate::digest::{DigestPart, DigestVerify};
|
||||
use base64::prelude::*;
|
||||
use tracing::{debug, warn};
|
||||
|
||||
fn verify(context: ring::digest::Context, name: &str, parts: &[DigestPart]) -> bool {
|
||||
if let Some(part) = parts
|
||||
.iter()
|
||||
.find(|p| p.algorithm.to_lowercase() == name.to_lowercase())
|
||||
{
|
||||
debug!("Verifying digest type, {}", name);
|
||||
let digest = context.finish();
|
||||
let encoded = BASE64_STANDARD.encode(digest.as_ref());
|
||||
|
||||
return part.digest == encoded;
|
||||
}
|
||||
warn!("No matching digest algorithm found for {}", name);
|
||||
warn!(
|
||||
"Provided: [{}]",
|
||||
parts.iter().fold(String::new(), |mut acc, item| {
|
||||
if acc.is_empty() {
|
||||
} else {
|
||||
acc.push_str(", ");
|
||||
}
|
||||
acc.push_str(&item.algorithm);
|
||||
acc
|
||||
})
|
||||
);
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
impl DigestVerify for Sha256 {
|
||||
fn update(&mut self, part: &[u8]) {
|
||||
self.ctx.update(part);
|
||||
}
|
||||
|
||||
fn verify(&mut self, parts: &[DigestPart]) -> bool {
|
||||
let alg = self.ctx.algorithm();
|
||||
let ctx = std::mem::replace(&mut self.ctx, ring::digest::Context::new(alg));
|
||||
|
||||
verify(ctx, Self::NAME, parts)
|
||||
}
|
||||
}
|
||||
|
||||
impl DigestVerify for Sha384 {
|
||||
fn update(&mut self, part: &[u8]) {
|
||||
self.ctx.update(part);
|
||||
}
|
||||
|
||||
fn verify(&mut self, parts: &[DigestPart]) -> bool {
|
||||
let alg = self.ctx.algorithm();
|
||||
let ctx = std::mem::replace(&mut self.ctx, ring::digest::Context::new(alg));
|
||||
|
||||
verify(ctx, Self::NAME, parts)
|
||||
}
|
||||
}
|
||||
|
||||
impl DigestVerify for Sha512 {
|
||||
fn update(&mut self, part: &[u8]) {
|
||||
self.ctx.update(part);
|
||||
}
|
||||
|
||||
fn verify(&mut self, parts: &[DigestPart]) -> bool {
|
||||
let alg = self.ctx.algorithm();
|
||||
let ctx = std::mem::replace(&mut self.ctx, ring::digest::Context::new(alg));
|
||||
|
||||
verify(ctx, Self::NAME, parts)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -21,13 +21,14 @@ impl DigestName for Sha512 {
|
|||
mod client {
|
||||
use super::*;
|
||||
use crate::digest::DigestCreate;
|
||||
use base64::prelude::*;
|
||||
|
||||
fn create<D: sha2::Digest + sha2::digest::FixedOutputReset>(
|
||||
digest: &mut D,
|
||||
input: &[u8],
|
||||
) -> String {
|
||||
sha2::Digest::update(digest, input);
|
||||
base64::encode(&digest.finalize_reset())
|
||||
BASE64_STANDARD.encode(&digest.finalize_reset())
|
||||
}
|
||||
|
||||
impl DigestCreate for Sha224 {
|
||||
|
@ -59,6 +60,7 @@ mod client {
|
|||
mod server {
|
||||
use super::*;
|
||||
use crate::digest::{DigestPart, DigestVerify};
|
||||
use base64::prelude::*;
|
||||
use tracing::{debug, warn};
|
||||
|
||||
fn verify<D: sha2::Digest + sha2::digest::FixedOutputReset>(
|
||||
|
@ -71,7 +73,7 @@ mod server {
|
|||
.find(|p| p.algorithm.to_lowercase() == name.to_lowercase())
|
||||
{
|
||||
debug!("Verifying digest type, {}", name);
|
||||
let encoded = base64::encode(&digest.finalize_reset());
|
||||
let encoded = BASE64_STANDARD.encode(&digest.finalize_reset());
|
||||
|
||||
return part.digest == encoded;
|
||||
}
|
||||
|
|
|
@ -40,17 +40,18 @@ impl DigestName for Sha3_512 {
|
|||
const NAME: &'static str = "SHA3-512";
|
||||
}
|
||||
|
||||
#[cfg(features = "client")]
|
||||
#[cfg(feature = "client")]
|
||||
mod client {
|
||||
use super::*;
|
||||
use crate::digest::DigestCreate;
|
||||
use base64::prelude::*;
|
||||
|
||||
fn create<D: sha3::Digest + sha3::digest::FixedOutputReset>(
|
||||
digest: &mut D,
|
||||
input: &[u8],
|
||||
) -> String {
|
||||
digest.update(input);
|
||||
base64::encode(&digest.finalize_reset())
|
||||
sha3::Digest::update(digest, input);
|
||||
BASE64_STANDARD.encode(&digest.finalize_reset())
|
||||
}
|
||||
|
||||
impl DigestCreate for Sha3_224 {
|
||||
|
@ -112,6 +113,7 @@ mod client {
|
|||
mod server {
|
||||
use super::*;
|
||||
use crate::digest::{DigestPart, DigestVerify};
|
||||
use base64::prelude::*;
|
||||
use tracing::{debug, warn};
|
||||
|
||||
fn verify<D: sha3::Digest + sha3::digest::FixedOutputReset>(
|
||||
|
@ -124,7 +126,7 @@ mod server {
|
|||
.find(|p| p.algorithm.to_lowercase() == name.to_lowercase())
|
||||
{
|
||||
debug!("Verifying digest type, {}", name);
|
||||
let encoded = base64::encode(&digest.finalize_reset());
|
||||
let encoded = BASE64_STANDARD.encode(&digest.finalize_reset());
|
||||
|
||||
return part.digest == encoded;
|
||||
}
|
||||
|
|
|
@ -5,13 +5,13 @@ use std::{fmt::Display, future::Future, pin::Pin};
|
|||
|
||||
use crate::{
|
||||
digest::{DigestClient, DigestCreate, SignExt},
|
||||
Config, PrepareSignError, Sign,
|
||||
Config, PrepareSignError, Sign, Spawn,
|
||||
};
|
||||
|
||||
impl SignExt for ClientRequest {
|
||||
fn authorization_signature_with_digest<F, E, K, D, V>(
|
||||
fn authorization_signature_with_digest<F, E, K, S, D, V>(
|
||||
self,
|
||||
config: Config,
|
||||
config: Config<S>,
|
||||
key_id: K,
|
||||
mut digest: D,
|
||||
v: V,
|
||||
|
@ -21,21 +21,25 @@ impl SignExt for ClientRequest {
|
|||
F: FnOnce(&str) -> Result<String, E> + Send + 'static,
|
||||
E: From<JoinError>
|
||||
+ From<PrepareSignError>
|
||||
+ From<crate::Canceled>
|
||||
+ From<InvalidHeaderValue>
|
||||
+ std::fmt::Debug
|
||||
+ Send
|
||||
+ 'static,
|
||||
K: Display + 'static,
|
||||
S: Spawn + 'static,
|
||||
D: DigestCreate + Send + 'static,
|
||||
V: AsRef<[u8]> + Send + 'static,
|
||||
Self: Sized,
|
||||
{
|
||||
Box::pin(async move {
|
||||
let (d, v) = actix_rt::task::spawn_blocking(move || {
|
||||
let d = digest.compute(v.as_ref());
|
||||
Ok((d, v)) as Result<(String, V), E>
|
||||
})
|
||||
.await??;
|
||||
let (d, v) = config
|
||||
.spawner
|
||||
.spawn_blocking(move || {
|
||||
let d = digest.compute(v.as_ref());
|
||||
Ok((d, v)) as Result<(String, V), E>
|
||||
})
|
||||
.await??;
|
||||
|
||||
let c = self
|
||||
.insert_header(("Digest", format!("{}={}", D::NAME, d)))
|
||||
|
@ -46,9 +50,9 @@ impl SignExt for ClientRequest {
|
|||
})
|
||||
}
|
||||
|
||||
fn signature_with_digest<F, E, K, D, V>(
|
||||
fn signature_with_digest<F, E, K, S, D, V>(
|
||||
self,
|
||||
config: Config,
|
||||
config: Config<S>,
|
||||
key_id: K,
|
||||
mut digest: D,
|
||||
v: V,
|
||||
|
@ -58,21 +62,25 @@ impl SignExt for ClientRequest {
|
|||
F: FnOnce(&str) -> Result<String, E> + Send + 'static,
|
||||
E: From<JoinError>
|
||||
+ From<PrepareSignError>
|
||||
+ From<crate::Canceled>
|
||||
+ From<InvalidHeaderValue>
|
||||
+ std::fmt::Debug
|
||||
+ Send
|
||||
+ 'static,
|
||||
K: Display + 'static,
|
||||
S: Spawn + 'static,
|
||||
D: DigestCreate + Send + 'static,
|
||||
V: AsRef<[u8]> + Send + 'static,
|
||||
Self: Sized,
|
||||
{
|
||||
Box::pin(async move {
|
||||
let (d, v) = actix_rt::task::spawn_blocking(move || {
|
||||
let d = digest.compute(v.as_ref());
|
||||
Ok((d, v)) as Result<(String, V), E>
|
||||
})
|
||||
.await??;
|
||||
let (d, v) = config
|
||||
.spawner
|
||||
.spawn_blocking(move || {
|
||||
let d = digest.compute(v.as_ref());
|
||||
Ok((d, v)) as Result<(String, V), E>
|
||||
})
|
||||
.await??;
|
||||
|
||||
let c = self
|
||||
.insert_header(("Digest", format!("{}={}", D::NAME, d)))
|
||||
|
|
125
actix/src/lib.rs
125
actix/src/lib.rs
|
@ -267,7 +267,7 @@ pub use self::server::{PrepareVerifyError, SignatureVerify};
|
|||
///
|
||||
/// By default, the config is set up to create and verify signatures that expire after 10
|
||||
/// seconds, and use the `(created)` and `(expires)` fields that were introduced in draft 11
|
||||
pub struct Config {
|
||||
pub struct Config<Spawner = DefaultSpawner> {
|
||||
/// The inner config type
|
||||
config: http_signature_normalization::Config,
|
||||
|
||||
|
@ -276,11 +276,77 @@ pub struct Config {
|
|||
|
||||
/// Whether to set the Date header
|
||||
set_date: bool,
|
||||
|
||||
/// The spawner used to create blocking operations
|
||||
spawner: Spawner,
|
||||
}
|
||||
|
||||
/// A default implementation of Spawner for spawning blocking operations
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
pub struct DefaultSpawner;
|
||||
|
||||
/// An error that indicates a blocking operation panicked and cannot return a response
|
||||
#[derive(Debug)]
|
||||
pub struct Canceled;
|
||||
|
||||
impl std::fmt::Display for Canceled {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "Operation was canceled")
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for Canceled {}
|
||||
|
||||
/// A trait dictating how to spawn a future onto a blocking threadpool. By default,
|
||||
/// http-signature-normalization-actix will use actix_rt's built-in blocking threadpool, but this
|
||||
/// can be customized
|
||||
pub trait Spawn {
|
||||
/// The future type returned by spawn_blocking
|
||||
type Future<T>: std::future::Future<Output = Result<T, Canceled>>;
|
||||
|
||||
/// Spawn the blocking function onto the threadpool
|
||||
fn spawn_blocking<Func, Out>(&self, func: Func) -> Self::Future<Out>
|
||||
where
|
||||
Func: FnOnce() -> Out + Send + 'static,
|
||||
Out: Send + 'static;
|
||||
}
|
||||
|
||||
/// The future returned by DefaultSpawner when spawning blocking operations on the actix_rt
|
||||
/// blocking threadpool
|
||||
pub struct DefaultSpawnerFuture<Out> {
|
||||
inner: actix_rt::task::JoinHandle<Out>,
|
||||
}
|
||||
|
||||
impl Spawn for DefaultSpawner {
|
||||
type Future<T> = DefaultSpawnerFuture<T>;
|
||||
|
||||
fn spawn_blocking<Func, Out>(&self, func: Func) -> Self::Future<Out>
|
||||
where
|
||||
Func: FnOnce() -> Out + Send + 'static,
|
||||
Out: Send + 'static,
|
||||
{
|
||||
DefaultSpawnerFuture {
|
||||
inner: actix_rt::task::spawn_blocking(func),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<Out> std::future::Future for DefaultSpawnerFuture<Out> {
|
||||
type Output = Result<Out, Canceled>;
|
||||
|
||||
fn poll(
|
||||
mut self: std::pin::Pin<&mut Self>,
|
||||
cx: &mut std::task::Context<'_>,
|
||||
) -> std::task::Poll<Self::Output> {
|
||||
let res = std::task::ready!(std::pin::Pin::new(&mut self.inner).poll(cx));
|
||||
|
||||
std::task::Poll::Ready(res.map_err(|_| Canceled))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "client")]
|
||||
mod client {
|
||||
use super::{Config, RequiredError};
|
||||
use super::{Config, RequiredError, Spawn};
|
||||
use actix_http::header::{InvalidHeaderValue, ToStrError};
|
||||
use actix_rt::task::JoinError;
|
||||
use std::{fmt::Display, future::Future, pin::Pin};
|
||||
|
@ -288,9 +354,9 @@ mod client {
|
|||
/// A trait implemented by the awc ClientRequest type to add an HTTP signature to the request
|
||||
pub trait Sign {
|
||||
/// Add an Authorization Signature to the request
|
||||
fn authorization_signature<F, E, K>(
|
||||
fn authorization_signature<F, E, K, S>(
|
||||
self,
|
||||
config: Config,
|
||||
config: Config<S>,
|
||||
key_id: K,
|
||||
f: F,
|
||||
) -> Pin<Box<dyn Future<Output = Result<Self, E>>>>
|
||||
|
@ -298,17 +364,19 @@ mod client {
|
|||
F: FnOnce(&str) -> Result<String, E> + Send + 'static,
|
||||
E: From<JoinError>
|
||||
+ From<PrepareSignError>
|
||||
+ From<crate::Canceled>
|
||||
+ From<InvalidHeaderValue>
|
||||
+ std::fmt::Debug
|
||||
+ Send
|
||||
+ 'static,
|
||||
K: Display + 'static,
|
||||
S: Spawn + 'static,
|
||||
Self: Sized;
|
||||
|
||||
/// Add a Signature to the request
|
||||
fn signature<F, E, K>(
|
||||
fn signature<F, E, K, S>(
|
||||
self,
|
||||
config: Config,
|
||||
config: Config<S>,
|
||||
key_id: K,
|
||||
f: F,
|
||||
) -> Pin<Box<dyn Future<Output = Result<Self, E>>>>
|
||||
|
@ -316,11 +384,13 @@ mod client {
|
|||
F: FnOnce(&str) -> Result<String, E> + Send + 'static,
|
||||
E: From<JoinError>
|
||||
+ From<PrepareSignError>
|
||||
+ From<crate::Canceled>
|
||||
+ From<InvalidHeaderValue>
|
||||
+ std::fmt::Debug
|
||||
+ Send
|
||||
+ 'static,
|
||||
K: Display + 'static,
|
||||
S: Spawn + 'static,
|
||||
Self: Sized;
|
||||
}
|
||||
|
||||
|
@ -378,9 +448,9 @@ mod server {
|
|||
/// Header is missing
|
||||
Missing,
|
||||
|
||||
#[error("Header is expired")]
|
||||
#[error("{0}")]
|
||||
/// Header is expired
|
||||
Expired,
|
||||
Expired(String),
|
||||
|
||||
#[error("Couldn't parse required field, {0}")]
|
||||
/// Couldn't parse required field
|
||||
|
@ -405,7 +475,9 @@ mod server {
|
|||
}
|
||||
hsn::PrepareVerifyError::Validate(validate_error) => match validate_error {
|
||||
hsn::verify::ValidateError::Missing => PrepareVerifyError::Missing,
|
||||
hsn::verify::ValidateError::Expired => PrepareVerifyError::Expired,
|
||||
e @ hsn::verify::ValidateError::Expired { .. } => {
|
||||
PrepareVerifyError::Expired(e.to_string())
|
||||
}
|
||||
},
|
||||
hsn::PrepareVerifyError::Required(required_error) => {
|
||||
PrepareVerifyError::Required(required_error)
|
||||
|
@ -413,6 +485,16 @@ mod server {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl actix_web::ResponseError for super::Canceled {
|
||||
fn status_code(&self) -> actix_http::StatusCode {
|
||||
actix_http::StatusCode::INTERNAL_SERVER_ERROR
|
||||
}
|
||||
|
||||
fn error_response(&self) -> actix_web::HttpResponse<actix_http::body::BoxBody> {
|
||||
actix_web::HttpResponse::new(self.status_code())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Config {
|
||||
|
@ -420,7 +502,9 @@ impl Config {
|
|||
pub fn new() -> Self {
|
||||
Config::default()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Spawner> Config<Spawner> {
|
||||
/// Since manually setting the Host header doesn't work so well in AWC, you can use this method
|
||||
/// to enable setting the Host header for signing requests without breaking client
|
||||
/// functionality
|
||||
|
@ -429,6 +513,24 @@ impl Config {
|
|||
config: self.config,
|
||||
set_host: true,
|
||||
set_date: self.set_date,
|
||||
spawner: self.spawner,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "client")]
|
||||
/// Set the spawner for spawning blocking tasks
|
||||
///
|
||||
/// http-signature-normalization-actix offloads signing messages and generating hashes to a
|
||||
/// blocking threadpool, which can be configured by providing a custom spawner.
|
||||
pub fn spawner<S>(self, spawner: S) -> Config<S>
|
||||
where
|
||||
S: Spawn,
|
||||
{
|
||||
Config {
|
||||
config: self.config,
|
||||
set_host: self.set_host,
|
||||
set_date: self.set_date,
|
||||
spawner,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -441,6 +543,7 @@ impl Config {
|
|||
config: self.config.mastodon_compat(),
|
||||
set_host: true,
|
||||
set_date: true,
|
||||
spawner: self.spawner,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -452,6 +555,7 @@ impl Config {
|
|||
config: self.config.require_digest(),
|
||||
set_host: self.set_host,
|
||||
set_date: self.set_date,
|
||||
spawner: self.spawner,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -464,6 +568,7 @@ impl Config {
|
|||
config: self.config.dont_use_created_field(),
|
||||
set_host: self.set_host,
|
||||
set_date: self.set_date,
|
||||
spawner: self.spawner,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -473,6 +578,7 @@ impl Config {
|
|||
config: self.config.set_expiration(expires_after),
|
||||
set_host: self.set_host,
|
||||
set_date: self.set_date,
|
||||
spawner: self.spawner,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -482,6 +588,7 @@ impl Config {
|
|||
config: self.config.require_header(header),
|
||||
set_host: self.set_host,
|
||||
set_date: self.set_date,
|
||||
spawner: self.spawner,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
//! Types for verifying requests with Actix Web
|
||||
|
||||
use crate::{Config, PrepareVerifyError, SignatureVerify};
|
||||
use crate::{Config, PrepareVerifyError, SignatureVerify, Spawn};
|
||||
use actix_web::{
|
||||
body::MessageBody,
|
||||
dev::{Payload, Service, ServiceRequest, ServiceResponse, Transform},
|
||||
http::StatusCode,
|
||||
Error, FromRequest, HttpMessage, HttpRequest, HttpResponse, ResponseError,
|
||||
};
|
||||
use futures_util::future::LocalBoxFuture;
|
||||
use futures_core::future::LocalBoxFuture;
|
||||
use std::{
|
||||
collections::HashSet,
|
||||
future::{ready, Ready},
|
||||
rc::Rc,
|
||||
task::{Context, Poll},
|
||||
};
|
||||
use tracing::{debug, Span};
|
||||
|
@ -18,8 +19,7 @@ use tracing_error::SpanTrace;
|
|||
use tracing_futures::Instrument;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
/// A marker type that can be used to guard routes when the signature middleware is set to
|
||||
/// 'optional'
|
||||
/// A marker type that is used to guard routes
|
||||
pub struct SignatureVerified(String);
|
||||
|
||||
impl SignatureVerified {
|
||||
|
@ -36,9 +36,7 @@ impl SignatureVerified {
|
|||
/// The Verify signature middleware
|
||||
///
|
||||
/// ```rust,ignore
|
||||
/// let middleware = VerifySignature::new(MyVerifier::new(), Config::default())
|
||||
/// .authorization()
|
||||
/// .optional();
|
||||
/// let middleware = VerifySignature::new(MyVerifier::new(), Config::default()).authorization();
|
||||
///
|
||||
/// HttpServer::new(move || {
|
||||
/// App::new()
|
||||
|
@ -47,11 +45,11 @@ impl SignatureVerified {
|
|||
/// .route("/unprotected", web::post().to(|| "No verification required"))
|
||||
/// })
|
||||
/// ```
|
||||
pub struct VerifySignature<T>(T, Config, HeaderKind, bool);
|
||||
pub struct VerifySignature<T, Spawner>(T, Config<Spawner>, HeaderKind);
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Debug)]
|
||||
#[doc(hidden)]
|
||||
pub struct VerifyMiddleware<T, S>(S, Config, HeaderKind, bool, T);
|
||||
pub struct VerifyMiddleware<T, Spawner, S>(Rc<S>, Config<Spawner>, HeaderKind, T);
|
||||
|
||||
#[derive(Copy, Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
|
||||
enum HeaderKind {
|
||||
|
@ -72,21 +70,39 @@ impl std::fmt::Display for HeaderKind {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, thiserror::Error)]
|
||||
#[error("Failed to verify http signature, {kind}")]
|
||||
#[derive(Clone)]
|
||||
#[doc(hidden)]
|
||||
pub struct VerifyError {
|
||||
context: SpanTrace,
|
||||
context: String,
|
||||
kind: VerifyErrorKind,
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for VerifyError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
writeln!(f, "{:?}", self.kind)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for VerifyError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
writeln!(f, "{}", self.kind)?;
|
||||
std::fmt::Display::fmt(&self.context, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for VerifyError {
|
||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||
self.kind.source()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, thiserror::Error)]
|
||||
enum VerifyErrorKind {
|
||||
#[error("Signature or Authorization header is missing")]
|
||||
MissingSignature,
|
||||
|
||||
#[error("Signature is expired")]
|
||||
ExpiredSignature,
|
||||
#[error("{0}")]
|
||||
ExpiredSignature(String),
|
||||
|
||||
#[error("Signature field could not be parsed")]
|
||||
ParseField(&'static str),
|
||||
|
@ -94,9 +110,6 @@ enum VerifyErrorKind {
|
|||
#[error("Signature is not a valid string")]
|
||||
ParseSignature,
|
||||
|
||||
#[error("Signature is invalid")]
|
||||
Validate,
|
||||
|
||||
#[error("Request extension not present")]
|
||||
Extension,
|
||||
|
||||
|
@ -107,13 +120,13 @@ enum VerifyErrorKind {
|
|||
impl VerifyError {
|
||||
fn new(span: &Span, kind: VerifyErrorKind) -> Self {
|
||||
span.in_scope(|| VerifyError {
|
||||
context: SpanTrace::capture(),
|
||||
context: SpanTrace::capture().to_string(),
|
||||
kind,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> VerifySignature<T>
|
||||
impl<T, Spawner> VerifySignature<T, Spawner>
|
||||
where
|
||||
T: SignatureVerify,
|
||||
{
|
||||
|
@ -122,26 +135,20 @@ where
|
|||
///
|
||||
/// By default, this middleware expects to verify Signature headers, and requires the presence
|
||||
/// of the header
|
||||
pub fn new(verify_signature: T, config: Config) -> Self {
|
||||
VerifySignature(verify_signature, config, HeaderKind::Signature, false)
|
||||
pub fn new(verify_signature: T, config: Config<Spawner>) -> Self
|
||||
where
|
||||
Spawner: Spawn,
|
||||
{
|
||||
VerifySignature(verify_signature, config, HeaderKind::Signature)
|
||||
}
|
||||
|
||||
/// Verify Authorization headers instead of Signature headers
|
||||
pub fn authorization(self) -> Self {
|
||||
VerifySignature(self.0, self.1, HeaderKind::Authorization, self.3)
|
||||
}
|
||||
|
||||
/// Mark the presence of a Signature or Authorization header as optional
|
||||
///
|
||||
/// If a header is present, it will be verified, but if there is not one present, the request
|
||||
/// is passed through. This can be used to set a global middleware, and then guard each route
|
||||
/// handler with the [`SignatureVerified`] type.
|
||||
pub fn optional(self) -> Self {
|
||||
VerifySignature(self.0, self.1, self.2, true)
|
||||
VerifySignature(self.0, self.1, HeaderKind::Authorization)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, S, B> VerifyMiddleware<T, S>
|
||||
impl<T, Spawner, S, B> VerifyMiddleware<T, Spawner, S>
|
||||
where
|
||||
T: SignatureVerify + Clone + 'static,
|
||||
T::Future: 'static,
|
||||
|
@ -161,10 +168,10 @@ where
|
|||
|
||||
let unverified = match res {
|
||||
Ok(unverified) => unverified,
|
||||
Err(PrepareVerifyError::Expired) => {
|
||||
Err(PrepareVerifyError::Expired(reason)) => {
|
||||
return Box::pin(ready(Err(VerifyError::new(
|
||||
&span,
|
||||
VerifyErrorKind::ExpiredSignature,
|
||||
VerifyErrorKind::ExpiredSignature(reason),
|
||||
)
|
||||
.into())));
|
||||
}
|
||||
|
@ -201,31 +208,25 @@ where
|
|||
let algorithm = unverified.algorithm().cloned();
|
||||
let key_id = unverified.key_id().to_owned();
|
||||
|
||||
let f1 = unverified.verify(|signature, signing_string| {
|
||||
let fut = span.in_scope(|| {
|
||||
self.4.clone().signature_verify(
|
||||
let verify_fut = unverified.verify(|signature, signing_string| {
|
||||
span.in_scope(|| {
|
||||
self.3.clone().signature_verify(
|
||||
algorithm,
|
||||
key_id.clone(),
|
||||
signature.to_string(),
|
||||
signing_string.to_string(),
|
||||
)
|
||||
});
|
||||
|
||||
fut.instrument(span.clone())
|
||||
})
|
||||
});
|
||||
|
||||
req.extensions_mut().insert(SignatureVerified(key_id));
|
||||
|
||||
let f2 = self.0.call(req);
|
||||
let service = Rc::clone(&self.0);
|
||||
|
||||
Box::pin(async move {
|
||||
let span = span;
|
||||
|
||||
if f1.await? {
|
||||
f2.await
|
||||
} else {
|
||||
Err(VerifyError::new(&span, VerifyErrorKind::Validate).into())
|
||||
if verify_fut.instrument(span).await? {
|
||||
req.extensions_mut().insert(SignatureVerified(key_id));
|
||||
}
|
||||
|
||||
service.call(req).await
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -259,31 +260,31 @@ impl FromRequest for SignatureVerified {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T, S, B> Transform<S, ServiceRequest> for VerifySignature<T>
|
||||
impl<T, Spawner, S, B> Transform<S, ServiceRequest> for VerifySignature<T, Spawner>
|
||||
where
|
||||
T: SignatureVerify + Clone + 'static,
|
||||
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = actix_web::Error> + 'static,
|
||||
S::Error: 'static,
|
||||
B: MessageBody + 'static,
|
||||
Spawner: Clone,
|
||||
{
|
||||
type Response = ServiceResponse<B>;
|
||||
type Error = actix_web::Error;
|
||||
type Transform = VerifyMiddleware<T, S>;
|
||||
type Transform = VerifyMiddleware<T, Spawner, S>;
|
||||
type InitError = ();
|
||||
type Future = Ready<Result<Self::Transform, Self::InitError>>;
|
||||
|
||||
fn new_transform(&self, service: S) -> Self::Future {
|
||||
ready(Ok(VerifyMiddleware(
|
||||
service,
|
||||
Rc::new(service),
|
||||
self.1.clone(),
|
||||
self.2,
|
||||
self.3,
|
||||
self.0.clone(),
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, S, B> Service<ServiceRequest> for VerifyMiddleware<T, S>
|
||||
impl<T, Spawner, S, B> Service<ServiceRequest> for VerifyMiddleware<T, Spawner, S>
|
||||
where
|
||||
T: SignatureVerify + Clone + 'static,
|
||||
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = actix_web::Error> + 'static,
|
||||
|
@ -303,7 +304,6 @@ where
|
|||
"Signature Verification",
|
||||
signature.kind = tracing::field::Empty,
|
||||
signature.expected_kind = tracing::field::display(&self.2),
|
||||
signature.optional = tracing::field::display(&self.3),
|
||||
);
|
||||
let authorization = req.headers().get("Authorization").is_some();
|
||||
let signature = req.headers().get("Signature").is_some();
|
||||
|
@ -322,17 +322,9 @@ where
|
|||
}
|
||||
} else {
|
||||
span.record("signature.kind", &tracing::field::display("None"));
|
||||
|
||||
if self.3 {
|
||||
return Box::pin(self.0.call(req));
|
||||
}
|
||||
}
|
||||
|
||||
Box::pin(ready(Err(VerifyError::new(
|
||||
&span,
|
||||
VerifyErrorKind::MissingSignature,
|
||||
)
|
||||
.into())))
|
||||
Box::pin(self.0.call(req))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{create::Signed, Config, PrepareSignError, Sign};
|
||||
use crate::{create::Signed, Config, PrepareSignError, Sign, Spawn};
|
||||
use actix_rt::task::JoinError;
|
||||
use awc::{
|
||||
http::header::{HttpDate, InvalidHeaderValue, TryIntoHeaderValue},
|
||||
|
@ -7,9 +7,9 @@ use awc::{
|
|||
use std::{fmt::Display, future::Future, pin::Pin, time::SystemTime};
|
||||
|
||||
impl Sign for ClientRequest {
|
||||
fn authorization_signature<F, E, K>(
|
||||
fn authorization_signature<F, E, K, S>(
|
||||
mut self,
|
||||
config: Config,
|
||||
config: Config<S>,
|
||||
key_id: K,
|
||||
f: F,
|
||||
) -> Pin<Box<dyn Future<Output = Result<Self, E>>>>
|
||||
|
@ -17,11 +17,13 @@ impl Sign for ClientRequest {
|
|||
F: FnOnce(&str) -> Result<String, E> + Send + 'static,
|
||||
E: From<JoinError>
|
||||
+ From<PrepareSignError>
|
||||
+ From<crate::Canceled>
|
||||
+ From<InvalidHeaderValue>
|
||||
+ std::fmt::Debug
|
||||
+ Send
|
||||
+ 'static,
|
||||
K: Display + 'static,
|
||||
S: Spawn + 'static,
|
||||
Self: Sized,
|
||||
{
|
||||
Box::pin(async move {
|
||||
|
@ -31,9 +33,9 @@ impl Sign for ClientRequest {
|
|||
})
|
||||
}
|
||||
|
||||
fn signature<F, E, K>(
|
||||
fn signature<F, E, K, S>(
|
||||
mut self,
|
||||
config: Config,
|
||||
config: Config<S>,
|
||||
key_id: K,
|
||||
f: F,
|
||||
) -> Pin<Box<dyn Future<Output = Result<Self, E>>>>
|
||||
|
@ -42,10 +44,12 @@ impl Sign for ClientRequest {
|
|||
E: From<JoinError>
|
||||
+ From<PrepareSignError>
|
||||
+ From<InvalidHeaderValue>
|
||||
+ From<crate::Canceled>
|
||||
+ std::fmt::Debug
|
||||
+ Send
|
||||
+ 'static,
|
||||
K: Display + 'static,
|
||||
S: Spawn + 'static,
|
||||
Self: Sized,
|
||||
{
|
||||
Box::pin(async move {
|
||||
|
@ -56,16 +60,22 @@ impl Sign for ClientRequest {
|
|||
}
|
||||
}
|
||||
|
||||
async fn prepare<F, E, K>(
|
||||
async fn prepare<F, E, K, S>(
|
||||
request: &mut ClientRequest,
|
||||
config: &Config,
|
||||
config: &Config<S>,
|
||||
key_id: K,
|
||||
f: F,
|
||||
) -> Result<Signed, E>
|
||||
where
|
||||
F: FnOnce(&str) -> Result<String, E> + Send + 'static,
|
||||
E: From<JoinError> + From<PrepareSignError> + std::fmt::Debug + Send + 'static,
|
||||
E: From<JoinError>
|
||||
+ From<PrepareSignError>
|
||||
+ From<crate::Canceled>
|
||||
+ std::fmt::Debug
|
||||
+ Send
|
||||
+ 'static,
|
||||
K: Display,
|
||||
S: Spawn + 'static,
|
||||
{
|
||||
if config.set_date && !request.headers().contains_key("date") {
|
||||
request.headers_mut().insert(
|
||||
|
@ -103,7 +113,10 @@ where
|
|||
|
||||
let key_id = key_id.to_string();
|
||||
|
||||
let signed = actix_rt::task::spawn_blocking(move || unsigned.sign(key_id, f)).await??;
|
||||
let signed = config
|
||||
.spawner
|
||||
.spawn_blocking(move || unsigned.sign(key_id, f))
|
||||
.await??;
|
||||
|
||||
Ok(signed)
|
||||
}
|
||||
|
|
61
flake.lock
Normal file
61
flake.lock
Normal file
|
@ -0,0 +1,61 @@
|
|||
{
|
||||
"nodes": {
|
||||
"flake-utils": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1694529238,
|
||||
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1700794826,
|
||||
"narHash": "sha256-RyJTnTNKhO0yqRpDISk03I/4A67/dp96YRxc86YOPgU=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "5a09cb4b393d58f9ed0d9ca1555016a8543c2ac8",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
25
flake.nix
Normal file
25
flake.nix
Normal file
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
description = "http-signature-normalization";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, flake-utils }:
|
||||
flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
pkgs = import nixpkgs {
|
||||
inherit system;
|
||||
};
|
||||
in
|
||||
{
|
||||
packages.default = pkgs.hello;
|
||||
|
||||
devShell = with pkgs; mkShell {
|
||||
nativeBuildInputs = [ cargo cargo-expand cargo-outdated cargo-zigbuild clippy gcc protobuf rust-analyzer rustc rustfmt ];
|
||||
|
||||
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
|
||||
};
|
||||
});
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
[package]
|
||||
name = "http-signature-normalization-http"
|
||||
description = "An HTTP Signatures library that leaves the signing to you"
|
||||
version = "0.4.0"
|
||||
version = "0.5.0"
|
||||
authors = ["asonix <asonix@asonix.dog>"]
|
||||
license-file = "../LICENSE"
|
||||
license = "AGPL-3.0"
|
||||
readme = "../README.md"
|
||||
repository = "https://git.asonix.dog/Aardwolf/http-signature-normalization"
|
||||
keywords = ["http", "signatures", "digest"]
|
||||
|
@ -13,4 +13,4 @@ edition = "2018"
|
|||
|
||||
[dependencies]
|
||||
http = "0.2"
|
||||
http-signature-normalization = { version = "0.6.0", path = ".." }
|
||||
http-signature-normalization = { version = "0.7.0", path = ".." }
|
||||
|
|
661
http/LICENSE
Normal file
661
http/LICENSE
Normal file
|
@ -0,0 +1,661 @@
|
|||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3, 19 November 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU Affero General Public License is a free, copyleft license for
|
||||
software and other kinds of works, specifically designed to ensure
|
||||
cooperation with the community in the case of network server software.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
our General Public Licenses are intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
Developers that use our General Public Licenses protect your rights
|
||||
with two steps: (1) assert copyright on the software, and (2) offer
|
||||
you this License which gives you legal permission to copy, distribute
|
||||
and/or modify the software.
|
||||
|
||||
A secondary benefit of defending all users' freedom is that
|
||||
improvements made in alternate versions of the program, if they
|
||||
receive widespread use, become available for other developers to
|
||||
incorporate. Many developers of free software are heartened and
|
||||
encouraged by the resulting cooperation. However, in the case of
|
||||
software used on network servers, this result may fail to come about.
|
||||
The GNU General Public License permits making a modified version and
|
||||
letting the public access it on a server without ever releasing its
|
||||
source code to the public.
|
||||
|
||||
The GNU Affero General Public License is designed specifically to
|
||||
ensure that, in such cases, the modified source code becomes available
|
||||
to the community. It requires the operator of a network server to
|
||||
provide the source code of the modified version running there to the
|
||||
users of that server. Therefore, public use of a modified version, on
|
||||
a publicly accessible server, gives the public access to the source
|
||||
code of the modified version.
|
||||
|
||||
An older license, called the Affero General Public License and
|
||||
published by Affero, was designed to accomplish similar goals. This is
|
||||
a different license, not a version of the Affero GPL, but Affero has
|
||||
released a new version of the Affero GPL which permits relicensing under
|
||||
this license.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, if you modify the
|
||||
Program, your modified version must prominently offer all users
|
||||
interacting with it remotely through a computer network (if your version
|
||||
supports such interaction) an opportunity to receive the Corresponding
|
||||
Source of your version by providing access to the Corresponding Source
|
||||
from a network server at no charge, through some standard or customary
|
||||
means of facilitating copying of software. This Corresponding Source
|
||||
shall include the Corresponding Source for any work covered by version 3
|
||||
of the GNU General Public License that is incorporated pursuant to the
|
||||
following paragraph.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the work with which it is combined will remain governed by version
|
||||
3 of the GNU General Public License.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU Affero General Public License from time to time. Such new versions
|
||||
will be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU Affero General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU Affero General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU Affero General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published
|
||||
by the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If your software can interact with users remotely through a computer
|
||||
network, you should also make sure that it provides a way for users to
|
||||
get its source. For example, if your program is a web application, its
|
||||
interface could display a "Source" link that leads users to an archive
|
||||
of the code. There are many ways you could offer source, and different
|
||||
solutions will be better for different programs; see section 13 for the
|
||||
specific requirements.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
|
@ -1,9 +1,9 @@
|
|||
[package]
|
||||
name = "http-signature-normalization-reqwest"
|
||||
description = "An HTTP Signatures library that leaves the signing to you"
|
||||
version = "0.7.1"
|
||||
version = "0.12.0"
|
||||
authors = ["asonix <asonix@asonix.dog>"]
|
||||
license-file = "LICENSE"
|
||||
license = "AGPL-3.0"
|
||||
readme = "README.md"
|
||||
repository = "https://git.asonix.dog/Aardwolf/http-signature-normalization"
|
||||
keywords = ["http", "signatures", "digest", "reqwest"]
|
||||
|
@ -11,22 +11,26 @@ edition = "2021"
|
|||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
[features]
|
||||
default = ["sha-2", "sha-3"]
|
||||
middleware = ["reqwest-middleware"]
|
||||
digest = ["base64", "tokio"]
|
||||
sha-2 = ["digest", "sha2"]
|
||||
sha-3 = ["digest", "sha3"]
|
||||
default = ["sha-2", "default-spawner"]
|
||||
middleware = ["dep:reqwest-middleware"]
|
||||
default-spawner = ["dep:tokio"]
|
||||
digest = ["dep:base64"]
|
||||
ring = ["digest", "dep:ring"]
|
||||
sha-2 = ["digest", "dep:sha2"]
|
||||
sha-3 = ["digest", "dep:sha3"]
|
||||
|
||||
[[example]]
|
||||
name = "client"
|
||||
required-features = ["sha-2"]
|
||||
required-features = ["default-spawner", "ring"]
|
||||
|
||||
[dependencies]
|
||||
base64 = { version = "0.13", optional = true }
|
||||
http-signature-normalization = { version = "0.6.0", path = ".." }
|
||||
async-trait = "0.1.71"
|
||||
base64 = { version = "0.22", optional = true }
|
||||
http-signature-normalization = { version = "0.7.0", path = ".." }
|
||||
httpdate = "1.0.2"
|
||||
reqwest = { version = "0.11", default-features = false, features = ["json"] }
|
||||
reqwest-middleware = { version = "0.2.0", optional = true }
|
||||
reqwest = { version = "0.12", default-features = false, features = ["json"] }
|
||||
reqwest-middleware = { version = "0.3.0", optional = true }
|
||||
ring = { version = "0.17.5", optional = true }
|
||||
sha2 = { version = "0.10", optional = true }
|
||||
sha3 = { version = "0.10", optional = true }
|
||||
thiserror = "1.0"
|
||||
|
@ -35,7 +39,7 @@ tokio = { version = "1", default-features = false, features = [
|
|||
], optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
pretty_env_logger = "0.4"
|
||||
pretty_env_logger = "0.5"
|
||||
tokio = { version = "1", default-features = false, features = [
|
||||
"rt-multi-thread",
|
||||
"macros",
|
||||
|
|
968
reqwest/LICENSE
968
reqwest/LICENSE
File diff suppressed because it is too large
Load diff
|
@ -63,20 +63,13 @@ pub enum MyError {
|
|||
```
|
||||
|
||||
### Contributing
|
||||
Unless otherwise stated, all contributions to this project will be licensed under the CSL with
|
||||
the exceptions listed in the License section of this file.
|
||||
Feel free to open issues for anything you find an issue with. Please note that any contributed code will be licensed under the AGPLv3.
|
||||
|
||||
### License
|
||||
This work is licensed under the Cooperative Software License. This is not a Free Software
|
||||
License, but may be considered a "source-available License." For most hobbyists, self-employed
|
||||
developers, worker-owned companies, and cooperatives, this software can be used in most
|
||||
projects so long as this software is distributed under the terms of the CSL. For more
|
||||
information, see the provided LICENSE file. If none exists, the license can be found online
|
||||
[here](https://lynnesbian.space/csl/). If you are a free software project and wish to use this
|
||||
software under the terms of the GNU Affero General Public License, please contact me at
|
||||
[asonix@asonix.dog](mailto:asonix@asonix.dog) and we can sort that out. If you wish to use this
|
||||
project under any other license, especially in proprietary software, the answer is likely no.
|
||||
Copyright © 2022 Riley Trautman
|
||||
|
||||
Http Signature Normalization Reqwest is currently licensed under the AGPL to the Lemmy project, found
|
||||
at [github.com/LemmyNet/lemmy](https://github.com/LemmyNet/lemmy)
|
||||
HTTP Signature Normalization Reqwest is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
HTTP Signature Normalization Reqwest is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. This file is part of HTTP Signature Normalization Reqwest.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with HTTP Signature Normalization Reqwest. If not, see [http://www.gnu.org/licenses/](http://www.gnu.org/licenses/).
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use http_signature_normalization_reqwest::prelude::*;
|
||||
use base64::{engine::general_purpose::STANDARD, Engine};
|
||||
use http_signature_normalization_reqwest::{digest::ring::Sha256, prelude::*};
|
||||
use reqwest::{
|
||||
header::{ACCEPT, USER_AGENT},
|
||||
Client,
|
||||
};
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
async fn request(config: Config) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
let digest = Sha256::new();
|
||||
|
@ -16,7 +16,7 @@ async fn request(config: Config) -> Result<(), Box<dyn std::error::Error + Send
|
|||
.header(ACCEPT, "text/plain")
|
||||
.signature_with_digest(config, "my-key-id", digest, "Hewwo-owo", |s| {
|
||||
println!("Signing String\n{}", s);
|
||||
Ok(base64::encode(s)) as Result<_, MyError>
|
||||
Ok(STANDARD.encode(s)) as Result<_, MyError>
|
||||
})
|
||||
.await?;
|
||||
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
use crate::{Config, Sign, SignError};
|
||||
use crate::{Config, Sign, SignError, Spawn};
|
||||
use reqwest::{Body, Request, RequestBuilder};
|
||||
use std::{fmt::Display, future::Future, pin::Pin};
|
||||
use std::fmt::Display;
|
||||
|
||||
#[cfg(feature = "ring")]
|
||||
pub mod ring;
|
||||
#[cfg(feature = "sha-2")]
|
||||
mod sha2;
|
||||
#[cfg(feature = "sha-3")]
|
||||
|
@ -21,184 +23,195 @@ pub trait DigestCreate {
|
|||
/// It generates HTTP Signatures after the Digest header has been added, in order to have
|
||||
/// verification that the body has not been tampered with, or that the request can't be replayed by
|
||||
/// a malicious entity
|
||||
#[async_trait::async_trait]
|
||||
pub trait SignExt: Sign {
|
||||
fn authorization_signature_with_digest<F, E, K, D, V>(
|
||||
async fn authorization_signature_with_digest<F, E, K, S, D, V>(
|
||||
self,
|
||||
config: Config,
|
||||
config: Config<S>,
|
||||
key_id: K,
|
||||
digest: D,
|
||||
v: V,
|
||||
f: F,
|
||||
) -> Pin<Box<dyn Future<Output = Result<Request, E>> + Send>>
|
||||
) -> Result<Request, E>
|
||||
where
|
||||
F: FnOnce(&str) -> Result<String, E> + Send + 'static,
|
||||
E: From<SignError> + From<reqwest::Error>,
|
||||
E: From<SignError> + From<reqwest::Error> + Send + 'static,
|
||||
K: Display + Send + 'static,
|
||||
D: DigestCreate + Send + 'static,
|
||||
V: AsRef<[u8]> + Into<Body> + Send + 'static,
|
||||
S: Spawn + Send + Sync,
|
||||
Self: Sized;
|
||||
|
||||
fn signature_with_digest<F, E, K, D, V>(
|
||||
async fn signature_with_digest<F, E, K, S, D, V>(
|
||||
self,
|
||||
config: Config,
|
||||
config: Config<S>,
|
||||
key_id: K,
|
||||
digest: D,
|
||||
v: V,
|
||||
f: F,
|
||||
) -> Pin<Box<dyn Future<Output = Result<Request, E>> + Send>>
|
||||
) -> Result<Request, E>
|
||||
where
|
||||
F: FnOnce(&str) -> Result<String, E> + Send + 'static,
|
||||
E: From<SignError> + From<reqwest::Error>,
|
||||
E: From<SignError> + From<reqwest::Error> + Send + 'static,
|
||||
K: Display + Send + 'static,
|
||||
D: DigestCreate + Send + 'static,
|
||||
V: AsRef<[u8]> + Into<Body> + Send + 'static,
|
||||
S: Spawn + Send + Sync,
|
||||
Self: Sized;
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl SignExt for RequestBuilder {
|
||||
fn authorization_signature_with_digest<F, E, K, D, V>(
|
||||
async fn authorization_signature_with_digest<F, E, K, S, D, V>(
|
||||
self,
|
||||
config: Config,
|
||||
config: Config<S>,
|
||||
key_id: K,
|
||||
mut digest: D,
|
||||
v: V,
|
||||
f: F,
|
||||
) -> Pin<Box<dyn Future<Output = Result<Request, E>> + Send>>
|
||||
) -> Result<Request, E>
|
||||
where
|
||||
F: FnOnce(&str) -> Result<String, E> + Send + 'static,
|
||||
E: From<SignError> + From<reqwest::Error>,
|
||||
E: From<SignError> + From<reqwest::Error> + Send + 'static,
|
||||
K: Display + Send + 'static,
|
||||
D: DigestCreate + Send + 'static,
|
||||
V: AsRef<[u8]> + Into<Body> + Send + 'static,
|
||||
Self: Sized,
|
||||
S: Spawn + Send + Sync,
|
||||
{
|
||||
Box::pin(async move {
|
||||
let (v, digest) = tokio::task::spawn_blocking(move || {
|
||||
let (v, digest) = config
|
||||
.spawner
|
||||
.spawn_blocking(move || {
|
||||
let digest = digest.compute(v.as_ref());
|
||||
(v, digest)
|
||||
})
|
||||
.await
|
||||
.map_err(|_| SignError::Canceled)?;
|
||||
|
||||
let mut req = self
|
||||
.header("Digest", format!("{}={}", D::NAME, digest))
|
||||
.authorization_signature(&config, key_id, f)?;
|
||||
let mut req = self
|
||||
.header("Digest", format!("{}={}", D::NAME, digest))
|
||||
.authorization_signature(&config, key_id, f)
|
||||
.await?;
|
||||
|
||||
*req.body_mut() = Some(Body::from(v.as_ref().to_vec()));
|
||||
*req.body_mut() = Some(Body::from(v.as_ref().to_vec()));
|
||||
|
||||
Ok(req)
|
||||
})
|
||||
Ok(req)
|
||||
}
|
||||
|
||||
fn signature_with_digest<F, E, K, D, V>(
|
||||
async fn signature_with_digest<F, E, K, S, D, V>(
|
||||
self,
|
||||
config: Config,
|
||||
config: Config<S>,
|
||||
key_id: K,
|
||||
mut digest: D,
|
||||
v: V,
|
||||
f: F,
|
||||
) -> Pin<Box<dyn Future<Output = Result<Request, E>> + Send>>
|
||||
) -> Result<Request, E>
|
||||
where
|
||||
F: FnOnce(&str) -> Result<String, E> + Send + 'static,
|
||||
E: From<SignError> + From<reqwest::Error>,
|
||||
E: From<SignError> + From<reqwest::Error> + Send + 'static,
|
||||
K: Display + Send + 'static,
|
||||
D: DigestCreate + Send + 'static,
|
||||
V: AsRef<[u8]> + Into<Body> + Send + 'static,
|
||||
Self: Sized,
|
||||
S: Spawn + Send + Sync,
|
||||
{
|
||||
Box::pin(async move {
|
||||
let (v, digest) = tokio::task::spawn_blocking(move || {
|
||||
let (v, digest) = config
|
||||
.spawner
|
||||
.spawn_blocking(move || {
|
||||
let digest = digest.compute(v.as_ref());
|
||||
(v, digest)
|
||||
})
|
||||
.await
|
||||
.map_err(|_| SignError::Canceled)?;
|
||||
|
||||
let mut req = self
|
||||
.header("Digest", format!("{}={}", D::NAME, digest))
|
||||
.signature(&config, key_id, f)?;
|
||||
let mut req = self
|
||||
.header("Digest", format!("{}={}", D::NAME, digest))
|
||||
.signature(&config, key_id, f)
|
||||
.await?;
|
||||
|
||||
*req.body_mut() = Some(Body::from(v.as_ref().to_vec()));
|
||||
*req.body_mut() = Some(Body::from(v.as_ref().to_vec()));
|
||||
|
||||
Ok(req)
|
||||
})
|
||||
Ok(req)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "middleware")]
|
||||
mod middleware {
|
||||
use super::{Config, DigestCreate, Sign, SignError, SignExt};
|
||||
use super::{Config, DigestCreate, Sign, SignError, SignExt, Spawn};
|
||||
use reqwest::{Body, Request};
|
||||
use reqwest_middleware::RequestBuilder;
|
||||
use std::{fmt::Display, future::Future, pin::Pin};
|
||||
use std::fmt::Display;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl SignExt for RequestBuilder {
|
||||
fn authorization_signature_with_digest<F, E, K, D, V>(
|
||||
async fn authorization_signature_with_digest<F, E, K, S, D, V>(
|
||||
self,
|
||||
config: Config,
|
||||
config: Config<S>,
|
||||
key_id: K,
|
||||
mut digest: D,
|
||||
v: V,
|
||||
f: F,
|
||||
) -> Pin<Box<dyn Future<Output = Result<Request, E>> + Send>>
|
||||
) -> Result<Request, E>
|
||||
where
|
||||
F: FnOnce(&str) -> Result<String, E> + Send + 'static,
|
||||
E: From<SignError> + From<reqwest::Error>,
|
||||
E: From<SignError> + From<reqwest::Error> + Send + 'static,
|
||||
K: Display + Send + 'static,
|
||||
D: DigestCreate + Send + 'static,
|
||||
V: AsRef<[u8]> + Into<Body> + Send + 'static,
|
||||
S: Spawn + Send + Sync,
|
||||
Self: Sized,
|
||||
{
|
||||
Box::pin(async move {
|
||||
let (v, digest) = tokio::task::spawn_blocking(move || {
|
||||
let (v, digest) = config
|
||||
.spawner
|
||||
.spawn_blocking(move || {
|
||||
let digest = digest.compute(v.as_ref());
|
||||
(v, digest)
|
||||
})
|
||||
.await
|
||||
.map_err(|_| SignError::Canceled)?;
|
||||
|
||||
let mut req = self
|
||||
.header("Digest", format!("{}={}", D::NAME, digest))
|
||||
.authorization_signature(&config, key_id, f)?;
|
||||
let mut req = self
|
||||
.header("Digest", format!("{}={}", D::NAME, digest))
|
||||
.authorization_signature(&config, key_id, f)
|
||||
.await?;
|
||||
|
||||
*req.body_mut() = Some(Body::from(v.as_ref().to_vec()));
|
||||
*req.body_mut() = Some(Body::from(v.as_ref().to_vec()));
|
||||
|
||||
Ok(req)
|
||||
})
|
||||
Ok(req)
|
||||
}
|
||||
|
||||
fn signature_with_digest<F, E, K, D, V>(
|
||||
async fn signature_with_digest<F, E, K, S, D, V>(
|
||||
self,
|
||||
config: Config,
|
||||
config: Config<S>,
|
||||
key_id: K,
|
||||
mut digest: D,
|
||||
v: V,
|
||||
f: F,
|
||||
) -> Pin<Box<dyn Future<Output = Result<Request, E>> + Send>>
|
||||
) -> Result<Request, E>
|
||||
where
|
||||
F: FnOnce(&str) -> Result<String, E> + Send + 'static,
|
||||
E: From<SignError> + From<reqwest::Error>,
|
||||
E: From<SignError> + From<reqwest::Error> + Send + 'static,
|
||||
K: Display + Send + 'static,
|
||||
D: DigestCreate + Send + 'static,
|
||||
V: AsRef<[u8]> + Into<Body> + Send + 'static,
|
||||
S: Spawn + Send + Sync,
|
||||
Self: Sized,
|
||||
{
|
||||
Box::pin(async move {
|
||||
let (v, digest) = tokio::task::spawn_blocking(move || {
|
||||
let (v, digest) = config
|
||||
.spawner
|
||||
.spawn_blocking(move || {
|
||||
let digest = digest.compute(v.as_ref());
|
||||
(v, digest)
|
||||
})
|
||||
.await
|
||||
.map_err(|_| SignError::Canceled)?;
|
||||
|
||||
let mut req = self
|
||||
.header("Digest", format!("{}={}", D::NAME, digest))
|
||||
.signature(&config, key_id, f)?;
|
||||
let mut req = self
|
||||
.header("Digest", format!("{}={}", D::NAME, digest))
|
||||
.signature(&config, key_id, f)
|
||||
.await?;
|
||||
|
||||
*req.body_mut() = Some(Body::from(v.as_ref().to_vec()));
|
||||
*req.body_mut() = Some(Body::from(v.as_ref().to_vec()));
|
||||
|
||||
Ok(req)
|
||||
})
|
||||
Ok(req)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
113
reqwest/src/digest/ring.rs
Normal file
113
reqwest/src/digest/ring.rs
Normal file
|
@ -0,0 +1,113 @@
|
|||
//! Types for creating digests with the `ring` cryptography library
|
||||
|
||||
use super::DigestCreate;
|
||||
|
||||
/// A Sha256 digest backed by ring
|
||||
#[derive(Clone)]
|
||||
pub struct Sha256 {
|
||||
ctx: ring::digest::Context,
|
||||
}
|
||||
|
||||
/// A Sha384 digest backed by ring
|
||||
#[derive(Clone)]
|
||||
pub struct Sha384 {
|
||||
ctx: ring::digest::Context,
|
||||
}
|
||||
|
||||
/// A Sha512 digest backed by ring
|
||||
#[derive(Clone)]
|
||||
pub struct Sha512 {
|
||||
ctx: ring::digest::Context,
|
||||
}
|
||||
|
||||
impl Sha256 {
|
||||
/// Create a new empty digest
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
/// Extract the context
|
||||
pub fn into_inner(self) -> ring::digest::Context {
|
||||
self.ctx
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Sha256 {
|
||||
fn default() -> Self {
|
||||
Sha256 {
|
||||
ctx: ring::digest::Context::new(&ring::digest::SHA256),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Sha384 {
|
||||
/// Create a new empty digest
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
/// Extract the context
|
||||
pub fn into_inner(self) -> ring::digest::Context {
|
||||
self.ctx
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Sha384 {
|
||||
fn default() -> Self {
|
||||
Sha384 {
|
||||
ctx: ring::digest::Context::new(&ring::digest::SHA384),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Sha512 {
|
||||
/// Create a new empty digest
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
/// Extract the context
|
||||
pub fn into_inner(self) -> ring::digest::Context {
|
||||
self.ctx
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Sha512 {
|
||||
fn default() -> Self {
|
||||
Sha512 {
|
||||
ctx: ring::digest::Context::new(&ring::digest::SHA512),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn create(mut context: ring::digest::Context, input: &[u8]) -> String {
|
||||
use base64::prelude::*;
|
||||
|
||||
context.update(input);
|
||||
let digest = context.finish();
|
||||
BASE64_STANDARD.encode(digest.as_ref())
|
||||
}
|
||||
|
||||
impl DigestCreate for Sha256 {
|
||||
const NAME: &'static str = "SHA-256";
|
||||
|
||||
fn compute(&mut self, input: &[u8]) -> String {
|
||||
create(self.ctx.clone(), input)
|
||||
}
|
||||
}
|
||||
|
||||
impl DigestCreate for Sha384 {
|
||||
const NAME: &'static str = "SHA-384";
|
||||
|
||||
fn compute(&mut self, input: &[u8]) -> String {
|
||||
create(self.ctx.clone(), input)
|
||||
}
|
||||
}
|
||||
|
||||
impl DigestCreate for Sha512 {
|
||||
const NAME: &'static str = "SHA-512";
|
||||
|
||||
fn compute(&mut self, input: &[u8]) -> String {
|
||||
create(self.ctx.clone(), input)
|
||||
}
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
use base64::prelude::*;
|
||||
use sha2::{Sha224, Sha256, Sha384, Sha512};
|
||||
|
||||
use super::DigestCreate;
|
||||
|
@ -7,7 +8,7 @@ fn create<D: sha2::Digest + sha2::digest::FixedOutputReset>(
|
|||
input: &[u8],
|
||||
) -> String {
|
||||
sha2::Digest::update(digest, input);
|
||||
base64::encode(&digest.finalize_reset())
|
||||
BASE64_STANDARD.encode(&digest.finalize_reset())
|
||||
}
|
||||
|
||||
impl DigestCreate for Sha224 {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use base64::prelude::*;
|
||||
use sha3::{
|
||||
Keccak224, Keccak256, Keccak256Full, Keccak384, Keccak512, Sha3_224, Sha3_256, Sha3_384,
|
||||
Sha3_512,
|
||||
|
@ -10,7 +11,7 @@ fn create<D: sha3::Digest + sha3::digest::FixedOutputReset>(
|
|||
input: &[u8],
|
||||
) -> String {
|
||||
sha3::Digest::update(digest, input);
|
||||
base64::encode(&digest.finalize_reset())
|
||||
BASE64_STANDARD.encode(&digest.finalize_reset())
|
||||
}
|
||||
|
||||
impl DigestCreate for Sha3_224 {
|
||||
|
|
|
@ -18,16 +18,23 @@ pub mod digest;
|
|||
pub mod prelude {
|
||||
pub use crate::{Config, Sign, SignError};
|
||||
|
||||
#[cfg(feature = "default-spawner")]
|
||||
pub use crate::default_spawner::DefaultSpawner;
|
||||
|
||||
#[cfg(feature = "digest")]
|
||||
pub use crate::digest::{DigestCreate, SignExt};
|
||||
}
|
||||
|
||||
#[cfg(feature = "default-spawner")]
|
||||
pub use default_spawner::DefaultSpawner;
|
||||
|
||||
#[cfg(feature = "default-spawner")]
|
||||
#[derive(Clone, Debug, Default)]
|
||||
/// Configuration for signing and verifying signatures
|
||||
///
|
||||
/// By default, the config is set up to create and verify signatures that expire after 10 seconds,
|
||||
/// and use the `(created)` and `(expires)` fields that were introduced in draft 11
|
||||
pub struct Config {
|
||||
pub struct Config<Spawner = DefaultSpawner> {
|
||||
/// The inner config type
|
||||
config: http_signature_normalization::Config,
|
||||
|
||||
|
@ -36,30 +43,133 @@ pub struct Config {
|
|||
|
||||
/// Whether to set the Date header
|
||||
set_date: bool,
|
||||
|
||||
/// How to spawn blocking tasks
|
||||
spawner: Spawner,
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "default-spawner"))]
|
||||
#[derive(Clone, Debug, Default)]
|
||||
/// Configuration for signing and verifying signatures
|
||||
///
|
||||
/// By default, the config is set up to create and verify signatures that expire after 10 seconds,
|
||||
/// and use the `(created)` and `(expires)` fields that were introduced in draft 11
|
||||
pub struct Config<Spawner> {
|
||||
/// The inner config type
|
||||
config: http_signature_normalization::Config,
|
||||
|
||||
/// Whether to set the Host header
|
||||
set_host: bool,
|
||||
|
||||
/// Whether to set the Date header
|
||||
set_date: bool,
|
||||
|
||||
/// How to spawn blocking tasks
|
||||
spawner: Spawner,
|
||||
}
|
||||
|
||||
#[cfg(feature = "default-spawner")]
|
||||
mod default_spawner {
|
||||
use super::{Canceled, Config, Spawn};
|
||||
|
||||
impl Config<DefaultSpawner> {
|
||||
/// Create a new config with the default spawner
|
||||
pub fn new() -> Self {
|
||||
Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
/// A default implementation of Spawner for spawning blocking operations
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
pub struct DefaultSpawner;
|
||||
|
||||
/// The future returned by DefaultSpawner when spawning blocking operations on the tokio
|
||||
/// blocking threadpool
|
||||
pub struct DefaultSpawnerFuture<Out> {
|
||||
inner: tokio::task::JoinHandle<Out>,
|
||||
}
|
||||
|
||||
impl Spawn for DefaultSpawner {
|
||||
type Future<T> = DefaultSpawnerFuture<T> where T: Send;
|
||||
|
||||
fn spawn_blocking<Func, Out>(&self, func: Func) -> Self::Future<Out>
|
||||
where
|
||||
Func: FnOnce() -> Out + Send + 'static,
|
||||
Out: Send + 'static,
|
||||
{
|
||||
DefaultSpawnerFuture {
|
||||
inner: tokio::task::spawn_blocking(func),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<Out> std::future::Future for DefaultSpawnerFuture<Out> {
|
||||
type Output = Result<Out, Canceled>;
|
||||
|
||||
fn poll(
|
||||
mut self: std::pin::Pin<&mut Self>,
|
||||
cx: &mut std::task::Context<'_>,
|
||||
) -> std::task::Poll<Self::Output> {
|
||||
let res = std::task::ready!(std::pin::Pin::new(&mut self.inner).poll(cx));
|
||||
|
||||
std::task::Poll::Ready(res.map_err(|_| Canceled))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// An error that indicates a blocking operation panicked and cannot return a response
|
||||
#[derive(Debug)]
|
||||
pub struct Canceled;
|
||||
|
||||
impl std::fmt::Display for Canceled {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "Operation was canceled")
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for Canceled {}
|
||||
|
||||
/// A trait dictating how to spawn a future onto a blocking threadpool. By default,
|
||||
/// http-signature-normalization-actix will use tokio's built-in blocking threadpool, but this
|
||||
/// can be customized
|
||||
pub trait Spawn {
|
||||
/// The future type returned by spawn_blocking
|
||||
type Future<T>: std::future::Future<Output = Result<T, Canceled>> + Send
|
||||
where
|
||||
T: Send;
|
||||
|
||||
/// Spawn the blocking function onto the threadpool
|
||||
fn spawn_blocking<Func, Out>(&self, func: Func) -> Self::Future<Out>
|
||||
where
|
||||
Func: FnOnce() -> Out + Send + 'static,
|
||||
Out: Send + 'static;
|
||||
}
|
||||
|
||||
/// A trait implemented by the reqwest RequestBuilder type to add an HTTP Signature to the request
|
||||
#[async_trait::async_trait]
|
||||
pub trait Sign {
|
||||
/// Add an Authorization Signature to the request
|
||||
fn authorization_signature<F, E, K>(
|
||||
async fn authorization_signature<F, E, K, S>(
|
||||
self,
|
||||
config: &Config,
|
||||
config: &Config<S>,
|
||||
key_id: K,
|
||||
f: F,
|
||||
) -> Result<Request, E>
|
||||
where
|
||||
Self: Sized,
|
||||
F: FnOnce(&str) -> Result<String, E>,
|
||||
E: From<SignError> + From<reqwest::Error>,
|
||||
K: Display;
|
||||
F: FnOnce(&str) -> Result<String, E> + Send + 'static,
|
||||
E: From<SignError> + From<reqwest::Error> + Send + 'static,
|
||||
K: Display + Send,
|
||||
S: Spawn + Send + Sync;
|
||||
|
||||
/// Add a Signature to the request
|
||||
fn signature<F, E, K>(self, config: &Config, key_id: K, f: F) -> Result<Request, E>
|
||||
async fn signature<F, E, K, S>(self, config: &Config<S>, key_id: K, f: F) -> Result<Request, E>
|
||||
where
|
||||
Self: Sized,
|
||||
F: FnOnce(&str) -> Result<String, E>,
|
||||
E: From<SignError> + From<reqwest::Error>,
|
||||
K: Display;
|
||||
F: FnOnce(&str) -> Result<String, E> + Send + 'static,
|
||||
E: From<SignError> + From<reqwest::Error> + Send + 'static,
|
||||
K: Display + Send,
|
||||
S: Spawn + Send + Sync;
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
|
@ -87,9 +197,15 @@ pub enum SignError {
|
|||
Canceled,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn new() -> Self {
|
||||
Default::default()
|
||||
impl<Spawner> Config<Spawner> {
|
||||
/// Create a new config with the provided spawner
|
||||
pub fn new_with_spawner(spawner: Spawner) -> Self {
|
||||
Config {
|
||||
config: Default::default(),
|
||||
set_host: Default::default(),
|
||||
set_date: Default::default(),
|
||||
spawner,
|
||||
}
|
||||
}
|
||||
|
||||
/// This method can be used to include the Host header in the HTTP Signature without
|
||||
|
@ -99,6 +215,7 @@ impl Config {
|
|||
config: self.config,
|
||||
set_host: true,
|
||||
set_date: self.set_date,
|
||||
spawner: self.spawner,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -111,6 +228,7 @@ impl Config {
|
|||
config: self.config.mastodon_compat(),
|
||||
set_host: true,
|
||||
set_date: true,
|
||||
spawner: self.spawner,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,6 +240,7 @@ impl Config {
|
|||
config: self.config.require_digest(),
|
||||
set_host: self.set_host,
|
||||
set_date: self.set_date,
|
||||
spawner: self.spawner,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -134,6 +253,7 @@ impl Config {
|
|||
config: self.config.dont_use_created_field(),
|
||||
set_host: self.set_host,
|
||||
set_date: self.set_date,
|
||||
spawner: self.spawner,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -143,6 +263,7 @@ impl Config {
|
|||
config: self.config.set_expiration(expiries_after),
|
||||
set_host: self.set_host,
|
||||
set_date: self.set_date,
|
||||
spawner: self.spawner,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -152,24 +273,36 @@ impl Config {
|
|||
config: self.config.require_header(header),
|
||||
set_host: self.set_host,
|
||||
set_date: self.set_date,
|
||||
spawner: self.spawner,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_spawner<NewSpawner: Spawn>(self, spawner: NewSpawner) -> Config<NewSpawner> {
|
||||
Config {
|
||||
config: self.config,
|
||||
set_host: self.set_host,
|
||||
set_date: self.set_date,
|
||||
spawner,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Sign for RequestBuilder {
|
||||
fn authorization_signature<F, E, K>(
|
||||
async fn authorization_signature<F, E, K, S>(
|
||||
self,
|
||||
config: &Config,
|
||||
config: &Config<S>,
|
||||
key_id: K,
|
||||
f: F,
|
||||
) -> Result<Request, E>
|
||||
where
|
||||
F: FnOnce(&str) -> Result<String, E>,
|
||||
E: From<SignError> + From<reqwest::Error>,
|
||||
K: Display,
|
||||
F: FnOnce(&str) -> Result<String, E> + Send + 'static,
|
||||
E: From<SignError> + From<reqwest::Error> + Send + 'static,
|
||||
K: Display + Send,
|
||||
S: Spawn + Send + Sync,
|
||||
{
|
||||
let mut request = self.build()?;
|
||||
let signed = prepare(&mut request, config, key_id, f)?;
|
||||
let signed = prepare(&mut request, config, key_id, f).await?;
|
||||
|
||||
let auth_header = signed.authorization_header();
|
||||
request.headers_mut().insert(
|
||||
|
@ -180,14 +313,15 @@ impl Sign for RequestBuilder {
|
|||
Ok(request)
|
||||
}
|
||||
|
||||
fn signature<F, E, K>(self, config: &Config, key_id: K, f: F) -> Result<Request, E>
|
||||
async fn signature<F, E, K, S>(self, config: &Config<S>, key_id: K, f: F) -> Result<Request, E>
|
||||
where
|
||||
F: FnOnce(&str) -> Result<String, E>,
|
||||
E: From<SignError> + From<reqwest::Error>,
|
||||
K: Display,
|
||||
F: FnOnce(&str) -> Result<String, E> + Send + 'static,
|
||||
E: From<SignError> + From<reqwest::Error> + Send + 'static,
|
||||
K: Display + Send,
|
||||
S: Spawn + Send + Sync,
|
||||
{
|
||||
let mut request = self.build()?;
|
||||
let signed = prepare(&mut request, config, key_id, f)?;
|
||||
let signed = prepare(&mut request, config, key_id, f).await?;
|
||||
|
||||
let sig_header = signed.signature_header();
|
||||
|
||||
|
@ -200,11 +334,17 @@ impl Sign for RequestBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
fn prepare<F, E, K>(req: &mut Request, config: &Config, key_id: K, f: F) -> Result<Signed, E>
|
||||
async fn prepare<F, E, K, S>(
|
||||
req: &mut Request,
|
||||
config: &Config<S>,
|
||||
key_id: K,
|
||||
f: F,
|
||||
) -> Result<Signed, E>
|
||||
where
|
||||
F: FnOnce(&str) -> Result<String, E>,
|
||||
E: From<SignError>,
|
||||
K: Display,
|
||||
F: FnOnce(&str) -> Result<String, E> + Send + 'static,
|
||||
E: From<SignError> + Send + 'static,
|
||||
K: Display + Send,
|
||||
S: Spawn,
|
||||
{
|
||||
if config.set_date && !req.headers().contains_key("date") {
|
||||
req.headers_mut().insert(
|
||||
|
@ -246,31 +386,38 @@ where
|
|||
.begin_sign(req.method().as_str(), &path_and_query, bt)
|
||||
.map_err(SignError::from)?;
|
||||
|
||||
let signed = unsigned.sign(key_id.to_string(), f)?;
|
||||
let key_string = key_id.to_string();
|
||||
let signed = config
|
||||
.spawner
|
||||
.spawn_blocking(move || unsigned.sign(key_string, f))
|
||||
.await
|
||||
.map_err(|_| SignError::Canceled)??;
|
||||
Ok(signed)
|
||||
}
|
||||
|
||||
#[cfg(feature = "middleware")]
|
||||
mod middleware {
|
||||
use super::{prepare, Config, Sign, SignError};
|
||||
use super::{prepare, Config, Sign, SignError, Spawn};
|
||||
use reqwest::Request;
|
||||
use reqwest_middleware::RequestBuilder;
|
||||
use std::fmt::Display;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Sign for RequestBuilder {
|
||||
fn authorization_signature<F, E, K>(
|
||||
async fn authorization_signature<F, E, K, S>(
|
||||
self,
|
||||
config: &Config,
|
||||
config: &Config<S>,
|
||||
key_id: K,
|
||||
f: F,
|
||||
) -> Result<Request, E>
|
||||
where
|
||||
F: FnOnce(&str) -> Result<String, E>,
|
||||
E: From<SignError> + From<reqwest::Error>,
|
||||
K: Display,
|
||||
F: FnOnce(&str) -> Result<String, E> + Send + 'static,
|
||||
E: From<SignError> + From<reqwest::Error> + Send + 'static,
|
||||
K: Display + Send,
|
||||
S: Spawn + Send + Sync,
|
||||
{
|
||||
let mut request = self.build()?;
|
||||
let signed = prepare(&mut request, config, key_id, f)?;
|
||||
let signed = prepare(&mut request, config, key_id, f).await?;
|
||||
|
||||
let auth_header = signed.authorization_header();
|
||||
request.headers_mut().insert(
|
||||
|
@ -281,14 +428,20 @@ mod middleware {
|
|||
Ok(request)
|
||||
}
|
||||
|
||||
fn signature<F, E, K>(self, config: &Config, key_id: K, f: F) -> Result<Request, E>
|
||||
async fn signature<F, E, K, S>(
|
||||
self,
|
||||
config: &Config<S>,
|
||||
key_id: K,
|
||||
f: F,
|
||||
) -> Result<Request, E>
|
||||
where
|
||||
F: FnOnce(&str) -> Result<String, E>,
|
||||
E: From<SignError> + From<reqwest::Error>,
|
||||
K: Display,
|
||||
F: FnOnce(&str) -> Result<String, E> + Send + 'static,
|
||||
E: From<SignError> + From<reqwest::Error> + Send + 'static,
|
||||
K: Display + Send,
|
||||
S: Spawn + Send + Sync,
|
||||
{
|
||||
let mut request = self.build()?;
|
||||
let signed = prepare(&mut request, config, key_id, f)?;
|
||||
let signed = prepare(&mut request, config, key_id, f).await?;
|
||||
|
||||
let sig_header = signed.signature_header();
|
||||
|
||||
|
|
|
@ -241,7 +241,7 @@ impl Config {
|
|||
})
|
||||
}
|
||||
|
||||
/// Perform the neccessary operations to produce and [`Unerified`] type, which can be used to
|
||||
/// Perform the neccessary operations to produce and [`Unverified`] type, which can be used to
|
||||
/// verify the header
|
||||
pub fn begin_verify(
|
||||
&self,
|
||||
|
|
|
@ -105,13 +105,35 @@ pub enum Algorithm {
|
|||
Unknown(String),
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
/// Indicator of which date field was checked for an expired error
|
||||
pub enum ExpiredField {
|
||||
/// (expires) pseudo-header
|
||||
Expires,
|
||||
|
||||
/// (created) pseudo-header
|
||||
Created,
|
||||
|
||||
/// Date header
|
||||
Date,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
/// Kinds of errors for validating a request
|
||||
pub enum ValidateError {
|
||||
/// The Authorization or Signature header is not present
|
||||
Missing,
|
||||
/// The request's `created` or `expires` field indicates it is too old to be valid
|
||||
Expired,
|
||||
Expired {
|
||||
/// Which field did the date come from
|
||||
field: ExpiredField,
|
||||
|
||||
/// When did the signature expire
|
||||
expires: SystemTime,
|
||||
|
||||
/// When was the signature checked
|
||||
checked: SystemTime,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
@ -180,20 +202,32 @@ impl Unvalidated {
|
|||
pub fn validate(self, expires_after: Duration) -> Result<Unverified, ValidateError> {
|
||||
if let Some(expires) = self.expires {
|
||||
if expires < self.parsed_at {
|
||||
return Err(ValidateError::Expired);
|
||||
return Err(ValidateError::Expired {
|
||||
field: ExpiredField::Expires,
|
||||
expires,
|
||||
checked: self.parsed_at,
|
||||
});
|
||||
}
|
||||
}
|
||||
if let Some(created) = self.created {
|
||||
if created + expires_after < self.parsed_at {
|
||||
return Err(ValidateError::Expired);
|
||||
return Err(ValidateError::Expired {
|
||||
field: ExpiredField::Created,
|
||||
expires: created + expires_after,
|
||||
checked: self.parsed_at,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(date) = self.date {
|
||||
if let Ok(datetime) = date.parse::<HttpDate>() {
|
||||
let system_time = SystemTime::from(datetime);
|
||||
if system_time + expires_after < self.parsed_at {
|
||||
return Err(ValidateError::Expired);
|
||||
let date = SystemTime::from(datetime);
|
||||
if date + expires_after < self.parsed_at {
|
||||
return Err(ValidateError::Expired {
|
||||
field: ExpiredField::Date,
|
||||
expires: date + expires_after,
|
||||
checked: self.parsed_at,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -370,24 +404,37 @@ impl Error for ParseSignatureError {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for ValidateError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
ValidateError::Missing => write!(f, "Http Signature is missing"),
|
||||
ValidateError::Expired => write!(f, "Http Signature is expired"),
|
||||
impl fmt::Display for ExpiredField {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::Expires => write!(f, "expires pseudo-header"),
|
||||
Self::Created => write!(f, "created pseudo-header"),
|
||||
Self::Date => write!(f, "Date header"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Error for ValidateError {
|
||||
fn description(&self) -> &'static str {
|
||||
impl fmt::Display for ValidateError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
ValidateError::Missing => "Http Signature is missing",
|
||||
ValidateError::Expired => "Http Signature is expired",
|
||||
ValidateError::Missing => write!(f, "Http Signature is missing"),
|
||||
ValidateError::Expired {
|
||||
field,
|
||||
expires,
|
||||
checked,
|
||||
} => write!(
|
||||
f,
|
||||
"Http Signature is expired, checked {}, checked at {}, expired at {}",
|
||||
field,
|
||||
httpdate::fmt_http_date(checked),
|
||||
httpdate::fmt_http_date(expires)
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Error for ValidateError {}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::ParsedHeader;
|
||||
|
|
661
warp/LICENSE
Normal file
661
warp/LICENSE
Normal file
|
@ -0,0 +1,661 @@
|
|||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3, 19 November 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU Affero General Public License is a free, copyleft license for
|
||||
software and other kinds of works, specifically designed to ensure
|
||||
cooperation with the community in the case of network server software.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
our General Public Licenses are intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
Developers that use our General Public Licenses protect your rights
|
||||
with two steps: (1) assert copyright on the software, and (2) offer
|
||||
you this License which gives you legal permission to copy, distribute
|
||||
and/or modify the software.
|
||||
|
||||
A secondary benefit of defending all users' freedom is that
|
||||
improvements made in alternate versions of the program, if they
|
||||
receive widespread use, become available for other developers to
|
||||
incorporate. Many developers of free software are heartened and
|
||||
encouraged by the resulting cooperation. However, in the case of
|
||||
software used on network servers, this result may fail to come about.
|
||||
The GNU General Public License permits making a modified version and
|
||||
letting the public access it on a server without ever releasing its
|
||||
source code to the public.
|
||||
|
||||
The GNU Affero General Public License is designed specifically to
|
||||
ensure that, in such cases, the modified source code becomes available
|
||||
to the community. It requires the operator of a network server to
|
||||
provide the source code of the modified version running there to the
|
||||
users of that server. Therefore, public use of a modified version, on
|
||||
a publicly accessible server, gives the public access to the source
|
||||
code of the modified version.
|
||||
|
||||
An older license, called the Affero General Public License and
|
||||
published by Affero, was designed to accomplish similar goals. This is
|
||||
a different license, not a version of the Affero GPL, but Affero has
|
||||
released a new version of the Affero GPL which permits relicensing under
|
||||
this license.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, if you modify the
|
||||
Program, your modified version must prominently offer all users
|
||||
interacting with it remotely through a computer network (if your version
|
||||
supports such interaction) an opportunity to receive the Corresponding
|
||||
Source of your version by providing access to the Corresponding Source
|
||||
from a network server at no charge, through some standard or customary
|
||||
means of facilitating copying of software. This Corresponding Source
|
||||
shall include the Corresponding Source for any work covered by version 3
|
||||
of the GNU General Public License that is incorporated pursuant to the
|
||||
following paragraph.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the work with which it is combined will remain governed by version
|
||||
3 of the GNU General Public License.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU Affero General Public License from time to time. Such new versions
|
||||
will be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU Affero General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU Affero General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU Affero General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published
|
||||
by the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If your software can interact with users remotely through a computer
|
||||
network, you should also make sure that it provides a way for users to
|
||||
get its source. For example, if your program is a web application, its
|
||||
interface could display a "Source" link that leads users to an archive
|
||||
of the code. There are many ways you could offer source, and different
|
||||
solutions will be better for different programs; see section 13 for the
|
||||
specific requirements.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
Loading…
Reference in a new issue