Compare commits

..

No commits in common. "master" and "v4.0.0-beta" have entirely different histories.

54 changed files with 2620 additions and 3399 deletions

View file

@ -1,32 +0,0 @@
#!/bin/bash
ruby_version=${1:-2.4.2}
if ! rvm use ruby-${ruby_version} &>/dev/null ; then
echo "The ruby version '${ruby_version}' doesn't exist!"
echo "Available versions are:"
rvm list rubies strings | cut -d '-' -f2
exit 2
fi
echo '# ---------------------------------'
echo "# Use ruby version: ${ruby_version}"
echo '# ---------------------------------'
cp -r /mpw ~/mpw
cd ~/mpw
gem install bundler --no-ri --no-rdoc
bundle install
gem build mpw.gemspec
gem install mpw-$(cat VERSION).gem
cp -a /dev/urandom /dev/random
rubocop
ruby ./test/init.rb
ruby ./test/test_config.rb
ruby ./test/test_item.rb
ruby ./test/test_mpw.rb
ruby ./test/test_translate.rb
ruby ./test/init.rb
ruby ./test/test_cli.rb
ruby ./test/test_import.rb

3
.gitignore vendored
View file

@ -1,4 +1 @@
Gemfile.lock Gemfile.lock
*.gem
.yardoc
doc

View file

@ -1,38 +0,0 @@
AllCops:
Exclude:
- db/**/*
- config/**/*
- Vagrantfile
TargetRubyVersion: 2.3
Naming/AccessorMethodName:
Enabled: false
Lint/RescueWithoutErrorClass:
Enabled: false
Metrics/LineLength:
Max: 120
Metrics/CyclomaticComplexity:
Enabled: false
Metrics/PerceivedComplexity:
Enabled: false
Metrics/MethodLength:
Enabled: false
Metrics/BlockLength:
Enabled: false
Metrics/ClassLength:
Enabled: false
Metrics/AbcSize:
Enabled: false
Style/NumericLiteralPrefix:
Enabled: false
Style/FrozenStringLiteralComment:
Enabled: false
Style/CommandLiteral:
Enabled: true
EnforcedStyle: percent_x
Style/Documentation:
Enabled: false

View file

@ -1,23 +1,13 @@
language: ruby language: ruby
dist: precise
rvm: rvm:
- 2.4.2 - 2.3.1
- 2.3.5 - 2.2.5
- 2.2.8
- 2.1.10 - 2.1.10
install: install:
- sudo cp -a /dev/urandom /dev/random
- sudo apt-get purge -y gnupg-agent gnupg2
- bundle install - bundle install
- gem install 'test-unit'
- echo 9999 > VERSION
- gem build mpw.gemspec - gem build mpw.gemspec
- gem install mpw-$(cat VERSION).gem - gem install mpw-9999.gem
script: script:
- rubocop - ruby ./test/tests.rb
- ruby ./test/init.rb
- ruby ./test/test_config.rb
- ruby ./test/test_item.rb
- ruby ./test/test_mpw.rb
- ruby ./test/test_translate.rb
- ruby ./test/init.rb
- ruby ./test/test_cli.rb
- ruby ./test/test_import.rb

43
CHANGELOG Normal file
View file

@ -0,0 +1,43 @@
= CHANGELOG =
== v4.0.0 (beta) ==
* new interface with a table
* new command line interface
* use text editor for add or update an item
* several bugs fix
== v3.2.1 ==
* fix bug when add a new item
== v3.2.0 ==
* add support OTP
* fix bug in synchronize
* improve interface
== v3.1.0 ==
* add clipboard
* can change gpg version
* minor change in interface
* several bugs fix
== v3.0.0 ==
* new storage format
* new share system
* remove MPW server
== v2.0.0 ==
* change format csv to yaml
* easy install with gem
* add sync with ftp and ssh
* many improvement
== v1.1.0 ==
* Add sync with MPW Server
* Add MPW Server
* Fix minors bugs

View file

@ -1,98 +0,0 @@
# CHANGELOG
## v4.2.2 (2017-08-15)
* minor improvements in the interface
## v4.2.1 (2017-07-30)
* fix bug in otp generator
## v4.2.0 (2017-06-06)
* feat: improve the interface
* feat: add copy url
* feat: add unit tests for cli
* feat: comment the code with yarn syntax
* fix several bugs
* fix translations
## v4.1.1 (2017-05-03)
* fix bug in init
## v4.1.0 (2017-04-22)
* feat: add options to update or add an item in command line
* feat: print config
* feat: add a specific path for a wallet
* feat: add rubocop to fix syntax
* fix: pinentry mode with gpg >= 2.1
* remove SSH and FTP synchronization
## v4.0.0 (2017-03-09)
* feature: set default wallet
* add option for generate a random password when you update an item
* fix encryption when you share an existing wallet
* several bugs fix
## v4.0.0-beta1 (2017-02-16)
* add manage share key with new interface
## v4.0.0-beta (2016-11-11)
* new interface with a table
* new command line interface
* use text editor for add or update an item
* fix generate gpg key with RSA
* several bugs fix
* add unit tests
## v3.2.1 (2016-08-06)
* fix bug when add a new item
## v3.2.0 (2016-08-03)
* add support OTP
* fix bug in synchronize
* improve interface
## v3.1.0 (2016-07-09)
* add clipboard
* can change gpg version
* minor change in interface
* several bugs fix
## v3.0.0 (2016-07-05)
* new storage format
* new share system
* remove MPW server
## v2.0.3 (2015-09-27)
* add no-sync option
## v2.0.1 (2015-06-23)
* fix mpw-ssh
## v2.0.0 (2015-06-22)
* change format csv to yaml
* easy install with gem
* add sync with ftp and ssh
* many improvement
## v1.1.0 (2014-01-28)
* Add sync with MPW Server
* Add MPW Server
* Fix minors bugs
## v1.0.0 (2014-01-15)
* first release

View file

@ -1,16 +0,0 @@
FROM debian:stretch
MAINTAINER Adrien Waksberg "mpw@yae.im"
RUN apt update
RUN apt dist-upgrade -y
RUN apt install -y procps gnupg1 curl git
RUN ln -snvf /usr/bin/gpg1 /usr/bin/gpg
RUN gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
RUN curl -sSL https://get.rvm.io | bash -s stable
RUN echo 'source "/usr/local/rvm/scripts/rvm"' >> /etc/bash.bashrc
RUN /bin/bash -l -c "rvm install 2.4.2"
RUN /bin/bash -l -c "rvm install 2.3.5"
RUN /bin/bash -l -c "rvm install 2.2.8"
RUN /bin/bash -l -c "rvm install 2.1.10"

22
Gemfile
View file

@ -1,14 +1,10 @@
source 'https://rubygems.org' source 'https://rubygems.org'
gem 'clipboard', '~> 1.1', '>= 1.1.1' gem "i18n", "~> 0.7", ">= 0.7.0"
gem 'colorize', '~> 0.8', '>= 0.8.1' gem "gpgme", "~> 2.0", ">= 2.0.12"
gem 'gpgme', '~> 2.0', '>= 2.0.14' gem "highline", "~> 1.7", ">= 1.7.8"
gem 'highline', '~> 1.7', '>= 1.7.8' gem "locale", "~> 2.1", ">= 2.1.2"
gem 'i18n', '~> 0.9', '>= 0.9.1' gem "colorize", "~> 0.8", ">= 0.8.1"
gem 'locale', '~> 2.1', '>= 2.1.2' gem "net-ssh", "~> 3.2", ">= 3.2.0"
gem 'rotp', '~> 3.3', '>= 3.3.0' gem "net-sftp", "~> 2.1", ">= 2.1.2"
gem "clipboard", "~> 1.1", ">= 1.1.1"
group :development do gem "rotp", "~> 3.1", ">= 3.1.0"
gem 'rubocop', '0.50.0'
gem 'test-unit'
gem 'yard'
end

474
LICENSE
View file

