Beispiel #1
0
bool AD::Connect()
{
    DWORD ret;
    LONG value;

    //if(!Init())
    //{
    if(!InitSSL())
    {
        Util::Warn(L"Unable to initialize an LDAP context.");
        return false;
    }
    else
    {
        if((ret = ldap_get_option(ldap, LDAP_OPT_SSL, (void *)&value)) != LDAP_SUCCESS)
        {
            Util::Error(LdapGetLastError(), L"ldap_get_option()");
        }
        if((void *)value == LDAP_OPT_ON)
        {
            if((ret = ldap_set_option(ldap, LDAP_OPT_SSL, LDAP_OPT_ON)) != LDAP_SUCCESS)
            {
                Util::Error(LdapGetLastError(), L"ldap_set_option()");
            }
        }
    }
    //}

    if(ldap_set_option(ldap, LDAP_OPT_PROTOCOL_VERSION, (void *)LDAP_VERSION3) != LDAP_SUCCESS)
    {
        Util::Error(LdapGetLastError(), L"ldap_set_option()");
        wprintf(L"Ret = %x\n", LdapGetLastError());
    }
    return (ldap_connect(ldap, NULL) == LDAP_SUCCESS) ? true : false;
}
int32_t CSSLClientAsync::ReConnectAsync()
{
    int32_t nErrorCode = 0;
    if (S_INVALID_SOCKET == GetSocket())
    {
        _InitSocket();
        InitSSL(GetCertFile().c_str(), GetKeyFile().c_str(), GetKeyPassword().c_str());
        nErrorCode = ConnectAsync(GetRemoteIP(), GetRemotePort());
    }
    return nErrorCode;
}
Beispiel #3
0
   void
   TCPServer::Run()
   {
      if (connection_security_ == CSSSL ||
          connection_security_ == CSSTARTTLSOptional ||
          connection_security_ == CSSTARTTLSRequired)
      {
         if (!InitSSL())
            return;
      }

      if (!InitAcceptor())
         return;

      StartAccept();
   }
