Testing and Securing Android Studio ApplicationsのKindle版が安かったのと米国レビューもそこそこあったので読んでみました。あと、TestingとSecuringを同時に扱っていたので、基礎的な知見もまとめられているものと期待して。
結果的には、出版日も2014年8月とそんなに古くないので、入り口的な書籍としては良いと思いました。ツールやコードの話もありますが、まだ古くて使えない、というレベルのものではないですし。
内容的には、intentに対するUnit testレベルとInstrumentationを使ったレベルでのテスト方法が、個人的には何気に参考になりました。
以下は、私の備忘録込みでつらつらと…
第1章では基本的なソフトウェアセキュリティ全般の話。
- Access control
- Asymmetric cryptography
- Authentication
- Availability
- Brute force
- Cipher
- Code injection
- Confidentiality
- Crack
- Decryption
- Denial-of-service(DoS)
- Distributed denial-of-service(DDoS)
- Dictionary attack
- Encryption
- Hash function
- Hijack attack
- Hypertext Transfer Protocol Secure
- Integrity
- MD5
- Man-in-the-middle attack
- Password
- Phishing
- Risk
- SHA1
- Sniffing attack
- Spoofing attack
- Threat
- Vulnerability
このうち、Threat、Vulnerabilities、risksに関してはさらに言及されていました。
Threat
- Interception
- Interruption
- Modification
- Fabrication
Vulnerability
- Improper authentication
- Buffer overflow
- Cross-site scripting(XSS)
- Input validation
- SQL injection
他、Secure code-designの基本として、いくつか原則をあげてたりします。
- Secure defaults
- Least privileges
- Clarity
- Small surface area
- Storage defence
- Failing securely
- Not trusting the third-party companies
- Simplicity
- Address vulnerabilities
Bugs lurk in corners and congregate at boundaries
本書では、テストタイプとして
- White box testing
- Control flow testing
- Data flow testing
- Basic path testing
- Statement coverage
- Black box testing
- Equivalence partitioning
- Boundary value analysis
- Cause-effect graphing
- State transition testing
- All pairs testing
- Syntax testing
あげていました。テストレベルとしては、
- Unit tests
- Integration tests
- Validation tests
- System tests
- Acceptance tests
という用語を使っていました。
2章から、Android Applicationに焦点をあてて、モバイル環境独自の特徴、Android securityの全体像、というように話を進めていました。
Androidにはsandboxingとって、アプリケーションごとにデータや実行を隔離する環境があります。そのほかにも、Secureな構造にするために以下のような機能を持っています。
- Application-defined permissions
- Interprocess communication
- Support for secure networking
- Support for cryptography
- Encrypted file system
- Application signing
それぞれに対して、コードなどを用いて説明を付与しているのですが、順にまとめられているのでチュートリアルよりざっと全体を把握できて良い感じ。また、セキュリティという観点から機能の説明を行っている場面も多いので、単なる機能的な側面よりも、非機能的な側面の理解が進みそうです。
3章ではモニタリング系。おなじみのDDMSでHeapやTraficを見たりする機能の、ツールな説明なので比較的すぐに陳腐化しそう。
4章では、Mitigating Vulnerabilitiesということでリスクを軽減する手段をまとめてます。
扱っていた項目はいか。
- Input validation
- android:inputType=”phone”のような要素を加える方法など
- SQL injection
- Permissions
- Handling a user’s data and credentials
- Interapplication communication
- Securing Intents
- Securing the content providers
の話題がありました。
5章はプライバシーに関する内容。主にはプライバシーデータ、暗号化、データの暗号化に関して話をしています。
Androidではデータの保存先として以下があります。
- Shared preference(key-value)
- Internal storage
- /data/data/yourpackage/files
- External storage
- SDカード
- DB
暗号化
- Symmetric
- Asymmetric or public-key
暗号化のアルゴリズムとして、PBKDF2の使い方をこの本では書いていました。Android4.4からこの方式に変わったそうですね。(でも、OSをまたいだデータ保存ではハマりポイントがあったような…)
SecretKeyFactory skf = SecretKeyFactory.getinstance("PBKDF2WithHmacSHA1");
6章ではSecuring Communication。おなじみのHTTPS、TLS、certificationなどの話です。ここら辺は情報系を学ぶと一般的な知識になるOSI Modelの話なんかがあっただけです。
7章では認証方法。パスワード、パターン、PINやアカウントマネージャの話。まぁ、飛ばして良さそうな。
8章からテストの話です。
UIのテストをするためにuiautomatorを使う話だけでした。UiSeceltor系だったり。
9章では、Unit/Functional Testingの話です。
ここの内容は2014年12月にでたAndroid Test Support Librariesのリリースで陳腐化した内容でもあるので、今から取り組む人はチュートリアル読んだ方がよさげなところ。
この中でも、 The activity Intent test は個人的に役に立ちました。
- Unit test level
- getStartdActivityIntnet を使ってnot nullを確認する
- UI test level
- instrumentsを経由してActivityMonitor objectを使う
... Instrumentation.ActivityMonitor monitor = getInstrumentation().addMonitor(SecondActivity.class.getName(), null, false); TouchUtils.clickView(this, mValidate); SecondActivity secondActivity = (SecondActivity)monitor.waitForActivityWithTimeout(2000); asserNotNull(secondActivity); getInstrumentation().removeMonitor(monitor); ...
他、stametemt testだと、
- callActivvityOnPause
- callActivityOnResume
をUiThreadTestとして実施するというものもありました。
ちょっとここら辺は知らなかった…
10章は補助ツール
- Spoon
- Mockit
- Android Mock
- FEST Android
- Roboletric
-
Robotium
- Espresso
- Appium
- Calabash
- MonkeyTalk
- Bot-bot
- Monkey
- Wireshark
など。
ツール系はあらかた知っているものでしたし、テストに関してはAndroid特有のActivityに関するテストが目新しいものでした。
一方、セキュリティ関係は全体を知る必要もあるのでよかったと思います。タオソフトのSecurity本よりも年代が新しいのと、ざっとまとまっているので全体的に話を把握したい人には良い本かも?
2 Comments