6 from .exceptions
import IrodsError, IrodsWarning
29 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
30 'A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
'I',
'J',
'K',
'L',
'M',
31 'N',
'O',
'P',
'Q',
'R',
'S',
'T',
'U',
'V',
'W',
'X',
'Y',
'Z',
32 'a',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'i',
'j',
'k',
'l',
'm',
33 'n',
'o',
'p',
'q',
'r',
's',
't',
'u',
'v',
'w',
'x',
'y',
'z',
34 '!',
'"',
'#',
'$',
'%',
'&',
"'",
'(',
')',
'*',
'+',
',',
'-',
'.',
'/'
37 maximum_password_length = 42
39 default_password_key =
'a9_3fker'
40 default_scramble_prefix =
'.E_'
46 seq_index = ord(s[6]) - ord(
'e')
47 seq = seq_list[seq_index]
62 encoded_string = s[7:]
66 for c
in encoded_string:
71 offset = ((seq >> bitshift) & 0x1f) + (uid & 0xf5f)
80 wheel_index = (len(wheel) + wheel.index(c) - offset) % len(wheel)
81 decoded_string += wheel[wheel_index]
89 if len(s) > maximum_password_length:
90 raise IrodsException(
"Password exceeds maximum length of {maximum_password_length} characters.".format(**locals()))
94 mtime =
int(time.time())
111 seq = seq_list[seq_index]
117 to_encode += chr(ord(
'S') - ((seq_index & 0x7) * 2))
121 to_encode += chr(((mtime >> 4) & 0xf) + ord(
'a'))
122 to_encode += chr((mtime & 0xf) + ord(
'a'))
123 to_encode += chr(((mtime >> 12) & 0xf) + ord(
'a'))
124 to_encode += chr(((mtime >> 8) & 0xf) + ord(
'a'))
138 offset = ((seq >> bitshift) & 0x1f) + (uid & 0xf5f)
147 wheel_index = (wheel.index(c) + offset) % len(wheel)
148 encoded_string += wheel[wheel_index]
153 encoded_string = chr(seq_index + ord(
'e')).
join([
160 encoded_string += chr(0)
162 return encoded_string
167 md5_hasher = hashlib.md5()
170 md5_hasher.update(key.ljust(100, chr(0))[:100].
encode(
'ascii'))
171 first = md5_hasher.digest()
173 md5_hasher = hashlib.md5()
174 md5_hasher.update(first)
175 second = md5_hasher.digest()
177 md5_hasher = hashlib.md5()
178 md5_hasher.update(first + second)
179 third = md5_hasher.digest()
181 return first + second + third + third
184 def unscramble(s, key=default_password_key, scramble_prefix=default_scramble_prefix, block_chaining=False):
186 key=default_password_key
188 if not s.startswith(scramble_prefix):
194 to_unscramble = s[len(scramble_prefix):]
198 encoder_ring_index = 0
203 unscrambled_string =
''
204 for c
in to_unscramble:
207 wheel_index = (wheel.index(c) - six.indexbytes(encoder_ring, encoder_ring_index % 61) - chain) % len(wheel)
208 unscrambled_string += wheel[wheel_index]
210 chain = ord(c) & 0xff
212 unscrambled_string += c
213 encoder_ring_index += 1
215 return unscrambled_string
218 def scramble(s, key=default_password_key, scramble_prefix=default_scramble_prefix, block_chaining=False):
219 if len(s) > maximum_password_length:
220 raise IrodsException(
"Password exceeds maximum length of {maximum_password_length} characters.".format(**locals()))
222 key=default_password_key
228 encoder_ring_index = 0
233 scrambled_string =
''
234 for c
in to_scramble:
237 wheel_index = (wheel.index(c) + six.indexbytes(encoder_ring, encoder_ring_index % 61) + chain) % len(wheel)
238 scrambled_string += wheel[wheel_index]
240 chain = ord(scrambled_string[-1]) & 0xff
242 scrambled_string += c
243 encoder_ring_index += 1
245 return scramble_prefix + scrambled_string