Jan Gabriel Kunze 5 years ago
parent
commit
5b508a11ca
4 changed files with 114 additions and 70 deletions
  1. 0
    19
      src/model/SIP.java
  2. 2
    2
      src/model/SIPRegister.java
  3. 102
    0
      src/model/SIPUnauthReq.java
  4. 10
    49
      src/model/SIPmodel.java

+ 0
- 19
src/model/SIP.java View File

@@ -1,19 +0,0 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

package model;

/**
*
* @author Jan
*/
public class SIP
{
public SIP()
{

}
}

+ 2
- 2
src/model/SIPRegister.java View File

@@ -31,9 +31,9 @@ import logger.OhmLogger;
*/
public class SIPRegister
{
private static final Logger lgRegister = OhmLogger.getLogger();
private Request request;

private static final Logger lgRegister = OhmLogger.getLogger();
public SIPRegister(String proxyAddress, String myTag, String myIPAddress, int myPort,
int branch, AddressFactory addressFactory, HeaderFactory headerFactory,
MessageFactory messageFactory, ContactHeader contactHeader, CallIdHeader callID)

+ 102
- 0
src/model/SIPUnauthReq.java View File

@@ -0,0 +1,102 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package model;

import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sip.ResponseEvent;
import javax.sip.address.Address;
import javax.sip.address.AddressFactory;
import javax.sip.address.URI;
import javax.sip.header.AllowHeader;
import javax.sip.header.AuthorizationHeader;
import javax.sip.header.CSeqHeader;
import javax.sip.header.CallIdHeader;
import javax.sip.header.ContactHeader;
import javax.sip.header.ExpiresHeader;
import javax.sip.header.FromHeader;
import javax.sip.header.HeaderFactory;
import javax.sip.header.MaxForwardsHeader;
import javax.sip.header.ToHeader;
import javax.sip.header.ViaHeader;
import javax.sip.header.WWWAuthenticateHeader;
import javax.sip.message.MessageFactory;
import javax.sip.message.Request;
import logger.OhmLogger;

/**
* Erstellt den Header auf eine Unauthorized Request vom SIP Server nach erstem
* Versuch der Anmeldung. Es sind immer 2 "Anmeldungen" nötig um sich zu registrieren!!
*
* @author Jan
*/
public class SIPUnauthReq
{
private Request unauthReq;
private static final Logger lgUnauth = OhmLogger.getLogger();

public SIPUnauthReq(String myName, String proxyAddress, String myTag,
String myIPAddress,
int branch, long cseq, int myPort,
ContactHeader contactHeader,
AddressFactory addressFactory, HeaderFactory headerFactory,
ResponseEvent responseEvent, MessageFactory messageFactory)
{
try
{
Address addresstob = addressFactory.createAddress("sip:" + myName + "@" + proxyAddress);
ToHeader temp = (ToHeader) responseEvent.getResponse().getHeader("To");

ToHeader to = headerFactory.createToHeader(addresstob, temp.getTag()); // Integer.toString(myTag) address + myTag
URI requestURI = addresstob.getURI();
CallIdHeader callId = (CallIdHeader) responseEvent.getResponse().getHeader("Call-ID");
FromHeader from = headerFactory.createFromHeader(addresstob, myTag); //this.contactAddress
WWWAuthenticateHeader wwwauth = (WWWAuthenticateHeader) responseEvent.getResponse().getHeader("WWW-Authenticate");

//wird bei AuthorizationHeader wirklich alles benötigt? war glaub nur mal Test -> testen!!
AuthorizationHeader auth = headerFactory.createAuthorizationHeader("Digest");//was kommt in den string
auth.setRealm(wwwauth.getRealm());
auth.setNonce(wwwauth.getNonce());
//Address addresstest = this.addressFactory.createAddress("sip:" + myName + "@192.168.100.11"); //vielleicht passwort setzen "sip:"+myName+":\"\"@192.168.100.11"
Address addresstest = addressFactory.createAddress("sip:" + myName + "@" + proxyAddress);
auth.setURI(addresstest.getURI());
auth.setUsername(myName);

ArrayList via = new ArrayList(); //Via needs a List as input
ViaHeader viaheader = headerFactory.createViaHeader(myIPAddress, myPort, "UDP", String.valueOf(branch + 2));// String.valueOf(hashCode())string branch
via.add(viaheader);

CSeqHeader cSeq = headerFactory.createCSeqHeader(cseq, "REGISTER");
MaxForwardsHeader maxForwards = headerFactory.createMaxForwardsHeader(70);
AllowHeader allow = headerFactory.createAllowHeader("NOTIFY,INVITE,ACK,CANCEL,BYE,REFER,INFO,OPTIONS,MESSAGE");
ExpiresHeader expire = headerFactory.createExpiresHeader(3600); //int value

//Zusätzliche Register Header nach Unauthorzied
//Create Request Header
unauthReq = messageFactory.createRequest(requestURI, "REGISTER", callId, cSeq, from, to, via, maxForwards);
unauthReq.addHeader(contactHeader);
unauthReq.addHeader(allow);
unauthReq.addHeader(expire);
unauthReq.addHeader(auth);

lgUnauth.info("Request Header für 2 Registrierung erstellt");
}
catch (Exception ex)
{
lgUnauth.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex);
}

}

/**
* @return the unauthReq
*/
public Request getUnauthReq()
{
return unauthReq;
}
}

