Commit 0019ab3 1 parent c75cb85 commit 0019ab3 Copy full SHA for 0019ab3
File tree 2 files changed +21
-0
lines changed
2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change 22
22
as_utc_from_local ,
23
23
get_configuration_url ,
24
24
get_latest_activity ,
25
+ get_ssl_context ,
25
26
update_doorbell_image_from_activity ,
26
27
update_lock_detail_from_activity ,
27
28
)
@@ -398,3 +399,8 @@ def test_get_configuration_url():
398
399
assert get_configuration_url (Brand .AUGUST ) == "https://account.august.com"
399
400
assert get_configuration_url (Brand .YALE_ACCESS ) == "https://account.august.com"
400
401
assert get_configuration_url (Brand .YALE_HOME ) == "https://account.aaecosystem.com"
402
+
403
+
404
+ def test_get_ssl_context ():
405
+ """Test getting the ssl context is cached."""
406
+ assert get_ssl_context () is get_ssl_context ()
Original file line number Diff line number Diff line change 1
1
import datetime
2
+ from functools import cache
3
+ import random
4
+ import ssl
2
5
from typing import Optional , Union
3
6
4
7
from .activity import (
@@ -112,3 +115,15 @@ def as_utc_from_local(dtime: datetime.datetime) -> datetime.datetime:
112
115
def get_configuration_url (brand : Brand ) -> str :
113
116
"""Return the configuration URL for the brand."""
114
117
return CONFIGURATION_URLS [brand ]
118
+
119
+
120
+ @cache
121
+ def get_ssl_context () -> ssl .SSLContext :
122
+ """Return an SSL context for cloudflare."""
123
+ context = ssl .create_default_context ()
124
+ ciphers = [cipher ["name" ] for cipher in context .get_ciphers ()]
125
+ default_ciphers = ciphers [:3 ]
126
+ backup_ciphers = ciphers [3 :]
127
+ random .shuffle (backup_ciphers )
128
+ context .set_ciphers (":" .join ((* default_ciphers , * backup_ciphers )))
129
+ return context
You can’t perform that action at this time.
0 commit comments