openfire登陆及密码验证过程

本文介绍了Openfire的登录流程,包括支持的登录方式和密码验证机制。重点讲解了使用Blowfish加密的密码存储,以及SASL Authentication中的PLAIN方式。详细解析了从Base64解码到验证密码的步骤,展示了服务器与客户端的交互过程。
摘要由CSDN通过智能技术生成

QQ: 277869380. 因为sina博客改版后xml字符无法正常显示。现在把sina博客上的内容迁移过来

本文有点乱,是我在openfire开发过程中随手写下来的


openfire支持多种方式的登陆, 包括TLS安全登陆和多种账号密码验证方式。

 

  

openfire的密码获取和设置部分由authProvider(DefaultAuthProvider)完成。

authProvider.getPassword(username.toLowerCase()); 从数据库中获取密码并解密。

 

openfire使用Blowfish对明文密码进行加密。它是一种对称密钥的分组密码,使用32位至448位的可变长度密钥,应用于内部加密或加密输出。openfire首先通过lCBCIV = m_rndGen.nextLong();对每一个明文密码产生一个随机数lCBCIV(8字节),然后使用这个随机数(64位密钥)来加密明文密码,最后一起存放在数据库表ofuser内。

 

openfire非常灵活,在实际项目中可以在配置文件(ofproperty表)中修改authProvider,加入自己的密码验证方

式。

 

登陆密码验证由StazaHandler的
("auth".equals(tag)) {
            // User is trying to authenticate using SASL
            startedSASL = true;
            // Process authentication stanza
            saslStatus = SASLAuthentication.handle(session, doc);
            处理。
           
       

最简单的当属PLAIN方式(base64编码)

    
           
         SASLAuthentication 解码base64码  
         token = StringUtils.decodeBase64(doc.getText().trim());
        
        
        
  SaslServerPlainImpl    PLAIN码的验证  
    public byte[] evaluateResponse(byte[] response)
        throws SaslException {
        if (completed) {
            throw new IllegalStateException("PLAIN authentication already completed");
        }
        if (aborted) {
            throw new IllegalStateException("PLAIN authentication previously aborted due to error");
        }
        try {
            if(response.length != 0) {
                String data = new String(response, "UTF8");
                StringTokenizer tokens = new StringTokenizer(data, "");
                if (tokens.countTokens() > 2) {
                    username = tokens.nextToken();
                    principal = tokens.nextToken();
                } else {
                    username = tokens.nextToken();
                    principal = username;
                }
                password = tokens.nextToken();
                NameCallback ncb = new NameCallback("PLAIN authentication ID: ",principal);
                VerifyPasswordCallback vpcb = new VerifyPasswordCallback(password.toCharArray());
                cbh.handle(new Callback[]{ncb,vpcb});

                if (vpcb.getVerified()) {
                    vpcb.clearPassword();
                

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值