Commit Graph

297 Commits

Author SHA1 Message Date
Brent Cook
e83c30c158 monkey patch more POSIX-like behavior out of winsock 2
Windows sockets functions look on the outside like they behave similarly
to POSIX functions, but there are many subtle and glaring differences,
including errors reported via WSAGetLastError, read, write, and close do
not work on sockets, setsockopt takes a (char *) rather than (void *),
etc.

This header implements wrappers that coerce more POSIX-like behavior
from these functions, making portable code easier to develop.

BENEFITS:
One does not necessarily need to sprinkle #ifdefs around code to handle
the Windows and non-Windows behavior when porting code.

CAVEATS:
There may be performance implications with the 'mother-may-I'
approach to determining if a descriptor is a socket or a file.

The errno mappings are not 100% what one might expect compared to POSIX
since there were not always good 1:1 equivalents from the WSA errors.
2014-12-03 17:07:17 -06:00
Brent Cook
cccdd689e3 add minimal winsock->BSD networking header shims
also add license header to existing shims
2014-12-03 17:07:17 -06:00
Brent Cook
1bbde19a7c add minimal poll(2) implementation for Windows
This provides sufficient functionality to run openssl(1) from a Windows
console. This is based on the original select-based version from from
songdongsheng@live.cn. Changes:

 * use nfds_t directly for iterating the fds.
 * add WSAGetLastError -> errno mappings
 * handle POLLHUP and the OOB data cases for revents
 * handle sparse arrays of fds correctly
 * KNF style updates
 * teach poll how to handle file handles as well as sockets

This handles the socket/non-socket issue  by alternating a loop between
WaitForMultipleObjects for non-sockets and and select for sockets. One
would think this would be terrible for performance, but as of this
writing, poll consumes about 6% of the time doing a bulk transfer
between a Linux box and 'openssl.exe s_server'.

I tried to implement this all in terms of WaitForMultipleObjects with a
select 'poll' at the end to get extra specific socket status. However,
the cost of setting up an event handle for each socket, setting the
WSAEventSelect attributes, and cleaning them up reliably was pretty
high. Since the event handle associated with a socket is also global,
creating a new one cancels the previous one or can be disabled
externally.

In addition, the 'FD_WRITE' status of a socket event handle does not
behave in an expected fashion, being triggered by an edge on a write
event rather than being level triggered.

