Google Code Prettify

2014年7月27日日曜日

NFCカード(payPass)を読んでみた - Octopusカードリーダー使ってみた

カードを読んで、カード番号次第で電源をオンにするような仕組みのプロトタイプを作りたかったので、ちょっとNFCの勉強しました。電源オンの仕組みは以前作ったので、今回取り組んだ案件の肝はカード読み取りです。

まずはカードリーターの確保。いろいろ買っちゃいましたが、案外これだけで十分そうです。HK$148 (2000円弱)で香港中のMTR駅構内のカスタマーサービスで買えます。

Welcome to Octopus Hong Kong - Get Your Octopus - Online Shop
http://onlineshop.octopus.com.hk/cart/?catid=3


ACSのACR122というものですが、シャムスイポだとHK$400とかぼったくられそうな品物ですが、MTRで買えばたったのHK$148です。香港の会社が製造していて、そこそこ海外でも認知されているようで。恐るべし香港。

制御に使うコンピューターですが、またしても、Raspberryで制御です。
持ち運んでどこでも見せることができるし、安いので最近はこればかりいじってます。
関係しそうな情報を片っ端から眺めて、ちょうどいいツールのめぼしをつけました。
やってることは、Linuxでlibnfcを使ってちょっとCとかシェルスクリプトを書いてるだけなんで、Raspberryだけでなくそこら中のLinuxでも同じはずです。

Hacking the NFC credit cards for fun and debit Renaud Lifchitz
http://www.ustream.tv/recorded/21805507
https://www.youtube.com/watch?v=VWIzW0rRw_s

"Hacking the NFC credit cards for fun and debit ;)" presentation slides - HES2012 - Renaud Lifchitz
https://code.google.com/p/readnfccc/downloads/detail?name=hes2012-bt-contactless-payments-insecurity.pdf&can=2&q=

Contacless payments insecurity Renaud Lifchitz - 8.8 Computer Security Conference October 24-25, 2013 – Santiago, Chile
http://www.8dot8.org/2013/deck/8dot8_2013_pres_RL.pdf


readnfccc ... English version
https://github.com/azet/readnfccc/blob/master/readnfccc.c

readnfccc 2.0 ... Spanish version
https://github.com/azet/readnfccc/blob/master/readnfccc.es.c


Complete list of EMV & NFC tags
https://www.eftlab.co.uk/index.php/site-map/knowledge-base/145-emv-nfc-tags

emvlab.org - the one-stop tools site for banking techies
http://www.emvlab.org/

emvlab.org:TLV Utilities - decodes EMV records encoded in tag-length-value (TLV) format.
http://www.emvlab.org/tlvutils/

Getting information from an EMV chip card with Java
http://blog.saush.com/2006/09/08/getting-information-from-an-emv-chip-card/

MasterCard PayPass Vendor Testing Guide (Terminals) Version 1.0 - September 2007
https://www.paypass.com/pdf/public_documents/PayPass%20Vendor%20Testing%20Guide%20Terminals%20Sept07.pdf

この、readnfcccっていうのが、手っ取り早くカード番号を読むのに使えそうなツールなのですが、どうもすんなりとは動きません。libnfcを入れるところから始まり、"byte_t"なんて型知らないとコンパイラに怒られ新しいバージョンを探し直したり、見つかった新しいバージョンもすんなりとは動作せず、自分の環境、カードで動作させるために、電文の内容を把握することが必要そうです。。ところどころプログラムをいじくって、どうにかこうにか、payPassカード番号だけは読み込むようになりました。。
下記のような雰囲気の修正をちょこちょこしてます。
単なるPoCだったのに、だいぶ疲れたのでもうおしまいです。

