Skip to content

Commit

Permalink
Tweaks to increase compability with VBCC and SAS/C out of the box (ho…
Browse files Browse the repository at this point in the history
…pefully helps with #44)
  • Loading branch information
Futaura committed Feb 13, 2021
1 parent dd7c209 commit de54117
Show file tree
Hide file tree
Showing 13 changed files with 140 additions and 53 deletions.
9 changes: 8 additions & 1 deletion dist/AmiSSL.readme
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ Requirements:
------------
- AmigaOS 4.0+/PPC, AmigaOS 3.0+/68020+ or MorphOS

- Tweaked SDK examples and OpenSSL includes to be more compatible with
vanilla VBCC and SAS/C compiler installations
- Restored SAS/C support to AmiSSL autoopen link library code
- Added native VBCC support to AmiSSL autoopen link library code
- Added lib/autoinit_amissl_main.c to SDK to allow VBCC, SAS/C and GCC
users to compile their own link library, if required

Version 4.7 (17.12.2020):
------------------------
- Updated OpenSSL backend to full compatibility to latest
Expand Down Expand Up @@ -138,7 +145,7 @@ Version 4.1 (13.03.2017):
- Added some m68k asm replacement code for potentially speeding up BN
calculation routines.
- Added AmiUpdate compatibility.
- included a newlib compiled version of libamisslauto.a.
- Included a newlib compiled version of libamisslauto.a.
- Minor improvements/Fixes for install script.

Version 4.0 (07.02.2017):
Expand Down
11 changes: 7 additions & 4 deletions dist/README-SDK
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ The following tags are currently available for InitAmiSSL() call:
use an internal errno pointer and thus errno changes will not be propagated
to your program.

Linker libraries that automatically open and set up AmiSSL are also available
as part of the AmiSSL SDK.
Linker libraries, that automatically open and set up AmiSSL, are also available
for GCC (OS3 and OS4) as part of the AmiSSL SDK. You may also compile your
own linker library from lib/autoinit_amissl_main.c which can be compiled
with VBCC and SAS/C, in addition to GCC.

Note, that unlike in AmiSSL v1, AmiSSLBase can be shared between different
subprocesses. Furthermore, this is encouraged since it allows the cache of
Expand Down Expand Up @@ -208,8 +210,9 @@ name than to change many occurrences of f. ex. ASN1_OBJECT_free to f. ex.
ASN1_OBJECT_free_stub whenever ASN1_OBJECT_free is passed as a function
pointer.

For SAS/C you will have to take special care where 64-bit integers are
concerned - in particular, OPENSSL_init_ssl(), which you mignt not even be
For SAS/C you will need to add "MemorySize=h IdentifierLength=80" to your
SC command line and have to take special care where 64-bit integers are
concerned. In particular, OPENSSL_init_ssl(), which you mignt not even be
calling directly, but is ultimately the end result of many of the macros for
older legacy SSL initialisation functions. Remember that for 64-bit
parameters, the high 32-bits are placed in D0 and the low 32-bits in D1.
Expand Down
4 changes: 0 additions & 4 deletions include/amissl/amissl.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
#ifndef AMISSL_AMISSL_H
#define AMISSL_AMISSL_H

#ifdef __SASC
#define ssize_t int
#endif

#include <openssl/opensslconf.h>

#ifndef OPENSSL_NO_AES
Expand Down
46 changes: 46 additions & 0 deletions include/amissl/types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/***************************************************************************
AmiSSL - OpenSSL wrapper for AmigaOS-based systems
Copyright (C) 1999-2006 Andrija Antonijevic, Stefan Burstroem
Copyright (C) 2006-2021 AmiSSL Open Source Team
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
AmiSSL Official Support Site: https://github.com/jens-maus/amissl
***************************************************************************/

#ifndef AMISSL_TYPES_H
#define AMISSL_TYPES_H

#if defined(__SASC)

#if !defined(_MACHINE_TYPES_H_) // include:amitcp/machine/types.h
typedef signed char int8_t;
typedef short int16_t;
typedef int int32_t;
#endif

typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;

/* Cannot use 64-bit functions - used only to allow headers to be parsed */
typedef int int64_t;
typedef unsigned int uint64_t;

#else

#include <stdint.h>

#endif

#endif /* !AMISSL_TYPES_H */
1 change: 0 additions & 1 deletion include/openssl/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ extern "C" {
#endif

# include <stddef.h>
# include <sys/types.h>

/*
* These names are outdated as of OpenSSL 1.1; a future release
Expand Down
11 changes: 8 additions & 3 deletions include/openssl/e_os2.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,14 @@ extern "C" {
# define OSSL_SSIZE_MAX MAX_INTN
# endif

# if defined(OPENSSL_SYS_AMIGA)
# define ossl_ssize_t int
# define OSSL_SSIZE_MAX INT_MAX
# endif

# ifndef ossl_ssize_t
# define ossl_ssize_t ssize_t
# if defined(OPENSSL_SYS_AMIGA) && (defined(__MORPHOS__) || defined(__SASC))
# define OSSL_SSIZE_MAX INT_MAX
# elif defined(SSIZE_MAX)
# if defined(SSIZE_MAX)
# define OSSL_SSIZE_MAX SSIZE_MAX
# elif defined(_POSIX_SSIZE_MAX)
# define OSSL_SSIZE_MAX _POSIX_SSIZE_MAX
Expand Down Expand Up @@ -267,6 +270,8 @@ typedef int int32_t;
typedef unsigned int uint32_t;
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
# elif defined(OPENSSL_SYS_AMIGA)
# include <amissl/types.h>
# else
# include <stdint.h>
# endif
Expand Down
2 changes: 0 additions & 2 deletions include/openssl/seed.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ extern "C" {
# endif
# endif

# include <sys/types.h>

# define SEED_BLOCK_SIZE 16
# define SEED_KEY_LENGTH 16

Expand Down
1 change: 0 additions & 1 deletion openssl/include/openssl/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ extern "C" {
#endif

# include <stddef.h>
# include <sys/types.h>

/*
* These names are outdated as of OpenSSL 1.1; a future release
Expand Down
11 changes: 8 additions & 3 deletions openssl/include/openssl/e_os2.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,14 @@ extern "C" {
# define OSSL_SSIZE_MAX MAX_INTN
# endif

# if defined(OPENSSL_SYS_AMIGA)
# define ossl_ssize_t int
# define OSSL_SSIZE_MAX INT_MAX
# endif

# ifndef ossl_ssize_t
# define ossl_ssize_t ssize_t
# if defined(OPENSSL_SYS_AMIGA) && (defined(__MORPHOS__) || defined(__SASC))
# define OSSL_SSIZE_MAX INT_MAX
# elif defined(SSIZE_MAX)
# if defined(SSIZE_MAX)
# define OSSL_SSIZE_MAX SSIZE_MAX
# elif defined(_POSIX_SSIZE_MAX)
# define OSSL_SSIZE_MAX _POSIX_SSIZE_MAX
Expand Down Expand Up @@ -264,6 +267,8 @@ typedef int int32_t;
typedef unsigned int uint32_t;
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
# elif defined(OPENSSL_SYS_AMIGA)
# include <amissl/types.h>
# else
# include <stdint.h>
# endif
Expand Down
2 changes: 0 additions & 2 deletions openssl/include/openssl/seed.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ extern "C" {
# endif
# endif

# include <sys/types.h>

# define SEED_BLOCK_SIZE 16
# define SEED_KEY_LENGTH 16

Expand Down
66 changes: 49 additions & 17 deletions src/autoinit_amissl_main.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#if defined(__amigaos4__) && !defined(__USE_INLINE__)
#define __USE_INLINE__
#endif

#include <proto/exec.h>
#include <proto/dos.h>

#include <exec/types.h>
#include <dos/dos.h>
#include <utility/tagitem.h>
#include <internal/amissl_compiler.h>
#include <libraries/amisslmaster.h>
#include <libraries/amissl.h>

Expand All @@ -13,24 +16,44 @@

#include <errno.h>

#if defined(__GNUC__)
#define CONSTRUCTOR(name) void __init_##name(void) __attribute__((constructor)); void __init_##name(void)
#define DESTRUCTOR(name) void __exit_##name(void) __attribute__((destructor)); void __exit_##name(void)
#define WEAK __attribute__((weak))
#define fatal_error(message) show_fatal_error(message)
#elif defined(__SASC)
#define CONSTRUCTOR(name) int __stdargs _STI_250_##name(void)
#define DESTRUCTOR(name) void __stdargs _STD_250_##name(void)
#define WEAK
#define fatal_error(message) return show_fatal_error(message)
#elif defined(__VBCC__)
#define CONSTRUCTOR(name) void _INIT_5_##name(void)
#define DESTRUCTOR(name) void _EXIT_5_##name(void)
#define WEAK
#define fatal_error(message) show_fatal_error(message)
#else
#error Compiler not supported
#endif

/****************************************************************************/

__attribute__((weak)) struct Library *AmiSSLBase = NULL;
__attribute__((weak)) struct Library *AmiSSLMasterBase = NULL;
__attribute__((weak)) struct Library *SocketBase = NULL;
WEAK struct Library *AmiSSLBase = NULL;
WEAK struct Library *AmiSSLMasterBase = NULL;
WEAK struct Library *SocketBase = NULL;

#if defined(__amigaos4__)
__attribute__((weak)) struct AmiSSLIFace * IAmiSSL = NULL;
__attribute__((weak)) struct AmiSSLMasterIFace * IAmiSSLMaster = NULL;
__attribute__((weak)) struct SocketIFace * ISocket = NULL;
WEAK struct AmiSSLIFace *IAmiSSL = NULL;
WEAK struct AmiSSLMasterIFace *IAmiSSLMaster = NULL;
WEAK struct SocketIFace *ISocket = NULL;
#endif

void __init_amissl_main(void) __attribute__((constructor));
void __exit_amissl_main(void) __attribute__((destructor));

/****************************************************************************/

static void fatal_error(const char *message)
#if defined(__SASC)
static int show_fatal_error(const char *message)
#else
static void show_fatal_error(const char *message)
#endif
{
BOOL from_wb = ((struct Process *)FindTask(NULL))->pr_CLI == 0;
BPTR fh;
Expand All @@ -54,7 +77,11 @@ static void fatal_error(const char *message)
Close(fh);
}

#if defined(__SASC)
return 1;
#else
exit(RETURN_FAIL);
#endif
}

#if !defined(__AROS__) && (defined(__VBCC__) || defined(NO_INLINE_STDARG))
Expand Down Expand Up @@ -141,14 +168,15 @@ asm (".align 2 \n\
#define XMKSTR(x) #x
#define MKSTR(x) XMKSTR(x)

void __init_amissl_main(void)
CONSTRUCTOR(amissl)
{
#if defined(__amigaos4__)
if (!ISocket)
#endif
{
if (!(SocketBase = OpenLibrary("bsdsocket.library", 4)))
fatal_error("Couldn't open bsdsocket.library v4!\n");
if (!SocketBase)
if (!(SocketBase = OpenLibrary("bsdsocket.library", 4)))
fatal_error("Couldn't open bsdsocket.library v4!\n");

#if defined(__amigaos4__)
if (!(ISocket = (struct SocketIFace *)GetInterface((struct Library *)SocketBase, "main", 1, NULL)))
Expand Down Expand Up @@ -195,18 +223,22 @@ void __init_amissl_main(void)
fatal_error("Couldn't initialize AmiSSL!\n");
#endif
}

#if defined(__SASC)
return 0; /* no error */
#endif
}

/****************************************************************************/

void __exit_amissl_main(void)
DESTRUCTOR(amissl)
{
if (AmiSSLBase)
{
#if defined(__amigaos4__)
if (IAmiSSL)
{
CleanupAmiSSL(TAG_DONE);
CleanupAmiSSLA(NULL);
DropInterface((struct Interface *)IAmiSSL);

IAmiSSL = NULL;
Expand All @@ -215,7 +247,7 @@ void __exit_amissl_main(void)
if (IAmiSSLMaster)
CloseAmiSSL();
#else
CleanupAmiSSL(TAG_DONE);
CleanupAmiSSLA(NULL);
CloseAmiSSL();
#endif

Expand Down
28 changes: 13 additions & 15 deletions test/https.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
#if defined(__amigaos4__)
#ifndef __USE_BASETYPE__
#define __USE_BASETYPE__
# ifndef __USE_INLINE__
# define __USE_INLINE__
# endif
# if defined(__VBCC__) && !defined(__USE_OLD_TIMEVAL__)
# define __USE_OLD_TIMEVAL__
# endif
#endif
#ifndef __USE_INLINE__
#define __USE_INLINE__
#endif
#ifndef __NEW_TIMEVAL_DEFINITION_USED__
#define __NEW_TIMEVAL_DEFINITION_USED__
#endif
#endif /* __amigaos4__ */

#include <sys/socket.h>
#include <netdb.h>
Expand All @@ -19,7 +16,9 @@

#include <proto/exec.h>
#include <proto/dos.h>
#define __NOLIBBASE__
#include <proto/utility.h>
#undef __NOLIBBASE__
#include <proto/amissl.h>
#include <proto/amisslmaster.h>
#include <proto/socket.h>
Expand All @@ -36,8 +35,7 @@ static void GenerateRandomSeed(char *buffer, int size);
static int ConnectToServer(char *, short, char *, short);
static int verify_cb(int preverify_ok, X509_STORE_CTX *ctx);

struct Library *AmiSSLMasterBase, *AmiSSLBase, *SocketBase;
struct UtilityBase *UtilityBase;
struct Library *AmiSSLMasterBase, *AmiSSLBase, *SocketBase, *UtilityBase;

BOOL AmiSSLInitialized;

Expand Down Expand Up @@ -242,9 +240,9 @@ static BOOL Init(void)
{
AmiSSLInitialized = FALSE;

if (!(UtilityBase = (struct UtilityBase *)OpenLibrary("utility.library", 0)))
if (!(UtilityBase = OpenLibrary("utility.library", 0)))
FPrintf(GetStdErr(), "Couldn't open utility.library!\n");
else if (!GETINTERFACE(IUtility, &UtilityBase->ub_LibNode))
else if (!GETINTERFACE(IUtility, UtilityBase))
FPrintf(GetStdErr(), "Couldn't get Socket interface!\n");
else if (!(SocketBase = OpenLibrary("bsdsocket.library", 4)))
FPrintf(GetStdErr(), "Couldn't open bsdsocket.library v4!\n");
Expand Down Expand Up @@ -285,7 +283,7 @@ static void Cleanup(void)
{
if (AmiSSLInitialized)
{ /* Must always call after successful InitAmiSSL() */
CleanupAmiSSL(TAG_DONE);
CleanupAmiSSLA(NULL);
}

if (AmiSSLBase)
Expand All @@ -304,7 +302,7 @@ static void Cleanup(void)
SocketBase = NULL;

DROPINTERFACE(IUtility);
CloseLibrary(&UtilityBase->ub_LibNode);
CloseLibrary(UtilityBase);
UtilityBase = NULL;
}

Expand Down
Loading

0 comments on commit de54117

Please sign in to comment.