Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
plain.py71 linesDownload Raw Back to sasl
1"""
2"""
3
4# Created on 2014.01.04
5#
6# Author: Giovanni Cannata
7#
8# Copyright 2014 - 2020 Giovanni Cannata
9#
10# This file is part of ldap3.
11#
12# ldap3 is free software: you can redistribute it and/or modify
13# it under the terms of the GNU Lesser General Public License as published
14# by the Free Software Foundation, either version 3 of the License, or
15# (at your option) any later version.
16#
17# ldap3 is distributed in the hope that it will be useful,
18# but WITHOUT ANY WARRANTY; without even the implied warranty of
19# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20# GNU Lesser General Public License for more details.
21#
22# You should have received a copy of the GNU Lesser General Public License
23# along with ldap3 in the COPYING and COPYING.LESSER files.
24# If not, see <http://www.gnu.org/licenses/>.
25
26# payload for PLAIN mechanism
27# message   = [authzid] UTF8NUL authcid UTF8NUL passwd
28# authcid   = 1*SAFE ; MUST accept up to 255 octets
29# authzid   = 1*SAFE ; MUST accept up to 255 octets
30# passwd    = 1*SAFE ; MUST accept up to 255 octets
31# UTF8NUL   = %x00 ; UTF-8 encoded NUL character
32#
33# SAFE      = UTF1 / UTF2 / UTF3 / UTF4
34#             ;; any UTF-8 encoded Unicode character except NUL
35#
36# UTF1      = %x01-7F ;; except NUL
37# UTF2      = %xC2-DF UTF0
38# UTF3      = %xE0 %xA0-BF UTF0 / %xE1-EC 2(UTF0) /
39#             %xED %x80-9F UTF0 / %xEE-EF 2(UTF0)
40# UTF4      = %xF0 %x90-BF 2(UTF0) / %xF1-F3 3(UTF0) /
41#             %xF4 %x80-8F 2(UTF0)
42# UTF0      = %x80-BF
43
44from ...protocol.sasl.sasl import send_sasl_negotiation
45from .sasl import sasl_prep
46from ...utils.conv import to_raw, to_unicode
47
48
49def sasl_plain(connection, controls):
50    authzid = connection.sasl_credentials[0]
51    authcid = connection.sasl_credentials[1]
52    passwd = connection.sasl_credentials[2]
53
54    payload = b''
55    if authzid:
56        payload += to_raw(sasl_prep(to_unicode(authzid)))
57
58    payload += b'\0'
59
60    if authcid:
61        payload += to_raw(sasl_prep(to_unicode(authcid)))
62
63    payload += b'\0'
64
65    if passwd:
66        payload += to_raw(sasl_prep(to_unicode(passwd)))
67
68    result = send_sasl_negotiation(connection, controls, payload)
69
70    return result
71 
codekingpro/portable-devtools · Team Ai