52c52
<   uint8_t SELECT_APP[] = {0x00, 0xA4, 0x04, 0x00, 0x07, 0xA0, 0x00, 0x00, 0x00, 0x04, 0x10, 0x10, 0x00};
---
>   uint8_t SELECT_APP[] = {0x00, 0xA4, 0x04, 0x00, 0x07, 0xA0, 0x00, 0x00, 0x00, 0x42, 0x10, 0x10, 0x00};
166,167c163
<     if (*res == 0x15 && *(res + 1) == 0x57) {
<     // if ( *(res + 1) == 0x57) {
---
>     if (*res == 0x9c && *(res + 1) == 0x57) {

2014年7月26日土曜日

Raspberry起動時にIP通知

出先にて、iPhoneやPocket Wifiを経由してRaspberryをインターネット接続している時に、iPadやらiPhoneからRaspberryにログインしたい時があります。Raspberry起動時にIP通知されるようにしました。

これを参考にメール設定。
TNET Raspberry Pi Site/ SMTP Mail Setup
http://rpi.tnet.com/project/faqs/smtp

具体的にはこんな感じで。
sudo apt-get install ssmtp
sudo apt-get install mailutils
sudo apt-get install mpack
pi@raspberrypi ~/wemo $ cat /etc/ssmtp/ssmtp.conf
#
# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
root=postmaster

# The place where the mail goes. The actual machine name is required no 
# MX records are consulted. Commonly mailhosts are named mail.domain.com
#mailhub=smtp.gmail.com:587

# Where will the mail seem to come from?
#rewriteDomain=

# The full hostname
hostname=raspberrypi

# Are users allowed to set their own From: address?
# YES - Allow the user to specify their own From: address
# NO - Use the system generated From: address
#FromLineOverride=YES


AuthUser=xxxxxx@gmail.com
AuthPass=xxxxxxxxx
FromLineOverride=YES
mailhub=smtp.gmail.com:587
UseSTARTTLS=YES

メール送信
echo "sample text" | mail -s "Subject" username@domain.tld

添付ファイル送信

mpack -s "test" /home/pi/test/somefile.ext username@domain.tld

Crontabに起動時の処理を設定
pi@raspberrypi ~/wemo $ crontab -l
MAILTO=""
@reboot /home/pi/wemo/reboot-notification
pi@raspberrypi ~/wemo $ cat reboot-notification
#!/bin/bash

echo `sudo ifconfig | mail -s "Reboot-Raspberry" xxxx@xxxxx.com`

これで、起動時にifconfigの内容がメールで届きます。実行内容を通知するうるさいメールはMAILTO=""で止めてます。

2014年6月23日月曜日

自作ネット家電 - Wemo制御をRaspberry Piで


前回導入した「エアコン制御のWemo」のため、単なるリモコン機能を作りたいだけなので、マイコンボードとでっかいボタンを買えば何とかなると思い、ArduinoとRaspberry Piのどちらにすればいいか悩み始めました。

Raspberry Piのほうが、フル機能のLinuxとして使い回しが楽そうで、どっちも大した値段ではないので、Raspberry Piを買いました。配線を減らしたいので、Wifiトークンを買い、基盤のままの運用は危なっかしいので透明なカバーも購入しました。シャムシュイポを歩き回って見つけ出したお店でしめてHK$530なり。びた一文もまけてくれなかった。






公式サイトからRASPBIANをダウンロードして、ラズビアン(レズビアン?)をインストールします。

Downloads | Raspberry Pi
http://www.raspberrypi.org/downloads/

INSTALLING OPERATING SYSTEM IMAGES ON MAC OS
http://www.raspberrypi.org/documentation/installation/installing-images/mac.md

Raspberry Pi の初期設定

Shell Script To Control Belkin WeMo’s

Shell Script To Control Belkin WeMo’s

RaspberryにWifi USBをくっつけて、Curl, Awkを入れた後、簡単なスクリプトをセットアップするだけでリモコンになりました。
ボタンと基盤を買ってみたものの、ベッドの上での乱暴な操作に耐えるにはきちんとした操作パッドが必要だと後になってから気がついたので、ファミコンキーパッドを買ってきました。これまたシャムスイポでHK$80。(写真は外部からの転用)




RaspberryPiでJoypadからコマンド入力
http://www.kotemaru.org/2013/08/25/raspberry-pi-joypad-command.html



2014年6月16日月曜日

自作ネット家電 - Wemoでエアコン電源制御

こんなものを買ってみました。照明制御とか空調制御とか。冬場のオイルヒーター制御にはフレキシブルなスケジュール制御や、出先からの電源制御があるといいので、こういうものが役に立ちそうだと、漠然な思いで買いました。10年近く前に秋月で購入した電源制御デバイスは有線LANや電源配線が煩雑で、感電/火事にならないかヒヤヒヤしたもので、結局実用にはいたりませんでした。
先月引っ越してきたフラットの寝室にはこんなエアコンがありました。リモコンは無く、壁のスイッチでオンオフします。寝たまま制御できないので、えらく困ります。

遠隔制御の第一歩として、まず電源プラグをくっつけました。壁からひっぺがして抜き差しできるコンセントにしました。




こんな感じにして、間にWemoをくっつけます。


Wemoが間に入り電源を制御できるようになりました。








すんなりとiPhoneで電源制御できるようになりましたが、いちいちiPhoneで操作するのがやっぱり面倒です。やっぱりリモコンがあるといいですが、ネット制御も捨てがたいです。という訳で、組み込み型のLinuxマシンのようなものを見っけて、それにボタンをくっつけて、「リモコン」を自作することにしました。これに関しては次の投稿で。

2013年1月6日日曜日

Nexus 7 3GにSMS機能を付加する

root化後に下記の手順を実行

Native SMS Nexus 7 3G texting send/receive/manage with stock JB mms.apk



Download file
Unzip
Load "mms.apk" into system/app and set permissions
Reboot

./abd shell  ... login to Android device
./abd push xxxx.apk /system/app  ...  apkをインストール

Error "Read-only file system" ==>
mount -rw -o remount /dev/block/mtdblock1 /system

2012年11月25日日曜日

iPhoneの「その他」メモリの削除方法

こんなようなことをして、iPhoneの「その他」メモリの削除成功しました。もう数ヶ月も数多を痛めてたので、ちょっと嬉しいなと。

1. PhoneClean ⇒ help a little bit
2. Restore from Backup ⇒ no help
3. Delete "F" folders in "iTunes Control/Music" by iExplorer ⇒ help huge (deleted 10GB)

この記事が一番有用でした。「8.8gb of "Other" memory?」
First off we will start with the basic things.Delete the cache, history, and cookies on any browser you have on the phone.Removing apps that you don't use or play anymore will also help. I believe game saves and settings in the apps also counts as other, but I could be wrong.Delete any trash or junk email. Sometimes it can build up, usually the iphone will delete it after a certain amount of days, but its always good to double check.Delete any tweaks or themes you don't use anymore in Cydia.Plug your iPhone into iTunes and uncheck open iTunes when iPhone is connected. This presumably makes iTunes double check your "other" data.
Now onto the more complicated stuff, you will need ifile, winscp, or anything like these to access the iPhones internal files. I will guide you through ifile since its what I used. I recommend holding "Power" and "Home" until your device turns off and turning it back on after everytime you delete something. Keep in mind that ifile by standard doesn't delete anything, when you click edit a trash can will show up on the bottom and you can empty the trash that way.Delete anything in the following folders (unless noted otherwise):var/mobile/media/applicationarchivesvar/mobile/media/downloadsvar/spool/mdtvar/mobile/ifile/trashvar/mobile/library/logs look for a file called ilocalis.log, if its there delete itvar/mobile/library/application/support/containers/ Look if there is anything big in there. (the blue button on the right will tell you how big the folder is among other information)
Okay now onto the next part: we can try to locate just one giant file that could be taking up all of your memory.You'll need to download terminal from cydia.Open terminal after it downloads.type su and hit returnThe password by default is: alpine the password will not show while typing it, again hit returnNow type find . -size +100M Make sure that M is capitalizedNotices the spaces find (space) . (space) -size (space) +100M CAPITALIZE THE MThis will now list anything with anything over 100MB. It will also list where the file can be found via ifile or winscp.At this point I can't really help you out, its your choice on what to delete and what not to delete. If you really need some help you can post a screenshot here or  and hopefully someone from imore or Modmyi can help you.
Now onto the last resorts.Launch iTunes and remove all of your music, make sure you have an purchased music transferred to the computer, hopefully you don't have any music that is on your iphone that isn't on your computer.Go into ifile.Tap the "Gear" icon and tap "Hidden Files" to turn it on.Tap "Done," then tap the "Back" navigation button to go all the way back to the root folder.Var/Mobile/Media/iTunes Control/MusicYou should see a bunch of folders that begin with an "F."Delete them all.Hold "Home" and "Power" simultaneously to restart the device.
The other last resortVar/Mobile/Cache I deleted this entire folder. It deletes all of your apps and all of your settings.

2012年1月29日日曜日

ドメインの移管とメールサーバーの移管

自分のドメインをno-ipからもっと安いサービスへ移管し、自宅サーバーで運用してたメールサーバーをgmailへ移管する作業を2,3ヶ月前に済ませたのですが、いまさらトラブルが見つかったので、その対処をしていたのですが、何をどう設定したのかすっかり忘れてしまい復習から始めました。同じことで困らないようにいくらか肝になるなる設定ポイントと参考にしたページをまとめておきます。

Whois登録情報の確認・修正 
  1. Whois登録情報の確認・修正
    ここに記載されているメールアドレスに認証コードに関するメールが届くので、正しくなければ更新しておく。更新するには、今現在利用しているDNSサービスプロバイダー(移管元)のページにアクセスして登録内容を更新するのが一般的。
  2. 移管元のDNSサービスプロバイダーから認証コード(Authcode)を取得 
    このときドメインロックをはずしておかないとうまくいかない。
  3. 移管先のDNSサービスプロバイダーに認証コードを入力する 
    自分のドメイン名を登録するのですが、移行の場合、認証コードの入力を求められる。これを入力することでドメイン名の移行が処理される。
  4. 移管先のDNSの設定を行う(MXレコード等) 
    メールが正しいメールサーバーに配信されるように設定。あと、移管先のネームサーバーを利用するように設定することも忘れずに。(単純に移管しただけの状況だと、移管元のネームサーバーが登録されたままのことがあります)
DNSの設定
(Google Appsのメールサービスを使うようにDNS設定をする)
mx aspmx.l.google.com. 10
mx alt1.aspmx.l.google.com. 20
mx alt2.aspmx.l.google.com. 20
mx aspmx2.googlemail.com. 30
mx aspmx3.googlemail.com. 30
mx aspmx4.googlemail.com. 30
mx aspmx5.googlemail.com. 30
txt @ v=spf1 include:aspmx.googlemail.com ~all


Gmailを独自ドメインのメールアドレスで利用

2011年7月6日水曜日

中国からあれこれアクセス

中国に住んでいて、やっぱり困っている人をちらほら見かけるので、もうちょっと具体的な説明を書いておきます。手っ取り早く説明すると、下記のどれかが必要です。
  • hotspot shield
  • Ultrasurf
  • Freegate

UltraSurf | 中国でyoutube twitter facebookを使おう!vpntube


Freegate 6.80無料ダウンロード


日本を拒否するムカつく海外サイトは「Hotspot Shield」で突破


2011年7月5日火曜日

ScanSnap S1500で名刺管理 - Evernoteでイクある

もともと名刺管理には、iPhoneのWorldCard Mobileを使ってたのですが、ちまちま1枚ごと写真を撮って、認識した文字を若干修正して、連絡先(Contacts)データベースにエクスポート⇒Googleへの自動同期、、、なんてことをしてたのですが数枚登録したところでくたびれてしまいました。そこで、ScanSnapの登場です。

ScanSnap S1500香港正規品バージョンにおまけで付いてきた名詞管理ソフトは、「CardMinder」ってもので、これがまたさっぱり名刺上の文字を認識しません。

住所とか、肩書きとかきっちり取り込んでほしい情報をばっちり逃しています。Googleに情報をのっけて自動的に各デバイスが情報を同期するようにしたかったのに、しょっぱなでこけてしまいました。

仕方ないのであれこれ調べた結果、自分には下記のソリューションが一番だと結論がでました。
  1. スキャン画像(Jpeg)を自動でEvernoteに流し込む
  2. Evernoteで最低限の仕分けを行う(仕事用と遊び用みたいな)
  3. EvernoteのOCR機能に頼り、文字検索可能な画像集になっているので、それをオフライン同期しておく、
  4. 必要に応じEvernoteの画像をWorldMobileにコピーして連絡先への追加を行う
#Evernoteで名刺検索をしていて、連絡先に登録しておくべき名詞であると判断した場合、いったん画像をカメラロールに転送し、それをWorldCard Mobileで取り込む

参考にしたページ:

2011年7月3日日曜日

裁断機はCarlのDC-210Nできまり

ScanSnap S1500を入手して、裁断機はどうしようかと考え続けてたところ、下記のような記事が目に留まり、自動的に購入が決定しました。

600冊自炊した私が、それでもCarlの裁断機をオススメする理由

幸いに、自分が住んでいる香港ならば気軽にTaobaoで買い物ができるので、Carl DC-210NもさくっとTaobaoから購入できました。かなり割安です。ただ、海外版ScanSnapには性能のいい名刺管理ソフトがついてないので、損をしている部分もあるわけで。。

Amazonだと1万円なのですね。
代理購入とかして、小遣い稼ぎできそうな。
Amazon.co.jp: カール事務器 ディスクカッター DC-210N