Skip to content

Commit 6167f16

Browse files
authored
Merge pull request #53 from hvalkerie19/patch-5
Create 12-cryptography.livemd
2 parents 7fee07d + 4670dff commit 6167f16

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed

modules/12-cryptography.livemd

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# ESCT: Part 12 - Cryptography
2+
3+
## Introduction
4+
5+
Cryptography is the process of transforming information or data from it's original form into one that is unreadable by systems, tools, or people unless they have a key. The part of the process that converts source data/information into the unreadable version is called encryption. Reversing that process is called decryption.
6+
7+
Like many concepts/technologies in security, cryptography is not new. Centuries of devisings ways to send messages between and among
8+
known and trusted senders/receivers while making those messages unreadable for enemies or anyone else for whom the message is not intended.
9+
Secret codes, etc.
10+
11+
Cryptography, like speaking or writing in code, is used whenever there something that needs to be kept secret in an environment where there are multiple other parties who could see or hear the secret but are not the intended recipient. The sender and receiver agree upon a code to exchange messages. Additionally, written notes can be stored and unless a reader has the code, won't know what the actual message is.
12+
13+
Cryptography is used throughout applications to protect sensitive information that while is needed for the operation of the application and it's components, is not intended to be openly shared. This module highlights how cryptography is applied
14+
15+
## Table of Contents
16+
17+
* [Types and Algorithms](#types-and-algorithms)
18+
* [Implementation in Modern Applications](#implementation-in-modern-applications)
19+
* [Related Concepts](#related-concepts)
20+
* [Security Concerns](#security-concerns)
21+
22+
## Types and Algorithms
23+
24+
### Description
25+
26+
There are two categories of cryptography, symmetric and asymmetric and within these categories, there are a variety of algorithms that are distinguished by:
27+
-how data gets chopped up to be encrypted
28+
-how many keys are involved in the encryption/decryption process
29+
-how the keys get generated/used (symmetric/asymmetric)
30+
-key size
31+
-number of cycles
32+
33+
In symmetric encryption, which is also called secret key encryption, a single key used for both encryption and decryption. Symmetric cryptography is bested used when performance and efficiency are important to the application component using/accessing the data to be secured.
34+
35+
In asymmetric encryption, which is also called public-key cryptography, two related but separate keys are generated and then one is used for encrypting while the other for decrpyting. The keys include one that is meant to be shared (pubic key) and one that must always be kept secret(private) but in this public key infrastructure (PKI) system, both keys work to secure client-server interactions, secure VPN connectsion, certificates, digital signatures, and help ensure the technology and data in the system is only accessible by authenticated, and authorized entities with keys.
36+
37+
When selecting an algorithm, best practice is to never build your own, and to always use established and proven algorithms, vetted and recommended by industry experts like NIST.
38+
39+
[symmetric cryptography](https://developer.mozilla.org/en-US/docs/Glossary/Symmetric-key_cryptography)
40+
[NIST](https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-77r1.pdf)
41+
### <span style="color:blue;">Example</span> / <span style="color:red;">Quiz</span>
42+
43+
44+
## Implementation in Modern Applications
45+
46+
### Description
47+
Modern applications have many components that store, process, transmit a variety of information and data. Often that information/data consists of "secrets" or is otherwise sensitive. This includes things like personal information on customers, user credentials, of anything else application developers would like to keep secret.
48+
49+
API keys, database credentials, tokens, admin passwords and other credentials to access privileged components and features, senstivitve data (PII, healthcare), private keys, signing certificates, are all examples of information that should not be available for every users and indeed, kept internal to the organization.
50+
51+
To secure this data, look to implement cryptography both at rest and in transit.
52+
53+
In-transit, ensure all requests/responses are sent using the secure version of the HTTP protocol, HTTPS. HTTP over TLS. Additionally, For remote access into development environments, SSH, VPN - for access to sensitive development environment internal to an organization/remote accessover a network.
54+
55+
56+
### <span style="color:blue;">Example (Draft)</span>
57+
```
58+
For elixir, ExCrypto module[ExCrypto](https://hexdocs.pm/ex_crypto/ExCrypto.html)
59+
60+
Consider what needs to be encrypted - sensitive data or any other data that
61+
Data classification, regulatory implications that must be protected from unauthorized access/seeing
62+
63+
Confidentiality
64+
65+
For in-transit
66+
use HTTPS which implements encrpytion over a channel. Diffie-Hellman
67+
[Serving over HTTPS
68+
](https://hexdocs.pm/plug/https.html)
69+
70+
[Erlang crypto module](https://elixir-lang.org/getting-started/erlang-libraries.html#the-crypto-module)
71+
72+
```
73+
74+
## Related Concepts
75+
76+
### Description
77+
78+
Hashing is sometimes implemented alongside encryption but has a different purpose. Cryptography used for confidentiality; keeping information secret except for intended recipient/audience.
79+
80+
Hashes are used to ensure the integrity of the data, meaning ensuring from it's creation/generation to it's final state, it remains unmodified and untampered with. Hash algorithms are one way functions that - compare starting hash from known good data, to end hash which will indicate changes. Hashing passwords is a common application. Comparing hashes to determine if correct password entered.
81+
Hash Algorithms - SHA1, SHA2, MD5 (obsolete) - follow recommendations from NIST [Approved Hash Algorithms](https://csrc.nist.gov/Projects/Hash-Functions)
82+
83+
## Security Concerns
84+
85+
Cryptographic Failures are the number two most common issue on the OWASP Top 10 A02:2021 – Cryptographic Failures
86+
87+
Related weaknesses include CWE-327: Broken or Risky Crypto Algorithm, and CWE-331 Insufficient Entropy.
88+
89+
Most of the concerns around cytography amount to data being inadvertently being sent in cleartext, sensitive data, the use of old, weak or custom cryptographic algorithms or protocols that are ineffective against attacker efforts to uncover keys, . Best practics is to never build your own crypto mechanisms. Use proven and secure methods like the following:
90+
-Secure Hashes: SHA-1 has been deprecated as of 2011 with a transition plan released in 2022. Recommenation to move towards orther families SHA256
91+
-Secure Encryption Algorithms; AES is the current standard; secure modes must be emplemented
92+
93+
Follow NIST Recommendations for configuring the most secure algorithms when building your applications and securing secrets and data.
94+
95+
Beware of hardcoding keys, private keys, in source code where they can be discovered by malicious actors. Avoid building your own crytographic mechanisms or using outdated protocols.
96+
97+
[Recommended algorithms
98+
](https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-77r1.pdf)[
99+
NIST](https://www.nist.gov/cryptography)
100+
[Encryption Standard](https://csrc.nist.gov/Projects/block-cipher-techniques)
101+
https://csrc.nist.gov/Projects/Hash-Functions
102+
[Elixir encryption, hashing, etc. Modules](https://elixir-lang.org/getting-started/erlang-libraries.html#the-crypto-module)
103+
[OWASP Top10](https://owasp.org/Top10/A02_2021-Cryptographic_Failures/)
104+
[Use TLS](https://cheatsheetseries.owasp.org/cheatsheets/Transport_Layer_Protection_Cheat_Sheet.html)
105+
### <span style="color:blue;">Example</span> / <span style="color:red;">Quiz</span>
106+
107+
**(True or False) You should build your own encryption from scratch.**
108+
*Uncomment the line with your answer
109+
110+
```
111+
# answer = True
112+
# answer = False
113+
114+
IO.puts(answer)
115+
```
116+
117+
[**<- Previous Module: Secure SDLC Concepts**](./3-ssdlc.livemd) || [**Next Module: Elixir Security ->**](./5-elixir.livemd)

0 commit comments

Comments
 (0)