Comments (7)
@v2ray 有点难度,在kcp里面,对数据的分段,是内部进行的,比如送入一个Payload []byte,可能被分割为很多个MTU大小的 UDP数据包发送,每个数据包都是独立加密封装的,并会填充CRC32。
其次,kcp为了做整个数据包加密,包括数据+KCP协议头(特别是协议头),只能在内部最终sendto之前完成加密,如果在外部做,kcp协议头只能是明文了,有安全风险。
所以这样的接口定义不合适,另外,目前的kcp-go使用的cipher.Block已经不依赖于某种特定的加密算法了, 常用算法都可以方便使用这个接口,比如加密算法在kcptun里面自定义。
所以,我的建议是,实现cipher.Block接口即可,和你给的接口定义没有本质差异
type Block interface {
// BlockSize returns the cipher's block size.
BlockSize() int
// Encrypt encrypts the first block in src into dst.
// Dst and src may point at the same memory.
Encrypt(dst, src []byte)
// Decrypt decrypts the first block in src into dst.
// Dst and src may point at the same memory.
Decrypt(dst, src []byte)
}
from kcp-go.
@v2ray 你说的意思,是不是把encrypt()/decrypt()函数描述的CFB模式,改为外部自定义?如果是这样,存在加密用法错误的风险,比如用 CTR/ECB,会导致特征泄漏,加密是需要精心设计的,最好不交给调用者控制,如果缺算法,可以补上即可。
from kcp-go.
是你说的第二种方式。
我想说的只是耦合的问题,加密解密和 session 没有直接关系,你可以把现有的 encrypt()/decrypt() 做成一个比如 DefaultCryptor,普通用户依然可以通过简单的调用实现默认的加密方式,而高级用户可以更自由地定义加密和解密的方式。
from kcp-go.
@v2ray 我试一下
from kcp-go.
@v2ray 实现了一个 BlockCrypt接口,看下是不是你需要的
from kcp-go.
谢谢,正是我想要的。
from kcp-go.
但愿自定义加密早日能成为现实,建议加入基于公钥的加密方式
from kcp-go.
Related Issues (20)
- write to non-existent host does not cause an error
- packetInput 允许用户自行处理解码失败的UDP包
- is it possible to disable ack, for use in unidirectional network.
- 希望Listener上能提供一个NewUdpSession的方法
- 如何提升kcp的速度? HOT 4
- kcp.(*UDPSession).update 存在内存泄漏? HOT 19
- 为什么一重启服务器端,就收不到客户端传来的信息呢
- 服务器链接超过某个数后内存暴涨 HOT 1
- 如何抵御重放攻击(How to defend against replay attacks)? HOT 1
- 用户数据过大时,会出现数据错乱问题 HOT 3
- 只能通过UDPSession.Close才能跳出readloop循环,如果通过调用SetXXXDeadline的方式,会造成协程泄露。 HOT 1
- 在穿越了NAT的P2P隧道里,使用kcp.NewConn2建立的一对连接无法成功通信
- 请教一个dynamic fec的参数问题 HOT 2
- CI
- Use of deprecated crypto libraries HOT 2
- 客户端动态fec调整问题请教 HOT 2
- [请教一下] 客户端和服务端任何一侧离线了该如何感知
- 当调用Read和Write后,修改UDPSession的超时时间不生效 HOT 1
- Data splitting and merging HOT 2
- How to handle restarts? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kcp-go.