摘要认证 调整测试

This commit is contained in:
shikong 2023-09-26 14:41:15 +08:00
parent b1d3d2d235
commit fd87512758
2 changed files with 15 additions and 3 deletions

View File

@ -2,12 +2,15 @@ package cn.skcks.docking.gb28181.sip.request;
import cn.skcks.docking.gb28181.sip.generic.SipBuilder;
import cn.skcks.docking.gb28181.sip.generic.SipRequestBuilder;
import cn.skcks.docking.gb28181.sip.utils.DigestAuthenticationHelper;
import cn.skcks.docking.gb28181.sip.utils.SipUtil;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import javax.sip.address.Address;
import javax.sip.address.SipURI;
import javax.sip.header.AuthorizationHeader;
import javax.sip.header.WWWAuthenticateHeader;
import javax.sip.message.Request;
@AllArgsConstructor
@ -23,18 +26,27 @@ public class RegisterRequestBuilder {
private String transport;
public Request createNoAuthorizationRequest(String callId) {
public Request createNoAuthorizationRequest(String callId, int expires) {
String local = SipBuilder.createHostAddress(localIp, localPort);
Address localAddress = SipBuilder.createAddress(SipBuilder.createSipURI(localId, local));
String target = SipBuilder.createHostAddress(targetIp, targetPort);
SipURI targetUri = SipBuilder.createSipURI(targetId, target);
return SipRequestBuilder.createRequest(targetUri, method,
Request request = SipRequestBuilder.createRequest(targetUri, method,
SipBuilder.createCallIdHeader(callId),
SipBuilder.createCSeqHeader(1L, method),
SipBuilder.createFromHeader(localAddress, SipUtil.generateFromTag()),
SipBuilder.createToHeader(localAddress),
SipBuilder.createViaHeaders(targetIp, targetPort, transport, SipUtil.generateViaTag()),
SipBuilder.createMaxForwardsHeader(70));
request.addHeader(SipBuilder.createExpiresHeader(expires));
return request;
}
public Request createNoAuthorizationRequest(String callId, int expires, String id, String passwd, WWWAuthenticateHeader wwwAuthenticateHeader) {
Request request = createNoAuthorizationRequest(callId, expires);
AuthorizationHeader authorization = DigestAuthenticationHelper.createAuthorization(method, targetIp, targetPort, targetId, id, passwd, wwwAuthenticateHeader);
request.addHeader(authorization);
return request;
}
}

View File

@ -43,7 +43,7 @@ public class RequestTest {
String callId = sipProvider.getNewCallId().getCallId();
RegisterRequestBuilder registerRequestBuilder = new RegisterRequestBuilder(localIp, localPort, localId, remoteIp, remotePort, remoteId, ListeningPoint.UDP);
Request noAuthorizationRequest = registerRequestBuilder.createNoAuthorizationRequest(callId);
Request noAuthorizationRequest = registerRequestBuilder.createNoAuthorizationRequest(callId, 3600);
log.info("\n{}",noAuthorizationRequest);
sipStack.deleteSipProvider(sipProvider);
sipStack.deleteListeningPoint(listeningPoint);