libpass 1.7.5.post0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. libpass-1.7.5.post0.dist-info/METADATA +81 -0
  2. libpass-1.7.5.post0.dist-info/RECORD +69 -0
  3. libpass-1.7.5.post0.dist-info/WHEEL +4 -0
  4. libpass-1.7.5.post0.dist-info/licenses/LICENSE +116 -0
  5. passlib/__init__.py +3 -0
  6. passlib/_data/wordsets/bip39.txt +2049 -0
  7. passlib/_data/wordsets/eff_long.txt +7776 -0
  8. passlib/_data/wordsets/eff_prefixed.txt +1296 -0
  9. passlib/_data/wordsets/eff_short.txt +1296 -0
  10. passlib/_setup/__init__.py +1 -0
  11. passlib/_setup/stamp.py +159 -0
  12. passlib/apache.py +1185 -0
  13. passlib/apps.py +260 -0
  14. passlib/context.py +2066 -0
  15. passlib/crypto/__init__.py +1 -0
  16. passlib/crypto/_blowfish/__init__.py +171 -0
  17. passlib/crypto/_blowfish/_gen_files.py +256 -0
  18. passlib/crypto/_blowfish/base.py +1239 -0
  19. passlib/crypto/_blowfish/unrolled.py +1691 -0
  20. passlib/crypto/_md4.py +249 -0
  21. passlib/crypto/des.py +2283 -0
  22. passlib/crypto/digest.py +1111 -0
  23. passlib/crypto/scrypt/__init__.py +299 -0
  24. passlib/crypto/scrypt/_builtin.py +254 -0
  25. passlib/crypto/scrypt/_gen_files.py +161 -0
  26. passlib/crypto/scrypt/_salsa.py +188 -0
  27. passlib/exc.py +432 -0
  28. passlib/ext/__init__.py +1 -0
  29. passlib/ext/django/__init__.py +6 -0
  30. passlib/ext/django/models.py +38 -0
  31. passlib/ext/django/utils.py +1326 -0
  32. passlib/handlers/__init__.py +1 -0
  33. passlib/handlers/argon2.py +1119 -0
  34. passlib/handlers/bcrypt.py +1217 -0
  35. passlib/handlers/cisco.py +450 -0
  36. passlib/handlers/des_crypt.py +642 -0
  37. passlib/handlers/digests.py +184 -0
  38. passlib/handlers/django.py +545 -0
  39. passlib/handlers/fshp.py +223 -0
  40. passlib/handlers/ldap_digests.py +379 -0
  41. passlib/handlers/md5_crypt.py +375 -0
  42. passlib/handlers/misc.py +224 -0
  43. passlib/handlers/mssql.py +258 -0
  44. passlib/handlers/mysql.py +136 -0
  45. passlib/handlers/oracle.py +177 -0
  46. passlib/handlers/pbkdf2.py +521 -0
  47. passlib/handlers/phpass.py +142 -0
  48. passlib/handlers/postgres.py +61 -0
  49. passlib/handlers/roundup.py +33 -0
  50. passlib/handlers/scram.py +589 -0
  51. passlib/handlers/scrypt.py +413 -0
  52. passlib/handlers/sha1_crypt.py +173 -0
  53. passlib/handlers/sha2_crypt.py +657 -0
  54. passlib/handlers/sun_md5_crypt.py +387 -0
  55. passlib/handlers/windows.py +349 -0
  56. passlib/hash.py +111 -0
  57. passlib/hosts.py +112 -0
  58. passlib/ifc.py +354 -0
  59. passlib/pwd.py +813 -0
  60. passlib/registry.py +583 -0
  61. passlib/totp.py +1968 -0
  62. passlib/utils/__init__.py +1221 -0
  63. passlib/utils/binary.py +897 -0
  64. passlib/utils/compat/__init__.py +200 -0
  65. passlib/utils/decor.py +234 -0
  66. passlib/utils/des.py +35 -0
  67. passlib/utils/handlers.py +2857 -0
  68. passlib/utils/md4.py +34 -0
  69. passlib/utils/pbkdf2.py +188 -0
