|
| 1 | +From 8c6c45e7c9c0981f55e81e3d1d21fe0e271e6294 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Liu Dongmiao < [email protected]> |
| 3 | +Date: Thu, 29 Feb 2024 05:36:02 +0000 |
| 4 | +Subject: [PATCH] support cipher none |
| 5 | + |
| 6 | +--- |
| 7 | + src/crypto.c | 40 ++++++++++++++++++++++++++++++++++++++++ |
| 8 | + src/local.c | 2 +- |
| 9 | + src/redir.c | 2 +- |
| 10 | + src/server.c | 2 +- |
| 11 | + src/tunnel.c | 2 +- |
| 12 | + 5 files changed, 44 insertions(+), 4 deletions(-) |
| 13 | + |
| 14 | +diff --git a/src/crypto.c b/src/crypto.c |
| 15 | +index b44d8674c..76570ec30 100644 |
| 16 | +--- a/src/crypto.c |
| 17 | ++++ b/src/crypto.c |
| 18 | +@@ -131,6 +131,42 @@ entropy_check(void) |
| 19 | + #endif |
| 20 | + } |
| 21 | + |
| 22 | ++#ifndef ATTR_UNUSED |
| 23 | ++#define ATTR_UNUSED __attribute__((unused)) |
| 24 | ++#endif |
| 25 | ++ |
| 26 | ++static int none_encrypt_all(ATTR_UNUSED buffer_t *a, ATTR_UNUSED cipher_t *b, ATTR_UNUSED size_t c) { |
| 27 | ++ return CRYPTO_OK; |
| 28 | ++} |
| 29 | ++ |
| 30 | ++static int none_decrypt_all(ATTR_UNUSED buffer_t *a, ATTR_UNUSED cipher_t *b, ATTR_UNUSED size_t c) { |
| 31 | ++ return CRYPTO_OK; |
| 32 | ++} |
| 33 | ++ |
| 34 | ++static int none_encrypt(ATTR_UNUSED buffer_t *a, ATTR_UNUSED cipher_ctx_t *b, ATTR_UNUSED size_t c) { |
| 35 | ++ return CRYPTO_OK; |
| 36 | ++} |
| 37 | ++ |
| 38 | ++static int none_decrypt(ATTR_UNUSED buffer_t *a, ATTR_UNUSED cipher_ctx_t *b, ATTR_UNUSED size_t c) { |
| 39 | ++ return CRYPTO_OK; |
| 40 | ++} |
| 41 | ++ |
| 42 | ++static void none_ctx_init(ATTR_UNUSED cipher_t *a, ATTR_UNUSED cipher_ctx_t *b, ATTR_UNUSED int c) { |
| 43 | ++} |
| 44 | ++ |
| 45 | ++static void none_ctx_release(ATTR_UNUSED cipher_ctx_t *a) { |
| 46 | ++} |
| 47 | ++ |
| 48 | ++static crypto_t none_crypt = { |
| 49 | ++ .cipher = NULL, |
| 50 | ++ .encrypt_all = &none_encrypt_all, |
| 51 | ++ .decrypt_all = &none_decrypt_all, |
| 52 | ++ .encrypt = &none_encrypt, |
| 53 | ++ .decrypt = &none_decrypt, |
| 54 | ++ .ctx_init = &none_ctx_init, |
| 55 | ++ .ctx_release = &none_ctx_release, |
| 56 | ++}; |
| 57 | ++ |
| 58 | + crypto_t * |
| 59 | + crypto_init(const char *password, const char *key, const char *method) |
| 60 | + { |
| 61 | +@@ -150,6 +186,10 @@ crypto_init(const char *password, const char *key, const char *method) |
| 62 | + #endif |
| 63 | + |
| 64 | + if (method != NULL) { |
| 65 | ++ if (strcmp(method, "none") == 0) { |
| 66 | ++ return &none_crypt; |
| 67 | ++ } |
| 68 | ++ |
| 69 | + for (i = 0; i < STREAM_CIPHER_NUM; i++) |
| 70 | + if (strcmp(method, supported_stream_ciphers[i]) == 0) { |
| 71 | + m = i; |
| 72 | +diff --git a/src/local.c b/src/local.c |
| 73 | +index fa1ca7b31..e57dc1a1b 100644 |
| 74 | +--- a/src/local.c |
| 75 | ++++ b/src/local.c |
| 76 | +@@ -1709,7 +1709,7 @@ main(int argc, char **argv) |
| 77 | + exit(EXIT_FAILURE); |
| 78 | + } |
| 79 | + #endif |
| 80 | +- if (!password && !key) { |
| 81 | ++ if (!password && !key && strcmp(method, "none")) { |
| 82 | + fprintf(stderr, "both password and key are NULL\n"); |
| 83 | + exit(EXIT_FAILURE); |
| 84 | + } |
| 85 | +diff --git a/src/redir.c b/src/redir.c |
| 86 | +index d36fe3fe7..3110f11fc 100644 |
| 87 | +--- a/src/redir.c |
| 88 | ++++ b/src/redir.c |
| 89 | +@@ -1150,7 +1150,7 @@ main(int argc, char **argv) |
| 90 | + } |
| 91 | + |
| 92 | + if (remote_num == 0 || remote_port == NULL || local_port == NULL |
| 93 | +- || (password == NULL && key == NULL)) { |
| 94 | ++ || (password == NULL && key == NULL && strcmp(method, "none"))) { |
| 95 | + usage(); |
| 96 | + exit(EXIT_FAILURE); |
| 97 | + } |
| 98 | +diff --git a/src/server.c b/src/server.c |
| 99 | +index 73b65996d..91cd2e935 100644 |
| 100 | +--- a/src/server.c |
| 101 | ++++ b/src/server.c |
| 102 | +@@ -2100,7 +2100,7 @@ main(int argc, char **argv) |
| 103 | + } |
| 104 | + |
| 105 | + if (server_num == 0 || server_port == NULL |
| 106 | +- || (password == NULL && key == NULL)) { |
| 107 | ++ || (password == NULL && key == NULL && strcmp(method, "none"))) { |
| 108 | + usage(); |
| 109 | + exit(EXIT_FAILURE); |
| 110 | + } |
| 111 | +diff --git a/src/tunnel.c b/src/tunnel.c |
| 112 | +index 99ed41287..fd5f2eb2c 100644 |
| 113 | +--- a/src/tunnel.c |
| 114 | ++++ b/src/tunnel.c |
| 115 | +@@ -1151,7 +1151,7 @@ main(int argc, char **argv) |
| 116 | + } |
| 117 | + |
| 118 | + if (remote_num == 0 || remote_port == NULL || tunnel_addr_str == NULL |
| 119 | +- || local_port == NULL || (password == NULL && key == NULL)) { |
| 120 | ++ || local_port == NULL || (password == NULL && key == NULL && strcmp(method, "none"))) { |
| 121 | + usage(); |
| 122 | + exit(EXIT_FAILURE); |
| 123 | + } |
0 commit comments