logo资料库

A Practical Guide to TPM 2.0.pdf

第1页 / 共375页
第2页 / 共375页
第3页 / 共375页
第4页 / 共375页
第5页 / 共375页
第6页 / 共375页
第7页 / 共375页
第8页 / 共375页
资料共375页,剩余部分请下载后查看
A Practical Guide to TPM 2.0
Contents at a Glance
About ApressOpen
Contents
About the Authors
About the Technical Reviewers
Acknowledgments
Introduction
Chapter 1: History of the TPM
Why a TPM?
History of Development of the TPM Specification from 1.1b to 1.2
How TPM 2.0 Developed from TPM 1.2
History of TPM 2.0 Specification Development
Summary
Chapter 2: Basic Security Concepts
Cryptographic Attacks
Brute Force
Calculating the Strength of Algorithms by Type
Attacks on the Algorithm Itself
Security Definitions
Cryptographic Families
Secure Hash (or Digest)
Hash Extend
HMAC: Message Authentication Code
KDF: Key Derivation Function
Authentication or Authorization Ticket
Symmetric-Encryption Key
Symmetric-Key Modes
Nonce
Asymmetric Keys
RSA Asymmetric-Key Algorithm
RSA for Key Encryption
RSA for Digital Signatures
ECC Asymmetric-Key Algorithm
ECDH Asymmetric-Key Algorithm to Use Elliptic Curves to Pass Keys
ECDSA Asymmetric-Key Algorithm to Use Elliptic Curves for Signatures
Public Key Certification
Summary
Chapter 3: Quick Tutorial on TPM 2.0
Scenarios for Using TPM 1.2
Identification
Encryption
Key Storage
Random Number Generator
NVRAM Storage
Platform Configuration Registers
Privacy Enablement
Scenarios for Using Additional TPM 2.0 Capabilities
Algorithm Agility (New in 2.0)
Enhanced Authorization (New in 2.0)
Quick Key Loading (new in 2.0)
Non-Brittle PCRs (New in 2.0)
Flexible Management (New in 2.0)
Identifying Resources by Name (New in 2.0)
Summary
Chapter 4: Existing Applications That Use TPMs
Application Interfaces Used to Talk to TPMs
TPM Administration and WMI
The Platform Crypto Provider
Virtual Smart Card
Applications That Use TPMs
Applications That Should Use the TPM but Don’t
Building Applications for TPM 1.2
TSS.Net and TSS.C++
Wave System s Embassy Suite
Rocks to Avoid When Developing TPM Applications
Microsoft BitLocker
IBM File and Folder Encryption
New Manageability Solutions in TPM 2.0
Summary
Chapter 5: Navigating the Specification
TPM 2.0 Library Specification: The Parts
Some Definitions
General Definitions
Definitions of the Major Fields of the Command Byte Stream
Definitions of the Major Fields of the Response Byte Stream
Getting Started in Part 3: the Commands
Data Details
Common Structure Constructs
TPM2B_XXX Structures
Structure with Union
Canonicalization
Endianness
Part 2: Notation Syntax
Part 3: Table Decorations
Commonly Used Sections of the Specification
How to Find Information in the Specification
Strategies for Ramping Up on TPM 2.0
Will
Ken
Dave
Other TPM 2.0 Specifications
Summary
Chapter 6: Execution Environment
Setting Up the TPM
Microsoft Simulator
Building the Simulator from Source Code
Setting Up a Binary Version of the Simulator
Running the Simulator
Testing the Simulator
Python Script
TSS.net
System API Test Code
Setting Up the Software Stack
TSS 2.0
TSS.net
Summary
Chapter 7: TPM Software Stack
The Stack: a High-Level View
Feature API
System API
Command Context Allocation Functions
Command Preparation Functions
Command Execution Functions
Command Completion Functions
Simple Code Example
System API Test Code
TCTI
TPM Access Broker ( TAB)
Resource Manager
Device Driver
Summary
Chapter 8: TPM Entities
Permanent Entities
Persistent Hierarchies
Ephemeral Hierarchy
Dictionary Attack Lockout Reset
Platform Configuration Registers ( PCR s)
Reserved Handles
Password Authorization Session
Platform NV Enable
Nonvolatile Indexes
Objects
Nonpersistent Entities
Persistent Entities
Entity Names
Summary
Chapter 9: Hierarchies
Three Persistent Hierarchies
Platform Hierarchy
Storage Hierarchy
Endorsement Hierarchy
Privacy
Activating a Credential
Other Privacy Considerations
NULL Hierarchy
Cryptographic Primitives
Random Number Generator
Digest Primitives
HMAC Primitives
RSA Primitives
Symmetric Key Primitives
Summary
Chapter 10: Keys
Key Commands
Key Generator
Primary Keys and Seeds
Persistence of Keys
Key Cache
Key Authorization
Key Destruction
Key Hierarchy
Key Types and Attributes
Symmetric and Asymmetric Keys Attributes
Duplication Attributes
Restricted Signing Key
Restricted Decryption Key
Context Management vs. Loading
NULL Hierarchy
Certification
Keys Unraveled
Summary
Chapter 11: NV Indexes
NV Ordinary Index
NV Counter Index
NV Bit Field Index
NV Extend Index
Hybrid Index
NV Access Controls
NV Written
NV Index Handle Values
NV Names
NV Password
Separate Commands
Summary
Chapter 12: Platform Configuration Registers
PCR Value
Number of PCRs
PCR Commands
PCRs for Authorization
PCRs for Attestation
PCR Quote in Detail
PCR Attributes
PCR Authorization and Policy
PCR Algorithms
Summary
Chapter 13: Authorizations and Sessions
Session-Related Definitions
Password, HMAC, and Policy Sessions: What Are They?
Session and Authorization: Compared and Contrasted
Authorization Roles
Command and Response Authorization Area Details
Command Authorization Area
Command Authorization Structures
Response Authorization Structures
Password Authorization: The Simplest Authorization
Password Authorization Lifecycle
Creating a Password Authorized Entity
Changing a Password Authorization for an Already Created Entity
Using a Password Authorization
Code Example: Password Session
Starting HMAC and Policy Sessions
TPM2_StartAuthSession Command
Session Key and HMAC Key Details
Guidelines for TPM2_StartAuthSession Handles and Parameters
Session Variations
Salted vs. Unsalted
Bound vs. Unbound
Use Cases for Session Variations
HMAC and Policy Sessions: Differences
HMAC Authorization
HMAC Authorization Lifecycle
Altering or Creating an Entity That Requires HMAC Authorization
Creating an HMAC Session
Using an HMAC Session to Authorize a Single Command
HMAC and Policy Session Code Example
Using an HMAC Session to Send Multiple Commands (Rolling Nonces)
HMAC Session Security
HMAC Session Data Structure
Policy Authorization
How Does EA Work?
Policy Authorization Time Intervals
Policy Authorization Lifecycle
Building the Entity’s Policy Digest
Creating the Entity to Use the Policy Digest
Starting the Real Policy Session
Sending Policy Commands to Fulfill the Policy
Performing the Action That Requires Authorization
Combined Authorization Lifecycle
Summary
Chapter 14: Extended Authorization (EA) Policies
Policies and Passwords
Why Extended Authorization?
Multiple Varieties of Authentication
Multifactor Authentication
How Extended Authorization Works
Creating Policies
Simple Assertion Policies
Passwords (Plaintext and HMAC) of the Object
Passwords of a Different Object
Digital Signatures (such as Smart Cards)
PCRs: State of the Machine
Locality of Command
Internal State of the TPM (Boot Counter and Timers)
Internal Value of an NV RAM Location
State of the External Device (GPS, Fingerprint Reader, and So On)
Flexible (Wild Card) Policy
Example 1: Smart card and Password
Example 2: A Policy for a Key Used Only for Signing with a Password
Example 3: A PC state, a Password, and a Fingerprint
Example 4: A Policy Good for One Boot Cycle
Example 5: A Policy for Flexible PCRs
Example 6: A Policy for Group Admission
Example 7: A Policy for NV RAM between 1 and 100
Command-Based Assertions
Multifactor Authentication
Compound Policies: Using Logical OR in a Policy
Making a Compound Policy
Example: A Policy for Work or Home Computers
Considerations in Creating Policies
End User Role
Administrator Role
Understudy Role
Office Role
Home Role
Using a Policy to Authorize a Command
Starting the Policy
Satisfying a Policy
Simple Assertions and Multifactor Assertions
If the Policy Is Compound
If the Policy Is Flexible (Uses a Wild Card)
Satisfying the Approved Policy
Transforming the Approved Policy in the Flexible Policy
Certified Policies
Summary
Chapter 15: Key Management
Key Generation
Templates
Key Trees: Keeping Keys in a Tree with the Same Algorithm Set
Duplication
Key Distribution
Key Activation
Key Destruction
Putting It All Together
Example 1: Simple Key Management
Example 2: An Enterprise IT Organization with Windows TPM 2.0 Enabled Systems
Summary
Chapter 16: Auditing TPM Commands
Why Audit
Audit Commands
Audit Types
Command Audit
Session Audit
Audit Log
Audit Data
Exclusive Audit
Summary
Chapter 17: Decrypt/Encrypt Sessions
What Do Encrypt/Decrypt Sessions Do?
Practical Use Cases
Decrypt/Encrypt Limitations
Decrypt/Encrypt Setup
Pseudocode Flow
Sample Code
Summary
Chapter 18: Context Management
TAB and the Resource Manager: A High-Level Description
TAB
Resource Manager
Resource Manager Operations
Management of Objects, Sessions, and Sequences
TPM Context-Management Features
TPM Internal Slots
Special Error Codes
TPM Context-Management Commands
Special Rules Related to Power and Shutdown Events
State Diagrams
Summary
Chapter 19: Startup, Shutdown, and Provisioning
Startup and Shutdown
Startup Initialization
Provisioning
TPM Manufacturer Provisioning
Platform OEM Provisioning
End User Provisioning
Deprovisioning
Summary
Chapter 20: Debugging
Low-Level Application Debugging
The Problem
Analyze the Error Code
Debug Trace Analysis
More Complex Errors
Last Resort
Common Bugs
Debugging High-level Applications
Debug Process
Typical Bugs
Authorization
Disabled Function
Missing Objects
Wrong Type
Bad Size
Policy
Summary
Chapter 21: Solving Bigger Problems with the TPM 2.0
Remote Provisioning of PCs with IDevIDs Using the EK
Technique 1
Technique 2
Technique 3
Data Backups
Separation of Privilege
Securing a Server’s Logon
Locking Firmware in an Embedded System, but Allowing for Upgrades
Summary
Chapter 22: Platform Security Technologies That Use TPM 2.0
The Three Technologies
Some Terms
Intel® Trusted Execution Technology (Intel® TXT)
High-Level Description
Intel TXT Platform Components
Intel TXT Boot Sequence
How TPM 2.0 Devices Are Used
NV Indices
PCRs
Conclusion: Intel TXT
ARM® TrustZone®
High-Level Description
TrustZone Is an Architectural Feature
Protection Target
System-Wide Security
Implementation of TrustZone
The NS bit
The Monitor
World Switching
Interrupts
Relationship to TPMs
AMD Secure Technology™
Hardware Validated Boot
TPM on an AMD Platform
SKINIT
Summary
Index
For your convenience Apress has placed some of the front matter material after the index. Please use the Bookmarks and Contents at a Glance links to access them.
Contents at a Glance About the Authors ��������������������������������������������������������������������������� xxi About the Technical Reviewers ���������������������������������������������������� xxiii Acknowledgments ��������������������������������������������������������������������������xxv Introduction ����������������������������������������������������������������������������������xxvii ■ Chapter 1: History of the TPM �������������������������������������������������������� 1 ■ Chapter 2: Basic Security Concepts ����������������������������������������������� 7 ■ Chapter 3: Quick Tutorial on TPM 2�0 ������������������������������������������� 23 ■ Chapter 4: Existing Applications That Use TPMs �������������������������� 39 ■ Chapter 5: Navigating the Specification ��������������������������������������� 51 ■ Chapter 6: Execution Environment ����������������������������������������������� 71 ■ Chapter 7: TPM Software Stack ���������������������������������������������������� 77 ■ Chapter 8: TPM Entities ���������������������������������������������������������������� 97 ■ Chapter 9: Hierarchies ���������������������������������������������������������������� 105 ■ Chapter 10: Keys ������������������������������������������������������������������������ 119 ■ Chapter 11: NV Indexes �������������������������������������������������������������� 137 ■ Chapter 12: Platform Configuration Registers ���������������������������� 151 ■ Chapter 13: Authorizations and Sessions ����������������������������������� 163 ■ Chapter 14: Extended Authorization (EA) Policies ���������������������� 217 ■ Chapter 15: Key Management ���������������������������������������������������� 249 v
■ Contents at a GlanCe ■ Chapter 16: Auditing TPM Commands ���������������������������������������� 263 ■ Chapter 17: Decrypt/Encrypt Sessions ��������������������������������������� 271 ■ Chapter 18: Context Management ���������������������������������������������� 289 ■ Chapter 19: Startup, Shutdown, and Provisioning ���������������������� 301 ■ Chapter 20: Debugging ��������������������������������������������������������������� 311 ■ Chapter 21: Solving Bigger Problems with the TPM 2�0 ������������ 323 ■ Chapter 22: Platform Security Technologies That Use TPM 2�0 ������������������������������������������������������������������������ 331 Index ���������������������������������������������������������������������������������������������� 349 vi
Introduction “Seminal!” “Riveting! I couldn’t put it down until the last page.” “I’m exhausted from reading this book! It kept me up three nights in a row. Where’s my Ambien when I need it?” “The suspense was killing me. I just had to read it straight through!” Although these responses to our book would be gratifying, it’s doubtful that any book on digital security will ever garner this type of reaction. Digital security is the computer equivalent of disaster insurance. Few people care very much about it or give it much thought, and everyone hates paying for it … until a catastrophe hits. Then we are either really glad we had it or really sad that we didn’t have enough of it or didn’t have it at all. We may sound like Chicken Little crying the “the sky is falling, the sky is falling,” but mark our words: a digital security catastrophe is headed your way. We could quote a plethora of statistics about the rising occurrence of digital security threats, but you’ve probably heard them, and, quite frankly, you don’t care, or at least you don’t care enough. It’s questionable whether any preaching on our part will make you care enough until you’re personally impacted by such a calamity, but we’ll try anyway. When your reputation is tarnished, your finances are impacted, your identity is stolen, your physical well-being is threatened, your company’s reputation and finances are harmed, and, quite possibly, your country is overthrown, then you’ll wake up to the need for cyber security. But it might be too late then. Like people living in a flood zone, the question isn’t whether the flood is coming, but rather when the disaster will hit and whether you’ll be prepared for it. The time to buy digital-security flood insurance is now! Don’t wait until the flood hits. A Practical Guide to TPM 2.0 can be part of your digital-security insurance policy. The TPM was designed as one of the core building blocks for digital security solutions. The November 2013 “Report to the President: Immediate Opportunities for Strengthening the Nation’s Cybersecurity” recommends “the universal adoption of the Trusted Platform Module (TPM), an industry-standard microchip designed to provide basic security- related functions, primarily involving encryption keys, including for phones and tablets.” Computers and devices that incorporate a TPM are able to create cryptographic keys and encrypt them so they can be decrypted only by the TPM. A TPM provides this limited but fundamental set of capabilities that higher layers of cybersecurity can then leverage. Today, TPMs are present in many laptop and desktop personal computers. They’re used by enterprises for tasks like secure disk encryption, but they have yet to be incorporated to any significant extent in smartphones, game consoles, televisions, in-car computer systems, and other computerized devices and industrial control systems. This needs to happen for such devices to be trustworthy constituents of the increasingly interconnected device ecosystem. xxvii
■ IntroduCtIon Our passion in writing this book is to empower and excite a rising generation of IT managers, security architects, systems programmers, application developers, and average users to use the TPM as the bedrock of increasingly sophisticated security solutions that will stem the rising tide of threats that are being aimed at us, our employers, and our civil institutions. Furthermore, the TPM is just plain cool. How many engineers, as children, played with simple cryptography for fun? The ability to send an encrypted message to a friend appeals to the secretive part of our human nature—the same part that enjoyed playing spy games when we were young. And besides being fun, there’s something inherently, morally right about protecting people’s assets from being stolen. The TPM 2.0 technology can accomplish this. We believe in this technology and hope to make believers of you, our readers, as well. Our hope is that you’ll get as excited about this technology as we are and “go out and do wonderful things” with it, to paraphrase Robert Noyce, one of Intel’s founders. Why a Book? Technical specifications are typically poor user manuals, and TPM 2.0 is no exception. One reader of the specification claimed it was “security through incomprehensibility.” Although the specification attempts to describe the functionality as clearly as possible, its prime objective is to describe how a TPM should work, not how it should be used. It’s written for implementers of TPMs, not for application writers using TPMs. Also, for better or for worse, the detailed operations of the TPM commands are specified in C source code. The structures are defined with various keywords and decorations that permit the Word document to be parsed into a C header file. Microsoft agreed with TCG that the source code in the specification would have an open source license and could be used to implement a TPM. However, although C can describe actions very precisely, even the best code isn’t as readable as text. One of the major purposes of this book is to interpret the specification into language that is more understandable to average software developers, especially those who need to understand the low-level details of the specification. Many readers don’t need to understand the detailed operation of the TPM and just want to know how to use the various functions. These readers expect TSS (the TCG software stack) middleware to handle the low-level details. They’re interested in how to use the new TPM features to accomplish innovative security functions. Thus, this book is just as concerned with describing how the TPM can be used as it is with explaining how it works. Throughout the book, as features are described, use cases for those features are interwoven. The use cases aren’t complete—they describe what the TPM 2.0 specification writers were thinking about when those features were designed, but the specification is so rich that it should be possible to implement many things beyond these use cases. Audience In writing this book, we’re trying to reach a broad audience of readers: low-level embedded system developers, driver developers, application developers, security architects, engineering managers, and even non-technical users of security applications. We hope to encourage the broadest possible adoption and use of TPMs. xxviii
■ IntroduCtIon Non-technical readers will want to focus on the introductory material, including the history of the TPM (Chapter 1), basic security concepts (Chapter 2), and existing applications that use TPMs (Chapter 4). Visionaries who know what they want to accomplish but aren’t themselves programmers will also benefit from reading these chapters, because knowing the basic ways in which TPMs can be used may provide inspiration for new use cases. Engineering managers, depending on their needs and technical expertise, can go as deep as they need to or want to. We hope that executives will read the book, see the possibilities provided by TPMs, and subsequently fund TPM-related projects. When they realize, for example, that it’s possible for an IT organization to cryptographically identify all of its machines before allowing them onto a network, that true random number generators are available to help seed OSs’ “get random number” functions, and that weaker passwords can be made stronger using the anti-dictionary-attack protections inherent in the TPM design, they may decide (and we hope they will) to make these features easily available to everyday people. Security architects definitely need to understand the functions provided by TPM 2.0 and, depending on the applications being developed, dive deep into how the TPM works in order to understand the security guarantees provided. Linking disparate machines or different functions to provide trusted software and networks should be possible using TPM functionality as security architects get creative. Commercial availability of this capability is long overdue. Application developers, both architects and implementers, are a significant focus of this book. These readers need to understand the TPM from a high-level viewpoint and will be especially interested in the use cases. TPM 2.0 is feature rich, and the use cases we describe will hopefully inspire creativity in developing and inventing security applications. Developers have to know the basics of symmetric and asymmetric keys and hashes in developing their applications—not the bit-by-bit computations, which are done in the TPM or support software—but rather the types of guarantees that can be obtained by using the TPM correctly. We also want the book to be useful to embedded system developers, middle ware developers, and programmers integrating TCG technology into operating systems and boot code. The TPM now exposes more general-purpose cryptographic functions, which are useful when a crypto library isn’t available due to either resource constraints or licensing issues. We hope that low-level developers will find that this book goes as deep as they need it to and that it serves as a critical tool in interpreting the specification. Toward this end, diagrams and working code examples are used to help clarify many concepts. We expect that embedded systems will increasingly use TPMs as the cost of the technology is reduced (making cryptographic computations cheap to integrate into embedded software) and as attacks on embedded software become more active. Roadmap If you’re new to security or need a refresher, Chapter 2 gives an overview of the security concepts required to understand the book. This chapter provides high-level knowledge of cryptography: we explain symmetric and asymmetric keys, secure hash algorithms, and how a message authentication code (MAC) can be used as a symmetric key digital xxix
■ IntroduCtIon signature. This chapter doesn’t delve into the underlying math used to implement cryptographic algorithms; this isn’t intended as a general-purpose security or cryptography textbook, because there is no need for most TPM 2.0 developers to possess that depth of knowledge. Chapter 3 presents a high-level tutorial on TPM 2.0 and the design rationale behind it. It begins with applications and use cases enabled by TPM 1.2, all of which are also available in TPM 2.0, and then continues by describing the new capabilities that are available with the TPM 2.0 specification. This chapter should help you understand why people are excited about the technology and want to use it in their applications and environments. Chapter 4 describes existing applications that use TPMs (currently, mostly 1.2). We assume that many of these applications will be ported to TPM 2.0. Some are open source, some are demonstration code written by academics to demonstrate what the TPM can do, some are applications that have been around a long time and that can be linked to use TPM features, and some are generally available applications written specifically to take advantage of the TPM’s capabilities. Chapter 5 provides a high-level orientation to the TPM 2.0 specification, offers pointers to critical parts of the specification, and explores some best practices for using the specification. Chapter 6 describes the setup and use of the execution environments available for running TPM 2.0 code examples. Chapter 7 discusses the trusted software stack (TSS). This is presented early in the book because succeeding code examples use various layers of the TSS. Chapter 8 begins the deep dive into TPM 2.0 functionality with a description of TPM 2.0 entities: keys, data blobs, and NV indices. Chapter 9 discusses hierarchies. Chapter 10 covers keys. Chapter 11 discusses NV indexes. Chapter 12 explores PCRs and attestation. Chapter 13 is one of the most in-depth chapters and is crucial if you’re developing low-level code or architecting systems that make extensive use of sessions and authorizations. Chapter 14 discusses enhanced authorization. Chapter 15 explains key management. Chapter 16 describes the TPM’s auditing capabilities. Chapter 17 examines decryption and encryption sessions and how to set them up. Chapter 18 describes object, sequence, and session context management and the basic functionality of a resource manager. Chapter 19 discusses TPM startup, initialization, and provisioning. In typical usage, these occur before keys and sessions are used, but knowledge of TPM entities and sessions is a prerequisite to understanding TPM initialization and provisioning. This is why we include this chapter after the previous three chapters. Chapter 20 presents best practices for debugging TPM 2.0 applications. Chapter 21 examines high-level applications that could use TPM 2.0 functionality. Chapter 22 discusses platform-level security technologies that incorporate TPM 2.0 devices into their security solutions. xxx
分享到:
收藏