Formal Methods for Secure Software Construction
Total Page:16
File Type:pdf, Size:1020Kb
Formal Methods for Secure Software Construction by Ben Goodspeed A Thesis Submitted to Saint Mary's University, Halifax, Nova Scotia in Partial Fulfillment of the Requirements for the Degree of Master of Science in Applied Science. April, 2016, Halifax, Nova Scotia Copyright Ben Goodspeed. Approved: Dr. Stavros Konstantinidis Supervisor Approved: Dr. Diego Rojas Examiner Approved: Dr. Cristian Suteanu Examiner Approved: Dr. Peter Selinger Examiner Date: April 8, 2016 Abstract Formal Methods for Secure Software Construction by Ben Goodspeed The objective of this thesis is to evaluate the state of the art in formal methods usage in secure computing. From this evaluation, we analyze the common components and search for weaknesses within the common workflows of secure software construction. An improved workflow is proposed and appropriate system requirements are discussed. The systems are evaluated and further tools in the form of libraries of functions, data types and proofs are provided to simplify work in the selected system. Future directions include improved program and proof guidance via compiler error messages, and targeted proof steps. April 8, 2016 \There is no such thing as perfect security, only varying levels of insecurity." Salman Rushdie Acknowledgements Thanks to Dr. Stavros Konstantinidis for supervising this work - providing no end of encouragement and freedom to learn. Thanks to Drs Rojas, Suteanu, and Selinger for their help in making this thesis what it is today. Thank you to Mayya Assouad for putting up with me while I did this, and reading countless drafts. Thanks to my father Dan Goodspeed, my mother Kathy Goodspeed, my aunt Amy Austin and my uncle Wayne Basler for supporting me throughout my education, and always encouraging me. Thank you to everyone at the writing center for helping with many drafts of this work. Thanks as well to Rozina Darvesh, Nicole Carter, Colin Kennedy, Dr Laurie Ricker and Jason Colburne for reading drafts and helping me get into and through graduate school! iii Contents Abstract i Acknowledgements iii List of Figures ix List of Tables xi Glossary xii 1 Introduction1 1.1 Contributions and Organization........................2 1.2 Motivation for Formal Methods........................3 1.3 Definitions of security.............................4 1.4 Trust.......................................5 2 Literature Review6 2.1 Operating systems and Hardware.......................6 2.2 Cryptography..................................7 2.3 Specification/Design..............................8 2.4 Quality Assurance...............................8 2.5 Attack Planning................................9 2.6 Programming Languages............................9 2.7 String Handling................................. 11 3 Background 13 3.1 Building Blocks................................. 13 3.1.1 Lattices................................. 13 3.1.2 Matrices................................. 14 3.1.3 Finite State Machines......................... 15 3.1.4 Zero Knowledge/Interactive Proof.................. 16 3.1.5 Lambda Calculus and Process Calculi................ 16 iv Contents v 3.1.6 Prolog.................................. 17 3.1.7 Markov Decision Processes...................... 17 3.1.8 Formal Verification and Proof assistants............... 18 3.1.9 Category Theory............................ 19 3.1.10 Secure Typed Languages........................ 20 3.2 Uses in defensive security........................... 20 3.2.1 Operating Systems........................... 20 3.2.2 Distributed and Parallel Systems................... 22 3.2.3 Databases................................ 23 3.2.4 Cryptography.............................. 23 3.2.5 Networks................................ 24 3.2.6 Hardware................................ 25 3.3 Uses in offensive security............................ 25 3.3.1 Attack planning............................ 26 3.3.2 Steganography............................. 26 3.4 Well known models............................... 26 3.4.1 Bell LaPadula.............................. 27 3.4.2 Biba................................... 27 3.4.3 Clark Wilson.............................. 28 3.4.4 Brewer Nash.............................. 29 3.4.5 Harrison Ruzzo Ullman........................ 31 3.5 The Mathematics of Strings.......................... 31 3.5.1 Standard................................ 33 3.5.2 Augmented with Negatives...................... 34 3.5.3 Categories................................ 35 3.5.3.1 Monoidal Category..................... 35 3.6 Fundamental Limitations........................... 36 4 Observations and Hypothesis 37 4.1 Definitions of Security............................. 37 4.2 Gaps....................................... 38 4.3 Industry vs Academia............................. 38 4.4 Hypothesis................................... 39 4.5 Methods..................................... 39 4.5.1 Objective: Selecting a Language................... 40 4.5.2 Objective: Proof driven development (PDD)............ 41 4.5.3 Objective: Provable Software Building Blocks............ 42 4.5.4 Objective: Proof tactics and Lemmas................ 42 4.5.5 Prediction: Verifiable Features.................... 42 4.5.6 Prediction: Subsequent Development................. 43 4.6 Summary.................................... 43 5 Selecting a Language 44 5.1 Details...................................... 45 Contents vi 5.1.1 Expressive Power/Toolchain...................... 45 5.1.2 Utility as a Theorem Prover...................... 46 5.1.3 Runnable Code............................. 47 5.1.4 Performance/Usability......................... 48 5.2 Coq....................................... 48 5.2.1 Tactics.................................. 49 5.2.2 Sample Code and Results....................... 50 5.3 Agda....................................... 51 5.3.1 Sample Code and Results....................... 52 5.4 Haskell...................................... 53 5.4.1 Sample Code and Results....................... 53 5.5 Isabelle..................................... 54 5.5.1 Sample Code and Results....................... 54 5.6 Idris....................................... 55 5.6.1 Sample Code and Results....................... 56 5.7 Summary.................................... 56 6 Proof Driven Development (PDD) 58 6.1 Waterfall.................................... 59 6.2 Agile/TDD................................... 59 6.2.1 Example Fixed Value Quantification Problems........... 61 6.3 PDD....................................... 63 6.3.1 Design By Contract.......................... 66 6.4 Examples.................................... 66 6.4.1 Standard Approach.......................... 67 6.4.2 PDD Approach............................. 68 6.5 Impacts..................................... 70 7 Secure Programming 71 7.1 Authentication................................. 71 7.1.1 Implementation in practice...................... 73 7.1.2 Cryptography.............................. 73 7.2 Formally Verified................................ 74 7.3 Implementation................................. 75 7.3.1 Examples and Pseudocode....................... 76 7.3.2 Idris................................... 77 8 Provable Software Building Blocks 81 8.1 String Handling................................. 81 8.1.1 General purpose language string representations.......... 82 8.1.2 Using Proof Assistants to Formalize Strings............. 82 8.1.3 API................................... 83 8.1.4 Primitive Delegation.......................... 84 8.1.5 Representation............................. 85 Contents vii 8.1.5.1 Cons Cells.......................... 85 8.1.6 Printf/Scanf............................... 86 8.2 Utilities..................................... 87 8.2.1 Rational................................. 87 8.2.2 Monadic State Helpers......................... 88 8.2.3 NFA................................... 88 8.2.4 Power List............................... 88 8.2.5 Permutations.............................. 88 8.2.6 Cyclic Shifts.............................. 89 8.3 Benchmarks................................... 89 8.3.1 Fib.................................... 89 8.3.2 Ackermann............................... 90 8.3.3 Sieve................................... 90 8.3.4 Binary Trees.............................. 90 8.4 Summary.................................... 90 9 Proofs and Tactics 99 9.1 Lists....................................... 99 9.1.1 Quantifiers............................... 100 9.1.2 Decision Procedures.......................... 100 9.2 Boolean Values and Lazy Evaluation..................... 101 9.3 Mathematical Structures............................ 102 9.4 Summary.................................... 103 10 Code Savings and Benchmark Results 108 10.1 Benchmark Results............................... 110 10.2 Contributions Revisited............................ 111 11 Related Work 113 12 Conclusion 115 12.1 Future Work.................................. 115 12.1.1 Error Messages............................. 116 12.1.2 Proof Targeting............................. 116 12.2 Summary.................................... 116 Bibliography 117 Appendix - Idris Syntax Guide 129 Appendix - Code 132 A.1 Extracted Code................................. 132 Contents viii Appendix - String Handling Code 140 A.2 Homomorphism................................. 140 A.3 ListQuantifiers................................. 142 A.4 ListCharDec................................... 144 A.5 ListDecisions.................................. 146 A.6 ListWord...................................