openbmc中关于invalid authentication algorithm问题

2 篇文章 0 订阅
1 篇文章 0 订阅

ipmitool工具

当在使用ipmitool进行链接openbmc设备时,某些版本的ipmitool会进行报错,内容为:Error in open session response message : invalid authentication algorithm。此问题为ipmitool版本过低,下载一个高版本ipmitool就可以解决。详情可以参考以下链接中的内容:

https://bugs.centos.org/view.php?id=17653

非ipmitool工具

当我们其他版本的工具来链接openbmc设备时,invalid authentication algorithm问题可能依旧会发生,或者说大概率会发生:)。此时我们需要分析源代码和ipmi协议来进行更改解决这个问题。为此,我们需要以下代码和工具:

1-phosphor-ipmi-net
2-wireshark
3-ipmi-second-gen-interface-spec-v2-rev1-1手册

我们先开宗明义的说明该问题出现的具体原因以及解决方法,再进行详细介绍该问题定位的方法。

问题的原因

(csdn传入图片一直失败,奇怪!)
在ipmi协议手册第318页,介绍了authentication algorithm、integrity algorithm、confidentiality algorithm三种类型共20中情况的算法组合。openbmc和类ipmitool工具必须要包含同一种算法组合,双方才可以验证成功。openbmc端只支持编号为17的算法组合(RAKP_HMAC_SHA256 + HMAC_SHA256_128 + AES_CBC_128)。类ipmitool工具支持什么类型的算法组合,需要参考问题定位

问题解决方法

在phosphor-ipmi-net工程下,open_session.cpp文件中,openSession函数里,进行修改如何内容:
修改authentication algorithm算法认证:

if (!cipher::rakp_auth::Interface::isAlgorithmSupported(
        static_cast<cipher::rakp_auth::Algorithms>(request->authAlgo)))
{
    response->status_code =
        static_cast<uint8_t>(RAKP_ReturnCode::INVALID_AUTH_ALGO);
    return outPayload;
}

在函数isAlgorithmSupported中,添加所需的算法内容即可:

static bool isAlgorithmSupported(Algorithms algo)
{
    if (algo == Algorithms::RAKP_HMAC_SHA256)
    {
        return true;
    }
    else
    {
        return false;
    }
}

修改integrity algorithm算法认证:

if (!cipher::integrity::Interface::isAlgorithmSupported(
        static_cast<cipher::integrity::Algorithms>(request->intAlgo)))
{
    response->status_code =
        static_cast<uint8_t>(RAKP_ReturnCode::INVALID_INTEGRITY_ALGO);
    return outPayload;
}

修改confidentiality algorithm算法认证:

if (!cipher::crypt::Interface::isAlgorithmSupported(
        static_cast<cipher::crypt::Algorithms>(request->confAlgo)))
{
    response->status_code =
        static_cast<uint8_t>(RAKP_ReturnCode::INVALID_CONF_ALGO);
    return outPayload;
}

问题如何定位

这个时候就需要用到wireshark,我们需要进行抓取通信的报文(图片无法上传。。。)
发送至openbmc设备的报文:
00 00 00 00 49 4d 50 49
00 00 00 08 01 00 00 00
01 00 00 08 01 00 00 00
02 00 00 08 01 00 00 00(此为数据区域的32字节)
我们可以在ipmi 手册13.17小节中找到该字段的介绍,第十三个字节的0::5为authentication algorithm,第二十一字节的0::5字节为integrity algorithm,第二十九字节的0::5为confidentiality algorithm。

