Thursday, February 18, 2016

TOTP - 银行的动态口令令牌是什么原理



http://blog.jobbole.com/97877/
在大众用户手中的动态口令令牌,并不使用任何对称或者非对称加密的算法,在整个银行的认证体系中,动态口令令牌只是一个一次性口令的产生器,在其中运行的主要计算仅包括时间因子的计算和散列值的计算。
动态口令算法又叫一次性口令算法,英文写作OTP(One-Time Password Algorithm), 动态口令令牌使用的算法是OTP中的一类,TOTP(Time-Based One-Time Password Algorithm) — 时间同步型动态口令。
时间同步型动态口令产生口令的时候和时间有关系,我们可以通过其工作的原理图来看一下:
Screen Shot 2016-02-08 at 5.06.00 PM.png
图示给出了动态口令的工作原理,突出了整个认证机制中的动态口令部分,我们可以清楚看到在最左边和最右边有完全相同的两个流程,这里分别代表了用户的令牌卡和银行服务器的验证机器做的工作。本文的重点就在这两个完全相同的流程上。
在用户从银行手中拿到动态口令令牌卡的时候,在令牌卡的内部已经存储了一份种子文件(即图中钥匙所代表的seed),这份种子文件在银行的服务器里保存的完全一样的一份,所以对于动态口令令牌来说,这种方式是 share secret的。另外在令牌硬件上的设置中,假使有人打开了这个令牌卡,种子文件将会从令牌卡的内存上擦除(待考证)。
令牌卡中有了种子文件,并实现了 TOTP 算法,在预先设置的间隔时间里它就能不断产生不同的动态口令,并显示到屏幕上,而银行服务器上跟随时间做同样的计算,也会得到和令牌卡同样的口令,用作认证。
那么 TOTP 算法具体做了什么操作呢?在 RFC6238 中有详细的算法描述,这里也会做简单的叙述。
TOTP 是来自 HOTP [RFC4226] 的变形,从统筹上看,他们都是将数据文件进行散列计算,只是HOTP的因子是事件因子,TOTP将因子换成了时间因子,具体的TOTP计算公式(其中的HMAC-SHA-256 也可能是 HMAC-SHA-512):
TOTP = Truncate(HMAC-SHA-256(K,T))
其中: K 为这里的种子文件内容; T 为计算出来的时间因子
公式中的 HMAC是密钥相关的哈希运算消息认证码(Hash-based Message Authentication Code),HMAC运算利用哈希算法,以一个密钥和一个消息为输入,生成一个消息摘要作为输出。而公式中给出的哈希算法是 SHA-256,这种哈希算法目前并没有好的破解办法。
令牌卡中预先设置了要显示的口令长度,TOTP 中的 Truncate 操作剪切获得口令。
以上就是动态口令令牌卡的内部原理。
几点补充:
1.  时间同步型动态口令对令牌卡和服务器的时间同步要求很高,时间误差会造成整个令牌的失灵,所以每一次用户成功使用令牌认证,服务器都会做相应的时间误差矫正。
2. 种子文件的产生使用了一种AES-128 变形而来的算法, AES-128 也是目前顶尖级的对称加密技术。
3. 目前从加密技术上以及数学理论上整个银行机制的认证系统基本无解。


Yes, significantly. OTP (One-Time Password) codes require a critical, centralized cryptographic seed stored on the IPA server matching the seed on your external device such that they both mathematically derive the same PIN concurrently. This seed can be stolen or manipulated, and such an occurrence effectively negates the OTP's security.

http://arstechnica.com/security/2011/06/rsa-finally-comes-clean-securid-is-compromised/ --http://blogs.rsa.com/anatomy-of-an-attack/)SecurID tokens are used in two-factor authentication systems. Each user account is linked to a token, and each token generates a pseudo-random number that changes periodically, typically every 30 or 60 seconds. To log in, the user enters a username, password, and the number shown on their token. The authentication server knows what number a particular token should be showing, and so uses this number to prove that the user is in possession of their token.
The exact sequence of numbers that a token generates is determined by a secret RSA-developed algorithm, and a seed value used to initialize the token. Each token has a different seed, and it's this seed that is linked to each user account. If the algorithm and seed are disclosed, the token itself becomes worthless; the numbers can be calculated in just the same way that the authentication server calculates them.

Labels

Review (572) System Design (334) System Design - Review (198) Java (189) Coding (75) Interview-System Design (65) Interview (63) Book Notes (59) Coding - Review (59) to-do (45) Linux (43) Knowledge (39) Interview-Java (35) Knowledge - Review (32) Database (31) Design Patterns (31) Big Data (29) Product Architecture (28) MultiThread (27) Soft Skills (27) Concurrency (26) Cracking Code Interview (26) Miscs (25) Distributed (24) OOD Design (24) Google (23) Career (22) Interview - Review (21) Java - Code (21) Operating System (21) Interview Q&A (20) System Design - Practice (20) Tips (19) Algorithm (17) Company - Facebook (17) Security (17) How to Ace Interview (16) Brain Teaser (14) Linux - Shell (14) Redis (14) Testing (14) Tools (14) Code Quality (13) Search (13) Spark (13) Spring (13) Company - LinkedIn (12) How to (12) Interview-Database (12) Interview-Operating System (12) Solr (12) Architecture Principles (11) Resource (10) Amazon (9) Cache (9) Git (9) Interview - MultiThread (9) Scalability (9) Trouble Shooting (9) Web Dev (9) Architecture Model (8) Better Programmer (8) Cassandra (8) Company - Uber (8) Java67 (8) Math (8) OO Design principles (8) SOLID (8) Design (7) Interview Corner (7) JVM (7) Java Basics (7) Kafka (7) Mac (7) Machine Learning (7) NoSQL (7) C++ (6) Chrome (6) File System (6) Highscalability (6) How to Better (6) Network (6) Restful (6) CareerCup (5) Code Review (5) Hash (5) How to Interview (5) JDK Source Code (5) JavaScript (5) Leetcode (5) Must Known (5) Python (5)

Popular Posts