diff options
| author | Simeon Simeonov | 2021-12-23 14:41:14 +0100 |
|---|---|---|
| committer | Simeon Simeonov | 2021-12-23 14:41:14 +0100 |
| commit | 4914b0c74ed669d6631897950ff1660ce91ef918 (patch) | |
| tree | 5bef79607256853f41fb3bb666e1c16604a7b258 | |
Initial commit and release for Christmas with love1.0.0
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | COPYING | 674 | ||||
| -rw-r--r-- | LICENSE | 674 | ||||
| -rw-r--r-- | README.md | 289 | ||||
| -rw-r--r-- | etoolkit/__init__.py | 34 | ||||
| -rw-r--r-- | etoolkit/__main__.py | 276 | ||||
| -rwxr-xr-x | etoolkit/etoolkit.py | 406 | ||||
| -rw-r--r-- | etoolkit_sample.json | 21 | ||||
| -rw-r--r-- | setup.py | 56 | ||||
| -rw-r--r-- | tests/conftest.py | 59 | ||||
| -rw-r--r-- | tests/test_cli.py | 40 | ||||
| -rw-r--r-- | tests/test_envtoolkit_instance.py | 64 | ||||
| -rw-r--r-- | tests/test_envtoolkit_instance_static.py | 102 |
13 files changed, 2696 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c18dd8d --- /dev/null +++ b/.gitignore | |||
| @@ -0,0 +1 @@ | |||
| __pycache__/ | |||
| @@ -0,0 +1,674 @@ | |||
| 1 | GNU GENERAL PUBLIC LICENSE | ||
| 2 | Version 3, 29 June 2007 | ||
| 3 | |||
| 4 | Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> | ||
| 5 | Everyone is permitted to copy and distribute verbatim copies | ||
| 6 | of this license document, but changing it is not allowed. | ||
| 7 | |||
| 8 | Preamble | ||
| 9 | |||
| 10 | The GNU General Public License is a free, copyleft license for | ||
| 11 | software and other kinds of works. | ||
| 12 | |||
| 13 | The licenses for most software and other practical works are designed | ||
| 14 | to take away your freedom to share and change the works. By contrast, | ||
| 15 | the GNU General Public License is intended to guarantee your freedom to | ||
| 16 | share and change all versions of a program--to make sure it remains free | ||
| 17 | software for all its users. We, the Free Software Foundation, use the | ||
| 18 | GNU General Public License for most of our software; it applies also to | ||
| 19 | any other work released this way by its authors. You can apply it to | ||
| 20 | your programs, too. | ||
| 21 | |||
| 22 | When we speak of free software, we are referring to freedom, not | ||
| 23 | price. Our General Public Licenses are designed to make sure that you | ||
| 24 | have the freedom to distribute copies of free software (and charge for | ||
| 25 | them if you wish), that you receive source code or can get it if you | ||
| 26 | want it, that you can change the software or use pieces of it in new | ||
| 27 | free programs, and that you know you can do these things. | ||
| 28 | |||
| 29 | To protect your rights, we need to prevent others from denying you | ||
| 30 | these rights or asking you to surrender the rights. Therefore, you have | ||
| 31 | certain responsibilities if you distribute copies of the software, or if | ||
| 32 | you modify it: responsibilities to respect the freedom of others. | ||
| 33 | |||
| 34 | For example, if you distribute copies of such a program, whether | ||
| 35 | gratis or for a fee, you must pass on to the recipients the same | ||
| 36 | freedoms that you received. You must make sure that they, too, receive | ||
| 37 | or can get the source code. And you must show them these terms so they | ||
| 38 | know their rights. | ||
| 39 | |||
| 40 | Developers that use the GNU GPL protect your rights with two steps: | ||
| 41 | (1) assert copyright on the software, and (2) offer you this License | ||
| 42 | giving you legal permission to copy, distribute and/or modify it. | ||
| 43 | |||
| 44 | For the developers' and authors' protection, the GPL clearly explains | ||
| 45 | that there is no warranty for this free software. For both users' and | ||
| 46 | authors' sake, the GPL requires that modified versions be marked as | ||
| 47 | changed, so that their problems will not be attributed erroneously to | ||
| 48 | authors of previous versions. | ||
| 49 | |||
| 50 | Some devices are designed to deny users access to install or run | ||
| 51 | modified versions of the software inside them, although the manufacturer | ||
| 52 | can do so. This is fundamentally incompatible with the aim of | ||
| 53 | protecting users' freedom to change the software. The systematic | ||
| 54 | pattern of such abuse occurs in the area of products for individuals to | ||
| 55 | use, which is precisely where it is most unacceptable. Therefore, we | ||
| 56 | have designed this version of the GPL to prohibit the practice for those | ||
| 57 | products. If such problems arise substantially in other domains, we | ||
| 58 | stand ready to extend this provision to those domains in future versions | ||
| 59 | of the GPL, as needed to protect the freedom of users. | ||
| 60 | |||
| 61 | Finally, every program is threatened constantly by software patents. | ||
| 62 | States should not allow patents to restrict development and use of | ||
| 63 | software on general-purpose computers, but in those that do, we wish to | ||
| 64 | avoid the special danger that patents applied to a free program could | ||
| 65 | make it effectively proprietary. To prevent this, the GPL assures that | ||
| 66 | patents cannot be used to render the program non-free. | ||
| 67 | |||
| 68 | The precise terms and conditions for copying, distribution and | ||
| 69 | modification follow. | ||
| 70 | |||
| 71 | TERMS AND CONDITIONS | ||
| 72 | |||
| 73 | 0. Definitions. | ||
| 74 | |||
| 75 | "This License" refers to version 3 of the GNU General Public License. | ||
| 76 | |||
| 77 | "Copyright" also means copyright-like laws that apply to other kinds of | ||
| 78 | works, such as semiconductor masks. | ||
| 79 | |||
| 80 | "The Program" refers to any copyrightable work licensed under this | ||
| 81 | License. Each licensee is addressed as "you". "Licensees" and | ||
| 82 | "recipients" may be individuals or organizations. | ||
| 83 | |||
| 84 | To "modify" a work means to copy from or adapt all or part of the work | ||
| 85 | in a fashion requiring copyright permission, other than the making of an | ||
| 86 | exact copy. The resulting work is called a "modified version" of the | ||
| 87 | earlier work or a work "based on" the earlier work. | ||
| 88 | |||
| 89 | A "covered work" means either the unmodified Program or a work based | ||
| 90 | on the Program. | ||
| 91 | |||
| 92 | To "propagate" a work means to do anything with it that, without | ||
| 93 | permission, would make you directly or secondarily liable for | ||
| 94 | infringement under applicable copyright law, except executing it on a | ||
| 95 | computer or modifying a private copy. Propagation includes copying, | ||
| 96 | distribution (with or without modification), making available to the | ||
| 97 | public, and in some countries other activities as well. | ||
| 98 | |||
| 99 | To "convey" a work means any kind of propagation that enables other | ||
| 100 | parties to make or receive copies. Mere interaction with a user through | ||
| 101 | a computer network, with no transfer of a copy, is not conveying. | ||
| 102 | |||
| 103 | An interactive user interface displays "Appropriate Legal Notices" | ||
| 104 | to the extent that it includes a convenient and prominently visible | ||
| 105 | feature that (1) displays an appropriate copyright notice, and (2) | ||
| 106 | tells the user that there is no warranty for the work (except to the | ||
| 107 | extent that warranties are provided), that licensees may convey the | ||
| 108 | work under this License, and how to view a copy of this License. If | ||
| 109 | the interface presents a list of user commands or options, such as a | ||
| 110 | menu, a prominent item in the list meets this criterion. | ||
| 111 | |||
| 112 | 1. Source Code. | ||
| 113 | |||
| 114 | The "source code" for a work means the preferred form of the work | ||
| 115 | for making modifications to it. "Object code" means any non-source | ||
| 116 | form of a work. | ||
| 117 | |||
| 118 | A "Standard Interface" means an interface that either is an official | ||
| 119 | standard defined by a recognized standards body, or, in the case of | ||
| 120 | interfaces specified for a particular programming language, one that | ||
| 121 | is widely used among developers working in that language. | ||
| 122 | |||
| 123 | The "System Libraries" of an executable work include anything, other | ||
| 124 | than the work as a whole, that (a) is included in the normal form of | ||
| 125 | packaging a Major Component, but which is not part of that Major | ||
| 126 | Component, and (b) serves only to enable use of the work with that | ||
| 127 | Major Component, or to implement a Standard Interface for which an | ||
| 128 | implementation is available to the public in source code form. A | ||
| 129 | "Major Component", in this context, means a major essential component | ||
| 130 | (kernel, window system, and so on) of the specific operating system | ||
| 131 | (if any) on which the executable work runs, or a compiler used to | ||
| 132 | produce the work, or an object code interpreter used to run it. | ||
| 133 | |||
| 134 | The "Corresponding Source" for a work in object code form means all | ||
| 135 | the source code needed to generate, install, and (for an executable | ||
| 136 | work) run the object code and to modify the work, including scripts to | ||
| 137 | control those activities. However, it does not include the work's | ||
| 138 | System Libraries, or general-purpose tools or generally available free | ||
| 139 | programs which are used unmodified in performing those activities but | ||
| 140 | which are not part of the work. For example, Corresponding Source | ||
| 141 | includes interface definition files associated with source files for | ||
| 142 | the work, and the source code for shared libraries and dynamically | ||
| 143 | linked subprograms that the work is specifically designed to require, | ||
| 144 | such as by intimate data communication or control flow between those | ||
| 145 | subprograms and other parts of the work. | ||
| 146 | |||
| 147 | The Corresponding Source need not include anything that users | ||
| 148 | can regenerate automatically from other parts of the Corresponding | ||
| 149 | Source. | ||
| 150 | |||
| 151 | The Corresponding Source for a work in source code form is that | ||
| 152 | same work. | ||
| 153 | |||
| 154 | 2. Basic Permissions. | ||
| 155 | |||
| 156 | All rights granted under this License are granted for the term of | ||
| 157 | copyright on the Program, and are irrevocable provided the stated | ||
| 158 | conditions are met. This License explicitly affirms your unlimited | ||
| 159 | permission to run the unmodified Program. The output from running a | ||
| 160 | covered work is covered by this License only if the output, given its | ||
| 161 | content, constitutes a covered work. This License acknowledges your | ||
| 162 | rights of fair use or other equivalent, as provided by copyright law. | ||
| 163 | |||
| 164 | You may make, run and propagate covered works that you do not | ||
| 165 | convey, without conditions so long as your license otherwise remains | ||
| 166 | in force. You may convey covered works to others for the sole purpose | ||
| 167 | of having them make modifications exclusively for you, or provide you | ||
| 168 | with facilities for running those works, provided that you comply with | ||
| 169 | the terms of this License in conveying all material for which you do | ||
| 170 | not control copyright. Those thus making or running the covered works | ||
| 171 | for you must do so exclusively on your behalf, under your direction | ||
| 172 | and control, on terms that prohibit them from making any copies of | ||
| 173 | your copyrighted material outside their relationship with you. | ||
| 174 | |||
| 175 | Conveying under any other circumstances is permitted solely under | ||
| 176 | the conditions stated below. Sublicensing is not allowed; section 10 | ||
| 177 | makes it unnecessary. | ||
| 178 | |||
| 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. | ||
| 180 | |||
| 181 | No covered work shall be deemed part of an effective technological | ||
| 182 | measure under any applicable law fulfilling obligations under article | ||
| 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or | ||
| 184 | similar laws prohibiting or restricting circumvention of such | ||
| 185 | measures. | ||
| 186 | |||
| 187 | When you convey a covered work, you waive any legal power to forbid | ||
| 188 | circumvention of technological measures to the extent such circumvention | ||
| 189 | is effected by exercising rights under this License with respect to | ||
| 190 | the covered work, and you disclaim any intention to limit operation or | ||
| 191 | modification of the work as a means of enforcing, against the work's | ||
| 192 | users, your or third parties' legal rights to forbid circumvention of | ||
| 193 | technological measures. | ||
| 194 | |||
| 195 | 4. Conveying Verbatim Copies. | ||
| 196 | |||
| 197 | You may convey verbatim copies of the Program's source code as you | ||
| 198 | receive it, in any medium, provided that you conspicuously and | ||
| 199 | appropriately publish on each copy an appropriate copyright notice; | ||
| 200 | keep intact all notices stating that this License and any | ||
| 201 | non-permissive terms added in accord with section 7 apply to the code; | ||
| 202 | keep intact all notices of the absence of any warranty; and give all | ||
| 203 | recipients a copy of this License along with the Program. | ||
| 204 | |||
| 205 | You may charge any price or no price for each copy that you convey, | ||
| 206 | and you may offer support or warranty protection for a fee. | ||
| 207 | |||
| 208 | 5. Conveying Modified Source Versions. | ||
| 209 | |||
| 210 | You may convey a work based on the Program, or the modifications to | ||
| 211 | produce it from the Program, in the form of source code under the | ||
| 212 | terms of section 4, provided that you also meet all of these conditions: | ||
| 213 | |||
| 214 | a) The work must carry prominent notices stating that you modified | ||
| 215 | it, and giving a relevant date. | ||
| 216 | |||
| 217 | b) The work must carry prominent notices stating that it is | ||
| 218 | released under this License and any conditions added under section | ||
| 219 | 7. This requirement modifies the requirement in section 4 to | ||
| 220 | "keep intact all notices". | ||
| 221 | |||
| 222 | c) You must license the entire work, as a whole, under this | ||
| 223 | License to anyone who comes into possession of a copy. This | ||
| 224 | License will therefore apply, along with any applicable section 7 | ||
| 225 | additional terms, to the whole of the work, and all its parts, | ||
| 226 | regardless of how they are packaged. This License gives no | ||
| 227 | permission to license the work in any other way, but it does not | ||
| 228 | invalidate such permission if you have separately received it. | ||
| 229 | |||
| 230 | d) If the work has interactive user interfaces, each must display | ||
| 231 | Appropriate Legal Notices; however, if the Program has interactive | ||
| 232 | interfaces that do not display Appropriate Legal Notices, your | ||
| 233 | work need not make them do so. | ||
| 234 | |||
| 235 | A compilation of a covered work with other separate and independent | ||
| 236 | works, which are not by their nature extensions of the covered work, | ||
| 237 | and which are not combined with it such as to form a larger program, | ||
| 238 | in or on a volume of a storage or distribution medium, is called an | ||
| 239 | "aggregate" if the compilation and its resulting copyright are not | ||
| 240 | used to limit the access or legal rights of the compilation's users | ||
| 241 | beyond what the individual works permit. Inclusion of a covered work | ||
| 242 | in an aggregate does not cause this License to apply to the other | ||
| 243 | parts of the aggregate. | ||
| 244 | |||
| 245 | 6. Conveying Non-Source Forms. | ||
| 246 | |||
| 247 | You may convey a covered work in object code form under the terms | ||
| 248 | of sections 4 and 5, provided that you also convey the | ||
| 249 | machine-readable Corresponding Source under the terms of this License, | ||
| 250 | in one of these ways: | ||
| 251 | |||
| 252 | a) Convey the object code in, or embodied in, a physical product | ||
| 253 | (including a physical distribution medium), accompanied by the | ||
| 254 | Corresponding Source fixed on a durable physical medium | ||
| 255 | customarily used for software interchange. | ||
| 256 | |||
| 257 | b) Convey the object code in, or embodied in, a physical product | ||
| 258 | (including a physical distribution medium), accompanied by a | ||
| 259 | written offer, valid for at least three years and valid for as | ||
| 260 | long as you offer spare parts or customer support for that product | ||
| 261 | model, to give anyone who possesses the object code either (1) a | ||
| 262 | copy of the Corresponding Source for all the software in the | ||
| 263 | product that is covered by this License, on a durable physical | ||
| 264 | medium customarily used for software interchange, for a price no | ||
| 265 | more than your reasonable cost of physically performing this | ||
| 266 | conveying of source, or (2) access to copy the | ||
| 267 | Corresponding Source from a network server at no charge. | ||
| 268 | |||
| 269 | c) Convey individual copies of the object code with a copy of the | ||
| 270 | written offer to provide the Corresponding Source. This | ||
| 271 | alternative is allowed only occasionally and noncommercially, and | ||
| 272 | only if you received the object code with such an offer, in accord | ||
| 273 | with subsection 6b. | ||
| 274 | |||
| 275 | d) Convey the object code by offering access from a designated | ||
| 276 | place (gratis or for a charge), and offer equivalent access to the | ||
| 277 | Corresponding Source in the same way through the same place at no | ||
| 278 | further charge. You need not require recipients to copy the | ||
| 279 | Corresponding Source along with the object code. If the place to | ||
| 280 | copy the object code is a network server, the Corresponding Source | ||
| 281 | may be on a different server (operated by you or a third party) | ||
| 282 | that supports equivalent copying facilities, provided you maintain | ||
| 283 | clear directions next to the object code saying where to find the | ||
| 284 | Corresponding Source. Regardless of what server hosts the | ||
| 285 | Corresponding Source, you remain obligated to ensure that it is | ||
| 286 | available for as long as needed to satisfy these requirements. | ||
| 287 | |||
| 288 | e) Convey the object code using peer-to-peer transmission, provided | ||
| 289 | you inform other peers where the object code and Corresponding | ||
| 290 | Source of the work are being offered to the general public at no | ||
| 291 | charge under subsection 6d. | ||
| 292 | |||
| 293 | A separable portion of the object code, whose source code is excluded | ||
| 294 | from the Corresponding Source as a System Library, need not be | ||
| 295 | included in conveying the object code work. | ||
| 296 | |||
| 297 | A "User Product" is either (1) a "consumer product", which means any | ||
| 298 | tangible personal property which is normally used for personal, family, | ||
| 299 | or household purposes, or (2) anything designed or sold for incorporation | ||
| 300 | into a dwelling. In determining whether a product is a consumer product, | ||
| 301 | doubtful cases shall be resolved in favor of coverage. For a particular | ||
| 302 | product received by a particular user, "normally used" refers to a | ||
| 303 | typical or common use of that class of product, regardless of the status | ||
| 304 | of the particular user or of the way in which the particular user | ||
| 305 | actually uses, or expects or is expected to use, the product. A product | ||
| 306 | is a consumer product regardless of whether the product has substantial | ||
| 307 | commercial, industrial or non-consumer uses, unless such uses represent | ||
| 308 | the only significant mode of use of the product. | ||
| 309 | |||
| 310 | "Installation Information" for a User Product means any methods, | ||
| 311 | procedures, authorization keys, or other information required to install | ||
| 312 | and execute modified versions of a covered work in that User Product from | ||
| 313 | a modified version of its Corresponding Source. The information must | ||
| 314 | suffice to ensure that the continued functioning of the modified object | ||
| 315 | code is in no case prevented or interfered with solely because | ||
| 316 | modification has been made. | ||
| 317 | |||
| 318 | If you convey an object code work under this section in, or with, or | ||
| 319 | specifically for use in, a User Product, and the conveying occurs as | ||
| 320 | part of a transaction in which the right of possession and use of the | ||
| 321 | User Product is transferred to the recipient in perpetuity or for a | ||
| 322 | fixed term (regardless of how the transaction is characterized), the | ||
| 323 | Corresponding Source conveyed under this section must be accompanied | ||
| 324 | by the Installation Information. But this requirement does not apply | ||
| 325 | if neither you nor any third party retains the ability to install | ||
| 326 | modified object code on the User Product (for example, the work has | ||
| 327 | been installed in ROM). | ||
| 328 | |||
| 329 | The requirement to provide Installation Information does not include a | ||
| 330 | requirement to continue to provide support service, warranty, or updates | ||
| 331 | for a work that has been modified or installed by the recipient, or for | ||
| 332 | the User Product in which it has been modified or installed. Access to a | ||
| 333 | network may be denied when the modification itself materially and | ||
| 334 | adversely affects the operation of the network or violates the rules and | ||
| 335 | protocols for communication across the network. | ||
| 336 | |||
| 337 | Corresponding Source conveyed, and Installation Information provided, | ||
| 338 | in accord with this section must be in a format that is publicly | ||
| 339 | documented (and with an implementation available to the public in | ||
| 340 | source code form), and must require no special password or key for | ||
| 341 | unpacking, reading or copying. | ||
| 342 | |||
| 343 | 7. Additional Terms. | ||
| 344 | |||
| 345 | "Additional permissions" are terms that supplement the terms of this | ||
| 346 | License by making exceptions from one or more of its conditions. | ||
| 347 | Additional permissions that are applicable to the entire Program shall | ||
| 348 | be treated as though they were included in this License, to the extent | ||
| 349 | that they are valid under applicable law. If additional permissions | ||
| 350 | apply only to part of the Program, that part may be used separately | ||
| 351 | under those permissions, but the entire Program remains governed by | ||
| 352 | this License without regard to the additional permissions. | ||
| 353 | |||
| 354 | When you convey a copy of a covered work, you may at your option | ||
| 355 | remove any additional permissions from that copy, or from any part of | ||
| 356 | it. (Additional permissions may be written to require their own | ||
| 357 | removal in certain cases when you modify the work.) You may place | ||
| 358 | additional permissions on material, added by you to a covered work, | ||
| 359 | for which you have or can give appropriate copyright permission. | ||
| 360 | |||
| 361 | Notwithstanding any other provision of this License, for material you | ||
| 362 | add to a covered work, you may (if authorized by the copyright holders of | ||
| 363 | that material) supplement the terms of this License with terms: | ||
| 364 | |||
| 365 | a) Disclaiming warranty or limiting liability differently from the | ||
| 366 | terms of sections 15 and 16 of this License; or | ||
| 367 | |||
| 368 | b) Requiring preservation of specified reasonable legal notices or | ||
| 369 | author attributions in that material or in the Appropriate Legal | ||
| 370 | Notices displayed by works containing it; or | ||
| 371 | |||
| 372 | c) Prohibiting misrepresentation of the origin of that material, or | ||
| 373 | requiring that modified versions of such material be marked in | ||
| 374 | reasonable ways as different from the original version; or | ||
| 375 | |||
| 376 | d) Limiting the use for publicity purposes of names of licensors or | ||
| 377 | authors of the material; or | ||
| 378 | |||
| 379 | e) Declining to grant rights under trademark law for use of some | ||
| 380 | trade names, trademarks, or service marks; or | ||
| 381 | |||
| 382 | f) Requiring indemnification of licensors and authors of that | ||
| 383 | material by anyone who conveys the material (or modified versions of | ||
| 384 | it) with contractual assumptions of liability to the recipient, for | ||
| 385 | any liability that these contractual assumptions directly impose on | ||
| 386 | those licensors and authors. | ||
| 387 | |||
| 388 | All other non-permissive additional terms are considered "further | ||
| 389 | restrictions" within the meaning of section 10. If the Program as you | ||
| 390 | received it, or any part of it, contains a notice stating that it is | ||
| 391 | governed by this License along with a term that is a further | ||
| 392 | restriction, you may remove that term. If a license document contains | ||
| 393 | a further restriction but permits relicensing or conveying under this | ||
| 394 | License, you may add to a covered work material governed by the terms | ||
| 395 | of that license document, provided that the further restriction does | ||
| 396 | not survive such relicensing or conveying. | ||
| 397 | |||
| 398 | If you add terms to a covered work in accord with this section, you | ||
| 399 | must place, in the relevant source files, a statement of the | ||
| 400 | additional terms that apply to those files, or a notice indicating | ||
| 401 | where to find the applicable terms. | ||
| 402 | |||
| 403 | Additional terms, permissive or non-permissive, may be stated in the | ||
| 404 | form of a separately written license, or stated as exceptions; | ||
| 405 | the above requirements apply either way. | ||
| 406 | |||
| 407 | 8. Termination. | ||
| 408 | |||
| 409 | You may not propagate or modify a covered work except as expressly | ||
| 410 | provided under this License. Any attempt otherwise to propagate or | ||
| 411 | modify it is void, and will automatically terminate your rights under | ||
| 412 | this License (including any patent licenses granted under the third | ||
| 413 | paragraph of section 11). | ||
| 414 | |||
| 415 | However, if you cease all violation of this License, then your | ||
| 416 | license from a particular copyright holder is reinstated (a) | ||
| 417 | provisionally, unless and until the copyright holder explicitly and | ||
| 418 | finally terminates your license, and (b) permanently, if the copyright | ||
| 419 | holder fails to notify you of the violation by some reasonable means | ||
| 420 | prior to 60 days after the cessation. | ||
| 421 | |||
| 422 | Moreover, your license from a particular copyright holder is | ||
| 423 | reinstated permanently if the copyright holder notifies you of the | ||
| 424 | violation by some reasonable means, this is the first time you have | ||
| 425 | received notice of violation of this License (for any work) from that | ||
| 426 | copyright holder, and you cure the violation prior to 30 days after | ||
| 427 | your receipt of the notice. | ||
| 428 | |||
| 429 | Termination of your rights under this section does not terminate the | ||
| 430 | licenses of parties who have received copies or rights from you under | ||
| 431 | this License. If your rights have been terminated and not permanently | ||
| 432 | reinstated, you do not qualify to receive new licenses for the same | ||
| 433 | material under section 10. | ||
| 434 | |||
| 435 | 9. Acceptance Not Required for Having Copies. | ||
| 436 | |||
| 437 | You are not required to accept this License in order to receive or | ||
| 438 | run a copy of the Program. Ancillary propagation of a covered work | ||
| 439 | occurring solely as a consequence of using peer-to-peer transmission | ||
| 440 | to receive a copy likewise does not require acceptance. However, | ||
| 441 | nothing other than this License grants you permission to propagate or | ||
| 442 | modify any covered work. These actions infringe copyright if you do | ||
| 443 | not accept this License. Therefore, by modifying or propagating a | ||
| 444 | covered work, you indicate your acceptance of this License to do so. | ||
| 445 | |||
| 446 | 10. Automatic Licensing of Downstream Recipients. | ||
| 447 | |||
| 448 | Each time you convey a covered work, the recipient automatically | ||
| 449 | receives a license from the original licensors, to run, modify and | ||
| 450 | propagate that work, subject to this License. You are not responsible | ||
| 451 | for enforcing compliance by third parties with this License. | ||
| 452 | |||
| 453 | An "entity transaction" is a transaction transferring control of an | ||
| 454 | organization, or substantially all assets of one, or subdividing an | ||
| 455 | organization, or merging organizations. If propagation of a covered | ||
| 456 | work results from an entity transaction, each party to that | ||
| 457 | transaction who receives a copy of the work also receives whatever | ||
| 458 | licenses to the work the party's predecessor in interest had or could | ||
| 459 | give under the previous paragraph, plus a right to possession of the | ||
| 460 | Corresponding Source of the work from the predecessor in interest, if | ||
| 461 | the predecessor has it or can get it with reasonable efforts. | ||
| 462 | |||
| 463 | You may not impose any further restrictions on the exercise of the | ||
| 464 | rights granted or affirmed under this License. For example, you may | ||
| 465 | not impose a license fee, royalty, or other charge for exercise of | ||
| 466 | rights granted under this License, and you may not initiate litigation | ||
| 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that | ||
| 468 | any patent claim is infringed by making, using, selling, offering for | ||
| 469 | sale, or importing the Program or any portion of it. | ||
| 470 | |||
| 471 | 11. Patents. | ||
| 472 | |||
| 473 | A "contributor" is a copyright holder who authorizes use under this | ||
| 474 | License of the Program or a work on which the Program is based. The | ||
| 475 | work thus licensed is called the contributor's "contributor version". | ||
| 476 | |||
| 477 | A contributor's "essential patent claims" are all patent claims | ||
| 478 | owned or controlled by the contributor, whether already acquired or | ||
| 479 | hereafter acquired, that would be infringed by some manner, permitted | ||
| 480 | by this License, of making, using, or selling its contributor version, | ||
| 481 | but do not include claims that would be infringed only as a | ||
| 482 | consequence of further modification of the contributor version. For | ||
| 483 | purposes of this definition, "control" includes the right to grant | ||
| 484 | patent sublicenses in a manner consistent with the requirements of | ||
| 485 | this License. | ||
| 486 | |||
| 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free | ||
| 488 | patent license under the contributor's essential patent claims, to | ||
| 489 | make, use, sell, offer for sale, import and otherwise run, modify and | ||
| 490 | propagate the contents of its contributor version. | ||
| 491 | |||
| 492 | In the following three paragraphs, a "patent license" is any express | ||
| 493 | agreement or commitment, however denominated, not to enforce a patent | ||
| 494 | (such as an express permission to practice a patent or covenant not to | ||
| 495 | sue for patent infringement). To "grant" such a patent license to a | ||
| 496 | party means to make such an agreement or commitment not to enforce a | ||
| 497 | patent against the party. | ||
| 498 | |||
| 499 | If you convey a covered work, knowingly relying on a patent license, | ||
| 500 | and the Corresponding Source of the work is not available for anyone | ||
| 501 | to copy, free of charge and under the terms of this License, through a | ||
| 502 | publicly available network server or other readily accessible means, | ||
| 503 | then you must either (1) cause the Corresponding Source to be so | ||
| 504 | available, or (2) arrange to deprive yourself of the benefit of the | ||
| 505 | patent license for this particular work, or (3) arrange, in a manner | ||
| 506 | consistent with the requirements of this License, to extend the patent | ||
| 507 | license to downstream recipients. "Knowingly relying" means you have | ||
| 508 | actual knowledge that, but for the patent license, your conveying the | ||
| 509 | covered work in a country, or your recipient's use of the covered work | ||
| 510 | in a country, would infringe one or more identifiable patents in that | ||
| 511 | country that you have reason to believe are valid. | ||
| 512 | |||
| 513 | If, pursuant to or in connection with a single transaction or | ||
| 514 | arrangement, you convey, or propagate by procuring conveyance of, a | ||
| 515 | covered work, and grant a patent license to some of the parties | ||
| 516 | receiving the covered work authorizing them to use, propagate, modify | ||
| 517 | or convey a specific copy of the covered work, then the patent license | ||
| 518 | you grant is automatically extended to all recipients of the covered | ||
| 519 | work and works based on it. | ||
| 520 | |||
| 521 | A patent license is "discriminatory" if it does not include within | ||
| 522 | the scope of its coverage, prohibits the exercise of, or is | ||
| 523 | conditioned on the non-exercise of one or more of the rights that are | ||
| 524 | specifically granted under this License. You may not convey a covered | ||
| 525 | work if you are a party to an arrangement with a third party that is | ||
| 526 | in the business of distributing software, under which you make payment | ||
| 527 | to the third party based on the extent of your activity of conveying | ||
| 528 | the work, and under which the third party grants, to any of the | ||
| 529 | parties who would receive the covered work from you, a discriminatory | ||
| 530 | patent license (a) in connection with copies of the covered work | ||
| 531 | conveyed by you (or copies made from those copies), or (b) primarily | ||
| 532 | for and in connection with specific products or compilations that | ||
| 533 | contain the covered work, unless you entered into that arrangement, | ||
| 534 | or that patent license was granted, prior to 28 March 2007. | ||
| 535 | |||
| 536 | Nothing in this License shall be construed as excluding or limiting | ||
| 537 | any implied license or other defenses to infringement that may | ||
| 538 | otherwise be available to you under applicable patent law. | ||
| 539 | |||
| 540 | 12. No Surrender of Others' Freedom. | ||
| 541 | |||
| 542 | If conditions are imposed on you (whether by court order, agreement or | ||
| 543 | otherwise) that contradict the conditions of this License, they do not | ||
| 544 | excuse you from the conditions of this License. If you cannot convey a | ||
| 545 | covered work so as to satisfy simultaneously your obligations under this | ||
| 546 | License and any other pertinent obligations, then as a consequence you may | ||
| 547 | not convey it at all. For example, if you agree to terms that obligate you | ||
| 548 | to collect a royalty for further conveying from those to whom you convey | ||
| 549 | the Program, the only way you could satisfy both those terms and this | ||
| 550 | License would be to refrain entirely from conveying the Program. | ||
| 551 | |||
| 552 | 13. Use with the GNU Affero General Public License. | ||
| 553 | |||
| 554 | Notwithstanding any other provision of this License, you have | ||
| 555 | permission to link or combine any covered work with a work licensed | ||
| 556 | under version 3 of the GNU Affero General Public License into a single | ||
| 557 | combined work, and to convey the resulting work. The terms of this | ||
| 558 | License will continue to apply to the part which is the covered work, | ||
| 559 | but the special requirements of the GNU Affero General Public License, | ||
| 560 | section 13, concerning interaction through a network will apply to the | ||
| 561 | combination as such. | ||
| 562 | |||
| 563 | 14. Revised Versions of this License. | ||
| 564 | |||
| 565 | The Free Software Foundation may publish revised and/or new versions of | ||
| 566 | the GNU General Public License from time to time. Such new versions will | ||
| 567 | be similar in spirit to the present version, but may differ in detail to | ||
| 568 | address new problems or concerns. | ||
| 569 | |||
| 570 | Each version is given a distinguishing version number. If the | ||
| 571 | Program specifies that a certain numbered version of the GNU General | ||
| 572 | Public License "or any later version" applies to it, you have the | ||
| 573 | option of following the terms and conditions either of that numbered | ||
| 574 | version or of any later version published by the Free Software | ||
| 575 | Foundation. If the Program does not specify a version number of the | ||
| 576 | GNU General Public License, you may choose any version ever published | ||
| 577 | by the Free Software Foundation. | ||
| 578 | |||
| 579 | If the Program specifies that a proxy can decide which future | ||
| 580 | versions of the GNU General Public License can be used, that proxy's | ||
| 581 | public statement of acceptance of a version permanently authorizes you | ||
| 582 | to choose that version for the Program. | ||
| 583 | |||
| 584 | Later license versions may give you additional or different | ||
| 585 | permissions. However, no additional obligations are imposed on any | ||
| 586 | author or copyright holder as a result of your choosing to follow a | ||
| 587 | later version. | ||
| 588 | |||
| 589 | 15. Disclaimer of Warranty. | ||
| 590 | |||
| 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY | ||
| 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT | ||
| 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY | ||
| 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, | ||
| 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM | ||
| 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF | ||
| 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. | ||
| 599 | |||
| 600 | 16. Limitation of Liability. | ||
| 601 | |||
| 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING | ||
| 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS | ||
| 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY | ||
| 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE | ||
| 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF | ||
| 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD | ||
| 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), | ||
| 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF | ||
| 610 | SUCH DAMAGES. | ||
| 611 | |||
| 612 | 17. Interpretation of Sections 15 and 16. | ||
| 613 | |||
| 614 | If the disclaimer of warranty and limitation of liability provided | ||
| 615 | above cannot be given local legal effect according to their terms, | ||
| 616 | reviewing courts shall apply local law that most closely approximates | ||
| 617 | an absolute waiver of all civil liability in connection with the | ||
| 618 | Program, unless a warranty or assumption of liability accompanies a | ||
| 619 | copy of the Program in return for a fee. | ||
| 620 | |||
| 621 | END OF TERMS AND CONDITIONS | ||
| 622 | |||
| 623 | How to Apply These Terms to Your New Programs | ||
| 624 | |||
| 625 | If you develop a new program, and you want it to be of the greatest | ||
| 626 | possible use to the public, the best way to achieve this is to make it | ||
| 627 | free software which everyone can redistribute and change under these terms. | ||
| 628 | |||
| 629 | To do so, attach the following notices to the program. It is safest | ||
| 630 | to attach them to the start of each source file to most effectively | ||
| 631 | state the exclusion of warranty; and each file should have at least | ||
| 632 | the "copyright" line and a pointer to where the full notice is found. | ||
| 633 | |||
| 634 | <one line to give the program's name and a brief idea of what it does.> | ||
| 635 | Copyright (C) <year> <name of author> | ||
| 636 | |||
| 637 | This program is free software: you can redistribute it and/or modify | ||
| 638 | it under the terms of the GNU General Public License as published by | ||
| 639 | the Free Software Foundation, either version 3 of the License, or | ||
| 640 | (at your option) any later version. | ||
| 641 | |||
| 642 | This program is distributed in the hope that it will be useful, | ||
| 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 645 | GNU General Public License for more details. | ||
| 646 | |||
| 647 | You should have received a copy of the GNU General Public License | ||
| 648 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 649 | |||
| 650 | Also add information on how to contact you by electronic and paper mail. | ||
| 651 | |||
| 652 | If the program does terminal interaction, make it output a short | ||
| 653 | notice like this when it starts in an interactive mode: | ||
| 654 | |||
| 655 | <program> Copyright (C) <year> <name of author> | ||
| 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. | ||
| 657 | This is free software, and you are welcome to redistribute it | ||
| 658 | under certain conditions; type `show c' for details. | ||
| 659 | |||
| 660 | The hypothetical commands `show w' and `show c' should show the appropriate | ||
| 661 | parts of the General Public License. Of course, your program's commands | ||
| 662 | might be different; for a GUI interface, you would use an "about box". | ||
| 663 | |||
| 664 | You should also get your employer (if you work as a programmer) or school, | ||
| 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. | ||
| 666 | For more information on this, and how to apply and follow the GNU GPL, see | ||
| 667 | <http://www.gnu.org/licenses/>. | ||
| 668 | |||
| 669 | The GNU General Public License does not permit incorporating your program | ||
| 670 | into proprietary programs. If your program is a subroutine library, you | ||
| 671 | may consider it more useful to permit linking proprietary applications with | ||
| 672 | the library. If this is what you want to do, use the GNU Lesser General | ||
| 673 | Public License instead of this License. But first, please read | ||
| 674 | <http://www.gnu.org/philosophy/why-not-lgpl.html>. | ||
| @@ -0,0 +1,674 @@ | |||
| 1 | GNU GENERAL PUBLIC LICENSE | ||
| 2 | Version 3, 29 June 2007 | ||
| 3 | |||
| 4 | Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> | ||
| 5 | Everyone is permitted to copy and distribute verbatim copies | ||
| 6 | of this license document, but changing it is not allowed. | ||
| 7 | |||
| 8 | Preamble | ||
| 9 | |||
| 10 | The GNU General Public License is a free, copyleft license for | ||
| 11 | software and other kinds of works. | ||
| 12 | |||
| 13 | The licenses for most software and other practical works are designed | ||
| 14 | to take away your freedom to share and change the works. By contrast, | ||
| 15 | the GNU General Public License is intended to guarantee your freedom to | ||
| 16 | share and change all versions of a program--to make sure it remains free | ||
| 17 | software for all its users. We, the Free Software Foundation, use the | ||
| 18 | GNU General Public License for most of our software; it applies also to | ||
| 19 | any other work released this way by its authors. You can apply it to | ||
| 20 | your programs, too. | ||
| 21 | |||
| 22 | When we speak of free software, we are referring to freedom, not | ||
| 23 | price. Our General Public Licenses are designed to make sure that you | ||
| 24 | have the freedom to distribute copies of free software (and charge for | ||
| 25 | them if you wish), that you receive source code or can get it if you | ||
| 26 | want it, that you can change the software or use pieces of it in new | ||
| 27 | free programs, and that you know you can do these things. | ||
| 28 | |||
| 29 | To protect your rights, we need to prevent others from denying you | ||
| 30 | these rights or asking you to surrender the rights. Therefore, you have | ||
| 31 | certain responsibilities if you distribute copies of the software, or if | ||
| 32 | you modify it: responsibilities to respect the freedom of others. | ||
| 33 | |||
| 34 | For example, if you distribute copies of such a program, whether | ||
| 35 | gratis or for a fee, you must pass on to the recipients the same | ||
| 36 | freedoms that you received. You must make sure that they, too, receive | ||
| 37 | or can get the source code. And you must show them these terms so they | ||
| 38 | know their rights. | ||
| 39 | |||
| 40 | Developers that use the GNU GPL protect your rights with two steps: | ||
| 41 | (1) assert copyright on the software, and (2) offer you this License | ||
| 42 | giving you legal permission to copy, distribute and/or modify it. | ||
| 43 | |||
| 44 | For the developers' and authors' protection, the GPL clearly explains | ||
| 45 | that there is no warranty for this free software. For both users' and | ||
| 46 | authors' sake, the GPL requires that modified versions be marked as | ||
| 47 | changed, so that their problems will not be attributed erroneously to | ||
| 48 | authors of previous versions. | ||
| 49 | |||
| 50 | Some devices are designed to deny users access to install or run | ||
| 51 | modified versions of the software inside them, although the manufacturer | ||
| 52 | can do so. This is fundamentally incompatible with the aim of | ||
| 53 | protecting users' freedom to change the software. The systematic | ||
| 54 | pattern of such abuse occurs in the area of products for individuals to | ||
| 55 | use, which is precisely where it is most unacceptable. Therefore, we | ||
| 56 | have designed this version of the GPL to prohibit the practice for those | ||
| 57 | products. If such problems arise substantially in other domains, we | ||
| 58 | stand ready to extend this provision to those domains in future versions | ||
| 59 | of the GPL, as needed to protect the freedom of users. | ||
| 60 | |||
| 61 | Finally, every program is threatened constantly by software patents. | ||
| 62 | States should not allow patents to restrict development and use of | ||
| 63 | software on general-purpose computers, but in those that do, we wish to | ||
| 64 | avoid the special danger that patents applied to a free program could | ||
| 65 | make it effectively proprietary. To prevent this, the GPL assures that | ||
| 66 | patents cannot be used to render the program non-free. | ||
| 67 | |||
| 68 | The precise terms and conditions for copying, distribution and | ||
| 69 | modification follow. | ||
| 70 | |||
| 71 | TERMS AND CONDITIONS | ||
| 72 | |||
| 73 | 0. Definitions. | ||
| 74 | |||
| 75 | "This License" refers to version 3 of the GNU General Public License. | ||
| 76 | |||
| 77 | "Copyright" also means copyright-like laws that apply to other kinds of | ||
| 78 | works, such as semiconductor masks. | ||
| 79 | |||
| 80 | "The Program" refers to any copyrightable work licensed under this | ||
| 81 | License. Each licensee is addressed as "you". "Licensees" and | ||
| 82 | "recipients" may be individuals or organizations. | ||
| 83 | |||
| 84 | To "modify" a work means to copy from or adapt all or part of the work | ||
| 85 | in a fashion requiring copyright permission, other than the making of an | ||
| 86 | exact copy. The resulting work is called a "modified version" of the | ||
| 87 | earlier work or a work "based on" the earlier work. | ||
| 88 | |||
| 89 | A "covered work" means either the unmodified Program or a work based | ||
| 90 | on the Program. | ||
| 91 | |||
| 92 | To "propagate" a work means to do anything with it that, without | ||
| 93 | permission, would make you directly or secondarily liable for | ||
| 94 | infringement under applicable copyright law, except executing it on a | ||
| 95 | computer or modifying a private copy. Propagation includes copying, | ||
| 96 | distribution (with or without modification), making available to the | ||
| 97 | public, and in some countries other activities as well. | ||
| 98 | |||
| 99 | To "convey" a work means any kind of propagation that enables other | ||
| 100 | parties to make or receive copies. Mere interaction with a user through | ||
| 101 | a computer network, with no transfer of a copy, is not conveying. | ||
| 102 | |||
| 103 | An interactive user interface displays "Appropriate Legal Notices" | ||
| 104 | to the extent that it includes a convenient and prominently visible | ||
| 105 | feature that (1) displays an appropriate copyright notice, and (2) | ||
| 106 | tells the user that there is no warranty for the work (except to the | ||
| 107 | extent that warranties are provided), that licensees may convey the | ||
| 108 | work under this License, and how to view a copy of this License. If | ||
| 109 | the interface presents a list of user commands or options, such as a | ||
| 110 | menu, a prominent item in the list meets this criterion. | ||
| 111 | |||
| 112 | 1. Source Code. | ||
| 113 | |||
| 114 | The "source code" for a work means the preferred form of the work | ||
| 115 | for making modifications to it. "Object code" means any non-source | ||
| 116 | form of a work. | ||
| 117 | |||
| 118 | A "Standard Interface" means an interface that either is an official | ||
| 119 | standard defined by a recognized standards body, or, in the case of | ||
| 120 | interfaces specified for a particular programming language, one that | ||
| 121 | is widely used among developers working in that language. | ||
| 122 | |||
| 123 | The "System Libraries" of an executable work include anything, other | ||
| 124 | than the work as a whole, that (a) is included in the normal form of | ||
| 125 | packaging a Major Component, but which is not part of that Major | ||
| 126 | Component, and (b) serves only to enable use of the work with that | ||
| 127 | Major Component, or to implement a Standard Interface for which an | ||
| 128 | implementation is available to the public in source code form. A | ||
| 129 | "Major Component", in this context, means a major essential component | ||
| 130 | (kernel, window system, and so on) of the specific operating system | ||
| 131 | (if any) on which the executable work runs, or a compiler used to | ||
| 132 | produce the work, or an object code interpreter used to run it. | ||
| 133 | |||
| 134 | The "Corresponding Source" for a work in object code form means all | ||
| 135 | the source code needed to generate, install, and (for an executable | ||
| 136 | work) run the object code and to modify the work, including scripts to | ||
| 137 | control those activities. However, it does not include the work's | ||
| 138 | System Libraries, or general-purpose tools or generally available free | ||
| 139 | programs which are used unmodified in performing those activities but | ||
| 140 | which are not part of the work. For example, Corresponding Source | ||
| 141 | includes interface definition files associated with source files for | ||
| 142 | the work, and the source code for shared libraries and dynamically | ||
| 143 | linked subprograms that the work is specifically designed to require, | ||
| 144 | such as by intimate data communication or control flow between those | ||
| 145 | subprograms and other parts of the work. | ||
| 146 | |||
| 147 | The Corresponding Source need not include anything that users | ||
| 148 | can regenerate automatically from other parts of the Corresponding | ||
| 149 | Source. | ||
| 150 | |||
| 151 | The Corresponding Source for a work in source code form is that | ||
| 152 | same work. | ||
| 153 | |||
| 154 | 2. Basic Permissions. | ||
| 155 | |||
| 156 | All rights granted under this License are granted for the term of | ||
| 157 | copyright on the Program, and are irrevocable provided the stated | ||
| 158 | conditions are met. This License explicitly affirms your unlimited | ||
| 159 | permission to run the unmodified Program. The output from running a | ||
| 160 | covered work is covered by this License only if the output, given its | ||
| 161 | content, constitutes a covered work. This License acknowledges your | ||
| 162 | rights of fair use or other equivalent, as provided by copyright law. | ||
| 163 | |||
| 164 | You may make, run and propagate covered works that you do not | ||
| 165 | convey, without conditions so long as your license otherwise remains | ||
| 166 | in force. You may convey covered works to others for the sole purpose | ||
| 167 | of having them make modifications exclusively for you, or provide you | ||
| 168 | with facilities for running those works, provided that you comply with | ||
| 169 | the terms of this License in conveying all material for which you do | ||
| 170 | not control copyright. Those thus making or running the covered works | ||
| 171 | for you must do so exclusively on your behalf, under your direction | ||
| 172 | and control, on terms that prohibit them from making any copies of | ||
| 173 | your copyrighted material outside their relationship with you. | ||
| 174 | |||
| 175 | Conveying under any other circumstances is permitted solely under | ||
| 176 | the conditions stated below. Sublicensing is not allowed; section 10 | ||
| 177 | makes it unnecessary. | ||
| 178 | |||
| 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. | ||
| 180 | |||
| 181 | No covered work shall be deemed part of an effective technological | ||
| 182 | measure under any applicable law fulfilling obligations under article | ||
| 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or | ||
| 184 | similar laws prohibiting or restricting circumvention of such | ||
| 185 | measures. | ||
| 186 | |||
| 187 | When you convey a covered work, you waive any legal power to forbid | ||
| 188 | circumvention of technological measures to the extent such circumvention | ||
| 189 | is effected by exercising rights under this License with respect to | ||
| 190 | the covered work, and you disclaim any intention to limit operation or | ||
| 191 | modification of the work as a means of enforcing, against the work's | ||
| 192 | users, your or third parties' legal rights to forbid circumvention of | ||
| 193 | technological measures. | ||
| 194 | |||
| 195 | 4. Conveying Verbatim Copies. | ||
| 196 | |||
| 197 | You may convey verbatim copies of the Program's source code as you | ||
| 198 | receive it, in any medium, provided that you conspicuously and | ||
| 199 | appropriately publish on each copy an appropriate copyright notice; | ||
| 200 | keep intact all notices stating that this License and any | ||
| 201 | non-permissive terms added in accord with section 7 apply to the code; | ||
| 202 | keep intact all notices of the absence of any warranty; and give all | ||
| 203 | recipients a copy of this License along with the Program. | ||
| 204 | |||
| 205 | You may charge any price or no price for each copy that you convey, | ||
| 206 | and you may offer support or warranty protection for a fee. | ||
| 207 | |||
| 208 | 5. Conveying Modified Source Versions. | ||
| 209 | |||
| 210 | You may convey a work based on the Program, or the modifications to | ||
| 211 | produce it from the Program, in the form of source code under the | ||
| 212 | terms of section 4, provided that you also meet all of these conditions: | ||
| 213 | |||
| 214 | a) The work must carry prominent notices stating that you modified | ||
| 215 | it, and giving a relevant date. | ||
| 216 | |||
| 217 | b) The work must carry prominent notices stating that it is | ||
| 218 | released under this License and any conditions added under section | ||
| 219 | 7. This requirement modifies the requirement in section 4 to | ||
| 220 | "keep intact all notices". | ||
| 221 | |||
| 222 | c) You must license the entire work, as a whole, under this | ||
| 223 | License to anyone who comes into possession of a copy. This | ||
| 224 | License will therefore apply, along with any applicable section 7 | ||
| 225 | additional terms, to the whole of the work, and all its parts, | ||
| 226 | regardless of how they are packaged. This License gives no | ||
| 227 | permission to license the work in any other way, but it does not | ||
| 228 | invalidate such permission if you have separately received it. | ||
| 229 | |||
| 230 | d) If the work has interactive user interfaces, each must display | ||
| 231 | Appropriate Legal Notices; however, if the Program has interactive | ||
| 232 | interfaces that do not display Appropriate Legal Notices, your | ||
| 233 | work need not make them do so. | ||
| 234 | |||
| 235 | A compilation of a covered work with other separate and independent | ||
| 236 | works, which are not by their nature extensions of the covered work, | ||
| 237 | and which are not combined with it such as to form a larger program, | ||
| 238 | in or on a volume of a storage or distribution medium, is called an | ||
| 239 | "aggregate" if the compilation and its resulting copyright are not | ||
| 240 | used to limit the access or legal rights of the compilation's users | ||
| 241 | beyond what the individual works permit. Inclusion of a covered work | ||
| 242 | in an aggregate does not cause this License to apply to the other | ||
| 243 | parts of the aggregate. | ||
| 244 | |||
| 245 | 6. Conveying Non-Source Forms. | ||
| 246 | |||
| 247 | You may convey a covered work in object code form under the terms | ||
| 248 | of sections 4 and 5, provided that you also convey the | ||
| 249 | machine-readable Corresponding Source under the terms of this License, | ||
| 250 | in one of these ways: | ||
| 251 | |||
| 252 | a) Convey the object code in, or embodied in, a physical product | ||
| 253 | (including a physical distribution medium), accompanied by the | ||
| 254 | Corresponding Source fixed on a durable physical medium | ||
| 255 | customarily used for software interchange. | ||
| 256 | |||
| 257 | b) Convey the object code in, or embodied in, a physical product | ||
| 258 | (including a physical distribution medium), accompanied by a | ||
| 259 | written offer, valid for at least three years and valid for as | ||
| 260 | long as you offer spare parts or customer support for that product | ||
| 261 | model, to give anyone who possesses the object code either (1) a | ||
| 262 | copy of the Corresponding Source for all the software in the | ||
| 263 | product that is covered by this License, on a durable physical | ||
| 264 | medium customarily used for software interchange, for a price no | ||
| 265 | more than your reasonable cost of physically performing this | ||
| 266 | conveying of source, or (2) access to copy the | ||
| 267 | Corresponding Source from a network server at no charge. | ||
| 268 | |||
| 269 | c) Convey individual copies of the object code with a copy of the | ||
| 270 | written offer to provide the Corresponding Source. This | ||
| 271 | alternative is allowed only occasionally and noncommercially, and | ||
| 272 | only if you received the object code with such an offer, in accord | ||
| 273 | with subsection 6b. | ||
| 274 | |||
| 275 | d) Convey the object code by offering access from a designated | ||
| 276 | place (gratis or for a charge), and offer equivalent access to the | ||
| 277 | Corresponding Source in the same way through the same place at no | ||
| 278 | further charge. You need not require recipients to copy the | ||
| 279 | Corresponding Source along with the object code. If the place to | ||
| 280 | copy the object code is a network server, the Corresponding Source | ||
| 281 | may be on a different server (operated by you or a third party) | ||
| 282 | that supports equivalent copying facilities, provided you maintain | ||
| 283 | clear directions next to the object code saying where to find the | ||
| 284 | Corresponding Source. Regardless of what server hosts the | ||
| 285 | Corresponding Source, you remain obligated to ensure that it is | ||
| 286 | available for as long as needed to satisfy these requirements. | ||
| 287 | |||
| 288 | e) Convey the object code using peer-to-peer transmission, provided | ||
| 289 | you inform other peers where the object code and Corresponding | ||
| 290 | Source of the work are being offered to the general public at no | ||
| 291 | charge under subsection 6d. | ||
| 292 | |||
| 293 | A separable portion of the object code, whose source code is excluded | ||
| 294 | from the Corresponding Source as a System Library, need not be | ||
| 295 | included in conveying the object code work. | ||
| 296 | |||
| 297 | A "User Product" is either (1) a "consumer product", which means any | ||
| 298 | tangible personal property which is normally used for personal, family, | ||
| 299 | or household purposes, or (2) anything designed or sold for incorporation | ||
| 300 | into a dwelling. In determining whether a product is a consumer product, | ||
| 301 | doubtful cases shall be resolved in favor of coverage. For a particular | ||
| 302 | product received by a particular user, "normally used" refers to a | ||
| 303 | typical or common use of that class of product, regardless of the status | ||
| 304 | of the particular user or of the way in which the particular user | ||
| 305 | actually uses, or expects or is expected to use, the product. A product | ||
| 306 | is a consumer product regardless of whether the product has substantial | ||
| 307 | commercial, industrial or non-consumer uses, unless such uses represent | ||
| 308 | the only significant mode of use of the product. | ||
| 309 | |||
| 310 | "Installation Information" for a User Product means any methods, | ||
| 311 | procedures, authorization keys, or other information required to install | ||
| 312 | and execute modified versions of a covered work in that User Product from | ||
| 313 | a modified version of its Corresponding Source. The information must | ||
| 314 | suffice to ensure that the continued functioning of the modified object | ||
| 315 | code is in no case prevented or interfered with solely because | ||
| 316 | modification has been made. | ||
| 317 | |||
| 318 | If you convey an object code work under this section in, or with, or | ||
| 319 | specifically for use in, a User Product, and the conveying occurs as | ||
| 320 | part of a transaction in which the right of possession and use of the | ||
| 321 | User Product is transferred to the recipient in perpetuity or for a | ||
| 322 | fixed term (regardless of how the transaction is characterized), the | ||
| 323 | Corresponding Source conveyed under this section must be accompanied | ||
| 324 | by the Installation Information. But this requirement does not apply | ||
| 325 | if neither you nor any third party retains the ability to install | ||
| 326 | modified object code on the User Product (for example, the work has | ||
| 327 | been installed in ROM). | ||
| 328 | |||
| 329 | The requirement to provide Installation Information does not include a | ||
| 330 | requirement to continue to provide support service, warranty, or updates | ||
| 331 | for a work that has been modified or installed by the recipient, or for | ||
| 332 | the User Product in which it has been modified or installed. Access to a | ||
| 333 | network may be denied when the modification itself materially and | ||
| 334 | adversely affects the operation of the network or violates the rules and | ||
| 335 | protocols for communication across the network. | ||
| 336 | |||
| 337 | Corresponding Source conveyed, and Installation Information provided, | ||
| 338 | in accord with this section must be in a format that is publicly | ||
| 339 | documented (and with an implementation available to the public in | ||
| 340 | source code form), and must require no special password or key for | ||
| 341 | unpacking, reading or copying. | ||
| 342 | |||
| 343 | 7. Additional Terms. | ||
| 344 | |||
| 345 | "Additional permissions" are terms that supplement the terms of this | ||
| 346 | License by making exceptions from one or more of its conditions. | ||
| 347 | Additional permissions that are applicable to the entire Program shall | ||
| 348 | be treated as though they were included in this License, to the extent | ||
| 349 | that they are valid under applicable law. If additional permissions | ||
| 350 | apply only to part of the Program, that part may be used separately | ||
| 351 | under those permissions, but the entire Program remains governed by | ||
| 352 | this License without regard to the additional permissions. | ||
| 353 | |||
| 354 | When you convey a copy of a covered work, you may at your option | ||
| 355 | remove any additional permissions from that copy, or from any part of | ||
| 356 | it. (Additional permissions may be written to require their own | ||
| 357 | removal in certain cases when you modify the work.) You may place | ||
| 358 | additional permissions on material, added by you to a covered work, | ||
| 359 | for which you have or can give appropriate copyright permission. | ||
| 360 | |||
| 361 | Notwithstanding any other provision of this License, for material you | ||
| 362 | add to a covered work, you may (if authorized by the copyright holders of | ||
| 363 | that material) supplement the terms of this License with terms: | ||
| 364 | |||
| 365 | a) Disclaiming warranty or limiting liability differently from the | ||
| 366 | terms of sections 15 and 16 of this License; or | ||
| 367 | |||
| 368 | b) Requiring preservation of specified reasonable legal notices or | ||
| 369 | author attributions in that material or in the Appropriate Legal | ||
| 370 | Notices displayed by works containing it; or | ||
| 371 | |||
| 372 | c) Prohibiting misrepresentation of the origin of that material, or | ||
| 373 | requiring that modified versions of such material be marked in | ||
| 374 | reasonable ways as different from the original version; or | ||
| 375 | |||
| 376 | d) Limiting the use for publicity purposes of names of licensors or | ||
| 377 | authors of the material; or | ||
| 378 | |||
| 379 | e) Declining to grant rights under trademark law for use of some | ||
| 380 | trade names, trademarks, or service marks; or | ||
| 381 | |||
| 382 | f) Requiring indemnification of licensors and authors of that | ||
| 383 | material by anyone who conveys the material (or modified versions of | ||
| 384 | it) with contractual assumptions of liability to the recipient, for | ||
| 385 | any liability that these contractual assumptions directly impose on | ||
| 386 | those licensors and authors. | ||
| 387 | |||
| 388 | All other non-permissive additional terms are considered "further | ||
| 389 | restrictions" within the meaning of section 10. If the Program as you | ||
| 390 | received it, or any part of it, contains a notice stating that it is | ||
| 391 | governed by this License along with a term that is a further | ||
| 392 | restriction, you may remove that term. If a license document contains | ||
| 393 | a further restriction but permits relicensing or conveying under this | ||
| 394 | License, you may add to a covered work material governed by the terms | ||
| 395 | of that license document, provided that the further restriction does | ||
| 396 | not survive such relicensing or conveying. | ||
| 397 | |||
| 398 | If you add terms to a covered work in accord with this section, you | ||
| 399 | must place, in the relevant source files, a statement of the | ||
| 400 | additional terms that apply to those files, or a notice indicating | ||
| 401 | where to find the applicable terms. | ||
| 402 | |||
| 403 | Additional terms, permissive or non-permissive, may be stated in the | ||
| 404 | form of a separately written license, or stated as exceptions; | ||
| 405 | the above requirements apply either way. | ||
| 406 | |||
| 407 | 8. Termination. | ||
| 408 | |||
| 409 | You may not propagate or modify a covered work except as expressly | ||
| 410 | provided under this License. Any attempt otherwise to propagate or | ||
| 411 | modify it is void, and will automatically terminate your rights under | ||
| 412 | this License (including any patent licenses granted under the third | ||
| 413 | paragraph of section 11). | ||
| 414 | |||
| 415 | However, if you cease all violation of this License, then your | ||
| 416 | license from a particular copyright holder is reinstated (a) | ||
| 417 | provisionally, unless and until the copyright holder explicitly and | ||
| 418 | finally terminates your license, and (b) permanently, if the copyright | ||
| 419 | holder fails to notify you of the violation by some reasonable means | ||
| 420 | prior to 60 days after the cessation. | ||
| 421 | |||
| 422 | Moreover, your license from a particular copyright holder is | ||
| 423 | reinstated permanently if the copyright holder notifies you of the | ||
| 424 | violation by some reasonable means, this is the first time you have | ||
| 425 | received notice of violation of this License (for any work) from that | ||
| 426 | copyright holder, and you cure the violation prior to 30 days after | ||
| 427 | your receipt of the notice. | ||
| 428 | |||
| 429 | Termination of your rights under this section does not terminate the | ||
| 430 | licenses of parties who have received copies or rights from you under | ||
| 431 | this License. If your rights have been terminated and not permanently | ||
| 432 | reinstated, you do not qualify to receive new licenses for the same | ||
| 433 | material under section 10. | ||
| 434 | |||
| 435 | 9. Acceptance Not Required for Having Copies. | ||
| 436 | |||
| 437 | You are not required to accept this License in order to receive or | ||
| 438 | run a copy of the Program. Ancillary propagation of a covered work | ||
| 439 | occurring solely as a consequence of using peer-to-peer transmission | ||
| 440 | to receive a copy likewise does not require acceptance. However, | ||
| 441 | nothing other than this License grants you permission to propagate or | ||
| 442 | modify any covered work. These actions infringe copyright if you do | ||
| 443 | not accept this License. Therefore, by modifying or propagating a | ||
| 444 | covered work, you indicate your acceptance of this License to do so. | ||
| 445 | |||
| 446 | 10. Automatic Licensing of Downstream Recipients. | ||
| 447 | |||
| 448 | Each time you convey a covered work, the recipient automatically | ||
| 449 | receives a license from the original licensors, to run, modify and | ||
| 450 | propagate that work, subject to this License. You are not responsible | ||
| 451 | for enforcing compliance by third parties with this License. | ||
| 452 | |||
| 453 | An "entity transaction" is a transaction transferring control of an | ||
| 454 | organization, or substantially all assets of one, or subdividing an | ||
| 455 | organization, or merging organizations. If propagation of a covered | ||
| 456 | work results from an entity transaction, each party to that | ||
| 457 | transaction who receives a copy of the work also receives whatever | ||
| 458 | licenses to the work the party's predecessor in interest had or could | ||
| 459 | give under the previous paragraph, plus a right to possession of the | ||
| 460 | Corresponding Source of the work from the predecessor in interest, if | ||
| 461 | the predecessor has it or can get it with reasonable efforts. | ||
| 462 | |||
| 463 | You may not impose any further restrictions on the exercise of the | ||
| 464 | rights granted or affirmed under this License. For example, you may | ||
| 465 | not impose a license fee, royalty, or other charge for exercise of | ||
| 466 | rights granted under this License, and you may not initiate litigation | ||
| 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that | ||
| 468 | any patent claim is infringed by making, using, selling, offering for | ||
| 469 | sale, or importing the Program or any portion of it. | ||
| 470 | |||
| 471 | 11. Patents. | ||
| 472 | |||
| 473 | A "contributor" is a copyright holder who authorizes use under this | ||
| 474 | License of the Program or a work on which the Program is based. The | ||
| 475 | work thus licensed is called the contributor's "contributor version". | ||
| 476 | |||
| 477 | A contributor's "essential patent claims" are all patent claims | ||
| 478 | owned or controlled by the contributor, whether already acquired or | ||
| 479 | hereafter acquired, that would be infringed by some manner, permitted | ||
| 480 | by this License, of making, using, or selling its contributor version, | ||
| 481 | but do not include claims that would be infringed only as a | ||
| 482 | consequence of further modification of the contributor version. For | ||
| 483 | purposes of this definition, "control" includes the right to grant | ||
| 484 | patent sublicenses in a manner consistent with the requirements of | ||
| 485 | this License. | ||
| 486 | |||
| 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free | ||
| 488 | patent license under the contributor's essential patent claims, to | ||
| 489 | make, use, sell, offer for sale, import and otherwise run, modify and | ||
| 490 | propagate the contents of its contributor version. | ||
| 491 | |||
| 492 | In the following three paragraphs, a "patent license" is any express | ||
| 493 | agreement or commitment, however denominated, not to enforce a patent | ||
| 494 | (such as an express permission to practice a patent or covenant not to | ||
| 495 | sue for patent infringement). To "grant" such a patent license to a | ||
| 496 | party means to make such an agreement or commitment not to enforce a | ||
| 497 | patent against the party. | ||
| 498 | |||
| 499 | If you convey a covered work, knowingly relying on a patent license, | ||
| 500 | and the Corresponding Source of the work is not available for anyone | ||
| 501 | to copy, free of charge and under the terms of this License, through a | ||
| 502 | publicly available network server or other readily accessible means, | ||
| 503 | then you must either (1) cause the Corresponding Source to be so | ||
| 504 | available, or (2) arrange to deprive yourself of the benefit of the | ||
| 505 | patent license for this particular work, or (3) arrange, in a manner | ||
| 506 | consistent with the requirements of this License, to extend the patent | ||
| 507 | license to downstream recipients. "Knowingly relying" means you have | ||
| 508 | actual knowledge that, but for the patent license, your conveying the | ||
| 509 | covered work in a country, or your recipient's use of the covered work | ||
| 510 | in a country, would infringe one or more identifiable patents in that | ||
| 511 | country that you have reason to believe are valid. | ||
| 512 | |||
| 513 | If, pursuant to or in connection with a single transaction or | ||
| 514 | arrangement, you convey, or propagate by procuring conveyance of, a | ||
| 515 | covered work, and grant a patent license to some of the parties | ||
| 516 | receiving the covered work authorizing them to use, propagate, modify | ||
| 517 | or convey a specific copy of the covered work, then the patent license | ||
| 518 | you grant is automatically extended to all recipients of the covered | ||
| 519 | work and works based on it. | ||
| 520 | |||
| 521 | A patent license is "discriminatory" if it does not include within | ||
| 522 | the scope of its coverage, prohibits the exercise of, or is | ||
| 523 | conditioned on the non-exercise of one or more of the rights that are | ||
| 524 | specifically granted under this License. You may not convey a covered | ||
| 525 | work if you are a party to an arrangement with a third party that is | ||
| 526 | in the business of distributing software, under which you make payment | ||
| 527 | to the third party based on the extent of your activity of conveying | ||
| 528 | the work, and under which the third party grants, to any of the | ||
| 529 | parties who would receive the covered work from you, a discriminatory | ||
| 530 | patent license (a) in connection with copies of the covered work | ||
| 531 | conveyed by you (or copies made from those copies), or (b) primarily | ||
| 532 | for and in connection with specific products or compilations that | ||
| 533 | contain the covered work, unless you entered into that arrangement, | ||
| 534 | or that patent license was granted, prior to 28 March 2007. | ||
| 535 | |||
| 536 | Nothing in this License shall be construed as excluding or limiting | ||
| 537 | any implied license or other defenses to infringement that may | ||
| 538 | otherwise be available to you under applicable patent law. | ||
| 539 | |||
| 540 | 12. No Surrender of Others' Freedom. | ||
| 541 | |||
| 542 | If conditions are imposed on you (whether by court order, agreement or | ||
| 543 | otherwise) that contradict the conditions of this License, they do not | ||
| 544 | excuse you from the conditions of this License. If you cannot convey a | ||
| 545 | covered work so as to satisfy simultaneously your obligations under this | ||
| 546 | License and any other pertinent obligations, then as a consequence you may | ||
| 547 | not convey it at all. For example, if you agree to terms that obligate you | ||
| 548 | to collect a royalty for further conveying from those to whom you convey | ||
| 549 | the Program, the only way you could satisfy both those terms and this | ||
| 550 | License would be to refrain entirely from conveying the Program. | ||
| 551 | |||
| 552 | 13. Use with the GNU Affero General Public License. | ||
| 553 | |||
| 554 | Notwithstanding any other provision of this License, you have | ||
| 555 | permission to link or combine any covered work with a work licensed | ||
| 556 | under version 3 of the GNU Affero General Public License into a single | ||
| 557 | combined work, and to convey the resulting work. The terms of this | ||
| 558 | License will continue to apply to the part which is the covered work, | ||
| 559 | but the special requirements of the GNU Affero General Public License, | ||
| 560 | section 13, concerning interaction through a network will apply to the | ||
| 561 | combination as such. | ||
| 562 | |||
| 563 | 14. Revised Versions of this License. | ||
| 564 | |||
| 565 | The Free Software Foundation may publish revised and/or new versions of | ||
| 566 | the GNU General Public License from time to time. Such new versions will | ||
| 567 | be similar in spirit to the present version, but may differ in detail to | ||
| 568 | address new problems or concerns. | ||
| 569 | |||
| 570 | Each version is given a distinguishing version number. If the | ||
| 571 | Program specifies that a certain numbered version of the GNU General | ||
| 572 | Public License "or any later version" applies to it, you have the | ||
| 573 | option of following the terms and conditions either of that numbered | ||
| 574 | version or of any later version published by the Free Software | ||
| 575 | Foundation. If the Program does not specify a version number of the | ||
| 576 | GNU General Public License, you may choose any version ever published | ||
| 577 | by the Free Software Foundation. | ||
| 578 | |||
| 579 | If the Program specifies that a proxy can decide which future | ||
| 580 | versions of the GNU General Public License can be used, that proxy's | ||
| 581 | public statement of acceptance of a version permanently authorizes you | ||
| 582 | to choose that version for the Program. | ||
| 583 | |||
| 584 | Later license versions may give you additional or different | ||
| 585 | permissions. However, no additional obligations are imposed on any | ||
| 586 | author or copyright holder as a result of your choosing to follow a | ||
| 587 | later version. | ||
| 588 | |||
| 589 | 15. Disclaimer of Warranty. | ||
| 590 | |||
| 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY | ||
| 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT | ||
| 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY | ||
| 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, | ||
| 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM | ||
| 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF | ||
| 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. | ||
| 599 | |||
| 600 | 16. Limitation of Liability. | ||
| 601 | |||
| 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING | ||
| 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS | ||
| 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY | ||
| 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE | ||
| 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF | ||
| 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD | ||
| 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), | ||
| 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF | ||
| 610 | SUCH DAMAGES. | ||
| 611 | |||
| 612 | 17. Interpretation of Sections 15 and 16. | ||
| 613 | |||
| 614 | If the disclaimer of warranty and limitation of liability provided | ||
| 615 | above cannot be given local legal effect according to their terms, | ||
| 616 | reviewing courts shall apply local law that most closely approximates | ||
| 617 | an absolute waiver of all civil liability in connection with the | ||
| 618 | Program, unless a warranty or assumption of liability accompanies a | ||
| 619 | copy of the Program in return for a fee. | ||
| 620 | |||
| 621 | END OF TERMS AND CONDITIONS | ||
| 622 | |||
| 623 | How to Apply These Terms to Your New Programs | ||
| 624 | |||
| 625 | If you develop a new program, and you want it to be of the greatest | ||
| 626 | possible use to the public, the best way to achieve this is to make it | ||
| 627 | free software which everyone can redistribute and change under these terms. | ||
| 628 | |||
| 629 | To do so, attach the following notices to the program. It is safest | ||
| 630 | to attach them to the start of each source file to most effectively | ||
| 631 | state the exclusion of warranty; and each file should have at least | ||
| 632 | the "copyright" line and a pointer to where the full notice is found. | ||
| 633 | |||
| 634 | <one line to give the program's name and a brief idea of what it does.> | ||
| 635 | Copyright (C) <year> <name of author> | ||
| 636 | |||
| 637 | This program is free software: you can redistribute it and/or modify | ||
| 638 | it under the terms of the GNU General Public License as published by | ||
| 639 | the Free Software Foundation, either version 3 of the License, or | ||
| 640 | (at your option) any later version. | ||
| 641 | |||
| 642 | This program is distributed in the hope that it will be useful, | ||
| 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 645 | GNU General Public License for more details. | ||
| 646 | |||
| 647 | You should have received a copy of the GNU General Public License | ||
| 648 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 649 | |||
| 650 | Also add information on how to contact you by electronic and paper mail. | ||
| 651 | |||
| 652 | If the program does terminal interaction, make it output a short | ||
| 653 | notice like this when it starts in an interactive mode: | ||
| 654 | |||
| 655 | <program> Copyright (C) <year> <name of author> | ||
| 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. | ||
| 657 | This is free software, and you are welcome to redistribute it | ||
| 658 | under certain conditions; type `show c' for details. | ||
| 659 | |||
| 660 | The hypothetical commands `show w' and `show c' should show the appropriate | ||
| 661 | parts of the General Public License. Of course, your program's commands | ||
| 662 | might be different; for a GUI interface, you would use an "about box". | ||
| 663 | |||
| 664 | You should also get your employer (if you work as a programmer) or school, | ||
| 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. | ||
| 666 | For more information on this, and how to apply and follow the GNU GPL, see | ||
| 667 | <http://www.gnu.org/licenses/>. | ||
| 668 | |||
| 669 | The GNU General Public License does not permit incorporating your program | ||
| 670 | into proprietary programs. If your program is a subroutine library, you | ||
| 671 | may consider it more useful to permit linking proprietary applications with | ||
| 672 | the library. If this is what you want to do, use the GNU Lesser General | ||
| 673 | Public License instead of this License. But first, please read | ||
| 674 | <http://www.gnu.org/philosophy/why-not-lgpl.html>. | ||
diff --git a/README.md b/README.md new file mode 100644 index 0000000..5c543f4 --- /dev/null +++ b/README.md | |||
| @@ -0,0 +1,289 @@ | |||
| 1 | # etoolkit | ||
| 2 | |||
| 3 | *etoolkit* is a simple toolkit for defining and setting environment variables | ||
| 4 | in a flexible and secure way. | ||
| 5 | |||
| 6 | |||
| 7 | ## General | ||
| 8 | |||
| 9 | *etoolkit* started as a simple idea while I was working at the University | ||
| 10 | of Oslo. Later I felt the need for even more flexible solution. The following | ||
| 11 | goals were set: | ||
| 12 | |||
| 13 | - the ability to define env. var. "instances" with support for inheritance | ||
| 14 | |||
| 15 | - encrypting values using a master password | ||
| 16 | |||
| 17 | - the ability to spawn a child process with the defined variables | ||
| 18 | |||
| 19 | - support for macros | ||
| 20 | |||
| 21 | |||
| 22 | ## Requirements | ||
| 23 | |||
| 24 | Apart from Python >= 3.7, the only requirement is | ||
| 25 | [cryptography](https://pypi.org/project/cryptography/) | ||
| 26 | |||
| 27 | |||
| 28 | ## Overview | ||
| 29 | |||
| 30 | In a typical UNIX environment, env. variables are usually set in one | ||
| 31 | or more of the initialization / startup files like f.i. */etc/profile*, | ||
| 32 | *~/.bash_profile*, *~/.bashrc*, *~/.tcshrc*, *~/.cshrc* ... depending | ||
| 33 | on the OS, shell, distribution... etc. | ||
| 34 | Env. variables represent key-value pairs (env. variable name and its value). | ||
| 35 | |||
| 36 | A potential problem when dealing with env. variables containing sensitive | ||
| 37 | values like passwords, tokens, connection strings... is that they are inherited | ||
| 38 | by all child processes spawned from the login / interactive shell. | ||
| 39 | |||
| 40 | A malicious / exploited process (like f.i. web browser) will then be able to | ||
| 41 | fetch those values by using *getenv*. Such process may in addition be able to | ||
| 42 | simply read *~/.bashrc* or any similar file readable by the process owner and | ||
| 43 | get the values from there if necessary. | ||
| 44 | |||
| 45 | *etoolkit* attempts to solve both of these problems. | ||
| 46 | |||
| 47 | When started, it reads env. variables from its own configuration file. | ||
| 48 | Sensitive data may be encrypted using a master password. Hence reading | ||
| 49 | etoolkit's configuration file will not reveal the real value of the data. | ||
| 50 | |||
| 51 | When *etoolkit* has processed (decryption, macro replacement, etc) its data, | ||
| 52 | it may define new env. variables corresponding to that data and may start a new | ||
| 53 | interactive shell. The processed environment variables will not be available | ||
| 54 | for processes that were not spawned by that same *etoolkit* session. | ||
| 55 | |||
| 56 | |||
| 57 | ## Installation | ||
| 58 | |||
| 59 | ### pip (pypi) | ||
| 60 | |||
| 61 | ```bash | ||
| 62 | pip install etoolkit | ||
| 63 | ``` | ||
| 64 | |||
| 65 | |||
| 66 | ### Gentoo | ||
| 67 | |||
| 68 | ```bash | ||
| 69 | layman -a sgs | ||
| 70 | emerge dev-python/etoolkit | ||
| 71 | ``` | ||
| 72 | |||
| 73 | |||
| 74 | ## Setup and examples | ||
| 75 | |||
| 76 | Most users (including me) will simply use the command line interface (CLI). | ||
| 77 | |||
| 78 | |||
| 79 | ### CLI | ||
| 80 | |||
| 81 | *etoolkit* comes with a simple CLI: | ||
| 82 | |||
| 83 | ```bash | ||
| 84 | python -m etoolkit -h | ||
| 85 | ``` | ||
| 86 | |||
| 87 | ... or even (if *etoolkit* was installed using the methods described above) | ||
| 88 | |||
| 89 | ```bash | ||
| 90 | etoolkit -h | ||
| 91 | ``` | ||
| 92 | |||
| 93 | |||
| 94 | The *etoolkit* CLI loads the configuration located by default in | ||
| 95 | *~/.etoolkit.json*. That file is based on | ||
| 96 | [etoolkit_sample.json](https://github.com/blackm0re/etoolkit/blob/master/etoolkit_sample.json). | ||
| 97 | |||
| 98 | The *"instances"* part of the configuration defines unique instances, each of | ||
| 99 | which represents its own environment with its own defined env. variables. | ||
| 100 | Each instance consists of key-value pairs corresponding to env. name and value. | ||
| 101 | All pairs will result in corresponding env. variables being defined, with the | ||
| 102 | exception of the following *etoolkit* internal keys: | ||
| 103 | |||
| 104 | - **ETOOLKIT_PARENT** - string - reference to another instance | ||
| 105 | |||
| 106 | - **ETOOLKIT_SENSITIVE** - list - env. variables containing sensitive data | ||
| 107 | |||
| 108 | All pairs defined in *"general"* (currently only **MASTER_PASSWORD_HASH**) are | ||
| 109 | *etoolkit* internal as well. | ||
| 110 | |||
| 111 | An instance may inherit (and if desired overwrite) key value pairs from its | ||
| 112 | parent. | ||
| 113 | |||
| 114 | Variables containing sensitive data can be encrypted / decrypted using a master | ||
| 115 | password. Currently *etoolkit* requires that all values in a configuration | ||
| 116 | file are encrypted with the same master password. Setting a master password | ||
| 117 | hash is a recommended but not mandatory. | ||
| 118 | |||
| 119 | ```bash | ||
| 120 | etoolkit -p | ||
| 121 | ``` | ||
| 122 | |||
| 123 | That command will prompt for master password and output a hash that can then | ||
| 124 | be stored | ||
| 125 | in ["general"]["MASTER_PASSWORD_HASH"]. | ||
| 126 | The hash is only used for verifying that a correct master password has been | ||
| 127 | provided at a later time. Issuing: | ||
| 128 | |||
| 129 | ```bash | ||
| 130 | etoolkit -e | ||
| 131 | ``` | ||
| 132 | |||
| 133 | will prompt for the master password, then for the value to be encrypted and | ||
| 134 | finally display the encrypted string of the value. Unless invoked with the | ||
| 135 | *-E* / *--echo* parameter *etoolkit* will not display the value that is about | ||
| 136 | to be encrypted. | ||
| 137 | |||
| 138 | More than one value can be encrypted / decrypted with a single master password | ||
| 139 | prompt if *-m* / *--multiple-values* parameter is provided. Manual decryption | ||
| 140 | of single value(s): | ||
| 141 | |||
| 142 | ```bash | ||
| 143 | etoolkit -d -m | ||
| 144 | ``` | ||
| 145 | |||
| 146 | Listing all available instances defined in the configuration file and then | ||
| 147 | loading a specific instance can be achieved by: | ||
| 148 | |||
| 149 | ```bash | ||
| 150 | etoolkit -l | ||
| 151 | etoolkit <instance-name> | ||
| 152 | ``` | ||
| 153 | |||
| 154 | *etoolkit* will prompt for the master password the first time it encounters | ||
| 155 | and encrypted value. Once provided the master password will be used to decrypt | ||
| 156 | the rest of the encrypted values. | ||
| 157 | |||
| 158 | When all values are fetched from a given instance (and its parents) and then | ||
| 159 | decrypted, they are further processed by replacing macros with their | ||
| 160 | corresponding values. Currently the following macros are supported: | ||
| 161 | |||
| 162 | - **%h** - the home directory of the user running *etoolkit* (~/) | ||
| 163 | |||
| 164 | - **%i** - the names of the instance that is about to be loaded | ||
| 165 | |||
| 166 | - **%u** - the username of the user running *etoolkit* (*getpass.getuser()*) | ||
| 167 | |||
| 168 | In addition, value starting with *":"* is appended to the existing value | ||
| 169 | (if any) of the env. variable about to be set | ||
| 170 | (like *MYVAR=$MYVAR\<new value\>)*). | ||
| 171 | The opposite is true for value ending with *":"* (*MYVAR=\<new value\>$MYVAR*). | ||
| 172 | |||
| 173 | When the variables are finally processed, *etoolkit* sets / changes them as env. | ||
| 174 | variables (using *setenv* / *os.environ.update*) and spawns an interactive | ||
| 175 | child process (by invoking *system($SHELL)*). | ||
| 176 | |||
| 177 | One can also spawn a different process than an interactive shell by using the | ||
| 178 | *-s* / *--spawn* parameter. | ||
| 179 | |||
| 180 | ```bash | ||
| 181 | etoolkit -s /bin/othershell <instance-name> | ||
| 182 | ``` | ||
| 183 | |||
| 184 | Contact the author for questions and suggestions! :) | ||
| 185 | |||
| 186 | |||
| 187 | ### Using the *EtoolkitInstance* class | ||
| 188 | |||
| 189 | *etoolkit* comes with its own *etoolkit* package that contains the | ||
| 190 | *EtoolkitInstance* class. | ||
| 191 | |||
| 192 | The class encapsulates the function of creating and processing instances | ||
| 193 | from a given structure (dict). | ||
| 194 | |||
| 195 | It may be useful if one should prefer for example making her own CLI interface. | ||
| 196 | or the *instances* structure being loaded from a diferent configuration file | ||
| 197 | (f.i. .yml). | ||
| 198 | |||
| 199 | ```python | ||
| 200 | import os | ||
| 201 | |||
| 202 | import etoolkit | ||
| 203 | |||
| 204 | |||
| 205 | # using some static methods in order to create encrypted values | ||
| 206 | etoolkit.EtoolkitInstance.encrypt('the very secret passwd', 'secret1') | ||
| 207 | # Out: 'enc-val$1$Y/TBb1F3siHTw6qZg9ERzZfA8PLPf2CwGSQLpu9jYWw=$FT5tS9o+ABvsxogIXpJim16Gz5SVtV8=' | ||
| 208 | |||
| 209 | etoolkit.EtoolkitInstance.encrypt('the very secret passwd', 'secret2') | ||
| 210 | # Out: 'enc-val$1$vIBcoCNiYrsDLtF41uLuSEnppBjhliD0B8jwcBJcj/c=$KwOGe/y1dlxktDaCnJPIVNuaQ4Q7yNo=' | ||
| 211 | |||
| 212 | |||
| 213 | # The encrypted values will be used in our configuration structure | ||
| 214 | # The following structure defines the 3 instances: default, dev and secret | ||
| 215 | instances = { | ||
| 216 | "general": { | ||
| 217 | }, | ||
| 218 | "instances": { | ||
| 219 | "default": { | ||
| 220 | "ETOOLKIT_PROMPT": "(%i)" | ||
| 221 | }, | ||
| 222 | "dev": { | ||
| 223 | "ETOOLKIT_PARENT": "default", | ||
| 224 | "PYTHONPATH": ":/home/user/.pythonpath", | ||
| 225 | "DB_CONNECTION": "enc-val$1$Y/TBb1F3siHTw6qZg9ERzZfA8PLPf2CwGSQLpu9jYWw=$FT5tS9o+ABvsxogIXpJim16Gz5SVtV8=" | ||
| 226 | }, | ||
| 227 | "secret": { | ||
| 228 | "ETOOLKIT_PARENT": "default", | ||
| 229 | "ETOOLKIT_SENSITIVE": ["PASSWORD"], | ||
| 230 | "GNUPGHOME": "%h/private/.gnupg", | ||
| 231 | "PASSWORD": "enc-val$1$vIBcoCNiYrsDLtF41uLuSEnppBjhliD0B8jwcBJcj/c=$KwOGe/y1dlxktDaCnJPIVNuaQ4Q7yNo=" | ||
| 232 | } | ||
| 233 | } | ||
| 234 | } | ||
| 235 | |||
| 236 | |||
| 237 | dev_instance = etoolkit.EtoolkitInstance('dev', instances) | ||
| 238 | |||
| 239 | # fetch the variables before the processing stage (calling get_environ()) | ||
| 240 | # since raw_env_variables is a dict, it can be modified (f.i. .update()) | ||
| 241 | dev_instance.raw_env_variables | ||
| 242 | |||
| 243 | dev_instance.master_password = 'the very secret passwd' # or perhaps using getpass | ||
| 244 | env_vars = dev_instance.get_env() | ||
| 245 | print(env_vars['PASSWORD']) # outputs: 'secret2' | ||
| 246 | |||
| 247 | inst.dump_env(env_vars) # prints all values, with the exception of 'PASSWORD' | ||
| 248 | |||
| 249 | # set the env. variables. | ||
| 250 | os.environ.update(env_vars) | ||
| 251 | ``` | ||
| 252 | |||
| 253 | |||
| 254 | ### Tips | ||
| 255 | |||
| 256 | When starting a new interactive process (f.i. bash), the process will | ||
| 257 | in turn invoke its startup script (f.i. *~/.bashrc*). | ||
| 258 | Avoid redefining the env. variables that have just been set by *etoolkit*! | ||
| 259 | |||
| 260 | If you want your shell prompt to display the name of the loaded instance, you | ||
| 261 | can set a new env. variable (f.i. "ETOOLKIT_PROMPT" as shown in the sample | ||
| 262 | configuration above) and then add the following at the bottom of your startup | ||
| 263 | file (f.i. ~/.bashrc): | ||
| 264 | |||
| 265 | ```bash | ||
| 266 | if [ -n "$ETOOLKIT_PROMPT" ]; then | ||
| 267 | export PS1="$ETOOLKIT_PROMPT$PS1" | ||
| 268 | fi | ||
| 269 | ``` | ||
| 270 | |||
| 271 | |||
| 272 | ## Support and contributing | ||
| 273 | |||
| 274 | *etoolkit* is hosted on GitHub: https://github.com/blackm0re/etoolkit | ||
| 275 | |||
| 276 | |||
| 277 | ## Author | ||
| 278 | |||
| 279 | Simeon Simeonov - sgs @ LiberaChat | ||
| 280 | |||
| 281 | |||
| 282 | ## [License](https://github.com/blackm0re/etoolkit/blob/master/LICENSE) | ||
| 283 | |||
| 284 | Copyright (c) 2021, Simeon Simeonov | ||
| 285 | All rights reserved. | ||
| 286 | |||
| 287 | [Licensed](https://github.com/blackm0re/etoolkit/blob/master/LICENSE) under the | ||
| 288 | GNU General Public License v3.0 or later. | ||
| 289 | SPDX-License-Identifier: GPL-3.0-or-later | ||
diff --git a/etoolkit/__init__.py b/etoolkit/__init__.py new file mode 100644 index 0000000..9a6d9aa --- /dev/null +++ b/etoolkit/__init__.py | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | # etoolkit | ||
| 2 | # Copyright (C) 2021 Simeon Simeonov | ||
| 3 | |||
| 4 | # This program is free software: you can redistribute it and/or modify | ||
| 5 | # it under the terms of the GNU General Public License as published by | ||
| 6 | # the Free Software Foundation, either version 3 of the License, or | ||
| 7 | # (at your option) any later version. | ||
| 8 | |||
| 9 | # This program is distributed in the hope that it will be useful, | ||
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | # GNU General Public License for more details. | ||
| 13 | |||
| 14 | # You should have received a copy of the GNU General Public License | ||
| 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | """A simple toolkit for setting environment variables in a flexible way""" | ||
| 17 | from .etoolkit import EtoolkitInstance, EtoolkitInstanceError | ||
| 18 | |||
| 19 | __author__ = 'Simeon Simeonov' | ||
| 20 | __version__ = '1.0.0' | ||
| 21 | __license__ = 'GPL3' | ||
| 22 | |||
| 23 | |||
| 24 | def int_or_str(value): | ||
| 25 | """Returns int value of value when possible""" | ||
| 26 | try: | ||
| 27 | return int(value) | ||
| 28 | except ValueError: | ||
| 29 | return value | ||
| 30 | |||
| 31 | |||
| 32 | VERSION = tuple(map(int_or_str, __version__.split('.'))) | ||
| 33 | |||
| 34 | __all__ = ['EtoolkitInstance', 'EtoolkitInstanceError'] | ||
diff --git a/etoolkit/__main__.py b/etoolkit/__main__.py new file mode 100644 index 0000000..8c4245d --- /dev/null +++ b/etoolkit/__main__.py | |||
| @@ -0,0 +1,276 @@ | |||
| 1 | # etoolkit | ||
| 2 | # Copyright (C) 2021 Simeon Simeonov | ||
| 3 | |||
| 4 | # This program is free software: you can redistribute it and/or modify | ||
| 5 | # it under the terms of the GNU General Public License as published by | ||
| 6 | # the Free Software Foundation, either version 3 of the License, or | ||
| 7 | # (at your option) any later version. | ||
| 8 | |||
| 9 | # This program is distributed in the hope that it will be useful, | ||
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | # GNU General Public License for more details. | ||
| 13 | |||
| 14 | # You should have received a copy of the GNU General Public License | ||
| 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | """ | ||
| 17 | CLI entry point for the etoolkit package | ||
| 18 | |||
| 19 | Examples: | ||
| 20 | python -m etoolkit -h | ||
| 21 | |||
| 22 | python -m etoolkit -p | ||
| 23 | """ | ||
| 24 | import argparse | ||
| 25 | import errno | ||
| 26 | import getpass | ||
| 27 | import json | ||
| 28 | import logging | ||
| 29 | import os | ||
| 30 | import sys | ||
| 31 | |||
| 32 | import etoolkit | ||
| 33 | |||
| 34 | DEFAULT_LOG_FORMAT = "%(levelname)s: %(message)s" | ||
| 35 | DEFAULT_LOG_LEVEL = logging.WARNING | ||
| 36 | |||
| 37 | logger = logging.getLogger(__name__) | ||
| 38 | |||
| 39 | |||
| 40 | def decrypt_value(args: argparse.Namespace, config: dict): | ||
| 41 | """ | ||
| 42 | Interactive function for decrypting value(s) | ||
| 43 | |||
| 44 | Prompts for master key password and then prompts for a value to decrypt | ||
| 45 | |||
| 46 | The decrypted value is printed to stdout | ||
| 47 | |||
| 48 | :param args: The arguments sent by the caller | ||
| 49 | :type args: arparse.Namespace | ||
| 50 | |||
| 51 | :param config: The config dict sent by the caller | ||
| 52 | :type config: dict | ||
| 53 | """ | ||
| 54 | password_hash = None | ||
| 55 | if 'general' in config: | ||
| 56 | password_hash = config['general'].get('MASTER_PASSWORD_HASH') | ||
| 57 | password = etoolkit.EtoolkitInstance.confirm_password_prompt( | ||
| 58 | password_hash, False | ||
| 59 | ) | ||
| 60 | while True: | ||
| 61 | try: | ||
| 62 | value = input('Value: ') | ||
| 63 | print( | ||
| 64 | 'Decrypted value: ' | ||
| 65 | f'{etoolkit.EtoolkitInstance.decrypt(password, value)}' | ||
| 66 | ) | ||
| 67 | if not args.multiple_values: | ||
| 68 | break | ||
| 69 | except KeyboardInterrupt: | ||
| 70 | print(os.linesep) | ||
| 71 | break | ||
| 72 | |||
| 73 | |||
| 74 | def encrypt_value(args: argparse.Namespace, config: dict): | ||
| 75 | """ | ||
| 76 | Interactive function for encrypting value(s) | ||
| 77 | |||
| 78 | Prompts for master key password and then prompts for a value to encrypt | ||
| 79 | |||
| 80 | The encrypted value is printed to stdout | ||
| 81 | |||
| 82 | :param args: The arguments sent by the caller | ||
| 83 | :type args: arparse.Namespace | ||
| 84 | |||
| 85 | :param config: The config dict sent by the caller | ||
| 86 | :type config: dict | ||
| 87 | """ | ||
| 88 | password_hash = None | ||
| 89 | if 'general' in config: | ||
| 90 | password_hash = config['general'].get('MASTER_PASSWORD_HASH') | ||
| 91 | password = etoolkit.EtoolkitInstance.confirm_password_prompt(password_hash) | ||
| 92 | while True: | ||
| 93 | try: | ||
| 94 | if args.echo: | ||
| 95 | value = input('Value: ') | ||
| 96 | else: | ||
| 97 | value = getpass.getpass('Value: ') | ||
| 98 | print( | ||
| 99 | 'Encrypted value: ' | ||
| 100 | f'{etoolkit.EtoolkitInstance.encrypt(password, value)}' | ||
| 101 | ) | ||
| 102 | if not args.multiple_values: | ||
| 103 | break | ||
| 104 | except KeyboardInterrupt: | ||
| 105 | print(os.linesep) | ||
| 106 | break | ||
| 107 | |||
| 108 | |||
| 109 | def main(inargs=None): | ||
| 110 | """main entry point""" | ||
| 111 | parser = argparse.ArgumentParser( | ||
| 112 | prog=__package__, | ||
| 113 | epilog=( | ||
| 114 | f'%(prog)s {etoolkit.__version__} by Simeon Simeonov ' | ||
| 115 | '(sgs @ LiberaChat)' | ||
| 116 | ), | ||
| 117 | description='The following options are available', | ||
| 118 | ) | ||
| 119 | group = parser.add_mutually_exclusive_group(required=True) | ||
| 120 | group.add_argument( | ||
| 121 | 'instance', | ||
| 122 | metavar='<instance>', | ||
| 123 | nargs='?', | ||
| 124 | type=str, | ||
| 125 | help='The instance to be loaded', | ||
| 126 | ) | ||
| 127 | group.add_argument( | ||
| 128 | '-d', | ||
| 129 | '--decrypt-value', | ||
| 130 | dest='decrypt_value', | ||
| 131 | action='store_true', | ||
| 132 | required=False, | ||
| 133 | help=( | ||
| 134 | 'Prompt for master password & value to decrypt, ' | ||
| 135 | 'display the decrypted value and exit' | ||
| 136 | ), | ||
| 137 | ) | ||
| 138 | group.add_argument( | ||
| 139 | '-e', | ||
| 140 | '--encrypt-value', | ||
| 141 | dest='encrypt_value', | ||
| 142 | action='store_true', | ||
| 143 | required=False, | ||
| 144 | help=( | ||
| 145 | 'Prompt for master password & value to encrypt, ' | ||
| 146 | 'display the encrypted value and exit' | ||
| 147 | ), | ||
| 148 | ) | ||
| 149 | group.add_argument( | ||
| 150 | '-l', | ||
| 151 | '--list', | ||
| 152 | dest='list', | ||
| 153 | action='store_true', | ||
| 154 | required=False, | ||
| 155 | help='List all defined instances', | ||
| 156 | ) | ||
| 157 | group.add_argument( | ||
| 158 | '-p', | ||
| 159 | '--generate-master-password-hash', | ||
| 160 | dest='password_hash', | ||
| 161 | action='store_true', | ||
| 162 | required=False, | ||
| 163 | help='Prompt for master password, display the generated hash and exit', | ||
| 164 | ) | ||
| 165 | parser.add_argument( | ||
| 166 | '-c', | ||
| 167 | '--config-file', | ||
| 168 | metavar='<path>', | ||
| 169 | type=str, | ||
| 170 | default=os.path.expanduser( | ||
| 171 | os.environ.get('ETOOLKIT_CONFIG', '~/.etoolkit.json') | ||
| 172 | ), | ||
| 173 | dest='config_file', | ||
| 174 | help='JSON config file (default: ~/.etoolkit.json)', | ||
| 175 | ) | ||
| 176 | parser.add_argument( | ||
| 177 | '-E', | ||
| 178 | '--echo', | ||
| 179 | dest='echo', | ||
| 180 | action='store_true', | ||
| 181 | help='Display the value to be encrypted (used together with -e)', | ||
| 182 | ) | ||
| 183 | parser.add_argument( | ||
| 184 | '-m', | ||
| 185 | '--multiple-values', | ||
| 186 | dest='multiple_values', | ||
| 187 | action='store_true', | ||
| 188 | help=( | ||
| 189 | 'Prompt for more than one value when ' | ||
| 190 | 'encrypting / decrypting until terminated ' | ||
| 191 | '(Ctrl+C) (used together with -d / -e)' | ||
| 192 | ), | ||
| 193 | ) | ||
| 194 | parser.add_argument( | ||
| 195 | '-q', | ||
| 196 | '--no-output', | ||
| 197 | dest='dump_output', | ||
| 198 | action='store_false', | ||
| 199 | default=True, | ||
| 200 | help='Do not print environment variables to stdout', | ||
| 201 | ) | ||
| 202 | parser.add_argument( | ||
| 203 | '-s', | ||
| 204 | '--spawn', | ||
| 205 | metavar='<path>', | ||
| 206 | type=str, | ||
| 207 | default='', | ||
| 208 | dest='spawn', | ||
| 209 | help='Spawn another process than $SHELL', | ||
| 210 | ) | ||
| 211 | parser.add_argument( | ||
| 212 | '-v', | ||
| 213 | '--version', | ||
| 214 | action='version', | ||
| 215 | version=f'%(prog)s {etoolkit.__version__}', | ||
| 216 | help='Display program-version and exit', | ||
| 217 | ) | ||
| 218 | args = parser.parse_args(inargs) | ||
| 219 | try: | ||
| 220 | with open(args.config_file, 'r', encoding='utf-8') as fp: | ||
| 221 | config_dict = json.load(fp) | ||
| 222 | except Exception as e: | ||
| 223 | logger.error("Unable to parse %r: %s", args.config_file, e) | ||
| 224 | raise SystemExit(errno.EIO) from e | ||
| 225 | |||
| 226 | try: | ||
| 227 | if args.decrypt_value: | ||
| 228 | decrypt_value(args, config_dict) | ||
| 229 | sys.exit(0) | ||
| 230 | if args.encrypt_value: | ||
| 231 | encrypt_value(args, config_dict) | ||
| 232 | sys.exit(0) | ||
| 233 | if args.password_hash: | ||
| 234 | master_password = ( | ||
| 235 | etoolkit.EtoolkitInstance.confirm_password_prompt() | ||
| 236 | ) | ||
| 237 | phash = etoolkit.EtoolkitInstance.get_new_password_hash( | ||
| 238 | master_password | ||
| 239 | ) | ||
| 240 | print(f'Master password hash: {phash}') | ||
| 241 | sys.exit(0) | ||
| 242 | if args.list: | ||
| 243 | for instance_name in sorted( | ||
| 244 | config_dict.get('instances', {}).keys() | ||
| 245 | ): | ||
| 246 | print(instance_name) | ||
| 247 | sys.exit(0) | ||
| 248 | |||
| 249 | inst = etoolkit.EtoolkitInstance(args.instance, config_dict) | ||
| 250 | inst.prompt_func = etoolkit.EtoolkitInstance.confirm_password_prompt | ||
| 251 | env = inst.get_environ() | ||
| 252 | |||
| 253 | if args.dump_output: | ||
| 254 | inst.dump_env(env) | ||
| 255 | |||
| 256 | os.environ.update(env) | ||
| 257 | |||
| 258 | if args.spawn: | ||
| 259 | os.system(args.spawn) | ||
| 260 | else: | ||
| 261 | os.system(os.getenv('SHELL', 'bash')) | ||
| 262 | except KeyboardInterrupt: | ||
| 263 | logger.debug('KeyboardInterrupt') | ||
| 264 | print(os.linesep) | ||
| 265 | sys.exit(0) | ||
| 266 | except etoolkit.EtoolkitInstanceError as e: | ||
| 267 | logger.error('EtoolkitInstanceError: %s', e) | ||
| 268 | sys.exit(1) | ||
| 269 | except Exception as e: | ||
| 270 | logger.error('Unexpected exception: %s', e) | ||
| 271 | sys.exit(1) | ||
| 272 | |||
| 273 | |||
| 274 | if __name__ == '__main__': | ||
| 275 | logging.basicConfig(level=DEFAULT_LOG_LEVEL, format=DEFAULT_LOG_FORMAT) | ||
| 276 | main() | ||
diff --git a/etoolkit/etoolkit.py b/etoolkit/etoolkit.py new file mode 100755 index 0000000..837d13a --- /dev/null +++ b/etoolkit/etoolkit.py | |||
| @@ -0,0 +1,406 @@ | |||
| 1 | # etoolkit | ||
| 2 | # Copyright (C) 2021 Simeon Simeonov | ||
| 3 | |||
| 4 | # This program is free software: you can redistribute it and/or modify | ||
| 5 | # it under the terms of the GNU General Public License as published by | ||
| 6 | # the Free Software Foundation, either version 3 of the License, or | ||
| 7 | # (at your option) any later version. | ||
| 8 | |||
| 9 | # This program is distributed in the hope that it will be useful, | ||
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | # GNU General Public License for more details. | ||
| 13 | |||
| 14 | # You should have received a copy of the GNU General Public License | ||
| 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | """The main module of the etoolkit package""" | ||
| 17 | import base64 | ||
| 18 | import getpass | ||
| 19 | import hashlib | ||
| 20 | import os | ||
| 21 | |||
| 22 | from cryptography.exceptions import InvalidTag | ||
| 23 | from cryptography.hazmat.primitives.ciphers.aead import AESGCM | ||
| 24 | |||
| 25 | |||
| 26 | class EtoolkitInstanceError(Exception): | ||
| 27 | """EtoolkitInstanceError - Generic exceptions related to instances""" | ||
| 28 | |||
| 29 | |||
| 30 | class EtoolkitInstance: | ||
| 31 | """A basic class representing a single instance""" | ||
| 32 | |||
| 33 | def __init__(self, name: str, data: dict): | ||
| 34 | """ | ||
| 35 | :param name: Instance name | ||
| 36 | :type name: str | ||
| 37 | |||
| 38 | :param data: .etoolkit.json alike dict | ||
| 39 | :type data: dict | ||
| 40 | """ | ||
| 41 | self._name = name | ||
| 42 | self._parent = None | ||
| 43 | self._raw_env_variables = {} | ||
| 44 | self._sensitive_env_variables = [] | ||
| 45 | self._master_password = None | ||
| 46 | self._master_password_hash = None | ||
| 47 | self._prompt_func = None # function to use when prompting for input | ||
| 48 | try: | ||
| 49 | inst_data = data['instances'][name] | ||
| 50 | except KeyError as e: | ||
| 51 | raise EtoolkitInstanceError(f'Unknown instance "{name}"') from e | ||
| 52 | if inst_data.get('ETOOLKIT_PARENT'): | ||
| 53 | self._parent = EtoolkitInstance(inst_data['ETOOLKIT_PARENT'], data) | ||
| 54 | self._raw_env_variables.update(self._parent.raw_env_variables) | ||
| 55 | self._sensitive_env_variables.extend( | ||
| 56 | self._parent.sensitive_env_variables | ||
| 57 | ) | ||
| 58 | if inst_data.get('ETOOLKIT_SENSITIVE'): | ||
| 59 | if not isinstance(inst_data['ETOOLKIT_SENSITIVE'], list): | ||
| 60 | raise EtoolkitInstanceError( | ||
| 61 | '"ETOOLKIT_SENSITIVE" must be a list' | ||
| 62 | ) | ||
| 63 | self._sensitive_env_variables.extend( | ||
| 64 | inst_data['ETOOLKIT_SENSITIVE'] | ||
| 65 | ) | ||
| 66 | self._raw_env_variables.update(inst_data) | ||
| 67 | # remove non env. variable data | ||
| 68 | self._raw_env_variables.pop('ETOOLKIT_PARENT', None) | ||
| 69 | self._raw_env_variables.pop('ETOOLKIT_SENSITIVE', None) | ||
| 70 | if 'general' in data and 'MASTER_PASSWORD_HASH' in data['general']: | ||
| 71 | self._master_password_hash = data['general'][ | ||
| 72 | 'MASTER_PASSWORD_HASH' | ||
| 73 | ] | ||
| 74 | |||
| 75 | @property | ||
| 76 | def master_password(self) -> str: | ||
| 77 | """master_password-property""" | ||
| 78 | return self._master_password | ||
| 79 | |||
| 80 | @master_password.setter | ||
| 81 | def master_password(self, value): | ||
| 82 | """master_password-property setter""" | ||
| 83 | self._master_password = value | ||
| 84 | |||
| 85 | @property | ||
| 86 | def master_password_hash(self) -> str: | ||
| 87 | """master_password_hash-property""" | ||
| 88 | return self._master_password_hash | ||
| 89 | |||
| 90 | @master_password_hash.setter | ||
| 91 | def master_password_hash(self, value): | ||
| 92 | """master_password_hash-property setter""" | ||
| 93 | self._master_password_hash = value | ||
| 94 | |||
| 95 | @property | ||
| 96 | def name(self) -> str: | ||
| 97 | """name-property""" | ||
| 98 | return self._name | ||
| 99 | |||
| 100 | @property | ||
| 101 | def prompt_func(self): | ||
| 102 | """prompt_func-property""" | ||
| 103 | return self._prompt_func | ||
| 104 | |||
| 105 | @prompt_func.setter | ||
| 106 | def prompt_func(self, value): | ||
| 107 | """prompt_func-property setter""" | ||
| 108 | self._prompt_func = value | ||
| 109 | |||
| 110 | @property | ||
| 111 | def raw_env_variables(self) -> dict: | ||
| 112 | """raw_env_variables-property""" | ||
| 113 | return self._raw_env_variables | ||
| 114 | |||
| 115 | @property | ||
| 116 | def sensitive_env_variables(self) -> list: | ||
| 117 | """sensitive_env_variables-property""" | ||
| 118 | return self._sensitive_env_variables | ||
| 119 | |||
| 120 | @staticmethod | ||
| 121 | def confirm_password_prompt( | ||
| 122 | password_hash: str = None, confirm: bool = True | ||
| 123 | ) -> str: | ||
| 124 | """ | ||
| 125 | Prompts for master password and then for confirmation if `confirm` True | ||
| 126 | |||
| 127 | :param password_hash: Hash to compare with instead of confirm | ||
| 128 | :type password_hash: str | ||
| 129 | |||
| 130 | :param confirm: Confirm the password (and see if there is a match) | ||
| 131 | :type confirm: bool | ||
| 132 | |||
| 133 | :return: Password provided by the user | ||
| 134 | :rtype: str | ||
| 135 | """ | ||
| 136 | try: | ||
| 137 | while True: | ||
| 138 | pass1 = getpass.getpass('Type master password: ') | ||
| 139 | if password_hash: | ||
| 140 | if EtoolkitInstance.password_matches(pass1, password_hash): | ||
| 141 | return pass1 | ||
| 142 | print('Wrong password') | ||
| 143 | continue | ||
| 144 | if confirm: | ||
| 145 | pass2 = getpass.getpass('Confirm master password: ') | ||
| 146 | if not pass1 or pass1 != pass2: | ||
| 147 | print('The passwords are either empty or do not match') | ||
| 148 | continue | ||
| 149 | return pass1.strip() | ||
| 150 | except Exception as e: | ||
| 151 | raise EtoolkitInstanceError('Prompt error') from e | ||
| 152 | |||
| 153 | @staticmethod | ||
| 154 | def decrypt(password: str, edata: str) -> str: | ||
| 155 | """ | ||
| 156 | Decrypts `edata` using `password`. | ||
| 157 | |||
| 158 | `edata` is in the following format: | ||
| 159 | enc-val$`version-num`$`bas64-salt`$`base64-encrypted_data` | ||
| 160 | |||
| 161 | :param password: The password to generate the key with | ||
| 162 | :type password: str | ||
| 163 | |||
| 164 | :param edata: The data to be decrypted | ||
| 165 | :type edata: str | ||
| 166 | |||
| 167 | :return: The output string / decrypted data | ||
| 168 | :rtype: str | ||
| 169 | """ | ||
| 170 | # check for supported versions | ||
| 171 | if not edata.startswith('enc-val$1$'): | ||
| 172 | raise EtoolkitInstanceError( | ||
| 173 | f'Unsupported encryption format: {edata}' | ||
| 174 | ) | ||
| 175 | try: | ||
| 176 | salt, data = [base64.b64decode(t) for t in edata[10:].split('$')] | ||
| 177 | nonce = salt[:12] | ||
| 178 | aesgcm = AESGCM( | ||
| 179 | hashlib.scrypt( | ||
| 180 | password.encode('utf-8'), | ||
| 181 | salt=salt, | ||
| 182 | n=2 ** 14, | ||
| 183 | r=8, | ||
| 184 | p=1, | ||
| 185 | dklen=32, | ||
| 186 | ) | ||
| 187 | ) | ||
| 188 | return aesgcm.decrypt(nonce, data, salt).decode() | ||
| 189 | except InvalidTag as e: | ||
| 190 | raise EtoolkitInstanceError( | ||
| 191 | f'Invalid tag when decrypting: {edata}' | ||
| 192 | ) from e | ||
| 193 | except Exception as e: | ||
| 194 | raise EtoolkitInstanceError( | ||
| 195 | f'Error when decrypting: {edata}' | ||
| 196 | ) from e | ||
| 197 | |||
| 198 | @staticmethod | ||
| 199 | def encrypt(password: str, data: str) -> str: | ||
| 200 | """ | ||
| 201 | Encrypts `data` using `password`. | ||
| 202 | |||
| 203 | The output string is in the following format: | ||
| 204 | enc-val$`version-num`$`bas64-salt`$`base64-encrypted_data` | ||
| 205 | |||
| 206 | :param password: The password to generate the key with | ||
| 207 | :type password: str | ||
| 208 | |||
| 209 | :param data: The data to be encrypted | ||
| 210 | :type data: str | ||
| 211 | |||
| 212 | :return: The output string | ||
| 213 | :rtype: str | ||
| 214 | """ | ||
| 215 | salt = os.urandom(32) | ||
| 216 | aesgcm = AESGCM( | ||
| 217 | hashlib.scrypt( | ||
| 218 | password.encode('utf-8'), | ||
| 219 | salt=salt, | ||
| 220 | n=2 ** 14, | ||
| 221 | r=8, | ||
| 222 | p=1, | ||
| 223 | dklen=32, | ||
| 224 | ) | ||
| 225 | ) | ||
| 226 | nonce = salt[:12] | ||
| 227 | edata = aesgcm.encrypt(nonce, data.encode('utf-8'), salt) | ||
| 228 | return ( | ||
| 229 | f'enc-val$1${base64.b64encode(salt).decode()}$' | ||
| 230 | f'{base64.b64encode(edata).decode()}' | ||
| 231 | ) | ||
| 232 | |||
| 233 | @staticmethod | ||
| 234 | def get_new_password_hash(password: str) -> str: | ||
| 235 | """ | ||
| 236 | Returns a complete password hash based on `password` | ||
| 237 | |||
| 238 | This password hash is *not* used as a key when encrypting / decrypting | ||
| 239 | but only for optional check if a correct master password is provided. | ||
| 240 | |||
| 241 | :param password: The plaintext password | ||
| 242 | :type password: str | ||
| 243 | |||
| 244 | :return: The hashed version of `password` | ||
| 245 | :rtype: str | ||
| 246 | """ | ||
| 247 | hash_algo = 'sha256' | ||
| 248 | iterations = 100000 | ||
| 249 | salt = os.urandom(32) | ||
| 250 | key = hashlib.pbkdf2_hmac( | ||
| 251 | hash_algo, password.encode('utf-8'), salt, iterations | ||
| 252 | ) | ||
| 253 | return ( | ||
| 254 | f'pbkdf2_{hash_algo}${iterations}$' | ||
| 255 | f'{base64.b64encode(salt).decode()}$' | ||
| 256 | f'{base64.b64encode(key).decode()}' | ||
| 257 | ) | ||
| 258 | |||
| 259 | @staticmethod | ||
| 260 | def parse_value(value, macros: dict): | ||
| 261 | """ | ||
| 262 | Returns the value with all macros replaced by their values | ||
| 263 | |||
| 264 | If `value` is not of type 'str' simply return `value` | ||
| 265 | |||
| 266 | :param value: A simple value | ||
| 267 | :type value: object | ||
| 268 | |||
| 269 | :param macros: Macros mapping | ||
| 270 | :type macros: dict | ||
| 271 | |||
| 272 | :return: New value with all macros replaced by their values | ||
| 273 | :rtype: object | ||
| 274 | """ | ||
| 275 | if not isinstance(value, str): | ||
| 276 | return value | ||
| 277 | for key, val in macros.items(): | ||
| 278 | value = value.replace(key, val) | ||
| 279 | return value | ||
| 280 | |||
| 281 | @staticmethod | ||
| 282 | def password_matches(password: str, password_hash: str) -> bool: | ||
| 283 | """ | ||
| 284 | Checks `password` agains s stored password hash | ||
| 285 | |||
| 286 | Hash format: pbkdf2_hashalgo$ietarations$salt-base64$key-base64 | ||
| 287 | |||
| 288 | :param password: password | ||
| 289 | :type password: str | ||
| 290 | |||
| 291 | :param password_hash: The pbkdf2_hmac password hash | ||
| 292 | :type password_hash: str | ||
| 293 | |||
| 294 | :return: True if the password matches or password_hash is None, | ||
| 295 | :rtype: bool | ||
| 296 | """ | ||
| 297 | if password_hash is None: | ||
| 298 | return True | ||
| 299 | # format: pbkdf2_hashalgo$ietarations$salt-base64$key-base64 | ||
| 300 | try: | ||
| 301 | tokens = password_hash.split('$') | ||
| 302 | key = hashlib.pbkdf2_hmac( | ||
| 303 | tokens[0].split('_')[1], | ||
| 304 | password.encode('utf-8'), | ||
| 305 | base64.b64decode(tokens[2]), | ||
| 306 | int(tokens[1]), | ||
| 307 | ) | ||
| 308 | return key == base64.b64decode(tokens[3]) | ||
| 309 | except Exception: | ||
| 310 | return False | ||
| 311 | |||
| 312 | def dump_env(self, env: dict): | ||
| 313 | """ | ||
| 314 | Prints an environment dict to stdout. | ||
| 315 | |||
| 316 | :param env: The environment dict | ||
| 317 | :type env: dict | ||
| 318 | """ | ||
| 319 | for key, value in env.items(): | ||
| 320 | if key in self._sensitive_env_variables: | ||
| 321 | print(f'{key}: ***') | ||
| 322 | continue | ||
| 323 | print(f'{key}: {value}') | ||
| 324 | |||
| 325 | def get_environ(self) -> dict: | ||
| 326 | """ | ||
| 327 | Generates a new environ dict | ||
| 328 | |||
| 329 | :return: New environment dict with all macros replaced by their values | ||
| 330 | :rtype: dict | ||
| 331 | """ | ||
| 332 | macros = { | ||
| 333 | '%h': os.path.expanduser('~'), | ||
| 334 | '%i': self.name, | ||
| 335 | # '%f': self.get_full_name(), | ||
| 336 | '%u': getpass.getuser(), | ||
| 337 | } | ||
| 338 | new_env = {} | ||
| 339 | for key, value in sorted( | ||
| 340 | self._raw_env_variables.items(), key=lambda x: x[0] | ||
| 341 | ): | ||
| 342 | if not value: | ||
| 343 | # perhaps unset instead of skipping? | ||
| 344 | continue | ||
| 345 | if isinstance(value, str) and value.startswith('enc-val$1$'): | ||
| 346 | value = self._decrypt_value(value) | ||
| 347 | if isinstance(value, str) and value.endswith(':'): | ||
| 348 | # if 'value' ends with ':', append the existing value of | ||
| 349 | # os.environ[key] after the value of 'value' | ||
| 350 | new_env[key] = self.parse_value( | ||
| 351 | value, macros | ||
| 352 | ) + os.environ.get(key, '') | ||
| 353 | elif isinstance(value, str) and value.startswith(':'): | ||
| 354 | # if 'value' starts with ':', append after the existing value | ||
| 355 | # of os.environ[key] | ||
| 356 | new_env[key] = os.environ.get(key, '') + self.parse_value( | ||
| 357 | value, macros | ||
| 358 | ) | ||
| 359 | else: | ||
| 360 | # completely overwrite the existing value of os.environ[key] | ||
| 361 | new_env[key] = self.parse_value(value, macros) | ||
| 362 | return new_env | ||
| 363 | |||
| 364 | def get_full_name(self, delimiter: str = '') -> str: | ||
| 365 | """ | ||
| 366 | Returns the entire instance inheritence path separated by `delimiter` | ||
| 367 | |||
| 368 | The format is: | ||
| 369 | `grandparent-name`<delimiter>`parent-name`<delimiter>`instance-name` | ||
| 370 | |||
| 371 | :param delimiter: Delimiter to separate parent instance names by | ||
| 372 | :type delimiter: str | ||
| 373 | |||
| 374 | :return: Path in case this instance has parent, instance.name otherwise | ||
| 375 | :rtype: str | ||
| 376 | """ | ||
| 377 | if self._parent is None: | ||
| 378 | return self.name | ||
| 379 | return self._parent.get_full_name(delimiter) + delimiter + self.name | ||
| 380 | |||
| 381 | def _decrypt_value(self, evalue: str) -> str: | ||
| 382 | """ | ||
| 383 | Decrypts an encrypted value using the master password | ||
| 384 | |||
| 385 | The method prompts for the master password when it encounters its | ||
| 386 | first encrypted value since the creation of its EtoolkitInstance | ||
| 387 | object | ||
| 388 | |||
| 389 | `evalue` is in the following format: | ||
| 390 | enc-val$`version-num`$`bas64-salt`$`base64-encrypted_data` | ||
| 391 | |||
| 392 | :param evalue: Encrypted value to be decrypted | ||
| 393 | :type evalue: str | ||
| 394 | |||
| 395 | :return: Decrypted value | ||
| 396 | :rtype: str | ||
| 397 | """ | ||
| 398 | if self._master_password is None: | ||
| 399 | if self._prompt_func is None: | ||
| 400 | raise EtoolkitInstanceError( | ||
| 401 | 'Neither password or prompt function set' | ||
| 402 | ) | ||
| 403 | self._master_password = self._prompt_func( | ||
| 404 | self._master_password_hash, confirm=False | ||
| 405 | ) | ||
| 406 | return EtoolkitInstance.decrypt(self._master_password, evalue) | ||
diff --git a/etoolkit_sample.json b/etoolkit_sample.json new file mode 100644 index 0000000..66c9d17 --- /dev/null +++ b/etoolkit_sample.json | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | { | ||
| 2 | "general": { | ||
| 3 | "MASTER_PASSWORD_HASH": "pbkdf2_sha256$100000$kFOQkAPtStZ/Ny/O4501ygHGQnqh5Y+ySxF9qVHriv8=$3BujuWzn3CfDnw4yiD9m3F+GjeW1MHHW40R/ThHNcn0=" | ||
| 4 | }, | ||
| 5 | "instances": { | ||
| 6 | "default": { | ||
| 7 | "ETOOLKIT_PROMPT": "(%i)" | ||
| 8 | }, | ||
| 9 | "dev": { | ||
| 10 | "ETOOLKIT_PARENT": "default", | ||
| 11 | "PYTHONPATH": ":/home/user/.pythonpath", | ||
| 12 | "DB_CONNECTION": "enc-val$1$Y/TBb1F3siHTw6qZg9ERzZfA8PLPf2CwGSQLpu9jYWw=$FT5tS9o+ABvsxogIXpJim16Gz5SVtV8=" | ||
| 13 | }, | ||
| 14 | "secret": { | ||
| 15 | "ETOOLKIT_PARENT": "default", | ||
| 16 | "ETOOLKIT_SENSITIVE": ["PASSWORD"], | ||
| 17 | "GNUPGHOME": "%h/private/.gnupg", | ||
| 18 | "PASSWORD": "enc-val$1$vIBcoCNiYrsDLtF41uLuSEnppBjhliD0B8jwcBJcj/c=$KwOGe/y1dlxktDaCnJPIVNuaQ4Q7yNo=" | ||
| 19 | } | ||
| 20 | } | ||
| 21 | } | ||
diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..b4681c3 --- /dev/null +++ b/setup.py | |||
| @@ -0,0 +1,56 @@ | |||
| 1 | # -*- coding: utf-8 -*- | ||
| 2 | |||
| 3 | import setuptools | ||
| 4 | |||
| 5 | import etoolkit | ||
| 6 | |||
| 7 | with open('README.md', 'r', encoding='utf-8') as fh: | ||
| 8 | long_description = fh.read() | ||
| 9 | |||
| 10 | |||
| 11 | setuptools.setup( | ||
| 12 | name='etoolkit', | ||
| 13 | version=etoolkit.__version__, | ||
| 14 | author=etoolkit.__author__, | ||
| 15 | author_email='sgs@pichove.org', | ||
| 16 | description=( | ||
| 17 | 'A simple toolkit for setting environment variables in a flexible way' | ||
| 18 | ), | ||
| 19 | license=etoolkit.__license__, | ||
| 20 | long_description=long_description, | ||
| 21 | long_description_content_type='text/markdown', | ||
| 22 | url='https://github.com/blackm0re/etoolkit', | ||
| 23 | packages=setuptools.find_packages(), | ||
| 24 | exclude_package_data={'': ['.gitignore']}, | ||
| 25 | entry_points={ | ||
| 26 | 'console_scripts': [ | ||
| 27 | 'etoolkit=etoolkit.__main__:main', | ||
| 28 | ], | ||
| 29 | }, | ||
| 30 | classifiers=[ | ||
| 31 | 'Development Status :: 5 - Production/Stable', | ||
| 32 | 'Environment :: Console', | ||
| 33 | 'Intended Audience :: Developers', | ||
| 34 | 'Intended Audience :: System Administrators', | ||
| 35 | ( | ||
| 36 | 'License :: OSI Approved :: GNU General Public License v3 or later' | ||
| 37 | ' (GPLv3+)' | ||
| 38 | ), | ||
| 39 | 'Programming Language :: Python :: 3 :: Only', | ||
| 40 | 'Programming Language :: Python :: 3.7', | ||
| 41 | 'Programming Language :: Python :: 3.8', | ||
| 42 | 'Programming Language :: Python :: 3.9', | ||
| 43 | 'Programming Language :: Python :: 3.10', | ||
| 44 | 'Programming Language :: Python :: 3.11', | ||
| 45 | 'Programming Language :: Python :: Implementation', | ||
| 46 | 'Operating System :: POSIX', | ||
| 47 | 'Topic :: Security :: Cryptography', | ||
| 48 | ], | ||
| 49 | keywords='unix environment security cryptography', | ||
| 50 | project_urls={ | ||
| 51 | 'Bug Reports': 'https://github.com/blackm0re/etoolkit/issues', | ||
| 52 | 'Source': 'https://github.com/blackm0re/etoolkit', | ||
| 53 | }, | ||
| 54 | install_requires=["cryptography>=3.2"], | ||
| 55 | python_requires='>=3.7', | ||
| 56 | ) | ||
diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..1f70259 --- /dev/null +++ b/tests/conftest.py | |||
| @@ -0,0 +1,59 @@ | |||
| 1 | # etoolkit | ||
| 2 | # Copyright (C) 2021 Simeon Simeonov | ||
| 3 | |||
| 4 | # This program is free software: you can redistribute it and/or modify | ||
| 5 | # it under the terms of the GNU General Public License as published by | ||
| 6 | # the Free Software Foundation, either version 3 of the License, or | ||
| 7 | # (at your option) any later version. | ||
| 8 | |||
| 9 | # This program is distributed in the hope that it will be useful, | ||
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | # GNU General Public License for more details. | ||
| 13 | |||
| 14 | # You should have received a copy of the GNU General Public License | ||
| 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | """Common fixtures""" | ||
| 17 | import pytest | ||
| 18 | |||
| 19 | |||
| 20 | @pytest.fixture | ||
| 21 | def config_data(): | ||
| 22 | """config_data for testing""" | ||
| 23 | return { | ||
| 24 | 'general': { | ||
| 25 | 'MASTER_PASSWORD_HASH': ( | ||
| 26 | 'pbkdf2_sha256$100000$kFOQkAPtStZ/Ny/O4501ygHGQnqh5Y+ySxF9qVHr' | ||
| 27 | 'iv8=$3BujuWzn3CfDnw4yiD9m3F+GjeW1MHHW40R/ThHNcn0=' | ||
| 28 | ) | ||
| 29 | }, | ||
| 30 | 'instances': { | ||
| 31 | 'default': {'ETOOLKIT_PROMPT': '(%i)'}, | ||
| 32 | 'dev': { | ||
| 33 | 'ETOOLKIT_PARENT': 'default', | ||
| 34 | 'PYTHONPATH': ':/home/user/.pythonpath', | ||
| 35 | 'DB_CONNECTION': ( | ||
| 36 | 'enc-val$1$Y/TBb1F3siHTw6qZg9ERzZfA8PLPf2CwGSQLpu9jYWw=$FT' | ||
| 37 | '5tS9o+ABvsxogIXpJim16Gz5SVtV8=' | ||
| 38 | ), | ||
| 39 | }, | ||
| 40 | 'secret': { | ||
| 41 | 'ETOOLKIT_PARENT': 'default', | ||
| 42 | 'ETOOLKIT_SENSITIVE': ['PASSWORD'], | ||
| 43 | 'GNUPGHOME': '%h/private/.gnupg', | ||
| 44 | 'PASSWORD': ( | ||
| 45 | 'enc-val$1$vIBcoCNiYrsDLtF41uLuSEnppBjhliD0B8jwcBJcj/c=$Kw' | ||
| 46 | 'OGe/y1dlxktDaCnJPIVNuaQ4Q7yNo=' | ||
| 47 | ), | ||
| 48 | }, | ||
| 49 | }, | ||
| 50 | } | ||
| 51 | |||
| 52 | |||
| 53 | @pytest.fixture | ||
| 54 | def password_hash(): | ||
| 55 | """password hash for testing, corresponding to 'the very secret passwd'""" | ||
| 56 | return ( | ||
| 57 | 'pbkdf2_sha256$100000$kFOQkAPtStZ/Ny/O4501ygHGQnqh5Y+ySxF9qVHr' | ||
| 58 | 'iv8=$3BujuWzn3CfDnw4yiD9m3F+GjeW1MHHW40R/ThHNcn0=' | ||
| 59 | ) | ||
diff --git a/tests/test_cli.py b/tests/test_cli.py new file mode 100644 index 0000000..1bd9be1 --- /dev/null +++ b/tests/test_cli.py | |||
| @@ -0,0 +1,40 @@ | |||
| 1 | # etoolkit | ||
| 2 | # Copyright (C) 2021 Simeon Simeonov | ||
| 3 | |||
| 4 | # This program is free software: you can redistribute it and/or modify | ||
| 5 | # it under the terms of the GNU General Public License as published by | ||
| 6 | # the Free Software Foundation, either version 3 of the License, or | ||
| 7 | # (at your option) any later version. | ||
| 8 | |||
| 9 | # This program is distributed in the hope that it will be useful, | ||
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | # GNU General Public License for more details. | ||
| 13 | |||
| 14 | # You should have received a copy of the GNU General Public License | ||
| 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | """Tests for the CLI (etoolkit.__main__""" | ||
| 17 | import pytest | ||
| 18 | |||
| 19 | import etoolkit | ||
| 20 | from etoolkit.__main__ import main | ||
| 21 | |||
| 22 | |||
| 23 | def test_help(capsys): | ||
| 24 | """Dummy test checking if the CLI is available at all""" | ||
| 25 | with pytest.raises(SystemExit) as exit_info: | ||
| 26 | main(['-h']) | ||
| 27 | assert exit_info.type == SystemExit | ||
| 28 | assert exit_info.value.code == 0 | ||
| 29 | assert capsys.readouterr().out.startswith('usage: etoolkit') | ||
| 30 | |||
| 31 | |||
| 32 | def test_version(capsys): | ||
| 33 | """Dummy test checking if the CLI is available at all""" | ||
| 34 | with pytest.raises(SystemExit) as exit_info: | ||
| 35 | main(['-v']) | ||
| 36 | assert exit_info.type == SystemExit | ||
| 37 | assert exit_info.value.code == 0 | ||
| 38 | assert capsys.readouterr().out.startswith( | ||
| 39 | f'etoolkit {etoolkit.__version__}' | ||
| 40 | ) | ||
diff --git a/tests/test_envtoolkit_instance.py b/tests/test_envtoolkit_instance.py new file mode 100644 index 0000000..2ffacd2 --- /dev/null +++ b/tests/test_envtoolkit_instance.py | |||
| @@ -0,0 +1,64 @@ | |||
| 1 | # etoolkit | ||
| 2 | # Copyright (C) 2021 Simeon Simeonov | ||
| 3 | |||
| 4 | # This program is free software: you can redistribute it and/or modify | ||
| 5 | # it under the terms of the GNU General Public License as published by | ||
| 6 | # the Free Software Foundation, either version 3 of the License, or | ||
| 7 | # (at your option) any later version. | ||
| 8 | |||
| 9 | # This program is distributed in the hope that it will be useful, | ||
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | # GNU General Public License for more details. | ||
| 13 | |||
| 14 | # You should have received a copy of the GNU General Public License | ||
| 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | """Tests for etoolkit.EtoolkitInstance""" | ||
| 17 | import pytest | ||
| 18 | |||
| 19 | import etoolkit | ||
| 20 | |||
| 21 | |||
| 22 | def test_instantiation(config_data, password_hash): | ||
| 23 | """Tests for object instatiation""" | ||
| 24 | with pytest.raises(etoolkit.EtoolkitInstanceError) as exc_info: | ||
| 25 | instance = etoolkit.EtoolkitInstance('devv', config_data) | ||
| 26 | assert exc_info.type is etoolkit.EtoolkitInstanceError | ||
| 27 | assert exc_info.value.args[0] == 'Unknown instance "devv"' | ||
| 28 | |||
| 29 | instance = etoolkit.EtoolkitInstance('secret', config_data) | ||
| 30 | assert 'ETOOLKIT_PARENT' not in instance.raw_env_variables | ||
| 31 | assert 'ETOOLKIT_SENSITIVE' not in instance.raw_env_variables | ||
| 32 | assert 'DB_CONNECTION' not in instance.sensitive_env_variables | ||
| 33 | assert 'PASSWORD' in instance.sensitive_env_variables | ||
| 34 | assert instance.name == 'secret' | ||
| 35 | assert instance.master_password_hash == password_hash | ||
| 36 | assert instance.master_password is None | ||
| 37 | |||
| 38 | |||
| 39 | def test_get_environ(config_data): | ||
| 40 | """Tests the EtoolkitInstance.get_environ method""" | ||
| 41 | instance = etoolkit.EtoolkitInstance('secret', config_data) | ||
| 42 | with pytest.raises(etoolkit.EtoolkitInstanceError) as exc_info: | ||
| 43 | env = instance.get_environ() | ||
| 44 | assert exc_info.type is etoolkit.EtoolkitInstanceError | ||
| 45 | assert exc_info.value.args[0] == 'Neither password or prompt function set' | ||
| 46 | |||
| 47 | instance.master_password = 'The very secret passwd' # wrong passwd | ||
| 48 | with pytest.raises(etoolkit.EtoolkitInstanceError) as exc_info: | ||
| 49 | env = instance.get_environ() | ||
| 50 | assert exc_info.type is etoolkit.EtoolkitInstanceError | ||
| 51 | assert exc_info.value.args[0].startswith( | ||
| 52 | 'Invalid tag when decrypting: enc-val$' | ||
| 53 | ) | ||
| 54 | |||
| 55 | instance.master_password = 'the very secret passwd' # correct passwd | ||
| 56 | env = instance.get_environ() | ||
| 57 | assert isinstance(env, dict) | ||
| 58 | assert env['PASSWORD'] == 'secret2' | ||
| 59 | |||
| 60 | |||
| 61 | def test_get_full_name(config_data): | ||
| 62 | """Tests the EtoolkitInstance.get_full_name method""" | ||
| 63 | instance = etoolkit.EtoolkitInstance('secret', config_data) | ||
| 64 | assert instance.get_full_name('->') == 'default->secret' | ||
diff --git a/tests/test_envtoolkit_instance_static.py b/tests/test_envtoolkit_instance_static.py new file mode 100644 index 0000000..d7ac857 --- /dev/null +++ b/tests/test_envtoolkit_instance_static.py | |||
| @@ -0,0 +1,102 @@ | |||
| 1 | # etoolkit | ||
| 2 | # Copyright (C) 2021 Simeon Simeonov | ||
| 3 | |||
| 4 | # This program is free software: you can redistribute it and/or modify | ||
| 5 | # it under the terms of the GNU General Public License as published by | ||
| 6 | # the Free Software Foundation, either version 3 of the License, or | ||
| 7 | # (at your option) any later version. | ||
| 8 | |||
| 9 | # This program is distributed in the hope that it will be useful, | ||
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | # GNU General Public License for more details. | ||
| 13 | |||
| 14 | # You should have received a copy of the GNU General Public License | ||
| 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | """Tests for etoolkit.EtoolkitInstance static methods""" | ||
| 17 | import unittest.mock | ||
| 18 | |||
| 19 | import pytest | ||
| 20 | |||
| 21 | import etoolkit | ||
| 22 | |||
| 23 | |||
| 24 | @unittest.mock.patch('getpass.getpass') | ||
| 25 | def test_confirm_password_prompt(getpass, password_hash): | ||
| 26 | """Tests the static EtoolkitInstance.confirm_password_prompt method""" | ||
| 27 | getpass.return_value = 'the very secret passwd' | ||
| 28 | assert ( | ||
| 29 | etoolkit.EtoolkitInstance.confirm_password_prompt(password_hash) | ||
| 30 | == 'the very secret passwd' | ||
| 31 | ) | ||
| 32 | assert ( | ||
| 33 | etoolkit.EtoolkitInstance.confirm_password_prompt(password_hash, False) | ||
| 34 | == 'the very secret passwd' | ||
| 35 | ) | ||
| 36 | |||
| 37 | |||
| 38 | def test_decrypt(): | ||
| 39 | """Tests the static EtoolkitInstance.decrypt method""" | ||
| 40 | assert ( | ||
| 41 | etoolkit.EtoolkitInstance.decrypt( | ||
| 42 | 'the very secret passwd', | ||
| 43 | ( | ||
| 44 | 'enc-val$1$Y/TBb1F3siHTw6qZg9ERzZfA8PLPf2CwGSQLpu9jYWw=$FT5tS9' | ||
| 45 | 'o+ABvsxogIXpJim16Gz5SVtV8=' | ||
| 46 | ), | ||
| 47 | ) | ||
| 48 | == 'secret1' | ||
| 49 | ) | ||
| 50 | |||
| 51 | # now test with modified edata | ||
| 52 | with pytest.raises(etoolkit.EtoolkitInstanceError) as exc_info: | ||
| 53 | edata = ( | ||
| 54 | 'enc-val$1$Y/TBb1F3siHTw6qZg9ERzZfA8PLPf2CwGSQLpu9jYWw=$FT5tS9' | ||
| 55 | 'o+ABvsxogIXpJim17Gz5SVtV8=' | ||
| 56 | ) | ||
| 57 | etoolkit.EtoolkitInstance.decrypt( | ||
| 58 | 'the very secret passwd', edata | ||
| 59 | ) == 'secret1' | ||
| 60 | assert exc_info.type is etoolkit.EtoolkitInstanceError | ||
| 61 | assert exc_info.value.args[0] == f'Invalid tag when decrypting: {edata}' | ||
| 62 | |||
| 63 | |||
| 64 | def test_encrypt(): | ||
| 65 | """Tests the static EtoolkitInstance.encrypt method""" | ||
| 66 | edata = etoolkit.EtoolkitInstance.encrypt('foo', 'bar') | ||
| 67 | assert edata.startswith('enc-val$') | ||
| 68 | assert len(edata) == 83 | ||
| 69 | # the edata should always be different because of random salting | ||
| 70 | assert edata != etoolkit.EtoolkitInstance.encrypt('foo', 'bar') | ||
| 71 | |||
| 72 | |||
| 73 | def test_get_new_password_hash(): | ||
| 74 | """Tests the static EtoolkitInstance.get_new_password_hash method""" | ||
| 75 | new_hash = etoolkit.EtoolkitInstance.get_new_password_hash( | ||
| 76 | 'the very secret passwd' | ||
| 77 | ) | ||
| 78 | # all pbkdf2 params are the same / hardcoded for the time being | ||
| 79 | assert new_hash.startswith('pbkdf2_sha256$100000$') | ||
| 80 | assert len(new_hash) == 110 | ||
| 81 | # the hash should always be different because of random salting | ||
| 82 | assert new_hash != etoolkit.EtoolkitInstance.get_new_password_hash( | ||
| 83 | 'the very secret passwd' | ||
| 84 | ) | ||
| 85 | |||
| 86 | |||
| 87 | def test_parse_value(): | ||
| 88 | """Tests the static EtoolkitInstance.parse_value method""" | ||
| 89 | assert ( | ||
| 90 | etoolkit.EtoolkitInstance.parse_value('t%bs%t', {'%b': 'e', '%t': 't'}) | ||
| 91 | == 'test' | ||
| 92 | ) | ||
| 93 | |||
| 94 | |||
| 95 | def test_password_matches(password_hash): | ||
| 96 | """Tests the static EtoolkitInstance.password_matches method""" | ||
| 97 | assert etoolkit.EtoolkitInstance.password_matches( | ||
| 98 | 'the very secret passwd', password_hash | ||
| 99 | ) | ||
| 100 | assert not etoolkit.EtoolkitInstance.password_matches( | ||
| 101 | 'the very secret passwdo', password_hash | ||
| 102 | ) | ||