@ -1,201 +1,339 @@
Apache License GNU GENERAL PUBLIC LICENSE
Version 2.0, January 2004 Version 2, June 1991
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
1. Definitions. Preamble
"License" shall mean the terms and conditions for use, reproduction, The licenses for most software are designed to take away your
and distribution as defined by Sections 1 through 9 of this document. freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
"Licensor" shall mean the copyright owner or entity authorized by When we speak of free software, we are referring to freedom, not
the copyright owner that is granting the License. price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service 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.
"Legal Entity" shall mean the union of the acting entity and all To protect your rights, we need to make restrictions that forbid
other entities that control, are controlled by, or are under common anyone to deny you these rights or to ask you to surrender the rights.
control with that entity. For the purposes of this definition, These restrictions translate to certain responsibilities for you if you
"control" means (i) the power, direct or indirect, to cause the distribute copies of the software, or if you modify it.
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity For example, if you distribute copies of such a program, whether
exercising permissions granted by this License. gratis or for a fee, you must give the recipients all the rights that
you have. 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.
"Source" form shall mean the preferred form for making modifications, We protect your rights with two steps: (1) copyright the software, and
including but not limited to software source code, documentation (2) offer you this license which gives you legal permission to copy,
source, and configuration files. distribute and/or modify the software.
"Object" form shall mean any form resulting from mechanical Also, for each author's protection and ours, we want to make certain
transformation or translation of a Source form, including but that everyone understands that there is no warranty for this free
not limited to compiled object code, generated documentation, software. If the software is modified by someone else and passed on, we
and conversions to other media types. want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
"Work" shall mean the work of authorship, whether in Source or Finally, any free program is threatened constantly by software
Object form, made available under the License, as indicated by a patents. We wish to avoid the danger that redistributors of a free
copyright notice that is included in or attached to the work program will individually obtain patent licenses, in effect making the
(an example is provided in the Appendix below). program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
"Derivative Works" shall mean any work, whether in Source or Object The precise terms and conditions for copying, distribution and
form, that is based on (or derived from) the Work and for which the modification follow.
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including GNU GENERAL PUBLIC LICENSE
the original version of the Work and any modifications or additions TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity 0. This License applies to any program or other work which contains
on behalf of whom a Contribution has been received by Licensor and a notice placed by the copyright holder saying it may be distributed
subsequently incorporated within the Work. under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
2. Grant of Copyright License. Subject to the terms and conditions of Activities other than copying, distribution and modification are not
this License, each Contributor hereby grants to You a perpetual, covered by this License; they are outside its scope. The act of
worldwide, non-exclusive, no-charge, royalty-free, irrevocable running the Program is not restricted, and the output from the Program
copyright license to reproduce, prepare Derivative Works of, is covered only if its contents constitute a work based on the
publicly display, publicly perform, sublicense, and distribute the Program (independent of having been made by running the Program).
Work and such Derivative Works in Source or Object form. Whether that is true depends on what the Program does.
3. Grant of Patent License. Subject to the terms and conditions of 1. You may copy and distribute verbatim copies of the Program's
this License, each Contributor hereby grants to You a perpetual, source code as you receive it, in any medium, provided that you
worldwide, non-exclusive, no-charge, royalty-free, irrevocable conspicuously and appropriately publish on each copy an appropriate
(except as stated in this section) patent license to make, have made, copyright notice and disclaimer of warranty; keep intact all the
use, offer to sell, sell, import, and otherwise transfer the Work, notices that refer to this License and to the absence of any warranty;
where such license applies only to those patent claims licensable and give any other recipients of the Program a copy of this License
by such Contributor that are necessarily infringed by their along with the Program.
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the You may charge a fee for the physical act of transferring a copy, and
Work or Derivative Works thereof in any medium, with or without you may at your option offer warranty protection in exchange for a fee.
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or 2. You may modify your copy or copies of the Program or any portion
Derivative Works a copy of this License; and of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
(b) You must cause any modified files to carry prominent notices a) You must cause the modified files to carry prominent notices
stating that You changed the files; and stating that you changed the files and the date of any change.
(c) You must retain, in the Source form of any Derivative Works b) You must cause any work that you distribute or publish, that in
that You distribute, all copyright, patent, trademark, and whole or in part contains or is derived from the Program or any
attribution notices from the Source form of the Work, part thereof, to be licensed as a whole at no charge to all third
excluding those notices that do not pertain to any part of parties under the terms of this License.
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its c) If the modified program normally reads commands interactively
distribution, then any Derivative Works that You distribute must when run, you must cause it, when started running for such
include a readable copy of the attribution notices contained interactive use in the most ordinary way, to print or display an
within such NOTICE file, excluding those notices that do not announcement including an appropriate copyright notice and a
pertain to any part of the Derivative Works, in at least one notice that there is no warranty (or else, saying that you provide
of the following places: within a NOTICE text file distributed a warranty) and that users may redistribute the program under
as part of the Derivative Works; within the Source form or these conditions, and telling the user how to view a copy of this
documentation, if provided along with the Derivative Works; or, License. (Exception: if the Program itself is interactive but
within a display generated by the Derivative Works, if and does not normally print such an announcement, your work based on
wherever such third-party notices normally appear. The contents the Program is not required to print an announcement.)
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and These requirements apply to the modified work as a whole. If
may provide additional or different license terms and conditions identifiable sections of that work are not derived from the Program,
for use, reproduction, or distribution of Your modifications, or and can be reasonably considered independent and separate works in
for any such Derivative Works as a whole, provided Your use, themselves, then this License, and its terms, do not apply to those
reproduction, and distribution of the Work otherwise complies with sections when you distribute them as separate works. But when you
the conditions stated in this License. distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
5. Submission of Contributions. Unless You explicitly state otherwise, Thus, it is not the intent of this section to claim rights or contest
any Contribution intentionally submitted for inclusion in the Work your rights to work written entirely by you; rather, the intent is to
by You to the Licensor shall be under the terms and conditions of exercise the right to control the distribution of derivative or
this License, without any additional terms or conditions. collective works based on the Program.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade In addition, mere aggregation of another work not based on the Program
names, trademarks, service marks, or product names of the Licensor, with the Program (or with a work based on the Program) on a volume of
except as required for reasonable and customary use in describing the a storage or distribution medium does not bring the other work under
origin of the Work and reproducing the content of the NOTICE file. the scope of this License.
7. Disclaimer of Warranty. Unless required by applicable law or 3. You may copy and distribute the Program (or a work based on it,
agreed to in writing, Licensor provides the Work (and each under Section 2) in object code or executable form under the terms of
Contributor provides its Contributions) on an "AS IS" BASIS, Sections 1 and 2 above provided that you also do one of the following:
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory, a) Accompany it with the complete corresponding machine-readable
whether in tort (including negligence), contract, or otherwise, source code, which must be distributed under the terms of Sections
unless required by applicable law (such as deliberate and grossly 1 and 2 above on a medium customarily used for software interchange; or,
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing b) Accompany it with a written offer, valid for at least three
the Work or Derivative Works thereof, You may choose to offer, years, to give any third party, for a charge no more than your
and charge a fee for, acceptance of support, warranty, indemnity, cost of physically performing source distribution, a complete
or other liability obligations and/or rights consistent with this machine-readable copy of the corresponding source code, to be
License. However, in accepting such obligations, You may act only distributed under the terms of Sections 1 and 2 above on a medium
on Your own behalf and on Your sole responsibility, not on behalf customarily used for software interchange; or,
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability c) Accompany it with the information you received as to the offer
incurred by, or claims asserted against, such Contributor by reason to distribute corresponding source code. (This alternative is
of your accepting any such warranty or additional liability. allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
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
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the 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 a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, 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.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE 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.
END OF TERMS AND CONDITIONS END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work. How to Apply These Terms to Your New Programs
To apply the Apache License to your work, attach the following If you develop a new program, and you want it to be of the greatest
boilerplate notice, with the fields enclosed by brackets "{}" possible use to the public, the best way to achieve this is to make it
replaced with your own identifying information. (Don't include free software which everyone can redistribute and change under these terms.
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2017 Adrien Waksberg 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
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
Licensed under the Apache License, Version 2.0 (the "License"); <one line to give the program's name and a brief idea of what it does.>
you may not use this file except in compliance with the License. Copyright (C) <year> <name of author>
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 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.
Unless required by applicable law or agreed to in writing, software This program is distributed in the hope that it will be useful,
distributed under the License is distributed on an "AS IS" BASIS, but WITHOUT ANY WARRANTY; without even the implied warranty of
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
See the License for the specific language governing permissions and GNU General Public License for more details.
limitations under the License.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision 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, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This 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.

195
README.md
View file

@ -1,195 +0,0 @@
# MPW: Manage your passwords!
[![Version](https://img.shields.io/badge/latest_version-4.2.2-green.svg)](https://github.com/nishiki/manage-password/releases)
[![Build Status](https://travis-ci.org/nishiki/manage-password.svg?branch=master)](https://travis-ci.org/nishiki/manage-password)
[![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](https://github.com/nishiki/manage-password/blob/master/LICENSE)
mpw is a little software which stores your passwords in [GnuPG](http://www.gnupg.org/) encrypted files.
## Features
* generate random password
* generate OTP code
* copy your login, password or otp in clipboard
* manage many wallets
* share a wallet with others GPG keys
## Install
On debian or ubuntu:
```
apt install ruby ruby-dev xclip
gem install mpw
```
## How to use
### First steps
Initialize your first wallet:
```
mpw config --init user@host.com
```
Add your first item:
```
mpw add --host assurance.com --port 443 --user user_2132 --protocol https --random
mpw add --host fric.com --user 230403 --otp-code 23434113 --protocol https --comment 'I love my bank' --random
```
And list your items:
```
mpw list
```
or search an item with
```
mpw list --pattern love
mpw list --group bank
```
Output:
```
Assurance
==========================================================================
ID | Host | User | OTP | Comment
==========================================================================
1 | https://assurance.com:443 | user_2132 | |
Bank
==========================================================================
ID | Host | User | OTP | Comment
==========================================================================
3 | https://fric.com | 230403 | X | I love my bank
```
Copy a password, login or OTP code:
```
mpw copy -p assurance.com
```
Update an item:
```
mpw update -p assurance.com
```
Delete an item:
```
mpw delete -p assurance.com
```
### Manage wallets
List all available wallets:
```
mpw wallet
```
List all GPG keys in wallet:
```
mpw wallet --list-keys [--wallet NAME]
```
Share with an other GPG key:
```
mpw wallet --add-gpg-key test42@localhost.com
or
mpw wallet --add-gpg-key /path/to/file
```
Remove a GPG key:
```
mpw wallet --delete-gpg-key test42@localhost.com
```
### Export and import data
You can export your data in yaml file with your passwords in clear text:
```
mpw export --file export.yml
```
Import data from an yaml file:
```
mpw import --file import.yml
```
Example yaml file for mpw:
```
---
1:
host: fric.com
user: 230403
group: Bank
password: 5XdiTQOubRDw9B0aJoMlcEyL
protocol: https
port:
otp_key: 330223432
comment: I love my bank
2:
host: assurance.com
user: user_2132
group: Assurance
password: DMyK6B3v4bWO52VzU7aTHIem
protocol: https
port: 443
otp_key:
comment:
```
### Config
Print the current config
```
mpw config
```
Output:
```
Configuration
==============================================
lang | fr
gpg_key | mpw@yae.im
default_wallet |
config_dir | /home/mpw/.config/mpw
pinmode | true
gpg_exe |
path_wallet_test | /tmp/test.mpw
password_numeric | true
password_alpha | true
password_special | false
password_length | 16
```
## Development
Don't run the tests on your local machine, you risk to lost your datas.
### Test on local machine with docker
* install [docker](https://docs.docker.com/engine/installation/)
* run the tests
```
docker run -v $(pwd):/mpw:ro -it nishiki/ruby:stretch /bin/bash -l /mpw/.docker-test
```
## License
```
* Author:: Adrien Waksberg <mpw@yae.im>
Copyright (c) 2013-2017 Adrien Waksberg
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```

54
README.rst Normal file
View file

@ -0,0 +1,54 @@
MPW: Manage your passwords!
*******************************************************
|Version| |Build Status| |License|
mpw is a little software which stores your passwords in `GnuPG <http://www.gnupg.org/>`_ encrypted files.
Features
========
* generate OTP code
* synchronize your passwords with SSH or FTP.
* copy your login, password or otp in clipboard
Install
=======
On debian or ubuntu::
apt install ruby ruby-dev xclip
gem install mpw
How to use
==========
A simple mpw usage::
mpw config --init user@host.com
mpw add
mpw copy
mpw add
mpw list
Output::
Bank
==============================================================================
ID | Host | User | Protocol | Port | OTP | Comment
==============================================================================
1 | bank.com | 1234456 | https | | X |
Linux
==============================================================================
ID | Host | User | Protocol | Port | OTP | Comment
==============================================================================
2 | linuxfr.org | example | https | | | Da Linux French Site
.. |Version| image:: https://img.shields.io/badge/latest_version-4.0.0--beta-yellow.svg
:target: https://github.com/nishiki/manage-password/releases
.. |License| image:: https://img.shields.io/badge/license-GPL--2.0-blue.svg
:target: https://github.com/nishiki/manage-password/blob/master/LICENSE
.. |Build Status| image:: https://travis-ci.org/nishiki/manage-password.svg?branch=master
:target: https://travis-ci.org/nishiki/manage-password

View file

@ -1 +1 @@
4.2.2 4.0.0-beta

40
bin/mpw
View file

@ -1,30 +1,26 @@
#!/usr/bin/env ruby #!/usr/bin/ruby
# MPW is a software to crypt and manage your passwords
# Copyright (C) 2016 Adrien Waksberg <mpw@yae.im>
# #
# Copyright:: 2013, Adrien Waksberg # 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.
# #
# Licensed to the Apache Software Foundation (ASF) under one # This program is distributed in the hope that it will be useful,
# or more contributor license agreements. See the NOTICE file # but WITHOUT ANY WARRANTY; without even the implied warranty of
# distributed with this work for additional information # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# regarding copyright ownership. The ASF licenses this file # GNU General Public License for more details.
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # You should have received a copy of the GNU General Public License
# # along with this program; if not, write to the Free Software
# Unless required by applicable law or agreed to in writing, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
$LOAD_PATH << File.expand_path('../../lib', __FILE__) $: << File.expand_path('../../lib', __FILE__)
require 'locale' require 'locale'
require 'set' require 'set'
require 'i18n' require 'i18n'
require 'colorize'
# --------------------------------------------------------- # # --------------------------------------------------------- #
# Set local # Set local
@ -48,12 +44,8 @@ I18n.locale = lang.to_sym
bin_dir = File.dirname(__FILE__) bin_dir = File.dirname(__FILE__)
command = "#{bin_dir}/mpw-#{ARGV[0]}" command = "#{bin_dir}/mpw-#{ARGV[0]}"
if Dir.glob("#{bin_dir}/mpw-*").include?(command.to_s) if Dir.glob("#{bin_dir}/mpw-*").include?("#{command}")
begin
Kernel.load(command) Kernel.load(command)
rescue OptionParser::ParseError => e
puts "#{I18n.t('display.error')}: #{e}".red
end
else else
puts "#{I18n.t('option.usage')}: mpw COMMAND [options]\n\n" puts "#{I18n.t('option.usage')}: mpw COMMAND [options]\n\n"
puts 'Commands:' puts 'Commands:'

View file

@ -1,22 +1,20 @@
#!/usr/bin/ruby
# MPW is a software to crypt and manage your passwords
# Copyright (C) 2016 Adrien Waksberg <mpw@yae.im>
# #
# Copyright:: 2013, Adrien Waksberg # 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.
# #
# Licensed to the Apache Software Foundation (ASF) under one # This program is distributed in the hope that it will be useful,
# or more contributor license agreements. See the NOTICE file # but WITHOUT ANY WARRANTY; without even the implied warranty of
# distributed with this work for additional information # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# regarding copyright ownership. The ASF licenses this file # GNU General Public License for more details.
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # You should have received a copy of the GNU General Public License
# # along with this program; if not, write to the Free Software
# Unless required by applicable law or agreed to in writing, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
require 'optparse' require 'optparse'
require 'mpw/config' require 'mpw/config'
@ -26,9 +24,8 @@ require 'mpw/cli'
# Options # Options
# --------------------------------------------------------- # # --------------------------------------------------------- #
values = {}
options = {} options = {}
options[:text_editor] = true options[:sync] = true
OptionParser.new do |opts| OptionParser.new do |opts|
opts.banner = "#{I18n.t('option.usage')}: mpw add [options]" opts.banner = "#{I18n.t('option.usage')}: mpw add [options]"
@ -37,48 +34,28 @@ OptionParser.new do |opts|
options[:config] = config options[:config] = config
end end
opts.on('-C', '--comment COMMENT', I18n.t('option.comment')) do |comment|
values[:comment] = comment
end
opts.on('-G', '--group NAME', I18n.t('option.new_group')) do |group|
values[:group] = group
end
opts.on('-h', '--help', I18n.t('option.help')) do opts.on('-h', '--help', I18n.t('option.help')) do
puts opts puts opts
exit 0 exit 0
end end
opts.on('-o', '--otp-code CODE', I18n.t('option.otp_code')) do |otp| opts.on('-n', '--no-sync', I18n.t('option.no_sync')) do
values[:otp_key] = otp options[:sync] = false
end end
opts.on('-r', '--random', I18n.t('option.random_password')) do opts.on('-r', '--random', I18n.t('option.random_password')) do
options[:password] = true options[:password] = true
end end
opts.on('-t', '--text-editor', I18n.t('option.text_editor')) do
options[:text_editor] = true
end
opts.on('-u', '--url URL', I18n.t('option.url')) do |url|
values[:url] = url
end
opts.on('-U', '--user USER', I18n.t('option.user')) do |user|
values[:user] = user
end
opts.on('-w', '--wallet NAME', I18n.t('option.wallet')) do |wallet| opts.on('-w', '--wallet NAME', I18n.t('option.wallet')) do |wallet|
options[:wallet] = wallet options[:wallet] = wallet
end end
end.parse! end.parse!
config = MPW::Config.new(options[:config]) config = MPW::Config.new(options[:config])
cli = MPW::Cli.new(config) cli = MPW::Cli.new(config, options[:sync])
cli.load_config cli.load_config
cli.get_wallet(options[:wallet]) cli.get_wallet(options[:wallet])
cli.decrypt cli.decrypt
cli.add(options[:password], options[:text_editor], values) cli.add(options[:password])

View file

@ -1,22 +1,20 @@
#!/usr/bin/ruby
# MPW is a software to crypt and manage your passwords
# Copyright (C) 2016 Adrien Waksberg <mpw@yae.im>
# #
# Copyright:: 2013, Adrien Waksberg # 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.
# #
# Licensed to the Apache Software Foundation (ASF) under one # This program is distributed in the hope that it will be useful,
# or more contributor license agreements. See the NOTICE file # but WITHOUT ANY WARRANTY; without even the implied warranty of
# distributed with this work for additional information # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# regarding copyright ownership. The ASF licenses this file # GNU General Public License for more details.
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # You should have received a copy of the GNU General Public License
# # along with this program; if not, write to the Free Software
# Unless required by applicable law or agreed to in writing, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
require 'optparse' require 'optparse'
require 'mpw/config' require 'mpw/config'
@ -36,10 +34,6 @@ OptionParser.new do |opts|
options[:config] = config options[:config] = config
end end
opts.on('-d', '--default-wallet NAME', I18n.t('option.default_wallet')) do |default_wallet|
values[:default_wallet] = default_wallet
end
opts.on('-g', '--gpg-exe PATH', I18n.t('option.gpg_exe')) do |gpg_exe| opts.on('-g', '--gpg-exe PATH', I18n.t('option.gpg_exe')) do |gpg_exe|
values[:gpg_exe] = gpg_exe values[:gpg_exe] = gpg_exe
end end
@ -58,64 +52,24 @@ OptionParser.new do |opts|
values[:gpg_key] = gpg_key values[:gpg_key] = gpg_key
end end
opts.on('-L', '--lang LANG', I18n.t('option.lang')) do |lang| opts.on('-l', '--lang LANG', I18n.t('option.lang')) do |lang|
values[:lang] = lang values[:lang] = lang
end end
opts.on('-P', '--enable-pinmode', I18n.t('option.pinmode')) do
values[:pinmode] = true
end
opts.on('-p', '--disable-pinmode', I18n.t('option.disable_pinmode')) do
values[:pinmode] = false
end
opts.on('-w', '--wallet-dir PATH', I18n.t('option.wallet_dir')) do |wallet_dir| opts.on('-w', '--wallet-dir PATH', I18n.t('option.wallet_dir')) do |wallet_dir|
values[:wallet_dir] = wallet_dir values[:wallet_dir] = wallet_dir
end end
opts.on('-l', '--length NUMBER', I18n.t('option.length')) do |length|
values[:pwd_length] = length.to_i
end
opts.on('-n', '--numeric', I18n.t('option.numeric')) do
values[:pwd_numeric] = true
end
opts.on('-N', '--disable-numeric', I18n.t('option.disable_numeric')) do
values[:pwd_numeric] = false
end
opts.on('-s', '--special-chars', I18n.t('option.special_chars')) do
values[:pwd_special] = true
end
opts.on('-S', '--disable-special-chars', I18n.t('option.special_chars')) do
values[:pwd_special] = false
end
opts.on('-a', '--alpha', I18n.t('option.alpha')) do
values[:pwd_alpha] = true
end
opts.on('-A', '--disable-alpha', I18n.t('option.disable_alpha')) do
values[:pwd_alpha] = false
end
end.parse! end.parse!
config = MPW::Config.new(options[:config]) config = MPW::Config.new(options[:config])
cli = MPW::Cli.new(config) cli = MPW::Cli.new(config, nil)
if options.key?(:init) if not options[:init].nil?
cli.setup(values) cli.setup(values)
cli.load_config cli.load_config
cli.get_wallet cli.get_wallet
cli.setup_gpg_key(values[:gpg_key]) cli.setup_gpg_key(options[:init])
cli.setup_wallet_config
else else
cli.load_config
if values.empty?
cli.list_config
else
cli.set_config(values) cli.set_config(values)
end
end end

View file

@ -1,22 +1,20 @@
#!/usr/bin/ruby
# MPW is a software to crypt and manage your passwords
# Copyright (C) 2016 Adrien Waksberg <mpw@yae.im>
# #
# Copyright:: 2013, Adrien Waksberg # 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.
# #
# Licensed to the Apache Software Foundation (ASF) under one # This program is distributed in the hope that it will be useful,
# or more contributor license agreements. See the NOTICE file # but WITHOUT ANY WARRANTY; without even the implied warranty of
# distributed with this work for additional information # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# regarding copyright ownership. The ASF licenses this file # GNU General Public License for more details.
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # You should have received a copy of the GNU General Public License
# # along with this program; if not, write to the Free Software
# Unless required by applicable law or agreed to in writing, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
require 'optparse' require 'optparse'
require 'mpw/config' require 'mpw/config'
@ -27,6 +25,7 @@ require 'mpw/cli'
# --------------------------------------------------------- # # --------------------------------------------------------- #
options = {} options = {}
options[:sync] = true
options[:clipboard] = true options[:clipboard] = true
values = {} values = {}
@ -50,6 +49,10 @@ OptionParser.new do |opts|
exit 0 exit 0
end end
opts.on('-n', '--no-sync', I18n.t('option.no_sync')) do
options[:sync] = false
end
opts.on('-p', '--pattern PATTERN', I18n.t('option.pattern')) do |pattern| opts.on('-p', '--pattern PATTERN', I18n.t('option.pattern')) do |pattern|
values[:pattern] = pattern values[:pattern] = pattern
end end
@ -60,7 +63,7 @@ OptionParser.new do |opts|
end.parse! end.parse!
config = MPW::Config.new(options[:config]) config = MPW::Config.new(options[:config])
cli = MPW::Cli.new(config) cli = MPW::Cli.new(config, options[:sync])
cli.load_config cli.load_config
cli.get_wallet(options[:wallet]) cli.get_wallet(options[:wallet])

View file

@ -1,22 +1,20 @@
#!/usr/bin/ruby
# MPW is a software to crypt and manage your passwords
# Copyright (C) 2016 Adrien Waksberg <mpw@yae.im>
# #
# Copyright:: 2013, Adrien Waksberg # 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.
# #
# Licensed to the Apache Software Foundation (ASF) under one # This program is distributed in the hope that it will be useful,
# or more contributor license agreements. See the NOTICE file # but WITHOUT ANY WARRANTY; without even the implied warranty of
# distributed with this work for additional information # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# regarding copyright ownership. The ASF licenses this file # GNU General Public License for more details.
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # You should have received a copy of the GNU General Public License
# # along with this program; if not, write to the Free Software
# Unless required by applicable law or agreed to in writing, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
require 'optparse' require 'optparse'
require 'mpw/config' require 'mpw/config'
@ -27,6 +25,7 @@ require 'mpw/cli'
# --------------------------------------------------------- # # --------------------------------------------------------- #
options = {} options = {}
options[:sync] = true
values = {} values = {}
OptionParser.new do |opts| OptionParser.new do |opts|
@ -45,6 +44,10 @@ OptionParser.new do |opts|
exit 0 exit 0
end end
opts.on('-n', '--no-sync', I18n.t('option.no_sync')) do
options[:sync] = false
end
opts.on('-p', '--pattern PATTERN', I18n.t('option.pattern')) do |pattern| opts.on('-p', '--pattern PATTERN', I18n.t('option.pattern')) do |pattern|
values[:pattern] = pattern values[:pattern] = pattern
end end
@ -55,7 +58,7 @@ OptionParser.new do |opts|
end.parse! end.parse!
config = MPW::Config.new(options[:config]) config = MPW::Config.new(options[:config])
cli = MPW::Cli.new(config) cli = MPW::Cli.new(config, options[:sync])
cli.load_config cli.load_config
cli.get_wallet(options[:wallet]) cli.get_wallet(options[:wallet])

View file

@ -1,19 +1,20 @@
# Licensed to the Apache Software Foundation (ASF) under one #!/usr/bin/ruby
# or more contributor license agreements. See the NOTICE file # MPW is a software to crypt and manage your passwords
# distributed with this work for additional information # Copyright (C) 2016 Adrien Waksberg <mpw@yae.im>
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # 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.
# #
# Unless required by applicable law or agreed to in writing, # This program is distributed in the hope that it will be useful,
# software distributed under the License is distributed on an # but WITHOUT ANY WARRANTY; without even the implied warranty of
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# KIND, either express or implied. See the License for the # GNU General Public License for more details.
# specific language governing permissions and limitations #
# under the License. # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require 'optparse' require 'optparse'
require 'mpw/config' require 'mpw/config'
@ -24,6 +25,7 @@ require 'mpw/cli'
# --------------------------------------------------------- # # --------------------------------------------------------- #
options = {} options = {}
options[:sync] = true
values = {} values = {}
OptionParser.new do |opts| OptionParser.new do |opts|
@ -46,6 +48,10 @@ OptionParser.new do |opts|
exit 0 exit 0
end end
opts.on('-n', '--no-sync', I18n.t('option.no_sync')) do
options[:sync] = false
end
opts.on('-p', '--pattern PATTERN', I18n.t('option.pattern')) do |pattern| opts.on('-p', '--pattern PATTERN', I18n.t('option.pattern')) do |pattern|
values[:pattern] = pattern values[:pattern] = pattern
end end
@ -56,7 +62,7 @@ OptionParser.new do |opts|
end.parse! end.parse!
config = MPW::Config.new(options[:config]) config = MPW::Config.new(options[:config])
cli = MPW::Cli.new(config) cli = MPW::Cli.new(config, options[:sync])
cli.load_config cli.load_config
cli.get_wallet(options[:wallet]) cli.get_wallet(options[:wallet])

View file

@ -1,19 +1,20 @@
# Licensed to the Apache Software Foundation (ASF) under one #!/usr/bin/ruby
# or more contributor license agreements. See the NOTICE file # MPW is a software to crypt and manage your passwords
# distributed with this work for additional information # Copyright (C) 2016 Adrien Waksberg <mpw@yae.im>
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # 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.
# #
# Unless required by applicable law or agreed to in writing, # This program is distributed in the hope that it will be useful,
# software distributed under the License is distributed on an # but WITHOUT ANY WARRANTY; without even the implied warranty of
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# KIND, either express or implied. See the License for the # GNU General Public License for more details.
# specific language governing permissions and limitations #
# under the License. # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require 'optparse' require 'optparse'
require 'mpw/mpw' require 'mpw/mpw'
@ -45,5 +46,5 @@ OptionParser.new do |opts|
end end
end.parse! end.parse!
puts MPW::MPW.password(options) puts MPW::MPW::password(options)
exit 0 exit 0

View file

@ -1,19 +1,20 @@
# Licensed to the Apache Software Foundation (ASF) under one #!/usr/bin/ruby
# or more contributor license agreements. See the NOTICE file # MPW is a software to crypt and manage your passwords
# distributed with this work for additional information # Copyright (C) 2016 Adrien Waksberg <mpw@yae.im>
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # 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.
# #
# Unless required by applicable law or agreed to in writing, # This program is distributed in the hope that it will be useful,
# software distributed under the License is distributed on an # but WITHOUT ANY WARRANTY; without even the implied warranty of
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# KIND, either express or implied. See the License for the # GNU General Public License for more details.
# specific language governing permissions and limitations #
# under the License. # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require 'optparse' require 'optparse'
require 'mpw/config' require 'mpw/config'
@ -23,13 +24,8 @@ require 'mpw/cli'
# Options # Options
# --------------------------------------------------------- # # --------------------------------------------------------- #
formats = options = {}
Dir["#{File.expand_path('../../lib/mpw/import', __FILE__)}/*.rb"] options[:sync] = true
.map { |v| File.basename(v, '.rb') }
.join(', ')
options = {
format: 'mpw'
}
OptionParser.new do |opts| OptionParser.new do |opts|
opts.banner = "#{I18n.t('option.usage')}: mpw import [options]" opts.banner = "#{I18n.t('option.usage')}: mpw import [options]"
@ -42,24 +38,24 @@ OptionParser.new do |opts|
options[:file] = file options[:file] = file
end end
opts.on('-F', '--format STRING', I18n.t('option.file_format', formats: formats)) do |format|
options[:format] = format
end
opts.on('-h', '--help', I18n.t('option.help')) do opts.on('-h', '--help', I18n.t('option.help')) do
puts opts puts opts
exit 0 exit 0
end end
opts.on('-n', '--no-sync', I18n.t('option.no_sync')) do
options[:sync] = false
end
opts.on('-w', '--wallet NAME', I18n.t('option.wallet')) do |wallet| opts.on('-w', '--wallet NAME', I18n.t('option.wallet')) do |wallet|
options[:wallet] = wallet options[:wallet] = wallet
end end
end.parse! end.parse!
config = MPW::Config.new(options[:config]) config = MPW::Config.new(options[:config])
cli = MPW::Cli.new(config) cli = MPW::Cli.new(config, options[:sync])
cli.load_config cli.load_config
cli.get_wallet(options[:wallet]) cli.get_wallet(options[:wallet])
cli.decrypt cli.decrypt
cli.import(options[:file], options[:format]) cli.import(options[:file])

View file

@ -1,19 +1,20 @@
# Licensed to the Apache Software Foundation (ASF) under one #!/usr/bin/ruby
# or more contributor license agreements. See the NOTICE file # MPW is a software to crypt and manage your passwords
# distributed with this work for additional information # Copyright (C) 2016 Adrien Waksberg <mpw@yae.im>
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # 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.
# #
# Unless required by applicable law or agreed to in writing, # This program is distributed in the hope that it will be useful,
# software distributed under the License is distributed on an # but WITHOUT ANY WARRANTY; without even the implied warranty of
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# KIND, either express or implied. See the License for the # GNU General Public License for more details.
# specific language governing permissions and limitations #
# under the License. # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require 'optparse' require 'optparse'
require 'mpw/config' require 'mpw/config'
@ -24,6 +25,7 @@ require 'mpw/cli'
# --------------------------------------------------------- # # --------------------------------------------------------- #
options = {} options = {}
options[:sync] = true
values = {} values = {}
OptionParser.new do |opts| OptionParser.new do |opts|
@ -46,13 +48,17 @@ OptionParser.new do |opts|
values[:pattern] = pattern values[:pattern] = pattern
end end
opts.on('-n', '--no-sync', I18n.t('option.no_sync')) do
options[:sync] = false
end
opts.on('-w', '--wallet NAME', I18n.t('option.wallet')) do |wallet| opts.on('-w', '--wallet NAME', I18n.t('option.wallet')) do |wallet|
options[:wallet] = wallet options[:wallet] = wallet
end end
end.parse! end.parse!
config = MPW::Config.new(options[:config]) config = MPW::Config.new(options[:config])
cli = MPW::Cli.new(config) cli = MPW::Cli.new(config, options[:sync])
cli.load_config cli.load_config
cli.get_wallet(options[:wallet]) cli.get_wallet(options[:wallet])

View file

@ -1,19 +1,20 @@
# Licensed to the Apache Software Foundation (ASF) under one #!/usr/bin/ruby
# or more contributor license agreements. See the NOTICE file # MPW is a software to crypt and manage your passwords
# distributed with this work for additional information # Copyright (C) 2016 Adrien Waksberg <mpw@yae.im>
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # 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.
# #
# Unless required by applicable law or agreed to in writing, # This program is distributed in the hope that it will be useful,
# software distributed under the License is distributed on an # but WITHOUT ANY WARRANTY; without even the implied warranty of
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# KIND, either express or implied. See the License for the # GNU General Public License for more details.
# specific language governing permissions and limitations #
# under the License. # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require 'optparse' require 'optparse'
require 'mpw/config' require 'mpw/config'
@ -23,10 +24,9 @@ require 'mpw/cli'
# Options # Options
# --------------------------------------------------------- # # --------------------------------------------------------- #
values = {}
search = {}
options = {} options = {}
options[:text_editor] = false options[:sync] = true
values = {}
OptionParser.new do |opts| OptionParser.new do |opts|
opts.banner = "#{I18n.t('option.usage')}: mpw update [options]" opts.banner = "#{I18n.t('option.usage')}: mpw update [options]"
@ -35,15 +35,7 @@ OptionParser.new do |opts|
options[:config] = config options[:config] = config
end end
opts.on('-C', '--comment COMMENT', I18n.t('option.comment')) do |comment|
values[:comment] = comment
end
opts.on('-g', '--group NAME', I18n.t('option.group')) do |group| opts.on('-g', '--group NAME', I18n.t('option.group')) do |group|
search[:group] = group
end
opts.on('-G', '--new-group NAME', I18n.t('option.new_group')) do |group|
values[:group] = group values[:group] = group
end end
@ -52,28 +44,12 @@ OptionParser.new do |opts|
exit 0 exit 0
end end
opts.on('-o', '--otp-code CODE', I18n.t('option.otp_code')) do |otp| opts.on('-n', '--no-sync', I18n.t('option.no_sync')) do
values[:otp_key] = otp options[:sync] = false
end end
opts.on('-p', '--pattern PATTERN', I18n.t('option.pattern')) do |pattern| opts.on('-p', '--pattern PATTERN', I18n.t('option.pattern')) do |pattern|
search[:pattern] = pattern values[:pattern] = pattern
end
opts.on('-r', '--random', I18n.t('option.random_password')) do
options[:password] = true
end
opts.on('-t', '--text-editor', I18n.t('option.text_editor')) do
options[:text_editor] = true
end
opts.on('-u', '--url URL', I18n.t('option.url')) do |url|
values[:url] = url
end
opts.on('-U', '--user USER', I18n.t('option.user')) do |user|
values[:user] = user
end end
opts.on('-w', '--wallet NAME', I18n.t('option.wallet')) do |wallet| opts.on('-w', '--wallet NAME', I18n.t('option.wallet')) do |wallet|
@ -82,11 +58,9 @@ OptionParser.new do |opts|
end.parse! end.parse!
config = MPW::Config.new(options[:config]) config = MPW::Config.new(options[:config])
cli = MPW::Cli.new(config) cli = MPW::Cli.new(config, options[:sync])
options[:text_editor] = true if values.empty?
cli.load_config cli.load_config
cli.get_wallet(options[:wallet]) cli.get_wallet(options[:wallet])
cli.decrypt cli.decrypt
cli.update(options[:password], options[:text_editor], search, values) cli.update(values)

View file

@ -1,19 +1,20 @@
# Licensed to the Apache Software Foundation (ASF) under one #!/usr/bin/ruby
# or more contributor license agreements. See the NOTICE file # MPW is a software to crypt and manage your passwords
# distributed with this work for additional information # Copyright (C) 2016 Adrien Waksberg <mpw@yae.im>
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # 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.
# #
# Unless required by applicable law or agreed to in writing, # This program is distributed in the hope that it will be useful,
# software distributed under the License is distributed on an # but WITHOUT ANY WARRANTY; without even the implied warranty of
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# KIND, either express or implied. See the License for the # GNU General Public License for more details.
# specific language governing permissions and limitations #
# under the License. # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require 'optparse' require 'optparse'
require 'mpw/config' require 'mpw/config'
@ -24,43 +25,51 @@ require 'mpw/cli'
# --------------------------------------------------------- # # --------------------------------------------------------- #
options = {} options = {}
options[:delete] = false options[:sync] = {}
values = {}
OptionParser.new do |opts| OptionParser.new do |opts|
opts.banner = "#{I18n.t('option.usage')}: mpw wallet [options]" opts.banner = "#{I18n.t('option.usage')}: mpw wallet [options]"
opts.on('-a', '--add-gpg-key NAME', I18n.t('option.add_gpg_key')) do |gpg_key|
options[:gpg_key] = gpg_key
end
opts.on('-c', '--config PATH', I18n.t('option.config')) do |config| opts.on('-c', '--config PATH', I18n.t('option.config')) do |config|
options[:config] = config options[:config] = config
end end
opts.on('-d', '--delete-gpg-key NAME', I18n.t('option.delete_gpg_key')) do |gpg_key|
options[:gpg_key] = gpg_key
options[:delete] = true
end
opts.on('-h', '--help', I18n.t('option.help')) do opts.on('-h', '--help', I18n.t('option.help')) do
puts opts puts opts
exit 0 exit 0
end end
opts.on('-l', '--list', I18n.t('option.list')) do opts.on('--host NAME', I18n.t('option.host')) do |host|
values[:host] = host
end
opts.on('-l', '--list', I18n.t('option.list')) do |list|
options[:list] = true options[:list] = true
end end
opts.on('-L', '--list-keys', I18n.t('option.list_keys')) do opts.on('-n', '--no-sync', I18n.t('option.no_sync')) do
options[:list_keys] = true options[:sync] = false
end end
opts.on('-p', '--path PATH', I18n.t('option.path')) do |path| opts.on('--password', I18n.t('option.password')) do
options[:path] = path values[:password] = true
end end
opts.on('-P', '--default-path', I18n.t('option.default_path')) do opts.on('--path PATH', I18n.t('option.path')) do |path|
options[:path] = 'default' values[:path] = path
end
opts.on('--port NUMBER', I18n.t('option.port')) do |port|
values[:port] = port
end
opts.on('--protocol NAME', I18n.t('option.protocol')) do |protocol|
values[:protocol] = protocol
end
opts.on('--user NAME', I18n.t('option.user')) do |user|
values[:user] = user
end end
opts.on('-w', '--wallet NAME', I18n.t('option.wallet')) do |wallet| opts.on('-w', '--wallet NAME', I18n.t('option.wallet')) do |wallet|
@ -69,22 +78,14 @@ OptionParser.new do |opts|
end.parse! end.parse!
config = MPW::Config.new(options[:config]) config = MPW::Config.new(options[:config])
cli = MPW::Cli.new(config) cli = MPW::Cli.new(config, options[:sync])
cli.load_config cli.load_config
if options.key?(:path) if not options[:list].nil?
cli.get_wallet(options[:wallet]) cli.list_wallet
cli.set_wallet_path(options[:path]) else
elsif options.key?(:list_keys) || options.key?(:gpg_key)
cli.get_wallet(options[:wallet]) cli.get_wallet(options[:wallet])
cli.decrypt cli.decrypt
cli.setup_wallet_config(values)
if options.key?(:list_keys)
cli.list_keys
elsif options.key?(:gpg_key)
options[:delete] ? cli.delete_key(options[:gpg_key]) : cli.add_key(options[:gpg_key])
end
else
cli.list_wallet
end end

View file

@ -1,31 +1,37 @@
--- ---
en: en:
error: error:
bad_class: "The object class isn't valid!"
config: config:
write: "Can't write the config file!" write: "Can't write the config file!"
load: "Checkconfig failed!" load: "Checkconfig failed!"
key_bad_format: "The key string isn't in the right format!" key_bad_format: "The key string isn't in good format!"
no_key_public: "You haven't entered the public key of %{key}!" no_key_public: "You haven't the public key of %{key}!"
genkey_gpg: genkey_gpg:
exception: "Can't create the GPG key!" exception: "Can't create the GPG key!"
name: "You must define a name for your GPG key!" name: "You must define a name for your GPG key!"
password: "You must define a password for your GPG key!" password: "You must define a password for your GPG key!"
empty: "The class is empty"
export: "Can't export, unable to write in %{file}!" export: "Can't export, unable to write in %{file}!"
export_key: "Can't export the GPG key"
gpg_file: gpg_file:
decrypt: "Can't decrypt file!" decrypt: "Can't decrypt file!"
encrypt: "Can't encrypt the GPG file!" encrypt: "Can't encrypt the GPG file!"
mpw_file: mpw_file:
read_data: "Can't read the MPW file!" read_data: "Can't to read the MPW file!"
write_data: "Can't write the MPW file!" write_data: "Can't to write the MPW file!"
import: "Can't import, unable to read %{file}!" import: "Can't import, unable to read %{file}!"
update: update:
host_and_comment_empty: "You must define a host or a comment!" name_empty: "You must define a name!"
sync:
general: "An error has appeared during the sync"
connection: "Connection fail!"
communication: "A communication problem with the server is appeared!"
download: "Can't download the file!"
not_authorized: "You haven't the access to remote file!"
upload: "Can't upload the file on the server!"
unknown: "An unknown error is occured!"
unknown_type: "The sync type is unknown"
warning: warning:
select: 'Your choice is not a valid item!' select: 'Your choice is not a valid element!'
command: command:
add: "Add a new item" add: "Add a new item"
@ -41,68 +47,53 @@ en:
option: option:
add: "Add an item or key" add: "Add an item or key"
add_gpg_key: "Share the wallet with another GPG key" alpha: "Use letter to generate a password"
alpha: "Use letter to create a password"
comment: "Specify a comment"
config: "Specify the configuration file to use" config: "Specify the configuration file to use"
clipboard: "Disable the clipboard feature" clipboard: "Disable the clipboard feature"
default_path: "Move the wallet to the default directory"
default_wallet: "Specify the default wallet to use"
delete_gpg_key: "Delete wallet sharing with an other GPG key"
disable_alpha: "Don't use letters to create a password"
disable_numeric: "Don't use numbers to generate a password"
disable_pinmode: "Disable the pinentry mode"
disable_special_chars: "Don't use special char to create a password"
export: "Export a wallet in an yaml file" export: "Export a wallet in an yaml file"
file_export: "Specify the file to export data" file_export: "Specify the file where export data"
file_format: "Format of import file (default: mpw; available: %{formats})"
file_import: "Specify the file to import" file_import: "Specify the file to import"
force: "Do not ask confirmation when deleting an item" force: "No ask to confirm when you delete an item"
generate_password: "Create a random password (default 8 characters)" generate_password: "Generate a random password (default 8 characters)"
gpg_exe: "Set the gpg binary path to use" gpg_exe: "Set the gpg binary path to use"
gpg_key: "Specify a GPG key (ex: user@example.com)" gpg_key: "Specify a GPG key (ex: user@example.com)"
group: "Search the items with specified group" group: "Search the items with specified group"
help: "Show this help message" help: "Show this help message"
host: "Specify the server for the synchronization"
init: "Initialize mpw" init: "Initialize mpw"
import: "Import item from an yaml file" import: "Import item since a yaml file"
key: "Define the key name" key: "Specify the key name"
lang: "Set the software language" lang: "Set the software language"
length: "Size of the password"
list: "List the wallets" list: "List the wallets"
list_keys: "List the GPG keys in wallet" no_sync: "Disable synchronization with the server"
new_group: "Define a group for the item" numeric: "Use number to generate a password"
numeric: "Use number to create a password" password: "Change the password for the synchronization"
otp_code: "Set an otp key" path: "Specify the remote path"
path: "Move the wallet in new specify directory"
pattern: "Given search pattern" pattern: "Given search pattern"
pinmode: "Enable pinentry mode (available with gpg >= 2.1)" port: "Specify the connection port"
random_password: "Generate a random password" protocol: "Specify the protocol for the connection"
setup: "Create a new configuration file" setup: "Create a new configuration file"
setup_wallet: "Create a new configuration file for a wallet" setup_wallet: "Create a new configuration file for a wallet"
special_chars: "Use special char to create a password" special_chars: "Use special char to generate a password"
show: "Search and display the items" show: "Search and show the items"
show_all: "Listing all items" show_all: "List all items"
text_editor: "Use text editor to edit the item" usage: "Usage"
usage: "Use" user: "Specify the user for the connection"
url: "Set an url (ex: https://example.com/path)"
user: "Set an user"
wallet: "Specify a wallet to use" wallet: "Specify a wallet to use"
wallet_dir: "Set the wallets folder" wallet_dir: "Set the wallets folder"
form: form:
select: select: "Select the item: "
choice: "Select the item: "
error: "No item selected"
add_key: add_key:
valid: "Key has been added!" valid: "Key has been added!"
add_item: add_item:
name: "Item name (mandatory)" name: "The item's name (mandatory"
group: "Group name" group: "The group's name"
host: "Hostname or ip" host: "The hostname or ip"
protocol: "Connection protocol (ssh, http, ...)" protocol: "The protocol of the connection (ssh, http, ...)"
login: "Connection ID" login: "The login of connection"
password: "Password" password: "The password"
port: "Connection port" port: "The connection port"
comment: "A comment" comment: "A comment"
otp_key: "The OTP secret" otp_key: "The OTP secret"
valid: "Item has been added!" valid: "Item has been added!"
@ -111,11 +102,9 @@ en:
clean: "The clipboard has been cleaned." clean: "The clipboard has been cleaned."
login: "The login has been copied in clipboard." login: "The login has been copied in clipboard."
password: "The password has been copied in clipboard for 30s!" password: "The password has been copied in clipboard for 30s!"
otp: "The OTP code has been copied %{time}s!" otp: "The OTP code has been copied for %{time}s!"
url: "The URL has been copied in clipboard."
help: help:
name: "Help" name: "Help"
url: "Press <u> to copy URL"
login: "Press <l> to copy the login" login: "Press <l> to copy the login"
password: "Press <p> to copy the password" password: "Press <p> to copy the password"
otp_code: "Press <o> to copy the otp code" otp_code: "Press <o> to copy the otp code"
@ -123,19 +112,12 @@ en:
delete_key: delete_key:
valid: "Key has been deleted!" valid: "Key has been deleted!"
delete_item: delete_item:
ask: "Are you sure you want to remove this item ?" ask: "Are you sure you want to remove the item ?"
valid: "The item has been removed!" valid: "The item has been removed!"
import: import:
ask: "Are you sure you want to import this file %{file} ?" ask: "Are you sure you want to import this file %{file} ?"
file_empty: "The import file is empty!" valid: "The import is succesfull!"
file_not_exist: "The import file doesn't exist!"
format_unknown: "The import format '%{file_format} is unknown!"
valid: "The import is successful!"
not_valid: "No data to import!" not_valid: "No data to import!"
set_config:
valid: "The config file has been edited!"
set_wallet_path:
valid: "The wallet has been moved!"
setup_config: setup_config:
title: "Setup a new config file" title: "Setup a new config file"
lang: "Choose your language (en, fr, ...) [default=%{lang}]: " lang: "Choose your language (en, fr, ...) [default=%{lang}]: "
@ -143,38 +125,45 @@ en:
gpg_exe: "Enter the executable GPG path (optional): " gpg_exe: "Enter the executable GPG path (optional): "
wallet_dir: "Enter the wallets's folder path [default=%{home}/wallets]: " wallet_dir: "Enter the wallets's folder path [default=%{home}/wallets]: "
valid: "The config file has been created!" valid: "The config file has been created!"
setup_wallet:
title: "Wallet setup"
sync_type: "Synchronization type (ssh, ftp): "
sync_host: "Synchronization server: "
sync_port: "Port of the synchronization server: "
sync_user: "Username for the synchronization: "
sync_pwd: "Password for the synchronization: "
sync_path: "File path for the synchronization : "
valid: "The wallet config file has been created!"
setup_gpg_key: setup_gpg_key:
title: "Setup a GPG key" title: "Setup a GPG key"
ask: "Do you want to create your GPG key ? (Y/n)" ask: "Do you want create your GPG key ? (Y/n)"
no_create: "You must to create manually your GPG key or relaunch the software." no_create: "You must create manually your GPG key or relaunch the software."
name: "Your name and lastname: " name: "Your name and lastname: "
password: "A password for the GPG key: " password: "A password for the GPG key: "
confirm_password: "Confirm your password: " confirm_password: "Confirm your password: "
error_password: "Your passwords aren't identical!" error_password: "Your passwords aren't identical!"
length: "Size of the GPG key [default=2048]: " length: "Size of the GPG key [default=2048]: "
expire: "Expire time of the GPG key [default=0 (unlimited)]: " expire: "Expire time of the GPG key [default=0 (unlimited)]: "
wait: "Please wait until GPG key is created, this process can take a few minutes." wait: "Please waiting during the GPG key generate, this process can take few minutes."
valid: "Your GPG key has been created ;-)" valid: "Your GPG key has been created ;-)"
update_item: update_item:
name: "Item name (mandatory)" name: "The item's name (mandatory"
group: "Group name" group: "The group's name"
host: "Hostname or ip" host: "The hostname or ip"
protocol: "Connection protocol (ssh, http, ...)" protocol: "The protocol of the connection (ssh, http, ...)"
login: "Login id" login: "The login of connection"
password: "Password (leave empty if you don't want to update it)" password: "The password (leave empty if you don't want change)"
port: "Connection port" port: "The connection port"
comment: "A comment" comment: "A comment"
otp_key: "Secret OTP (leave empty if you don't want to update it" otp_key: "The OTP secret (leave empty if you don't want change"
valid: "Item has been updated!" valid: "Item has been updated!"
export: export:
valid: "The export in %{file} is successful!" valid: "The export in %{file} is succesfull!"
display: display:
comment: "Comment" comment: "Comment"
config: "Configuration"
error: "ERROR" error: "ERROR"
keys: "GPG keys" gpg_password: "GPG passphrase: "
gpg_password: "GPG password: "
group: "Group" group: "Group"
login: "Login" login: "Login"
name: "Name" name: "Name"
@ -185,7 +174,6 @@ en:
port: "Port" port: "Port"
protocol: "Protocol" protocol: "Protocol"
server: "Server" server: "Server"
wallets: "Wallets"
warning: "Warning" warning: "Warning"
formats: formats:

View file

@ -1,7 +1,6 @@
--- ---
fr: fr:
error: error:
bad_class: "La classe de l'objet n'est pas celle attendue!"
config: config:
write: "Impossible d'écrire le fichier de configuration!" write: "Impossible d'écrire le fichier de configuration!"
load: "Le fichier de configuration est invalide!" load: "Le fichier de configuration est invalide!"
@ -11,9 +10,7 @@ fr:
exception: "La création de la clé GPG n'a pas pu aboutir!" exception: "La création de la clé GPG n'a pas pu aboutir!"
name: "Vous devez définir un nom pour votre clé GPG!" name: "Vous devez définir un nom pour votre clé GPG!"
password: "Vous devez définir un mot de passe pour votre clé GPG!" password: "Vous devez définir un mot de passe pour votre clé GPG!"
empty: "La classe est vide"
export: "Impossible d'exporter les données dans le fichier %{file}!" export: "Impossible d'exporter les données dans le fichier %{file}!"
export_key: "Impossible d'exporter la clé GPG"
gpg_file: gpg_file:
decrypt: "Impossible de déchiffrer le fichier GPG!" decrypt: "Impossible de déchiffrer le fichier GPG!"
encrypt: "Impossible de chiffrer le fichier GPG!" encrypt: "Impossible de chiffrer le fichier GPG!"
@ -22,7 +19,16 @@ fr:
write_data: "Impossible d'écrire le fichier MPW!" write_data: "Impossible d'écrire le fichier MPW!"
import: "Impossible d'importer le fichier %{file}, car il n'est pas lisible!" import: "Impossible d'importer le fichier %{file}, car il n'est pas lisible!"
update: update:
host_and_comment_empty: "Vous devez définir un host ou un commentaire!" name_empty: "Vous devez définir un nom!"
sync:
general: "Une erreur est survenue durant la synchronisation"
connection: "La connexion n'a pu être établie!"
communication: "Un problème de communication avec le serveur est apparu!"
download: "Impossible de télécharger le fichier!"
not_authorized: "Vous n'avez pas les autorisations d'accès au fichier distant!"
upload: "Impossible d'envoyer le fichier sur le serveur!"
unknown: "Une erreur inconnue est survenue!"
unknown_type: "Le type de synchronisation est inconnu"
warning: warning:
select: "Votre choix n'est pas un élément valide!" select: "Votre choix n'est pas un élément valide!"
@ -41,21 +47,11 @@ fr:
option: option:
add: "Ajoute un élément ou une clé" add: "Ajoute un élément ou une clé"
add_gpg_key: "Partage le portefeuille avec une autre clé GPG"
alpha: "Utilise des lettres dans la génération d'un mot de passe" alpha: "Utilise des lettres dans la génération d'un mot de passe"
config: "Spécifie le fichier de configuration à utiliser" config: "Spécifie le fichier de configuration à utiliser"
comment: "Spécifie un commentaire"
clipboard: "Désactive la fonction presse papier" clipboard: "Désactive la fonction presse papier"
default_path: "Déplace le portefeuille dans le dossier par défaut"
default_wallet: "Spécifie le porte-feuille à utiliser par défaut"
delete_gpg_key: "Supprime le partage le portefeuille avec une autre clé GPG"
disable_alpha: "Désactive l'utilisation des lettres dans la génération d'un mot de passe"
disable_numeric: "Désactive l'utilisation des chiffre dans la génération d'un mot de passe"
disable_pinmode: "Désactive le mode pinentry"
disable_special_chars: "Désactive l'utilisation des charactères speciaux dans la génération d'un mot de passe"
export: "Exporte un portefeuille dans un fichier yaml" export: "Exporte un portefeuille dans un fichier yaml"
file_export: "Spécifie le fichier où exporter les données" file_export: "Spécifie le fichier où exporter les données"
file_format: "Format du fichier d'import (défault: mpw; disponible: %{formats})"
file_import: "Spécifie le fichier à importer" file_import: "Spécifie le fichier à importer"
force: "Ne demande pas de confirmation pour la suppression d'un élément" force: "Ne demande pas de confirmation pour la suppression d'un élément"
generate_password: "Génére un mot de passe aléatoire (défaut 8 caractères)" generate_password: "Génére un mot de passe aléatoire (défaut 8 caractères)"
@ -63,36 +59,31 @@ fr:
gpg_key: "Spécifie une clé GPG (ex: user@example.com)" gpg_key: "Spécifie une clé GPG (ex: user@example.com)"
group: "Recherche les éléments appartenant au groupe spécifié" group: "Recherche les éléments appartenant au groupe spécifié"
help: "Affiche ce message d'aide" help: "Affiche ce message d'aide"
host: "Spécifie le serveur pour la synchronisation"
import: "Importe des éléments depuis un fichier yaml" import: "Importe des éléments depuis un fichier yaml"
init: "Initialise mpw" init: "Initialise mpw"
key: "Spécifie le nom d'une clé" key: "Spécifie le nom d'une clé"
lang: "Spécifie la langue du logiciel (ex: fr)" lang: "Spécifie la langue du logiciel (ex: fr)"
length: "Taille du mot de passe"
list: "Liste les portefeuilles" list: "Liste les portefeuilles"
list_keys: "Liste les clés GPG dans le portefeuille" no_sync: "Désactive la synchronisation avec le serveur"
new_group: "Spécifie le groupe de l'item"
numeric: "Utilise des chiffre dans la génération d'un mot de passe" numeric: "Utilise des chiffre dans la génération d'un mot de passe"
otp_code: "Spécifie un code OTP" password: "Changer le mot de passe de connexion"
path: "Déplace le portefeuille dans un nouveau dossier" path: "Spécifie le chemin distant"
pattern: "Motif de donnée à chercher" pattern: "Motif de donnée à chercher"
pinmode: "Active le mode pinentry (valable avec gpg >= 2.1)" port: "Spécifie le port de connexion"
random_password: "Génére un mot de passe aléatoire" protocol: "Spécifie le protocol utilisé pour la connexion"
setup: "Création d'un nouveau fichier de configuration" setup: "Création d'un nouveau fichier de configuration"
setup_wallet: "Création d'un nouveau fichier de configuration pour un portefeuille" setup_wallet: "Création d'un nouveau fichier de configuration pour un portefeuille"
special_chars: "Utilise des charactères speciaux dans la génération d'un mot de passe" special_chars: "Utilise des charactères speciaux dans la génération d'un mot de passe"
show: "Recherche et affiche les éléments" show: "Recherche et affiche les éléments"
show_all: "Liste tous les éléments" show_all: "Liste tous les éléments"
text_editor: "Active l'édition avec un éditeur de texte"
usage: "Utilisation" usage: "Utilisation"
url: "Spécifie l'url (ex: http://example.com/path)" user: "Spécifie l'identifiant de connection"
user: "Spécifie un utilisateur"
wallet: "Spécifie le portefeuille à utiliser" wallet: "Spécifie le portefeuille à utiliser"
wallet_dir: "Spécifie le répertoire des portefeuilles" wallet_dir: "Spécifie le répertoire des portefeuilles"
form: form:
select: select: "Sélectionner l'élément: "
choice: "Sélectionner l'élément: "
error: "Aucun élément sélectionné"
add_key: add_key:
valid: "La clé a bien été ajoutée!" valid: "La clé a bien été ajoutée!"
add_item: add_item:
@ -112,10 +103,8 @@ fr:
login: "L'identifiant a été copié dans le presse papier" login: "L'identifiant a été copié dans le presse papier"
password: "Le mot de passe a été copié dans le presse papier pour 30s!" password: "Le mot de passe a été copié dans le presse papier pour 30s!"
otp: "Le code OTP a été copié dans le presse papier il est valable %{time}s!" otp: "Le code OTP a été copié dans le presse papier il est valable %{time}s!"
url: "L'URL a été copié dans le presse papier"
help: help:
name: "Aide" name: "Aide"
url: "Pressez <u> pour copier l'URL"
login: "Pressez <l> pour copier l'identifiant" login: "Pressez <l> pour copier l'identifiant"
password: "Pressez <p> pour copier le mot de passe" password: "Pressez <p> pour copier le mot de passe"
otp_code: "Pressez <o> pour copier le code OTP" otp_code: "Pressez <o> pour copier le code OTP"
@ -127,15 +116,8 @@ fr:
valid: "L'élément a bien été supprimé!" valid: "L'élément a bien été supprimé!"
import: import:
ask: "Êtes vous sûre de vouloir importer le fichier %{file} ?" ask: "Êtes vous sûre de vouloir importer le fichier %{file} ?"
file_empty: "Le fichier d'import est vide!"
file_not_exist: "Le fichier d'import n'existe pas"
format_unknown: "Le format d'import '%{file_format}' est inconnu!"
valid: "L'import est un succès!" valid: "L'import est un succès!"
not_valid: "Aucune donnée à importer!" not_valid: "Aucune donnée à importer!"
set_config:
valid: "Le fichier de configuration a bien été modifié!"
set_wallet_path:
valid: "Le portefeuille a bien été déplacé!"
setup_config: setup_config:
title: "Création d'un nouveau fichier de configuration" title: "Création d'un nouveau fichier de configuration"
lang: "Choisissez votre langue (en, fr, ...) [défaut=%{lang}]: " lang: "Choisissez votre langue (en, fr, ...) [défaut=%{lang}]: "
@ -143,6 +125,15 @@ fr:
gpg_exe: "Entrez le chemin de l'exécutable GPG (optionnel): " gpg_exe: "Entrez le chemin de l'exécutable GPG (optionnel): "
wallet_dir: "Entrez le chemin du répertoire qui contiendra les porte-feuilles de mot de passe [défaut=%{home}/wallets]: " wallet_dir: "Entrez le chemin du répertoire qui contiendra les porte-feuilles de mot de passe [défaut=%{home}/wallets]: "
valid: "Le fichier de configuration a bien été créé!" valid: "Le fichier de configuration a bien été créé!"
setup_wallet:
title: "Configuration du porte-feuille"
sync_type: "Type de synchronisation (ssh, ftp): "
sync_host: "Serveur: "
sync_port: "Port: "
sync_user: "Utilisateur: "
sync_pwd: "Mot de passe: "
sync_path: "Chemin du fichier: "
valid: "Le fichier de configuration du porte-feuille a bien été créé!"
setup_gpg_key: setup_gpg_key:
title: "Configuration d'une nouvelle clé GPG" title: "Configuration d'une nouvelle clé GPG"
ask: "Voulez vous créer votre clé GPG ? (O/n)" ask: "Voulez vous créer votre clé GPG ? (O/n)"
@ -171,9 +162,7 @@ fr:
display: display:
comment: "Commentaire" comment: "Commentaire"
config: "Configuration"
error: "ERREUR" error: "ERREUR"
keys: "Clés GPG"
gpg_password: "Mot de passe GPG: " gpg_password: "Mot de passe GPG: "
group: "Groupe" group: "Groupe"
login: "Identifiant" login: "Identifiant"
@ -185,7 +174,6 @@ fr:
port: "Port" port: "Port"
protocol: "Protocol" protocol: "Protocol"
server: "Serveur" server: "Serveur"
wallets: "Porte-feuilles"
warning: "Warning" warning: "Warning"
formats: formats:

View file

@ -1,22 +1,20 @@
#!/usr/bin/ruby
# MPW is a software to crypt and manage your passwords
# Copyright (C) 2016 Adrien Waksberg <mpw@yae.im>
# #
# Copyright:: 2013, Adrien Waksberg # 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.
# #
# Licensed to the Apache Software Foundation (ASF) under one # This program is distributed in the hope that it will be useful,
# or more contributor license agreements. See the NOTICE file # but WITHOUT ANY WARRANTY; without even the implied warranty of
# distributed with this work for additional information # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# regarding copyright ownership. The ASF licenses this file # GNU General Public License for more details.
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # You should have received a copy of the GNU General Public License
# # along with this program; if not, write to the Free Software
# Unless required by applicable law or agreed to in writing, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
require 'readline' require 'readline'
require 'locale' require 'locale'
@ -29,60 +27,58 @@ require 'mpw/item'
require 'mpw/mpw' require 'mpw/mpw'
module MPW module MPW
class Cli class Cli
# @param config [Config]
def initialize(config) # Constructor
# @args: config -> the config
# sync -> boolean for sync or not
def initialize(config, sync=true)
@config = config @config = config
@sync = sync
end end
# Change a parameter int the config after init # Change a parameter int the config after init
# @param options [Hash] param to change # @args: options -> param to change
def set_config(options) def set_config(options)
@config.setup(options) gpg_key = options[:gpg_key] || @config.key
lang = options[:lang] || @config.lang
wallet_dir = options[:wallet_dir] || @config.wallet_dir
gpg_exe = options[:gpg_exe] || @config.gpg_exe
puts I18n.t('form.set_config.valid').to_s.green @config.setup(gpg_key, lang, wallet_dir, gpg_exe)
rescue => e rescue Exception => e
puts "#{I18n.t('display.error')} #15: #{e}".red puts "#{I18n.t('display.error')} #15: #{e}".red
exit 2 exit 2
end end
# Change the wallet path
# @param path [String] new path
def set_wallet_path(path)
@config.set_wallet_path(path, @wallet)
puts I18n.t('form.set_wallet_path.valid').to_s.green
rescue => e
puts "#{I18n.t('display.error')} #19: #{e}".red
exit 2
end
# Create a new config file # Create a new config file
# @param options [Hash] # @args: options -> set param
def setup(options) def setup(options)
options[:lang] = options[:lang] || Locale::Tag.parse(ENV['LANG']).to_simple.to_s[0..1] lang = options[:lang] || Locale::Tag.parse(ENV['LANG']).to_simple.to_s[0..1]
I18n.locale = options[:lang].to_sym I18n.locale = lang.to_sym
@config.setup(options) @config.setup(options[:gpg_key], lang, options[:wallet_dir], options[:gpg_exe])
load_config load_config
puts I18n.t('form.setup_config.valid').to_s.green puts "#{I18n.t('form.setup_config.valid')}".green
rescue => e rescue Exception => e
puts "#{I18n.t('display.error')} #8: #{e}".red puts "#{I18n.t('display.error')} #8: #{e}".red
exit 2 exit 2
end end
# Setup a new GPG key # Setup a new GPG key
# @param gpg_key [String] gpg key name # @args: gpg_key -> the key name
def setup_gpg_key(gpg_key) def setup_gpg_key(gpg_key)
return if @config.check_gpg_key? return if @config.check_gpg_key?
password = ask(I18n.t('form.setup_gpg_key.password')) { |q| q.echo = false } password = ask(I18n.t('form.setup_gpg_key.password')) {|q| q.echo = false}
confirm = ask(I18n.t('form.setup_gpg_key.confirm_password')) { |q| q.echo = false } confirm = ask(I18n.t('form.setup_gpg_key.confirm_password')) {|q| q.echo = false}
raise I18n.t('form.setup_gpg_key.error_password') if password != confirm if password != confirm
raise I18n.t('form.setup_gpg_key.error_password')
end
@password = password.to_s @password = password.to_s
@ -90,118 +86,74 @@ module MPW
@config.setup_gpg_key(@password, gpg_key) @config.setup_gpg_key(@password, gpg_key)
puts I18n.t('form.setup_gpg_key.valid').to_s.green puts "#{I18n.t('form.setup_gpg_key.valid')}".green
rescue => e rescue Exception => e
puts "#{I18n.t('display.error')} #8: #{e}".red puts "#{I18n.t('display.error')} #8: #{e}".red
exit 2 exit 2
end end
# List gpg keys in wallet # Setup wallet config for sync
def list_keys # @args: options -> value to change
table_list('keys', @mpw.list_keys) def setup_wallet_config(options={})
if not options[:password].nil?
options[:password] = ask(I18n.t('form.setup_wallet.password')) {|q| q.echo = false}
end end
# List config #wallet_file = wallet.nil? ? "#{@config.wallet_dir}/default.mpw" : "#{@config.wallet_dir}/#{wallet}.mpw"
def list_config
config = {
'lang' => @config.lang,
'gpg_key' => @config.gpg_key,
'default_wallet' => @config.default_wallet,
'wallet_dir' => @config.wallet_dir,
'pinmode' => @config.pinmode,
'gpg_exe' => @config.gpg_exe
}
@config.wallet_paths.each { |k, v| config["path_wallet_#{k}"] = "#{v}/#{k}.mpw" } @mpw = MPW.new(@config.key, @wallet_file, @password, @config.gpg_exe)
@config.password.each { |k, v| config["password_#{k}"] = v } @mpw.read_data
@mpw.set_config(options)
@mpw.write_data
table_list('config', config) puts "#{I18n.t('form.setup_wallet.valid')}".green
rescue Exception => e
puts "#{I18n.t('display.error')} #10: #{e}".red
exit 2
end end
# Load config # Load config
def load_config def load_config
@config.load_config @config.load_config
rescue => e
rescue Exception => e
puts "#{I18n.t('display.error')} #10: #{e}".red puts "#{I18n.t('display.error')} #10: #{e}".red
exit 2 exit 2
end end
# Request the GPG password and decrypt the file # Request the GPG password and decrypt the file
def decrypt def decrypt
if defined?(@mpw) if not defined?(@mpw)
@mpw.read_data @password = ask(I18n.t('display.gpg_password')) {|q| q.echo = false}
else @mpw = MPW.new(@config.key, @wallet_file, @password, @config.gpg_exe)
begin end
@mpw = MPW.new(@config.gpg_key, @wallet_file, nil, @config.gpg_exe, @config.pinmode)
@mpw.read_data @mpw.read_data
rescue @mpw.sync if @sync
@password = ask(I18n.t('display.gpg_password')) { |q| q.echo = false } rescue Exception => e
@mpw = MPW.new(@config.gpg_key, @wallet_file, @password, @config.gpg_exe, @config.pinmode)
@mpw.read_data
end
end
rescue => e
puts "#{I18n.t('display.error')} #11: #{e}".red puts "#{I18n.t('display.error')} #11: #{e}".red
exit 2 exit 2
end end
# Format list on a table
# @param title [String] name of table
# @param list an array or hash
def table_list(title, list)
length = { k: 0, v: 0 }
if list.is_a?(Array)
i = 0
list = list.map do |item|
i += 1
[i, item]
end.to_h
end
list.each do |k, v|
length[:k] = k.to_s.length if length[:k] < k.to_s.length
length[:v] = v.to_s.length if length[:v] < v.to_s.length
end
puts "\n#{I18n.t("display.#{title}")}".red
print ' '
(length[:k] + length[:v] + 5).times { print '=' }
print "\n"
list.each do |k, v|
print " #{k}".cyan
(length[:k] - k.to_s.length + 1).times { print ' ' }
puts "| #{v}"
end
print "\n"
end
# Format items on a table # Format items on a table
# @param items [Array] def table(items=[])
def table_items(items = [])
group = '.' group = '.'
i = 1 i = 1
length_total = 10 length_total = 10
data = { id: { length: 3, color: 'cyan' }, data = { id: { length: 3, color: 'cyan' },
host: { length: 9, color: 'yellow' }, host: { length: 9, color: 'yellow' },
user: { length: 7, color: 'green' }, user: { length: 7, color: 'green' },
protocol: { length: 9, color: 'white' },
port: { length: 5, color: 'white' },
otp: { length: 4, color: 'white' }, otp: { length: 4, color: 'white' },
comment: { length: 14, color: 'magenta' } } comment: { length: 14, color: 'magenta' },
}
items.each do |item| items.each do |item|
data.each do |k, v| data.each do |k, v|
case k next if k == :id or k == :otp
when :id, :otp
next v[:length] = item.send(k.to_s).length + 3 if item.send(k.to_s).to_s.length >= v[:length]
when :host
v[:length] = item.url.length + 3 if item.url.length >= v[:length]
else
v[:length] = item.send(k.to_s).to_s.length + 3 if item.send(k.to_s).to_s.length >= v[:length]
end
end end
end end
data[:id][:length] = items.length.to_s.length + 2 if items.length.to_s.length > data[:id][:length] data[:id][:length] = items.length.to_s.length + 2 if items.length.to_s.length > data[:id][:length]
@ -244,22 +196,16 @@ module MPW
data.each do |k, v| data.each do |k, v|
next if k == :id next if k == :id
if k == :otp
print '| ' print '| '
if item.otp; print ' X ' else 4.times { print ' ' } end
case k next
when :otp
item.otp ? (print ' X ') : 4.times { print ' ' }
when :host
print "#{item.protocol}://".light_black if item.protocol
print item.host.send(v[:color])
print ":#{item.port}".light_black if item.port
(v[:length] - item.url.to_s.length).times { print ' ' }
else
print item.send(k.to_s).to_s.send(v[:color])
(v[:length] - item.send(k.to_s).to_s.length).times { print ' ' }
end end
print '| '
print "#{item.send(k.to_s)}".send(v[:color])
(v[:length] - item.send(k.to_s).to_s.length).times { print ' ' }
end end
print "\n" print "\n"
@ -270,67 +216,53 @@ module MPW
end end
# Display the query's result # Display the query's result
# @param options [Hash] the options to search # @args: options -> the option to search
def list(**options) def list(options={})
result = @mpw.list(options) result = @mpw.list(options)
if result.empty? if result.length == 0
puts I18n.t('display.nothing') puts I18n.t('display.nothing')
else else
table_items(result) table(result)
end end
end end
# Get an item when multiple choice # Get an item when multiple choice
# @param items [Array] list of items # @args: items -> array of items
# @return [Item] an item # @rtrn: item
def get_item(items) def get_item(items)
return items[0] if items.length == 1 return items[0] if items.length == 1
items.sort! { |a, b| a.group.to_s.downcase <=> b.group.to_s.downcase } items.sort! { |a,b| a.group.to_s.downcase <=> b.group.to_s.downcase }
choice = ask(I18n.t('form.select.choice')).to_i choice = ask(I18n.t('form.select')).to_i
raise I18n.t('form.select.error') unless choice >= 1 && choice <= items.length if choice >= 1 and choice <= items.length
return items[choice-1]
items[choice - 1] else
return nil
end end
# Print help message for clipboard mode
# @param item [Item]
def clipboard_help(item)
puts "----- #{I18n.t('form.clipboard.help.name')} -----".cyan
puts I18n.t('form.clipboard.help.url')
puts I18n.t('form.clipboard.help.login')
puts I18n.t('form.clipboard.help.password')
puts I18n.t('form.clipboard.help.otp_code') if item.otp
puts I18n.t('form.clipboard.help.quit')
end end
# Copy in clipboard the login and password # Copy in clipboard the login and password
# @param item [Item] # @args: item -> the item
# @param clipboard [Boolean] enable clipboard # clipboard -> enable clipboard
def clipboard(item, clipboard = true) def clipboard(item, clipboard=true)
pid = nil
# Security: force quit after 90s # Security: force quit after 90s
Thread.new do Thread.new do
sleep 90 sleep 90
exit exit
end end
Kernel.loop do while true
choice = ask(I18n.t('form.clipboard.choice')).to_s choice = ask(I18n.t('form.clipboard.choice')).to_s
case choice case choice
when 'q', 'quit' when 'q', 'quit'
break break
when 'u', 'url'
if clipboard
Clipboard.copy(item.url)
puts I18n.t('form.clipboard.url').green
else
puts item.url
end
when 'l', 'login' when 'l', 'login'
if clipboard if clipboard
Clipboard.copy(item.user) Clipboard.copy(item.user)
@ -354,10 +286,7 @@ module MPW
end end
when 'o', 'otp' when 'o', 'otp'
if !item.otp if clipboard
clipboard_help(item)
next
elsif clipboard
Clipboard.copy(@mpw.get_otp_code(item.id)) Clipboard.copy(@mpw.get_otp_code(item.id))
else else
puts @mpw.get_otp_code(item.id) puts @mpw.get_otp_code(item.id)
@ -365,7 +294,12 @@ module MPW
puts I18n.t('form.clipboard.otp', time: @mpw.get_otp_remaining_time).yellow puts I18n.t('form.clipboard.otp', time: @mpw.get_otp_remaining_time).yellow
else else
clipboard_help(item) puts "----- #{I18n.t('form.clipboard.help.name')} -----".cyan
puts I18n.t('form.clipboard.help.login')
puts I18n.t('form.clipboard.help.password')
puts I18n.t('form.clipboard.help.otp_code')
puts I18n.t('form.clipboard.help.quit')
next
end end
end end
@ -376,71 +310,61 @@ module MPW
# List all wallets # List all wallets
def list_wallet def list_wallet
wallets = @config.wallet_paths.keys wallets = Dir.glob("#{@config.wallet_dir}/*.mpw")
Dir.glob("#{@config.wallet_dir}/*.mpw").each do |f| wallets.each do |wallet|
wallet = File.basename(f, '.mpw') puts File.basename(wallet, '.mpw')
wallet += ' *'.green if wallet == @config.default_wallet
wallets << wallet
end end
table_list('wallets', wallets)
end end
# Display the wallet # Display the wallet
# @param wallet [String] wallet name # @args: wallet -> the wallet name
def get_wallet(wallet = nil) def get_wallet(wallet=nil)
@wallet =
if wallet.to_s.empty? if wallet.to_s.empty?
wallets = Dir.glob("#{@config.wallet_dir}/*.mpw") wallets = Dir.glob("#{@config.wallet_dir}/*.mpw")
if wallets.length == 1
File.basename(wallets[0], '.mpw')
elsif !@config.default_wallet.to_s.empty?
@config.default_wallet
else
'default'
end
else
wallet
end
@wallet_file = if wallets.length == 1
if @config.wallet_paths.key?(@wallet) @wallet_file = wallets[0]
"#{@config.wallet_paths[@wallet]}/#{@wallet}.mpw"
else else
"#{@config.wallet_dir}/#{@wallet}.mpw" @wallet_file = "#{@config.wallet_dir}/default.mpw"
end
else
@wallet_file = "#{@config.wallet_dir}/#{wallet}.mpw"
end end
end end
# Add a new public key # Add a new public key
# @param key [String] key name or key file to add # args: key -> the key name to add
def add_key(key) # file -> gpg public file to import
@mpw.add_key(key) def add_key(key, file=nil)
@mpw.add_key(key, file)
@mpw.write_data @mpw.write_data
@mpw.sync(true) if @sync
puts I18n.t('form.add_key.valid').to_s.green puts "#{I18n.t('form.add_key.valid')}".green
rescue => e rescue Exception => e
puts "#{I18n.t('display.error')} #13: #{e}".red puts "#{I18n.t('display.error')} #13: #{e}".red
end end
# Add new public key # Add new public key
# @param key [String] key name to delete # args: key -> the key name to delete
def delete_key(key) def delete_key(key)
@mpw.delete_key(key) @mpw.delete_key(key)
@mpw.write_data @mpw.write_data
@mpw.sync(true) if @sync
puts I18n.t('form.delete_key.valid').to_s.green puts "#{I18n.t('form.delete_key.valid')}".green
rescue => e rescue Exception => e
puts "#{I18n.t('display.error')} #15: #{e}".red puts "#{I18n.t('display.error')} #15: #{e}".red
end end
# Text editor interface # Text editor interface
# @param template_name [String] template name # @args: template -> template name
# @param item [Item] the item to edit # item -> the item to edit
# @param password [Boolean] disable field password # password -> disable field password
# @return [Hash] the values for an item def text_editor(template_name, item=nil, password=false)
def text_editor(template_name, password = false, item = nil, **options)
editor = ENV['EDITOR'] || 'nano' editor = ENV['EDITOR'] || 'nano'
options = {}
opts = {} opts = {}
template_file = "#{File.expand_path('../../../templates', __FILE__)}/#{template_name}.erb" template_file = "#{File.expand_path('../../../templates', __FILE__)}/#{template_name}.erb"
template = ERB.new(IO.read(template_file)) template = ERB.new(IO.read(template_file))
@ -454,170 +378,170 @@ module MPW
system("#{editor} #{tmp_file}") system("#{editor} #{tmp_file}")
opts = YAML.load_file(tmp_file) opts = YAML::load_file(tmp_file)
end end
opts.delete_if { |_, v| v.to_s.empty? } opts.delete_if { |k,v| v.to_s.empty? }
opts.each do |k, v| opts.each do |k,v|
options[k.to_sym] = v options[k.to_sym] = v
end end
options return options
end end
# Form to add a new item # Form to add a new item
# @param password [Boolean] generate a random password # @args: password -> generate a random password
# @param text_editor [Boolean] enable text editor mode def add(password=false)
# @param values [Hash] multiples value to set the item options = text_editor('add_form', nil, password)
def add(password = false, text_editor = false, **values)
options = text_editor('add_form', password, nil, values) if text_editor
item = Item.new(options) item = Item.new(options)
options[:password] = MPW.password(@config.password) if password
if password
options[:password] = MPW::password(length: 24)
end
@mpw.add(item) @mpw.add(item)
@mpw.set_password(item.id, options[:password]) if options.key?(:password) @mpw.set_password(item.id, options[:password]) if options.has_key?(:password)
@mpw.set_otp_key(item.id, options[:otp_key]) if options.key?(:otp_key) @mpw.set_otp_key(item.id, options[:otp_key]) if options.has_key?(:otp_key)
@mpw.write_data @mpw.write_data
@mpw.sync(true) if @sync
puts I18n.t('form.add_item.valid').to_s.green puts "#{I18n.t('form.add_item.valid')}".green
rescue => e rescue Exception => e
puts "#{I18n.t('display.error')} #13: #{e}".red puts "#{I18n.t('display.error')} #13: #{e}".red
end end
# Update an item # Update an item
# @param password [Boolean] generate a random password # @args: options -> the option to search
# @param text_editor [Boolean] enable text editor mode def update(options={})
# @param options [Hash] the options to search
# @param values [Hash] multiples value to set the item
def update(password = false, text_editor = false, options = {}, **values)
items = @mpw.list(options) items = @mpw.list(options)
if items.empty? if items.length == 0
puts I18n.t('display.nothing') puts "#{I18n.t('display.warning')}: #{I18n.t('warning.select')}".yellow
else else
table_items(items) if items.length > 1 table(items) if items.length > 1
item = get_item(items) item = get_item(items)
values = text_editor('update_form', password, item, values) if text_editor options = text_editor('update_form', item)
values[:password] = MPW.password(@config.password) if password
item.update(values) item.update(options)
@mpw.set_password(item.id, values[:password]) if values.key?(:password) @mpw.set_password(item.id, options[:password]) if options.has_key?(:password)
@mpw.set_otp_key(item.id, values[:otp_key]) if values.key?(:otp_key) @mpw.set_otp_key(item.id, options[:otp_key]) if options.has_key?(:otp_key)
@mpw.write_data @mpw.write_data
@mpw.sync(true) if @sync
puts I18n.t('form.update_item.valid').to_s.green puts "#{I18n.t('form.update_item.valid')}".green
end end
rescue => e rescue Exception => e
puts "#{I18n.t('display.error')} #14: #{e}".red puts "#{I18n.t('display.error')} #14: #{e}".red
end end
# Remove an item # Remove an item
# @param options [Hash] the options to search # @args: options -> the option to search
def delete(**options) def delete(options={})
items = @mpw.list(options) items = @mpw.list(options)
if items.empty? if items.length == 0
puts I18n.t('display.nothing') puts "#{I18n.t('display.warning')}: #{I18n.t('warning.select')}".yellow
else else
table_items(items) table(items)
item = get_item(items) item = get_item(items)
confirm = ask("#{I18n.t('form.delete_item.ask')} (y/N) ").to_s confirm = ask("#{I18n.t('form.delete_item.ask')} (y/N) ").to_s
return unless confirm =~ /^(y|yes|YES|Yes|Y)$/ if not confirm =~ /^(y|yes|YES|Yes|Y)$/
return false
end
item.delete item.delete
@mpw.write_data @mpw.write_data
@mpw.sync(true) if @sync
puts I18n.t('form.delete_item.valid').to_s.green puts "#{I18n.t('form.delete_item.valid')}".green
end end
rescue => e rescue Exception => e
puts "#{I18n.t('display.error')} #16: #{e}".red puts "#{I18n.t('display.error')} #16: #{e}".red
end end
# Copy a password, otp, login # Copy a password, otp, login
# @param clipboard [Boolean] enable clipboard # @args: clipboard -> enable clipboard
# @param options [Hash] the options to search # options -> the option to search
def copy(clipboard = true, **options) def copy(clipboard=true, options={})
items = @mpw.list(options) items = @mpw.list(options)
if items.empty? if items.length == 0
puts I18n.t('display.nothing') puts "#{I18n.t('display.warning')}: #{I18n.t('warning.select')}".yellow
else else
table_items(items) table(items)
item = get_item(items) item = get_item(items)
clipboard(item, clipboard) clipboard(item, clipboard)
end end
rescue => e rescue Exception => e
puts "#{I18n.t('display.error')} #14: #{e}".red puts "#{I18n.t('display.error')} #14: #{e}".red
end end
# Export the items in an yaml file # Export the items in a CSV file
# @param file [String] the path of destination file # @args: file -> the destination file
# @param options [Hash] options to search # options -> option to search
def export(file, options) def export(file, options)
file = 'export-mpw.yml' if file.to_s.empty? file = 'export-mpw.yml' if file.to_s.empty?
items = @mpw.list(options) items = @mpw.list(options)
data = {} data = {}
i = 1
items.each do |item| items.each do |item|
data.merge!( data.merge!(i => { 'host' => item.host,
item.id => { 'user' => item.user,
'comment' => item.comment,
'created' => item.created,
'group' => item.group, 'group' => item.group,
'last_edit' => item.last_edit,
'otp_key' => @mpw.get_otp_key(item.id),
'password' => @mpw.get_password(item.id), 'password' => @mpw.get_password(item.id),
'url' => item.url, 'protocol' => item.protocol,
'user' => item.user 'port' => item.port,
'otp_key' => @mpw.get_otp_key(item.id),
'comment' => item.comment,
'last_edit' => item.last_edit,
'created' => item.created,
} }
) )
i += 1
end end
File.open(file, 'w') { |f| f << data.to_yaml } File.open(file, 'w') {|f| f << data.to_yaml}
puts I18n.t('form.export.valid', file: file).to_s.green puts "#{I18n.t('export.valid', file)}".green
rescue => e rescue Exception => e
puts "#{I18n.t('display.error')} #17: #{e}".red puts "#{I18n.t('display.error')} #17: #{e}".red
end end
# Import items from an yaml file # Import items from a YAML file
# @param file [String] path of import file # @args: file -> the import file
# @param format [String] the software import file format def import(file)
def import(file, format = 'mpw') raise I18n.t('import.file_empty') if file.to_s.empty?
raise I18n.t('form.import.file_empty') if file.to_s.empty? raise I18n.t('import.file_not_exist') if not File.exist?(file)
raise I18n.t('form.import.file_not_exist') unless File.exist?(file)
begin YAML::load_file(file).each_value do |row|
require "mpw/import/#{format}"
rescue LoadError
raise I18n.t('form.import.format_unknown', file_format: format)
end
Import.send(format, file).each_value do |row| item = Item.new(group: row['group'],
item = Item.new( host: row['host'],
protocol: row['protocol'],
user: row['user'],
port: row['port'],
comment: row['comment'], comment: row['comment'],
group: row['group'],
url: row['url'],
user: row['user']
) )
next if item.empty? next if item.empty?
@mpw.add(item) @mpw.add(item)
@mpw.set_password(item.id, row['password']) unless row['password'].to_s.empty? @mpw.set_password(item.id, row['password']) if not row['password'].to_s.empty?
@mpw.set_otp_key(item.id, row['otp_key']) unless row['otp_key'].to_s.empty? @mpw.set_otp_key(item.id, row['otp_key']) if not row['otp_key'].to_s.empty?
end end
@mpw.write_data @mpw.write_data
puts I18n.t('form.import.valid').to_s.green puts "#{I18n.t('form.import.valid')}".green
rescue => e rescue Exception => e
puts "#{I18n.t('display.error')} #18: #{e}".red puts "#{I18n.t('display.error')} #18: #{e}".red
end end
end end
end end

View file

@ -1,22 +1,20 @@
#!/usr/bin/ruby
# MPW is a software to crypt and manage your passwords
# Copyright (C) 2016 Adrien Waksberg <mpw@yae.im>
# #
# Copyright:: 2013, Adrien Waksberg # 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.
# #
# Licensed to the Apache Software Foundation (ASF) under one # This program is distributed in the hope that it will be useful,
# or more contributor license agreements. See the NOTICE file # but WITHOUT ANY WARRANTY; without even the implied warranty of
# distributed with this work for additional information # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# regarding copyright ownership. The ASF licenses this file # GNU General Public License for more details.
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # You should have received a copy of the GNU General Public License
# # along with this program; if not, write to the Free Software
# Unless required by applicable law or agreed to in writing, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
require 'gpgme' require 'gpgme'
require 'yaml' require 'yaml'
@ -24,71 +22,54 @@ require 'i18n'
require 'fileutils' require 'fileutils'
module MPW module MPW
class Config class Config
attr_accessor :error_msg attr_accessor :error_msg
attr_accessor :gpg_key attr_accessor :key
attr_accessor :lang attr_accessor :lang
attr_accessor :config_dir attr_accessor :config_dir
attr_accessor :default_wallet
attr_accessor :wallet_dir attr_accessor :wallet_dir
attr_accessor :wallet_paths
attr_accessor :gpg_exe attr_accessor :gpg_exe
attr_accessor :password
attr_accessor :pinmode
# @param config_file [String] path of config file # Constructor
def initialize(config_file = nil) # @args: config_file -> the specify config file
def initialize(config_file=nil)
@config_file = config_file @config_file = config_file
@config_dir =
if RUBY_PLATFORM =~ /darwin/ if /darwin/ =~ RUBY_PLATFORM
"#{Dir.home}/Library/Preferences/mpw" @config_dir = "#{Dir.home}/Library/Preferences/mpw"
elsif RUBY_PLATFORM =~ /cygwin|mswin|mingw|bccwin|wince|emx/ elsif /cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM
"#{Dir.home}/AppData/Local/mpw" @config_dir = "#{Dir.home}/AppData/Local/mpw"
else else
"#{Dir.home}/.config/mpw" @config_dir = "#{Dir.home}/.config/mpw"
end end
@config_file = "#{@config_dir}/mpw.cfg" if @config_file.to_s.empty? if @config_file.nil? or @config_file.empty?
@config_file = "#{@config_dir}/mpw.cfg"
end
end end
# Create a new config file # Create a new config file
# @param options [Hash] the value to set the config file # @args: key -> the gpg key to encrypt
def setup(**options) # lang -> the software language
gpg_key = options[:gpg_key] || @gpg_key # wallet_dir -> the directory where are the wallets password
lang = options[:lang] || @lang # gpg_exe -> the path of gpg executable
wallet_dir = options[:wallet_dir] || @wallet_dir # @rtrn: true if le config file is create
default_wallet = options[:default_wallet] || @default_wallet def setup(key, lang, wallet_dir, gpg_exe)
gpg_exe = options[:gpg_exe] || @gpg_exe if not key =~ /[a-zA-Z0-9.-_]+\@[a-zA-Z0-9]+\.[a-zA-Z]+/
pinmode = options.key?(:pinmode) ? options[:pinmode] : @pinmode
password = {
numeric: true,
alpha: true,
special: false,
length: 16
}
%w[numeric special alpha length].each do |k|
if options.key?("pwd_#{k}".to_sym)
password[k.to_sym] = options["pwd_#{k}".to_sym]
elsif !@password.nil? && @password.key?(k.to_sym)
password[k.to_sym] = @password[k.to_sym]
end
end
unless gpg_key =~ /[a-zA-Z0-9.-_]+\@[a-zA-Z0-9]+\.[a-zA-Z]+/
raise I18n.t('error.config.key_bad_format') raise I18n.t('error.config.key_bad_format')
end end
wallet_dir = "#{@config_dir}/wallets" if wallet_dir.to_s.empty? if wallet_dir.to_s.empty?
config = { 'gpg_key' => gpg_key, wallet_dir = "#{@config_dir}/wallets"
end
config = { 'key' => key,
'lang' => lang, 'lang' => lang,
'wallet_dir' => wallet_dir, 'wallet_dir' => wallet_dir,
'default_wallet' => default_wallet,
'gpg_exe' => gpg_exe, 'gpg_exe' => gpg_exe,
'password' => password, }
'pinmode' => pinmode,
'wallet_paths' => @wallet_paths }
FileUtils.mkdir_p(@config_dir, mode: 0700) FileUtils.mkdir_p(@config_dir, mode: 0700)
FileUtils.mkdir_p(wallet_dir, mode: 0700) FileUtils.mkdir_p(wallet_dir, mode: 0700)
@ -96,95 +77,68 @@ module MPW
File.open(@config_file, 'w') do |file| File.open(@config_file, 'w') do |file|
file << config.to_yaml file << config.to_yaml
end end
rescue => e
rescue Exception => e
raise "#{I18n.t('error.config.write')}\n#{e}" raise "#{I18n.t('error.config.write')}\n#{e}"
end end
# Setup a new gpg key # Setup a new gpg key
# @param password [String] gpg key password # @args: password -> the GPG key password
# @param name [String] the name of user # name -> the name of user
# @param length [Integer] length of the gpg key # length -> length of the GPG key
# @param expire [Integer] time of expire to gpg key # expire -> the time of expire to GPG key
# @rtrn: true if the GPG key is create, else false
def setup_gpg_key(password, name, length = 4096, expire = 0) def setup_gpg_key(password, name, length = 4096, expire = 0)
raise I18n.t('error.config.genkey_gpg.name') if name.to_s.empty? if name.to_s.empty?
raise I18n.t('error.config.genkey_gpg.password') if password.to_s.empty? raise "#{I18n.t('error.config.genkey_gpg.name')}"
elsif password.to_s.empty?
raise "#{I18n.t('error.config.genkey_gpg.password')}"
end
param = '' param = ''
param << '<GnupgKeyParms format="internal">' + "\n" param << '<GnupgKeyParms format="internal">' + "\n"
param << "Key-Type: RSA\n" param << "Key-Type: DSA\n"
param << "Key-Length: #{length}\n" param << "Key-Length: #{length}\n"
param << "Subkey-Type: ELG-E\n" param << "Subkey-Type: ELG-E\n"
param << "Subkey-Length: #{length}\n" param << "Subkey-Length: #{length}\n"
param << "Name-Real: #{name}\n" param << "Name-Real: #{name}\n"
param << "Name-Comment: #{name}\n" param << "Name-Comment: #{name}\n"
param << "Name-Email: #{@gpg_key}\n" param << "Name-Email: #{@key}\n"
param << "Expire-Date: #{expire}\n" param << "Expire-Date: #{expire}\n"
param << "Passphrase: #{password}\n" param << "Passphrase: #{password}\n"
param << "</GnupgKeyParms>\n" param << "</GnupgKeyParms>\n"
ctx = GPGME::Ctx.new ctx = GPGME::Ctx.new
ctx.genkey(param, nil, nil) ctx.genkey(param, nil, nil)
rescue => e rescue Exception => e
raise "#{I18n.t('error.config.genkey_gpg.exception')}\n#{e}" raise "#{I18n.t('error.config.genkey_gpg.exception')}\n#{e}"
end end
# Load the config file # Load the config file
def load_config def load_config
config = YAML.load_file(@config_file) config = YAML::load_file(@config_file)
@gpg_key = config['gpg_key'] @key = config['key']
@lang = config['lang'] @lang = config['lang']
@wallet_dir = config['wallet_dir'] @wallet_dir = config['wallet_dir']
@wallet_paths = config['wallet_paths'] || {}
@default_wallet = config['default_wallet']
@gpg_exe = config['gpg_exe'] @gpg_exe = config['gpg_exe']
@password = config['password'] || {}
@pinmode = config['pinmode'] || false
raise if @gpg_key.empty? || @wallet_dir.empty? raise if @key.empty? or @wallet_dir.empty?
I18n.locale = @lang.to_sym I18n.locale = @lang.to_sym
rescue => e
rescue Exception => e
raise "#{I18n.t('error.config.load')}\n#{e}" raise "#{I18n.t('error.config.load')}\n#{e}"
end end
# Check if private key exist # Check if private key exist
# @return [Boolean] true if the key exist, else false # @rtrn: true if the key exist, else false
def check_gpg_key? def check_gpg_key?
ctx = GPGME::Ctx.new ctx = GPGME::Ctx.new
ctx.each_key(@gpg_key, true) do ctx.each_key(@key, true) do
return true return true
end end
false return false
end
# Change the path of one wallet
# @param path [String]new directory path
# @param wallet [String] wallet name
def set_wallet_path(path, wallet)
path = @wallet_dir if path == 'default'
path = File.absolute_path(path)
return if path == @wallet_dir && File.exist?("#{@wallet_dir}/#{wallet}.mpw")
return if path == @wallet_paths[wallet]
old_wallet_file =
if @wallet_paths.key?(wallet)
"#{@wallet_paths[wallet]}/#{wallet}.mpw"
else
"#{@wallet_dir}/#{wallet}.mpw"
end
FileUtils.mkdir_p(path) unless Dir.exist?(path)
FileUtils.mv(old_wallet_file, "#{path}/#{wallet}.mpw") if File.exist?(old_wallet_file)
if path == @wallet_dir
@wallet_paths.delete(wallet)
else
@wallet_paths[wallet] = path
end
setup
end
end end
end end
end

View file

@ -1,53 +0,0 @@
#
# Copyright:: 2013, Adrien Waksberg
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
require 'csv'
module MPW
module Import
# Import an export mpw file
# @param file [String] the file path to import
def self.gorilla(file)
data = {}
CSV.foreach(file, headers: true) do |row|
id = row['uuid']
comment =
if row['title'] && row['notes']
"#{row['title']} #{row['notes']}"
elsif row['title']
row['title']
elsif row['notes']
row['notes']
end
data[id] = {
'comment' => comment,
'group' => row['group'],
'password' => row['password'],
'url' => row['url'],
'user' => row['user']
}
end
data
end
end
end

View file

@ -1,53 +0,0 @@
#
# Copyright:: 2013, Adrien Waksberg
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
require 'csv'
module MPW
module Import
# Import an keepass2 export csv file
# @param file [String] the file path to import
def self.keepass(file)
data = {}
CSV.foreach(file, headers: true) do |row|
id = "#{row['Group']} #{row['Title']}"
comment =
if row['Title'] && row['Notes']
"#{row['Title']} #{row['Notes']}"
elsif row['Title']
row['Title']
elsif row['Notes']
row['Notes']
end
data[id] = {
'comment' => comment,
'group' => row['Group'],
'password' => row['Password'],
'url' => row['URL'],
'user' => row['Username']
}
end
data
end
end
end

View file

@ -1,31 +0,0 @@
#
# Copyright:: 2013, Adrien Waksberg
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
require 'yaml'
module MPW
module Import
# Import an export mpw file
# @param file [String] the file path to import
def self.mpw(file)
YAML.load_file(file)
end
end
end

View file

@ -1,48 +0,0 @@
#
# Copyright:: 2013, Adrien Waksberg
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
require 'yaml'
module MPW
module Import
# Import an export mpw file
# @param file [String] the file path to import
def self.mpw_old(file)
data = {}
YAML.load_file(file).each do |id, item|
url = ''
url += "#{item['protocol']}://" if item['protocol']
url += item['host']
url += ":#{item['port']}" if item['port']
data[id] = {
'comment' => item['comment'],
'group' => item['group'],
'otp' => item['otp'],
'password' => item['password'],
'url' => url,
'user' => item['user']
}
end
data
end
end
end

View file

@ -1,45 +1,48 @@
#!/usr/bin/ruby
# MPW is a software to crypt and manage your passwords
# Copyright (C) 2016 Adrien Waksberg <mpw@yae.im>
# #
# Copyright:: 2013, Adrien Waksberg # 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.
# #
# Licensed to the Apache Software Foundation (ASF) under one # This program is distributed in the hope that it will be useful,
# or more contributor license agreements. See the NOTICE file # but WITHOUT ANY WARRANTY; without even the implied warranty of
# distributed with this work for additional information # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# regarding copyright ownership. The ASF licenses this file # GNU General Public License for more details.
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # You should have received a copy of the GNU General Public License
# # along with this program; if not, write to the Free Software
# Unless required by applicable law or agreed to in writing, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
require 'i18n' require 'i18n'
require 'uri'
module MPW module MPW
class Item class Item
attr_accessor :created
attr_accessor :comment attr_accessor :id
attr_accessor :group attr_accessor :group
attr_accessor :host attr_accessor :host
attr_accessor :id
attr_accessor :otp
attr_accessor :port
attr_accessor :protocol attr_accessor :protocol
attr_accessor :last_edit
attr_accessor :url
attr_accessor :user attr_accessor :user
attr_accessor :port
attr_accessor :otp
attr_accessor :comment
attr_accessor :last_edit
attr_accessor :last_sync
attr_accessor :created
# @param options [Hash] the option :host is required # Constructor
def initialize(**options) # Create a new item
@host = '' # @args: options -> a hash of parameter
# raise an error if the hash hasn't the key name
def initialize(options={})
if not options.has_key?(:host) or options[:host].to_s.empty?
raise I18n.t('error.update.name_empty')
end
if !options[:id] || !options[:created] if not options.has_key?(:id) or options[:id].to_s.empty? or not options.has_key?(:created) or options[:created].to_s.empty?
@id = generate_id @id = generate_id
@created = Time.now.to_i @created = Time.now.to_i
else else
@ -53,56 +56,54 @@ module MPW
end end
# Update the item # Update the item
# @param options [Hash] # @args: options -> a hash of parameter
def update(**options) def update(options={})
unless options[:url] || options[:comment] if options.has_key?(:host) and options[:host].to_s.empty?
raise I18n.t('error.update.host_and_comment_empty') raise I18n.t('error.update.name_empty')
end end
if options[:url] @group = options[:group] if options.has_key?(:group)
uri = URI(options[:url]) @host = options[:host] if options.has_key?(:host)
@host = uri.host || options[:url] @protocol = options[:protocol] if options.has_key?(:protocol)
@port = uri.port || nil @user = options[:user] if options.has_key?(:user)
@protocol = uri.scheme || nil @port = options[:port].to_i if options.has_key?(:port) and not options[:port].to_s.empty?
@url = options[:url] @otp = options[:otp] if options.has_key?(:otp)
@comment = options[:comment] if options.has_key?(:comment)
@last_edit = Time.now.to_i if not options.has_key?(:no_update_last_edit)
end end
@comment = options[:comment] if options.key?(:comment) # Update last_sync
@group = options[:group] if options.key?(:group) def set_last_sync
@last_edit = Time.now.to_i unless options.key?(:no_update_last_edit) @last_sync = Time.now.to_i
@otp = options[:otp] if options.key?(:otp)
@user = options[:user] if options.key?(:user)
end end
# Delete all data # Delete all data
def delete def delete
@id = nil @id = nil
@comment = nil
@created = nil
@group = nil @group = nil
@host = nil @host = nil
@last_edit = nil
@otp = nil
@port = nil
@protocol = nil @protocol = nil
@url = nil
@user = nil @user = nil
@port = nil
@otp = nil
@comment = nil
@created = nil
@last_edit = nil
@last_sync = nil
end end
def empty? def empty?
@id.to_s.empty? return @id.to_s.empty?
end end
def nil? def nil?
false return false
end end
private
# Generate an random id # Generate an random id
# @return [String] random string private
def generate_id def generate_id
[*('A'..'Z'), *('a'..'z'), *('0'..'9')].sample(16).join return ([*('A'..'Z'),*('a'..'z'),*('0'..'9')]).sample(16).join
end
end end
end end
end

View file

@ -1,22 +1,20 @@
#!/usr/bin/ruby
# MPW is a software to crypt and manage your passwords
# Copyright (C) 2016 Adrien Waksberg <mpw@yae.im>
# #
# Copyright:: 2013, Adrien Waksberg # 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.
# #
# Licensed to the Apache Software Foundation (ASF) under one # This program is distributed in the hope that it will be useful,
# or more contributor license agreements. See the NOTICE file # but WITHOUT ANY WARRANTY; without even the implied warranty of
# distributed with this work for additional information # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# regarding copyright ownership. The ASF licenses this file # GNU General Public License for more details.
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # You should have received a copy of the GNU General Public License
# # along with this program; if not, write to the Free Software
# Unless required by applicable law or agreed to in writing, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
require 'rubygems/package' require 'rubygems/package'
require 'gpgme' require 'gpgme'
@ -26,24 +24,23 @@ require 'rotp'
require 'mpw/item' require 'mpw/item'
module MPW module MPW
class MPW class MPW
# @param key [String] gpg key name
# @param wallet_file [String] path of the wallet file # Constructor
# @param gpg_pass [String] password of the gpg key def initialize(key, wallet_file, gpg_pass=nil, gpg_exe=nil)
# @param gpg_exe [String] path of the gpg executable
# @param pinmode [Boolean] enable the gpg pinmode
def initialize(key, wallet_file, gpg_pass = nil, gpg_exe = nil, pinmode = false)
@key = key @key = key
@gpg_pass = gpg_pass @gpg_pass = gpg_pass
@gpg_exe = gpg_exe @gpg_exe = gpg_exe
@wallet_file = wallet_file @wallet_file = wallet_file
@pinmode = pinmode
GPGME::Engine.set_info(GPGME::PROTOCOL_OpenPGP, @gpg_exe, "#{Dir.home}/.gnupg") unless @gpg_exe.to_s.empty? if not @gpg_exe.to_s.empty?
GPGME::Engine.set_info(GPGME::PROTOCOL_OpenPGP, @gpg_exe, "#{Dir.home}/.gnupg")
end
end end
# Read mpw file # Read mpw file
def read_data def read_data
@config = {}
@data = [] @data = []
@keys = {} @keys = {}
@passwords = {} @passwords = {}
@ -51,27 +48,30 @@ module MPW
data = nil data = nil
return unless File.exist?(@wallet_file) return if not File.exists?(@wallet_file)
Gem::Package::TarReader.new(File.open(@wallet_file)) do |tar| Gem::Package::TarReader.new(File.open(@wallet_file)) do |tar|
tar.each do |f| tar.each do |f|
case f.full_name case f.full_name
when 'wallet/config.gpg'
@config = YAML.load(decrypt(f.read))
when 'wallet/meta.gpg' when 'wallet/meta.gpg'
data = decrypt(f.read) data = decrypt(f.read)
when %r{^wallet/keys/(?<key>.+)\.pub$} when /^wallet\/keys\/(?<key>.+)\.pub$/
key = Regexp.last_match('key') key = Regexp.last_match('key')
if GPGME::Key.find(:public, key).empty? if GPGME::Key.find(:public, key).length == 0
GPGME::Key.import(f.read, armor: true) GPGME::Key.import(f.read, armor: true)
end end
@keys[key] = f.read @keys[key] = f.read
when %r{^wallet/passwords/(?<id>[a-zA-Z0-9]+)\.gpg$} when /^wallet\/passwords\/(?<id>[a-zA-Z0-9]+)\.gpg$/
@passwords[Regexp.last_match('id')] = f.read @passwords[Regexp.last_match('id')] = f.read
when %r{^wallet/otp_keys/(?<id>[a-zA-Z0-9]+)\.gpg$} when /^wallet\/otp_keys\/(?<id>[a-zA-Z0-9]+)\.gpg$/
@otp_keys[Regexp.last_match('id')] = f.read @otp_keys[Regexp.last_match('id')] = f.read
else else
@ -80,29 +80,29 @@ module MPW
end end
end end
unless data.to_s.empty? if not data.nil? and not data.empty?
YAML.safe_load(data).each_value do |d| YAML.load(data).each_value do |d|
@data.push( @data.push(Item.new(id: d['id'],
Item.new(
id: d['id'],
group: d['group'], group: d['group'],
host: d['host'],
protocol: d['protocol'],
user: d['user'], user: d['user'],
url: d['url'], port: d['port'],
otp: @otp_keys.key?(d['id']), otp: @otp_keys.has_key?(d['id']),
comment: d['comment'], comment: d['comment'],
last_edit: d['last_edit'], last_edit: d['last_edit'],
created: d['created'] created: d['created'],
) )
) )
end end
end end
add_key(@key) unless @keys.key?(@key) add_key(@key) if @keys[@key].nil?
rescue => e rescue Exception => e
raise "#{I18n.t('error.mpw_file.read_data')}\n#{e}" raise "#{I18n.t('error.mpw_file.read_data')}\n#{e}"
end end
# Encrypt all data in tarball # Encrypt a file
def write_data def write_data
data = {} data = {}
tmp_file = "#{@wallet_file}.tmp" tmp_file = "#{@wallet_file}.tmp"
@ -110,25 +110,32 @@ module MPW
@data.each do |item| @data.each do |item|
next if item.empty? next if item.empty?
data.merge!( data.merge!(item.id => { 'id' => item.id,
item.id => {
'id' => item.id,
'group' => item.group, 'group' => item.group,
'host' => item.host,
'protocol' => item.protocol,
'user' => item.user, 'user' => item.user,
'url' => item.url, 'port' => item.port,
'comment' => item.comment, 'comment' => item.comment,
'last_edit' => item.last_edit, 'last_edit' => item.last_edit,
'created' => item.created 'created' => item.created,
} }
) )
end end
@config['last_update'] = Time.now.to_i
Gem::Package::TarWriter.new(File.open(tmp_file, 'w+')) do |tar| Gem::Package::TarWriter.new(File.open(tmp_file, 'w+')) do |tar|
data_encrypt = encrypt(data.to_yaml) data_encrypt = encrypt(data.to_yaml)
tar.add_file_simple('wallet/meta.gpg', 0400, data_encrypt.length) do |io| tar.add_file_simple('wallet/meta.gpg', 0400, data_encrypt.length) do |io|
io.write(data_encrypt) io.write(data_encrypt)
end end
config = encrypt(@config.to_yaml)
tar.add_file_simple('wallet/config.gpg', 0400, config.length) do |io|
io.write(config)
end
@passwords.each do |id, password| @passwords.each do |id, password|
tar.add_file_simple("wallet/passwords/#{id}.gpg", 0400, password.length) do |io| tar.add_file_simple("wallet/passwords/#{id}.gpg", 0400, password.length) do |io|
io.write(password) io.write(password)
@ -149,79 +156,88 @@ module MPW
end end
File.rename(tmp_file, @wallet_file) File.rename(tmp_file, @wallet_file)
rescue => e rescue Exception => e
File.unlink(tmp_file) if File.exist?(tmp_file) File.unlink(tmp_file) if File.exist?(tmp_file)
raise "#{I18n.t('error.mpw_file.write_data')}\n#{e}" raise "#{I18n.t('error.mpw_file.write_data')}\n#{e}"
end end
# Get a password # Get a password
# @param id [String] the item id # args: id -> the item id
def get_password(id) def get_password(id)
password = decrypt(@passwords[id]) password = decrypt(@passwords[id])
if /^\$[a-zA-Z0-9]{4,9}::(?<password>.+)$/ =~ password if /^\$[a-zA-Z0-9]{4,9}::(?<password>.+)$/ =~ password
Regexp.last_match('password') return Regexp.last_match('password')
else else
password return password
end end
end end
# Set a new password for an item # Set a password
# @param id [String] the item id # args: id -> the item id
# @param password [String] the new password # password -> the new password
def set_password(id, password) def set_password(id, password)
salt = MPW.password(length: Random.rand(4..9)) salt = MPW::password(length: Random.rand(4..9))
password = "$#{salt}::#{password}" password = "$#{salt}::#{password}"
@passwords[id] = encrypt(password) @passwords[id] = encrypt(password)
end end
# Return the list of all gpg keys
# @return [Array] the gpg keys name
def list_keys
@keys.keys
end
# Add a public key # Add a public key
# @param key [String] new public key file or name # args: key -> new public key
def add_key(key) # file -> public gpg file to import
if File.exist?(key) def add_key(key, file=nil)
data = File.open(key).read if not file.nil? and File.exists?(file)
key_import = GPGME::Key.import(data, armor: true) data = File.open(file).read
key = GPGME::Key.get(key_import.imports[0].fpr).uids[0].email GPGME::Key.import(data, armor: true)
else else
data = GPGME::Key.export(key, armor: true).read data = GPGME::Key.export(key, armor: true).read
end end
raise I18n.t('error.export_key') if data.to_s.empty? if data.to_s.empty?
raise I18n.t('error.export_key')
end
@keys[key] = data @keys[key] = data
@passwords.each_key { |id| set_password(id, get_password(id)) }
@otp_keys.each_key { |id| set_otp_key(id, get_otp_key(id)) }
end end
# Delete a public key # Delete a public key
# @param key [String] public key to delete # args: key -> public key to delete
def delete_key(key) def delete_key(key)
@keys.delete(key) @keys.delete(key)
@passwords.each_key { |id| set_password(id, get_password(id)) } end
@otp_keys.each_key { |id| set_otp_key(id, get_otp_key(id)) }
# Set config
# args: config -> a hash with config options
def set_config(options={})
@config = {} if @config.nil?
@config['protocol'] = options[:protocol] if options.has_key?(:protocol)
@config['host'] = options[:host] if options.has_key?(:host)
@config['port'] = options[:port] if options.has_key?(:port)
@config['user'] = options[:user] if options.has_key?(:user)
@config['password'] = options[:password] if options.has_key?(:password)
@config['path'] = options[:path] if options.has_key?(:path)
@config['last_sync'] = @config['last_sync'].nil? ? 0 : @config['last_sync']
end end
# Add a new item # Add a new item
# @param item [Item] # @args: item -> Object MPW::Item
def add(item) def add(item)
raise I18n.t('error.bad_class') unless item.instance_of?(Item) if not item.instance_of?(Item)
raise I18n.t('error.empty') if item.empty? raise I18n.t('error.bad_class')
elsif item.empty?
raise I18n.t('error.add.empty')
else
@data.push(item) @data.push(item)
end end
end
# Search in some csv data # Search in some csv data
# @param options [Hash] # @args: options -> a hash with paramaters
# @return [Array] a list with the resultat of the search # @rtrn: a list with the resultat of the search
def list(**options) def list(options={})
result = [] result = []
search = options[:pattern].to_s.downcase search = options[:pattern].to_s.downcase
@ -229,110 +245,217 @@ module MPW
@data.each do |item| @data.each do |item|
next if item.empty? next if item.empty?
next unless group.empty? || group.eql?(item.group.to_s.downcase) next if not group.empty? and not group.eql?(item.group.to_s.downcase)
host = item.host.to_s.downcase host = item.host.to_s.downcase
comment = item.comment.to_s.downcase comment = item.comment.to_s.downcase
next unless host =~ /^.*#{search}.*$/ || comment =~ /^.*#{search}.*$/ if not host =~ /^.*#{search}.*$/ and not comment =~ /^.*#{search}.*$/
next
end
result.push(item) result.push(item)
end end
result return result
end end
# Search an item with an id # Search in some csv data
# @param id [String]the id item # @args: id -> the id item
# @return [Item] an item or nil # @rtrn: a row with the result of the search
def search_by_id(id) def search_by_id(id)
@data.each do |item| @data.each do |item|
return item if item.id == id return item if item.id == id
end end
nil return nil
end end
# Set a new opt key # Get last sync
# @param id [String] the item id def get_last_sync
# @param key [String] the new key return @config['last_sync'].to_i
rescue
return 0
end
# Sync data with remote file
# @args: force -> force the sync
def sync(force=false)
return if @config.empty? or @config['protocol'].to_s.empty?
return if get_last_sync + 300 > Time.now.to_i and not force
tmp_file = "#{@wallet_file}.sync"
case @config['protocol']
when 'sftp', 'scp', 'ssh'
require "mpw/sync/ssh"
sync = SyncSSH.new(@config)
when 'ftp'
require 'mpw/sync/ftp'
sync = SyncFTP.new(@config)
else
raise I18n.t('error.sync.unknown_type')
end
sync.connect
sync.get(tmp_file)
remote = MPW.new(@key, tmp_file, @gpg_pass, @gpg_exe)
remote.read_data
File.unlink(tmp_file) if File.exist?(tmp_file)
return if remote.get_last_sync == @config['last_update']
if not remote.to_s.empty?
@data.each do |item|
update = false
remote.list.each do |r|
next if item.id != r.id
# Update item
if item.last_edit < r.last_edit
item.update(group: r.group,
host: r.host,
protocol: r.protocol,
user: r.user,
port: r.port,
comment: r.comment
)
set_password(item.id, remote.get_password(item.id))
end
r.delete
update = true
break
end
# Remove an old item
if not update and item.last_sync.to_i < get_last_sync and item.last_edit < get_last_sync
item.delete
end
end
end
# Add item
remote.list.each do |r|
next if r.last_edit <= get_last_sync
item = Item.new(id: r.id,
group: r.group,
host: r.host,
protocol: r.protocol,
user: r.user,
port: r.port,
comment: r.comment,
created: r.created,
last_edit: r.last_edit
)
set_password(item.id, remote.get_password(item.id))
add(item)
end
remote = nil
@data.each do |item|
item.set_last_sync
end
@config['last_sync'] = Time.now.to_i
write_data
sync.update(@wallet_file)
rescue Exception => e
File.unlink(tmp_file) if File.exist?(tmp_file)
raise "#{I18n.t('error.sync.general')}\n#{e}"
end
# Set an opt key
# args: id -> the item id
# key -> the new key
def set_otp_key(id, key) def set_otp_key(id, key)
@otp_keys[id] = encrypt(key.to_s) unless key.to_s.empty? if not key.to_s.empty?
@otp_keys[id] = encrypt(key.to_s)
end
end end
# Get an opt key # Get an opt key
# @param id [String] the item id # args: id -> the item id
# key -> the new key
def get_otp_key(id) def get_otp_key(id)
@otp_keys.key?(id) ? decrypt(@otp_keys[id]) : nil if @otp_keys.has_key?(id)
return decrypt(@otp_keys[id])
else
return nil
end
end end
# Get an otp code # Get an otp code
# @param id [String] the item id # @args: id -> the item id
# @return [String] an otp code # @rtrn: an otp code
def get_otp_code(id) def get_otp_code(id)
@otp_keys.key?(id) ? ROTP::TOTP.new(decrypt(@otp_keys[id])).now : 0 if not @otp_keys.has_key?(id)
return 0
else
return ROTP::TOTP.new(decrypt(@otp_keys[id])).now
end
end end
# Get remaining time before expire otp code # Get remaining time before expire otp code
# @return [Integer] time in seconde # @rtrn: return time in seconde
def get_otp_remaining_time def get_otp_remaining_time
(Time.now.utc.to_i / 30 + 1) * 30 - Time.now.utc.to_i return (Time.now.utc.to_i / 30 + 1) * 30 - Time.now.utc.to_i
end end
# Generate a random password # Generate a random password
# @param options [Hash] :length, :special, :alpha, :numeric # @args: options -> :length, :special, :alpha, :numeric
# @return [String] a random string # @rtrn: a random string
def self.password(**options) def self.password(options={})
length = if not options.include?(:length) or options[:length].to_i <= 0
if !options.include?(:length) || options[:length].to_i <= 0 length = 8
8 elsif options[:length].to_i >= 32768
elsif options[:length].to_i >= 32_768 length = 32768
32_768
else else
options[:length].to_i length = options[:length].to_i
end end
chars = [] chars = []
chars += [*('!'..'?')] - [*('0'..'9')] if options[:special] chars += [*('!'..'?')] - [*('0'..'9')] if options.include?(:special)
chars += [*('A'..'Z'), *('a'..'z')] if options[:alpha] chars += [*('A'..'Z'),*('a'..'z')] if options.include?(:alpha)
chars += [*('0'..'9')] if options[:numeric] chars += [*('0'..'9')] if options.include?(:numeric)
chars = [*('A'..'Z'), *('a'..'z'), *('0'..'9')] if chars.empty? chars = [*('A'..'Z'),*('a'..'z'),*('0'..'9')] if chars.empty?
result = '' result = ''
length.times do while length > 62 do
result << chars.sample result << chars.sample(62).join
length -= 62
end end
result << chars.sample(length).join
result return result
end end
private
# Decrypt a gpg file # Decrypt a gpg file
# @param data [String] data to decrypt # @args: data -> string to decrypt
# @return [String] data decrypted private
def decrypt(data) def decrypt(data)
return nil if data.to_s.empty? return nil if data.to_s.empty?
password =
if /^(1\.[0-9.]+|2\.0)(\.[0-9]+)?/ =~ GPGME::Engine.info.first.version || @pinmode
{ password: @gpg_pass }
else
{ password: @gpg_pass,
pinentry_mode: GPGME::PINENTRY_MODE_LOOPBACK }
end
crypto = GPGME::Crypto.new(armor: true) crypto = GPGME::Crypto.new(armor: true)
crypto
.decrypt(data, password) return crypto.decrypt(data, password: @gpg_pass).read.force_encoding('utf-8')
.read.force_encoding('utf-8') rescue Exception => e
rescue => e
raise "#{I18n.t('error.gpg_file.decrypt')}\n#{e}" raise "#{I18n.t('error.gpg_file.decrypt')}\n#{e}"
end end
# Encrypt a file # Encrypt a file
# @param data [String] data to encrypt # args: data -> string to encrypt
# @return [String] data encrypted private
def encrypt(data) def encrypt(data)
recipients = [] recipients = []
crypto = GPGME::Crypto.new(armor: true, always_trust: true) crypto = GPGME::Crypto.new(armor: true, always_trust: true)
@ -343,9 +466,10 @@ module MPW
recipients.push(key) recipients.push(key)
end end
crypto.encrypt(data, recipients: recipients).read return crypto.encrypt(data, recipients: recipients).read
rescue => e rescue Exception => e
raise "#{I18n.t('error.gpg_file.encrypt')}\n#{e}" raise "#{I18n.t('error.gpg_file.encrypt')}\n#{e}"
end end
end
end
end end

68
lib/mpw/sync/ftp.rb Normal file
View file

@ -0,0 +1,68 @@
#!/usr/bin/ruby
# MPW is a software to crypt and manage your passwords
# Copyright (C) 2016 Adrien Waksberg <mpw@yae.im>
#
# 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, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require 'i18n'
require 'net/ftp'
module MPW
class FTP
# Constructor
# @args: config -> the config
def initialize(config)
@host = config['host']
@user = config['user']
@password = config['password']
@path = config['path']
@port = config['port'].instance_of?(Integer) ? 22 : config['port']
end
# Connect to server
def connect
Net::FTP.open(@host) do |ftp|
ftp.login(@user, @password)
break
end
rescue Exception => e
raise "#{I18n.t('error.sync.connection')}\n#{e}"
end
# Get data on server
# @args: file_tmp -> the path where download the file
def get(file_tmp)
Net::FTP.open(@host) do |ftp|
ftp.login(@user, @password)
ftp.gettextfile(@path, file_tmp)
end
rescue Exception => e
raise "#{I18n.t('error.sync.download')}\n#{e}"
end
# Update the remote data
# @args: file_gpg -> the data to send on server
def update(file_gpg)
Net::FTP.open(@host) do |ftp|
ftp.login(@user, @password)
ftp.puttextfile(file_gpg, @path)
end
rescue Exception => e
raise "#{I18n.t('error.sync.upload')}\n#{e}"
end
end
end

67
lib/mpw/sync/ssh.rb Normal file
View file

@ -0,0 +1,67 @@
#!/usr/bin/ruby
# MPW is a software to crypt and manage your passwords
# Copyright (C) 2016 Adrien Waksberg <mpw@yae.im>
#
# 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, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require 'i18n'
require 'net/ssh'
require 'net/sftp'
module MPW
class SyncSSH
# Constructor
# @args: config -> the config
def initialize(config)
@host = config['host']
@user = config['user']
@password = config['password']
@path = config['path']
@port = config['port'].instance_of?(Integer) ? 22 : config['port']
end
# Connect to server
def connect
Net::SSH.start(@host, @user, password: @password, port: @port) do
break
end
rescue Exception => e
raise "#{I18n.t('error.sync.connection')}\n#{e}"
end
# Get data on server
# @args: file_tmp -> the path where download the file
def get(file_tmp)
Net::SFTP.start(@host, @user, password: @password, port: @port) do |sftp|
sftp.lstat(@path) do |response|
sftp.download!(@path, file_tmp) if response.ok?
end
end
rescue Exception => e
raise "#{I18n.t('error.sync.download')}\n#{e}"
end
# Update the remote data
# @args: file_gpg -> the data to send on server
def update(file_gpg)
Net::SFTP.start(@host, @user, password: @password, port: @port) do |sftp|
sftp.upload!(file_gpg, @path)
end
rescue Exception => e
raise "#{I18n.t('error.sync.upload')}\n#{e}"
end
end
end

View file

@ -1,3 +1,4 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__) lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
@ -11,18 +12,18 @@ Gem::Specification.new do |spec|
spec.homepage = 'https://github.com/nishiki/manage-password' spec.homepage = 'https://github.com/nishiki/manage-password'
spec.license = 'GPL-2.0' spec.license = 'GPL-2.0'
spec.files = %x(git ls-files -z).split("\x0") spec.files = `git ls-files -z`.split("\x0")
spec.executables = ['mpw'] spec.executables = ['mpw']
spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ['lib'] spec.require_paths = ['lib']
spec.required_ruby_version = '>= 2.1' spec.add_dependency "i18n", "~> 0.7", ">= 0.7.0"
spec.add_dependency "gpgme", "~> 2.0", ">= 2.0.12"
spec.add_dependency 'i18n', '~> 0.9', '>= 0.9.1' spec.add_dependency "highline", "~> 1.7", ">= 1.7.8"
spec.add_dependency 'gpgme', '~> 2.0', '>= 2.0.14' spec.add_dependency "locale", "~> 2.1", ">= 2.1.2"
spec.add_dependency 'highline', '~> 1.7', '>= 1.7.8' spec.add_dependency "colorize", "~> 0.8", ">= 0.8.1"
spec.add_dependency 'locale', '~> 2.1', '>= 2.1.2' spec.add_dependency "net-ssh", "~> 3.2", ">= 3.2.0"
spec.add_dependency 'colorize', '~> 0.8', '>= 0.8.1' spec.add_dependency "net-sftp", "~> 2.1", ">= 2.1.2"
spec.add_dependency 'clipboard', '~> 1.1', '>= 1.1.1' spec.add_dependency "clipboard", "~> 1.1", ">= 1.1.1"
spec.add_dependency 'rotp', '~> 3.3', '>= 3.3.0' spec.add_dependency "rotp", "~> 3.1", ">= 3.1.0"
end end

View file

@ -1,13 +1,9 @@
--- ---
# <%= I18n.t('form.add_item.url') %> host: # <%= I18n.t('form.add_item.host') %>
url: <%= options[:url] %> user: # <%= I18n.t('form.add_item.login') %>
# <%= I18n.t('form.add_item.login') %> group: # <%= I18n.t('form.add_item.group') %>
user: <%= options[:user] %> protocol: # <%= I18n.t('form.add_item.protocol') %><% if not password %>
# <%= I18n.t('form.add_item.group') %> password: # <%= I18n.t('form.add_item.password') %><% end %>
group: <%= options[:group] %><% unless password %> port: # <%= I18n.t('form.add_item.port') %>
# <%= I18n.t('form.add_item.password') %> comment: # <%= I18n.t('form.add_item.comment') %>
password:<% end %> otp_key: # <%= I18n.t('form.add_item.otp_key') %>
# <%= I18n.t('form.add_item.comment') %>
comment: <%= options[:comment] %>
# <%= I18n.t('form.add_item.otp_key') %>
otp_key: <%= options[:otp] %>

9
templates/setup_form.erb Normal file
View file

@ -0,0 +1,9 @@
---
# <%= I18n.t('form.setup_config.lang') %>
language: <%= @config.lang %>
# <%= I18n.t('form.setup_config.gpg_key') %>
gpg_key: <%= @config.key %>
# <%= I18n.t('form.setup_config.wallet_dir') %>
wallet_dir: <%= @config.config_dir %>
# <%= I18n.t('form.setup_config.gpg_exe') %>
gpg_exe: <%= @config.gpg_exe %>

View file

@ -1,13 +1,17 @@
--- ---
# <%= I18n.t('form.update_item.url') %> # <%= I18n.t('form.update_item.host') %>
host: <% if options[:url] %><%= options[:url] %><% else %><%= item.url %><% end %> host: <%= item.host %>
# <%= I18n.t('form.update_item.login') %> # <%= I18n.t('form.update_item.login') %>
user: <% if options[:user] %><%= options[:user] %><% else %><%= item.user %><% end %><% unless password %> user: <%= item.user %>
# <%= I18n.t('form.update_item.password') %> # <%= I18n.t('form.update_item.password') %>
password: <% end %> password:
# <%= I18n.t('form.update_item.group') %> # <%= I18n.t('form.update_item.group') %>
group: <% if options[:group] %><%= options[:group] %><% else %><%= item.group %><% end %> group: <%= item.group %>
# <%= I18n.t('form.update_item.protocol') %>
protocol: <%= item.protocol %>
# <%= I18n.t('form.update_item.port') %>
port: <%= item.port %>
# <%= I18n.t('form.update_item.otp_key') %> # <%= I18n.t('form.update_item.otp_key') %>
otp_key: <% if options[:otp_key] %><%= options[:otp_key] %><% end %> opt_key:
# <%= I18n.t('form.update_item.comment') %> # <%= I18n.t('form.update_item.comment') %>
comment: <% if options[:comment] %><%= options[:comment] %><% else %><%= item.comment %><% end %> comment: <%= item.comment %>

View file

@ -1,16 +0,0 @@
---
1:
url: https://fric.com
user: 230403
group: Bank
password: 5XdiTQOubRDw9B0aJoMlcEyL
otp_key: 330223432
comment: I love my bank
2:
url: https://assurance.com:443
user: user_2132
host: assurance.com
group: Assurance
password: DMyK6B3v4bWO52VzU7aTHIem
otp_key:
comment:

View file

@ -1,31 +1,28 @@
add: add_new:
url: 'https://example.com:8080' group: 'test_group'
group: 'Bank' host: 'test_host'
host: 'example.com' protocol: 'test_protocol'
protocol: 'https' user: 'test_user'
user: 'admin' password: 'test_password'
password: 'VmfnCN6pPIqgRIbc' port: '42'
port: '8080' comment: 'test_comment'
comment: 'the website'
import: add_existing:
id: 'TEST-ID-XXXXX' id: 'TEST-ID-XXXXX'
url: 'https://gogole.com:8081/toto' group: 'test_group_existing'
group: 'Cloud' host: 'test_host_existing'
host: 'gogole.com' protocol: 'test_protocol_existing'
protocol: 'https' user: 'test_user_existing'
user: 'gg-2304' password: 'test_password_existing'
password: 'TITl0kV9CDDa9sVK' port: '44'
port: '8081' comment: 'test_comment_existing'
comment: 'My little servers'
created: 1386752948 created: 1386752948
update: update:
url: 'ssh://example2.com:2222' group: 'test_group_update'
group: 'Assurance' host: 'test_host_update'
host: 'example2.com' protocol: 'test_protocol_update'
protocol: 'ssh' user: 'test_user_update'
user: 'root' password: 'test_password_update'
password: 'kbSrbv4WlMaVxaZ7' port: '43'
port: '2222' comment: 'test_comment_update'
comment: 'i love ssh'

View file

@ -1,4 +0,0 @@
uuid,group,title,url,user,password,notes
49627979-e393-48c4-49ca-1cf66603238e,Bank,Fric,http://fric.com,12345,secret,money money
49627979-e393-48c4-49ca-1cf66603238f,,My little server,server.com,secret2,
49627979-e393-48c4-49ca-1cf66603238g,Cloud,,ssh://fric.com:4333,username,secret,bastion

View file

@ -1,3 +0,0 @@
"Group","Title","Username","Password","URL","Notes"
"Racine","Bank","123456","ywcExJW8qmBVTSyi","http://bank.com/login","My little bank"
"Racine/Cloud","GAFAM","wesh","superpassword","localhost.local",""

View file

@ -1,35 +0,0 @@
---
1:
host: fric.com
user: 12345
group: Bank
password: secret
protocol: http
port:
otp_key:
comment: Fric money money
last_edit: 1487623641
created: 1485729356
2:
host: server.com
user: sercret2
group:
password:
protocol:
port: 4222
otp_key:
comment: My little server
last_edit: 1487623641
created: 1485729356
3:
host: fric.com
user: username
group: Cloud
password:
protocol: ssh
port: 4333
otp_key:
comment: bastion
last_edit: 1487623641
created: 1485729356

View file

@ -1,21 +0,0 @@
require 'fileutils'
require 'gpgme'
FileUtils.rm_rf("#{Dir.home}/.config/mpw")
FileUtils.rm_rf("#{Dir.home}/.gnupg")
param = ''
param << '<GnupgKeyParms format="internal">' + "\n"
param << "Key-Type: RSA\n"
param << "Key-Length: 512\n"
param << "Subkey-Type: ELG-E\n"
param << "Subkey-Length: 512\n"
param << "Name-Real: test\n"
param << "Name-Comment: test\n"
param << "Name-Email: test2@example.com\n"
param << "Expire-Date: 0\n"
param << "Passphrase: password\n"
param << "</GnupgKeyParms>\n"
ctx = GPGME::Ctx.new
ctx.genkey(param, nil, nil)

1
test/test.sh Normal file
View file

@ -0,0 +1 @@
echo "test\ntest\n" | ruby ./bin/mpw config --init test@test.com

11
test/test2.rb Normal file
View file

@ -0,0 +1,11 @@
require 'open3'
Open3.popen3("./bin/mpw config --init test@test.com") do |stdin, stdout, stderr, thread|
stdin.puts 'test'
stdin.puts 'test'
end
Open3.popen3("./bin/mpw list") do |stdin, stdout, stderr, thread|
stdin.puts 'test'
puts stdout
end

View file

@ -1,256 +0,0 @@
require 'i18n'
require 'test/unit'
class TestConfig < Test::Unit::TestCase
def setup
if defined?(I18n.enforce_available_locales)
I18n.enforce_available_locales = true
end
I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
I18n.load_path = ["#{File.expand_path('../../i18n', __FILE__)}/en.yml"]
I18n.locale = :en
@password = 'password'
@fixtures = YAML.load_file('./test/files/fixtures.yml')
@gpg_key = 'test@example.com'
end
def test_00_init_config
output = %x(
echo "#{@password}\n#{@password}" | mpw config \
--init #{@gpg_key} \
2>/dev/null
)
assert_match(I18n.t('form.setup_config.valid'), output)
assert_match(I18n.t('form.setup_gpg_key.valid'), output)
end
def test_01_add_item
data = @fixtures['add']
output = %x(
echo #{@password} | mpw add \
--url #{data['url']} \
--user #{data['user']} \
--comment '#{data['comment']}' \
--group #{data['group']} \
--random \
2>/dev/null
)
assert_match(I18n.t('form.add_item.valid'), output)
output = %x(echo #{@password} | mpw list 2>/dev/null)
assert_match(%r{#{data['protocol']}://.+#{data['host']}.+:#{data['port']}}, output)
assert_match(data['user'], output)
assert_match(data['comment'], output)
assert_match(data['group'], output)
end
def test_02_search
data = @fixtures['add']
output = %x(echo #{@password} | mpw list --group #{data['group']} 2>/dev/null)
assert_match(%r{#{data['protocol']}://.+#{data['host']}.+:#{data['port']}}, output)
output = %x(echo #{@password} | mpw list --pattern #{data['host']} 2>/dev/null)
assert_match(%r{#{data['protocol']}://.+#{data['host']}.+:#{data['port']}}, output)
output = %x(echo #{@password} | mpw list --pattern #{data['comment']} 2>/dev/null)
assert_match(%r{#{data['protocol']}://.+#{data['host']}.+:#{data['port']}}, output)
output = %x(echo #{@password} | mpw list --group R1Pmfbp626TFpjlr 2>/dev/null)
assert_match(I18n.t('display.nothing'), output)
output = %x(echo #{@password} | mpw list --pattern h1IfnKqamaGM9oEX 2>/dev/null)
assert_match(I18n.t('display.nothing'), output)
end
def test_03_update_item
data = @fixtures['update']
output = %x(
echo #{@password} | mpw update \
-p #{@fixtures['add']['host']} \
--url #{data['url']} \
--user #{data['user']} \
--comment '#{data['comment']}' \
--new-group #{data['group']} \
2>/dev/null
)
assert_match(I18n.t('form.update_item.valid'), output)
output = %x(echo #{@password} | mpw list 2>/dev/null)
assert_match(%r{#{data['protocol']}://.+#{data['host']}.+:#{data['port']}}, output)
assert_match(data['user'], output)
assert_match(data['comment'], output)
assert_match(data['group'], output)
end
def test_04_delete_item
output = %x(
echo "#{@password}\ny" | mpw delete \
-p #{@fixtures['update']['host']} \
2>/dev/null
)
assert_match(I18n.t('form.delete_item.valid'), output)
output = %x(echo #{@password} | mpw list 2>/dev/null)
assert_match(I18n.t('display.nothing'), output)
end
def test_05_import_export
file_import = './test/files/fixtures-import.yml'
file_export = '/tmp/test-mpw.yml'
output = %x(echo #{@password} | mpw import --file #{file_import} 2>/dev/null)
assert_match(I18n.t('form.import.valid', file: file_import), output)
output = %x(echo #{@password} | mpw export --file #{file_export} 2>/dev/null)
assert_match(I18n.t('form.export.valid', file: file_export), output)
assert(File.exist?(file_export))
assert_equal(YAML.load_file(file_export).length, 2)
YAML.load_file(file_import).each_value do |import|
error = true
YAML.load_file(file_export).each_value do |export|
next if import['url'] != export['url']
%w[user group password protocol port otp_key comment].each do |key|
assert_equal(import[key].to_s, export[key].to_s)
end
error = false
break
end
assert(!error)
end
end
def test_06_copy
data = YAML.load_file('./test/files/fixtures-import.yml')[2]
output = %x(
echo "#{@password}\np\nq" | mpw copy \
--disable-clipboard \
-p #{data['host']} \
2>/dev/null
)
assert_match(data['password'], output)
end
def test_07_setup_wallet
gpg_key = 'test2@example.com'
output = %x(echo #{@password} | mpw wallet --add-gpg-key #{gpg_key} 2>/dev/null)
assert_match(I18n.t('form.add_key.valid'), output)
output = %x(echo #{@password} | mpw wallet --list-keys 2>/dev/null)
assert_match("| #{@gpg_key}", output)
assert_match("| #{gpg_key}", output)
output = %x(echo #{@password} | mpw wallet --delete-gpg-key #{gpg_key} 2>/dev/null)
assert_match(I18n.t('form.delete_key.valid'), output)
output = %x(echo #{@password} | mpw wallet --list-keys 2>/dev/null)
assert_match("| #{@gpg_key}", output)
assert_no_match(/\| #{gpg_key}/, output)
output = %x(mpw wallet)
assert_match('| default', output)
output = %x(mpw wallet --path '.')
assert_match(I18n.t('form.set_wallet_path.valid'), output)
output = %x(mpw config)
assert_match(%r{path_wallet_default.+\| #{Dir.pwd}/default.mpw}, output)
assert(File.exist?("#{Dir.pwd}/default.mpw"))
output = %x(mpw wallet)
assert_match('default', output)
output = %x(mpw wallet --default-path)
assert_match(I18n.t('form.set_wallet_path.valid'), output)
output = %x(mpw config)
assert_no_match(/path_wallet_default/, output)
end
def test_08_setup_config
gpg_key = 'test2@example.com'
gpg_exe = '/usr/bin/gpg2'
wallet_dir = '/tmp'
length = 24
wallet = 'work'
output = %x(
mpw config \
--gpg-exe #{gpg_exe} \
--key #{gpg_key} \
--enable-pinmode \
--disable-alpha \
--disable-special-chars \
--disable-numeric \
--length #{length} \
--wallet-dir #{wallet_dir} \
--default-wallet #{wallet}
)
assert_match(I18n.t('form.set_config.valid'), output)
output = %x(mpw config)
assert_match(/gpg_key.+\| #{gpg_key}/, output)
assert_match(/gpg_exe.+\| #{gpg_exe}/, output)
assert_match(/pinmode.+\| true/, output)
assert_match(/default_wallet.+\| #{wallet}/, output)
assert_match(/wallet_dir.+\| #{wallet_dir}/, output)
assert_match(/password_length.+\| #{length}/, output)
%w[numeric alpha special].each do |k|
assert_match(/password_#{k}.+\| false/, output)
end
output = %x(
mpw config \
--gpg-exe '' \
--key #{@gpg_key} \
--alpha \
--special-chars \
--numeric \
--disable-pinmode
)
assert_match(I18n.t('form.set_config.valid'), output)
output = %x(mpw config)
assert_match(/gpg_key.+\| #{@gpg_key}/, output)
assert_match(/pinmode.+\| false/, output)
%w[numeric alpha special].each do |k|
assert_match(/password_#{k}.+\| true/, output)
end
end
def test_09_generate_password
length = 24
output = %x(
mpw genpwd \
--length #{length} \
--alpha
)
assert_match(/[a-zA-Z]{#{length}}/, output)
output = %x(
mpw genpwd \
--length #{length} \
--numeric
)
assert_match(/[0-9]{#{length}}/, output)
output = %x(
mpw genpwd \
--length #{length} \
--special-chars
)
assert_no_match(/[a-zA-Z0-9]/, output)
end
end

View file

@ -1,3 +1,5 @@
#!/usr/bin/ruby
require 'mpw/config' require 'mpw/config'
require 'test/unit' require 'test/unit'
require 'locale' require 'locale'
@ -18,62 +20,21 @@ class TestConfig < Test::Unit::TestCase
end end
def test_00_config def test_00_config
data = { data = { key: 'test@example.com',
gpg_key: 'test@example.com',
lang: 'en', lang: 'en',
wallet_dir: '/tmp/test', wallet_dir: '/tmp/test',
gpg_exe: '' gpg_exe: '',
} }
@config = MPW::Config.new @config = MPW::Config.new
@config.setup(data) @config.setup(data[:key], data[:lang], data[:wallet_dir], data[:gpg_exe])
@config.load_config @config.load_config
data.each do |k, v| data.each do |k,v|
assert_equal(v, @config.send(k)) assert_equal(v, @config.send(k))
end end
@config.setup_gpg_key('password', 'test@example.com', 2048) @config.setup_gpg_key('password', 'test@example.com', 2048)
assert(@config.check_gpg_key?) assert(@config.check_gpg_key?)
end end
def test_01_password
data = {
pwd_alpha: false,
pwd_numeric: false,
pwd_special: true,
pwd_length: 32
}
@config = MPW::Config.new
@config.load_config
assert_equal(@config.password[:length], 16)
assert(@config.password[:alpha])
assert(@config.password[:numeric])
assert(!@config.password[:special])
@config.setup(data)
@config.load_config
assert_equal(@config.password[:length], data[:pwd_length])
assert(!@config.password[:alpha])
assert(!@config.password[:numeric])
assert(@config.password[:special])
end
def test_02_wallet_paths
new_path = '/tmp/mpw-test'
@config = MPW::Config.new
@config.load_config
assert(!@config.wallet_paths['default'])
@config.set_wallet_path(new_path, 'default')
assert_equal(@config.wallet_paths['default'], new_path)
@config.set_wallet_path('default', 'default')
assert(!@config.wallet_paths['default'])
end
end end

View file

@ -1,79 +0,0 @@
require 'i18n'
require 'test/unit'
class TestImport < Test::Unit::TestCase
def setup
if defined?(I18n.enforce_available_locales)
I18n.enforce_available_locales = true
end
I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
I18n.load_path = ["#{File.expand_path('../../i18n', __FILE__)}/en.yml"]
I18n.locale = :en
@password = 'password'
end
def test_00_import_mpw_old
file = './test/files/import-mpw_old.txt'
format = 'mpw_old'
output = %x(
mpw import \
--file #{file} \
--format #{format} \
--wallet #{format}
)
assert_match(I18n.t('form.import.valid'), output)
output = %x(echo #{@password} | mpw list --group Bank --wallet #{format})
assert_match(%r{http://.*fric\.com.*12345.*Fric money money}, output)
output = %x(echo #{@password} | mpw list --group Cloud --wallet #{format})
assert_match(%r{ssh://.*fric\.com.*:4333.*username.*bastion}, output)
output = %x(echo #{@password} | mpw list --wallet #{format})
assert_match(/server\.com.*My little server/, output)
end
def test_01_import_gorilla
file = './test/files/import-gorilla.txt'
format = 'gorilla'
output = %x(
mpw import \
--file #{file} \
--format #{format} \
--wallet #{format}
)
assert_match(I18n.t('form.import.valid'), output)
output = %x(echo #{@password} | mpw list --group Bank --wallet #{format})
assert_match(%r{http://.*fric\.com.*12345.*Fric money money}, output)
output = %x(echo #{@password} | mpw list --group Cloud --wallet #{format})
assert_match(%r{ssh://.*fric\.com.*:4333.*username.*bastion}, output)
output = %x(echo #{@password} | mpw list --wallet #{format})
assert_match(/server\.com.*My little server/, output)
end
def test_02_import_keepass
file = './test/files/import-keepass.txt'
format = 'keepass'
output = %x(
mpw import \
--file #{file} \
--format #{format} \
--wallet #{format}
)
assert_match(I18n.t('form.import.valid'), output)
output = %x(echo #{@password} | mpw list --group 'Racine/Cloud' --wallet #{format})
assert_match(/localhost\.local.*wesh.*GAFAM/, output)
output = %x(echo #{@password} | mpw list --wallet #{format})
assert_match(%r{http://.*bank\.com.*123456.*Bank My little bank}, output)
end
end

View file

@ -1,9 +1,14 @@
#!/usr/bin/ruby
require 'mpw/item' require 'mpw/item'
require 'test/unit' require 'test/unit'
require 'yaml' require 'yaml'
class TestItem < Test::Unit::TestCase class TestItem < Test::Unit::TestCase
def setup def setup
@fixture_file = 'test/files/fixtures.yml'
@fixtures = YAML.load_file(@fixture_file)
if defined?(I18n.enforce_available_locales) if defined?(I18n.enforce_available_locales)
I18n.enforce_available_locales = false I18n.enforce_available_locales = false
end end
@ -11,19 +16,21 @@ class TestItem < Test::Unit::TestCase
I18n.load_path = Dir['./i18n/cli/*.yml'] I18n.load_path = Dir['./i18n/cli/*.yml']
I18n.default_locale = :en I18n.default_locale = :en
@fixtures = YAML.load_file('./test/files/fixtures.yml')
puts
end end
def test_00_add_without_name def test_00_add_without_name
assert_raise(RuntimeError) { MPW::Item.new } assert_raise(RuntimeError){MPW::Item.new}
end end
def test_01_add def test_01_add_new
data = { data = { group: @fixtures['add_new']['group'],
group: @fixtures['add']['group'], host: @fixtures['add_new']['host'],
user: @fixtures['add']['user'], protocol: @fixtures['add_new']['protocol'],
url: @fixtures['add']['url'], user: @fixtures['add_new']['user'],
comment: @fixtures['add']['comment'] port: @fixtures['add_new']['port'],
comment: @fixtures['add_new']['comment'],
} }
item = MPW::Item.new(data) item = MPW::Item.new(data)
@ -31,23 +38,23 @@ class TestItem < Test::Unit::TestCase
assert(!item.nil?) assert(!item.nil?)
assert(!item.empty?) assert(!item.empty?)
assert_equal(@fixtures['add']['url'], item.url) assert_equal(@fixtures['add_new']['group'], item.group)
assert_equal(@fixtures['add']['group'], item.group) assert_equal(@fixtures['add_new']['host'], item.host)
assert_equal(@fixtures['add']['host'], item.host) assert_equal(@fixtures['add_new']['protocol'], item.protocol)
assert_equal(@fixtures['add']['protocol'], item.protocol) assert_equal(@fixtures['add_new']['user'], item.user)
assert_equal(@fixtures['add']['user'], item.user) assert_equal(@fixtures['add_new']['port'].to_i, item.port)
assert_equal(@fixtures['add']['port'].to_i, item.port) assert_equal(@fixtures['add_new']['comment'], item.comment)
assert_equal(@fixtures['add']['comment'], item.comment)
end end
def test_02_import def test_02_add_existing
data = { data = { id: @fixtures['add_existing']['id'],
id: @fixtures['import']['id'], group: @fixtures['add_existing']['group'],
group: @fixtures['import']['group'], host: @fixtures['add_existing']['host'],
user: @fixtures['import']['user'], protocol: @fixtures['add_existing']['protocol'],
url: @fixtures['import']['url'], user: @fixtures['add_existing']['user'],
comment: @fixtures['import']['comment'], port: @fixtures['add_existing']['port'],
created: @fixtures['import']['created'] comment: @fixtures['add_existing']['comment'],
created: @fixtures['add_existing']['created'],
} }
item = MPW::Item.new(data) item = MPW::Item.new(data)
@ -55,23 +62,23 @@ class TestItem < Test::Unit::TestCase
assert(!item.nil?) assert(!item.nil?)
assert(!item.empty?) assert(!item.empty?)
assert_equal(@fixtures['import']['id'], item.id) assert_equal(@fixtures['add_existing']['id'], item.id)
assert_equal(@fixtures['import']['url'], item.url) assert_equal(@fixtures['add_existing']['group'], item.group)
assert_equal(@fixtures['import']['group'], item.group) assert_equal(@fixtures['add_existing']['host'], item.host)
assert_equal(@fixtures['import']['host'], item.host) assert_equal(@fixtures['add_existing']['protocol'], item.protocol)
assert_equal(@fixtures['import']['protocol'], item.protocol) assert_equal(@fixtures['add_existing']['user'], item.user)
assert_equal(@fixtures['import']['user'], item.user) assert_equal(@fixtures['add_existing']['port'].to_i, item.port)
assert_equal(@fixtures['import']['port'].to_i, item.port) assert_equal(@fixtures['add_existing']['comment'], item.comment)
assert_equal(@fixtures['import']['comment'], item.comment) assert_equal(@fixtures['add_existing']['created'], item.created)
assert_equal(@fixtures['import']['created'], item.created)
end end
def test_03_update def test_03_update
data = { data = { group: @fixtures['add_new']['group'],
group: @fixtures['add']['group'], host: @fixtures['add_new']['host'],
user: @fixtures['add']['user'], protocol: @fixtures['add_new']['protocol'],
url: @fixtures['add']['url'], user: @fixtures['add_new']['user'],
comment: @fixtures['add']['comment'] port: @fixtures['add_new']['port'],
comment: @fixtures['add_new']['comment'],
} }
item = MPW::Item.new(data) item = MPW::Item.new(data)
@ -82,11 +89,12 @@ class TestItem < Test::Unit::TestCase
created = item.created created = item.created
last_edit = item.last_edit last_edit = item.last_edit
data = { data = { group: @fixtures['update']['group'],
group: @fixtures['update']['group'], host: @fixtures['update']['host'],
protocol: @fixtures['update']['protocol'],
user: @fixtures['update']['user'], user: @fixtures['update']['user'],
url: @fixtures['update']['url'], port: @fixtures['update']['port'],
comment: @fixtures['update']['comment'] comment: @fixtures['update']['comment'],
} }
sleep(1) sleep(1)
@ -94,7 +102,6 @@ class TestItem < Test::Unit::TestCase
assert(!item.empty?) assert(!item.empty?)
assert_equal(@fixtures['update']['url'], item.url)
assert_equal(@fixtures['update']['group'], item.group) assert_equal(@fixtures['update']['group'], item.group)
assert_equal(@fixtures['update']['host'], item.host) assert_equal(@fixtures['update']['host'], item.host)
assert_equal(@fixtures['update']['protocol'], item.protocol) assert_equal(@fixtures['update']['protocol'], item.protocol)
@ -107,11 +114,12 @@ class TestItem < Test::Unit::TestCase
end end
def test_05_update_one_element def test_05_update_one_element
data = { data = { group: @fixtures['add_new']['group'],
group: @fixtures['add']['group'], host: @fixtures['add_new']['host'],
user: @fixtures['add']['user'], protocol: @fixtures['add_new']['protocol'],
url: @fixtures['add']['url'], user: @fixtures['add_new']['user'],
comment: @fixtures['add']['comment'] port: @fixtures['add_new']['port'],
comment: @fixtures['add_new']['comment'],
} }
item = MPW::Item.new(data) item = MPW::Item.new(data)
@ -122,25 +130,25 @@ class TestItem < Test::Unit::TestCase
last_edit = item.last_edit last_edit = item.last_edit
sleep(1) sleep(1)
item.update(comment: @fixtures['update']['comment']) assert(item.update({comment: @fixtures['update']['comment']}))
assert_equal(@fixtures['add']['url'], item.url) assert_equal(@fixtures['add_new']['group'], item.group)
assert_equal(@fixtures['add']['group'], item.group) assert_equal(@fixtures['add_new']['host'], item.host)
assert_equal(@fixtures['add']['host'], item.host) assert_equal(@fixtures['add_new']['protocol'], item.protocol)
assert_equal(@fixtures['add']['protocol'], item.protocol) assert_equal(@fixtures['add_new']['user'], item.user)
assert_equal(@fixtures['add']['user'], item.user) assert_equal(@fixtures['add_new']['port'].to_i, item.port)
assert_equal(@fixtures['add']['port'].to_i, item.port)
assert_equal(@fixtures['update']['comment'], item.comment) assert_equal(@fixtures['update']['comment'], item.comment)
assert_not_equal(last_edit, item.last_edit) assert_not_equal(last_edit, item.last_edit)
end end
def test_05_delete def test_05_delete
data = { data = { group: @fixtures['add_new']['group'],
group: @fixtures['add']['group'], host: @fixtures['add_new']['host'],
user: @fixtures['add']['user'], protocol: @fixtures['add_new']['protocol'],
url: @fixtures['add']['url'], user: @fixtures['add_new']['user'],
comment: @fixtures['add']['comment'] port: @fixtures['add_new']['port'],
comment: @fixtures['add_new']['comment'],
} }
item = MPW::Item.new(data) item = MPW::Item.new(data)
@ -153,7 +161,6 @@ class TestItem < Test::Unit::TestCase
assert(item.empty?) assert(item.empty?)
assert_equal(nil, item.id) assert_equal(nil, item.id)
assert_equal(nil, item.url)
assert_equal(nil, item.group) assert_equal(nil, item.group)
assert_equal(nil, item.host) assert_equal(nil, item.host)
assert_equal(nil, item.protocol) assert_equal(nil, item.protocol)

View file

@ -1,3 +1,5 @@
#!/usr/bin/ruby
require 'mpw/mpw' require 'mpw/mpw'
require 'mpw/item' require 'mpw/item'
require 'test/unit' require 'test/unit'
@ -6,6 +8,8 @@ require 'csv'
class TestMPW < Test::Unit::TestCase class TestMPW < Test::Unit::TestCase
def setup def setup
fixture_file = './test/files/fixtures.yml'
wallet_file = 'default.gpg' wallet_file = 'default.gpg'
key = 'test@example.com' key = 'test@example.com'
password = 'password' password = 'password'
@ -15,7 +19,7 @@ class TestMPW < Test::Unit::TestCase
end end
@mpw = MPW::MPW.new(key, wallet_file, password) @mpw = MPW::MPW.new(key, wallet_file, password)
@fixtures = YAML.load_file('./test/files/fixtures.yml') @fixtures = YAML.load_file(fixture_file)
end end
def test_00_decrypt_empty_file def test_00_decrypt_empty_file
@ -29,11 +33,12 @@ class TestMPW < Test::Unit::TestCase
end end
def test_02_add_item def test_02_add_item
data = { data = { group: @fixtures['add_new']['group'],
group: @fixtures['add']['group'], host: @fixtures['add_new']['host'],
user: @fixtures['add']['user'], protocol: @fixtures['add_new']['protocol'],
url: @fixtures['add']['url'], user: @fixtures['add_new']['user'],
comment: @fixtures['add']['comment'] port: @fixtures['add_new']['port'],
comment: @fixtures['add_new']['comment'],
} }
item = MPW::Item.new(data) item = MPW::Item.new(data)
@ -43,12 +48,12 @@ class TestMPW < Test::Unit::TestCase
@mpw.read_data @mpw.read_data
@mpw.add(item) @mpw.add(item)
@mpw.set_password(item.id, @fixtures['add']['password']) @mpw.set_password(item.id, @fixtures['add_new']['password'])
assert_equal(1, @mpw.list.length) assert_equal(1, @mpw.list.length)
item = @mpw.list[0] item = @mpw.list[0]
@fixtures['add'].each do |k, v| @fixtures['add_new'].each do |k,v|
if k == 'password' if k == 'password'
assert_equal(v, @mpw.get_password(item.id)) assert_equal(v, @mpw.get_password(item.id))
else else
@ -64,7 +69,7 @@ class TestMPW < Test::Unit::TestCase
assert_equal(1, @mpw.list.length) assert_equal(1, @mpw.list.length)
item = @mpw.list[0] item = @mpw.list[0]
@fixtures['add'].each do |k, v| @fixtures['add_new'].each do |k,v|
if k == 'password' if k == 'password'
assert_equal(v, @mpw.get_password(item.id)) assert_equal(v, @mpw.get_password(item.id))
else else
@ -75,9 +80,13 @@ class TestMPW < Test::Unit::TestCase
def test_04_delete_item def test_04_delete_item
@mpw.read_data @mpw.read_data
assert_equal(1, @mpw.list.length) assert_equal(1, @mpw.list.length)
@mpw.list.each(&:delete) @mpw.list.each do |item|
item.delete
end
assert_equal(0, @mpw.list.length) assert_equal(0, @mpw.list.length)
@mpw.write_data @mpw.write_data
@ -87,11 +96,12 @@ class TestMPW < Test::Unit::TestCase
@mpw.read_data @mpw.read_data
@fixtures.each_value do |v| @fixtures.each_value do |v|
data = { data = { group: v['group'],
group: v['group'], host: v['host'],
protocol: v['protocol'],
user: v['user'], user: v['user'],
url: v['url'], port: v['port'],
comment: v['comment'] comment: v['comment'],
} }
item = MPW::Item.new(data) item = MPW::Item.new(data)
@ -104,27 +114,8 @@ class TestMPW < Test::Unit::TestCase
end end
assert_equal(3, @mpw.list.length) assert_equal(3, @mpw.list.length)
assert_equal(1, @mpw.list(group: @fixtures['add']['group']).length) assert_equal(1, @mpw.list(group: @fixtures['add_new']['group']).length)
assert_equal(1, @mpw.list(pattern: 'gogole').length) assert_equal(1, @mpw.list(pattern: 'existing').length)
assert_equal(2, @mpw.list(pattern: 'example[2\.]').length) assert_equal(2, @mpw.list(pattern: 'host_[eu]').length)
end
def test_06_add_gpg_key
@mpw.read_data
@mpw.add_key('test2@example.com')
assert_equal(2, @mpw.list_keys.length)
@mpw.write_data
end
def test_07_delete_gpg_key
@mpw.read_data
assert_equal(2, @mpw.list_keys.length)
@mpw.delete_key('test2@example.com')
assert_equal(1, @mpw.list_keys.length)
@mpw.write_data
end end
end end

View file

@ -1,29 +0,0 @@
require 'yaml'
require 'test/unit'
class TestTranslate < Test::Unit::TestCase
def test_00_check_translate
missing = 0
Dir.glob('i18n/*.yml').each do |yaml|
lang = File.basename(yaml, '.yml')
translate = YAML.load_file(yaml)
%x(grep -r -o "I18n.t('.*)" bin/ lib/ | cut -d"'" -f2).each_line do |line|
begin
t = translate[lang]
line.strip.split('.').each do |v|
t = t[v]
end
assert(!t.to_s.empty?)
rescue
puts "#{lang}.#{line}"
missing = 1
end
end
end
assert_equal(0, missing)
end
end

5
test/tests.rb Normal file
View file

@ -0,0 +1,5 @@
#!/usr/bin/ruby
require_relative 'test_config.rb'
require_relative 'test_item.rb'
require_relative 'test_mpw.rb'