Another fun horror story is how stdin in windows might be a console, it
might be a pipe, it might be something else. If these all worked in the
same way, it would be great. But, since a console-stdin can also signal
on a mouse or window event, it means we can easily get stuck in a
blocking read (you can't make stdin non-blocking) if the non-character
events are not filtered out. So, poll does that too.

See here for various additional horror stories:

http://www.postgresql.org/message-id/4351.1336927207@sss.pgh.pa.us
2014-12-03 17:03:47 -06:00
Brent Cook
96bf8be098 update and mask unit tests when running on win32
Update pq_test to ignore changes in whitespace.
Update for new testssl params, specify absolute paths to test binaries.
Fork-based tests do not make sense on Windows.
Disable building biotest, since it is too specific to OpenBSD's behavior
to be useful on other platforms.
2014-12-03 17:02:29 -06:00
Brent Cook
58fcd3c39c Add conditional compilation for windows and posix functions.
This adds a Windows-specific versions of several symbols from libcrypto
and openssl(1).
2014-12-03 17:02:29 -06:00
Brent Cook
7f0646f612 Update win32 build defines 2014-12-03 17:02:29 -06:00
Brent Cook
43e041a533 don't ignore a non-existent file 2014-12-03 17:02:23 -06:00
Brent Cook
2103690cbf improve readability of generated Makefile.am files 2014-11-23 08:33:56 -06:00
Brent Cook
1bd0c2fb2e ignore gost and camellia dirs 2014-11-18 08:04:18 -06:00
Brent Cook
29f8d827f2 Enable GOST in libcrypto and libssl, contributed by Dmitry Eremin-Solenikov
Ensure the public camellia.h header is installed along with gost.h
2014-11-18 08:02:32 -06:00
宋冬生
648e913627 Use _WIN32 instead of __WIN32.
ok bcook@
2014-11-18 07:41:08 -06:00
Brent Cook
f223e6f14d Add the Cammelia cipher to libcrypto.
from miod@:

There used to be a strong reluctance to provide this cipher in LibreSSL in the
past, because the licence terms under which Cammelia was released by NTT were
free-but-not-in-the-corners, by restricting the right to modify the source
code, as well retaining the right to enforce their patents against anyone
in the future.

However, as stated in http://www.ntt.co.jp/news/news06e/0604/060413a.html ,
NTT changed its mind and made this code truly free. We only wish there had
been more visibility of this, for we could have had enabled Cammelia
earlier (-:

Licence change noticed by deraadt@. General agreement from the usual LibreSSL
suspects.

Crank libcrypto.so minor version due to the added symbols.
2014-11-17 17:48:46 -06:00
Brent Cook
d84aa5cbc1 Quiet clang warnings about unused arguments in general.
Check if we are using clang, rather than simply if we are on OS X.
Note: recent LLVM releases do not seem to need this anyway.
2014-11-03 21:06:40 -06:00
Brent Cook
94ec2b6b1c make 'autoreconf' work from dist tarball
We need to include VERSION for it to run.
2014-11-03 21:05:47 -06:00
Brent Cook
0aeb93b9fc override native arc4random_buf on FreeBSD
The FreeBSD-native arc4random_buf implementation falls back to weak
sources of entropy if the sysctl fails. Remove these dangerous fallbacks
by overriding locally.

Unfortunately, pthread_atfork() is broken on FreeBSD (at least 9 and 10)
if a program does not link to -lthr. Callbacks registered with
pthread_atfork() simply fail silently. So, it is not always possible to
detect a PID wraparound. I wish we could do better.

This improves arc4random_buf's safety compared to the native FreeBSD
implementation. Tested on FreeBSD 9 and 10.

ok beck@ deraadt@
2014-11-03 01:19:36 -06:00
Brent Cook
8abf8e1e15 override native arc4random_buf on OS X
While the native OS X implementation is fork-safe, it does not seed
safely, as of the latest released OS X libc sources, version 997.90.3.
It only uses weak sources of entropy if accessing /dev/urandom fails.

ok beck@ deraadt@
2014-11-03 01:19:36 -06:00
Brent Cook
e864776f0b update README to reflect current porting approach
ok beck@ deraadt@
2014-11-03 01:18:32 -06:00
Brent Cook
1c5591947a Add an OpenSSL compatible ./config wrapper
This allows sofware expecting OpenSSL's config script, to a limited
extent, to continue building without changes.

Thanks to technion for pointing this out and providing the initial
patch.
2014-10-31 07:35:06 -05:00
Brent Cook
a2373f7007 wrap arc4random header
ok @doug
2014-10-30 19:15:20 -05:00
Brent Cook
a4cc953911 Improve and simplify function and header detection logic.
Simplify autoconf checks by using AC_CHECK_FUNCS/HEADERS.
Clarify some ambiguous dependencies around strnlen/strndup.
Unconditionally enable pidwraptest for all arc4random implementations.
Remove HAVE_VASPRINTF conditional, since asprintf requires vasprintf.

ok @doug
2014-10-30 19:15:11 -05:00
Brent Cook
727bccd093 use the correct HOST_OS for the Windows build
ok doug@
2014-10-30 10:55:30 -05:00
Brent Cook
72c1e56b38 enable -lcrypto -lssl with all test programs directly.
This removes the need to specify each one individually.

ok doug@
2014-10-30 10:55:30 -05:00
Brent Cook
ccaf9cdd9c remove duplicate (and overlapping) .1 manpages
openssl.1 contains all of the information from the other application
manpages, and is the only one packaged in OpenBSD. So, remove the other
obsolete .1 manpages (and avoid overlapping system pages like passwd.1)
2014-10-26 09:23:03 -05:00
Brent Cook
8b695e534b set various glibc flags that also are useful with mingw
for example, asprintf/vasprintf are unmasked with _GNU_SOURCE in mingw
2014-10-22 19:12:18 -05:00
Brent Cook
eb26e56ba8 undef LIBRESSL_INTERNAL for the pidwrap test. 2014-10-22 13:06:36 -05:00
kinichiro
a91d1013cf update string.h for include strings.h for HPUX environment 2014-10-22 12:45:01 -05:00
Brent Cook
54259e50a5 include a proper check for memmem when configuring unit tests
This allows the proper compatibility header definition to be exposed.
2014-10-22 12:37:06 -05:00
Brent Cook
48520cf629 bump version 2014-10-22 11:16:39 -05:00
Brent Cook
04bb7a665d update with 2.1.1 changes
ok beck@
2014-10-15 22:28:34 -05:00
Brent Cook
a007fb9d53 LibreSSL portable README update
Add more info on how to build from source, where to download it from.
2014-10-15 16:36:08 -05:00
Brent Cook
2408253191 add extended ChangeLog file
help people more easily find the code and changes
2014-10-14 22:25:16 -05:00
Brent Cook
6b729df5d8 update gitignore to see changelog 2014-10-14 22:23:16 -05:00
Brent Cook
9c8cf59362 add missing commas from man links 2014-10-14 21:54:37 -05:00
Brent Cook
67ec615a35 update man links 2014-10-14 20:55:04 -05:00
Brent Cook
3d3c24670a don't fail to make dist on a clean repo 2014-10-14 20:54:42 -05:00
Brent Cook
cf1c1f350c crank version 2014-10-14 20:44:55 -05:00
Brent Cook
0534fffefa update to new converted SSL manpages 2014-10-14 20:43:30 -05:00
Brent Cook
5c23f25103 clear local manpage cache before generating a release tarball
Remove the possibility of having any bad or old manpages in releases
while still being able to cache for quick development tarballs.
2014-09-26 16:12:53 -05:00
Brent Cook
3f944e83ff update for upstream move of the openssl app 2014-08-27 21:46:43 -05:00
Brent Cook
e7edc4a76f ensure compatibility with posix shell
remove bash comparison, thanks kinichiro
2014-08-18 21:55:37 -05:00
Brent Cook
01726893f5 add --disable-asm flag for disabling inline asm
Surprisingly (or not), a lot of OpenSSL's inline assembly actually makes
things slower with a relatively modern compiler (read, gcc >= 4.x).
2014-08-17 07:58:32 -05:00
Brent Cook
2cef68f3ed allow inline asm
use default of -std=gnu99 for it to be recognized
2014-08-16 14:16:01 -05:00
Brent Cook
2d719eb3d7 set _DEFAULT_SOURCE on linux hosts
this is the replacement for _BSD_SOURCE on newer glibc's
2014-08-16 08:17:32 -05:00
inoguchi
6dccbae663 update stdio.h for including stdarg.h
it seems that including stdarg.h is needed for defining va_list
environment is hpux 11.31(ia64) with gcc 4.7.1.

without stdarg.h, I got compilation error like this.
  "error: 'va_list' undeclared (first use in this function)"

I checked with gcc -E, then I noticed that __va_list is defined but va_list is not.
  "typedef __gnuc_va_list __va_list;"

with including stdarg.h, va_list is defined.
  "typedef __gnuc_va_list va_list;"
2014-08-12 21:18:27 -05:00
Brent Cook
46b6df7cb0 remove configure.am.tpl, pull in VERSION directly
from wouter@
2014-08-12 21:17:41 -05:00
Brent Cook
d6a485d1a1 rebase on pull when updating the openbsd branch
this avoids inadvertent local merges
2014-08-08 07:32:38 -05:00
Brent Cook
00b51d5c25 conditionally build strnlen if needed.
it is only used by strndup

prodded by Sortie@
2014-08-02 21:59:36 -05:00
Brent Cook
c95574be92 tie master libressl branch to openbsd master
Added OPENBSD_BRANCH to set what branch update.sh should checkout.
2014-07-31 22:08:30 -05:00
Bob Beck
3e21619bcf Crank version on HEAD to 2.1.0 2.0 cointinues on OPENBSD_5_6 branch 2014-07-31 18:53:48 -06:00
Brent Cook
105da446ba define MAP_ANON for systems with MAP_ANONYMOUS
switch the sense of this check
2014-07-30 22:16:01 -05:00