-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is a very limited implementation of IMAPv4rev1 (rfc3501). But this is sufficient for mutt, isync and thunderbird clients. Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
- Loading branch information
Showing
12 changed files
with
1,554 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/env python3 | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
# Copyright (C) 2023 Alexey Gladkov <gladkov.alexey@gmail.com> | ||
|
||
__author__ = 'Alexey Gladkov <gladkov.alexey@gmail.com>' | ||
|
||
import base64 | ||
import binascii | ||
import hashlib | ||
import hmac | ||
import os | ||
import random | ||
import time | ||
|
||
from typing import Callable, Tuple, Any | ||
|
||
import jiramail | ||
|
||
logger = jiramail.logger | ||
|
||
def cram_md5(user: str, password: str, interact: Callable[[Any, str], str], data: Any) -> Tuple[bool, str]: | ||
pid = os.getpid() | ||
now = time.time_ns() | ||
rnd = random.randrange(2**32 - 1) | ||
shared = f"<{pid}.{now}.{rnd}@jiramail>" | ||
|
||
line = interact(data, base64.b64encode(shared.encode()).decode()) | ||
|
||
try: | ||
buf = base64.standard_b64decode(line).decode() | ||
except binascii.Error: | ||
return (False, "couldn't decode your credentials") | ||
|
||
fields = buf.split(" ") | ||
|
||
if len(fields) != 2: | ||
return (False, "wrong number of fields in the token") | ||
|
||
hexdigest = hmac.new(password.encode(), | ||
shared.encode(), | ||
hashlib.md5).hexdigest() | ||
|
||
if hmac.compare_digest(user, fields[0]) and hmac.compare_digest(hexdigest, fields[1]): | ||
return (True, "authentication successful") | ||
|
||
return (False, "authenticate failure") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.