|
11 | 11 | */ |
12 | 12 |
|
13 | 13 | private import ConceptsImports |
| 14 | + |
| 15 | +/** |
| 16 | + * Provides models for cryptographic concepts. |
| 17 | + * |
| 18 | + * Note: The `CryptographicAlgorithm` class currently doesn't take weak keys into |
| 19 | + * consideration for the `isWeak` member predicate. So RSA is always considered |
| 20 | + * secure, although using a low number of bits will actually make it insecure. We plan |
| 21 | + * to improve our libraries in the future to more precisely capture this aspect. |
| 22 | + */ |
| 23 | +module Cryptography { |
| 24 | + class CryptographicAlgorithm = CryptoAlgorithms::CryptographicAlgorithm; |
| 25 | + |
| 26 | + class EncryptionAlgorithm = CryptoAlgorithms::EncryptionAlgorithm; |
| 27 | + |
| 28 | + class HashingAlgorithm = CryptoAlgorithms::HashingAlgorithm; |
| 29 | + |
| 30 | + class PasswordHashingAlgorithm = CryptoAlgorithms::PasswordHashingAlgorithm; |
| 31 | + |
| 32 | + /** |
| 33 | + * A data-flow node that is an application of a cryptographic algorithm. For example, |
| 34 | + * encryption, decryption, signature-validation. |
| 35 | + * |
| 36 | + * Extend this class to refine existing API models. If you want to model new APIs, |
| 37 | + * extend `CryptographicOperation::Range` instead. |
| 38 | + */ |
| 39 | + class CryptographicOperation extends DataFlow::Node instanceof CryptographicOperation::Range { |
| 40 | + /** Gets the algorithm used, if it matches a known `CryptographicAlgorithm`. */ |
| 41 | + CryptographicAlgorithm getAlgorithm() { result = super.getAlgorithm() } |
| 42 | + |
| 43 | + /** Gets an input the algorithm is used on, for example the plain text input to be encrypted. */ |
| 44 | + DataFlow::Node getAnInput() { result = super.getAnInput() } |
| 45 | + |
| 46 | + /** |
| 47 | + * Gets the block mode used to perform this cryptographic operation. |
| 48 | + * This may have no result - for example if the `CryptographicAlgorithm` used |
| 49 | + * is a stream cipher rather than a block cipher. |
| 50 | + */ |
| 51 | + BlockMode getBlockMode() { result = super.getBlockMode() } |
| 52 | + } |
| 53 | + |
| 54 | + /** Provides classes for modeling new applications of a cryptographic algorithms. */ |
| 55 | + module CryptographicOperation { |
| 56 | + /** |
| 57 | + * A data-flow node that is an application of a cryptographic algorithm. For example, |
| 58 | + * encryption, decryption, signature-validation. |
| 59 | + * |
| 60 | + * Extend this class to model new APIs. If you want to refine existing API models, |
| 61 | + * extend `CryptographicOperation` instead. |
| 62 | + */ |
| 63 | + abstract class Range extends DataFlow::Node { |
| 64 | + /** Gets the algorithm used, if it matches a known `CryptographicAlgorithm`. */ |
| 65 | + abstract CryptographicAlgorithm getAlgorithm(); |
| 66 | + |
| 67 | + /** Gets an input the algorithm is used on, for example the plain text input to be encrypted. */ |
| 68 | + abstract DataFlow::Node getAnInput(); |
| 69 | + |
| 70 | + /** |
| 71 | + * Gets the block mode used to perform this cryptographic operation. |
| 72 | + * This may have no result - for example if the `CryptographicAlgorithm` used |
| 73 | + * is a stream cipher rather than a block cipher. |
| 74 | + */ |
| 75 | + abstract BlockMode getBlockMode(); |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * A cryptographic block cipher mode of operation. This can be used to encrypt |
| 81 | + * data of arbitrary length using a block encryption algorithm. |
| 82 | + */ |
| 83 | + class BlockMode extends string { |
| 84 | + BlockMode() { this = ["ECB", "CBC", "GCM", "CCM", "CFB", "OFB", "CTR", "OPENPGP"] } |
| 85 | + |
| 86 | + /** Holds if this block mode is considered to be insecure. */ |
| 87 | + predicate isWeak() { this = "ECB" } |
| 88 | + } |
| 89 | +} |
0 commit comments