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 ...
随机推荐
- BZOJ3356 : [Usaco2004 Jan]禁闭围栏
首先将坐标离散化,考虑从左往右扫描线 碰到插入操作则插入 碰到删除操作的: 当前包含i的矩形数=y1在[1,y2[i]]之间的矩形数-y2在[1,y1[i]-1]之间的矩形数 用两棵树状数组维护即可, ...
- ZOJ 3805 (树形DP)
题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5337 题目大意:方块连接,呈树形.每个方块有两种接法,一种接在父块 ...
- Java读数据是的编码问题。
今天使用Java的I/O读写数据的时候,出现了中文乱码问题,在老师的帮助下找到了问题的根源: 在window中新建文件时,如果你新建的是文本文件或者是一个windows无法识别的文件,他默认使用的编码 ...
- Gradle dsl method not found renderscriptSupportMode()
连接: How to use the Renderscript Support Library with Gradle Android-Studio and Renderscript support ...
- CC150 - 11.2
Question: Write a method to sort an array of strings so that all the anagrams are next to each other ...
- 【BZOJ】1834: [ZJOI2010]network 网络扩容(最大流+费用流)
http://www.lydsy.com/JudgeOnline/problem.php?id=1834 我又思考人生了T_T,nd的数组开小了,一直wa,调了一个小时才发现啊!!!!!我一直以为我的 ...
- COJ 拯救瑞恩
试题描述 在n行n列的字符方阵中I表示“我”最初所在位置,R是大兵瑞恩所在位置.4<n<11.“我”从当前位置可以向上.或下.或左.或右移动一格,只要新点无障碍且未出界.标有“.”的位置可 ...
- jQuery.Validate验证库详解
一.用前必备官方网站:http://bassistance.de/jquery-plugins/jquery-plugin-validation/ API: http://jquery.bassist ...
- PHP多重判断删除文件函数
<?function delete_file($file) { if (file_exists($file)) { $delete = chmod ($file, ...
- git基础及分支
关于版本控制 git是一种分布版本控制系统,每一主机都保存了完整副本.必杀技是分支. 在Windows可安装git客户端msysgit. git基础 第一次看progit觉得有点不懂,不懂版本控制,一 ...