Beispiel #1
0
/**
 * Open the AmiSSL3 library for the given thread.
 *
 * @param thread
 * @return 1 on success, 0 on failure.
 */
static int open_amissl3(struct thread_s *thread)
{
	thread->amisslmasterlib = NULL;
	thread->amissllib = NULL;

#ifdef __AMIGAOS4__
	thread->iamisslmaster = NULL;
	thread->iamissl =  NULL;
#endif

	if (!(thread->amisslmasterlib = OpenLibraryInterface("amisslmaster.library",AMISSLMASTER_MIN_VERSION, &thread->iamisslmaster)))
		goto bailout;

	if (!InitAmiSSLMaster(AMISSL_CURRENT_VERSION, TRUE))
		goto bailout;

	if (!(thread->amissllib = OpenAmiSSL()))
		goto bailout;

#ifdef __AMIGAOS4__
	if (!(thread->iamissl = (struct AmiSSLIFace *)GetInterface(thread->amissllib,"main",1,NULL)))
		goto bailout;
#endif
	if (InitAmiSSL(AmiSSL_SocketBase, (ULONG)SocketBase, TAG_DONE) != 0)
		goto bailout;

	return 1;
bailout:
	close_amissl3(thread);
	return 0;
}
Beispiel #2
0
/* Open and initialize AmiSSL */
static BOOL Init(void)
{
	BOOL is_ok = FALSE;

	if (!(SocketBase = OpenLibrary("bsdsocket.library", 4)))
		FPrintf(GetStdErr(), "Couldn't open bsdsocket.library v4!\n");
#if defined(__amigaos4__)
	else if (!(ISocket = (struct SocketIFace *)GetInterface(SocketBase, "main", 1, NULL)))
		FPrintf(GetStdErr(), "Couldn't get Socket interface!\n");
#endif
	else if (!(AmiSSLMasterBase = OpenLibrary("amisslmaster.library",
	                                          AMISSLMASTER_MIN_VERSION)))
		FPrintf(GetStdErr(), "Couldn't open amisslmaster.library v"
		                     MKSTR(AMISSLMASTER_MIN_VERSION) "!\n");
#if defined(__amigaos4__)
	else if (!(IAmiSSLMaster = (struct AmiSSLMasterIFace *)GetInterface(AmiSSLMasterBase,
	                                                                    "main", 1, NULL)))
		FPrintf(GetStdErr(), "Couldn't get AmiSSLMaster interface!\n");
#endif
	else if (!InitAmiSSLMaster(AMISSL_CURRENT_VERSION, TRUE))
		FPrintf(GetStdErr(), "AmiSSL version is too old!\n");
	else if (!(AmiSSLBase = OpenAmiSSL()))
		FPrintf(GetStdErr(), "Couldn't open AmiSSL!\n");
#if defined(__amigaos4__)
	else if (!(IAmiSSL = (struct AmiSSLIFace *)GetInterface(AmiSSLBase,
	                                                        "main", 1, NULL)))
		FPrintf(GetStdErr(), "Couldn't get AmiSSL interface!\n");
#endif
#if defined(__amigaos4__)
	else if (InitAmiSSL(AmiSSL_ErrNoPtr, &errno,
	                    AmiSSL_ISocket, ISocket,
	                    TAG_DONE) != 0)
#else
	else if (InitAmiSSL(AmiSSL_ErrNoPtr, &errno,
	                    AmiSSL_SocketBase, SocketBase,
	                    TAG_DONE) != 0)
#endif
		FPrintf(GetStdErr(), "Couldn't initialize AmiSSL!\n");
	else
		is_ok = TRUE;

	if (!is_ok)
		Cleanup(); /* This is safe to call even if something failed above */

	return(is_ok);
}
Beispiel #3
0
int main(void)
{
#if 1
{
	printf("single base test\n");
	AmiSSLBase = OpenLibrary(LIBNAME, 0);
	printf("base %08lx\n", AmiSSLBase);
	if(AmiSSLBase != NULL &&
     GETINTERFACE(IAmiSSL, AmiSSLBase))
	{
		printf("checking base %08lx...", AmiSSLBase);
    #if defined(__amigaos4__)
		printf(" iface %08lx...", IAmiSSL);
    #endif
		InitAmiSSL(TAG_DONE);
		CleanupAmiSSL(TAG_DONE);
		printf(" done\n");
    DROPINTERFACE(IAmiSSL);
		CloseLibrary(AmiSSLBase);
	}
	printf("single base test finished\n");
}
#endif

#if 1
{
	struct Library *base1 = NULL;
	struct Library *base2 = NULL;
  #if defined(__amigaos4__)
  struct AmiSSLIFace *ibase1 = NULL;
  struct AmiSSLIFace *ibase2 = NULL;
  #endif

	printf("multi base test\n");

	kprintf("########################\n");
	kprintf("OpenLibrary(base1)\n");
	base1 = OpenLibrary(LIBNAME, 0);
	printf("base1 %08lx\n", base1);
	kprintf("# done #################\n");

	kprintf("########################\n");
	kprintf("OpenLibrary(base2)\n");
	base2 = OpenLibrary(LIBNAME, 0);
	printf("base2 %08lx\n", base2);
	kprintf("# done #################\n");

	if(base1 != NULL && base2 != NULL &&
     GETINTERFACE(ibase1, base1) &&
     GETINTERFACE(ibase2, base2))
	{
    LONG ret = 0;

		AmiSSLBase = base1;
    #if defined(__amigaos4__)
    IAmiSSL = ibase1;
    #endif
		kprintf("########################\n");
		kprintf("checking base1 %08lx\n", AmiSSLBase);
		printf("checking base1 %08lx...", AmiSSLBase);
    #if defined(__amigaos4__)
		printf(" iface %08lx...", IAmiSSL);
    #endif
		ret = InitAmiSSL(TAG_DONE);
		printf(" done: %ld\n", ret);
		CleanupAmiSSL(TAG_DONE);
		kprintf("# done #################\n");

		AmiSSLBase = base2;
    #if defined(__amigaos4__)
    IAmiSSL = ibase2;
    #endif
		kprintf("########################\n");
		kprintf("checking base2 %08lx\n", AmiSSLBase);
		printf("checking base2 %08lx...", AmiSSLBase);
    #if defined(__amigaos4__)
		printf(" iface %08lx...", IAmiSSL);
    #endif
		ret = InitAmiSSL(TAG_DONE);
		printf(" done: %ld\n", ret);
		CleanupAmiSSL(TAG_DONE);
		kprintf("# done #################\n");

		AmiSSLBase = base1;
    #if defined(__amigaos4__)
    IAmiSSL = ibase1;
    #endif
		kprintf("########################\n");
		kprintf("checking base1 %08lx\n", AmiSSLBase);
		printf("checking base1 %08lx...", AmiSSLBase);
    #if defined(__amigaos4__)
		printf(" iface %08lx...", IAmiSSL);
    #endif
		ret = InitAmiSSL(TAG_DONE);
		printf(" done: %ld\n", ret);
		CleanupAmiSSL(TAG_DONE);
		kprintf("# done #################\n");

		AmiSSLBase = base2;
    #if defined(__amigaos4__)
    IAmiSSL = ibase2;
    #endif
		kprintf("########################\n");
		kprintf("checking base2 %08lx\n", AmiSSLBase);
		printf("checking base2 %08lx...", AmiSSLBase);
    #if defined(__amigaos4__)
		printf(" iface %08lx...", IAmiSSL);
    #endif
		ret = InitAmiSSL(TAG_DONE);
		printf(" done: %ld\n", ret);
		CleanupAmiSSL(TAG_DONE);
		kprintf("# done #################\n");
	}

	if(base1 != NULL)
  {
    DROPINTERFACE(ibase1);
		CloseLibrary(base1);
  }

	if(base2 != NULL)
  {
    DROPINTERFACE(ibase2);
		CloseLibrary(base2);
  }
	printf("multi base test finished\n");
}
#endif

// lets perform a full-fledged amissl test case
#if 1
{
  printf("\ncomplex amissl test\n");
  if((AmiSSLMasterBase = OpenLibrary("amisslmaster.library", 0)) != NULL &&
     GETINTERFACE(IAmiSSLMaster, AmiSSLMasterBase))
  {
    printf("amisslmaster.library opened: %08lx\n", AmiSSLMasterBase);

    if(InitAmiSSLMaster(AMISSL_CURRENT_VERSION, TRUE))
    {
      printf("amisslmaster.library initialized\n");

      if((AmiSSLBase = OpenAmiSSL()) != NULL &&
         GETINTERFACE(IAmiSSL, AmiSSLBase))
      {
        char tmp[24+1];

        printf("successfully opened AmiSSL library %d.%d (%s): %08lx\n", AmiSSLBase->lib_Version, AmiSSLBase->lib_Revision, (char *)AmiSSLBase->lib_IdString, AmiSSLBase);

        // initialize AmiSSL/OpenSSL related stuff
        printf("initializing internal OpenSSL strings:\n");
        ERR_load_BIO_strings();
        printf("ERR_load_BIO_string() done.\n");
        SSL_load_error_strings();
        printf("SSL_load_error_strings() done.\n");
        OpenSSL_add_all_algorithms();
        printf("OpenSSL_add_all_algorithms() done.\n");
        SSL_library_init();
        printf("SSL_library_init() done.\n");

        // seed the random number generator with some valuable entropy
        snprintf(tmp, sizeof(tmp), "%08lx%08lx%08lx", (unsigned long)time((time_t *)NULL), (unsigned long)FindTask(NULL), (unsigned long)rand());
        printf("about to seed random number generator\n");
        RAND_seed(tmp, strlen(tmp));
        printf("RAND_seed() done!\n");

        // cleanup
        printf("starting cleanup\n");
        CleanupAmiSSLA(NULL);
        printf("CleanupAmiSSLA() done!\n");
        DROPINTERFACE(IAmiSSL);
        CloseAmiSSL();
        printf("CloseAmiSSL() done!\n");
        AmiSSLBase = NULL;
      }
    }

    printf("About to close amisslmaster.library\n");
    DROPINTERFACE(IAmiSSLMaster);
    CloseLibrary(AmiSSLMasterBase);
    printf("done.\n");
    AmiSSLMasterBase = NULL;
  }
}
#endif

	return 0;
}