mirror of
https://github.com/strongbox-password-safe/browser-autofill.git
synced 2026-05-20 20:40:37 +00:00
Hello, World!
This commit is contained in:
+661
@@ -0,0 +1,661 @@
|
||||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3, 19 November 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU Affero General Public License is a free, copyleft license for
|
||||
software and other kinds of works, specifically designed to ensure
|
||||
cooperation with the community in the case of network server software.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
our General Public Licenses are intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
Developers that use our General Public Licenses protect your rights
|
||||
with two steps: (1) assert copyright on the software, and (2) offer
|
||||
you this License which gives you legal permission to copy, distribute
|
||||
and/or modify the software.
|
||||
|
||||
A secondary benefit of defending all users' freedom is that
|
||||
improvements made in alternate versions of the program, if they
|
||||
receive widespread use, become available for other developers to
|
||||
incorporate. Many developers of free software are heartened and
|
||||
encouraged by the resulting cooperation. However, in the case of
|
||||
software used on network servers, this result may fail to come about.
|
||||
The GNU General Public License permits making a modified version and
|
||||
letting the public access it on a server without ever releasing its
|
||||
source code to the public.
|
||||
|
||||
The GNU Affero General Public License is designed specifically to
|
||||
ensure that, in such cases, the modified source code becomes available
|
||||
to the community. It requires the operator of a network server to
|
||||
provide the source code of the modified version running there to the
|
||||
users of that server. Therefore, public use of a modified version, on
|
||||
a publicly accessible server, gives the public access to the source
|
||||
code of the modified version.
|
||||
|
||||
An older license, called the Affero General Public License and
|
||||
published by Affero, was designed to accomplish similar goals. This is
|
||||
a different license, not a version of the Affero GPL, but Affero has
|
||||
released a new version of the Affero GPL which permits relicensing under
|
||||
this license.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, if you modify the
|
||||
Program, your modified version must prominently offer all users
|
||||
interacting with it remotely through a computer network (if your version
|
||||
supports such interaction) an opportunity to receive the Corresponding
|
||||
Source of your version by providing access to the Corresponding Source
|
||||
from a network server at no charge, through some standard or customary
|
||||
means of facilitating copying of software. This Corresponding Source
|
||||
shall include the Corresponding Source for any work covered by version 3
|
||||
of the GNU General Public License that is incorporated pursuant to the
|
||||
following paragraph.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the work with which it is combined will remain governed by version
|
||||
3 of the GNU General Public License.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU Affero General Public License from time to time. Such new versions
|
||||
will be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU Affero General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU Affero General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU Affero General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published
|
||||
by the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If your software can interact with users remotely through a computer
|
||||
network, you should also make sure that it provides a way for users to
|
||||
get its source. For example, if your program is a web application, its
|
||||
interface could display a "Source" link that leads users to an archive
|
||||
of the code. There are many ways you could offer source, and different
|
||||
solutions will be better for different programs; see section 13 for the
|
||||
specific requirements.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
@@ -0,0 +1,73 @@
|
||||
# Strongbox Browser AutoFill Extension
|
||||
Strongbox Browser AutoFill Extension official distributions can be found on the relevant browser stores here:
|
||||
|
||||
Chrome/Chromium: https://chrome.google.com/webstore/detail/strongbox-autofill/mnilpkfepdibngheginihjpknnopchbn
|
||||
Firefox: https://addons.mozilla.org/firefox/addon/strongbox-autofill/
|
||||
|
||||
# Localization - Help Wanted
|
||||
If you would like to see Strongbox translated into your language just get in touch (support@strongboxsafe.com) and we'll get you access to our localization platform. Localization and translation is managed through the parallel Babel project. This is managed under the MIT licence to avoid issues with the Apple's App Store and ownership:
|
||||
|
||||
https://github.com/strongbox-password-safe/babel
|
||||
|
||||
Big thank you to all the localization contributors
|
||||
|
||||
- Chinese - GY & Attis & Anonymous
|
||||
- Czech - S474N
|
||||
- Dutch - Wishes to remain anonymous
|
||||
- French - Charles-Ivan Chesneau
|
||||
- German - @Slummi
|
||||
- Greek - John Spiropoulos
|
||||
- Italian - Marco Ermini
|
||||
- Japanese - Anonymous
|
||||
- Norwegian - Ole Aldric
|
||||
- Polish - Łukasz Oryński
|
||||
- Portuguese (PT-BR) - Wolfgang Marcos
|
||||
- Russian - Wishes to remain anonymous
|
||||
- Spanish - Wishes to remain anonymous
|
||||
- Swedish - Jari Häkkinen
|
||||
- Turkish - evreka
|
||||
- Ukrainian - Artem Polivanchuk
|
||||
|
||||
# License Notes (AGPL)
|
||||
This code provided here is licensed under the GNU AGPL by default, except for localization which is managed under the MIT Licence in the Babel sub project. Copyright/Ownership is held by Mark McGuill.
|
||||
|
||||
# Supporting Development
|
||||
There are several ways you can help support continuous development.
|
||||
|
||||
### App Store Purchase
|
||||
Obviously if you purchase a subscription or lifetime licence Apple's App Stores that's really helpful.
|
||||
|
||||
### Leave a Review
|
||||
If you like the app, you can always help out by leaving a *5 star review* in the App Store(s) (Apple, Mozilla or Google's stores). This is very helpful, and helps get the word out about Strongbox. If you can, please leave a positive comment too. You can review the App on Apple here:
|
||||
|
||||
Apple App Store: https://apps.apple.com/app/strongbox-password-safe/id897283731
|
||||
Chrome/Chromium: https://chrome.google.com/webstore/detail/strongbox-autofill/mnilpkfepdibngheginihjpknnopchbn
|
||||
Firefox: https://addons.mozilla.org/firefox/addon/strongbox-autofill/
|
||||
|
||||
# Help / Tech Support
|
||||
If you're having trouble, please checkout the following sources:
|
||||
|
||||
- [Online Support](https://strongboxsafe.com/support/)
|
||||
- [Twitter @StrongboxSafe](https://twitter.com/StrongboxSafe "@StrongboxSafe")
|
||||
- [Reddit r/strongbox](https://www.reddit.com/r/strongbox/ "r/strongbox")
|
||||
|
||||
Another important step is to restart your device, it's surprising how often this can fix issues.
|
||||
|
||||
# Build Issues
|
||||
The code is provided here in the spirit transparency, security and openness. Anyone can view the code and verify that everything is above board, the algorithms are correct and there are no backdoors or other malicious features present. Please do not file issues about build trouble or problems, they will be closed as "won't fix". What is here is all of the functional code used in building Strongbox Browser AutoFill, other non functional files (e.g. artwork, images, auxilliary and build configs) are not present. Translation strings files are managed in the separate Babel repository.
|
||||
|
||||
# Open Source not Open Contribution
|
||||
At the moment, we are not accepting pull requests and do not want to manage contributions from others. The code here is under the AGPL which Apple will not allow in the App Store. The code is provided here in the spirit of transparency, security and openness.
|
||||
|
||||
# Acknowledgements
|
||||
Kudos to Rony Shapiro, Bruce Schneier and all the Password Safe team for their amazing work and the original Password Safe format and application.
|
||||
|
||||
The official KeePass site is here:
|
||||
|
||||
https://keepass.info/
|
||||
|
||||
Credit to Dominik Reichl and all the KeePass team for their incredible technical skill, for coming up with a great format, and their seminal KeePass app.
|
||||
|
||||
Hats off to the KeePassXC team for their fantastic cross platform apps.
|
||||
|
||||
https://keepassxc.org/
|
||||
Generated
+12787
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,62 @@
|
||||
{
|
||||
"name": "strongbox-af-ext",
|
||||
"version": "1.0.5",
|
||||
"description": "Strongbox Browser AutoFill Extension",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"dev:chrome": "NODE_ENV=development TARGET_BROWSER=chrome webpack --watch",
|
||||
"dev:firefox": "NODE_ENV=development TARGET_BROWSER=firefox webpack --watch",
|
||||
"build:chrome": "NODE_ENV=production TARGET_BROWSER=chrome webpack",
|
||||
"build:firefox": "NODE_ENV=production TARGET_BROWSER=firefox webpack",
|
||||
"lint": "eslint . --ext .ts"
|
||||
},
|
||||
"author": "Mark McGuill",
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"devDependencies": {
|
||||
"@types/react": "^18.0.17",
|
||||
"@types/react-dom": "^18.0.6",
|
||||
"@types/webextension-polyfill": "^0.9.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.53.0",
|
||||
"@typescript-eslint/parser": "^5.53.0",
|
||||
"copy-webpack-plugin": "^11.0.0",
|
||||
"css-loader": "^6.7.1",
|
||||
"eslint": "^8.34.0",
|
||||
"eslint-config-airbnb": "^19.0.4",
|
||||
"eslint-plugin-import": "^2.27.5",
|
||||
"eslint-plugin-jsx-a11y": "^6.7.1",
|
||||
"eslint-plugin-react": "^7.32.2",
|
||||
"eslint-plugin-react-hooks": "^4.6.0",
|
||||
"html-webpack-plugin": "^5.5.0",
|
||||
"mini-css-extract-plugin": "^2.6.1",
|
||||
"ts-loader": "^9.3.1",
|
||||
"typescript": "^4.9.5",
|
||||
"webpack": "^5.74.0",
|
||||
"webpack-cli": "^4.10.0",
|
||||
"webpack-dev-server": "^4.10.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@emotion/react": "^11.10.4",
|
||||
"@emotion/styled": "^11.10.4",
|
||||
"@fontsource/roboto": "^4.5.8",
|
||||
"@mui/icons-material": "^5.10.3",
|
||||
"@mui/material": "^5.10.3",
|
||||
"otpauth": "^8.0.2",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"strip-comments": "^2.0.1",
|
||||
"tweetnacl": "^1.0.3",
|
||||
"webextension-polyfill": "^0.10.0"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"root": true,
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"plugins": [
|
||||
"@typescript-eslint"
|
||||
],
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/eslint-recommended",
|
||||
"plugin:@typescript-eslint/recommended"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,463 @@
|
||||
import { NativeAppApi } from '../Messaging/NativeAppApi';
|
||||
import {
|
||||
IconManager,
|
||||
IconState,
|
||||
} from './IconManager';
|
||||
import { AutoFillCredential } from '../Messaging/Protocol/AutoFillCredential';
|
||||
import { WellKnownField } from '../Messaging/Protocol/WellKnownField';
|
||||
import browser from 'webextension-polyfill';
|
||||
import { GetStatusResponse } from '../Messaging/Protocol/GetStatusResponse';
|
||||
import { CredentialsForUrlResponse } from '../Messaging/Protocol/CredentialsForUrlResponse';
|
||||
import { SettingsStore } from '../Settings/SettingsStore';
|
||||
import { CreateEntryResponse } from '../Messaging/Protocol/CreateEntryResponse';
|
||||
import { CreateEntryRequest } from '../Messaging/Protocol/CreateEntryRequest';
|
||||
import { GetGroupsRequest } from '../Messaging/Protocol/GetGroupsRequest';
|
||||
import { GetGroupsResponse } from '../Messaging/Protocol/GetGroupsResponse';
|
||||
import { GeneratePasswordRequest } from '../Messaging/Protocol/GeneratePasswordRequest';
|
||||
import { GeneratePasswordResponse } from '../Messaging/Protocol/GeneratePasswordResponse';
|
||||
import { GetNewEntryDefaultsRequest } from '../Messaging/Protocol/GetNewEntryDefaultsRequest';
|
||||
import { GetNewEntryDefaultsResponse } from '../Messaging/Protocol/GetNewEntryDefaultsResponse';
|
||||
import { UnlockResponse } from '../Messaging/Protocol/UnlockResponse';
|
||||
import { DatabaseSummary } from '../Messaging/Protocol/DatabaseSummary';
|
||||
import { LastKnownDatabasesItem } from '../Settings/Settings';
|
||||
import { CopyFieldResponse } from '../Messaging/Protocol/CopyFieldRequest';
|
||||
|
||||
export class BackgroundManager {
|
||||
private static instance: BackgroundManager;
|
||||
|
||||
private constructor() {
|
||||
|
||||
}
|
||||
|
||||
public static getInstance(): BackgroundManager {
|
||||
if (!BackgroundManager.instance) {
|
||||
BackgroundManager.instance = new BackgroundManager();
|
||||
}
|
||||
|
||||
return BackgroundManager.instance;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public async doSimpleStatusUpdate(): Promise<void> {
|
||||
|
||||
await this.getStatus();
|
||||
}
|
||||
|
||||
public async updatePopupIconBasedOnStatus(status: GetStatusResponse | null) {
|
||||
if (status === null) {
|
||||
await IconManager.setIcon(IconState.disconnected);
|
||||
}
|
||||
else {
|
||||
const unlockedDatabases = status.databases.filter((database) => {
|
||||
return !database.locked;
|
||||
});
|
||||
|
||||
if (unlockedDatabases.length == 0) {
|
||||
await IconManager.setIcon(IconState.allDatabasesLocked);
|
||||
} else {
|
||||
await IconManager.setIcon(IconState.good);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static async getCurrentTab(): Promise<browser.Tabs.Tab | undefined> {
|
||||
const tabs = await browser.tabs.query({
|
||||
active: true,
|
||||
currentWindow: true,
|
||||
});
|
||||
|
||||
return tabs[0];
|
||||
}
|
||||
|
||||
async getCurrentUrl(): Promise<string | undefined> {
|
||||
const tab = await BackgroundManager.getCurrentTab();
|
||||
if (!tab) {
|
||||
return;
|
||||
}
|
||||
|
||||
return tab ? tab.url : undefined;
|
||||
}
|
||||
|
||||
public async refreshCredentialsAndAutoFillIfNecessary(force = false, shouldAttemptAutoFill = false): Promise<void> {
|
||||
try {
|
||||
const tab = await BackgroundManager.getCurrentTab();
|
||||
const url = tab?.url;
|
||||
|
||||
if (!url || !tab) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (force
|
||||
|
||||
|| shouldAttemptAutoFill) {
|
||||
|
||||
|
||||
|
||||
const credentials = await this.checkForCredentialsUrl(url);
|
||||
|
||||
|
||||
|
||||
const tabID = tab.id;
|
||||
if (shouldAttemptAutoFill && tabID && credentials && credentials.length > 0) {
|
||||
|
||||
const settings = await SettingsStore.getSettings();
|
||||
|
||||
|
||||
if (tabID && (settings.autoFillImmediatelyIfOnlyASingleMatch && credentials.length == 1) ||
|
||||
(settings.autoFillImmediatelyWithFirstMatch)) {
|
||||
setTimeout(() => { this.doOnLoadFill(tabID, credentials[0]); }, 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
}
|
||||
}
|
||||
|
||||
public doOnLoadFill(tabID: number, credential: AutoFillCredential) {
|
||||
this.fillWithCredential(tabID, credential, true);
|
||||
}
|
||||
|
||||
public async autoFillCurrentTabWithFirstMatch(): Promise<void> {
|
||||
|
||||
const tab = await BackgroundManager.getCurrentTab();
|
||||
|
||||
if (!tab || !tab.id) {
|
||||
return;
|
||||
}
|
||||
|
||||
const url = tab.url;
|
||||
|
||||
if (url) {
|
||||
const results = await this.checkForCredentialsUrl(url);
|
||||
|
||||
if (results != null) {
|
||||
if (results.length > 0) {
|
||||
await this.fillWithCredential(tab.id, results[0]);
|
||||
}
|
||||
else {
|
||||
}
|
||||
}
|
||||
else {
|
||||
await IconManager.setIcon(IconState.disconnected);
|
||||
}
|
||||
}
|
||||
else {
|
||||
}
|
||||
}
|
||||
|
||||
public async fillWithCredential(tabId: number, credential: AutoFillCredential, onLoad = false) {
|
||||
|
||||
await browser.tabs.sendMessage(tabId, { credential: credential, onLoadFill: onLoad });
|
||||
}
|
||||
|
||||
|
||||
|
||||
private async updateBadgeAndIconBasedOnCredentialsResponse(response: CredentialsForUrlResponse, endTime: number, startTime: number) {
|
||||
const unlockedDatabaseCount = response.unlockedDatabaseCount;
|
||||
const resultCount = response.results.length;
|
||||
|
||||
|
||||
if (unlockedDatabaseCount == 0) {
|
||||
await IconManager.setIcon(IconState.allDatabasesLocked);
|
||||
} else {
|
||||
if (response.results.length > 0) {
|
||||
const settings = await SettingsStore.getSettings();
|
||||
|
||||
if (settings.showMatchCountOnPopupBadge) {
|
||||
await IconManager.setIcon(
|
||||
IconState.good,
|
||||
response.results.length.toString()
|
||||
);
|
||||
}
|
||||
else {
|
||||
await IconManager.setIcon(
|
||||
IconState.good
|
||||
);
|
||||
}
|
||||
} else {
|
||||
await IconManager.setIcon(IconState.good);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async copyTotpCodeIfConfiguredAfterFill(credential: AutoFillCredential): Promise<void> {
|
||||
if (credential.totp != '') {
|
||||
await NativeAppApi.getInstance().copyField(credential.databaseId, credential.uuid, WellKnownField.totp);
|
||||
}
|
||||
}
|
||||
|
||||
private async createNewEntry(details: CreateEntryRequest): Promise<CreateEntryResponse | null> {
|
||||
|
||||
|
||||
const response = await NativeAppApi.getInstance().createEntry(details);
|
||||
|
||||
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
private async getGroups(details: GetGroupsRequest): Promise<GetGroupsResponse | null> {
|
||||
|
||||
|
||||
const response = await NativeAppApi.getInstance().getGroups(details);
|
||||
|
||||
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
private async unlockDatabase(uuid: string): Promise<UnlockResponse | null> {
|
||||
|
||||
const status = await this.getStatus();
|
||||
|
||||
if (status == null) {
|
||||
const response = await this.launchStrongbox();
|
||||
|
||||
if (!response) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
|
||||
await new Promise(f => setTimeout(f, 500));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const response2 = await NativeAppApi.getInstance().unlockDatabase(uuid);
|
||||
|
||||
|
||||
|
||||
|
||||
return response2;
|
||||
}
|
||||
|
||||
private async getNewEntryDefaults(details: GetNewEntryDefaultsRequest): Promise<GetNewEntryDefaultsResponse | null> {
|
||||
|
||||
|
||||
const response = await NativeAppApi.getInstance().getNewEntryDefaults(details);
|
||||
|
||||
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
private async generatePassword(details: GeneratePasswordRequest): Promise<GeneratePasswordResponse | null> {
|
||||
|
||||
|
||||
const response = await NativeAppApi.getInstance().generatePassword(details);
|
||||
|
||||
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
private async getStatus(): Promise<GetStatusResponse | null> {
|
||||
|
||||
|
||||
await IconManager.setIcon(IconState.disconnected);
|
||||
|
||||
const status = await NativeAppApi.getInstance().getStatus();
|
||||
|
||||
|
||||
if (status) {
|
||||
const databases = status.databases;
|
||||
|
||||
this.updateLastKnownDatabases(databases);
|
||||
}
|
||||
|
||||
await this.updatePopupIconBasedOnStatus(status);
|
||||
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
async updateLastKnownDatabases(databases: DatabaseSummary[]) {
|
||||
const stored = await SettingsStore.getSettings();
|
||||
const mapped = databases
|
||||
.filter(database => database.autoFillEnabled)
|
||||
.map(database => new LastKnownDatabasesItem(database.nickName, database.uuid));
|
||||
stored.lastKnownDatabases = mapped;
|
||||
|
||||
await SettingsStore.setSettings(stored);
|
||||
}
|
||||
|
||||
private async launchStrongbox(): Promise<boolean> {
|
||||
|
||||
const response = await NativeAppApi.getInstance().launchStrongbox();
|
||||
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
private async copyField(credential: AutoFillCredential, field: WellKnownField, explicitTotp = false): Promise<CopyFieldResponse | null> {
|
||||
|
||||
const response = await NativeAppApi.getInstance().copyField(credential.databaseId, credential.uuid, field, explicitTotp);
|
||||
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
public async onMessage(message: any, sender: any): Promise<any> {
|
||||
|
||||
|
||||
|
||||
if (message.type === 'popup-request') {
|
||||
if (message.value == 'refresh-popup-icon') {
|
||||
this.updatePopupIconBasedOnStatus(message.status);
|
||||
}
|
||||
}
|
||||
else if (message.type === 'get-status') {
|
||||
const response = await this.getStatus();
|
||||
|
||||
|
||||
return response;
|
||||
}
|
||||
else if (message.type === 'launch-strongbox') {
|
||||
const response = await this.launchStrongbox();
|
||||
|
||||
|
||||
return response;
|
||||
}
|
||||
else if (message.type === 'unlock-database') {
|
||||
return await this.unlockDatabase(message.details.uuid);
|
||||
}
|
||||
else if (message.type === 'get-groups') {
|
||||
const details = message.details;
|
||||
|
||||
|
||||
|
||||
const response = await this.getGroups(details);
|
||||
|
||||
|
||||
|
||||
return response;
|
||||
}
|
||||
else if (message.type === 'get-new-entry-defaults') {
|
||||
const details = message.details;
|
||||
|
||||
|
||||
|
||||
const response = await this.getNewEntryDefaults(details);
|
||||
|
||||
|
||||
|
||||
return response;
|
||||
}
|
||||
else if (message.type === 'generate-password') {
|
||||
const details = message.details;
|
||||
|
||||
|
||||
|
||||
const response = await this.generatePassword(details);
|
||||
|
||||
|
||||
|
||||
return response;
|
||||
}
|
||||
else if (message.type === 'create-new-entry') {
|
||||
const details = message.details;
|
||||
|
||||
|
||||
|
||||
const response = await this.createNewEntry(details);
|
||||
|
||||
|
||||
|
||||
return response;
|
||||
}
|
||||
else if (message.type === 'copy-totp-after-fill') {
|
||||
const credential = message.details;
|
||||
|
||||
|
||||
|
||||
const response = await this.copyTotpCodeIfConfiguredAfterFill(credential);
|
||||
|
||||
|
||||
|
||||
return response;
|
||||
}
|
||||
else if (message.type === 'copy-username') {
|
||||
const credential = message.details;
|
||||
|
||||
|
||||
|
||||
const response = await this.copyField(credential, WellKnownField.username);
|
||||
|
||||
|
||||
|
||||
return response;
|
||||
}
|
||||
else if (message.type === 'copy-password') {
|
||||
const credential = message.details;
|
||||
|
||||
|
||||
|
||||
const response = await this.copyField(credential, WellKnownField.password);
|
||||
|
||||
|
||||
|
||||
return response;
|
||||
}
|
||||
else if (message.type === 'copy-totp') {
|
||||
const credential = message.details;
|
||||
|
||||
|
||||
|
||||
const response = await this.copyField(credential, WellKnownField.totp, true);
|
||||
|
||||
|
||||
|
||||
return response;
|
||||
}
|
||||
else if (message.type === 'get-tab-for-this-content-script') {
|
||||
|
||||
|
||||
return sender.tab as browser.Tabs.Tab;
|
||||
}
|
||||
else if (message.type === 'get-credentials') {
|
||||
|
||||
|
||||
const tab = sender.tab as browser.Tabs.Tab;
|
||||
const url = tab?.url;
|
||||
|
||||
if (url) {
|
||||
const credentials = await this.checkForCredentialsUrl(url);
|
||||
|
||||
|
||||
|
||||
return credentials;
|
||||
}
|
||||
else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
return Promise.reject();
|
||||
}
|
||||
|
||||
private async checkForCredentialsUrl(url: string): Promise<AutoFillCredential[] | null> {
|
||||
const startTime = performance.now();
|
||||
|
||||
const response = await NativeAppApi.getInstance().credentialsForUrl(url);
|
||||
|
||||
if (response != null) {
|
||||
const endTime = performance.now();
|
||||
|
||||
await this.updateBadgeAndIconBasedOnCredentialsResponse(response, endTime, startTime);
|
||||
|
||||
return response.results;
|
||||
}
|
||||
else {
|
||||
await IconManager.setIcon(IconState.disconnected);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import browser from 'webextension-polyfill';
|
||||
|
||||
export enum IconState {
|
||||
disconnected,
|
||||
allDatabasesLocked,
|
||||
good,
|
||||
}
|
||||
export class IconManager {
|
||||
static async setIcon(
|
||||
state: IconState,
|
||||
badgeText = '',
|
||||
badgeColor = '#344d56'
|
||||
): Promise<void> {
|
||||
const action = browser.action || browser.browserAction;
|
||||
|
||||
if (action == undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
|
||||
if (state == IconState.disconnected) {
|
||||
await action.setIcon({
|
||||
path: {
|
||||
19: '/assets/icons/app-icon-grey-19.png',
|
||||
38: '/assets/icons/app-icon-grey-38.png',
|
||||
},
|
||||
});
|
||||
|
||||
await action.setTitle({ title: 'Strongbox: Not Running' });
|
||||
} else if (state == IconState.allDatabasesLocked) {
|
||||
await action.setIcon({
|
||||
path: {
|
||||
19: '/assets/icons/app-icon-all-locked-19.png',
|
||||
38: '/assets/icons/app-icon-all-locked-38.png',
|
||||
},
|
||||
});
|
||||
|
||||
await action.setTitle({ title: 'Strongbox: Locked' });
|
||||
} else {
|
||||
await action.setIcon({
|
||||
path: {
|
||||
19: '/assets/icons/app-icon-blue-19.png',
|
||||
38: '/assets/icons/app-icon-blue-38.png',
|
||||
},
|
||||
});
|
||||
await action.setTitle({ title: 'Strongbox' });
|
||||
}
|
||||
|
||||
await action.setBadgeText({ text: badgeText });
|
||||
await action.setBadgeBackgroundColor({ color: badgeColor });
|
||||
} catch (error) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import browser from 'webextension-polyfill';
|
||||
import { BackgroundManager } from './BackgroundManager';
|
||||
|
||||
|
||||
|
||||
browser.runtime.onInstalled.addListener(async (): Promise<void> => {
|
||||
await BackgroundManager.getInstance().doSimpleStatusUpdate();
|
||||
});
|
||||
|
||||
|
||||
|
||||
browser.windows.onFocusChanged.addListener((windowId) => {
|
||||
|
||||
if (windowId != browser.windows.WINDOW_ID_NONE) {
|
||||
BackgroundManager.getInstance().refreshCredentialsAndAutoFillIfNecessary(true);
|
||||
}
|
||||
else {
|
||||
BackgroundManager.getInstance().doSimpleStatusUpdate();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
browser.tabs.onActivated.addListener((e) => {
|
||||
BackgroundManager.getInstance().refreshCredentialsAndAutoFillIfNecessary();
|
||||
});
|
||||
|
||||
|
||||
|
||||
browser.tabs.onUpdated.addListener((e) => {
|
||||
BackgroundManager.getInstance().refreshCredentialsAndAutoFillIfNecessary();
|
||||
});
|
||||
|
||||
|
||||
|
||||
browser.runtime.onMessage.addListener((message: any, sender: any): Promise<any> => {
|
||||
return BackgroundManager.getInstance().onMessage(message, sender);
|
||||
});
|
||||
|
||||
|
||||
|
||||
browser.commands.onCommand.addListener((command) => {
|
||||
if (command == 'autofill-first') {
|
||||
BackgroundManager.getInstance().autoFillCurrentTabWithFirstMatch();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
browser.webNavigation.onCompleted.addListener((tab) => {
|
||||
if (tab.frameId == 0) {
|
||||
BackgroundManager.getInstance().refreshCredentialsAndAutoFillIfNecessary(false, true);
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,111 @@
|
||||
import { AutoFillCredential } from '../Messaging/Protocol/AutoFillCredential';
|
||||
import { PageAnalyser } from './PageAnalyser';
|
||||
|
||||
export class AutoFiller {
|
||||
async doIt(credential: AutoFillCredential,
|
||||
inlineFieldInitiator: HTMLInputElement | null = null,
|
||||
inlineFieldInitiatorIsPassword = false, fillMultiple = false): Promise<boolean> {
|
||||
const usernames = PageAnalyser.getAllUsernameInputs();
|
||||
const passwords = PageAnalyser.getAllPasswordInputs();
|
||||
|
||||
let filledSomething = false;
|
||||
|
||||
|
||||
|
||||
if (inlineFieldInitiator !== null && !inlineFieldInitiatorIsPassword) {
|
||||
this.fillFieldAndAnimate(inlineFieldInitiator, credential.username);
|
||||
filledSomething = true;
|
||||
}
|
||||
else {
|
||||
|
||||
if (usernames.length === 0) {
|
||||
}
|
||||
|
||||
for (const usernameField of usernames) {
|
||||
this.fillFieldAndAnimate(usernameField, credential.username);
|
||||
filledSomething = true;
|
||||
|
||||
if (!fillMultiple) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (inlineFieldInitiator !== null && inlineFieldInitiatorIsPassword) {
|
||||
this.fillFieldAndAnimate(inlineFieldInitiator, credential.password);
|
||||
filledSomething = true;
|
||||
}
|
||||
else {
|
||||
|
||||
if (passwords.length === 0) {
|
||||
}
|
||||
|
||||
for (const passwordField of passwords) {
|
||||
this.fillFieldAndAnimate(passwordField, credential.password);
|
||||
filledSomething = true;
|
||||
|
||||
if (!fillMultiple) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return filledSomething;
|
||||
}
|
||||
|
||||
private fillFieldAndAnimate(field: HTMLInputElement, value: string) {
|
||||
this.fillField(field, value);
|
||||
|
||||
field.classList.add('com-phoebecode-strongbox-autofill-animated');
|
||||
|
||||
setTimeout(function () {
|
||||
if (field) {
|
||||
field.classList.remove('com-phoebecode-strongbox-autofill-animated');
|
||||
}
|
||||
}, 500);
|
||||
}
|
||||
|
||||
private getKeyboardEvent(eventName: string) {
|
||||
return new window.KeyboardEvent(eventName, {
|
||||
bubbles: true,
|
||||
cancelable: false,
|
||||
});
|
||||
}
|
||||
|
||||
private fillField(field: HTMLInputElement, value: string) {
|
||||
const originalValue = field.value;
|
||||
|
||||
field.click();
|
||||
field.focus();
|
||||
|
||||
field.dispatchEvent(this.getKeyboardEvent('keydown'));
|
||||
field.dispatchEvent(this.getKeyboardEvent('keypress'));
|
||||
field.dispatchEvent(this.getKeyboardEvent('keyup'));
|
||||
|
||||
if (field.value !== originalValue) {
|
||||
field.value = originalValue;
|
||||
}
|
||||
|
||||
field.value = value;
|
||||
|
||||
field.dispatchEvent(this.getKeyboardEvent('keydown'));
|
||||
field.dispatchEvent(this.getKeyboardEvent('keypress'));
|
||||
field.dispatchEvent(this.getKeyboardEvent('keyup'));
|
||||
|
||||
const onInputEvent = field.ownerDocument.createEvent('HTMLEvents');
|
||||
onInputEvent.initEvent('input', true, true);
|
||||
field.dispatchEvent(onInputEvent);
|
||||
|
||||
const onChangeEvent = field.ownerDocument.createEvent('HTMLEvents');
|
||||
onChangeEvent.initEvent('change', true, true);
|
||||
field.dispatchEvent(onChangeEvent);
|
||||
|
||||
field.blur();
|
||||
|
||||
if (field.value !== value) {
|
||||
field.value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,585 @@
|
||||
import { AutoFillCredential } from "../Messaging/Protocol/AutoFillCredential";
|
||||
import { GetStatusResponse } from "../Messaging/Protocol/GetStatusResponse";
|
||||
import { AutoFiller } from "./AutoFiller";
|
||||
import browser from 'webextension-polyfill';
|
||||
import { CreateEntryRequest } from "../Messaging/Protocol/CreateEntryRequest";
|
||||
import { CreateEntryResponse } from "../Messaging/Protocol/CreateEntryResponse";
|
||||
import ReactDOM from 'react-dom/client';
|
||||
import CreateNewEntryDialog from "./CreateNewEntryDialog";
|
||||
import React from "react";
|
||||
import { Utils } from "../Utils";
|
||||
import { GetGroupsResponse } from "../Messaging/Protocol/GetGroupsResponse";
|
||||
import { GetGroupsRequest } from "../Messaging/Protocol/GetGroupsRequest";
|
||||
import { GetNewEntryDefaultsRequest } from "../Messaging/Protocol/GetNewEntryDefaultsRequest";
|
||||
import { GetNewEntryDefaultsResponse } from "../Messaging/Protocol/GetNewEntryDefaultsResponse";
|
||||
import { GeneratePasswordRequest } from "../Messaging/Protocol/GeneratePasswordRequest";
|
||||
import { GeneratePasswordResponse } from "../Messaging/Protocol/GeneratePasswordResponse";
|
||||
import NotificationToast from "./NotificationToast";
|
||||
import { UnlockResponse } from "../Messaging/Protocol/UnlockResponse";
|
||||
import { PageAnalyser } from "./PageAnalyser";
|
||||
import InlineMiniFieldMenu from "./InlineMiniFieldMenu";
|
||||
import { SettingsStore } from "../Settings/SettingsStore";
|
||||
import createCache, { EmotionCache } from '@emotion/cache';
|
||||
import { LastKnownDatabasesItem, Settings } from "../Settings/Settings";
|
||||
|
||||
export class ContentScriptManager {
|
||||
pageLoadFillDone = false;
|
||||
reactRoot: ReactDOM.Root;
|
||||
reactRootPopupMenu: ReactDOM.Root | null;
|
||||
currentlyFocusedInputElement: HTMLElement | null;
|
||||
|
||||
constructor() {
|
||||
}
|
||||
|
||||
onDOMLoaded() {
|
||||
|
||||
this.addFocusListener();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
this.bindToFocus();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
async getStatus(): Promise<GetStatusResponse | null> {
|
||||
const ret = await browser.runtime.sendMessage({ type: "get-status" });
|
||||
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
async getCredentials(): Promise<AutoFillCredential[] | null> {
|
||||
const ret = await browser.runtime.sendMessage({ type: "get-credentials" });
|
||||
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
async getGroups(request: GetGroupsRequest): Promise<GetGroupsResponse | null> {
|
||||
const ret = await browser.runtime.sendMessage({ type: "get-groups", details: request });
|
||||
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
async launchStrongbox() {
|
||||
const ret = await browser.runtime.sendMessage({ type: "launch-strongbox" });
|
||||
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
async onCopyUsername(credential: AutoFillCredential) {
|
||||
await browser.runtime.sendMessage({ type: "copy-username", details: credential });
|
||||
}
|
||||
|
||||
async onCopyPassword(credential: AutoFillCredential) {
|
||||
await browser.runtime.sendMessage({ type: "copy-password", details: credential });
|
||||
}
|
||||
|
||||
async onCopyTotp(credential: AutoFillCredential) {
|
||||
await browser.runtime.sendMessage({ type: "copy-totp", details: credential });
|
||||
}
|
||||
|
||||
async unlockDatabase(uuid: string): Promise<UnlockResponse | null> {
|
||||
const ret = await browser.runtime.sendMessage({
|
||||
type: "unlock-database", details: {
|
||||
uuid: uuid,
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
async getNewEntryDefaults(request: GetNewEntryDefaultsRequest): Promise<GetNewEntryDefaultsResponse | null> {
|
||||
const ret = await browser.runtime.sendMessage({ type: "get-new-entry-defaults", details: request });
|
||||
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
async generatePassword(request: GeneratePasswordRequest): Promise<GeneratePasswordResponse | null> {
|
||||
const ret = await browser.runtime.sendMessage({ type: "generate-password", details: request });
|
||||
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
async createNewEntry(details: CreateEntryRequest): Promise<CreateEntryResponse | null> {
|
||||
const ret = await browser.runtime.sendMessage({ type: "create-new-entry", details: details });
|
||||
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
async copyTotpCodeIfConfiguredAfterFill(details: AutoFillCredential): Promise<void> {
|
||||
const ret = await browser.runtime.sendMessage({ type: "copy-totp-after-fill", details: details });
|
||||
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
async getCurrentTab(): Promise<browser.Tabs.Tab | null> {
|
||||
const ret = await browser.runtime.sendMessage({ type: "get-tab-for-this-content-script" });
|
||||
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
onCreatedNewItem(credential: AutoFillCredential) {
|
||||
this.showNotificationToast();
|
||||
|
||||
this.onFillWithCredential(credential);
|
||||
}
|
||||
|
||||
|
||||
|
||||
snackBarShadowRoot: HTMLElement;
|
||||
snackBarEmotionCache: EmotionCache;
|
||||
snackBarReactRoot: ReactDOM.Root;
|
||||
static readonly SNACKBAR_SHADOW_CONTAINER_ID = 'strongbox-cs-snackbar-shadow-container';
|
||||
|
||||
ensureSnackBarRoot() {
|
||||
const found = document.getElementById(ContentScriptManager.SNACKBAR_SHADOW_CONTAINER_ID);
|
||||
if (!found) {
|
||||
const created = document.createElement('div');
|
||||
created.id = ContentScriptManager.SNACKBAR_SHADOW_CONTAINER_ID;
|
||||
document.body.append(created);
|
||||
|
||||
const shadowContainer = created.attachShadow({ mode: 'open' });
|
||||
const emotionRoot = document.createElement('style');
|
||||
const shadowRootElement = document.createElement('div');
|
||||
shadowContainer.appendChild(emotionRoot);
|
||||
shadowContainer.appendChild(shadowRootElement);
|
||||
|
||||
this.snackBarEmotionCache = createCache({
|
||||
key: 'css',
|
||||
prepend: true,
|
||||
container: emotionRoot,
|
||||
});
|
||||
|
||||
this.snackBarShadowRoot = shadowRootElement;
|
||||
this.snackBarReactRoot = ReactDOM.createRoot(this.snackBarShadowRoot);
|
||||
}
|
||||
}
|
||||
|
||||
showNotificationToast() {
|
||||
this.ensureSnackBarRoot();
|
||||
|
||||
const snackbar = React.createElement(NotificationToast, {
|
||||
key: Utils.getUUIDString(),
|
||||
shadowRootElement: this.snackBarShadowRoot,
|
||||
cache: this.snackBarEmotionCache,
|
||||
});
|
||||
|
||||
this.snackBarReactRoot.render(snackbar);
|
||||
}
|
||||
|
||||
|
||||
|
||||
createNewDialogShadowRoot: HTMLElement;
|
||||
createNewDialogEmotionCache: EmotionCache;
|
||||
createNewDialogReactRoot: ReactDOM.Root;
|
||||
static readonly CREATE_NEW_DIALOG_SHADOW_CONTAINER_ID = 'strongbox-cs-create-new-dialog-shadow-container';
|
||||
|
||||
ensureCreateNewDialogRoot() {
|
||||
const found = document.getElementById(ContentScriptManager.CREATE_NEW_DIALOG_SHADOW_CONTAINER_ID);
|
||||
if (!found) {
|
||||
const created = document.createElement('div');
|
||||
created.id = ContentScriptManager.CREATE_NEW_DIALOG_SHADOW_CONTAINER_ID;
|
||||
document.body.append(created);
|
||||
|
||||
const shadowContainer = created.attachShadow({ mode: 'open' });
|
||||
const emotionRoot = document.createElement('style');
|
||||
const shadowRootElement = document.createElement('div');
|
||||
shadowContainer.appendChild(emotionRoot);
|
||||
shadowContainer.appendChild(shadowRootElement);
|
||||
|
||||
this.createNewDialogEmotionCache = createCache({
|
||||
key: 'css',
|
||||
prepend: true,
|
||||
container: emotionRoot,
|
||||
});
|
||||
|
||||
this.createNewDialogShadowRoot = shadowRootElement;
|
||||
this.createNewDialogReactRoot = ReactDOM.createRoot(this.createNewDialogShadowRoot);
|
||||
}
|
||||
}
|
||||
|
||||
async showCreateNewEntryDialog() {
|
||||
this.ensureCreateNewDialogRoot();
|
||||
|
||||
const url = await this.getFavIconUrl();
|
||||
|
||||
const favIconBase64 = url ? await this.getFavIconBase64Data(url) : null;
|
||||
const isDefaultFavIcon = favIconBase64 == null;
|
||||
const favIconUrl: string | null = isDefaultFavIcon ? null : url;
|
||||
|
||||
const dialog = React.createElement(CreateNewEntryDialog, {
|
||||
getStatus: async () => { const status = await this.getStatus(); return status; },
|
||||
getGroups: async (request) => { const response = await this.getGroups(request); return response; },
|
||||
getNewEntryDefaults: async (request) => { const response = await this.getNewEntryDefaults(request); return response; },
|
||||
generatePassword: async (request) => { const response = await this.generatePassword(request); return response; },
|
||||
faviconUrl: favIconUrl,
|
||||
onCreate: async (details) => { const response = await this.createNewEntry(details); return response; },
|
||||
onCreatedItem: (credential) => { this.onCreatedNewItem(credential); },
|
||||
key: Utils.getUUIDString(),
|
||||
unlockDatabase: async (uuid) => { const response = await this.unlockDatabase(uuid); return response; },
|
||||
shadowRootElement: this.createNewDialogShadowRoot,
|
||||
cache: this.createNewDialogEmotionCache,
|
||||
favIconBase64: favIconBase64,
|
||||
});
|
||||
|
||||
this.createNewDialogReactRoot.render(dialog);
|
||||
}
|
||||
|
||||
async getFavIconBase64Data(url: string): Promise<string | null> {
|
||||
|
||||
|
||||
const testImg = document.createElement('img') as HTMLImageElement;
|
||||
if (testImg === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
testImg.src = url;
|
||||
|
||||
try {
|
||||
await testImg.decode();
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const imageData = Utils.getImageElementBase64PNGData(testImg);
|
||||
|
||||
if (imageData && imageData?.length > 20 * 1024) {
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
const chromeDefaultFavIconHash = -1499456902;
|
||||
if (imageData == null || testImg.naturalHeight === 0) {
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
else if (Utils.quickHashString(imageData) === chromeDefaultFavIconHash) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return imageData;
|
||||
}
|
||||
|
||||
private async getFavIconUrl(): Promise<string | null> {
|
||||
if (Utils.isFirefox()) {
|
||||
const thisTab = await this.getCurrentTab();
|
||||
return thisTab?.favIconUrl ?? null;
|
||||
}
|
||||
else {
|
||||
const url = new URL(browser.runtime.getURL("/_favicon/"));
|
||||
url.searchParams.set("pageUrl", document.location.href);
|
||||
url.searchParams.set("size", "128");
|
||||
return url.toString();
|
||||
}
|
||||
}
|
||||
|
||||
handleSaveNewEntry(details: CreateEntryRequest) {
|
||||
return this.createNewEntry(details);
|
||||
}
|
||||
|
||||
|
||||
|
||||
listen = false;
|
||||
focusOrBlurListener: EventListener = (event) => this.onFocusChanged(event);
|
||||
addFocusListener() {
|
||||
|
||||
this.listen = true;
|
||||
document.addEventListener('focus', this.focusOrBlurListener, true);
|
||||
document.addEventListener('blur', this.focusOrBlurListener, true);
|
||||
}
|
||||
|
||||
removeFocusListener() {
|
||||
|
||||
this.listen = false;
|
||||
document.removeEventListener('focus', this.focusOrBlurListener, true);
|
||||
document.removeEventListener('blur', this.focusOrBlurListener, true);
|
||||
}
|
||||
|
||||
timeout: NodeJS.Timeout | null;
|
||||
clearBlurTimeout() {
|
||||
if (this.timeout) {
|
||||
clearTimeout(this.timeout);
|
||||
this.timeout = null;
|
||||
}
|
||||
}
|
||||
|
||||
async onFocusChanged(event: Event) {
|
||||
if (!this.listen) {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
this.clearBlurTimeout();
|
||||
|
||||
if (event.type === 'blur') {
|
||||
this.timeout = setTimeout(() => { this.bindToFocus(); this.timeout = null; }, 200);
|
||||
}
|
||||
else {
|
||||
this.bindToFocus();
|
||||
}
|
||||
}
|
||||
|
||||
async bindToFocus() {
|
||||
const focusedElement = document.activeElement as HTMLInputElement;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
const shouldRun = await this.shouldRun();
|
||||
if (!shouldRun) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (focusedElement) {
|
||||
const usernames = PageAnalyser.getAllUsernameInputs();
|
||||
const attachUsername = usernames.find(input => input == focusedElement);
|
||||
const passwords = PageAnalyser.getAllPasswordInputs();
|
||||
const attachPassword = passwords.find(input => input == focusedElement);
|
||||
|
||||
if (attachUsername || attachPassword) {
|
||||
const isPasswordField = attachPassword !== undefined;
|
||||
|
||||
|
||||
const status = await this.getStatus();
|
||||
|
||||
|
||||
|
||||
|
||||
this.showInlineMenu(focusedElement, status, isPasswordField);
|
||||
}
|
||||
else {
|
||||
}
|
||||
}
|
||||
else {
|
||||
}
|
||||
}
|
||||
|
||||
async onMiniIconClick(fieldElement: HTMLInputElement, isPasswordField: boolean) {
|
||||
this.removeFocusListener();
|
||||
this.clearBlurTimeout();
|
||||
|
||||
const status = await this.getStatus();
|
||||
|
||||
const noUnlockedDatabases = false;
|
||||
const singleAutoFillDatabaseUuid: string | null = null;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (noUnlockedDatabases && singleAutoFillDatabaseUuid) {
|
||||
await this.unlockDatabase(singleAutoFillDatabaseUuid);
|
||||
}
|
||||
else {
|
||||
await this.showInlineMenu(fieldElement, status, isPasswordField);
|
||||
}
|
||||
|
||||
this.addFocusListener();
|
||||
}
|
||||
|
||||
async getLastKnownAutoFillDatabases(): Promise<LastKnownDatabasesItem[]> {
|
||||
const stored = await SettingsStore.getSettings();
|
||||
return stored.lastKnownDatabases;
|
||||
}
|
||||
|
||||
|
||||
|
||||
inlineMenuShadowRoot: HTMLElement;
|
||||
inlineMenuEmotionCache: EmotionCache;
|
||||
inlineMenuReactRoot: ReactDOM.Root;
|
||||
static readonly INLINE_MENU_SHADOW_CONTAINER_ID = 'strongbox-cs-inline-menu-shadow-container';
|
||||
|
||||
ensureInlineMenuRoot() {
|
||||
const found = document.getElementById(ContentScriptManager.INLINE_MENU_SHADOW_CONTAINER_ID);
|
||||
if (!found) {
|
||||
const created = document.createElement('div');
|
||||
created.id = ContentScriptManager.INLINE_MENU_SHADOW_CONTAINER_ID;
|
||||
document.body.append(created);
|
||||
|
||||
const shadowContainer = created.attachShadow({ mode: 'open' });
|
||||
const emotionRoot = document.createElement('style');
|
||||
const shadowRootElement = document.createElement('div');
|
||||
shadowContainer.appendChild(emotionRoot);
|
||||
shadowContainer.appendChild(shadowRootElement);
|
||||
|
||||
this.inlineMenuEmotionCache = createCache({
|
||||
key: 'css',
|
||||
prepend: true,
|
||||
container: emotionRoot,
|
||||
});
|
||||
|
||||
this.inlineMenuShadowRoot = shadowRootElement;
|
||||
this.inlineMenuReactRoot = ReactDOM.createRoot(this.inlineMenuShadowRoot);
|
||||
}
|
||||
}
|
||||
|
||||
async shouldRun(): Promise<boolean> {
|
||||
const settings = await SettingsStore.getSettings();
|
||||
if (!settings.showInlineIconAndPopupMenu || Settings.isUrlIsInDoNotShowInlineMenusList(settings, document.location.href)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
async showInlineMenu(fieldElement: HTMLInputElement, status: GetStatusResponse | null, isPasswordField: boolean, show = true) {
|
||||
|
||||
|
||||
const shouldRun = await this.shouldRun();
|
||||
if (!shouldRun) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.ensureInlineMenuRoot();
|
||||
|
||||
if (status == null) {
|
||||
}
|
||||
|
||||
const showCreateNew = status?.serverSettings?.supportsCreateNew ?? false;
|
||||
const unlockedDatabaseAvailable = status ? status.databases.filter(database => database.autoFillEnabled && !database.locked).length != 0 : false;
|
||||
|
||||
const credentials = status == null ? [] : (await this.getCredentials() ?? []);
|
||||
|
||||
const unlockableDatabases = await this.getUnlockableDatabases(status);
|
||||
|
||||
const menuComponent = React.createElement(InlineMiniFieldMenu, {
|
||||
anchorEl: fieldElement,
|
||||
unlockedDatabaseAvailable: unlockedDatabaseAvailable,
|
||||
key: Utils.getUUIDString(),
|
||||
credentials: credentials,
|
||||
showCreateNew: showCreateNew && unlockedDatabaseAvailable,
|
||||
onCreateNewEntry: () => { this.showCreateNewEntryDialog(); },
|
||||
onLaunchStrongbox: () => { this.launchStrongbox(); },
|
||||
onUnlockDatabase: async (databaseUuid: string) => { await this.unlockDatabase(databaseUuid); },
|
||||
onFillWithCredential: async (credential) => { await this.onFillWithCredential(credential, fieldElement, isPasswordField); },
|
||||
isPasswordField: isPasswordField,
|
||||
shadowRootElement: this.inlineMenuShadowRoot,
|
||||
cache: this.inlineMenuEmotionCache,
|
||||
show: show,
|
||||
unlockableDatabases: unlockableDatabases,
|
||||
onCopyUsername: (credential) => { this.onCopyUsername(credential); },
|
||||
onCopyPassword: (credential) => { this.onCopyPassword(credential); },
|
||||
onCopyTotp: (credential) => { this.onCopyTotp(credential); },
|
||||
});
|
||||
|
||||
await this.inlineMenuReactRoot.render(menuComponent);
|
||||
}
|
||||
|
||||
async getUnlockableDatabases(status: GetStatusResponse | null): Promise<LastKnownDatabasesItem[]> {
|
||||
if (status) {
|
||||
return status.databases.filter(database => database.autoFillEnabled && database.locked).map(database => new LastKnownDatabasesItem(database.nickName, database.uuid));
|
||||
}
|
||||
else {
|
||||
const stored = await SettingsStore.getSettings();
|
||||
return stored.lastKnownDatabases;
|
||||
}
|
||||
}
|
||||
|
||||
async onFillWithCredential(credential: AutoFillCredential, inlineFieldInitiator: HTMLInputElement | null = null, inlineFieldInitiatorIsPassword = false) {
|
||||
await this.autoFillWithCredential(credential, false, inlineFieldInitiator, inlineFieldInitiatorIsPassword);
|
||||
}
|
||||
|
||||
async autoFillWithCredential(credential: AutoFillCredential, isPageLoadFill = false, inlineFieldInitiator: HTMLInputElement | null = null, inlineFieldInitiatorIsPassword = false, fillMultiple = false): Promise<boolean> {
|
||||
|
||||
if (isPageLoadFill) {
|
||||
|
||||
if (this.pageLoadFillDone) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.pageLoadFillDone = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
this.removeFocusListener();
|
||||
|
||||
const autoFiller = new AutoFiller();
|
||||
const filled = await autoFiller.doIt(credential, inlineFieldInitiator, inlineFieldInitiatorIsPassword, fillMultiple);
|
||||
|
||||
setTimeout(() => { this.addFocusListener(); }, 500);
|
||||
|
||||
if (filled) {
|
||||
this.copyTotpCodeIfConfiguredAfterFill(credential);
|
||||
}
|
||||
|
||||
return filled;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,576 @@
|
||||
import * as React from 'react';
|
||||
import DialogTitle from '@mui/material/DialogTitle';
|
||||
import Dialog from '@mui/material/Dialog';
|
||||
import { Accordion, AccordionDetails, AccordionSummary, Alert, AlertTitle, Autocomplete, Backdrop, Box, Button, CircularProgress, Collapse, createTheme, DialogActions, DialogContent, Divider, FormControl, Icon, IconButton, InputAdornment, InputLabel, makeStyles, MenuItem, OutlinedInput, Select, SelectChangeEvent, Snackbar, TextField, ThemeProvider, Typography } from '@mui/material';
|
||||
import { AddCircle, Close, ExpandMore, Folder, Home, Lock, LockOpen, Refresh, Visibility, VisibilityOff } from '@mui/icons-material';
|
||||
import { CreateEntryRequest } from '../Messaging/Protocol/CreateEntryRequest';
|
||||
import { CreateEntryResponse } from '../Messaging/Protocol/CreateEntryResponse';
|
||||
import { DatabaseSummary } from '../Messaging/Protocol/DatabaseSummary';
|
||||
import { GetGroupsRequest } from '../Messaging/Protocol/GetGroupsRequest';
|
||||
import { GetGroupsResponse } from '../Messaging/Protocol/GetGroupsResponse';
|
||||
import { GroupSummary } from '../Messaging/Protocol/GroupSummary';
|
||||
import { GetNewEntryDefaultsRequest } from '../Messaging/Protocol/GetNewEntryDefaultsRequest';
|
||||
import { GetNewEntryDefaultsResponse } from '../Messaging/Protocol/GetNewEntryDefaultsResponse';
|
||||
import { GeneratePasswordRequest } from '../Messaging/Protocol/GeneratePasswordRequest';
|
||||
import { GeneratePasswordResponse } from '../Messaging/Protocol/GeneratePasswordResponse';
|
||||
import { GetStatusResponse } from '../Messaging/Protocol/GetStatusResponse';
|
||||
import { StrongboxColours } from '../StrongboxColours';
|
||||
import browser from 'webextension-polyfill';
|
||||
import { UnlockResponse } from '../Messaging/Protocol/UnlockResponse';
|
||||
import { AutoFillCredential } from '../Messaging/Protocol/AutoFillCredential';
|
||||
import { CacheProvider, EmotionCache } from '@emotion/react';
|
||||
|
||||
export interface CreateNewEntryDialogProps {
|
||||
getStatus: () => Promise<GetStatusResponse | null>;
|
||||
getNewEntryDefaults: (request: GetNewEntryDefaultsRequest) => Promise<GetNewEntryDefaultsResponse | null>;
|
||||
generatePassword: (request: GeneratePasswordRequest) => Promise<GeneratePasswordResponse | null>;
|
||||
getGroups: (request: GetGroupsRequest) => Promise<GetGroupsResponse | null>;
|
||||
faviconUrl: string | null;
|
||||
onCreate: (details: CreateEntryRequest) => Promise<CreateEntryResponse | null>;
|
||||
onCreatedItem: (credential: AutoFillCredential) => void;
|
||||
unlockDatabase: (uuid: string) => Promise<UnlockResponse | null>;
|
||||
shadowRootElement: HTMLElement;
|
||||
cache: EmotionCache;
|
||||
favIconBase64: string | null;
|
||||
}
|
||||
|
||||
export default function CreateNewEntryDialog(props: CreateNewEntryDialogProps) {
|
||||
const [open, setOpen] = React.useState<boolean>(true);
|
||||
const [saveInExpanded, setSaveInExpanded] = React.useState<boolean>(false);
|
||||
const [unlockWaitSpinnerOpen, setUnlockWaitSpinnerOpen] = React.useState<boolean>(false);
|
||||
const [toastOpen, setToastOpen] = React.useState<boolean>(false);
|
||||
const [toastIsError, setToastIsError] = React.useState<boolean>(false);
|
||||
const [toastMessage, setToastMessage] = React.useState<string>('');
|
||||
const [selectedDatabaseIdx, setSelectedDatabaseIdx] = React.useState<number | null>(null);
|
||||
const [selectedGroup, setSelectedGroup] = React.useState<string>('');
|
||||
const [databases, setDatabases] = React.useState<DatabaseSummary[]>([]);
|
||||
const [groups, setGroups] = React.useState<GroupSummary[]>([]);
|
||||
const [username, setUsername] = React.useState<string>('Loading...');
|
||||
const [mostPopularUsernames, setMostPopularUsernames] = React.useState<string[]>([]);
|
||||
const [title, setTitle] = React.useState<string>(document.title);
|
||||
const [password, setPassword] = React.useState<string>('Loading...');
|
||||
const [showPassword, setShowPassword] = React.useState(false);
|
||||
|
||||
React.useEffect(() => {
|
||||
loadDatabasesAtStartup().catch((error) => {
|
||||
showErrorToast('Could not load databases!');
|
||||
});
|
||||
}, []);
|
||||
|
||||
React.useEffect(() => {
|
||||
refreshDefaults().catch((error) => {
|
||||
showErrorToast('Could not load defaults!');
|
||||
});
|
||||
}, [databases, selectedDatabaseIdx]);
|
||||
|
||||
React.useEffect(() => {
|
||||
refreshGroups().catch((error) => {
|
||||
showErrorToast('Could not refresh groups!');
|
||||
});
|
||||
}, [databases, selectedDatabaseIdx]);
|
||||
|
||||
const handleGenerateNewPassword = async () => {
|
||||
const req = new GeneratePasswordRequest();
|
||||
const resp = await props.generatePassword(req);
|
||||
|
||||
if (resp === null) {
|
||||
showErrorToast('Could Not Generate Password');
|
||||
}
|
||||
else {
|
||||
setPassword(resp.password);
|
||||
|
||||
|
||||
if (!showPassword) {
|
||||
setShowPassword(true);
|
||||
setTimeout(() => { setShowPassword(false); }, 3000);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const handleUnlockRequest = async () => {
|
||||
if (selectedDatabaseIdx == null || !currentlySelectedDatabase()?.locked) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
const uuid = databases[selectedDatabaseIdx].uuid;
|
||||
const resp = await props.unlockDatabase(uuid);
|
||||
|
||||
if (resp === null) {
|
||||
showErrorToast('Could not Unlock Database');
|
||||
}
|
||||
else {
|
||||
setUnlockWaitSpinnerOpen(true);
|
||||
pollForUnlockStatusChanged(uuid);
|
||||
}
|
||||
};
|
||||
|
||||
async function pollForUnlockStatusChanged(uuid: string, iteration = 0) {
|
||||
const resp = await props.getStatus();
|
||||
|
||||
if (resp != null) {
|
||||
const database = resp.databases.find(database => database.uuid === uuid);
|
||||
if (database && !database.locked) {
|
||||
const dbs = resp.databases;
|
||||
const afDbs = dbs.filter(database => database.autoFillEnabled);
|
||||
|
||||
setDatabases(afDbs);
|
||||
const unlockedIdx = afDbs.findIndex(database => database.uuid === uuid);
|
||||
setSelectedDatabaseIdx(unlockedIdx != -1 ? unlockedIdx : afDbs.length > 0 ? 0 : null);
|
||||
setSaveInExpanded(unlockedIdx === -1);
|
||||
setUnlockWaitSpinnerOpen(false);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
showErrorToast('Could not get unlock status in poll!');
|
||||
setUnlockWaitSpinnerOpen(false);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
const checkIntervalMs = 250;
|
||||
const checkForSecs = 20;
|
||||
const maxIterations = (1000 / checkIntervalMs) * checkForSecs;
|
||||
|
||||
if (iteration < maxIterations) {
|
||||
setTimeout(() => {
|
||||
pollForUnlockStatusChanged(uuid, iteration + 1);
|
||||
}, checkIntervalMs);
|
||||
}
|
||||
else {
|
||||
setUnlockWaitSpinnerOpen(false);
|
||||
}
|
||||
}
|
||||
|
||||
const loadDatabasesAtStartup = async () => {
|
||||
|
||||
|
||||
const status = await props.getStatus();
|
||||
|
||||
if (status === null) {
|
||||
showErrorToast('Could Not Connect to Strongbox');
|
||||
setDatabases([]);
|
||||
setSelectedDatabaseIdx(null);
|
||||
setSaveInExpanded(true);
|
||||
}
|
||||
else {
|
||||
const dbs = status.databases;
|
||||
const afDbs = dbs.filter(database => database.autoFillEnabled);
|
||||
|
||||
setDatabases(afDbs);
|
||||
|
||||
const unlockedIdx = afDbs.findIndex(database => !database.locked);
|
||||
setSelectedDatabaseIdx(unlockedIdx != -1 ? unlockedIdx : afDbs.length > 0 ? 0 : null);
|
||||
|
||||
setSaveInExpanded(unlockedIdx === -1);
|
||||
}
|
||||
};
|
||||
|
||||
const refreshDefaults = async () => {
|
||||
if (selectedDatabaseIdx == null || currentlySelectedDatabase()?.locked) {
|
||||
setUsername('Loading...');
|
||||
setPassword('Loading...');
|
||||
setMostPopularUsernames([]);
|
||||
}
|
||||
else {
|
||||
|
||||
|
||||
const req = new GetNewEntryDefaultsRequest();
|
||||
req.databaseId = databases[selectedDatabaseIdx].uuid;
|
||||
const resp = await props.getNewEntryDefaults(req);
|
||||
|
||||
if (resp === null || resp.error) {
|
||||
showErrorToast('Error getting defaults');
|
||||
setUsername('Loading...');
|
||||
setPassword('Loading...');
|
||||
setMostPopularUsernames([]);
|
||||
}
|
||||
else {
|
||||
setUsername(resp.username ?? '');
|
||||
setPassword(resp.password ?? '');
|
||||
setMostPopularUsernames(resp.mostPopularUsernames ?? []);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const refreshGroups = async () => {
|
||||
if (selectedDatabaseIdx == null || currentlySelectedDatabase()?.locked) {
|
||||
|
||||
setGroups([]);
|
||||
setSelectedGroup('');
|
||||
return;
|
||||
}
|
||||
else {
|
||||
|
||||
|
||||
const req = new GetGroupsRequest();
|
||||
req.databaseId = databases[selectedDatabaseIdx].uuid;
|
||||
const grps = await props.getGroups(req);
|
||||
|
||||
if (grps === null || grps.error) {
|
||||
showErrorToast('Could not refresh Groups');
|
||||
setGroups([]);
|
||||
setSelectedGroup('');
|
||||
}
|
||||
else {
|
||||
setGroups(grps.groups);
|
||||
setSelectedGroup(grps.groups.length == 0 ? '' : grps.groups[0].uuid);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const showErrorToast = (message: string, duration = 5000) => {
|
||||
setToastOpen(true);
|
||||
setToastIsError(true);
|
||||
setToastMessage(message);
|
||||
|
||||
setTimeout(() => { setToastOpen(false); }, duration);
|
||||
};
|
||||
|
||||
const handleCreate = async () => {
|
||||
if (!isValidForSubmission() || selectedDatabaseIdx === null) {
|
||||
showErrorToast('There is not a valid new entry.');
|
||||
return;
|
||||
}
|
||||
|
||||
const selectedDatabase = databases[selectedDatabaseIdx];
|
||||
|
||||
const details = new CreateEntryRequest();
|
||||
|
||||
details.databaseId = selectedDatabase.uuid;
|
||||
details.groupId = selectedGroup;
|
||||
details.icon = props.favIconBase64;
|
||||
details.title = title;
|
||||
details.username = username;
|
||||
details.password = password;
|
||||
details.url = document.location.href;
|
||||
|
||||
const result = await props.onCreate(details);
|
||||
|
||||
if (result === null || result.error) {
|
||||
showErrorToast('Could not create new entry. error=[' + result?.error + '');
|
||||
}
|
||||
else {
|
||||
setOpen(false);
|
||||
|
||||
|
||||
if (result.credential != null) {
|
||||
props.onCreatedItem(result.credential);
|
||||
}
|
||||
else {
|
||||
const cred = new AutoFillCredential();
|
||||
cred.username = username;
|
||||
cred.password = password;
|
||||
props.onCreatedItem(cred);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const isValidForSubmission = () => {
|
||||
return hasSelectedValidUnlockedDatabase();
|
||||
};
|
||||
|
||||
const handleChangeDatabase = (event: SelectChangeEvent) => {
|
||||
|
||||
setSelectedDatabaseIdx(+event.target.value);
|
||||
};
|
||||
|
||||
const handleChangeGroup = (event: SelectChangeEvent) => {
|
||||
|
||||
setSelectedGroup(event.target.value);
|
||||
};
|
||||
|
||||
const handleClose = (event: never, reason: string) => {
|
||||
if (reason && reason == "backdropClick") {
|
||||
return;
|
||||
}
|
||||
|
||||
closeDialog();
|
||||
};
|
||||
|
||||
const closeDialog = () => {
|
||||
setOpen(false);
|
||||
};
|
||||
|
||||
const currentlySelectedDatabase = () => {
|
||||
return selectedDatabaseIdx === null ? null : databases[selectedDatabaseIdx];
|
||||
};
|
||||
|
||||
const hasSelectedValidUnlockedDatabase = () => {
|
||||
return selectedDatabaseIdx === null ? false : !databases[selectedDatabaseIdx].locked;
|
||||
};
|
||||
|
||||
const handleUsernameChange = (event: any, newInputValue: string) => {
|
||||
setUsername(newInputValue);
|
||||
};
|
||||
|
||||
const handleClickShowPassword = () => setShowPassword((show) => !show);
|
||||
|
||||
const handleMouseDownPassword = (event: { preventDefault: () => void; }) => {
|
||||
event.preventDefault();
|
||||
};
|
||||
|
||||
const darkTheme = createTheme({
|
||||
palette: { mode: 'dark' },
|
||||
components: {
|
||||
MuiPopover: {
|
||||
defaultProps: {
|
||||
container: props.shadowRootElement,
|
||||
},
|
||||
},
|
||||
MuiPopper: {
|
||||
defaultProps: {
|
||||
container: props.shadowRootElement,
|
||||
},
|
||||
},
|
||||
MuiDialog: {
|
||||
defaultProps: {
|
||||
container: props.shadowRootElement,
|
||||
},
|
||||
},
|
||||
MuiModal: {
|
||||
defaultProps: {
|
||||
container: props.shadowRootElement,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return (
|
||||
<CacheProvider value={props.cache}>
|
||||
<ThemeProvider theme={darkTheme}>
|
||||
<Dialog open={open}
|
||||
disablePortal
|
||||
PaperProps={{
|
||||
style: { borderRadius: 15 }
|
||||
}}
|
||||
sx={{ p: '3px', zIndex: '2147483640' }}
|
||||
|
||||
fullWidth
|
||||
maxWidth='xs'
|
||||
onClose={handleClose}
|
||||
onKeyDown={async (event) => {
|
||||
if (event.metaKey && event.key === 'Enter') {
|
||||
await handleCreate();
|
||||
}
|
||||
}}>
|
||||
<Backdrop
|
||||
sx={{ color: '#fff', zIndex: (theme) => theme.zIndex.drawer + 1 }}
|
||||
open={unlockWaitSpinnerOpen}
|
||||
>
|
||||
<Box sx={{ display: 'flex', gap: '8px' }}>
|
||||
<CircularProgress color="inherit" />
|
||||
<Typography variant='subtitle1'>Please Unlock Your Database...</Typography>
|
||||
</Box>
|
||||
</Backdrop>
|
||||
<DialogTitle align='center' sx={{ pb: 1 }}>
|
||||
<Box sx={{ display: 'flex', justifyContent: 'center', alignItems: 'center', gap: '8px' }}>
|
||||
<Box
|
||||
component="img"
|
||||
sx={{
|
||||
height: 24,
|
||||
width: 24,
|
||||
|
||||
}}
|
||||
src={browser.runtime.getURL('assets/icons/app-icon-circle.png')}
|
||||
/>
|
||||
<Typography
|
||||
color="text.secondary"
|
||||
variant="body1"
|
||||
>Create New Entry</Typography>
|
||||
</Box>
|
||||
</DialogTitle>
|
||||
<DialogContent dividers={true} sx={{ zIndex: '2147483641' }}>
|
||||
<Collapse in={toastOpen}>
|
||||
<Alert
|
||||
severity={toastIsError ? 'error' : 'success'}
|
||||
action={
|
||||
<IconButton
|
||||
aria-label="close"
|
||||
color="inherit"
|
||||
size="small"
|
||||
|
||||
onClick={() => {
|
||||
setToastOpen(false);
|
||||
}}
|
||||
>
|
||||
<Close fontSize="inherit" />
|
||||
</IconButton>
|
||||
}
|
||||
sx={{ mb: 2 }}
|
||||
>
|
||||
<AlertTitle>{toastIsError ? 'Error' : 'Success'}</AlertTitle>
|
||||
{toastMessage}
|
||||
</Alert>
|
||||
</Collapse>
|
||||
<Box sx={{ display: 'flex', flexDirection: 'column', gap: '20px' }} >
|
||||
<Box display={hasSelectedValidUnlockedDatabase() ? '' : 'none'}>
|
||||
<Box sx={{ display: 'flex', flexDirection: 'column', gap: '20px' }}>
|
||||
<Box sx={{ display: 'flex', flexDirection: 'row', gap: '8px', alignItems: 'center' }}>
|
||||
{props.faviconUrl ? (
|
||||
<Box
|
||||
component="img"
|
||||
id='create-new-entry-icon'
|
||||
sx={{
|
||||
height: 32,
|
||||
width: 32,
|
||||
}}
|
||||
src={props.faviconUrl}
|
||||
/>) : (<Lock sx={{
|
||||
height: 32,
|
||||
width: 32,
|
||||
}} htmlColor={StrongboxColours.niceBlue} />)}
|
||||
< TextField
|
||||
autoFocus
|
||||
label="Title"
|
||||
fullWidth
|
||||
value={title}
|
||||
error={title.length === 0 ? true : false}
|
||||
|
||||
onChange={(event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
setTitle(event.target.value);
|
||||
}}
|
||||
></TextField>
|
||||
</Box>
|
||||
<FormControl variant="outlined" fullWidth >
|
||||
<Autocomplete
|
||||
freeSolo
|
||||
selectOnFocus
|
||||
autoHighlight
|
||||
autoComplete
|
||||
handleHomeEndKeys
|
||||
inputValue={username}
|
||||
onInputChange={handleUsernameChange}
|
||||
options={mostPopularUsernames}
|
||||
renderInput={(params) =>
|
||||
<TextField {...params}
|
||||
label="Username"
|
||||
error={username.length === 0 ? true : false} />}
|
||||
/>
|
||||
</FormControl>
|
||||
<Box sx={{ display: 'flex', gap: '3px', alignItems: 'center' }}>
|
||||
<FormControl variant="outlined" fullWidth>
|
||||
<InputLabel htmlFor="outlined-adornment-password">Password</InputLabel>
|
||||
<OutlinedInput
|
||||
value={password}
|
||||
error={password.length === 0 ? true : false}
|
||||
onChange={(event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
setPassword(event.target.value);
|
||||
}}
|
||||
type={showPassword ? 'text' : 'password'}
|
||||
endAdornment={
|
||||
<InputAdornment position="end">
|
||||
<IconButton
|
||||
aria-label="toggle password visibility"
|
||||
onClick={handleClickShowPassword}
|
||||
onMouseDown={handleMouseDownPassword}
|
||||
edge="end"
|
||||
>
|
||||
{showPassword ? <VisibilityOff /> : <Visibility />}
|
||||
</IconButton>
|
||||
</InputAdornment>
|
||||
}
|
||||
label="Password"
|
||||
/>
|
||||
</FormControl>
|
||||
<IconButton onClick={handleGenerateNewPassword} sx={{ height: "40px", width: "40px" }}>
|
||||
<Refresh color='primary' />
|
||||
</IconButton>
|
||||
</Box>
|
||||
</Box>
|
||||
</Box>
|
||||
<Accordion sx={{ borderRadius: '5px' }}
|
||||
expanded={saveInExpanded}
|
||||
onChange={(e, newExpanded) => { setSaveInExpanded(newExpanded || !hasSelectedValidUnlockedDatabase()); }}>
|
||||
<AccordionSummary expandIcon={<ExpandMore />}>
|
||||
<Typography sx={{ color: 'text.secondary', pr: '20px' }} variant='body1' fontWeight='light'>
|
||||
{hasSelectedValidUnlockedDatabase() ? 'Save In' : 'Save In...'}
|
||||
</Typography>
|
||||
<Typography variant='body1' >{hasSelectedValidUnlockedDatabase() ? currentlySelectedDatabase()?.nickName : ''}</Typography>
|
||||
</AccordionSummary>
|
||||
<AccordionDetails >
|
||||
<Box sx={{ display: 'flex', flexDirection: 'column', gap: '20px' }} component='form'>
|
||||
<Box sx={{ display: 'flex', flexDirection: 'row', gap: '4px', alignItems: 'center', justifyItems: 'center', flexGrow: 1 }}>
|
||||
<FormControl fullWidth >
|
||||
<InputLabel>Database</InputLabel>
|
||||
<Select
|
||||
MenuProps={{
|
||||
style: { zIndex: 2147483641 }
|
||||
}}
|
||||
value={databases.length === 0 ? 'no-available-databases' : (selectedDatabaseIdx !== null ? selectedDatabaseIdx.toString() : '')}
|
||||
label="Database"
|
||||
fullWidth
|
||||
disabled={databases.length === 0}
|
||||
onChange={handleChangeDatabase}
|
||||
>
|
||||
{databases.length > 0 ? (databases.map((database, idx) =>
|
||||
(
|
||||
<MenuItem value={idx.toString()} key={idx}>
|
||||
<div style={{ display: 'flex', gap: 5, alignItems: 'center' }}>
|
||||
{database.locked ? (<Lock color='error' />) : (<LockOpen />)}
|
||||
<Box>{database.locked ? database.nickName + ' (Locked)' : database.nickName}</Box>
|
||||
</div>
|
||||
</MenuItem>)
|
||||
)) :
|
||||
(<MenuItem key='no-available-databases' value='no-available-databases' disabled>
|
||||
No AutoFill Databases Available
|
||||
</MenuItem>)
|
||||
}
|
||||
</Select>
|
||||
</FormControl>
|
||||
{currentlySelectedDatabase()?.locked ? (<IconButton onClick={handleUnlockRequest}><LockOpen color='primary' /></IconButton>) : ('')}
|
||||
</Box>
|
||||
<Box display={hasSelectedValidUnlockedDatabase() ? '' : 'none'}>
|
||||
<FormControl fullWidth>
|
||||
<InputLabel>Group</InputLabel>
|
||||
<Select
|
||||
MenuProps={{
|
||||
style: { zIndex: 2147483641 }
|
||||
}}
|
||||
value={selectedGroup}
|
||||
label="Group"
|
||||
fullWidth
|
||||
|
||||
sx={{
|
||||
|
||||
|
||||
|
||||
|
||||
}}
|
||||
onChange={handleChangeGroup}
|
||||
>
|
||||
{groups.map((group, idx) =>
|
||||
(
|
||||
<MenuItem value={group.uuid} key={group.uuid}>
|
||||
<div style={{ display: 'flex', gap: 5, alignItems: 'center' }}>
|
||||
{idx == 0 ? (<Home />) : (<Folder />)}
|
||||
{idx == 0 ? (<Box sx={{ fontStyle: 'italic' }}>{group.title}</Box>) : (<Box>{group.title}</Box>)}
|
||||
</div>
|
||||
</MenuItem>
|
||||
))
|
||||
}
|
||||
</Select>
|
||||
</FormControl>
|
||||
</Box>
|
||||
</Box>
|
||||
</AccordionDetails>
|
||||
</Accordion>
|
||||
</Box>
|
||||
</DialogContent>
|
||||
<DialogActions sx={{ p: 2 }}>
|
||||
<Box sx={{ display: 'flex', justifyContent: 'space-between', flexGrow: '1' }}>
|
||||
<Button onClick={closeDialog}>Cancel</Button>
|
||||
<Button variant="contained" startIcon={<AddCircle />} onClick={async () => { handleCreate(); }} disabled={!isValidForSubmission()} >
|
||||
Create (⌘⏎)
|
||||
</Button>
|
||||
</Box>
|
||||
</DialogActions>
|
||||
</Dialog>
|
||||
</ThemeProvider >
|
||||
</CacheProvider >
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import * as React from 'react';
|
||||
import { createTheme, ThemeProvider } from '@mui/material/styles';
|
||||
import { CacheProvider, EmotionCache } from '@emotion/react';
|
||||
|
||||
export interface EmptyShellProps {
|
||||
shadowRootElement: HTMLElement;
|
||||
cache: EmotionCache;
|
||||
}
|
||||
|
||||
export default function EmptyShell(props: EmptyShellProps) {
|
||||
const darkTheme = createTheme({
|
||||
palette: { mode: 'dark' },
|
||||
components: {
|
||||
MuiPopover: {
|
||||
defaultProps: {
|
||||
container: props.shadowRootElement,
|
||||
},
|
||||
},
|
||||
MuiPopper: {
|
||||
defaultProps: {
|
||||
container: props.shadowRootElement,
|
||||
},
|
||||
},
|
||||
MuiDialog: {
|
||||
defaultProps: {
|
||||
container: props.shadowRootElement,
|
||||
},
|
||||
},
|
||||
MuiModal: {
|
||||
defaultProps: {
|
||||
container: props.shadowRootElement,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return (
|
||||
<CacheProvider value={props.cache}>
|
||||
<ThemeProvider theme={darkTheme}>
|
||||
</ThemeProvider >
|
||||
</CacheProvider>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
|
||||
export default class FormModel {
|
||||
element: HTMLFormElement;
|
||||
|
||||
passwordField: HTMLInputElement | null;
|
||||
|
||||
usernameField: HTMLInputElement | null;
|
||||
|
||||
submitButton: HTMLElement | null;
|
||||
|
||||
constructor(element: HTMLFormElement, passwordField: HTMLInputElement | null, usernameField: HTMLInputElement | null, submitButton: HTMLElement | null) {
|
||||
this.element = element;
|
||||
this.passwordField = passwordField;
|
||||
this.usernameField = usernameField;
|
||||
this.submitButton = submitButton;
|
||||
}
|
||||
|
||||
getUsername(): string | null {
|
||||
if (this.usernameField != null) {
|
||||
return this.usernameField.value;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
getPassword(): string | null {
|
||||
if (this.passwordField != null) {
|
||||
return this.passwordField.value;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
import * as React from 'react';
|
||||
import MenuItem from '@mui/material/MenuItem';
|
||||
import { AutoFillCredential } from '../Messaging/Protocol/AutoFillCredential';
|
||||
import { Box, Button, IconButton, Menu, Typography } from '@mui/material';
|
||||
import { MoreHoriz } from '@mui/icons-material';
|
||||
|
||||
export function InlineMenuCredentialItem(
|
||||
credential: AutoFillCredential,
|
||||
handleCredentialClick: (credential: AutoFillCredential) => void,
|
||||
handleCopyUsername: (credential: AutoFillCredential) => void,
|
||||
handleCopyPassword: (credential: AutoFillCredential) => void,
|
||||
handleCopyTotp: (credential: AutoFillCredential) => void,
|
||||
credentialsAreFromMultipleDatabases: () => boolean
|
||||
): JSX.Element {
|
||||
function getCurrentTotpCode(credential: AutoFillCredential, formatted = true): string {
|
||||
return AutoFillCredential.getCurrentTotpCode(credential, formatted);
|
||||
}
|
||||
|
||||
const handleMoreButtonClick = (event: any) => {
|
||||
setAnchorEl(event.currentTarget);
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
};
|
||||
|
||||
const onCopyUsername = (event: any) => {
|
||||
handleCopyUsername(credential);
|
||||
setAnchorEl(null);
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
};
|
||||
const onCopyPassword = (event: any) => {
|
||||
handleCopyPassword(credential);
|
||||
setAnchorEl(null);
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
};
|
||||
const onCopyTotp = (event: any) => {
|
||||
handleCopyTotp(credential);
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
};
|
||||
|
||||
const handleClose = () => {
|
||||
setAnchorEl(null);
|
||||
};
|
||||
|
||||
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
|
||||
const open = Boolean(anchorEl);
|
||||
|
||||
return <MenuItem key={credential.uuid} onClick={() => { handleCredentialClick(credential); }}>
|
||||
<Box sx={{ display: 'flex', gap: '12px', flexDirection: 'row', alignItems: 'center', flexGrow: 1 }}>
|
||||
<Box sx={{ flexShrink: 1 }}>
|
||||
<Box
|
||||
component="img"
|
||||
display="block"
|
||||
sx={{
|
||||
height: 32,
|
||||
width: 32,
|
||||
borderRadius: '5px'
|
||||
}}
|
||||
alt="Icon"
|
||||
src={credential.icon} />
|
||||
</Box>
|
||||
<Box sx={{ display: 'flex', gap: '0px', flexDirection: 'column', flexGrow: 1, minWidth: '200px' }}>
|
||||
<Box sx={{ display: 'flex', justifyContent: 'space-between', gap: '12px', alignContent: 'center', alignItems: 'center' }}>
|
||||
<Typography sx={{ pb: 0, mb: 0, textAlign: 'left' }} variant='body1'>{credential.title}</Typography>
|
||||
<Box sx={{ display: 'flex', flexDirection: 'row', gap: '1px', justifyItems: 'center', alignItems: 'center' }}>
|
||||
{credential.totp.length > 0 ?
|
||||
(<Button size='small' onClick={onCopyTotp}><Typography sx={{ pb: 0, mb: 0, textAlign: 'left' }} variant='caption'>{getCurrentTotpCode(credential)}</Typography></Button>) : ('')}
|
||||
<Menu
|
||||
id="basic-menu"
|
||||
anchorEl={anchorEl}
|
||||
open={open}
|
||||
onClose={handleClose}
|
||||
sx={{ zIndex: '2147483642' }}
|
||||
MenuListProps={{
|
||||
'aria-labelledby': 'basic-button',
|
||||
}}
|
||||
>
|
||||
<MenuItem onClick={onCopyUsername}>Copy Username</MenuItem>
|
||||
<MenuItem onClick={onCopyPassword}>Copy Password</MenuItem>
|
||||
</Menu>
|
||||
<IconButton size="small" onClick={handleMoreButtonClick} ><MoreHoriz fontSize="small" /></IconButton>
|
||||
</Box>
|
||||
</Box>
|
||||
<Box sx={{ display: 'flex', justifyContent: 'space-between', gap: '12px', alignItems: 'center' }}>
|
||||
<Typography sx={{ color: 'text.secondary' }} variant='body2'>{credential.username}</Typography>
|
||||
{credentialsAreFromMultipleDatabases() ? (<Typography sx={{ color: 'text.disabled' }} variant='body2'>{credential.databaseName}</Typography>) : ('')}
|
||||
</Box>
|
||||
</Box>
|
||||
</Box>
|
||||
</MenuItem>;
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
import ReactDOM from 'react-dom/client';
|
||||
import browser from 'webextension-polyfill';
|
||||
|
||||
export class InlineMiniFieldIcon {
|
||||
fieldElement: HTMLInputElement;
|
||||
iconElement: HTMLElement;
|
||||
reactRoot: ReactDOM.Root;
|
||||
|
||||
isVisible: boolean;
|
||||
|
||||
static readonly INLINE_ICON_SHADOW_CONTAINER_ID = 'strongbox-cs-inline-icon-shadow-container';
|
||||
|
||||
static ensureShadow() {
|
||||
const found = document.getElementById(InlineMiniFieldIcon.INLINE_ICON_SHADOW_CONTAINER_ID);
|
||||
if (!found) {
|
||||
const created = document.createElement('div');
|
||||
created.id = InlineMiniFieldIcon.INLINE_ICON_SHADOW_CONTAINER_ID;
|
||||
document.body.append(created);
|
||||
created.attachShadow({ mode: 'open' });
|
||||
}
|
||||
}
|
||||
|
||||
static getShadowRoot(): ShadowRoot | null {
|
||||
InlineMiniFieldIcon.ensureShadow();
|
||||
|
||||
const found = document.getElementById(InlineMiniFieldIcon.INLINE_ICON_SHADOW_CONTAINER_ID);
|
||||
|
||||
return found?.shadowRoot ?? null;
|
||||
}
|
||||
|
||||
static attachToField(field: HTMLInputElement, disconnected: boolean, clickHandler: () => void): InlineMiniFieldIcon {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
const icon = document.createElement('div');
|
||||
icon.style.zIndex = '2147483640';
|
||||
icon.style.backgroundImage = 'url(' + browser.runtime.getURL('assets/icons/app-icon-circle.png') + ')';
|
||||
icon.style.filter = disconnected ? 'saturate(0%)' : '';
|
||||
icon.style.backgroundSize = 'contain';
|
||||
icon.style.position = 'absolute';
|
||||
|
||||
InlineMiniFieldIcon.getShadowRoot()?.append(icon);
|
||||
|
||||
const miniIcon = new InlineMiniFieldIcon();
|
||||
|
||||
miniIcon.fieldElement = field;
|
||||
miniIcon.iconElement = icon;
|
||||
|
||||
miniIcon.bindIconPosition();
|
||||
miniIcon.bindVisibilityToFocus();
|
||||
|
||||
|
||||
|
||||
miniIcon.iconElement.addEventListener('click', () => { clickHandler(); });
|
||||
|
||||
return miniIcon;
|
||||
}
|
||||
|
||||
detach() {
|
||||
|
||||
this.show(false);
|
||||
|
||||
}
|
||||
|
||||
async show(show = true) {
|
||||
if (show == this.isVisible) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!show) {
|
||||
this.iconElement.style.display = 'none';
|
||||
this.isVisible = false;
|
||||
}
|
||||
else {
|
||||
this.iconElement.style.removeProperty('display');
|
||||
this.isVisible = true;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
async bindVisibilityToFocus() {
|
||||
const isDomFocused = document.activeElement === this.fieldElement;
|
||||
|
||||
|
||||
await this.show(isDomFocused);
|
||||
}
|
||||
|
||||
bindIconPosition() {
|
||||
|
||||
|
||||
|
||||
const size = (this.fieldElement.offsetHeight > 28) ? 24 : 16;
|
||||
this.iconElement.style.width = InlineMiniFieldIcon.pixelsCssString(size);
|
||||
this.iconElement.style.height = InlineMiniFieldIcon.pixelsCssString(size);
|
||||
|
||||
const rect = this.fieldElement.getBoundingClientRect();
|
||||
const left = InlineMiniFieldIcon.getRelativeLeftPosition(rect);
|
||||
const top = InlineMiniFieldIcon.getRelativeTopPosition(rect);
|
||||
|
||||
const scrollTop = document.scrollingElement ? document.scrollingElement.scrollTop : 0;
|
||||
const scrollLeft = document.scrollingElement ? document.scrollingElement.scrollLeft : 0;
|
||||
|
||||
const offset = InlineMiniFieldIcon.calculateIconOffset(this.fieldElement, size);
|
||||
|
||||
this.iconElement.style.top = InlineMiniFieldIcon.pixelsCssString(top + scrollTop + offset);
|
||||
this.iconElement.style.left = InlineMiniFieldIcon.pixelsCssString(left + scrollLeft + this.fieldElement.offsetWidth - size - offset);
|
||||
}
|
||||
|
||||
static calculateIconOffset(field: HTMLElement, size: number) {
|
||||
const middle = field.offsetHeight / 2;
|
||||
const foo = middle - size / 2;
|
||||
|
||||
const offset = foo;
|
||||
|
||||
return (offset < 0) ? 0 : offset;
|
||||
}
|
||||
|
||||
static getRelativeLeftPosition(rect: DOMRect) {
|
||||
return rect.left;
|
||||
|
||||
|
||||
}
|
||||
|
||||
static getRelativeTopPosition(rect: DOMRect) {
|
||||
return rect.top;
|
||||
|
||||
|
||||
}
|
||||
|
||||
static pixelsCssString(value: number) {
|
||||
return String(value) + 'px';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,242 @@
|
||||
import * as React from 'react';
|
||||
import { createTheme, ThemeProvider } from '@mui/material/styles';
|
||||
import MenuItem from '@mui/material/MenuItem';
|
||||
import { AutoFillCredential } from '../Messaging/Protocol/AutoFillCredential';
|
||||
import { Box, ClickAwayListener, Divider, MenuList, Paper, Popper } from '@mui/material';
|
||||
import browser from 'webextension-polyfill';
|
||||
import { CacheProvider, EmotionCache } from '@emotion/react';
|
||||
import { ContentScriptManager } from './ContentScriptManager';
|
||||
import { LastKnownDatabasesItem } from '../Settings/Settings';
|
||||
import { ExploreOffOutlined, LockOpenOutlined, SearchOff } from '@mui/icons-material';
|
||||
import { InlineMenuCredentialItem } from './InlineMenuCredentialItem';
|
||||
|
||||
interface InlineMiniFieldMenuProps {
|
||||
anchorEl: HTMLElement;
|
||||
unlockedDatabaseAvailable: boolean;
|
||||
showCreateNew: boolean;
|
||||
credentials: AutoFillCredential[];
|
||||
onCreateNewEntry: () => void;
|
||||
onLaunchStrongbox: () => void;
|
||||
onUnlockDatabase: (databaseUuid: string) => void;
|
||||
onFillWithCredential: (credential: AutoFillCredential) => Promise<void>;
|
||||
isPasswordField: boolean;
|
||||
shadowRootElement: HTMLElement;
|
||||
cache: EmotionCache;
|
||||
show: boolean;
|
||||
unlockableDatabases: LastKnownDatabasesItem[];
|
||||
onCopyUsername: (credential: AutoFillCredential) => void;
|
||||
onCopyPassword: (credential: AutoFillCredential) => void;
|
||||
onCopyTotp: (credential: AutoFillCredential) => void;
|
||||
}
|
||||
|
||||
export default function InlineMiniFieldMenu(props: InlineMiniFieldMenuProps) {
|
||||
const [anchorEl] = React.useState<HTMLElement | null>(props.anchorEl);
|
||||
const [open, setOpen] = React.useState(Boolean(props.show));
|
||||
const [focusFirstItem, setFocusFirstItem] = React.useState(false);
|
||||
const [filterCredentials, setFilteredCredentials] = React.useState(props.credentials);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (anchorEl) {
|
||||
|
||||
const listener = handleKeyDownInAnchorElement;
|
||||
anchorEl.addEventListener('keyup', listener);
|
||||
|
||||
const blurListener = handleBlurOnAnchorElement;
|
||||
anchorEl.addEventListener('blur', blurListener);
|
||||
|
||||
|
||||
|
||||
return () => {
|
||||
|
||||
anchorEl.removeEventListener('keyup', listener);
|
||||
anchorEl.removeEventListener('blur', blurListener);
|
||||
};
|
||||
}
|
||||
else {
|
||||
}
|
||||
}, [anchorEl]);
|
||||
|
||||
const credentialsAreFromMultipleDatabases = () => {
|
||||
const dbs = filterCredentials.map(credential => credential.databaseId);
|
||||
const uniqueDbs = new Set(dbs);
|
||||
return uniqueDbs.size > 1;
|
||||
};
|
||||
|
||||
const handleBlurOnAnchorElement = (event: FocusEvent) => {
|
||||
if (anchorEl) {
|
||||
const rt = event.relatedTarget as HTMLElement;
|
||||
|
||||
if (rt && rt.id === ContentScriptManager.INLINE_MENU_SHADOW_CONTAINER_ID) {
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
hideMenu(false);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const handleKeyDownInAnchorElement = (event: KeyboardEvent) => {
|
||||
if (anchorEl) {
|
||||
const inputElement = anchorEl as HTMLInputElement;
|
||||
|
||||
|
||||
if (event.key === 'Escape') {
|
||||
hideMenu();
|
||||
}
|
||||
else if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
||||
|
||||
setOpen(true);
|
||||
setFocusFirstItem(true);
|
||||
}
|
||||
else {
|
||||
if (!props.isPasswordField) {
|
||||
const filtered = props.credentials.filter(credential => {
|
||||
return credential.username.toLocaleUpperCase().indexOf(inputElement.value.toLocaleUpperCase()) !== -1 ||
|
||||
credential.title.toLocaleUpperCase().indexOf(inputElement.value.toLocaleUpperCase()) !== -1;
|
||||
}
|
||||
);
|
||||
setFilteredCredentials(filtered);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const handleCreateNewEntry = () => {
|
||||
hideMenu(false);
|
||||
props.onCreateNewEntry();
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
const handleUnlockDatabase = (databaseUuid: string) => {
|
||||
hideMenu(false);
|
||||
props.onUnlockDatabase(databaseUuid);
|
||||
};
|
||||
|
||||
const hideMenu = (restoreFocus = true) => {
|
||||
|
||||
setOpen(false);
|
||||
|
||||
if (restoreFocus && anchorEl) {
|
||||
anchorEl.focus();
|
||||
}
|
||||
};
|
||||
|
||||
const handleClickAway = (event: Event) => {
|
||||
|
||||
if (event.target != anchorEl) {
|
||||
hideMenu(false);
|
||||
}
|
||||
else {
|
||||
}
|
||||
};
|
||||
|
||||
const handleCredentialClick = (credential: AutoFillCredential) => {
|
||||
hideMenu(false);
|
||||
props.onFillWithCredential(credential);
|
||||
};
|
||||
|
||||
const handleCopyUsername = (credential: AutoFillCredential) => { props.onCopyUsername(credential); hideMenu(false); };
|
||||
const handleCopyPassword = (credential: AutoFillCredential) => { props.onCopyPassword(credential); hideMenu(false); };
|
||||
const handleCopyTotp = (credential: AutoFillCredential) => { props.onCopyTotp(credential); hideMenu(false); };
|
||||
|
||||
const darkTheme = createTheme({
|
||||
palette: { mode: 'dark' },
|
||||
components: {
|
||||
MuiPopover: {
|
||||
defaultProps: {
|
||||
container: props.shadowRootElement,
|
||||
},
|
||||
},
|
||||
MuiPopper: {
|
||||
defaultProps: {
|
||||
container: props.shadowRootElement,
|
||||
},
|
||||
},
|
||||
MuiDialog: {
|
||||
defaultProps: {
|
||||
container: props.shadowRootElement,
|
||||
},
|
||||
},
|
||||
MuiModal: {
|
||||
defaultProps: {
|
||||
container: props.shadowRootElement,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return (
|
||||
<CacheProvider value={props.cache}>
|
||||
<ThemeProvider theme={darkTheme}>
|
||||
<ClickAwayListener onClickAway={(event) => handleClickAway(event)}>
|
||||
<Popper sx={{ zIndex: '2147483640' }}
|
||||
open={open}
|
||||
anchorEl={anchorEl}
|
||||
placement='bottom-start'
|
||||
onKeyDown={(event) => {
|
||||
if (event.key === 'Escape') {
|
||||
hideMenu(true);
|
||||
}
|
||||
}}>
|
||||
<Paper sx={{ mt: '1px', borderRadius: '15px', maxWidth: '400px', overflow: 'hidden' }}>
|
||||
<MenuList autoFocusItem={focusFirstItem} disabledItemsFocusable={true}>
|
||||
{(filterCredentials.length === 0 && props.unlockedDatabaseAvailable) ? (<MenuItem disabled dense>
|
||||
<Box sx={{ display: 'flex', gap: '12px', alignItems: 'center' }}>
|
||||
<SearchOff />
|
||||
No Matching Entries Found
|
||||
</Box>
|
||||
</MenuItem>) : ('')}
|
||||
{filterCredentials.map((credential) => (
|
||||
InlineMenuCredentialItem(credential, handleCredentialClick, handleCopyUsername, handleCopyPassword, handleCopyTotp, credentialsAreFromMultipleDatabases)))
|
||||
}
|
||||
{((props.unlockableDatabases.length !== 0 && props.unlockedDatabaseAvailable)) ? (<Divider />) : ''}
|
||||
{props.unlockableDatabases.map((database) => (
|
||||
<MenuItem dense onClick={() => handleUnlockDatabase(database.uuid)}
|
||||
key={database.uuid}>
|
||||
<Box sx={{ display: 'flex', gap: '12px', alignItems: 'center' }}>
|
||||
<LockOpenOutlined htmlColor='orange' />
|
||||
Unlock {database.nickName}
|
||||
</Box>
|
||||
</MenuItem>
|
||||
))}
|
||||
{(props.showCreateNew && ((filterCredentials.length !== 0 || (filterCredentials.length === 0 && props.unlockedDatabaseAvailable)) || (props.unlockableDatabases.length !== 0))) ? (<Divider />) : ''}
|
||||
{!props.showCreateNew ? '' : (
|
||||
<MenuItem dense onClick={handleCreateNewEntry} key='create-new-item-menu-item'>
|
||||
<Box sx={{ display: 'flex', gap: '12px', alignItems: 'center' }}>
|
||||
<Box
|
||||
component="img"
|
||||
sx={{
|
||||
height: 24,
|
||||
width: 24,
|
||||
|
||||
}}
|
||||
src={browser.runtime.getURL('assets/icons/app-icon-circle.png')}
|
||||
/>
|
||||
Create New in Strongbox
|
||||
</Box>
|
||||
</MenuItem>)
|
||||
}
|
||||
{!props.showCreateNew && props.unlockableDatabases.length == 0 && filterCredentials.length === 0 ? (
|
||||
<MenuItem disabled dense>
|
||||
<Box sx={{ display: 'flex', gap: '12px', alignItems: 'center' }}>
|
||||
<ExploreOffOutlined />
|
||||
No AutoFill Enabled Databases
|
||||
</Box>
|
||||
</MenuItem>) :
|
||||
('')
|
||||
}
|
||||
</MenuList>
|
||||
</Paper>
|
||||
</Popper>
|
||||
</ClickAwayListener>
|
||||
</ThemeProvider >
|
||||
</CacheProvider>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
import * as React from 'react';
|
||||
import { Alert, createTheme, Portal, Snackbar, ThemeProvider } from '@mui/material';
|
||||
import { CacheProvider, EmotionCache } from '@emotion/react';
|
||||
|
||||
export interface NotificationToastProps {
|
||||
shadowRootElement: HTMLElement;
|
||||
cache: EmotionCache;
|
||||
}
|
||||
|
||||
export default function NotificationToast(props: NotificationToastProps) {
|
||||
const [snackBarOpen, setSnackBarOpen] = React.useState<boolean>(true);
|
||||
|
||||
const handleCloseSnackBar = () => {
|
||||
setSnackBarOpen(false);
|
||||
};
|
||||
|
||||
const darkTheme = createTheme({
|
||||
palette: { mode: 'dark' },
|
||||
components: {
|
||||
MuiPopover: {
|
||||
defaultProps: {
|
||||
container: props.shadowRootElement,
|
||||
},
|
||||
},
|
||||
MuiPopper: {
|
||||
defaultProps: {
|
||||
container: props.shadowRootElement,
|
||||
},
|
||||
},
|
||||
MuiDialog: {
|
||||
defaultProps: {
|
||||
container: props.shadowRootElement,
|
||||
},
|
||||
},
|
||||
MuiModal: {
|
||||
defaultProps: {
|
||||
container: props.shadowRootElement,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return (
|
||||
<CacheProvider value={props.cache}>
|
||||
<ThemeProvider theme={darkTheme}>
|
||||
<Snackbar open={snackBarOpen} autoHideDuration={3000} onClose={handleCloseSnackBar}>
|
||||
<Alert onClose={handleCloseSnackBar} severity="success" sx={{ width: '100%' }}>
|
||||
Successfully Created New Entry
|
||||
</Alert>
|
||||
</Snackbar>
|
||||
</ThemeProvider>
|
||||
</CacheProvider>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
export class PageAnalyser {
|
||||
static getAllUsernameInputs(visible = true): HTMLInputElement[] {
|
||||
const all = this.getAllInputs(visible);
|
||||
|
||||
const result = all.filter((input) => PageAnalyser.isUsernameInput(input));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static getAllPasswordInputs(visible = true): HTMLInputElement[] {
|
||||
const all = this.getAllInputs(visible);
|
||||
|
||||
const result = all.filter((input) => PageAnalyser.isPasswordInput(input));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static getAllInputs(visible = true): HTMLInputElement[] {
|
||||
const inputs = Array.from<HTMLInputElement>(
|
||||
document.getElementsByTagName('input')
|
||||
);
|
||||
|
||||
|
||||
|
||||
const iframes = Array.from<HTMLIFrameElement>(
|
||||
document.getElementsByTagName('iframe')
|
||||
);
|
||||
|
||||
|
||||
|
||||
for (const iframe of iframes) {
|
||||
|
||||
|
||||
const iframeInputs = iframe.contentDocument?.getElementsByTagName('input');
|
||||
if (iframeInputs) {
|
||||
const iframeInputsArray = Array.from<HTMLInputElement>(iframeInputs);
|
||||
|
||||
|
||||
|
||||
inputs.push(...iframeInputsArray);
|
||||
}
|
||||
}
|
||||
|
||||
return inputs.filter(input => !visible || PageAnalyser.isInputVisible(input));
|
||||
}
|
||||
|
||||
static isPasswordInput(input: HTMLInputElement) {
|
||||
return input.type === 'password';
|
||||
}
|
||||
|
||||
static isUsernameInput(input: HTMLInputElement) {
|
||||
const isInteresting = input.type === 'email' ||
|
||||
input.type === 'text' ||
|
||||
input.type === 'username' ||
|
||||
input.type === 'tel';
|
||||
|
||||
if (!isInteresting) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const usernameLikeFieldMatches = [
|
||||
"user",
|
||||
"email",
|
||||
"e-mail",
|
||||
"customer",
|
||||
"login",
|
||||
"acct",
|
||||
"account",
|
||||
"clientnumber",
|
||||
|
||||
"benutzer",
|
||||
"alias"];
|
||||
|
||||
|
||||
|
||||
return PageAnalyser.inputFieldMatchesStrings(input, usernameLikeFieldMatches) && !PageAnalyser.isSearchInput(input);
|
||||
}
|
||||
|
||||
static isSearchInput(input: HTMLInputElement) {
|
||||
if (input.type === 'search') {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const searchMatchNames: string[] = ['search'];
|
||||
|
||||
return PageAnalyser.inputFieldMatchesStrings(input, searchMatchNames);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static inputFieldMatchesStrings(input: HTMLInputElement, matchNames: string[]) {
|
||||
if (PageAnalyser.stringFuzzyContainsAny(input.id, matchNames)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (PageAnalyser.stringFuzzyContainsAny(input.name, matchNames)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (PageAnalyser.stringFuzzyContainsAny(input.autocomplete, matchNames)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (PageAnalyser.stringFuzzyContainsAny(input.placeholder, matchNames)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (PageAnalyser.stringFuzzyContainsAny(input.title, matchNames)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (input.ariaLabel && PageAnalyser.stringFuzzyContainsAny(input.ariaLabel, matchNames)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
input.labels?.forEach(label => {
|
||||
if (PageAnalyser.stringFuzzyContainsAny(label.innerText, matchNames)) {
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
for (let i = 0, atts = input.attributes, n = atts.length; i < n; i++) {
|
||||
const att = atts[i];
|
||||
|
||||
|
||||
if (att.nodeValue && PageAnalyser.stringFuzzyContainsAny(att.nodeValue, matchNames)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static stringFuzzyContainsAny(string1: string, matches: string[]): boolean {
|
||||
if (string1 === undefined || string1 === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const result = matches.find((match) => { return PageAnalyser.stringFuzzyContains(string1, match); });
|
||||
|
||||
return result != undefined;
|
||||
}
|
||||
|
||||
static stringFuzzyContains(string1: string, match: string) {
|
||||
const value1 = string1.replace(/(?:\r\n|\r|\n)/g, "").trim().toLowerCase();
|
||||
|
||||
return value1.indexOf(match.toLowerCase()) !== -1;
|
||||
}
|
||||
|
||||
static isInputVisible(element: HTMLInputElement) {
|
||||
let theEl: HTMLElement | null = element as HTMLElement;
|
||||
|
||||
for (; theEl;) {
|
||||
|
||||
if (!!(theEl.offsetParent || theEl.offsetWidth || theEl.offsetHeight || theEl.getClientRects().length) === false) {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const style = theEl.style;
|
||||
|
||||
if ('none' === style.display || 'hidden' == style.visibility) {
|
||||
|
||||
return false;
|
||||
}
|
||||
const computedStyle = getComputedStyle(theEl);
|
||||
if ('none' === computedStyle.display || 'hidden' == computedStyle.visibility) {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
theEl = theEl.parentElement;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
import { PageAnalyser } from "./PageAnalyser";
|
||||
import browser from 'webextension-polyfill';
|
||||
import FormModel from "./FormModel";
|
||||
|
||||
export class SubmissionCatcher {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
@keyframes strongbox-autofill-animated {
|
||||
0% {
|
||||
transform: scale(1, 1);
|
||||
}
|
||||
|
||||
50% {
|
||||
transform: scale(1.2, 1.2);
|
||||
}
|
||||
|
||||
100% {
|
||||
transform: scale(1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
.com-phoebecode-strongbox-autofill-animated {
|
||||
animation: strongbox-autofill-animated 200ms ease-in-out 0ms 1;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import browser from 'webextension-polyfill';
|
||||
import './content.css';
|
||||
import { ContentScriptManager } from './ContentScriptManager';
|
||||
|
||||
const contentScriptManager = new ContentScriptManager();
|
||||
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', afterDOMLoaded);
|
||||
} else {
|
||||
afterDOMLoaded();
|
||||
}
|
||||
|
||||
function afterDOMLoaded() {
|
||||
contentScriptManager.onDOMLoaded();
|
||||
}
|
||||
|
||||
browser.runtime.onMessage.addListener((message): void => {
|
||||
if (message.credential) {
|
||||
contentScriptManager.autoFillWithCredential(message.credential, message.onLoadFill, null, false, true);
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,277 @@
|
||||
import nacl, { BoxKeyPair } from 'tweetnacl';
|
||||
import { NativeMessagingHelper } from '../Messaging/NativeMessagingHelper';
|
||||
import { AutoFillEncryptedRequest } from './Protocol/AutoFillEncryptedRequest';
|
||||
import { AutoFillEncryptedResponse } from './Protocol/AutoFillEncryptedResponse';
|
||||
import { AutoFillMessageType } from './Protocol/AutoFillMessageType';
|
||||
import { CopyFieldRequest, CopyFieldResponse } from './Protocol/CopyFieldRequest';
|
||||
import { CreateEntryRequest } from './Protocol/CreateEntryRequest';
|
||||
import { CreateEntryResponse } from './Protocol/CreateEntryResponse';
|
||||
import { CredentialsForUrlRequest } from './Protocol/CredentialsForUrlRequest';
|
||||
import { CredentialsForUrlResponse } from './Protocol/CredentialsForUrlResponse';
|
||||
import { GeneratePasswordRequest } from './Protocol/GeneratePasswordRequest';
|
||||
import { GeneratePasswordResponse } from './Protocol/GeneratePasswordResponse';
|
||||
import { GetGroupsRequest } from './Protocol/GetGroupsRequest';
|
||||
import { GetGroupsResponse } from './Protocol/GetGroupsResponse';
|
||||
import { GetNewEntryDefaultsRequest } from './Protocol/GetNewEntryDefaultsRequest';
|
||||
import { GetNewEntryDefaultsResponse } from './Protocol/GetNewEntryDefaultsResponse';
|
||||
import { GetStatusResponse } from './Protocol/GetStatusResponse';
|
||||
import { LockRequest } from './Protocol/LockRequest';
|
||||
import { LockResponse } from './Protocol/LockResponse';
|
||||
import { SearchRequest } from './Protocol/SearchRequest';
|
||||
import { UnlockRequest } from './Protocol/UnlockRequest';
|
||||
import { UnlockResponse } from './Protocol/UnlockResponse';
|
||||
import { WellKnownField } from './Protocol/WellKnownField';
|
||||
|
||||
export class NativeAppApi {
|
||||
private static instance: NativeAppApi;
|
||||
private keyPair: BoxKeyPair;
|
||||
private latestServerPublicKey: string | undefined;
|
||||
|
||||
private constructor() {
|
||||
this.keyPair = nacl.box.keyPair();
|
||||
}
|
||||
|
||||
public static getInstance(): NativeAppApi {
|
||||
if (!NativeAppApi.instance) {
|
||||
NativeAppApi.instance = new NativeAppApi();
|
||||
}
|
||||
|
||||
return NativeAppApi.instance;
|
||||
}
|
||||
|
||||
public async launchStrongbox(): Promise<boolean> {
|
||||
try {
|
||||
const response = await NativeMessagingHelper.getInstance().ping({ 'launch': true });
|
||||
|
||||
|
||||
return response.success;
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public async getStatus(): Promise<GetStatusResponse | null> {
|
||||
const startTime = performance.now();
|
||||
|
||||
const request = new AutoFillEncryptedRequest();
|
||||
request.messageType = AutoFillMessageType.status;
|
||||
request.clientPublicKey = this.byteArrayToBase64(this.keyPair.publicKey);
|
||||
|
||||
const status = await this.sendMessage<GetStatusResponse>(request);
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
public async createEntry(details: CreateEntryRequest): Promise<CreateEntryResponse | null> {
|
||||
const encrypted = await this.buildEncryptedRequest(details, AutoFillMessageType.createEntry);
|
||||
|
||||
|
||||
return await this.sendMessage<CreateEntryResponse>(encrypted);
|
||||
}
|
||||
|
||||
public async getGroups(details: GetGroupsRequest): Promise<GetGroupsResponse | null> {
|
||||
const encrypted = await this.buildEncryptedRequest(details, AutoFillMessageType.getGroups);
|
||||
|
||||
return await this.sendMessage<GetGroupsResponse>(encrypted);
|
||||
}
|
||||
|
||||
public async getNewEntryDefaults(details: GetNewEntryDefaultsRequest): Promise<GetNewEntryDefaultsResponse | null> {
|
||||
const encrypted = await this.buildEncryptedRequest(details, AutoFillMessageType.getNewEntryDefaults);
|
||||
|
||||
return await this.sendMessage<GetNewEntryDefaultsResponse>(encrypted);
|
||||
}
|
||||
|
||||
public async generatePassword(details: GeneratePasswordRequest): Promise<GeneratePasswordResponse | null> {
|
||||
const encrypted = await this.buildEncryptedRequest(details, AutoFillMessageType.generatePassword);
|
||||
|
||||
return await this.sendMessage<GeneratePasswordResponse>(encrypted);
|
||||
}
|
||||
|
||||
public async credentialsForUrl(url: string): Promise<CredentialsForUrlResponse | null> {
|
||||
const credRequest = new CredentialsForUrlRequest();
|
||||
credRequest.url = url;
|
||||
|
||||
const encrypted = await this.buildEncryptedRequest(credRequest, AutoFillMessageType.getCredentialsForUrl);
|
||||
|
||||
return await this.sendMessage<CredentialsForUrlResponse>(encrypted);
|
||||
}
|
||||
|
||||
public async copyField(databaseId: string, nodeId: string, field: WellKnownField, explicitTotp = false): Promise<CopyFieldResponse | null> {
|
||||
const request = new CopyFieldRequest();
|
||||
request.databaseId = databaseId;
|
||||
request.nodeId = nodeId;
|
||||
request.field = field;
|
||||
request.explicitTotp = explicitTotp;
|
||||
|
||||
const encrypted = await this.buildEncryptedRequest(request, AutoFillMessageType.copyField);
|
||||
|
||||
return await this.sendMessage<CopyFieldResponse>(encrypted);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async unlockDatabase(databaseId: string): Promise<UnlockResponse | null> {
|
||||
const request = new UnlockRequest();
|
||||
request.databaseId = databaseId;
|
||||
|
||||
const encrypted = await this.buildEncryptedRequest(request, AutoFillMessageType.unlock);
|
||||
return await this.sendMessage<UnlockResponse>(encrypted);
|
||||
}
|
||||
|
||||
public async lockDatabase(databaseId: string): Promise<LockResponse | null> {
|
||||
const request = new LockRequest();
|
||||
request.databaseId = databaseId;
|
||||
const encrypted = await this.buildEncryptedRequest(request, AutoFillMessageType.lock);
|
||||
return await this.sendMessage<LockResponse>(encrypted);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private async sendMessage<Type>(msg: unknown | null): Promise<Type | null> {
|
||||
if (msg === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
const response: AutoFillEncryptedResponse = await NativeMessagingHelper.getInstance().ping(msg);
|
||||
return this.handleResponse<Type>(response);
|
||||
} catch (error) {
|
||||
this.latestServerPublicKey = undefined;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private handleResponse<Type>(response: AutoFillEncryptedResponse): Type | null {
|
||||
if (response.success) {
|
||||
const messageBytes = this.base64ToByteArray(response.message);
|
||||
const nonceBytes = this.base64ToByteArray(response.nonce);
|
||||
this.latestServerPublicKey = response.serverPublicKey;
|
||||
|
||||
|
||||
|
||||
const serverPk = this.base64ToByteArray(response.serverPublicKey);
|
||||
|
||||
const decryptedBytes = nacl.box.open(
|
||||
messageBytes,
|
||||
nonceBytes,
|
||||
serverPk,
|
||||
this.keyPair.secretKey
|
||||
);
|
||||
|
||||
if (decryptedBytes == null) {
|
||||
this.latestServerPublicKey = undefined;
|
||||
return null;
|
||||
}
|
||||
|
||||
const string = new TextDecoder().decode(decryptedBytes);
|
||||
const object: Type = JSON.parse(string);
|
||||
|
||||
return object;
|
||||
} else {
|
||||
this.latestServerPublicKey = undefined;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private async encryptMessage(
|
||||
message: string,
|
||||
nonce: Uint8Array
|
||||
): Promise<string | null> {
|
||||
|
||||
|
||||
await this.ensureServerPublicKey();
|
||||
|
||||
if (this.latestServerPublicKey) {
|
||||
const encoded = new TextEncoder().encode(message);
|
||||
const serverPk = this.base64ToByteArray(this.latestServerPublicKey);
|
||||
|
||||
const cipherText = nacl.box(
|
||||
encoded,
|
||||
nonce,
|
||||
serverPk,
|
||||
this.keyPair.secretKey
|
||||
);
|
||||
|
||||
|
||||
|
||||
return this.byteArrayToBase64(cipherText);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private async ensureServerPublicKey() {
|
||||
|
||||
|
||||
if (!this.latestServerPublicKey) {
|
||||
|
||||
await this.getStatus();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private async buildEncryptedRequest<Type>(
|
||||
innerRequest: Type, messageType: AutoFillMessageType
|
||||
): Promise<AutoFillEncryptedRequest | null> {
|
||||
|
||||
const json = JSON.stringify(innerRequest);
|
||||
const nonce = this.generateNonce();
|
||||
const base64Encrypted = await this.encryptMessage(json, nonce);
|
||||
|
||||
if (base64Encrypted === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const request = new AutoFillEncryptedRequest();
|
||||
|
||||
request.messageType = messageType;
|
||||
request.clientPublicKey = this.byteArrayToBase64(this.keyPair.publicKey);
|
||||
request.nonce = this.byteArrayToBase64(nonce);
|
||||
request.message = base64Encrypted;
|
||||
|
||||
|
||||
|
||||
return request;
|
||||
}
|
||||
|
||||
private generateNonce(): Uint8Array {
|
||||
return nacl.randomBytes(nacl.box.nonceLength);
|
||||
}
|
||||
|
||||
private byteArrayToBase64(bytes: Uint8Array): string {
|
||||
let binary = '';
|
||||
const len = bytes.byteLength;
|
||||
|
||||
for (let i = 0; i < len; i++) {
|
||||
binary += String.fromCharCode(bytes[i]);
|
||||
}
|
||||
|
||||
return btoa(binary);
|
||||
}
|
||||
|
||||
private base64ToByteArray(base64: string): Uint8Array {
|
||||
const binary_string = atob(base64);
|
||||
const len = binary_string.length;
|
||||
const bytes = new Uint8Array(len);
|
||||
|
||||
for (let i = 0; i < len; i++) {
|
||||
bytes[i] = binary_string.charCodeAt(i);
|
||||
}
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async search(query: string) {
|
||||
|
||||
const searchRequest = new SearchRequest();
|
||||
|
||||
searchRequest.query = query;
|
||||
|
||||
const encrypted = this.buildEncryptedRequest(searchRequest, AutoFillMessageType.search);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import browser from 'webextension-polyfill';
|
||||
import { AutoFillEncryptedResponse } from './Protocol/AutoFillEncryptedResponse';
|
||||
|
||||
export class NativeMessagingHelper {
|
||||
private static instance: NativeMessagingHelper;
|
||||
|
||||
private constructor() {
|
||||
|
||||
}
|
||||
|
||||
public static getInstance(): NativeMessagingHelper {
|
||||
if (!NativeMessagingHelper.instance) {
|
||||
NativeMessagingHelper.instance = new NativeMessagingHelper();
|
||||
}
|
||||
|
||||
return NativeMessagingHelper.instance;
|
||||
}
|
||||
|
||||
private static AppId = 'com.markmcguill.strongbox';
|
||||
|
||||
public async ping(message: unknown): Promise<AutoFillEncryptedResponse> {
|
||||
return browser.runtime.sendNativeMessage(
|
||||
NativeMessagingHelper.AppId,
|
||||
message
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import * as OTPAuth from 'otpauth';
|
||||
|
||||
export class AutoFillCredential {
|
||||
databaseId = '';
|
||||
uuid = '';
|
||||
title = '';
|
||||
username = '';
|
||||
password = '';
|
||||
url = '';
|
||||
totp = '';
|
||||
icon = '';
|
||||
customFields: { [key: string]: [value: string]; } = {};
|
||||
databaseName = 'Foo';
|
||||
tags: string[] = [];
|
||||
favourite = false;
|
||||
|
||||
static getCurrentTotpCode(credential: AutoFillCredential, formatted = true): string {
|
||||
if (credential.totp.length > 0) {
|
||||
try {
|
||||
const parsedTotp = OTPAuth.URI.parse(credential.totp);
|
||||
const code = parsedTotp.generate();
|
||||
|
||||
if (code.length > 0 && formatted) {
|
||||
const middle = Math.floor(code.length / 2);
|
||||
if (middle > 0) {
|
||||
return code.substring(0, middle) + '-' + code.substring(middle);
|
||||
}
|
||||
else {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return code;
|
||||
}
|
||||
} catch (error) {
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import { AutoFillMessageType } from './AutoFillMessageType';
|
||||
|
||||
export class AutoFillEncryptedRequest {
|
||||
public clientPublicKey = 'foo';
|
||||
public nonce = '';
|
||||
public message = 'message';
|
||||
public messageType: AutoFillMessageType = AutoFillMessageType.status;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
export class AutoFillEncryptedResponse {
|
||||
public success = false;
|
||||
public errorMessage = '';
|
||||
public serverPublicKey = '';
|
||||
public message = '';
|
||||
public nonce = '';
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
export enum AutoFillMessageType {
|
||||
status,
|
||||
search,
|
||||
getCredentialsForUrl,
|
||||
copyField,
|
||||
lock,
|
||||
unlock,
|
||||
createEntry,
|
||||
getGroups,
|
||||
getNewEntryDefaults,
|
||||
generatePassword,
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { WellKnownField } from "./WellKnownField";
|
||||
|
||||
export class CopyFieldRequest {
|
||||
databaseId = '';
|
||||
nodeId = '';
|
||||
field: WellKnownField;
|
||||
explicitTotp = false;
|
||||
}
|
||||
|
||||
export class CopyFieldResponse {
|
||||
success: boolean;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
|
||||
export class CreateEntryRequest {
|
||||
databaseId: string;
|
||||
groupId: string | null;
|
||||
icon: string | null;
|
||||
title: string | null;
|
||||
username: string | null;
|
||||
password: string | null;
|
||||
url: string | null;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import { AutoFillCredential } from "./AutoFillCredential";
|
||||
|
||||
export class CreateEntryResponse {
|
||||
uuid: string | null;
|
||||
error: string | null;
|
||||
credential: AutoFillCredential | null;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export class CredentialsForUrlRequest {
|
||||
url: string;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { AutoFillCredential } from './AutoFillCredential';
|
||||
|
||||
export class CredentialsForUrlResponse {
|
||||
unlockedDatabaseCount: number;
|
||||
results: [AutoFillCredential];
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
export class DatabaseSummary {
|
||||
public uuid: string;
|
||||
public nickName: string;
|
||||
public locked: boolean;
|
||||
public autoFillEnabled: boolean;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
|
||||
export class GeneratePasswordRequest {
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
|
||||
export class GeneratePasswordResponse {
|
||||
password: string;
|
||||
alternatives: string[];
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export class GetGroupsRequest {
|
||||
databaseId: string;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { GroupSummary } from "./GroupSummary";
|
||||
|
||||
export class GetGroupsResponse {
|
||||
error: string | null;
|
||||
groups: GroupSummary[];
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
export class GetNewEntryDefaultsRequest {
|
||||
databaseId: string;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
|
||||
export class GetNewEntryDefaultsResponse {
|
||||
error: string | null;
|
||||
username: string | null;
|
||||
mostPopularUsernames: string[] | null;
|
||||
password: string | null;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { DatabaseSummary } from './DatabaseSummary';
|
||||
|
||||
export class ServerSettings {
|
||||
public supportsCreateNew: boolean;
|
||||
}
|
||||
|
||||
export class GetStatusResponse {
|
||||
public serverVersionInfo: string;
|
||||
public databases: [DatabaseSummary];
|
||||
public serverSettings: ServerSettings;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
|
||||
|
||||
|
||||
export class GroupSummary {
|
||||
title: string;
|
||||
uuid: string;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
|
||||
export class LockRequest {
|
||||
databaseId = '';
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
export class LockResponse {
|
||||
databaseId = '';
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export class SearchRequest {
|
||||
query: string;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import { AutoFillCredential } from './AutoFillCredential';
|
||||
|
||||
export class SearchResponse {
|
||||
results: [AutoFillCredential];
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export class UnlockRequest {
|
||||
databaseId = '';
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export class UnlockResponse {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
|
||||
export enum WellKnownField {
|
||||
username,
|
||||
password,
|
||||
totp,
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
import * as React from 'react';
|
||||
import Typography from '@mui/material/Typography';
|
||||
import { AutoFillCredential } from '../Messaging/Protocol/AutoFillCredential';
|
||||
import Box from '@mui/system/Box';
|
||||
import { AvTimer, Key, Person } from '@mui/icons-material';
|
||||
import { IconButton, Paper, Tooltip } from '@mui/material';
|
||||
import * as OTPAuth from 'otpauth';
|
||||
import { NativeAppApi } from '../Messaging/NativeAppApi';
|
||||
import { WellKnownField } from '../Messaging/Protocol/WellKnownField';
|
||||
|
||||
interface CredentialListItemProps {
|
||||
credential: AutoFillCredential;
|
||||
showToast: (message: string) => void;
|
||||
}
|
||||
|
||||
export default function CredentialsListItem({
|
||||
credential,
|
||||
showToast,
|
||||
}: CredentialListItemProps) {
|
||||
const onCopyUsername = () => {
|
||||
NativeAppApi.getInstance().copyField(credential.databaseId, credential.uuid, WellKnownField.username);
|
||||
showToast('Username Copied');
|
||||
};
|
||||
const onCopyPassword = () => {
|
||||
NativeAppApi.getInstance().copyField(credential.databaseId, credential.uuid, WellKnownField.password);
|
||||
showToast('Password Copied');
|
||||
};
|
||||
const onCopyTotp = () => {
|
||||
NativeAppApi.getInstance().copyField(credential.databaseId, credential.uuid, WellKnownField.totp, true);
|
||||
showToast('TOTP Copied');
|
||||
};
|
||||
|
||||
let currentTotpCode = getCurrentTotpCode();
|
||||
|
||||
if (currentTotpCode.length > 0) {
|
||||
const middle = Math.floor(currentTotpCode.length / 2);
|
||||
if (middle > 0) {
|
||||
currentTotpCode =
|
||||
currentTotpCode.substring(0, middle) +
|
||||
'-' +
|
||||
currentTotpCode.substring(middle);
|
||||
}
|
||||
}
|
||||
|
||||
function getCurrentTotpCode(): string {
|
||||
if (credential.totp.length > 0) {
|
||||
try {
|
||||
const parsedTotp = OTPAuth.URI.parse(credential.totp);
|
||||
return parsedTotp.generate();
|
||||
} catch (error) {
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
return (
|
||||
<Paper elevation={18}>
|
||||
<Box
|
||||
display="flex"
|
||||
sx={{
|
||||
m: '5px',
|
||||
p: '5px',
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
alignContent: 'center',
|
||||
alignItems: 'center',
|
||||
}}
|
||||
>
|
||||
<Box
|
||||
sx={{
|
||||
flexGrow: 0,
|
||||
flexShrink: 0,
|
||||
alignContent: 'center',
|
||||
justifyContent: 'center',
|
||||
marginTop: 'auto',
|
||||
marginBottom: 'auto',
|
||||
}}
|
||||
>
|
||||
<Box
|
||||
component="img"
|
||||
display="block"
|
||||
sx={{
|
||||
height: 32,
|
||||
width: 37,
|
||||
margin: 'auto',
|
||||
paddingLeft: '5px',
|
||||
marginRight: '12px'
|
||||
}}
|
||||
alt="Icon"
|
||||
src={credential.icon}
|
||||
/>
|
||||
</Box>
|
||||
<Box
|
||||
sx={{
|
||||
flexGrow: 0,
|
||||
flexShrink: 0,
|
||||
width: '215px',
|
||||
}}
|
||||
>
|
||||
<Box>
|
||||
<Typography
|
||||
variant="body2"
|
||||
sx={{
|
||||
whiteSpace: 'nowrap',
|
||||
overflow: 'hidden',
|
||||
textOverflow: 'ellipsis',
|
||||
}}
|
||||
>
|
||||
{credential.favourite ? '⭐️ ' : ''}{credential.title}
|
||||
</Typography>
|
||||
</Box>
|
||||
<Box>
|
||||
<Typography
|
||||
variant="caption"
|
||||
display="inline"
|
||||
color="text.secondary"
|
||||
sx={{
|
||||
whiteSpace: 'nowrap',
|
||||
overflow: 'hidden',
|
||||
textOverflow: 'ellipsis',
|
||||
marginTop: '0px',
|
||||
padding: 0,
|
||||
}}
|
||||
>
|
||||
{credential.username}
|
||||
</Typography>
|
||||
{/* <Typography
|
||||
variant="body2"
|
||||
sx={{ fontFamily: 'monospace' }}
|
||||
display="inline"
|
||||
>
|
||||
| 038523
|
||||
</Typography> */}
|
||||
</Box>
|
||||
</Box>
|
||||
<Box display="flex" flexDirection="column" alignContent="center">
|
||||
<Box
|
||||
display="flex"
|
||||
sx={{
|
||||
flexGrow: 0,
|
||||
flexShrink: 0,
|
||||
width: '115px',
|
||||
overflow: 'hidden',
|
||||
justifyContent: 'flex-end',
|
||||
alignContent: 'center',
|
||||
}}
|
||||
>
|
||||
<Tooltip title="Copy Username">
|
||||
<span>
|
||||
<IconButton
|
||||
size="small"
|
||||
onClick={(event) => {
|
||||
event.stopPropagation();
|
||||
onCopyUsername();
|
||||
}}
|
||||
>
|
||||
<Person fontSize="inherit" />
|
||||
</IconButton>
|
||||
</span>
|
||||
</Tooltip>
|
||||
<Tooltip title="Copy Password">
|
||||
<span>
|
||||
<IconButton
|
||||
size="small"
|
||||
onClick={(event) => {
|
||||
event.stopPropagation();
|
||||
onCopyPassword();
|
||||
}}
|
||||
>
|
||||
<Key fontSize="inherit" />
|
||||
</IconButton>
|
||||
</span>
|
||||
</Tooltip>
|
||||
<Tooltip title="Copy TOTP">
|
||||
<span>
|
||||
<IconButton
|
||||
size="small"
|
||||
disabled={currentTotpCode == ''}
|
||||
onClick={(event) => {
|
||||
event.stopPropagation();
|
||||
onCopyTotp();
|
||||
}}
|
||||
>
|
||||
<AvTimer fontSize="inherit" />
|
||||
</IconButton>
|
||||
</span>
|
||||
</Tooltip>
|
||||
</Box>
|
||||
{currentTotpCode == '' ? (
|
||||
''
|
||||
) : (
|
||||
<Box justifyContent="flex-end">
|
||||
<Typography
|
||||
variant="body2"
|
||||
sx={{ fontFamily: 'monospace', paddingRight: '5px' }}
|
||||
align="right"
|
||||
>
|
||||
{currentTotpCode}
|
||||
</Typography>
|
||||
</Box>
|
||||
)}
|
||||
</Box>
|
||||
</Box>
|
||||
</Paper>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
import * as React from 'react';
|
||||
import List from '@mui/material/List';
|
||||
import ListItem from '@mui/material/ListItem';
|
||||
import { NativeAppApi } from '../Messaging/NativeAppApi';
|
||||
import { AutoFillCredential } from '../Messaging/Protocol/AutoFillCredential';
|
||||
import { useEffect, useState } from 'react';
|
||||
import CredentialsListItem from './CredentialsListItem';
|
||||
import NoResultsFoundPopupComponent from './NoResultsFoundPopupComponent';
|
||||
import { BackgroundManager } from '../Background/BackgroundManager';
|
||||
import { ListSubheader } from '@mui/material';
|
||||
|
||||
interface CurrentTabCredentialsComponentProps {
|
||||
showToast: (message: string) => void;
|
||||
}
|
||||
|
||||
function CurrentTabCredentialsComponent({
|
||||
showToast,
|
||||
}: CurrentTabCredentialsComponentProps) {
|
||||
|
||||
const [grouped, setGrouped] = useState<Map<string, AutoFillCredential[]>>(new Map<string, AutoFillCredential[]>());
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<unknown>();
|
||||
const [tabId, setTabId] = useState<number | undefined>();
|
||||
|
||||
useEffect(() => {
|
||||
async function getCredentials() {
|
||||
try {
|
||||
const result = await getCredentialsForCurrentUrl();
|
||||
if (!result) {
|
||||
return;
|
||||
}
|
||||
|
||||
const [tabId, creds] = result;
|
||||
|
||||
const groupedBy = creds.reduce((r: Map<string, AutoFillCredential[]>, cred: AutoFillCredential) => {
|
||||
r.set(cred.databaseName, [...r.get(cred.databaseName) || [], cred]);
|
||||
return r;
|
||||
}, new Map<string, AutoFillCredential[]>());
|
||||
|
||||
|
||||
|
||||
setGrouped(groupedBy);
|
||||
|
||||
setTabId(tabId);
|
||||
} catch (err) {
|
||||
setError(err);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
getCredentials();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<List
|
||||
subheader={
|
||||
<ListSubheader component="div" key='parent-div-subheader' id="nested-list-subheader" sx={{ textAlign: 'center' }}>
|
||||
URL Matches
|
||||
</ListSubheader>
|
||||
}
|
||||
sx={{ minwidth: '400px', maxWidth: '400px', overflow: 'hidden', scrollbarWidth: 'none', mt: 0, pt: 0 }}>
|
||||
{!loading && tabId != undefined ?
|
||||
(
|
||||
grouped.size == 0 ? (
|
||||
<NoResultsFoundPopupComponent />
|
||||
) :
|
||||
(
|
||||
<div key='parent-div'>
|
||||
{[...grouped.keys()].map((databaseName) => (
|
||||
<div key={databaseName}>
|
||||
<ListSubheader key={databaseName} sx={{ lineHeight: '20px' }}>{databaseName}</ListSubheader>
|
||||
{(grouped.get(databaseName) || []).map((credential) =>
|
||||
(
|
||||
<ListItem sx={{ mb: '3px', mt: '3px' }}
|
||||
disableGutters
|
||||
disablePadding
|
||||
button
|
||||
key={credential.uuid}
|
||||
onClick={() => onItemClicked(tabId, credential)}
|
||||
>
|
||||
<CredentialsListItem
|
||||
key={credential.uuid}
|
||||
credential={credential}
|
||||
showToast={showToast}
|
||||
/>
|
||||
</ListItem>
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
)
|
||||
:
|
||||
(
|
||||
'Loading...'
|
||||
)
|
||||
}
|
||||
</ List >
|
||||
);
|
||||
}
|
||||
|
||||
async function getCredentialsForCurrentUrl(): Promise<[number, AutoFillCredential[]] | undefined> {
|
||||
|
||||
|
||||
const startTime = performance.now();
|
||||
|
||||
const tab = await BackgroundManager.getCurrentTab();
|
||||
const url = tab ? tab.url : undefined;
|
||||
const tabId = tab?.id;
|
||||
|
||||
if (!url || !tabId) {
|
||||
return;
|
||||
} else {
|
||||
}
|
||||
const response = await NativeAppApi.getInstance().credentialsForUrl(url);
|
||||
const endTime = performance.now();
|
||||
|
||||
if (response != null) {
|
||||
const resultCount = response.results.length ?? 0;
|
||||
|
||||
|
||||
return [tabId, response.results];
|
||||
}
|
||||
}
|
||||
|
||||
async function onItemClicked(
|
||||
tabId: number,
|
||||
credential: AutoFillCredential
|
||||
): Promise<void> {
|
||||
await BackgroundManager.getInstance().fillWithCredential(tabId, credential);
|
||||
|
||||
window.close();
|
||||
}
|
||||
|
||||
export default CurrentTabCredentialsComponent;
|
||||
@@ -0,0 +1,110 @@
|
||||
import * as React from 'react';
|
||||
import Typography from '@mui/material/Typography';
|
||||
import Box from '@mui/system/Box';
|
||||
import { Lock, LockOpen } from '@mui/icons-material';
|
||||
import { Button, Paper } from '@mui/material';
|
||||
import { DatabaseSummary } from '../Messaging/Protocol/DatabaseSummary';
|
||||
import { NativeAppApi } from '../Messaging/NativeAppApi';
|
||||
|
||||
interface DatabaseListItemProps {
|
||||
database: DatabaseSummary;
|
||||
showToast: (message: string) => void;
|
||||
}
|
||||
|
||||
export default function DatabaseListItem({
|
||||
database,
|
||||
showToast,
|
||||
}: DatabaseListItemProps) {
|
||||
const onUnlock = async (database: DatabaseSummary) => {
|
||||
await NativeAppApi.getInstance().unlockDatabase(database.uuid);
|
||||
window.close();
|
||||
};
|
||||
const onLock = async (database: DatabaseSummary) => {
|
||||
await NativeAppApi.getInstance().lockDatabase(database.uuid);
|
||||
window.close();
|
||||
};
|
||||
|
||||
return (
|
||||
<Paper elevation={18}>
|
||||
<Box
|
||||
display="flex"
|
||||
sx={{
|
||||
m: '5px',
|
||||
p: 1,
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
alignContent: 'center',
|
||||
alignItems: 'center',
|
||||
}}
|
||||
>
|
||||
{ /* Status Lock Image */}
|
||||
<Box
|
||||
sx={{
|
||||
flexGrow: 0,
|
||||
alignContent: 'center',
|
||||
justifyContent: 'center',
|
||||
marginTop: 'auto',
|
||||
marginBottom: 'auto',
|
||||
}}
|
||||
>
|
||||
<Box display="flex"
|
||||
flexDirection="column"
|
||||
alignContent="center">
|
||||
{database.autoFillEnabled ?
|
||||
(database.locked ?
|
||||
<Lock fontSize="medium" color='error' /> :
|
||||
<LockOpen fontSize='medium' color='success' />) : (
|
||||
<Lock fontSize="medium" color='disabled' />)}
|
||||
</Box>
|
||||
</Box>
|
||||
{ /* Nick Name and Status Subtitle */}
|
||||
<Box
|
||||
display='flex' flexDirection="column"
|
||||
flexGrow={1}
|
||||
sx={{
|
||||
p: '0',
|
||||
ml: 1,
|
||||
}}
|
||||
>
|
||||
<Box>
|
||||
<Typography
|
||||
variant='body1'
|
||||
sx={{
|
||||
whiteSpace: 'nowrap',
|
||||
overflow: 'hidden',
|
||||
textOverflow: 'ellipsis',
|
||||
}}
|
||||
>
|
||||
{database.nickName}
|
||||
</Typography>
|
||||
</Box>
|
||||
<Box>
|
||||
<Typography
|
||||
variant="caption"
|
||||
display="inline"
|
||||
color="text.secondary"
|
||||
sx={{
|
||||
whiteSpace: 'nowrap',
|
||||
overflow: 'hidden',
|
||||
textOverflow: 'ellipsis',
|
||||
}}
|
||||
>
|
||||
{database.autoFillEnabled ? (database.locked ? 'Locked' : 'Unlocked') : ('AutoFill Not Enabled')}
|
||||
</Typography>
|
||||
</Box>
|
||||
</Box>
|
||||
<Box sx={{ ml: 2, mr: 1 }}>
|
||||
{database.autoFillEnabled ?
|
||||
(database.locked ?
|
||||
<Button variant="outlined" size='small' onClick={() => {
|
||||
onUnlock(database);
|
||||
}}>Unlock</Button> :
|
||||
<Button variant="outlined" size='small' onClick={() => {
|
||||
onLock(database);
|
||||
}}>Lock</Button>) :
|
||||
('')}
|
||||
</Box>
|
||||
</Box>
|
||||
</Paper>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
import { Box, List, ListItem, ListSubheader, Typography } from '@mui/material';
|
||||
import React, { useState } from 'react';
|
||||
import { NativeAppApi } from '../Messaging/NativeAppApi';
|
||||
import { DatabaseSummary } from '../Messaging/Protocol/DatabaseSummary';
|
||||
import DatabaseListItem from './DatabaseListItem';
|
||||
|
||||
interface DatabasesListPopupComponentProps {
|
||||
showToast: (message: string) => void;
|
||||
}
|
||||
|
||||
function DatabasesListPopupComponent({
|
||||
showToast
|
||||
}: DatabasesListPopupComponentProps) {
|
||||
const [databases, setDatabases] = useState<DatabaseSummary[]>();
|
||||
const [loading, setLoading] = useState<boolean>(true);
|
||||
const [error, setError] = useState<boolean>();
|
||||
|
||||
React.useEffect(() => {
|
||||
async function getCurrentStatus() {
|
||||
|
||||
const status = await NativeAppApi.getInstance().getStatus();
|
||||
if (status != null) {
|
||||
setDatabases(status.databases);
|
||||
} else {
|
||||
setError(true);
|
||||
}
|
||||
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
getCurrentStatus().catch(() => {
|
||||
});
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<List
|
||||
subheader={
|
||||
<ListSubheader component="div" id="nested-list-subheader" sx={{ textAlign: 'center' }}>
|
||||
Databases
|
||||
</ListSubheader>
|
||||
}
|
||||
sx={{ minWidth: '400px', minHeight: '100px', mt: 0, pt: 0 }}>
|
||||
{!loading && databases != undefined ? (
|
||||
databases.length ? (
|
||||
databases.map((database) => (
|
||||
<DatabaseListItem
|
||||
database={database}
|
||||
showToast={showToast}
|
||||
key={database.uuid}
|
||||
/>))) :
|
||||
(
|
||||
<Box>
|
||||
<Box display="block">
|
||||
<Typography
|
||||
variant="body1"
|
||||
align="center"
|
||||
|
||||
sx={{
|
||||
textOverflow: 'ellipsis',
|
||||
padding: 0,
|
||||
}}
|
||||
>
|
||||
No Databases
|
||||
</Typography>
|
||||
</Box>
|
||||
<Box>
|
||||
<Typography
|
||||
variant="body2"
|
||||
align="center"
|
||||
color="text.secondary"
|
||||
sx={{
|
||||
textOverflow: 'ellipsis',
|
||||
padding: '5px',
|
||||
}}
|
||||
>
|
||||
You don't have any databases yet, why not add one to Strongbox?
|
||||
</Typography>
|
||||
</Box>
|
||||
</Box>
|
||||
)
|
||||
) :
|
||||
('Loading...')}
|
||||
</List >
|
||||
);
|
||||
}
|
||||
|
||||
export default DatabasesListPopupComponent;
|
||||
@@ -0,0 +1,51 @@
|
||||
import { Typography, Box, Icon, IconButton, Stack } from '@mui/material';
|
||||
import React from 'react';
|
||||
import { Search } from '@mui/icons-material';
|
||||
|
||||
function NoResultsFoundPopupComponent() {
|
||||
return (
|
||||
<Stack
|
||||
direction="column"
|
||||
justifyContent="center"
|
||||
alignItems="center"
|
||||
minWidth='400px'
|
||||
spacing={0}
|
||||
>
|
||||
<Box display="block">
|
||||
<Search
|
||||
color="disabled"
|
||||
sx={{
|
||||
fontSize: 60,
|
||||
}}
|
||||
/>
|
||||
</Box>
|
||||
<Box>
|
||||
<Typography
|
||||
variant="h6"
|
||||
align="center"
|
||||
sx={{
|
||||
textOverflow: 'ellipsis',
|
||||
padding: 0,
|
||||
}}
|
||||
>
|
||||
No Matches
|
||||
</Typography>
|
||||
</Box>
|
||||
<Box>
|
||||
<Typography
|
||||
variant="body2"
|
||||
align="center"
|
||||
color="text.secondary"
|
||||
sx={{
|
||||
textOverflow: 'ellipsis',
|
||||
padding: '5px',
|
||||
}}
|
||||
>
|
||||
Strongbox could not find any matching entries for this website
|
||||
</Typography>
|
||||
</Box>
|
||||
</Stack>
|
||||
);
|
||||
}
|
||||
|
||||
export default NoResultsFoundPopupComponent;
|
||||
@@ -0,0 +1,50 @@
|
||||
import { Typography, Box, Stack, Button, IconButton, ListItem, List } from '@mui/material';
|
||||
import React from 'react';
|
||||
import { HorizontalRule, HorizontalRuleTwoTone, Person, RocketLaunch, SensorsOff } from '@mui/icons-material';
|
||||
import { NativeAppApi } from '../Messaging/NativeAppApi';
|
||||
|
||||
interface NotRunningPopupComponentProps {
|
||||
onRefresh: () => void;
|
||||
}
|
||||
|
||||
function NotRunningPopupComponent({
|
||||
onRefresh,
|
||||
}: NotRunningPopupComponentProps) {
|
||||
return (
|
||||
<Stack direction="column" justifyContent="center" alignItems="center" spacing={0} minWidth='400px' sx={{ m: 2, width: 300 }}>
|
||||
<Box><SensorsOff color="disabled" sx={{ fontSize: 60 }} /></Box>
|
||||
<Box>
|
||||
<Typography variant="h5" align="center" sx={{ textOverflow: 'ellipsis', padding: 0, }}>Strongbox Unavailable</Typography>
|
||||
</Box>
|
||||
<Box>
|
||||
<IconButton color='primary' onClick={() => onLaunch(onRefresh)} ><RocketLaunch fontSize="inherit" /></IconButton>
|
||||
<Button onClick={() => onLaunch(onRefresh)}>Launch Strongbox</Button>
|
||||
</Box>
|
||||
<HorizontalRuleTwoTone sx={{ width: '300px' }} />
|
||||
<Box display="block" sx={{ display: 'flex', flexDirection: 'column' }}>
|
||||
<Box>
|
||||
<Typography variant="h6" align="center" sx={{ textOverflow: 'ellipsis', padding: 0 }} >
|
||||
Troubleshooting<br />
|
||||
<Typography variant="body2" align="left" sx={{ textOverflow: 'ellipsis', padding: 0 }} >
|
||||
1. Make sure Strongbox is installed and running.<br />
|
||||
2. Make sure you are a Pro user, AutoFill is a paid Pro feature.<br />
|
||||
3. Check the setting below is enabled:<br />
|
||||
<p>
|
||||
<Typography variant="caption" align="left" sx={{ textOverflow: 'ellipsis', padding: 0 }} >
|
||||
Settings {'>'} Advanced {'>'} Chrome & Firefox AutoFill Extension
|
||||
</Typography>
|
||||
</p>
|
||||
</Typography>
|
||||
</Typography>
|
||||
</Box>
|
||||
</Box>
|
||||
</Stack>
|
||||
);
|
||||
}
|
||||
|
||||
async function onLaunch(onRefresh: () => void) {
|
||||
await NativeAppApi.getInstance().launchStrongbox();
|
||||
onRefresh();
|
||||
}
|
||||
|
||||
export default NotRunningPopupComponent;
|
||||
@@ -0,0 +1,131 @@
|
||||
import * as React from 'react';
|
||||
import Box from '@mui/material/Box';
|
||||
import CssBaseline from '@mui/material/CssBaseline';
|
||||
import browser from 'webextension-polyfill';
|
||||
|
||||
|
||||
import '@fontsource/roboto/300.css';
|
||||
import '@fontsource/roboto/400.css';
|
||||
import '@fontsource/roboto/500.css';
|
||||
import '@fontsource/roboto/700.css';
|
||||
|
||||
import { createTheme, ThemeProvider } from '@mui/material/styles';
|
||||
import CurrentTabCredentialsComponent from './CurrentTabCredentials';
|
||||
|
||||
import { Snackbar, Alert, Paper, BottomNavigation, BottomNavigationAction } from '@mui/material';
|
||||
import { NativeAppApi } from '../Messaging/NativeAppApi';
|
||||
import NotRunningPopupComponent from './NotRunningPopupComponent';
|
||||
import { Storage, DomainVerification, Settings } from '@mui/icons-material';
|
||||
import DatabasesListPopupComponent from './DatabasesListPopupComponent';
|
||||
import SettingsPopupComponent from './SettingsPopupComponent';
|
||||
|
||||
const darkTheme = createTheme({ palette: { mode: 'dark' } });
|
||||
|
||||
export default function PopupComponent() {
|
||||
const ref = React.useRef<HTMLDivElement>(null);
|
||||
|
||||
const [loading, setLoading] = React.useState<boolean>(true);
|
||||
const [unlockedCount, setUnlockedCount] = React.useState(0);
|
||||
|
||||
const [error, setError] = React.useState<boolean>(false);
|
||||
|
||||
const [selectedTab, setSelectedTab] = React.useState(1);
|
||||
|
||||
const [popupVisible, setPopupVisible] = React.useState(false);
|
||||
const [toastMessage, setToastMessage] = React.useState('');
|
||||
|
||||
const showToast = (message: string) => {
|
||||
setToastMessage(message);
|
||||
setPopupVisible(true);
|
||||
};
|
||||
|
||||
const handleToastClose = (
|
||||
event?: React.SyntheticEvent | Event,
|
||||
reason?: string
|
||||
) => {
|
||||
if (reason === 'clickaway') {
|
||||
return;
|
||||
}
|
||||
|
||||
setPopupVisible(false);
|
||||
};
|
||||
|
||||
const onDismiss = () => {
|
||||
|
||||
|
||||
window.close();
|
||||
};
|
||||
|
||||
React.useEffect(() => {
|
||||
async function getCurrentStatus() {
|
||||
|
||||
|
||||
const status = await NativeAppApi.getInstance().getStatus();
|
||||
|
||||
if (status != null) {
|
||||
|
||||
|
||||
const unlocked = status.databases.filter((database) => !database.locked && database.autoFillEnabled);
|
||||
|
||||
setUnlockedCount(unlocked.length);
|
||||
setSelectedTab(unlocked.length == 0 ? 1 : 0);
|
||||
|
||||
}
|
||||
else {
|
||||
setError(true);
|
||||
}
|
||||
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
getCurrentStatus().catch(() => {
|
||||
});
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<ThemeProvider theme={darkTheme}>
|
||||
<Box sx={{ overflow: 'hidden', scrollbarWidth: 'none' }} ref={ref}>
|
||||
<CssBaseline />
|
||||
{loading ? (
|
||||
'Loading...'
|
||||
) : error ? (
|
||||
<NotRunningPopupComponent onRefresh={onDismiss} />
|
||||
) : selectedTab > 0 ? (
|
||||
selectedTab == 1 ? (
|
||||
<DatabasesListPopupComponent showToast={(message) => showToast(message)} />) : (<SettingsPopupComponent />)
|
||||
) : (
|
||||
<CurrentTabCredentialsComponent
|
||||
showToast={(message) => showToast(message)}
|
||||
/>
|
||||
)}
|
||||
|
||||
<Snackbar open={popupVisible} autoHideDuration={1000} onClose={handleToastClose}>
|
||||
<Alert
|
||||
onClose={handleToastClose}
|
||||
severity="success"
|
||||
sx={{ width: '100%' }}
|
||||
>
|
||||
{toastMessage}
|
||||
</Alert>
|
||||
</Snackbar>
|
||||
|
||||
<Paper
|
||||
elevation={1}
|
||||
square
|
||||
>
|
||||
<BottomNavigation
|
||||
showLabels
|
||||
value={selectedTab}
|
||||
onChange={(_event, newValue) => {
|
||||
setSelectedTab(newValue);
|
||||
}}
|
||||
>
|
||||
{unlockedCount === 0 ? '' : <BottomNavigationAction label={unlockedCount === 0 ? '' : 'Matches'} icon={<DomainVerification color={selectedTab == 0 ? 'primary' : 'disabled'} />} />}
|
||||
<BottomNavigationAction label="Databases" icon={<Storage color={selectedTab == 1 ? 'primary' : 'disabled'} />} />
|
||||
{error ? ('') : (<BottomNavigationAction label="Settings" icon={<Settings color={selectedTab == 2 ? 'primary' : 'disabled'} />} />)}
|
||||
</BottomNavigation>
|
||||
</Paper>
|
||||
</Box>
|
||||
</ThemeProvider >
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
import { Box, Checkbox, Divider, FormControlLabel, FormGroup, List, ListItem, ListSubheader, Typography } from '@mui/material';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { BackgroundManager } from '../Background/BackgroundManager';
|
||||
import { Settings } from '../Settings/Settings';
|
||||
import { SettingsStore } from '../Settings/SettingsStore';
|
||||
|
||||
function SettingsPopupComponent() {
|
||||
const [settings, setSettings] = useState<Settings>(new Settings());
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [currentUrl, setCurrentUrl] = useState<string | undefined>('Loading...');
|
||||
|
||||
useEffect(() => {
|
||||
async function getStoredSettings() {
|
||||
const stored = await SettingsStore.getSettings();
|
||||
setSettings(stored);
|
||||
|
||||
const tab = await BackgroundManager.getCurrentTab();
|
||||
const url = tab ? tab.url : undefined;
|
||||
|
||||
setCurrentUrl(url);
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
getStoredSettings();
|
||||
}, []);
|
||||
|
||||
const toggleAutoFillImmediatelyIfOnlyASingleMatch = async () => {
|
||||
const stored = await SettingsStore.getSettings();
|
||||
stored.autoFillImmediatelyIfOnlyASingleMatch = !stored.autoFillImmediatelyIfOnlyASingleMatch;
|
||||
|
||||
await SettingsStore.setSettings(stored);
|
||||
|
||||
const stored2 = await SettingsStore.getSettings();
|
||||
setSettings(stored2);
|
||||
};
|
||||
|
||||
const toggleShowInline = async () => {
|
||||
const stored = await SettingsStore.getSettings();
|
||||
stored.showInlineIconAndPopupMenu = !stored.showInlineIconAndPopupMenu;
|
||||
|
||||
await SettingsStore.setSettings(stored);
|
||||
|
||||
const stored2 = await SettingsStore.getSettings();
|
||||
setSettings(stored2);
|
||||
};
|
||||
|
||||
const toggleAutoFillImmediatelyWithFirstMatch = async () => {
|
||||
const stored = await SettingsStore.getSettings();
|
||||
stored.autoFillImmediatelyWithFirstMatch = !stored.autoFillImmediatelyWithFirstMatch;
|
||||
|
||||
await SettingsStore.setSettings(stored);
|
||||
|
||||
const stored2 = await SettingsStore.getSettings();
|
||||
setSettings(stored2);
|
||||
};
|
||||
|
||||
const toggleDomainToDoNotRunList = async () => {
|
||||
const url = currentUrl ?? '';
|
||||
|
||||
if (isUrlIsInDoNotShowInlineMenusList(url)) {
|
||||
await removeThisDomainToDoNotRunList(url);
|
||||
}
|
||||
else {
|
||||
await addThisDomainToDoNotRunList(url);
|
||||
}
|
||||
};
|
||||
|
||||
const removeThisDomainToDoNotRunList = async (url: string) => {
|
||||
const stored = await SettingsStore.getSettings();
|
||||
|
||||
if (!stored.doNotShowInlineMenusOnDomains) {
|
||||
stored.doNotShowInlineMenusOnDomains = [];
|
||||
}
|
||||
else {
|
||||
const prepped = prepUrlForDoNotRunList(url);
|
||||
const index = stored.doNotShowInlineMenusOnDomains.indexOf(prepped, 0);
|
||||
if (index > -1) {
|
||||
|
||||
stored.doNotShowInlineMenusOnDomains.splice(index, 1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
await SettingsStore.setSettings(stored);
|
||||
|
||||
const stored2 = await SettingsStore.getSettings();
|
||||
setSettings(stored2);
|
||||
};
|
||||
|
||||
const addThisDomainToDoNotRunList = async (url: string) => {
|
||||
const stored = await SettingsStore.getSettings();
|
||||
|
||||
if (!stored.doNotShowInlineMenusOnDomains) {
|
||||
stored.doNotShowInlineMenusOnDomains = [];
|
||||
}
|
||||
|
||||
stored.doNotShowInlineMenusOnDomains.push(prepUrlForDoNotRunList(url));
|
||||
|
||||
|
||||
|
||||
const uniqueItems = [...new Set(stored.doNotShowInlineMenusOnDomains)];
|
||||
stored.doNotShowInlineMenusOnDomains = uniqueItems;
|
||||
|
||||
|
||||
await SettingsStore.setSettings(stored);
|
||||
|
||||
const stored2 = await SettingsStore.getSettings();
|
||||
setSettings(stored2);
|
||||
};
|
||||
|
||||
|
||||
const prepUrlForDoNotRunList = (url: string) => {
|
||||
return Settings.prepUrlForDoNotRunList(url);
|
||||
};
|
||||
|
||||
const isUrlIsInDoNotShowInlineMenusList = (url: string) => {
|
||||
return Settings.isUrlIsInDoNotShowInlineMenusList(settings, url);
|
||||
};
|
||||
|
||||
|
||||
|
||||
const toggleShowMatchCountOnPopupBadge = async () => {
|
||||
const stored = await SettingsStore.getSettings();
|
||||
stored.showMatchCountOnPopupBadge = !stored.showMatchCountOnPopupBadge;
|
||||
|
||||
await SettingsStore.setSettings(stored);
|
||||
|
||||
const stored2 = await SettingsStore.getSettings();
|
||||
setSettings(stored2);
|
||||
};
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<List
|
||||
subheader={
|
||||
<ListSubheader component="div" id="nested-list-subheader" sx={{ textAlign: 'center' }}>
|
||||
Settings
|
||||
</ListSubheader>
|
||||
}
|
||||
sx={{ minWidth: '400px', minHeight: '150px' }}>
|
||||
|
||||
{loading ? ('') : (
|
||||
<FormGroup>
|
||||
<ListItem>
|
||||
<FormControlLabel control={<Checkbox checked={settings.showInlineIconAndPopupMenu}
|
||||
onChange={toggleShowInline} />}
|
||||
label="Show Inline Menus" />
|
||||
</ListItem>
|
||||
<ListItem>
|
||||
<FormControlLabel
|
||||
control={<Checkbox checked={settings.showMatchCountOnPopupBadge}
|
||||
onChange={toggleShowMatchCountOnPopupBadge} />}
|
||||
label="Show Match Count Badge on Popup Icon" />
|
||||
</ListItem>
|
||||
<ListItem>
|
||||
<FormControlLabel
|
||||
control={<Checkbox checked={settings.autoFillImmediatelyIfOnlyASingleMatch}
|
||||
onChange={toggleAutoFillImmediatelyIfOnlyASingleMatch} />}
|
||||
label="Fill on Load if Only Single Match Found" />
|
||||
</ListItem>
|
||||
<ListItem>
|
||||
<FormControlLabel control={<Checkbox checked={settings.autoFillImmediatelyWithFirstMatch}
|
||||
onChange={toggleAutoFillImmediatelyWithFirstMatch} />}
|
||||
label="Always Fill on Load with First Match" />
|
||||
</ListItem>
|
||||
<ListItem>
|
||||
<FormControlLabel control={
|
||||
<Checkbox disabled={!currentUrl}
|
||||
checked={isUrlIsInDoNotShowInlineMenusList(currentUrl ?? '')}
|
||||
onChange={toggleDomainToDoNotRunList} />}
|
||||
label={'Hide Inline Menus on this Domain (' + prepUrlForDoNotRunList(currentUrl ?? '') + ')'} />
|
||||
</ListItem>
|
||||
</FormGroup >)}
|
||||
</List >
|
||||
<Divider />
|
||||
<Box sx={{ p: 1 }}>
|
||||
<Typography
|
||||
variant="body2"
|
||||
align="center"
|
||||
color="text.primary"
|
||||
sx={{
|
||||
textOverflow: 'ellipsis',
|
||||
padding: '5px',
|
||||
}}
|
||||
>
|
||||
Strongbox AutoFill {process.env.VERSION}
|
||||
</Typography>
|
||||
<Typography
|
||||
variant="body2"
|
||||
align="center"
|
||||
color="text.secondary"
|
||||
sx={{
|
||||
textOverflow: 'ellipsis',
|
||||
padding: '5px',
|
||||
textAlign: 'center'
|
||||
}}
|
||||
>
|
||||
© Phoebe Code Limited
|
||||
</Typography>
|
||||
</Box>
|
||||
<Divider />
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
export default SettingsPopupComponent;
|
||||
@@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=550" />
|
||||
<!-- <meta name="viewport" content="initial-scale=1, width=device-width" /> -->
|
||||
<title>Popup</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="popup-root"></div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,11 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom/client';
|
||||
import PopupComponent from './PopupComponent';
|
||||
|
||||
ReactDOM.createRoot(
|
||||
document.getElementById('popup-root') as HTMLElement
|
||||
).render(
|
||||
<React.StrictMode>
|
||||
<PopupComponent />
|
||||
</React.StrictMode>
|
||||
);
|
||||
@@ -0,0 +1,142 @@
|
||||
import * as React from 'react';
|
||||
import Avatar from '@mui/material/Avatar';
|
||||
import List from '@mui/material/List';
|
||||
import ListItem from '@mui/material/ListItem';
|
||||
import ListItemAvatar from '@mui/material/ListItemAvatar';
|
||||
import ListItemText from '@mui/material/ListItemText';
|
||||
import DialogTitle from '@mui/material/DialogTitle';
|
||||
import Dialog from '@mui/material/Dialog';
|
||||
import PersonIcon from '@mui/icons-material/Person';
|
||||
import AddIcon from '@mui/icons-material/Add';
|
||||
import { blue } from '@mui/material/colors';
|
||||
import { ListSubheader } from '@mui/material';
|
||||
import NoResultsFoundPopupComponent from '../Popup/NoResultsFoundPopupComponent';
|
||||
import { AutoFillCredential } from '../Messaging/Protocol/AutoFillCredential';
|
||||
import CredentialsListItem from '../Popup/CredentialsListItem';
|
||||
import { createTheme, ThemeProvider } from '@mui/material/styles';
|
||||
|
||||
import CssBaseline from '@mui/material/CssBaseline';
|
||||
|
||||
|
||||
import '@fontsource/roboto/300.css';
|
||||
import '@fontsource/roboto/400.css';
|
||||
import '@fontsource/roboto/500.css';
|
||||
import '@fontsource/roboto/700.css';
|
||||
|
||||
const emails = ['username@gmail.com', 'user02@gmail.com'];
|
||||
|
||||
const darkTheme = createTheme({ palette: { mode: 'dark' } });
|
||||
|
||||
export interface SimpleDialogProps {
|
||||
open: boolean;
|
||||
groupedCredentials: Map<string, AutoFillCredential[]>;
|
||||
selectedValue: string;
|
||||
onClose: (value: string) => void;
|
||||
fillCredential: (credential: AutoFillCredential) => void;
|
||||
}
|
||||
|
||||
function SimpleDialog(props: SimpleDialogProps) {
|
||||
const { onClose, groupedCredentials, selectedValue, open, fillCredential } = props;
|
||||
|
||||
const handleClose = () => {
|
||||
onClose(selectedValue);
|
||||
};
|
||||
|
||||
async function handleListItemClick(
|
||||
credential: AutoFillCredential
|
||||
): Promise<void> {
|
||||
fillCredential(credential);
|
||||
onClose("email");
|
||||
}
|
||||
const showToast = () => { console.log('TODO'); };
|
||||
|
||||
return (
|
||||
<ThemeProvider theme={darkTheme}>
|
||||
<CssBaseline />
|
||||
<Dialog onClose={handleClose} open={open}>
|
||||
<DialogTitle>Select Credential</DialogTitle>
|
||||
|
||||
<List
|
||||
sx={{ minwidth: '400px', maxWidth: '400px', overflow: 'hidden', scrollbarWidth: 'none', mt: 0, pt: 0 }}>
|
||||
{groupedCredentials.size == 0 ? (
|
||||
<NoResultsFoundPopupComponent />
|
||||
) :
|
||||
(
|
||||
<div>
|
||||
{[...groupedCredentials.keys()].map((databaseName) => (
|
||||
<div>
|
||||
<ListSubheader key={databaseName} sx={{ lineHeight: '20px' }}>{databaseName}</ListSubheader>
|
||||
{(groupedCredentials.get(databaseName) || []).map((credential) =>
|
||||
(
|
||||
<ListItem sx={{ mb: '3px', mt: '3px' }}
|
||||
disableGutters
|
||||
disablePadding
|
||||
button
|
||||
key={credential.uuid}
|
||||
onClick={() => handleListItemClick(credential)}
|
||||
>
|
||||
<CredentialsListItem
|
||||
credential={credential}
|
||||
showToast={showToast}
|
||||
/>
|
||||
</ListItem>
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
</ List >
|
||||
|
||||
{/* <List sx={{ pt: 0 }}>
|
||||
{emails.map((email) => (
|
||||
<ListItem button onClick={() => handleListItemClick(email)} key={email}>
|
||||
<ListItemAvatar>
|
||||
<Avatar sx={{ bgcolor: blue[100], color: blue[600] }}>
|
||||
<PersonIcon />
|
||||
</Avatar>
|
||||
</ListItemAvatar>
|
||||
<ListItemText primary={email} />
|
||||
</ListItem>
|
||||
))}
|
||||
<ListItem autoFocus button onClick={() => handleListItemClick('addAccount')}>
|
||||
<ListItemAvatar>
|
||||
<Avatar>
|
||||
<AddIcon />
|
||||
</Avatar>
|
||||
</ListItemAvatar>
|
||||
<ListItemText primary="Add account" />
|
||||
</ListItem>
|
||||
</List> */}
|
||||
</Dialog>
|
||||
</ThemeProvider>
|
||||
);
|
||||
}
|
||||
|
||||
export interface SelectCredentialComponentProps {
|
||||
groupedCredentials: Map<string, AutoFillCredential[]>;
|
||||
fillCredential: (credential: AutoFillCredential) => void;
|
||||
}
|
||||
|
||||
export default function SelectCredentialComponent(props: SelectCredentialComponentProps) {
|
||||
const [open, setOpen] = React.useState(true);
|
||||
const [selectedValue, setSelectedValue] = React.useState(emails[1]);
|
||||
|
||||
const handleClose = (value: string) => {
|
||||
setOpen(false);
|
||||
setSelectedValue(value);
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<SimpleDialog
|
||||
selectedValue={selectedValue}
|
||||
open={open}
|
||||
onClose={handleClose}
|
||||
groupedCredentials={props.groupedCredentials}
|
||||
fillCredential={props.fillCredential} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
export class LastKnownDatabasesItem {
|
||||
nickName = '';
|
||||
uuid = '';
|
||||
|
||||
constructor(nickName: string, uuid: string) {
|
||||
this.nickName = nickName;
|
||||
this.uuid = uuid;
|
||||
}
|
||||
}
|
||||
|
||||
export class Settings {
|
||||
autoFillImmediatelyIfOnlyASingleMatch = true;
|
||||
autoFillImmediatelyWithFirstMatch = false;
|
||||
showMatchCountOnPopupBadge = true;
|
||||
showInlineIconAndPopupMenu = true;
|
||||
lastKnownDatabases: LastKnownDatabasesItem[] = [];
|
||||
doNotShowInlineMenusOnDomains: string[] = [];
|
||||
|
||||
static prepUrlForDoNotRunList(url: string) {
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
return a.hostname.toLocaleLowerCase();
|
||||
}
|
||||
|
||||
static isUrlIsInDoNotShowInlineMenusList(settings: Settings, url: string) {
|
||||
const prepped = Settings.prepUrlForDoNotRunList(url);
|
||||
const domains = (settings.doNotShowInlineMenusOnDomains ?? []);
|
||||
const ret = domains.indexOf(prepped) > -1;
|
||||
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import browser from 'webextension-polyfill';
|
||||
import { Settings } from './Settings';
|
||||
|
||||
export class SettingsStore {
|
||||
public static async getSettings(): Promise<Settings> {
|
||||
const settingsKey = 'settings.v7';
|
||||
|
||||
const ret = await browser.storage.sync.get([settingsKey]);
|
||||
|
||||
if (ret[settingsKey]) {
|
||||
|
||||
return ret[settingsKey];
|
||||
}
|
||||
else {
|
||||
|
||||
|
||||
return new Settings();
|
||||
}
|
||||
}
|
||||
|
||||
public static setSettings(settings: Settings) {
|
||||
browser.storage.sync.set({ 'settings.v7': settings });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export class StrongboxColours {
|
||||
static niceBlue = '#409DFF';
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
export class Utils {
|
||||
static getUUIDString(): string {
|
||||
const S4 = function () {
|
||||
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
|
||||
};
|
||||
return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
|
||||
}
|
||||
|
||||
static getImageElementBase64PNGData(image: HTMLImageElement): string | null {
|
||||
const canvas: HTMLCanvasElement = document.createElement('canvas');
|
||||
if (canvas == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
canvas.width = image.naturalWidth;
|
||||
canvas.height = image.naturalHeight;
|
||||
|
||||
const context = canvas.getContext('2d');
|
||||
if (context == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
context.drawImage(image, 0, 0);
|
||||
|
||||
const dataURL = canvas.toDataURL();
|
||||
|
||||
const base64 = dataURL.replace('data:', '').replace(/^.+,/, '');
|
||||
|
||||
return base64;
|
||||
}
|
||||
|
||||
static quickHashString(str: string): number {
|
||||
|
||||
let hash = 0, i, chr;
|
||||
|
||||
if (str.length === 0) return hash;
|
||||
|
||||
for (i = 0; i < str.length; i++) {
|
||||
chr = str.charCodeAt(i);
|
||||
hash = ((hash << 5) - hash) + chr;
|
||||
hash |= 0;
|
||||
}
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
static isFirefox(): boolean {
|
||||
return (
|
||||
navigator.userAgent.indexOf(" Firefox/") !== -1 ||
|
||||
navigator.userAgent.indexOf(" Gecko/") !== -1
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
{
|
||||
"manifest_version": 3,
|
||||
"name": "Strongbox AutoFill",
|
||||
"version": "1.0.5",
|
||||
"icons": {
|
||||
"128": "assets/icons/app-icon-blue-128.png"
|
||||
},
|
||||
"content_security_policy": {
|
||||
"extension_page": "script-src 'self' ; object-src 'self'"
|
||||
},
|
||||
"web_accessible_resources": [
|
||||
{
|
||||
"resources": [
|
||||
"assets/icons/app-icon-blue-19.png",
|
||||
"assets/icons/app-icon-grey-38.png",
|
||||
"assets/icons/app-icon-grey-19.png",
|
||||
"assets/icons/app-icon-blue-38.png",
|
||||
"assets/icons/app-icon-circle.png",
|
||||
"_favicon/*"
|
||||
],
|
||||
"matches": [
|
||||
"<all_urls>"
|
||||
],
|
||||
"extension_ids": [
|
||||
"*"
|
||||
]
|
||||
}
|
||||
],
|
||||
"commands": {
|
||||
"autofill-first": {
|
||||
"suggested_key": {
|
||||
"default": "Ctrl+Shift+L"
|
||||
},
|
||||
"description": "AutoFill"
|
||||
}
|
||||
},
|
||||
"action": {
|
||||
"default_title": "Strongbox",
|
||||
"default_popup": "popup.html",
|
||||
"default_icon": {
|
||||
"19": "assets/icons/app-icon-blue-19.png",
|
||||
"38": "assets/icons/app-icon-blue-38.png"
|
||||
}
|
||||
},
|
||||
"description": "Strongbox Browser AutoFill Extension",
|
||||
"short_name": "Strongbox",
|
||||
"permissions": [
|
||||
"tabs",
|
||||
"nativeMessaging",
|
||||
"webNavigation",
|
||||
"storage",
|
||||
"favicon"
|
||||
],
|
||||
"host_permissions": [
|
||||
"http:
|
||||
"https:
|
||||
],
|
||||
"author": "Phoebe Code Limited",
|
||||
"minimum_chrome_version": "88",
|
||||
"background": {
|
||||
"service_worker": "js/background.bundle.js",
|
||||
"type": "module"
|
||||
},
|
||||
"content_scripts": [
|
||||
{
|
||||
"all_frames": true,
|
||||
"matches": [
|
||||
"http:
|
||||
"https:
|
||||
],
|
||||
"js": [
|
||||
"js/content.bundle.js"
|
||||
],
|
||||
"css": [
|
||||
"content.css"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
{
|
||||
"manifest_version": 2,
|
||||
"name": "Strongbox AutoFill",
|
||||
"version": "1.0.5",
|
||||
"icons": {
|
||||
"128": "assets/icons/app-icon-blue-128.png"
|
||||
},
|
||||
"description": "Strongbox Browser AutoFill Extension",
|
||||
"short_name": "Strongbox",
|
||||
"permissions": [
|
||||
"tabs",
|
||||
"nativeMessaging",
|
||||
"<all_urls>",
|
||||
"webNavigation",
|
||||
"storage"
|
||||
],
|
||||
"author": "Phoebe Code Limited",
|
||||
"background": {
|
||||
"scripts": [
|
||||
"js/background.bundle.js"
|
||||
]
|
||||
},
|
||||
"browser_specific_settings": {
|
||||
"gecko": {
|
||||
"id": "strongbox@phoebecode.com"
|
||||
}
|
||||
},
|
||||
"browser_action": {
|
||||
"browser_style": true,
|
||||
"default_icon": {
|
||||
"128": "assets/icons/app-icon-blue-128.png"
|
||||
},
|
||||
"default_title": "Strongbox",
|
||||
"default_popup": "popup.html"
|
||||
},
|
||||
"web_accessible_resources": [
|
||||
"assets/icons/app-icon-circle.png"
|
||||
],
|
||||
"commands": {
|
||||
"autofill-first": {
|
||||
"suggested_key": {
|
||||
"default": "Ctrl+Shift+L"
|
||||
},
|
||||
"description": "AutoFill"
|
||||
}
|
||||
},
|
||||
"content_scripts": [
|
||||
{
|
||||
"all_frames": true,
|
||||
"matches": [
|
||||
"http:
|
||||
"https:
|
||||
],
|
||||
"js": [
|
||||
"js/content.bundle.js"
|
||||
],
|
||||
"css": [
|
||||
"content.css"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"esModuleInterop": true,
|
||||
"jsx": "react",
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"lib": [
|
||||
"dom",
|
||||
"ES2020"
|
||||
],
|
||||
"strict": true,
|
||||
"strictPropertyInitialization": false,
|
||||
"sourceMap": true,
|
||||
"target": "ES2020"
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
const path = require('path');
|
||||
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
||||
const TerserPlugin = require("terser-webpack-plugin");
|
||||
const webpack = require("webpack");
|
||||
|
||||
|
||||
const sourcePath = path.join(__dirname, 'src');
|
||||
const destPath = path.join(__dirname, 'dist');
|
||||
const targetBrowser = process.env.TARGET_BROWSER;
|
||||
|
||||
const prod = process.env.NODE_ENV === 'production';
|
||||
|
||||
module.exports = {
|
||||
mode: prod ? 'production' : 'development',
|
||||
entry: {
|
||||
background: path.join(sourcePath, 'Background', 'background.ts'),
|
||||
content: path.join(sourcePath, 'Content', 'content.ts'),
|
||||
|
||||
popup: path.join(sourcePath, 'Popup', 'popup.tsx'),
|
||||
|
||||
|
||||
},
|
||||
output: {
|
||||
path: path.join(destPath, targetBrowser),
|
||||
filename: 'js/[name].bundle.js',
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.(ts|tsx)$/,
|
||||
exclude: /node_modules/,
|
||||
resolve: {
|
||||
extensions: ['.ts', '.tsx', '.js', '.json'],
|
||||
},
|
||||
use: 'ts-loader',
|
||||
},
|
||||
{
|
||||
test: /\.css$/,
|
||||
use: [{ loader: MiniCssExtractPlugin.loader }, 'css-loader'],
|
||||
},
|
||||
],
|
||||
},
|
||||
devtool: prod ? undefined : 'source-map',
|
||||
plugins: [
|
||||
new HtmlWebpackPlugin({
|
||||
template: path.join(sourcePath, 'Popup', 'popup.html'),
|
||||
inject: 'body',
|
||||
chunks: ['popup'],
|
||||
hash: true,
|
||||
filename: 'popup.html',
|
||||
}),
|
||||
new webpack.DefinePlugin({
|
||||
'process.env.VERSION': JSON.stringify(
|
||||
process.env.npm_package_version,
|
||||
),
|
||||
}),
|
||||
new MiniCssExtractPlugin(),
|
||||
new CopyWebpackPlugin({
|
||||
patterns: [{ from: 'src/assets', to: 'assets' }],
|
||||
}),
|
||||
|
||||
|
||||
|
||||
new CopyWebpackPlugin({
|
||||
patterns: [
|
||||
{
|
||||
from: `src/manifest.${targetBrowser}.json`,
|
||||
to: './manifest.json',
|
||||
},
|
||||
],
|
||||
}),
|
||||
],
|
||||
optimization: {
|
||||
minimize: prod,
|
||||
minimizer: [new TerserPlugin({
|
||||
terserOptions: {
|
||||
format: {
|
||||
comments: false,
|
||||
},
|
||||
compress: {
|
||||
drop_console: true
|
||||
}
|
||||
},
|
||||
extractComments: false,
|
||||
})],
|
||||
},
|
||||
stats: {
|
||||
all: false,
|
||||
builtAt: true,
|
||||
errors: true,
|
||||
hash: true,
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user