| 1 | package crypto |
| 2 | |
| 3 | import ( |
| 4 | "github.com/smallstep/cli/command" |
| 5 | "github.com/smallstep/cli/command/crypto/hash" |
| 6 | "github.com/smallstep/cli/command/crypto/jose" |
| 7 | "github.com/smallstep/cli/command/crypto/jwe" |
| 8 | "github.com/smallstep/cli/command/crypto/jwk" |
| 9 | "github.com/smallstep/cli/command/crypto/jws" |
| 10 | "github.com/smallstep/cli/command/crypto/jwt" |
| 11 | "github.com/smallstep/cli/command/crypto/kdf" |
| 12 | "github.com/smallstep/cli/command/crypto/key" |
| 13 | "github.com/smallstep/cli/command/crypto/nacl" |
| 14 | "github.com/smallstep/cli/command/crypto/otp" |
| 15 | "github.com/smallstep/cli/command/crypto/winpe" |
| 16 | "github.com/urfave/cli" |
| 17 | ) |
| 18 | |
| 19 | func init() { |
| 20 | cmd := cli.Command{ |
| 21 | Name: "crypto", |
| 22 | Usage: "useful cryptographic plumbing", |
| 23 | Description: `The **step crypto** command group provides a selection of useful cryptographic |
| 24 | primitives that balances completeness and safety (cryptographic strength, ease |
| 25 | of use, and misuse prevention). Subcommands include flags and arguments to |
| 26 | select algorithms and fine-tune behaviors, but we've selected safe defaults for |
| 27 | you wherever possible. |
| 28 | |
| 29 | Insecure or subtle cryptographic primitives and options are gated with flags to |
| 30 | prevent accidental misuse. Such primitives and options will not work unless you |
| 31 | pass the corresponding flags to indicate that you understand the risks |
| 32 | (**--insecure** and **--subtle**, respectively). Our rationale for these |
| 33 | decisions is usually documented in the **SECURITY CONSIDERATIONS** section of |
| 34 | the help for each subcommand. |
| 35 | |
| 36 | ## SECURITY CONSIDERATIONS |
| 37 | |
| 38 | The strength of cryptographic mechanisms depends on the strength of all links |
| 39 | in the security chain. This includes the quality and strength of algorithms, |
| 40 | random number generation, distribution mechanisms, etc. It also includes |
| 41 | protection against hostile observation and tampering as well as the security of |
| 42 | the overall system including the operating system and personnel, etc. Where |
| 43 | possible, we've selected secure defaults. Whenever a subtle or insecure |
| 44 | cryptographic operation is attempted affirmative confirmation via prompt or |
| 45 | command line flag is required, indicating that you understand and accept the |
| 46 | risks. That said, many of these factors are beyond the scope of this tool. |
| 47 | |
| 48 | **Key Length** |
| 49 | |
| 50 | : This tool enforces a minimum key size of **256 bits for symmetric keys**, which is |
| 51 | generally considered quantum-safe and accepted as sufficient for the |
| 52 | foreseeable future. |
| 53 | |
| 54 | : This tool enforces the NIST recommended minimum key size of **2048 bits for RSA** |
| 55 | keys, which RSA claims is equivalent in strength to 112 bit symmetric keys and |
| 56 | is likely to be sufficient until 2030. An RSA key length of at least 3072 bits, |
| 57 | which RSA claims is equivalent to 128 bit symmetric keys, should be used if |
| 58 | security is required beyond 2030. |
| 59 | |
| 60 | : Elliptic curve cryptography is generally believed to be secure with shorter |
| 61 | keys than RSA requires. NIST guidelines state that ECC keys should be twice the |
| 62 | length of the equivalent strength symmetric key. The rough equivalencies for |
| 63 | the elliptic curves supported by this tool are: |
| 64 | |
| 65 | : | key type | curve | RSA equivalent | symmetric key equivalent | |
| 66 | |----------|---------|----------------|--------------------------| |
| 67 | | EC | P-256 | ~3000 bits | ~128 bits | |
| 68 | | EC | P-384 | ~4096 bits | ~192 bits | |
| 69 | | EC | P-521 | ~15000 bits | ~256 bits | |
| 70 | | OKP | Ed25519 | ~3000 bits | ~140 bits | |
| 71 | |
| 72 | : Elliptic curve cryptography has the additional advantages of much smaller key |
| 73 | sizes for equivalent security levels, and much faster cryptographic operations |
| 74 | compared to RSA. The strength of these keys is generally considered sufficient |
| 75 | for the predictable and foreseeable future. |
| 76 | |
| 77 | : Note that for cryptographic protocols that have perfect forward secrecry and |
| 78 | only use asymmetric keys for symmetric key negotiation your system will remain |
| 79 | secure against future threats as long as the keys are large enough that they |
| 80 | cannot be cracked today. In other words, sizing your keys to protect against |
| 81 | potential future threats is largely irrelevant. |
| 82 | |
| 83 | **Key Use** |
| 84 | |
| 85 | : In general you should not use an asymmetric keypair for both signing and |
| 86 | encryption. Using a single key for both operations can introduce attack vectors |
| 87 | that would not otherwise exist. Attacks aside, signing keys and encryption |
| 88 | keys generally have different life cycles. Signing keys are generally destroyed |
| 89 | once they're no longer useful for singing new data. Encryption keys, on the |
| 90 | other hand, must be retained as long as data exists that was encrypted for the |
| 91 | key. So using a signing key for encryption may force you to retain a signing |
| 92 | key for longer than it's needed, leaving it susceptible to misuse. |
| 93 | |
| 94 | : Raw public or private keys don't have any associated data, therefore this |
| 95 | tool cannot enforce key use on raw keys and this responsibility is up to |
| 96 | you. For keys in an "envelope" the envelope typically includes key use |
| 97 | restrictions (e.g., the "use" parameter in JWKs and the "Key Usage" |
| 98 | attribute of X.509 certificates). This tool generally requires key use to be |
| 99 | specified when creating an enveloped key, and enforces key use restrictions |
| 100 | when an enveloped key is being used. |
| 101 | |
| 102 | **Safe Curves** |
| 103 | |
| 104 | : There is some concern that certain standard elliptic curves are very hard to |
| 105 | implement correctly. These concerns are not purely theoretical. Implementation |
| 106 | issues have been uncovered and real attacks have been demonstrated. |
| 107 | |
| 108 | : While we take these concerns seriously, these curves are widely used in |
| 109 | practice, largely because they are perceived to be stronger than RSA and have |
| 110 | been implemented in more places than the "safe curves". Therefore, **we've |
| 111 | opted not to gate non-safe curves**. We've further elected to make **P-256** |
| 112 | the default curve for EC keys. |
| 113 | |
| 114 | : Still, it is important to be aware of the security risks assocated with their |
| 115 | risk. You should consider using "safe curves" if possible. We may change our |
| 116 | mind as support for safe curves improves. |
| 117 | |
| 118 | : Safe and non-safe curves implemented by this tool are: |
| 119 | |
| 120 | : | key type | curve | safe | |
| 121 | |----------|---------|------| |
| 122 | | EC | P-256 | NO | |
| 123 | | EC | P-384 | NO | |
| 124 | | EC | P-521 | NO | |
| 125 | | OKP | Ed25519 | YES | |
| 126 | |
| 127 | : For more information see https://safecurves.cr.yp.to/ |
| 128 | |
| 129 | **Quantum Safety** |
| 130 | |
| 131 | : Quantum-safe cryptography refers to keys and algorithms that are secure against |
| 132 | an attack by a quantum computer. As of 2018 most public key algorithms are not |
| 133 | quantum safe. In particular, **none of the public key algorithms implemented by |
| 134 | this tool are quantum safe**. However, no quantum computer exists that is |
| 135 | powerful enough to break current algorithms. Using cryptographic protocols with |
| 136 | forward secrecy is the best way to protect against future quantum attacks. |
| 137 | |
| 138 | **Forward Secrecy** |
| 139 | |
| 140 | : A cryptosystem or protocol has forward secrecy (or perfect forward secrecy) if, |
| 141 | for each session or interaction, a random key is generated such that an |
| 142 | attacker with access to all private keys would still not know the generated |
| 143 | key. This can be accomplished using Diffie-Hellman key exchange, for instance. |
| 144 | |
| 145 | : Forward secrecy can protect against an attacker who stores intercepted |
| 146 | communication and waits for your private key to be compromised, at which point |
| 147 | they could decrypt the stored communication. It also offers good protection |
| 148 | against quantum attacks since symmetric key cryptosystems like AES are already |
| 149 | considered quantum resistant with sufficiently large key sizes. The current |
| 150 | best quantum attack against symmetric key systems requires work proportional to |
| 151 | the square of the size of the key space. In other words, a symmetric key is |
| 152 | half as strong against a quantum attack vs. a conventional attack, so your key |
| 153 | needs to be twice as long for equivalent quantum-safe security. A 256 bit |
| 154 | symmetric key in the context of a quantum attack is equivalent in strength to a |
| 155 | 128 bit key in the context of a conventional attack. |
| 156 | `, |
| 157 | Subcommands: cli.Commands{ |
| 158 | changePassCommand(), |
| 159 | createKeyPairCommand(), |
| 160 | jwk.Command(), |
| 161 | jwt.Command(), |
| 162 | jwe.Command(), |
| 163 | jws.Command(), |
| 164 | jose.Command(), |
| 165 | hash.Command(), |
| 166 | kdf.Command(), |
| 167 | key.Command(), |
| 168 | nacl.Command(), |
| 169 | otp.Command(), |
| 170 | winpe.Command(), |
| 171 | }, |
| 172 | } |
| 173 | |
| 174 | command.Register(cmd) |
| 175 | } |