Beispiel #4
0
int
ConnectionEstablish( char *server_name, int port )
{
  int len;
  char rx_buffer[1024]; /* Temporary... */

  wmnotify_infos.sock_fd = SocketOpen( wmnotify_infos.server_name, wmnotify_infos.port );
  if( wmnotify_infos.sock_fd < 0 ) {
    goto error;
  }

#if HAVE_SSL
  if( wmnotify_infos.use_ssl == true ) {
    int status;
    status = InitSSL( wmnotify_infos.sock_fd );
    if( status != EXIT_SUCCESS ) {
      goto error;
    }
  }
#endif

  /* Testing connection. */
  len = WmnotifyGetResponse( rx_buffer, 1024 );
  if( len < 0 ) {
    goto error;
  }

  if( wmnotify_infos.debug ) {
    rx_buffer[len] = 0;
    printf(" Connect response:\n%s\n", rx_buffer );
  }

  return EXIT_SUCCESS;

 error:
  return EXIT_FAILURE;
}
Beispiel #5
0
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow)
{
	HRESULT hRes = ::CoInitialize(NULL);
// If you are running on NT 4.0 or higher you can use the following call instead to 
// make the EXE free threaded. This means that calls come in on a random RPC thread.
//	HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
	ATLASSERT(SUCCEEDED(hRes));

#ifdef _DEBUG
	// ATLTRACEで日本語を使うために必要
	_tsetlocale( LC_ALL, _T("japanese") );
#endif

	// this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used
	::DefWindowProc(NULL, 0, 0, 0L);

	AtlInitCommonControls(ICC_BAR_CLASSES);	// add flags to support other controls

    // リッチエディットコントロール初期化
    HINSTANCE hRich = LoadLibrary(CRichEditCtrl::GetLibraryName());
    if(hRich == NULL){
        AtlMessageBox(NULL, _T("リッチエディットコントロール初期化失敗"),
            _T("エラー"), MB_OK | MB_ICONERROR);
        return 0;
    }

	hRes = _Module.Init(NULL, hInstance);
	ATLASSERT(SUCCEEDED(hRes));
	
	int nRet = 0;
	try {

		CVersionControl::Run();

		CSettings::LoadSettings();

		CSocket::Init();

		WinHTTPWrapper::InitWinHTTP();

		CSettings::s_SSLFilter = InitSSL();

		nRet = Run(lpstrCmdLine, nCmdShow);

		if (CSettings::s_SSLFilter)
			TermSSL();

		WinHTTPWrapper::TermWinHTTP();

		CSocket::Term();

		CSettings::SaveSettings();
	}
	catch (std::exception& e) {
		ERROR_LOG << e.what();
	}

	FreeLibrary(hRich);

	_Module.Term();
	::CoUninitialize();

	return nRet;
}
Beispiel #6
0
int main(int argc , char *argv[])
{
    
     int sfd;
     char *P_num; 
     SSL_CTX * ctx;
     struct sockaddr_in cli_addr;   
     socklen_t len ;
     int cli;
     pid_t pid;
     struct sigaction sa;

    //Innitiliaze Server
   if (checkFileStruct() == -1){
       printf("Server: Problem With OldTrusty File Structure\n");
       exit(1);
   }
   //Initialize the Vouch Structure
       initVouchStruct();
   
    //Initialize SSL 
       
    if (argc != 2) {
        printf("Usage %s <portNUMBER> \n" , argv[0]);
        exit(1);
    }
    P_num = argv[1]; //Set Port

    ctx = InitSSL();
    load_Certs(ctx, "OldTrusty/ServerCerts/server.crt", "OldTrusty/ServerCerts/server.key");  //ALL IN ONE ? 
    //Get A regular tcp socket. already bound and listening.
    sfd = sock_setup(P_num);

    sa.sa_handler = sigchld_handler; // reap all dead processes
    sigemptyset(&sa.sa_mask);
    sa.sa_flags = SA_RESTART;
    if (sigaction(SIGCHLD, &sa, NULL) == -1) {
    perror("sigaction");
    exit(1); }
    

    printf("Server: OldTrusty Awaiting Connections on Port: %s\n" , P_num);

      //***********************************MAIN ACCEPT LOOP STARTS HERE *****************************/
    for(;;) {     
             
    len  = sizeof(cli_addr);
    
    cli = accept(sfd,  (struct sockaddr *)&cli_addr, &len); 
        if (cli == -1) {
            perror("accept");
            continue;
        }
    printf("Server: OLDTRUSTY recieved A Connection from: %s:%d\n",inet_ntoa(cli_addr.sin_addr), ntohs(cli_addr.sin_port));

    SSL *ssl;

   
   if ( ( pid = fork())  == 0 ){

    //WE ARE THE CHILD
    close(sfd);    //Child doesnt need listner


    //Layer SSL Over Client Socket
    ssl = SSL_new(ctx); 
    SSL_set_fd(ssl, cli); 

  
    //HANDSHAKE.. 
    if ( SSL_accept(ssl) == -1)    
       ERR_print_errors_fp(stderr);

    //Show Client Certs (If any) // CAN ADDif require client auth then     //for now jsut show client certs if has any
    ShowCerts(ssl);

    // Here is a connection to the client 
    do_clients_bidding(ssl);
    
    SSL_free(ssl);
    close(cli);

    exit(0); // kill child.

    }  

    close(cli); //Parent closes connected socket (Being Handled in child)

    }  ///***END MAIN ACCEPT LOOP *****//
     
    SSL_CTX_free(ctx); //release context TODO never get hear?? graceful shutdown of server?
   
   
return 0;

}  
Beispiel #7
0
int main(int argc , char *argv[])
{
    
     int sfd;
     char *P_num; 
     SSL_CTX * ctx;
     struct sockaddr_in cli_addr;   
     socklen_t len ;
     int cli;
     pid_t pid;

    //Innitiliaze Server
   if (checkFileStruct() == -1){
       printf("Problem With OldTrusty File Structure\n");
       exit(1);
   }
   



    //Initialize SSL 
       
    if (argc != 2) {
        printf("Usage %s <portNUMBER> \n" , argv[0]);
        exit(1);
    }
    P_num = argv[1]; //Set Port

    ctx = InitSSL();
    load_Certs(ctx, "OldTrusty/ServerCerts/mycert.pem", "OldTrusty/ServerCerts/mycert.pem");  //ALL IN ONE ? 
    //Get A regular tcp socket. already bound and listening.
    sfd = sock_setup(P_num);


    printf("OldTrusty Awaiting Connections on Port: %s\n" , P_num);

      //***********************************MAIN ACCEPT LOOP STARTS HERE *****************************/
    for(;;) {     
        //Ever ?? 
        
      len  = sizeof(cli_addr);
    
    cli = accept(sfd,  (struct sockaddr *)&cli_addr, &len); 
        if (cli == -1) {
            perror("accept");
            continue;
        }
    printf("OLDTRUSTY RECIEVED A Connection from: %s:%d\n",inet_ntoa(cli_addr.sin_addr), ntohs(cli_addr.sin_port));

    SSL *ssl;

   
   if ( ( pid = fork())  == 0 ){

    //WE ARE THE CHILD
    close(sfd);    //Child doesnt need listner


    //Layer SSL Over Client Socket
    ssl = SSL_new(ctx); 
    SSL_set_fd(ssl, cli); 

  
    //HANDSHAKE.. 
    if ( SSL_accept(ssl) == -1)    
       ERR_print_errors_fp(stderr);

    //CREATE BIO OBJECT FOR THE SSL ?? TODO TO US OpenSSL over other channels (not just socketS)
    //TODO

    //Show Client Certs (If any) // CAN ADDif require client auth then -- check_cert(ssl,client )
    //for now jsut show client certs if has any
    ShowCerts(ssl);

    // Here is a connection to the client 
    do_clients_bidding(ssl);


    
    SSL_free(ssl);
    close(cli);

    exit(0); // kill child.

    }  

    close(cli); //Parent closes connected socket (Being Handled in child)

    }  ///***END MAIN ACCEPT LOOP *****//
     

    SSL_CTX_free(ctx); //release context TODO never get hear?? graceful shutdown of server?
   
   
return 0;

}