Apache Httpd Server 2.2 Auth Password Formats
Notes about the password encryption formats generated and understood by Apache.
Basic Authentication
There are four formats that Apache recognizes for basic-authentication passwords. Note that not all formats work on every platform.:
PLAIN TEXT (i.e. unencrypted)Windows, BEOS, & Netware only.CRYPTUnix only. Uses the traditional Unix crypt(3) function with a randomly-generated 32-bit salt (only 12 bits used) and the first 8 characters of the password.SHA1"{SHA}" + Base64-encoded SHA-1 digest of the password.MD5"$apr1$" + the result of an Apache-specific algorithm using an iterated (1,000 times) MD5 digest of various combinations of a random 32-bit salt and the password. See the APR source file for the details of the algorithm.Generating values with htpasswd
MD5
$ htpasswd -nbm myName myPassword
myName:$apr1$r31.....$HqJZimcKQFAMYayBlzkrA/
SHA1
$ htpasswd -nbs myName myPassword
myName:{SHA}VBPuJHI7uixaa6LQGWx4s+5GKNE=
CRYPT
$ htpasswd -nbd myName myPassword
myName:rqXexS6ZhobKA
Generating CRYPT and MD5 values with the OpenSSL command-line program
OpenSSL knows the Apache-specific MD5 algorithm.
MD5
$ openssl passwd -apr1 myPassword
$apr1$qHDFfhPC$nITSVHgYbDAK1Y0acGRnY0
CRYPT
openssl passwd -crypt myPassword
qQ5vTYO3c8dsU
Validating CRYPT or MD5 passwords with the OpenSSL command line program
The salt for a CRYPT password is the first two characters (converted to a binary value). To validate myPassword against rqXexS6ZhobKA
CRYPT
$ openssl passwd -crypt -salt rq myPassword
Warning: truncating password to 8 characters
rqXexS6ZhobKA
Note that using myPasswo instead of myPassword will produce the same result because only the first 8 characters of CRYPT passwords are considered.
The salt for an MD5 password is between $apr1$ and the following $ (as a Base64-encoded binary value - max 8 chars). To validate myPasswordagainst $apr1$r31.....$HqJZimcKQFAMYayBlzkrA/
MD5
$ openssl passwd -apr1 -salt r31..... myPassword
$apr1$r31.....$HqJZimcKQFAMYayBlzkrA/
Database password fields for mod_dbd
The SHA1 variant is probably the most useful format for DBD authentication. Since the SHA1 and Base64 functions are commonly available, other software can populate a database with encrypted passwords that are usable by Apache basic authentication.
To create Apache SHA1-variant basic-authentication passwords in various languages:
PHP
'{SHA}' . base64_encode(sha1($password, TRUE))
Java
"{SHA}" + new sun.misc.BASE64Encoder().encode(java.security.MessageDigest.getInstance("SHA1").digest(password.getBytes()))
ColdFusion
"{SHA}" & ToBase64(BinaryDecode(Hash(password, "SHA1"), "Hex"))
Ruby
require 'digest/sha1'
require 'base64'
'{SHA}' + Base64.encode64(Digest::SHA1.digest(password))
C or C++
Use the APR function: apr_sha1_base64
PostgreSQL (with the contrib/pgcrypto functions installed)
'{SHA}'||encode(digest(password,'sha1'),'base64')
Apache recognizes one format for digest-authentication passwords - the MD5 hash of the string user:realm:password as a 32-character string of hexadecimal digits. realm is the Authorization Realm argument to the directive in httpd.conf.
Database password fields for mod_dbd
Since the MD5 function is commonly available, other software can populate a database with encrypted passwords that are usable by Apache digest authentication.
To create Apache digest-authentication passwords in various languages:
PHP
md5($user . ':' . $realm . ':' .$password)
Java
byte b[] = java.security.MessageDigest.getInstance("MD5").digest( (user + ":" + realm + ":" + password ).getBytes());
java.math.BigInteger bi = new java.math.BigInteger(1, b);
String s = bi.toString(16);
while (s.length() < 32)
s = "0" + s;// String s is the encrypted password
ColdFusion
LCase(Hash( (user & ":" & realm & ":" & password) , "MD5"))
Ruby
require 'digest/md5'
Digest::MD5.hexdigest(user + ':' + realm + ':' + password)
PostgreSQL (with the contrib/pgcrypto functions installed)
encode(digest( user || ':' || realm || ':' || password , 'md5'), 'hex')
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29867/viewspace-722432/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Apache(httpd)詳解Apachehttpd
- apache httpd安裝 配置Apachehttpd
- Starting httpd: httpd: Could not reliably determine the serverhttpdServer
- Apache的httpd命令詳解Apachehttpd
- httpd 一鍵編譯安裝指令碼(centos6&7_httpd2.2&2.4)httpd編譯指令碼CentOS
- apache啟動報錯:httpd: aprApachehttpd
- Apache2.2提示Cannot load php5apache2.dll into server的的解決ApachePHPServer
- 啟動apache遇到錯誤:httpd: Could not reliably determine the server's fully qualified domain nameApachehttpdServerAI
- Apache httpd和php的結合方式ApachehttpdPHP
- Linux——搭建Apache(httpd)伺服器LinuxApachehttpd伺服器
- apache的httpd.conf翻譯Apachehttpd
- python urllib socks5 auth username password 設定Python
- [備忘]Redis執行出現Client sent AUTH, but no password is setRedisclient
- apache提示錯誤:httpd-ahssl.confApachehttpd
- Mac下配置Apache Httpd的Https/SSLMacApachehttpd
- Linux上編譯安裝Apache出現httpd: Could not reliably determine the server's fully qualified domain nameLinux編譯ApachehttpdServerAI
- apache_httpd.conf_重定向到其它網址Apachehttpd
- Apache主配置檔案httpd.conf 詳解Apachehttpd
- Apache httpd和JBoss構建高可用叢集環境Apachehttpd
- 【高可用HA】Apache (1) —— Mac下安裝Apache Httpd到自定義路徑(非/etc/apache2)ApacheMachttpd
- 配置Apache2.2+PHP5+CakePHP1.2+MySQL5ApachePHPMySql
- Apache 2.2 + Php 5.1 安裝問題解決ApachePHP
- Apache的httpd.conf檔案常用指令解釋(轉)Apachehttpd
- Hacked VisualSVN Server by PHP to allow user change passwordServerPHP
- apache2.2+PHP5.2.3+mysql5.0+gd+zend+phpmyadminApachePHPMySql
- apache2.2+tomcat6負載均衡問題ApacheTomcat負載
- 【高可用HA】Apache (3) —— Mac下配置Apache Httpd負載均衡(Load Balancer)之mod_proxyApacheMachttpd負載
- 【高可用HA】Apache (4) —— Mac下配置Apache Httpd負載均衡(Load Balancer)之mod_jkApacheMachttpd負載
- APACHE WEB SERVER管理(轉)ApacheWebServer
- vmware server web access的login name和passwordServerWeb
- Apache2.2與Tomcat7整合方案詳解ApacheTomcat
- Chapter 2. Video Formats and QualityAPTIDEORM
- Apache httpd-2.0.47 + Tomcat 5.0 OR tomcat-4.1.24 + jk2 +(轉)ApachehttpdTomcat
- 解決安裝Redis之後設定密碼,報(error) ERR Client sent AUTH, but no password is setRedis密碼Errorclient
- auth
- 配置Apache Server + Tomcat (轉)ApacheServerTomcat
- Apache HTTPd 2.4.49 路徑穿越漏洞(CVE-2021-41773)復現Apachehttpd
- apache2.2支援worker,rewrite模組,支援執行緒Apache執行緒