You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

107 line
3.2 KiB

  1. """passlib.hosts"""
  2. #=============================================================================
  3. # imports
  4. #=============================================================================
  5. # core
  6. from warnings import warn
  7. # pkg
  8. from passlib.context import LazyCryptContext
  9. from passlib.exc import PasslibRuntimeWarning
  10. from passlib import registry
  11. from passlib.utils import has_crypt, unix_crypt_schemes
  12. # local
  13. __all__ = [
  14. "linux_context", "linux2_context",
  15. "openbsd_context",
  16. "netbsd_context",
  17. "freebsd_context",
  18. "host_context",
  19. ]
  20. #=============================================================================
  21. # linux support
  22. #=============================================================================
  23. # known platform names - linux2
  24. linux_context = linux2_context = LazyCryptContext(
  25. schemes = [ "sha512_crypt", "sha256_crypt", "md5_crypt",
  26. "des_crypt", "unix_disabled" ],
  27. deprecated = [ "des_crypt" ],
  28. )
  29. #=============================================================================
  30. # bsd support
  31. #=============================================================================
  32. # known platform names -
  33. # freebsd2
  34. # freebsd3
  35. # freebsd4
  36. # freebsd5
  37. # freebsd6
  38. # freebsd7
  39. #
  40. # netbsd1
  41. # referencing source via -http://fxr.googlebit.com
  42. # freebsd 6,7,8 - des, md5, bcrypt, bsd_nthash
  43. # netbsd - des, ext, md5, bcrypt, sha1
  44. # openbsd - des, ext, md5, bcrypt
  45. freebsd_context = LazyCryptContext(["bcrypt", "md5_crypt", "bsd_nthash",
  46. "des_crypt", "unix_disabled"])
  47. openbsd_context = LazyCryptContext(["bcrypt", "md5_crypt", "bsdi_crypt",
  48. "des_crypt", "unix_disabled"])
  49. netbsd_context = LazyCryptContext(["bcrypt", "sha1_crypt", "md5_crypt",
  50. "bsdi_crypt", "des_crypt", "unix_disabled"])
  51. # XXX: include darwin in this list? it's got a BSD crypt variant,
  52. # but that's not what it uses for user passwords.
  53. #=============================================================================
  54. # current host
  55. #=============================================================================
  56. if registry.os_crypt_present:
  57. # NOTE: this is basically mimicing the output of os crypt(),
  58. # except that it uses passlib's (usually stronger) defaults settings,
  59. # and can be inspected and used much more flexibly.
  60. def _iter_os_crypt_schemes():
  61. """helper which iterates over supported os_crypt schemes"""
  62. out = registry.get_supported_os_crypt_schemes()
  63. if out:
  64. # only offer disabled handler if there's another scheme in front,
  65. # as this can't actually hash any passwords
  66. out += ("unix_disabled",)
  67. return out
  68. host_context = LazyCryptContext(_iter_os_crypt_schemes())
  69. #=============================================================================
  70. # other platforms
  71. #=============================================================================
  72. # known platform strings -
  73. # aix3
  74. # aix4
  75. # atheos
  76. # beos5
  77. # darwin
  78. # generic
  79. # hp-ux11
  80. # irix5
  81. # irix6
  82. # mac
  83. # next3
  84. # os2emx
  85. # riscos
  86. # sunos5
  87. # unixware7
  88. #=============================================================================
  89. # eof
  90. #=============================================================================