def shutdown(profileDir): """ Shut down the cryptographic services. You must call startup() before doing cryptographic operations again. @param profileDir: The profile directory. A snapshot of current entropy state will be saved into a file in this directory. It is not a fatal error if the file cannot be created. """ Rand.save_file(_randpoolPath(profileDir)) m2threading.cleanup()
def __init__(self, handler, host='localhost', port=8000): threading.init() Rand.load_file('../randpool.dat', -1) ctx=echod_lib.init_context('sslv3','server.pem', 'ca.pem', SSL.verify_peer) ctx.set_tmp_dh('dh1024.pem') config = Config() server = TCPServer.__connection(self, host, port) while 1: server.OpenConnection() server.HandleConnection(handler,config.config,ctx) server.CloseConnection() Rand.save_file('../randpool.dat') threading.cleanup()
def stopCrypto(profileDir): """ Shut down the cryptographic services. You must call startup() before doing cryptographic operations again. @param profileDir: The profile directory. A snapshot of current entropy state will be saved into a file in this directory. It is not a fatal error if the file cannot be created. @return: The number of bytes saved to file. """ from osaf.framework.certstore import utils ret = 0 if utils.entropyInitialized: ret = Rand.save_file(_randpoolPath(profileDir)) m2threading.cleanup() return ret
def RunClient(*args, **kw): m2threading.init() id = kw['id'] venueUri = kw['url'] app = kw['app'] iter = app.GetOption("rt") verbose = kw['verbose'] profile = ClientProfile() profile.name = "Test Client %s" % id profile.publicId = str(GUID()) client = MyVenueClient(profile, app) for i in range(iter): try: if verbose: print "Entering Venue: %s" % venueUri ret = client.EnterVenue(venueUri) if ret: print '** EnterVenue ret = ', ret print "Client %d Entered %s %d times" % (id, venueUri,i) except: print traceback.print_exc() continue if verbose: client.PrintVenueState() # Pick next one if client.venueState is not None: exits = client.venueState.connections.values() if len(exits): next_index = random.randint(0, len(exits)-1) venueUri = exits[next_index].uri try: time.sleep(1) client.ExitVenue() if verbose: print "Exited venue !" except: print traceback.print_exc() client.Shutdown() m2threading.cleanup()
def RunClient(*args, **kw): m2threading.init() id = kw["id"] venueUri = kw["url"] app = kw["app"] iter = app.GetOption("rt") verbose = kw["verbose"] profile = ClientProfile() profile.name = "Test Client %s" % id profile.publicId = str(GUID()) client = MyVenueClient(profile, app) for i in range(iter): try: if verbose: print "Entering Venue: %s" % venueUri ret = client.EnterVenue(venueUri) if ret: print "** EnterVenue ret = ", ret print "Client %d Entered %s %d times" % (id, venueUri, i) except: print traceback.print_exc() continue if verbose: client.PrintVenueState() # Pick next one if client.venueState is not None: exits = client.venueState.connections.values() if len(exits): next_index = random.randint(0, len(exits) - 1) venueUri = exits[next_index].uri try: time.sleep(1) client.ExitVenue() if verbose: print "Exited venue !" except: print traceback.print_exc() client.Shutdown() m2threading.cleanup()
def test_multiInitCleanup(self): m2threading.init() m2threading.init() m2threading.cleanup() m2threading.cleanup() m2threading.init() m2threading.cleanup()
conn.close() else: conn.clear() print 'SSL Connection closed' if __name__=='__main__': threading.init() Rand.load_file('../randpool.dat', -1) ctx = setup_server_ctx() # How about something like this? #conn_root = SSL.Connection(ctx) #conn_root.bind(('127.0.0.1', 9999)) #conn_root.listen(5) #while 1: # ssl, addr = conn_root.accept() # thread.start_new_thread(server_thread, (ctx, ssl, addr)) sock = socket(AF_INET, SOCK_STREAM) sock.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) sock.bind(('', 9999)) sock.listen(5) while 1: conn, addr = sock.accept() thread.start_new_thread(server_thread, (ctx, conn, addr)) Rand.save_file('../randpool.dat') threading.cleanup()
def passive(): ctx = SSL.Context('sslv23') f = ftpslib.FTP_TLS(ssl_ctx=ctx) f.connect('127.0.0.1', 39021) f.auth_tls() f.set_pasv(1) f.login('ftp', 'ngps@') f.prot_p() f.retrlines('LIST') f.quit() def active(): ctx = SSL.Context('sslv23') f = ftpslib.FTP_TLS(ssl_ctx=ctx) f.connect('127.0.0.1', 39021) f.auth_tls() f.set_pasv(0) f.login('ftp', 'ngps@') f.prot_p() f.retrlines('LIST') f.quit() if __name__ == '__main__': threading.init() active() passive() threading.cleanup()
def teardown(self): testutil.remove_tmp_directory() m2_threading.cleanup()
vcList = list() print "Spawning venue clients" for id in range(app.GetOption("nc")): client = threading.Thread(target=RunClient, name="Venue Client %s" % id, kwargs = {'id':id, 'url': venueUri, 'app' : app, 'verbose' : verbose }) client.start() while 1: numdaemonthreads = 0 threads = threading.enumerate() numthreads = len(threads) print "Num Threads: ", numthreads for t in threads: print t if t.isDaemon(): numdaemonthreads += 1 # loop until only the main thread and daemon threads remain if numdaemonthreads == numthreads - 1: break time.sleep(1.0) m2threading.cleanup() sys.exit(0)
while not handshake_complete: input_token = new_sock.recv(1024) readbio.write(input_token) ret = self.sslbio.do_handshake() if ret <= 0: if not self.sslbio.should_retry() or not self.sslbio.should_read(): sys.exit("unrecoverable error in handshake - server") else: handshake_complete = True output_token = writebio.read() if output_token is not None: new_sock.sendall(output_token) handshake_client.join() sock.close() new_sock.close() def suite(): return unittest.makeSuite(SSLTestCase) if __name__ == '__main__': Rand.load_file('randpool.dat', -1) m2threading.init() unittest.TextTestRunner().run(suite()) m2threading.cleanup() Rand.save_file('randpool.dat')
def tearDown(self): m2threading.cleanup()
#while server.IsRunning(): # res = m.getDeferred(fakeDeferred("got it!")) while server.IsRunning(): time.sleep(0.05) log.debug("After main loop!") # Stop the hosting environment try: server.Stop() log.debug("Stopped Hosting Environment, exiting.") except: log.exception("Exception stopping server") M2Crypto_threading.cleanup() time.sleep(1) for thrd in threading.enumerate(): log.debug("Thread %s", thrd) # Exit cleanly sys.exit(0) if __name__ == "__main__": import socket try: main() except socket.error, e: if e.args[0] == 98:
# res = m.getDeferred(fakeDeferred("got it!")) while server.IsRunning(): time.sleep(0.05) log.debug("After main loop!") # Stop the hosting environment try: server.Stop() log.debug("Stopped Hosting Environment, exiting.") except: log.exception("Exception stopping server") M2Crypto_threading.cleanup() time.sleep(1) for thrd in threading.enumerate(): log.debug("Thread %s", thrd) # Exit cleanly sys.exit(0) if __name__ == "__main__": import socket try: main() except socket.error,e: if e.args[0] == 98: