The Pirate Bay (海盜灣) 從 Torrent 檔下載換成 Magnet URI (磁力連結)

The Pirate Bay 將把 torrent 檔下載方式換成磁力連結:「The Pirate Bay Will Stop Serving Torrents」。

Magnet URI 下載 BitTorrent 檔案其實只是多了一個抓 torrent 檔的步驟:首先先從 Magnet URI 內取得 SHA1 值,然後透過 DHT 抓到 torrent 檔的 metadata,然後後面就可以照舊進行... 至於 DHT 的初次建立,除了可以透過中央式的 router.utorrent.com 取得外,也可以透過其他 torrent 檔案下載所提供的 tracker 找到節點。在取得一批節點後,透過 PEX 交換出更多的節點。

DHT + PEX 的技術逐漸成熟 (愈來愈多程式支援),然後是最大的 torrent site 採用。之後的 public torrent site 應該都會改朝這個方向走...

儲存密碼的方式

主要是參考「Cryptographic Right Answers」這篇給的建議:

Password handling: As soon as you receive a password, hash it using scrypt or PBKDF2 and erase the plaintext password from memory.
Do NOT store users' passwords. Do NOT hash them with MD5. Use a real key derivation algorithm. PBKDF2 is the most official standard; but scrypt is stronger.
Please keep in mind that even if YOUR application isn't particularly sensitive, your users are probably re-using passwords which they have used on other, more sensitive, websites -- so if you screw up how you store your users' passwords, you might end up doing them a lot of harm.

其中 scrypt 是作者自己發展的演算法,這邊看看就好。

你可以用 PBKDF2 (RFC 2898)。這邊假設的前提是,你不需要常常重複計算使用者的密碼是否正確。在這個前提下,我們可以把演算法弄得很複雜,而且很耗時,要複雜到用硬體加速也無法產生實質上有效的攻擊。

如果你對密碼學這個領域並不熟,Colin Percival 這篇文章可以拿來當做起點,文章裡面告訴你,某些類型的問題會用某些工具解決。

自己編 rTorrent 與 libTorrent...

Ubuntu 提供的 rTorrent 比較舊,11.04 上面只有 0.8.6 可以用,11.10 則是 0.8.7。目前最新的 stable 是 0.8.9,有支援 magnet uri... 找了 launchpad 上面有沒有人做,看起來是沒有 :/

因為不想影響到系統舊版的 libTorrent 與 rTorrent,所以裝在自己的 home directory 下。

先安裝 libTorrent,用 ./configure --prefix=/home/gslin/foo 之後用 make 編完後 make install 就可以了,有缺軟體的部份會跳訊息出來,用 apt-get 補上 -dev 版本後再繼續安裝。

再來是 rTorrent,首先要注意的是要裝 libncursesw5-dev,也就是有 wide character support 的版本,不然顯示 UTF-8 會有問題 (實際在磁碟上的檔名不會有問題,但顯示會有問題),接著用 libtorrent_CFLAGS="-I/home/gslin/foo/include" libtorrent_LIBS="-L/home/gslin/foo/lib -ltorrent" ./configure --prefix=/home/gslin/foo 指定 libtrorrent 所在位置,然後用 make 編完後 make install

接下來用 ~/foo/rtorrent 執行,應該就會是新版的 rTorrent 了...

請更新 HP 印表機的韌體...

HP 發了安全通告「HPSBPI02728 SSRT100692 rev.2 - Certain HP Printers and HP Digital Senders, Remote Firmware Update Enabled by Default」,在安全通告內列出的印表機都有安全問題,「允許遠端安裝未經授權的印表機韌體」,攻擊者可以遠端直接安裝有木馬的韌體:

A potential security vulnerability has been identified with certain HP printers and HP digital senders. The vulnerability could be exploited remotely to install unauthorized printer firmware.

另外可以參考 CVE-2011-4161 的說明:

The default configuration of the HP CM8060 Color MFP with Edgeline; Color LaserJet 3xxx, 4xxx, 5550, 9500, CMxxxx, CPxxxx, and Enterprise CPxxxx; Digital Sender 9200c and 9250c; LaserJet 4xxx, 5200, 90xx, Mxxxx, and Pxxxx; and LaserJet Enterprise 500 color M551, 600, M4555 MFP, and P3015 enables the Remote Firmware Update (RFU) setting, which allows remote attackers to execute arbitrary code by using a session on TCP port 9100 to upload a crafted firmware update.

能更新的就想辦法更新吧,無法更新的看看有沒有辦法處理 port 9100...

Akamai 買下 Cotendo...

Akaiami 的新聞稿先出來了:「December 22, 2011 - Akamai to Acquire Cotendo」,Cotendo 的只有在 Twitter 上看到官方帳號提到 Akamai 的新聞稿。

併購的金額在:

Under terms of the agreement, Akamai will acquire all of the outstanding equity of Cotendo in exchange for a net cash payment of approximately $268 million

