SslSocket.hx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package python.net;
  2. import python.lib.Ssl;
  3. import python.lib.ssl.Purpose;
  4. import python.lib.socket.Socket as PSocket;
  5. import sys.net.Host;
  6. class SslSocket extends sys.net.Socket {
  7. var hostName:String;
  8. override function __initSocket ():Void {
  9. #if (python_version >= 3.4)
  10. var context = Ssl.create_default_context(Purpose.SERVER_AUTH);
  11. #else
  12. // hopefully these options are good enough
  13. var context = new python.lib.ssl.SSLContext(Ssl.PROTOCOL_SSLv23);
  14. context.verify_mode = Ssl.CERT_REQUIRED;
  15. context.set_default_verify_paths();
  16. context.options |= Ssl.OP_NO_SSLv2;
  17. context.options |= Ssl.OP_NO_SSLv3;
  18. context.options |= Ssl.OP_NO_COMPRESSION;
  19. #end
  20. context.options |= Ssl.OP_NO_TLSv1 #if (python_version >= 3.4) | Ssl.OP_NO_TLSv1_1 #end; // python 3.4 | Ssl.OP_NO_TLSv1_1;
  21. __s = new PSocket();
  22. __s = context.wrap_socket(__s,
  23. false,
  24. true,
  25. true,
  26. this.hostName
  27. );
  28. }
  29. public override function connect( host : Host, port : Int ) : Void {
  30. this.hostName = host.host;
  31. super.connect(host, port);
  32. }
  33. public override function bind( host : Host, port : Int ) : Void {
  34. throw "not implemented";
  35. }
  36. }