One Time Auth
One Time Auth
One-time authentication (shortened as OTA) is a new experimental feature designed to improve the security against CCA. You should understand the protocol before reading this document.
By default, the server that supports OTA should run in the compatible mode. OTA is only applied if the client's request header has a flag set. However, if the server switch on OTA explicitly, all clients must switch on OTA, otherwise connections will be denied.
The authentication method is HMAC-SHA1 which has wide supports among all major platforms and fairly good speed.
TCP
The structure of an OTA-enabled request (unencrypted) is shown below:
+------+---------------------+------------------+-----------+
| ATYP | Destination Address | Destination Port | HMAC-SHA1 |
+------+---------------------+------------------+-----------+
| 1 | Variable | 2 | 10 |
+------+---------------------+------------------+-----------+
ATYP is a 8-bit char where the rightmost four bits, 0b00001111 (0xf), are reserved for address types, the flag bit of OTA is 0b00010000 (0x10). In C/C++, simply check if ATYP & 0x10 == 0x10, then OTA is enabled.
The key of HMAC-SHA1 is (IV + KEY), and the input is the whole header (not including HMAC-SHA1). The output of HMAC-SHA1 is truncated to leftmost 80 bits (10 bytes) according to RFC 2104.
Chunk Authentication
The structure of an OTA-enabled chunk (decrypted) of shadowsocks TCP relay is shown below:
+----------+-----------+----------+----
| DATA.LEN | HMAC-SHA1 | DATA | ...
+----------+-----------+----------+----
| 2 | 10 | Variable | ...
+----------+-----------+----------+----
DATA.LEN is a 16-bit big-endian integer indicating the length of DATA.
The input of HMAC-SHA1 is DATA. And the key of HMAC-SHA1 is (IV + Chunk ID) where Chunk ID is an unsigned integer counted per connection from 0. In order to achieve this, both server side and client side need to keep a counter for each TCP connection. Chunk ID must be converted to big-endian before constructing the key of HMAC-SHA1.
For a client, after constructing an OTA-enabled request, the whole chunk is encrypted as a payload then sent to server-side.
Tips:
- The server must check the completeness of a shadowsocks TCP request before verifying HMAC-SHA1 and forwarding.
- The chunk authentication is only applied for the packets sent from client-side shadowsocks.
UDP
There is no session in UDP relay, each UDP packet contains both header and data. Therefore, for an OTA-enabled UDP packet, the datagram structure (unencrypted) is slightly different:
+------+---------------------+------------------+----------+-----------+
| ATYP | Destination Address | Destination Port | DATA | HMAC-SHA1 |
+------+---------------------+------------------+----------+-----------+
| 1 | Variable | 2 | Variable | 10 |
+------+---------------------+------------------+----------+-----------+
The key of HMAC-SHA1 is (IV + KEY), and the input is the header plus data.
One Time Auth的更多相关文章
- Laravel 5.3 auth中间件底层实现详解
1. 注册认证中间件, 在文件 app/Http/Kernel.php 内完成: protected $routeMiddleware = [ 'auth' => \Illuminate\Aut ...
- httpclient进行basic auth认证
private HttpClientContext context = HttpClientContext.create(); public void addUserOAuth(String user ...
- Apache增加Basic Auth
在.htaccess文件中增加 AuthUserFile /var/www/htpasswd/test.htpasswd AuthName EnterPassword AuthType Basic r ...
- asp.net mvc api auth
一.登录 /// <summary> /// 获取令牌 /// </summary> /// <param name="userName">用户 ...
- Send Push Notifications to iOS Devices using Xcode 8 and Swift 3, APNs Auth Key
Send Push Notifications to iOS Devices using Xcode 8 and Swift 3 OCT 6, 2016 Push notifications are ...
- RBAC在thinkphp中有Auth类 可以很好的实现权限控制
import('ORG.Util.Auth');//加载类库 $auth=new Auth(); if($auth->check('show_button',1)){// 第一个参数是规则名称, ...
- 智慧城市的【Auth】登录对象
从Auth对象看前端:1.将与Auth对象相关的功能分离出来.所含的内容包括:[个人中心相关信息的显示,注册,登录,忘记密码,修改密码,个人信息修改]. 2.从“我的”页面开始,显示使用哪儿的数据,需 ...
- auth用户认证库
关于auth库,建议如下:1. ion_auth,基于Redux重写而成,非常不错的认证库,国外用的很多,几个最新的ci2.0.2基础上的开源系统(如doveforum)都用它,支持ci 2.0和以上 ...
- Redis集群~StackExchange.Redis(10月6号版1.1.608.0)连接Twemproxy支持Auth指令了
回到目录 对于StackExchange.Redis这个驱动来说,之前的版本在使用Proxy为Twemproxy代理时,它是不支持Password属性的,即不支持原始的Auth指令,而我也修改过源代码 ...
- Server asks us to fall back to SIMPLE auth, but this client is configured to only allow secure connections.
我是在flume向hdfs 写(sink)数据时遇到的这个错误. Server (是指hdfs) asks us to fall back to SIMPLE auth, but this clien ...
随机推荐
- bzoj1016 [JSOI2008]最小生成树计数
1016: [JSOI2008]最小生成树计数 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 3517 Solved: 1396[Submit][St ...
- Remove Duplicates from Sorted List II leetcode java
题目: Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct ...
- CSS中a标签样式的“爱恨”原则
CSS为一些特殊效果准备了特定的工具,我们称之为“伪类”.其中有几项是我们经常用到的,下面我们就详细介绍一下经常用于定义链接样式的四个伪类,它们分别是: 1 :link 2 :visited 3 :h ...
- iOS开发项目之二 [ App appicon与启动图]
*appicon尺寸 *不是所有的appicon都是需要配置 *尽量不要透明--(透明的话,会在桌面显示成背景黑色) 1 如果没有配置5s的启动图,回去往下找,找到4s之后,会把界面以4s启动图的大小 ...
- The declared package does not match the expected package
The declared package does not match the expected package. 1.选中项目右击选择Build Path-->再选择Configure Bui ...
- 使用CSS3实现百叶窗
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title&g ...
- 一个关于el中获取对象属性的错误
具体过程描述为: 在JSP页面中通过<%%>定义一个非public类.并定义两个属性相应的get和set方法.在该代码段中实例化该对象,并将该对象放入Request域中. 然后在页面中使用 ...
- Leetcode | N-Queens I & II
N-Queens I The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no ...
- PAT天梯赛练习题 L2-013 红色警报(并查集+逆序加边)
L2-013. 红色警报 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 战争中保持各个城市间的连通性非常重要.本题要求你编写一 ...
- FlowVisor 安装
参考:Github-FlowVisor-wiki 第一步 添加公钥: 命令: $ wget http://updates.onlab.us/GPG-KEY-ONLAB $ sudo apt-key a ...