Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/2023-compatibility'
Browse files Browse the repository at this point in the history
  • Loading branch information
bain3 committed Sep 2, 2023
2 parents 0d38cb6 + ddbeee1 commit ed2040c
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions pronotepy/pronoteAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,10 @@ def initialise(self) -> Tuple[Any, Any]:
"Unable to connect to pronote, please try again later"
)

# uuid
self.encryption.rsa_keys = {
"MR": self.attributes["MR"],
"ER": self.attributes["ER"],
}
uuid = base64.b64encode(
self.encryption.rsa_encrypt(self.encryption.aes_iv_temp)
self.encryption.aes_iv_temp
if self.root_site.startswith("https")
else self.encryption.rsa_encrypt(self.encryption.aes_iv_temp)
).decode()
# post
json_post = {"Uuid": uuid, "identifiantNav": None}
Expand Down Expand Up @@ -271,7 +268,7 @@ def _parse_html(self, html: bytes) -> dict:
key, value = attr.split(":")
attributes[key] = value.replace("'", "")

if "MR" not in attributes or "ER" not in attributes:
if "h" not in attributes:
raise ValueError("internal exception to retry -> cannot prase html")

return attributes
Expand Down Expand Up @@ -306,6 +303,10 @@ def _prepare_onglets(list_of_onglets): # type: ignore


class _Encryption(object):
# taken from eleve.js
RSA_1024_MODULO = 130337874517286041778445012253514395801341480334668979416920989365464528904618150245388048105865059387076357492684573172203245221386376405947824377827224846860699130638566643129067735803555082190977267155957271492183684665050351182476506458843580431717209261903043895605014125081521285387341454154194253026277
RSA_1024_EXPONENT = 65537

def __init__(self) -> None:
"""The encryption part of the API. You shouldn't have to use this normally."""
# aes
Expand Down Expand Up @@ -337,9 +338,7 @@ def aes_set_key(self, key: Optional[bytes] = None) -> None:
self.aes_key = MD5.new(key).digest()

def rsa_encrypt(self, data: bytes) -> bytes:
key = RSA.construct(
(int(self.rsa_keys["MR"], 16), int(self.rsa_keys["ER"], 16))
)
key = RSA.construct((self.RSA_1024_MODULO, self.RSA_1024_EXPONENT))
# noinspection PyTypeChecker
pkcs = PKCS1_v1_5.new(key)
return pkcs.encrypt(data)
Expand Down

0 comments on commit ed2040c

Please sign in to comment.