OTP Identity Challenge Skill
Challenge users for fresh two-factor authentication before sensitive actions.
When to Use
Require OTP verification before:
- - Deploy commands (
kubectl apply, terraform apply) - Financial operations (transfers, payment approvals)
- Data access (PII exports, customer data)
- Admin operations (user modifications, permission changes)
Scripts
verify.sh
Verify a user's OTP code and record verification state.
CODEBLOCK0
Parameters:
- -
user_id - Identifier for the user (e.g., email, username) - INLINECODE3 - Either 6-digit TOTP or 44-character YubiKey OTP
Exit codes:
- -
0 - Verification successful - INLINECODE5 - Invalid code or rate limited
- INLINECODE6 - Configuration error (missing secret, invalid format)
Output on success:
CODEBLOCK1
Output on failure:
CODEBLOCK2
check-status.sh
Check if a user's verification is still valid.
CODEBLOCK3
Exit codes:
- -
0 - User has valid (non-expired) verification - INLINECODE8 - User not verified or verification expired
Output:
CODEBLOCK4
generate-secret.sh
Generate a new TOTP secret with QR code (requires qrencode to be installed).
CODEBLOCK5
Usage Pattern
CODEBLOCK6
Configuration
Required for TOTP:
- -
OTP_SECRET - Base32 TOTP secret
Required for YubiKey:
- -
YUBIKEY_CLIENT_ID - Yubico API client ID - INLINECODE12 - Yubico API secret key (base64)
Optional:
- -
OTP_INTERVAL_HOURS - Verification expiry (default: 24) - INLINECODE14 - Failed attempts before rate limiting (default: 3)
- INLINECODE15 - State file path (default:
memory/otp-state.json)
Configuration can be set via environment variables or in ~/.openclaw/config.yaml:
CODEBLOCK7
Code Format Detection
The script auto-detects code type:
- - 6 digits (
123456) → TOTP validation - 44 ModHex characters (
cccccc...) → YubiKey validation
ModHex alphabet: INLINECODE20
State File
Verification state stored in memory/otp-state.json. Contains only timestamps, no secrets.
Human Documentation
See README.md for:
- - Installation instructions
- Setup guides (TOTP and YubiKey)
- Security considerations
- Troubleshooting
- Examples
OTP 身份验证技能
在执行敏感操作前,要求用户进行新的双重身份验证。
使用场景
在以下操作前需要 OTP 验证:
- - 部署命令(kubectl apply、terraform apply)
- 财务操作(转账、支付审批)
- 数据访问(PII 导出、客户数据)
- 管理操作(用户修改、权限变更)
脚本
verify.sh
验证用户的 OTP 代码并记录验证状态。
bash
./verify.sh <用户ID> <验证码>
参数:
- - 用户ID - 用户标识符(例如:邮箱、用户名)
- 验证码 - 6 位 TOTP 或 44 字符 YubiKey OTP
退出码:
- - 0 - 验证成功
- 1 - 无效验证码或触发频率限制
- 2 - 配置错误(缺少密钥、格式无效)
成功输出:
✅ OTP 已验证用户 <用户ID>(24 小时内有效)
✅ YubiKey 已验证用户 <用户ID>(24 小时内有效)
失败输出:
❌ 无效的 OTP 验证码
❌ 尝试次数过多。请在 X 分钟后重试。
❌ 验证码格式无效。应为 6 位 TOTP 或 44 字符 YubiKey OTP。
check-status.sh
检查用户的验证是否仍然有效。
bash
./check-status.sh <用户ID>
退出码:
- - 0 - 用户拥有有效(未过期)的验证
- 1 - 用户未验证或验证已过期
输出:
✅ 还有 23 小时有效
⚠️ 2 小时前已过期
❌ 从未验证
generate-secret.sh
生成带有二维码的新 TOTP 密钥(需要安装 qrencode)。
bash
./generate-secret.sh <账户名>
使用模式
bash
#!/bin/bash
source ../otp/verify.sh
if ! verify_otp $用户ID $OTP验证码; then
echo 🔒 此操作需要 OTP 验证
exit 1
fi
继续执行敏感操作
配置
TOTP 必需配置:
- - OTP_SECRET - Base32 TOTP 密钥
YubiKey 必需配置:
- - YUBIKEYCLIENTID - Yubico API 客户端 ID
- YUBIKEYSECRETKEY - Yubico API 密钥(base64)
可选配置:
- - OTPINTERVALHOURS - 验证过期时间(默认:24 小时)
- OTPMAXFAILURES - 触发频率限制前的失败尝试次数(默认:3 次)
- OTPSTATEFILE - 状态文件路径(默认:memory/otp-state.json)
配置可通过环境变量或 ~/.openclaw/config.yaml 设置:
yaml
security:
otp:
secret: BASE32_SECRET
yubikey:
clientId: 12345
secretKey: base64secret
验证码格式检测
脚本自动检测验证码类型:
- - 6 位数字(123456)→ TOTP 验证
- 44 个 ModHex 字符(cccccc...)→ YubiKey 验证
ModHex 字母表:cbdefghijklnrtuv
状态文件
验证状态存储在 memory/otp-state.json 中。仅包含时间戳,不包含密钥。
用户文档
详见 README.md:
- - 安装说明
- 设置指南(TOTP 和 YubiKey)
- 安全注意事项
- 故障排除
- 示例