@@ -0,0 +1,387 @@
1
+ """passlib.handlers.sun_md5_crypt - Sun's Md5 Crypt, used on Solaris
2
+
3
+ .. warning::
4
+
5
+ This implementation may not reproduce
6
+ the original Solaris behavior in some border cases.
7
+ See documentation for details.
8
+ """
9
+
10
+ # =============================================================================
11
+ # imports
12
+ # =============================================================================
13
+ # core
14
+ from hashlib import md5
15
+ import re
16
+ import logging
17
+
18
+ log = logging.getLogger(__name__)
19
+ from warnings import warn
20
+
21
+ # site
22
+ # pkg
23
+ from passlib.utils import to_unicode
24
+ from passlib.utils.binary import h64
25
+ from passlib.utils.compat import str_to_bascii
26
+ import passlib.utils.handlers as uh
27
+
28
+ # local
29
+ __all__ = [
30
+ "sun_md5_crypt",
31
+ ]
32
+
33
+ # =============================================================================
34
+ # backend
35
+ # =============================================================================
36
+ # constant data used by alg - Hamlet act 3 scene 1 + null char
37
+ # exact bytes as in http://www.ibiblio.org/pub/docs/books/gutenberg/etext98/2ws2610.txt
38
+ # from Project Gutenberg.
39
+
40
+ MAGIC_HAMLET = (
41
+ b"To be, or not to be,--that is the question:--\n"
42
+ b"Whether 'tis nobler in the mind to suffer\n"
43
+ b"The slings and arrows of outrageous fortune\n"
44
+ b"Or to take arms against a sea of troubles,\n"
45
+ b"And by opposing end them?--To die,--to sleep,--\n"
46
+ b"No more; and by a sleep to say we end\n"
47
+ b"The heartache, and the thousand natural shocks\n"
48
+ b"That flesh is heir to,--'tis a consummation\n"
49
+ b"Devoutly to be wish'd. To die,--to sleep;--\n"
50
+ b"To sleep! perchance to dream:--ay, there's the rub;\n"
51
+ b"For in that sleep of death what dreams may come,\n"
52
+ b"When we have shuffled off this mortal coil,\n"
53
+ b"Must give us pause: there's the respect\n"
54
+ b"That makes calamity of so long life;\n"
55
+ b"For who would bear the whips and scorns of time,\n"
56
+ b"The oppressor's wrong, the proud man's contumely,\n"
57
+ b"The pangs of despis'd love, the law's delay,\n"
58
+ b"The insolence of office, and the spurns\n"
59
+ b"That patient merit of the unworthy takes,\n"
60
+ b"When he himself might his quietus make\n"
61
+ b"With a bare bodkin? who would these fardels bear,\n"
62
+ b"To grunt and sweat under a weary life,\n"
63
+ b"But that the dread of something after death,--\n"
64
+ b"The undiscover'd country, from whose bourn\n"
65
+ b"No traveller returns,--puzzles the will,\n"
66
+ b"And makes us rather bear those ills we have\n"
67
+ b"Than fly to others that we know not of?\n"
68
+ b"Thus conscience does make cowards of us all;\n"
69
+ b"And thus the native hue of resolution\n"
70
+ b"Is sicklied o'er with the pale cast of thought;\n"
71
+ b"And enterprises of great pith and moment,\n"
72
+ b"With this regard, their currents turn awry,\n"
73
+ b"And lose the name of action.--Soft you now!\n"
74
+ b"The fair Ophelia!--Nymph, in thy orisons\n"
75
+ b"Be all my sins remember'd.\n\x00" # <- apparently null at end of C string is included (test vector won't pass otherwise)
76
+ )
77
+
78
+ # NOTE: these sequences are pre-calculated iteration ranges used by X & Y loops w/in rounds function below
79
+ xr = range(7)
80
+ _XY_ROUNDS = [
81
+ tuple((i, i, i + 3) for i in xr), # xrounds 0
82
+ tuple((i, i + 1, i + 4) for i in xr), # xrounds 1
83
+ tuple((i, i + 8, (i + 11) & 15) for i in xr), # yrounds 0
84
+ tuple((i, (i + 9) & 15, (i + 12) & 15) for i in xr), # yrounds 1
85
+ ]
86
+ del xr
87
+
88
+
89
+ def raw_sun_md5_crypt(secret, rounds, salt):
90
+ """given secret & salt, return encoded sun-md5-crypt checksum"""
91
+ global MAGIC_HAMLET
92
+ assert isinstance(secret, bytes)
93
+ assert isinstance(salt, bytes)
94
+
95
+ # validate rounds
96
+ if rounds <= 0:
97
+ rounds = 0
98
+ real_rounds = 4096 + rounds
99
+ # NOTE: spec seems to imply max 'rounds' is 2**32-1
100
+
101
+ # generate initial digest to start off round 0.
102
+ # NOTE: algorithm 'salt' includes full config string w/ trailing "$"
103
+ result = md5(secret + salt).digest()
104
+ assert len(result) == 16
105
+
106
+ # NOTE: many things in this function have been inlined (to speed up the loop
107
+ # as much as possible), to the point that this code barely resembles
108
+ # the algorithm as described in the docs. in particular:
109
+ #
110
+ # * all accesses to a given bit have been inlined using the formula
111
+ # rbitval(bit) = (rval((bit>>3) & 15) >> (bit & 7)) & 1
112
+ #
113
+ # * the calculation of coinflip value R has been inlined
114
+ #
115
+ # * the conditional division of coinflip value V has been inlined as
116
+ # a shift right of 0 or 1.
117
+ #
118
+ # * the i, i+3, etc iterations are precalculated in lists.
119
+ #
120
+ # * the round-based conditional division of x & y is now performed
121
+ # by choosing an appropriate precalculated list, so that it only
122
+ # calculates the 7 bits which will actually be used.
123
+ #
124
+ X_ROUNDS_0, X_ROUNDS_1, Y_ROUNDS_0, Y_ROUNDS_1 = _XY_ROUNDS
125
+
126
+ # NOTE: % appears to be *slightly* slower than &, so we prefer & if possible
127
+
128
+ round = 0
129
+ while round < real_rounds:
130
+ # convert last result byte string to list of byte-ints for easy access
131
+ rval = [c for c in result].__getitem__
132
+
133
+ # build up X bit by bit
134
+ x = 0
135
+ xrounds = (
136
+ X_ROUNDS_1 if (rval((round >> 3) & 15) >> (round & 7)) & 1 else X_ROUNDS_0
137
+ )
138
+ for i, ia, ib in xrounds:
139
+ a = rval(ia)
140
+ b = rval(ib)
141
+ v = rval((a >> (b % 5)) & 15) >> ((b >> (a & 7)) & 1)
142
+ x |= ((rval((v >> 3) & 15) >> (v & 7)) & 1) << i
143
+
144
+ # build up Y bit by bit
145
+ y = 0
146
+ yrounds = (
147
+ Y_ROUNDS_1
148
+ if (rval(((round + 64) >> 3) & 15) >> (round & 7)) & 1
149
+ else Y_ROUNDS_0
150
+ )
151
+ for i, ia, ib in yrounds:
152
+ a = rval(ia)
153
+ b = rval(ib)
154
+ v = rval((a >> (b % 5)) & 15) >> ((b >> (a & 7)) & 1)
155
+ y |= ((rval((v >> 3) & 15) >> (v & 7)) & 1) << i
156
+
157
+ # extract x'th and y'th bit, xoring them together to yeild "coin flip"
158
+ coin = ((rval(x >> 3) >> (x & 7)) ^ (rval(y >> 3) >> (y & 7))) & 1
159
+
160
+ # construct hash for this round
161
+ h = md5(result)
162
+ if coin:
163
+ h.update(MAGIC_HAMLET)
164
+ h.update(str(round).encode("ascii"))
165
+ result = h.digest()
166
+
167
+ round += 1
168
+
169
+ # encode output
170
+ return h64.encode_transposed_bytes(result, _chk_offsets)
171
+
172
+
173
+ # NOTE: same offsets as md5_crypt
174
+ _chk_offsets = (
175
+ 12,
176
+ 6,
177
+ 0,
178
+ 13,
179
+ 7,
180
+ 1,
181
+ 14,
182
+ 8,
183
+ 2,
184
+ 15,
185
+ 9,
186
+ 3,
187
+ 5,
188
+ 10,
189
+ 4,
190
+ 11,
191
+ )
192
+
193
+
194
+ # =============================================================================
195
+ # handler
196
+ # =============================================================================
197
+ class sun_md5_crypt(uh.HasRounds, uh.HasSalt, uh.GenericHandler):
198
+ """This class implements the Sun-MD5-Crypt password hash, and follows the :ref:`password-hash-api`.
199
+
200
+ It supports a variable-length salt, and a variable number of rounds.
201
+
202
+ The :meth:`~passlib.ifc.PasswordHash.using` method accepts the following optional keywords:
203
+
204
+ :type salt: str
205
+ :param salt:
206
+ Optional salt string.
207
+ If not specified, a salt will be autogenerated (this is recommended).
208
+ If specified, it must be drawn from the regexp range ``[./0-9A-Za-z]``.
209
+
210
+ :type salt_size: int
211
+ :param salt_size:
212
+ If no salt is specified, this parameter can be used to specify
213
+ the size (in characters) of the autogenerated salt.
214
+ It currently defaults to 8.
215
+
216
+ :type rounds: int
217
+ :param rounds:
218
+ Optional number of rounds to use.
219
+ Defaults to 34000, must be between 0 and 4294963199, inclusive.
220
+
221
+ :type bare_salt: bool
222
+ :param bare_salt:
223
+ Optional flag used to enable an alternate salt digest behavior
224
+ used by some hash strings in this scheme.
225
+ This flag can be ignored by most users.
226
+ Defaults to ``False``.
227
+ (see :ref:`smc-bare-salt` for details).
228
+
229
+ :type relaxed: bool
230
+ :param relaxed:
231
+ By default, providing an invalid value for one of the other
232
+ keywords will result in a :exc:`ValueError`. If ``relaxed=True``,
233
+ and the error can be corrected, a :exc:`~passlib.exc.PasslibHashWarning`
234
+ will be issued instead. Correctable errors include ``rounds``
235
+ that are too small or too large, and ``salt`` strings that are too long.
236
+
237
+ .. versionadded:: 1.6
238
+ """
239
+
240
+ # ===================================================================
241
+ # class attrs
242
+ # ===================================================================
243
+ name = "sun_md5_crypt"
244
+ setting_kwds = ("salt", "rounds", "bare_salt", "salt_size")
245
+ checksum_chars = uh.HASH64_CHARS
246
+ checksum_size = 22
247
+
248
+ # NOTE: docs say max password length is 255.
249
+ # release 9u2
250
+
251
+ # NOTE: not sure if original crypt has a salt size limit,
252
+ # all instances that have been seen use 8 chars.
253
+ default_salt_size = 8
254
+ max_salt_size = None
255
+ salt_chars = uh.HASH64_CHARS
256
+
257
+ default_rounds = 34000 # current passlib default
258
+ min_rounds = 0
259
+ max_rounds = 4294963199 ##2**32-1-4096
260
+ # XXX: ^ not sure what it does if past this bound... does 32 int roll over?
261
+ rounds_cost = "linear"
262
+
263
+ ident_values = ("$md5$", "$md5,")
264
+
265
+ # ===================================================================
266
+ # instance attrs
267
+ # ===================================================================
268
+ bare_salt = False # flag to indicate legacy hashes that lack "$$" suffix
269
+
270
+ # ===================================================================
271
+ # constructor
272
+ # ===================================================================
273
+ def __init__(self, bare_salt=False, **kwds):
274
+ self.bare_salt = bare_salt
275
+ super().__init__(**kwds)
276
+
277
+ # ===================================================================
278
+ # internal helpers
279
+ # ===================================================================
280
+ @classmethod
281
+ def identify(cls, hash):
282
+ hash = uh.to_unicode_for_identify(hash)
283
+ return hash.startswith(cls.ident_values)
284
+
285
+ @classmethod
286
+ def from_string(cls, hash):
287
+ hash = to_unicode(hash, "ascii", "hash")
288
+
289
+ #
290
+ # detect if hash specifies rounds value.
291
+ # if so, parse and validate it.
292
+ # by end, set 'rounds' to int value, and 'tail' containing salt+chk
293
+ #
294
+ if hash.startswith("$md5$"):
295
+ rounds = 0
296
+ salt_idx = 5
297
+ elif hash.startswith("$md5,rounds="):
298
+ idx = hash.find("$", 12)
299
+ if idx == -1:
300
+ raise uh.exc.MalformedHashError(cls, "unexpected end of rounds")
301
+ rstr = hash[12:idx]
302
+ try:
303
+ rounds = int(rstr)
304
+ except ValueError:
305
+ raise uh.exc.MalformedHashError(cls, "bad rounds")
306
+ if rstr != str(rounds):
307
+ raise uh.exc.ZeroPaddedRoundsError(cls)
308
+ if rounds == 0:
309
+ # NOTE: not sure if this is forbidden by spec or not;
310
+ # but allowing it would complicate things,
311
+ # and it should never occur anyways.
312
+ raise uh.exc.MalformedHashError(cls, "explicit zero rounds")
313
+ salt_idx = idx + 1
314
+ else:
315
+ raise uh.exc.InvalidHashError(cls)
316
+
317
+ #
318
+ # salt/checksum separation is kinda weird,
319
+ # to deal cleanly with some backward-compatible workarounds
320
+ # implemented by original implementation.
321
+ #
322
+ chk_idx = hash.rfind("$", salt_idx)
323
+ if chk_idx == -1:
324
+ # ''-config for $-hash
325
+ salt = hash[salt_idx:]
326
+ chk = None
327
+ bare_salt = True
328
+ elif chk_idx == len(hash) - 1:
329
+ if chk_idx > salt_idx and hash[-2] == "$":
330
+ raise uh.exc.MalformedHashError(cls, "too many '$' separators")
331
+ # $-config for $$-hash
332
+ salt = hash[salt_idx:-1]
333
+ chk = None
334
+ bare_salt = False
335
+ elif chk_idx > 0 and hash[chk_idx - 1] == "$":
336
+ # $$-hash
337
+ salt = hash[salt_idx : chk_idx - 1]
338
+ chk = hash[chk_idx + 1 :]
339
+ bare_salt = False
340
+ else:
341
+ # $-hash
342
+ salt = hash[salt_idx:chk_idx]
343
+ chk = hash[chk_idx + 1 :]
344
+ bare_salt = True
345
+
346
+ return cls(
347
+ rounds=rounds,
348
+ salt=salt,
349
+ checksum=chk,
350
+ bare_salt=bare_salt,
351
+ )
352
+
353
+ def to_string(self, _withchk=True):
354
+ ss = "" if self.bare_salt else "$"
355
+ rounds = self.rounds
356
+ if rounds > 0:
357
+ hash = "$md5,rounds=%d$%s%s" % (rounds, self.salt, ss)
358
+ else:
359
+ hash = "$md5$%s%s" % (self.salt, ss)
360
+ if _withchk:
361
+ chk = self.checksum
362
+ hash = "%s$%s" % (hash, chk)
363
+ return hash
364
+
365
+ # ===================================================================
366
+ # primary interface
367
+ # ===================================================================
368
+ # TODO: if we're on solaris, check for native crypt() support.
369
+ # this will require extra testing, to make sure native crypt
370
+ # actually behaves correctly. of particular importance:
371
+ # when using ""-config, make sure to append "$x" to string.
372
+
373
+ def _calc_checksum(self, secret):
374
+ # NOTE: no reference for how sun_md5_crypt handles unicode
375
+ if isinstance(secret, str):
376
+ secret = secret.encode("utf-8")
377
+ config = str_to_bascii(self.to_string(_withchk=False))
378
+ return raw_sun_md5_crypt(secret, self.rounds, config).decode("ascii")
379
+
380
+ # ===================================================================
381
+ # eoc
382
+ # ===================================================================
383
+
384
+
385
+ # =============================================================================
386
+ # eof
387
+ # =============================================================================