pax_global_header00006660000000000000000000000064133733521100014510gustar00rootroot0000000000000052 comment=1e9d10ca75ae1a8672a7f192809713463657778e pass-otp-1.2.0/000077500000000000000000000000001337335211000132565ustar00rootroot00000000000000pass-otp-1.2.0/.travis.yml000066400000000000000000000015601337335211000153710ustar00rootroot00000000000000dist: trusty sudo: false language: bash env: - PASS_VERSION=1.7.3 - PASS_VERSION=master addons: apt: packages: - cabal-install - expect - ghc - oathtool before_script: - wget https://git.zx2c4.com/password-store/snapshot/password-store-$PASS_VERSION.tar.xz - tar -xvf password-store-$PASS_VERSION.tar.xz - ln -s password-store-$PASS_VERSION/src/password-store.sh pass - if [ ! -f "${HOME}/.cabal/bin/shellcheck" ]; then cabal update; cabal install ShellCheck; fi - ln -s "${HOME}/.cabal/bin/shellcheck" shellcheck - export PATH=$PATH:. - export TEST_OPTS="-v" install: true before_cache: - rm $HOME/.cabal/logs/build.log cache: directories: - $HOME/.cabal script: - make lint - cd test && make all notifications: email: recipients: - tadfisher@gmail.com on_success: never on_failure: always pass-otp-1.2.0/CHANGELOG.md000066400000000000000000000052251337335211000150730ustar00rootroot00000000000000Change Log ============= Version 1.2.0 *(2018-11-15)* ------------------------------- * New: Bash completion is now supported. (thanks Zoltan Kertesz) * Fix getopt parsing; passing `--issuer` and `--account` should no longer hang. (thanks @xPMo) Version 1.1.1 *(2018-06-28)* ------------------------------- This is mainly a bugfix release. * Numerous build and test infrstructure updates. (thanks @LucidOne) * `insert` and `append` now require only one of "issuer" or "account", matching the documentation. (thanks @sudoforge and @xPMo) * `append` now displays the passfile in its prompt. (thanks @sudoforge) * Add a separate `LICENSE` file. (thanks @dmarcoux) * Avoid use of herestrings when reading input. (thanks @rbuzatu90) * Discard base64 padding (`=` characters) in OTP secrets. In addition, thanks to @endgame and @brainstorm for their contributions to the documentation. Version 1.1.0 *(2018-03-04)* ------------------------------- * New: `insert` and `append` commands accept secret parameters directly using the `--secret`, `--issuer` and `--account` arguments. * Fix compatibility with Bash versions prior to 4.x. * Return an error status for `code` when the passfile does not contain an `otpauth://` entry. Version 1.0.0 *(2017-03-20)* ------------------------------- * New: `insert` command accepts `otpauth://` URIs directly. * New: `append` command appends or replaces OTP URIs in existing passfiles. * New: `validate` command validates an `otpauth://` URI against the [Key Uri Format](https://github.com/google/google-authenticator/wiki/Key-Uri-Format) standard. * Rename `show` to `code` for disambiguation from `pass show`. `show` is still supported as an alias. * **Drop `insert totp` and `insert hotp` commands.** These were cumbersome to support and are obviated by key URIs. * **Drop support for the 0.1.0 OTP passfile format.** Please see the [Migrating from pass-otp 0.1.0](https://github.com/tadfisher/pass-otp/blob/v1.0.0/README.md#migrating-from-pass-otp-01) section of the README for advice on migrating your OTP passfiles from the previous version. * **Drop support for entering OTP secrets as arguments.** This practice is prone to history leakage, which is why it is not supported by `pass insert`. Intrepid users may use `echo | pass otp insert`, but they should be warned to disable their shell's history feature. Version 0.1.0 *(2017-02-14)* ---------------------------- * Initial release. * Supports the following commands: - `insert totp`: Insert a TOTP secret. - `insert hotp`: Insert an HOTP secret. - `show`: Generate a QR code. - `uri`: Generate an otpauth:// URI for a secret. pass-otp-1.2.0/LICENSE000066400000000000000000001045151337335211000142710ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . pass-otp-1.2.0/Makefile000066400000000000000000000022741337335211000147230ustar00rootroot00000000000000PROG ?= otp PREFIX ?= /usr DESTDIR ?= LIBDIR ?= $(PREFIX)/lib SYSTEM_EXTENSION_DIR ?= $(LIBDIR)/password-store/extensions MANDIR ?= $(PREFIX)/share/man BASHCOMPDIR ?= /etc/bash_completion.d all: @echo "pass-$(PROG) is a shell script and does not need compilation, it can be simply executed." @echo "" @echo "To install it try \"make install\" instead." @echo @echo "To run pass $(PROG) one needs to have some tools installed on the system:" @echo " password store" install: @install -v -d "$(DESTDIR)$(MANDIR)/man1" && install -m 0644 -v pass-$(PROG).1 "$(DESTDIR)$(MANDIR)/man1/pass-$(PROG).1" @install -v -d "$(DESTDIR)$(SYSTEM_EXTENSION_DIR)/" @install -v -m0755 $(PROG).bash "$(DESTDIR)$(SYSTEM_EXTENSION_DIR)/$(PROG).bash" @install -v -d "$(DESTDIR)$(BASHCOMPDIR)/" @install -v -m 644 pass-otp.bash.completion "$(DESTDIR)$(BASHCOMPDIR)/pass-otp" @echo @echo "pass-$(PROG) is installed succesfully" @echo uninstall: @rm -vrf \ "$(DESTDIR)$(SYSTEM_EXTENSION_DIR)/$(PROG).bash" \ "$(DESTDIR)$(MANDIR)/man1/pass-$(PROG).1" "$(DESTDIR)$(BASHCOMPDIR)/pass-otp" lint: shellcheck -s bash $(PROG).bash $(MAKE) -C test lint test: $(MAKE) -C test .PHONY: install uninstall lint test pass-otp-1.2.0/README.md000066400000000000000000000162741337335211000145470ustar00rootroot00000000000000 | Branch | Status | |--------|--------| | [**master**](https://github.com/tadfisher/pass-otp/tree/master) | [![Build Status: master](https://travis-ci.org/tadfisher/pass-otp.svg?branch=master)](https://travis-ci.org/tadfisher/pass-otp) | | [**develop**](https://github.com/tadfisher/pass-otp/tree/develop) | [![Build Status: develop](https://travis-ci.org/tadfisher/pass-otp.svg?branch=develop)](https://travis-ci.org/tadfisher/pass-otp) | # pass-otp A [pass](https://www.passwordstore.org/) extension for managing one-time-password (OTP) tokens. ## Usage ``` Usage: pass otp [code] [--clip,-c] pass-name Generate an OTP code and optionally put it on the clipboard. If put on the clipboard, it will be cleared in 45 seconds. pass otp insert [--force,-f] [--echo,-e] [pass-name] Prompt for and insert a new OTP key URI. If pass-name is not supplied, use the URI label. Optionally, echo the input. Prompt before overwriting existing password unless forced. This command accepts input from stdin. pass otp append [--force,-f] [--echo,-e] pass-name Appends an OTP key URI to an existing password file. Optionally, echo the input. Prompt before overwriting an existing URI unless forced. This command accepts input from stdin. pass otp uri [--clip,-c] [--qrcode,-q] pass-name Display the key URI stored in pass-name. Optionally, put it on the clipboard, or display a QR code. pass otp validate uri Test if the given URI is a valid OTP key URI. More information may be found in the pass-otp(1) man page. ``` ## Examples Prompt for an OTP token, hiding input: ``` $ pass otp insert totp-secret Enter otpauth:// URI for totp-secret: Retype otpauth:// URI for totp-secret: ``` Prompt for an OTP token, echoing input: ``` $ pass otp insert -e totp-secret Enter otpauth:// URI for totp-secret: otpauth://totp/totp-secret?secret=AAAAAAAAAAAAAAAA&issuer=totp-secret ``` Pipe an `otpauth://` URI into a passfile: ``` $ pass otp insert totp-secret < totp-secret.txt ``` Use [zbar](http://zbar.sourceforge.net/) to decode a QR image into a passfile: ``` $ zbarimg -q --raw qrcode.png | pass otp insert totp-secret ``` The same, but appending to an existing passfile: ``` $ zbarimg -q --raw google-qrcode.png | pass otp append google/example@gmail.com ``` Generate a 2FA code using this token: ``` $ pass otp totp-secret 698816 ``` Display a QR code for an OTP token: ``` $ pass otp uri -q totp-secret █████████████████████████████████████ █████████████████████████████████████ ████ ▄▄▄▄▄ ██▄▄ ▀█ ▀ █▀█ ▄▄▄▄▄ ████ ████ █ █ █▀▄ █▀▀▄▀▀██ █ █ █ ████ ████ █▄▄▄█ █▄▀ █▄▄▄ █▀▀▄ █ █▄▄▄█ ████ ████▄▄▄▄▄▄▄█▄▀▄█ ▀ █▄█ ▀▄█▄▄▄▄▄▄▄████ ████▄▄▀██▄▄ ▀▄ █▄█▀ ▀▄▀▀▄▀█▀ ▄▀██████ ████ ▀▄▀ ▄▀ ▄▀ ▄▄ ▄ ███ ██ █ ███████ ████▀▀ ▄▄█▄▄▄▄ █ █ ▀███▀▄▀ ▀▀█ ████ ████▀▄▀ ▀ ▄█▀▄██ ▀▀▄██▀█▀▄▀▀ ▀█▀████ ████▀ █▀ ▄▄██ █▀▄▄▄ ▄▀ ▄▀ ▀ ▄▀▀████ ████ ▄ ▀█ ▄█▄ ▀ ▄██▄▀██▄ ▀▀▀█ ▄▀ ████ ████▄█▄▄▄█▄▄ █▄▄ ▀█ █▄█▀ ▄▄▄ █▄█▄████ ████ ▄▄▄▄▄ █ ▄▀▀▀▀▄ █▄▄ █▄█ ███▀████ ████ █ █ ██▀▄ █▄█ ▀█▀ ▄▄▄█▀▄ ████ ████ █▄▄▄█ █▀▄ █ █ ██▄▄▀ ▀▄█ ▄▀████ ████▄▄▄▄▄▄▄█▄█▄▄███▄█▄█▄█▄█▄██▄██████ █████████████████████████████████████ █████████████████████████████████████ ``` ## Installation ### From git ``` git clone https://github.com/tadfisher/pass-otp cd pass-otp sudo make install ``` ### Arch Linux `pass-otp` is available in the `[community]` repository: ``` pacman -S pass-otp ``` ### Debian `pass-otp` is available in `buster` and `sid` repositories with the package-name `pass-extension-otp` according to [tracker](https://tracker.debian.org/pkg/pass-otp): ``` apt install pass-extension-otp ``` ### Gentoo Linux ``` emerge app-admin/pass-otp ``` ### Nix/NixOS The following expression builds `pass` with the `pass-otp` extension: ```nix with pkgs; pass.withExtensions (exts: [ exts.pass-otp ]) ``` The above can be installed imperatively via `nix-env` or ran in a temprorary environment via `nix-shell`. ### macOS #### Brew ``` brew install oath-toolkit bash-completion git clone https://github.com/tadfisher/pass-otp cd pass-otp make install PREFIX=$(brew --prefix) BASHCOMPDIR=$(brew --prefix)/etc/bash_completion.d ``` #### Macports.org ``` sudo port install pass-otp ``` ### openSUSE ``` zypper install pass-otp ``` ### Crux Linux pass-otp in this port ``` #/etc/ports/mk.httpup # MK ports collection # # https://github.com/beli3ver/crux-ports/ ROOT_DIR=/usr/ports/mk URL=https://raw.githubusercontent.com/beli3ver/crux-ports/master/ ``` ## Requirements - `pass` 1.7.0 or later for extension support - `oathtool` for generating 2FA codes - `qrencode` for generating QR code images ### Build requirements - `make test` - `pass` >= 1.7.0 - `git` - `oathtool` - `expect` - `make lint` - `shellcheck` ## Migrating from pass-otp 0.1 `pass-otp` has switched to storing OTP tokens in the standard [Key Uri Format](https://github.com/google/google-authenticator/wiki/Key-Uri-Format). You'll need to edit any saved tokens and change them to this format. For example: ``` $ pass edit totp-secret ``` Old format: ``` otp_secret: AAAAAAAAAAAAAAAA otp_type: totp otp_algorithm: sha1 otp_period: 30 otp_digits: 6 ``` New format: ``` otpauth://totp/totp-secret?secret=AAAAAAAAAAAAAAAA&issuer=totp-secret ``` Note that the following default values do not need to be specified in the URI: | parameter | default | | --------- | ------- | | algorithm | sha1 | | period | 30 | | digits | 6 | ## Migrating from Google Authenticator **Warning:** This method is provided as a means to transport your TOTP tokens to other devices, disconnected from your single factor authentication part. If you add those secrets into the same basket of eggs, you will be defeating the whole purpose of the [multi factor authentication](https://en.wikipedia.org/wiki/Multi-factor_authentication) mantra. Please think it through before running this migration. If you read the warning paragraph above, [keep calm and move on with the migration](https://github.com/tadfisher/pass-otp/wiki/How-to-migrate-your-Google-Authenticator-database-to-pass-otp%3F). pass-otp-1.2.0/otp.bash000077500000000000000000000311151337335211000147230ustar00rootroot00000000000000#!/usr/bin/env bash # pass otp - Password Store Extension (https://www.passwordstore.org/) # Copyright (C) 2017 Tad Fisher # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # [] VERSION="1.1.1" OATH=$(which oathtool) ## source: https://gist.github.com/cdown/1163649 urlencode() { local l=${#1} for (( i = 0 ; i < l ; i++ )); do local c=${1:i:1} case "$c" in [a-zA-Z0-9.~_-]) printf "%c" "$c";; ' ') printf + ;; *) printf '%%%.2X' "'$c" esac done } urldecode() { # urldecode local url_encoded="${1//+/ }" printf '%b' "${url_encoded//%/\\x}" } # Parse a Key URI per: https://github.com/google/google-authenticator/wiki/Key-Uri-Format # Vars are consumed by caller # shellcheck disable=SC2034 otp_parse_uri() { local uri="$1" uri="${uri//\`/%60}" uri="${uri//\"/%22}" local pattern='^otpauth:\/\/(totp|hotp)(\/(([^:?]+)?(:([^:?]*))?))?\?(.+)$' [[ "$uri" =~ $pattern ]] || die "Cannot parse OTP key URI: $uri" otp_uri=${BASH_REMATCH[0]} otp_type=${BASH_REMATCH[1]} otp_label=${BASH_REMATCH[3]} otp_accountname=$(urldecode "${BASH_REMATCH[6]}") [[ -z $otp_accountname ]] && otp_accountname=$(urldecode "${BASH_REMATCH[4]}") || otp_issuer=$(urldecode "${BASH_REMATCH[4]}") [[ -z $otp_accountname ]] && die "Invalid key URI (missing accountname): $otp_uri" local p=${BASH_REMATCH[7]} local params local IFS=\&; read -r -a params < <(echo "$p") ; unset IFS pattern='^([^=]+)=(.+)$' for param in "${params[@]}"; do if [[ "$param" =~ $pattern ]]; then case ${BASH_REMATCH[1]} in secret) otp_secret=${BASH_REMATCH[2]} ;; digits) otp_digits=${BASH_REMATCH[2]} ;; algorithm) otp_algorithm=${BASH_REMATCH[2]} ;; period) otp_period=${BASH_REMATCH[2]} ;; counter) otp_counter=${BASH_REMATCH[2]} ;; issuer) otp_issuer=$(urldecode "${BASH_REMATCH[2]}") ;; *) ;; esac fi done [[ -z "$otp_secret" ]] && die "Invalid key URI (missing secret): $otp_uri" pattern='^[0-9]+$' [[ "$otp_type" == 'hotp' ]] && [[ ! "$otp_counter" =~ $pattern ]] && die "Invalid key URI (missing counter): $otp_uri" } otp_read_uri() { local uri prompt="$1" echo="$2" if [[ -t 0 ]]; then if [[ $echo -eq 0 ]]; then read -r -p "Enter otpauth:// URI for $prompt: " -s uri || exit 1 echo read -r -p "Retype otpauth:// URI for $prompt: " -s uri_again || exit 1 echo [[ "$uri" == "$uri_again" ]] || die "Error: the entered URIs do not match." else read -r -p "Enter otpauth:// URI for $prompt: " -e uri fi else read -r uri fi otp_parse_uri "$uri" } otp_read_secret() { local uri prompt="$1" echo="$2" issuer accountname separator [ ! "$3" = false ] && issuer="$(urlencode "$3")" [ ! "$4" = false ] && accountname="$(urlencode "$4")" [ -n "$issuer" ] && [ -n "$accountname" ] && separator=":" if [[ -t 0 ]]; then if [[ $echo -eq 0 ]]; then read -r -p "Enter secret for $prompt: " -s secret || exit 1 echo read -r -p "Retype secret for $prompt: " -s secret_again || exit 1 echo [[ "$secret" == "$secret_again" ]] || die "Error: the entered secrets do not match." else read -r -p "Enter secret for $prompt: " -e secret fi else read -r secret fi uri="otpauth://totp/${issuer}${separator}${accountname}?secret=${secret}" [ -n "$issuer" ] && uri="${uri}&issuer=${issuer}" otp_parse_uri "$uri" } otp_insert() { local path="$1" passfile="$2" contents="$3" message="$4" check_sneaky_paths "$path" set_git "$passfile" mkdir -p -v "$PREFIX/$(dirname "$path")" set_gpg_recipients "$(dirname "$path")" echo "$contents" | $GPG -e "${GPG_RECIPIENT_ARGS[@]}" -o "$passfile" "${GPG_OPTS[@]}" || die "OTP secret encryption aborted." git_add_file "$passfile" "$message" } cmd_otp_usage() { cat <<-_EOF Usage: $PROGRAM otp [code] [--clip,-c] pass-name Generate an OTP code and optionally put it on the clipboard. If put on the clipboard, it will be cleared in $CLIP_TIME seconds. $PROGRAM otp insert [--force,-f] [--echo,-e] [[--secret, -s] [--issuer,-i issuer] [--account,-a account]] [pass-name] Prompt for and insert a new OTP key. If 'secret' is specified, prompt for the OTP secret, assuming SHA1 algorithm, 30-second period, and 6 OTP digits; one of 'issuer' or 'account' is also required. Otherwise, prompt for a key URI; if 'pass-name' is not supplied, use the URI label. Optionally, echo the input. Prompt before overwriting existing URI unless forced. This command accepts input from stdin. $PROGRAM otp append [--force,-f] [--echo,-e] [[--secret, -s] [--issuer,-i issuer] [--account,-a account]] pass-name Appends an OTP key URI to an existing password file. If 'secret' is specified, prompt for the OTP secret, assuming SHA1 algorithm, 30-second period, and 6 OTP digits; one of 'issuer' or 'account' is also required. Otherwise, prompt for a key URI. Optionally, echo the input. Prompt before overwriting an existing URI unless forced. This command accepts input from stdin. $PROGRAM otp uri [--clip,-c] [--qrcode,-q] pass-name Display the key URI stored in pass-name. Optionally, put it on the clipboard, or display a QR code. $PROGRAM otp validate uri Test if the given URI is a valid OTP key URI. More information may be found in the pass-otp(1) man page. _EOF exit 0 } cmd_otp_version() { echo $VERSION exit 0 } cmd_otp_insert() { local opts force=0 echo=0 from_secret=0 opts="$($GETOPT -o fesi:a: -l force,echo,secret,issuer:,account: -n "$PROGRAM" -- "$@")" local err=$? eval set -- "$opts" while true; do case $1 in -f|--force) force=1; shift ;; -e|--echo) echo=1; shift ;; -s|--secret) from_secret=1; shift;; -i|--issuer) issuer=$2; shift; shift;; -a|--account) account=$2; shift; shift;; --) shift; break ;; esac done [[ $err -ne 0 ]] && die "Usage: $PROGRAM $COMMAND insert [--force,-f] [--echo,-e] [--secret, -s] [--issuer,-i issuer] [--account,-a account] [pass-name]" local prompt path uri if [[ $# -eq 1 ]]; then path="${1%/}" prompt="$path" else prompt="this token" fi if [[ $from_secret -eq 1 ]]; then [ -z "$issuer" ] && issuer=false [ -z "$account" ] && account=false [ "$issuer" = false ] && [ "$account" = false ] && die "Missing one of either '--issuer' or '--account'" otp_read_secret "$prompt" $echo "$issuer" "$account" else otp_read_uri "$prompt" $echo fi if [[ -z "$path" ]]; then [[ -n "$otp_issuer" ]] && path+="$otp_issuer/" path+="$otp_accountname" yesno "Insert into $path?" fi local passfile="$PREFIX/$path.gpg" [[ $force -eq 0 && -e $passfile ]] && yesno "An entry already exists for $path. Overwrite it?" otp_insert "$path" "$passfile" "$otp_uri" "Add OTP secret for $path to store." } cmd_otp_append() { local opts force=0 echo=0 from_secret=0 opts="$($GETOPT -o fesi:a: -l force,echo,secret,issuer:,account: -n "$PROGRAM" -- "$@")" local err=$? eval set -- "$opts" while true; do case $1 in -f|--force) force=1; shift ;; -e|--echo) echo=1; shift ;; -s|--secret) from_secret=1; shift;; -i|--issuer) issuer=$2; shift; shift;; -a|--account) account=$2; shift; shift;; --) shift; break ;; esac done [[ $err -ne 0 || $# -ne 1 ]] && die "Usage: $PROGRAM $COMMAND append [--force,-f] [--echo,-e] [--secret, -s] [--issuer,-i issuer] [--account,-a account] pass-name" local uri local path="${1%/}" local prompt="$path" local passfile="$PREFIX/$path.gpg" [[ -f $passfile ]] || die "Passfile not found" local existing contents="" while IFS= read -r line; do [[ -z "$existing" && "$line" == otpauth://* ]] && existing="$line" [[ -n "$contents" ]] && contents+=$'\n' contents+="$line" done < <($GPG -d "${GPG_OPTS[@]}" "$passfile") [[ -n "$existing" ]] && yesno "An OTP secret already exists for $path. Overwrite it?" if [[ $from_secret -eq 1 ]]; then [ -z "$issuer" ] && issuer=false [ -z "$account" ] && account=false [ "$issuer" = false ] && [ "$account" = false ] && die "Missing one of either '--issuer' or '--account'" otp_read_secret "$prompt" $echo "$issuer" "$account" else otp_read_uri "$prompt" $echo fi local replaced if [[ -n "$existing" ]]; then while IFS= read -r line; do [[ "$line" == otpauth://* ]] && line="$otp_uri" [[ -n "$replaced" ]] && replaced+=$'\n' replaced+="$line" done < <(echo "$contents") else replaced="$contents"$'\n'"$otp_uri" fi local message if [[ -n "$existing" ]]; then message="Replace OTP secret for $path." else message="Append OTP secret for $path." fi otp_insert "$path" "$passfile" "$replaced" "$message" } cmd_otp_code() { [[ -z "$OATH" ]] && die "Failed to generate OTP code: oathtool is not installed." local opts clip=0 opts="$($GETOPT -o c -l clip -n "$PROGRAM" -- "$@")" local err=$? eval set -- "$opts" while true; do case $1 in -c|--clip) clip=1; shift ;; --) shift; break ;; esac done [[ $err -ne 0 || $# -ne 1 ]] && die "Usage: $PROGRAM $COMMAND [--clip,-c] pass-name" local path="${1%/}" local passfile="$PREFIX/$path.gpg" check_sneaky_paths "$path" [[ ! -f $passfile ]] && die "$path: passfile not found." contents=$($GPG -d "${GPG_OPTS[@]}" "$passfile") while read -r -a line; do if [[ "$line" == otpauth://* ]]; then otp_parse_uri "$line" break fi done < <(echo "$contents") local cmd case "$otp_type" in totp) cmd="$OATH -b --totp" [[ -n "$otp_algorithm" ]] && cmd+=$(echo "=${otp_algorithm}"|tr "[:upper:]" "[:lower:]") [[ -n "$otp_period" ]] && cmd+=" --time-step-size=$otp_period"s [[ -n "$otp_digits" ]] && cmd+=" --digits=$otp_digits" cmd+=" $otp_secret" ;; hotp) local counter=$((otp_counter+1)) cmd="$OATH -b --hotp --counter=$counter" [[ -n "$otp_digits" ]] && cmd+=" --digits=$otp_digits" cmd+=" $otp_secret" ;; *) die "$path: OTP secret not found." ;; esac local out; out=$($cmd) || die "$path: failed to generate OTP code." if [[ "$otp_type" == "hotp" ]]; then # Increment HOTP counter in-place local line replaced uri=${otp_uri/&counter=$otp_counter/&counter=$counter} while IFS= read -r line; do [[ "$line" == otpauth://* ]] && line="$uri" [[ -n "$replaced" ]] && replaced+=$'\n' replaced+="$line" done < <(echo "$contents") otp_insert "$path" "$passfile" "$replaced" "Increment HOTP counter for $path." fi if [[ $clip -ne 0 ]]; then clip "$out" "OTP code for $path" else echo "$out" fi } cmd_otp_uri() { local contents qrcode=0 clip=0 opts="$($GETOPT -o q -l qrcode -n "$PROGRAM" -- "$@")" local err=$? eval set -- "$opts" while true; do case $1 in -q|--qrcode) qrcode=1; shift ;; -c|--clip) clip=1; shift ;; --) shift; break ;; esac done [[ $err -ne 0 || $# -ne 1 ]] && die "Usage: $PROGRAM $COMMAND uri [--clip,-c | --qrcode,-q] pass-name" local path="$1" local passfile="$PREFIX/$path.gpg" check_sneaky_paths "$path" [[ ! -f $passfile ]] && die "Passfile not found" contents=$($GPG -d "${GPG_OPTS[@]}" "$passfile") while read -r -a line; do if [[ "$line" == otpauth://* ]]; then otp_parse_uri "$line" break fi done < <(echo "$contents") if [[ $clip -eq 1 ]]; then clip "$otp_uri" "OTP key URI for $path" elif [[ $qrcode -eq 1 ]]; then qrcode "$otp_uri" "OTP key URI for $path" else echo "$otp_uri" fi } cmd_otp_validate() { otp_parse_uri "$1" } case "$1" in help|--help|-h) shift; cmd_otp_usage "$@" ;; version|--version) shift; cmd_otp_version "$@" ;; insert|add) shift; cmd_otp_insert "$@" ;; append) shift; cmd_otp_append "$@" ;; uri) shift; cmd_otp_uri "$@" ;; validate) shift; cmd_otp_validate "$@" ;; code|show) shift; cmd_otp_code "$@" ;; *) cmd_otp_code "$@" ;; esac exit 0 pass-otp-1.2.0/pass-otp.1000066400000000000000000000107431337335211000151130ustar00rootroot00000000000000.TH PASS-OTP 1 "2017 March 19" "Password store OTP extension" .SH NAME pass-otp - A \fBpass\fP(1) extension for managing one-time-password (OTP) tokens. .SH SYNOPSIS .B pass otp [ .I COMMAND ] [ .I OPTIONS ]... [ .I ARGS ]... .SH DESCRIPTION .B pass-otp extends the .BR pass (1) utility with the .B otp command for adding OTP secrets, generating OTP codes, and displaying secret key URIs using the standard \fIotpauth://\fP scheme. If no COMMAND is specified, COMMAND defaults to \fBcode\fP. .SH COMMANDS .TP \fBotp code\fP [ \fI--clip\fP, \fI-c\fP ] \fIpass-name\fP Generate and print an OTP code from the secret key stored in \fIpass-name\fP using \fBoathtool\fP(1). If \fI--clip\fP or \fI-c\fP is specified, do not print the code but instead copy it to the clipboard using \fBxclip\fP(1) and then restore the clipboard after 45 (or \fIPASSWORD_STORE_CLIP_TIME\fP) seconds. This command is alternatively named \fBshow\fP. .TP \fBotp insert\fP [ \fI--force\fP, \fI-f\fP ] [ \fI--echo\fP, \fI-e\fP ] \ [ [ \fI--secret\fP, \fI-s\fP ] [ \fI--issuer\fP, \fI-i\fP \fIissuer\fP ] \ [ \fI--account\fP, \fI-a\fP \fIaccount\fP ] ] [ \fIpass-name\fP ] Prompt for and insert a new OTP secret into the password store at \fIpass-name\fP. If \fI--secret\fP is specified, prompt for the \fIsecret\fP value, assuming SHA1 algorithm, 30-second period, and 6 OTP digits. One or both of \fIissuer\fP and \fIaccount\fP must also be specified. If \fI--secret\fP is not specified, prompt for a key URI; see the documentation at .UR https://\:github.\:com/\:google/\:google-authenticator/\:wiki/\:Key-Uri-Format .UE for the key URI specification. The secret is consumed from stdin; specify \fI--echo\fP or \fI-e\fP to echo input when running this command interactively. If \fIpass-name\fP is not specified, convert the \fIissuer:accountname\fP URI label to a path in the form of \fIisser/accountname\fP. Prompt before overwriting an existing secret, unless \fI--force\fP or \fI-f\fP is specified. This command is alternatively named \fBadd\fP. .TP \fBotp append\fP [ \fI--force\fP, \fI-f\fP ] [ \fI--echo\fP, \fI-e\fP ] \ [ [ \fI--secret\fP, \fI-s\fP ] [ \fI--issuer\fP, \fI-i\fP \fIissuer\fP ] \ [ \fI--account\fP, \fI-a\fP \fIaccount\fP ] ] \fIpass-name\fP Append an OTP secret to the password stored in \fIpass-name\fP, preserving any existing lines. If \fI--secret\fP is specified, prompt for the \fIsecret\fP value, assuming SHA1 algorithm, 30-second period, and 6 OTP digits. One or both of \fIissuer\fP and \fIaccount\fP must also be specified. If \fI--secret\fP is not specified, prompt for a key URI; see the documentation at .UR https://\:github.\:com/\:google/\:google-authenticator/\:wiki/\:Key-Uri-Format .UE for the key URI specification. The URI is consumed from stdin; specify \fI--echo\fP or \fI-e\fP to echo input when running this command interactively. Prompt before overwriting an existing secret, unless \fI--force\fP or \fI-f\fP is specified. .TP \fBotp uri\fP [ \fI--clip\fP, \fI-c\fP | \fI--qrcode\fP, \fI-q\fP ] \fIpass-name\fP Print the key URI stored in \fIpass-name\fP to stdout. If \fI--clip\fP or \fI-c\fP is specified, do not print the URI but instead copy it to the clipboard using .BR xclip (1) and then restore the clipboard after 45 (or \fIPASSWORD_STORE_CLIP_TIME\fP) seconds. If \fI--qrcode\fP or \fI-q\fP is specified, do not print the URI but instead display a QR code using .BR qrencode (1) either to the terminal or graphically if supported. .TP \fBotp validate\fP \fIuri\fP Test a URI string for validity according to the Key Uri Format. For more information about this format, see the documentation at .UR https://\:github.\:com/\:google/\:google-authenticator/\:wiki/\:Key-Uri-Format .UE . .SH OPTIONS .TP \fBhelp\fP, \fB\-h\fP, \fB\-\-help\fP Show usage message. .SH SEE ALSO .BR pass (1), .BR qrencode (1), .BR zbarimg (1) .SH AUTHORS .B pass-otp was written by .MT tadfisher@gmail.com Tad Fisher .ME . .SH COPYING This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . pass-otp-1.2.0/pass-otp.bash.completion000066400000000000000000000013621337335211000200350ustar00rootroot00000000000000PASSWORD_STORE_EXTENSION_COMMANDS+=(otp) __password_store_extension_complete_otp() { if [[ $COMP_CWORD -gt 2 ]]; then case "${COMP_WORDS[2]}" in insert|append) COMPREPLY+=($(compgen -W "-e --echo -f --force -s --secret -i --issuer -a --account" -- ${cur})) _pass_complete_entries ;; uri) COMPREPLY+=($(compgen -W "-c --clip -q --qrcode" -- ${cur})) _pass_complete_entries ;; validate) _pass_complete_entries ;; *) COMPREPLY+=($(compgen -W "-h --help" -- ${cur})) _pass_complete_entries ;; esac else COMPREPLY+=($(compgen -W "insert append uri validate -h --help -c --clip" -- ${cur})) _pass_complete_entries 1 fi } pass-otp-1.2.0/test/000077500000000000000000000000001337335211000142355ustar00rootroot00000000000000pass-otp-1.2.0/test/.gitignore000066400000000000000000000000611337335211000162220ustar00rootroot00000000000000gnupg/random_seed test-results/ trash directory.*pass-otp-1.2.0/test/Makefile000066400000000000000000000035251337335211000157020ustar00rootroot00000000000000# Run tests # # Copyright (c) 2011-2012 Mathias Lafeldt # Copyright (c) 2005-2012 Git project # Copyright (c) 2005-2012 Junio C Hamano # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see http://www.gnu.org/licenses/ . SHELL := /bin/bash SHELL_PATH ?= $(SHELL) SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH)) RM ?= rm -f PROVE ?= prove AGGREGATE_SCRIPT ?= aggregate-results.sh DEFAULT_TEST_TARGET ?= test T = $(sort $(wildcard *.t)) all: $(DEFAULT_TEST_TARGET) debug: pre-clean TEST_OPTS="-v" $(MAKE) aggregate-results-and-cleanup test: pre-clean $(MAKE) aggregate-results-and-cleanup prove: pre-clean @echo "*** prove ***"; $(PROVE) --exec '$(SHELL_PATH_SQ)' $(PROVE_OPTS) $(T) :: $(TEST_OPTS) $(MAKE) clean-except-prove-cache $(T): @echo "*** $@ ***"; '$(SHELL_PATH_SQ)' $@ $(TEST_OPTS) pre-clean: $(RM) -r test-results clean-except-prove-cache: $(RM) -r 'trash directory'.* test-results clean: clean-except-prove-cache $(RM) .prove $(RM) gnupg/random_seed aggregate-results-and-cleanup: $(MAKE) aggregate-results $(MAKE) clean aggregate-results: $(T) for f in test-results/*.counts; do \ echo "$$f"; \ done | '$(SHELL_PATH_SQ)' '$(AGGREGATE_SCRIPT)' lint: shellcheck -s bash setup.sh .PHONY: all debug test prove $(T) pre-clean clean lint .PHONY: aggregate-results-and-cleanup aggregate-results pass-otp-1.2.0/test/aggregate-results.sh000077500000000000000000000027041337335211000202240ustar00rootroot00000000000000#!/bin/sh # # Copyright (c) 2008-2012 Git project # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see http://www.gnu.org/licenses/ . failed_tests= fixed=0 success=0 failed=0 broken=0 total=0 while read file; do while read type value; do case $type in '') continue ;; fixed) fixed=$(($fixed + $value)) ;; success) success=$(($success + $value)) ;; failed) failed=$(($failed + $value)) if test $value != 0; then test_name=$(expr "$file" : 'test-results/\(.*\)\.[0-9]*\.counts') failed_tests="$failed_tests $test_name" fi ;; broken) broken=$(($broken + $value)) ;; total) total=$(($total + $value)) ;; esac done <"$file" done if test -n "$failed_tests"; then printf "\nfailed test(s):$failed_tests\n\n" fi printf "%-8s%d\n" fixed $fixed printf "%-8s%d\n" success $success printf "%-8s%d\n" failed $failed printf "%-8s%d\n" broken $broken printf "%-8s%d\n" total $total pass-otp-1.2.0/test/append.t000077500000000000000000000067061337335211000157050ustar00rootroot00000000000000#!/usr/bin/env bash export test_description="Tests pass otp append commands" . ./setup.sh test_expect_success 'Reads non-terminal input' ' existing="foo bar baz" uri="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Foo" test_pass_init && "$PASS" insert -e passfile <<< "$existing" && "$PASS" otp append -e passfile <<< "$uri" && [[ $("$PASS" otp uri passfile) == "$uri" ]] ' test_expect_success 'Read secret non-terminal input' ' existing="foo bar baz" secret=JBSWY3DPEHPK3PXP uri="otpauth://totp/Example:alice%40google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example" test_pass_init && "$PASS" insert -e passfile <<< "$existing" && "$PASS" otp append -s -i Example -a alice@google.com -e passfile <<< "$secret" && [[ $("$PASS" otp uri passfile) == "$uri" ]] ' test_expect_success 'Reads terminal input in noecho mode' ' existing="foo bar baz" uri="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example" test_pass_init && "$PASS" insert -e passfile <<< "$existing" && { expect -d <߷6^e^w"CTDTM4U-Pk ;YwqM&Z#Ղ%&BNxxln,ø ǫP̧^vw@8ٮЁp7t'58d26(p3Y]ZL:4qœ?hFdW¸]!P0l]K<~ꈠr+G ܖ5R(qs)(1:e3:)(1:d256:E5*\62qJ,z;(3!n COQ2hwlt26&J[N4/B+#9,\niOj``&h5Ìi( q0!R&lF WL?fRu5P[O2hi T۠J~ ~;i^x5i>eIcz= ~31 \tw929%-{-=p`N Z1)(1:p129:ͳ zjX/[cL{j"ɹYqlh9ɲ?U @mXO3jr"KUB„}rJfeeqу#HqKӠWWiYIڟgm!%)(1:q129:$:?:$ߩAzh,a:!Ql#8;J1 djHE` IMQ,t'%.@`=YmMVCPS3~"d LX`_aǾL`R@.ͿaNlM>Rc G=]pEIgĂ]hp)(1:e3:)(1:d256:4.̏*}Pal~m{EM pwK5!YƜ${ąr uߴc1cnwm@/2j38⤼-CkAjwB%MV3LH9OLbތUECFH}?!\=ɢx}k'ңErY5F9C%5Bf{E ;Sj~ձG5ElwŸ+ 06֡v5d[LE . @*!)(1:p129:+\H7"sRBjb.@WxfupBmHm1{ʡj,l\q2d 'U:VqfYaO֏LTr@h`+NXj[i~M)(1:q129:ZnUn L ʖ*' Ir}R mDL\aN={αy@ޔn{{4XƎ!^( a~?` -J=N6= Ǧ2DfV3*<_)(1:u128:o^ts5EJ 4/2g_<䜪v%jM J\[`>;e~ |k/45f[_J L㔊T()wQk?;)))pass-otp-1.2.0/test/gnupg/private-keys-v1.d/615FC2A5B2CBFD58B7FFA0A140D43B74AB9748B0.key000066400000000000000000000017211337335211000260220ustar00rootroot00000000000000(11:private-key(3:rsa(1:n257:A^[Ypr)E8B[ULs8p)yj/g`[S*>V6DcD1Z!q_? 3K0EpKȫ:u}藊wTKT2_Nd$bV=U3-*Vy!Q_c%q:M?v_=DYY˔7m " y-{鵑#G}Ʊ*GetL)(1:e3:)(1:d256: qz.a'2xxCj/dCikUQJ`Or=i:T+yۥVbi}=kdv6\;rc\ 3#)\:FRD"Y $f3YD;kKn=̴D=/!j 'Z*#P-H pDvgL|(71BoMK4 :n:etqa53@G]kdS~8c7H)qVT)(1:p129:ˆIjCʙ.q@fǧVBǛ*wJ;>{8%ao|YBtڍ騱lQN<K"_k`3¬Gk)(1:e3:)(1:d256:+OfY$* <}iT  "(kY"^81U4p/n;J\:J3V"\)pE\j/*@|zy6-削'k("f!5CzE3 %BAt:@,IQv F7wRX%9HGP ,vƂŸ*b+g".'1lɜ9㢕7}&Gh)nU`0/uT\.U)(1:p129:骢bhLQVdee2'uGQc2Oe,;BvYzAb3ٟhqԙ!1žTg ,cϗ'brH$}r"v_qk<^q|mPQC}-Ub8Ļ(^Ni)(1:p129:vb ᓼ k;!M%>±E,moՃy4ꦮD@iwmf^{l`-淘`*I <Q6eSޟ)(1:q129:]Vr()Wzv<>`WP ǝ .di3T&!/Jvֵ z}9s=SQd~5R"B=FWY)CČ4KiqcJ9e)(1:u129:'*Sӑ\J] `lI3{\NN`M^U dVƜ_is-nv.ThO*1OC/\2^¶@rF+^3r-]LJ)))pass-otp-1.2.0/test/gnupg/private-keys-v1.d/C93858C40FA9E117DA4E7F336580B8B12354EB83.key000066400000000000000000000017211337335211000257320ustar00rootroot00000000000000(11:private-key(3:rsa(1:n257:|h.(}#ľv #pkTIgXI gb0Uޏ`␼B`*PĚ=N,hڰa3#WkB}Lda-YD~h;1A@ەl\i9w8/-́^_d,][ Z'2y=[J%/e Z?@7`O|cexoIAeqdkrs뀯0J{<Ը%)(1:e3:)(1:d256:j2ȝ3uG5rg?"&x"|C_!V–+zܠ0;3}xW8զLW8fU-](* іpN sD{Sw--)(1:q129:>=Fq)ɜv@8 ޵M ߗթepm>9 '/B#$&NvÞڈձɶ5 KoRo}c@s"+F%ƔA)A)(1:u128:NЌ,ӕ[} Jq b3tji.>Ǡc-m2P]7C5GEAze|i|bVGLC wx&~o<)͠G$ W0ѕ{()))pass-otp-1.2.0/test/gnupg/private-keys-v1.d/C93F70CA322D4F42E7FC7D54F6367E65C23E5CA3.key000066400000000000000000000017221337335211000260120ustar00rootroot00000000000000(11:private-key(3:rsa(1:n257:TZbjoz2OUm^ϭkKtyG᪁kZ[ӏ,hz()Q=e2d' KB]gL*iPO[c| ʲmcJk/XF %ĸJhBQ^g*2ƙgJ{F֨e^~zs8g}|+v \N;RsM8q4Z}m8"F_EMc+ݔ3 h+)(1:e3:)(1:d256:2K/5 0rD1mmUi< 7~u;r>l[WJ%4ʞ 6Zbkki^M3>K0iwT0XT 4xp Ƴ@t>t "*]nr`PАG.n62sQA 0ͺv&k3b3ݻ zg u,߯=ooLlh_MQ Vԏ¥b izlk#6")(1:p129:Ţ`bIGyMn.ַqTT,WvZ :\>_ovk*o_N}8r'ucG'kļ.yXAD5^RKxFhϺ޻į|Ckq'M)(1:q129:Aܠnf%jTRKՔdcG'v$Kۄ=% 1d. KͲ*qHثq!FG'H>LBml}9=hW)(1:u129:!1j+W|=ϫaMXߋby G0 `Ε~#F>6{aʸJCy8t0fK~qKN)))pass-otp-1.2.0/test/gnupg/private-keys-v1.d/CDA6EE91E62A15AB9F6A3041FE01CC123B7E9D23.key000066400000000000000000000017221337335211000260200ustar00rootroot00000000000000(11:private-key(3:rsa(1:n257:ꑯVf_%en uUTXR]ӳ 2;'{u& }$,A rI)^Wn݁m-;iVN`,VG֯ 0ܤׇ(ZbIV*쁛XI3O˽c)d!f1OݤII0f *mjS7@FNVjn%^t1b^^6D\@̘gZ)(1:e3:)(1:d256: {7jhj9S$(ϟOSx>q;4&ǯNu\-<87頶#mpTfq`*niV 6xl5Qy,uk6e9vK~ 4B|MІb6֙dD{Ȧ'A`@H=u],U {WeGڀf)))pass-otp-1.2.0/test/gnupg/private-keys-v1.d/FFED3C5A6A52B200BCCE3F41593EA51D6054649F.key000066400000000000000000000017221337335211000260100ustar00rootroot00000000000000(11:private-key(3:rsa(1:n257:εezh7k-zm_>O=L?-} LFۮ,K'aUE8D+ vLP\=cnE$Lsen 2I^bUs72`W/^e ͒퀈TR{%!~GU5Bq oi@jvlN&&жF =|mp3J;o*a{C doBI*7R丑 ѯ)(1:e3:)(1:d256: x=qoN\뮆O+9}vD4ABj *nFaYpAWu?H\vu;k}_{|?#6󺣔pih((b9%Ũ7Szqbv63|ilMC?։K͗dKh7hgtI=o$nmzBojO9VCQfwb"X f H#y\r (U)(1:p129: Qڿ &˝zp<W8׹euFmHKTrnn3BIa4EeJv;k5,Ֆװ~jڠ$DcPS .)WD7s|Zٮq)(1:q129:bL 3_k`3¬Gkpass test key 19#SW3q   ̝Gϐ{6Kg('AIÊ*23Nq@]cKN+B1f *n:^=0x5w4?InugmO5kGam#띏tMռ2poy y`,]eKmgH9oB+Io܉XMOnK n ݙo^}'- GDRʠ\s-qD;] o3DnNksvg5. SW3q6gR+8m?uԻƷ!S.k 3:wV`;E%>߷6^e^w"CTDTM4U-Pk ;YwqM&Z#Ղ%&BNxxln,ø ǫP̧^vw@8ٮЁp7t'58d26(p3Y]ZL:4qœ?hFdW¸]!P0l]K<~ꈠr+G ܖ5R(qs SW3q ̝Gϐ{"A&jXU2>. n޻(`vSylY!@v-H,0/JSK:{{'$izX2P^`NҏC2f.<-dUn&5o_\SFhHP?㦻u!Xj|-4\Xȝj'6tb535kڤEa;ki 45J<5gKnR ;-)QJ#fN:9s^j:Ǯ SW3ꑯVf_%en uUTXR]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Y@ctiK=?\б ND/]H6-EknbLc6rU5nfwVɷ\TK2y#[ (lx\`Y^UK.ffU| $-.D/N'| -+pass-otp-1.2.0/test/gnupg/trustdb.gpg000066400000000000000000000031001337335211000175350ustar00rootroot00000000000000gpgSW4 & " $  Ǎ'Ak̝Gϐ{ fϲavH* pD0e6Eݿtt! %ɛ 0%8L bK4qAEķ}T# &Nl[L X0 z x&v)fwmi% M؁Ecdn1cc M*gYCs9 ' R޶*"ҔcîjF+=wpass-otp-1.2.0/test/insert.t000077500000000000000000000074551337335211000157440ustar00rootroot00000000000000#!/usr/bin/env bash export test_description="Tests pass otp insert commands" . ./setup.sh test_expect_success 'Reads non-terminal input' ' uri="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example" test_pass_init && "$PASS" otp insert passfile <<< "$uri" && [[ $("$PASS" show passfile) == "$uri" ]] ' test_expect_success 'Reads terminal input in noecho mode' ' uri="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example" test_pass_init expect </dev/null 2>&1 && tput setaf 1 >/dev/null 2>&1 && tput sgr0 >/dev/null 2>&1 ) && color=t while test "$#" -ne 0; do case "$1" in -d|--d|--de|--deb|--debu|--debug) debug=t; shift ;; -i|--i|--im|--imm|--imme|--immed|--immedi|--immedia|--immediat|--immediate) immediate=t; shift ;; -l|--l|--lo|--lon|--long|--long-|--long-t|--long-te|--long-tes|--long-test|--long-tests) TEST_LONG=t; export TEST_LONG; shift ;; --in|--int|--inte|--inter|--intera|--interac|--interact|--interacti|--interactiv|--interactive|--interactive-|--interactive-t|--interactive-te|--interactive-tes|--interactive-test|--interactive-tests): TEST_INTERACTIVE=t; export TEST_INTERACTIVE; verbose=t; shift ;; -h|--h|--he|--hel|--help) help=t; shift ;; -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose) verbose=t; shift ;; -q|--q|--qu|--qui|--quie|--quiet) # Ignore --quiet under a TAP::Harness. Saying how many tests # passed without the ok/not ok details is always an error. test -z "$HARNESS_ACTIVE" && quiet=t; shift ;; --chain-lint) chain_lint=t; shift ;; --no-chain-lint) chain_lint=; shift ;; --no-color) color=; shift ;; --root=*) root=$(expr "z$1" : 'z[^=]*=\(.*\)') shift ;; *) echo "error: unknown test option '$1'" >&2; exit 1 ;; esac done if test -n "$color"; then # Save the color control sequences now rather than run tput # each time say_color() is called. This is done for two # reasons: # * TERM will be changed to dumb # * HOME will be changed to a temporary directory and tput # might need to read ~/.terminfo from the original HOME # directory to get the control sequences # Note: This approach assumes the control sequences don't end # in a newline for any terminal of interest (command # substitutions strip trailing newlines). Given that most # (all?) terminals in common use are related to ECMA-48, this # shouldn't be a problem. say_color_error=$(tput bold; tput setaf 1) # bold red say_color_skip=$(tput setaf 4) # blue say_color_warn=$(tput setaf 3) # brown/yellow say_color_pass=$(tput setaf 2) # green say_color_info=$(tput setaf 6) # cyan say_color_reset=$(tput sgr0) say_color_="" # no formatting for normal text say_color() { test -z "$1" && test -n "$quiet" && return eval "say_color_color=\$say_color_$1" shift printf "%s\\n" "$say_color_color$*$say_color_reset" } else say_color() { test -z "$1" && test -n "$quiet" && return shift printf "%s\n" "$*" } fi TERM=dumb export TERM error() { say_color error "error: $*" EXIT_OK=t exit 1 } say() { say_color info "$*" } test -n "$test_description" || error "Test script did not set test_description." if test "$help" = "t"; then echo "$test_description" exit 0 fi exec 5>&1 exec 6<&0 if test "$verbose" = "t"; then exec 4>&2 3>&1 else exec 4>/dev/null 3>/dev/null fi test_failure=0 test_count=0 test_fixed=0 test_broken=0 test_success=0 die() { code=$? if test -n "$EXIT_OK"; then exit $code else echo >&5 "FATAL: Unexpected exit with code $code" exit 1 fi } EXIT_OK= trap 'die' EXIT # Public: Define that a test prerequisite is available. # # The prerequisite can later be checked explicitly using test_have_prereq or # implicitly by specifying the prerequisite name in calls to test_expect_success # or test_expect_failure. # # $1 - Name of prerequiste (a simple word, in all capital letters by convention) # # Examples # # # Set PYTHON prerequisite if interpreter is available. # command -v python >/dev/null && test_set_prereq PYTHON # # # Set prerequisite depending on some variable. # test -z "$NO_GETTEXT" && test_set_prereq GETTEXT # # Returns nothing. test_set_prereq() { satisfied_prereq="$satisfied_prereq$1 " } satisfied_prereq=" " # Public: Check if one or more test prerequisites are defined. # # The prerequisites must have previously been set with test_set_prereq. # The most common use of this is to skip all the tests if some essential # prerequisite is missing. # # $1 - Comma-separated list of test prerequisites. # # Examples # # # Skip all remaining tests if prerequisite is not set. # if ! test_have_prereq PERL; then # skip_all='skipping perl interface tests, perl not available' # test_done # fi # # Returns 0 if all prerequisites are defined or 1 otherwise. test_have_prereq() { # prerequisites can be concatenated with ',' save_IFS=$IFS IFS=, set -- $* IFS=$save_IFS total_prereq=0 ok_prereq=0 missing_prereq= for prerequisite; do case "$prerequisite" in !*) negative_prereq=t prerequisite=${prerequisite#!} ;; *) negative_prereq= esac total_prereq=$(($total_prereq + 1)) case "$satisfied_prereq" in *" $prerequisite "*) satisfied_this_prereq=t ;; *) satisfied_this_prereq= esac case "$satisfied_this_prereq,$negative_prereq" in t,|,t) ok_prereq=$(($ok_prereq + 1)) ;; *) # Keep a list of missing prerequisites; restore # the negative marker if necessary. prerequisite=${negative_prereq:+!}$prerequisite if test -z "$missing_prereq"; then missing_prereq=$prerequisite else missing_prereq="$prerequisite,$missing_prereq" fi esac done test $total_prereq = $ok_prereq } # You are not expected to call test_ok_ and test_failure_ directly, use # the text_expect_* functions instead. test_ok_() { test_success=$(($test_success + 1)) say_color "" "ok $test_count - $@" } test_failure_() { test_failure=$(($test_failure + 1)) say_color error "not ok $test_count - $1" shift echo "$@" | sed -e 's/^/# /' test "$immediate" = "" || { EXIT_OK=t; exit 1; } } test_known_broken_ok_() { test_fixed=$(($test_fixed + 1)) say_color error "ok $test_count - $@ # TODO known breakage vanished" } test_known_broken_failure_() { test_broken=$(($test_broken + 1)) say_color warn "not ok $test_count - $@ # TODO known breakage" } # Public: Execute commands in debug mode. # # Takes a single argument and evaluates it only when the test script is started # with --debug. This is primarily meant for use during the development of test # scripts. # # $1 - Commands to be executed. # # Examples # # test_debug "cat some_log_file" # # Returns the exit code of the last command executed in debug mode or 0 # otherwise. test_debug() { test "$debug" = "" || eval "$1" } # Public: Stop execution and start a shell. # # This is useful for debugging tests and only makes sense together with "-v". # Be sure to remove all invocations of this command before submitting. test_pause() { if test "$verbose" = t; then "$SHELL_PATH" <&6 >&3 2>&4 else error >&5 "test_pause requires --verbose" fi } test_eval_() { # This is a separate function because some tests use # "return" to end a test_expect_success block early. case ",$test_prereq," in *,INTERACTIVE,*) eval "$*" ;; *) eval &3 2>&4 "$*" ;; esac } test_run_() { test_cleanup=: expecting_failure=$2 test_eval_ "$1" eval_ret=$? if test "$chain_lint" = "t"; then test_eval_ "(exit 117) && $1" if test "$?" != 117; then error "bug in the test script: broken &&-chain: $1" fi fi if test -z "$immediate" || test $eval_ret = 0 || test -n "$expecting_failure"; then test_eval_ "$test_cleanup" fi if test "$verbose" = "t" && test -n "$HARNESS_ACTIVE"; then echo "" fi return "$eval_ret" } test_skip_() { test_count=$(($test_count + 1)) to_skip= for skp in $SKIP_TESTS; do case $this_test.$test_count in $skp) to_skip=t break esac done if test -z "$to_skip" && test -n "$test_prereq" && ! test_have_prereq "$test_prereq"; then to_skip=t fi case "$to_skip" in t) of_prereq= if test "$missing_prereq" != "$test_prereq"; then of_prereq=" of $test_prereq" fi say_color skip >&3 "skipping test: $@" say_color skip "ok $test_count # skip $1 (missing $missing_prereq${of_prereq})" : true ;; *) false ;; esac } # Public: Run test commands and expect them to succeed. # # When the test passed, an "ok" message is printed and the number of successful # tests is incremented. When it failed, a "not ok" message is printed and the # number of failed tests is incremented. # # With --immediate, exit test immediately upon the first failed test. # # Usually takes two arguments: # $1 - Test description # $2 - Commands to be executed. # # With three arguments, the first will be taken to be a prerequisite: # $1 - Comma-separated list of test prerequisites. The test will be skipped if # not all of the given prerequisites are set. To negate a prerequisite, # put a "!" in front of it. # $2 - Test description # $3 - Commands to be executed. # # Examples # # test_expect_success \ # 'git-write-tree should be able to write an empty tree.' \ # 'tree=$(git-write-tree)' # # # Test depending on one prerequisite. # test_expect_success TTY 'git --paginate rev-list uses a pager' \ # ' ... ' # # # Multiple prerequisites are separated by a comma. # test_expect_success PERL,PYTHON 'yo dawg' \ # ' test $(perl -E 'print eval "1 +" . qx[python -c "print 2"]') == "4" ' # # Returns nothing. test_expect_success() { test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq= test "$#" = 2 || error "bug in the test script: not 2 or 3 parameters to test_expect_success" export test_prereq if ! test_skip_ "$@"; then say >&3 "expecting success: $2" if test_run_ "$2"; then test_ok_ "$1" else test_failure_ "$@" fi fi echo >&3 "" } # Public: Run test commands and expect them to fail. Used to demonstrate a known # breakage. # # This is NOT the opposite of test_expect_success, but rather used to mark a # test that demonstrates a known breakage. # # When the test passed, an "ok" message is printed and the number of fixed tests # is incremented. When it failed, a "not ok" message is printed and the number # of tests still broken is incremented. # # Failures from these tests won't cause --immediate to stop. # # Usually takes two arguments: # $1 - Test description # $2 - Commands to be executed. # # With three arguments, the first will be taken to be a prerequisite: # $1 - Comma-separated list of test prerequisites. The test will be skipped if # not all of the given prerequisites are set. To negate a prerequisite, # put a "!" in front of it. # $2 - Test description # $3 - Commands to be executed. # # Returns nothing. test_expect_failure() { test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq= test "$#" = 2 || error "bug in the test script: not 2 or 3 parameters to test_expect_failure" export test_prereq if ! test_skip_ "$@"; then say >&3 "checking known breakage: $2" if test_run_ "$2" expecting_failure; then test_known_broken_ok_ "$1" else test_known_broken_failure_ "$1" fi fi echo >&3 "" } # Public: Run command and ensure that it fails in a controlled way. # # Use it instead of "! ". For example, when dies due to a # segfault, test_must_fail diagnoses it as an error, while "! " would # mistakenly be treated as just another expected failure. # # This is one of the prefix functions to be used inside test_expect_success or # test_expect_failure. # # $1.. - Command to be executed. # # Examples # # test_expect_success 'complain and die' ' # do something && # do something else && # test_must_fail git checkout ../outerspace # ' # # Returns 1 if the command succeeded (exit code 0). # Returns 1 if the command died by signal (exit codes 130-192) # Returns 1 if the command could not be found (exit code 127). # Returns 0 otherwise. test_must_fail() { "$@" exit_code=$? if test $exit_code = 0; then echo >&2 "test_must_fail: command succeeded: $*" return 1 elif test $exit_code -gt 129 -a $exit_code -le 192; then echo >&2 "test_must_fail: died by signal: $*" return 1 elif test $exit_code = 127; then echo >&2 "test_must_fail: command not found: $*" return 1 fi return 0 } # Public: Run command and ensure that it succeeds or fails in a controlled way. # # Similar to test_must_fail, but tolerates success too. Use it instead of # " || :" to catch failures caused by a segfault, for instance. # # This is one of the prefix functions to be used inside test_expect_success or # test_expect_failure. # # $1.. - Command to be executed. # # Examples # # test_expect_success 'some command works without configuration' ' # test_might_fail git config --unset all.configuration && # do something # ' # # Returns 1 if the command died by signal (exit codes 130-192) # Returns 1 if the command could not be found (exit code 127). # Returns 0 otherwise. test_might_fail() { "$@" exit_code=$? if test $exit_code -gt 129 -a $exit_code -le 192; then echo >&2 "test_might_fail: died by signal: $*" return 1 elif test $exit_code = 127; then echo >&2 "test_might_fail: command not found: $*" return 1 fi return 0 } # Public: Run command and ensure it exits with a given exit code. # # This is one of the prefix functions to be used inside test_expect_success or # test_expect_failure. # # $1 - Expected exit code. # $2.. - Command to be executed. # # Examples # # test_expect_success 'Merge with d/f conflicts' ' # test_expect_code 1 git merge "merge msg" B master # ' # # Returns 0 if the expected exit code is returned or 1 otherwise. test_expect_code() { want_code=$1 shift "$@" exit_code=$? if test $exit_code = $want_code; then return 0 fi echo >&2 "test_expect_code: command exited with $exit_code, we wanted $want_code $*" return 1 } # Public: Compare two files to see if expected output matches actual output. # # The TEST_CMP variable defines the command used for the comparision; it # defaults to "diff -u". Only when the test script was started with --verbose, # will the command's output, the diff, be printed to the standard output. # # This is one of the prefix functions to be used inside test_expect_success or # test_expect_failure. # # $1 - Path to file with expected output. # $2 - Path to file with actual output. # # Examples # # test_expect_success 'foo works' ' # echo expected >expected && # foo >actual && # test_cmp expected actual # ' # # Returns the exit code of the command set by TEST_CMP. test_cmp() { ${TEST_CMP:-diff -u} "$@" } # Public: portably print a sequence of numbers. # # seq is not in POSIX and GNU seq might not be available everywhere, # so it is nice to have a seq implementation, even a very simple one. # # $1 - Starting number. # $2 - Ending number. # # Examples # # test_expect_success 'foo works 10 times' ' # for i in $(test_seq 1 10) # do # foo || return # done # ' # # Returns 0 if all the specified numbers can be displayed. test_seq() { i="$1" j="$2" while test "$i" -le "$j" do echo "$i" || return i=$(expr "$i" + 1) done } # Public: Check if the file expected to be empty is indeed empty, and barfs # otherwise. # # $1 - File to check for emptyness. # # Returns 0 if file is empty, 1 otherwise. test_must_be_empty() { if test -s "$1" then echo "'$1' is not empty, it contains:" cat "$1" return 1 fi } # Public: Schedule cleanup commands to be run unconditionally at the end of a # test. # # If some cleanup command fails, the test will not pass. With --immediate, no # cleanup is done to help diagnose what went wrong. # # This is one of the prefix functions to be used inside test_expect_success or # test_expect_failure. # # $1.. - Commands to prepend to the list of cleanup commands. # # Examples # # test_expect_success 'test core.capslock' ' # git config core.capslock true && # test_when_finished "git config --unset core.capslock" && # do_something # ' # # Returns the exit code of the last cleanup command executed. test_when_finished() { test_cleanup="{ $* } && (exit \"\$eval_ret\"); eval_ret=\$?; $test_cleanup" } # Public: Schedule cleanup commands to be run unconditionally when all tests # have run. # # This can be used to clean up things like test databases. It is not needed to # clean up temporary files, as test_done already does that. # # Examples: # # cleanup mysql -e "DROP DATABASE mytest" # # Returns the exit code of the last cleanup command executed. final_cleanup= cleanup() { final_cleanup="{ $* } && (exit \"\$eval_ret\"); eval_ret=\$?; $final_cleanup" } # Public: Summarize test results and exit with an appropriate error code. # # Must be called at the end of each test script. # # Can also be used to stop tests early and skip all remaining tests. For this, # set skip_all to a string explaining why the tests were skipped before calling # test_done. # # Examples # # # Each test script must call test_done at the end. # test_done # # # Skip all remaining tests if prerequisite is not set. # if ! test_have_prereq PERL; then # skip_all='skipping perl interface tests, perl not available' # test_done # fi # # Returns 0 if all tests passed or 1 if there was a failure. test_done() { EXIT_OK=t if test -z "$HARNESS_ACTIVE"; then test_results_dir="$SHARNESS_TEST_DIRECTORY/test-results" mkdir -p "$test_results_dir" test_results_path="$test_results_dir/$this_test.$$.counts" cat >>"$test_results_path" <<-EOF total $test_count success $test_success fixed $test_fixed broken $test_broken failed $test_failure EOF fi if test "$test_fixed" != 0; then say_color error "# $test_fixed known breakage(s) vanished; please update test(s)" fi if test "$test_broken" != 0; then say_color warn "# still have $test_broken known breakage(s)" fi if test "$test_broken" != 0 || test "$test_fixed" != 0; then test_remaining=$(( $test_count - $test_broken - $test_fixed )) msg="remaining $test_remaining test(s)" else test_remaining=$test_count msg="$test_count test(s)" fi case "$test_failure" in 0) # Maybe print SKIP message if test -n "$skip_all" && test $test_count -gt 0; then error "Can't use skip_all after running some tests" fi [ -z "$skip_all" ] || skip_all=" # SKIP $skip_all" if test $test_remaining -gt 0; then say_color pass "# passed all $msg" fi say "1..$test_count$skip_all" test_eval_ "$final_cleanup" test -d "$remove_trash" && cd "$(dirname "$remove_trash")" && rm -rf "$(basename "$remove_trash")" exit 0 ;; *) say_color error "# failed $test_failure among $msg" say "1..$test_count" exit 1 ;; esac } # Public: Root directory containing tests. Tests can override this variable, # e.g. for testing Sharness itself. : ${SHARNESS_TEST_DIRECTORY:=$(pwd)} export SHARNESS_TEST_DIRECTORY # Public: Source directory of test code and sharness library. # This directory may be different from the directory in which tests are # being run. : ${SHARNESS_TEST_SRCDIR:=$(cd $(dirname $0) && pwd)} export SHARNESS_TEST_SRCDIR # Public: Build directory that will be added to PATH. By default, it is set to # the parent directory of SHARNESS_TEST_DIRECTORY. : ${SHARNESS_BUILD_DIRECTORY:="$SHARNESS_TEST_DIRECTORY/.."} PATH="$SHARNESS_BUILD_DIRECTORY:$PATH" export PATH SHARNESS_BUILD_DIRECTORY # Public: Path to test script currently executed. SHARNESS_TEST_FILE="$0" export SHARNESS_TEST_FILE # Prepare test area. SHARNESS_TRASH_DIRECTORY="trash directory.$(basename "$SHARNESS_TEST_FILE" ".$SHARNESS_TEST_EXTENSION")" test -n "$root" && SHARNESS_TRASH_DIRECTORY="$root/$SHARNESS_TRASH_DIRECTORY" case "$SHARNESS_TRASH_DIRECTORY" in /*) ;; # absolute path is good *) SHARNESS_TRASH_DIRECTORY="$SHARNESS_TEST_DIRECTORY/$SHARNESS_TRASH_DIRECTORY" ;; esac test "$debug" = "t" || remove_trash="$SHARNESS_TRASH_DIRECTORY" rm -rf "$SHARNESS_TRASH_DIRECTORY" || { EXIT_OK=t echo >&5 "FATAL: Cannot prepare test area" exit 1 } # # Load any extensions in $srcdir/sharness.d/*.sh # if test -d "${SHARNESS_TEST_SRCDIR}/sharness.d" then for file in "${SHARNESS_TEST_SRCDIR}"/sharness.d/*.sh do # Ensure glob was not an empty match: test -e "${file}" || break if test -n "$debug" then echo >&5 "sharness: loading extensions from ${file}" fi . "${file}" if test $? != 0 then echo >&5 "sharness: Error loading ${file}. Aborting." exit 1 fi done fi # Public: Empty trash directory, the test area, provided for each test. The HOME # variable is set to that directory too. export SHARNESS_TRASH_DIRECTORY HOME="$SHARNESS_TRASH_DIRECTORY" export HOME mkdir -p "$SHARNESS_TRASH_DIRECTORY" || exit 1 # Use -P to resolve symlinks in our working directory so that the cwd # in subprocesses like git equals our $PWD (for pathname comparisons). cd -P "$SHARNESS_TRASH_DIRECTORY" || exit 1 this_test=${SHARNESS_TEST_FILE##*/} this_test=${this_test%.$SHARNESS_TEST_EXTENSION} for skp in $SKIP_TESTS; do case "$this_test" in $skp) say_color info >&3 "skipping test $this_test altogether" skip_all="skip all tests in $this_test" test_done esac done test -n "$TEST_LONG" && test_set_prereq EXPENSIVE test -n "$TEST_INTERACTIVE" && test_set_prereq INTERACTIVE # Make sure this script ends with code 0 : # vi: set ts=4 sw=4 noet : pass-otp-1.2.0/test/uri.t000077500000000000000000000012141337335211000152220ustar00rootroot00000000000000#!/usr/bin/env bash export test_description='Tests pass otp URI parsing' . ./setup.sh test_expect_success 'Shows key URI in single-line passfile' ' uri="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example" test_pass_init && "$PASS" otp insert passfile <<< "$uri" && [[ $("$PASS" otp uri passfile) == "$uri" ]] ' test_expect_success 'Shows key URI in multi-line passfile' ' uri="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example" test_pass_init && "$PASS" insert -m passfile < <(echo -e "password\nfoo\n$uri\nbar") && [[ $("$PASS" otp uri passfile) == "$uri" ]] ' test_done pass-otp-1.2.0/test/validate.t000077500000000000000000000020611337335211000162150ustar00rootroot00000000000000#!/usr/bin/env bash export test_description='Tests pass otp URI parsing' . ./setup.sh test_expect_success 'Parses a basic TOTP URI' ' "$PASS" otp validate "otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example" ' test_expect_success 'Parses a complex TOTP URI' ' "$PASS" otp validate otpauth://totp/ACME%20Co:john.doe@email.com?secret=HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ&issuer=ACME%20Co&algorithm=SHA1&digits=6&period=30 ' test_expect_success 'Parses a basic HOTP URI' ' "$PASS" otp validate "otpauth://hotp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&counter=10&issuer=Example" ' test_expect_success 'Fails for bogus URL' ' test_must_fail "$PASS" otp validate https://www.google.com/ ' test_expect_success 'Fails for missing secret' ' test_must_fail "$PASS" otp validate otpauth://totp/ACME%20Co:john.doe@email.com?issuer=ACME%20Co&algorithm=SHA1&digits=6&period=30 ' test_expect_success 'Fails for missing counter' ' test_must_fail "$PASS" otp validate otpauth://hotp?secret=HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ ' test_done