New Concept of the Android Keystore Service with Regard to Security and Portability
Total Page:16
File Type:pdf, Size:1020Kb
University of Bremen Department of Mathematics and Computer Science New concept of the Android keystore service with regard to security and portability. Master’s Thesis by Fritjof Bornebusch reviewed by Dr. Karsten Sohr Prof. Dr. Jan Peleska supervised by Dipl. Inf. Florian Junge 2016 Confirmation I hereby confirm that I wrote this master thesis on my own and that I have used only the indicated references, resources, and aids. In German: Hiermit bestätige ich, dass ich die vorliegende Masterthesis selbstständig verfasst, und keine anderen als die angegebenen Quellen und Hilfsmittel verwendet habe. Bremen, 1/13/2016 Fritjof Bornebusch “Any fool can write code that a computer can understand. Good programmers write code that humans can understand.” – Martin Fowler – Bornebusch, Fritjof New concept of the Android keystore service with regard to security and portability. Master’s thesis, Department 3 - Mathematics / Computer Science University of Bremen, 2015 This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License (CC BY-NC-SA 4.0). To view a copy of this license, send an email to [email protected], visit http://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons, PO Box 1866, Mountain View, California, 94042, USA. Table of Contents Acknowledgements 7 List of Figures 9 List of Listings 10 Acronyms 13 Glossary 15 1 Introduction 19 2 Background 24 2.1 Android System Architecture . 24 2.1.1 Security-Enhanced Linux . 28 2.1.2 Capabilities . 31 2.2 Memory Vulnerabilities . 32 2.2.1 Buffer Overflow Protection . 33 2.2.2 Dead Store Elimination . 36 2.3 Encryption . 38 2.3.1 Symmetric-Key Algorithm . 38 2.3.2 Asymmetric-Key Algorithm . 39 2.3.3 Mode of Operation . 40 2.4 Hashing . 41 2.4.1 Secure Hash Algorithm . 42 2.4.2 Passphrase . 42 2.5 Signature . 43 5 TABLE OF CONTENTS 3 Analysis of the Android keystore service 45 3.1 Design . 46 3.1.1 The Android RPC subsystem . 47 3.1.2 Architecture of the Android keystore service . 48 3.2 Application Programming Interface . 57 3.2.1 Java . 57 3.2.2 C++ . 58 3.3 Implementation . 59 3.3.1 Coding Style . 59 3.3.2 Library Functions . 60 3.3.3 SELinux . 65 3.3.4 Compiler Flags . 67 3.3.5 Logging . 68 3.3.6 Folder structure . 71 3.4 Init subsystem . 72 3.5 Implemented hashing algorithm . 74 3.5.1 Master key generation . 77 3.6 Implemented encryption algorithm . 79 3.7 Result . 81 4 Implementation of the new keystore service 84 4.1 Design . 85 4.2 Implementation . 85 4.2.1 Compiler Flags . 87 4.2.2 Folder structure . 90 4.2.3 Application Programming Interface . 91 4.3 Security . 91 4.3.1 Hashing . 92 4.3.2 Encryption . 93 4.4 Portability . 97 4.4.1 Design . 98 4.4.2 Privilege Separation . 99 4.4.3 Implementation . 104 4.5 Result . 112 6 TABLE OF CONTENTS 5 Evaluation 114 5.1 Android . 114 5.1.1 Testing . 115 5.2 Portable version . 116 5.2.1 Testing . 118 5.3 Result . 119 6 Conclusion and Future Work 120 6.1 Conclusion . 120 6.2 Future Work . 123 Bibliography 125 Appendices 129 A Static analysing logs 131 B keystore_cli(1) usage 133 C ks(1) usage 134 D Android keystore compiler flags 135 E Portable keystore compiler flags 136 F Structures for sending and receiving 138 G Class diagram 140 7 Acknowledgements Thank you Prof. Dr. Jan Peleska, Dr. Karsten Sohr, and Florian Junge for making this thesis possible with your believing in the relevance of this topic. This document is my own work, but it would not be in this shape without the help of friends. They spotted weak arguments, linguistic and technical errors, as well as poor sentences and made this thesis comprehensive and focused. Without their help it would not be in this shape. Aaron Lye Thank you for your comments, for the discussions about the technical aspects of this document, and for checking the bibliography. Christina Plump Thank your for your comments, linguistic corrections, and the discussions about weak argumentations. Max Nitze Thank you for your comments, and the discussions about the technical aspects of this document. Kai Hillmann Thank you for the discussions about the structure of this document. Edina Alessa Staschewski Thank you for supporting me in my lazy times and pushing me back to work. At last, a big thank you to those who are not listed by name here for supporting me when I was busy. This helped me a lot to finish my study by writing this master thesis. 8 List of Figures 2.1 Android system architecture . 25 2.2 Android intents . 27 2.3 Stack layout . 34 2.4 Stack layout with canary . 34 2.5 Time to brute-force 128 bit AES key . 39 2.6 Electronic Codebook mode . 40 2.7 Cipher Block Chaining mode . 41 2.8 Keyed-Hash Message Authentication Code . 43 3.1 Android keystore service design . 46 3.2 The Android RPC subsystem . 47 3.3 Android keystore service class diagram . 49 3.4 MD5 value hashing . 76 3.5 Original plain text encryption . 81 3.6 scan-build(1) errors . 82 3.7 gcc(1) flag errors . 82 4.1 Portable keystore service design . 98 4.2 Design of the portable version . 99 G.1 Keystore transactions . 140 G.2 Class dependency diagram . 141 G.3 Class keystore . 142 G.4 Classes blob and entropy . 143 G.5 Class userstate . 144 9 List of Listings 2.1 Dead store elimination example . 36 2.2 Dead store elimination without optimizations . 37 2.3 Dead store elimination with optimizations . 37 3.1 BnKeystoreService: onTransaction method implementation . 51 3.2 grant_t type ................................... 52 3.3 Register keystore proxy . 53 3.4 BpKeystoreService: test method implementation in keystore service . 54 3.5 Accessing BpKeystoreService from the keystore client . 54 3.6 Original blob structure . 56 3.7 memcpy(3) function call . 60 3.8 malloc(3) function call . 61 3.9 malloc(3) function call in keystore service . 61 3.10 atoi(3) function call . 62 3.11 atoi(3) function call no. 1 . 63 3.12 atoi(3) function call no. 2 . 63 3.13 strtol(3) function call . 64 3.14 Convert string to int safely . 64 3.15 SELinux permissions . 65 3.16 SELinux users . 66.