Demystifying Cryptography with OpenSSL 3.0

Book description

Use OpenSSL to add security features to your application, including cryptographically strong symmetric and asymmetric encryption, digital signatures, SSL/TLS connectivity, and PKI handling

Key Features

    Book Description

    Security and networking are essential features of software today. The modern internet is full of worms, Trojan horses, men-in-the-middle, and other threats. This is why maintaining security is more important than ever.

    OpenSSL is one of the most widely used and essential open source projects on the internet for this purpose. If you are a software developer, system administrator, network security engineer, or DevOps specialist, you’ve probably stumbled upon this toolset in the past – but how do you make the most out of it? With the help of this book, you will learn the most important features of OpenSSL, and gain insight into its full potential.

    This book contains step-by-step explanations of essential cryptography and network security concepts, as well as practical examples illustrating the usage of those concepts. You’ll start by learning the basics, such as how to perform symmetric encryption and calculate message digests. Next, you will discover more about cryptography: MAC and HMAC, public and private keys, and digital signatures. As you progress, you will explore best practices for using X.509 certificates, public key infrastructure, and TLS connections.

    By the end of this book, you’ll be able to use the most popular features of OpenSSL, allowing you to implement cryptography and TLS in your applications and network infrastructure.

    What you will learn

    • Understand how to use symmetric cryptography
    • Get to grips with message digests, MAC, and HMAC
    • Discover asymmetric cryptography and digital signatures
    • Focus on how to apply and use X.509 certificates
    • Dive into TLS and its proper usage
    • Manage advanced and special usages of TLS
    • Find out how to run a mini certificate authority for your organization

    Who this book is for

    This book is for software developers, system administrators, DevOps specialists, network security engineers, and analysts, or anyone who wants to keep their applications and infrastructure secure. Software developers will learn how to use the OpenSSL library to empower their software with cryptography and TLS. DevOps professionals and sysadmins will learn how to work with cryptographic keys and certificates on the command line, and how to set up a mini-CA for their organization. A basic understanding of security and networking is required.

