Compare commits
76 commits
f9185b5969
...
244f45d6c6
Author | SHA1 | Date | |
---|---|---|---|
244f45d6c6 | |||
66d2cd7907 | |||
86f18b577a | |||
c0a1aec7f7 | |||
458d1bd9f9 | |||
e723528eb8 | |||
c4cd5ee352 | |||
b6829ff2b5 | |||
54b401b944 | |||
99e811086c | |||
a11c8b463f | |||
df96d894a8 | |||
3be5cd104d | |||
97f2c17282 | |||
9806c317e9 | |||
7aafd0334e | |||
7fc4815b15 | |||
f02109bdc9 | |||
919f75b8ee | |||
20df727b83 | |||
340f2a3c75 | |||
9a6f37aa05 | |||
f3f6cf973f | |||
0618ecc00f | |||
e1b61e631f | |||
f51ea0bd78 | |||
d127393402 | |||
c3b1ee799a | |||
d47251c251 | |||
2967c87990 | |||
9c8945141c | |||
76a343a36d | |||
a433ad2593 | |||
e89833f20e | |||
7ec1125b3f | |||
4cdabf6603 | |||
938c558cdc | |||
1d6820a4f1 | |||
86050e2201 | |||
0bc51a9917 | |||
a842818175 | |||
81b3dcf3ea | |||
8cd3b381cf | |||
1c48fcd35e | |||
b29f3ed1e2 | |||
eadf1cd3a4 | |||
50c638b534 | |||
f01df7b4c4 | |||
5be20b0e70 | |||
d5e540789b | |||
c5d0e185c3 | |||
![]() |
b0ce6109d7 | ||
![]() |
0efc7f3666 | ||
![]() |
5fbea63320 | ||
![]() |
fa9352d938 | ||
![]() |
4f35485005 | ||
![]() |
4e79783617 | ||
![]() |
fa248abdbf | ||
![]() |
83a8217b26 | ||
![]() |
6be9e90ceb | ||
![]() |
ea3a070d13 | ||
![]() |
0ff277ed4c | ||
![]() |
7165734aef | ||
![]() |
724b2ae472 | ||
![]() |
bc05135566 | ||
![]() |
b11db4f3ae | ||
![]() |
90756b49a1 | ||
![]() |
78c5a22c15 | ||
![]() |
5109796f76 | ||
![]() |
ba99c62e6a | ||
![]() |
43b62ee1c9 | ||
![]() |
6580c2a748 | ||
![]() |
824eed83f2 | ||
![]() |
fcabcd91dc | ||
![]() |
d0ac2a909b | ||
![]() |
15caf5e4dc |
70 changed files with 2062 additions and 941 deletions
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. <https://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The GNU 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 <https://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:
|
||||||
|
|
||||||
|
Socialbox-PHP Copyright (C) 2022-2025 Nosial
|
||||||
|
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
|
||||||
|
<https://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
|
||||||
|
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
3
README.md
Normal file
3
README.md
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# Socialbox-PHP
|
||||||
|
|
||||||
|
Documentation coming soon.
|
|
@ -1,90 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Socialbox\Abstracts;
|
|
||||||
|
|
||||||
use RuntimeException;
|
|
||||||
use Socialbox\Classes\CacheLayer\MemcachedCacheLayer;
|
|
||||||
use Socialbox\Classes\CacheLayer\RedisCacheLayer;
|
|
||||||
use Socialbox\Classes\Configuration;
|
|
||||||
|
|
||||||
abstract class CacheLayer
|
|
||||||
{
|
|
||||||
private static ?CacheLayer $instance = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stores a value in the cache with an associated key and an optional time-to-live (TTL).
|
|
||||||
*
|
|
||||||
* @param string $key The key under which the value is stored.
|
|
||||||
* @param mixed $value The value to be stored.
|
|
||||||
* @param int $ttl Optional. The time-to-live for the cache entry in seconds. A value of 0 indicates no expiration.
|
|
||||||
* @return bool Returns true if the value was successfully set, false otherwise.
|
|
||||||
*/
|
|
||||||
public abstract function set(string $key, mixed $value, int $ttl=0): bool;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves a value from the cache with the specified key.
|
|
||||||
*
|
|
||||||
* @param string $key The key of the value to retrieve.
|
|
||||||
* @return mixed The value associated with the key, or null if the key does not exist.
|
|
||||||
*/
|
|
||||||
public abstract function get(string $key): mixed;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Deletes a value from the cache with the specified key.
|
|
||||||
*
|
|
||||||
* @param string $key The key of the value to delete.
|
|
||||||
* @return bool Returns true if the value was successfully deleted, false otherwise.
|
|
||||||
*/
|
|
||||||
public abstract function delete(string $key): bool;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if a value exists in the cache with the specified key.
|
|
||||||
*
|
|
||||||
* @param string $key The key to check.
|
|
||||||
* @return bool Returns true if the key exists, false otherwise.
|
|
||||||
*/
|
|
||||||
public abstract function exists(string $key): bool;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Counts the number of items that start with the given prefix.
|
|
||||||
*
|
|
||||||
* @param string $prefix The prefix to search for.
|
|
||||||
* @return int The count of items starting with the provided prefix.
|
|
||||||
*/
|
|
||||||
public abstract function getPrefixCount(string $prefix): int;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clears all values from the cache.
|
|
||||||
*
|
|
||||||
* @return bool Returns true if the cache was successfully cleared, false otherwise.
|
|
||||||
*/
|
|
||||||
public abstract function clear(): bool;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves the singleton instance of the cache layer.
|
|
||||||
*
|
|
||||||
* @return CacheLayer The singleton instance of the cache layer.
|
|
||||||
*/
|
|
||||||
public static function getInstance(): CacheLayer
|
|
||||||
{
|
|
||||||
if (self::$instance === null)
|
|
||||||
{
|
|
||||||
$engine = Configuration::getCacheConfiguration()->getEngine();
|
|
||||||
|
|
||||||
if ($engine === 'redis')
|
|
||||||
{
|
|
||||||
self::$instance = new RedisCacheLayer();
|
|
||||||
}
|
|
||||||
else if ($engine === 'memcached')
|
|
||||||
{
|
|
||||||
self::$instance = new MemcachedCacheLayer();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new RuntimeException('Invalid cache engine specified in the configuration, must be either "redis" or "memcached".');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return self::$instance;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,18 +1,53 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Socialbox\Classes;
|
namespace Socialbox\Classes;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use Redis;
|
||||||
|
|
||||||
class CacheLayer
|
class CacheLayer
|
||||||
{
|
|
||||||
private static CacheLayer $instance;
|
|
||||||
|
|
||||||
public static function getInstance(): CacheLayer
|
|
||||||
{
|
{
|
||||||
if (!isset(self::$instance))
|
private static ?Redis $instance = null;
|
||||||
{
|
|
||||||
self::$instance = new CacheLayer();
|
|
||||||
}
|
|
||||||
|
|
||||||
return self::$instance;
|
/**
|
||||||
}
|
* Get the Redis instance, returns null if caching is turned off or there was an error connecting
|
||||||
}
|
* to the Redis server.
|
||||||
|
*
|
||||||
|
* @return Redis|null
|
||||||
|
*/
|
||||||
|
public static function getInstance(): ?Redis
|
||||||
|
{
|
||||||
|
// Return null if caching is turned off
|
||||||
|
if(!Configuration::getCacheConfiguration()->isEnabled())
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (self::$instance === null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
self::$instance = new Redis();
|
||||||
|
self::$instance->connect(
|
||||||
|
Configuration::getCacheConfiguration()->getHost(),
|
||||||
|
Configuration::getCacheConfiguration()->getPort()
|
||||||
|
);
|
||||||
|
|
||||||
|
if(Configuration::getCacheConfiguration()->getPassword() !== null)
|
||||||
|
{
|
||||||
|
self::$instance->auth(Configuration::getCacheConfiguration()->getPassword());
|
||||||
|
}
|
||||||
|
|
||||||
|
self::$instance->select(Configuration::getCacheConfiguration()->getDatabase());
|
||||||
|
}
|
||||||
|
catch (Exception $e)
|
||||||
|
{
|
||||||
|
self::$instance = null;
|
||||||
|
Logger::getLogger()->critical($e->getMessage(), $e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return self::$instance;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,113 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Socialbox\Classes\CacheLayer;
|
|
||||||
|
|
||||||
use Memcached;
|
|
||||||
use RuntimeException;
|
|
||||||
use Socialbox\Abstracts\CacheLayer;
|
|
||||||
use Socialbox\Classes\Configuration;
|
|
||||||
|
|
||||||
class MemcachedCacheLayer extends CacheLayer
|
|
||||||
{
|
|
||||||
private Memcached $memcached;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Memcached cache layer constructor.
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
if (!extension_loaded('memcached'))
|
|
||||||
{
|
|
||||||
throw new RuntimeException('The Memcached extension is not loaded in your PHP environment.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->memcached = new Memcached();
|
|
||||||
$this->memcached->addServer(Configuration::getCacheConfiguration()->getHost(), Configuration::getCacheConfiguration()->getPort());
|
|
||||||
if(Configuration::getCacheConfiguration()->getUsername() !== null || Configuration::getCacheConfiguration()->getPassword() !== null)
|
|
||||||
{
|
|
||||||
$this->memcached->setSaslAuthData(Configuration::getCacheConfiguration()->getUsername(), Configuration::getCacheConfiguration()->getPassword());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
public function set(string $key, mixed $value, int $ttl = 0): bool
|
|
||||||
{
|
|
||||||
if (!$this->memcached->set($key, $value, $ttl))
|
|
||||||
{
|
|
||||||
throw new RuntimeException('Failed to set the value in the Memcached cache.');
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
public function get(string $key): mixed
|
|
||||||
{
|
|
||||||
$result = $this->memcached->get($key);
|
|
||||||
|
|
||||||
if ($this->memcached->getResultCode() !== Memcached::RES_SUCCESS)
|
|
||||||
{
|
|
||||||
throw new RuntimeException('Failed to get the value from the Memcached cache.');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
public function delete(string $key): bool
|
|
||||||
{
|
|
||||||
if (!$this->memcached->delete($key) && $this->memcached->getResultCode() !== Memcached::RES_NOTFOUND)
|
|
||||||
{
|
|
||||||
throw new RuntimeException('Failed to delete the value from the Memcached cache.');
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
public function exists(string $key): bool
|
|
||||||
{
|
|
||||||
$this->memcached->get($key);
|
|
||||||
return $this->memcached->getResultCode() === Memcached::RES_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
public function getPrefixCount(string $prefix): int
|
|
||||||
{
|
|
||||||
$stats = $this->memcached->getStats();
|
|
||||||
$count = 0;
|
|
||||||
|
|
||||||
foreach ($stats as $server => $data)
|
|
||||||
{
|
|
||||||
if (str_starts_with($server, $prefix))
|
|
||||||
{
|
|
||||||
$count += $data['curr_items'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $count;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
public function clear(): bool
|
|
||||||
{
|
|
||||||
if (!$this->memcached->flush())
|
|
||||||
{
|
|
||||||
throw new RuntimeException('Failed to clear the Memcached cache.');
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,135 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Socialbox\Classes\CacheLayer;
|
|
||||||
|
|
||||||
use Redis;
|
|
||||||
use RedisException;
|
|
||||||
use RuntimeException;
|
|
||||||
use Socialbox\Abstracts\CacheLayer;
|
|
||||||
use Socialbox\Classes\Configuration;
|
|
||||||
|
|
||||||
class RedisCacheLayer extends CacheLayer
|
|
||||||
{
|
|
||||||
private Redis $redis;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Redis cache layer constructor.
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
if (!extension_loaded('redis'))
|
|
||||||
{
|
|
||||||
throw new RuntimeException('The Redis extension is not loaded in your PHP environment.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->redis = new Redis();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
$this->redis->connect(Configuration::getCacheConfiguration()->getHost(), Configuration::getCacheConfiguration()->getPort());
|
|
||||||
if (Configuration::getCacheConfiguration()->getPassword() !== null)
|
|
||||||
{
|
|
||||||
$this->redis->auth(Configuration::getCacheConfiguration()->getPassword());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Configuration::getCacheConfiguration()->getDatabase() !== null)
|
|
||||||
{
|
|
||||||
$this->redis->select(Configuration::getCacheConfiguration()->getDatabase());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (RedisException $e)
|
|
||||||
{
|
|
||||||
throw new RuntimeException('Failed to connect to the Redis server.', 0, $e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
public function set(string $key, mixed $value, int $ttl = 0): bool
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return $this->redis->set($key, $value, $ttl);
|
|
||||||
}
|
|
||||||
catch (RedisException $e)
|
|
||||||
{
|
|
||||||
throw new RuntimeException('Failed to set the value in the Redis cache.', 0, $e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
public function get(string $key): mixed
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return $this->redis->get($key);
|
|
||||||
}
|
|
||||||
catch (RedisException $e)
|
|
||||||
{
|
|
||||||
throw new RuntimeException('Failed to get the value from the Redis cache.', 0, $e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
public function delete(string $key): bool
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return $this->redis->del($key) > 0;
|
|
||||||
}
|
|
||||||
catch (RedisException $e)
|
|
||||||
{
|
|
||||||
throw new RuntimeException('Failed to delete the value from the Redis cache.', 0, $e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
public function exists(string $key): bool
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return $this->redis->exists($key);
|
|
||||||
}
|
|
||||||
catch (RedisException $e)
|
|
||||||
{
|
|
||||||
throw new RuntimeException('Failed to check if the key exists in the Redis cache.', 0, $e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
public function getPrefixCount(string $prefix): int
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return count($this->redis->keys($prefix . '*'));
|
|
||||||
}
|
|
||||||
catch (RedisException $e)
|
|
||||||
{
|
|
||||||
throw new RuntimeException('Failed to get the count of keys with the specified prefix in the Redis cache.', 0, $e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
public function clear(): bool
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return $this->redis->flushAll();
|
|
||||||
}
|
|
||||||
catch (RedisException $e)
|
|
||||||
{
|
|
||||||
throw new RuntimeException('Failed to clear the Redis cache.', 0, $e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -109,7 +109,6 @@
|
||||||
|
|
||||||
// Cache layer configuration
|
// Cache layer configuration
|
||||||
$config->setDefault('cache.enabled', false);
|
$config->setDefault('cache.enabled', false);
|
||||||
$config->setDefault('cache.engine', 'redis');
|
|
||||||
$config->setDefault('cache.host', '127.0.0.1');
|
$config->setDefault('cache.host', '127.0.0.1');
|
||||||
$config->setDefault('cache.port', 6379);
|
$config->setDefault('cache.port', 6379);
|
||||||
$config->setDefault('cache.username', null);
|
$config->setDefault('cache.username', null);
|
||||||
|
@ -170,6 +169,7 @@
|
||||||
$config->setDefault('policies.get_encryption_channels_limit', 100);
|
$config->setDefault('policies.get_encryption_channels_limit', 100);
|
||||||
$config->setDefault('policies.get_encryption_channel_incoming_limit', 100);
|
$config->setDefault('policies.get_encryption_channel_incoming_limit', 100);
|
||||||
$config->setDefault('policies.get_encryption_channel_outgoing_limit', 100);
|
$config->setDefault('policies.get_encryption_channel_outgoing_limit', 100);
|
||||||
|
$config->setDefault('policies.encryption_channel_max_messages', 100);
|
||||||
|
|
||||||
// Default privacy states for information fields associated with the peer
|
// Default privacy states for information fields associated with the peer
|
||||||
$config->setDefault('policies.default_display_picture_privacy', 'PUBLIC');
|
$config->setDefault('policies.default_display_picture_privacy', 'PUBLIC');
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
class CacheConfiguration
|
class CacheConfiguration
|
||||||
{
|
{
|
||||||
private bool $enabled;
|
private bool $enabled;
|
||||||
private string $engine;
|
|
||||||
private string $host;
|
private string $host;
|
||||||
private int $port;
|
private int $port;
|
||||||
private ?string $username;
|
private ?string $username;
|
||||||
|
@ -38,7 +37,6 @@
|
||||||
public function __construct(array $data)
|
public function __construct(array $data)
|
||||||
{
|
{
|
||||||
$this->enabled = (bool)$data['enabled'];
|
$this->enabled = (bool)$data['enabled'];
|
||||||
$this->engine = (string)$data['engine'];
|
|
||||||
$this->host = (string)$data['host'];
|
$this->host = (string)$data['host'];
|
||||||
$this->port = (int)$data['port'];
|
$this->port = (int)$data['port'];
|
||||||
$this->username = $data['username'] ? (string)$data['username'] : null;
|
$this->username = $data['username'] ? (string)$data['username'] : null;
|
||||||
|
@ -59,16 +57,6 @@
|
||||||
return $this->enabled;
|
return $this->enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves the engine name.
|
|
||||||
*
|
|
||||||
* @return string Returns the name of the engine.
|
|
||||||
*/
|
|
||||||
public function getEngine(): string
|
|
||||||
{
|
|
||||||
return $this->engine;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the host value.
|
* Retrieves the host value.
|
||||||
*
|
*
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
private int $getEncryptionChannelsLimit;
|
private int $getEncryptionChannelsLimit;
|
||||||
private int $getEncryptionChannelIncomingLimit;
|
private int $getEncryptionChannelIncomingLimit;
|
||||||
private int $getEncryptionChannelOutgoingLimit;
|
private int $getEncryptionChannelOutgoingLimit;
|
||||||
|
private int $encryptionChannelMaxMessages;
|
||||||
private PrivacyState $defaultDisplayPicturePrivacy;
|
private PrivacyState $defaultDisplayPicturePrivacy;
|
||||||
private PrivacyState $defaultFirstNamePrivacy;
|
private PrivacyState $defaultFirstNamePrivacy;
|
||||||
private PrivacyState $defaultMiddleNamePrivacy;
|
private PrivacyState $defaultMiddleNamePrivacy;
|
||||||
|
@ -51,6 +52,7 @@
|
||||||
$this->getEncryptionChannelsLimit = $data['get_encryption_channels_limit'];
|
$this->getEncryptionChannelsLimit = $data['get_encryption_channels_limit'];
|
||||||
$this->getEncryptionChannelIncomingLimit = $data['get_encryption_channel_incoming_limit'];
|
$this->getEncryptionChannelIncomingLimit = $data['get_encryption_channel_incoming_limit'];
|
||||||
$this->getEncryptionChannelOutgoingLimit = $data['get_encryption_channel_outgoing_limit'];
|
$this->getEncryptionChannelOutgoingLimit = $data['get_encryption_channel_outgoing_limit'];
|
||||||
|
$this->encryptionChannelMaxMessages = $data['encryption_channel_max_messages'];
|
||||||
$this->defaultDisplayPicturePrivacy = PrivacyState::tryFrom($data['default_display_picture_privacy']) ?? PrivacyState::PRIVATE;
|
$this->defaultDisplayPicturePrivacy = PrivacyState::tryFrom($data['default_display_picture_privacy']) ?? PrivacyState::PRIVATE;
|
||||||
$this->defaultFirstNamePrivacy = PrivacyState::tryFrom($data['default_first_name_privacy']) ?? PrivacyState::PRIVATE;
|
$this->defaultFirstNamePrivacy = PrivacyState::tryFrom($data['default_first_name_privacy']) ?? PrivacyState::PRIVATE;
|
||||||
$this->defaultMiddleNamePrivacy = PrivacyState::tryFrom($data['default_middle_name_privacy']) ?? PrivacyState::PRIVATE;
|
$this->defaultMiddleNamePrivacy = PrivacyState::tryFrom($data['default_middle_name_privacy']) ?? PrivacyState::PRIVATE;
|
||||||
|
@ -158,6 +160,16 @@
|
||||||
return $this->getEncryptionChannelOutgoingLimit;
|
return $this->getEncryptionChannelOutgoingLimit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the maximum number of messages that can be stored in an encryption channel
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getEncryptionChannelMaxMessages(): int
|
||||||
|
{
|
||||||
|
return $this->encryptionChannelMaxMessages;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the default privacy state for the display picture
|
* Returns the default privacy state for the display picture
|
||||||
*
|
*
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use Socialbox\Abstracts\Method;
|
use Socialbox\Abstracts\Method;
|
||||||
|
use Socialbox\Enums\ReservedUsernames;
|
||||||
use Socialbox\Enums\StandardError;
|
use Socialbox\Enums\StandardError;
|
||||||
use Socialbox\Enums\Types\ContactRelationshipType;
|
use Socialbox\Enums\Types\ContactRelationshipType;
|
||||||
use Socialbox\Exceptions\DatabaseOperationException;
|
use Socialbox\Exceptions\DatabaseOperationException;
|
||||||
|
@ -32,14 +33,7 @@
|
||||||
throw new MissingRpcArgumentException('peer');
|
throw new MissingRpcArgumentException('peer');
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
$peerAddress = PeerAddress::fromAddress($rpcRequest->getParameter('peer'));
|
||||||
{
|
|
||||||
$address = PeerAddress::fromAddress($rpcRequest->getParameter('peer'));
|
|
||||||
}
|
|
||||||
catch(InvalidArgumentException $e)
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('peer', $e);
|
|
||||||
}
|
|
||||||
|
|
||||||
if($rpcRequest->containsParameter('relationship') && $rpcRequest->getParameter('relationship') !== null)
|
if($rpcRequest->containsParameter('relationship') && $rpcRequest->getParameter('relationship') !== null)
|
||||||
{
|
{
|
||||||
|
@ -57,22 +51,26 @@
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$peer = $request->getPeer();
|
$peer = $request->getPeer();
|
||||||
if($peer->getAddress() == $address)
|
if($peer->getAddress() == $peerAddress)
|
||||||
{
|
{
|
||||||
return $rpcRequest->produceError(StandardError::FORBIDDEN, 'Cannot add self as contact');
|
return $rpcRequest->produceError(StandardError::FORBIDDEN, 'Cannot add self as contact');
|
||||||
}
|
}
|
||||||
|
elseif($peer->getUsername() === ReservedUsernames::HOST->value)
|
||||||
|
{
|
||||||
|
return $rpcRequest->produceError(StandardError::FORBIDDEN, 'Cannot add host as contact');
|
||||||
|
}
|
||||||
|
|
||||||
// Resolve the peer, this would throw a StandardException if something goes wrong
|
// Resolve the peer, this would throw a StandardException if something goes wrong
|
||||||
Socialbox::resolvePeer($address);
|
Socialbox::resolvePeer($peerAddress);
|
||||||
|
|
||||||
// Check if the contact already exists
|
// Check if the contact already exists
|
||||||
if(ContactManager::isContact($peer, $address))
|
if(ContactManager::isContact($peer, $peerAddress))
|
||||||
{
|
{
|
||||||
return $rpcRequest->produceResponse(false);
|
return $rpcRequest->produceResponse(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the contact
|
// Create the contact
|
||||||
ContactManager::createContact($peer, $address, $relationship);
|
ContactManager::createContact($peer, $peerAddress, $relationship);
|
||||||
}
|
}
|
||||||
catch (DatabaseOperationException $e)
|
catch (DatabaseOperationException $e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -29,19 +29,12 @@
|
||||||
throw new MissingRpcArgumentException('peer');
|
throw new MissingRpcArgumentException('peer');
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
$peerAddress = PeerAddress::fromAddress($rpcRequest->getParameter('peer'));
|
||||||
{
|
|
||||||
$address = PeerAddress::fromAddress($rpcRequest->getParameter('peer'));
|
|
||||||
}
|
|
||||||
catch(InvalidArgumentException $e)
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('peer', $e);
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$peer = $request->getPeer();
|
$peer = $request->getPeer();
|
||||||
return $rpcRequest->produceResponse(ContactManager::isContact($peer, $address));
|
return $rpcRequest->produceResponse(ContactManager::isContact($peer, $peerAddress));
|
||||||
}
|
}
|
||||||
catch (DatabaseOperationException $e)
|
catch (DatabaseOperationException $e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -30,26 +30,19 @@
|
||||||
throw new MissingRpcArgumentException('peer');
|
throw new MissingRpcArgumentException('peer');
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
$peerAddress = PeerAddress::fromAddress($rpcRequest->getParameter('peer'));
|
||||||
{
|
|
||||||
$address = PeerAddress::fromAddress($rpcRequest->getParameter('peer'));
|
|
||||||
}
|
|
||||||
catch(InvalidArgumentException $e)
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('peer', $e);
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Check if the contact already exists
|
// Check if the contact already exists
|
||||||
$peer = $request->getPeer();
|
$peer = $request->getPeer();
|
||||||
if(!ContactManager::isContact($peer, $address))
|
if(!ContactManager::isContact($peer, $peerAddress))
|
||||||
{
|
{
|
||||||
return $rpcRequest->produceResponse(false);
|
return $rpcRequest->produceResponse(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the contact
|
// Create the contact
|
||||||
ContactManager::deleteContact($peer, $address);
|
ContactManager::deleteContact($peer, $peerAddress);
|
||||||
}
|
}
|
||||||
catch (DatabaseOperationException $e)
|
catch (DatabaseOperationException $e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -29,24 +29,16 @@
|
||||||
throw new MissingRpcArgumentException('peer');
|
throw new MissingRpcArgumentException('peer');
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
$peerAddress = PeerAddress::fromAddress($rpcRequest->getParameter('peer'));
|
||||||
{
|
|
||||||
$address = PeerAddress::fromAddress($rpcRequest->getParameter('peer'));
|
|
||||||
}
|
|
||||||
catch(InvalidArgumentException $e)
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('peer', $e);
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if(!ContactManager::isContact($request->getPeer(), $address))
|
if(!ContactManager::isContact($request->getPeer(), $peerAddress))
|
||||||
{
|
{
|
||||||
// Return empty response if the contact does not exist
|
|
||||||
return $rpcRequest->produceResponse();
|
return $rpcRequest->produceResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
$rpcRequest->produceResponse(ContactManager::getStandardContact($request->getPeer(), $address));
|
return $rpcRequest->produceResponse(ContactManager::getStandardContact($request->getPeer(), $peerAddress));
|
||||||
}
|
}
|
||||||
catch(DatabaseOperationException $e)
|
catch(DatabaseOperationException $e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
use Socialbox\Classes\Configuration;
|
use Socialbox\Classes\Configuration;
|
||||||
use Socialbox\Enums\StandardError;
|
use Socialbox\Enums\StandardError;
|
||||||
use Socialbox\Exceptions\DatabaseOperationException;
|
use Socialbox\Exceptions\DatabaseOperationException;
|
||||||
use Socialbox\Exceptions\Standard\InvalidRpcArgumentException;
|
|
||||||
use Socialbox\Exceptions\Standard\StandardRpcException;
|
use Socialbox\Exceptions\Standard\StandardRpcException;
|
||||||
use Socialbox\Interfaces\SerializableInterface;
|
use Socialbox\Interfaces\SerializableInterface;
|
||||||
use Socialbox\Managers\ContactManager;
|
use Socialbox\Managers\ContactManager;
|
||||||
|
@ -23,32 +22,20 @@
|
||||||
public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
|
public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
|
||||||
{
|
{
|
||||||
$limit = Configuration::getPoliciesConfiguration()->getGetContactsLimit();
|
$limit = Configuration::getPoliciesConfiguration()->getGetContactsLimit();
|
||||||
if($rpcRequest->containsParameter('limit', true))
|
if($rpcRequest->containsParameter('limit'))
|
||||||
{
|
{
|
||||||
$limit = (int)$rpcRequest->getParameter('limit');
|
$limit = (int)$rpcRequest->getParameter('limit');
|
||||||
if($limit <= 0)
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('limit', 'Invalid limit, must be greater than 0');
|
|
||||||
}
|
|
||||||
|
|
||||||
$limit = min($limit, Configuration::getPoliciesConfiguration()->getGetContactsLimit());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$page = 0;
|
$page = 0;
|
||||||
if($rpcRequest->containsParameter('page', true))
|
if($rpcRequest->containsParameter('page'))
|
||||||
{
|
{
|
||||||
$page = (int)$rpcRequest->getParameter('page');
|
$page = (int)$rpcRequest->getParameter('page');
|
||||||
if($page < 0)
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('page', 'Invalid page, must be greater than or equal to 0');
|
|
||||||
}
|
|
||||||
|
|
||||||
$page = max($page, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return $rpcRequest->produceResponse(ContactManager::getStandardContacts($request->getPeer(), $limit, $page));
|
return $rpcRequest->produceResponse(ContactManager::getStandardContacts($request->getPeer()->getUuid(), $limit, $page));
|
||||||
}
|
}
|
||||||
catch(DatabaseOperationException $e)
|
catch(DatabaseOperationException $e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Socialbox\Classes\StandardMethods\AddressBook;
|
||||||
|
|
||||||
|
use Socialbox\Abstracts\Method;
|
||||||
|
use Socialbox\Enums\StandardError;
|
||||||
|
use Socialbox\Exceptions\DatabaseOperationException;
|
||||||
|
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
||||||
|
use Socialbox\Exceptions\Standard\StandardRpcException;
|
||||||
|
use Socialbox\Interfaces\SerializableInterface;
|
||||||
|
use Socialbox\Managers\ContactManager;
|
||||||
|
use Socialbox\Objects\ClientRequest;
|
||||||
|
use Socialbox\Objects\PeerAddress;
|
||||||
|
use Socialbox\Objects\RpcRequest;
|
||||||
|
|
||||||
|
class AddressBookRevokeAllSignatures extends Method
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
* @noinspection DuplicatedCode
|
||||||
|
*/
|
||||||
|
public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
|
||||||
|
{
|
||||||
|
if(!$rpcRequest->containsParameter('peer'))
|
||||||
|
{
|
||||||
|
throw new MissingRpcArgumentException('peer');
|
||||||
|
}
|
||||||
|
|
||||||
|
$peerAddress = PeerAddress::fromAddress($rpcRequest->getParameter('peer'));
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Check if the contact already exists
|
||||||
|
$contact = ContactManager::getContact($request->getPeer(), $peerAddress);
|
||||||
|
}
|
||||||
|
catch (DatabaseOperationException $e)
|
||||||
|
{
|
||||||
|
throw new StandardRpcException('Failed to check contact state with calling peer', StandardError::INTERNAL_SERVER_ERROR, $e);
|
||||||
|
}
|
||||||
|
|
||||||
|
if($contact === null)
|
||||||
|
{
|
||||||
|
return $rpcRequest->produceResponse(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ContactManager::removeAllContactSigningKeys($contact);
|
||||||
|
}
|
||||||
|
catch (DatabaseOperationException $e)
|
||||||
|
{
|
||||||
|
throw new StandardRpcException('Failed to remove all contact signatures', StandardError::INTERNAL_SERVER_ERROR, $e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return success
|
||||||
|
return $rpcRequest->produceResponse(true);
|
||||||
|
}
|
||||||
|
}
|
|
@ -14,7 +14,6 @@
|
||||||
use Socialbox\Objects\ClientRequest;
|
use Socialbox\Objects\ClientRequest;
|
||||||
use Socialbox\Objects\PeerAddress;
|
use Socialbox\Objects\PeerAddress;
|
||||||
use Socialbox\Objects\RpcRequest;
|
use Socialbox\Objects\RpcRequest;
|
||||||
use Symfony\Component\Uid\Uuid;
|
|
||||||
|
|
||||||
class AddressBookRevokeSignature extends Method
|
class AddressBookRevokeSignature extends Method
|
||||||
{
|
{
|
||||||
|
@ -29,34 +28,17 @@
|
||||||
throw new MissingRpcArgumentException('peer');
|
throw new MissingRpcArgumentException('peer');
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
$peerAddress = PeerAddress::fromAddress($rpcRequest->getParameter('peer'));
|
||||||
{
|
|
||||||
$address = PeerAddress::fromAddress($rpcRequest->getParameter('peer'));
|
|
||||||
}
|
|
||||||
catch(InvalidArgumentException $e)
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('peer', $e);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!$rpcRequest->containsParameter('signature_uuid'))
|
if(!$rpcRequest->containsParameter('signature_uuid'))
|
||||||
{
|
{
|
||||||
throw new MissingRpcArgumentException('signature_uuid');
|
throw new MissingRpcArgumentException('signature_uuid');
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
$signatureUuid = Uuid::fromString($rpcRequest->getParameter('signature_uuid'));
|
|
||||||
}
|
|
||||||
catch(InvalidArgumentException $e)
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('signature_uuid', $e);
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Check if the contact already exists
|
// Check if the contact already exists
|
||||||
$peer = $request->getPeer();
|
$contact = ContactManager::getContact($request->getPeer(), $peerAddress);
|
||||||
$contact = ContactManager::getContact($peer, $address);
|
|
||||||
}
|
}
|
||||||
catch (DatabaseOperationException $e)
|
catch (DatabaseOperationException $e)
|
||||||
{
|
{
|
||||||
|
@ -70,6 +52,7 @@
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
$signatureUuid = (string)$rpcRequest->getParameter('signature_uuid');
|
||||||
if(!ContactManager::contactSigningKeyUuidExists($contact, $signatureUuid))
|
if(!ContactManager::contactSigningKeyUuidExists($contact, $signatureUuid))
|
||||||
{
|
{
|
||||||
return $rpcRequest->produceResponse(false);
|
return $rpcRequest->produceResponse(false);
|
||||||
|
|
|
@ -2,12 +2,10 @@
|
||||||
|
|
||||||
namespace Socialbox\Classes\StandardMethods\AddressBook;
|
namespace Socialbox\Classes\StandardMethods\AddressBook;
|
||||||
|
|
||||||
use InvalidArgumentException;
|
|
||||||
use Socialbox\Abstracts\Method;
|
use Socialbox\Abstracts\Method;
|
||||||
use Socialbox\Classes\Configuration;
|
use Socialbox\Classes\Configuration;
|
||||||
use Socialbox\Enums\StandardError;
|
use Socialbox\Enums\StandardError;
|
||||||
use Socialbox\Exceptions\DatabaseOperationException;
|
use Socialbox\Exceptions\DatabaseOperationException;
|
||||||
use Socialbox\Exceptions\Standard\InvalidRpcArgumentException;
|
|
||||||
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
||||||
use Socialbox\Exceptions\Standard\StandardRpcException;
|
use Socialbox\Exceptions\Standard\StandardRpcException;
|
||||||
use Socialbox\Interfaces\SerializableInterface;
|
use Socialbox\Interfaces\SerializableInterface;
|
||||||
|
@ -16,7 +14,6 @@
|
||||||
use Socialbox\Objects\PeerAddress;
|
use Socialbox\Objects\PeerAddress;
|
||||||
use Socialbox\Objects\RpcRequest;
|
use Socialbox\Objects\RpcRequest;
|
||||||
use Socialbox\Socialbox;
|
use Socialbox\Socialbox;
|
||||||
use Symfony\Component\Uid\Uuid;
|
|
||||||
|
|
||||||
class AddressBookTrustSignature extends Method
|
class AddressBookTrustSignature extends Method
|
||||||
{
|
{
|
||||||
|
@ -30,41 +27,26 @@
|
||||||
throw new MissingRpcArgumentException('peer');
|
throw new MissingRpcArgumentException('peer');
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
$peerAddress = PeerAddress::fromAddress($rpcRequest->getParameter('peer'));
|
||||||
{
|
|
||||||
$address = PeerAddress::fromAddress($rpcRequest->getParameter('peer'));
|
|
||||||
}
|
|
||||||
catch(InvalidArgumentException $e)
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('peer', $e);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!$rpcRequest->containsParameter('signature_uuid'))
|
if(!$rpcRequest->containsParameter('signature_uuid'))
|
||||||
{
|
{
|
||||||
throw new MissingRpcArgumentException('signature_uuid');
|
throw new MissingRpcArgumentException('signature_uuid');
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
$signatureUuid = (string)$rpcRequest->getParameter('signature_uuid');
|
||||||
{
|
$signingKey = Socialbox::resolvePeerSignature($peerAddress, $signatureUuid);
|
||||||
$signatureUuid = Uuid::fromString($rpcRequest->getParameter('signature_uuid'));
|
|
||||||
}
|
|
||||||
catch(InvalidArgumentException $e)
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('signature_uuid', $e);
|
|
||||||
}
|
|
||||||
|
|
||||||
$signingKey = Socialbox::resolvePeerSignature($address, $signatureUuid);
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Check if the contact already exists
|
// Check if the contact already exists
|
||||||
$peer = $request->getPeer();
|
$peer = $request->getPeer();
|
||||||
if(!ContactManager::isContact($peer, $address))
|
if(!ContactManager::isContact($peer, $peerAddress))
|
||||||
{
|
{
|
||||||
ContactManager::createContact($peer, $address);
|
ContactManager::createContact($peer, $peerAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
$contact = ContactManager::getContact($peer, $address);
|
$contact = ContactManager::getContact($peer, $peerAddress);
|
||||||
if(ContactManager::contactGetSigningKeysCount($contact) > Configuration::getPoliciesConfiguration()->getMaxContactSigningKeys())
|
if(ContactManager::contactGetSigningKeysCount($contact) > Configuration::getPoliciesConfiguration()->getMaxContactSigningKeys())
|
||||||
{
|
{
|
||||||
return $rpcRequest->produceError(StandardError::FORBIDDEN, 'The contact has exceeded the maximum amount of trusted signatures');
|
return $rpcRequest->produceError(StandardError::FORBIDDEN, 'The contact has exceeded the maximum amount of trusted signatures');
|
||||||
|
|
|
@ -28,21 +28,14 @@
|
||||||
throw new MissingRpcArgumentException('peer');
|
throw new MissingRpcArgumentException('peer');
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
$peerAddress = PeerAddress::fromAddress($rpcRequest->getParameter('peer'));
|
||||||
{
|
|
||||||
$address = PeerAddress::fromAddress($rpcRequest->getParameter('peer'));
|
|
||||||
}
|
|
||||||
catch(InvalidArgumentException $e)
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('peer', $e);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!$rpcRequest->containsParameter('relationship'))
|
if(!$rpcRequest->containsParameter('relationship'))
|
||||||
{
|
{
|
||||||
throw new MissingRpcArgumentException('relationship');
|
throw new MissingRpcArgumentException('relationship');
|
||||||
}
|
}
|
||||||
$relationship = ContactRelationshipType::tryFrom(strtoupper($rpcRequest->getParameter('relationship')));
|
$newRelationship = ContactRelationshipType::tryFrom(strtoupper($rpcRequest->getParameter('relationship')));
|
||||||
if($relationship === null)
|
if($newRelationship === null)
|
||||||
{
|
{
|
||||||
throw new InvalidRpcArgumentException('relationship');
|
throw new InvalidRpcArgumentException('relationship');
|
||||||
}
|
}
|
||||||
|
@ -50,14 +43,14 @@
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Check if the contact already exists
|
// Check if the contact already exists
|
||||||
$peer = $request->getPeer();
|
$requestingPeer = $request->getPeer();
|
||||||
if(!ContactManager::isContact($peer, $address))
|
if(!ContactManager::isContact($requestingPeer->getUuid(), $peerAddress))
|
||||||
{
|
{
|
||||||
return $rpcRequest->produceError(StandardError::FORBIDDEN, 'Contact does not exist');
|
return $rpcRequest->produceError(StandardError::FORBIDDEN, 'Contact does not exist');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the contact
|
// Create the contact
|
||||||
ContactManager::updateContactRelationship($peer, $address, $relationship);
|
ContactManager::updateContactRelationship($requestingPeer->getUuid(), $peerAddress, $newRelationship);
|
||||||
}
|
}
|
||||||
catch (DatabaseOperationException $e)
|
catch (DatabaseOperationException $e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
namespace Socialbox\Classes\StandardMethods\Core;
|
namespace Socialbox\Classes\StandardMethods\Core;
|
||||||
|
|
||||||
use InvalidArgumentException;
|
|
||||||
use Socialbox\Abstracts\Method;
|
use Socialbox\Abstracts\Method;
|
||||||
use Socialbox\Enums\ReservedUsernames;
|
use Socialbox\Enums\ReservedUsernames;
|
||||||
use Socialbox\Enums\StandardError;
|
use Socialbox\Enums\StandardError;
|
||||||
|
@ -30,20 +29,13 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse the peer address
|
// Parse the peer address
|
||||||
try
|
$peerAddress = PeerAddress::fromAddress((string)$rpcRequest->getParameter('peer'));
|
||||||
{
|
|
||||||
$peerAddress = PeerAddress::fromAddress($rpcRequest->getParameter('peer'));
|
|
||||||
}
|
|
||||||
catch(InvalidArgumentException $e)
|
|
||||||
{
|
|
||||||
throw new StandardRpcException('Peer Address Error: ' . $e->getMessage(), StandardError::RPC_INVALID_ARGUMENTS, $e);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if host is making the request & the identifier is not empty
|
// Check if host is making the request & the identifier is not empty
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$identifyAs = null;
|
$identifyAs = null;
|
||||||
if ($request->getPeer()->getUsername() == ReservedUsernames::HOST && $request->getIdentifyAs() != null)
|
if ($request->getPeer()->getUsername() === ReservedUsernames::HOST->value && $request->getIdentifyAs() !== null)
|
||||||
{
|
{
|
||||||
$identifyAs = $request->getIdentifyAs();
|
$identifyAs = $request->getIdentifyAs();
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,10 +35,6 @@
|
||||||
{
|
{
|
||||||
throw new MissingRpcArgumentException('signature_uuid');
|
throw new MissingRpcArgumentException('signature_uuid');
|
||||||
}
|
}
|
||||||
elseif(!Validator::validateUuid($rpcRequest->getParameter('signature_uuid')))
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('signature_uuid', 'Invalid UUID V4');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $rpcRequest->produceResponse(Socialbox::resolvePeerSignature(
|
return $rpcRequest->produceResponse(Socialbox::resolvePeerSignature(
|
||||||
$rpcRequest->getParameter('peer'), $rpcRequest->getParameter('signature_uuid')
|
$rpcRequest->getParameter('peer'), $rpcRequest->getParameter('signature_uuid')
|
||||||
|
|
|
@ -4,8 +4,6 @@
|
||||||
|
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use Socialbox\Abstracts\Method;
|
use Socialbox\Abstracts\Method;
|
||||||
use Socialbox\Classes\Cryptography;
|
|
||||||
use Socialbox\Classes\Validator;
|
|
||||||
use Socialbox\Exceptions\Standard\InvalidRpcArgumentException;
|
use Socialbox\Exceptions\Standard\InvalidRpcArgumentException;
|
||||||
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
||||||
use Socialbox\Interfaces\SerializableInterface;
|
use Socialbox\Interfaces\SerializableInterface;
|
||||||
|
@ -32,10 +30,6 @@
|
||||||
{
|
{
|
||||||
throw new MissingRpcArgumentException('signature_uuid');
|
throw new MissingRpcArgumentException('signature_uuid');
|
||||||
}
|
}
|
||||||
elseif(!Validator::validateUuid($rpcRequest->getParameter('signature_uuid')))
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('signature_uuid', 'Invalid UUID V4');
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!$rpcRequest->containsParameter('signature'))
|
if(!$rpcRequest->containsParameter('signature'))
|
||||||
{
|
{
|
||||||
|
@ -46,10 +40,6 @@
|
||||||
{
|
{
|
||||||
throw new MissingRpcArgumentException('sha512');
|
throw new MissingRpcArgumentException('sha512');
|
||||||
}
|
}
|
||||||
elseif(!Cryptography::validateSha512($rpcRequest->getParameter('sha512')))
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('sha512', 'Invalid SHA512');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse the peer address
|
// Parse the peer address
|
||||||
try
|
try
|
||||||
|
|
|
@ -4,14 +4,11 @@
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Socialbox\Abstracts\Method;
|
use Socialbox\Abstracts\Method;
|
||||||
use Socialbox\Classes\Cryptography;
|
|
||||||
use Socialbox\Classes\Logger;
|
use Socialbox\Classes\Logger;
|
||||||
use Socialbox\Classes\Validator;
|
|
||||||
use Socialbox\Enums\StandardError;
|
use Socialbox\Enums\StandardError;
|
||||||
use Socialbox\Enums\Status\EncryptionChannelStatus;
|
use Socialbox\Enums\Status\EncryptionChannelStatus;
|
||||||
use Socialbox\Exceptions\DatabaseOperationException;
|
use Socialbox\Exceptions\DatabaseOperationException;
|
||||||
use Socialbox\Exceptions\RpcException;
|
use Socialbox\Exceptions\RpcException;
|
||||||
use Socialbox\Exceptions\Standard\InvalidRpcArgumentException;
|
|
||||||
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
||||||
use Socialbox\Exceptions\Standard\StandardRpcException;
|
use Socialbox\Exceptions\Standard\StandardRpcException;
|
||||||
use Socialbox\Interfaces\SerializableInterface;
|
use Socialbox\Interfaces\SerializableInterface;
|
||||||
|
@ -55,19 +52,11 @@
|
||||||
{
|
{
|
||||||
throw new MissingRpcArgumentException('channel_uuid');
|
throw new MissingRpcArgumentException('channel_uuid');
|
||||||
}
|
}
|
||||||
elseif(!Validator::validateUuid($rpcRequest->getParameter('channel_uuid')))
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('channel_uuid', 'The given channel uuid is not a valid UUID V4');
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!$rpcRequest->containsParameter('public_encryption_key'))
|
if(!$rpcRequest->containsParameter('public_encryption_key'))
|
||||||
{
|
{
|
||||||
throw new MissingRpcArgumentException('public_encryption_key');
|
throw new MissingRpcArgumentException('public_encryption_key');
|
||||||
}
|
}
|
||||||
elseif(!Cryptography::validatePublicEncryptionKey('public_encryption_key'))
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('public_encryption_key', 'The given public encryption key is invalid');
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -98,8 +87,8 @@
|
||||||
{
|
{
|
||||||
$rpcClient = Socialbox::getExternalSession($encryptionChannel->getCallingPeerAddress()->getDomain());
|
$rpcClient = Socialbox::getExternalSession($encryptionChannel->getCallingPeerAddress()->getDomain());
|
||||||
$rpcClient->encryptionAcceptChannel(
|
$rpcClient->encryptionAcceptChannel(
|
||||||
channelUuid: $rpcRequest->getParameter('channel_uuid'),
|
channelUuid: (string)$rpcRequest->getParameter('channel_uuid'),
|
||||||
publicEncryptionKey: $rpcRequest->getParameter('public_encryption_key'),
|
publicEncryptionKey: (string)$rpcRequest->getParameter('public_encryption_key'),
|
||||||
identifiedAs: $receivingPeer->getAddress()
|
identifiedAs: $receivingPeer->getAddress()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -155,19 +144,11 @@
|
||||||
{
|
{
|
||||||
throw new MissingRpcArgumentException('channel_uuid');
|
throw new MissingRpcArgumentException('channel_uuid');
|
||||||
}
|
}
|
||||||
elseif(!Validator::validateUuid($rpcRequest->getParameter('channel_uuid')))
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('channel_uuid', 'The given channel uuid is not a valid UUID V4');
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!$rpcRequest->containsParameter('public_encryption_key'))
|
if(!$rpcRequest->containsParameter('public_encryption_key'))
|
||||||
{
|
{
|
||||||
throw new MissingRpcArgumentException('public_encryption_key');
|
throw new MissingRpcArgumentException('public_encryption_key');
|
||||||
}
|
}
|
||||||
elseif(!Cryptography::validatePublicEncryptionKey('public_encryption_key'))
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('public_encryption_key', 'The given public encryption key is invalid');
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
|
@ -5,12 +5,10 @@
|
||||||
use Exception;
|
use Exception;
|
||||||
use Socialbox\Abstracts\Method;
|
use Socialbox\Abstracts\Method;
|
||||||
use Socialbox\Classes\Logger;
|
use Socialbox\Classes\Logger;
|
||||||
use Socialbox\Classes\Validator;
|
|
||||||
use Socialbox\Enums\StandardError;
|
use Socialbox\Enums\StandardError;
|
||||||
use Socialbox\Enums\Status\EncryptionChannelStatus;
|
use Socialbox\Enums\Status\EncryptionChannelStatus;
|
||||||
use Socialbox\Exceptions\DatabaseOperationException;
|
use Socialbox\Exceptions\DatabaseOperationException;
|
||||||
use Socialbox\Exceptions\RpcException;
|
use Socialbox\Exceptions\RpcException;
|
||||||
use Socialbox\Exceptions\Standard\InvalidRpcArgumentException;
|
|
||||||
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
||||||
use Socialbox\Exceptions\Standard\StandardRpcException;
|
use Socialbox\Exceptions\Standard\StandardRpcException;
|
||||||
use Socialbox\Interfaces\SerializableInterface;
|
use Socialbox\Interfaces\SerializableInterface;
|
||||||
|
@ -32,23 +30,11 @@
|
||||||
{
|
{
|
||||||
throw new MissingRpcArgumentException('channel_uuid');
|
throw new MissingRpcArgumentException('channel_uuid');
|
||||||
}
|
}
|
||||||
elseif(!Validator::validateUuid($rpcRequest->getParameter('channel_uuid')))
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('channel_uuid', 'The given channel uuid is not a valid UUID V4');
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!$rpcRequest->containsParameter('message_uuid'))
|
if(!$rpcRequest->containsParameter('message_uuid'))
|
||||||
{
|
{
|
||||||
throw new MissingRpcArgumentException('message_uuid');
|
throw new MissingRpcArgumentException('message_uuid');
|
||||||
}
|
}
|
||||||
elseif(!is_string($rpcRequest->getParameter('message_uuid')))
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('message_uuid', 'Must be type string');
|
|
||||||
}
|
|
||||||
elseif(!Validator::validateUuid($rpcRequest->getParameter('message_uuid')))
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('message_uuid', 'Invalid message UUID V4');
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -177,7 +163,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
EncryptionChannelManager::acknowledgeMessage(
|
EncryptionChannelManager::acknowledgeMessage(
|
||||||
$rpcRequest->getParameter('channel_uuid'), $rpcRequest->getParameter('message_uuid')
|
(string)$rpcRequest->getParameter('channel_uuid'), (string)$rpcRequest->getParameter('message_uuid')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
catch(DatabaseOperationException $e)
|
catch(DatabaseOperationException $e)
|
||||||
|
@ -191,8 +177,8 @@
|
||||||
{
|
{
|
||||||
$rpcClient = Socialbox::getExternalSession($message->getOwner($encryptionChannel)->getDomain());
|
$rpcClient = Socialbox::getExternalSession($message->getOwner($encryptionChannel)->getDomain());
|
||||||
$rpcClient->encryptionChannelAcknowledgeMessage(
|
$rpcClient->encryptionChannelAcknowledgeMessage(
|
||||||
channelUuid: $rpcRequest->getParameter('channel_uuid'),
|
channelUuid: (string)$rpcRequest->getParameter('channel_uuid'),
|
||||||
messageUuid: $rpcRequest->getParameter('message_uuid'),
|
messageUuid: (string)$rpcRequest->getParameter('message_uuid'),
|
||||||
identifiedAs: $requestingPeer->getAddress()
|
identifiedAs: $requestingPeer->getAddress()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,18 +2,20 @@
|
||||||
|
|
||||||
namespace Socialbox\Classes\StandardMethods\EncryptionChannel;
|
namespace Socialbox\Classes\StandardMethods\EncryptionChannel;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
use Socialbox\Abstracts\Method;
|
use Socialbox\Abstracts\Method;
|
||||||
use Socialbox\Classes\Validator;
|
use Socialbox\Classes\Logger;
|
||||||
use Socialbox\Enums\StandardError;
|
use Socialbox\Enums\StandardError;
|
||||||
use Socialbox\Enums\Status\EncryptionChannelStatus;
|
use Socialbox\Enums\Status\EncryptionChannelStatus;
|
||||||
use Socialbox\Exceptions\DatabaseOperationException;
|
use Socialbox\Exceptions\DatabaseOperationException;
|
||||||
use Socialbox\Exceptions\Standard\InvalidRpcArgumentException;
|
use Socialbox\Exceptions\RpcException;
|
||||||
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
||||||
use Socialbox\Exceptions\Standard\StandardRpcException;
|
use Socialbox\Exceptions\Standard\StandardRpcException;
|
||||||
use Socialbox\Interfaces\SerializableInterface;
|
use Socialbox\Interfaces\SerializableInterface;
|
||||||
use Socialbox\Managers\EncryptionChannelManager;
|
use Socialbox\Managers\EncryptionChannelManager;
|
||||||
use Socialbox\Objects\ClientRequest;
|
use Socialbox\Objects\ClientRequest;
|
||||||
use Socialbox\Objects\RpcRequest;
|
use Socialbox\Objects\RpcRequest;
|
||||||
|
use Socialbox\Socialbox;
|
||||||
|
|
||||||
class EncryptionChannelReceive extends Method
|
class EncryptionChannelReceive extends Method
|
||||||
{
|
{
|
||||||
|
@ -27,10 +29,6 @@
|
||||||
{
|
{
|
||||||
throw new MissingRpcArgumentException('channel_uuid');
|
throw new MissingRpcArgumentException('channel_uuid');
|
||||||
}
|
}
|
||||||
elseif(!Validator::validateUuid($rpcRequest->getParameter('channel_uuid')))
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('channel_uuid', 'The given channel uuid is not a valid UUID V4');
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -78,21 +76,64 @@
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
$messages = EncryptionChannelManager::receiveData(
|
$messages = EncryptionChannelManager::receiveData(
|
||||||
$rpcRequest->getParameter('channel_uuid'), $encryptionChannel->determineRecipient($requestingPeer->getAddress(), true)
|
$rpcRequest->getParameter('channel_uuid'), $encryptionChannel->determineRecipient($requestingPeer->getAddress(), true)
|
||||||
);
|
);
|
||||||
|
|
||||||
if($acknowledge)
|
|
||||||
{
|
|
||||||
EncryptionChannelManager::acknowledgeMessagesBatch($rpcRequest->getParameter('channel_uuid'), array_map(fn($message) => $message->getUuid(), $messages));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch(DatabaseOperationException $e)
|
catch(DatabaseOperationException $e)
|
||||||
{
|
{
|
||||||
throw new StandardRpcException('Failed to retrieve the messages', StandardError::INTERNAL_SERVER_ERROR, $e);
|
throw new StandardRpcException('Failed to retrieve the messages', StandardError::INTERNAL_SERVER_ERROR, $e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($acknowledge)
|
||||||
|
{
|
||||||
|
$messageUuids = array_map(fn($message) => $message->getUuid(), $messages);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
EncryptionChannelManager::acknowledgeMessagesBatch(
|
||||||
|
channelUuid: $rpcRequest->getParameter('channel_uuid'),
|
||||||
|
messageUuids: $messageUuids,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (DatabaseOperationException $e)
|
||||||
|
{
|
||||||
|
throw new StandardRpcException('Failed to acknowledge the messages locally', StandardError::INTERNAL_SERVER_ERROR, $e);
|
||||||
|
}
|
||||||
|
|
||||||
|
$externalPeer = $encryptionChannel->getExternalPeer();
|
||||||
|
if($externalPeer !== null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$rpcClient = Socialbox::getExternalSession($externalPeer->getDomain());
|
||||||
|
$rpcClient->encryptionChannelAcknowledgeMessages(
|
||||||
|
channelUuid: (string)$rpcRequest->getParameter('channel_uuid'),
|
||||||
|
messageUuids: $messageUuids,
|
||||||
|
identifiedAs: $requestingPeer->getAddress()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch(Exception $e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
EncryptionChannelManager::rejectMessage($rpcRequest->getParameter('channel_uuid'), $rpcRequest->getParameter('message_uuid'), true);
|
||||||
|
}
|
||||||
|
catch (DatabaseOperationException $e)
|
||||||
|
{
|
||||||
|
Logger::getLogger()->error('Error rejecting message as server', $e);
|
||||||
|
}
|
||||||
|
|
||||||
|
if($e instanceof RpcException)
|
||||||
|
{
|
||||||
|
throw StandardRpcException::fromRpcException($e);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new StandardRpcException('Failed to acknowledge the message with the external server', StandardError::INTERNAL_SERVER_ERROR, $e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $rpcRequest->produceResponse(array_map(fn($message) => $message->toStandard(), $messages));
|
return $rpcRequest->produceResponse(array_map(fn($message) => $message->toStandard(), $messages));
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -5,12 +5,10 @@
|
||||||
use Exception;
|
use Exception;
|
||||||
use Socialbox\Abstracts\Method;
|
use Socialbox\Abstracts\Method;
|
||||||
use Socialbox\Classes\Logger;
|
use Socialbox\Classes\Logger;
|
||||||
use Socialbox\Classes\Validator;
|
|
||||||
use Socialbox\Enums\StandardError;
|
use Socialbox\Enums\StandardError;
|
||||||
use Socialbox\Enums\Status\EncryptionChannelStatus;
|
use Socialbox\Enums\Status\EncryptionChannelStatus;
|
||||||
use Socialbox\Exceptions\DatabaseOperationException;
|
use Socialbox\Exceptions\DatabaseOperationException;
|
||||||
use Socialbox\Exceptions\RpcException;
|
use Socialbox\Exceptions\RpcException;
|
||||||
use Socialbox\Exceptions\Standard\InvalidRpcArgumentException;
|
|
||||||
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
||||||
use Socialbox\Exceptions\Standard\StandardRpcException;
|
use Socialbox\Exceptions\Standard\StandardRpcException;
|
||||||
use Socialbox\Interfaces\SerializableInterface;
|
use Socialbox\Interfaces\SerializableInterface;
|
||||||
|
@ -32,27 +30,15 @@
|
||||||
{
|
{
|
||||||
throw new MissingRpcArgumentException('channel_uuid');
|
throw new MissingRpcArgumentException('channel_uuid');
|
||||||
}
|
}
|
||||||
elseif(!Validator::validateUuid($rpcRequest->getParameter('channel_uuid')))
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('channel_uuid', 'The given channel uuid is not a valid UUID V4');
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!$rpcRequest->containsParameter('message_uuid'))
|
if(!$rpcRequest->containsParameter('message_uuid'))
|
||||||
{
|
{
|
||||||
throw new MissingRpcArgumentException('message_uuid');
|
throw new MissingRpcArgumentException('message_uuid');
|
||||||
}
|
}
|
||||||
elseif(!is_string($rpcRequest->getParameter('message_uuid')))
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('message_uuid', 'Must be type string');
|
|
||||||
}
|
|
||||||
elseif(!Validator::validateUuid($rpcRequest->getParameter('message_uuid')))
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('message_uuid', 'Invalid message UUID V4');
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$channelUuid = $rpcRequest->getParameter('channel_uuid');
|
$channelUuid = (string)$rpcRequest->getParameter('channel_uuid');
|
||||||
$encryptionChannel = EncryptionChannelManager::getChannel($channelUuid);
|
$encryptionChannel = EncryptionChannelManager::getChannel($channelUuid);
|
||||||
}
|
}
|
||||||
catch(DatabaseOperationException $e)
|
catch(DatabaseOperationException $e)
|
||||||
|
@ -117,7 +103,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
EncryptionChannelManager::rejectMessage(
|
EncryptionChannelManager::rejectMessage(
|
||||||
$rpcRequest->getParameter('channel_uuid'), $rpcRequest->getParameter('message_uuid')
|
(string)$rpcRequest->getParameter('channel_uuid'), (string)$rpcRequest->getParameter('message_uuid')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
catch(DatabaseOperationException $e)
|
catch(DatabaseOperationException $e)
|
||||||
|
@ -176,8 +162,8 @@
|
||||||
return $rpcRequest->produceError(StandardError::UNAUTHORIZED, 'The message is not for the requesting peer');
|
return $rpcRequest->produceError(StandardError::UNAUTHORIZED, 'The message is not for the requesting peer');
|
||||||
}
|
}
|
||||||
|
|
||||||
EncryptionChannelManager::acknowledgeMessage(
|
EncryptionChannelManager::rejectMessage(
|
||||||
$rpcRequest->getParameter('channel_uuid'), $rpcRequest->getParameter('message_uuid')
|
(string)$rpcRequest->getParameter('channel_uuid'), (string)$rpcRequest->getParameter('message_uuid')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
catch(DatabaseOperationException $e)
|
catch(DatabaseOperationException $e)
|
||||||
|
@ -191,8 +177,8 @@
|
||||||
{
|
{
|
||||||
$rpcClient = Socialbox::getExternalSession($message->getOwner($encryptionChannel)->getDomain());
|
$rpcClient = Socialbox::getExternalSession($message->getOwner($encryptionChannel)->getDomain());
|
||||||
$rpcClient->encryptionChannelRejectMessage(
|
$rpcClient->encryptionChannelRejectMessage(
|
||||||
channelUuid: $rpcRequest->getParameter('channel_uuid'),
|
channelUuid: (string)$rpcRequest->getParameter('channel_uuid'),
|
||||||
messageUuid: $rpcRequest->getParameter('message_uuid'),
|
messageUuid: (string)$rpcRequest->getParameter('message_uuid'),
|
||||||
identifiedAs: $requestingPeer->getAddress()
|
identifiedAs: $requestingPeer->getAddress()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -200,7 +186,7 @@
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
EncryptionChannelManager::rejectMessage($rpcRequest->getParameter('channel_uuid'), $rpcRequest->getParameter('message_uuid'), true);
|
EncryptionChannelManager::rejectMessage((string)$rpcRequest->getParameter('channel_uuid'), (string)$rpcRequest->getParameter('message_uuid'), true);
|
||||||
}
|
}
|
||||||
catch (DatabaseOperationException $e)
|
catch (DatabaseOperationException $e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -32,10 +32,6 @@
|
||||||
{
|
{
|
||||||
throw new MissingRpcArgumentException('channel_uuid');
|
throw new MissingRpcArgumentException('channel_uuid');
|
||||||
}
|
}
|
||||||
elseif(!Validator::validateUuid($rpcRequest->getParameter('channel_uuid')))
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('channel_uuid', 'The given channel uuid is not a valid UUID V4');
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -102,10 +98,6 @@
|
||||||
{
|
{
|
||||||
throw new MissingRpcArgumentException('checksum');
|
throw new MissingRpcArgumentException('checksum');
|
||||||
}
|
}
|
||||||
elseif(!Cryptography::validateSha512($rpcRequest->getParameter('checksum')))
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('checksum', 'The given checksum is not a valid SHA-512 checksum');
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!$rpcRequest->containsParameter('data'))
|
if(!$rpcRequest->containsParameter('data'))
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,13 +4,10 @@
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Socialbox\Abstracts\Method;
|
use Socialbox\Abstracts\Method;
|
||||||
use Socialbox\Classes\Logger;
|
|
||||||
use Socialbox\Classes\Validator;
|
|
||||||
use Socialbox\Enums\StandardError;
|
use Socialbox\Enums\StandardError;
|
||||||
use Socialbox\Enums\Status\EncryptionChannelStatus;
|
use Socialbox\Enums\Status\EncryptionChannelStatus;
|
||||||
use Socialbox\Exceptions\DatabaseOperationException;
|
use Socialbox\Exceptions\DatabaseOperationException;
|
||||||
use Socialbox\Exceptions\RpcException;
|
use Socialbox\Exceptions\RpcException;
|
||||||
use Socialbox\Exceptions\Standard\InvalidRpcArgumentException;
|
|
||||||
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
||||||
use Socialbox\Exceptions\Standard\StandardRpcException;
|
use Socialbox\Exceptions\Standard\StandardRpcException;
|
||||||
use Socialbox\Interfaces\SerializableInterface;
|
use Socialbox\Interfaces\SerializableInterface;
|
||||||
|
@ -31,14 +28,17 @@
|
||||||
{
|
{
|
||||||
throw new MissingRpcArgumentException('channel_uuid');
|
throw new MissingRpcArgumentException('channel_uuid');
|
||||||
}
|
}
|
||||||
elseif(!Validator::validateUuid($rpcRequest->getParameter('channel_uuid')))
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('channel_uuid', 'The given channel uuid is not a valid UUID V4');
|
|
||||||
}
|
|
||||||
|
|
||||||
if($request->isExternal())
|
try
|
||||||
{
|
{
|
||||||
return self::handleExternal($request, $rpcRequest);
|
if ($request->isExternal())
|
||||||
|
{
|
||||||
|
return self::handleExternal($request, $rpcRequest);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (DatabaseOperationException $e)
|
||||||
|
{
|
||||||
|
throw new StandardRpcException('There was an error while handling the external request', StandardError::INTERNAL_SERVER_ERROR, $e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::handleInternal($request, $rpcRequest);
|
return self::handleInternal($request, $rpcRequest);
|
||||||
|
@ -98,15 +98,6 @@
|
||||||
}
|
}
|
||||||
catch(Exception $e)
|
catch(Exception $e)
|
||||||
{
|
{
|
||||||
try
|
|
||||||
{
|
|
||||||
EncryptionChannelManager::declineChannel($rpcRequest->getParameter('channel_uuid'), true);
|
|
||||||
}
|
|
||||||
catch(DatabaseOperationException $e)
|
|
||||||
{
|
|
||||||
Logger::getLogger()->error('Error declining channel as server', $e);
|
|
||||||
}
|
|
||||||
|
|
||||||
if($e instanceof RpcException)
|
if($e instanceof RpcException)
|
||||||
{
|
{
|
||||||
throw StandardRpcException::fromRpcException($e);
|
throw StandardRpcException::fromRpcException($e);
|
||||||
|
@ -145,13 +136,11 @@
|
||||||
{
|
{
|
||||||
return $rpcRequest->produceError(StandardError::NOT_FOUND, 'The requested encryption channel was not found');
|
return $rpcRequest->produceError(StandardError::NOT_FOUND, 'The requested encryption channel was not found');
|
||||||
}
|
}
|
||||||
|
elseif(!$encryptionChannel->isParticipant($request->getIdentifyAs()))
|
||||||
if(!$encryptionChannel->isParticipant($request->getIdentifyAs()))
|
|
||||||
{
|
{
|
||||||
return $rpcRequest->produceError(StandardError::UNAUTHORIZED, 'The requested encryption channel is not accessible');
|
return $rpcRequest->produceError(StandardError::UNAUTHORIZED, 'The requested encryption channel is not accessible');
|
||||||
}
|
}
|
||||||
|
elseif($encryptionChannel->getStatus() === EncryptionChannelStatus::CLOSED)
|
||||||
if($encryptionChannel->getStatus() === EncryptionChannelStatus::CLOSED)
|
|
||||||
{
|
{
|
||||||
return $rpcRequest->produceResponse(false);
|
return $rpcRequest->produceResponse(false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,15 +3,11 @@
|
||||||
namespace Socialbox\Classes\StandardMethods\EncryptionChannel;
|
namespace Socialbox\Classes\StandardMethods\EncryptionChannel;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use InvalidArgumentException;
|
|
||||||
use Socialbox\Abstracts\Method;
|
use Socialbox\Abstracts\Method;
|
||||||
use Socialbox\Classes\Cryptography;
|
|
||||||
use Socialbox\Classes\Logger;
|
use Socialbox\Classes\Logger;
|
||||||
use Socialbox\Classes\Validator;
|
|
||||||
use Socialbox\Enums\StandardError;
|
use Socialbox\Enums\StandardError;
|
||||||
use Socialbox\Exceptions\DatabaseOperationException;
|
use Socialbox\Exceptions\DatabaseOperationException;
|
||||||
use Socialbox\Exceptions\RpcException;
|
use Socialbox\Exceptions\RpcException;
|
||||||
use Socialbox\Exceptions\Standard\InvalidRpcArgumentException;
|
|
||||||
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
||||||
use Socialbox\Exceptions\Standard\StandardRpcException;
|
use Socialbox\Exceptions\Standard\StandardRpcException;
|
||||||
use Socialbox\Interfaces\SerializableInterface;
|
use Socialbox\Interfaces\SerializableInterface;
|
||||||
|
@ -57,19 +53,11 @@
|
||||||
{
|
{
|
||||||
throw new MissingRpcArgumentException('receiving_peer');
|
throw new MissingRpcArgumentException('receiving_peer');
|
||||||
}
|
}
|
||||||
elseif(!Validator::validatePeerAddress($rpcRequest->getParameter('receiving_peer')))
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('receiving_peer', 'Invalid Receiving Peer Address');
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!$rpcRequest->containsParameter('public_encryption_key'))
|
if(!$rpcRequest->containsParameter('public_encryption_key'))
|
||||||
{
|
{
|
||||||
throw new MissingRpcArgumentException('public_encryption_key');
|
throw new MissingRpcArgumentException('public_encryption_key');
|
||||||
}
|
}
|
||||||
elseif(!Cryptography::validatePublicEncryptionKey($rpcRequest->getParameter('public_encryption_key')))
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('public_encryption_key', 'The given public encryption key is invalid');
|
|
||||||
}
|
|
||||||
|
|
||||||
$receivingPeerAddress = PeerAddress::fromAddress($rpcRequest->getParameter('receiving_peer'));
|
$receivingPeerAddress = PeerAddress::fromAddress($rpcRequest->getParameter('receiving_peer'));
|
||||||
Socialbox::resolvePeer($receivingPeerAddress);
|
Socialbox::resolvePeer($receivingPeerAddress);
|
||||||
|
@ -92,10 +80,6 @@
|
||||||
callingPublicEncryptionKey: $rpcRequest->getParameter('public_encryption_ke')
|
callingPublicEncryptionKey: $rpcRequest->getParameter('public_encryption_ke')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
catch(InvalidArgumentException $e)
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException(null, $e);
|
|
||||||
}
|
|
||||||
catch (DatabaseOperationException $e)
|
catch (DatabaseOperationException $e)
|
||||||
{
|
{
|
||||||
throw new StandardRpcException('There was an error while trying to create a new encryption channel', StandardError::INTERNAL_SERVER_ERROR, $e);
|
throw new StandardRpcException('There was an error while trying to create a new encryption channel', StandardError::INTERNAL_SERVER_ERROR, $e);
|
||||||
|
@ -133,21 +117,6 @@
|
||||||
|
|
||||||
throw new StandardRpcException('There was an error while trying to notify the external server of the encryption channel', StandardError::INTERNAL_SERVER_ERROR, $e);
|
throw new StandardRpcException('There was an error while trying to notify the external server of the encryption channel', StandardError::INTERNAL_SERVER_ERROR, $e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for sanity reasons
|
|
||||||
if($externalUuid !== $uuid)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
EncryptionChannelManager::declineChannel($uuid, true);
|
|
||||||
}
|
|
||||||
catch(DatabaseOperationException $e)
|
|
||||||
{
|
|
||||||
Logger::getLogger()->error('Error declining channel as server', $e);
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new StandardRpcException('The external server did not return the correct UUID', StandardError::UUID_MISMATCH);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -173,29 +142,17 @@
|
||||||
{
|
{
|
||||||
throw new MissingRpcArgumentException('receiving_peer');
|
throw new MissingRpcArgumentException('receiving_peer');
|
||||||
}
|
}
|
||||||
elseif(!Validator::validatePeerAddress($rpcRequest->getParameter('receiving_peer')))
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('receiving_peer', 'Invalid Receiving Peer Address');
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!$rpcRequest->containsParameter('public_encryption_key'))
|
if(!$rpcRequest->containsParameter('public_encryption_key'))
|
||||||
{
|
{
|
||||||
throw new MissingRpcArgumentException('public_encryption_key');
|
throw new MissingRpcArgumentException('public_encryption_key');
|
||||||
}
|
}
|
||||||
elseif(!Cryptography::validatePublicEncryptionKey($rpcRequest->getParameter('public_encryption_key')))
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('public_encryption_key', 'The given public encryption key is invalid');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for an additional required parameter 'channel_uuid'
|
// Check for an additional required parameter 'channel_uuid'
|
||||||
if(!$rpcRequest->containsParameter('channel_uuid'))
|
if(!$rpcRequest->containsParameter('channel_uuid'))
|
||||||
{
|
{
|
||||||
throw new MissingRpcArgumentException('channel_uuid');
|
throw new MissingRpcArgumentException('channel_uuid');
|
||||||
}
|
}
|
||||||
elseif(!Validator::validateUuid($rpcRequest->getParameter('channel_uuid')))
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('channel_uuid', 'The given UUID is not a valid UUID v4 format');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if the UUID already is used on this server
|
// Check if the UUID already is used on this server
|
||||||
try
|
try
|
||||||
|
@ -236,7 +193,7 @@
|
||||||
callingPeer: $callingPeer,
|
callingPeer: $callingPeer,
|
||||||
receivingPeer: $receivingPeerAddress,
|
receivingPeer: $receivingPeerAddress,
|
||||||
callingPublicEncryptionKey: $rpcRequest->getParameter('public_encryption_key'),
|
callingPublicEncryptionKey: $rpcRequest->getParameter('public_encryption_key'),
|
||||||
channelUUid: $rpcRequest->getParameter('channel_uuid')
|
channelUuid: $rpcRequest->getParameter('channel_uuid')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
catch(DatabaseOperationException $e)
|
catch(DatabaseOperationException $e)
|
||||||
|
|
|
@ -5,12 +5,10 @@
|
||||||
use Exception;
|
use Exception;
|
||||||
use Socialbox\Abstracts\Method;
|
use Socialbox\Abstracts\Method;
|
||||||
use Socialbox\Classes\Logger;
|
use Socialbox\Classes\Logger;
|
||||||
use Socialbox\Classes\Validator;
|
|
||||||
use Socialbox\Enums\StandardError;
|
use Socialbox\Enums\StandardError;
|
||||||
use Socialbox\Enums\Status\EncryptionChannelStatus;
|
use Socialbox\Enums\Status\EncryptionChannelStatus;
|
||||||
use Socialbox\Exceptions\DatabaseOperationException;
|
use Socialbox\Exceptions\DatabaseOperationException;
|
||||||
use Socialbox\Exceptions\RpcException;
|
use Socialbox\Exceptions\RpcException;
|
||||||
use Socialbox\Exceptions\Standard\InvalidRpcArgumentException;
|
|
||||||
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
||||||
use Socialbox\Exceptions\Standard\StandardRpcException;
|
use Socialbox\Exceptions\Standard\StandardRpcException;
|
||||||
use Socialbox\Interfaces\SerializableInterface;
|
use Socialbox\Interfaces\SerializableInterface;
|
||||||
|
@ -54,10 +52,6 @@
|
||||||
{
|
{
|
||||||
throw new MissingRpcArgumentException('channel_uuid');
|
throw new MissingRpcArgumentException('channel_uuid');
|
||||||
}
|
}
|
||||||
elseif(!Validator::validateUuid($rpcRequest->getParameter('channel_uuid')))
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('channel_uuid', 'The given channel uuid is not a valid UUID V4');
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -143,10 +137,6 @@
|
||||||
{
|
{
|
||||||
throw new MissingRpcArgumentException('channel_uuid');
|
throw new MissingRpcArgumentException('channel_uuid');
|
||||||
}
|
}
|
||||||
elseif(!Validator::validateUuid($rpcRequest->getParameter('channel_uuid')))
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('channel_uuid', 'The given channel uuid is not a valid UUID V4');
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,88 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Socialbox\Classes\StandardMethods\EncryptionChannel;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use Socialbox\Abstracts\Method;
|
||||||
|
use Socialbox\Enums\StandardError;
|
||||||
|
use Socialbox\Enums\Status\EncryptionChannelStatus;
|
||||||
|
use Socialbox\Exceptions\DatabaseOperationException;
|
||||||
|
use Socialbox\Exceptions\RpcException;
|
||||||
|
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
||||||
|
use Socialbox\Exceptions\Standard\StandardRpcException;
|
||||||
|
use Socialbox\Interfaces\SerializableInterface;
|
||||||
|
use Socialbox\Managers\EncryptionChannelManager;
|
||||||
|
use Socialbox\Objects\ClientRequest;
|
||||||
|
use Socialbox\Objects\RpcRequest;
|
||||||
|
use Socialbox\Socialbox;
|
||||||
|
|
||||||
|
class EncryptionDeleteChannel extends Method
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
|
||||||
|
{
|
||||||
|
if(!$rpcRequest->containsParameter('channel_uuid'))
|
||||||
|
{
|
||||||
|
throw new MissingRpcArgumentException('channel_uuid');
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$requestingPeer = $request->getPeer();
|
||||||
|
$encryptionChannel = EncryptionChannelManager::getChannel($rpcRequest->getParameter('channel_uuid'));
|
||||||
|
}
|
||||||
|
catch(DatabaseOperationException $e)
|
||||||
|
{
|
||||||
|
throw new StandardRpcException('There was an error while trying to obtain the encryption channel', StandardError::INTERNAL_SERVER_ERROR, $e);
|
||||||
|
}
|
||||||
|
|
||||||
|
if($encryptionChannel === null)
|
||||||
|
{
|
||||||
|
return $rpcRequest->produceError(StandardError::NOT_FOUND, 'The requested encryption channel was not found');
|
||||||
|
}
|
||||||
|
elseif(!$encryptionChannel->isParticipant($requestingPeer->getAddress()))
|
||||||
|
{
|
||||||
|
return $rpcRequest->produceError(StandardError::UNAUTHORIZED, 'The requested encryption channel is not accessible');
|
||||||
|
}
|
||||||
|
elseif($encryptionChannel->getStatus() === EncryptionChannelStatus::CLOSED)
|
||||||
|
{
|
||||||
|
return $rpcRequest->produceResponse(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
EncryptionChannelManager::deleteChannel($encryptionChannel->getUuid());
|
||||||
|
}
|
||||||
|
catch(DatabaseOperationException $e)
|
||||||
|
{
|
||||||
|
throw new StandardRpcException('An error occurred while trying to delete the encryption channel', StandardError::INTERNAL_SERVER_ERROR, $e);
|
||||||
|
}
|
||||||
|
|
||||||
|
$externalPeer = $encryptionChannel->getExternalPeer();
|
||||||
|
if($externalPeer !== null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$rpcClient = Socialbox::getExternalSession($encryptionChannel->getCallingPeerAddress()->getDomain());
|
||||||
|
$rpcClient->encryptionCloseChannel(
|
||||||
|
channelUuid: $rpcRequest->getParameter('channel_uuid'),
|
||||||
|
identifiedAs: $requestingPeer->getAddress()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch(Exception $e)
|
||||||
|
{
|
||||||
|
if($e instanceof RpcException)
|
||||||
|
{
|
||||||
|
throw StandardRpcException::fromRpcException($e);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new StandardRpcException('There was an error while trying to notify the external server of the encryption channel', StandardError::INTERNAL_SERVER_ERROR, $e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $rpcRequest->produceResponse(true);
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,10 +3,8 @@
|
||||||
namespace Socialbox\Classes\StandardMethods\EncryptionChannel;
|
namespace Socialbox\Classes\StandardMethods\EncryptionChannel;
|
||||||
|
|
||||||
use Socialbox\Abstracts\Method;
|
use Socialbox\Abstracts\Method;
|
||||||
use Socialbox\Classes\Validator;
|
|
||||||
use Socialbox\Enums\StandardError;
|
use Socialbox\Enums\StandardError;
|
||||||
use Socialbox\Exceptions\DatabaseOperationException;
|
use Socialbox\Exceptions\DatabaseOperationException;
|
||||||
use Socialbox\Exceptions\Standard\InvalidRpcArgumentException;
|
|
||||||
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
||||||
use Socialbox\Exceptions\Standard\StandardRpcException;
|
use Socialbox\Exceptions\Standard\StandardRpcException;
|
||||||
use Socialbox\Interfaces\SerializableInterface;
|
use Socialbox\Interfaces\SerializableInterface;
|
||||||
|
@ -26,15 +24,11 @@
|
||||||
{
|
{
|
||||||
throw new MissingRpcArgumentException('channel_uuid');
|
throw new MissingRpcArgumentException('channel_uuid');
|
||||||
}
|
}
|
||||||
elseif(!Validator::validateUuid($rpcRequest->getParameter('channel_uuid')))
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('channel_uuid', 'The given channel uuid is not a valid UUID V4');
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$requestingPeer = $request->getPeer();
|
$requestingPeer = $request->getPeer();
|
||||||
$encryptionChannel = EncryptionChannelManager::getChannel($rpcRequest->getParameter('channel_uuid'));
|
$encryptionChannel = EncryptionChannelManager::getChannel((string)$rpcRequest->getParameter('channel_uuid'));
|
||||||
}
|
}
|
||||||
catch(DatabaseOperationException $e)
|
catch(DatabaseOperationException $e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Socialbox\Classes\StandardMethods\EncryptionChannel;
|
||||||
|
|
||||||
|
use InvalidArgumentException;
|
||||||
|
use Socialbox\Abstracts\Method;
|
||||||
|
use Socialbox\Classes\Configuration;
|
||||||
|
use Socialbox\Enums\StandardError;
|
||||||
|
use Socialbox\Exceptions\DatabaseOperationException;
|
||||||
|
use Socialbox\Exceptions\Standard\InvalidRpcArgumentException;
|
||||||
|
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
||||||
|
use Socialbox\Exceptions\Standard\StandardRpcException;
|
||||||
|
use Socialbox\Interfaces\SerializableInterface;
|
||||||
|
use Socialbox\Managers\EncryptionChannelManager;
|
||||||
|
use Socialbox\Objects\ClientRequest;
|
||||||
|
use Socialbox\Objects\RpcRequest;
|
||||||
|
|
||||||
|
class EncryptionGetChannelRequests extends Method
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
|
||||||
|
{
|
||||||
|
if(!$rpcRequest->containsParameter('channel_uuid'))
|
||||||
|
{
|
||||||
|
throw new MissingRpcArgumentException('channel_uuid');
|
||||||
|
}
|
||||||
|
|
||||||
|
$page = 1;
|
||||||
|
$limit = Configuration::getPoliciesConfiguration()->getEncryptionChannelRequestsLimit();
|
||||||
|
if($rpcRequest->containsParameter('page'))
|
||||||
|
{
|
||||||
|
$page = (int)$rpcRequest->getParameter('page');
|
||||||
|
}
|
||||||
|
|
||||||
|
if($rpcRequest->containsParameter('limit'))
|
||||||
|
{
|
||||||
|
$limit = (int)$rpcRequest->getParameter('limit');
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$requestingPeer = $request->getPeer();
|
||||||
|
return $rpcRequest->produceResponse(array_map(function($channel) use ($requestingPeer)
|
||||||
|
{
|
||||||
|
return $channel->toStandard();
|
||||||
|
}, EncryptionChannelManager::getChannelRequests($requestingPeer->getAddress(), $page, $limit)));
|
||||||
|
}
|
||||||
|
catch(InvalidArgumentException $e)
|
||||||
|
{
|
||||||
|
throw InvalidRpcArgumentException::fromInvalidArgumentException($e);
|
||||||
|
}
|
||||||
|
catch(DatabaseOperationException $e)
|
||||||
|
{
|
||||||
|
throw new StandardRpcException('There was an error while trying to obtain the encryption channel requests', StandardError::INTERNAL_SERVER_ERROR, $e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Socialbox\Classes\StandardMethods\EncryptionChannel;
|
||||||
|
|
||||||
|
use Socialbox\Abstracts\Method;
|
||||||
|
use Socialbox\Classes\Configuration;
|
||||||
|
use Socialbox\Enums\StandardError;
|
||||||
|
use Socialbox\Exceptions\DatabaseOperationException;
|
||||||
|
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
||||||
|
use Socialbox\Exceptions\Standard\StandardRpcException;
|
||||||
|
use Socialbox\Interfaces\SerializableInterface;
|
||||||
|
use Socialbox\Managers\EncryptionChannelManager;
|
||||||
|
use Socialbox\Objects\ClientRequest;
|
||||||
|
use Socialbox\Objects\RpcRequest;
|
||||||
|
|
||||||
|
class EncryptionGetChannels extends Method
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
|
||||||
|
{
|
||||||
|
if(!$rpcRequest->containsParameter('channel_uuid'))
|
||||||
|
{
|
||||||
|
throw new MissingRpcArgumentException('channel_uuid');
|
||||||
|
}
|
||||||
|
|
||||||
|
$page = 1;
|
||||||
|
$limit = Configuration::getPoliciesConfiguration()->getEncryptionChannelsLimit();
|
||||||
|
if($rpcRequest->containsParameter('page'))
|
||||||
|
{
|
||||||
|
$page = (int)$rpcRequest->getParameter('page');
|
||||||
|
}
|
||||||
|
|
||||||
|
if($rpcRequest->containsParameter('limit'))
|
||||||
|
{
|
||||||
|
$limit = (int)$rpcRequest->getParameter('limit');
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$requestingPeer = $request->getPeer();
|
||||||
|
return $rpcRequest->produceResponse(array_map(function($channel) use ($requestingPeer)
|
||||||
|
{
|
||||||
|
return $channel->toStandard();
|
||||||
|
}, EncryptionChannelManager::getChannels($requestingPeer->getAddress(), $page, $limit)));
|
||||||
|
}
|
||||||
|
catch(DatabaseOperationException $e)
|
||||||
|
{
|
||||||
|
throw new StandardRpcException('There was an error while trying to obtain the encryption channels', StandardError::INTERNAL_SERVER_ERROR, $e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,60 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Socialbox\Classes\StandardMethods\EncryptionChannel;
|
||||||
|
|
||||||
|
use Socialbox\Abstracts\Method;
|
||||||
|
use Socialbox\Classes\Configuration;
|
||||||
|
use Socialbox\Classes\Validator;
|
||||||
|
use Socialbox\Enums\StandardError;
|
||||||
|
use Socialbox\Exceptions\DatabaseOperationException;
|
||||||
|
use Socialbox\Exceptions\Standard\InvalidRpcArgumentException;
|
||||||
|
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
||||||
|
use Socialbox\Exceptions\Standard\StandardRpcException;
|
||||||
|
use Socialbox\Interfaces\SerializableInterface;
|
||||||
|
use Socialbox\Managers\EncryptionChannelManager;
|
||||||
|
use Socialbox\Objects\ClientRequest;
|
||||||
|
use Socialbox\Objects\RpcRequest;
|
||||||
|
|
||||||
|
class EncryptionGetIncomingChannels extends Method
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
|
||||||
|
{
|
||||||
|
if(!$rpcRequest->containsParameter('channel_uuid'))
|
||||||
|
{
|
||||||
|
throw new MissingRpcArgumentException('channel_uuid');
|
||||||
|
}
|
||||||
|
elseif(!Validator::validateUuid($rpcRequest->getParameter('channel_uuid')))
|
||||||
|
{
|
||||||
|
throw new InvalidRpcArgumentException('channel_uuid', 'The given channel uuid is not a valid UUID V4');
|
||||||
|
}
|
||||||
|
|
||||||
|
$page = 1;
|
||||||
|
$limit = Configuration::getPoliciesConfiguration()->getEncryptionChannelIncomingLimit();
|
||||||
|
if($rpcRequest->containsParameter('page'))
|
||||||
|
{
|
||||||
|
$page = (int)$rpcRequest->getParameter('page');
|
||||||
|
}
|
||||||
|
|
||||||
|
if($rpcRequest->containsParameter('limit'))
|
||||||
|
{
|
||||||
|
$limit = (int)$rpcRequest->getParameter('limit');
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$requestingPeer = $request->getPeer();
|
||||||
|
return $rpcRequest->produceResponse(array_map(function($channel) use ($requestingPeer)
|
||||||
|
{
|
||||||
|
return $channel->toStandard();
|
||||||
|
}, EncryptionChannelManager::getIncomingChannels($requestingPeer->getAddress(), $page, $limit)));
|
||||||
|
}
|
||||||
|
catch(DatabaseOperationException $e)
|
||||||
|
{
|
||||||
|
throw new StandardRpcException('There was an error while trying to obtain incoming encryption channels', StandardError::INTERNAL_SERVER_ERROR, $e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Socialbox\Classes\StandardMethods\EncryptionChannel;
|
||||||
|
|
||||||
|
use Socialbox\Abstracts\Method;
|
||||||
|
use Socialbox\Classes\Configuration;
|
||||||
|
use Socialbox\Enums\StandardError;
|
||||||
|
use Socialbox\Exceptions\DatabaseOperationException;
|
||||||
|
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
||||||
|
use Socialbox\Exceptions\Standard\StandardRpcException;
|
||||||
|
use Socialbox\Interfaces\SerializableInterface;
|
||||||
|
use Socialbox\Managers\EncryptionChannelManager;
|
||||||
|
use Socialbox\Objects\ClientRequest;
|
||||||
|
use Socialbox\Objects\RpcRequest;
|
||||||
|
|
||||||
|
class EncryptionGetOutgoingChannels extends Method
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
|
||||||
|
{
|
||||||
|
if(!$rpcRequest->containsParameter('channel_uuid'))
|
||||||
|
{
|
||||||
|
throw new MissingRpcArgumentException('channel_uuid');
|
||||||
|
}
|
||||||
|
|
||||||
|
$page = 1;
|
||||||
|
$limit = Configuration::getPoliciesConfiguration()->getEncryptionChannelOutgoingLimit();
|
||||||
|
if($rpcRequest->containsParameter('page'))
|
||||||
|
{
|
||||||
|
$page = (int)$rpcRequest->getParameter('page');
|
||||||
|
}
|
||||||
|
|
||||||
|
if($rpcRequest->containsParameter('limit'))
|
||||||
|
{
|
||||||
|
$limit = (int)$rpcRequest->getParameter('limit');
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$requestingPeer = $request->getPeer();
|
||||||
|
return $rpcRequest->produceResponse(array_map(function($channel) use ($requestingPeer)
|
||||||
|
{
|
||||||
|
return $channel->toStandard();
|
||||||
|
}, EncryptionChannelManager::getOutgoingChannels($requestingPeer->getAddress(), $page, $limit)));
|
||||||
|
}
|
||||||
|
catch(DatabaseOperationException $e)
|
||||||
|
{
|
||||||
|
throw new StandardRpcException('There was an error while trying to obtain outgoing encryption channels', StandardError::INTERNAL_SERVER_ERROR, $e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Socialbox\Abstracts\Method;
|
use Socialbox\Abstracts\Method;
|
||||||
|
use Socialbox\Classes\Logger;
|
||||||
use Socialbox\Enums\Flags\SessionFlags;
|
use Socialbox\Enums\Flags\SessionFlags;
|
||||||
use Socialbox\Enums\PrivacyState;
|
use Socialbox\Enums\PrivacyState;
|
||||||
use Socialbox\Enums\StandardError;
|
use Socialbox\Enums\StandardError;
|
||||||
|
@ -31,7 +32,8 @@
|
||||||
{
|
{
|
||||||
throw new MissingRpcArgumentException('field');
|
throw new MissingRpcArgumentException('field');
|
||||||
}
|
}
|
||||||
$fieldName = InformationFieldName::tryFrom(strtoupper($rpcRequest->getParameter('field')));
|
|
||||||
|
$fieldName = InformationFieldName::tryFrom(strtoupper((string)$rpcRequest->getParameter('field')));
|
||||||
if($fieldName === null)
|
if($fieldName === null)
|
||||||
{
|
{
|
||||||
throw new InvalidRpcArgumentException('field');
|
throw new InvalidRpcArgumentException('field');
|
||||||
|
@ -42,17 +44,14 @@
|
||||||
{
|
{
|
||||||
throw new MissingRpcArgumentException('value');
|
throw new MissingRpcArgumentException('value');
|
||||||
}
|
}
|
||||||
|
|
||||||
$value = $rpcRequest->getParameter('value');
|
$value = $rpcRequest->getParameter('value');
|
||||||
if(!$fieldName->validate($value))
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('value');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Privacy parameter is optional
|
// Privacy parameter is optional
|
||||||
$privacy = null;
|
$privacy = null;
|
||||||
if($rpcRequest->containsParameter('privacy') && $rpcRequest->getParameter('privacy') !== null)
|
if($rpcRequest->containsParameter('privacy') && $rpcRequest->getParameter('privacy') !== null)
|
||||||
{
|
{
|
||||||
$privacy = PrivacyState::tryFrom(strtoupper($rpcRequest->getParameter('privacy')));
|
$privacy = PrivacyState::tryFrom(strtoupper((string)$rpcRequest->getParameter('privacy')));
|
||||||
if($privacy === null)
|
if($privacy === null)
|
||||||
{
|
{
|
||||||
throw new InvalidRpcArgumentException('privacy');
|
throw new InvalidRpcArgumentException('privacy');
|
||||||
|
@ -133,8 +132,7 @@
|
||||||
}
|
}
|
||||||
catch (DatabaseOperationException $e)
|
catch (DatabaseOperationException $e)
|
||||||
{
|
{
|
||||||
// Something is seriously wrong if we can't roll back the information field
|
Logger::getLogger()->critical('Failed to rollback information field', $e);
|
||||||
throw new StandardRpcException('Failed to rollback the information field', StandardError::INTERNAL_SERVER_ERROR, $e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if($e instanceof StandardRpcException)
|
if($e instanceof StandardRpcException)
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
namespace Socialbox\Classes\StandardMethods\Settings;
|
namespace Socialbox\Classes\StandardMethods\Settings;
|
||||||
|
|
||||||
use Exception;
|
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use Socialbox\Abstracts\Method;
|
use Socialbox\Abstracts\Method;
|
||||||
use Socialbox\Classes\Configuration;
|
use Socialbox\Classes\Configuration;
|
||||||
|
@ -33,15 +32,11 @@
|
||||||
{
|
{
|
||||||
$expires = (int)$rpcRequest->getParameter('expires');
|
$expires = (int)$rpcRequest->getParameter('expires');
|
||||||
}
|
}
|
||||||
if(!$rpcRequest->containsParameter('name'))
|
|
||||||
{
|
|
||||||
throw new MissingRpcArgumentException('name');
|
|
||||||
}
|
|
||||||
|
|
||||||
$name = null;
|
$name = null;
|
||||||
if($rpcRequest->containsParameter('name'))
|
if($rpcRequest->containsParameter('name'))
|
||||||
{
|
{
|
||||||
$name = $rpcRequest->getParameter('name');
|
$name = (string)$rpcRequest->getParameter('name');
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
|
|
|
@ -27,7 +27,9 @@
|
||||||
{
|
{
|
||||||
throw new MissingRpcArgumentException('field');
|
throw new MissingRpcArgumentException('field');
|
||||||
}
|
}
|
||||||
$fieldName = InformationFieldName::tryFrom(strtoupper($rpcRequest->getParameter('field')));
|
|
||||||
|
$fieldName = InformationFieldName::tryFrom(strtoupper((string)$rpcRequest->getParameter('field')));
|
||||||
|
|
||||||
if($fieldName === null)
|
if($fieldName === null)
|
||||||
{
|
{
|
||||||
throw new InvalidRpcArgumentException('field');
|
throw new InvalidRpcArgumentException('field');
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
|
|
||||||
use Socialbox\Abstracts\Method;
|
use Socialbox\Abstracts\Method;
|
||||||
use Socialbox\Classes\Configuration;
|
use Socialbox\Classes\Configuration;
|
||||||
use Socialbox\Classes\Cryptography;
|
|
||||||
use Socialbox\Enums\StandardError;
|
use Socialbox\Enums\StandardError;
|
||||||
use Socialbox\Exceptions\CryptographyException;
|
use Socialbox\Exceptions\CryptographyException;
|
||||||
use Socialbox\Exceptions\DatabaseOperationException;
|
use Socialbox\Exceptions\DatabaseOperationException;
|
||||||
|
@ -58,14 +57,9 @@
|
||||||
throw new InvalidRpcArgumentException('password', 'When a password is set, the current password must be provided to delete an OTP');
|
throw new InvalidRpcArgumentException('password', 'When a password is set, the current password must be provided to delete an OTP');
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!Cryptography::validateSha512($rpcRequest->getParameter('password')))
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('password', 'The provided password is not a valid SHA-512 hash');
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if(!PasswordManager::verifyPassword($peer, $rpcRequest->getParameter('password')))
|
if(!PasswordManager::verifyPassword($peer, (string)$rpcRequest->getParameter('password')))
|
||||||
{
|
{
|
||||||
return $rpcRequest->produceError(StandardError::FORBIDDEN, 'The provided password is incorrect');
|
return $rpcRequest->produceError(StandardError::FORBIDDEN, 'The provided password is incorrect');
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,11 +4,9 @@
|
||||||
|
|
||||||
use Socialbox\Abstracts\Method;
|
use Socialbox\Abstracts\Method;
|
||||||
use Socialbox\Classes\Configuration;
|
use Socialbox\Classes\Configuration;
|
||||||
use Socialbox\Classes\Cryptography;
|
|
||||||
use Socialbox\Enums\StandardError;
|
use Socialbox\Enums\StandardError;
|
||||||
use Socialbox\Exceptions\CryptographyException;
|
use Socialbox\Exceptions\CryptographyException;
|
||||||
use Socialbox\Exceptions\DatabaseOperationException;
|
use Socialbox\Exceptions\DatabaseOperationException;
|
||||||
use Socialbox\Exceptions\Standard\InvalidRpcArgumentException;
|
|
||||||
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
||||||
use Socialbox\Exceptions\Standard\StandardRpcException;
|
use Socialbox\Exceptions\Standard\StandardRpcException;
|
||||||
use Socialbox\Interfaces\SerializableInterface;
|
use Socialbox\Interfaces\SerializableInterface;
|
||||||
|
@ -37,31 +35,25 @@
|
||||||
throw new MissingRpcArgumentException('password');
|
throw new MissingRpcArgumentException('password');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate the password parameter
|
|
||||||
if(!Cryptography::validateSha512($rpcRequest->getParameter('password')))
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('password', 'Must be a valid SHA-512 hash');
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Get the peer
|
// Get the peer
|
||||||
$peer = $request->getPeer();
|
$requestingPeer = $request->getPeer();
|
||||||
|
|
||||||
// Check if the password is set
|
// Check if the password is set
|
||||||
if (!PasswordManager::usesPassword($peer->getUuid()))
|
if (!PasswordManager::usesPassword($requestingPeer->getUuid()))
|
||||||
{
|
{
|
||||||
return $rpcRequest->produceError(StandardError::METHOD_NOT_ALLOWED, "Cannot delete password when one isn't already set");
|
return $rpcRequest->produceError(StandardError::METHOD_NOT_ALLOWED, "Cannot delete password when one isn't already set");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify the existing password before deleting it
|
// Verify the existing password before deleting it
|
||||||
if (!PasswordManager::verifyPassword($peer->getUuid(), $rpcRequest->getParameter('password')))
|
if (!PasswordManager::verifyPassword($requestingPeer->getUuid(), (string)$rpcRequest->getParameter('password')))
|
||||||
{
|
{
|
||||||
return $rpcRequest->produceResponse(false);
|
return $rpcRequest->produceResponse(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete the password
|
// Delete the password
|
||||||
PasswordManager::deletePassword($peer->getUuid());
|
PasswordManager::deletePassword($requestingPeer->getUuid());
|
||||||
}
|
}
|
||||||
catch(CryptographyException)
|
catch(CryptographyException)
|
||||||
{
|
{
|
||||||
|
|
|
@ -23,28 +23,21 @@
|
||||||
*/
|
*/
|
||||||
public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
|
public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
|
||||||
{
|
{
|
||||||
if(!$rpcRequest->containsParameter('uuid'))
|
if(!$rpcRequest->containsParameter('signature_uuid'))
|
||||||
{
|
{
|
||||||
throw new MissingRpcArgumentException('uuid');
|
throw new MissingRpcArgumentException('signature_uuid');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$signatureUuid = (string)$rpcRequest->getParameter('signature_uuid');
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$uuid = Uuid::fromString($rpcRequest->getParameter('uuid'));
|
if(!SigningKeysManager::signingKeyExists($request->getPeer()->getUuid(), $signatureUuid))
|
||||||
}
|
|
||||||
catch(InvalidArgumentException)
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('uuid');
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if(!SigningKeysManager::signingKeyExists($request->getPeer()->getUuid(), $uuid))
|
|
||||||
{
|
{
|
||||||
return $rpcRequest->produceResponse(false);
|
return $rpcRequest->produceResponse(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
SigningKeysManager::deleteSigningKey($request->getPeer()->getUuid(), $uuid);
|
SigningKeysManager::deleteSigningKey($request->getPeer()->getUuid(), $signatureUuid);
|
||||||
}
|
}
|
||||||
catch(DatabaseOperationException $e)
|
catch(DatabaseOperationException $e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
{
|
{
|
||||||
throw new MissingRpcArgumentException('field');
|
throw new MissingRpcArgumentException('field');
|
||||||
}
|
}
|
||||||
|
|
||||||
$fieldName = InformationFieldName::tryFrom(strtoupper($rpcRequest->getParameter('field')));
|
$fieldName = InformationFieldName::tryFrom(strtoupper($rpcRequest->getParameter('field')));
|
||||||
if($fieldName === null)
|
if($fieldName === null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -19,14 +19,14 @@
|
||||||
*/
|
*/
|
||||||
public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
|
public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
|
||||||
{
|
{
|
||||||
if(!$rpcRequest->containsParameter('uuid') && $rpcRequest->getParameter('uuid') !== null)
|
if(!$rpcRequest->containsParameter('signature_uuid'))
|
||||||
{
|
{
|
||||||
throw new MissingRpcArgumentException('uuid');
|
throw new MissingRpcArgumentException('signature_uuid');
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$key = SigningKeysManager::getSigningKey($request->getPeer()->getUuid(), $rpcRequest->getParameter('uuid'));
|
$key = SigningKeysManager::getSigningKey($request->getPeer()->getUuid(), (string)$rpcRequest->getParameter('signature_uuid'));
|
||||||
}
|
}
|
||||||
catch (DatabaseOperationException $e)
|
catch (DatabaseOperationException $e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -27,7 +27,8 @@
|
||||||
{
|
{
|
||||||
throw new MissingRpcArgumentException('field');
|
throw new MissingRpcArgumentException('field');
|
||||||
}
|
}
|
||||||
$fieldName = InformationFieldName::tryFrom(strtoupper($rpcRequest->getParameter('field')));
|
|
||||||
|
$fieldName = InformationFieldName::tryFrom(strtoupper((string)$rpcRequest->getParameter('field')));
|
||||||
if($fieldName === null)
|
if($fieldName === null)
|
||||||
{
|
{
|
||||||
throw new InvalidRpcArgumentException('field');
|
throw new InvalidRpcArgumentException('field');
|
||||||
|
|
|
@ -4,12 +4,10 @@
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Socialbox\Abstracts\Method;
|
use Socialbox\Abstracts\Method;
|
||||||
use Socialbox\Classes\Cryptography;
|
|
||||||
use Socialbox\Enums\Flags\SessionFlags;
|
use Socialbox\Enums\Flags\SessionFlags;
|
||||||
use Socialbox\Enums\StandardError;
|
use Socialbox\Enums\StandardError;
|
||||||
use Socialbox\Exceptions\CryptographyException;
|
use Socialbox\Exceptions\CryptographyException;
|
||||||
use Socialbox\Exceptions\DatabaseOperationException;
|
use Socialbox\Exceptions\DatabaseOperationException;
|
||||||
use Socialbox\Exceptions\Standard\InvalidRpcArgumentException;
|
|
||||||
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
||||||
use Socialbox\Exceptions\Standard\StandardRpcException;
|
use Socialbox\Exceptions\Standard\StandardRpcException;
|
||||||
use Socialbox\Interfaces\SerializableInterface;
|
use Socialbox\Interfaces\SerializableInterface;
|
||||||
|
@ -26,7 +24,6 @@
|
||||||
*/
|
*/
|
||||||
public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
|
public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$peer = $request->getPeer();
|
$peer = $request->getPeer();
|
||||||
|
@ -65,14 +62,9 @@
|
||||||
throw new MissingRpcArgumentException('password');
|
throw new MissingRpcArgumentException('password');
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!Cryptography::validateSha512($rpcRequest->getParameter('password')))
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('password', 'The provided password is not a valid SHA-512 hash');
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if(!PasswordManager::verifyPassword($peer, $rpcRequest->getParameter('password')))
|
if(!PasswordManager::verifyPassword($peer, (string)$rpcRequest->getParameter('password')))
|
||||||
{
|
{
|
||||||
return $rpcRequest->produceError(StandardError::FORBIDDEN, 'The provided password is incorrect');
|
return $rpcRequest->produceError(StandardError::FORBIDDEN, 'The provided password is incorrect');
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,12 +3,10 @@
|
||||||
namespace Socialbox\Classes\StandardMethods\Settings;
|
namespace Socialbox\Classes\StandardMethods\Settings;
|
||||||
|
|
||||||
use Socialbox\Abstracts\Method;
|
use Socialbox\Abstracts\Method;
|
||||||
use Socialbox\Classes\Cryptography;
|
|
||||||
use Socialbox\Enums\Flags\SessionFlags;
|
use Socialbox\Enums\Flags\SessionFlags;
|
||||||
use Socialbox\Enums\StandardError;
|
use Socialbox\Enums\StandardError;
|
||||||
use Socialbox\Exceptions\CryptographyException;
|
use Socialbox\Exceptions\CryptographyException;
|
||||||
use Socialbox\Exceptions\DatabaseOperationException;
|
use Socialbox\Exceptions\DatabaseOperationException;
|
||||||
use Socialbox\Exceptions\Standard\InvalidRpcArgumentException;
|
|
||||||
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
||||||
use Socialbox\Exceptions\Standard\StandardRpcException;
|
use Socialbox\Exceptions\Standard\StandardRpcException;
|
||||||
use Socialbox\Interfaces\SerializableInterface;
|
use Socialbox\Interfaces\SerializableInterface;
|
||||||
|
@ -28,12 +26,6 @@
|
||||||
{
|
{
|
||||||
throw new MissingRpcArgumentException('password');
|
throw new MissingRpcArgumentException('password');
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!Cryptography::validatePasswordHash($rpcRequest->getParameter('password')))
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('password', "Must be a valid argon2id hash");
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (PasswordManager::usesPassword($request->getPeer()->getUuid()))
|
if (PasswordManager::usesPassword($request->getPeer()->getUuid()))
|
||||||
|
@ -49,7 +41,7 @@
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Set the password
|
// Set the password
|
||||||
PasswordManager::setPassword($request->getPeer(), $rpcRequest->getParameter('password'));
|
PasswordManager::setPassword($request->getPeer(), (string)$rpcRequest->getParameter('password'));
|
||||||
|
|
||||||
// Remove the SET_PASSWORD flag & update the session flow if necessary
|
// Remove the SET_PASSWORD flag & update the session flow if necessary
|
||||||
SessionManager::updateFlow($request->getSession(), [SessionFlags::SET_PASSWORD]);
|
SessionManager::updateFlow($request->getSession(), [SessionFlags::SET_PASSWORD]);
|
||||||
|
|
|
@ -2,13 +2,9 @@
|
||||||
|
|
||||||
namespace Socialbox\Classes\StandardMethods\Settings;
|
namespace Socialbox\Classes\StandardMethods\Settings;
|
||||||
|
|
||||||
use Exception;
|
|
||||||
use InvalidArgumentException;
|
|
||||||
use ncc\ThirdParty\Symfony\Uid\Uuid;
|
|
||||||
use Socialbox\Abstracts\Method;
|
use Socialbox\Abstracts\Method;
|
||||||
use Socialbox\Enums\StandardError;
|
use Socialbox\Enums\StandardError;
|
||||||
use Socialbox\Exceptions\DatabaseOperationException;
|
use Socialbox\Exceptions\DatabaseOperationException;
|
||||||
use Socialbox\Exceptions\Standard\InvalidRpcArgumentException;
|
|
||||||
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
||||||
use Socialbox\Exceptions\Standard\StandardRpcException;
|
use Socialbox\Exceptions\Standard\StandardRpcException;
|
||||||
use Socialbox\Interfaces\SerializableInterface;
|
use Socialbox\Interfaces\SerializableInterface;
|
||||||
|
@ -23,28 +19,20 @@
|
||||||
*/
|
*/
|
||||||
public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
|
public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
|
||||||
{
|
{
|
||||||
if(!$rpcRequest->containsParameter('uuid'))
|
if(!$rpcRequest->containsParameter('signature_uuid'))
|
||||||
{
|
{
|
||||||
throw new MissingRpcArgumentException('uuid');
|
throw new MissingRpcArgumentException('signature_uuid');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$signatureUuid = (string)$rpcRequest->getParameter('signature_uuid');
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$uuid = Uuid::fromString($rpcRequest->getParameter('uuid'));
|
return $rpcRequest->produceResponse(SigningKeysManager::signingKeyExists($request->getPeer()->getUuid(), $signatureUuid));
|
||||||
}
|
|
||||||
catch(InvalidArgumentException)
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('uuid');
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return $rpcRequest->produceResponse(SigningKeysManager::signingKeyExists($request->getPeer()->getUuid(), $uuid));
|
|
||||||
}
|
}
|
||||||
catch(DatabaseOperationException $e)
|
catch(DatabaseOperationException $e)
|
||||||
{
|
{
|
||||||
throw new StandardRpcException('Failed to check the signing key existence', StandardError::INTERNAL_SERVER_ERROR, $e);
|
throw new StandardRpcException('Failed to check the signing key existence', StandardError::INTERNAL_SERVER_ERROR, $e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -27,7 +27,8 @@
|
||||||
{
|
{
|
||||||
throw new MissingRpcArgumentException('field');
|
throw new MissingRpcArgumentException('field');
|
||||||
}
|
}
|
||||||
$fieldName = InformationFieldName::tryFrom(strtoupper($rpcRequest->getParameter('field')));
|
|
||||||
|
$fieldName = InformationFieldName::tryFrom(strtoupper((string)$rpcRequest->getParameter('field')));
|
||||||
if($fieldName === null)
|
if($fieldName === null)
|
||||||
{
|
{
|
||||||
throw new InvalidRpcArgumentException('field');
|
throw new InvalidRpcArgumentException('field');
|
||||||
|
@ -38,11 +39,7 @@
|
||||||
{
|
{
|
||||||
throw new MissingRpcArgumentException('value');
|
throw new MissingRpcArgumentException('value');
|
||||||
}
|
}
|
||||||
$value = $rpcRequest->getParameter('value');
|
$value = (string)$rpcRequest->getParameter('value');
|
||||||
if(!$fieldName->validate($value))
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('value');
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
{
|
{
|
||||||
throw new MissingRpcArgumentException('field');
|
throw new MissingRpcArgumentException('field');
|
||||||
}
|
}
|
||||||
$fieldName = InformationFieldName::tryFrom(strtoupper($rpcRequest->getParameter('field')));
|
$fieldName = InformationFieldName::tryFrom(strtoupper((string)$rpcRequest->getParameter('field')));
|
||||||
if($fieldName === null)
|
if($fieldName === null)
|
||||||
{
|
{
|
||||||
throw new InvalidRpcArgumentException('field');
|
throw new InvalidRpcArgumentException('field');
|
||||||
|
@ -39,7 +39,7 @@
|
||||||
throw new MissingRpcArgumentException('privacy');
|
throw new MissingRpcArgumentException('privacy');
|
||||||
}
|
}
|
||||||
|
|
||||||
$privacy = PrivacyState::tryFrom(strtoupper($rpcRequest->getParameter('privacy')));
|
$privacy = PrivacyState::tryFrom(strtoupper((string)$rpcRequest->getParameter('privacy')));
|
||||||
if($privacy === null)
|
if($privacy === null)
|
||||||
{
|
{
|
||||||
throw new InvalidRpcArgumentException('privacy');
|
throw new InvalidRpcArgumentException('privacy');
|
||||||
|
@ -47,20 +47,19 @@
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$peer = $request->getPeer();
|
$requestingPeer = $request->getPeer();
|
||||||
if(!PeerInformationManager::fieldExists($peer, $fieldName))
|
if(!PeerInformationManager::fieldExists($requestingPeer, $fieldName))
|
||||||
{
|
{
|
||||||
return $rpcRequest->produceResponse(false);
|
return $rpcRequest->produceResponse(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
PeerInformationManager::updatePrivacyState($peer, $fieldName, $privacy);
|
PeerInformationManager::updatePrivacyState($requestingPeer, $fieldName, $privacy);
|
||||||
}
|
}
|
||||||
catch(DatabaseOperationException $e)
|
catch(DatabaseOperationException $e)
|
||||||
{
|
{
|
||||||
throw new StandardRpcException('Failed to update the information field', StandardError::INTERNAL_SERVER_ERROR, $e);
|
throw new StandardRpcException('Failed to update the information field', StandardError::INTERNAL_SERVER_ERROR, $e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return $rpcRequest->produceResponse(true);
|
return $rpcRequest->produceResponse(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,11 +3,9 @@
|
||||||
namespace Socialbox\Classes\StandardMethods\Settings;
|
namespace Socialbox\Classes\StandardMethods\Settings;
|
||||||
|
|
||||||
use Socialbox\Abstracts\Method;
|
use Socialbox\Abstracts\Method;
|
||||||
use Socialbox\Classes\Cryptography;
|
|
||||||
use Socialbox\Enums\StandardError;
|
use Socialbox\Enums\StandardError;
|
||||||
use Socialbox\Exceptions\CryptographyException;
|
use Socialbox\Exceptions\CryptographyException;
|
||||||
use Socialbox\Exceptions\DatabaseOperationException;
|
use Socialbox\Exceptions\DatabaseOperationException;
|
||||||
use Socialbox\Exceptions\Standard\InvalidRpcArgumentException;
|
|
||||||
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
||||||
use Socialbox\Exceptions\Standard\StandardRpcException;
|
use Socialbox\Exceptions\Standard\StandardRpcException;
|
||||||
use Socialbox\Interfaces\SerializableInterface;
|
use Socialbox\Interfaces\SerializableInterface;
|
||||||
|
@ -26,22 +24,11 @@
|
||||||
{
|
{
|
||||||
throw new MissingRpcArgumentException('password');
|
throw new MissingRpcArgumentException('password');
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!Cryptography::validatePasswordHash($rpcRequest->getParameter('password')))
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('password', 'Must be a valid argon2id hash');
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!$rpcRequest->containsParameter('existing_password'))
|
if(!$rpcRequest->containsParameter('existing_password'))
|
||||||
{
|
{
|
||||||
throw new MissingRpcArgumentException('existing_password');
|
throw new MissingRpcArgumentException('existing_password');
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!Cryptography::validateSha512($rpcRequest->getParameter('existing_password')))
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('existing_password', 'Must be a valid SHA-512 hash');
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!PasswordManager::usesPassword($request->getPeer()->getUuid()))
|
if (!PasswordManager::usesPassword($request->getPeer()->getUuid()))
|
||||||
|
@ -73,7 +60,7 @@
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Set the password
|
// Set the password
|
||||||
PasswordManager::updatePassword($request->getPeer(), $rpcRequest->getParameter('password'));
|
PasswordManager::updatePassword($request->getPeer(), (string)$rpcRequest->getParameter('password'));
|
||||||
}
|
}
|
||||||
catch(CryptographyException $e)
|
catch(CryptographyException $e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$result = CaptchaManager::answerCaptcha($session->getPeerUuid(), $rpcRequest->getParameter('answer'));
|
$result = CaptchaManager::answerCaptcha($session->getPeerUuid(), (string)$rpcRequest->getParameter('answer'));
|
||||||
|
|
||||||
if($result)
|
if($result)
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if(!$request->getPeer()->isExternal())
|
if(!$request->isExternal())
|
||||||
{
|
{
|
||||||
return $rpcRequest->produceError(StandardError::FORBIDDEN, 'Only external peers can authenticate using this method');
|
return $rpcRequest->produceError(StandardError::FORBIDDEN, 'Only external peers can authenticate using this method');
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@
|
||||||
|
|
||||||
// Build the captcha
|
// Build the captcha
|
||||||
// Returns HTML base64 encoded image of the captcha
|
// Returns HTML base64 encoded image of the captcha
|
||||||
// Important note: Must always be HTML-BASE64 which means it must be prefixed with `data:image/jpeg;base64,`
|
// Important note: Must always be data URI scheme eg; data:content/type;base64,
|
||||||
return $rpcRequest->produceResponse(new ImageCaptchaVerification([
|
return $rpcRequest->produceResponse(new ImageCaptchaVerification([
|
||||||
'expires' => $captchaRecord->getExpires(),
|
'expires' => $captchaRecord->getExpires(),
|
||||||
'content' => (new CaptchaBuilder($answer))->build()->inline()
|
'content' => (new CaptchaBuilder($answer))->build()->inline()
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
use Socialbox\Enums\Flags\SessionFlags;
|
use Socialbox\Enums\Flags\SessionFlags;
|
||||||
use Socialbox\Enums\StandardError;
|
use Socialbox\Enums\StandardError;
|
||||||
use Socialbox\Exceptions\CryptographyException;
|
use Socialbox\Exceptions\CryptographyException;
|
||||||
|
use Socialbox\Exceptions\DatabaseOperationException;
|
||||||
use Socialbox\Exceptions\Standard\InvalidRpcArgumentException;
|
use Socialbox\Exceptions\Standard\InvalidRpcArgumentException;
|
||||||
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
||||||
use Socialbox\Exceptions\Standard\StandardRpcException;
|
use Socialbox\Exceptions\Standard\StandardRpcException;
|
||||||
|
@ -35,7 +36,15 @@
|
||||||
throw new InvalidRpcArgumentException('code', 'Invalid OTP code length');
|
throw new InvalidRpcArgumentException('code', 'Invalid OTP code length');
|
||||||
}
|
}
|
||||||
|
|
||||||
$session = $request->getSession();
|
try
|
||||||
|
{
|
||||||
|
$session = $request->getSession();
|
||||||
|
}
|
||||||
|
catch (DatabaseOperationException $e)
|
||||||
|
{
|
||||||
|
throw new StandardRpcException('An error occurred while trying to get the session', StandardError::INTERNAL_SERVER_ERROR, $e);
|
||||||
|
}
|
||||||
|
|
||||||
if(!$session->flagExists(SessionFlags::VER_OTP))
|
if(!$session->flagExists(SessionFlags::VER_OTP))
|
||||||
{
|
{
|
||||||
return $rpcRequest->produceError(StandardError::METHOD_NOT_ALLOWED, 'One Time Password verification is not required at this time');
|
return $rpcRequest->produceError(StandardError::METHOD_NOT_ALLOWED, 'One Time Password verification is not required at this time');
|
||||||
|
|
|
@ -4,11 +4,9 @@
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Socialbox\Abstracts\Method;
|
use Socialbox\Abstracts\Method;
|
||||||
use Socialbox\Classes\Cryptography;
|
|
||||||
use Socialbox\Enums\Flags\SessionFlags;
|
use Socialbox\Enums\Flags\SessionFlags;
|
||||||
use Socialbox\Enums\StandardError;
|
use Socialbox\Enums\StandardError;
|
||||||
use Socialbox\Exceptions\CryptographyException;
|
use Socialbox\Exceptions\CryptographyException;
|
||||||
use Socialbox\Exceptions\Standard\InvalidRpcArgumentException;
|
|
||||||
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
||||||
use Socialbox\Exceptions\Standard\StandardRpcException;
|
use Socialbox\Exceptions\Standard\StandardRpcException;
|
||||||
use Socialbox\Interfaces\SerializableInterface;
|
use Socialbox\Interfaces\SerializableInterface;
|
||||||
|
@ -30,11 +28,6 @@
|
||||||
throw new MissingRpcArgumentException('password');
|
throw new MissingRpcArgumentException('password');
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!Cryptography::validateSha512($rpcRequest->getParameter('password')))
|
|
||||||
{
|
|
||||||
throw new InvalidRpcArgumentException('password', 'Invalid SHA-512 hash');
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$session = $request->getSession();
|
$session = $request->getSession();
|
||||||
|
|
|
@ -46,7 +46,7 @@
|
||||||
}
|
}
|
||||||
catch(JsonException $e)
|
catch(JsonException $e)
|
||||||
{
|
{
|
||||||
throw new InvalidArgumentException("Failed to encode json input", $e);
|
throw new InvalidArgumentException("Failed to encode json input", 0, $e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -79,4 +79,17 @@
|
||||||
{
|
{
|
||||||
return preg_match("/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/", $uuid) === 1;
|
return preg_match("/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/", $uuid) === 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if a given Unix timestamp falls within a specified range of the current time.
|
||||||
|
*
|
||||||
|
* @param int $timestamp The Unix timestamp to check.
|
||||||
|
* @param int $range The range in seconds within which the timestamp should fall.
|
||||||
|
* @return bool True if the timestamp is within the range, false otherwise.
|
||||||
|
*/
|
||||||
|
public static function isTimestampInRange(int $timestamp, int $range): bool
|
||||||
|
{
|
||||||
|
$currentTime = time();
|
||||||
|
return ($timestamp >= ($currentTime - $range)) && ($timestamp <= ($currentTime + $range));
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -8,6 +8,7 @@
|
||||||
use Socialbox\Classes\StandardMethods\AddressBook\AddressBookDeleteContact;
|
use Socialbox\Classes\StandardMethods\AddressBook\AddressBookDeleteContact;
|
||||||
use Socialbox\Classes\StandardMethods\AddressBook\AddressBookGetContact;
|
use Socialbox\Classes\StandardMethods\AddressBook\AddressBookGetContact;
|
||||||
use Socialbox\Classes\StandardMethods\AddressBook\AddressBookGetContacts;
|
use Socialbox\Classes\StandardMethods\AddressBook\AddressBookGetContacts;
|
||||||
|
use Socialbox\Classes\StandardMethods\AddressBook\AddressBookRevokeAllSignatures;
|
||||||
use Socialbox\Classes\StandardMethods\AddressBook\AddressBookRevokeSignature;
|
use Socialbox\Classes\StandardMethods\AddressBook\AddressBookRevokeSignature;
|
||||||
use Socialbox\Classes\StandardMethods\AddressBook\AddressBookTrustSignature;
|
use Socialbox\Classes\StandardMethods\AddressBook\AddressBookTrustSignature;
|
||||||
use Socialbox\Classes\StandardMethods\AddressBook\AddressBookUpdateRelationship;
|
use Socialbox\Classes\StandardMethods\AddressBook\AddressBookUpdateRelationship;
|
||||||
|
@ -18,6 +19,21 @@
|
||||||
use Socialbox\Classes\StandardMethods\Core\ResolvePeer;
|
use Socialbox\Classes\StandardMethods\Core\ResolvePeer;
|
||||||
use Socialbox\Classes\StandardMethods\Core\ResolveSignature;
|
use Socialbox\Classes\StandardMethods\Core\ResolveSignature;
|
||||||
use Socialbox\Classes\StandardMethods\Core\VerifySignature;
|
use Socialbox\Classes\StandardMethods\Core\VerifySignature;
|
||||||
|
use Socialbox\Classes\StandardMethods\EncryptionChannel\EncryptionAcceptChannel;
|
||||||
|
use Socialbox\Classes\StandardMethods\EncryptionChannel\EncryptionChannelAcknowledgeMessage;
|
||||||
|
use Socialbox\Classes\StandardMethods\EncryptionChannel\EncryptionChannelExists;
|
||||||
|
use Socialbox\Classes\StandardMethods\EncryptionChannel\EncryptionChannelReceive;
|
||||||
|
use Socialbox\Classes\StandardMethods\EncryptionChannel\EncryptionChannelRejectMessage;
|
||||||
|
use Socialbox\Classes\StandardMethods\EncryptionChannel\EncryptionChannelSend;
|
||||||
|
use Socialbox\Classes\StandardMethods\EncryptionChannel\EncryptionCloseChannel;
|
||||||
|
use Socialbox\Classes\StandardMethods\EncryptionChannel\EncryptionCreateChannel;
|
||||||
|
use Socialbox\Classes\StandardMethods\EncryptionChannel\EncryptionDeclineChannel;
|
||||||
|
use Socialbox\Classes\StandardMethods\EncryptionChannel\EncryptionDeleteChannel;
|
||||||
|
use Socialbox\Classes\StandardMethods\EncryptionChannel\EncryptionGetChannel;
|
||||||
|
use Socialbox\Classes\StandardMethods\EncryptionChannel\EncryptionGetChannelRequests;
|
||||||
|
use Socialbox\Classes\StandardMethods\EncryptionChannel\EncryptionGetChannels;
|
||||||
|
use Socialbox\Classes\StandardMethods\EncryptionChannel\EncryptionGetIncomingChannels;
|
||||||
|
use Socialbox\Classes\StandardMethods\EncryptionChannel\EncryptionGetOutgoingChannels;
|
||||||
use Socialbox\Classes\StandardMethods\ServerDocuments\AcceptCommunityGuidelines;
|
use Socialbox\Classes\StandardMethods\ServerDocuments\AcceptCommunityGuidelines;
|
||||||
use Socialbox\Classes\StandardMethods\ServerDocuments\AcceptPrivacyPolicy;
|
use Socialbox\Classes\StandardMethods\ServerDocuments\AcceptPrivacyPolicy;
|
||||||
use Socialbox\Classes\StandardMethods\ServerDocuments\AcceptTermsOfService;
|
use Socialbox\Classes\StandardMethods\ServerDocuments\AcceptTermsOfService;
|
||||||
|
@ -64,8 +80,9 @@
|
||||||
case ADDRESS_BOOK_DELETE_CONTACT = 'addressBookDeleteContact';
|
case ADDRESS_BOOK_DELETE_CONTACT = 'addressBookDeleteContact';
|
||||||
case ADDRESS_BOOK_GET_CONTACT = 'addressBookGetContact';
|
case ADDRESS_BOOK_GET_CONTACT = 'addressBookGetContact';
|
||||||
case ADDRESS_BOOK_GET_CONTACTS = 'addressBookGetContacts';
|
case ADDRESS_BOOK_GET_CONTACTS = 'addressBookGetContacts';
|
||||||
case ADDRESS_BOOK_TRUST_SIGNATURE = 'addressBookTrustSignature';
|
case ADDRESS_BOOK_REVOKE_ALL_SIGNATURES = 'addressBookRevokeAllSignatures';
|
||||||
case ADDRESS_BOOK_REVOKE_SIGNATURE = 'addressBookRevokeSignature';
|
case ADDRESS_BOOK_REVOKE_SIGNATURE = 'addressBookRevokeSignature';
|
||||||
|
case ADDRESS_BOOK_TRUST_SIGNATURE = 'addressBookTrustSignature';
|
||||||
case ADDRESS_BOOK_UPDATE_RELATIONSHIP = 'addressBookUpdateRelationship';
|
case ADDRESS_BOOK_UPDATE_RELATIONSHIP = 'addressBookUpdateRelationship';
|
||||||
|
|
||||||
// Core Methods
|
// Core Methods
|
||||||
|
@ -81,11 +98,18 @@
|
||||||
case ENCRYPTION_ACCEPT_CHANNEL = 'encryptionAcceptChannel';
|
case ENCRYPTION_ACCEPT_CHANNEL = 'encryptionAcceptChannel';
|
||||||
case ENCRYPTION_CHANNEL_ACKNOWLEDGE_MESSAGE = 'encryptionChannelAcknowledgeMessage';
|
case ENCRYPTION_CHANNEL_ACKNOWLEDGE_MESSAGE = 'encryptionChannelAcknowledgeMessage';
|
||||||
case ENCRYPTION_CHANNEL_EXISTS = 'encryptionChannelExists';
|
case ENCRYPTION_CHANNEL_EXISTS = 'encryptionChannelExists';
|
||||||
|
case ENCRYPTION_CHANNEL_RECEIVE = 'encryptionChannelReceive';
|
||||||
|
case ENCRYPTION_CHANNEL_REJECT_MESSAGE = 'encryptionChannelRejectMessage';
|
||||||
case ENCRYPTION_CHANNEL_SEND = 'encryptionChannelSend';
|
case ENCRYPTION_CHANNEL_SEND = 'encryptionChannelSend';
|
||||||
case ENCRYPTION_CLOSE_CHANNEL = 'encryptionCloseChannel';
|
case ENCRYPTION_CLOSE_CHANNEL = 'encryptionCloseChannel';
|
||||||
case ENCRYPTION_CREATE_CHANNEL = 'encryptionCreateChannel';
|
case ENCRYPTION_CREATE_CHANNEL = 'encryptionCreateChannel';
|
||||||
case ENCRYPTION_DECLINE_CHANNEL = 'encryptionDeclineChannel';
|
case ENCRYPTION_DECLINE_CHANNEL = 'encryptionDeclineChannel';
|
||||||
|
case ENCRYPTION_DELETE_CHANNEL = 'encryptionDeleteChannel';
|
||||||
case ENCRYPTION_GET_CHANNEL = 'encryptionGetChannel';
|
case ENCRYPTION_GET_CHANNEL = 'encryptionGetChannel';
|
||||||
|
case ENCRYPTION_GET_CHANNEL_REQUESTS = 'encryptionGetChannelRequests';
|
||||||
|
case ENCRYPTION_GET_CHANNELS = 'encryptionGetChannels';
|
||||||
|
case ENCRYPTION_GET_INCOMING_CHANNELS = 'encryptionGetIncomingChannels';
|
||||||
|
case ENCRYPTION_GET_OUTGOING_CHANNELS = 'encryptionGetOutgoingChannels';
|
||||||
|
|
||||||
// ServerDocument Methods
|
// ServerDocument Methods
|
||||||
case ACCEPT_COMMUNITY_GUIDELINES = 'acceptCommunityGuidelines';
|
case ACCEPT_COMMUNITY_GUIDELINES = 'acceptCommunityGuidelines';
|
||||||
|
@ -181,8 +205,9 @@
|
||||||
self::ADDRESS_BOOK_DELETE_CONTACT => AddressBookDeleteContact::execute($request, $rpcRequest),
|
self::ADDRESS_BOOK_DELETE_CONTACT => AddressBookDeleteContact::execute($request, $rpcRequest),
|
||||||
self::ADDRESS_BOOK_GET_CONTACT => AddressBookGetContact::execute($request, $rpcRequest),
|
self::ADDRESS_BOOK_GET_CONTACT => AddressBookGetContact::execute($request, $rpcRequest),
|
||||||
self::ADDRESS_BOOK_GET_CONTACTS => AddressBookGetContacts::execute($request, $rpcRequest),
|
self::ADDRESS_BOOK_GET_CONTACTS => AddressBookGetContacts::execute($request, $rpcRequest),
|
||||||
self::ADDRESS_BOOK_TRUST_SIGNATURE => AddressBookTrustSignature::execute($request, $rpcRequest),
|
self::ADDRESS_BOOK_REVOKE_ALL_SIGNATURES => AddressBookRevokeAllSignatures::execute($request, $rpcRequest),
|
||||||
self::ADDRESS_BOOK_REVOKE_SIGNATURE => AddressBookRevokeSignature::execute($request, $rpcRequest),
|
self::ADDRESS_BOOK_REVOKE_SIGNATURE => AddressBookRevokeSignature::execute($request, $rpcRequest),
|
||||||
|
self::ADDRESS_BOOK_TRUST_SIGNATURE => AddressBookTrustSignature::execute($request, $rpcRequest),
|
||||||
self::ADDRESS_BOOK_UPDATE_RELATIONSHIP => AddressBookUpdateRelationship::execute($request, $rpcRequest),
|
self::ADDRESS_BOOK_UPDATE_RELATIONSHIP => AddressBookUpdateRelationship::execute($request, $rpcRequest),
|
||||||
|
|
||||||
// Core Methods
|
// Core Methods
|
||||||
|
@ -194,6 +219,23 @@
|
||||||
self::RESOLVE_SIGNATURE => ResolveSignature::execute($request, $rpcRequest),
|
self::RESOLVE_SIGNATURE => ResolveSignature::execute($request, $rpcRequest),
|
||||||
self::VERIFY_SIGNATURE => VerifySignature::execute($request, $rpcRequest),
|
self::VERIFY_SIGNATURE => VerifySignature::execute($request, $rpcRequest),
|
||||||
|
|
||||||
|
// Encryption Channel Methods
|
||||||
|
self::ENCRYPTION_ACCEPT_CHANNEL => EncryptionAcceptChannel::execute($request, $rpcRequest),
|
||||||
|
self::ENCRYPTION_CHANNEL_ACKNOWLEDGE_MESSAGE => EncryptionChannelAcknowledgeMessage::execute($request, $rpcRequest),
|
||||||
|
self::ENCRYPTION_CHANNEL_EXISTS => EncryptionChannelExists::execute($request, $rpcRequest),
|
||||||
|
self::ENCRYPTION_CHANNEL_RECEIVE => EncryptionChannelReceive::execute($request, $rpcRequest),
|
||||||
|
self::ENCRYPTION_CHANNEL_REJECT_MESSAGE => EncryptionChannelRejectMessage::execute($request, $rpcRequest),
|
||||||
|
self::ENCRYPTION_CHANNEL_SEND => EncryptionChannelSend::execute($request, $rpcRequest),
|
||||||
|
self::ENCRYPTION_CLOSE_CHANNEL => EncryptionCloseChannel::execute($request, $rpcRequest),
|
||||||
|
self::ENCRYPTION_CREATE_CHANNEL => EncryptionCreateChannel::execute($request, $rpcRequest),
|
||||||
|
self::ENCRYPTION_DECLINE_CHANNEL => EncryptionDeclineChannel::execute($request, $rpcRequest),
|
||||||
|
self::ENCRYPTION_DELETE_CHANNEL => EncryptionDeleteChannel::execute($request, $rpcRequest),
|
||||||
|
self::ENCRYPTION_GET_CHANNEL => EncryptionGetChannel::execute($request, $rpcRequest),
|
||||||
|
self::ENCRYPTION_GET_CHANNEL_REQUESTS => EncryptionGetChannelRequests::execute($request, $rpcRequest),
|
||||||
|
self::ENCRYPTION_GET_CHANNELS => EncryptionGetChannels::execute($request, $rpcRequest),
|
||||||
|
self::ENCRYPTION_GET_INCOMING_CHANNELS => EncryptionGetIncomingChannels::execute($request, $rpcRequest),
|
||||||
|
self::ENCRYPTION_GET_OUTGOING_CHANNELS => EncryptionGetOutgoingChannels::execute($request, $rpcRequest),
|
||||||
|
|
||||||
// Server Document Methods
|
// Server Document Methods
|
||||||
self::ACCEPT_PRIVACY_POLICY => AcceptPrivacyPolicy::execute($request, $rpcRequest),
|
self::ACCEPT_PRIVACY_POLICY => AcceptPrivacyPolicy::execute($request, $rpcRequest),
|
||||||
self::ACCEPT_COMMUNITY_GUIDELINES => AcceptCommunityGuidelines::execute($request, $rpcRequest),
|
self::ACCEPT_COMMUNITY_GUIDELINES => AcceptCommunityGuidelines::execute($request, $rpcRequest),
|
||||||
|
|
|
@ -3,10 +3,12 @@
|
||||||
namespace Socialbox\Managers;
|
namespace Socialbox\Managers;
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
|
use InvalidArgumentException;
|
||||||
use PDOException;
|
use PDOException;
|
||||||
use Socialbox\Classes\Database;
|
use Socialbox\Classes\Database;
|
||||||
use Socialbox\Classes\Logger;
|
use Socialbox\Classes\Logger;
|
||||||
use Socialbox\Classes\Utilities;
|
use Socialbox\Classes\Utilities;
|
||||||
|
use Socialbox\Classes\Validator;
|
||||||
use Socialbox\Enums\Status\CaptchaStatus;
|
use Socialbox\Enums\Status\CaptchaStatus;
|
||||||
use Socialbox\Exceptions\DatabaseOperationException;
|
use Socialbox\Exceptions\DatabaseOperationException;
|
||||||
use Socialbox\Objects\Database\CaptchaRecord;
|
use Socialbox\Objects\Database\CaptchaRecord;
|
||||||
|
@ -17,26 +19,30 @@
|
||||||
/**
|
/**
|
||||||
* Creates a new captcha for the given peer UUID.
|
* Creates a new captcha for the given peer UUID.
|
||||||
*
|
*
|
||||||
* @param string|PeerDatabaseRecord $peer_uuid The UUID of the peer to create the captcha for.
|
* @param string|PeerDatabaseRecord $peerUuid The UUID of the peer to create the captcha for.
|
||||||
* @return string The answer to the captcha.
|
* @return string The answer to the captcha.
|
||||||
* @throws DatabaseOperationException If the operation fails.
|
* @throws DatabaseOperationException If the operation fails.
|
||||||
*/
|
*/
|
||||||
public static function createCaptcha(string|PeerDatabaseRecord $peer_uuid): string
|
public static function createCaptcha(string|PeerDatabaseRecord $peerUuid): string
|
||||||
{
|
{
|
||||||
// If the peer_uuid is a RegisteredPeerRecord, get the UUID
|
// If the peer_uuid is a RegisteredPeerRecord, get the UUID
|
||||||
if($peer_uuid instanceof PeerDatabaseRecord)
|
if($peerUuid instanceof PeerDatabaseRecord)
|
||||||
{
|
{
|
||||||
$peer_uuid = $peer_uuid->getUuid();
|
$peerUuid = $peerUuid->getUuid();
|
||||||
|
}
|
||||||
|
elseif(!Validator::validateUuid($peerUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given internal peer UUID is not a valid UUID V4');
|
||||||
}
|
}
|
||||||
|
|
||||||
$answer = Utilities::randomString(6, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789');
|
$answer = Utilities::randomString(6, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789');
|
||||||
$current_time = (new DateTime())->setTimestamp(time())->format('Y-m-d H:i:s');
|
$current_time = (new DateTime())->setTimestamp(time())->format('Y-m-d H:i:s');
|
||||||
|
|
||||||
if(!self::captchaExists($peer_uuid))
|
if(!self::captchaExists($peerUuid))
|
||||||
{
|
{
|
||||||
Logger::getLogger()->debug('Creating a new captcha record for peer ' . $peer_uuid);
|
Logger::getLogger()->debug('Creating a new captcha record for peer ' . $peerUuid);
|
||||||
$statement = Database::getConnection()->prepare("INSERT INTO captcha_images (peer_uuid, created, answer) VALUES (?, ?, ?)");
|
$statement = Database::getConnection()->prepare("INSERT INTO captcha_images (peer_uuid, created, answer) VALUES (?, ?, ?)");
|
||||||
$statement->bindParam(1, $peer_uuid);
|
$statement->bindParam(1, $peerUuid);
|
||||||
$statement->bindParam(2, $current_time);
|
$statement->bindParam(2, $current_time);
|
||||||
$statement->bindParam(3, $answer);
|
$statement->bindParam(3, $answer);
|
||||||
|
|
||||||
|
@ -52,11 +58,11 @@
|
||||||
return $answer;
|
return $answer;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::getLogger()->debug('Updating an existing captcha record for peer ' . $peer_uuid);
|
Logger::getLogger()->debug('Updating an existing captcha record for peer ' . $peerUuid);
|
||||||
$statement = Database::getConnection()->prepare("UPDATE captcha_images SET answer=?, status='UNSOLVED', created=? WHERE peer_uuid=?");
|
$statement = Database::getConnection()->prepare("UPDATE captcha_images SET answer=?, status='UNSOLVED', created=? WHERE peer_uuid=?");
|
||||||
$statement->bindParam(1, $answer);
|
$statement->bindParam(1, $answer);
|
||||||
$statement->bindParam(2, $current_time);
|
$statement->bindParam(2, $current_time);
|
||||||
$statement->bindParam(3, $peer_uuid);
|
$statement->bindParam(3, $peerUuid);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -73,25 +79,25 @@
|
||||||
/**
|
/**
|
||||||
* Answers a captcha for the given peer UUID.
|
* Answers a captcha for the given peer UUID.
|
||||||
*
|
*
|
||||||
* @param string|PeerDatabaseRecord $peer_uuid The UUID of the peer to answer the captcha for.
|
* @param string|PeerDatabaseRecord $peerUuid The UUID of the peer to answer the captcha for.
|
||||||
* @param string $answer The answer to the captcha.
|
* @param string $answer The answer to the captcha.
|
||||||
* @return bool True if the answer is correct, false otherwise.
|
* @return bool True if the answer is correct, false otherwise.
|
||||||
* @throws DatabaseOperationException If the operation fails.
|
* @throws DatabaseOperationException If the operation fails.
|
||||||
*/
|
*/
|
||||||
public static function answerCaptcha(string|PeerDatabaseRecord $peer_uuid, string $answer): bool
|
public static function answerCaptcha(string|PeerDatabaseRecord $peerUuid, string $answer): bool
|
||||||
{
|
{
|
||||||
if($peer_uuid instanceof PeerDatabaseRecord)
|
if($peerUuid instanceof PeerDatabaseRecord)
|
||||||
{
|
{
|
||||||
$peer_uuid = $peer_uuid->getUuid();
|
$peerUuid = $peerUuid->getUuid();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return false if the captcha does not exist
|
// Return false if the captcha does not exist
|
||||||
if(!self::captchaExists($peer_uuid))
|
if(!self::captchaExists($peerUuid))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$captcha = self::getCaptcha($peer_uuid);
|
$captcha = self::getCaptcha($peerUuid);
|
||||||
|
|
||||||
// Return false if the captcha has already been solved
|
// Return false if the captcha has already been solved
|
||||||
if($captcha->getStatus() === CaptchaStatus::SOLVED)
|
if($captcha->getStatus() === CaptchaStatus::SOLVED)
|
||||||
|
@ -112,7 +118,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
$statement = Database::getConnection()->prepare("UPDATE captcha_images SET status='SOLVED', answered=NOW() WHERE peer_uuid=?");
|
$statement = Database::getConnection()->prepare("UPDATE captcha_images SET status='SOLVED', answered=NOW() WHERE peer_uuid=?");
|
||||||
$statement->bindParam(1, $peer_uuid);
|
$statement->bindParam(1, $peerUuid);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -129,24 +135,24 @@
|
||||||
/**
|
/**
|
||||||
* Retrieves the captcha record for the given peer UUID.
|
* Retrieves the captcha record for the given peer UUID.
|
||||||
*
|
*
|
||||||
* @param string|PeerDatabaseRecord $peer_uuid The UUID of the peer to retrieve the captcha for.
|
* @param string|PeerDatabaseRecord $peerUuid The UUID of the peer to retrieve the captcha for.
|
||||||
* @return CaptchaRecord|null The captcha record.
|
* @return CaptchaRecord|null The captcha record.
|
||||||
* @throws DatabaseOperationException If the operation fails.
|
* @throws DatabaseOperationException If the operation fails.
|
||||||
*/
|
*/
|
||||||
public static function getCaptcha(string|PeerDatabaseRecord $peer_uuid): ?CaptchaRecord
|
public static function getCaptcha(string|PeerDatabaseRecord $peerUuid): ?CaptchaRecord
|
||||||
{
|
{
|
||||||
// If the peer_uuid is a RegisteredPeerRecord, get the UUID
|
// If the peer_uuid is a RegisteredPeerRecord, get the UUID
|
||||||
if($peer_uuid instanceof PeerDatabaseRecord)
|
if($peerUuid instanceof PeerDatabaseRecord)
|
||||||
{
|
{
|
||||||
$peer_uuid = $peer_uuid->getUuid();
|
$peerUuid = $peerUuid->getUuid();
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::getLogger()->debug('Getting the captcha record for peer ' . $peer_uuid);
|
Logger::getLogger()->debug('Getting the captcha record for peer ' . $peerUuid);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$statement = Database::getConnection()->prepare("SELECT * FROM captcha_images WHERE peer_uuid=? LIMIT 1");
|
$statement = Database::getConnection()->prepare("SELECT * FROM captcha_images WHERE peer_uuid=? LIMIT 1");
|
||||||
$statement->bindParam(1, $peer_uuid);
|
$statement->bindParam(1, $peerUuid);
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
$result = $statement->fetch();
|
$result = $statement->fetch();
|
||||||
}
|
}
|
||||||
|
@ -166,24 +172,24 @@
|
||||||
/**
|
/**
|
||||||
* Checks if a captcha exists for the given peer UUID.
|
* Checks if a captcha exists for the given peer UUID.
|
||||||
*
|
*
|
||||||
* @param string|PeerDatabaseRecord $peer_uuid The UUID of the peer to check for a captcha.
|
* @param string|PeerDatabaseRecord $peerUuid The UUID of the peer to check for a captcha.
|
||||||
* @return bool True if a captcha exists, false otherwise.
|
* @return bool True if a captcha exists, false otherwise.
|
||||||
* @throws DatabaseOperationException If the operation fails.
|
* @throws DatabaseOperationException If the operation fails.
|
||||||
*/
|
*/
|
||||||
public static function captchaExists(string|PeerDatabaseRecord $peer_uuid): bool
|
public static function captchaExists(string|PeerDatabaseRecord $peerUuid): bool
|
||||||
{
|
{
|
||||||
// If the peer_uuid is a RegisteredPeerRecord, get the UUID
|
// If the peer_uuid is a RegisteredPeerRecord, get the UUID
|
||||||
if($peer_uuid instanceof PeerDatabaseRecord)
|
if($peerUuid instanceof PeerDatabaseRecord)
|
||||||
{
|
{
|
||||||
$peer_uuid = $peer_uuid->getUuid();
|
$peerUuid = $peerUuid->getUuid();
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::getLogger()->debug('Checking if a captcha exists for peer ' . $peer_uuid);
|
Logger::getLogger()->debug('Checking if a captcha exists for peer ' . $peerUuid);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$statement = Database::getConnection()->prepare("SELECT COUNT(*) FROM captcha_images WHERE peer_uuid=?");
|
$statement = Database::getConnection()->prepare("SELECT COUNT(*) FROM captcha_images WHERE peer_uuid=?");
|
||||||
$statement->bindParam(1, $peer_uuid);
|
$statement->bindParam(1, $peerUuid);
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
$result = $statement->fetchColumn();
|
$result = $statement->fetchColumn();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,10 +2,15 @@
|
||||||
|
|
||||||
namespace Socialbox\Managers;
|
namespace Socialbox\Managers;
|
||||||
|
|
||||||
|
use DateTime;
|
||||||
|
use InvalidArgumentException;
|
||||||
use ncc\ThirdParty\Symfony\Uid\UuidV4;
|
use ncc\ThirdParty\Symfony\Uid\UuidV4;
|
||||||
use PDO;
|
use PDO;
|
||||||
use PDOException;
|
use PDOException;
|
||||||
|
use Socialbox\Classes\Configuration;
|
||||||
|
use Socialbox\Classes\Cryptography;
|
||||||
use Socialbox\Classes\Database;
|
use Socialbox\Classes\Database;
|
||||||
|
use Socialbox\Classes\Validator;
|
||||||
use Socialbox\Enums\Types\ContactRelationshipType;
|
use Socialbox\Enums\Types\ContactRelationshipType;
|
||||||
use Socialbox\Exceptions\DatabaseOperationException;
|
use Socialbox\Exceptions\DatabaseOperationException;
|
||||||
use Socialbox\Objects\Database\ContactDatabaseRecord;
|
use Socialbox\Objects\Database\ContactDatabaseRecord;
|
||||||
|
@ -30,6 +35,15 @@
|
||||||
{
|
{
|
||||||
$contactAddress = $contactAddress->getAddress();
|
$contactAddress = $contactAddress->getAddress();
|
||||||
}
|
}
|
||||||
|
elseif(!Validator::validateUuid($contactAddress))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given contact address is invalid');
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!Validator::validateUuid($peerUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given peer internal UUID is not a valid UUID V4');
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -63,6 +77,15 @@
|
||||||
{
|
{
|
||||||
$contactAddress = $contactAddress->getAddress();
|
$contactAddress = $contactAddress->getAddress();
|
||||||
}
|
}
|
||||||
|
elseif(!Validator::validatePeerAddress($contactAddress))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given contact address is not a valid peer address');
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!Validator::validateUuid($peerUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given internal peer UUID is not a valid UUID V4');
|
||||||
|
}
|
||||||
|
|
||||||
$uuid = UuidV4::v4()->toRfc4122();
|
$uuid = UuidV4::v4()->toRfc4122();
|
||||||
|
|
||||||
|
@ -122,6 +145,15 @@
|
||||||
{
|
{
|
||||||
$contactAddress = $contactAddress->getAddress();
|
$contactAddress = $contactAddress->getAddress();
|
||||||
}
|
}
|
||||||
|
elseif(!Validator::validatePeerAddress($contactAddress))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given contact address is not a valid peer address');
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!Validator::validateUuid($peerUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given internal peer UUID is not a valid UUID V4');
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -159,6 +191,15 @@
|
||||||
{
|
{
|
||||||
$contactAddress = $contactAddress->getAddress();
|
$contactAddress = $contactAddress->getAddress();
|
||||||
}
|
}
|
||||||
|
elseif(!Validator::validatePeerAddress($contactAddress))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given contact address is invalid');
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!Validator::validateUuid($peerUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given internal peer UUID is not a valid UUID V4');
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -188,6 +229,15 @@
|
||||||
{
|
{
|
||||||
$contactAddress = $contactAddress->getAddress();
|
$contactAddress = $contactAddress->getAddress();
|
||||||
}
|
}
|
||||||
|
elseif(!Validator::validatePeerAddress($contactAddress))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given contact address is not a valid peer address');
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!Validator::validateUuid($peerUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given internal peer UUID is not a valid UUID V4');
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -295,12 +345,21 @@
|
||||||
{
|
{
|
||||||
if ($page < 1)
|
if ($page < 1)
|
||||||
{
|
{
|
||||||
$page = 1;
|
throw new InvalidArgumentException('The page number cannot be less than 1');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($limit < 1)
|
if ($limit < 1)
|
||||||
{
|
{
|
||||||
$limit = 1;
|
throw new InvalidArgumentException('The limit cannot be less than 1');
|
||||||
|
}
|
||||||
|
elseif($limit > Configuration::getPoliciesConfiguration()->getGetContactsLimit())
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The limit cannot exceed a value of ' . Configuration::getPoliciesConfiguration()->getGetContactsLimit());
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!Validator::validateUuid($peerUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given peer UUID is not a valid UUID V4');
|
||||||
}
|
}
|
||||||
|
|
||||||
$contacts = [];
|
$contacts = [];
|
||||||
|
@ -344,6 +403,10 @@
|
||||||
{
|
{
|
||||||
$contactUuid = $contactUuid->getUuid();
|
$contactUuid = $contactUuid->getUuid();
|
||||||
}
|
}
|
||||||
|
elseif(!Validator::validateUuid($contactUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given contact UUID is not a valid UUID V4');
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -360,7 +423,7 @@
|
||||||
$statement->bindParam(':expires', $expires);
|
$statement->bindParam(':expires', $expires);
|
||||||
$created = $signingKey->getCreated();
|
$created = $signingKey->getCreated();
|
||||||
$statement->bindParam(':created', $created);
|
$statement->bindParam(':created', $created);
|
||||||
$trustedOn = (new \DateTime())->format('Y-m-d H:i:s');
|
$trustedOn = (new DateTime())->format('Y-m-d H:i:s');
|
||||||
$statement->bindParam(':trusted_on', $trustedOn);
|
$statement->bindParam(':trusted_on', $trustedOn);
|
||||||
}
|
}
|
||||||
catch(PDOException $e)
|
catch(PDOException $e)
|
||||||
|
@ -369,6 +432,14 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a signing key from a contact in the database.
|
||||||
|
*
|
||||||
|
* @param string|ContactDatabaseRecord $contactUuid The unique identifier of the contact to remove the signing key from.
|
||||||
|
* @param string $signatureUuid The UUID of the signing key to remove.
|
||||||
|
* @return void
|
||||||
|
* @throws DatabaseOperationException If the database query fails.
|
||||||
|
*/
|
||||||
public static function removeContactSigningKey(string|ContactDatabaseRecord $contactUuid, string $signatureUuid): void
|
public static function removeContactSigningKey(string|ContactDatabaseRecord $contactUuid, string $signatureUuid): void
|
||||||
{
|
{
|
||||||
if($contactUuid instanceof ContactDatabaseRecord)
|
if($contactUuid instanceof ContactDatabaseRecord)
|
||||||
|
@ -389,6 +460,32 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes all signing keys for a contact from the database.
|
||||||
|
*
|
||||||
|
* @param string|ContactDatabaseRecord $contactUuid The unique identifier of the contact to remove all signing keys from.
|
||||||
|
* @return void
|
||||||
|
* @throws DatabaseOperationException If the database query fails.
|
||||||
|
*/
|
||||||
|
public static function removeAllContactSigningKeys(string|ContactDatabaseRecord $contactUuid): void
|
||||||
|
{
|
||||||
|
if($contactUuid instanceof ContactDatabaseRecord)
|
||||||
|
{
|
||||||
|
$contactUuid = $contactUuid->getUuid();
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$statement = Database::getConnection()->prepare('DELETE FROM contacts_known_keys WHERE contact_uuid=:contact_uuid');
|
||||||
|
$statement->bindParam(':contact_uuid', $contactUuid);
|
||||||
|
$statement->execute();
|
||||||
|
}
|
||||||
|
catch(PDOException $e)
|
||||||
|
{
|
||||||
|
throw new DatabaseOperationException('Failed to remove all signing keys from a contact in the database', $e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines if a signing key UUID exists for a contact in the database.
|
* Determines if a signing key UUID exists for a contact in the database.
|
||||||
*
|
*
|
||||||
|
@ -403,6 +500,15 @@
|
||||||
{
|
{
|
||||||
$contactUuid = $contactUuid->getUuid();
|
$contactUuid = $contactUuid->getUuid();
|
||||||
}
|
}
|
||||||
|
elseif(!Validator::validateUuid($contactUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given contact UUID is not a valid UUID V4');
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!Validator::validateUuid($signatureUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given signature UUID is not a valid UUID V4');
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -432,6 +538,10 @@
|
||||||
{
|
{
|
||||||
$contactUuid = $contactUuid->getUuid();
|
$contactUuid = $contactUuid->getUuid();
|
||||||
}
|
}
|
||||||
|
elseif(!Validator::validateUuid($contactUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given contact UUID is not a valid UUID V4');
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -532,6 +642,10 @@
|
||||||
{
|
{
|
||||||
$contactUuid = $contactUuid->getUuid();
|
$contactUuid = $contactUuid->getUuid();
|
||||||
}
|
}
|
||||||
|
elseif(!Validator::validateUuid($contactUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given contact UUID is not a valid UUID V4');
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
|
@ -30,6 +30,11 @@
|
||||||
*/
|
*/
|
||||||
public static function channelUuidExists(string $channelUuid): bool
|
public static function channelUuidExists(string $channelUuid): bool
|
||||||
{
|
{
|
||||||
|
if(!Validator::validateUuid($channelUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('Invalid channel UUID V4');
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$stmt = Database::getConnection()->prepare('SELECT COUNT(*) FROM encryption_channels WHERE uuid=:uuid');
|
$stmt = Database::getConnection()->prepare('SELECT COUNT(*) FROM encryption_channels WHERE uuid=:uuid');
|
||||||
|
@ -76,18 +81,18 @@
|
||||||
* @param string|PeerAddress $callingPeer The peer address of the caller.
|
* @param string|PeerAddress $callingPeer The peer address of the caller.
|
||||||
* @param string|PeerAddress $receivingPeer The peer address of the receiver.
|
* @param string|PeerAddress $receivingPeer The peer address of the receiver.
|
||||||
* @param string $callingPublicEncryptionKey The public encryption key of the caller.
|
* @param string $callingPublicEncryptionKey The public encryption key of the caller.
|
||||||
* @param string|null $channelUUid The UUID of the channel. If not provided, a new UUID will be generated.
|
* @param string|null $channelUuid The UUID of the channel. If not provided, a new UUID will be generated.
|
||||||
* @return string The UUID of the created channel.
|
* @return string The UUID of the created channel.
|
||||||
* @throws DatabaseOperationException If the database operation fails.
|
* @throws DatabaseOperationException If the database operation fails.
|
||||||
*/
|
*/
|
||||||
public static function createChannel(string|PeerAddress $callingPeer, string|PeerAddress $receivingPeer,
|
public static function createChannel(string|PeerAddress $callingPeer, string|PeerAddress $receivingPeer,
|
||||||
string $callingPublicEncryptionKey, ?string $channelUUid=null): string
|
string $callingPublicEncryptionKey, ?string $channelUuid=null): string
|
||||||
{
|
{
|
||||||
if($channelUUid === null)
|
if($channelUuid === null)
|
||||||
{
|
{
|
||||||
$channelUUid = Uuid::v4()->toRfc4122();
|
$channelUuid = Uuid::v4()->toRfc4122();
|
||||||
}
|
}
|
||||||
elseif(!Validator::validateUuid($channelUUid))
|
elseif(!Validator::validateUuid($channelUuid))
|
||||||
{
|
{
|
||||||
throw new InvalidArgumentException('Invalid UUID V4');
|
throw new InvalidArgumentException('Invalid UUID V4');
|
||||||
}
|
}
|
||||||
|
@ -117,15 +122,15 @@
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$channelUUid = $channelUUid ?? Uuid::v4()->toRfc4122();
|
$channelUuid = $channelUuid ?? Uuid::v4()->toRfc4122();
|
||||||
$stmt = Database::getConnection()->prepare('INSERT INTO encryption_channels (uuid, calling_peer_address, receiving_peer_address, calling_peer_address, calling_public_encryption_key) VALUES (:uuid, :calling_peer_address, :receiving_peer_address, :calling_peer_address, :calling_public_encryption_key)');
|
$stmt = Database::getConnection()->prepare('INSERT INTO encryption_channels (uuid, calling_peer_address, receiving_peer_address, calling_peer_address, calling_public_encryption_key) VALUES (:uuid, :calling_peer_address, :receiving_peer_address, :calling_peer_address, :calling_public_encryption_key)');
|
||||||
$stmt->bindParam(':uuid', $channelUUid);
|
$stmt->bindParam(':uuid', $channelUuid);
|
||||||
$stmt->bindParam(':calling_peer_address', $callingPeer);
|
$stmt->bindParam(':calling_peer_address', $callingPeer);
|
||||||
$stmt->bindParam(':receiving_peer_address', $receivingPeer);
|
$stmt->bindParam(':receiving_peer_address', $receivingPeer);
|
||||||
$stmt->bindParam(':calling_public_encryption_key', $callingPublicEncryptionKey);
|
$stmt->bindParam(':calling_public_encryption_key', $callingPublicEncryptionKey);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
|
|
||||||
return $channelUUid;
|
return $channelUuid;
|
||||||
}
|
}
|
||||||
catch (PDOException $e)
|
catch (PDOException $e)
|
||||||
{
|
{
|
||||||
|
@ -330,14 +335,15 @@
|
||||||
*/
|
*/
|
||||||
public static function getIncomingChannels(string|PeerAddress $peerAddress, int $page=1, int $limit=100): array
|
public static function getIncomingChannels(string|PeerAddress $peerAddress, int $page=1, int $limit=100): array
|
||||||
{
|
{
|
||||||
|
if(is_string($peerAddress) && !Validator::validatePeerAddress($peerAddress))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('Invalid Peer Address');
|
||||||
|
}
|
||||||
|
|
||||||
if($peerAddress instanceof PeerAddress)
|
if($peerAddress instanceof PeerAddress)
|
||||||
{
|
{
|
||||||
$peerAddress = $peerAddress->getAddress();
|
$peerAddress = $peerAddress->getAddress();
|
||||||
}
|
}
|
||||||
elseif(!Validator::validatePeerAddress($peerAddress))
|
|
||||||
{
|
|
||||||
throw new InvalidArgumentException('Invalid Peer Address');
|
|
||||||
}
|
|
||||||
|
|
||||||
if($page < 1)
|
if($page < 1)
|
||||||
{
|
{
|
||||||
|
@ -414,7 +420,7 @@
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$offset = ($page -1) * $limit;
|
$offset = ($page -1) * $limit;
|
||||||
$stmt = Database::getConnection()->prepare('SELECT * FROM encryption_channels WHERE calling_peer_address=:peer_address LIMIT :limit OFFSET :offset');
|
$stmt = Database::getConnection()->prepare('SELECT * FROM encryption_channels WHERE calling_peer_address=:peer_address ORDER BY created LIMIT :limit OFFSET :offset');
|
||||||
$stmt->bindParam(':peer_address', $peerAddress);
|
$stmt->bindParam(':peer_address', $peerAddress);
|
||||||
$stmt->bindParam(':limit', $limit);
|
$stmt->bindParam(':limit', $limit);
|
||||||
$stmt->bindParam(':offset', $offset);
|
$stmt->bindParam(':offset', $offset);
|
||||||
|
@ -446,15 +452,15 @@
|
||||||
*/
|
*/
|
||||||
public static function getChannelRequests(string|PeerAddress $peerAddress, int $page=1, int $limit=100): array
|
public static function getChannelRequests(string|PeerAddress $peerAddress, int $page=1, int $limit=100): array
|
||||||
{
|
{
|
||||||
if($peerAddress instanceof PeerAddress)
|
if(is_string($peerAddress) && !Validator::validatePeerAddress($peerAddress))
|
||||||
{
|
|
||||||
$peerAddress = $peerAddress->getAddress();
|
|
||||||
}
|
|
||||||
elseif(!Validator::validatePeerAddress($peerAddress))
|
|
||||||
{
|
{
|
||||||
throw new InvalidArgumentException('Invalid Peer Address');
|
throw new InvalidArgumentException('Invalid Peer Address');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($peerAddress instanceof PeerAddress)
|
||||||
|
{
|
||||||
|
$peerAddress = $peerAddress->getAddress();
|
||||||
|
}
|
||||||
|
|
||||||
if($page < 1)
|
if($page < 1)
|
||||||
{
|
{
|
||||||
|
@ -521,10 +527,38 @@
|
||||||
throw new InvalidArgumentException('Invalid UUID V4 of the message');
|
throw new InvalidArgumentException('Invalid UUID V4 of the message');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!Validator::validateUuid($channelUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('Invalid UUID V4 of the channel');
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!Cryptography::validateSha512($checksum))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('Invalid checksum, must be SHA512');
|
||||||
|
}
|
||||||
|
|
||||||
|
if(empty($data))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('Data cannot be empty');
|
||||||
|
}
|
||||||
|
|
||||||
if($messageTimestamp === null)
|
if($messageTimestamp === null)
|
||||||
{
|
{
|
||||||
$messageTimestamp = time();
|
$messageTimestamp = time();
|
||||||
}
|
}
|
||||||
|
elseif(!Validator::isTimestampInRange($messageTimestamp, 3600))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('Invalid timestamp, must be within 1 hour');
|
||||||
|
}
|
||||||
|
|
||||||
|
$currentMessageCount = self::getMessageCount($channelUuid);
|
||||||
|
if($currentMessageCount > Configuration::getPoliciesConfiguration()->getEncryptionChannelMaxMessages())
|
||||||
|
{
|
||||||
|
// Delete the oldest messages to make room for the new one
|
||||||
|
self::deleteMessages($channelUuid, self::getOldestMessage($channelUuid, (
|
||||||
|
$currentMessageCount - Configuration::getPoliciesConfiguration()->getEncryptionChannelMaxMessages()
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -590,23 +624,42 @@
|
||||||
* @return EncryptionChannelMessageRecord[] An array of message objects returned
|
* @return EncryptionChannelMessageRecord[] An array of message objects returned
|
||||||
* @throws DatabaseOperationException Thrown if there was a database operation error
|
* @throws DatabaseOperationException Thrown if there was a database operation error
|
||||||
*/
|
*/
|
||||||
public static function receiveData(string $channelUuid, EncryptionMessageRecipient|string $recipient): array
|
public static function receiveData(string $channelUuid, EncryptionMessageRecipient|string $recipient, int $limit=100): array
|
||||||
{
|
{
|
||||||
if(!Validator::validateUuid($channelUuid))
|
if(!Validator::validateUuid($channelUuid))
|
||||||
{
|
{
|
||||||
throw new InvalidArgumentException('The given Channel UUID is not a valid V4 UUID');
|
throw new InvalidArgumentException('The given Channel UUID is not a valid V4 UUID');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
elseif(is_string($recipient))
|
||||||
|
{
|
||||||
|
$recipient = EncryptionMessageRecipient::tryFrom($recipient);
|
||||||
|
if($recipient === null)
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given recipient is not a valid EncryptionMessageRecipient');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if($recipient instanceof EncryptionMessageRecipient)
|
if($recipient instanceof EncryptionMessageRecipient)
|
||||||
{
|
{
|
||||||
$recipient = $recipient->value;
|
$recipient = $recipient->value;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given recipient is not a valid EncryptionMessageRecipient');
|
||||||
|
}
|
||||||
|
|
||||||
|
if($limit < 1)
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The limit cannot be less than 1');
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$stmt = Database::getConnection()->prepare("SELECT * FROM encryption_channels_com WHERE channel_uuid=:channel_uuid AND recipient=:recipient AND status='SENT' ORDER BY timestamp LIMIT 100");
|
$stmt = Database::getConnection()->prepare("SELECT * FROM encryption_channels_com WHERE channel_uuid=:channel_uuid AND recipient=:recipient AND status='SENT' ORDER BY timestamp LIMIT :limit");
|
||||||
$stmt->bindParam(':channel_uuid', $channelUuid);
|
$stmt->bindParam(':channel_uuid', $channelUuid);
|
||||||
$stmt->bindParam(':recipient', $recipient);
|
$stmt->bindParam(':recipient', $recipient);
|
||||||
|
$stmt->bindParam(':limit', $limit);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$results = $stmt->fetchAll();
|
$results = $stmt->fetchAll();
|
||||||
|
|
||||||
|
@ -676,6 +729,14 @@
|
||||||
throw new InvalidArgumentException('The given Message UUIDs array is empty');
|
throw new InvalidArgumentException('The given Message UUIDs array is empty');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach($messageUuids as $messageUuid)
|
||||||
|
{
|
||||||
|
if(!Validator::validateUuid($messageUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given Message UUID is not a valid V4 uuid');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$placeholders = implode(',', array_fill(0, count($messageUuids), '?'));
|
$placeholders = implode(',', array_fill(0, count($messageUuids), '?'));
|
||||||
$query = "UPDATE encryption_channels_com SET status='RECEIVED' WHERE channel_uuid=:channel_uuid AND uuid IN ($placeholders)";
|
$query = "UPDATE encryption_channels_com SET status='RECEIVED' WHERE channel_uuid=:channel_uuid AND uuid IN ($placeholders)";
|
||||||
|
|
||||||
|
@ -732,4 +793,156 @@
|
||||||
throw new DatabaseOperationException('There was an error while rejecting the message record', $e);
|
throw new DatabaseOperationException('There was an error while rejecting the message record', $e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the total message count in a given channel
|
||||||
|
*
|
||||||
|
* @param string $channelUuid The channel UUID to check
|
||||||
|
* @return int The number of messages there is
|
||||||
|
* @throws DatabaseOperationException Thrown if there was a database operation error
|
||||||
|
*/
|
||||||
|
public static function getMessageCount(string $channelUuid): int
|
||||||
|
{
|
||||||
|
if(!Validator::validateUuid($channelUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given Channel UUID is not a valid V4 UUID');
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$stmt = Database::getConnection()->prepare("SELECT COUNT(*) FROM encryption_channels_com WHERE channel_uuid=:channel_uuid");
|
||||||
|
$stmt->bindParam(':channel_uuid', $channelUuid);
|
||||||
|
$stmt->execute();
|
||||||
|
|
||||||
|
return (int)$stmt->fetchColumn();
|
||||||
|
}
|
||||||
|
catch(PDOException $e)
|
||||||
|
{
|
||||||
|
throw new DatabaseOperationException('There was an error while trying to retrieve the message count', $e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an array of oldest messages in the queue, sorted by timestamp
|
||||||
|
*
|
||||||
|
* @param string $channelUuid The channel UUID to check
|
||||||
|
* @param int $amount The number of messages to retrieve
|
||||||
|
* @return string[] An array of message records
|
||||||
|
* @throws DatabaseOperationException Thrown if there was a database operation error
|
||||||
|
*/
|
||||||
|
public static function getOldestMessage(string $channelUuid, int $amount=1): array
|
||||||
|
{
|
||||||
|
if(!Validator::validateUuid($channelUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given Channel UUID is not a valid V4 UUID');
|
||||||
|
}
|
||||||
|
|
||||||
|
if($amount < 1)
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The amount of messages to retrieve cannot be less than 1');
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$stmt = Database::getConnection()->prepare("SELECT uuid FROM encryption_channels_com WHERE channel_uuid=:channel_uuid AND status='SENT' ORDER BY timestamp LIMIT :amount");
|
||||||
|
$stmt->bindParam(':channel_uuid', $channelUuid);
|
||||||
|
$stmt->bindParam(':amount', $amount, PDO::PARAM_INT);
|
||||||
|
$stmt->execute();
|
||||||
|
|
||||||
|
$results = $stmt->fetchAll();
|
||||||
|
if(!$results)
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return array_map(fn($result) => $result['uuid'], $results);
|
||||||
|
}
|
||||||
|
catch(PDOException $e)
|
||||||
|
{
|
||||||
|
throw new DatabaseOperationException('There was an error while trying to retrieve the oldest message', $e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a message record from the database
|
||||||
|
*
|
||||||
|
* @param string $channelUuid The Unique Universal Identifier of the channel
|
||||||
|
* @param string $messageUuid The Unique Universal Identifier of the message
|
||||||
|
* @return void
|
||||||
|
* @throws DatabaseOperationException Thrown if there was an error with the database operation
|
||||||
|
*/
|
||||||
|
public static function deleteMessage(string $channelUuid, string $messageUuid): void
|
||||||
|
{
|
||||||
|
if(!Validator::validateUuid($channelUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given Channel UUID is not a valid V4 UUID');
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!Validator::validateUuid($messageUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given Message UUID is not a valid V4 UUID');
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$stmt = Database::getConnection()->prepare("DELETE FROM encryption_channels_com WHERE channel_uuid=:channel_uuid AND uuid=:message_uuid LIMIT 1");
|
||||||
|
$stmt->bindParam(':channel_uuid', $channelUuid);
|
||||||
|
$stmt->bindParam(':message_uuid', $messageUuid);
|
||||||
|
$stmt->execute();
|
||||||
|
}
|
||||||
|
catch(PDOException $e)
|
||||||
|
{
|
||||||
|
throw new DatabaseOperationException('There was an error while trying to delete the message record', $e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a batch of messages from the database
|
||||||
|
*
|
||||||
|
* @param string $channelUuid The Unique Universal Identifier of the channel
|
||||||
|
* @param array $messageUuids An array of message UUIDs to delete
|
||||||
|
* @return void
|
||||||
|
* @throws DatabaseOperationException Thrown if there was an error with the database operation
|
||||||
|
*/
|
||||||
|
public static function deleteMessages(string $channelUuid, array $messageUuids): void
|
||||||
|
{
|
||||||
|
if(count($messageUuids) === 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
elseif(count($messageUuids) === 1)
|
||||||
|
{
|
||||||
|
self::deleteMessage($channelUuid, $messageUuids[0]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!Validator::validateUuid($channelUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given Channel UUID is not a valid V4 UUID');
|
||||||
|
}
|
||||||
|
|
||||||
|
if(empty($messageUuids))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given Message UUIDs array is empty');
|
||||||
|
}
|
||||||
|
|
||||||
|
$placeholders = implode(',', array_fill(0, count($messageUuids), '?'));
|
||||||
|
$query = "DELETE FROM encryption_channels_com WHERE channel_uuid=:channel_uuid AND uuid IN ($placeholders)";
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$stmt = Database::getConnection()->prepare($query);
|
||||||
|
$stmt->bindParam(':channel_uuid', $channelUuid);
|
||||||
|
foreach($messageUuids as $index => $messageUuid)
|
||||||
|
{
|
||||||
|
$stmt->bindValue($index + 1, $messageUuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
$stmt->execute();
|
||||||
|
}
|
||||||
|
catch(PDOException $e)
|
||||||
|
{
|
||||||
|
throw new DatabaseOperationException('There was an error while deleting the message records', $e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -2,12 +2,14 @@
|
||||||
|
|
||||||
namespace Socialbox\Managers;
|
namespace Socialbox\Managers;
|
||||||
|
|
||||||
use DateTime;
|
use InvalidArgumentException;
|
||||||
use PDOException;
|
use PDOException;
|
||||||
|
use Random\RandomException;
|
||||||
use Socialbox\Classes\Configuration;
|
use Socialbox\Classes\Configuration;
|
||||||
use Socialbox\Classes\Cryptography;
|
use Socialbox\Classes\Cryptography;
|
||||||
use Socialbox\Classes\Database;
|
use Socialbox\Classes\Database;
|
||||||
use Socialbox\Classes\OtpCryptography;
|
use Socialbox\Classes\OtpCryptography;
|
||||||
|
use Socialbox\Classes\Validator;
|
||||||
use Socialbox\Exceptions\CryptographyException;
|
use Socialbox\Exceptions\CryptographyException;
|
||||||
use Socialbox\Exceptions\DatabaseOperationException;
|
use Socialbox\Exceptions\DatabaseOperationException;
|
||||||
use Socialbox\Objects\Database\PeerDatabaseRecord;
|
use Socialbox\Objects\Database\PeerDatabaseRecord;
|
||||||
|
@ -27,6 +29,10 @@
|
||||||
{
|
{
|
||||||
$peerUuid = $peerUuid->getUuid();
|
$peerUuid = $peerUuid->getUuid();
|
||||||
}
|
}
|
||||||
|
elseif(!Validator::validateUuid($peerUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given internal peer UUID is not a valid UUID V4');
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -45,18 +51,15 @@
|
||||||
/**
|
/**
|
||||||
* Creates and stores a new OTP (One-Time Password) secret for the specified peer, and generates a key URI.
|
* Creates and stores a new OTP (One-Time Password) secret for the specified peer, and generates a key URI.
|
||||||
*
|
*
|
||||||
* @param string|PeerDatabaseRecord $peer The unique identifier of the peer, either as a string UUID
|
* @param PeerDatabaseRecord $peerDatabaseRecord The unique identifier of the peer, either as a string UUID
|
||||||
* or an instance of RegisteredPeerRecord.
|
* or an instance of RegisteredPeerRecord.
|
||||||
* @return string The generated OTP key URI that can be used for applications like authenticator apps.
|
* @return string The generated OTP key URI that can be used for applications like authenticator apps.
|
||||||
|
* @throws CryptographyException If there is an error during the encryption of the OTP secret.
|
||||||
* @throws DatabaseOperationException If there is an error during the database operation.
|
* @throws DatabaseOperationException If there is an error during the database operation.
|
||||||
|
* @throws RandomException If there is an error during the generation of the OTP secret.
|
||||||
*/
|
*/
|
||||||
public static function createOtp(string|PeerDatabaseRecord $peer): string
|
public static function createOtp(PeerDatabaseRecord $peerDatabaseRecord): string
|
||||||
{
|
{
|
||||||
if(is_string($peer))
|
|
||||||
{
|
|
||||||
$peer = RegisteredPeerManager::getPeer($peer);
|
|
||||||
}
|
|
||||||
|
|
||||||
$secret = OtpCryptography::generateSecretKey(Configuration::getSecurityConfiguration()->getOtpSecretKeyLength());
|
$secret = OtpCryptography::generateSecretKey(Configuration::getSecurityConfiguration()->getOtpSecretKeyLength());
|
||||||
$encryptionKey = Configuration::getCryptographyConfiguration()->getRandomInternalEncryptionKey();
|
$encryptionKey = Configuration::getCryptographyConfiguration()->getRandomInternalEncryptionKey();
|
||||||
$encryptedSecret = Cryptography::encryptMessage($secret, $encryptionKey, Configuration::getCryptographyConfiguration()->getEncryptionKeysAlgorithm());
|
$encryptedSecret = Cryptography::encryptMessage($secret, $encryptionKey, Configuration::getCryptographyConfiguration()->getEncryptionKeysAlgorithm());
|
||||||
|
@ -64,7 +67,8 @@
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$stmt = Database::getConnection()->prepare("INSERT INTO authentication_otp (peer_uuid, secret) VALUES (:peer_uuid, :secret)");
|
$stmt = Database::getConnection()->prepare("INSERT INTO authentication_otp (peer_uuid, secret) VALUES (:peer_uuid, :secret)");
|
||||||
$stmt->bindParam(':peer_uuid', $peer);
|
$peerUuid = $peerDatabaseRecord->getUuid();
|
||||||
|
$stmt->bindParam(':peer_uuid', $peerUuid);
|
||||||
$stmt->bindParam(':secret', $encryptedSecret);
|
$stmt->bindParam(':secret', $encryptedSecret);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
}
|
}
|
||||||
|
@ -73,7 +77,7 @@
|
||||||
throw new DatabaseOperationException('An error occurred while creating the OTP secret in the database', $e);
|
throw new DatabaseOperationException('An error occurred while creating the OTP secret in the database', $e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return OtpCryptography::generateKeyUri($peer->getAddress(), $secret,
|
return OtpCryptography::generateKeyUri($peerDatabaseRecord->getAddress(), $secret,
|
||||||
Configuration::getInstanceConfiguration()->getDomain(),
|
Configuration::getInstanceConfiguration()->getDomain(),
|
||||||
Configuration::getSecurityConfiguration()->getOtpTimeStep(),
|
Configuration::getSecurityConfiguration()->getOtpTimeStep(),
|
||||||
Configuration::getSecurityConfiguration()->getOtpDigits(),
|
Configuration::getSecurityConfiguration()->getOtpDigits(),
|
||||||
|
@ -173,6 +177,7 @@
|
||||||
*
|
*
|
||||||
* @param string|PeerDatabaseRecord $peerUuid The peer's UUID or an instance of RegisteredPeerRecord whose OTP record's last updated timestamp needs to be retrieved
|
* @param string|PeerDatabaseRecord $peerUuid The peer's UUID or an instance of RegisteredPeerRecord whose OTP record's last updated timestamp needs to be retrieved
|
||||||
* @return int The last updated timestamp of the OTP record, or 0 if no such record exists
|
* @return int The last updated timestamp of the OTP record, or 0 if no such record exists
|
||||||
|
* @throws DatabaseOperationException if the database operation fails.
|
||||||
*/
|
*/
|
||||||
public static function getLastUpdated(string|PeerDatabaseRecord $peerUuid): int
|
public static function getLastUpdated(string|PeerDatabaseRecord $peerUuid): int
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,11 +3,13 @@
|
||||||
namespace Socialbox\Managers;
|
namespace Socialbox\Managers;
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
|
use InvalidArgumentException;
|
||||||
use PDO;
|
use PDO;
|
||||||
use PDOException;
|
use PDOException;
|
||||||
use Socialbox\Classes\Configuration;
|
use Socialbox\Classes\Configuration;
|
||||||
use Socialbox\Classes\Cryptography;
|
use Socialbox\Classes\Cryptography;
|
||||||
use Socialbox\Classes\Database;
|
use Socialbox\Classes\Database;
|
||||||
|
use Socialbox\Classes\Validator;
|
||||||
use Socialbox\Exceptions\CryptographyException;
|
use Socialbox\Exceptions\CryptographyException;
|
||||||
use Socialbox\Exceptions\DatabaseOperationException;
|
use Socialbox\Exceptions\DatabaseOperationException;
|
||||||
use Socialbox\Objects\Database\PeerDatabaseRecord;
|
use Socialbox\Objects\Database\PeerDatabaseRecord;
|
||||||
|
@ -27,6 +29,10 @@
|
||||||
{
|
{
|
||||||
$peerUuid = $peerUuid->getUuid();
|
$peerUuid = $peerUuid->getUuid();
|
||||||
}
|
}
|
||||||
|
elseif(!Validator::validateUuid($peerUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given internal peer UUID is not a valid UUID V4');
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -57,11 +63,15 @@
|
||||||
{
|
{
|
||||||
$peerUuid = $peerUuid->getUuid();
|
$peerUuid = $peerUuid->getUuid();
|
||||||
}
|
}
|
||||||
|
elseif(!Validator::validateUuid($peerUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given internal peer UUID is not a valid UUID V4');
|
||||||
|
}
|
||||||
|
|
||||||
// Throws an exception if the hash is invalid
|
// Throws an exception if the hash is invalid
|
||||||
if(!Cryptography::validatePasswordHash($hash))
|
if(!Cryptography::validatePasswordHash($hash))
|
||||||
{
|
{
|
||||||
throw new CryptographyException('Invalid password hash');
|
throw new CryptographyException('Invalid password aragon2id hash');
|
||||||
}
|
}
|
||||||
|
|
||||||
$encryptionKey = Configuration::getCryptographyConfiguration()->getRandomInternalEncryptionKey();
|
$encryptionKey = Configuration::getCryptographyConfiguration()->getRandomInternalEncryptionKey();
|
||||||
|
@ -96,10 +106,14 @@
|
||||||
{
|
{
|
||||||
$peerUuid = $peerUuid->getUuid();
|
$peerUuid = $peerUuid->getUuid();
|
||||||
}
|
}
|
||||||
|
elseif(!Validator::validateUuid($peerUuid))
|
||||||
|
{
|
||||||
|
throw new CryptographyException('The given internal peer UUID is not a valid UUID V4');
|
||||||
|
}
|
||||||
|
|
||||||
if(!Cryptography::validatePasswordHash($hash))
|
if(!Cryptography::validatePasswordHash($hash))
|
||||||
{
|
{
|
||||||
throw new CryptographyException('Invalid password hash');
|
throw new CryptographyException('Invalid password argon2id hash');
|
||||||
}
|
}
|
||||||
|
|
||||||
$encryptionKey = Configuration::getCryptographyConfiguration()->getRandomInternalEncryptionKey();
|
$encryptionKey = Configuration::getCryptographyConfiguration()->getRandomInternalEncryptionKey();
|
||||||
|
@ -134,6 +148,10 @@
|
||||||
{
|
{
|
||||||
$peerUuid = $peerUuid->getUuid();
|
$peerUuid = $peerUuid->getUuid();
|
||||||
}
|
}
|
||||||
|
elseif(!Validator::validateUuid($peerUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given internal peer UUID is not a valid UUID V4');
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -162,6 +180,15 @@
|
||||||
{
|
{
|
||||||
$peerUuid = $peerUuid->getUuid();
|
$peerUuid = $peerUuid->getUuid();
|
||||||
}
|
}
|
||||||
|
elseif(!Validator::validateUuid($peerUuid))
|
||||||
|
{
|
||||||
|
throw new CryptographyException('The given internal peer UUID is not a valid UUID V4');
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!Cryptography::validateSha512($sha512))
|
||||||
|
{
|
||||||
|
throw new CryptographyException('Invalid SHA-512 hash');
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
|
@ -2,9 +2,11 @@
|
||||||
|
|
||||||
namespace Socialbox\Managers;
|
namespace Socialbox\Managers;
|
||||||
|
|
||||||
|
use InvalidArgumentException;
|
||||||
use PDOException;
|
use PDOException;
|
||||||
use Socialbox\Classes\Configuration;
|
use Socialbox\Classes\Configuration;
|
||||||
use Socialbox\Classes\Database;
|
use Socialbox\Classes\Database;
|
||||||
|
use Socialbox\Classes\Validator;
|
||||||
use Socialbox\Enums\PrivacyState;
|
use Socialbox\Enums\PrivacyState;
|
||||||
use Socialbox\Enums\Types\InformationFieldName;
|
use Socialbox\Enums\Types\InformationFieldName;
|
||||||
use Socialbox\Exceptions\DatabaseOperationException;
|
use Socialbox\Exceptions\DatabaseOperationException;
|
||||||
|
@ -29,6 +31,15 @@
|
||||||
{
|
{
|
||||||
$peerUuid = $peerUuid->getUuid();
|
$peerUuid = $peerUuid->getUuid();
|
||||||
}
|
}
|
||||||
|
elseif(!Validator::validateUuid($peerUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given internal peer UUID is not a valid UUID V4');
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!$property->validate($value))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException(sprintf('The given value %s is not valid for property %s', $value, $property->value));
|
||||||
|
}
|
||||||
|
|
||||||
if($privacyState === null)
|
if($privacyState === null)
|
||||||
{
|
{
|
||||||
|
@ -77,10 +88,19 @@
|
||||||
{
|
{
|
||||||
$peerUuid = $peerUuid->getUuid();
|
$peerUuid = $peerUuid->getUuid();
|
||||||
}
|
}
|
||||||
|
elseif(!Validator::validateUuid($peerUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given internal peer UUID is not a valid UUID V4');
|
||||||
|
}
|
||||||
|
|
||||||
if(!self::fieldExists($peerUuid, $property))
|
if(!self::fieldExists($peerUuid, $property))
|
||||||
{
|
{
|
||||||
throw new DatabaseOperationException(sprintf('Cannot to update property %s for peer %s, property does not exist', $property->value, $peerUuid));
|
self::addField($peerUuid, $property, $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!$property->validate($value))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException(sprintf('The given value %s is not valid for property %s', $value, $property->value));
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -113,10 +133,14 @@
|
||||||
{
|
{
|
||||||
$peerUuid = $peerUuid->getUuid();
|
$peerUuid = $peerUuid->getUuid();
|
||||||
}
|
}
|
||||||
|
elseif(!Validator::validateUuid($peerUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given internal peer UUID is not a valid UUID V4');
|
||||||
|
}
|
||||||
|
|
||||||
if(!self::fieldExists($peerUuid, $property))
|
if(!self::fieldExists($peerUuid, $property))
|
||||||
{
|
{
|
||||||
throw new \InvalidArgumentException(sprintf('Cannot update privacy state, the requested property %s does not exist with %s', $property->value, $peerUuid));
|
throw new InvalidArgumentException(sprintf('Cannot update privacy state, the requested property %s does not exist with %s', $property->value, $peerUuid));
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -149,6 +173,10 @@
|
||||||
{
|
{
|
||||||
$peerUuid = $peerUuid->getUuid();
|
$peerUuid = $peerUuid->getUuid();
|
||||||
}
|
}
|
||||||
|
elseif(!Validator::validateUuid($peerUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given internal peer UUID is not a valid UUID V4');
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -180,6 +208,10 @@
|
||||||
{
|
{
|
||||||
$peerUuid = $peerUuid->getUuid();
|
$peerUuid = $peerUuid->getUuid();
|
||||||
}
|
}
|
||||||
|
elseif(!Validator::validateUuid($peerUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given internal peer UUID is not a valid UUID V4');
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -216,6 +248,10 @@
|
||||||
{
|
{
|
||||||
$peerUuid = $peerUuid->getUuid();
|
$peerUuid = $peerUuid->getUuid();
|
||||||
}
|
}
|
||||||
|
elseif(!Validator::validateUuid($peerUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given internal peer UUID is not a valid UUID V4');
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -253,7 +289,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
$results = [];
|
$results = [];
|
||||||
/** @var PrivacyState $privacyState */
|
|
||||||
foreach($privacyFilters as $privacyState)
|
foreach($privacyFilters as $privacyState)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -292,6 +327,10 @@
|
||||||
{
|
{
|
||||||
$peerUuid = $peerUuid->getUuid();
|
$peerUuid = $peerUuid->getUuid();
|
||||||
}
|
}
|
||||||
|
elseif(!Validator::validateUuid($peerUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given internal peer UUID is not a valid UUID V4');
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
|
@ -8,9 +8,11 @@
|
||||||
use PDOException;
|
use PDOException;
|
||||||
use Socialbox\Classes\Cryptography;
|
use Socialbox\Classes\Cryptography;
|
||||||
use Socialbox\Classes\Database;
|
use Socialbox\Classes\Database;
|
||||||
|
use Socialbox\Classes\Validator;
|
||||||
use Socialbox\Enums\SigningKeyState;
|
use Socialbox\Enums\SigningKeyState;
|
||||||
use Socialbox\Exceptions\CryptographyException;
|
use Socialbox\Exceptions\CryptographyException;
|
||||||
use Socialbox\Exceptions\DatabaseOperationException;
|
use Socialbox\Exceptions\DatabaseOperationException;
|
||||||
|
use Socialbox\Objects\Database\PeerDatabaseRecord;
|
||||||
use Socialbox\Objects\Database\SigningKeyRecord;
|
use Socialbox\Objects\Database\SigningKeyRecord;
|
||||||
|
|
||||||
class SigningKeysManager
|
class SigningKeysManager
|
||||||
|
@ -19,12 +21,21 @@
|
||||||
/**
|
/**
|
||||||
* Retrieves the count of signing keys associated with a specific peer UUID.
|
* Retrieves the count of signing keys associated with a specific peer UUID.
|
||||||
*
|
*
|
||||||
* @param string $peerUuid The UUID of the peer for which to count the signing keys.
|
* @param string|PeerDatabaseRecord $peerUuid The UUID of the peer for which to count the signing keys.
|
||||||
* @return int The number of signing keys associated with the given peer UUID.
|
* @return int The number of signing keys associated with the given peer UUID.
|
||||||
* @throws DatabaseOperationException If there is an error during the database operation.
|
* @throws DatabaseOperationException If there is an error during the database operation.
|
||||||
*/
|
*/
|
||||||
public static function getSigningKeyCount(string $peerUuid): int
|
public static function getSigningKeyCount(string|PeerDatabaseRecord $peerUuid): int
|
||||||
{
|
{
|
||||||
|
if($peerUuid instanceof PeerDatabaseRecord)
|
||||||
|
{
|
||||||
|
$peerUuid = $peerUuid->getUuid();
|
||||||
|
}
|
||||||
|
elseif(!Validator::validateUuid($peerUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given internal peer UUID is not a valid UUID V4');
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$statement = Database::getConnection()->prepare("SELECT COUNT(*) FROM signing_keys WHERE peer_uuid=:peer_uuid");
|
$statement = Database::getConnection()->prepare("SELECT COUNT(*) FROM signing_keys WHERE peer_uuid=:peer_uuid");
|
||||||
|
@ -42,21 +53,29 @@
|
||||||
/**
|
/**
|
||||||
* Adds a signing key to the database for a specific peer.
|
* Adds a signing key to the database for a specific peer.
|
||||||
*
|
*
|
||||||
* @param string $peerUuid The unique identifier of the peer associated with the signing key.
|
* @param string|PeerDatabaseRecord $peerUuid The unique identifier of the peer associated with the signing key.
|
||||||
* @param string $publicKey The public signing key to be added. Must be valid according to the Cryptography::validatePublicSigningKey method.
|
* @param string $publicKey The public signing key to be added. Must be valid according to the Cryptography::validatePublicSigningKey method.
|
||||||
* @param string $name Optional name associated with the signing key. Must not exceed 64 characters in length.
|
* @param string $name Optional name associated with the signing key. Must not exceed 64 characters in length.
|
||||||
* @param int|null $expires Optional expiration timestamp for the signing key. Can be null if the key does not expire.
|
* @param int|null $expires Optional expiration timestamp for the signing key. Can be null if the key does not expire.
|
||||||
* @return string The UUID of the newly added signing key.
|
* @return string The UUID of the newly added signing key.
|
||||||
* @throws DatabaseOperationException If the operation to add the signing key to the database fails.
|
* @throws DatabaseOperationException If the operation to add the signing key to the database fails.
|
||||||
*/
|
*/
|
||||||
public static function addSigningKey(string $peerUuid, string $publicKey, string $name, ?int $expires=null): string
|
public static function addSigningKey(string|PeerDatabaseRecord $peerUuid, string $publicKey, string $name, ?int $expires=null): string
|
||||||
{
|
{
|
||||||
|
if($peerUuid instanceof PeerDatabaseRecord)
|
||||||
|
{
|
||||||
|
$peerUuid = $peerUuid->getUuid();
|
||||||
|
}
|
||||||
|
elseif(!Validator::validateUuid($peerUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given internal peer UUID is not a valid UUID V4');
|
||||||
|
}
|
||||||
|
|
||||||
if(!Cryptography::validatePublicSigningKey($publicKey))
|
if(!Cryptography::validatePublicSigningKey($publicKey))
|
||||||
{
|
{
|
||||||
throw new InvalidArgumentException('The public key is invalid');
|
throw new InvalidArgumentException('The public key is invalid');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(empty($name))
|
if(empty($name))
|
||||||
{
|
{
|
||||||
throw new InvalidArgumentException('The name cannot be empty');
|
throw new InvalidArgumentException('The name cannot be empty');
|
||||||
|
@ -112,14 +131,28 @@
|
||||||
/**
|
/**
|
||||||
* Updates the state of a signing key in the database identified by its UUID.
|
* Updates the state of a signing key in the database identified by its UUID.
|
||||||
*
|
*
|
||||||
* @param string $peerUuid The UUID of the peer associated with the signing key.
|
* @param string|PeerDatabaseRecord $peerUuid The UUID of the peer associated with the signing key.
|
||||||
* @param string $uuid The unique identifier of the signing key to update.
|
* @param string $signatureUuid The unique identifier of the signing key to update.
|
||||||
* @param SigningKeyState $state The new state to set for the signing key.
|
* @param SigningKeyState $state The new state to set for the signing key.
|
||||||
* @return void
|
* @return void
|
||||||
* @throws DatabaseOperationException
|
* @throws DatabaseOperationException
|
||||||
*/
|
*/
|
||||||
public static function updateSigningKeyState(string $peerUuid, string $uuid, SigningKeyState $state): void
|
public static function updateSigningKeyState(string|PeerDatabaseRecord $peerUuid, string $signatureUuid, SigningKeyState $state): void
|
||||||
{
|
{
|
||||||
|
if($peerUuid instanceof PeerDatabaseRecord)
|
||||||
|
{
|
||||||
|
$peerUuid = $peerUuid->getUuid();
|
||||||
|
}
|
||||||
|
elseif(!Validator::validateUuid($peerUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given internal peer UUID is not a valid UUID V4');
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!Validator::validateUuid($signatureUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given signature UUID is not a valid UUID V4');
|
||||||
|
}
|
||||||
|
|
||||||
$state = $state->value;
|
$state = $state->value;
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -127,7 +160,7 @@
|
||||||
$statement = Database::getConnection()->prepare("UPDATE signing_keys SET state=:state WHERE peer_uuid=:peer_uuid AND uuid=:uuid");
|
$statement = Database::getConnection()->prepare("UPDATE signing_keys SET state=:state WHERE peer_uuid=:peer_uuid AND uuid=:uuid");
|
||||||
$statement->bindParam(':state', $state);
|
$statement->bindParam(':state', $state);
|
||||||
$statement->bindParam(':peer_uuid', $peerUuid);
|
$statement->bindParam(':peer_uuid', $peerUuid);
|
||||||
$statement->bindParam(':uuid', $uuid);
|
$statement->bindParam(':uuid', $signatureUuid);
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
}
|
}
|
||||||
catch (PDOException $e)
|
catch (PDOException $e)
|
||||||
|
@ -139,17 +172,31 @@
|
||||||
/**
|
/**
|
||||||
* Retrieves a signing key from the database using the provided UUID.
|
* Retrieves a signing key from the database using the provided UUID.
|
||||||
*
|
*
|
||||||
* @param string $peerUuid The UUID of the peer associated with the signing key.
|
* @param string|PeerDatabaseRecord $peerUuid The UUID of the peer associated with the signing key.
|
||||||
* @param string $uuid The UUID of the signing key to retrieve.
|
* @param string $signatureUuid The UUID of the signing key to retrieve.
|
||||||
* @return SigningKeyRecord|null The signing key record if found, or null if no record exists.
|
* @return SigningKeyRecord|null The signing key record if found, or null if no record exists.
|
||||||
* @throws DatabaseOperationException If a database error occurs during the operation.
|
* @throws DatabaseOperationException If a database error occurs during the operation.
|
||||||
*/
|
*/
|
||||||
public static function getSigningKey(string $peerUuid, string $uuid): ?SigningKeyRecord
|
public static function getSigningKey(string|PeerDatabaseRecord $peerUuid, string $signatureUuid): ?SigningKeyRecord
|
||||||
{
|
{
|
||||||
|
if($peerUuid instanceof PeerDatabaseRecord)
|
||||||
|
{
|
||||||
|
$peerUuid = $peerUuid->getUuid();
|
||||||
|
}
|
||||||
|
elseif(!Validator::validateUuid($peerUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given internal peer UUID is not a valid UUID V4');
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!Validator::validateUuid($signatureUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given signature UUID is not a valid UUID V4');
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$statement = Database::getConnection()->prepare("SELECT * FROM signing_keys WHERE uuid=:uuid AND peer_uuid=:peer_uuid");
|
$statement = Database::getConnection()->prepare("SELECT * FROM signing_keys WHERE uuid=:uuid AND peer_uuid=:peer_uuid");
|
||||||
$statement->bindParam(':uuid', $uuid);
|
$statement->bindParam(':uuid', $signatureUuid);
|
||||||
$statement->bindParam(':peer_uuid', $peerUuid);
|
$statement->bindParam(':peer_uuid', $peerUuid);
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
|
|
||||||
|
@ -169,12 +216,21 @@
|
||||||
/**
|
/**
|
||||||
* Retrieves the signing keys associated with a specific peer UUID.
|
* Retrieves the signing keys associated with a specific peer UUID.
|
||||||
*
|
*
|
||||||
* @param string $peerUuid The UUID of the peer whose signing keys are to be retrieved.
|
* @param string|PeerDatabaseRecord $peerUuid The UUID of the peer whose signing keys are to be retrieved.
|
||||||
* @return SigningKeyRecord[] An array of SigningKeyRecord objects representing the signing keys.
|
* @return SigningKeyRecord[] An array of SigningKeyRecord objects representing the signing keys.
|
||||||
* @throws DatabaseOperationException If an error occurs during the database operation.
|
* @throws DatabaseOperationException If an error occurs during the database operation.
|
||||||
*/
|
*/
|
||||||
public static function getSigningKeys(string $peerUuid): array
|
public static function getSigningKeys(string|PeerDatabaseRecord $peerUuid): array
|
||||||
{
|
{
|
||||||
|
if($peerUuid instanceof PeerDatabaseRecord)
|
||||||
|
{
|
||||||
|
$peerUuid = $peerUuid->getUuid();
|
||||||
|
}
|
||||||
|
elseif(!Validator::validateUuid($peerUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given internal peer UUID is not a valid UUID V4');
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$statement = Database::getConnection()->prepare("SELECT * FROM signing_keys WHERE peer_uuid=:peer_uuid");
|
$statement = Database::getConnection()->prepare("SELECT * FROM signing_keys WHERE peer_uuid=:peer_uuid");
|
||||||
|
@ -198,17 +254,31 @@
|
||||||
/**
|
/**
|
||||||
* Checks if a signing key exists in the database using the provided UUID.
|
* Checks if a signing key exists in the database using the provided UUID.
|
||||||
*
|
*
|
||||||
* @param string $peerUuid The UUID of the peer associated with the signing key.
|
* @param string|PeerDatabaseRecord $peerUuid The UUID of the peer associated with the signing key.
|
||||||
* @param string $uuid The UUID of the signing key to check.
|
* @param string $signatureUuid The UUID of the signing key to check.
|
||||||
* @return bool True if the signing key exists, false otherwise.
|
* @return bool True if the signing key exists, false otherwise.
|
||||||
* @throws DatabaseOperationException If a database error occurs during the operation.
|
* @throws DatabaseOperationException If a database error occurs during the operation.
|
||||||
*/
|
*/
|
||||||
public static function signingKeyExists(string $peerUuid, string $uuid): bool
|
public static function signingKeyExists(string|PeerDatabaseRecord $peerUuid, string $signatureUuid): bool
|
||||||
{
|
{
|
||||||
|
if($peerUuid instanceof PeerDatabaseRecord)
|
||||||
|
{
|
||||||
|
$peerUuid = $peerUuid->getUuid();
|
||||||
|
}
|
||||||
|
elseif(!Validator::validateUuid($peerUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given internal peer UUID is not a valid UUID V4');
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!Validator::validateUuid($signatureUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given signature UUID is not a valid UUID V4');
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$statement = Database::getConnection()->prepare("SELECT COUNT(*) FROM signing_keys WHERE uuid=:uuid AND peer_uuid=:peer_uuid");
|
$statement = Database::getConnection()->prepare("SELECT COUNT(*) FROM signing_keys WHERE uuid=:uuid AND peer_uuid=:peer_uuid");
|
||||||
$statement->bindParam(':uuid', $uuid);
|
$statement->bindParam(':uuid', $signatureUuid);
|
||||||
$statement->bindParam(':peer_uuid', $peerUuid);
|
$statement->bindParam(':peer_uuid', $peerUuid);
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
|
|
||||||
|
@ -223,17 +293,31 @@
|
||||||
/**
|
/**
|
||||||
* Deletes a signing key from the database using the provided UUID.
|
* Deletes a signing key from the database using the provided UUID.
|
||||||
*
|
*
|
||||||
* @param string $peerUuid The UUID of the peer associated with the signing key.
|
* @param string|PeerDatabaseRecord $peerUuid The UUID of the peer associated with the signing key.
|
||||||
* @param string $uuid The UUID of the signing key to delete.
|
* @param string $signatureUuid The UUID of the signing key to delete.
|
||||||
* @return void
|
* @return void
|
||||||
* @throws DatabaseOperationException If a database error occurs during the operation.
|
* @throws DatabaseOperationException If a database error occurs during the operation.
|
||||||
*/
|
*/
|
||||||
public static function deleteSigningKey(string $peerUuid, string $uuid): void
|
public static function deleteSigningKey(string|PeerDatabaseRecord $peerUuid, string $signatureUuid): void
|
||||||
{
|
{
|
||||||
|
if($peerUuid instanceof PeerDatabaseRecord)
|
||||||
|
{
|
||||||
|
$peerUuid = $peerUuid->getUuid();
|
||||||
|
}
|
||||||
|
elseif(!Validator::validateUuid($peerUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given internal peer UUID is not a valid UUID V4');
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!Validator::validateUuid($signatureUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The given signature UUID is not a valid UUID V4');
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$statement = Database::getConnection()->prepare("DELETE FROM signing_keys WHERE uuid=:uuid AND peer_uuid=:peer_uuid");
|
$statement = Database::getConnection()->prepare("DELETE FROM signing_keys WHERE uuid=:uuid AND peer_uuid=:peer_uuid");
|
||||||
$statement->bindParam(':uuid', $uuid);
|
$statement->bindParam(':uuid', $signatureUuid);
|
||||||
$statement->bindParam(':peer_uuid', $peerUuid);
|
$statement->bindParam(':peer_uuid', $peerUuid);
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
}
|
}
|
||||||
|
|
|
@ -244,7 +244,6 @@
|
||||||
* @param string $decryptedContent The decrypted content to verify the signature against.
|
* @param string $decryptedContent The decrypted content to verify the signature against.
|
||||||
* @return bool True if the signature is valid, false otherwise.
|
* @return bool True if the signature is valid, false otherwise.
|
||||||
* @throws DatabaseOperationException Thrown if an error occurs while retrieving the client's public signing key.
|
* @throws DatabaseOperationException Thrown if an error occurs while retrieving the client's public signing key.
|
||||||
* @throws StandardRpcException Thrown if the session UUID is invalid.
|
|
||||||
*/
|
*/
|
||||||
private function verifySignature(string $decryptedContent): bool
|
private function verifySignature(string $decryptedContent): bool
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Socialbox\Objects;
|
|
||||||
|
|
||||||
class ResolvedServer
|
|
||||||
{
|
|
||||||
private string $endpoint;
|
|
||||||
private string $publicKey;
|
|
||||||
|
|
||||||
public function __construct(string $endpoint, string $publicKey)
|
|
||||||
{
|
|
||||||
$this->endpoint = $endpoint;
|
|
||||||
$this->publicKey = $publicKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getEndpoint(): string
|
|
||||||
{
|
|
||||||
return $this->endpoint;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getPublicKey(): string
|
|
||||||
{
|
|
||||||
return $this->publicKey;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -7,6 +7,7 @@
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use Socialbox\Classes\Cryptography;
|
use Socialbox\Classes\Cryptography;
|
||||||
use Socialbox\Classes\RpcClient;
|
use Socialbox\Classes\RpcClient;
|
||||||
|
use Socialbox\Classes\Validator;
|
||||||
use Socialbox\Enums\PrivacyState;
|
use Socialbox\Enums\PrivacyState;
|
||||||
use Socialbox\Enums\StandardMethods;
|
use Socialbox\Enums\StandardMethods;
|
||||||
use Socialbox\Enums\Status\SignatureVerificationStatus;
|
use Socialbox\Enums\Status\SignatureVerificationStatus;
|
||||||
|
@ -85,6 +86,7 @@
|
||||||
* @param PeerAddress|string $receivingPeer The address of the peer to create the channel with
|
* @param PeerAddress|string $receivingPeer The address of the peer to create the channel with
|
||||||
* @return string The UUID of the encryption channel
|
* @return string The UUID of the encryption channel
|
||||||
* @throws CryptographyException Thrown if there was an error while generating the encryption key pair
|
* @throws CryptographyException Thrown if there was an error while generating the encryption key pair
|
||||||
|
* @throws RpcException Thrown if there was an error with the RPC request
|
||||||
*/
|
*/
|
||||||
public function newEncryptionChannel(string|PeerAddress $receivingPeer): string
|
public function newEncryptionChannel(string|PeerAddress $receivingPeer): string
|
||||||
{
|
{
|
||||||
|
@ -496,14 +498,13 @@
|
||||||
*
|
*
|
||||||
* @param PeerAddress|string $peer The address of the peer to verify the signature for
|
* @param PeerAddress|string $peer The address of the peer to verify the signature for
|
||||||
* @param string $signatureUuid The UUID of the signature to verify
|
* @param string $signatureUuid The UUID of the signature to verify
|
||||||
* @param string $signaturePublicKey The public key that was used to create the signature
|
|
||||||
* @param string $signature The signature to verify
|
* @param string $signature The signature to verify
|
||||||
* @param string $sha512 The SHA512 hash of the data that was signed
|
* @param string $sha512 The SHA512 hash of the data that was signed
|
||||||
* @param int|null $signatureTime Optional. The timestamp of the signature creation time
|
* @param int|null $signatureTime Optional. The timestamp of the signature creation time
|
||||||
* @return SignatureVerificationStatus the status of the verification
|
* @return SignatureVerificationStatus the status of the verification
|
||||||
* @throws RpcException Thrown if there was an error with the RPC request
|
* @throws RpcException Thrown if there was an error with the RPC request
|
||||||
*/
|
*/
|
||||||
public function verifySignature(PeerAddress|string $peer, string $signatureUuid, string $signaturePublicKey, string $signature, string $sha512, ?int $signatureTime=null): SignatureVerificationStatus
|
public function verifySignature(PeerAddress|string $peer, string $signatureUuid, string $signature, string $sha512, ?int $signatureTime=null): SignatureVerificationStatus
|
||||||
{
|
{
|
||||||
if($peer instanceof PeerAddress)
|
if($peer instanceof PeerAddress)
|
||||||
{
|
{
|
||||||
|
@ -537,6 +538,20 @@
|
||||||
{
|
{
|
||||||
$identifiedAs = $identifiedAs->getAddress();
|
$identifiedAs = $identifiedAs->getAddress();
|
||||||
}
|
}
|
||||||
|
elseif(is_string($identifiedAs) && !Validator::validatePeerAddress($identifiedAs))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('Invalid Peer Address');
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!Validator::validateUuid($channelUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('Invalid Channel UUID V4');
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!Cryptography::validatePublicEncryptionKey($publicEncryptionKey))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('Invalid Public Encryption Key');
|
||||||
|
}
|
||||||
|
|
||||||
return $this->sendRequest(
|
return $this->sendRequest(
|
||||||
new RpcRequest(StandardMethods::ENCRYPTION_ACCEPT_CHANNEL, parameters: [
|
new RpcRequest(StandardMethods::ENCRYPTION_ACCEPT_CHANNEL, parameters: [
|
||||||
|
@ -546,23 +561,6 @@
|
||||||
)->getResponse()->getResult();
|
)->getResponse()->getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if an encryption channel exists for the given channel UUID.
|
|
||||||
*
|
|
||||||
* @param string $channelUuid The UUID of the channel to check.
|
|
||||||
*
|
|
||||||
* @return bool True if an encryption channel exists, false otherwise.
|
|
||||||
* @throws RpcException Thrown if there was an error with the RPC request.
|
|
||||||
*/
|
|
||||||
public function encryptionChannelExists(string $channelUuid): bool
|
|
||||||
{
|
|
||||||
return $this->sendRequest(
|
|
||||||
new RpcRequest(StandardMethods::ENCRYPTION_CHANNEL_EXISTS, parameters: [
|
|
||||||
'channel_uuid' => $channelUuid
|
|
||||||
])
|
|
||||||
)->getResponse()->getResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Acknowledges an encrypted message in a specific channel.
|
* Acknowledges an encrypted message in a specific channel.
|
||||||
*
|
*
|
||||||
|
@ -594,7 +592,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Acknowledges messages in an encryption channel.
|
* Acknowledges multiple messages in an encryption channel by sending multiple requests at once
|
||||||
*
|
*
|
||||||
* @param string $channelUuid The UUID of the encryption channel.
|
* @param string $channelUuid The UUID of the encryption channel.
|
||||||
* @param array $messageUuids An array of message UUIDs to acknowledge.
|
* @param array $messageUuids An array of message UUIDs to acknowledge.
|
||||||
|
@ -615,6 +613,23 @@
|
||||||
]), $messageUuids), $identifiedAs);
|
]), $messageUuids), $identifiedAs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if an encryption channel exists for the given channel UUID.
|
||||||
|
*
|
||||||
|
* @param string $channelUuid The UUID of the channel to check.
|
||||||
|
*
|
||||||
|
* @return bool True if an encryption channel exists, false otherwise.
|
||||||
|
* @throws RpcException Thrown if there was an error with the RPC request.
|
||||||
|
*/
|
||||||
|
public function encryptionChannelExists(string $channelUuid): bool
|
||||||
|
{
|
||||||
|
return $this->sendRequest(
|
||||||
|
new RpcRequest(StandardMethods::ENCRYPTION_CHANNEL_EXISTS, parameters: [
|
||||||
|
'channel_uuid' => $channelUuid
|
||||||
|
])
|
||||||
|
)->getResponse()->getResult();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rejects a message from the encryption channel
|
* Rejects a message from the encryption channel
|
||||||
*
|
*
|
||||||
|
@ -744,6 +759,22 @@
|
||||||
)->getResponse()->getResult();
|
)->getResponse()->getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes an encryption channel by its UUID.
|
||||||
|
*
|
||||||
|
* @param string $channelUuid The UUID of the encryption channel to delete.
|
||||||
|
* @return bool True if the channel was successfully deleted, false otherwise.
|
||||||
|
* @throws RpcException Thrown if there was an error with the RPC request
|
||||||
|
*/
|
||||||
|
public function encryptionDeleteChannel(string $channelUuid): bool
|
||||||
|
{
|
||||||
|
return $this->sendRequest(
|
||||||
|
new RpcRequest(StandardMethods::ENCRYPTION_DELETE_CHANNEL, parameters: [
|
||||||
|
'channel_uuid' => $channelUuid
|
||||||
|
])
|
||||||
|
)->getResponse()->getResult();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves an encryption channel by its UUID.
|
* Retrieves an encryption channel by its UUID.
|
||||||
*
|
*
|
||||||
|
@ -760,6 +791,66 @@
|
||||||
)->getResponse()->getResult());
|
)->getResponse()->getResult());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves encrypted channel requests with pagination support.
|
||||||
|
*
|
||||||
|
* This method fetches channel requests that have encryption enabled.
|
||||||
|
*
|
||||||
|
* @param int|null $page The page number to retrieve (defaults to 1)
|
||||||
|
* @param int|null $limit The maximum number of items per page (null means use default system limit)
|
||||||
|
* @return EncryptionChannel[] An array containing encryption channels
|
||||||
|
* @throws RpcException Thrown if there was an error with the RPC request
|
||||||
|
*/
|
||||||
|
public function encryptionGetChannelRequests(?int $page=1, ?int $limit=null): array
|
||||||
|
{
|
||||||
|
return array_map(fn($channel) => new EncryptionChannel($channel),
|
||||||
|
$this->sendRequest(new RpcRequest(StandardMethods::ENCRYPTION_GET_CHANNEL_REQUESTS, parameters: [
|
||||||
|
'page' => $page,
|
||||||
|
'limit' => $limit
|
||||||
|
]))->getResponse()->getResult()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves incoming encryption channels with pagination support.
|
||||||
|
*
|
||||||
|
* This method fetches channels that are incoming to the authenticated peer.
|
||||||
|
*
|
||||||
|
* @param int|null $page The page number to retrieve (defaults to 1)
|
||||||
|
* @param int|null $limit The maximum number of items per page (null means use default system limit)
|
||||||
|
* @return EncryptionChannel[] An array containing encryption channels
|
||||||
|
* @throws RpcException Thrown if there was an error with the RPC request
|
||||||
|
*/
|
||||||
|
public function encryptionGetIncomingChannels(?int $page=1, ?int $limit=null): array
|
||||||
|
{
|
||||||
|
return array_map(fn($channel) => new EncryptionChannel($channel),
|
||||||
|
$this->sendRequest(new RpcRequest(StandardMethods::ENCRYPTION_GET_INCOMING_CHANNELS, parameters: [
|
||||||
|
'page' => $page,
|
||||||
|
'limit' => $limit
|
||||||
|
]))->getResponse()->getResult()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves outgoing encryption channels with pagination support.
|
||||||
|
*
|
||||||
|
* This method fetches channels that are outgoing from the authenticated peer.
|
||||||
|
*
|
||||||
|
* @param int|null $page The page number to retrieve (defaults to 1)
|
||||||
|
* @param int|null $limit The maximum number of items per page (null means use default system limit)
|
||||||
|
* @return EncryptionChannel[] An array containing encryption channels
|
||||||
|
* @throws RpcException Thrown if there was an error with the RPC request
|
||||||
|
*/
|
||||||
|
public function getOutgoingChannels(?int $page=1, ?int $limit=null): array
|
||||||
|
{
|
||||||
|
return array_map(fn($channel) => new EncryptionChannel($channel),
|
||||||
|
$this->sendRequest(new RpcRequest(StandardMethods::ENCRYPTION_GET_OUTGOING_CHANNELS, parameters: [
|
||||||
|
'page' => $page,
|
||||||
|
'limit' => $limit
|
||||||
|
]))->getResponse()->getResult()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Accepts the community guidelines, returns True if the guidelines were accepted.
|
* Accepts the community guidelines, returns True if the guidelines were accepted.
|
||||||
*
|
*
|
||||||
|
@ -955,7 +1046,7 @@
|
||||||
{
|
{
|
||||||
return $this->sendRequest(
|
return $this->sendRequest(
|
||||||
new RpcRequest(StandardMethods::SETTINGS_DELETE_SIGNATURE, parameters: [
|
new RpcRequest(StandardMethods::SETTINGS_DELETE_SIGNATURE, parameters: [
|
||||||
'uuid' => $uuid
|
'signature_uuid' => $uuid
|
||||||
])
|
])
|
||||||
)->getResponse()->getResult();
|
)->getResponse()->getResult();
|
||||||
}
|
}
|
||||||
|
@ -1006,7 +1097,7 @@
|
||||||
{
|
{
|
||||||
return new Signature($this->sendRequest(
|
return new Signature($this->sendRequest(
|
||||||
new RpcRequest(StandardMethods::SETTINGS_GET_SIGNATURE, parameters: [
|
new RpcRequest(StandardMethods::SETTINGS_GET_SIGNATURE, parameters: [
|
||||||
'uuid' => $uuid
|
'signature_uuid' => $uuid
|
||||||
])
|
])
|
||||||
)->getResponse()->getResult());
|
)->getResponse()->getResult());
|
||||||
}
|
}
|
||||||
|
@ -1093,15 +1184,15 @@
|
||||||
/**
|
/**
|
||||||
* Checks if a signature exists in the peer's profile, returns True if the signature exists.
|
* Checks if a signature exists in the peer's profile, returns True if the signature exists.
|
||||||
*
|
*
|
||||||
* @param string $uuid The UUID of the signature to check for it's existence
|
* @param string $signatureUuid The UUID of the signature to check for it's existence
|
||||||
* @return bool Returns True if the signature exists, False otherwise
|
* @return bool Returns True if the signature exists, False otherwise
|
||||||
* @throws RpcException Thrown if there was an error with the RPC request
|
* @throws RpcException Thrown if there was an error with the RPC request
|
||||||
*/
|
*/
|
||||||
public function settingsSignatureExists(string $uuid): bool
|
public function settingsSignatureExists(string $signatureUuid): bool
|
||||||
{
|
{
|
||||||
return $this->sendRequest(
|
return $this->sendRequest(
|
||||||
new RpcRequest(StandardMethods::SETTINGS_SIGNATURE_EXISTS, parameters: [
|
new RpcRequest(StandardMethods::SETTINGS_SIGNATURE_EXISTS, parameters: [
|
||||||
'uuid' => $uuid
|
'signature_uuid' => $signatureUuid
|
||||||
])
|
])
|
||||||
)->getResponse()->getResult();
|
)->getResponse()->getResult();
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
use Socialbox\Exceptions\RequestException;
|
use Socialbox\Exceptions\RequestException;
|
||||||
use Socialbox\Exceptions\ResolutionException;
|
use Socialbox\Exceptions\ResolutionException;
|
||||||
use Socialbox\Exceptions\RpcException;
|
use Socialbox\Exceptions\RpcException;
|
||||||
|
use Socialbox\Exceptions\Standard\InvalidRpcArgumentException;
|
||||||
use Socialbox\Exceptions\Standard\StandardRpcException;
|
use Socialbox\Exceptions\Standard\StandardRpcException;
|
||||||
use Socialbox\Managers\ContactManager;
|
use Socialbox\Managers\ContactManager;
|
||||||
use Socialbox\Managers\ExternalSessionManager;
|
use Socialbox\Managers\ExternalSessionManager;
|
||||||
|
@ -789,6 +790,16 @@
|
||||||
*/
|
*/
|
||||||
public static function verifyTimedSignature(PeerAddress|string $signingPeer, string $signatureUuid, string $signature, string $messageHash, int $signatureTime): SignatureVerificationStatus
|
public static function verifyTimedSignature(PeerAddress|string $signingPeer, string $signatureUuid, string $signature, string $messageHash, int $signatureTime): SignatureVerificationStatus
|
||||||
{
|
{
|
||||||
|
if(!Validator::validateUuid($signatureUuid))
|
||||||
|
{
|
||||||
|
return SignatureVerificationStatus::INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!Cryptography::validateSha512($messageHash))
|
||||||
|
{
|
||||||
|
return SignatureVerificationStatus::INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
// Resolve the peer signature key
|
// Resolve the peer signature key
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -838,6 +849,16 @@
|
||||||
*/
|
*/
|
||||||
public static function verifySignature(PeerAddress|string $signingPeer, string $signatureUuid, string $signature, string $messageHash): SignatureVerificationStatus
|
public static function verifySignature(PeerAddress|string $signingPeer, string $signatureUuid, string $signature, string $messageHash): SignatureVerificationStatus
|
||||||
{
|
{
|
||||||
|
if(!Validator::validateUuid($signatureUuid))
|
||||||
|
{
|
||||||
|
return SignatureVerificationStatus::INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!Cryptography::validateSha512($messageHash))
|
||||||
|
{
|
||||||
|
return SignatureVerificationStatus::INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$signingKey = self::resolvePeerSignature($signingPeer, $signatureUuid);
|
$signingKey = self::resolvePeerSignature($signingPeer, $signatureUuid);
|
||||||
|
@ -881,14 +902,7 @@
|
||||||
// Convert string peer address to object PeerAddress
|
// Convert string peer address to object PeerAddress
|
||||||
if(is_string($peerAddress))
|
if(is_string($peerAddress))
|
||||||
{
|
{
|
||||||
try
|
$peerAddress = PeerAddress::fromAddress($peerAddress);
|
||||||
{
|
|
||||||
$peerAddress = PeerAddress::fromAddress($peerAddress);
|
|
||||||
}
|
|
||||||
catch(InvalidArgumentException $e)
|
|
||||||
{
|
|
||||||
throw new StandardRpcException($e->getMessage(), StandardError::RPC_INVALID_ARGUMENTS, $e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prevent resolutions against any host
|
// Prevent resolutions against any host
|
||||||
|
@ -897,6 +911,11 @@
|
||||||
throw new StandardRpcException('Cannot resolve signature for a host peer', StandardError::FORBIDDEN);
|
throw new StandardRpcException('Cannot resolve signature for a host peer', StandardError::FORBIDDEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!Validator::validateUuid($signatureUuid))
|
||||||
|
{
|
||||||
|
throw new InvalidRpcArgumentException('The given signature UUID is not a valid UUID V4');
|
||||||
|
}
|
||||||
|
|
||||||
// If the peer is registered within this server
|
// If the peer is registered within this server
|
||||||
if($peerAddress->getDomain() === Configuration::getInstanceConfiguration()->getDomain())
|
if($peerAddress->getDomain() === Configuration::getInstanceConfiguration()->getDomain())
|
||||||
{
|
{
|
||||||
|
|
|
@ -278,8 +278,6 @@
|
||||||
$message = "Message to sign";
|
$message = "Message to sign";
|
||||||
|
|
||||||
$this->expectException(CryptographyException::class);
|
$this->expectException(CryptographyException::class);
|
||||||
$this->expectExceptionMessage("Failed to sign message");
|
|
||||||
|
|
||||||
Cryptography::signMessage($message, $invalidPrivateKey);
|
Cryptography::signMessage($message, $invalidPrivateKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue