Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions TeXmacs/progs/client/client-base.scm
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@
(set-user-info "email" email))))
(with server (client-start server-name)
(when (!= server -1)
(enter-secure-mode server)
(client-remote-eval*
server `(new-account ,pseudo ,name ,passwd ,email ,agreed)
(lambda (msg)
Expand All @@ -198,7 +197,6 @@
(ahash-set! client-active-connections server (list server-name pseudo))
(ahash-set! client-active-connections server-name server)
(set! remote-client-list (client-active-servers))
(enter-secure-mode server)
(client-remote-eval* server `(remote-login ,pseudo ,passwd) wcb)))))

(tm-define (client-login server-name pseudo passwd)
Expand Down
1 change: 0 additions & 1 deletion TeXmacs/progs/prog/glue-symbols.scm
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,6 @@
"client-stop"
"client-read"
"client-write"
"enter-secure-mode"
"connection-start"
"connection-status"
"connection-write-string"
Expand Down
114 changes: 114 additions & 0 deletions devel/0131.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# [0131] 移除 Openssl 插件及相关加密通信功能

## 1 相关文档
- [dddd.md](dddd.md) - 任务文档模板

## 2 任务相关的代码文件
- `src/Plugins/Openssl/openssl.cpp`
- `src/Plugins/Openssl/openssl.hpp`
- `src/System/Link/tm_link.cpp`
- `src/System/Link/tm_link.hpp`
- `src/System/Link/texmacs_client.cpp`
- `src/System/Link/client_server.hpp`
- `TeXmacs/progs/client/client-base.scm`
- `TeXmacs/progs/prog/glue-symbols.scm`
- `src/Scheme/Glue/glue_basic.lua`
- `xmake.lua`

## 3 如何测试

### 3.1 确定性测试(单元测试)
```
# 无新增单元测试,通过编译即可验证
```

### 3.2 非确定性测试(文档验证)
```
xmake b stem
```

## 4 如何提交

提交前执行以下最少步骤:

```bash
# 编译验证
xmake b stem
```

## 5 What

移除 Openssl 插件及其在 socket 通信链路中的加密功能调用,包括:

1. **Openssl 插件本身**:`src/Plugins/Openssl/` 目录下的 `openssl.cpp` 和 `openssl.hpp`,提供基于外部 `openssl` 命令行工具的 RSA 加密/解密、AES 加密/解密、密钥生成和哈希功能。
2. **链路层加密逻辑**:`tm_link` 中基于 `secret` 成员变量的数据包加解密,以及 `secure_server` / `secure_client` 握手协议。
3. **客户端安全模式入口**:`texmacs_client.cpp` 中的 `enter_secure_mode` 函数及 `client_server.hpp` 中的声明。
4. **Scheme 层安全模式调用**:`client-base.scm` 中 `new-account` 和 `client-login-then` 函数对 `enter-secure-mode` 的调用。
5. **Glue 绑定**:`glue_basic.lua` 中 `enter-secure-mode` 的 glue 定义,以及 `glue-symbols.scm` 中的对应符号。
6. **构建系统引用**:`xmake.lua` 中对 `src/Plugins/Openssl/**.cpp` 的编译引用。

## 6 Why

Mogan STEM 不使用 TeXmacs 的远程协作(client/server)功能,该功能依赖 Openssl 插件对 socket 通信进行 RSA+AES 加密。保留这部分代码会引入对外部 `openssl` 命令行工具的依赖,且相关功能在当前产品中无实际使用场景,属于死代码,应予以清理。

## 7 How

### 7.1 分析结论

Openssl 插件的功能仅在 `tm_link` 的 socket 通信加密场景中被调用:

- `secret_encode` / `secret_decode`:在 `write_packet` / `read_packet` 中对数据包进行 AES 加解密。
- `secret_generate`:在 `secure_server` 中生成随机密钥。
- `rsa_encode` / `rsa_decode` / `rsa_my_public_key` / `rsa_my_private_key`:在 `secure_server` / `secure_client` 中完成 RSA 密钥交换。
- `enter_secure_mode` / `enter-secure-mode`:C++ 实现为 `enter_secure_mode`,Scheme 层通过 glue 调用。在 `client-base.scm` 的 `new-account` 和 `client-login-then` 中被调用。

因此,移除 Openssl 插件的同时,需要同步移除 `tm_link` 中的加密逻辑和 `texmacs_client` 中的安全模式入口。

### 7.2 修改步骤

#### 7.2.1 移除 Openssl 插件

- 删除 `src/Plugins/Openssl/openssl.cpp`
- 删除 `src/Plugins/Openssl/openssl.hpp`

#### 7.2.2 移除 tm_link 中的加密逻辑

在 `src/System/Link/tm_link.hpp` 中:
- 移除 `string secret;` 成员变量。
- 移除 `secure_server (string cmd)` 和 `secure_client ()` 方法声明。

在 `src/System/Link/tm_link.cpp` 中:
- 移除 `#include "../Plugins/Openssl/openssl.hpp"`。
- 在 `write_packet` 中移除 `if (secret != "") s= secret_encode (s, secret);` 及其条件判断,直接写入原始数据。
- 在 `read_packet` 中移除 `secure_server (message_receive (r));` 的分支(该分支处理以 `!` 开头的服务器握手包),以及 `if (secret != "") back= secret_decode (back, secret);` 的解密逻辑。
- 删除 `secure_server` 和 `secure_client` 的方法实现。

#### 7.2.3 移除客户端安全模式入口

在 `src/System/Link/texmacs_client.cpp` 中:
- 移除 QTTEXMACS 版本的 `enter_secure_mode (int fd)` 函数实现。
- 移除非 QTTEXMACS 版本的 `enter_secure_mode (int fd)` 函数实现。

在 `src/System/Link/client_server.hpp` 中:
- 移除 `void enter_secure_mode (int fd);` 声明。

#### 7.2.4 移除 Scheme 层安全模式调用

在 `TeXmacs/progs/client/client-base.scm` 中:
- 移除 `new-account` 函数中的 `(enter-secure-mode server)` 调用。
- 移除 `client-login-then` 函数中的 `(enter-secure-mode server)` 调用。

#### 7.2.5 移除 Glue 绑定

Glue 代码(`build/glue/glue_basic.cpp` 等)由构建系统根据 lua 定义自动生成,**只需修改源定义文件**。

在 `src/Scheme/Glue/glue_basic.lua` 中:
- 移除 `enter-secure-mode` 的 glue 定义。

在 `TeXmacs/progs/prog/glue-symbols.scm` 中:
- 移除 `"enter-secure-mode"` 符号。

#### 7.2.6 更新构建系统

在 `xmake.lua` 中:
- 从 `add_files` 列表中移除 `"src/Plugins/Openssl/**.cpp"`。
145 changes: 0 additions & 145 deletions src/Plugins/Openssl/openssl.cpp

This file was deleted.

26 changes: 0 additions & 26 deletions src/Plugins/Openssl/openssl.hpp

This file was deleted.

9 changes: 0 additions & 9 deletions src/Scheme/Glue/glue_basic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1099,15 +1099,6 @@ function main()
"string"
}
},
{
scm_name = "enter-secure-mode",
cpp_name = "enter_secure_mode",
ret_type = "void",
arg_list = {
"int"
}
},

-- connections to extern systems
{
scm_name = "connection-start",
Expand Down
2 changes: 0 additions & 2 deletions src/System/Link/client_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,4 @@ void client_stop (int fd);
string client_read (int fd);
void client_write (int fd, string s);

void enter_secure_mode (int fd);

#endif // defined CLIENT_SERVER_H
13 changes: 0 additions & 13 deletions src/System/Link/texmacs_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,6 @@ client_write (int fd, string s) {
client->write_packet (s, LINK_IN);
}

void
enter_secure_mode (int fd) {
socket_link* client= the_clients[fd];
if (client == NULL || !client->alive ()) return;
client->secure_client ();
}

#else // Non QT part

typedef socket_link_rep* weak_socket_link;
Expand Down Expand Up @@ -151,10 +144,4 @@ client_write (int fd, string s) {
client->write_packet (s, LINK_IN);
}

void
enter_secure_mode (int fd) {
weak_socket_link client= find_client (fd);
if (client == NULL || !client->alive) return;
client->secure_client ();
}
#endif
Loading
Loading