keycloak-spi-private
クラス | 公開メンバ関数 | 静的公開変数類 | 非公開変数類 | 全メンバ一覧
org.keycloak.models.utils.TimeBasedOTP クラス
org.keycloak.models.utils.TimeBasedOTP の継承関係図
Inheritance graph
org.keycloak.models.utils.TimeBasedOTP 連携図
Collaboration graph

クラス

class  Clock
 

公開メンバ関数

 TimeBasedOTP ()
 
 TimeBasedOTP (String algorithm, int numberDigits, int timeIntervalInSeconds, int lookAheadWindow)
 
String generateTOTP (String secretKey)
 
boolean validateTOTP (String token, byte[] secret)
 
void setCalendar (Calendar calendar)
 

静的公開変数類

static final int DEFAULT_INTERVAL_SECONDS = 30
 
static final int DEFAULT_DELAY_WINDOW = 1
 

非公開変数類

Clock clock
 

詳解

TOTP: Time-based One-time Password Algorithm Based on http://tools.ietf.org/html/draft-mraihi-totp-timebased-06

著者
anil saldhana
から
Sep 20, 2010

構築子と解体子

◆ TimeBasedOTP() [1/2]

org.keycloak.models.utils.TimeBasedOTP.TimeBasedOTP ( )
inline
37  {
38  this(DEFAULT_ALGORITHM, DEFAULT_NUMBER_DIGITS, DEFAULT_INTERVAL_SECONDS, DEFAULT_DELAY_WINDOW);
39  }
static final int DEFAULT_DELAY_WINDOW
Definition: TimeBasedOTP.java:33
static final int DEFAULT_INTERVAL_SECONDS
Definition: TimeBasedOTP.java:32

◆ TimeBasedOTP() [2/2]

org.keycloak.models.utils.TimeBasedOTP.TimeBasedOTP ( String  algorithm,
int  numberDigits,
int  timeIntervalInSeconds,
int  lookAheadWindow 
)
inline
引数
algorithmthe encryption algorithm
numberDigitsthe number of digits for tokens
timeIntervalInSecondsthe number of seconds a token is valid
lookAheadWindowthe number of previous intervals that should be used to validate tokens.
47  {
48  super(numberDigits, algorithm, lookAheadWindow);
49  this.clock = new Clock(timeIntervalInSeconds);
50  }
Clock clock
Definition: TimeBasedOTP.java:35

関数詳解

◆ generateTOTP()

String org.keycloak.models.utils.TimeBasedOTP.generateTOTP ( String  secretKey)
inline

Generates a token.

引数
secretKeythe secret key to derive the token from.
57  {
58  long T = this.clock.getCurrentInterval();
59 
60  String steps = Long.toHexString(T).toUpperCase();
61 
62  // Just get a 16 digit string
63  while (steps.length() < 16)
64  steps = "0" + steps;
65 
66  return generateOTP(secretKey, steps, this.numberDigits, this.algorithm);
67  }
Clock clock
Definition: TimeBasedOTP.java:35
long getCurrentInterval()
Definition: TimeBasedOTP.java:109

◆ setCalendar()

void org.keycloak.models.utils.TimeBasedOTP.setCalendar ( Calendar  calendar)
inline
96  {
97  this.clock.setCalendar(calendar);
98  }
void setCalendar(Calendar calendar)
Definition: TimeBasedOTP.java:119
Clock clock
Definition: TimeBasedOTP.java:35

◆ validateTOTP()

boolean org.keycloak.models.utils.TimeBasedOTP.validateTOTP ( String  token,
byte []  secret 
)
inline

Validates a token using a secret key.

引数
tokenOTP string to validate
secretShared secret
戻り値
76  {
77  long currentInterval = this.clock.getCurrentInterval();
78 
79  for (int i = this.lookAheadWindow; i >= 0; --i) {
80  String steps = Long.toHexString(currentInterval - i).toUpperCase();
81 
82  // Just get a 16 digit string
83  while (steps.length() < 16)
84  steps = "0" + steps;
85 
86  String candidate = generateOTP(new String(secret), steps, this.numberDigits, this.algorithm);
87 
88  if (candidate.equals(token)) {
89  return true;
90  }
91  }
92 
93  return false;
94  }
Clock clock
Definition: TimeBasedOTP.java:35
long getCurrentInterval()
Definition: TimeBasedOTP.java:109

メンバ詳解

◆ clock

Clock org.keycloak.models.utils.TimeBasedOTP.clock
private

◆ DEFAULT_DELAY_WINDOW

final int org.keycloak.models.utils.TimeBasedOTP.DEFAULT_DELAY_WINDOW = 1
static

◆ DEFAULT_INTERVAL_SECONDS

final int org.keycloak.models.utils.TimeBasedOTP.DEFAULT_INTERVAL_SECONDS = 30
static

このクラス詳解は次のファイルから抽出されました: