pax_global_header 0000666 0000000 0000000 00000000064 13203022126 0014501 g ustar 00root root 0000000 0000000 52 comment=c50ed60c7b405bd3c8da4bf61db42e85caaf4407
openfortivpn-1.6.0/ 0000775 0000000 0000000 00000000000 13203022126 0014236 5 ustar 00root root 0000000 0000000 openfortivpn-1.6.0/.gitignore 0000664 0000000 0000000 00000000277 13203022126 0016234 0 ustar 00root root 0000000 0000000 *.o
.deps
aclocal.m4
autom4te.cache
compile
config.log
config.status
configure
cscope.*
depcomp
install-sh
Makefile
Makefile.in
missing
openfortivpn
.dirstamp
doc/*.1
config.sub
config.guess
openfortivpn-1.6.0/.travis.yml 0000664 0000000 0000000 00000001065 13203022126 0016351 0 ustar 00root root 0000000 0000000 language: c
sudo: false
install:
- >
[ -f $HOME/astyle/build/gcc/bin/astyle ] || {
wget -O astyle_2.05.1_linux.tar.gz http://sourceforge.net/projects/astyle/files/astyle/astyle%202.05.1/astyle_2.05.1_linux.tar.gz/download;
tar -xf astyle_2.05.1_linux.tar.gz -C $HOME;
make -C $HOME/astyle/build/gcc;
}
- make -C $HOME/astyle/build/gcc prefix=$HOME install
cache:
directories:
- $HOME/astyle
script:
- ./tests/lint/run.sh
- >
./autogen.sh
&& ./configure --prefix=/usr --sysconfdir=/etc
&& make
openfortivpn-1.6.0/LICENSE 0000664 0000000 0000000 00000106063 13203022126 0015251 0 ustar 00root root 0000000 0000000 GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
Copyright (C)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
Copyright (C)
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
.
Exception
In addition, as a special exception, the copyright holders give permission
to link the code of portions of this program with the OpenSSL library under
certain conditions as described in each individual source file, and distribute
linked combinations including the two.
You must obey the GNU General Public License in all respects for all of the
code used other than OpenSSL. If you modify file(s) with this exception, you
may extend this exception to your version of the file(s), but you are not
obligated to do so. If you do not wish to do so, delete this exception
statement from your version. If you delete this exception statement from all
source files in the program, then also delete it here.
openfortivpn-1.6.0/LICENSE.OpenSSL 0000664 0000000 0000000 00000014206 13203022126 0016530 0 ustar 00root root 0000000 0000000
LICENSE ISSUES
==============
The OpenSSL toolkit stays under a dual license, i.e. both the conditions of
the OpenSSL License and the original SSLeay license apply to the toolkit.
See below for the actual license texts. Actually both licenses are BSD-style
Open Source licenses. In case of any license issues related to OpenSSL
please contact openssl-core@openssl.org.
OpenSSL License
---------------
/* ====================================================================
* Copyright (c) 1998-2011 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* openssl-core@openssl.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This product includes cryptographic software written by Eric Young
* (eay@cryptsoft.com). This product includes software written by Tim
* Hudson (tjh@cryptsoft.com).
*
*/
Original SSLeay License
-----------------------
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
*
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/
openfortivpn-1.6.0/Makefile.am 0000664 0000000 0000000 00000002347 13203022126 0016300 0 ustar 00root root 0000000 0000000 # http://mij.oltrelinux.com/devel/autoconf-automake/
bin_PROGRAMS = openfortivpn
openfortivpn_SOURCES = src/config.c src/config.h src/hdlc.c src/hdlc.h \
src/http.c src/http.h src/io.c src/io.h src/ipv4.c \
src/ipv4.h src/log.c src/log.h src/tunnel.c \
src/tunnel.h src/main.c src/ssl.h src/xml.c \
src/xml.h src/userinput.c src/userinput.h
openfortivpn_CFLAGS = -Wall --pedantic -std=gnu99
openfortivpn_CPPFLAGS = -DSYSCONFDIR=\"$(sysconfdir)\"
openfortivpn_CFLAGS += $(OPENSSL_CFLAGS)
openfortivpn_LDADD = $(OPENSSL_LIBS)
DISTCHECK_CONFIGURE_FLAGS = CFLAGS=-Werror
confdir=$(sysconfdir)/openfortivpn
datadir=$(prefix)/share/openfortivpn
data_DATA=etc/openfortivpn/config.template
install-data-hook:
chmod 0600 $(DESTDIR)$(datadir)/config.template ; \
if ! test -e $(DESTDIR)$(sysconfdir)/openfortivpn/config ; then \
mkdir -p $(DESTDIR)$(sysconfdir)/openfortivpn ; \
cp -a $(DESTDIR)$(datadir)/config.template \
$(DESTDIR)$(sysconfdir)/openfortivpn/config ; \
fi
dist_man_MANS = doc/openfortivpn.1
doc/openfortivpn.1: $(srcdir)/doc/openfortivpn.1.in
sed -e 's|[@]SYSCONFDIR[@]|$(sysconfdir)|g;s|[@]DATADIR[@]|$(datadir)|g;' $^ >$@
EXTRA_DIST = LICENSE README.md doc/openfortivpn.1.in $(data_DATA)
openfortivpn-1.6.0/README.md 0000664 0000000 0000000 00000007626 13203022126 0015530 0 ustar 00root root 0000000 0000000 openfortivpn
============
openfortivpn is a client for PPP+SSL VPN tunnel services.
It spawns a pppd process and operates the communication between the gateway and
this process.
It is compatible with Fortinet VPNs.
--------
Examples
--------
* Simply connect to a VPN:
```
openfortivpn vpn-gateway:8443 --username=foo
```
* Connect to a VPN using an authentication realm:
```
openfortivpn vpn-gateway:8443 --username=foo --realm=bar
```
* Don't set IP routes and don't add VPN nameservers to `/etc/resolv.conf`:
```
openfortivpn vpn-gateway:8443 -u foo -p bar --no-routes --no-dns
```
* Using a config file:
```
openfortivpn
```
With `/etc/openfortivpn/config` containing:
```
host = vpn-gateway
port = 8443
username = foo
password = bar
set-dns = 0
set-routes = 0
# X509 certificate sha256 sum, trust only this one!
trusted-cert = e46d4aff08ba6914e64daa85bc6112a422fa7ce16631bff0b592a28556f993db
```
----------
Installing
----------
openfortivpn is packaged for [Fedora](https://admin.fedoraproject.org/pkgdb/package/rpms/openfortivpn/), [openSUSE / SLE](https://software.opensuse.org/package/openfortivpn), [Gentoo](https://packages.gentoo.org/packages/net-vpn/openfortivpn), [NixOS](https://github.com/NixOS/nixpkgs/tree/master/pkgs/tools/networking/openfortivpn), [Arch Linux](https://aur.archlinux.org/packages/openfortivpn) and [Solus](https://packages.solus-project.com/unstable/o/openfortivpn/) under the package name `openfortivpn`.
For other distros, you'll need to build and install from source:
1. Install build dependencies.
* RHEL/CentOS/Fedora: `gcc` `automake` `autoconf` `openssl-devel`
* Debian/Ubuntu: `gcc` `automake` `autoconf` `libssl-dev`
* Arch Linux: `gcc` `automake` `autoconf` `openssl`
* Gentoo Linux: `net-dialup/ppp`
* openSUSE: `gcc` `automake` `autoconf` `libopenssl-devel`
* macOS(Homebrew): `automake` `autoconf` `openssl@1.0`
On Linux, if you manage your kernel yourself, ensure to compile those modules:
```
CONFIG_PPP=m
CONFIG_PPP_ASYNC=m
```
On macOS, install 'Homebrew' to install the build dependencies:
```shell
# Install 'Homebrew'
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
# Install Dependencies
brew install automake autoconf openssl@1.0
```
On macOS, install 'openfortivpn'...
```
brew install openfortivpn
```
...**or** build a version of your choice from source following the instructions in step 2.
2. Build and install.
```shell
./autogen.sh
./configure --prefix=/usr/local --sysconfdir=/etc
make
sudo make install
```
If you need to specify the openssl location you can set the
`$PKG_CONFIG_PATH` environment variable.
----------------
Running as root?
----------------
openfortivpn needs elevated privileges at three steps during tunnel set up:
* when spawning a `/usr/sbin/pppd` process;
* when setting IP routes through VPN (when the tunnel is up);
* when adding nameservers to `/etc/resolv.conf` (when the tunnel is up).
For these reasons, you may need to use `sudo openfortivpn`.
If you need it to be usable by non-sudoer users, you might consider adding an
entry in `/etc/sudoers`.
For example:
`visudo -f /etc/sudoers.d/openfortivpn`
```
Cmnd_Alias OPENFORTIVPN = /usr/bin/openfortivpn
%adm ALL = (ALL) OPENFORTIVPN
```
**Warning**: Make sure only trusted users can run openfortivpn as root!
As described in [#54](https://github.com/adrienverge/openfortivpn/issues/54),
a malicious user could use `--pppd-plugin` and `--pppd-log` options to divert
the program's behaviour.
------------
Contributing
------------
Feel free to make pull requests!
C coding style should follow the
[Linux kernel Documentation/CodingStyle](http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?id=refs/heads/master).
openfortivpn-1.6.0/autogen.sh 0000775 0000000 0000000 00000000074 13203022126 0016240 0 ustar 00root root 0000000 0000000 #!/bin/sh
set -exu
aclocal
autoconf
automake --add-missing
openfortivpn-1.6.0/configure.ac 0000664 0000000 0000000 00000002251 13203022126 0016524 0 ustar 00root root 0000000 0000000 # -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.68])
AC_INIT([openfortivpn], [1.6.0])
AC_CONFIG_SRCDIR([src/main.c])
AM_INIT_AUTOMAKE([foreign subdir-objects])
# Checks for programs.
AC_PROG_CC
AC_GNU_SOURCE
# Helps support multiarch by setting 'host_os' and 'host_cpu'
AC_CANONICAL_HOST
AM_SILENT_RULES([yes])
# Checks for libraries.
PKG_CHECK_MODULES(OPENSSL, [libcrypto libssl])
AC_CHECK_LIB([pthread], [pthread_create], [], [AC_MSG_ERROR([Cannot find libpthread.])])
AC_CHECK_LIB([util], [forkpty], [], [AC_MSG_ERROR([Cannot find libutil.])])
# Checks for header files.
AC_CHECK_HEADERS([arpa/inet.h fcntl.h netdb.h netinet/in.h stddef.h stdint.h stdlib.h string.h strings.h sys/ioctl.h sys/socket.h unistd.h])
# Checks for typedefs, structures, and compiler characteristics.
AC_C_INLINE
AC_TYPE_OFF_T
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T
AC_TYPE_UINT16_T
AC_TYPE_UINT32_T
AC_TYPE_UINT8_T
# Checks for library functions.
AC_FUNC_MALLOC
AC_FUNC_REALLOC
AC_CHECK_FUNCS([getaddrinfo inet_ntoa ntohs memmove memset memmem select socket strerror strstr strtol])
AC_OUTPUT(Makefile)
openfortivpn-1.6.0/doc/ 0000775 0000000 0000000 00000000000 13203022126 0015003 5 ustar 00root root 0000000 0000000 openfortivpn-1.6.0/doc/openfortivpn.1.in 0000664 0000000 0000000 00000015646 13203022126 0020237 0 ustar 00root root 0000000 0000000 .TH OPENFORTIVPN 1 "October 23, 2017" ""
.SH NAME
openfortivpn \- Client for PPP+SSL VPN tunnel services
.SH SYNOPSIS
.B openfortivpn
[\fI\fR:\fI\fR]
[\fB\-u\fR \fI\fR]
[\fB\-p\fR \fI\fR]
[\fB\-\-realm=\fI\fR]
[\fB\-\-set-routes=\fR]
[\fB\-\-no-routes\fR]
[\fB\-\-set-dns=\fR]
[\fB\-\-half-internet-routes=\fR]
[\fB\-\-no-dns\fR]
[\fB\-\-ca-file=\fI\fR]
[\fB\-\-user-cert=\fI\fR]
[\fB\-\-user-key=\fI\fR]
[\fB\-\-use-syslog\fR]
[\fB\-\-trusted-cert=\fI\fR]
[\fB\-\-insecure-ssl\fR]
[\fB\-\-cipher-list=\fI\fR]
[\fB\-\-pppd-no-peerdns\fR]
[\fB\-\-pppd-log=\fI\fR]
[\fB\-\-pppd-plugin=\fI\fR]
[\fB\-\-pppd-ipparam=\fI\fR]
[\fB\-\-pppd-ifname=\fI\fR]
[\fB\-c\fR \fI\fR]
[\fB\-v|\-q\fR]
.br
.B openfortivpn
\-\-help
.br
.B openfortivpn
\-\-version
.SH DESCRIPTION
.B openfortivpn
connects to a VPN by setting up a tunnel to the gateway at
\fI\fR:\fI\fR.
.SH OPTIONS
.TP
\fB\-\-help\fR
Show this help message and exit.
.TP
\fB\-\-version\fR
Show version and exit.
.TP
\fB\-c \fI\fR, \fB\-\-config=\fI\fR
Specify a custom config file (default: @SYSCONFDIR@/openfortivpn/config).
.TP
\fB\-u \fI\fR, \fB\-\-username=\fI\fR
VPN account username.
.TP
\fB\-p \fI\fR, \fB\-\-password=\fI\fR
VPN account password.
.TP
\fB\-\-realm=\fI\fR
Connect to the specified authentication realm. Defaults to empty, which
is usually what you want.
.TP
\fB\-\-set-routes=\fI\fR, \fB\-\-no-routes\fR
Set if we should try to configure IP routes through the VPN when tunnel is up. If used multiple times, the last one takes priority.
\fB\-\-no-routes\fR is the same as \fB\-\-set-routes=\fI0\fR.
.TP
\fB\-\-half-internet-routes=\fI\fR, if set to 1, tells openfortivpn not to
replace the default route by a different one, but set up two separate /1-routes instead.
.TP
\fB\-\-set-dns=\fI\fR, \fB\-\-no-dns\fR
Set if we should add VPN nameservers in /etc/resolv.conf when tunnel is up. If used multiple times, the last one takes priority.
\fB\-\-no-dns\fR is the same as \fB\-\-set-dns=\fI0\fR.
.TP
\fB\-\-ca-file=\fI\fR
Use specified PEM-encoded certificate bundle instead of system-wide store to
verify the gateway certificate.
.TP
\fB\-\-user-cert=\fI\fR
Use specified PEM-encoded certificate if the server requires authentication
with a certificate.
.TP
\fB\-\-user-key=\fI\fR
Use specified PEM-encoded key if the server requires authentication with
a certificate.
.TP
\fB\-\-use-syslog\fR
Log to syslog instead of terminal.
.TP
\fB\-\-trusted-cert=\fI\fR
Trust a given gateway. If classical SSL certificate validation fails, the
gateway certificate will be matched against this value. \fI\fR is the
X509 certificate's sha256 sum. This option can be used multiple times to trust
several certificates.
.TP
\fB\-\-insecure-ssl\fR
Do not disable insecure SSL protocols/ciphers.
If your server requires a specific cipher, consider using \fB\-\-cipher-list\fR
instead.
.TP
\fB\-\-cipher-list=\fI\fR
Openssl ciphers to use. If default does not work, you can try alternatives
such as HIGH:!MD5:!RC4 or as suggested by the Cipher: line in the output of
\fBopenssl\fP(1) (e.g. AES256-GCM-SHA384):
$ openssl s_client -connect \fI\fR
(default: HIGH:!aNULL:!kRSA:!PSK:!SRP:!MD5:!RC4)
.TP
\fB\-\-pppd-no-peerdns\fR
Do not ask peer ppp server for DNS addresses and do not make pppd rewrite
/etc/resolv.conf.
.TP
\fB\-\-pppd-log=\fI\fR
Set pppd in debug mode and save its logs into \fI\fR.
.TP
\fB\-\-pppd-plugin=\fI\fR
Use specified pppd plugin instead of configuring the resolver and routes
directly.
.TP
\fB\-\-pppd-ipparam=\fI\fR
Provides an extra parameter to the ip-up, ip-pre-up and ip-down scripts. See man
.BR pppd(8)
for further details
.TP
\fB\-\-pppd-ifname=\fI\fR
Set the ppp interface name. Only if supported by pppd. Patched versions of pppd
implement this option but may not be available on your platform.
.TP
\fB\-v\fR
Increase verbosity. Can be used multiple times to be even more verbose.
.TP
\fB\-q\fR
Decrease verbosity. Can be used multiple times to be even less verbose.
.SH ENVIRONMENT and proxy support
.B openfortivpn
can be run behind a http that supports the http connect command.
It checks if one of the environment variables
.B https_proxy HTTPS_PROXY all_proxy ALL_PROXY
is set which are supposed to contain a string of the format
.br
.B http://[host]:[port]
.br
where
.B [host]
is the ip or the fully qualified host name of the proxy server
.B [port]
is the tcp port number where the proxy is listening for
incoming connections. If one of these variables is defined,
.B openfortivpn
tries to first establish a tcp connection to this proxy (plain http, not encrypted),
and then makes a request to connect to the vpn host as given on the command line
or in the config file. The proxy is supposed to forward any subsequent packets
transparently to the vpn host, so that the tls layer of the connection effectively
is establshed between the client and the vpn host, and the proxy just acts as a
forwarding instance on the lower level of the tcp connection.
The following environment variables are set by
.B openfortivpn
and
.BR pppd(8)
or its scripts can obtain information this way:
.br
VPN_GATEWAY the ip of the gateway host
.br
and for each route three variables are set up, where an integer number
is appended to the variable names, denoting the number of the current route:
.br
VPN_ROUTE_DEST_... the destination network of the route
.br
VPN_ROUTE_MASK_... the network mask for this route
.br
VPN_ROUTE_GATEWAY_... the gateway for the current route entry
.SH CONFIG FILE
Options can be taken from a configuration file. Options passed in the command
line will override those from the config file, though. The default config file
is @SYSCONFDIR@/openfortivpn/config, but this can be set using the \fB\-c\fR option.
An empty template for the config file is installed to
@DATADIR@/config.template
.TP
A config file looks like:
# this is a comment
.br
host = vpn-gateway
.br
port = 8443
.br
username = foo
.br
password = bar
.br
user-cert = @SYSCONFDIR@/openfortivpn/user-cert.pem
.br
user-key = @SYSCONFDIR@/openfortivpn/user-key.pem
.br
# the sha256 digest of the trusted host certs obtained by
.br
# openssl dgst -sha256 server-cert.pem:
.br
trusted-cert = certificatedigest4daa8c5fe6c...
.br
trusted-cert = othercertificatedigest6631bf...
.br
# This would specify a ca bundle instead of system-wide store
.br
# ca-file = @SYSCONFDIR@/openfortivpn/ca-bundle.pem
.br
set-dns = 1
.br
set-routes = 1
.br
half-internet-routes = 0
.br
pppd-use-peerdns = 1
.br
# aternatively, use a specific pppd plugin instead
.br
# pppd-plugin = /usr/lib/pppd/default/some-plugin.so
.br
# for debugging pppd write logs here
.br
# pppd-log = /var/log/pppd.log
.br
# pass an ipparam string to pppd
.br
# pppd-ipparam = somestringtopasstopppd
.br
insecure-ssl = 0
.br
cipher-list = HIGH:!aNULL:!kRSA:!PSK:!SRP:!MD5:!RC4
openfortivpn-1.6.0/etc/ 0000775 0000000 0000000 00000000000 13203022126 0015011 5 ustar 00root root 0000000 0000000 openfortivpn-1.6.0/etc/openfortivpn/ 0000775 0000000 0000000 00000000000 13203022126 0017542 5 ustar 00root root 0000000 0000000 openfortivpn-1.6.0/etc/openfortivpn/config.template 0000664 0000000 0000000 00000000134 13203022126 0022542 0 ustar 00root root 0000000 0000000 # config file for openfortivpn, see man openfortivpn(1)
host =
port =
username =
password =
openfortivpn-1.6.0/src/ 0000775 0000000 0000000 00000000000 13203022126 0015025 5 ustar 00root root 0000000 0000000 openfortivpn-1.6.0/src/config.c 0000664 0000000 0000000 00000015715 13203022126 0016447 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2015 Adrien Vergé
*
* 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 .
*/
#include "config.h"
#include "log.h"
#include
#include
#include
#include
#include
/*
* Adds a sha256 digest to the list of trusted certificates.
*/
int add_trusted_cert(struct vpn_config *cfg, const char *digest)
{
struct x509_digest *last, *new;
new = malloc(sizeof(struct x509_digest));
if (new == NULL)
return ERR_CFG_NO_MEM;
new->next = NULL;
strncpy(new->data, digest, SHA256STRLEN - 1);
new->data[SHA256STRLEN - 1] = '\0';
if (cfg->cert_whitelist == NULL) {
cfg->cert_whitelist = new;
} else {
for (last = cfg->cert_whitelist; last->next != NULL;
last = last->next)
;
last->next = new;
}
return 0;
}
/*
* Converts string to bool int
*
* @params[in] str the string to read from
* @return 0 or 1 if successful, < 0 if unrecognized value
*/
int strtob(const char *str)
{
if (str[0] == '\0')
return 0;
else if (strcasecmp(str, "true") == 0)
return 1;
else if (strcasecmp(str, "false") == 0)
return 0;
else if (isdigit(str[0]) == 0)
return -1;
long int i = strtol(str, NULL, 0);
if (i < 0 || i > 1)
return -1;
return i;
}
/*
* Reads filename contents and fill cfg with its values.
*
* @param[out] cfg the struct vpn_config to store configuration values
* @param[in] filename the file to read values from
* @return 0 if successful, or < 0 in case of error
*/
int load_config(struct vpn_config *cfg, const char *filename)
{
int ret = ERR_CFG_UNKNOWN;
FILE *file;
struct stat stat;
char *buffer, *line;
file = fopen(filename, "r");
if (file == NULL)
return ERR_CFG_SEE_ERRNO;
if (fstat(fileno(file), &stat) == -1) {
ret = ERR_CFG_SEE_ERRNO;
goto err_close;
}
if (stat.st_size == 0) {
ret = ERR_CFG_EMPTY_FILE;
goto err_close;
}
buffer = malloc(stat.st_size + 1);
if (buffer == NULL) {
ret = ERR_CFG_NO_MEM;
goto err_close;
}
// Copy all file contents at once
if (fread(buffer, stat.st_size, 1, file) != 1) {
ret = ERR_CFG_CANNOT_READ;
goto err_free;
}
buffer[stat.st_size] = '\0';
// Read line by line
for (line = strtok(buffer, "\n"); line != NULL;
line = strtok(NULL, "\n")) {
char *key, *equals, *val;
int i;
if (line[0] == '#')
continue;
// Expect something like: "key = value"
equals = strchr(line, '=');
if (equals == NULL) {
log_warn("Bad line in config file: \"%s\".\n", line);
continue;
}
equals[0] = '\0';
key = line;
val = equals + 1;
// Remove heading spaces
while (key[0] != '\0' && (key[0] == ' ' || key[0] == '\t'))
key++;
while (val[0] != '\0' && (val[0] == ' ' || val[0] == '\t'))
val++;
// Remove trailing spaces
for (i = strlen(key) - 1; i > 0; i--) {
if (key[i] == ' ' || key[i] == '\t')
key[i] = '\0';
else
break;
}
for (i = strlen(val) - 1; i > 0; i--) {
if (val[i] == ' ' || val[i] == '\t')
val[i] = '\0';
else
break;
}
if (strcmp(key, "host") == 0) {
strncpy(cfg->gateway_host, val, FIELD_SIZE);
cfg->gateway_host[FIELD_SIZE] = '\0';
} else if (strcmp(key, "port") == 0) {
long int port = strtol(val, NULL, 0);
if (port <= 0 || port > 65535) {
log_warn("Bad port in config file: \"%d\".\n",
port);
continue;
}
cfg->gateway_port = port;
} else if (strcmp(key, "username") == 0) {
strncpy(cfg->username, val, FIELD_SIZE - 1);
cfg->username[FIELD_SIZE] = '\0';
} else if (strcmp(key, "password") == 0) {
strncpy(cfg->password, val, FIELD_SIZE - 1);
cfg->password[FIELD_SIZE] = '\0';
} else if (strcmp(key, "otp") == 0) {
strncpy(cfg->otp, val, FIELD_SIZE - 1);
cfg->otp[FIELD_SIZE] = '\0';
} else if (strcmp(key, "realm") == 0) {
strncpy(cfg->realm, val, FIELD_SIZE - 1);
cfg->realm[FIELD_SIZE] = '\0';
} else if (strcmp(key, "set-dns") == 0) {
int set_dns = strtob(val);
if (set_dns < 0) {
log_warn("Bad set-dns in config file: \"%s\".\n",
val);
continue;
}
cfg->set_dns = set_dns;
} else if (strcmp(key, "set-routes") == 0) {
int set_routes = strtob(val);
if (set_routes < 0) {
log_warn("Bad set-routes in config file: \"%s\".\n",
val);
continue;
}
cfg->set_routes = set_routes;
} else if (strcmp(key, "half-internet-routes") == 0) {
int half_internet_routes = strtob(val);
if (half_internet_routes < 0) {
log_warn("Bad half-internet-routes in config" \
" file: \"%s\".\n", val);
continue;
}
cfg->half_internet_routes = half_internet_routes;
} else if (strcmp(key, "pppd-use-peerdns") == 0) {
int pppd_use_peerdns = strtob(val);
if (pppd_use_peerdns < 0) {
log_warn("Bad pppd-use-peerdns in config file:"
" \"%s\".\n", val);
continue;
}
cfg->pppd_use_peerdns = pppd_use_peerdns;
} else if (strcmp(key, "pppd-log") == 0) {
cfg->pppd_log = strdup(val);
} else if (strcmp(key, "pppd-plugin") == 0) {
cfg->pppd_plugin = strdup(val);
} else if (strcmp(key, "pppd-ipparam") == 0) {
cfg->pppd_ipparam = strdup(val);
} else if (strcmp(key, "pppd-ifname") == 0) {
cfg->pppd_ifname = strdup(val);
} else if (strcmp(key, "use-syslog") == 0) {
int use_syslog = strtob(val);
if (use_syslog < 0) {
log_warn("Bad use-syslog in config file: \"%s\".\n",
val);
continue;
}
cfg->use_syslog = use_syslog;
} else if (strcmp(key, "trusted-cert") == 0) {
if (strlen(val) != SHA256STRLEN - 1) {
log_warn("Bad certificate sha256 digest in "
"config file: \"%s\".\n", val);
continue;
}
if (add_trusted_cert(cfg, val))
log_warn("Could not add certificate digest to "
"whitelist.\n");
} else if (strcmp(key, "ca-file") == 0) {
cfg->ca_file = strdup(val);
} else if (strcmp(key, "user-cert") == 0) {
cfg->user_cert = strdup(val);
} else if (strcmp(key, "user-key") == 0) {
cfg->user_key = strdup(val);
} else if (strcmp(key, "insecure-ssl") == 0) {
int insecure_ssl = strtob(val);
if (insecure_ssl < 0) {
log_warn("Bad insecure-ssl in config file: \"%s\".\n",
val);
continue;
}
cfg->insecure_ssl = insecure_ssl;
} else if (strcmp(key, "cipher-list") == 0) {
cfg->cipher_list = strdup(val);
} else {
log_warn("Bad key in config file: \"%s\".\n", key);
goto err_free;
}
}
ret = 0;
err_free:
free(buffer);
err_close:
fclose(file);
return ret;
}
openfortivpn-1.6.0/src/config.h 0000664 0000000 0000000 00000004446 13203022126 0016453 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2015 Adrien Vergé
*
* 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 .
*/
#ifndef _OPENFORTIVPN_CONFIG_H
#define _OPENFORTIVPN_CONFIG_H
#include
#include
#include
#include
#define ERR_CFG_UNKNOWN -1
#define ERR_CFG_SEE_ERRNO -2
#define ERR_CFG_EMPTY_FILE -3
#define ERR_CFG_NO_MEM -4
#define ERR_CFG_CANNOT_READ -5
static inline const char *err_cfg_str(int code)
{
if (code == ERR_CFG_SEE_ERRNO)
return strerror(errno);
else if (code == ERR_CFG_EMPTY_FILE)
return "Empty file";
else if (code == ERR_CFG_NO_MEM)
return "Not enough memory";
else if (code == ERR_CFG_CANNOT_READ)
return "Cannot read file";
return "unknown";
}
#define SHA256LEN (256 / 8)
#define SHA256STRLEN (2 * SHA256LEN + 1)
struct x509_digest {
struct x509_digest *next;
char data[SHA256STRLEN];
};
#define FIELD_SIZE 64
#define COOKIE_SIZE 4096
struct vpn_config {
char gateway_host[FIELD_SIZE + 1];
struct in_addr gateway_ip;
uint16_t gateway_port;
char username[FIELD_SIZE + 1];
char password[FIELD_SIZE + 1];
char otp[FIELD_SIZE + 1];
char cookie[COOKIE_SIZE + 1];
char realm[FIELD_SIZE + 1];
int set_routes;
int set_dns;
int pppd_use_peerdns;
int use_syslog;
int half_internet_routes;
char *pppd_log;
char *pppd_plugin;
char *pppd_ipparam;
char *pppd_ifname;
char *ca_file;
char *user_cert;
char *user_key;
int verify_cert;
int insecure_ssl;
char *cipher_list;
struct x509_digest *cert_whitelist;
};
int add_trusted_cert(struct vpn_config *cfg, const char *digest);
int strtob(const char *str);
int load_config(struct vpn_config *cfg, const char *filename);
#endif
openfortivpn-1.6.0/src/hdlc.c 0000664 0000000 0000000 00000017227 13203022126 0016114 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2015 Adrien Vergé
*
* 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 .
*/
#include "hdlc.h"
#define in_sending_accm(byte) \
((byte) < 0x20 || ((byte) & 0x7f) == 0x7d || ((byte) & 0x7f) == 0x7e)
#define in_receiving_accm(byte) \
((byte) < 0x20)
static uint16_t fcs_tab[] = {
0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
};
/*
* 16-bit frame check sequence from RFC1662.
*/
static uint16_t frame_checksum_16bit(uint16_t sum, uint8_t *seq, size_t length)
{
size_t i;
for (i = 0; i < length; i++)
sum = (sum >> 8) ^ fcs_tab[0xff & (sum ^ seq[i])];
return sum;
}
static int need_flag_sequence = 1;
/*
* Wraps a PPP packet into a HDLC frame and write it to a buffer.
*
* @param[out] frame the buffer to store the encoded frame
* @param[in] frmsize the output buffer size
* @param[in] packet the buffer containing the packet
* @param[in] pktsize the input packet size
* @return the number of bytes written to the buffer (i.e. the
* HDLC-encoded frame length) or ERR_HDLC_BUFFER_TOO_SMALL
* if the output buffer is too small
*/
ssize_t hdlc_encode(uint8_t *frame, size_t frmsize,
uint8_t *packet, size_t pktsize)
{
ssize_t written = 0;
uint16_t checksum;
uint8_t address_control_prefix[] = { 0xff, 0x03 };
int i;
uint8_t byte;
if (frmsize < 7)
return ERR_HDLC_BUFFER_TOO_SMALL;
if (need_flag_sequence)
frame[written++] = 0x7e; // FlagSequence
// Escape and write AddressControlPrefix (0xff 0x03)
frame[written++] = 0xff;
frame[written++] = 0x7d;
frame[written++] = 0x23;
checksum = frame_checksum_16bit(0xffff, address_control_prefix, 2);
checksum = frame_checksum_16bit(checksum, packet, pktsize);
for (i = 0; i < pktsize; i++) {
byte = packet[i];
if (frmsize < written + 2)
return ERR_HDLC_BUFFER_TOO_SMALL;
if (in_sending_accm(byte)) {
frame[written++] = 0x7d;
frame[written++] = byte ^ 0x20;
} else {
frame[written++] = byte;
}
}
if (frmsize < written + 3)
return ERR_HDLC_BUFFER_TOO_SMALL;
// Escape and write checksum
byte = (checksum ^ 0xffff) & 0xff;
if (in_sending_accm(byte)) {
frame[written++] = 0x7d;
frame[written++] = byte ^ 0x20;
} else {
frame[written++] = byte;
}
byte = (checksum ^ 0xffff) >> 8;
if (in_sending_accm(byte)) {
frame[written++] = 0x7d;
frame[written++] = byte ^ 0x20;
} else {
frame[written++] = byte;
}
frame[written++] = 0x7e; // FlagSequence
need_flag_sequence = 0;
return written;
}
/*
* Finds the first frame in a buffer, starting search at start.
*
* Return ERR_HDLC_NO_FRAME_FOUND if no frame is found. Otherwise, returns the
* first frame length and sets start to its beginning offset in the buffer.
*/
ssize_t hdlc_find_frame(uint8_t *buffer, size_t bufsize, off_t *start)
{
int i, s = -1, e = -1;
// Look for frame start
for (i = *start; i < bufsize - 2; i++) {
if (buffer[i] == 0x7e) { // FlagSequence
s = i + 1;
break;
}
}
if (s == -1)
return ERR_HDLC_NO_FRAME_FOUND;
// Discard empty packets
while (s < bufsize - 2 && buffer[s] == 0x7e)
s++;
// Look for frame end
for (i = s; i < bufsize; i++) {
if (buffer[i] == 0x7e) { // FlagSequence
e = i;
break;
}
}
if (e == -1)
return ERR_HDLC_NO_FRAME_FOUND;
*start = s;
return e - s;
}
/*
* Extracts the first PPP packet found in the input buffer.
*
* The frame should be passed without its surrounding 0x7e bytes.
*
* @param[in] frame the buffer containing the encoded frame
* @param[in] frmsize the input buffer size
* @param[out] packet the buffer to store the decoded packet
* @param[in] pktsize the output packet buffer size
* @return the number of bytes written to the output packet
* buffer, or < 0 in case of error
*/
ssize_t hdlc_decode(uint8_t *frame, size_t frmsize,
uint8_t *packet, size_t pktsize)
{
off_t start = 0;
ssize_t written = 0;
int has_address_control_prefix = 0;
int i;
int in_escape;
uint16_t checksum;
if (frmsize < 5)
return ERR_HDLC_INVALID_FRAME;
// Remove AddressControlPrefix (0xff 0x03, escaped)
if (frame[0] == 0xff && frame[1] == 0x7d && frame[2] == 0x23) {
start += 3;
has_address_control_prefix = 1;
}
in_escape = 0;
for (i = start; i < frmsize; i++) {
uint8_t byte = frame[i];
if (byte == 0x7d) { // ControlEscape
if (in_escape)
return ERR_HDLC_INVALID_FRAME;
in_escape = 1;
continue;
} else if (in_escape) {
byte ^= 0x20; // ControlModifier
in_escape = 0;
} else if (in_receiving_accm(byte)) {
continue; // Drop characters possibly introduced by DCE
}
if (written >= pktsize)
return ERR_HDLC_BUFFER_TOO_SMALL;
packet[written++] = byte;
}
if (in_escape)
return ERR_HDLC_INVALID_FRAME;
if (written < 3)
return ERR_HDLC_INVALID_FRAME;
// Control checksum validity and remove it from packet
if (has_address_control_prefix)
checksum = 0x3de3; // Precomputed checksum for { 0xff, 0x03 }
else
checksum = 0xffff;
checksum = frame_checksum_16bit(checksum, packet, written);
if (checksum != 0xf0b8)
return ERR_HDLC_BAD_CHECKSUM;
written -= 2;
return written;
}
openfortivpn-1.6.0/src/hdlc.h 0000664 0000000 0000000 00000003060 13203022126 0016107 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2015 Adrien Vergé
*
* 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 .
*/
#ifndef _OPENFORTIVPN_HDLC_H
#define _OPENFORTIVPN_HDLC_H
#include
#include
#include
#include
#define ERR_HDLC_BUFFER_TOO_SMALL -1
#define ERR_HDLC_NO_FRAME_FOUND -2
#define ERR_HDLC_INVALID_FRAME -3
#define ERR_HDLC_BAD_CHECKSUM -4
/*
* These macros are used to help decide how much to malloc before encoding or
* decoding. They over-evaluate the output size so it is sure the output will
* fit.
*/
#define estimated_encoded_size(ppp_pkt_len) (9 + 2 * (ppp_pkt_len))
#define estimated_decoded_size(hdlc_frm_len) (hdlc_frm_len)
ssize_t hdlc_encode(uint8_t *frame, size_t frmsize,
uint8_t *packet, size_t pktsize);
ssize_t hdlc_find_frame(uint8_t *buffer, size_t bufsize, off_t *start);
ssize_t hdlc_decode(uint8_t *frame, size_t frmsize,
uint8_t *packet, size_t pktsize);
#endif
openfortivpn-1.6.0/src/http.c 0000664 0000000 0000000 00000041123 13203022126 0016151 0 ustar 00root root 0000000 0000000 /*
* Copyright (C) 2015 Adrien Vergé
*
* 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 .
*/
#include "http.h"
#include "xml.h"
#include "ssl.h"
#include "ipv4.h"
#include "userinput.h"
#include "log.h"
#include
#include
#define BUFSZ 0x8000
/*
* URL-encodes a string for HTTP requests.
*
* The dest buffer size MUST be at least strlen(str) * 3 + 1.
*
* @param[out] dest the buffer to write the URL-encoded string
* @param[in] str the input string to be escaped
*/
static void url_encode(char *dest, const char *str)
{
while (*str != '\0') {
if (isalnum(*str) || *str == '-' || *str == '_'
|| *str == '.' || *str == '~')
*dest++ = *str;
else if (*str == ' ')
*dest++ = '+';
else {
static const char hex[] = "0123456789abcdef";
*dest++ = '%';
*dest++ = hex[*str >> 4];
*dest++ = hex[*str & 15];
}
str++;
}
*dest = '\0';
}
/*
* Sends data to the HTTP server.
*
* @param[in] request the data to send to the server
* @return 1 in case of success
* < 0 in case of error
*/
int http_send(struct tunnel *tunnel, const char *request, ...)
{
va_list args;
char buffer[BUFSZ];
int length;
int n = 0;
va_start(args, request);
length = vsnprintf(buffer, BUFSZ, request, args);
va_end(args);
if (length < 0)
return ERR_HTTP_INVALID;
else if (length == BUFSZ)
return ERR_HTTP_TOO_LONG;
while (n == 0)
n = safe_ssl_write(tunnel->ssl_handle, (uint8_t *) buffer,
length);
if (n < 0) {
log_debug("Error writing to SSL connection (%s).\n",
err_ssl_str(n));
return ERR_HTTP_SSL;
}
return 1;
}
static const char *find_header(const char *res, const char *header)
{
const char *line = res;
while (memcmp(line, "\r\n", 2)) {
int line_len = (char *) memmem(line, BUFSZ, "\r\n", 2) - line;
int head_len = strlen(header);
if (line_len > head_len && !strncasecmp(line, header, head_len))
return line + head_len;
line += line_len + 2;
}
return NULL;
}
/*
* Receives data from the HTTP server.
*
* @param[out] response if not NULL, this pointer is set to reference
* the new allocated buffer containing the data
* sent by the server
* @return 1 in case of success
* < 0 in case of error
*/
int http_receive(struct tunnel *tunnel, char **response)
{
char *buffer, *res;
int n = 0;
int bytes_read = 0;
int header_size = 0;
int content_size = 0;
int chunked = 0;
buffer = malloc(BUFSZ);
if (buffer == NULL)
return ERR_HTTP_NO_MEM;
do {
n = safe_ssl_read(tunnel->ssl_handle,
(uint8_t *) buffer + bytes_read,
BUFSZ - 1 - bytes_read);
if (n > 0) {
const char *eoh;
bytes_read += n;
if (!header_size) {
/* Did we see the header end? Then get the body size. */
eoh = memmem(buffer, bytes_read, "\r\n\r\n", 4);
if (eoh) {
const char *header;
header = find_header(buffer, "Content-Length: ");
header_size = eoh - buffer + 4;
if (header)
content_size = atoi(header);
if (find_header(buffer,
"Transfer-Encoding: chunked"))
chunked = 1;
}
}
if (header_size) {
/* We saw the whole header, let's check if the
* body is done as well */
if (chunked) {
/* Last chunk terminator. Done naively. */
if (bytes_read >= 7 &&
!memcmp(&buffer[bytes_read - 7],
"\r\n0\r\n\r\n", 7))
break;
} else {
if (bytes_read >= header_size + content_size)
break;
}
}
if (bytes_read == BUFSZ - 1) {
log_warn("Response too big\n");
free(buffer);
return ERR_HTTP_SSL;
}
}
} while (n >= 0);
if (!header_size) {
log_debug("Error reading from SSL connection (%s).\n",
err_ssl_str(n));
free(buffer);
return ERR_HTTP_SSL;
}
if (memmem(&buffer[header_size], bytes_read - header_size,
"", 53) ||
memmem(buffer, header_size, "permission_denied denied", 24) ||
memmem(buffer, header_size, "Permission denied", 17)) {
free(buffer);
return ERR_HTTP_PERMISSION;
}
if (response == NULL) {
free(buffer);
return 1;
}
res = realloc(buffer, bytes_read + 1);
if (res == NULL) {
free(buffer);
return ERR_HTTP_NO_MEM;
}
res[bytes_read] = '\0';
*response = res;
return 1;
}
static int do_http_request(struct tunnel *tunnel, const char *method,
const char *uri, const char *data, char **response)
{
int ret;
char *template = ("%s %s HTTP/1.1\r\n"
"Host: %s:%d\r\n"
"User-Agent: Mozilla/5.0 SV1\r\n"
"Accept: text/plain\r\n"
"Accept-Encoding: identify\r\n"
"Content-Type: application/x-www-form-urlencoded\r\n"
"Cookie: %s\r\n"
"Content-Length: %d\r\n"
"\r\n%s");
ret = http_send(tunnel, template, method, uri,
tunnel->config->gateway_host,
tunnel->config->gateway_port, tunnel->config->cookie,
strlen(data), data);
if (ret != 1)
return ret;
return http_receive(tunnel, response);
}
/*
* Sends and receives data from the HTTP server.
*
* @param[out] response if not NULL, this pointer is set to reference
* the new allocated buffer containing the data
* sent by the server
* @return 1 in case of success
* < 0 in case of error
*/
static int http_request(struct tunnel *tunnel, const char *method,
const char *uri, const char *data, char **response)
{
int ret = do_http_request(tunnel, method, uri, data, response);
if (ret == ERR_HTTP_SSL) {
ssl_connect(tunnel);
ret = do_http_request(tunnel, method, uri, data, response);
}
if (ret != 1)
log_warn("Error issuing %s request\n", uri);
return ret;
}
/*
* Read value for key from a string like "key1=value1&key2=value2".
* The `key` arg is supposed to contains the final "=".
*
* @return 1 in case of success
* -1 key not found
* -2 value too large for buffer
* -3 if no memory
*/
static int get_value_from_response(const char *buf, const char *key,
char *retbuf, size_t retbuflen)
{
int ret;
char *tokens, *kv_pair;
size_t keylen = strlen(key);
tokens = strdup(buf);
if (tokens == NULL)
return -3;
ret = -1;
kv_pair = strtok(tokens, "&,\r\n");
for (; kv_pair != NULL; kv_pair = strtok(NULL, "&,\r\n")) {
if (strncmp(key, kv_pair, keylen) == 0) {
char *val = &kv_pair[keylen];
if (strlen(val) > retbuflen - 1) { // value too long
ret = -2;
} else {
strcpy(retbuf, val);
ret = 1;
}
break;
}
}
free(tokens);
return ret;
}
static int get_auth_cookie(struct tunnel *tunnel, char *buf)
{
int ret = 0;
const char *line;
ret = ERR_HTTP_NO_COOKIE;
line = find_header(buf, "Set-Cookie: ");
if (line) {
if (strncmp(line, "SVPNCOOKIE=", 11) == 0) {
if (line[11] == ';' || line[11] == '\0') {
log_debug("Empty cookie.\n");
} else {
char *end;
end = strstr(line, "\r");
end[0] = '\0';
end = strstr(line, ";");
if (end != NULL)
end[0] = '\0';
log_debug("Cookie: %s\n", line);
strncpy(tunnel->config->cookie, line, COOKIE_SIZE);
tunnel->config->cookie[COOKIE_SIZE] = '\0';
if (strlen(line) > COOKIE_SIZE) {
log_error("Cookie larger than expected:"
" %zu > %d\n",
strlen(line), COOKIE_SIZE);
} else {
ret = 1; // success
}
}
}
}
return ret;
}
static
int try_otp_auth(struct tunnel *tunnel, const char *buffer, char **res)
{
char data[256];
char path[40];
char tmp[40];
char prompt[80];
const char *t = NULL, *n = NULL, *v = NULL, *e = NULL;
const char *s = buffer;
char *d = data;
const char *p = NULL;
/* Length-check for destination buffer */
#define SPACE_AVAILABLE(sz) (sizeof(data) - (d - data) >= (sz))
/* Get the form action */
s = strcasestr(s, "