21 March 2023, 20:24 | #1 |
Registered User
Join Date: Apr 2016
Location: Perth, Australia
Posts: 396
|
Can't seem to initialise AmiSSL
Hi all
I'm trying to write an app that can send HTTP requests to an API but I am struggling to get AmiSSL initialised. Everything starts well but then it errors out at OpenAmiSSLTags(). I have installed the latest version of AmiSSL on my Amiga (5.7). I am using the Amiga C extension for viscose as my dev environment. Ive also tried replacing OpenAmiSSLTags() with InitAmiSSLMaster(AMISSL_CURRENT_VERSION, TRUE) and it still fails Code:
#include "support/gcc8_c_support.h" #include <amissl/amissl.h> #include <proto/exec.h> #include <proto/socket.h> #include <proto/amissl.h> #include <proto/amisslmaster.h> #include <proto/utility.h> #include <libraries/amisslmaster.h> #include <libraries/amissl.h> struct Library *AmiSSLMasterBase, *AmiSSLBase, *AmiSSLExtBase, *SocketBase; struct UtilityBase *UtilityBase; extern struct ExecBase *SysBase; extern struct DosLibrary *DOSBase; #define GETINTERFACE(iface, base) TRUE LONG initOpenAIConnector() { long errno = 0; BOOL AmiSSLInitialized = FALSE; if (!(UtilityBase = (struct UtilityBase *)OpenLibrary("utility.library", 0))) return RETURN_ERROR; UBYTE text[] = "opened utility.library\n"; Write(Output(), (APTR)text, strlen(text)); Delay(50); if ((SocketBase = OpenLibrary("bsdsocket.library\n", 4)) != 0) return RETURN_ERROR; UBYTE text2[] = "opened bsdsocket.library\n"; Write(Output(), (APTR)text2, strlen(text2)); Delay(50); if ((AmiSSLMasterBase = OpenLibrary("amisslmaster.library\n", AMISSLMASTER_MIN_VERSION)) != 0) return RETURN_ERROR; UBYTE text3[] = "opened amisslmaster.library\n"; Write(Output(), (APTR)text3, strlen(text3)); Delay(50); if (!GETINTERFACE(IAmiSSLMaster, AmiSSLMasterBase)) { return RETURN_ERROR; } UBYTE text366[] = "got amisslmaster.library interface\n"; Write(Output(), (APTR)text366, strlen(text366)); Delay(50); if (OpenAmiSSLTags(AMISSL_CURRENT_VERSION, AmiSSL_UsesOpenSSLStructs, FALSE, AmiSSL_GetAmiSSLBase, &AmiSSLBase, AmiSSL_GetAmiSSLExtBase, &AmiSSLExtBase, AmiSSL_SocketBase, SocketBase, AmiSSL_ErrNoPtr, &errno, TAG_DONE) != 0) { return RETURN_ERROR; } UBYTE text4[] = "initialized amisslmaster.library\n"; Write(Output(), (APTR)text4, strlen(text4)); Delay(50); return RETURN_OK; } |
21 March 2023, 21:29 | #2 |
Returning fan!
Join Date: Jan 2011
Location: Montréal, QC, Canada
Posts: 1,434
|
Hi Nightfox!
Actually, you need to do both: InitAmiSSLMaster() and then OpenAmiSSL() Please have a look here, I simplified the use of AmiSSL as much as possible! Let me know if that helps! Tygre |
21 March 2023, 22:13 | #3 |
Registered User
Join Date: Apr 2016
Location: Perth, Australia
Posts: 396
|
Thanks! I have made some changes and the code now looks like this:
Code:
if (!(UtilityBase = (struct UtilityBase *)OpenLibrary("utility.library", 0))) return RETURN_ERROR; UBYTE text[] = "opened utility.library\n"; Write(Output(), (APTR)text, strlen(text)); Delay(50); if ((SocketBase = OpenLibrary("bsdsocket.library\n", 4)) != 0) return RETURN_ERROR; UBYTE text2[] = "opened bsdsocket.library\n"; Write(Output(), (APTR)text2, strlen(text2)); Delay(50); if ((AmiSSLMasterBase = OpenLibrary("amisslmaster.library\n", AMISSLMASTER_MIN_VERSION)) != 0) return RETURN_ERROR; UBYTE text3[] = "opened amisslmaster.library\n"; Write(Output(), (APTR)text3, strlen(text3)); Delay(50); if((AmiSSLBase = OpenAmiSSL()) == FALSE) { return RETURN_ERROR; } UBYTE text5[] = "opened amissl.library\n"; Write(Output(), (APTR)text5, strlen(text5)); Delay(50); |
21 March 2023, 22:29 | #4 |
Registered User
Join Date: Apr 2016
Location: Perth, Australia
Posts: 396
|
Maybe it has something to do with the fact I’m using a gcc build environment and amissl might not like it
|
21 March 2023, 22:32 | #5 |
Registered User
Join Date: Jan 2002
Location: Germany
Posts: 7,009
|
Code:
if ((SocketBase = OpenLibrary("bsdsocket.library\n", 4)) != 0) return RETURN_ERROR; The same is with AmiSSLMasterBase, you continue if it is NULL and return error when it succeeds, which never happens because of the \n in the name. Now that AmiSSLMasterBase is NULL you use it to call OpenAmiSSL(). This crashes of course, you cannot call a library function if the library base is NULL. Additionally you should learn about the difference of integers and pointers. While the C compiler might tolerate that mixture, the code becomes much more logical and readable if you use NULL to compare with pointers, 0 to compare with integers and FALSE only to compare boolean values. Comparing a pointer with FALSE is irritating for everybody who tries to read your code. |
21 March 2023, 23:02 | #6 |
Registered User
Join Date: Apr 2016
Location: Perth, Australia
Posts: 396
|
Thanks so much! No idea how that \n ended up in there.
Here is the current init code but it fails at if (InitAmiSSLMaster(AMISSL_CURRENT_VERSION, TRUE) == FALSE) Code:
if ((UtilityBase = OpenLibrary("utility.library", 0)) == NULL) return RETURN_ERROR; UBYTE text[] = "opened utility.library\n"; Write(Output(), (APTR)text, strlen(text)); Delay(50); if ((SocketBase = OpenLibrary("bsdsocket.library", 0)) == NULL) return RETURN_ERROR; UBYTE text2[] = "opened bsdsocket.library\n"; Write(Output(), (APTR)text2, strlen(text2)); Delay(50); if ((AmiSSLMasterBase = OpenLibrary("amisslmaster.library", AMISSLMASTER_MIN_VERSION)) == NULL) return RETURN_ERROR; UBYTE text3[] = "opened amisslmaster.library\n"; Write(Output(), (APTR)text3, strlen(text3)); Delay(50); if (!GETINTERFACE(IAmiSSLMaster, AmiSSLMasterBase)) { return RETURN_ERROR; } UBYTE text366[] = "got amisslmaster.library interface\n"; Write(Output(), (APTR)text366, strlen(text366)); Delay(50); if (InitAmiSSLMaster(AMISSL_CURRENT_VERSION, TRUE) == FALSE) return RETURN_ERROR; UBYTE text4[] = "initialized amisslmaster.library\n"; Write(Output(), (APTR)text4, strlen(text4)); Delay(50); if ((AmiSSLBase = OpenAmiSSL()) == FALSE) return RETURN_ERROR; UBYTE text555[] = "opened amissl.library\n"; Write(Output(), (APTR)text555, strlen(text555)); Delay(50); |
21 March 2023, 23:34 | #7 |
Registered User
Join Date: Apr 2016
Location: Perth, Australia
Posts: 396
|
OK I fixed it by changing it to
if (InitAmiSSLMaster(AMISSL_V3xx, TRUE) == FALSE) For some reason it doesn't detect the latest version despite me installing the latest one today.... But now if ((AmiSSLBase = OpenAmiSSL()) == FALSE) is failing Last edited by Nightfox; 21 March 2023 at 23:40. |
22 March 2023, 02:25 | #8 |
Returning fan!
Join Date: Jan 2011
Location: Montréal, QC, Canada
Posts: 1,434
|
Hey!
Could you maybe run SnoopDOS to see what's happening behind the scene? PS. Try to make it work with AMISSL_CURRENT_VERSION, that could be the root cause of your problems. PPS. Do you open utility.library too? PPPS. Are you on AmigaOS v3.x or v4.x? Let us know! Tygre |
22 March 2023, 05:11 | #9 |
Registered User
Join Date: Apr 2016
Location: Perth, Australia
Posts: 396
|
I have SnoopDOS installed and I have asked ChatGPT how to use it so I'll try that out and report back.
Yeah I definitely wanted to change it to AMISSL_CURRENT_VERSION so I will try to get that working! Yes utility.library opens perfectly. I'm on AmigaOS 3.2 Update 2 released a few weeks ago. Last edited by Nightfox; 22 March 2023 at 05:34. |
22 March 2023, 05:52 | #10 |
Registered User
Join Date: Apr 2016
Location: Perth, Australia
Posts: 396
|
I updated it to request for current version.
Here is the output plus the snoopdos log. It fails on the line Code:
if (InitAmiSSLMaster(AMISSL_CURRENT_VERSION, TRUE) == FALSE |
22 March 2023, 08:12 | #11 |
bye
Join Date: Jun 2016
Location: Some / Where
Posts: 680
|
have a look here: https://github.com/jens-maus/amissl/..._amissl_main.c
for my m68k-amigaos-gcc you might also use this file as lib. Last edited by bebbo; 26 October 2023 at 13:18. |
22 March 2023, 11:22 | #12 |
Registered User
Join Date: Apr 2016
Location: Perth, Australia
Posts: 396
|
Thanks for the autoinit stuff but I just figured it out!
So turns out when I installed AmiSSL I installed it to my other partition and I had an older version in LIBS: haha I could move it over but instead I have done the better thing of making the program not care where it's installed. Changed it to Code:
AmiSSLMasterBase = OpenLibrary("AMISSL:libs/amisslmaster.library", AMISSLMASTER_MIN_VERSION) |
22 March 2023, 13:31 | #13 |
Returning fan!
Join Date: Jan 2011
Location: Montréal, QC, Canada
Posts: 1,434
|
Hi!
Glad that you figured it out! PS. Maybe it's not such a good practice to hard-code the path to the AmiSSLMaster library because it and other things may still look into LIBS: and then there'll be mismatches... Cheers! |
27 March 2023, 00:00 | #14 |
Registered User
Join Date: Aug 2018
Location: United Kingdom
Posts: 198
|
Some things to clear up:
|
28 March 2023, 03:46 | #15 |
Returning fan!
Join Date: Jan 2011
Location: Montréal, QC, Canada
Posts: 1,434
|
Hi Futaura!
Do you know why we should not use InitAmiSSLMaster() and OpenAmiSSL() anymore? One (old?) example provided with AmiSSL uses them, the other (more recent?) example uses OpenAmiSSLTags(). Cheers! |
28 March 2023, 10:34 | #16 | |
ex. demoscener "Bigmama"
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,631
|
From here: https://github.com/jens-maus/amissl/...ist/README-SDK
Quote:
|
|
28 March 2023, 14:25 | #17 |
Returning fan!
Join Date: Jan 2011
Location: Montréal, QC, Canada
Posts: 1,434
|
Hi Hooverphonique!
Thanks! I had read that before but it doesn't really explain why OpenAmiSSLTags() is better than the combination of InitAmiSSLMaster(), OpenAmiSSL(), and InitAmiSSL(). I understand that OpenAmiSSLTags() can do as much and maybe even more than the three combined but, for a "minimal" usage, it seems just simpler? Cheers! |
29 March 2023, 17:22 | #18 |
Registered User
Join Date: Aug 2018
Location: United Kingdom
Posts: 198
|
Well, yes, it is mainly to make opening AmiSSL simpler, whilst also adding flexibility for expansion in the future. There were some complaints in the past that the old API was confusing and the changes required for AmiSSL v5 (i.e. two library bases on OS3) would make things even more complicated. With OpenAmiSSLTags(), it hides all the complications that developers don't necessarily need to know - currently, it calls the 3 old functions itself . I really want to do everything I can to make it easier for any developer to use AmiSSL - it doesn't even need to be used for SSL/TLS, as the cryptographic library is also very useful on its own. AmiSSL is also carefully optimised for AmigaOS which straight ports of OpenSSL are not.
It shouldn't really have ever been so complex to begin, although there are historical good reasons for it (in relation to applications that fully utilise the multithreaded functionality of AmiSSL, in which individual threads must still call Init/CleanupAmiSSL()). |
29 March 2023, 18:13 | #19 |
Returning fan!
Join Date: Jan 2011
Location: Montréal, QC, Canada
Posts: 1,434
|
Hi Futaura!
Thank you, that makes total sense indeed Always very interesting to understand how software evolve Cheers! |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
AmiSSL 4.9 Now Available | Futaura | News | 4 | 06 April 2021 19:44 |
New AmiSSL v4.6 | stevelord | News | 1 | 09 June 2020 13:42 |
AmiSSL 4 | Robbie | support.Apps | 62 | 17 February 2020 19:54 |
AmiSSL 4.0 | Sir_Lucas | News | 6 | 09 February 2017 12:45 |
new AmiSSL | hal9000 | support.Apps | 1 | 14 August 2016 18:23 |
|
|