+ 10
- 49
src/model/SIPmodel.java View File

@@ -63,12 +63,12 @@ public class SIPmodel implements SipListenerExt
Boolean werdeAngerufen;
private int countWerdeAngerufen;

public long cSequenz = 1;
private long cSequenz = 1;
private String proxyTag;
private String myTag = String.valueOf(new Random().nextInt());
private int branch = Integer.valueOf(hashCode());
public Address contactAddress;
public ContactHeader contactHeader;
private Address contactAddress;
private ContactHeader contactHeader;

public SIPmodel(Hauptfenster view) //Konstruktor für eigene Daten
{
@@ -96,7 +96,6 @@ public class SIPmodel implements SipListenerExt
this.listeningPoint = this.sipStack.createListeningPoint(this.myIPAddress, this.myPort, this.protocolTyp);
this.sipProvider = this.sipStack.createSipProvider(this.listeningPoint);
this.sipProvider.addSipListener(this);
//this.contactAddress = this.addressFactory.createAddress("sip:129@" + this.myIPAddress + ":" + this.myPort); //+ ":" + this.myPort
this.contactAddress = this.addressFactory.createAddress("sip:" + myName + "@" + this.myIPAddress + ":" + this.myPort);
this.contactHeader = this.headerFactory.createContactHeader(contactAddress);
}
@@ -221,51 +220,17 @@ public class SIPmodel implements SipListenerExt
@Override
public void processResponse(ResponseEvent responseEvent)
{
System.out.println("---Response---");
//System.out.println(responseEvent.getResponse());

if (responseEvent.getResponse().getStatusCode() == Response.UNAUTHORIZED)
{
try
{
Address addresstob = this.addressFactory.createAddress("sip:" + myName + "@" + proxyAddress);
ToHeader temp = (ToHeader) responseEvent.getResponse().getHeader("To");

ToHeader to = this.headerFactory.createToHeader(addresstob, temp.getTag()); // Integer.toString(myTag) address + myTag
URI requestURI = addresstob.getURI();
CallIdHeader callId = (CallIdHeader) responseEvent.getResponse().getHeader("Call-ID");
FromHeader from = this.headerFactory.createFromHeader(addresstob, this.myTag); //this.contactAddress
WWWAuthenticateHeader wwwauth = (WWWAuthenticateHeader) responseEvent.getResponse().getHeader("WWW-Authenticate");

//wird bei AuthorizationHeader wirklich alles benötigt? war glaub nur mal Test -> testen!!
AuthorizationHeader auth = this.headerFactory.createAuthorizationHeader("Digest");//was kommt in den string
auth.setRealm(wwwauth.getRealm());
auth.setNonce(wwwauth.getNonce());
//Address addresstest = this.addressFactory.createAddress("sip:" + myName + "@192.168.100.11"); //vielleicht passwort setzen "sip:"+myName+":\"\"@192.168.100.11"
Address addresstest = this.addressFactory.createAddress("sip:" + myName + "@" + proxyAddress);
auth.setURI(addresstest.getURI());
auth.setUsername(myName);

ArrayList via = new ArrayList(); //Via needs a List as input
ViaHeader viaheader = this.headerFactory.createViaHeader(this.myIPAddress, this.myPort, "UDP", String.valueOf(branch + 2));// String.valueOf(hashCode())string branch
via.add(viaheader);

CSeqHeader cSeq = this.headerFactory.createCSeqHeader(2L, "REGISTER");
MaxForwardsHeader maxForwards = this.headerFactory.createMaxForwardsHeader(70);
AllowHeader allow = this.headerFactory.createAllowHeader("NOTIFY,INVITE,ACK,CANCEL,BYE,REFER,INFO,OPTIONS,MESSAGE");
ExpiresHeader expire = this.headerFactory.createExpiresHeader(3600); //int value

//Zusätzliche Register Header nach Unauthorzied
//Create Request Header
Request request = this.messageFactory.createRequest(requestURI, "REGISTER", callId, cSeq, from, to, via, maxForwards);
request.addHeader(contactHeader);
request.addHeader(allow);
request.addHeader(expire);
request.addHeader(auth);
this.sipProvider.sendRequest(request);
cSequenz += 1L;
branch += 10;
SIPUnauthReq req2 = new SIPUnauthReq(myName, proxyAddress, myTag, myIPAddress, branch, cSequenz, myPort, contactHeader, addressFactory, headerFactory, responseEvent, messageFactory);
sipProvider.sendRequest(req2.getUnauthReq());
view.getTxtArea().append("Erfolgreich registriert\n");
}
catch (ParseException | SipException | InvalidArgumentException ex)
catch (SipException ex)
{
lg.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex);
}
@@ -288,7 +253,6 @@ public class SIPmodel implements SipListenerExt

public Response create180Ringing(RequestEvent requestEvent) throws ParseException, SipException
{
Response responsering = this.messageFactory.createResponse(180, requestEvent.getRequest());
responsering.addHeader((ViaHeader) requestEvent.getRequest().getHeader("Via"));
responsering.addHeader((FromHeader) requestEvent.getRequest().getHeader("From"));
@@ -326,14 +290,12 @@ public class SIPmodel implements SipListenerExt
view.getTxtArea().append("Trying geschickt\n");
lg.info("Trying ist raus");

//Ringing Message to Server (Responste Ringing)From tag: proxyTag, To Tag, persönlicher Tag
//Ringing Header erzeugen und abschicken From tag: proxyTag; To Tag: persönlicher Tag
SIP180Ringing tempRinging = new SIP180Ringing(requestEvent, myTag, proxyTag, contactHeader, headerFactory);
sipProvider.sendResponse(tempRinging.getResponseRing());
view.getTxtArea().append("Ringing geschickt\n");

//Jetzt kommt 200 Ok SIP Header + SDP (SIP/SDP)
//Sdp Header erstellen nächster Schritt
//200OK Header mit Session Description erstellen
invite = false;
SIP200Ok respcall = new SIP200Ok(messageFactory, requestEvent, contactHeader, headerFactory);
SIPSessionDescription sdp = new SIPSessionDescription(myName, myIPAddress, requestEvent, false);
@@ -346,7 +308,6 @@ public class SIPmodel implements SipListenerExt
catch (SipException ex)
{
Logger.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex);

}
}
else

Loading…
Cancel
Save