openbmc设备发送出去的报文:
00 04 00 00 49 4d 50 49
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00
我们可以在ipmi手册13.18小节中找到该字段的介绍,第二字节为错误码介绍,可以看到标号为04,错误类型为invalid authentication algorithm.

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
在 Spring Boot 结合 Spring Security 场景,使用 JWT 生成 token 并存放在 MySQL ,可以按照以下步骤进行: 1. 添加 JWT 依赖:在 pom.xml 文件添加以下依赖: ```xml <dependency> <groupId>io.jsonwebtoken</groupId> <artifactId>jjwt</artifactId> <version>0.9.1</version> </dependency> ``` 2. 编写 JWT 工具类:编写 JWT 工具类,实现 JWT 的生成、解析和验证等功能,示例代码如下: ```java import io.jsonwebtoken.Claims; import io.jsonwebtoken.Jwts; import io.jsonwebtoken.SignatureAlgorithm; import java.util.Date; import java.util.HashMap; import java.util.Map; public class JwtUtils { private static final String SECRET_KEY = "secret_key"; // 密钥 private static final long EXPIRATION_TIME = 86400000; // 过期时间(24小时) // 生成 token public static String generateToken(String username) { Map<String, Object> claims = new HashMap<>(); claims.put("username", username); return Jwts.builder() .setClaims(claims) .setExpiration(new Date(System.currentTimeMillis() + EXPIRATION_TIME)) .signWith(SignatureAlgorithm.HS512, SECRET_KEY) .compact(); } // 解析 token public static Claims parseToken(String token) { return Jwts.parser() .setSigningKey(SECRET_KEY) .parseClaimsJws(token) .getBody(); } // 验证 token public static boolean validateToken(String token) { try { Jwts.parser().setSigningKey(SECRET_KEY).parseClaimsJws(token); return true; } catch (Exception e) { return false; } } } ``` 3. 编写登录接口:在登录接口,使用 JWT 工具类生成 token 并存储到 MySQL 数据库,示例代码如下: ```java import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; import org.springframework.security.core.AuthenticationException; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; @RestController public class LoginController { @Autowired private AuthenticationManager authenticationManager; @Autowired private UserDetailsService userDetailsService; @Autowired private PasswordEncoder passwordEncoder; @Autowired private UserRepository userRepository; // 登录接口 @PostMapping("/login") public ApiResponse login(@RequestBody LoginRequest loginRequest) { try { // 认证用户信息 Authentication authentication = authenticationManager.authenticate( new UsernamePasswordAuthenticationToken(loginRequest.getUsername(), loginRequest.getPassword())); UserDetails userDetails = (UserDetails) authentication.getPrincipal(); // 生成 token 并存储到数据库 String token = JwtUtils.generateToken(userDetails.getUsername()); User user = userRepository.findByUsername(userDetails.getUsername()); user.setToken(token); userRepository.save(user); return ApiResponse.success(user); } catch (AuthenticationException e) { return ApiResponse.fail("Invalid username or password"); } } } ``` 在上面的示例,首先通过 AuthenticationManager 认证用户信息,然后使用 JwtUtils 工具类生成 token,并将 token 存储到数据库。 4. 编写请求拦截器:在请求拦截器,从请求头获取 token,并使用 JwtUtils 工具类验证 token 的有效性,示例代码如下: ```java import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.AuthenticationException; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.stereotype.Component; import org.springframework.web.servlet.HandlerInterceptor; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @Component public class JwtInterceptor implements HandlerInterceptor { @Autowired private UserDetailsService userDetailsService; // 在请求到达之前拦截请求 @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { String token = request.getHeader("Authorization"); if (token != null && token.startsWith("Bearer ")) { token = token.substring(7); if (JwtUtils.validateToken(token)) { String username = JwtUtils.parseToken(token).get("username").toString(); UserDetails userDetails = userDetailsService.loadUserByUsername(username); JwtAuthenticationToken authenticationToken = new JwtAuthenticationToken(userDetails, null, userDetails.getAuthorities()); authenticationToken.setToken(token); SecurityContextHolder.getContext().setAuthentication(authenticationToken); return true; } } throw new AuthenticationException("Invalid token"); } } ``` 在上面的示例,首先从请求头获取 token,并使用 JwtUtils 工具类验证 token 的有效性,如果 token 有效,则将用户信息保存在 SecurityContextHolder ,后续的请求处理会使用这些信息进行身份验证。 通过以上步骤,就可以在 Spring Boot 结合 Spring Security 场景,使用 JWT 生成 token 并存放在 MySQL 。需要注意的是,存储 token 的表需要包含用户 ID 和 token 字段,以便后续通过用户 ID 查找 token。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值