摘要认证 调整

This commit is contained in:
shikong 2023-09-26 14:33:04 +08:00
parent 84cab3441f
commit b1d3d2d235
2 changed files with 5 additions and 5 deletions

View File

@ -220,7 +220,7 @@ public class DigestAuthenticationHelper {
} }
@SneakyThrows @SneakyThrows
public static AuthorizationHeader createAuthorization(String serverIp, int serverPort, String serverId, String deviceId,String password, WWWAuthenticateHeader www){ public static AuthorizationHeader createAuthorization(String method,String serverIp, int serverPort, String serverId, String deviceId,String password, WWWAuthenticateHeader www){
String hostAddress = SipBuilder.createHostAddress(serverIp, serverPort); String hostAddress = SipBuilder.createHostAddress(serverIp, serverPort);
SipURI sipURI = SipBuilder.createSipURI(serverId, hostAddress); SipURI sipURI = SipBuilder.createSipURI(serverId, hostAddress);
if (www == null) { if (www == null) {
@ -249,7 +249,7 @@ public class DigestAuthenticationHelper {
} }
} }
String HA1 = DigestUtil.md5Hex((deviceId + ":" + realm + ":" + password).getBytes()); String HA1 = DigestUtil.md5Hex((deviceId + ":" + realm + ":" + password).getBytes());
String HA2= DigestUtil.md5Hex((Request.REGISTER + ":" + sipURI.toString()).getBytes()); String HA2= DigestUtil.md5Hex((method.toUpperCase() + ":" + sipURI.toString()).getBytes());
StringBuilder reStr = new StringBuilder(); StringBuilder reStr = new StringBuilder();
reStr.append(HA1); reStr.append(HA1);

View File

@ -17,17 +17,17 @@ public class AuthenticationTest {
@Test @Test
void test() { void test() {
AuthorizationHeader authorization = DigestAuthenticationHelper.createAuthorization(serverIp, serverPort, serverId, deviceId, "123456",null); AuthorizationHeader authorization = DigestAuthenticationHelper.createAuthorization(Request.REGISTER, serverIp, serverPort, serverId, deviceId, "123456", null);
log.info("\n{}", authorization); log.info("\n{}", authorization);
WWWAuthenticateHeader wwwAuthenticateHeader = DigestAuthenticationHelper.generateChallenge(domain); WWWAuthenticateHeader wwwAuthenticateHeader = DigestAuthenticationHelper.generateChallenge(domain);
log.info("\n{}", wwwAuthenticateHeader); log.info("\n{}", wwwAuthenticateHeader);
authorization = DigestAuthenticationHelper.createAuthorization(serverIp, serverPort, serverId, deviceId, "123456",wwwAuthenticateHeader); authorization = DigestAuthenticationHelper.createAuthorization(Request.REGISTER, serverIp, serverPort, serverId, deviceId, "123456", wwwAuthenticateHeader);
log.info("\n{}", authorization); log.info("\n{}", authorization);
boolean passed = DigestAuthenticationHelper.doAuthenticatePlainTextPassword(Request.REGISTER, authorization, "123456"); boolean passed = DigestAuthenticationHelper.doAuthenticatePlainTextPassword(Request.REGISTER, authorization, "123456");
log.info("authorization passed {}",passed); log.info("authorization passed {}", passed);
} }
} }