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
passlib/ifc.py ADDED
@@ -0,0 +1,354 @@
1
+ """passlib.ifc - abstract interfaces used by Passlib"""
2
+
3
+ # =============================================================================
4
+ # imports
5
+ # =============================================================================
6
+ # core
7
+ import logging
8
+
9
+ log = logging.getLogger(__name__)
10
+ import sys
11
+
12
+ # site
13
+ # pkg
14
+ from passlib.utils.decor import deprecated_method
15
+
16
+ # local
17
+ __all__ = [
18
+ "PasswordHash",
19
+ ]
20
+
21
+ # =============================================================================
22
+ # PasswordHash interface
23
+ # =============================================================================
24
+ from abc import ABC, abstractmethod
25
+
26
+ # XXX: mark some attributes with abstractproperty()?
27
+ # or would type hinting be enough?
28
+
29
+
30
+ # XXX: rename this to PasswordHasher?
31
+ class PasswordHash(ABC):
32
+ """This class describes an abstract interface which all password hashes
33
+ in Passlib adhere to. Under Python 2.6 and up, this is an actual
34
+ Abstract Base Class built using the :mod:`!abc` module.
35
+
36
+ See the Passlib docs for full documentation.
37
+ """
38
+
39
+ # ===================================================================
40
+ # class attributes
41
+ # ===================================================================
42
+
43
+ # ---------------------------------------------------------------
44
+ # general information
45
+ # ---------------------------------------------------------------
46
+ ##name
47
+ ##setting_kwds
48
+ ##context_kwds
49
+
50
+ #: flag which indicates this hasher matches a "disabled" hash
51
+ #: (e.g. unix_disabled, or django_disabled); and doesn't actually
52
+ #: depend on the provided password.
53
+ is_disabled = False
54
+
55
+ #: Should be None, or a positive integer indicating hash
56
+ #: doesn't support secrets larger than this value.
57
+ #: Whether hash throws error or silently truncates secret
58
+ #: depends on .truncate_error and .truncate_verify_reject flags below.
59
+ #: NOTE: calls may treat as boolean, since value will never be 0.
60
+ #: .. versionadded:: 1.7
61
+ #: .. TODO: passlib 1.8: deprecate/rename this attr to "max_secret_size"?
62
+ truncate_size = None
63
+
64
+ # NOTE: these next two default to the optimistic "ideal",
65
+ # most hashes in passlib have to default to False
66
+ # for backward compat and/or expected behavior with existing hashes.
67
+
68
+ #: If True, .hash() should throw a :exc:`~passlib.exc.PasswordSizeError` for
69
+ #: any secrets larger than .truncate_size. Many hashers default to False
70
+ #: for historical / compatibility purposes, indicating they will silently
71
+ #: truncate instead. All such hashers SHOULD support changing
72
+ #: the policy via ``.using(truncate_error=True)``.
73
+ #: .. versionadded:: 1.7
74
+ #: .. TODO: passlib 1.8: deprecate/rename this attr to "truncate_hash_error"?
75
+ truncate_error = True
76
+
77
+ #: If True, .verify() should reject secrets larger than max_password_size.
78
+ #: Many hashers default to False for historical / compatibility purposes,
79
+ #: indicating they will match on the truncated portion instead.
80
+ #: .. versionadded:: 1.7.1
81
+ truncate_verify_reject = True
82
+
83
+ # ---------------------------------------------------------------
84
+ # salt information -- if 'salt' in setting_kwds
85
+ # ---------------------------------------------------------------
86
+ ##min_salt_size
87
+ ##max_salt_size
88
+ ##default_salt_size
89
+ ##salt_chars
90
+ ##default_salt_chars
91
+
92
+ # ---------------------------------------------------------------
93
+ # rounds information -- if 'rounds' in setting_kwds
94
+ # ---------------------------------------------------------------
95
+ ##min_rounds
96
+ ##max_rounds
97
+ ##default_rounds
98
+ ##rounds_cost
99
+
100
+ # ---------------------------------------------------------------
101
+ # encoding info -- if 'encoding' in context_kwds
102
+ # ---------------------------------------------------------------
103
+ ##default_encoding
104
+
105
+ # ===================================================================
106
+ # primary methods
107
+ # ===================================================================
108
+ @classmethod
109
+ @abstractmethod
110
+ def hash(
111
+ cls,
112
+ secret, # *
113
+ **setting_and_context_kwds,
114
+ ): # pragma: no cover -- abstract method
115
+ r"""
116
+ Hash secret, returning result.
117
+ Should handle generating salt, etc, and should return string
118
+ containing identifier, salt & other configuration, as well as digest.
119
+
120
+ :param \\*\\*settings_kwds:
121
+
122
+ Pass in settings to customize configuration of resulting hash.
123
+
124
+ .. deprecated:: 1.7
125
+
126
+ Starting with Passlib 1.7, callers should no longer pass settings keywords
127
+ (e.g. ``rounds`` or ``salt`` directly to :meth:`!hash`); should use
128
+ ``.using(**settings).hash(secret)`` construction instead.
129
+
130
+ Support will be removed in Passlib 2.0.
131
+
132
+ :param \\*\\*context_kwds:
133
+
134
+ Specific algorithms may require context-specific information (such as the user login).
135
+ """
136
+ # FIXME: need stub for classes that define .encrypt() instead ...
137
+ # this should call .encrypt(), and check for recursion back to here.
138
+ raise NotImplementedError("must be implemented by subclass")
139
+
140
+ @deprecated_method(deprecated="1.7", removed="2.0", replacement=".hash()")
141
+ @classmethod
142
+ def encrypt(cls, *args, **kwds):
143
+ """
144
+ Legacy alias for :meth:`hash`.
145
+
146
+ .. deprecated:: 1.7
147
+ This method was renamed to :meth:`!hash` in version 1.7.
148
+ This alias will be removed in version 2.0, and should only
149
+ be used for compatibility with Passlib 1.3 - 1.6.
150
+ """
151
+ return cls.hash(*args, **kwds)
152
+
153
+ # XXX: could provide default implementation which hands value to
154
+ # hash(), and then does constant-time comparision on the result
155
+ # (after making both are same string type)
156
+ @classmethod
157
+ @abstractmethod
158
+ def verify(
159
+ cls, secret, hash, **context_kwds
160
+ ): # pragma: no cover -- abstract method
161
+ """verify secret against hash, returns True/False"""
162
+ raise NotImplementedError("must be implemented by subclass")
163
+
164
+ # ===================================================================
165
+ # configuration
166
+ # ===================================================================
167
+ @classmethod
168
+ @abstractmethod
169
+ def using(cls, relaxed=False, **kwds):
170
+ """
171
+ Return another hasher object (typically a subclass of the current one),
172
+ which integrates the configuration options specified by ``kwds``.
173
+ This should *always* return a new object, even if no configuration options are changed.
174
+
175
+ .. todo::
176
+
177
+ document which options are accepted.
178
+
179
+ :returns:
180
+ typically returns a subclass for most hasher implementations.
181
+
182
+ .. todo::
183
+
184
+ add this method to main documentation.
185
+ """
186
+ raise NotImplementedError("must be implemented by subclass")
187
+
188
+ # ===================================================================
189
+ # migration
190
+ # ===================================================================
191
+ @classmethod
192
+ def needs_update(cls, hash, secret=None):
193
+ """
194
+ check if hash's configuration is outside desired bounds,
195
+ or contains some other internal option which requires
196
+ updating the password hash.
197
+
198
+ :param hash:
199
+ hash string to examine
200
+
201
+ :param secret:
202
+ optional secret known to have verified against the provided hash.
203
+ (this is used by some hashes to detect legacy algorithm mistakes).
204
+
205
+ :return:
206
+ whether secret needs re-hashing.
207
+
208
+ .. versionadded:: 1.7
209
+ """
210
+ # by default, always report that we don't need update
211
+ return False
212
+
213
+ # ===================================================================
214
+ # additional methods
215
+ # ===================================================================
216
+ @classmethod
217
+ @abstractmethod
218
+ def identify(cls, hash): # pragma: no cover -- abstract method
219
+ """check if hash belongs to this scheme, returns True/False"""
220
+ raise NotImplementedError("must be implemented by subclass")
221
+
222
+ @deprecated_method(deprecated="1.7", removed="2.0")
223
+ @classmethod
224
+ def genconfig(cls, **setting_kwds): # pragma: no cover -- abstract method
225
+ """
226
+ compile settings into a configuration string for genhash()
227
+
228
+ .. deprecated:: 1.7
229
+
230
+ As of 1.7, this method is deprecated, and slated for complete removal in Passlib 2.0.
231
+
232
+ For all known real-world uses, hashing a constant string
233
+ should provide equivalent functionality.
234
+
235
+ This deprecation may be reversed if a use-case presents itself in the mean time.
236
+ """
237
+ # NOTE: this fallback runs full hash alg, w/ whatever cost param is passed along.
238
+ # implementations (esp ones w/ variable cost) will want to subclass this
239
+ # with a constant-time implementation that just renders a config string.
240
+ if cls.context_kwds:
241
+ raise NotImplementedError("must be implemented by subclass")
242
+ return cls.using(**setting_kwds).hash("")
243
+
244
+ @deprecated_method(deprecated="1.7", removed="2.0")
245
+ @classmethod
246
+ def genhash(cls, secret, config, **context):
247
+ """
248
+ generated hash for secret, using settings from config/hash string
249
+
250
+ .. deprecated:: 1.7
251
+
252
+ As of 1.7, this method is deprecated, and slated for complete removal in Passlib 2.0.
253
+
254
+ This deprecation may be reversed if a use-case presents itself in the mean time.
255
+ """
256
+ # XXX: if hashes reliably offered a .parse() method, could make a fallback for this.
257
+ raise NotImplementedError("must be implemented by subclass")
258
+
259
+ # ===================================================================
260
+ # undocumented methods / attributes
261
+ # ===================================================================
262
+ # the following entry points are used internally by passlib,
263
+ # and aren't documented as part of the exposed interface.
264
+ # they are subject to change between releases,
265
+ # but are documented here so there's a list of them *somewhere*.
266
+
267
+ # ---------------------------------------------------------------
268
+ # extra metdata
269
+ # ---------------------------------------------------------------
270
+
271
+ #: this attribute shouldn't be used by hashers themselves,
272
+ #: it's reserved for the CryptContext to track which hashers are deprecated.
273
+ #: Note the context will only set this on objects it owns (and generated by .using()),
274
+ #: and WONT set it on global objects.
275
+ #: [added in 1.7]
276
+ #: TODO: document this, or at least the use of testing for
277
+ #: 'CryptContext().handler().deprecated'
278
+ deprecated = False
279
+
280
+ #: optionally present if hasher corresponds to format built into Django.
281
+ #: this attribute (if not None) should be the Django 'algorithm' name.
282
+ #: also indicates to passlib.ext.django that (when installed in django),
283
+ #: django's native hasher should be used in preference to this one.
284
+ ## django_name
285
+
286
+ # ---------------------------------------------------------------
287
+ # checksum information - defined for many hashes
288
+ # ---------------------------------------------------------------
289
+ ## checksum_chars
290
+ ## checksum_size
291
+
292
+ # ---------------------------------------------------------------
293
+ # experimental methods
294
+ # ---------------------------------------------------------------
295
+
296
+ ##@classmethod
297
+ ##def normhash(cls, hash):
298
+ ## """helper to clean up non-canonic instances of hash.
299
+ ## currently only provided by bcrypt() to fix an historical passlib issue.
300
+ ## """
301
+
302
+ # experimental helper to parse hash into components.
303
+ ##@classmethod
304
+ ##def parsehash(cls, hash, checksum=True, sanitize=False):
305
+ ## """helper to parse hash into components, returns dict"""
306
+
307
+ # experiment helper to estimate bitsize of different hashes,
308
+ # implement for GenericHandler, but may be currently be off for some hashes.
309
+ # want to expand this into a way to programmatically compare
310
+ # "strengths" of different hashes and hash algorithms.
311
+ # still needs to have some factor for estimate relative cost per round,
312
+ # ala in the style of the scrypt whitepaper.
313
+ ##@classmethod
314
+ ##def bitsize(cls, **kwds):
315
+ ## """returns dict mapping component -> bits contributed.
316
+ ## components currently include checksum, salt, rounds.
317
+ ## """
318
+
319
+ # ===================================================================
320
+ # eoc
321
+ # ===================================================================
322
+
323
+
324
+ class DisabledHash(PasswordHash):
325
+ """
326
+ extended disabled-hash methods; only need be present if .disabled = True
327
+ """
328
+
329
+ is_disabled = True
330
+
331
+ @classmethod
332
+ def disable(cls, hash=None):
333
+ """
334
+ return string representing a 'disabled' hash;
335
+ optionally including previously enabled hash
336
+ (this is up to the individual scheme).
337
+ """
338
+ # default behavior: ignore original hash, return standalone marker
339
+ return cls.hash("")
340
+
341
+ @classmethod
342
+ def enable(cls, hash):
343
+ """
344
+ given a disabled-hash string,
345
+ extract previously-enabled hash if one is present,
346
+ otherwise raises ValueError
347
+ """
348
+ # default behavior: no way to restore original hash
349
+ raise ValueError("cannot restore original hash")
350
+
351
+
352
+ # =============================================================================
353
+ # eof
354
+ # =============================================================================