diff options
| author | Eli Collins <elic@assurancetechnologies.com> | 2011-04-29 00:08:17 -0400 |
|---|---|---|
| committer | Eli Collins <elic@assurancetechnologies.com> | 2011-04-29 00:08:17 -0400 |
| commit | c8d8eb0d9b1c753d342307b070fb1ad09cc351a6 (patch) | |
| tree | 491d6e0b3136edee39bc2001331eb4ed09a38afd /docs/modular_crypt_format.rst | |
| parent | bc98bc9188ed66d78ad3864443432690745da585 (diff) | |
| download | passlib-c8d8eb0d9b1c753d342307b070fb1ad09cc351a6.tar.gz | |
large rework of documentation; mainly to give more room to LDAP hashes, and document ldap CRYPT hashes
Diffstat (limited to 'docs/modular_crypt_format.rst')
| -rw-r--r-- | docs/modular_crypt_format.rst | 144 |
1 files changed, 144 insertions, 0 deletions
diff --git a/docs/modular_crypt_format.rst b/docs/modular_crypt_format.rst new file mode 100644 index 0000000..21b2053 --- /dev/null +++ b/docs/modular_crypt_format.rst @@ -0,0 +1,144 @@ +.. index:: modular crypt format + +.. _modular-crypt-format: + +.. rst-class:: html-toggle + +==================== +Modular Crypt Format +==================== + +.. centered:: *or*, a side note about a standard that isn't + +In short, the modular crypt format (MCF) is a standard +for encoding password hash strings, which requires hashes +have the format :samp:`${identifier}${content}`; where +:samp:`{identifier}` is an short alphanumeric string uniquely +identifying a particular scheme, and :samp:`{content}` +is the contents of the scheme, using only the characters +``[a-zA-Z0-9./]``. + +However, there appears to be no actual rules, specification document, +or central registry of identifiers; so the modular +crypt format is more of an ad-hoc idea than a true standard. + +History +======= +Historically, most unix systems supported only :class:`~passlib.hash.des_crypt`. +Around the same time, many incompatible variations were also developed, +but their hashes were not easily distingiushable from each other +(see :ref:`archaic-unix-schemes`); making it impossible to use +multiple hashes on one system, or progressively migrate to a newer scheme. + +This was solved with the advent of the MCF, +which was introduced around the time that :class:`~passlib.hash.md5_crypt` was developed. +This format allows hashes from multiple schemes to exist within the same +database, by requiring that all hash strings begin with a unique prefix +using the format :samp:`${identifier}$`. + +Requirements +============ +Unfortunately, there is no specification document for this format. +Instead, it exists in *de facto* form only; the following +is an attempt to roughly identify the guidelines followed +by the modular crypt format hashes found in passlib: + +1. Hash strings must use only 7-bit ascii characters. + + This is not strictly enforced at all; + for example Linux will accept 8-bit characters + within hash salt strings. However, **no** known + system generates hashes violating this rule; + and no such test vectors exist either, + so it can probably be assumed to be a case + of "permissive in what you accept, strict in what you generate". + +2. Hash strings should always start with the prefix :samp:`${identifier}$`, + where :samp:`{identifier}` is a short string uniquely identifying + hashes generated by that algorithm, using only lower case ascii + letters, numbers, and hyphens. + + Initially, most schemes adhereing to this format + only used a single digit to identify the hash + (eg ``$1$`` for :class:`!md5_crypt`). + Because of this, many systems only look at the first + character when attempting to distinguish hashes. + + Despite this, as Unix systems have branched off, + new hashes have been developed which used larger + identifying strings (eg ``$sha1$`` for :class:`sha1_crypt`); + so in general identifier strings should not be assumed to use a single character. + +3. Aside from the prefix, hashes should contain only ascii letters, + ascii numbers, and the characters in ``./``; though ``$`` + may be used as an internal field separator. + + This is the least adhered-to of any modular crypt format rule. + Other characters (such as ``=``, ``,``) are sometimes + used by various formats. + + The only hard and fast stricture + is that ``:`` and non-printable characters be avoided, + since this would interfere with parsing of /etc/passwd + where these hashes are typically stored. + + Pretty much all modular-crypt-format hashes + use ascii letters, numbers, ``.``, and ``/`` + to provide base64 encoding of their raw data, + though the exact character value assignments vary between hashes + (see :mod:`passlib.utils.h64`). + +4. Hash schemes should put their "checksum" portion + at the end of the hash, preferrably separated + by a ``$``. + + This allows password hashes to be easily truncated + to a "configuration string" containing just + the identifying prefix, rounds, salt, etc. + + This string then encodes all the information + generated needed to generate a new hash + in order to verify a password, without + having to perform excessive parsing. + + Most modular crypt format hashes follow this, + though some (like :class:`~passlib.hash.bcrypt`) omit the ``$`` separator. + +.. note:: + + All of the above is guesswork based on examination of existing + hashes and OS implementations; and was written merely + to clarify the issue of what the "modular crypt format" is. + It is drawn from no authoritative sources. + +.. _mcf-identifiers: + +Identifiers & Platform Support +============================== + +The following chart lists the various operating systems, which +hash algorithms are known to be supported, as well as the hash's +identifying prefix. + +==================================== ================== =========== =========== =========== =========== +Scheme Prefix Linux FreeBSD NetBSD OpenBSD +==================================== ================== =========== =========== =========== =========== +:class:`~passlib.hash.nthash` ``$3$`` y +:class:`~passlib.hash.des_crypt` n/a y y y y +:class:`~passlib.hash.bsdi_crypt` ``_`` y y +:class:`~passlib.hash.md5_crypt` ``$1$`` y y y y +:class:`~passlib.hash.sun_md5_crypt` ``$md5$`` +:class:`~passlib.hash.bcrypt` ``$2$``, ``$2a$`` y y y +:class:`~passlib.hash.sha1_crypt` ``$sha1$`` y +:class:`~passlib.hash.sha256_crypt` ``$5$`` y +:class:`~passlib.hash.sha512_crypt` ``$6$`` y +==================================== ================== =========== =========== =========== =========== + +.. note:: + + :class:`!des_crypt` and :class:`!bsdi_crypt` do not conform to the MCF, + but are listed here for completeness. + +.. todo:: + + include Solaris and other Unix flavors in this chart. |
