English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. C/C++

 
 
Thread Tools
Old 21 March 2023, 20:24   #1
Nightfox
Registered User
 
Nightfox's Avatar
 
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;

}
Nightfox is offline  
Old 21 March 2023, 21:29   #2
tygre
Returning fan!
 
tygre's Avatar
 
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
tygre is offline  
Old 21 March 2023, 22:13   #3
Nightfox
Registered User
 
Nightfox's Avatar
 
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);
... but it fails at if((AmiSSLBase = OpenAmiSSL()) == FALSE)
Nightfox is offline  
Old 21 March 2023, 22:29   #4
Nightfox
Registered User
 
Nightfox's Avatar
 
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
Nightfox is offline  
Old 21 March 2023, 22:32   #5
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 7,009
Code:
	if ((SocketBase = OpenLibrary("bsdsocket.library\n", 4)) != 0)
		return RETURN_ERROR;
This is completely wrong. First of all the \n at the end will always cause OpenLibrary to fail. If it fails it returns NULL. But you check not-equal NULL and then return error. So you return error when OpenLibrary proceeds and continue if it fails.

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.
thomas is offline  
Old 21 March 2023, 23:02   #6
Nightfox
Registered User
 
Nightfox's Avatar
 
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);
Nightfox is offline  
Old 21 March 2023, 23:34   #7
Nightfox
Registered User
 
Nightfox's Avatar
 
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.
Nightfox is offline  
Old 22 March 2023, 02:25   #8
tygre
Returning fan!
 
tygre's Avatar
 
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
tygre is offline  
Old 22 March 2023, 05:11   #9
Nightfox
Registered User
 
Nightfox's Avatar
 
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.
Nightfox is offline  
Old 22 March 2023, 05:52   #10
Nightfox
Registered User
 
Nightfox's Avatar
 
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
https://ibb.co/c6crwT0
Nightfox is offline  
Old 22 March 2023, 08:12   #11
bebbo
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.
bebbo is offline  
Old 22 March 2023, 11:22   #12
Nightfox
Registered User
 
Nightfox's Avatar
 
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)
since the AmiSSL installer creates an ASSIGN automatically and programs really should use this instead of leaving it up to the system to find the library.
Nightfox is offline  
Old 22 March 2023, 13:31   #13
tygre
Returning fan!
 
tygre's Avatar
 
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!
tygre is offline  
Old 27 March 2023, 00:00   #14
Futaura
Registered User
 
Futaura's Avatar
 
Join Date: Aug 2018
Location: United Kingdom
Posts: 198
Some things to clear up:
  1. You should not use AMISSL: assign in the OpenLibrary() call - AMISSL:Libs is added to the LIBS: assign in s:user-startup. The libraries are not located in AMISSL: on OS4.
  2. Only install AmiSSL to a single location unless you really know what you're doing - it is safe for older versions to co-exist in the same location. That is the better thing to do.
  3. You were correct first time to use OpenAmiSSLTags(). It supercedes both InitAmiSSLMaster() and OpenAmiSSL(), which should no longer be used.
  4. Read the documentation
Futaura is offline  
Old 28 March 2023, 03:46   #15
tygre
Returning fan!
 
tygre's Avatar
 
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!
tygre is offline  
Old 28 March 2023, 10:34   #16
hooverphonique
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:
...However, we encourage developers to use the new OpenAmiSSLTags() function, in place of InitAmiSSLMaster(), OpenAmiSSL() and InitAmiSSL() (these functions will still continue to operate as before). Details of OpenSSL changes are available at https://www.openssl.org/docs/manmast...ion_guide.html and with GCC you will receive warnings if you use any deprecated functions.
Generally, don't use deprecated stuff if you can avoid it, because it's likely to be removed in a future version, breaking your build.
hooverphonique is offline  
Old 28 March 2023, 14:25   #17
tygre
Returning fan!
 
tygre's Avatar
 
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!
tygre is offline  
Old 29 March 2023, 17:22   #18
Futaura
Registered User
 
Futaura's Avatar
 
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()).
Futaura is offline  
Old 29 March 2023, 18:13   #19
tygre
Returning fan!
 
tygre's Avatar
 
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!
tygre is offline  
 


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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 20:09.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.09655 seconds with 15 queries