<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>2015/05/22 on Yano&#39;s digital garage</title>
    <link>https://www.bravotouring.com/~yano/archives/2015/05/22/</link>
    <description>Recent content in 2015/05/22 on Yano&#39;s digital garage</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <lastBuildDate>Fri, 22 May 2015 09:32:28 +0900</lastBuildDate>
    <atom:link href="https://www.bravotouring.com/~yano/archives/2015/05/22/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Basic認証の落とし穴</title>
      <link>https://www.bravotouring.com/~yano/diary/it/20150522basicauth.htm</link>
      <pubDate>Fri, 22 May 2015 09:32:28 +0900</pubDate>
      <guid>https://www.bravotouring.com/~yano/diary/it/20150522basicauth.htm</guid>
      <description>&lt;p&gt;とある案件で&lt;a href=&#34;http://ja.wikipedia.org/wiki/REST&#34;&gt;REST&lt;/a&gt;APIによる&#34;ユーザ認証&#34;の振舞いを確認しようとして、予てより&lt;a href=&#34;http://httpd.apache.org/&#34;&gt;Apache HTTP Server&lt;/a&gt;に登録してあるユーザアカウントを流用して検証していたのだが、期待とは裏腹に&lt;span class=&#34;Warning&#34;&gt;&#34;401:認証エラー&#34;とならない&lt;/span&gt;事があった。&lt;/p&gt;&#xA;&lt;p&gt;具体的には、&#34;PaSsWoRd&#34;というパスワード設定に対して&#34;PaSsWoRdXyZ&#34;を与えたのに「認証OK」と判断されてしまったので、「何か設定しくじってるのかな～？」とググったら、&lt;a href=&#34;https://www.softel.co.jp/blogs/tech/archives/2408&#34;&gt;【apache】ベーシック認証で8文字以上の長いパスワードを設定するときの注意&lt;/a&gt;というのを発見。&lt;/p&gt;&#xA;&lt;p&gt;確かに&lt;a href=&#34;http://httpd.apache.org/docs/2.4/programs/htpasswd.html&#34;&gt;htpasswd - Manage user files for basic authentication&lt;/a&gt;の「Security Considerations(セキュリティ考慮事項)」には&#xA;&lt;blockquote cite=&#34;http://httpd.apache.org/docs/2.4/programs/htpasswd.html&#34;&gt;&#xA;When using the crypt() algorithm, note that &lt;span class=&#34;Warning&#34;&gt;only the first 8 characters&lt;/span&gt; of the password are used to form the password. If the supplied password is longer, the extra characters will be silently discarded.&lt;/blockquote&gt;&#xA;ざっくり意訳すると&lt;blockquote&gt;&#xA;crypt()アルゴリズムを使用する場合、パスワードの&lt;span class=&#34;Warning&#34;&gt;最初の8文字分&lt;/span&gt;しか使用されないことに注意してください。与えられたパスワードが長い場合、余分な文字は黙って破棄されます。&lt;/blockquote&gt;と書いてあったよ。&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&#34;Software&#34;&gt;Windows&lt;/span&gt;版の場合は&lt;a href=&#34;http://ja.wikipedia.org/wiki/MD5&#34;&gt;MD5&lt;/a&gt;アルゴリズムがデフォルトとなっている事から&lt;span class=&#34;Warning&#34;&gt;最初の8文字&lt;/span&gt;の呪縛は無いそうなので、&lt;span class=&#34;Software&#34;&gt;Linux&lt;/span&gt;版も&lt;a href=&#34;http://ja.wikipedia.org/wiki/MD5&#34;&gt;MD5&lt;/a&gt;をデフォルトにしなくちゃダメでしょ、と思ってUbuntu 14.04の&lt;span class=&#34;Software&#34;&gt;htpasswd&lt;/span&gt;を確認したところ&#xA;&lt;blockquote class=&#34;Log&#34;&gt;&#xA;yano@GT110b:~$ htpasswd -nb userhoge password&lt;br/&gt;&#xA;userhoge:$apr1$UQ0/lsy.$gpZwn.kvveLE5pYxs5eaW.&lt;br/&gt;&lt;br/&gt;&#xA;yano@GT110b:~$ htpasswd -nb userhoge passwordXYZ&lt;br/&gt;&#xA;userhoge:$apr1$jpjd1bYr$Wv/R7ai0xF6j.v6HAMe4s0&lt;br/&gt;&lt;br/&gt;&#xA;&lt;/blockquote&gt;&#xA;…と異なる結果になったので、「おや？」と思いhelpをみたところ&#xA;&lt;blockquote class=&#34;Log&#34;&gt;&#xA;yano@GT110b:~$ &lt;span class=&#34;Software&#34;&gt;htpasswd&lt;/span&gt; --help&lt;br/&gt;&#xA;Usage:&lt;br/&gt;&#xA;        htpasswd [-cimBdpsDv] [-C cost] passwordfile username&lt;br/&gt;&#xA;        htpasswd -b[cmBdpsDv] [-C cost] passwordfile username password&lt;br/&gt;&#xA;&lt;br/&gt;&#xA;        htpasswd -n[imBdps] [-C cost] username&lt;br/&gt;&#xA;        htpasswd -nb[mBdps] [-C cost] username password&lt;br/&gt;&#xA; -c  Create a new file.&lt;br/&gt;&#xA; -n  Don&#39;t update file; display results on stdout.&lt;br/&gt;&#xA; -b  Use the password from the command line rather than prompting for it.&lt;br/&gt;&#xA; -i  Read password from stdin without verification (for script usage).&lt;br/&gt;&#xA; -m  Force &lt;span class=&#34;Topics&#34;&gt;MD5&lt;/span&gt; encryption of the password &lt;span class=&#34;Topics&#34;&gt;(default)&lt;/span&gt;.&lt;br/&gt;&#xA; -B  Force bcrypt encryption of the password (very secure).&lt;br/&gt;&#xA; -C  Set the computing time used for the bcrypt algorithm&lt;br/&gt;&#xA;     (higher is more secure but slower, default: 5, valid: 4 to 31).&lt;br/&gt;&#xA; -d  Force CRYPT encryption of the password (8 chars max, insecure).&lt;br/&gt;&#xA; -s  Force SHA encryption of the password (insecure).&lt;br/&gt;&#xA; -p  Do not encrypt the password (plaintext, insecure).&lt;br/&gt;&#xA; -D  Delete the specified user.&lt;br/&gt;&#xA; -v  Verify password for the specified user.&lt;br/&gt;&#xA;On other systems than Windows and NetWare the &#39;-p&#39; flag will probably not work.&lt;br/&gt;&#xA;The SHA algorithm does not use a salt and is less secure than the MD5 algorithm.&lt;br/&gt;&#xA;yano@GT110b:~$&#xA;&lt;/blockquote&gt;&#xA;という結果となり、&lt;span class=&#34;Topics&#34;&gt;デフォルトMD5&lt;/span&gt;になっている事が確認できたので、今回&lt;span class=&#34;Warning&#34;&gt;最初の8文字分&lt;/span&gt;しか効かなかったのは、10年近くも昔の設定を安易に使い回してきたのが原因のようだ。&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
