Compare commits
62 Commits
fingerprin
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fde96d2200 | ||
|
|
ca627780b8 | ||
|
|
a3cff019f3 | ||
|
|
6c907e9163 | ||
|
|
74ebb401b1 | ||
|
|
3662b6d705 | ||
|
|
f1a44edd6b | ||
|
|
d400dd8154 | ||
|
|
dd067d7514 | ||
|
|
46ff14ed3c | ||
|
|
f371478e17 | ||
|
|
9518b127ce | ||
|
|
3c1a8ee4b9 | ||
|
|
ea0ffa41ec | ||
|
|
179ecc71b3 | ||
|
|
4f5e1ff299 | ||
|
|
c920fefbb0 | ||
|
|
4692ac10ab | ||
|
|
62de00febb | ||
|
|
8408469776 | ||
|
|
c6b61ae607 | ||
|
|
fabf2bee29 | ||
|
|
df1c957acb | ||
|
|
370406c6f4 | ||
|
|
bc56f07aaa | ||
|
|
7d94f31a99 | ||
|
|
aa7d05f9b5 | ||
|
|
1932e1a1ed | ||
|
|
6935c70081 | ||
|
|
899e11bf88 | ||
|
|
111df84ac0 | ||
|
|
51db4578ae | ||
|
|
e787f540cf | ||
|
|
5c784ead7f | ||
|
|
dbbdb1f5d8 | ||
|
|
1b2be846be | ||
|
|
98e88b749a | ||
|
|
d84e141714 | ||
|
|
9e66504e59 | ||
|
|
a71a4bc15a | ||
|
|
93f7989dae | ||
|
|
87fae0f983 | ||
|
|
8a00482fbd | ||
|
|
f92517c82a | ||
|
|
8341af8c93 | ||
|
|
803dc5ba3a | ||
|
|
791663c84b | ||
|
|
4a7bc1667a | ||
|
|
087b1d78dc | ||
|
|
f7e13b3f2c | ||
|
|
076a0f1588 | ||
|
|
891eb255f5 | ||
|
|
7a64e2483f | ||
|
|
e4ae0419db | ||
|
|
803f9c2adb | ||
|
|
87b5b940fb | ||
|
|
6cfef9e8ff | ||
|
|
f1ae9ac2a3 | ||
|
|
93918c225d | ||
|
|
b778f7dc47 | ||
|
|
69c75b10ee | ||
|
|
07a879a2a6 |
674
LICENSE
Normal file
674
LICENSE
Normal file
@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<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 General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
||||
74
README.md
74
README.md
@ -1,9 +1,6 @@
|
||||
|
||||
# Overview
|
||||
|
||||
This is a ratcheting forward secrecy protocol that works in synchronous and asynchronous messaging
|
||||
environments. The protocol overview is available [here](https://github.com/trevp/axolotl/wiki),
|
||||
and the details of the wire format are available [here](https://github.com/WhisperSystems/TextSecure/wiki/ProtocolV2).
|
||||
A ratcheting forward secrecy protocol that works in synchronous and asynchronous messaging environments.
|
||||
|
||||
## PreKeys
|
||||
|
||||
@ -15,7 +12,7 @@ PreKeys, and transmit all of them to the server.
|
||||
|
||||
## Sessions
|
||||
|
||||
The axolotl protocol is session-oriented. Clients establish a "session," which is then used for
|
||||
Signal Protocol is session-oriented. Clients establish a "session," which is then used for
|
||||
all subsequent encrypt/decrypt operations. There is no need to ever tear down a session once one
|
||||
has been established.
|
||||
|
||||
@ -23,7 +20,7 @@ Sessions are established in one of three ways:
|
||||
|
||||
1. PreKeyBundles. A client that wishes to send a message to a recipient can establish a session by
|
||||
retrieving a PreKeyBundle for that recipient from the server.
|
||||
1. PreKeyWhisperMessages. A client can receive a PreKeyWhisperMessage from a recipient and use it
|
||||
1. PreKeySignalMessages. A client can receive a PreKeySignalMessage from a recipient and use it
|
||||
to establish a session.
|
||||
1. KeyExchangeMessages. Two clients can exchange KeyExchange messages to establish a session.
|
||||
|
||||
@ -40,70 +37,73 @@ State is kept in the following places:
|
||||
1. Signed PreKey States. Clients will need to maintain the state of their signed PreKeys.
|
||||
1. Session State. Clients will need to maintain the state of the sessions they have established.
|
||||
|
||||
# Using libaxolotl
|
||||
# Using libsignal-protocol
|
||||
|
||||
## Configuration
|
||||
|
||||
On Android:
|
||||
|
||||
```
|
||||
```groovy
|
||||
dependencies {
|
||||
compile 'org.whispersystems:axolotl-android:(latest version number)'
|
||||
compile 'org.whispersystems:signal-protocol-android:(latest version number)'
|
||||
}
|
||||
```
|
||||
|
||||
For pure Java apps:
|
||||
|
||||
```
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>org.whispersystems</groupId>
|
||||
<artifactId>axolotl-java</artifactId>
|
||||
<artifactId>signal-protocol-java</artifactId>
|
||||
<version>(latest version number)</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
## Install time
|
||||
|
||||
At install time, a libaxolotl client needs to generate its identity keys, registration id, and
|
||||
At install time, a libsignal client needs to generate its identity keys, registration id, and
|
||||
prekeys.
|
||||
|
||||
IdentityKeyPair identityKeyPair = KeyHelper.generateIdentityKeyPair();
|
||||
int registrationId = KeyHelper.generateRegistrationId();
|
||||
List<PreKeyRecord> preKeys = KeyHelper.generatePreKeys(startId, 100);
|
||||
PreKeyRecord lastResortKey = KeyHelper.generateLastResortKey();
|
||||
SignedPreKeyRecord signedPreKey = KeyHelper.generateSignedPreKey(identityKeyPair, 5);
|
||||
```java
|
||||
IdentityKeyPair identityKeyPair = KeyHelper.generateIdentityKeyPair();
|
||||
int registrationId = KeyHelper.generateRegistrationId();
|
||||
List<PreKeyRecord> preKeys = KeyHelper.generatePreKeys(startId, 100);
|
||||
SignedPreKeyRecord signedPreKey = KeyHelper.generateSignedPreKey(identityKeyPair, 5);
|
||||
|
||||
// Store identityKeyPair somewhere durable and safe.
|
||||
// Store registrationId somewhere durable and safe.
|
||||
|
||||
// Store preKeys in PreKeyStore.
|
||||
// Store signed prekey in SignedPreKeyStore.
|
||||
// Store identityKeyPair somewhere durable and safe.
|
||||
// Store registrationId somewhere durable and safe.
|
||||
|
||||
// Store preKeys in PreKeyStore.
|
||||
// Store signed prekey in SignedPreKeyStore.
|
||||
```
|
||||
|
||||
## Building a session
|
||||
|
||||
A libaxolotl client needs to implement four interfaces: IdentityKeyStore, PreKeyStore,
|
||||
A libsignal client needs to implement four interfaces: IdentityKeyStore, PreKeyStore,
|
||||
SignedPreKeyStore, and SessionStore. These will manage loading and storing of identity,
|
||||
prekeys, signed prekeys, and session state.
|
||||
|
||||
Once those are implemented, building a session is fairly straightforward:
|
||||
|
||||
SessionStore sessionStore = new MySessionStore();
|
||||
PreKeyStore preKeyStore = new MyPreKeyStore();
|
||||
SignedPreKeyStore signedPreKeyStore = new MySignedPreKeyStore();
|
||||
IdentityKeyStore identityStore = new MyIdentityKeyStore();
|
||||
```java
|
||||
SessionStore sessionStore = new MySessionStore();
|
||||
PreKeyStore preKeyStore = new MyPreKeyStore();
|
||||
SignedPreKeyStore signedPreKeyStore = new MySignedPreKeyStore();
|
||||
IdentityKeyStore identityStore = new MyIdentityKeyStore();
|
||||
|
||||
// Instantiate a SessionBuilder for a remote recipientId + deviceId tuple.
|
||||
SessionBuilder sessionBuilder = new SessionBuilder(sessionStore, preKeyStore, signedPreKeyStore,
|
||||
identityStore, recipientId, deviceId);
|
||||
// Instantiate a SessionBuilder for a remote recipientId + deviceId tuple.
|
||||
SessionBuilder sessionBuilder = new SessionBuilder(sessionStore, preKeyStore, signedPreKeyStore,
|
||||
identityStore, recipientId, deviceId);
|
||||
|
||||
// Build a session with a PreKey retrieved from the server.
|
||||
sessionBuilder.process(retrievedPreKey);
|
||||
// Build a session with a PreKey retrieved from the server.
|
||||
sessionBuilder.process(retrievedPreKey);
|
||||
|
||||
SessionCipher sessionCipher = new SessionCipher(sessionStore, recipientId, deviceId);
|
||||
CiphertextMessage message = sessionCipher.encrypt("Hello world!".getBytes("UTF-8"));
|
||||
|
||||
deliver(message.serialize());
|
||||
SessionCipher sessionCipher = new SessionCipher(sessionStore, recipientId, deviceId);
|
||||
CiphertextMessage message = sessionCipher.encrypt("Hello world!".getBytes("UTF-8"));
|
||||
|
||||
deliver(message.serialize());
|
||||
```
|
||||
|
||||
# Legal things
|
||||
## Cryptography Notice
|
||||
|
||||
@ -116,7 +116,7 @@ The form and manner of this distribution makes it eligible for export under the
|
||||
|
||||
## License
|
||||
|
||||
Copyright 2013-2015 Open Whisper Systems
|
||||
Copyright 2013-2019 Open Whisper Systems
|
||||
|
||||
Licensed under the GPLv3: http://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
||||
|
||||
@ -1,10 +1,16 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
jcenter {
|
||||
content {
|
||||
includeVersion 'org.jetbrains.trove4j', 'trove4j', '20160824'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:1.0.0'
|
||||
classpath 'com.android.tools.build:gradle:3.5.1'
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,34 +18,40 @@ apply plugin: 'com.android.library'
|
||||
apply plugin: 'maven'
|
||||
apply plugin: 'signing'
|
||||
|
||||
archivesBaseName = "axolotl-android"
|
||||
archivesBaseName = "signal-protocol-android"
|
||||
version = version_number
|
||||
group = group_info
|
||||
|
||||
android {
|
||||
compileSdkVersion 21
|
||||
buildToolsVersion "21.1.2"
|
||||
compileSdkVersion 28
|
||||
buildToolsVersion '28.0.3'
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 19
|
||||
targetSdkVersion 28
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_7
|
||||
targetCompatibility JavaVersion.VERSION_1_7
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
androidTest {
|
||||
java.srcDirs = ['src/androidTest/java', project(':tests').file('src/test/java')]
|
||||
}
|
||||
}
|
||||
|
||||
libraryVariants.all { variant ->
|
||||
variant.outputs.each { output ->
|
||||
def outputFile = output.outputFile
|
||||
if (outputFile != null && outputFile.name.endsWith('.aar')) {
|
||||
def fileName = "${archivesBaseName}-${version}.aar"
|
||||
output.outputFile = new File(outputFile.parent, fileName)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
jcenter {
|
||||
content {
|
||||
includeVersion 'org.jetbrains.trove4j', 'trove4j', '20160824'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@ -49,8 +61,25 @@ dependencies {
|
||||
}
|
||||
}
|
||||
|
||||
def isReleaseBuild() {
|
||||
return version.contains("SNAPSHOT") == false
|
||||
}
|
||||
|
||||
def getReleaseRepositoryUrl() {
|
||||
return hasProperty('sonatypeRepo') ? sonatypeRepo
|
||||
: "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
|
||||
}
|
||||
|
||||
def getRepositoryUsername() {
|
||||
return hasProperty('whisperSonatypeUsername') ? whisperSonatypeUsername : ""
|
||||
}
|
||||
|
||||
def getRepositoryPassword() {
|
||||
return hasProperty('whisperSonatypePassword') ? whisperSonatypePassword : ""
|
||||
}
|
||||
|
||||
signing {
|
||||
required { has("release") && gradle.taskGraph.hasTask("uploadArchives") }
|
||||
required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") }
|
||||
sign configurations.archives
|
||||
}
|
||||
|
||||
@ -59,20 +88,20 @@ uploadArchives {
|
||||
repositories.mavenDeployer {
|
||||
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
|
||||
|
||||
repository(url: sonatypeRepo) {
|
||||
authentication(userName: whisperSonatypeUsername, password: whisperSonatypePassword)
|
||||
repository(url: getReleaseRepositoryUrl()) {
|
||||
authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
|
||||
}
|
||||
|
||||
pom.project {
|
||||
name 'axolotl-android'
|
||||
name 'signal-protocol-android'
|
||||
packaging 'aar'
|
||||
description 'Axolotl library for Android'
|
||||
url 'https://github.com/WhisperSystems/libaxolotl-android'
|
||||
description 'Signal Protocol cryptography library for Android'
|
||||
url 'https://github.com/WhisperSystems/libsignal-android'
|
||||
|
||||
scm {
|
||||
url 'scm:git@github.com:WhisperSystems/libaxolotl-android.git'
|
||||
connection 'scm:git@github.com:WhisperSystems/libaxolotl-android.git'
|
||||
developerConnection 'scm:git@github.com:WhisperSystems/libaxolotl-android.git'
|
||||
url 'scm:git@github.com:WhisperSystems/libsignal-android.git'
|
||||
connection 'scm:git@github.com:WhisperSystems/libsignal-android.git'
|
||||
developerConnection 'scm:git@github.com:WhisperSystems/libsignal-android.git'
|
||||
}
|
||||
|
||||
licenses {
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
package org.whispersystems.libaxolotl;
|
||||
package org.whispersystems.libsignal;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.whispersystems.libaxolotl.ecc.Curve;
|
||||
import org.whispersystems.libaxolotl.ecc.ECKeyPair;
|
||||
import org.whispersystems.libsignal.ecc.Curve;
|
||||
import org.whispersystems.libsignal.ecc.ECKeyPair;
|
||||
|
||||
public class CurveTest extends TestCase {
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.whispersystems.libaxolotl">
|
||||
package="org.whispersystems.libsignal">
|
||||
</manifest>
|
||||
|
||||
@ -1,24 +0,0 @@
|
||||
package org.whispersystems.libaxolotl.util;
|
||||
|
||||
import android.util.Log;
|
||||
import android.util.SparseIntArray;
|
||||
|
||||
import org.whispersystems.libaxolotl.logging.AxolotlLogger;
|
||||
|
||||
public class AndroidAxolotlLogger implements AxolotlLogger {
|
||||
|
||||
private static final SparseIntArray PRIORITY_MAP = new SparseIntArray(5) {{
|
||||
put(AxolotlLogger.INFO, Log.INFO);
|
||||
put(AxolotlLogger.ASSERT, Log.ASSERT);
|
||||
put(AxolotlLogger.DEBUG, Log.DEBUG);
|
||||
put(AxolotlLogger.VERBOSE, Log.VERBOSE);
|
||||
put(AxolotlLogger.WARN, Log.WARN);
|
||||
|
||||
}};
|
||||
|
||||
@Override
|
||||
public void log(int priority, String tag, String message) {
|
||||
int androidPriority = PRIORITY_MAP.get(priority, Log.WARN);
|
||||
Log.println(androidPriority, tag, message);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
/**
|
||||
* Copyright (C) 2014-2016 Open Whisper Systems
|
||||
*
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
package org.whispersystems.libsignal.util;
|
||||
|
||||
import android.util.Log;
|
||||
import android.util.SparseIntArray;
|
||||
|
||||
import org.whispersystems.libsignal.logging.SignalProtocolLogger;
|
||||
|
||||
public class AndroidSignalProtocolLogger implements SignalProtocolLogger {
|
||||
|
||||
private static final SparseIntArray PRIORITY_MAP = new SparseIntArray(5) {{
|
||||
put(SignalProtocolLogger.INFO, Log.INFO);
|
||||
put(SignalProtocolLogger.ASSERT, Log.ASSERT);
|
||||
put(SignalProtocolLogger.DEBUG, Log.DEBUG);
|
||||
put(SignalProtocolLogger.VERBOSE, Log.VERBOSE);
|
||||
put(SignalProtocolLogger.WARN, Log.WARN);
|
||||
|
||||
}};
|
||||
|
||||
@Override
|
||||
public void log(int priority, String tag, String message) {
|
||||
int androidPriority = PRIORITY_MAP.get(priority, Log.WARN);
|
||||
Log.println(androidPriority, tag, message);
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,7 @@
|
||||
subprojects {
|
||||
ext.version_number = "1.3.4"
|
||||
ext.version_number = "2.8.1"
|
||||
ext.group_info = "org.whispersystems"
|
||||
ext.curve25519_version = "0.2.4"
|
||||
ext.curve25519_version = "0.5.0"
|
||||
|
||||
if (JavaVersion.current().isJava8Compatible()) {
|
||||
allprojects {
|
||||
|
||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
5
gradle/wrapper/gradle-wrapper.properties
vendored
5
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,6 +1,7 @@
|
||||
#Tue Dec 09 10:15:39 PST 2014
|
||||
# Note: Check https://gradle.org/release-checksums/ before updating wrapper or distribution
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionSha256Sum=027fdd265d277bae65a0d349b6b8da02135b0b8e14ba891e26281fa877fe37a2
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
|
||||
|
||||
130
gradlew
vendored
130
gradlew
vendored
@ -1,4 +1,20 @@
|
||||
#!/usr/bin/env bash
|
||||
#!/usr/bin/env sh
|
||||
|
||||
#
|
||||
# Copyright 2015 the original author or authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
@ -6,47 +22,6 @@
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS=""
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn ( ) {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die ( ) {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
esac
|
||||
|
||||
# For Cygwin, ensure paths are in UNIX format before anything is touched.
|
||||
if $cygwin ; then
|
||||
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
|
||||
fi
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
@ -61,9 +36,49 @@ while [ -h "$PRG" ] ; do
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >&-
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >&-
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
NONSTOP* )
|
||||
nonstop=true
|
||||
;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
@ -90,7 +105,7 @@ location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
@ -110,10 +125,11 @@ if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin, switch paths to Windows format before running java
|
||||
if $cygwin ; then
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
@ -154,11 +170,19 @@ if $cygwin ; then
|
||||
esac
|
||||
fi
|
||||
|
||||
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
|
||||
function splitJvmOpts() {
|
||||
JVM_OPTS=("$@")
|
||||
# Escape application args
|
||||
save () {
|
||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||
echo " "
|
||||
}
|
||||
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
|
||||
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
|
||||
APP_ARGS=$(save "$@")
|
||||
|
||||
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
|
||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||
|
||||
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
|
||||
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
|
||||
cd "$(dirname "$0")"
|
||||
fi
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
|
||||
30
gradlew.bat
vendored
30
gradlew.bat
vendored
@ -1,3 +1,19 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@ -8,14 +24,14 @@
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS=
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
@ -46,10 +62,9 @@ echo location of your Java installation.
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windowz variants
|
||||
@rem Get command-line arguments, handling Windows variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
if "%@eval[2+2]" == "4" goto 4NT_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
@ -60,11 +75,6 @@ set _SKIP=2
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
goto execute
|
||||
|
||||
:4NT_args
|
||||
@rem Get arguments from the 4NT Shell from JP Software
|
||||
set CMD_LINE_ARGS=%$
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
@ -1,9 +1,21 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.10'
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'com.google.protobuf'
|
||||
apply plugin: 'maven'
|
||||
apply plugin: 'signing'
|
||||
|
||||
sourceCompatibility = 1.7
|
||||
archivesBaseName = "axolotl-java"
|
||||
archivesBaseName = "signal-protocol-java"
|
||||
version = version_number
|
||||
group = group_info
|
||||
|
||||
@ -22,11 +34,30 @@ sourceSets {
|
||||
|
||||
dependencies {
|
||||
compile "org.whispersystems:curve25519-java:${curve25519_version}"
|
||||
compile 'com.google.protobuf:protobuf-java:2.5.0'
|
||||
compile 'com.google.protobuf:protobuf-javalite:3.10.0'
|
||||
|
||||
testCompile ('junit:junit:3.8.2')
|
||||
}
|
||||
|
||||
protobuf {
|
||||
protoc {
|
||||
artifact = 'com.google.protobuf:protoc:3.10.0'
|
||||
}
|
||||
generateProtoTasks {
|
||||
all().each { task ->
|
||||
task.builtins {
|
||||
java {
|
||||
option "lite"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main.proto.srcDir '../protobuf'
|
||||
}
|
||||
|
||||
|
||||
test {
|
||||
testLogging {
|
||||
@ -37,8 +68,25 @@ test {
|
||||
include 'org/whispersystems/**'
|
||||
}
|
||||
|
||||
def isReleaseBuild() {
|
||||
return version.contains("SNAPSHOT") == false
|
||||
}
|
||||
|
||||
def getReleaseRepositoryUrl() {
|
||||
return hasProperty('sonatypeRepo') ? sonatypeRepo
|
||||
: "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
|
||||
}
|
||||
|
||||
def getRepositoryUsername() {
|
||||
return hasProperty('whisperSonatypeUsername') ? whisperSonatypeUsername : ""
|
||||
}
|
||||
|
||||
def getRepositoryPassword() {
|
||||
return hasProperty('whisperSonatypePassword') ? whisperSonatypePassword : ""
|
||||
}
|
||||
|
||||
signing {
|
||||
required { has("release") && gradle.taskGraph.hasTask("uploadArchives") }
|
||||
required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") }
|
||||
sign configurations.archives
|
||||
}
|
||||
|
||||
@ -47,20 +95,20 @@ uploadArchives {
|
||||
repositories.mavenDeployer {
|
||||
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
|
||||
|
||||
repository(url: sonatypeRepo) {
|
||||
authentication(userName: whisperSonatypeUsername, password: whisperSonatypePassword)
|
||||
repository(url: getReleaseRepositoryUrl()) {
|
||||
authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
|
||||
}
|
||||
|
||||
pom.project {
|
||||
name 'axolotl-java'
|
||||
name 'signal-protocol-java'
|
||||
packaging 'jar'
|
||||
description 'Axolotl library for Java'
|
||||
url 'https://github.com/WhisperSystems/libaxolotl-android'
|
||||
description 'Signal Protocol cryptography library for Java'
|
||||
url 'https://github.com/WhisperSystems/libsignal-android'
|
||||
|
||||
scm {
|
||||
url 'scm:git@github.com:WhisperSystems/libaxolotl-android.git'
|
||||
connection 'scm:git@github.com:WhisperSystems/libaxolotl-android.git'
|
||||
developerConnection 'scm:git@github.com:WhisperSystems/libaxolotl-android.git'
|
||||
url 'scm:git@github.com:WhisperSystems/libsignal-android.git'
|
||||
connection 'scm:git@github.com:WhisperSystems/libsignal-android.git'
|
||||
developerConnection 'scm:git@github.com:WhisperSystems/libsignal-android.git'
|
||||
}
|
||||
|
||||
licenses {
|
||||
|
||||
@ -1,5 +0,0 @@
|
||||
package org.whispersystems.libaxolotl;
|
||||
|
||||
public interface DecryptionCallback {
|
||||
public void handlePlaintext(byte[] plaintext);
|
||||
}
|
||||
@ -1,7 +0,0 @@
|
||||
package org.whispersystems.libaxolotl;
|
||||
|
||||
public class DuplicateMessageException extends Exception {
|
||||
public DuplicateMessageException(String s) {
|
||||
super(s);
|
||||
}
|
||||
}
|
||||
@ -1,34 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2014 Open Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.whispersystems.libaxolotl;
|
||||
|
||||
public class InvalidKeyException extends Exception {
|
||||
|
||||
public InvalidKeyException() {}
|
||||
|
||||
public InvalidKeyException(String detailMessage) {
|
||||
super(detailMessage);
|
||||
}
|
||||
|
||||
public InvalidKeyException(Throwable throwable) {
|
||||
super(throwable);
|
||||
}
|
||||
|
||||
public InvalidKeyException(String detailMessage, Throwable throwable) {
|
||||
super(detailMessage, throwable);
|
||||
}
|
||||
}
|
||||
@ -1,27 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2014 Open Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.whispersystems.libaxolotl;
|
||||
|
||||
public class InvalidKeyIdException extends Exception {
|
||||
public InvalidKeyIdException(String detailMessage) {
|
||||
super(detailMessage);
|
||||
}
|
||||
|
||||
public InvalidKeyIdException(Throwable throwable) {
|
||||
super(throwable);
|
||||
}
|
||||
}
|
||||
@ -1,28 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2014 Open Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.whispersystems.libaxolotl;
|
||||
|
||||
public class InvalidMacException extends Exception {
|
||||
|
||||
public InvalidMacException(String detailMessage) {
|
||||
super(detailMessage);
|
||||
}
|
||||
|
||||
public InvalidMacException(Throwable throwable) {
|
||||
super(throwable);
|
||||
}
|
||||
}
|
||||
@ -1,40 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2014 Open Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.whispersystems.libaxolotl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class InvalidMessageException extends Exception {
|
||||
|
||||
public InvalidMessageException() {}
|
||||
|
||||
public InvalidMessageException(String detailMessage) {
|
||||
super(detailMessage);
|
||||
}
|
||||
|
||||
public InvalidMessageException(Throwable throwable) {
|
||||
super(throwable);
|
||||
}
|
||||
|
||||
public InvalidMessageException(String detailMessage, Throwable throwable) {
|
||||
super(detailMessage, throwable);
|
||||
}
|
||||
|
||||
public InvalidMessageException(String detailMessage, List<Exception> exceptions) {
|
||||
super(detailMessage, exceptions.get(0));
|
||||
}
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2014 Open Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.whispersystems.libaxolotl;
|
||||
|
||||
public class InvalidVersionException extends Exception {
|
||||
public InvalidVersionException(String detailMessage) {
|
||||
super(detailMessage);
|
||||
}
|
||||
}
|
||||
@ -1,7 +0,0 @@
|
||||
package org.whispersystems.libaxolotl;
|
||||
|
||||
public class LegacyMessageException extends Exception {
|
||||
public LegacyMessageException(String s) {
|
||||
super(s);
|
||||
}
|
||||
}
|
||||
@ -1,407 +0,0 @@
|
||||
package org.whispersystems.libaxolotl;
|
||||
|
||||
|
||||
import org.whispersystems.libaxolotl.ecc.Curve;
|
||||
import org.whispersystems.libaxolotl.ecc.ECKeyPair;
|
||||
import org.whispersystems.libaxolotl.ecc.ECPublicKey;
|
||||
import org.whispersystems.libaxolotl.logging.Log;
|
||||
import org.whispersystems.libaxolotl.protocol.CiphertextMessage;
|
||||
import org.whispersystems.libaxolotl.protocol.KeyExchangeMessage;
|
||||
import org.whispersystems.libaxolotl.protocol.PreKeyWhisperMessage;
|
||||
import org.whispersystems.libaxolotl.ratchet.AliceAxolotlParameters;
|
||||
import org.whispersystems.libaxolotl.ratchet.BobAxolotlParameters;
|
||||
import org.whispersystems.libaxolotl.ratchet.RatchetingSession;
|
||||
import org.whispersystems.libaxolotl.ratchet.SymmetricAxolotlParameters;
|
||||
import org.whispersystems.libaxolotl.state.AxolotlStore;
|
||||
import org.whispersystems.libaxolotl.state.IdentityKeyStore;
|
||||
import org.whispersystems.libaxolotl.state.PreKeyBundle;
|
||||
import org.whispersystems.libaxolotl.state.PreKeyStore;
|
||||
import org.whispersystems.libaxolotl.state.SessionRecord;
|
||||
import org.whispersystems.libaxolotl.state.SessionState;
|
||||
import org.whispersystems.libaxolotl.state.SessionStore;
|
||||
import org.whispersystems.libaxolotl.state.SignedPreKeyStore;
|
||||
import org.whispersystems.libaxolotl.util.KeyHelper;
|
||||
import org.whispersystems.libaxolotl.util.Medium;
|
||||
import org.whispersystems.libaxolotl.util.guava.Optional;
|
||||
|
||||
/**
|
||||
* SessionBuilder is responsible for setting up encrypted sessions.
|
||||
* Once a session has been established, {@link org.whispersystems.libaxolotl.SessionCipher}
|
||||
* can be used to encrypt/decrypt messages in that session.
|
||||
* <p>
|
||||
* Sessions are built from one of three different possible vectors:
|
||||
* <ol>
|
||||
* <li>A {@link org.whispersystems.libaxolotl.state.PreKeyBundle} retrieved from a server.</li>
|
||||
* <li>A {@link org.whispersystems.libaxolotl.protocol.PreKeyWhisperMessage} received from a client.</li>
|
||||
* <li>A {@link org.whispersystems.libaxolotl.protocol.KeyExchangeMessage} sent to or received from a client.</li>
|
||||
* </ol>
|
||||
*
|
||||
* Sessions are constructed per recipientId + deviceId tuple. Remote logical users are identified
|
||||
* by their recipientId, and each logical recipientId can have multiple physical devices.
|
||||
*
|
||||
* @author Moxie Marlinspike
|
||||
*/
|
||||
public class SessionBuilder {
|
||||
|
||||
private static final String TAG = SessionBuilder.class.getSimpleName();
|
||||
|
||||
private final SessionStore sessionStore;
|
||||
private final PreKeyStore preKeyStore;
|
||||
private final SignedPreKeyStore signedPreKeyStore;
|
||||
private final IdentityKeyStore identityKeyStore;
|
||||
private final AxolotlAddress remoteAddress;
|
||||
|
||||
/**
|
||||
* Constructs a SessionBuilder.
|
||||
*
|
||||
* @param sessionStore The {@link org.whispersystems.libaxolotl.state.SessionStore} to store the constructed session in.
|
||||
* @param preKeyStore The {@link org.whispersystems.libaxolotl.state.PreKeyStore} where the client's local {@link org.whispersystems.libaxolotl.state.PreKeyRecord}s are stored.
|
||||
* @param identityKeyStore The {@link org.whispersystems.libaxolotl.state.IdentityKeyStore} containing the client's identity key information.
|
||||
* @param remoteAddress The address of the remote user to build a session with.
|
||||
*/
|
||||
public SessionBuilder(SessionStore sessionStore,
|
||||
PreKeyStore preKeyStore,
|
||||
SignedPreKeyStore signedPreKeyStore,
|
||||
IdentityKeyStore identityKeyStore,
|
||||
AxolotlAddress remoteAddress)
|
||||
{
|
||||
this.sessionStore = sessionStore;
|
||||
this.preKeyStore = preKeyStore;
|
||||
this.signedPreKeyStore = signedPreKeyStore;
|
||||
this.identityKeyStore = identityKeyStore;
|
||||
this.remoteAddress = remoteAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a SessionBuilder
|
||||
* @param store The {@link org.whispersystems.libaxolotl.state.AxolotlStore} to store all state information in.
|
||||
* @param remoteAddress The address of the remote user to build a session with.
|
||||
*/
|
||||
public SessionBuilder(AxolotlStore store, AxolotlAddress remoteAddress) {
|
||||
this(store, store, store, store, remoteAddress);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a new session from a received {@link org.whispersystems.libaxolotl.protocol.PreKeyWhisperMessage}.
|
||||
*
|
||||
* After a session is constructed in this way, the embedded {@link org.whispersystems.libaxolotl.protocol.WhisperMessage}
|
||||
* can be decrypted.
|
||||
*
|
||||
* @param message The received {@link org.whispersystems.libaxolotl.protocol.PreKeyWhisperMessage}.
|
||||
* @throws org.whispersystems.libaxolotl.InvalidKeyIdException when there is no local
|
||||
* {@link org.whispersystems.libaxolotl.state.PreKeyRecord}
|
||||
* that corresponds to the PreKey ID in
|
||||
* the message.
|
||||
* @throws org.whispersystems.libaxolotl.InvalidKeyException when the message is formatted incorrectly.
|
||||
* @throws org.whispersystems.libaxolotl.UntrustedIdentityException when the {@link IdentityKey} of the sender is untrusted.
|
||||
*/
|
||||
/*package*/ Optional<Integer> process(SessionRecord sessionRecord, PreKeyWhisperMessage message)
|
||||
throws InvalidKeyIdException, InvalidKeyException, UntrustedIdentityException
|
||||
{
|
||||
int messageVersion = message.getMessageVersion();
|
||||
IdentityKey theirIdentityKey = message.getIdentityKey();
|
||||
|
||||
Optional<Integer> unsignedPreKeyId;
|
||||
|
||||
if (!identityKeyStore.isTrustedIdentity(remoteAddress.getName(), theirIdentityKey)) {
|
||||
throw new UntrustedIdentityException(remoteAddress.getName(), theirIdentityKey);
|
||||
}
|
||||
|
||||
switch (messageVersion) {
|
||||
case 2: unsignedPreKeyId = processV2(sessionRecord, message); break;
|
||||
case 3: unsignedPreKeyId = processV3(sessionRecord, message); break;
|
||||
default: throw new AssertionError("Unknown version: " + messageVersion);
|
||||
}
|
||||
|
||||
identityKeyStore.saveIdentity(remoteAddress.getName(), theirIdentityKey);
|
||||
return unsignedPreKeyId;
|
||||
}
|
||||
|
||||
private Optional<Integer> processV3(SessionRecord sessionRecord, PreKeyWhisperMessage message)
|
||||
throws UntrustedIdentityException, InvalidKeyIdException, InvalidKeyException
|
||||
{
|
||||
|
||||
if (sessionRecord.hasSessionState(message.getMessageVersion(), message.getBaseKey().serialize())) {
|
||||
Log.w(TAG, "We've already setup a session for this V3 message, letting bundled message fall through...");
|
||||
return Optional.absent();
|
||||
}
|
||||
|
||||
ECKeyPair ourSignedPreKey = signedPreKeyStore.loadSignedPreKey(message.getSignedPreKeyId()).getKeyPair();
|
||||
|
||||
BobAxolotlParameters.Builder parameters = BobAxolotlParameters.newBuilder();
|
||||
|
||||
parameters.setTheirBaseKey(message.getBaseKey())
|
||||
.setTheirIdentityKey(message.getIdentityKey())
|
||||
.setOurIdentityKey(identityKeyStore.getIdentityKeyPair())
|
||||
.setOurSignedPreKey(ourSignedPreKey)
|
||||
.setOurRatchetKey(ourSignedPreKey);
|
||||
|
||||
if (message.getPreKeyId().isPresent()) {
|
||||
parameters.setOurOneTimePreKey(Optional.of(preKeyStore.loadPreKey(message.getPreKeyId().get()).getKeyPair()));
|
||||
} else {
|
||||
parameters.setOurOneTimePreKey(Optional.<ECKeyPair>absent());
|
||||
}
|
||||
|
||||
if (!sessionRecord.isFresh()) sessionRecord.archiveCurrentState();
|
||||
|
||||
RatchetingSession.initializeSession(sessionRecord.getSessionState(), message.getMessageVersion(), parameters.create());
|
||||
|
||||
sessionRecord.getSessionState().setLocalRegistrationId(identityKeyStore.getLocalRegistrationId());
|
||||
sessionRecord.getSessionState().setRemoteRegistrationId(message.getRegistrationId());
|
||||
sessionRecord.getSessionState().setAliceBaseKey(message.getBaseKey().serialize());
|
||||
|
||||
if (message.getPreKeyId().isPresent() && message.getPreKeyId().get() != Medium.MAX_VALUE) {
|
||||
return message.getPreKeyId();
|
||||
} else {
|
||||
return Optional.absent();
|
||||
}
|
||||
}
|
||||
|
||||
private Optional<Integer> processV2(SessionRecord sessionRecord, PreKeyWhisperMessage message)
|
||||
throws UntrustedIdentityException, InvalidKeyIdException, InvalidKeyException
|
||||
{
|
||||
if (!message.getPreKeyId().isPresent()) {
|
||||
throw new InvalidKeyIdException("V2 message requires one time prekey id!");
|
||||
}
|
||||
|
||||
if (!preKeyStore.containsPreKey(message.getPreKeyId().get()) &&
|
||||
sessionStore.containsSession(remoteAddress))
|
||||
{
|
||||
Log.w(TAG, "We've already processed the prekey part of this V2 session, letting bundled message fall through...");
|
||||
return Optional.absent();
|
||||
}
|
||||
|
||||
ECKeyPair ourPreKey = preKeyStore.loadPreKey(message.getPreKeyId().get()).getKeyPair();
|
||||
|
||||
BobAxolotlParameters.Builder parameters = BobAxolotlParameters.newBuilder();
|
||||
|
||||
parameters.setOurIdentityKey(identityKeyStore.getIdentityKeyPair())
|
||||
.setOurSignedPreKey(ourPreKey)
|
||||
.setOurRatchetKey(ourPreKey)
|
||||
.setOurOneTimePreKey(Optional.<ECKeyPair>absent())
|
||||
.setTheirIdentityKey(message.getIdentityKey())
|
||||
.setTheirBaseKey(message.getBaseKey());
|
||||
|
||||
if (!sessionRecord.isFresh()) sessionRecord.archiveCurrentState();
|
||||
|
||||
RatchetingSession.initializeSession(sessionRecord.getSessionState(), message.getMessageVersion(), parameters.create());
|
||||
|
||||
sessionRecord.getSessionState().setLocalRegistrationId(identityKeyStore.getLocalRegistrationId());
|
||||
sessionRecord.getSessionState().setRemoteRegistrationId(message.getRegistrationId());
|
||||
sessionRecord.getSessionState().setAliceBaseKey(message.getBaseKey().serialize());
|
||||
|
||||
if (message.getPreKeyId().get() != Medium.MAX_VALUE) {
|
||||
return message.getPreKeyId();
|
||||
} else {
|
||||
return Optional.absent();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a new session from a {@link org.whispersystems.libaxolotl.state.PreKeyBundle} retrieved from
|
||||
* a server.
|
||||
*
|
||||
* @param preKey A PreKey for the destination recipient, retrieved from a server.
|
||||
* @throws InvalidKeyException when the {@link org.whispersystems.libaxolotl.state.PreKeyBundle} is
|
||||
* badly formatted.
|
||||
* @throws org.whispersystems.libaxolotl.UntrustedIdentityException when the sender's
|
||||
* {@link IdentityKey} is not
|
||||
* trusted.
|
||||
*/
|
||||
public void process(PreKeyBundle preKey) throws InvalidKeyException, UntrustedIdentityException {
|
||||
synchronized (SessionCipher.SESSION_LOCK) {
|
||||
if (!identityKeyStore.isTrustedIdentity(remoteAddress.getName(), preKey.getIdentityKey())) {
|
||||
throw new UntrustedIdentityException(remoteAddress.getName(), preKey.getIdentityKey());
|
||||
}
|
||||
|
||||
if (preKey.getSignedPreKey() != null &&
|
||||
!Curve.verifySignature(preKey.getIdentityKey().getPublicKey(),
|
||||
preKey.getSignedPreKey().serialize(),
|
||||
preKey.getSignedPreKeySignature()))
|
||||
{
|
||||
throw new InvalidKeyException("Invalid signature on device key!");
|
||||
}
|
||||
|
||||
if (preKey.getSignedPreKey() == null && preKey.getPreKey() == null) {
|
||||
throw new InvalidKeyException("Both signed and unsigned prekeys are absent!");
|
||||
}
|
||||
|
||||
boolean supportsV3 = preKey.getSignedPreKey() != null;
|
||||
SessionRecord sessionRecord = sessionStore.loadSession(remoteAddress);
|
||||
ECKeyPair ourBaseKey = Curve.generateKeyPair();
|
||||
ECPublicKey theirSignedPreKey = supportsV3 ? preKey.getSignedPreKey() : preKey.getPreKey();
|
||||
Optional<ECPublicKey> theirOneTimePreKey = Optional.fromNullable(preKey.getPreKey());
|
||||
Optional<Integer> theirOneTimePreKeyId = theirOneTimePreKey.isPresent() ? Optional.of(preKey.getPreKeyId()) :
|
||||
Optional.<Integer>absent();
|
||||
|
||||
AliceAxolotlParameters.Builder parameters = AliceAxolotlParameters.newBuilder();
|
||||
|
||||
parameters.setOurBaseKey(ourBaseKey)
|
||||
.setOurIdentityKey(identityKeyStore.getIdentityKeyPair())
|
||||
.setTheirIdentityKey(preKey.getIdentityKey())
|
||||
.setTheirSignedPreKey(theirSignedPreKey)
|
||||
.setTheirRatchetKey(theirSignedPreKey)
|
||||
.setTheirOneTimePreKey(supportsV3 ? theirOneTimePreKey : Optional.<ECPublicKey>absent());
|
||||
|
||||
if (!sessionRecord.isFresh()) sessionRecord.archiveCurrentState();
|
||||
|
||||
RatchetingSession.initializeSession(sessionRecord.getSessionState(),
|
||||
supportsV3 ? 3 : 2,
|
||||
parameters.create());
|
||||
|
||||
sessionRecord.getSessionState().setUnacknowledgedPreKeyMessage(theirOneTimePreKeyId, preKey.getSignedPreKeyId(), ourBaseKey.getPublicKey());
|
||||
sessionRecord.getSessionState().setLocalRegistrationId(identityKeyStore.getLocalRegistrationId());
|
||||
sessionRecord.getSessionState().setRemoteRegistrationId(preKey.getRegistrationId());
|
||||
sessionRecord.getSessionState().setAliceBaseKey(ourBaseKey.getPublicKey().serialize());
|
||||
|
||||
sessionStore.storeSession(remoteAddress, sessionRecord);
|
||||
identityKeyStore.saveIdentity(remoteAddress.getName(), preKey.getIdentityKey());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a new session from a {@link org.whispersystems.libaxolotl.protocol.KeyExchangeMessage}
|
||||
* received from a remote client.
|
||||
*
|
||||
* @param message The received KeyExchangeMessage.
|
||||
* @return The KeyExchangeMessage to respond with, or null if no response is necessary.
|
||||
* @throws InvalidKeyException if the received KeyExchangeMessage is badly formatted.
|
||||
*/
|
||||
public KeyExchangeMessage process(KeyExchangeMessage message)
|
||||
throws InvalidKeyException, UntrustedIdentityException, StaleKeyExchangeException
|
||||
{
|
||||
synchronized (SessionCipher.SESSION_LOCK) {
|
||||
if (!identityKeyStore.isTrustedIdentity(remoteAddress.getName(), message.getIdentityKey())) {
|
||||
throw new UntrustedIdentityException(remoteAddress.getName(), message.getIdentityKey());
|
||||
}
|
||||
|
||||
KeyExchangeMessage responseMessage = null;
|
||||
|
||||
if (message.isInitiate()) responseMessage = processInitiate(message);
|
||||
else processResponse(message);
|
||||
|
||||
return responseMessage;
|
||||
}
|
||||
}
|
||||
|
||||
private KeyExchangeMessage processInitiate(KeyExchangeMessage message) throws InvalidKeyException {
|
||||
int flags = KeyExchangeMessage.RESPONSE_FLAG;
|
||||
SessionRecord sessionRecord = sessionStore.loadSession(remoteAddress);
|
||||
|
||||
if (message.getVersion() >= 3 &&
|
||||
!Curve.verifySignature(message.getIdentityKey().getPublicKey(),
|
||||
message.getBaseKey().serialize(),
|
||||
message.getBaseKeySignature()))
|
||||
{
|
||||
throw new InvalidKeyException("Bad signature!");
|
||||
}
|
||||
|
||||
SymmetricAxolotlParameters.Builder builder = SymmetricAxolotlParameters.newBuilder();
|
||||
|
||||
if (!sessionRecord.getSessionState().hasPendingKeyExchange()) {
|
||||
builder.setOurIdentityKey(identityKeyStore.getIdentityKeyPair())
|
||||
.setOurBaseKey(Curve.generateKeyPair())
|
||||
.setOurRatchetKey(Curve.generateKeyPair());
|
||||
} else {
|
||||
builder.setOurIdentityKey(sessionRecord.getSessionState().getPendingKeyExchangeIdentityKey())
|
||||
.setOurBaseKey(sessionRecord.getSessionState().getPendingKeyExchangeBaseKey())
|
||||
.setOurRatchetKey(sessionRecord.getSessionState().getPendingKeyExchangeRatchetKey());
|
||||
flags |= KeyExchangeMessage.SIMULTAENOUS_INITIATE_FLAG;
|
||||
}
|
||||
|
||||
builder.setTheirBaseKey(message.getBaseKey())
|
||||
.setTheirRatchetKey(message.getRatchetKey())
|
||||
.setTheirIdentityKey(message.getIdentityKey());
|
||||
|
||||
SymmetricAxolotlParameters parameters = builder.create();
|
||||
|
||||
if (!sessionRecord.isFresh()) sessionRecord.archiveCurrentState();
|
||||
|
||||
RatchetingSession.initializeSession(sessionRecord.getSessionState(),
|
||||
Math.min(message.getMaxVersion(), CiphertextMessage.CURRENT_VERSION),
|
||||
parameters);
|
||||
|
||||
sessionStore.storeSession(remoteAddress, sessionRecord);
|
||||
identityKeyStore.saveIdentity(remoteAddress.getName(), message.getIdentityKey());
|
||||
|
||||
byte[] baseKeySignature = Curve.calculateSignature(parameters.getOurIdentityKey().getPrivateKey(),
|
||||
parameters.getOurBaseKey().getPublicKey().serialize());
|
||||
|
||||
return new KeyExchangeMessage(sessionRecord.getSessionState().getSessionVersion(),
|
||||
message.getSequence(), flags,
|
||||
parameters.getOurBaseKey().getPublicKey(),
|
||||
baseKeySignature, parameters.getOurRatchetKey().getPublicKey(),
|
||||
parameters.getOurIdentityKey().getPublicKey());
|
||||
}
|
||||
|
||||
private void processResponse(KeyExchangeMessage message)
|
||||
throws StaleKeyExchangeException, InvalidKeyException
|
||||
{
|
||||
SessionRecord sessionRecord = sessionStore.loadSession(remoteAddress);
|
||||
SessionState sessionState = sessionRecord.getSessionState();
|
||||
boolean hasPendingKeyExchange = sessionState.hasPendingKeyExchange();
|
||||
boolean isSimultaneousInitiateResponse = message.isResponseForSimultaneousInitiate();
|
||||
|
||||
if (!hasPendingKeyExchange || sessionState.getPendingKeyExchangeSequence() != message.getSequence()) {
|
||||
Log.w(TAG, "No matching sequence for response. Is simultaneous initiate response: " + isSimultaneousInitiateResponse);
|
||||
if (!isSimultaneousInitiateResponse) throw new StaleKeyExchangeException();
|
||||
else return;
|
||||
}
|
||||
|
||||
SymmetricAxolotlParameters.Builder parameters = SymmetricAxolotlParameters.newBuilder();
|
||||
|
||||
parameters.setOurBaseKey(sessionRecord.getSessionState().getPendingKeyExchangeBaseKey())
|
||||
.setOurRatchetKey(sessionRecord.getSessionState().getPendingKeyExchangeRatchetKey())
|
||||
.setOurIdentityKey(sessionRecord.getSessionState().getPendingKeyExchangeIdentityKey())
|
||||
.setTheirBaseKey(message.getBaseKey())
|
||||
.setTheirRatchetKey(message.getRatchetKey())
|
||||
.setTheirIdentityKey(message.getIdentityKey());
|
||||
|
||||
if (!sessionRecord.isFresh()) sessionRecord.archiveCurrentState();
|
||||
|
||||
RatchetingSession.initializeSession(sessionRecord.getSessionState(),
|
||||
Math.min(message.getMaxVersion(), CiphertextMessage.CURRENT_VERSION),
|
||||
parameters.create());
|
||||
|
||||
if (sessionRecord.getSessionState().getSessionVersion() >= 3 &&
|
||||
!Curve.verifySignature(message.getIdentityKey().getPublicKey(),
|
||||
message.getBaseKey().serialize(),
|
||||
message.getBaseKeySignature()))
|
||||
{
|
||||
throw new InvalidKeyException("Base key signature doesn't match!");
|
||||
}
|
||||
|
||||
sessionStore.storeSession(remoteAddress, sessionRecord);
|
||||
identityKeyStore.saveIdentity(remoteAddress.getName(), message.getIdentityKey());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiate a new session by sending an initial KeyExchangeMessage to the recipient.
|
||||
*
|
||||
* @return the KeyExchangeMessage to deliver.
|
||||
*/
|
||||
public KeyExchangeMessage process() {
|
||||
synchronized (SessionCipher.SESSION_LOCK) {
|
||||
try {
|
||||
int sequence = KeyHelper.getRandomSequence(65534) + 1;
|
||||
int flags = KeyExchangeMessage.INITIATE_FLAG;
|
||||
ECKeyPair baseKey = Curve.generateKeyPair();
|
||||
ECKeyPair ratchetKey = Curve.generateKeyPair();
|
||||
IdentityKeyPair identityKey = identityKeyStore.getIdentityKeyPair();
|
||||
byte[] baseKeySignature = Curve.calculateSignature(identityKey.getPrivateKey(), baseKey.getPublicKey().serialize());
|
||||
SessionRecord sessionRecord = sessionStore.loadSession(remoteAddress);
|
||||
|
||||
sessionRecord.getSessionState().setPendingKeyExchange(sequence, baseKey, ratchetKey, identityKey);
|
||||
sessionStore.storeSession(remoteAddress, sessionRecord);
|
||||
|
||||
return new KeyExchangeMessage(2, sequence, flags, baseKey.getPublicKey(), baseKeySignature,
|
||||
ratchetKey.getPublicKey(), identityKey.getPublicKey());
|
||||
} catch (InvalidKeyException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -1,4 +0,0 @@
|
||||
package org.whispersystems.libaxolotl;
|
||||
|
||||
public class StaleKeyExchangeException extends Throwable {
|
||||
}
|
||||
@ -1,41 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2013 Open Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.whispersystems.libaxolotl.ecc;
|
||||
|
||||
public class DjbECPrivateKey implements ECPrivateKey {
|
||||
|
||||
private final byte[] privateKey;
|
||||
|
||||
DjbECPrivateKey(byte[] privateKey) {
|
||||
this.privateKey = privateKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] serialize() {
|
||||
return privateKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return Curve.DJB_TYPE;
|
||||
}
|
||||
|
||||
public byte[] getPrivateKey() {
|
||||
return privateKey;
|
||||
}
|
||||
}
|
||||
@ -1,37 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2013 Open Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.whispersystems.libaxolotl.ecc;
|
||||
|
||||
public class ECKeyPair {
|
||||
|
||||
private final ECPublicKey publicKey;
|
||||
private final ECPrivateKey privateKey;
|
||||
|
||||
public ECKeyPair(ECPublicKey publicKey, ECPrivateKey privateKey) {
|
||||
this.publicKey = publicKey;
|
||||
this.privateKey = privateKey;
|
||||
}
|
||||
|
||||
public ECPublicKey getPublicKey() {
|
||||
return publicKey;
|
||||
}
|
||||
|
||||
public ECPrivateKey getPrivateKey() {
|
||||
return privateKey;
|
||||
}
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2013 Open Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.whispersystems.libaxolotl.ecc;
|
||||
|
||||
public interface ECPrivateKey {
|
||||
public byte[] serialize();
|
||||
public int getType();
|
||||
}
|
||||
@ -1,27 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2013 Open Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.whispersystems.libaxolotl.ecc;
|
||||
|
||||
public interface ECPublicKey extends Comparable<ECPublicKey> {
|
||||
|
||||
public static final int KEY_SIZE = 33;
|
||||
|
||||
public byte[] serialize();
|
||||
|
||||
public int getType();
|
||||
}
|
||||
@ -1,20 +0,0 @@
|
||||
package org.whispersystems.libaxolotl.fingerprint;
|
||||
|
||||
public class DisplayableFingerprint {
|
||||
|
||||
private final String localFingerprint;
|
||||
private final String remoteFingerprint;
|
||||
|
||||
public DisplayableFingerprint(String localFingerprint, String remoteFingerprint) {
|
||||
this.localFingerprint = localFingerprint;
|
||||
this.remoteFingerprint = remoteFingerprint;
|
||||
}
|
||||
|
||||
public String getDisplayText() {
|
||||
if (localFingerprint.compareTo(remoteFingerprint) <= 0) {
|
||||
return localFingerprint + remoteFingerprint;
|
||||
} else {
|
||||
return remoteFingerprint + localFingerprint;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,8 +0,0 @@
|
||||
package org.whispersystems.libaxolotl.fingerprint;
|
||||
|
||||
import org.whispersystems.libaxolotl.IdentityKey;
|
||||
|
||||
public interface FingerprintGenerator {
|
||||
public Fingerprint createFor(String localStableIdentifier, IdentityKey localIdentityKey,
|
||||
String remoteStableIdentifier, IdentityKey remoteIdentityKey);
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,12 +0,0 @@
|
||||
package org.whispersystems.libaxolotl.fingerprint;
|
||||
|
||||
public class FingerprintVersionMismatchException extends Exception {
|
||||
|
||||
public FingerprintVersionMismatchException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public FingerprintVersionMismatchException(Exception e) {
|
||||
super(e);
|
||||
}
|
||||
}
|
||||
@ -1,82 +0,0 @@
|
||||
package org.whispersystems.libaxolotl.fingerprint;
|
||||
|
||||
import org.whispersystems.libaxolotl.IdentityKey;
|
||||
import org.whispersystems.libaxolotl.util.ByteUtil;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
public class NumericFingerprintGenerator implements FingerprintGenerator {
|
||||
|
||||
private static final int VERSION = 0;
|
||||
|
||||
private final long iterations;
|
||||
|
||||
/**
|
||||
* Construct a fingerprint generator for 60 digit numerics.
|
||||
*
|
||||
* @param iterations The number of internal iterations to perform in the process of
|
||||
* generating a fingerprint. This needs to be constant, and synchronized
|
||||
* across all clients.
|
||||
*
|
||||
* The higher the iteration count, the higher the security level:
|
||||
*
|
||||
* - 1024 ~ 109.7 bits
|
||||
* - 1400 > 110 bits
|
||||
* - 5200 > 112 bits
|
||||
*/
|
||||
public NumericFingerprintGenerator(long iterations) {
|
||||
this.iterations = iterations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a scannable and displayble fingerprint.
|
||||
*
|
||||
* @param localStableIdentifier The client's "stable" identifier.
|
||||
* @param localIdentityKey The client's identity key.
|
||||
* @param remoteStableIdentifier The remote party's "stable" identifier.
|
||||
* @param remoteIdentityKey The remote party's identity key.
|
||||
* @return A unique fingerprint for this conversation.
|
||||
*/
|
||||
@Override
|
||||
public Fingerprint createFor(String localStableIdentifier, IdentityKey localIdentityKey,
|
||||
String remoteStableIdentifier, IdentityKey remoteIdentityKey)
|
||||
{
|
||||
DisplayableFingerprint displayableFingerprint = new DisplayableFingerprint(getDisplayStringFor(localStableIdentifier, localIdentityKey),
|
||||
getDisplayStringFor(remoteStableIdentifier, remoteIdentityKey));
|
||||
|
||||
ScannableFingerprint scannableFingerprint = new ScannableFingerprint(VERSION,
|
||||
localStableIdentifier, localIdentityKey,
|
||||
remoteStableIdentifier, remoteIdentityKey);
|
||||
|
||||
return new Fingerprint(displayableFingerprint, scannableFingerprint);
|
||||
}
|
||||
|
||||
private String getDisplayStringFor(String stableIdentifier, IdentityKey identityKey) {
|
||||
try {
|
||||
MessageDigest digest = MessageDigest.getInstance("SHA-512");
|
||||
byte[] hash = ByteUtil.combine(ByteUtil.shortToByteArray(VERSION),
|
||||
identityKey.getPublicKey().serialize(),
|
||||
stableIdentifier.getBytes());
|
||||
|
||||
for (int i=0;i<iterations;i++) {
|
||||
hash = digest.digest(hash);
|
||||
}
|
||||
|
||||
return getEncodedChunk(hash, 0) +
|
||||
getEncodedChunk(hash, 5) +
|
||||
getEncodedChunk(hash, 10) +
|
||||
getEncodedChunk(hash, 15) +
|
||||
getEncodedChunk(hash, 20) +
|
||||
getEncodedChunk(hash, 25);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
private String getEncodedChunk(byte[] hash, int offset) {
|
||||
long chunk = ByteUtil.byteArray5ToLong(hash, offset) % 100000;
|
||||
return String.format("%05d", chunk);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,73 +0,0 @@
|
||||
package org.whispersystems.libaxolotl.fingerprint;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
|
||||
import org.whispersystems.libaxolotl.IdentityKey;
|
||||
import org.whispersystems.libaxolotl.fingerprint.FingerprintProtos.CombinedFingerprint;
|
||||
import org.whispersystems.libaxolotl.fingerprint.FingerprintProtos.FingerprintData;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
|
||||
public class ScannableFingerprint {
|
||||
|
||||
private final CombinedFingerprint combinedFingerprint;
|
||||
|
||||
public ScannableFingerprint(int version,
|
||||
String localStableIdentifier, IdentityKey localIdentityKey,
|
||||
String remoteStableIdentifier, IdentityKey remoteIdentityKey)
|
||||
{
|
||||
this.combinedFingerprint = CombinedFingerprint.newBuilder()
|
||||
.setVersion(version)
|
||||
.setLocalFingerprint(FingerprintData.newBuilder()
|
||||
.setIdentifier(ByteString.copyFrom(localStableIdentifier.getBytes()))
|
||||
.setPublicKey(ByteString.copyFrom(localIdentityKey.serialize())))
|
||||
.setRemoteFingerprint(FingerprintData.newBuilder()
|
||||
.setIdentifier(ByteString.copyFrom(remoteStableIdentifier.getBytes()))
|
||||
.setPublicKey(ByteString.copyFrom(remoteIdentityKey.serialize())))
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A byte string to be displayed in a QR code.
|
||||
*/
|
||||
public byte[] getSerialized() {
|
||||
return combinedFingerprint.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare a scanned QR code with what we expect.
|
||||
*
|
||||
* @param scannedFingerprintData The scanned data
|
||||
* @return True if matching, otehrwise false.
|
||||
* @throws FingerprintVersionMismatchException if the scanned fingerprint is the wrong version.
|
||||
* @throws FingerprintIdentifierMismatchException if the scanned fingerprint is for the wrong stable identifier.
|
||||
*/
|
||||
public boolean compareTo(byte[] scannedFingerprintData)
|
||||
throws FingerprintVersionMismatchException, FingerprintIdentifierMismatchException
|
||||
{
|
||||
try {
|
||||
CombinedFingerprint scannedFingerprint = CombinedFingerprint.parseFrom(scannedFingerprintData);
|
||||
|
||||
if (!scannedFingerprint.hasRemoteFingerprint() || !scannedFingerprint.hasLocalFingerprint() ||
|
||||
!scannedFingerprint.hasVersion() || scannedFingerprint.getVersion() != combinedFingerprint.getVersion())
|
||||
{
|
||||
throw new FingerprintVersionMismatchException();
|
||||
}
|
||||
|
||||
if (!combinedFingerprint.getLocalFingerprint().getIdentifier().equals(scannedFingerprint.getRemoteFingerprint().getIdentifier()) ||
|
||||
!combinedFingerprint.getRemoteFingerprint().getIdentifier().equals(scannedFingerprint.getLocalFingerprint().getIdentifier()))
|
||||
{
|
||||
throw new FingerprintIdentifierMismatchException(combinedFingerprint.getLocalFingerprint().getIdentifier().toString(),
|
||||
combinedFingerprint.getRemoteFingerprint().getIdentifier().toString(),
|
||||
scannedFingerprint.getLocalFingerprint().getIdentifier().toString(),
|
||||
scannedFingerprint.getRemoteFingerprint().getIdentifier().toString());
|
||||
}
|
||||
|
||||
return MessageDigest.isEqual(combinedFingerprint.getLocalFingerprint().toByteArray(), scannedFingerprint.getRemoteFingerprint().toByteArray()) &&
|
||||
MessageDigest.isEqual(combinedFingerprint.getRemoteFingerprint().toByteArray(), scannedFingerprint.getLocalFingerprint().toByteArray());
|
||||
} catch (InvalidProtocolBufferException e) {
|
||||
throw new FingerprintVersionMismatchException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,63 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2014-2015 Open Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.whispersystems.libaxolotl.groups;
|
||||
|
||||
import org.whispersystems.libaxolotl.AxolotlAddress;
|
||||
|
||||
/**
|
||||
* A representation of a (groupId + senderId + deviceId) tuple.
|
||||
*/
|
||||
public class SenderKeyName {
|
||||
|
||||
private final String groupId;
|
||||
private final AxolotlAddress sender;
|
||||
|
||||
public SenderKeyName(String groupId, AxolotlAddress sender) {
|
||||
this.groupId = groupId;
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
public String getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
public AxolotlAddress getSender() {
|
||||
return sender;
|
||||
}
|
||||
|
||||
public String serialize() {
|
||||
return groupId + "::" + sender.getName() + "::" + String.valueOf(sender.getDeviceId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (other == null) return false;
|
||||
if (!(other instanceof SenderKeyName)) return false;
|
||||
|
||||
SenderKeyName that = (SenderKeyName)other;
|
||||
|
||||
return
|
||||
this.groupId.equals(that.groupId) &&
|
||||
this.sender.equals(that.sender);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.groupId.hashCode() ^ this.sender.hashCode();
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,8 +0,0 @@
|
||||
package org.whispersystems.libaxolotl.kdf;
|
||||
|
||||
public class HKDFv2 extends HKDF {
|
||||
@Override
|
||||
protected int getIterationStartOffset() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -1,8 +0,0 @@
|
||||
package org.whispersystems.libaxolotl.kdf;
|
||||
|
||||
public class HKDFv3 extends HKDF {
|
||||
@Override
|
||||
protected int getIterationStartOffset() {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@ -1,14 +0,0 @@
|
||||
package org.whispersystems.libaxolotl.logging;
|
||||
|
||||
public class AxolotlLoggerProvider {
|
||||
|
||||
private static AxolotlLogger provider;
|
||||
|
||||
public static AxolotlLogger getProvider() {
|
||||
return provider;
|
||||
}
|
||||
|
||||
public static void setProvider(AxolotlLogger provider) {
|
||||
AxolotlLoggerProvider.provider = provider;
|
||||
}
|
||||
}
|
||||
@ -1,35 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2014 Open Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.whispersystems.libaxolotl.protocol;
|
||||
|
||||
public interface CiphertextMessage {
|
||||
|
||||
public static final int UNSUPPORTED_VERSION = 1;
|
||||
public static final int CURRENT_VERSION = 3;
|
||||
|
||||
public static final int WHISPER_TYPE = 2;
|
||||
public static final int PREKEY_TYPE = 3;
|
||||
public static final int SENDERKEY_TYPE = 4;
|
||||
public static final int SENDERKEY_DISTRIBUTION_TYPE = 5;
|
||||
|
||||
// This should be the worst case (worse than V2). So not always accurate, but good enough for padding.
|
||||
public static final int ENCRYPTED_MESSAGE_OVERHEAD = 53;
|
||||
|
||||
public byte[] serialize();
|
||||
public int getType();
|
||||
|
||||
}
|
||||
@ -1,153 +0,0 @@
|
||||
package org.whispersystems.libaxolotl.protocol;
|
||||
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
|
||||
import org.whispersystems.libaxolotl.IdentityKey;
|
||||
import org.whispersystems.libaxolotl.InvalidKeyException;
|
||||
import org.whispersystems.libaxolotl.InvalidMessageException;
|
||||
import org.whispersystems.libaxolotl.InvalidVersionException;
|
||||
import org.whispersystems.libaxolotl.LegacyMessageException;
|
||||
import org.whispersystems.libaxolotl.ecc.Curve;
|
||||
import org.whispersystems.libaxolotl.ecc.ECPublicKey;
|
||||
import org.whispersystems.libaxolotl.util.ByteUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.whispersystems.libaxolotl.protocol.WhisperProtos.KeyExchangeMessage.Builder;
|
||||
|
||||
public class KeyExchangeMessage {
|
||||
|
||||
public static final int INITIATE_FLAG = 0x01;
|
||||
public static final int RESPONSE_FLAG = 0X02;
|
||||
public static final int SIMULTAENOUS_INITIATE_FLAG = 0x04;
|
||||
|
||||
private final int version;
|
||||
private final int supportedVersion;
|
||||
private final int sequence;
|
||||
private final int flags;
|
||||
|
||||
private final ECPublicKey baseKey;
|
||||
private final byte[] baseKeySignature;
|
||||
private final ECPublicKey ratchetKey;
|
||||
private final IdentityKey identityKey;
|
||||
private final byte[] serialized;
|
||||
|
||||
public KeyExchangeMessage(int messageVersion, int sequence, int flags,
|
||||
ECPublicKey baseKey, byte[] baseKeySignature,
|
||||
ECPublicKey ratchetKey,
|
||||
IdentityKey identityKey)
|
||||
{
|
||||
this.supportedVersion = CiphertextMessage.CURRENT_VERSION;
|
||||
this.version = messageVersion;
|
||||
this.sequence = sequence;
|
||||
this.flags = flags;
|
||||
this.baseKey = baseKey;
|
||||
this.baseKeySignature = baseKeySignature;
|
||||
this.ratchetKey = ratchetKey;
|
||||
this.identityKey = identityKey;
|
||||
|
||||
byte[] version = {ByteUtil.intsToByteHighAndLow(this.version, this.supportedVersion)};
|
||||
Builder builder = WhisperProtos.KeyExchangeMessage
|
||||
.newBuilder()
|
||||
.setId((sequence << 5) | flags)
|
||||
.setBaseKey(ByteString.copyFrom(baseKey.serialize()))
|
||||
.setRatchetKey(ByteString.copyFrom(ratchetKey.serialize()))
|
||||
.setIdentityKey(ByteString.copyFrom(identityKey.serialize()));
|
||||
|
||||
if (messageVersion >= 3) {
|
||||
builder.setBaseKeySignature(ByteString.copyFrom(baseKeySignature));
|
||||
}
|
||||
|
||||
this.serialized = ByteUtil.combine(version, builder.build().toByteArray());
|
||||
}
|
||||
|
||||
public KeyExchangeMessage(byte[] serialized)
|
||||
throws InvalidMessageException, InvalidVersionException, LegacyMessageException
|
||||
{
|
||||
try {
|
||||
byte[][] parts = ByteUtil.split(serialized, 1, serialized.length - 1);
|
||||
this.version = ByteUtil.highBitsToInt(parts[0][0]);
|
||||
this.supportedVersion = ByteUtil.lowBitsToInt(parts[0][0]);
|
||||
|
||||
if (this.version <= CiphertextMessage.UNSUPPORTED_VERSION) {
|
||||
throw new LegacyMessageException("Unsupported legacy version: " + this.version);
|
||||
}
|
||||
|
||||
if (this.version > CiphertextMessage.CURRENT_VERSION) {
|
||||
throw new InvalidVersionException("Unknown version: " + this.version);
|
||||
}
|
||||
|
||||
WhisperProtos.KeyExchangeMessage message = WhisperProtos.KeyExchangeMessage.parseFrom(parts[1]);
|
||||
|
||||
if (!message.hasId() || !message.hasBaseKey() ||
|
||||
!message.hasRatchetKey() || !message.hasIdentityKey() ||
|
||||
(this.version >=3 && !message.hasBaseKeySignature()))
|
||||
{
|
||||
throw new InvalidMessageException("Some required fields missing!");
|
||||
}
|
||||
|
||||
this.sequence = message.getId() >> 5;
|
||||
this.flags = message.getId() & 0x1f;
|
||||
this.serialized = serialized;
|
||||
this.baseKey = Curve.decodePoint(message.getBaseKey().toByteArray(), 0);
|
||||
this.baseKeySignature = message.getBaseKeySignature().toByteArray();
|
||||
this.ratchetKey = Curve.decodePoint(message.getRatchetKey().toByteArray(), 0);
|
||||
this.identityKey = new IdentityKey(message.getIdentityKey().toByteArray(), 0);
|
||||
} catch (InvalidKeyException | IOException e) {
|
||||
throw new InvalidMessageException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public int getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public ECPublicKey getBaseKey() {
|
||||
return baseKey;
|
||||
}
|
||||
|
||||
public byte[] getBaseKeySignature() {
|
||||
return baseKeySignature;
|
||||
}
|
||||
|
||||
public ECPublicKey getRatchetKey() {
|
||||
return ratchetKey;
|
||||
}
|
||||
|
||||
public IdentityKey getIdentityKey() {
|
||||
return identityKey;
|
||||
}
|
||||
|
||||
public boolean hasIdentityKey() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public int getMaxVersion() {
|
||||
return supportedVersion;
|
||||
}
|
||||
|
||||
public boolean isResponse() {
|
||||
return ((flags & RESPONSE_FLAG) != 0);
|
||||
}
|
||||
|
||||
public boolean isInitiate() {
|
||||
return (flags & INITIATE_FLAG) != 0;
|
||||
}
|
||||
|
||||
public boolean isResponseForSimultaneousInitiate() {
|
||||
return (flags & SIMULTAENOUS_INITIATE_FLAG) != 0;
|
||||
}
|
||||
|
||||
public int getFlags() {
|
||||
return flags;
|
||||
}
|
||||
|
||||
public int getSequence() {
|
||||
return sequence;
|
||||
}
|
||||
|
||||
public byte[] serialize() {
|
||||
return serialized;
|
||||
}
|
||||
}
|
||||
@ -1,147 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2014 Open Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.whispersystems.libaxolotl.protocol;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
|
||||
import org.whispersystems.libaxolotl.IdentityKey;
|
||||
import org.whispersystems.libaxolotl.InvalidKeyException;
|
||||
import org.whispersystems.libaxolotl.InvalidMessageException;
|
||||
import org.whispersystems.libaxolotl.InvalidVersionException;
|
||||
import org.whispersystems.libaxolotl.LegacyMessageException;
|
||||
import org.whispersystems.libaxolotl.ecc.Curve;
|
||||
import org.whispersystems.libaxolotl.ecc.ECPublicKey;
|
||||
import org.whispersystems.libaxolotl.util.ByteUtil;
|
||||
import org.whispersystems.libaxolotl.util.guava.Optional;
|
||||
|
||||
|
||||
public class PreKeyWhisperMessage implements CiphertextMessage {
|
||||
|
||||
private final int version;
|
||||
private final int registrationId;
|
||||
private final Optional<Integer> preKeyId;
|
||||
private final int signedPreKeyId;
|
||||
private final ECPublicKey baseKey;
|
||||
private final IdentityKey identityKey;
|
||||
private final WhisperMessage message;
|
||||
private final byte[] serialized;
|
||||
|
||||
public PreKeyWhisperMessage(byte[] serialized)
|
||||
throws InvalidMessageException, InvalidVersionException
|
||||
{
|
||||
try {
|
||||
this.version = ByteUtil.highBitsToInt(serialized[0]);
|
||||
|
||||
if (this.version > CiphertextMessage.CURRENT_VERSION) {
|
||||
throw new InvalidVersionException("Unknown version: " + this.version);
|
||||
}
|
||||
|
||||
WhisperProtos.PreKeyWhisperMessage preKeyWhisperMessage
|
||||
= WhisperProtos.PreKeyWhisperMessage.parseFrom(ByteString.copyFrom(serialized, 1,
|
||||
serialized.length-1));
|
||||
|
||||
if ((version == 2 && !preKeyWhisperMessage.hasPreKeyId()) ||
|
||||
(version == 3 && !preKeyWhisperMessage.hasSignedPreKeyId()) ||
|
||||
!preKeyWhisperMessage.hasBaseKey() ||
|
||||
!preKeyWhisperMessage.hasIdentityKey() ||
|
||||
!preKeyWhisperMessage.hasMessage())
|
||||
{
|
||||
throw new InvalidMessageException("Incomplete message.");
|
||||
}
|
||||
|
||||
this.serialized = serialized;
|
||||
this.registrationId = preKeyWhisperMessage.getRegistrationId();
|
||||
this.preKeyId = preKeyWhisperMessage.hasPreKeyId() ? Optional.of(preKeyWhisperMessage.getPreKeyId()) : Optional.<Integer>absent();
|
||||
this.signedPreKeyId = preKeyWhisperMessage.hasSignedPreKeyId() ? preKeyWhisperMessage.getSignedPreKeyId() : -1;
|
||||
this.baseKey = Curve.decodePoint(preKeyWhisperMessage.getBaseKey().toByteArray(), 0);
|
||||
this.identityKey = new IdentityKey(Curve.decodePoint(preKeyWhisperMessage.getIdentityKey().toByteArray(), 0));
|
||||
this.message = new WhisperMessage(preKeyWhisperMessage.getMessage().toByteArray());
|
||||
} catch (InvalidProtocolBufferException | InvalidKeyException | LegacyMessageException e) {
|
||||
throw new InvalidMessageException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public PreKeyWhisperMessage(int messageVersion, int registrationId, Optional<Integer> preKeyId,
|
||||
int signedPreKeyId, ECPublicKey baseKey, IdentityKey identityKey,
|
||||
WhisperMessage message)
|
||||
{
|
||||
this.version = messageVersion;
|
||||
this.registrationId = registrationId;
|
||||
this.preKeyId = preKeyId;
|
||||
this.signedPreKeyId = signedPreKeyId;
|
||||
this.baseKey = baseKey;
|
||||
this.identityKey = identityKey;
|
||||
this.message = message;
|
||||
|
||||
WhisperProtos.PreKeyWhisperMessage.Builder builder =
|
||||
WhisperProtos.PreKeyWhisperMessage.newBuilder()
|
||||
.setSignedPreKeyId(signedPreKeyId)
|
||||
.setBaseKey(ByteString.copyFrom(baseKey.serialize()))
|
||||
.setIdentityKey(ByteString.copyFrom(identityKey.serialize()))
|
||||
.setMessage(ByteString.copyFrom(message.serialize()))
|
||||
.setRegistrationId(registrationId);
|
||||
|
||||
if (preKeyId.isPresent()) {
|
||||
builder.setPreKeyId(preKeyId.get());
|
||||
}
|
||||
|
||||
byte[] versionBytes = {ByteUtil.intsToByteHighAndLow(this.version, CURRENT_VERSION)};
|
||||
byte[] messageBytes = builder.build().toByteArray();
|
||||
|
||||
this.serialized = ByteUtil.combine(versionBytes, messageBytes);
|
||||
}
|
||||
|
||||
public int getMessageVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public IdentityKey getIdentityKey() {
|
||||
return identityKey;
|
||||
}
|
||||
|
||||
public int getRegistrationId() {
|
||||
return registrationId;
|
||||
}
|
||||
|
||||
public Optional<Integer> getPreKeyId() {
|
||||
return preKeyId;
|
||||
}
|
||||
|
||||
public int getSignedPreKeyId() {
|
||||
return signedPreKeyId;
|
||||
}
|
||||
|
||||
public ECPublicKey getBaseKey() {
|
||||
return baseKey;
|
||||
}
|
||||
|
||||
public WhisperMessage getWhisperMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] serialize() {
|
||||
return serialized;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return CiphertextMessage.PREKEY_TYPE;
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,54 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2014 Open Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.whispersystems.libaxolotl.ratchet;
|
||||
|
||||
import org.whispersystems.libaxolotl.InvalidKeyException;
|
||||
import org.whispersystems.libaxolotl.ecc.Curve;
|
||||
import org.whispersystems.libaxolotl.ecc.ECKeyPair;
|
||||
import org.whispersystems.libaxolotl.ecc.ECPublicKey;
|
||||
import org.whispersystems.libaxolotl.kdf.DerivedRootSecrets;
|
||||
import org.whispersystems.libaxolotl.kdf.HKDF;
|
||||
import org.whispersystems.libaxolotl.util.ByteUtil;
|
||||
import org.whispersystems.libaxolotl.util.Pair;
|
||||
|
||||
public class RootKey {
|
||||
|
||||
private final HKDF kdf;
|
||||
private final byte[] key;
|
||||
|
||||
public RootKey(HKDF kdf, byte[] key) {
|
||||
this.kdf = kdf;
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public byte[] getKeyBytes() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public Pair<RootKey, ChainKey> createChain(ECPublicKey theirRatchetKey, ECKeyPair ourRatchetKey)
|
||||
throws InvalidKeyException
|
||||
{
|
||||
byte[] sharedSecret = Curve.calculateAgreement(theirRatchetKey, ourRatchetKey.getPrivateKey());
|
||||
byte[] derivedSecretBytes = kdf.deriveSecrets(sharedSecret, key, "WhisperRatchet".getBytes(), DerivedRootSecrets.SIZE);
|
||||
DerivedRootSecrets derivedSecrets = new DerivedRootSecrets(derivedSecretBytes);
|
||||
|
||||
RootKey newRootKey = new RootKey(kdf, derivedSecrets.getRootKey());
|
||||
ChainKey newChainKey = new ChainKey(kdf, derivedSecrets.getChainKey(), 0);
|
||||
|
||||
return new Pair<>(newRootKey, newChainKey);
|
||||
}
|
||||
}
|
||||
@ -1,6 +0,0 @@
|
||||
package org.whispersystems.libaxolotl.state;
|
||||
|
||||
public interface AxolotlStore
|
||||
extends IdentityKeyStore, PreKeyStore, SessionStore, SignedPreKeyStore
|
||||
{
|
||||
}
|
||||
@ -1,57 +0,0 @@
|
||||
package org.whispersystems.libaxolotl.state;
|
||||
|
||||
import org.whispersystems.libaxolotl.IdentityKey;
|
||||
import org.whispersystems.libaxolotl.IdentityKeyPair;
|
||||
|
||||
/**
|
||||
* Provides an interface to identity information.
|
||||
*
|
||||
* @author Moxie Marlinspike
|
||||
*/
|
||||
public interface IdentityKeyStore {
|
||||
|
||||
/**
|
||||
* Get the local client's identity key pair.
|
||||
*
|
||||
* @return The local client's persistent identity key pair.
|
||||
*/
|
||||
public IdentityKeyPair getIdentityKeyPair();
|
||||
|
||||
/**
|
||||
* Return the local client's registration ID.
|
||||
* <p>
|
||||
* Clients should maintain a registration ID, a random number
|
||||
* between 1 and 16380 that's generated once at install time.
|
||||
*
|
||||
* @return the local client's registration ID.
|
||||
*/
|
||||
public int getLocalRegistrationId();
|
||||
|
||||
/**
|
||||
* Save a remote client's identity key
|
||||
* <p>
|
||||
* Store a remote client's identity key as trusted.
|
||||
*
|
||||
* @param name The name of the remote client.
|
||||
* @param identityKey The remote client's identity key.
|
||||
*/
|
||||
public void saveIdentity(String name, IdentityKey identityKey);
|
||||
|
||||
|
||||
/**
|
||||
* Verify a remote client's identity key.
|
||||
* <p>
|
||||
* Determine whether a remote client's identity is trusted. Convention is
|
||||
* that the TextSecure protocol is 'trust on first use.' This means that
|
||||
* an identity key is considered 'trusted' if there is no entry for the recipient
|
||||
* in the local store, or if it matches the saved key for a recipient in the local
|
||||
* store. Only if it mismatches an entry in the local store is it considered
|
||||
* 'untrusted.'
|
||||
*
|
||||
* @param name The name of the remote client.
|
||||
* @param identityKey The identity key to verify.
|
||||
* @return true if trusted, false if untrusted.
|
||||
*/
|
||||
public boolean isTrustedIdentity(String name, IdentityKey identityKey);
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,46 +0,0 @@
|
||||
package org.whispersystems.libaxolotl.state.impl;
|
||||
|
||||
import org.whispersystems.libaxolotl.IdentityKey;
|
||||
import org.whispersystems.libaxolotl.IdentityKeyPair;
|
||||
import org.whispersystems.libaxolotl.ecc.Curve;
|
||||
import org.whispersystems.libaxolotl.ecc.ECKeyPair;
|
||||
import org.whispersystems.libaxolotl.state.IdentityKeyStore;
|
||||
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class InMemoryIdentityKeyStore implements IdentityKeyStore {
|
||||
|
||||
private final Map<String, IdentityKey> trustedKeys = new HashMap<>();
|
||||
|
||||
private final IdentityKeyPair identityKeyPair;
|
||||
private final int localRegistrationId;
|
||||
|
||||
public InMemoryIdentityKeyStore(IdentityKeyPair identityKeyPair, int localRegistrationId) {
|
||||
this.identityKeyPair = identityKeyPair;
|
||||
this.localRegistrationId = localRegistrationId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentityKeyPair getIdentityKeyPair() {
|
||||
return identityKeyPair;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLocalRegistrationId() {
|
||||
return localRegistrationId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveIdentity(String name, IdentityKey identityKey) {
|
||||
trustedKeys.put(name, identityKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTrustedIdentity(String name, IdentityKey identityKey) {
|
||||
IdentityKey trusted = trustedKeys.get(name);
|
||||
return (trusted == null || trusted.equals(identityKey));
|
||||
}
|
||||
}
|
||||
@ -1,5 +0,0 @@
|
||||
package org.whispersystems.libaxolotl.util;
|
||||
|
||||
public class Medium {
|
||||
public static int MAX_VALUE = 0xFFFFFF;
|
||||
}
|
||||
@ -1,51 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2014 Open WhisperSystems
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.whispersystems.libaxolotl.util;
|
||||
|
||||
public class Pair<T1, T2> {
|
||||
private final T1 v1;
|
||||
private final T2 v2;
|
||||
|
||||
public Pair(T1 v1, T2 v2) {
|
||||
this.v1 = v1;
|
||||
this.v2 = v2;
|
||||
}
|
||||
|
||||
public T1 first(){
|
||||
return v1;
|
||||
}
|
||||
|
||||
public T2 second(){
|
||||
return v2;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof Pair &&
|
||||
equal(((Pair) o).first(), first()) &&
|
||||
equal(((Pair) o).second(), second());
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return first().hashCode() ^ second().hashCode();
|
||||
}
|
||||
|
||||
private boolean equal(Object first, Object second) {
|
||||
if (first == null && second == null) return true;
|
||||
if (first == null || second == null) return false;
|
||||
return first.equals(second);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
/**
|
||||
* Copyright (C) 2014-2016 Open Whisper Systems
|
||||
*
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
package org.whispersystems.libsignal;
|
||||
|
||||
public interface DecryptionCallback {
|
||||
public void handlePlaintext(byte[] plaintext);
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Copyright (C) 2014-2016 Open Whisper Systems
|
||||
*
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
package org.whispersystems.libsignal;
|
||||
|
||||
public class DuplicateMessageException extends Exception {
|
||||
public DuplicateMessageException(String s) {
|
||||
super(s);
|
||||
}
|
||||
}
|
||||
@ -1,25 +1,14 @@
|
||||
/**
|
||||
* Copyright (C) 2014 Open Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
/**
|
||||
* Copyright (C) 2014-2016 Open Whisper Systems
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
package org.whispersystems.libaxolotl;
|
||||
package org.whispersystems.libsignal;
|
||||
|
||||
|
||||
import org.whispersystems.libaxolotl.ecc.Curve;
|
||||
import org.whispersystems.libaxolotl.ecc.ECPublicKey;
|
||||
import org.whispersystems.libaxolotl.util.Hex;
|
||||
import org.whispersystems.libsignal.ecc.Curve;
|
||||
import org.whispersystems.libsignal.ecc.ECPublicKey;
|
||||
import org.whispersystems.libsignal.util.Hex;
|
||||
|
||||
/**
|
||||
* A class for representing an identity key.
|
||||
@ -1,28 +1,17 @@
|
||||
/**
|
||||
* Copyright (C) 2013 Open Whisper Systems
|
||||
* Copyright (C) 2014-2016 Open Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
package org.whispersystems.libaxolotl;
|
||||
package org.whispersystems.libsignal;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
|
||||
import org.whispersystems.libaxolotl.ecc.Curve;
|
||||
import org.whispersystems.libaxolotl.ecc.ECPrivateKey;
|
||||
import org.whispersystems.libsignal.ecc.Curve;
|
||||
import org.whispersystems.libsignal.ecc.ECPrivateKey;
|
||||
|
||||
import static org.whispersystems.libaxolotl.state.StorageProtos.IdentityKeyPairStructure;
|
||||
import static org.whispersystems.libsignal.state.StorageProtos.IdentityKeyPairStructure;
|
||||
|
||||
/**
|
||||
* Holder for public and private identity key pair.
|
||||
@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Copyright (C) 2014-2016 Open Whisper Systems
|
||||
*
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
package org.whispersystems.libsignal;
|
||||
|
||||
public class InvalidKeyException extends Exception {
|
||||
|
||||
public InvalidKeyException() {}
|
||||
|
||||
public InvalidKeyException(String detailMessage) {
|
||||
super(detailMessage);
|
||||
}
|
||||
|
||||
public InvalidKeyException(Throwable throwable) {
|
||||
super(throwable);
|
||||
}
|
||||
|
||||
public InvalidKeyException(String detailMessage, Throwable throwable) {
|
||||
super(detailMessage, throwable);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
/**
|
||||
* Copyright (C) 2014-2016 Open Whisper Systems
|
||||
*
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
package org.whispersystems.libsignal;
|
||||
|
||||
public class InvalidKeyIdException extends Exception {
|
||||
public InvalidKeyIdException(String detailMessage) {
|
||||
super(detailMessage);
|
||||
}
|
||||
|
||||
public InvalidKeyIdException(Throwable throwable) {
|
||||
super(throwable);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Copyright (C) 2014-2016 Open Whisper Systems
|
||||
*
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
package org.whispersystems.libsignal;
|
||||
|
||||
public class InvalidMacException extends Exception {
|
||||
|
||||
public InvalidMacException(String detailMessage) {
|
||||
super(detailMessage);
|
||||
}
|
||||
|
||||
public InvalidMacException(Throwable throwable) {
|
||||
super(throwable);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
/**
|
||||
* Copyright (C) 2014-2016 Open Whisper Systems
|
||||
*
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
package org.whispersystems.libsignal;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class InvalidMessageException extends Exception {
|
||||
|
||||
public InvalidMessageException() {}
|
||||
|
||||
public InvalidMessageException(String detailMessage) {
|
||||
super(detailMessage);
|
||||
}
|
||||
|
||||
public InvalidMessageException(Throwable throwable) {
|
||||
super(throwable);
|
||||
}
|
||||
|
||||
public InvalidMessageException(String detailMessage, Throwable throwable) {
|
||||
super(detailMessage, throwable);
|
||||
}
|
||||
|
||||
public InvalidMessageException(String detailMessage, List<Exception> exceptions) {
|
||||
super(detailMessage, exceptions.get(0));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Copyright (C) 2014-2016 Open Whisper Systems
|
||||
*
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
package org.whispersystems.libsignal;
|
||||
|
||||
public class InvalidVersionException extends Exception {
|
||||
public InvalidVersionException(String detailMessage) {
|
||||
super(detailMessage);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Copyright (C) 2014-2016 Open Whisper Systems
|
||||
*
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
package org.whispersystems.libsignal;
|
||||
|
||||
public class LegacyMessageException extends Exception {
|
||||
public LegacyMessageException(String s) {
|
||||
super(s);
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,9 @@
|
||||
package org.whispersystems.libaxolotl;
|
||||
/**
|
||||
* Copyright (C) 2014-2016 Open Whisper Systems
|
||||
*
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
package org.whispersystems.libsignal;
|
||||
|
||||
public class NoSessionException extends Exception {
|
||||
public NoSessionException(String s) {
|
||||
@ -0,0 +1,213 @@
|
||||
/**
|
||||
* Copyright (C) 2014-2016 Open Whisper Systems
|
||||
*
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
package org.whispersystems.libsignal;
|
||||
|
||||
|
||||
import org.whispersystems.libsignal.ecc.Curve;
|
||||
import org.whispersystems.libsignal.ecc.ECKeyPair;
|
||||
import org.whispersystems.libsignal.ecc.ECPublicKey;
|
||||
import org.whispersystems.libsignal.logging.Log;
|
||||
import org.whispersystems.libsignal.protocol.PreKeySignalMessage;
|
||||
import org.whispersystems.libsignal.protocol.SignalMessage;
|
||||
import org.whispersystems.libsignal.ratchet.AliceSignalProtocolParameters;
|
||||
import org.whispersystems.libsignal.ratchet.BobSignalProtocolParameters;
|
||||
import org.whispersystems.libsignal.ratchet.RatchetingSession;
|
||||
import org.whispersystems.libsignal.state.IdentityKeyStore;
|
||||
import org.whispersystems.libsignal.state.PreKeyBundle;
|
||||
import org.whispersystems.libsignal.state.PreKeyStore;
|
||||
import org.whispersystems.libsignal.state.SessionRecord;
|
||||
import org.whispersystems.libsignal.state.SessionStore;
|
||||
import org.whispersystems.libsignal.state.SignalProtocolStore;
|
||||
import org.whispersystems.libsignal.state.SignedPreKeyStore;
|
||||
import org.whispersystems.libsignal.util.Medium;
|
||||
import org.whispersystems.libsignal.util.guava.Optional;
|
||||
|
||||
/**
|
||||
* SessionBuilder is responsible for setting up encrypted sessions.
|
||||
* Once a session has been established, {@link org.whispersystems.libsignal.SessionCipher}
|
||||
* can be used to encrypt/decrypt messages in that session.
|
||||
* <p>
|
||||
* Sessions are built from one of three different possible vectors:
|
||||
* <ol>
|
||||
* <li>A {@link org.whispersystems.libsignal.state.PreKeyBundle} retrieved from a server.</li>
|
||||
* <li>A {@link PreKeySignalMessage} received from a client.</li>
|
||||
* </ol>
|
||||
*
|
||||
* Sessions are constructed per recipientId + deviceId tuple. Remote logical users are identified
|
||||
* by their recipientId, and each logical recipientId can have multiple physical devices.
|
||||
*
|
||||
* @author Moxie Marlinspike
|
||||
*/
|
||||
public class SessionBuilder {
|
||||
|
||||
private static final String TAG = SessionBuilder.class.getSimpleName();
|
||||
|
||||
private final SessionStore sessionStore;
|
||||
private final PreKeyStore preKeyStore;
|
||||
private final SignedPreKeyStore signedPreKeyStore;
|
||||
private final IdentityKeyStore identityKeyStore;
|
||||
private final SignalProtocolAddress remoteAddress;
|
||||
|
||||
/**
|
||||
* Constructs a SessionBuilder.
|
||||
*
|
||||
* @param sessionStore The {@link org.whispersystems.libsignal.state.SessionStore} to store the constructed session in.
|
||||
* @param preKeyStore The {@link org.whispersystems.libsignal.state.PreKeyStore} where the client's local {@link org.whispersystems.libsignal.state.PreKeyRecord}s are stored.
|
||||
* @param identityKeyStore The {@link org.whispersystems.libsignal.state.IdentityKeyStore} containing the client's identity key information.
|
||||
* @param remoteAddress The address of the remote user to build a session with.
|
||||
*/
|
||||
public SessionBuilder(SessionStore sessionStore,
|
||||
PreKeyStore preKeyStore,
|
||||
SignedPreKeyStore signedPreKeyStore,
|
||||
IdentityKeyStore identityKeyStore,
|
||||
SignalProtocolAddress remoteAddress)
|
||||
{
|
||||
this.sessionStore = sessionStore;
|
||||
this.preKeyStore = preKeyStore;
|
||||
this.signedPreKeyStore = signedPreKeyStore;
|
||||
this.identityKeyStore = identityKeyStore;
|
||||
this.remoteAddress = remoteAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a SessionBuilder
|
||||
* @param store The {@link SignalProtocolStore} to store all state information in.
|
||||
* @param remoteAddress The address of the remote user to build a session with.
|
||||
*/
|
||||
public SessionBuilder(SignalProtocolStore store, SignalProtocolAddress remoteAddress) {
|
||||
this(store, store, store, store, remoteAddress);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a new session from a received {@link PreKeySignalMessage}.
|
||||
*
|
||||
* After a session is constructed in this way, the embedded {@link SignalMessage}
|
||||
* can be decrypted.
|
||||
*
|
||||
* @param message The received {@link PreKeySignalMessage}.
|
||||
* @throws org.whispersystems.libsignal.InvalidKeyIdException when there is no local
|
||||
* {@link org.whispersystems.libsignal.state.PreKeyRecord}
|
||||
* that corresponds to the PreKey ID in
|
||||
* the message.
|
||||
* @throws org.whispersystems.libsignal.InvalidKeyException when the message is formatted incorrectly.
|
||||
* @throws org.whispersystems.libsignal.UntrustedIdentityException when the {@link IdentityKey} of the sender is untrusted.
|
||||
*/
|
||||
/*package*/ Optional<Integer> process(SessionRecord sessionRecord, PreKeySignalMessage message)
|
||||
throws InvalidKeyIdException, InvalidKeyException, UntrustedIdentityException
|
||||
{
|
||||
IdentityKey theirIdentityKey = message.getIdentityKey();
|
||||
|
||||
if (!identityKeyStore.isTrustedIdentity(remoteAddress, theirIdentityKey, IdentityKeyStore.Direction.RECEIVING)) {
|
||||
throw new UntrustedIdentityException(remoteAddress.getName(), theirIdentityKey);
|
||||
}
|
||||
|
||||
Optional<Integer> unsignedPreKeyId = processV3(sessionRecord, message);
|
||||
|
||||
identityKeyStore.saveIdentity(remoteAddress, theirIdentityKey);
|
||||
|
||||
return unsignedPreKeyId;
|
||||
}
|
||||
|
||||
private Optional<Integer> processV3(SessionRecord sessionRecord, PreKeySignalMessage message)
|
||||
throws UntrustedIdentityException, InvalidKeyIdException, InvalidKeyException
|
||||
{
|
||||
|
||||
if (sessionRecord.hasSessionState(message.getMessageVersion(), message.getBaseKey().serialize())) {
|
||||
Log.w(TAG, "We've already setup a session for this V3 message, letting bundled message fall through...");
|
||||
return Optional.absent();
|
||||
}
|
||||
|
||||
ECKeyPair ourSignedPreKey = signedPreKeyStore.loadSignedPreKey(message.getSignedPreKeyId()).getKeyPair();
|
||||
|
||||
BobSignalProtocolParameters.Builder parameters = BobSignalProtocolParameters.newBuilder();
|
||||
|
||||
parameters.setTheirBaseKey(message.getBaseKey())
|
||||
.setTheirIdentityKey(message.getIdentityKey())
|
||||
.setOurIdentityKey(identityKeyStore.getIdentityKeyPair())
|
||||
.setOurSignedPreKey(ourSignedPreKey)
|
||||
.setOurRatchetKey(ourSignedPreKey);
|
||||
|
||||
if (message.getPreKeyId().isPresent()) {
|
||||
parameters.setOurOneTimePreKey(Optional.of(preKeyStore.loadPreKey(message.getPreKeyId().get()).getKeyPair()));
|
||||
} else {
|
||||
parameters.setOurOneTimePreKey(Optional.<ECKeyPair>absent());
|
||||
}
|
||||
|
||||
if (!sessionRecord.isFresh()) sessionRecord.archiveCurrentState();
|
||||
|
||||
RatchetingSession.initializeSession(sessionRecord.getSessionState(), parameters.create());
|
||||
|
||||
sessionRecord.getSessionState().setLocalRegistrationId(identityKeyStore.getLocalRegistrationId());
|
||||
sessionRecord.getSessionState().setRemoteRegistrationId(message.getRegistrationId());
|
||||
sessionRecord.getSessionState().setAliceBaseKey(message.getBaseKey().serialize());
|
||||
|
||||
if (message.getPreKeyId().isPresent()) {
|
||||
return message.getPreKeyId();
|
||||
} else {
|
||||
return Optional.absent();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a new session from a {@link org.whispersystems.libsignal.state.PreKeyBundle} retrieved from
|
||||
* a server.
|
||||
*
|
||||
* @param preKey A PreKey for the destination recipient, retrieved from a server.
|
||||
* @throws InvalidKeyException when the {@link org.whispersystems.libsignal.state.PreKeyBundle} is
|
||||
* badly formatted.
|
||||
* @throws org.whispersystems.libsignal.UntrustedIdentityException when the sender's
|
||||
* {@link IdentityKey} is not
|
||||
* trusted.
|
||||
*/
|
||||
public void process(PreKeyBundle preKey) throws InvalidKeyException, UntrustedIdentityException {
|
||||
synchronized (SessionCipher.SESSION_LOCK) {
|
||||
if (!identityKeyStore.isTrustedIdentity(remoteAddress, preKey.getIdentityKey(), IdentityKeyStore.Direction.SENDING)) {
|
||||
throw new UntrustedIdentityException(remoteAddress.getName(), preKey.getIdentityKey());
|
||||
}
|
||||
|
||||
if (preKey.getSignedPreKey() != null &&
|
||||
!Curve.verifySignature(preKey.getIdentityKey().getPublicKey(),
|
||||
preKey.getSignedPreKey().serialize(),
|
||||
preKey.getSignedPreKeySignature()))
|
||||
{
|
||||
throw new InvalidKeyException("Invalid signature on device key!");
|
||||
}
|
||||
|
||||
if (preKey.getSignedPreKey() == null) {
|
||||
throw new InvalidKeyException("No signed prekey!");
|
||||
}
|
||||
|
||||
SessionRecord sessionRecord = sessionStore.loadSession(remoteAddress);
|
||||
ECKeyPair ourBaseKey = Curve.generateKeyPair();
|
||||
ECPublicKey theirSignedPreKey = preKey.getSignedPreKey();
|
||||
Optional<ECPublicKey> theirOneTimePreKey = Optional.fromNullable(preKey.getPreKey());
|
||||
Optional<Integer> theirOneTimePreKeyId = theirOneTimePreKey.isPresent() ? Optional.of(preKey.getPreKeyId()) :
|
||||
Optional.<Integer>absent();
|
||||
|
||||
AliceSignalProtocolParameters.Builder parameters = AliceSignalProtocolParameters.newBuilder();
|
||||
|
||||
parameters.setOurBaseKey(ourBaseKey)
|
||||
.setOurIdentityKey(identityKeyStore.getIdentityKeyPair())
|
||||
.setTheirIdentityKey(preKey.getIdentityKey())
|
||||
.setTheirSignedPreKey(theirSignedPreKey)
|
||||
.setTheirRatchetKey(theirSignedPreKey)
|
||||
.setTheirOneTimePreKey(theirOneTimePreKey);
|
||||
|
||||
if (!sessionRecord.isFresh()) sessionRecord.archiveCurrentState();
|
||||
|
||||
RatchetingSession.initializeSession(sessionRecord.getSessionState(), parameters.create());
|
||||
|
||||
sessionRecord.getSessionState().setUnacknowledgedPreKeyMessage(theirOneTimePreKeyId, preKey.getSignedPreKeyId(), ourBaseKey.getPublicKey());
|
||||
sessionRecord.getSessionState().setLocalRegistrationId(identityKeyStore.getLocalRegistrationId());
|
||||
sessionRecord.getSessionState().setRemoteRegistrationId(preKey.getRegistrationId());
|
||||
sessionRecord.getSessionState().setAliceBaseKey(ourBaseKey.getPublicKey().serialize());
|
||||
|
||||
identityKeyStore.saveIdentity(remoteAddress, preKey.getIdentityKey());
|
||||
sessionStore.storeSession(remoteAddress, sessionRecord);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,40 +1,29 @@
|
||||
/**
|
||||
* Copyright (C) 2013 Open Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
/**
|
||||
* Copyright (C) 2014-2016 Open Whisper Systems
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
package org.whispersystems.libaxolotl;
|
||||
package org.whispersystems.libsignal;
|
||||
|
||||
import org.whispersystems.libaxolotl.ecc.Curve;
|
||||
import org.whispersystems.libaxolotl.ecc.ECKeyPair;
|
||||
import org.whispersystems.libaxolotl.ecc.ECPublicKey;
|
||||
import org.whispersystems.libaxolotl.protocol.CiphertextMessage;
|
||||
import org.whispersystems.libaxolotl.protocol.PreKeyWhisperMessage;
|
||||
import org.whispersystems.libaxolotl.protocol.WhisperMessage;
|
||||
import org.whispersystems.libaxolotl.ratchet.ChainKey;
|
||||
import org.whispersystems.libaxolotl.ratchet.MessageKeys;
|
||||
import org.whispersystems.libaxolotl.ratchet.RootKey;
|
||||
import org.whispersystems.libaxolotl.state.AxolotlStore;
|
||||
import org.whispersystems.libaxolotl.state.IdentityKeyStore;
|
||||
import org.whispersystems.libaxolotl.state.PreKeyStore;
|
||||
import org.whispersystems.libaxolotl.state.SessionRecord;
|
||||
import org.whispersystems.libaxolotl.state.SessionState;
|
||||
import org.whispersystems.libaxolotl.state.SessionStore;
|
||||
import org.whispersystems.libaxolotl.state.SignedPreKeyStore;
|
||||
import org.whispersystems.libaxolotl.util.ByteUtil;
|
||||
import org.whispersystems.libaxolotl.util.Pair;
|
||||
import org.whispersystems.libaxolotl.util.guava.Optional;
|
||||
import org.whispersystems.libsignal.ecc.Curve;
|
||||
import org.whispersystems.libsignal.ecc.ECKeyPair;
|
||||
import org.whispersystems.libsignal.ecc.ECPublicKey;
|
||||
import org.whispersystems.libsignal.protocol.CiphertextMessage;
|
||||
import org.whispersystems.libsignal.protocol.PreKeySignalMessage;
|
||||
import org.whispersystems.libsignal.protocol.SignalMessage;
|
||||
import org.whispersystems.libsignal.ratchet.ChainKey;
|
||||
import org.whispersystems.libsignal.ratchet.MessageKeys;
|
||||
import org.whispersystems.libsignal.ratchet.RootKey;
|
||||
import org.whispersystems.libsignal.state.SignalProtocolStore;
|
||||
import org.whispersystems.libsignal.state.IdentityKeyStore;
|
||||
import org.whispersystems.libsignal.state.PreKeyStore;
|
||||
import org.whispersystems.libsignal.state.SessionRecord;
|
||||
import org.whispersystems.libsignal.state.SessionState;
|
||||
import org.whispersystems.libsignal.state.SessionStore;
|
||||
import org.whispersystems.libsignal.state.SignedPreKeyStore;
|
||||
import org.whispersystems.libsignal.util.ByteUtil;
|
||||
import org.whispersystems.libsignal.util.Pair;
|
||||
import org.whispersystems.libsignal.util.guava.Optional;
|
||||
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
@ -49,10 +38,10 @@ import javax.crypto.NoSuchPaddingException;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
|
||||
import static org.whispersystems.libaxolotl.state.SessionState.UnacknowledgedPreKeyMessageItems;
|
||||
import static org.whispersystems.libsignal.state.SessionState.UnacknowledgedPreKeyMessageItems;
|
||||
|
||||
/**
|
||||
* The main entry point for Axolotl encrypt/decrypt operations.
|
||||
* The main entry point for Signal Protocol encrypt/decrypt operations.
|
||||
*
|
||||
* Once a session has been established with {@link SessionBuilder},
|
||||
* this class can be used for all encrypt/decrypt operations within
|
||||
@ -64,10 +53,11 @@ public class SessionCipher {
|
||||
|
||||
public static final Object SESSION_LOCK = new Object();
|
||||
|
||||
private final SessionStore sessionStore;
|
||||
private final SessionBuilder sessionBuilder;
|
||||
private final PreKeyStore preKeyStore;
|
||||
private final AxolotlAddress remoteAddress;
|
||||
private final SessionStore sessionStore;
|
||||
private final IdentityKeyStore identityKeyStore;
|
||||
private final SessionBuilder sessionBuilder;
|
||||
private final PreKeyStore preKeyStore;
|
||||
private final SignalProtocolAddress remoteAddress;
|
||||
|
||||
/**
|
||||
* Construct a SessionCipher for encrypt/decrypt operations on a session.
|
||||
@ -79,16 +69,17 @@ public class SessionCipher {
|
||||
*/
|
||||
public SessionCipher(SessionStore sessionStore, PreKeyStore preKeyStore,
|
||||
SignedPreKeyStore signedPreKeyStore, IdentityKeyStore identityKeyStore,
|
||||
AxolotlAddress remoteAddress)
|
||||
SignalProtocolAddress remoteAddress)
|
||||
{
|
||||
this.sessionStore = sessionStore;
|
||||
this.preKeyStore = preKeyStore;
|
||||
this.remoteAddress = remoteAddress;
|
||||
this.sessionBuilder = new SessionBuilder(sessionStore, preKeyStore, signedPreKeyStore,
|
||||
identityKeyStore, remoteAddress);
|
||||
this.sessionStore = sessionStore;
|
||||
this.preKeyStore = preKeyStore;
|
||||
this.identityKeyStore = identityKeyStore;
|
||||
this.remoteAddress = remoteAddress;
|
||||
this.sessionBuilder = new SessionBuilder(sessionStore, preKeyStore, signedPreKeyStore,
|
||||
identityKeyStore, remoteAddress);
|
||||
}
|
||||
|
||||
public SessionCipher(AxolotlStore store, AxolotlAddress remoteAddress) {
|
||||
public SessionCipher(SignalProtocolStore store, SignalProtocolAddress remoteAddress) {
|
||||
this(store, store, store, store, remoteAddress);
|
||||
}
|
||||
|
||||
@ -98,7 +89,7 @@ public class SessionCipher {
|
||||
* @param paddedMessage The plaintext message bytes, optionally padded to a constant multiple.
|
||||
* @return A ciphertext message encrypted to the recipient+device tuple.
|
||||
*/
|
||||
public CiphertextMessage encrypt(byte[] paddedMessage) {
|
||||
public CiphertextMessage encrypt(byte[] paddedMessage) throws UntrustedIdentityException {
|
||||
synchronized (SESSION_LOCK) {
|
||||
SessionRecord sessionRecord = sessionStore.loadSession(remoteAddress);
|
||||
SessionState sessionState = sessionRecord.getSessionState();
|
||||
@ -108,24 +99,30 @@ public class SessionCipher {
|
||||
int previousCounter = sessionState.getPreviousCounter();
|
||||
int sessionVersion = sessionState.getSessionVersion();
|
||||
|
||||
byte[] ciphertextBody = getCiphertext(sessionVersion, messageKeys, paddedMessage);
|
||||
CiphertextMessage ciphertextMessage = new WhisperMessage(sessionVersion, messageKeys.getMacKey(),
|
||||
senderEphemeral, chainKey.getIndex(),
|
||||
previousCounter, ciphertextBody,
|
||||
sessionState.getLocalIdentityKey(),
|
||||
sessionState.getRemoteIdentityKey());
|
||||
byte[] ciphertextBody = getCiphertext(messageKeys, paddedMessage);
|
||||
CiphertextMessage ciphertextMessage = new SignalMessage(sessionVersion, messageKeys.getMacKey(),
|
||||
senderEphemeral, chainKey.getIndex(),
|
||||
previousCounter, ciphertextBody,
|
||||
sessionState.getLocalIdentityKey(),
|
||||
sessionState.getRemoteIdentityKey());
|
||||
|
||||
if (sessionState.hasUnacknowledgedPreKeyMessage()) {
|
||||
UnacknowledgedPreKeyMessageItems items = sessionState.getUnacknowledgedPreKeyMessageItems();
|
||||
int localRegistrationId = sessionState.getLocalRegistrationId();
|
||||
|
||||
ciphertextMessage = new PreKeyWhisperMessage(sessionVersion, localRegistrationId, items.getPreKeyId(),
|
||||
items.getSignedPreKeyId(), items.getBaseKey(),
|
||||
sessionState.getLocalIdentityKey(),
|
||||
(WhisperMessage) ciphertextMessage);
|
||||
ciphertextMessage = new PreKeySignalMessage(sessionVersion, localRegistrationId, items.getPreKeyId(),
|
||||
items.getSignedPreKeyId(), items.getBaseKey(),
|
||||
sessionState.getLocalIdentityKey(),
|
||||
(SignalMessage) ciphertextMessage);
|
||||
}
|
||||
|
||||
sessionState.setSenderChainKey(chainKey.getNextChainKey());
|
||||
|
||||
if (!identityKeyStore.isTrustedIdentity(remoteAddress, sessionState.getRemoteIdentityKey(), IdentityKeyStore.Direction.SENDING)) {
|
||||
throw new UntrustedIdentityException(remoteAddress.getName(), sessionState.getRemoteIdentityKey());
|
||||
}
|
||||
|
||||
identityKeyStore.saveIdentity(remoteAddress, sessionState.getRemoteIdentityKey());
|
||||
sessionStore.storeSession(remoteAddress, sessionRecord);
|
||||
return ciphertextMessage;
|
||||
}
|
||||
@ -134,19 +131,19 @@ public class SessionCipher {
|
||||
/**
|
||||
* Decrypt a message.
|
||||
*
|
||||
* @param ciphertext The {@link PreKeyWhisperMessage} to decrypt.
|
||||
* @param ciphertext The {@link PreKeySignalMessage} to decrypt.
|
||||
*
|
||||
* @return The plaintext.
|
||||
* @throws InvalidMessageException if the input is not valid ciphertext.
|
||||
* @throws DuplicateMessageException if the input is a message that has already been received.
|
||||
* @throws LegacyMessageException if the input is a message formatted by a protocol version that
|
||||
* is no longer supported.
|
||||
* @throws InvalidKeyIdException when there is no local {@link org.whispersystems.libaxolotl.state.PreKeyRecord}
|
||||
* @throws InvalidKeyIdException when there is no local {@link org.whispersystems.libsignal.state.PreKeyRecord}
|
||||
* that corresponds to the PreKey ID in the message.
|
||||
* @throws InvalidKeyException when the message is formatted incorrectly.
|
||||
* @throws UntrustedIdentityException when the {@link IdentityKey} of the sender is untrusted.
|
||||
*/
|
||||
public byte[] decrypt(PreKeyWhisperMessage ciphertext)
|
||||
public byte[] decrypt(PreKeySignalMessage ciphertext)
|
||||
throws DuplicateMessageException, LegacyMessageException, InvalidMessageException,
|
||||
InvalidKeyIdException, InvalidKeyException, UntrustedIdentityException
|
||||
{
|
||||
@ -156,7 +153,7 @@ public class SessionCipher {
|
||||
/**
|
||||
* Decrypt a message.
|
||||
*
|
||||
* @param ciphertext The {@link PreKeyWhisperMessage} to decrypt.
|
||||
* @param ciphertext The {@link PreKeySignalMessage} to decrypt.
|
||||
* @param callback A callback that is triggered after decryption is complete,
|
||||
* but before the updated session state has been committed to the session
|
||||
* DB. This allows some implementations to store the committed plaintext
|
||||
@ -169,12 +166,12 @@ public class SessionCipher {
|
||||
* @throws DuplicateMessageException if the input is a message that has already been received.
|
||||
* @throws LegacyMessageException if the input is a message formatted by a protocol version that
|
||||
* is no longer supported.
|
||||
* @throws InvalidKeyIdException when there is no local {@link org.whispersystems.libaxolotl.state.PreKeyRecord}
|
||||
* @throws InvalidKeyIdException when there is no local {@link org.whispersystems.libsignal.state.PreKeyRecord}
|
||||
* that corresponds to the PreKey ID in the message.
|
||||
* @throws InvalidKeyException when the message is formatted incorrectly.
|
||||
* @throws UntrustedIdentityException when the {@link IdentityKey} of the sender is untrusted.
|
||||
*/
|
||||
public byte[] decrypt(PreKeyWhisperMessage ciphertext, DecryptionCallback callback)
|
||||
public byte[] decrypt(PreKeySignalMessage ciphertext, DecryptionCallback callback)
|
||||
throws DuplicateMessageException, LegacyMessageException, InvalidMessageException,
|
||||
InvalidKeyIdException, InvalidKeyException, UntrustedIdentityException
|
||||
{
|
||||
@ -198,7 +195,7 @@ public class SessionCipher {
|
||||
/**
|
||||
* Decrypt a message.
|
||||
*
|
||||
* @param ciphertext The {@link WhisperMessage} to decrypt.
|
||||
* @param ciphertext The {@link SignalMessage} to decrypt.
|
||||
*
|
||||
* @return The plaintext.
|
||||
* @throws InvalidMessageException if the input is not valid ciphertext.
|
||||
@ -207,9 +204,9 @@ public class SessionCipher {
|
||||
* is no longer supported.
|
||||
* @throws NoSessionException if there is no established session for this contact.
|
||||
*/
|
||||
public byte[] decrypt(WhisperMessage ciphertext)
|
||||
public byte[] decrypt(SignalMessage ciphertext)
|
||||
throws InvalidMessageException, DuplicateMessageException, LegacyMessageException,
|
||||
NoSessionException
|
||||
NoSessionException, UntrustedIdentityException
|
||||
{
|
||||
return decrypt(ciphertext, new NullDecryptionCallback());
|
||||
}
|
||||
@ -217,7 +214,7 @@ public class SessionCipher {
|
||||
/**
|
||||
* Decrypt a message.
|
||||
*
|
||||
* @param ciphertext The {@link WhisperMessage} to decrypt.
|
||||
* @param ciphertext The {@link SignalMessage} to decrypt.
|
||||
* @param callback A callback that is triggered after decryption is complete,
|
||||
* but before the updated session state has been committed to the session
|
||||
* DB. This allows some implementations to store the committed plaintext
|
||||
@ -232,9 +229,9 @@ public class SessionCipher {
|
||||
* is no longer supported.
|
||||
* @throws NoSessionException if there is no established session for this contact.
|
||||
*/
|
||||
public byte[] decrypt(WhisperMessage ciphertext, DecryptionCallback callback)
|
||||
public byte[] decrypt(SignalMessage ciphertext, DecryptionCallback callback)
|
||||
throws InvalidMessageException, DuplicateMessageException, LegacyMessageException,
|
||||
NoSessionException
|
||||
NoSessionException, UntrustedIdentityException
|
||||
{
|
||||
synchronized (SESSION_LOCK) {
|
||||
|
||||
@ -245,6 +242,12 @@ public class SessionCipher {
|
||||
SessionRecord sessionRecord = sessionStore.loadSession(remoteAddress);
|
||||
byte[] plaintext = decrypt(sessionRecord, ciphertext);
|
||||
|
||||
if (!identityKeyStore.isTrustedIdentity(remoteAddress, sessionRecord.getSessionState().getRemoteIdentityKey(), IdentityKeyStore.Direction.RECEIVING)) {
|
||||
throw new UntrustedIdentityException(remoteAddress.getName(), sessionRecord.getSessionState().getRemoteIdentityKey());
|
||||
}
|
||||
|
||||
identityKeyStore.saveIdentity(remoteAddress, sessionRecord.getSessionState().getRemoteIdentityKey());
|
||||
|
||||
callback.handlePlaintext(plaintext);
|
||||
|
||||
sessionStore.storeSession(remoteAddress, sessionRecord);
|
||||
@ -253,7 +256,7 @@ public class SessionCipher {
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] decrypt(SessionRecord sessionRecord, WhisperMessage ciphertext)
|
||||
private byte[] decrypt(SessionRecord sessionRecord, SignalMessage ciphertext)
|
||||
throws DuplicateMessageException, LegacyMessageException, InvalidMessageException
|
||||
{
|
||||
synchronized (SESSION_LOCK) {
|
||||
@ -288,7 +291,7 @@ public class SessionCipher {
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] decrypt(SessionState sessionState, WhisperMessage ciphertextMessage)
|
||||
private byte[] decrypt(SessionState sessionState, SignalMessage ciphertextMessage)
|
||||
throws InvalidMessageException, DuplicateMessageException, LegacyMessageException
|
||||
{
|
||||
if (!sessionState.hasSenderChain()) {
|
||||
@ -301,19 +304,17 @@ public class SessionCipher {
|
||||
sessionState.getSessionVersion()));
|
||||
}
|
||||
|
||||
int messageVersion = ciphertextMessage.getMessageVersion();
|
||||
ECPublicKey theirEphemeral = ciphertextMessage.getSenderRatchetKey();
|
||||
int counter = ciphertextMessage.getCounter();
|
||||
ChainKey chainKey = getOrCreateChainKey(sessionState, theirEphemeral);
|
||||
MessageKeys messageKeys = getOrCreateMessageKeys(sessionState, theirEphemeral,
|
||||
chainKey, counter);
|
||||
|
||||
ciphertextMessage.verifyMac(messageVersion,
|
||||
sessionState.getRemoteIdentityKey(),
|
||||
ciphertextMessage.verifyMac(sessionState.getRemoteIdentityKey(),
|
||||
sessionState.getLocalIdentityKey(),
|
||||
messageKeys.getMacKey());
|
||||
|
||||
byte[] plaintext = getPlaintext(messageVersion, messageKeys, ciphertextMessage.getBody());
|
||||
byte[] plaintext = getPlaintext(messageKeys, ciphertextMessage.getBody());
|
||||
|
||||
sessionState.clearUnacknowledgedPreKeyMessage();
|
||||
|
||||
@ -391,58 +392,26 @@ public class SessionCipher {
|
||||
return chainKey.getMessageKeys();
|
||||
}
|
||||
|
||||
private byte[] getCiphertext(int version, MessageKeys messageKeys, byte[] plaintext) {
|
||||
private byte[] getCiphertext(MessageKeys messageKeys, byte[] plaintext) {
|
||||
try {
|
||||
Cipher cipher;
|
||||
|
||||
if (version >= 3) {
|
||||
cipher = getCipher(Cipher.ENCRYPT_MODE, messageKeys.getCipherKey(), messageKeys.getIv());
|
||||
} else {
|
||||
cipher = getCipher(Cipher.ENCRYPT_MODE, messageKeys.getCipherKey(), messageKeys.getCounter());
|
||||
}
|
||||
|
||||
Cipher cipher = getCipher(Cipher.ENCRYPT_MODE, messageKeys.getCipherKey(), messageKeys.getIv());
|
||||
return cipher.doFinal(plaintext);
|
||||
} catch (IllegalBlockSizeException | BadPaddingException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] getPlaintext(int version, MessageKeys messageKeys, byte[] cipherText)
|
||||
private byte[] getPlaintext(MessageKeys messageKeys, byte[] cipherText)
|
||||
throws InvalidMessageException
|
||||
{
|
||||
try {
|
||||
Cipher cipher;
|
||||
|
||||
if (version >= 3) {
|
||||
cipher = getCipher(Cipher.DECRYPT_MODE, messageKeys.getCipherKey(), messageKeys.getIv());
|
||||
} else {
|
||||
cipher = getCipher(Cipher.DECRYPT_MODE, messageKeys.getCipherKey(), messageKeys.getCounter());
|
||||
}
|
||||
|
||||
Cipher cipher = getCipher(Cipher.DECRYPT_MODE, messageKeys.getCipherKey(), messageKeys.getIv());
|
||||
return cipher.doFinal(cipherText);
|
||||
} catch (IllegalBlockSizeException | BadPaddingException e) {
|
||||
throw new InvalidMessageException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private Cipher getCipher(int mode, SecretKeySpec key, int counter) {
|
||||
try {
|
||||
Cipher cipher = Cipher.getInstance("AES/CTR/NoPadding");
|
||||
|
||||
byte[] ivBytes = new byte[16];
|
||||
ByteUtil.intToByteArray(ivBytes, 0, counter);
|
||||
|
||||
IvParameterSpec iv = new IvParameterSpec(ivBytes);
|
||||
cipher.init(mode, key, iv);
|
||||
|
||||
return cipher;
|
||||
} catch (NoSuchAlgorithmException | NoSuchPaddingException | java.security.InvalidKeyException |
|
||||
InvalidAlgorithmParameterException e)
|
||||
{
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
private Cipher getCipher(int mode, SecretKeySpec key, IvParameterSpec iv) {
|
||||
try {
|
||||
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
||||
@ -1,11 +1,16 @@
|
||||
package org.whispersystems.libaxolotl;
|
||||
/**
|
||||
* Copyright (C) 2014-2016 Open Whisper Systems
|
||||
*
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
package org.whispersystems.libsignal;
|
||||
|
||||
public class AxolotlAddress {
|
||||
public class SignalProtocolAddress {
|
||||
|
||||
private final String name;
|
||||
private final int deviceId;
|
||||
|
||||
public AxolotlAddress(String name, int deviceId) {
|
||||
public SignalProtocolAddress(String name, int deviceId) {
|
||||
this.name = name;
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
@ -26,9 +31,9 @@ public class AxolotlAddress {
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (other == null) return false;
|
||||
if (!(other instanceof AxolotlAddress)) return false;
|
||||
if (!(other instanceof SignalProtocolAddress)) return false;
|
||||
|
||||
AxolotlAddress that = (AxolotlAddress)other;
|
||||
SignalProtocolAddress that = (SignalProtocolAddress)other;
|
||||
return this.name.equals(that.name) && this.deviceId == that.deviceId;
|
||||
}
|
||||
|
||||
@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Copyright (C) 2014-2016 Open Whisper Systems
|
||||
*
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
package org.whispersystems.libsignal;
|
||||
|
||||
public class StaleKeyExchangeException extends Throwable {
|
||||
}
|
||||
@ -1,4 +1,9 @@
|
||||
package org.whispersystems.libaxolotl;
|
||||
/**
|
||||
* Copyright (C) 2014-2016 Open Whisper Systems
|
||||
*
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
package org.whispersystems.libsignal;
|
||||
|
||||
public class UntrustedIdentityException extends Exception {
|
||||
|
||||
@ -0,0 +1,54 @@
|
||||
package org.whispersystems.libsignal.devices;
|
||||
|
||||
import org.whispersystems.libsignal.util.ByteArrayComparator;
|
||||
import org.whispersystems.libsignal.util.ByteUtil;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class DeviceConsistencyCodeGenerator {
|
||||
|
||||
private static final int CODE_VERSION = 0;
|
||||
|
||||
public static String generateFor(DeviceConsistencyCommitment commitment,
|
||||
List<DeviceConsistencySignature> signatures)
|
||||
{
|
||||
try {
|
||||
ArrayList<DeviceConsistencySignature> sortedSignatures = new ArrayList<>(signatures);
|
||||
Collections.sort(sortedSignatures, new SignatureComparator());
|
||||
|
||||
MessageDigest messageDigest = MessageDigest.getInstance("SHA-512");
|
||||
messageDigest.update(ByteUtil.shortToByteArray(CODE_VERSION));
|
||||
messageDigest.update(commitment.toByteArray());
|
||||
|
||||
for (DeviceConsistencySignature signature : sortedSignatures) {
|
||||
messageDigest.update(signature.getVrfOutput());
|
||||
}
|
||||
|
||||
byte[] hash = messageDigest.digest();
|
||||
|
||||
String digits = getEncodedChunk(hash, 0) + getEncodedChunk(hash, 5);
|
||||
return digits.substring(0, 6);
|
||||
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static String getEncodedChunk(byte[] hash, int offset) {
|
||||
long chunk = ByteUtil.byteArray5ToLong(hash, offset) % 100000;
|
||||
return String.format("%05d", chunk);
|
||||
}
|
||||
|
||||
|
||||
private static class SignatureComparator extends ByteArrayComparator implements Comparator<DeviceConsistencySignature> {
|
||||
@Override
|
||||
public int compare(DeviceConsistencySignature first, DeviceConsistencySignature second) {
|
||||
return compare(first.getVrfOutput(), second.getVrfOutput());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,49 @@
|
||||
package org.whispersystems.libsignal.devices;
|
||||
|
||||
import org.whispersystems.libsignal.IdentityKey;
|
||||
import org.whispersystems.libsignal.util.ByteUtil;
|
||||
import org.whispersystems.libsignal.util.IdentityKeyComparator;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class DeviceConsistencyCommitment {
|
||||
|
||||
private static final String VERSION = "DeviceConsistencyCommitment_V0";
|
||||
|
||||
private final int generation;
|
||||
private final byte[] serialized;
|
||||
|
||||
public DeviceConsistencyCommitment(int generation, List<IdentityKey> identityKeys) {
|
||||
try {
|
||||
ArrayList<IdentityKey> sortedIdentityKeys = new ArrayList<>(identityKeys);
|
||||
Collections.sort(sortedIdentityKeys, new IdentityKeyComparator());
|
||||
|
||||
MessageDigest messageDigest = MessageDigest.getInstance("SHA-512");
|
||||
messageDigest.update(VERSION.getBytes());
|
||||
messageDigest.update(ByteUtil.intToByteArray(generation));
|
||||
|
||||
for (IdentityKey commitment : sortedIdentityKeys) {
|
||||
messageDigest.update(commitment.getPublicKey().serialize());
|
||||
}
|
||||
|
||||
this.generation = generation;
|
||||
this.serialized = messageDigest.digest();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] toByteArray() {
|
||||
return serialized;
|
||||
}
|
||||
|
||||
public int getGeneration() {
|
||||
return generation;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
package org.whispersystems.libsignal.devices;
|
||||
|
||||
public class DeviceConsistencySignature {
|
||||
|
||||
private final byte[] signature;
|
||||
private final byte[] vrfOutput;
|
||||
|
||||
public DeviceConsistencySignature(byte[] signature, byte[] vrfOutput) {
|
||||
this.signature = signature;
|
||||
this.vrfOutput = vrfOutput;
|
||||
}
|
||||
|
||||
public byte[] getVrfOutput() {
|
||||
return vrfOutput;
|
||||
}
|
||||
|
||||
public byte[] getSignature() {
|
||||
return signature;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,25 +1,14 @@
|
||||
/**
|
||||
* Copyright (C) 2013 Open Whisper Systems
|
||||
* Copyright (C) 2013-2016 Open Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
package org.whispersystems.libaxolotl.ecc;
|
||||
package org.whispersystems.libsignal.ecc;
|
||||
|
||||
import org.whispersystems.curve25519.Curve25519;
|
||||
import org.whispersystems.curve25519.Curve25519KeyPair;
|
||||
import org.whispersystems.curve25519.NoSuchProviderException;
|
||||
import org.whispersystems.libaxolotl.InvalidKeyException;
|
||||
import org.whispersystems.curve25519.VrfSignatureVerificationFailedException;
|
||||
import org.whispersystems.libsignal.InvalidKeyException;
|
||||
|
||||
import static org.whispersystems.curve25519.Curve25519.BEST;
|
||||
|
||||
@ -41,10 +30,18 @@ public class Curve {
|
||||
public static ECPublicKey decodePoint(byte[] bytes, int offset)
|
||||
throws InvalidKeyException
|
||||
{
|
||||
if (bytes == null || bytes.length - offset < 1) {
|
||||
throw new InvalidKeyException("No key type identifier");
|
||||
}
|
||||
|
||||
int type = bytes[offset] & 0xFF;
|
||||
|
||||
switch (type) {
|
||||
case Curve.DJB_TYPE:
|
||||
if (bytes.length - offset < 33) {
|
||||
throw new InvalidKeyException("Bad key length: " + bytes.length);
|
||||
}
|
||||
|
||||
byte[] keyBytes = new byte[32];
|
||||
System.arraycopy(bytes, offset+1, keyBytes, 0, keyBytes.length);
|
||||
return new DjbECPublicKey(keyBytes);
|
||||
@ -60,6 +57,14 @@ public class Curve {
|
||||
public static byte[] calculateAgreement(ECPublicKey publicKey, ECPrivateKey privateKey)
|
||||
throws InvalidKeyException
|
||||
{
|
||||
if (publicKey == null) {
|
||||
throw new InvalidKeyException("public value is null");
|
||||
}
|
||||
|
||||
if (privateKey == null) {
|
||||
throw new InvalidKeyException("private value is null");
|
||||
}
|
||||
|
||||
if (publicKey.getType() != privateKey.getType()) {
|
||||
throw new InvalidKeyException("Public and private keys must be of the same type!");
|
||||
}
|
||||
@ -76,6 +81,10 @@ public class Curve {
|
||||
public static boolean verifySignature(ECPublicKey signingKey, byte[] message, byte[] signature)
|
||||
throws InvalidKeyException
|
||||
{
|
||||
if (signingKey == null || message == null || signature == null) {
|
||||
throw new InvalidKeyException("Values must not be null");
|
||||
}
|
||||
|
||||
if (signingKey.getType() == DJB_TYPE) {
|
||||
return Curve25519.getInstance(BEST)
|
||||
.verifySignature(((DjbECPublicKey) signingKey).getPublicKey(), message, signature);
|
||||
@ -87,6 +96,10 @@ public class Curve {
|
||||
public static byte[] calculateSignature(ECPrivateKey signingKey, byte[] message)
|
||||
throws InvalidKeyException
|
||||
{
|
||||
if (signingKey == null || message == null) {
|
||||
throw new InvalidKeyException("Values must not be null");
|
||||
}
|
||||
|
||||
if (signingKey.getType() == DJB_TYPE) {
|
||||
return Curve25519.getInstance(BEST)
|
||||
.calculateSignature(((DjbECPrivateKey) signingKey).getPrivateKey(), message);
|
||||
@ -94,4 +107,35 @@ public class Curve {
|
||||
throw new InvalidKeyException("Unknown type: " + signingKey.getType());
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] calculateVrfSignature(ECPrivateKey signingKey, byte[] message)
|
||||
throws InvalidKeyException
|
||||
{
|
||||
if (signingKey == null || message == null) {
|
||||
throw new InvalidKeyException("Values must not be null");
|
||||
}
|
||||
|
||||
if (signingKey.getType() == DJB_TYPE) {
|
||||
return Curve25519.getInstance(BEST)
|
||||
.calculateVrfSignature(((DjbECPrivateKey)signingKey).getPrivateKey(), message);
|
||||
} else {
|
||||
throw new InvalidKeyException("Unknown type: " + signingKey.getType());
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] verifyVrfSignature(ECPublicKey signingKey, byte[] message, byte[] signature)
|
||||
throws InvalidKeyException, VrfSignatureVerificationFailedException
|
||||
{
|
||||
if (signingKey == null || message == null || signature == null) {
|
||||
throw new InvalidKeyException("Values must not be null");
|
||||
}
|
||||
|
||||
if (signingKey.getType() == DJB_TYPE) {
|
||||
return Curve25519.getInstance(BEST)
|
||||
.verifyVrfSignature(((DjbECPublicKey) signingKey).getPublicKey(), message, signature);
|
||||
} else {
|
||||
throw new InvalidKeyException("Unknown type: " + signingKey.getType());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Copyright (C) 2013-2016 Open Whisper Systems
|
||||
*
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
|
||||
package org.whispersystems.libsignal.ecc;
|
||||
|
||||
public class DjbECPrivateKey implements ECPrivateKey {
|
||||
|
||||
private final byte[] privateKey;
|
||||
|
||||
DjbECPrivateKey(byte[] privateKey) {
|
||||
this.privateKey = privateKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] serialize() {
|
||||
return privateKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return Curve.DJB_TYPE;
|
||||
}
|
||||
|
||||
public byte[] getPrivateKey() {
|
||||
return privateKey;
|
||||
}
|
||||
}
|
||||
@ -1,23 +1,12 @@
|
||||
/**
|
||||
* Copyright (C) 2013 Open Whisper Systems
|
||||
* Copyright (C) 2013-2016 Open Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
|
||||
package org.whispersystems.libaxolotl.ecc;
|
||||
package org.whispersystems.libsignal.ecc;
|
||||
|
||||
import org.whispersystems.libaxolotl.util.ByteUtil;
|
||||
import org.whispersystems.libsignal.util.ByteUtil;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.Arrays;
|
||||
@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Copyright (C) 2013-2016 Open Whisper Systems
|
||||
*
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
package org.whispersystems.libsignal.ecc;
|
||||
|
||||
public class ECKeyPair {
|
||||
|
||||
private final ECPublicKey publicKey;
|
||||
private final ECPrivateKey privateKey;
|
||||
|
||||
public ECKeyPair(ECPublicKey publicKey, ECPrivateKey privateKey) {
|
||||
this.publicKey = publicKey;
|
||||
this.privateKey = privateKey;
|
||||
}
|
||||
|
||||
public ECPublicKey getPublicKey() {
|
||||
return publicKey;
|
||||
}
|
||||
|
||||
public ECPrivateKey getPrivateKey() {
|
||||
return privateKey;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Copyright (C) 2013-2016 Open Whisper Systems
|
||||
*
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
|
||||
package org.whispersystems.libsignal.ecc;
|
||||
|
||||
public interface ECPrivateKey {
|
||||
public byte[] serialize();
|
||||
public int getType();
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
/**
|
||||
* Copyright (C) 2013-2016 Open Whisper Systems
|
||||
*
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
|
||||
package org.whispersystems.libsignal.ecc;
|
||||
|
||||
public interface ECPublicKey extends Comparable<ECPublicKey> {
|
||||
|
||||
public static final int KEY_SIZE = 33;
|
||||
|
||||
public byte[] serialize();
|
||||
|
||||
public int getType();
|
||||
}
|
||||
@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Copyright (C) 2016 Open Whisper Systems
|
||||
*
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
package org.whispersystems.libsignal.fingerprint;
|
||||
|
||||
import org.whispersystems.libsignal.util.ByteUtil;
|
||||
|
||||
public class DisplayableFingerprint {
|
||||
|
||||
private final String localFingerprintNumbers;
|
||||
private final String remoteFingerprintNumbers;
|
||||
|
||||
DisplayableFingerprint(byte[] localFingerprint, byte[] remoteFingerprint)
|
||||
{
|
||||
this.localFingerprintNumbers = getDisplayStringFor(localFingerprint);
|
||||
this.remoteFingerprintNumbers = getDisplayStringFor(remoteFingerprint);
|
||||
}
|
||||
|
||||
public String getDisplayText() {
|
||||
if (localFingerprintNumbers.compareTo(remoteFingerprintNumbers) <= 0) {
|
||||
return localFingerprintNumbers + remoteFingerprintNumbers;
|
||||
} else {
|
||||
return remoteFingerprintNumbers + localFingerprintNumbers;
|
||||
}
|
||||
}
|
||||
|
||||
private String getDisplayStringFor(byte[] fingerprint) {
|
||||
return getEncodedChunk(fingerprint, 0) +
|
||||
getEncodedChunk(fingerprint, 5) +
|
||||
getEncodedChunk(fingerprint, 10) +
|
||||
getEncodedChunk(fingerprint, 15) +
|
||||
getEncodedChunk(fingerprint, 20) +
|
||||
getEncodedChunk(fingerprint, 25);
|
||||
}
|
||||
|
||||
private String getEncodedChunk(byte[] hash, int offset) {
|
||||
long chunk = ByteUtil.byteArray5ToLong(hash, offset) % 100000;
|
||||
return String.format("%05d", chunk);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,4 +1,9 @@
|
||||
package org.whispersystems.libaxolotl.fingerprint;
|
||||
/**
|
||||
* Copyright (C) 2016 Open Whisper Systems
|
||||
*
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
package org.whispersystems.libsignal.fingerprint;
|
||||
|
||||
public class Fingerprint {
|
||||
|
||||
@ -20,7 +25,7 @@ public class Fingerprint {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A scannable fingerprint that can be scanned anc compared locally.
|
||||
* @return A scannable fingerprint that can be scanned and compared locally.
|
||||
*/
|
||||
public ScannableFingerprint getScannableFingerprint() {
|
||||
return scannableFingerprint;
|
||||
@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Copyright (C) 2016 Open Whisper Systems
|
||||
*
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
package org.whispersystems.libsignal.fingerprint;
|
||||
|
||||
import org.whispersystems.libsignal.IdentityKey;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface FingerprintGenerator {
|
||||
public Fingerprint createFor(int version,
|
||||
byte[] localStableIdentifier,
|
||||
IdentityKey localIdentityKey,
|
||||
byte[] remoteStableIdentifier,
|
||||
IdentityKey remoteIdentityKey);
|
||||
|
||||
public Fingerprint createFor(int version,
|
||||
byte[] localStableIdentifier,
|
||||
List<IdentityKey> localIdentityKey,
|
||||
byte[] remoteStableIdentifier,
|
||||
List<IdentityKey> remoteIdentityKey);
|
||||
}
|
||||
@ -1,4 +1,9 @@
|
||||
package org.whispersystems.libaxolotl.fingerprint;
|
||||
/**
|
||||
* Copyright (C) 2016 Open Whisper Systems
|
||||
*
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
package org.whispersystems.libsignal.fingerprint;
|
||||
|
||||
public class FingerprintIdentifierMismatchException extends Exception {
|
||||
|
||||
@ -0,0 +1,14 @@
|
||||
/**
|
||||
* Copyright (C) 2016 Open Whisper Systems
|
||||
*
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
package org.whispersystems.libsignal.fingerprint;
|
||||
|
||||
public class FingerprintParsingException extends Exception {
|
||||
|
||||
public FingerprintParsingException(Exception nested) {
|
||||
super(nested);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Copyright (C) 2016 Open Whisper Systems
|
||||
*
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
package org.whispersystems.libsignal.fingerprint;
|
||||
|
||||
public class FingerprintVersionMismatchException extends Exception {
|
||||
|
||||
private final int theirVersion;
|
||||
private final int ourVersion;
|
||||
|
||||
public FingerprintVersionMismatchException(int theirVersion, int ourVersion) {
|
||||
super();
|
||||
this.theirVersion = theirVersion;
|
||||
this.ourVersion = ourVersion;
|
||||
}
|
||||
|
||||
public int getTheirVersion() {
|
||||
return theirVersion;
|
||||
}
|
||||
|
||||
public int getOurVersion() {
|
||||
return ourVersion;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,137 @@
|
||||
/**
|
||||
* Copyright (C) 2016 Open Whisper Systems
|
||||
*
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
package org.whispersystems.libsignal.fingerprint;
|
||||
|
||||
import org.whispersystems.libsignal.IdentityKey;
|
||||
import org.whispersystems.libsignal.util.ByteUtil;
|
||||
import org.whispersystems.libsignal.util.IdentityKeyComparator;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class NumericFingerprintGenerator implements FingerprintGenerator {
|
||||
|
||||
private static final int FINGERPRINT_VERSION = 0;
|
||||
|
||||
private final int iterations;
|
||||
|
||||
/**
|
||||
* Construct a fingerprint generator for 60 digit numerics.
|
||||
*
|
||||
* @param iterations The number of internal iterations to perform in the process of
|
||||
* generating a fingerprint. This needs to be constant, and synchronized
|
||||
* across all clients.
|
||||
*
|
||||
* The higher the iteration count, the higher the security level:
|
||||
*
|
||||
* - 1024 ~ 109.7 bits
|
||||
* - 1400 > 110 bits
|
||||
* - 5200 > 112 bits
|
||||
*/
|
||||
public NumericFingerprintGenerator(int iterations) {
|
||||
this.iterations = iterations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a scannable and displayable fingerprint.
|
||||
*
|
||||
* @param version The version of fingerprint you are generating.
|
||||
* @param localStableIdentifier The client's "stable" identifier.
|
||||
* @param localIdentityKey The client's identity key.
|
||||
* @param remoteStableIdentifier The remote party's "stable" identifier.
|
||||
* @param remoteIdentityKey The remote party's identity key.
|
||||
* @return A unique fingerprint for this conversation.
|
||||
*/
|
||||
@Override
|
||||
public Fingerprint createFor(int version,
|
||||
byte[] localStableIdentifier,
|
||||
final IdentityKey localIdentityKey,
|
||||
byte[] remoteStableIdentifier,
|
||||
final IdentityKey remoteIdentityKey)
|
||||
{
|
||||
return createFor(version,
|
||||
localStableIdentifier,
|
||||
new LinkedList<IdentityKey>() {{
|
||||
add(localIdentityKey);
|
||||
}},
|
||||
remoteStableIdentifier,
|
||||
new LinkedList<IdentityKey>() {{
|
||||
add(remoteIdentityKey);
|
||||
}});
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a scannable and displayable fingerprint for logical identities that have multiple
|
||||
* physical keys.
|
||||
*
|
||||
* Do not trust the output of this unless you've been through the device consistency process
|
||||
* for the provided localIdentityKeys.
|
||||
*
|
||||
* @param version The version of fingerprint you are generating.
|
||||
* @param localStableIdentifier The client's "stable" identifier.
|
||||
* @param localIdentityKeys The client's collection of physical identity keys.
|
||||
* @param remoteStableIdentifier The remote party's "stable" identifier.
|
||||
* @param remoteIdentityKeys The remote party's collection of physical identity key.
|
||||
* @return A unique fingerprint for this conversation.
|
||||
*/
|
||||
public Fingerprint createFor(int version,
|
||||
byte[] localStableIdentifier,
|
||||
List<IdentityKey> localIdentityKeys,
|
||||
byte[] remoteStableIdentifier,
|
||||
List<IdentityKey> remoteIdentityKeys)
|
||||
{
|
||||
byte[] localFingerprint = getFingerprint(iterations, localStableIdentifier, localIdentityKeys);
|
||||
byte[] remoteFingerprint = getFingerprint(iterations, remoteStableIdentifier, remoteIdentityKeys);
|
||||
|
||||
DisplayableFingerprint displayableFingerprint = new DisplayableFingerprint(localFingerprint,
|
||||
remoteFingerprint);
|
||||
|
||||
ScannableFingerprint scannableFingerprint = new ScannableFingerprint(version,
|
||||
localFingerprint,
|
||||
remoteFingerprint);
|
||||
|
||||
return new Fingerprint(displayableFingerprint, scannableFingerprint);
|
||||
}
|
||||
|
||||
private byte[] getFingerprint(int iterations, byte[] stableIdentifier, List<IdentityKey> unsortedIdentityKeys) {
|
||||
try {
|
||||
MessageDigest digest = MessageDigest.getInstance("SHA-512");
|
||||
byte[] publicKey = getLogicalKeyBytes(unsortedIdentityKeys);
|
||||
byte[] hash = ByteUtil.combine(ByteUtil.shortToByteArray(FINGERPRINT_VERSION),
|
||||
publicKey, stableIdentifier);
|
||||
|
||||
for (int i=0;i<iterations;i++) {
|
||||
digest.update(hash);
|
||||
hash = digest.digest(publicKey);
|
||||
}
|
||||
|
||||
return hash;
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] getLogicalKeyBytes(List<IdentityKey> identityKeys) {
|
||||
ArrayList<IdentityKey> sortedIdentityKeys = new ArrayList<>(identityKeys);
|
||||
Collections.sort(sortedIdentityKeys, new IdentityKeyComparator());
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
|
||||
for (IdentityKey identityKey : sortedIdentityKeys) {
|
||||
byte[] publicKeyBytes = identityKey.getPublicKey().serialize();
|
||||
baos.write(publicKeyBytes, 0, publicKeyBytes.length);
|
||||
}
|
||||
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,73 @@
|
||||
/**
|
||||
* Copyright (C) 2016 Open Whisper Systems
|
||||
*
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
package org.whispersystems.libsignal.fingerprint;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
|
||||
import org.whispersystems.libsignal.fingerprint.FingerprintProtos.CombinedFingerprints;
|
||||
import org.whispersystems.libsignal.fingerprint.FingerprintProtos.LogicalFingerprint;
|
||||
import org.whispersystems.libsignal.util.ByteUtil;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
|
||||
public class ScannableFingerprint {
|
||||
|
||||
private final int version;
|
||||
private final CombinedFingerprints fingerprints;
|
||||
|
||||
ScannableFingerprint(int version, byte[] localFingerprintData, byte[] remoteFingerprintData)
|
||||
{
|
||||
LogicalFingerprint localFingerprint = LogicalFingerprint.newBuilder()
|
||||
.setContent(ByteString.copyFrom(ByteUtil.trim(localFingerprintData, 32)))
|
||||
.build();
|
||||
|
||||
LogicalFingerprint remoteFingerprint = LogicalFingerprint.newBuilder()
|
||||
.setContent(ByteString.copyFrom(ByteUtil.trim(remoteFingerprintData, 32)))
|
||||
.build();
|
||||
|
||||
this.version = version;
|
||||
this.fingerprints = CombinedFingerprints.newBuilder()
|
||||
.setVersion(version)
|
||||
.setLocalFingerprint(localFingerprint)
|
||||
.setRemoteFingerprint(remoteFingerprint)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A byte string to be displayed in a QR code.
|
||||
*/
|
||||
public byte[] getSerialized() {
|
||||
return fingerprints.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare a scanned QR code with what we expect.
|
||||
*
|
||||
* @param scannedFingerprintData The scanned data
|
||||
* @return True if matching, otherwise false.
|
||||
* @throws FingerprintVersionMismatchException if the scanned fingerprint is the wrong version.
|
||||
*/
|
||||
public boolean compareTo(byte[] scannedFingerprintData)
|
||||
throws FingerprintVersionMismatchException,
|
||||
FingerprintParsingException
|
||||
{
|
||||
try {
|
||||
CombinedFingerprints scanned = CombinedFingerprints.parseFrom(scannedFingerprintData);
|
||||
|
||||
if (!scanned.hasRemoteFingerprint() || !scanned.hasLocalFingerprint() ||
|
||||
!scanned.hasVersion() || scanned.getVersion() != version)
|
||||
{
|
||||
throw new FingerprintVersionMismatchException(scanned.getVersion(), version);
|
||||
}
|
||||
|
||||
return MessageDigest.isEqual(fingerprints.getLocalFingerprint().getContent().toByteArray(), scanned.getRemoteFingerprint().getContent().toByteArray()) &&
|
||||
MessageDigest.isEqual(fingerprints.getRemoteFingerprint().getContent().toByteArray(), scanned.getLocalFingerprint().getContent().toByteArray());
|
||||
} catch (InvalidProtocolBufferException e) {
|
||||
throw new FingerprintParsingException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,33 +1,22 @@
|
||||
/**
|
||||
* Copyright (C) 2014-2015 Open Whisper Systems
|
||||
* Copyright (C) 2014-2016 Open Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
package org.whispersystems.libaxolotl.groups;
|
||||
package org.whispersystems.libsignal.groups;
|
||||
|
||||
import org.whispersystems.libaxolotl.DecryptionCallback;
|
||||
import org.whispersystems.libaxolotl.DuplicateMessageException;
|
||||
import org.whispersystems.libaxolotl.InvalidKeyIdException;
|
||||
import org.whispersystems.libaxolotl.InvalidMessageException;
|
||||
import org.whispersystems.libaxolotl.LegacyMessageException;
|
||||
import org.whispersystems.libaxolotl.NoSessionException;
|
||||
import org.whispersystems.libaxolotl.groups.ratchet.SenderChainKey;
|
||||
import org.whispersystems.libaxolotl.groups.ratchet.SenderMessageKey;
|
||||
import org.whispersystems.libaxolotl.groups.state.SenderKeyRecord;
|
||||
import org.whispersystems.libaxolotl.groups.state.SenderKeyState;
|
||||
import org.whispersystems.libaxolotl.groups.state.SenderKeyStore;
|
||||
import org.whispersystems.libaxolotl.protocol.SenderKeyMessage;
|
||||
import org.whispersystems.libsignal.DecryptionCallback;
|
||||
import org.whispersystems.libsignal.DuplicateMessageException;
|
||||
import org.whispersystems.libsignal.InvalidKeyIdException;
|
||||
import org.whispersystems.libsignal.InvalidMessageException;
|
||||
import org.whispersystems.libsignal.LegacyMessageException;
|
||||
import org.whispersystems.libsignal.NoSessionException;
|
||||
import org.whispersystems.libsignal.groups.ratchet.SenderChainKey;
|
||||
import org.whispersystems.libsignal.groups.ratchet.SenderMessageKey;
|
||||
import org.whispersystems.libsignal.groups.state.SenderKeyRecord;
|
||||
import org.whispersystems.libsignal.groups.state.SenderKeyState;
|
||||
import org.whispersystems.libsignal.groups.state.SenderKeyStore;
|
||||
import org.whispersystems.libsignal.protocol.SenderKeyMessage;
|
||||
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
@ -40,10 +29,10 @@ import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
|
||||
/**
|
||||
* The main entry point for axolotl group encrypt/decrypt operations.
|
||||
* The main entry point for Signal Protocol group encrypt/decrypt operations.
|
||||
*
|
||||
* Once a session has been established with {@link org.whispersystems.libaxolotl.groups.GroupSessionBuilder}
|
||||
* and a {@link org.whispersystems.libaxolotl.protocol.SenderKeyDistributionMessage} has been
|
||||
* Once a session has been established with {@link org.whispersystems.libsignal.groups.GroupSessionBuilder}
|
||||
* and a {@link org.whispersystems.libsignal.protocol.SenderKeyDistributionMessage} has been
|
||||
* distributed to each member of the group, this class can be used for all subsequent encrypt/decrypt
|
||||
* operations within that session (ie: until group membership changes).
|
||||
*
|
||||
@ -148,7 +137,7 @@ public class GroupCipher {
|
||||
senderKeyStore.storeSenderKey(senderKeyId, record);
|
||||
|
||||
return plaintext;
|
||||
} catch (org.whispersystems.libaxolotl.InvalidKeyException | InvalidKeyIdException e) {
|
||||
} catch (org.whispersystems.libsignal.InvalidKeyException | InvalidKeyIdException e) {
|
||||
throw new InvalidMessageException(e);
|
||||
}
|
||||
}
|
||||
@ -1,33 +1,22 @@
|
||||
/**
|
||||
* Copyright (C) 2014-2015 Open Whisper Systems
|
||||
* Copyright (C) 2014-2016 Open Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
package org.whispersystems.libaxolotl.groups;
|
||||
package org.whispersystems.libsignal.groups;
|
||||
|
||||
import org.whispersystems.libaxolotl.InvalidKeyException;
|
||||
import org.whispersystems.libaxolotl.InvalidKeyIdException;
|
||||
import org.whispersystems.libaxolotl.groups.state.SenderKeyRecord;
|
||||
import org.whispersystems.libaxolotl.groups.state.SenderKeyState;
|
||||
import org.whispersystems.libaxolotl.groups.state.SenderKeyStore;
|
||||
import org.whispersystems.libaxolotl.protocol.SenderKeyDistributionMessage;
|
||||
import org.whispersystems.libaxolotl.util.KeyHelper;
|
||||
import org.whispersystems.libsignal.InvalidKeyException;
|
||||
import org.whispersystems.libsignal.InvalidKeyIdException;
|
||||
import org.whispersystems.libsignal.groups.state.SenderKeyRecord;
|
||||
import org.whispersystems.libsignal.groups.state.SenderKeyState;
|
||||
import org.whispersystems.libsignal.groups.state.SenderKeyStore;
|
||||
import org.whispersystems.libsignal.protocol.SenderKeyDistributionMessage;
|
||||
import org.whispersystems.libsignal.util.KeyHelper;
|
||||
|
||||
/**
|
||||
* GroupSessionBuilder is responsible for setting up group SenderKey encrypted sessions.
|
||||
*
|
||||
* Once a session has been established, {@link org.whispersystems.libaxolotl.groups.GroupCipher}
|
||||
* Once a session has been established, {@link org.whispersystems.libsignal.groups.GroupCipher}
|
||||
* can be used to encrypt/decrypt messages in that session.
|
||||
* <p>
|
||||
* The built sessions are unidirectional: they can be used either for sending or for receiving,
|
||||
@ -0,0 +1,52 @@
|
||||
/**
|
||||
* Copyright (C) 2014-2016 Open Whisper Systems
|
||||
*
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
package org.whispersystems.libsignal.groups;
|
||||
|
||||
import org.whispersystems.libsignal.SignalProtocolAddress;
|
||||
|
||||
/**
|
||||
* A representation of a (groupId + senderId + deviceId) tuple.
|
||||
*/
|
||||
public class SenderKeyName {
|
||||
|
||||
private final String groupId;
|
||||
private final SignalProtocolAddress sender;
|
||||
|
||||
public SenderKeyName(String groupId, SignalProtocolAddress sender) {
|
||||
this.groupId = groupId;
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
public String getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
public SignalProtocolAddress getSender() {
|
||||
return sender;
|
||||
}
|
||||
|
||||
public String serialize() {
|
||||
return groupId + "::" + sender.getName() + "::" + String.valueOf(sender.getDeviceId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (other == null) return false;
|
||||
if (!(other instanceof SenderKeyName)) return false;
|
||||
|
||||
SenderKeyName that = (SenderKeyName)other;
|
||||
|
||||
return
|
||||
this.groupId.equals(that.groupId) &&
|
||||
this.sender.equals(that.sender);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.groupId.hashCode() ^ this.sender.hashCode();
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,20 +1,9 @@
|
||||
/**
|
||||
* Copyright (C) 2014-2015 Open Whisper Systems
|
||||
* Copyright (C) 2014-2016 Open Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
package org.whispersystems.libaxolotl.groups.ratchet;
|
||||
package org.whispersystems.libsignal.groups.ratchet;
|
||||
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
@ -1,24 +1,13 @@
|
||||
/**
|
||||
* Copyright (C) 2014-2015 Open Whisper Systems
|
||||
* Copyright (C) 2014-2016 Open Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
|
||||
package org.whispersystems.libaxolotl.groups.ratchet;
|
||||
package org.whispersystems.libsignal.groups.ratchet;
|
||||
|
||||
import org.whispersystems.libaxolotl.kdf.HKDFv3;
|
||||
import org.whispersystems.libaxolotl.util.ByteUtil;
|
||||
import org.whispersystems.libsignal.kdf.HKDFv3;
|
||||
import org.whispersystems.libsignal.util.ByteUtil;
|
||||
|
||||
/**
|
||||
* The final symmetric material (IV and Cipher Key) used for encrypting
|
||||
@ -1,37 +1,26 @@
|
||||
/**
|
||||
* Copyright (C) 2014-2015 Open Whisper Systems
|
||||
* Copyright (C) 2014-2016 Open Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
package org.whispersystems.libaxolotl.groups.state;
|
||||
package org.whispersystems.libsignal.groups.state;
|
||||
|
||||
import org.whispersystems.libaxolotl.InvalidKeyIdException;
|
||||
import org.whispersystems.libaxolotl.ecc.ECKeyPair;
|
||||
import org.whispersystems.libaxolotl.ecc.ECPublicKey;
|
||||
import org.whispersystems.libaxolotl.state.StorageProtos;
|
||||
import org.whispersystems.libsignal.InvalidKeyIdException;
|
||||
import org.whispersystems.libsignal.ecc.ECKeyPair;
|
||||
import org.whispersystems.libsignal.ecc.ECPublicKey;
|
||||
import org.whispersystems.libsignal.state.StorageProtos;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.whispersystems.libaxolotl.state.StorageProtos.SenderKeyRecordStructure;
|
||||
import static org.whispersystems.libsignal.state.StorageProtos.SenderKeyRecordStructure;
|
||||
|
||||
/**
|
||||
* A durable representation of a set of SenderKeyStates for a specific
|
||||
* SenderKeyName.
|
||||
*
|
||||
* @author Moxie Marlisnpike
|
||||
* @author Moxie Marlinspike
|
||||
*/
|
||||
public class SenderKeyRecord {
|
||||
|
||||
@ -1,37 +1,26 @@
|
||||
/**
|
||||
* Copyright (C) 2014-2015 Open Whisper Systems
|
||||
* Copyright (C) 2014-2016 Open Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
package org.whispersystems.libaxolotl.groups.state;
|
||||
package org.whispersystems.libsignal.groups.state;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
|
||||
import org.whispersystems.libaxolotl.InvalidKeyException;
|
||||
import org.whispersystems.libaxolotl.ecc.Curve;
|
||||
import org.whispersystems.libaxolotl.ecc.ECKeyPair;
|
||||
import org.whispersystems.libaxolotl.ecc.ECPrivateKey;
|
||||
import org.whispersystems.libaxolotl.ecc.ECPublicKey;
|
||||
import org.whispersystems.libaxolotl.groups.ratchet.SenderChainKey;
|
||||
import org.whispersystems.libaxolotl.groups.ratchet.SenderMessageKey;
|
||||
import org.whispersystems.libaxolotl.util.guava.Optional;
|
||||
import org.whispersystems.libsignal.InvalidKeyException;
|
||||
import org.whispersystems.libsignal.ecc.Curve;
|
||||
import org.whispersystems.libsignal.ecc.ECKeyPair;
|
||||
import org.whispersystems.libsignal.ecc.ECPrivateKey;
|
||||
import org.whispersystems.libsignal.ecc.ECPublicKey;
|
||||
import org.whispersystems.libsignal.groups.ratchet.SenderChainKey;
|
||||
import org.whispersystems.libsignal.groups.ratchet.SenderMessageKey;
|
||||
import org.whispersystems.libsignal.util.guava.Optional;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.whispersystems.libaxolotl.state.StorageProtos.SenderKeyStateStructure;
|
||||
import static org.whispersystems.libsignal.state.StorageProtos.SenderKeyStateStructure;
|
||||
|
||||
/**
|
||||
* Represents the state of an individual SenderKey ratchet.
|
||||
@ -1,27 +1,16 @@
|
||||
/**
|
||||
* Copyright (C) 2014-2015 Open Whisper Systems
|
||||
* Copyright (C) 2014-2016 Open Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
package org.whispersystems.libaxolotl.groups.state;
|
||||
package org.whispersystems.libsignal.groups.state;
|
||||
|
||||
import org.whispersystems.libaxolotl.groups.SenderKeyName;
|
||||
import org.whispersystems.libsignal.groups.SenderKeyName;
|
||||
|
||||
public interface SenderKeyStore {
|
||||
|
||||
/**
|
||||
* Commit to storage the {@link org.whispersystems.libaxolotl.groups.state.SenderKeyRecord} for a
|
||||
* Commit to storage the {@link org.whispersystems.libsignal.groups.state.SenderKeyRecord} for a
|
||||
* given (groupId + senderId + deviceId) tuple.
|
||||
*
|
||||
* @param senderKeyName the (groupId + senderId + deviceId) tuple.
|
||||
@ -30,7 +19,7 @@ public interface SenderKeyStore {
|
||||
public void storeSenderKey(SenderKeyName senderKeyName, SenderKeyRecord record);
|
||||
|
||||
/**
|
||||
* Returns a copy of the {@link org.whispersystems.libaxolotl.groups.state.SenderKeyRecord}
|
||||
* Returns a copy of the {@link org.whispersystems.libsignal.groups.state.SenderKeyRecord}
|
||||
* corresponding to the (groupId + senderId + deviceId) tuple, or a new SenderKeyRecord if
|
||||
* one does not currently exist.
|
||||
* <p>
|
||||
@ -1,23 +1,12 @@
|
||||
/**
|
||||
* Copyright (C) 2014 Open Whisper Systems
|
||||
* Copyright (C) 2014-2016 Open Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
|
||||
package org.whispersystems.libaxolotl.kdf;
|
||||
package org.whispersystems.libsignal.kdf;
|
||||
|
||||
import org.whispersystems.libaxolotl.util.ByteUtil;
|
||||
import org.whispersystems.libsignal.util.ByteUtil;
|
||||
|
||||
import java.text.ParseException;
|
||||
|
||||
@ -1,6 +1,11 @@
|
||||
package org.whispersystems.libaxolotl.kdf;
|
||||
/**
|
||||
* Copyright (C) 2014-2016 Open Whisper Systems
|
||||
*
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
package org.whispersystems.libsignal.kdf;
|
||||
|
||||
import org.whispersystems.libaxolotl.util.ByteUtil;
|
||||
import org.whispersystems.libsignal.util.ByteUtil;
|
||||
|
||||
public class DerivedRootSecrets {
|
||||
|
||||
@ -1,21 +1,10 @@
|
||||
/**
|
||||
* Copyright (C) 2013 Open Whisper Systems
|
||||
* Copyright (C) 2013-2016 Open Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
|
||||
package org.whispersystems.libaxolotl.kdf;
|
||||
package org.whispersystems.libsignal.kdf;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.security.InvalidKeyException;
|
||||
@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Copyright (C) 2014-2016 Open Whisper Systems
|
||||
*
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
package org.whispersystems.libsignal.kdf;
|
||||
|
||||
public class HKDFv2 extends HKDF {
|
||||
@Override
|
||||
protected int getIterationStartOffset() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Copyright (C) 2014-2016 Open Whisper Systems
|
||||
*
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
package org.whispersystems.libsignal.kdf;
|
||||
|
||||
public class HKDFv3 extends HKDF {
|
||||
@Override
|
||||
protected int getIterationStartOffset() {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,9 @@
|
||||
package org.whispersystems.libaxolotl.logging;
|
||||
/**
|
||||
* Copyright (C) 2014-2016 Open Whisper Systems
|
||||
*
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
package org.whispersystems.libsignal.logging;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
@ -9,47 +14,47 @@ public class Log {
|
||||
private Log() {}
|
||||
|
||||
public static void v(String tag, String msg) {
|
||||
log(AxolotlLogger.VERBOSE, tag, msg);
|
||||
log(SignalProtocolLogger.VERBOSE, tag, msg);
|
||||
}
|
||||
|
||||
public static void v(String tag, String msg, Throwable tr) {
|
||||
log(AxolotlLogger.VERBOSE, tag, msg + '\n' + getStackTraceString(tr));
|
||||
log(SignalProtocolLogger.VERBOSE, tag, msg + '\n' + getStackTraceString(tr));
|
||||
}
|
||||
|
||||
public static void d(String tag, String msg) {
|
||||
log(AxolotlLogger.DEBUG, tag, msg);
|
||||
log(SignalProtocolLogger.DEBUG, tag, msg);
|
||||
}
|
||||
|
||||
public static void d(String tag, String msg, Throwable tr) {
|
||||
log(AxolotlLogger.DEBUG, tag, msg + '\n' + getStackTraceString(tr));
|
||||
log(SignalProtocolLogger.DEBUG, tag, msg + '\n' + getStackTraceString(tr));
|
||||
}
|
||||
|
||||
public static void i(String tag, String msg) {
|
||||
log(AxolotlLogger.INFO, tag, msg);
|
||||
log(SignalProtocolLogger.INFO, tag, msg);
|
||||
}
|
||||
|
||||
public static void i(String tag, String msg, Throwable tr) {
|
||||
log(AxolotlLogger.INFO, tag, msg + '\n' + getStackTraceString(tr));
|
||||
log(SignalProtocolLogger.INFO, tag, msg + '\n' + getStackTraceString(tr));
|
||||
}
|
||||
|
||||
public static void w(String tag, String msg) {
|
||||
log(AxolotlLogger.WARN, tag, msg);
|
||||
log(SignalProtocolLogger.WARN, tag, msg);
|
||||
}
|
||||
|
||||
public static void w(String tag, String msg, Throwable tr) {
|
||||
log(AxolotlLogger.WARN, tag, msg + '\n' + getStackTraceString(tr));
|
||||
log(SignalProtocolLogger.WARN, tag, msg + '\n' + getStackTraceString(tr));
|
||||
}
|
||||
|
||||
public static void w(String tag, Throwable tr) {
|
||||
log(AxolotlLogger.WARN, tag, getStackTraceString(tr));
|
||||
log(SignalProtocolLogger.WARN, tag, getStackTraceString(tr));
|
||||
}
|
||||
|
||||
public static void e(String tag, String msg) {
|
||||
log(AxolotlLogger.ERROR, tag, msg);
|
||||
log(SignalProtocolLogger.ERROR, tag, msg);
|
||||
}
|
||||
|
||||
public static void e(String tag, String msg, Throwable tr) {
|
||||
log(AxolotlLogger.ERROR, tag, msg + '\n' + getStackTraceString(tr));
|
||||
log(SignalProtocolLogger.ERROR, tag, msg + '\n' + getStackTraceString(tr));
|
||||
}
|
||||
|
||||
private static String getStackTraceString(Throwable tr) {
|
||||
@ -75,7 +80,7 @@ public class Log {
|
||||
}
|
||||
|
||||
private static void log(int priority, String tag, String msg) {
|
||||
AxolotlLogger logger = AxolotlLoggerProvider.getProvider();
|
||||
SignalProtocolLogger logger = SignalProtocolLoggerProvider.getProvider();
|
||||
|
||||
if (logger != null) {
|
||||
logger.log(priority, tag, msg);
|
||||
@ -1,6 +1,11 @@
|
||||
package org.whispersystems.libaxolotl.logging;
|
||||
/**
|
||||
* Copyright (C) 2014-2016 Open Whisper Systems
|
||||
*
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
package org.whispersystems.libsignal.logging;
|
||||
|
||||
public interface AxolotlLogger {
|
||||
public interface SignalProtocolLogger {
|
||||
|
||||
public static final int VERBOSE = 2;
|
||||
public static final int DEBUG = 3;
|
||||
@ -0,0 +1,19 @@
|
||||
/**
|
||||
* Copyright (C) 2014-2016 Open Whisper Systems
|
||||
*
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
package org.whispersystems.libsignal.logging;
|
||||
|
||||
public class SignalProtocolLoggerProvider {
|
||||
|
||||
private static SignalProtocolLogger provider;
|
||||
|
||||
public static SignalProtocolLogger getProvider() {
|
||||
return provider;
|
||||
}
|
||||
|
||||
public static void setProvider(SignalProtocolLogger provider) {
|
||||
SignalProtocolLoggerProvider.provider = provider;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Copyright (C) 2014-2016 Open Whisper Systems
|
||||
*
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
package org.whispersystems.libsignal.protocol;
|
||||
|
||||
public interface CiphertextMessage {
|
||||
|
||||
public static final int CURRENT_VERSION = 3;
|
||||
|
||||
public static final int WHISPER_TYPE = 2;
|
||||
public static final int PREKEY_TYPE = 3;
|
||||
public static final int SENDERKEY_TYPE = 4;
|
||||
public static final int SENDERKEY_DISTRIBUTION_TYPE = 5;
|
||||
|
||||
// This should be the worst case (worse than V2). So not always accurate, but good enough for padding.
|
||||
public static final int ENCRYPTED_MESSAGE_OVERHEAD = 53;
|
||||
|
||||
public byte[] serialize();
|
||||
public int getType();
|
||||
|
||||
}
|
||||
@ -0,0 +1,62 @@
|
||||
package org.whispersystems.libsignal.protocol;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
|
||||
import org.whispersystems.curve25519.VrfSignatureVerificationFailedException;
|
||||
import org.whispersystems.libsignal.IdentityKey;
|
||||
import org.whispersystems.libsignal.IdentityKeyPair;
|
||||
import org.whispersystems.libsignal.InvalidKeyException;
|
||||
import org.whispersystems.libsignal.InvalidMessageException;
|
||||
import org.whispersystems.libsignal.devices.DeviceConsistencyCommitment;
|
||||
import org.whispersystems.libsignal.devices.DeviceConsistencySignature;
|
||||
import org.whispersystems.libsignal.ecc.Curve;
|
||||
|
||||
public class DeviceConsistencyMessage {
|
||||
|
||||
private final DeviceConsistencySignature signature;
|
||||
private final int generation;
|
||||
private final byte[] serialized;
|
||||
|
||||
public DeviceConsistencyMessage(DeviceConsistencyCommitment commitment, IdentityKeyPair identityKeyPair) {
|
||||
try {
|
||||
byte[] signatureBytes = Curve.calculateVrfSignature(identityKeyPair.getPrivateKey(), commitment.toByteArray());
|
||||
byte[] vrfOutputBytes = Curve.verifyVrfSignature(identityKeyPair.getPublicKey().getPublicKey(), commitment.toByteArray(), signatureBytes);
|
||||
|
||||
this.generation = commitment.getGeneration();
|
||||
this.signature = new DeviceConsistencySignature(signatureBytes, vrfOutputBytes);
|
||||
this.serialized = SignalProtos.DeviceConsistencyCodeMessage.newBuilder()
|
||||
.setGeneration(commitment.getGeneration())
|
||||
.setSignature(ByteString.copyFrom(signature.getSignature()))
|
||||
.build()
|
||||
.toByteArray();
|
||||
} catch (InvalidKeyException | VrfSignatureVerificationFailedException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
public DeviceConsistencyMessage(DeviceConsistencyCommitment commitment, byte[] serialized, IdentityKey identityKey) throws InvalidMessageException {
|
||||
try {
|
||||
SignalProtos.DeviceConsistencyCodeMessage message = SignalProtos.DeviceConsistencyCodeMessage.parseFrom(serialized);
|
||||
byte[] vrfOutputBytes = Curve.verifyVrfSignature(identityKey.getPublicKey(), commitment.toByteArray(), message.getSignature().toByteArray());
|
||||
|
||||
this.generation = message.getGeneration();
|
||||
this.signature = new DeviceConsistencySignature(message.getSignature().toByteArray(), vrfOutputBytes);
|
||||
this.serialized = serialized;
|
||||
} catch (InvalidProtocolBufferException | InvalidKeyException | VrfSignatureVerificationFailedException e) {
|
||||
throw new InvalidMessageException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] getSerialized() {
|
||||
return serialized;
|
||||
}
|
||||
|
||||
public DeviceConsistencySignature getSignature() {
|
||||
return signature;
|
||||
}
|
||||
|
||||
public int getGeneration() {
|
||||
return generation;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,139 @@
|
||||
/**
|
||||
* Copyright (C) 2014-2016 Open Whisper Systems
|
||||
*
|
||||
* Licensed according to the LICENSE file in this repository.
|
||||
*/
|
||||
package org.whispersystems.libsignal.protocol;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
|
||||
import org.whispersystems.libsignal.IdentityKey;
|
||||
import org.whispersystems.libsignal.InvalidKeyException;
|
||||
import org.whispersystems.libsignal.InvalidMessageException;
|
||||
import org.whispersystems.libsignal.InvalidVersionException;
|
||||
import org.whispersystems.libsignal.LegacyMessageException;
|
||||
import org.whispersystems.libsignal.ecc.Curve;
|
||||
import org.whispersystems.libsignal.ecc.ECPublicKey;
|
||||
import org.whispersystems.libsignal.util.ByteUtil;
|
||||
import org.whispersystems.libsignal.util.guava.Optional;
|
||||
|
||||
|
||||
public class PreKeySignalMessage implements CiphertextMessage {
|
||||
|
||||
private final int version;
|
||||
private final int registrationId;
|
||||
private final Optional<Integer> preKeyId;
|
||||
private final int signedPreKeyId;
|
||||
private final ECPublicKey baseKey;
|
||||
private final IdentityKey identityKey;
|
||||
private final SignalMessage message;
|
||||
private final byte[] serialized;
|
||||
|
||||
public PreKeySignalMessage(byte[] serialized)
|
||||
throws InvalidMessageException, InvalidVersionException
|
||||
{
|
||||
try {
|
||||
this.version = ByteUtil.highBitsToInt(serialized[0]);
|
||||
|
||||
if (this.version > CiphertextMessage.CURRENT_VERSION) {
|
||||
throw new InvalidVersionException("Unknown version: " + this.version);
|
||||
}
|
||||
|
||||
if (this.version < CiphertextMessage.CURRENT_VERSION) {
|
||||
throw new LegacyMessageException("Legacy version: " + this.version);
|
||||
}
|
||||
|
||||
SignalProtos.PreKeySignalMessage preKeyWhisperMessage
|
||||
= SignalProtos.PreKeySignalMessage.parseFrom(ByteString.copyFrom(serialized, 1,
|
||||
serialized.length-1));
|
||||
|
||||
if (!preKeyWhisperMessage.hasSignedPreKeyId() ||
|
||||
!preKeyWhisperMessage.hasBaseKey() ||
|
||||
!preKeyWhisperMessage.hasIdentityKey() ||
|
||||
!preKeyWhisperMessage.hasMessage())
|
||||
{
|
||||
throw new InvalidMessageException("Incomplete message.");
|
||||
}
|
||||
|
||||
this.serialized = serialized;
|
||||
this.registrationId = preKeyWhisperMessage.getRegistrationId();
|
||||
this.preKeyId = preKeyWhisperMessage.hasPreKeyId() ? Optional.of(preKeyWhisperMessage.getPreKeyId()) : Optional.<Integer>absent();
|
||||
this.signedPreKeyId = preKeyWhisperMessage.hasSignedPreKeyId() ? preKeyWhisperMessage.getSignedPreKeyId() : -1;
|
||||
this.baseKey = Curve.decodePoint(preKeyWhisperMessage.getBaseKey().toByteArray(), 0);
|
||||
this.identityKey = new IdentityKey(Curve.decodePoint(preKeyWhisperMessage.getIdentityKey().toByteArray(), 0));
|
||||
this.message = new SignalMessage(preKeyWhisperMessage.getMessage().toByteArray());
|
||||
} catch (InvalidProtocolBufferException | InvalidKeyException | LegacyMessageException e) {
|
||||
throw new InvalidMessageException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public PreKeySignalMessage(int messageVersion, int registrationId, Optional<Integer> preKeyId,
|
||||
int signedPreKeyId, ECPublicKey baseKey, IdentityKey identityKey,
|
||||
SignalMessage message)
|
||||
{
|
||||
this.version = messageVersion;
|
||||
this.registrationId = registrationId;
|
||||
this.preKeyId = preKeyId;
|
||||
this.signedPreKeyId = signedPreKeyId;
|
||||
this.baseKey = baseKey;
|
||||
this.identityKey = identityKey;
|
||||
this.message = message;
|
||||
|
||||
SignalProtos.PreKeySignalMessage.Builder builder =
|
||||
SignalProtos.PreKeySignalMessage.newBuilder()
|
||||
.setSignedPreKeyId(signedPreKeyId)
|
||||
.setBaseKey(ByteString.copyFrom(baseKey.serialize()))
|
||||
.setIdentityKey(ByteString.copyFrom(identityKey.serialize()))
|
||||
.setMessage(ByteString.copyFrom(message.serialize()))
|
||||
.setRegistrationId(registrationId);
|
||||
|
||||
if (preKeyId.isPresent()) {
|
||||
builder.setPreKeyId(preKeyId.get());
|
||||
}
|
||||
|
||||
byte[] versionBytes = {ByteUtil.intsToByteHighAndLow(this.version, CURRENT_VERSION)};
|
||||
byte[] messageBytes = builder.build().toByteArray();
|
||||
|
||||
this.serialized = ByteUtil.combine(versionBytes, messageBytes);
|
||||
}
|
||||
|
||||
public int getMessageVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public IdentityKey getIdentityKey() {
|
||||
return identityKey;
|
||||
}
|
||||
|
||||
public int getRegistrationId() {
|
||||
return registrationId;
|
||||
}
|
||||
|
||||
public Optional<Integer> getPreKeyId() {
|
||||
return preKeyId;
|
||||
}
|
||||
|
||||
public int getSignedPreKeyId() {
|
||||
return signedPreKeyId;
|
||||
}
|
||||
|
||||
public ECPublicKey getBaseKey() {
|
||||
return baseKey;
|
||||
}
|
||||
|
||||
public SignalMessage getWhisperMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] serialize() {
|
||||
return serialized;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return CiphertextMessage.PREKEY_TYPE;
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user