2014年9月25日 星期四

Fix bash Vulnerability CVE-2014-6271

測試方式:
env x='() { :;}; echo vulnerable' bash -c 'echo hello'

如果出現以下,代表你是安全的
bash: warning: x: ignoring function definition attempt
bash: error importing function definition for `x'
hello

如果出現以下,代表會被這漏洞攻擊
vulnerable
hello


修正方式:
sudo apt-get update && sudo apt-get install bash


參考:http://askubuntu.com/questions/528101/what-is-the-cve-2014-6271-bash-vulnerability-and-how-do-i-fix-it


但是很不幸的 Ubuntu 沒修正完全。
後續還有 CVE-2014-7169 要修XD


Update:
https://twitter.com/ErrataRob/status/514831122400686080/photo/1
csh、tcsh、ksh、sh、zsh 全部中囉~可喜可賀!

SOP For Create User in Ubuntu

以下範例使用者名稱皆用 testuser

建立使用者和設定密碼
sudo useradd -d /home/testuser -m testuser
sudo passwd testuser

指定使用者 shell 用 bash(如果是的話)
sudo chsh -s /bin/bash testuser

讓使用者可以 sudo(如果需要)
sudo adduser testuser sudo

讓使用者可以透過 public key 登入
sudo mkdir /home/testuser/.ssh
sudo chown testuser:testuser /home/testuser/.ssh
sudo chmod 700 /home/testuser/.ssh

sudo mv testuser-id_rsa.pub /home/testuser/.ssh/authorized_keys
sudo chown testuser:testuser /home/testuser/.ssh/authorized_keys
sudo chmod 600 /home/testuser/.ssh/authorized_keys

2014年9月4日 星期四

Import Data To MySQL Efficiently

使用以下指令產生一百萬筆 user 的假資料

for i in `seq 1 1000000`; do echo "test$i,pass$i,,2014-09-05 03:43:27" >> users.csv; done

使用 mysqlimport 匯入資料
MySQL Host:mysql-demo
Database 名稱:my_database
Table 名稱:users
csv 檔名務必和 Table 名稱一樣。

mysqlimport --fields-terminated-by=, --columns='username,password,pass_details,created_at' --local -h mysql-demo.cxu7skntlvtx.us-east-1.rds.amazonaws.com -u admin -p my_database users.csv

使用這種方式匯入資料比使用一個 Transaction 包一堆 Insert SQL 快上百倍。
但需注意此方式如果匯入錯誤,後果自行承擔!

參考:http://chriseiffel.com/everything-linux/how-to-import-a-large-csv-file-to-mysql/

2014年8月27日 星期三

AWS EC2 AES-NI Testing

參考:https://forums.aws.amazon.com/thread.jspa?threadID=122148

AES-NI 是用來加速加解密過程的 CPU 功能,在目前的全部 ec2 instance type 都有支援。

不使用高階函式 -evp(同時也不會使用到 AES-NI)
$ openssl speed -elapsed aes-128-cbc

The 'numbers' are in 1000s of bytes per second processed.
type             16 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
aes-128 cbc     112765.34k   122879.02k   125167.36k   126346.92k   126593.71k


強制不使用 AES-NI
$ OPENSSL_ia32cap="~0x200000200000000" openssl speed -elapsed -evp aes-128-cbc

The 'numbers' are in 1000s of bytes per second processed.
type             16 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
aes-128-cbc     277520.21k   305234.35k   311621.46k   314812.76k   315200.85k



使用 AES-NI
$ openssl speed -elapsed -evp aes-128-cbc

The 'numbers' are in 1000s of bytes per second processed.
type             16 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
aes-128-cbc     561544.04k   598301.61k   607955.80k   610393.43k   611164.16k



由以上數據可以很明顯看出

  1. 有用高階函式庫很明顯
  2. 有 AES-NI 的 CPU 在做 AES 加密時速度快 2 倍。


2014年8月8日 星期五

Database GUI Tools

Sequel Pro:http://www.sequelpro.com/
免費,但只能連 MySQL

Navicat:
http://www.navicat.com/
要錢,但不錯用

MySQL Workbench
http://www.mysql.com/products/workbench/

2014年5月23日 星期五

Install Tsung From Source Code On AWS Ubuntu 14.04 LTS (PV) Instance

官方參考:http://tsung.erlang-projects.org/user_manual/installation.html#dependencies

前置準備,安裝需要用到的程式。執行以下命令
  1. apt-get update
  2. apt-get install make
  3. apt-get install erlang-base
  4. apt-get install erlang-ssl
  5. apt-get install erlang-dev
  6. apt-get install erlang-snmp
  7. apt-get install erlang-eunit
  8. apt-get install erlang-xmerl
  9. apt-get install erlang-inets
  10. apt-get install erlang-os-mon
  11. apt-get install gnuplot
  12. apt-get install python-matplotlib
  13. apt-get install libtemplate-perl


下載 Tsung

  1. wget http://tsung.erlang-projects.org/dist/tsung-1.5.1.tar.gz
  2. tar -zxvf tsung-1.5.1.tar.gz


進入剛剛下載的 tsung1.5.1 內,準備開始安裝前的設定,執行
  1. ./configure
看是否一切正常,或有沒有少裝什麼套件,接著開始安裝,執行
  1. make
  2. make install

完成

Install ejabberd 14.05 XMPP Server From Source Code On AWS Ubuntu 14.04 LTS (PV) Instance

官方參考:http://www.process-one.net/docs/ejabberd/guide_en.html#installation

前置準備,安裝需要用到的程式。執行以下命令

  1. apt-get update
  2. apt-get install git-core
  3. apt-get install make
  4. apt-get install gcc
  5. apt-get install erlang-dev
  6. apt-get install erlang-asn1
  7. apt-get install erlang-inets
  8. apt-get install erlang-odbc
  9. apt-get install erlang-nox
  10. apt-get install libssl-dev
  11. apt-get install libyaml-dev
  12. apt-get install libexpat1-dev
  13. apt-get install zlib1g-dev(非必要,但請在執行 configure 時加上 --disable-ejabberd_zlib)
  14. apt-get install libssl-dev(非必要,但請在執行 configure 時加上 --disable-tls)


開始下載 ejabberd,並切換到要安裝的版本,執行以下命令

  1. git clone git://github.com/processone/ejabberd.git ejabberd
  2. cd ejabberd
  3. git checkout -b 2.1.x origin/2.1.x
若要直接從官網抓最新版的 source 來裝,執行以下命令:
  1. wget http://www.process-one.net/downloads/downloads-action.php?file=/ejabberd/14.05/ejabberd-14.05.tgz
  2. tar -zxvf ejabberd-14.05.tgz


進入剛剛下載的 ejabberd/src 內,準備開始安裝前的設定,執行
  1. ./configure
看是否一切正常,或有沒有少裝什麼套件,接著開始安裝,執行
  1. make
  2. make install

安裝完成後,啟動 ejabberd
  1. ejabberdctl start
啟動完畢後,看是否正常
  1. ejabberdctl status
要出現類似以下文字:

The node ejabberd@localhost is started with status: started
ejabberd 2.1.13 is running in that node

這樣就完成了。

2014年5月8日 星期四

Sublime Text 2 jQueryMobile Snippets

最近剛好要做一點 jQueryMobile 的頁面,順便用了一下 Sublime 的 Snippet,發現滿好用的。 就寫了些很基本的 Snippet 讓大家用,還未開發完全。 

在網路上有其他人也有做一樣的事情,但是版本有點舊了,且用 HTML5 的寫法。 因此自己做了一個降級用 div 的版本。 順便補上一些 1.4.2 的新元件。

https://github.com/CateyesLin/Sublime-jQueryMobile-1.4.2-Snippets

[有空] 的話會再 [慢慢] 補完。

2014年4月28日 星期一

Android 4.4 Decode Bitmap From InputStream Return NULL

在 Android 4.4 時,如果 BitmapFactory 重複使用同一個 InputStream 去進行 decode 會回傳 null。
就算第一次只是拿去用 inJustDecodeBounds 也一樣。
每次要使用前都要做 is.reset();



2014年3月31日 星期一

Android Alter Table Column Data Type

CREATE TABLE IF NOT EXISTS **TEMP_TABLE** (id integer primary key autoincrement, **col2change integer not null**, ...)

INSERT INTO TEMP_TABLE SELECT * FROM EXISTING_TABLE

DROP TABLE EXISTING_TABLE

ALTER TABLE TEMP_TABLE RENAME TO EXISTING_TABLE

由於 SQLite 並沒有提供直接修改欄位的功能,因此做以下步驟

  1. 根據需要建立新的暫存 Table scheme
  2. 將資料倒到新的暫存 Table
  3. 刪掉原本的 Table
  4. 將暫存 Table 的名稱修改為原本的 Table 名稱


參考:http://stackoverflow.com/questions/10155834/need-a-good-method-to-change-sqlite-column-data-type

2014年2月25日 星期二

OrmLite ProGuard Setting

OrmLite 的 ProGuard setting


# OrmLite uses reflection
-keep class com.j256.**
-keepclassmembers class com.j256.** { *; }
-keep enum com.j256.**
-keepclassmembers enum com.j256.** { *; }
-keep interface com.j256.**
-keepclassmembers interface com.j256.** { *; }

-keepclassmembers class * { 
  public <init>(android.content.Context); 
}
-keepattributes *Annotation*
沒設定可能會出現 DataField 的 Annotation 無法找到 reference。
參考:http://stackoverflow.com/questions/9853096/proguard-with-ormlite-on-android

2014年2月16日 星期日

Android Free Chart Library Comparison

列一下 Android 的圖表 Library 比較以及看起來的優缺點。

較推薦
  1. AChartEngine:https://code.google.com/p/achartengine/
    仍在維護、支援圖表種類夠多、沒針對 dpi 處理。
  2. AFreeChart:https://code.google.com/p/afreechart/
    久未維護、支援圖表種類夠多、沒針對 dpi 處理、沒針對螢幕大小處理。
  3. AndroidPlot:https://bitbucket.org/androidplot/androidplot/overview
    仍在維護、支援圖表種類夠多、似乎有針對 dpi 處理
其他
  1. HoloGraphLibrary:https://bitbucket.org/danielnadeau/holographlibrary
    仍在維護、支援圖表種類少、有處理 dpi、有處理螢幕大小。
  2. GraphView:https://github.com/jjoe64/GraphView
    較少在維護、支援圖表種類少、dpi 及螢幕尺寸問題因不符需求不確定。
  3. StockChartView:http://stockchartview.org/
    仍在維護、較新出、圖表支援種類尚不足?、未處理 dpi



Convert Project From Subversion To Git Using git2svn

從 SVM 匯入專案到 Git
可手動用 git svn 或是用 git2svn。
而 git2svn 也是 GitHub 推薦的移轉方式

GitHub:https://github.com/nirvdrum/svn2git


用法可參考 README 的說明,不同格式的 svn 配置方式會需要不同的參數。
一般來說用第一個就可以,不過也有例外。

例如這次要將 AChartEngine 做一份 Git Mirror。
由於 AChartEngine 只有 trunk 一個目錄(見上方連結),因此用了第三個方式:

svn2git http://svn.example.com/path/to/repo --trunk trunk --nobranches --notags

2014年2月13日 星期四

Intent Filter android:scheme Must Be In Lowercase

從 Android 4.4 開始,內建瀏覽器改為 Chrome。
而 Chrome 在解讀網址時,會將網址的 scheme 轉為小寫。
因此在實作上要遵從官方的說法。

且官方原本也就建議 Intent Filter 的 scheme 和 host 都必須使用小寫。
官方說明:http://developer.android.com/guide/topics/manifest/data-element.html