Skip to content

Commit

Permalink
Merge pull request #1486 from freakboy3742/winforms-tls
Browse files Browse the repository at this point in the history
Explicitly define allowed Winforms TLS protocols.
  • Loading branch information
freakboy3742 authored May 11, 2022
2 parents 938e5c1 + b8da0bd commit 5b15e08
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
18 changes: 17 additions & 1 deletion src/winforms/toga_winforms/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@
from toga import Key
from .keys import toga_to_winforms_key

from .libs import Threading, WinForms, shcore, user32, win_version
from .libs import (
SecurityProtocolType,
ServicePointManager,
Threading,
WinForms,
shcore,
user32,
win_version
)
from .libs.proactor import WinformsProactorEventLoop
from .window import Window

Expand Down Expand Up @@ -69,6 +77,14 @@ def create(self):
self.native.EnableVisualStyles()
self.native.SetCompatibleTextRenderingDefault(False)

# Ensure that TLS1.2 and TLS1.3 are enabled for HTTPS connections.
# For some reason, some Windows installs have these protocols
# turned off by default. SSL3, TLS1.0 and TLS1.1 are *not* enabled
# as they are deprecated protocols and their use should *not* be
# encouraged.
ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12
ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls13

self.interface.commands.add(
toga.Command(
lambda _: self.interface.about(),
Expand Down
2 changes: 2 additions & 0 deletions src/winforms/toga_winforms/libs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
PointF,
Rectangle,
RectangleF,
SecurityProtocolType,
ServicePointManager,
Single,
Size,
SolidBrush,
Expand Down
1 change: 1 addition & 0 deletions src/winforms/toga_winforms/libs/winforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@

from System.Threading.Tasks import Task, TaskScheduler # noqa: F401, E402

from System.Net import SecurityProtocolType, ServicePointManager # noqa: F401, E402

user32 = ctypes.windll.user32
# shcore dll not exist on some Windows versions
Expand Down
2 changes: 1 addition & 1 deletion src/winforms/toga_winforms/widgets/imageview.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ImageView(Widget):
def create(self):
self.native = WinForms.PictureBox()
self.native.interface = self.interface
self.native.SizeMode = WinForms.PictureBoxSizeMode.StretchImage
self.native.SizeMode = WinForms.PictureBoxSizeMode.Zoom

def set_image(self, image):
# If an image already exists, ensure it is destroyed
Expand Down

0 comments on commit 5b15e08

Please sign in to comment.