-
Chapter 1 Safe Initialization
-
Sanitizing the Environment
-
Restricting Privileges on Windows
-
Dropping Privileges in setuid Programs
-
Limiting Risk with Privilege Separation
-
Managing File Descriptors Safely
-
Creating a Child Process Securely
-
Executing External Programs Securely
-
Executing External Programs Securely
-
Disabling Memory Dumps in the Event of a Crash
-
-
Chapter 2 Access Control
-
Understanding the Unix Access Control Model
-
Understanding the Windows Access Control Model
-
Determining Whether a User Has Access to a File on Unix
-
Determining Whether a Directory Is Secure
-
Erasing Files Securely
-
Accessing File Information Securely
-
Restricting Access Permissions for New Files on Unix
-
Locking Files
-
Synchronizing Resource Access Across Processes on Unix
-
Synchronizing Resource Access Across Processes on Windows
-
Creating Files for Temporary Use
-
Restricting Filesystem Access on Unix
-
Restricting Filesystem and Network Access on FreeBSD
-
-
Chapter 3 Input Validation
-
Understanding Basic Data Validation Techniques
-
Preventing Attacks on Formatting Functions
-
Preventing Buffer Overflows
-
Using the SafeStr Library
-
Preventing Integer Coercion and Wrap-Around Problems
-
Using Environment Variables Securely
-
Validating Filenames and Paths
-
Evaluating URL Encodings
-
Validating Email Addresses
-
Preventing Cross-Site Scripting
-
Preventing SQL Injection Attacks
-
Detecting Illegal UTF-8 Characters
-
Preventing File Descriptor Overflows When Using select( )
-
-
Chapter 4 Symmetric Cryptography Fundamentals
-
Representing Keys for Use in Cryptographic Algorithms
-
Generating Random Symmetric Keys
-
Representing Binary Keys (or Other Raw Data) as Hexadecimal
-
Turning ASCII Hex Keys (or Other ASCII Hex Data) into Binary
-
Performing Base64 Encoding
-
Performing Base64 Decoding
-
Representing Keys (or Other Binary Data) as English Text
-
Converting Text Keys to Binary Keys
-
Using Salts, Nonces, and Initialization Vectors
-
Deriving Symmetric Keys from a Password
-
Algorithmically Generating Symmetric Keys from One Base Secret
-
Encrypting in a Single Reduced Character Set
-
Managing Key Material Securely
-
Timing Cryptographic Primitives
-
-
Chapter 5 Symmetric Encryption
-
Deciding Whether to Use Multiple Encryption Algorithms
-
Figuring Out Which Encryption Algorithm Is Best
-
Selecting an Appropriate Key Length
-
Selecting a Cipher Mode
-
Using a Raw Block Cipher
-
Using a Generic CBC Mode Implementation
-
Using a Generic CFB Mode Implementation
-
Using a Generic OFB Mode Implementation
-
Using a Generic CTR Mode Implementation
-
Using CWC Mode
-
Manually Adding and Checking Cipher Padding
-
Precomputing Keystream in OFB, CTR, CCM, or CWC Modes (or with Stream Ciphers)
-
Parallelizing Encryption and Decryption in Modes That Allow It (Without Breaking Compatibility)
-
Parallelizing Encryption and Decryption in Arbitrary Modes (Breaking Compatibility)
-
Performing File or Disk Encryption
-
Using a High-Level, Error-Resistant Encryption and Decryption API
-
Performing Block Cipher Setup (for CBC, CFB, OFB, and ECB Modes) in OpenSSL
-
Using Variable Key-Length Ciphers in OpenSSL
-
Disabling Cipher Padding in OpenSSL in CBC Mode
-
Performing Additional Cipher Setup in OpenSSL
-
Querying Cipher Configuration Properties in OpenSSL
-
Performing Low-Level Encryption and Decryption with OpenSSL
-
Setting Up and Using RC4
-
Using One-Time Pads
-
Using Symmetric Encryption with Microsoft's CryptoAPI
-
Creating a CryptoAPI Key Object from Raw Key Data
-
Extracting Raw Key Data from a CryptoAPI Key Object
-
-
Chapter 6 Hashes and Message Authentication
-
Understanding the Basics of Hashes and MACs
-
Deciding Whether to Support Multiple Message Digests or MACs
-
Choosing a Cryptographic Hash Algorithm
-
Choosing a Message Authentication Code
-
Incrementally Hashing Data
-
Hashing a Single String
-
Using a Cryptographic Hash
-
Using a Nonce to Protect Against Birthday Attacks
-
Checking Message Integrity
-
Using HMAC
-
Using OMAC (a Simple Block Cipher-Based MAC)
-
Using HMAC or OMAC with a Nonce
-
Using a MAC That's Reasonably Fast in Software and Hardware
-
Using a MAC That's Optimized for Software Speed
-
Constructing a Hash Function from a Block Cipher
-
Using a Block Cipher to Build a Full-Strength Hash Function
-
Using Smaller MAC Tags
-
Making Encryption and Message Integrity Work Together
-
Making Your Own MAC
-
Encrypting with a Hash Function
-
Securely Authenticating a MAC (Thwarting Capture Replay Attacks)
-
Parallelizing MACs
-
-
Chapter 7 Public Key Cryptography
-
Determining When to Use Public Key Cryptography
-
Selecting a Public Key Algorithm
-
Selecting Public Key Sizes
-
Manipulating Big Numbers
-
Generating a Prime Number (Testing for Primality)
-
Generating an RSA Key Pair
-
Disentangling the Public and Private Keys in OpenSSL
-
Converting Binary Strings to Integers for Use with RSA
-
Converting Integers into Binary Strings for Use with RSA
-
Performing Raw Encryption with an RSA Public Key
-
Performing Raw Decryption Using an RSA Private Key
-
Signing Data Using an RSA Private Key
-
Verifying Signed Data Using an RSA Public Key
-
Securely Signing and Encrypting with RSA
-
Using the Digital Signature Algorithm (DSA)
-
Representing Public Keys and Certificates in Binary (DER Encoding)
-
Representing Keys and Certificates in Plaintext (PEM Encoding)
-
-
Chapter 8 Authentication and Key Exchange
-
Choosing an Authentication Method
-
Getting User and Group Information on Unix
-
Getting User and Group Information on Windows
-
Restricting Access Based on Hostname or IP Address
-
Generating Random Passwords and Passphrases
-
Testing the Strength of Passwords
-
Prompting for a Password
-
Throttling Failed Authentication Attempts
-
Performing Password-Based Authentication with crypt( )
-
Performing Password-Based Authentication with MD5-MCF
-
Performing Password-Based Authentication with PBKDF2
-
Authenticating with PAM
-
Authenticating with Kerberos
-
Authenticating with HTTP Cookies
-
Performing Password-Based Authentication and Key Exchange
-
Performing Authenticated Key Exchange Using RSA
-
Using Basic Diffie-Hellman Key Agreement
-
Using Diffie-Hellman and DSA Together
-
Minimizing the Window of Vulnerability When Authenticating Without a PKI
-
Providing Forward Secrecy in a Symmetric System
-
Ensuring Forward Secrecy in a Public Key System
-
Confirming Requests via Email
-
-
Chapter 9 Networking
-
Creating an SSL Client
-
Creating an SSL Server
-
Using Session Caching to Make SSL Servers More Efficient
-
Securing Web Communication on Windows Using the WinInet API
-
Enabling SSL without Modifying Source Code
-
Using Kerberos Encryption
-
Performing Interprocess Communication Using Sockets
-
Performing Authentication with Unix Domain Sockets
-
Performing Session ID Management
-
Securing Database Connections
-
Using a Virtual Private Network to Secure Network Connections
-
Building an Authenticated Secure Channel Without SSL
-
-
Chapter 10 Public Key Infrastructure
-
Understanding Public Key Infrastructure (PKI)
-
Obtaining a Certificate
-
Using Root Certificates
-
Understanding X.509 Certificate Verification Methodology
-
Performing X.509 Certificate Verification with OpenSSL
-
Performing X.509 Certificate Verification with CryptoAPI
-
Verifying an SSL Peer's Certificate
-
Adding Hostname Checking to Certificate Verification
-
Using a Whitelist to Verify Certificates
-
Obtaining Certificate Revocation Lists with OpenSSL
-
Obtaining CRLs with CryptoAPI
-
Checking Revocation Status via OCSP with OpenSSL
-
-
Chapter 11 Random Numbers
-
Determining What Kind of Random Numbers to Use
-
Using a Generic API for Randomness and Entropy
-
Using the Standard Unix Randomness Infrastructure
-
Using the Standard Windows Randomness Infrastructure
-
Using an Application-Level Generator
-
Reseeding a Pseudo-Random Number Generator
-
Using an Entropy Gathering Daemon-Compatible Solution
-
Getting Entropy or Pseudo-Randomness Using EGADS
-
Using the OpenSSL Random Number API
-
Getting Random Integers
-
Getting a Random Integer in a Range
-
Getting a Random Floating-Point Value with Uniform Distribution
-
Getting Floating-Point Values with Nonuniform Distributions
-
Getting a Random Printable ASCII String
-
Shuffling Fairly
-
Compressing Data with Entropy into a Fixed-Size Seed
-
Getting Entropy at Startup
-
Statistically Testing Random Numbers
-
Performing Entropy Estimation and Management
-
Gathering Entropy from the Keyboard
-
Gathering Entropy from Mouse Events on Windows
-
Gathering Entropy from Thread Timings
-
Gathering Entropy from System State
-
-
Chapter 12 Anti-Tampering
-
Understanding the Problem of Software Protection
-
Detecting Modification
-
Obfuscating Code
-
Performing Bit and Byte Obfuscation
-
Performing Constant Transforms on Variables
-
Merging Scalar Variables
-
Splitting Variables
-
Disguising Boolean Values
-
Using Function Pointers
-
Restructuring Arrays
-
Hiding Strings
-
Detecting Debuggers
-
Detecting Unix Debuggers
-
Detecting Windows Debuggers
-
Detecting SoftICE
-
Countering Disassembly
-
Using Self-Modifying Code
-
-
Chapter 13 Other Topics
-
Performing Error Handling
-
Erasing Data from Memory Securely
-
Preventing Memory from Being Paged to Disk
-
Using Variable Arguments Properly
-
Performing Proper Signal Handling
-
Protecting against Shatter Attacks on Windows
-
Guarding Against Spawning Too Many Threads
-
Guarding Against Creating Too Many Network Sockets
-
Guarding Against Resource Starvation Attacks on Unix
-
Guarding Against Resource Starvation Attacks on Windows
-
Following Best Practices for Audit Logging
-
-
Colophon
- Title:
- Secure Programming Cookbook for C and C++
- By:
- John Viega, Matt Messier
- Publisher:
- O'Reilly Media
- Formats:
-
- Ebook
- Safari Books Online
- Print Release:
- July 2003
- Ebook Release:
- February 2009
- Pages:
- 792
- Print ISBN:
- 978-0-596-00394-4
- | ISBN 10:
- 0-596-00394-3
- Ebook ISBN:
- 978-0-596-10389-7
- | ISBN 10:
- 0-596-10389-1
Our look is the result of reader comments, our own experimentation, and feedback from distribution channels. Distinctive covers complement our distinctive approach to technical topics, breathing personality and life into potentially dry subjects. The animal on the cover of Secure Programming Cookbook for C and C++ is a crested porcupine. Crested porcupines (Hystrix cristata) are the largest porcupines on earth. Adults can weigh as much as 50 pounds, and their average length is between 25 and 30 inches. They have been known to live over 20 years while in captivity.
The crested porcupine is covered with black bristly fur. But running down the top of its head and neck is a crest of white bristly hairs that give way to an array of black and white spines that cover the animal's back, sides, and short tail. The short spines on the tail are hollow, which makes them rattle when shaken.
Highly adaptable creatures, crested porcupines can live in forests, plantations, rocky or mountainous areas, as well as deserts. They are found in Italy, Sicily, and along the Mediterranean coast of Africa as far south as Tanzania and northern Congo. They they shelter in caves, rock crevices, aardvark holes, or burrows they dig themselves. These burrows are often extensive and can be used for many years.
Crested porcupines live in monogamous pairs and form family groups sharing complex burrows. They are nocturnal and forage at night, moving along tracks or roads. They will often travel up to nine miles per night in search of food. They primarily eat roots, bark, and fallen fruit, but have a fondness, too, for cultivated root crops such as cassava, potatoes, and carrots. Although they are vegetarians, porcupine burrows are often littered with bones. They gnaw on the bones to sharpen their incisor teeth and to obtain calcium.
At birth, crested porcupines weigh only three percent of their mother's weight. When born, the young porcupine's quills are white and soft, although they start to become hard within hours. Their eyes are open and incisors are already crowning shortly after birth. After only one week, their spines begin to harden and, although small, they leave the nest.
When threatened, the crested porcupine raises and fans its quills to create the illusion of greater size. The crested porcupine will then stamp its feet, click its teeth, and growl or hiss while vibrating specialized quills that produce a characteristic rattle. The "rattle quills" on the end of the tail are hollow and open at the end, thus producing the most noise. If an enemy persists, the porcupine runs backward until it rams its attacker. Such attacks have been known to kill lions, leopards, hyenas, and humans-- and these predators have often been found with porcupine quills lodged in their throats. New quills grow in to replace lost ones.
Porcupine quills have long been a favorite ornament and good luck charm in Africa. The hollow rattle quills serve as musical instruments and were once used as containers for gold dust. Darren Kelly was the production editor, and Leanne Soylemez was the copyeditor for Secure Programming Cookbook for C and C++. Derek Di Matteo, Reg Aubry, Claire Cloutier, and Jane Ellin provided quality control. John Bickelhaupt wrote the index. Jamie Peppard, Reg Aubry, Judy Hoer, and Mary Agner provided production support.
Emma Colby designed the cover of this book, based on a series design by Edie Freedman. The cover image is a 19th-century engraving from the Dover Pictorial Archive. Emma Colby produced the cover layout with QuarkXPress 4.1 using Adobe's ITC Garamond font.
David Futato designed the interior layout. This book was converted by Joe Wizda to FrameMaker 5.5.6 with a format conversion tool created by Erik Ray, Jason McIntosh, Neil Walls, and Mike Sierra, which uses Perl and XML technologies. The text font is Linotype Birka; the heading font is Adobe Myriad Condensed; and the code font is LucasFont's TheSans Mono Condensed. The illustrations that appear in the book were produced by Robert Romano and Jessamyn Read using Macromedia Free-Hand 9 and Adobe Photoshop 6. The tip and warning icons were drawn by Christopher Bing. This colophon was written by Darren Kelly.
