static void Cleanup(void) { if (AmiSSLBase) { #if defined(__amigaos4__) if (IAmiSSL) { CleanupAmiSSL(TAG_DONE); DropInterface((struct Interface *)IAmiSSL); IAmiSSL = NULL; } #endif CloseAmiSSL(); AmiSSLBase = NULL; } #if defined(__amigaos4__) DropInterface((struct Interface *)IAmiSSLMaster); IAmiSSLMaster = NULL; #endif CloseLibrary(AmiSSLMasterBase); AmiSSLMasterBase = NULL; #if defined(__amigaos4__) DropInterface((struct Interface *)ISocket); ISocket = NULL; #endif CloseLibrary(SocketBase); SocketBase = NULL; }
void close_ssl_lib(void) { struct thread_s *thread; SM_ENTER; if (!(thread = (struct thread_s*)FindTask(NULL)->tc_UserData)) goto out; #ifndef NO_SSL if (!thread->ssllib_opencnt) { SM_LEAVE; return; } SM_DEBUGF(10,("AmiSSL opened %ld times\n",thread->ssllib_opencnt - 1)); if (!(--thread->ssllib_opencnt)) { SSL_CTX_free((SSL_CTX*)thread->ssl_ctx); thread->ssl_ctx = NULL; #ifndef USE_OPENSSL #ifdef USE_AMISSL3 close_amissl3(thread); #else CleanupAmiSSL(TAG_DONE); CloseLibraryInterface(thread->amissllib,thread->iamissl); thread->amissllib = NULL; thread->iamissl = NULL; #endif #endif close_socket_lib(); } #endif out: SM_LEAVE; }
/** * Close the AmiSSL3 library for the given thread. * * @param thread * @return */ static void close_amissl3(struct thread_s *thread) { CleanupAmiSSL(TAG_DONE); #ifdef __AMIGAOS4__ DropInterface((struct Interface*)thread->iamissl); thread->iamissl = NULL; #endif /* FIXME: Closing amissl will lead to crashes on subsequent calls to socket() * at least on OS4. Therefore, this is disabled when compiling for this * operating system. */ #ifndef __AMIGAOS4__ CloseAmiSSL(); #endif thread->amissllib = NULL; CloseLibraryInterface(thread->amisslmasterlib,thread->iamisslmaster); thread->iamisslmaster = NULL; thread->amisslmasterlib = NULL; CloseLibraryInterface(thread->amissllib,thread->iamissl); thread->amissllib = NULL; thread->iamissl = NULL; }
int open_ssl_lib(void) { #ifdef NO_SSL return 0; #else struct thread_s *thread; SM_ENTER; if (!(thread = (struct thread_s*)FindTask(NULL)->tc_UserData)) goto out; if (!open_socket_lib()) goto out; #ifndef USE_OPENSSL if (!thread->amissllib) { #ifdef USE_AMISSL3 if (open_amissl3(thread)) { #else SM_DEBUGF(10,("Open amissl.library\n")); if ((thread->amissllib = OpenLibraryInterface("amissl.library",1,&thread->iamissl))) { if (!InitAmiSSL(AmiSSL_Version, AmiSSL_CurrentVersion, AmiSSL_Revision, AmiSSL_CurrentRevision, AmiSSL_SocketBase, (ULONG)SocketBase, /* AmiSSL_VersionOverride, TRUE,*/ /* If you insist */ TAG_DONE)) { #endif #endif if ((thread->ssl_ctx = ssl_create_context())) { /* Everything is ok */ thread->ssllib_opencnt = 1; SM_DEBUGF(10,("AmiSSL opened %ld times\n",thread->ssllib_opencnt)); SM_RETURN(1,"%ld"); return 1; } #ifndef USE_OPENSSL #ifdef USE_AMISSL3 close_amissl3(thread); } #else CleanupAmiSSL(TAG_DONE); } CloseLibraryInterface(thread->amissllib,thread->iamissl); thread->iamissl = NULL; thread->amissllib = NULL; } #endif } else { thread->ssllib_opencnt++; SM_DEBUGF(10,("AmiSSL opened %ld times\n",thread->ssllib_opencnt)); SM_RETURN(1,"%ld"); return 1; } #else /* USE_OPENSSL */ return 1; #endif out: close_socket_lib(); SM_RETURN(0,"%ld"); return 0; #endif }
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; }