Table of contents

  1. Demystifying Cryptography with OpenSSL 3.0
  2. Foreword
  3. Contributors
  4. About the author
  5. About the reviewer
  6. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Download the color images
    6. Conventions used
    7. Get in touch
    8. Share Your Thoughts
  7. Part 1: Introduction
  8. Chapter 1: OpenSSL and Other SSL/TLS Libraries
    1. What is OpenSSL?
    2. The history of OpenSSL
    3. What’s new in OpenSSL 3.0?
    4. Comparing OpenSSL with GnuTLS
    5. Comparing OpenSSL with NSS
    6. Comparing OpenSSL with Botan
    7. Comparing OpenSSL with lightweight TLS libraries
    8. Comparing OpenSSL with LibreSSL
    9. Comparing OpenSSL with BoringSSL
    10. Summary
  9. Part 2: Symmetric Cryptography
  10. Chapter 2: Symmetric Encryption and Decryption
    1. Technical requirements
    2. Understanding symmetric encryption
    3. An overview of the symmetric ciphers supported by OpenSSL
      1. Comparing block ciphers and stream ciphers
      2. Understanding symmetric cipher security
      3. How many bits of security is enough?
      4. Reviewing the AES cipher
      5. Reviewing DES and 3DES ciphers
      6. Reviewing the RC4 cipher
      7. Reviewing the ChaCha20 cipher
      8. Reviewing other symmetric ciphers supported by OpenSSL
    4. Block cipher modes of operation
      1. Reviewing the Electronic Code Book mode
      2. Reviewing CBC mode
      3. Reviewing CTR mode
      4. Reviewing GCM
      5. Reviewing AES-GCM-SIV
      6. Other block cipher operation modes
      7. Choosing the block cipher operation mode
    5. Padding for block ciphers
    6. How to generate a symmetric encryption key
    7. Downloading and installing OpenSSL
    8. How to encrypt and decrypt with AES on the command line
    9. Initializing and uninitializing OpenSSL library
    10. How to compile and link with OpenSSL
    11. How to encrypt with AES programmatically
      1. Implementing the encryption program
      2. Running the encrypt program
    12. How to decrypt with AES programmatically
      1. Implementing the decrypt program
      2. Running the decrypt program
    13. Summary
  11. Chapter 3: Message Digests
    1. Technical requirements
    2. What are message digests and cryptographic hash functions?
    3. Why are message digests needed?
      1. Data integrity verification
      2. Basis for HMAC
      3. Digital signatures
      4. Network protocols
      5. Password verification
      6. Content identifier
      7. Blockchain and cryptocurrencies
      8. Proof-of-work
    4. Assessing the security of cryptographic hash functions
    5. Overview of the cryptographic hash functions supported by OpenSSL
      1. Reviewing the SHA-2 family of hash functions
      2. Reviewing the SHA-3 family of hash functions
      3. Reviewing the SHA-1 and SHA-0 hash functions
      4. Reviewing the MD family of hash functions
      5. Reviewing the BLAKE2 family of hash functions
      6. Reviewing less popular hash functions supported by OpenSSL
      7. Which cryptographic hash function should you choose?
    6. How to calculate a message digest on the command line
    7. How to calculate the message digest programmatically
      1. Implementing the digest program
      2. Running the digest program
    8. Summary
  12. Chapter 4: MAC and HMAC
    1. Technical requirements
    2. What is a MAC?
    3. Understanding MAC function security
    4. HMAC – a hash-based MAC
    5. MAC, encryption, and the Cryptographic Doom Principle
    6. How to calculate HMAC on the command line
    7. How to calculate HMAC programmatically
      1. Implementing the hmac program
      2. Running the hmac program
    8. Summary
  13. Chapter 5: Derivation of an Encryption Key from a Password
    1. Technical requirements
    2. Understanding the differences between a password and an encryption key
    3. What is a key derivation function?
    4. Overview of key derivation functions supported by OpenSSL
    5. Deriving a key from a password on the command line
    6. Deriving a key from a password programmatically
      1. Implementing the kdf program
      2. Running the kdf program
    7. Summary
  14. Part 3: Asymmetric Cryptography and Certificates
  15. Chapter 6: Asymmetric Encryption and Decryption
    1. Technical requirements
    2. Understanding asymmetric encryption
    3. Understanding a Man in the Middle attack
      1. Meeting in person
      2. Verifying a key fingerprint over the phone
      3. Key splitting
      4. Signing the key by a trusted third party
    4. What kind of asymmetric encryption is available in OpenSSL?
    5. Understanding a session key
    6. Understanding RSA security
    7. How to generate an RSA keypair
    8. How to encrypt and decrypt with RSA on the command line
    9. How to encrypt with RSA programmatically
      1. Implementing the rsa-encrypt program
      2. Running the rsa-encrypt program
    10. Understanding the OpenSSL error queue
    11. How to decrypt with RSA programmatically
      1. Implementing the rsa-decrypt program
      2. Running the rsa-decrypt program
    12. Summary
  16. Chapter 7: Digital Signatures and Their Verification
    1. Technical requirements
    2. Understanding digital signatures
      1. Difference between digital signatures and MACs
    3. Overview of digital signature algorithms supported by OpenSSL
      1. Reviewing RSA
      2. Reviewing DSA
      3. Reviewing ECDSA
      4. Reviewing EdDSA
      5. Reviewing SM2
      6. Which digital signature algorithm should you choose?
    4. How to generate an elliptic curve keypair
    5. How to sign and verify a signature on the command line
    6. How to sign programmatically
      1. Implementing the ec-sign program
      2. Running the ec-sign program
    7. How to verify a signature programmatically
      1. Implementing the ec-verify program
      2. Running the ec-verify program
    8. Summary
  17. Chapter 8: X.509 Certificates and PKI
    1. Technical requirements
    2. What is an X.509 certificate?
    3. Understanding certificate signing chains
    4. How are X.509 certificates issued?
    5. What are X509v3 extensions?
    6. Understanding X.509 Public Key Infrastructure
    7. How to generate a self-signed certificate
    8. How to generate a non-self-signed certificate
    9. How to verify a certificate on the command line
    10. How to verify a certificate programmatically
      1. Implementing the x509-verify program
      2. Running the x509-verify program
    11. Summary
  18. Part 4: TLS Connections and Secure Communication
  19. Chapter 9: Establishing TLS Connections and Sending Data over Them
    1. Technical requirements
    2. Understanding the TLS protocol
      1. Understanding a TLS handshake
      2. What happens after the TLS handshake?
    3. The history of the TLS protocol
    4. Establishing a TLS client connection on the command line
    5. Preparing certificates for a TLS server connection
    6. Accepting a TLS server connection on the command line
    7. Understanding OpenSSL BIOs
    8. Establishing a TLS client connection programmatically
      1. Implementing the tls-client program
      2. Running the tls-client program
    9. Accepting a TLS server connection programmatically
      1. Implementing the tls-server program
      2. Running the tls-server program
    10. Summary
  20. Chapter 10: Using X.509 Certificates in TLS
    1. Technical requirements
    2. Custom verification of peer certificates in C programs
      1. Registering the verification callback
      2. Implementing the verification callback
      3. Running the program
    3. Using Certificate Revocation Lists in C programs
      1. Registering the CRL lookup callback
      2. Implementing the CRL lookup callback
      3. Implementing the function for downloading a CRL from a distribution point
      4. Implementing the function for downloading a CRL from an HTTP URL
      5. Running the program
    4. Using the Online Certificate Status Protocol
      1. Understanding the Online Certificate Status Protocol
      2. Using OCSP on the command line
      3. Using OCSP in C programs
    5. Using TLS client certificates
      1. Generating TLS client certificates
      2. Packaging client certificates into PKCS #12 container files
      3. Requesting and verifying a TLS client certificate on the server side programmatically
      4. Establishing a TLS client connection with a client certificate programmatically
    6. Summary
  21. Chapter 11: Special Usages of TLS
    1. Technical requirements
    2. Understanding TLS certificate pinning
    3. Using TLS certificate pinning
      1. Changing the run_tls_client() function
      2. Implementing the cert_verify_callback() function
      3. Running the tls-cert-pinning program
    4. Understanding blocking and non-blocking sockets
    5. Using TLS on non-blocking sockets
      1. Changing the run_tls_client() function
      2. Running the tls-client-non-blocking program
    6. Understanding TLS on non-standard sockets
    7. Using TLS on non-standard sockets
      1. Implementing the service_bios() function
      2. Reimplementing the run_tls_client() function
      3. Running the tls-client-memory-bio program
    8. Summary
  22. Part 5: Running a Mini-CA
  23. Chapter 12: Running a Mini-CA
    1. Technical requirements
    2. Understanding the openssl ca subcommand
    3. Generating a root CA certificate
    4. Generating an intermediate CA certificate
    5. Generating a certificate for a web server
    6. Generating a certificate for a web and email client
    7. Revoking certificates and generating CRLs
    8. Providing certificate revocation status via OCSP
    9. Summary
  24. Index
    1. Why subscribe?
  25. Other Books You May Enjoy
    1. Packt is searching for authors like you

Product information

  • Title: Demystifying Cryptography with OpenSSL 3.0
  • Author(s): Alexei Khlebnikov
  • Release date: October 2022
  • Publisher(s): Packt Publishing
  • ISBN: 9781800560345