上個月月底的時候就有消息了:「Akamai Reportedly Buying Rival Cotendo For Up To $350 Million」,不過一直都是謠傳而已...

Cotendo 的產品在 Akamai 裡面都有對應的產品,這次併購看起來比較像是減少競爭對手,或是買專利...

把 Google Plus 的數字 icon 藏起來...

那個紅色的數字 icon 還蠻妨礙工作的,到 userscripts.org 上翻一翻,果然有人有寫過了 (雖然是沒幾天前):「Go Away! Google Plus」。

PS:隨便丟字進去測試的時候,發現 "test" 第五名是 tw.yahoo.com,這是怎麼了...?

gitolite 的 hook...

弄了整個週末的 gitolite,總算是把 hook 搞定。

簡單的說,修改完 ~/.gitolite/hooks/common/ 裡的 hook script 後,需要下 gl-setup 指令,這個指令會把現在所有的 git repository 內的 hook script 再 symbolic link 一次。

另外,gitolite 的環境變數可能會影響 git 本身執行 (我是在 git pull -v 更新某個目錄下的 git repository 時失敗),這時可以用 /usr/bin/env -i /usr/local/bin/git 確保 git 執行時不會被環境變數影響...

gitolite 看起來是個好東西,不過光是靠官方的文件要搞定頗累... (週末都在 Stack Overflow 上度過)

如果要自己寫 TOTP 的幾個要看的東西...

整理下來:

有玩過 HMAC 的人,讀這些文件應該不難...

TOTP 在預設的情況下,其實就是 HMAC-SHA-1 後取後面 32bits,然後轉成數字取 100000 的餘數,而 TOTP 文件是架構在 HOTP 的定義上,把時間切齊 (預設 30secs) 變成整數丟進去攪和,然後特地交代要處理 2038 年超過 Int32 的 case XDDD

最後 Google 那份文件是要輸出 QR code 讓手機可以讀的方式,建議不要用網路服務產生 QR code (因為有 secret key 啊),寧可自己抓 library 建一個用...

另外 Google Authenticator 一堆東西都只能用預設值 (Currently, the XXX is ignored by the Google Authenticator implementations.),所以也沒什麼好選的,就拿預設值吧... :o

Server side 的話,至少我在 CPAN 上面看到 Authen-OATH 可以用了,用起來也很簡單 :o

YouTube (Google) 允許環球唱片 (Universal Music Group,UMG) 直接移除非 UMG 所擁有版權的影片

依照環球唱片 (Universal Music Group,UMG) 提供給法院的文件中,YouTube (也就是 Google) 允許 UMG 透過 YouTube 的 CMS (Content Management System) 移除「不屬於 UMG 的影片」:「Google Deal Allegedly Lets UMG Wipe YouTube Videos It Doesn't Own」,文件 (PDF) 在:「gov.uscourts.cand.248875.14.0.pdf」這邊可以下載取得。

重點在於這份文件中第四頁的這段:

The UMG-YouTube agreement grants UMG rights to effect the removal of user-posted videos through YouTube’s Content Management System (“CMS”), based on a number of contractually specified criteria that are not limited to the infringements of copyrights owned or controlled by UMG. Klaus Decl., Ex. 4 (Klaus to Kavanaugh letter, Dec. 14, 2011). Dotcom speculates in his declaration that Universal must have sent a so-called “DMCA notification form,” such as the one he printed and attached at Ex. E to his declaration, to YouTube. Doctcom Decl. ¶ 11. But UMG (which interacts with YouTube) does not use that form when requesting the removal of material pursuant to UMG’s contract with YouTube. UMG uses YouTube’s automated CMS system.

繼續來看後續吧...

同時用 mod_deflate 與 mod_fastcgi 所產生的問題...

今天花了不少時間找到的問題...

問題是使用 mod_fastcgi 以及 mod_deflate 時,Content-Encoding 會是 gzip,但 Content-Length 會是未壓縮的長度。

也就是說,伺服器端在 header 提供的 Content-Length 可能寫 8KB,但實際上只丟出 2KB (壓縮後的大小),於是瀏覽器讀完這 2KB 後會停下來一直等,等到 Keep-Alive timeout 斷線 (在我機器上預設是 5 秒)。

在 timeout 斷線後 browser 會就抓到的資料直接解開執行 (因為這 2KB 都有抓到,於是都正確執行)。如果用瀏覽器這邊的 debugger 觀察,就會發現從 first byte 後 5.00 秒才 document ready。

解法有人在 2008 年給過:「Content-Length header should be set using ap_set_content_length」,不過因為 mod_fastcgi 一直沒出新的正式版,所以大家都還是拿到舊的版本。

所以,與之前修正 multi-threading 的問題一樣,往 ports 本身丟 patch:「Update www/mod_fastcgi to fix mod_deflate issue.」,修正後再測試就正常了。