Normalize line endings

See also #227
sip-call-params
Ingo Bauersachs 11 years ago
parent 577d850a0a
commit be0540e2b7

@ -1,180 +1,180 @@
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Copyright @ 2015 Atlassian Pty Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.java.sip.communicator.impl.protocol.sip.net;
import static net.java.sip.communicator.service.protocol.ProtocolProviderFactory.PROXY_AUTO_CONFIG;
import java.net.*;
import java.util.*;
import net.java.sip.communicator.impl.protocol.sip.*;
import net.java.sip.communicator.service.dns.*;
/**
* Abstract class for the determining the address for the SIP proxy.
*
* @author Ingo Bauersachs
*/
public abstract class ProxyConnection
{
private List<String> returnedAddresses = new LinkedList<String>();
protected String transport;
protected InetSocketAddress socketAddress;
protected final SipAccountIDImpl account;
/**
* Creates a new instance of this class.
* @param account the account of this SIP protocol instance
*/
protected ProxyConnection(SipAccountIDImpl account)
{
this.account = account;
}
/**
* Gets the address to use for the next connection attempt.
* @return the address of the last lookup.
*/
public final InetSocketAddress getAddress()
{
return socketAddress;
}
/**
* Gets the transport to use for the next connection attempt.
* @return the transport of the last lookup.
*/
public final String getTransport()
{
return transport;
}
/**
* In case we are using an outbound proxy this method returns
* a suitable string for use with Router.
* The method returns <tt>null</tt> otherwise.
*
* @return the string of our outbound proxy if we are using one and
* <tt>null</tt> otherwise.
*/
public final String getOutboundProxyString()
{
if(socketAddress == null)
return null;
InetAddress proxyAddress = socketAddress.getAddress();
StringBuilder proxyStringBuffer
= new StringBuilder(proxyAddress.getHostAddress());
if(proxyAddress instanceof Inet6Address)
{
proxyStringBuffer.insert(0, '[');
proxyStringBuffer.append(']');
}
proxyStringBuffer.append(':');
proxyStringBuffer.append(socketAddress.getPort());
proxyStringBuffer.append('/');
proxyStringBuffer.append(transport);
return proxyStringBuffer.toString();
}
/**
* Compares an InetAddress against the active outbound proxy. The comparison
* is by reference, not equals.
*
* @param addressToTest The addres to test.
* @return True when the InetAddress is the same as the outbound proxy.
*/
public final boolean isSameInetAddress(InetAddress addressToTest)
{
// if the proxy is not yet initialized then this is not the provider
// that caused this comparison
if(socketAddress == null)
return false;
return addressToTest == socketAddress.getAddress();
}
/**
* Retrieves the next address to use from DNS. Duplicate results are
* suppressed.
*
* @return True if a new address is available through {@link #getAddress()},
* false if the last address was reached. A new lookup from scratch
* can be started by calling {@link #reset()}.
* @throws DnssecException if there is a problem related to DNSSEC
*/
public final boolean getNextAddress() throws DnssecException
{
boolean result;
String key = null;
do
{
result = getNextAddressFromDns();
if(result && socketAddress != null)
{
key = getOutboundProxyString();
if(!returnedAddresses.contains(key))
{
returnedAddresses.add(key);
break;
}
}
}
while(result && returnedAddresses.contains(key));
return result;
}
/**
* Implementations must use this method to get the next address, but do not
* have to care about duplicate addresses.
*
* @return True when a further address was available.
* @throws DnssecException when a DNSSEC validation failure occured.
*/
protected abstract boolean getNextAddressFromDns()
throws DnssecException;
/**
* Resets the lookup to it's initial state. Overriders methods have to call
* this method through a super-call.
*/
public void reset()
{
returnedAddresses.clear();
}
/**
* Factory method to create a proxy connection based on the account settings
* of the protocol provider.
*
* @param pps the protocol provider that needs a SIP server connection.
* @return An instance of a derived class.
*/
public static ProxyConnection create(ProtocolProviderServiceSipImpl pps)
{
if (pps.getAccountID().getAccountPropertyBoolean(PROXY_AUTO_CONFIG,
true))
return new AutoProxyConnection((SipAccountIDImpl) pps.getAccountID(),
pps.getDefaultTransport());
else
return new ManualProxyConnection((SipAccountIDImpl) pps.getAccountID());
}
}
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Copyright @ 2015 Atlassian Pty Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.java.sip.communicator.impl.protocol.sip.net;
import static net.java.sip.communicator.service.protocol.ProtocolProviderFactory.PROXY_AUTO_CONFIG;
import java.net.*;
import java.util.*;
import net.java.sip.communicator.impl.protocol.sip.*;
import net.java.sip.communicator.service.dns.*;
/**
* Abstract class for the determining the address for the SIP proxy.
*
* @author Ingo Bauersachs
*/
public abstract class ProxyConnection
{
private List<String> returnedAddresses = new LinkedList<String>();
protected String transport;
protected InetSocketAddress socketAddress;
protected final SipAccountIDImpl account;
/**
* Creates a new instance of this class.
* @param account the account of this SIP protocol instance
*/
protected ProxyConnection(SipAccountIDImpl account)
{
this.account = account;
}
/**
* Gets the address to use for the next connection attempt.
* @return the address of the last lookup.
*/
public final InetSocketAddress getAddress()
{
return socketAddress;
}
/**
* Gets the transport to use for the next connection attempt.
* @return the transport of the last lookup.
*/
public final String getTransport()
{
return transport;
}
/**
* In case we are using an outbound proxy this method returns
* a suitable string for use with Router.
* The method returns <tt>null</tt> otherwise.
*
* @return the string of our outbound proxy if we are using one and
* <tt>null</tt> otherwise.
*/
public final String getOutboundProxyString()
{
if(socketAddress == null)
return null;
InetAddress proxyAddress = socketAddress.getAddress();
StringBuilder proxyStringBuffer
= new StringBuilder(proxyAddress.getHostAddress());
if(proxyAddress instanceof Inet6Address)
{
proxyStringBuffer.insert(0, '[');
proxyStringBuffer.append(']');
}
proxyStringBuffer.append(':');
proxyStringBuffer.append(socketAddress.getPort());
proxyStringBuffer.append('/');
proxyStringBuffer.append(transport);
return proxyStringBuffer.toString();
}
/**
* Compares an InetAddress against the active outbound proxy. The comparison
* is by reference, not equals.
*
* @param addressToTest The addres to test.
* @return True when the InetAddress is the same as the outbound proxy.
*/
public final boolean isSameInetAddress(InetAddress addressToTest)
{
// if the proxy is not yet initialized then this is not the provider
// that caused this comparison
if(socketAddress == null)
return false;
return addressToTest == socketAddress.getAddress();
}
/**
* Retrieves the next address to use from DNS. Duplicate results are
* suppressed.
*
* @return True if a new address is available through {@link #getAddress()},
* false if the last address was reached. A new lookup from scratch
* can be started by calling {@link #reset()}.
* @throws DnssecException if there is a problem related to DNSSEC
*/
public final boolean getNextAddress() throws DnssecException
{
boolean result;
String key = null;
do
{
result = getNextAddressFromDns();
if(result && socketAddress != null)
{
key = getOutboundProxyString();
if(!returnedAddresses.contains(key))
{
returnedAddresses.add(key);
break;
}
}
}
while(result && returnedAddresses.contains(key));
return result;
}
/**
* Implementations must use this method to get the next address, but do not
* have to care about duplicate addresses.
*
* @return True when a further address was available.
* @throws DnssecException when a DNSSEC validation failure occured.
*/
protected abstract boolean getNextAddressFromDns()
throws DnssecException;
/**
* Resets the lookup to it's initial state. Overriders methods have to call
* this method through a super-call.
*/
public void reset()
{
returnedAddresses.clear();
}
/**
* Factory method to create a proxy connection based on the account settings
* of the protocol provider.
*
* @param pps the protocol provider that needs a SIP server connection.
* @return An instance of a derived class.
*/
public static ProxyConnection create(ProtocolProviderServiceSipImpl pps)
{
if (pps.getAccountID().getAccountPropertyBoolean(PROXY_AUTO_CONFIG,
true))
return new AutoProxyConnection((SipAccountIDImpl) pps.getAccountID(),
pps.getDefaultTransport());
else
return new ManualProxyConnection((SipAccountIDImpl) pps.getAccountID());
}
}

@ -1,4 +1,4 @@
/*
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Copyright @ 2015 Atlassian Pty Ltd
@ -15,211 +15,211 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.java.sip.communicator.impl.protocol.sip.net;
import java.security.cert.*;
import java.text.*;
import java.util.*;
import java.util.regex.*;
import javax.sip.address.*;
import net.java.sip.communicator.impl.protocol.sip.*;
import net.java.sip.communicator.service.certificate.*;
import net.java.sip.communicator.util.*;
/**
* Matcher that extracts certificate identities according to <a
* href="http://tools.ietf.org/html/rfc5922#section-7.1">RFC5922, Section
* 7.1</a> and compares them with the rules from Section 7.2 and 7.3.
* @see #PNAME_STRICT_RFC5922 for wildcard handling; the default is false
*
* @author Ingo Bauersachs
*/
public class RFC5922Matcher
implements CertificateMatcher
{
/**
* When set to true, enables strict validation of the hostname according to
* <a href="http://tools.ietf.org/html/rfc5922#section-7.2">RFC5922 Section
* 7.2</a>
*/
public final static String PNAME_STRICT_RFC5922 =
"net.java.sip.communicator.sip.tls.STRICT_RFC5922";
private ProtocolProviderServiceSipImpl provider;
/**
* Creates a new instance of this class.
* @param provider The SIP Provider to which this matcher belongs.
*/
public RFC5922Matcher(ProtocolProviderServiceSipImpl provider)
{
this.provider = provider;
}
/** Our class logger. */
private static final Logger logger = Logger
.getLogger(CertificateMatcher.class);
/*
* (non-Javadoc)
*
* @see
* net.java.sip.communicator.service.certificate.CertificateMatcher#verify
* (java.lang.Iterable, java.security.cert.X509Certificate)
*/
public void verify(Iterable<String> identitiesToTest, X509Certificate cert)
throws CertificateException
{
boolean strict = SipActivator.getConfigurationService()
.getBoolean(PNAME_STRICT_RFC5922, false);
// if any of the identities is contained in the certificate we're good
boolean oneMatched = false;
Iterable<String> certIdentities = extractCertIdentities(cert);
for (String identity : identitiesToTest)
{
// check if the intended hostname is contained in one of the
// hostnames of the certificate according to
// http://tools.ietf.org/html/rfc5922#section-7.2
for(String dnsName : certIdentities)
{
try
{
if(NetworkUtils.compareDnsNames(dnsName, identity) == 0)
{
// one of the hostnames matched, we're good to go
return;
}
if(!strict
// is a wildcard name
&& dnsName.startsWith("*.")
// contains at least two dots (*.example.com)
&& identity.indexOf(".") < identity.lastIndexOf(".")
// compare *.example.com stripped to example.com with
// - foo.example.com stripped to example.com
// - foo.bar.example.com to bar.example.com
&& NetworkUtils.compareDnsNames(
dnsName.substring(2),
identity.substring(identity.indexOf(".")+1)) == 0)
{
// the wildcard matched, we're good to go
return;
}
}
catch (ParseException e)
{} // we don't care - this hostname did not match
}
}
if (!oneMatched)
throw new CertificateException("None of <" + identitiesToTest
+ "> matched by the rules of RFC5922 to the cert with CN="
+ cert.getSubjectDN());
}
private Iterable<String> extractCertIdentities(X509Certificate cert)
{
List<String> certIdentities = new ArrayList<String>();
Collection<List<?>> subjAltNames = null;
try
{
subjAltNames = cert.getSubjectAlternativeNames();
}
catch (CertificateParsingException ex)
{
logger.error("Error parsing TLS certificate", ex);
}
// subjAltName types are defined in rfc2459
final Integer dnsNameType = 2;
final Integer uriNameType = 6;
if (subjAltNames != null)
{
if (logger.isDebugEnabled())
logger.debug("found subjAltNames: " + subjAltNames);
// First look for a URI in the subjectAltName field
for (List<?> altName : subjAltNames)
{
// 0th position is the alt name type
// 1st position is the alt name data
if (altName.get(0).equals(uriNameType))
{
SipURI altNameUri;
try
{
altNameUri =
provider.getAddressFactory().createSipURI(
(String) altName.get(1));
// only sip URIs are allowed
if (!"sip".equals(altNameUri.getScheme()))
continue;
// user certificates are not allowed
if (altNameUri.getUser() != null)
continue;
String altHostName = altNameUri.getHost();
if (logger.isDebugEnabled())
{
logger.debug("found uri " + altName.get(1)
+ ", hostName " + altHostName);
}
certIdentities.add(altHostName);
}
catch (ParseException e)
{
logger.error("certificate contains invalid uri: "
+ altName.get(1));
}
}
}
// DNS An implementation MUST accept a domain name system
// identifier as a SIP domain identity if and only if no other
// identity is found that matches the "sip" URI type described
// above.
if (certIdentities.isEmpty())
{
for (List<?> altName : subjAltNames)
{
if (altName.get(0).equals(dnsNameType))
{
if (logger.isDebugEnabled())
logger.debug("found dns " + altName.get(1));
certIdentities.add(altName.get(1).toString());
}
}
}
}
else
{
// If and only if the subjectAltName does not appear in the
// certificate, the implementation MAY examine the CN field of the
// certificate. If a valid DNS name is found there, the
// implementation MAY accept this value as a SIP domain identity.
String dname = cert.getSubjectDN().getName();
String cname = "";
try
{
Pattern EXTRACT_CN =
Pattern.compile(".*CN\\s*=\\s*([\\w*\\.]+).*");
Matcher matcher = EXTRACT_CN.matcher(dname);
if (matcher.matches())
{
cname = matcher.group(1);
if (logger.isDebugEnabled())
{
logger.debug("found CN: " + cname + " from DN: "
+ dname);
}
certIdentities.add(cname);
}
}
catch (Exception ex)
{
logger.error("exception while extracting CN", ex);
}
}
return certIdentities;
}
}
package net.java.sip.communicator.impl.protocol.sip.net;
import java.security.cert.*;
import java.text.*;
import java.util.*;
import java.util.regex.*;
import javax.sip.address.*;
import net.java.sip.communicator.impl.protocol.sip.*;
import net.java.sip.communicator.service.certificate.*;
import net.java.sip.communicator.util.*;
/**
* Matcher that extracts certificate identities according to <a
* href="http://tools.ietf.org/html/rfc5922#section-7.1">RFC5922, Section
* 7.1</a> and compares them with the rules from Section 7.2 and 7.3.
* @see #PNAME_STRICT_RFC5922 for wildcard handling; the default is false
*
* @author Ingo Bauersachs
*/
public class RFC5922Matcher
implements CertificateMatcher
{
/**
* When set to true, enables strict validation of the hostname according to
* <a href="http://tools.ietf.org/html/rfc5922#section-7.2">RFC5922 Section
* 7.2</a>
*/
public final static String PNAME_STRICT_RFC5922 =
"net.java.sip.communicator.sip.tls.STRICT_RFC5922";
private ProtocolProviderServiceSipImpl provider;
/**
* Creates a new instance of this class.
* @param provider The SIP Provider to which this matcher belongs.
*/
public RFC5922Matcher(ProtocolProviderServiceSipImpl provider)
{
this.provider = provider;
}
/** Our class logger. */
private static final Logger logger = Logger
.getLogger(CertificateMatcher.class);
/*
* (non-Javadoc)
*
* @see
* net.java.sip.communicator.service.certificate.CertificateMatcher#verify
* (java.lang.Iterable, java.security.cert.X509Certificate)
*/
public void verify(Iterable<String> identitiesToTest, X509Certificate cert)
throws CertificateException
{
boolean strict = SipActivator.getConfigurationService()
.getBoolean(PNAME_STRICT_RFC5922, false);
// if any of the identities is contained in the certificate we're good
boolean oneMatched = false;
Iterable<String> certIdentities = extractCertIdentities(cert);
for (String identity : identitiesToTest)
{
// check if the intended hostname is contained in one of the
// hostnames of the certificate according to
// http://tools.ietf.org/html/rfc5922#section-7.2
for(String dnsName : certIdentities)
{
try
{
if(NetworkUtils.compareDnsNames(dnsName, identity) == 0)
{
// one of the hostnames matched, we're good to go
return;
}
if(!strict
// is a wildcard name
&& dnsName.startsWith("*.")
// contains at least two dots (*.example.com)
&& identity.indexOf(".") < identity.lastIndexOf(".")
// compare *.example.com stripped to example.com with
// - foo.example.com stripped to example.com
// - foo.bar.example.com to bar.example.com
&& NetworkUtils.compareDnsNames(
dnsName.substring(2),
identity.substring(identity.indexOf(".")+1)) == 0)
{
// the wildcard matched, we're good to go
return;
}
}
catch (ParseException e)
{} // we don't care - this hostname did not match
}
}
if (!oneMatched)
throw new CertificateException("None of <" + identitiesToTest
+ "> matched by the rules of RFC5922 to the cert with CN="
+ cert.getSubjectDN());
}
private Iterable<String> extractCertIdentities(X509Certificate cert)
{
List<String> certIdentities = new ArrayList<String>();
Collection<List<?>> subjAltNames = null;
try
{
subjAltNames = cert.getSubjectAlternativeNames();
}
catch (CertificateParsingException ex)
{
logger.error("Error parsing TLS certificate", ex);
}
// subjAltName types are defined in rfc2459
final Integer dnsNameType = 2;
final Integer uriNameType = 6;
if (subjAltNames != null)
{
if (logger.isDebugEnabled())
logger.debug("found subjAltNames: " + subjAltNames);
// First look for a URI in the subjectAltName field
for (List<?> altName : subjAltNames)
{
// 0th position is the alt name type
// 1st position is the alt name data
if (altName.get(0).equals(uriNameType))
{
SipURI altNameUri;
try
{
altNameUri =
provider.getAddressFactory().createSipURI(
(String) altName.get(1));
// only sip URIs are allowed
if (!"sip".equals(altNameUri.getScheme()))
continue;
// user certificates are not allowed
if (altNameUri.getUser() != null)
continue;
String altHostName = altNameUri.getHost();
if (logger.isDebugEnabled())
{
logger.debug("found uri " + altName.get(1)
+ ", hostName " + altHostName);
}
certIdentities.add(altHostName);
}
catch (ParseException e)
{
logger.error("certificate contains invalid uri: "
+ altName.get(1));
}
}
}
// DNS An implementation MUST accept a domain name system
// identifier as a SIP domain identity if and only if no other
// identity is found that matches the "sip" URI type described
// above.
if (certIdentities.isEmpty())
{
for (List<?> altName : subjAltNames)
{
if (altName.get(0).equals(dnsNameType))
{
if (logger.isDebugEnabled())
logger.debug("found dns " + altName.get(1));
certIdentities.add(altName.get(1).toString());
}
}
}
}
else
{
// If and only if the subjectAltName does not appear in the
// certificate, the implementation MAY examine the CN field of the
// certificate. If a valid DNS name is found there, the
// implementation MAY accept this value as a SIP domain identity.
String dname = cert.getSubjectDN().getName();
String cname = "";
try
{
Pattern EXTRACT_CN =
Pattern.compile(".*CN\\s*=\\s*([\\w*\\.]+).*");
Matcher matcher = EXTRACT_CN.matcher(dname);
if (matcher.matches())
{
cname = matcher.group(1);
if (logger.isDebugEnabled())
{
logger.debug("found CN: " + cname + " from DN: "
+ dname);
}
certIdentities.add(cname);
}
}
catch (Exception ex)
{
logger.error("exception while extracting CN", ex);
}
}
return certIdentities;
}
}

@ -1,251 +1,251 @@
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Copyright @ 2015 Atlassian Pty Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.java.sip.communicator.impl.sysactivity;
import net.java.sip.communicator.util.Logger;
import org.jitsi.util.*;
/**
* @author Damian Minkov
*/
public class SystemActivityNotifications
{
/**
* The <tt>Logger</tt> used by the <tt>SystemActivityNotifications</tt>
* class to log debugging information.
*/
private static final Logger logger
= Logger.getLogger(SystemActivityNotifications.class);
/**
* Computer display has stand by.
*/
public static final int NOTIFY_DISPLAY_SLEEP = 2;
/**
* Computer display wakes up after stand by.
*/
public static final int NOTIFY_DISPLAY_WAKE = 3;
/**
* A change in dns configuration has occurred.
*/
public static final int NOTIFY_DNS_CHANGE = 10;
/**
* All processes have been informed about ending session, now notify for
* the actual end session.
*/
public static final int NOTIFY_ENDSESSION = 12;
/**
* A change in network configuration has occurred.
*/
public static final int NOTIFY_NETWORK_CHANGE = 9;
/**
* Notifies for start of process of ending desktop session,
* logoff or shutdown.
*/
public static final int NOTIFY_QUERY_ENDSESSION = 11;
/**
* Screen has been locked.
*/
public static final int NOTIFY_SCREEN_LOCKED = 7;
/**
* Screen has been unlocked.
*/
public static final int NOTIFY_SCREEN_UNLOCKED = 8;
/**
* Screensaver has been started.
*/
public static final int NOTIFY_SCREENSAVER_START = 4;
/**
* Screensaver has been stopped.
*/
public static final int NOTIFY_SCREENSAVER_STOP = 6;
/**
* Screensaver will stop.
*/
public static final int NOTIFY_SCREENSAVER_WILL_STOP = 5;
/**
* Notify that computers is going to sleep.
*/
public static final int NOTIFY_SLEEP = 0;
/**
* Notify that computer is wakeing up after stand by.
*/
public static final int NOTIFY_WAKE = 1;
/**
* The native instance.
*/
private static long ptr;
/**
* Init native library.
*/
static
{
try
{
// Don't load native library on Android to prevent the exception
if(!org.jitsi.util.OSUtils.IS_ANDROID)
{
JNIUtils.loadLibrary("sysactivitynotifications",
SystemActivityNotifications.class.getClassLoader());
ptr = allocAndInit();
if (ptr == -1)
ptr = 0;
}
}
catch (Throwable t)
{
if (t instanceof ThreadDeath)
throw (ThreadDeath) t;
else
logger.warn("Failed to initialize native counterpart", t);
}
}
/**
* Allocate native resources and gets a pointer.
*
* @return
*/
private static native long allocAndInit();
/**
* Returns the when was last input in milliseconds. The time when there was
* any activity on the computer.
*
* @return the last input in milliseconds
*/
public static native long getLastInput();
/**
* Whether native library is loaded.
*
* @return whether native library is loaded.
*/
public static boolean isLoaded()
{
return (ptr != 0);
}
/**
* Release native resources.
*
* @param ptr
*/
private static native void release(long ptr);
/**
* Sets notifier delegate.
*
* @param ptr
* @param delegate
*/
public static native void setDelegate(
long ptr,
NotificationsDelegate delegate);
/**
* Sets delegate.
*
* @param delegate
*/
public static void setDelegate(NotificationsDelegate delegate)
{
if (ptr != 0)
setDelegate(ptr, delegate);
}
/**
* Start.
*/
public static void start()
{
if (ptr != 0)
start(ptr);
}
/**
* Start processing.
*
* @param ptr
*/
private static native void start(long ptr);
/**
* Stop.
*/
public static void stop()
{
if (ptr != 0)
{
stop(ptr);
release(ptr);
ptr = 0;
}
}
/**
* Stop processing.
*
* @param ptr
*/
private static native void stop(long ptr);
/**
* Delegate class to be notified about changes.
*/
public interface NotificationsDelegate
{
/**
* Callback method when receiving notifications.
*
* @param type
*/
public void notify(int type);
/**
* Callback method when receiving special network notifications.
*
* @param family family of network change (ipv6, ipv4)
* @param luidIndex unique index of interface
* @param name name of the interface
* @param type of the interface
* @param connected whether interface is connected or not.
*/
public void notifyNetworkChange(
int family,
long luidIndex,
String name,
long type,
boolean connected);
}
}
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Copyright @ 2015 Atlassian Pty Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.java.sip.communicator.impl.sysactivity;
import net.java.sip.communicator.util.Logger;
import org.jitsi.util.*;
/**
* @author Damian Minkov
*/
public class SystemActivityNotifications
{
/**
* The <tt>Logger</tt> used by the <tt>SystemActivityNotifications</tt>
* class to log debugging information.
*/
private static final Logger logger
= Logger.getLogger(SystemActivityNotifications.class);
/**
* Computer display has stand by.
*/
public static final int NOTIFY_DISPLAY_SLEEP = 2;
/**
* Computer display wakes up after stand by.
*/
public static final int NOTIFY_DISPLAY_WAKE = 3;
/**
* A change in dns configuration has occurred.
*/
public static final int NOTIFY_DNS_CHANGE = 10;
/**
* All processes have been informed about ending session, now notify for
* the actual end session.
*/
public static final int NOTIFY_ENDSESSION = 12;
/**
* A change in network configuration has occurred.
*/
public static final int NOTIFY_NETWORK_CHANGE = 9;
/**
* Notifies for start of process of ending desktop session,
* logoff or shutdown.
*/
public static final int NOTIFY_QUERY_ENDSESSION = 11;
/**
* Screen has been locked.
*/
public static final int NOTIFY_SCREEN_LOCKED = 7;
/**
* Screen has been unlocked.
*/
public static final int NOTIFY_SCREEN_UNLOCKED = 8;
/**
* Screensaver has been started.
*/
public static final int NOTIFY_SCREENSAVER_START = 4;
/**
* Screensaver has been stopped.
*/
public static final int NOTIFY_SCREENSAVER_STOP = 6;
/**
* Screensaver will stop.
*/
public static final int NOTIFY_SCREENSAVER_WILL_STOP = 5;
/**
* Notify that computers is going to sleep.
*/
public static final int NOTIFY_SLEEP = 0;
/**
* Notify that computer is wakeing up after stand by.
*/
public static final int NOTIFY_WAKE = 1;
/**
* The native instance.
*/
private static long ptr;
/**
* Init native library.
*/
static
{
try
{
// Don't load native library on Android to prevent the exception
if(!org.jitsi.util.OSUtils.IS_ANDROID)
{
JNIUtils.loadLibrary("sysactivitynotifications",
SystemActivityNotifications.class.getClassLoader());
ptr = allocAndInit();
if (ptr == -1)
ptr = 0;
}
}
catch (Throwable t)
{
if (t instanceof ThreadDeath)
throw (ThreadDeath) t;
else
logger.warn("Failed to initialize native counterpart", t);
}
}
/**
* Allocate native resources and gets a pointer.
*
* @return
*/
private static native long allocAndInit();
/**
* Returns the when was last input in milliseconds. The time when there was
* any activity on the computer.
*
* @return the last input in milliseconds
*/
public static native long getLastInput();
/**
* Whether native library is loaded.
*
* @return whether native library is loaded.
*/
public static boolean isLoaded()
{
return (ptr != 0);
}
/**
* Release native resources.
*
* @param ptr
*/
private static native void release(long ptr);
/**
* Sets notifier delegate.
*
* @param ptr
* @param delegate
*/
public static native void setDelegate(
long ptr,
NotificationsDelegate delegate);
/**
* Sets delegate.
*
* @param delegate
*/
public static void setDelegate(NotificationsDelegate delegate)
{
if (ptr != 0)
setDelegate(ptr, delegate);
}
/**
* Start.
*/
public static void start()
{
if (ptr != 0)
start(ptr);
}
/**
* Start processing.
*
* @param ptr
*/
private static native void start(long ptr);
/**
* Stop.
*/
public static void stop()
{
if (ptr != 0)
{
stop(ptr);
release(ptr);
ptr = 0;
}
}
/**
* Stop processing.
*
* @param ptr
*/
private static native void stop(long ptr);
/**
* Delegate class to be notified about changes.
*/
public interface NotificationsDelegate
{
/**
* Callback method when receiving notifications.
*
* @param type
*/
public void notify(int type);
/**
* Callback method when receiving special network notifications.
*
* @param family family of network change (ipv6, ipv4)
* @param luidIndex unique index of interface
* @param name name of the interface
* @param type of the interface
* @param connected whether interface is connected or not.
*/
public void notifyNetworkChange(
int family,
long luidIndex,
String name,
long type,
boolean connected);
}
}

@ -1,208 +1,208 @@
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Copyright @ 2015 Atlassian Pty Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.java.sip.communicator.plugin.contactinfo;
import java.util.*;
import net.java.sip.communicator.service.browserlauncher.*;
import net.java.sip.communicator.service.contactlist.*;
import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.util.*;
import org.jitsi.service.configuration.*;
import org.osgi.framework.*;
/**
* The Activator of the Contact Info bundle.
*
* @author Adam Goldstein
* @author Yana Stamcheva
*/
public class ContactInfoActivator implements BundleActivator
{
private Logger logger = Logger.getLogger(ContactInfoActivator.class);
/**
* Indicates if the contact info button is enabled in the chat window.
*/
private static final String ENABLED_IN_CHAT_WINDOW_PROP
= "net.java.sip.communicator.plugin.contactinfo." +
"ENABLED_IN_CHAT_WINDOW_PROP";
/**
* Indicates if the contact info button is enabled in the call window.
*/
private static final String ENABLED_IN_CALL_WINDOW_PROP
= "net.java.sip.communicator.plugin.contactinfo." +
"ENABLED_IN_CALL_WINDOW_PROP";
private static BrowserLauncherService browserLauncherService;
/**
* The image loader service implementation.
*/
private static ImageLoaderService<?> imageLoaderService = null;
/**
* The contact list service implementation.
*/
private static MetaContactListService metaCListService;
static BundleContext bundleContext;
/**
* Starts this bundle.
*/
public void start(BundleContext bc) throws Exception
{
bundleContext = bc;
Hashtable<String, String> containerFilter
= new Hashtable<String, String>();
containerFilter.put(
Container.CONTAINER_ID,
Container.CONTAINER_CONTACT_RIGHT_BUTTON_MENU.getID());
bundleContext.registerService(
PluginComponentFactory.class.getName(),
new ContactInfoPluginComponentFactory(
Container.CONTAINER_CONTACT_RIGHT_BUTTON_MENU),
containerFilter);
if(getConfigService().getBoolean(ENABLED_IN_CHAT_WINDOW_PROP, false))
{
containerFilter = new Hashtable<String, String>();
containerFilter.put(
Container.CONTAINER_ID,
Container.CONTAINER_CHAT_TOOL_BAR.getID());
bundleContext.registerService(
PluginComponentFactory.class.getName(),
new ContactInfoPluginComponentFactory(
Container.CONTAINER_CHAT_TOOL_BAR),
containerFilter);
}
if(getConfigService().getBoolean(ENABLED_IN_CALL_WINDOW_PROP, false))
{
containerFilter = new Hashtable<String, String>();
containerFilter.put(
Container.CONTAINER_ID,
Container.CONTAINER_CALL_DIALOG.getID());
bundleContext.registerService(
PluginComponentFactory.class.getName(),
new ContactInfoPluginComponentFactory(
Container.CONTAINER_CALL_DIALOG),
containerFilter);
}
if (logger.isInfoEnabled())
logger.info("CONTACT INFO... [REGISTERED]");
}
public void stop(BundleContext bc) throws Exception
{
}
/**
* Returns the <tt>BrowserLauncherService</tt> obtained from the bundle
* context.
* @return the <tt>BrowserLauncherService</tt> obtained from the bundle
* context
*/
public static BrowserLauncherService getBrowserLauncher()
{
if (browserLauncherService == null)
{
ServiceReference serviceReference = bundleContext
.getServiceReference(BrowserLauncherService.class.getName());
browserLauncherService = (BrowserLauncherService) bundleContext
.getService(serviceReference);
}
return browserLauncherService;
}
/**
* Returns the imageLoaderService instance, if missing query osgi for it.
* @return the imageLoaderService.
*/
public static ImageLoaderService<?> getImageLoaderService()
{
if(imageLoaderService == null)
{
imageLoaderService
= ServiceUtils.getService(
bundleContext,
ImageLoaderService.class);
}
return imageLoaderService;
}
/**
* Returns the <tt>MetaContactListService</tt> obtained from the bundle
* context.
* @return the <tt>MetaContactListService</tt> obtained from the bundle
* context
*/
public static MetaContactListService getContactListService()
{
if (metaCListService == null)
{
metaCListService
= ServiceUtils.getService(
bundleContext,
MetaContactListService.class);
}
return metaCListService;
}
/**
* Returns a reference to a ConfigurationService implementation currently
* registered in the bundle context or null if no such implementation was
* found.
*
* @return a currently valid implementation of the ConfigurationService.
*/
public static ConfigurationService getConfigService()
{
return ServiceUtils.getService(bundleContext,
ConfigurationService.class);
}
/**
* Contact info create factory.
*/
private class ContactInfoPluginComponentFactory
extends PluginComponentFactory
{
ContactInfoPluginComponentFactory(Container c)
{
super(c);
}
@Override
protected PluginComponent getPluginInstance()
{
return new ContactInfoMenuItem(getContainer(), this);
}
}
}
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Copyright @ 2015 Atlassian Pty Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.java.sip.communicator.plugin.contactinfo;
import java.util.*;
import net.java.sip.communicator.service.browserlauncher.*;
import net.java.sip.communicator.service.contactlist.*;
import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.util.*;
import org.jitsi.service.configuration.*;
import org.osgi.framework.*;
/**
* The Activator of the Contact Info bundle.
*
* @author Adam Goldstein
* @author Yana Stamcheva
*/
public class ContactInfoActivator implements BundleActivator
{
private Logger logger = Logger.getLogger(ContactInfoActivator.class);
/**
* Indicates if the contact info button is enabled in the chat window.
*/
private static final String ENABLED_IN_CHAT_WINDOW_PROP
= "net.java.sip.communicator.plugin.contactinfo." +
"ENABLED_IN_CHAT_WINDOW_PROP";
/**
* Indicates if the contact info button is enabled in the call window.
*/
private static final String ENABLED_IN_CALL_WINDOW_PROP
= "net.java.sip.communicator.plugin.contactinfo." +
"ENABLED_IN_CALL_WINDOW_PROP";
private static BrowserLauncherService browserLauncherService;
/**
* The image loader service implementation.
*/
private static ImageLoaderService<?> imageLoaderService = null;
/**
* The contact list service implementation.
*/
private static MetaContactListService metaCListService;
static BundleContext bundleContext;
/**
* Starts this bundle.
*/
public void start(BundleContext bc) throws Exception
{
bundleContext = bc;
Hashtable<String, String> containerFilter
= new Hashtable<String, String>();
containerFilter.put(
Container.CONTAINER_ID,
Container.CONTAINER_CONTACT_RIGHT_BUTTON_MENU.getID());
bundleContext.registerService(
PluginComponentFactory.class.getName(),
new ContactInfoPluginComponentFactory(
Container.CONTAINER_CONTACT_RIGHT_BUTTON_MENU),
containerFilter);
if(getConfigService().getBoolean(ENABLED_IN_CHAT_WINDOW_PROP, false))
{
containerFilter = new Hashtable<String, String>();
containerFilter.put(
Container.CONTAINER_ID,
Container.CONTAINER_CHAT_TOOL_BAR.getID());
bundleContext.registerService(
PluginComponentFactory.class.getName(),
new ContactInfoPluginComponentFactory(
Container.CONTAINER_CHAT_TOOL_BAR),
containerFilter);
}
if(getConfigService().getBoolean(ENABLED_IN_CALL_WINDOW_PROP, false))
{
containerFilter = new Hashtable<String, String>();
containerFilter.put(
Container.CONTAINER_ID,
Container.CONTAINER_CALL_DIALOG.getID());
bundleContext.registerService(
PluginComponentFactory.class.getName(),
new ContactInfoPluginComponentFactory(
Container.CONTAINER_CALL_DIALOG),
containerFilter);
}
if (logger.isInfoEnabled())
logger.info("CONTACT INFO... [REGISTERED]");
}
public void stop(BundleContext bc) throws Exception
{
}
/**
* Returns the <tt>BrowserLauncherService</tt> obtained from the bundle
* context.
* @return the <tt>BrowserLauncherService</tt> obtained from the bundle
* context
*/
public static BrowserLauncherService getBrowserLauncher()
{
if (browserLauncherService == null)
{
ServiceReference serviceReference = bundleContext
.getServiceReference(BrowserLauncherService.class.getName());
browserLauncherService = (BrowserLauncherService) bundleContext
.getService(serviceReference);
}
return browserLauncherService;
}
/**
* Returns the imageLoaderService instance, if missing query osgi for it.
* @return the imageLoaderService.
*/
public static ImageLoaderService<?> getImageLoaderService()
{
if(imageLoaderService == null)
{
imageLoaderService
= ServiceUtils.getService(
bundleContext,
ImageLoaderService.class);
}
return imageLoaderService;
}
/**
* Returns the <tt>MetaContactListService</tt> obtained from the bundle
* context.
* @return the <tt>MetaContactListService</tt> obtained from the bundle
* context
*/
public static MetaContactListService getContactListService()
{
if (metaCListService == null)
{
metaCListService
= ServiceUtils.getService(
bundleContext,
MetaContactListService.class);
}
return metaCListService;
}
/**
* Returns a reference to a ConfigurationService implementation currently
* registered in the bundle context or null if no such implementation was
* found.
*
* @return a currently valid implementation of the ConfigurationService.
*/
public static ConfigurationService getConfigService()
{
return ServiceUtils.getService(bundleContext,
ConfigurationService.class);
}
/**
* Contact info create factory.
*/
private class ContactInfoPluginComponentFactory
extends PluginComponentFactory
{
ContactInfoPluginComponentFactory(Container c)
{
super(c);
}
@Override
protected PluginComponent getPluginInstance()
{
return new ContactInfoMenuItem(getContainer(), this);
}
}
}

@ -1,4 +1,4 @@
/*
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Copyright @ 2015 Atlassian Pty Ltd
@ -15,490 +15,490 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.java.sip.communicator.plugin.desktoputil;
import java.awt.*;
import java.security.*;
import java.security.cert.*;
import java.security.cert.Certificate;
import java.security.interfaces.*;
import java.util.*;
import javax.naming.*;
import javax.naming.ldap.*;
import javax.security.auth.x500.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
import javax.swing.text.*;
import javax.swing.tree.*;
import org.jitsi.service.resources.*;
/**
* Panel that shows the content of an X509Certificate.
*/
public class X509CertificatePanel
extends TransparentPanel
{
private static final long serialVersionUID = -8368302061995971947L;
private final JEditorPane infoTextPane = new JEditorPane();
private final ResourceManagementService R
= DesktopUtilActivator.getResources();
/**
* Constructs a X509 certificate panel from a single certificate.
* If a chain is available instead use the second constructor.
* This constructor is kept for backwards compatibility and for convenience
* when there is only one certificate of interest.
*
* @param certificate <tt>X509Certificate</tt> object
*/
public X509CertificatePanel(Certificate certificate)
{
this(new Certificate[]
{
certificate
});
}
/**
* Constructs a X509 certificate panel.
*
* @param certificates <tt>X509Certificate</tt> objects
*/
public X509CertificatePanel(Certificate[] certificates)
{
setLayout(new BorderLayout(5, 5));
// Certificate chain list
TransparentPanel topPanel = new TransparentPanel(new BorderLayout());
topPanel.add(new JLabel("<html><body><b>"
+ R.getI18NString("service.gui.CERT_INFO_CHAIN")
+ "</b></body></html>"), BorderLayout.NORTH);
DefaultMutableTreeNode top = new DefaultMutableTreeNode();
DefaultMutableTreeNode previous = top;
for (int i = certificates.length - 1; i >= 0; i--)
{
Certificate cert = certificates[i];
DefaultMutableTreeNode next = new DefaultMutableTreeNode(cert);
previous.add(next);
previous = next;
}
JTree tree = new JTree(top);
tree.setBorder(new BevelBorder(BevelBorder.LOWERED));
tree.setRootVisible(false);
tree.setExpandsSelectedPaths(true);
tree.getSelectionModel().setSelectionMode(
TreeSelectionModel.SINGLE_TREE_SELECTION);
tree.setCellRenderer(new DefaultTreeCellRenderer()
{
@Override
public Component getTreeCellRendererComponent(JTree tree,
Object value, boolean sel, boolean expanded, boolean leaf,
int row, boolean hasFocus)
{
JLabel component = (JLabel) super.getTreeCellRendererComponent(
tree, value, sel, expanded, leaf, row, hasFocus);
if (value instanceof DefaultMutableTreeNode)
{
Object o = ((DefaultMutableTreeNode) value).getUserObject();
if (o instanceof X509Certificate)
{
component.setText(
getSimplifiedName((X509Certificate) o));
}
else
{
// We don't know how to represent this certificate type,
// let's use the first 20 characters
String text = o.toString();
if (text.length() > 20)
{
text = text.substring(0, 20);
}
component.setText(text);
}
}
return component;
}
});
tree.getSelectionModel().addTreeSelectionListener(
new TreeSelectionListener()
{
@Override
public void valueChanged(TreeSelectionEvent e)
{
valueChangedPerformed(e);
}
});
tree.setSelectionPath(new TreePath(((
(DefaultTreeModel)tree.getModel()).getPathToRoot(previous))));
topPanel.add(tree, BorderLayout.CENTER);
add(topPanel, BorderLayout.NORTH);
// Certificate details pane
Caret caret = infoTextPane.getCaret();
if (caret instanceof DefaultCaret)
{
((DefaultCaret) caret).setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
}
/*
* Make JEditorPane respect our default font because we will be using it
* to just display text.
*/
infoTextPane.putClientProperty(
JEditorPane.HONOR_DISPLAY_PROPERTIES,
true);
infoTextPane.setOpaque(false);
infoTextPane.setEditable(false);
infoTextPane.setContentType("text/html");
infoTextPane.setText(toString(certificates[0]));
final JScrollPane certScroll = new JScrollPane(infoTextPane);
certScroll.setPreferredSize(new Dimension(300, 500));
add(certScroll, BorderLayout.CENTER);
}
/**
* Creates a String representation of the given object.
* @param certificate to print
* @return the String representation
*/
private String toString(Object certificate)
{
final StringBuilder sb = new StringBuilder();
sb.append("<html><body>\n");
if (certificate instanceof X509Certificate)
{
renderX509(sb, (X509Certificate) certificate);
}
else
{
sb.append("<pre>\n");
sb.append(certificate.toString());
sb.append("</pre>\n");
}
sb.append("</body></html>");
return sb.toString();
}
/**
* Appends an HTML representation of the given X509Certificate.
* @param sb StringBuilder to append to
* @param certificate to print
*/
private void renderX509(StringBuilder sb, X509Certificate certificate)
{
X500Principal issuer = certificate.getIssuerX500Principal();
X500Principal subject = certificate.getSubjectX500Principal();
sb.append("<table cellspacing='1' cellpadding='1'>\n");
// subject
addTitle(sb, R.getI18NString("service.gui.CERT_INFO_ISSUED_TO"));
try
{
for(Rdn name : new LdapName(subject.getName()).getRdns())
{
String nameType = name.getType();
String lblKey = "service.gui.CERT_INFO_" + nameType;
String lbl = R.getI18NString(lblKey);
if ((lbl == null) || ("!" + lblKey + "!").equals(lbl))
lbl = nameType;
final String value;
Object nameValue = name.getValue();
if (nameValue instanceof byte[])
{
byte[] nameValueAsByteArray = (byte[]) nameValue;
value
= getHex(nameValueAsByteArray) + " ("
+ new String(nameValueAsByteArray) + ")";
}
else
value = nameValue.toString();
addField(sb, lbl, value);
}
}
catch (InvalidNameException ine)
{
addField(sb, R.getI18NString("service.gui.CERT_INFO_CN"),
subject.getName());
}
// issuer
addTitle(sb, R.getI18NString("service.gui.CERT_INFO_ISSUED_BY"));
try
{
for(Rdn name : new LdapName(issuer.getName()).getRdns())
{
String nameType = name.getType();
String lblKey = "service.gui.CERT_INFO_" + nameType;
String lbl = R.getI18NString(lblKey);
if ((lbl == null) || ("!" + lblKey + "!").equals(lbl))
lbl = nameType;
final String value;
Object nameValue = name.getValue();
if (nameValue instanceof byte[])
{
byte[] nameValueAsByteArray = (byte[]) nameValue;
value
= getHex(nameValueAsByteArray) + " ("
+ new String(nameValueAsByteArray) + ")";
}
else
value = nameValue.toString();
addField(sb, lbl, value);
}
}
catch (InvalidNameException ine)
{
addField(sb, R.getI18NString("service.gui.CERT_INFO_CN"),
issuer.getName());
}
// validity
addTitle(sb, R.getI18NString("service.gui.CERT_INFO_VALIDITY"));
addField(sb, R.getI18NString("service.gui.CERT_INFO_ISSUED_ON"),
certificate.getNotBefore().toString());
addField(sb, R.getI18NString("service.gui.CERT_INFO_EXPIRES_ON"),
certificate.getNotAfter().toString());
addTitle(sb, R.getI18NString("service.gui.CERT_INFO_FINGERPRINTS"));
try
{
String sha1String = getThumbprint(certificate, "SHA1");
String md5String = getThumbprint(certificate, "MD5");
addField(sb, "SHA1:", sha1String);
addField(sb, "MD5:", md5String);
}
catch (CertificateException e)
{
// do nothing as we cannot show this value
}
addTitle(sb, R.getI18NString("service.gui.CERT_INFO_CERT_DETAILS"));
addField(sb, R.getI18NString("service.gui.CERT_INFO_SER_NUM"),
certificate.getSerialNumber().toString());
addField(sb, R.getI18NString("service.gui.CERT_INFO_VER"),
String.valueOf(certificate.getVersion()));
addField(sb, R.getI18NString("service.gui.CERT_INFO_SIGN_ALG"),
String.valueOf(certificate.getSigAlgName()));
addTitle(sb, R.getI18NString("service.gui.CERT_INFO_PUB_KEY_INFO"));
addField(sb, R.getI18NString("service.gui.CERT_INFO_ALG"),
certificate.getPublicKey().getAlgorithm());
if(certificate.getPublicKey().getAlgorithm().equals("RSA"))
{
RSAPublicKey key = (RSAPublicKey)certificate.getPublicKey();
addField(sb, R.getI18NString("service.gui.CERT_INFO_PUB_KEY"),
R.getI18NString(
"service.gui.CERT_INFO_KEY_BYTES_PRINT",
new String[]{
String.valueOf(key.getModulus().toByteArray().length-1),
key.getModulus().toString(16)
}));
addField(sb, R.getI18NString("service.gui.CERT_INFO_EXP"),
key.getPublicExponent().toString());
addField(sb, R.getI18NString("service.gui.CERT_INFO_KEY_SIZE"),
R.getI18NString(
"service.gui.CERT_INFO_KEY_BITS_PRINT",
new String[]{
String.valueOf(key.getModulus().bitLength())}));
}
else if(certificate.getPublicKey().getAlgorithm().equals("DSA"))
{
DSAPublicKey key =
(DSAPublicKey)certificate.getPublicKey();
addField(sb, "Y:", key.getY().toString(16));
}
addField(sb, R.getI18NString("service.gui.CERT_INFO_SIGN"),
R.getI18NString(
"service.gui.CERT_INFO_KEY_BYTES_PRINT",
new String[]{
String.valueOf(certificate.getSignature().length),
getHex(certificate.getSignature())
}));
sb.append("</table>\n");
}
/**
* Add a title.
*
* @param sb StringBuilder to append to
* @param title to print
*/
private void addTitle(StringBuilder sb, String title)
{
sb.append("<tr><td colspan='2'")
.append(" style='margin-top: 5pt; white-space: nowrap'><p><b>")
.append(title).append("</b></p></td></tr>\n");
}
/**
* Add a field.
* @param sb StringBuilder to append to
* @param field name of the certificate field
* @param value to print
*/
private void addField(StringBuilder sb, String field, String value)
{
sb.append("<tr>")
.append("<td style='margin-left: 5pt; margin-right: 25pt;")
.append(" white-space: nowrap'>")
.append(field).append("</td>")
.append("<td>").append(value).append("</td>")
.append("</tr>\n");
}
/**
* Converts the byte array to hex string.
* @param raw the data.
* @return the hex string.
*/
private String getHex( byte [] raw )
{
if (raw == null)
return null;
StringBuilder hex = new StringBuilder(2 * raw.length);
Formatter f = new Formatter(hex);
try
{
for (byte b : raw)
f.format("%02x", b);
}
finally
{
f.close();
}
return hex.toString();
}
/**
* Calculates the hash of the certificate known as the "thumbprint"
* and returns it as a string representation.
*
* @param cert The certificate to hash.
* @param algorithm The hash algorithm to use.
* @return The SHA-1 hash of the certificate.
* @throws CertificateException
*/
private static String getThumbprint(X509Certificate cert, String algorithm)
throws CertificateException
{
MessageDigest digest;
try
{
digest = MessageDigest.getInstance(algorithm);
}
catch (NoSuchAlgorithmException e)
{
throw new CertificateException(e);
}
byte[] encodedCert = cert.getEncoded();
StringBuilder sb = new StringBuilder(encodedCert.length * 2);
Formatter f = new Formatter(sb);
try
{
for (byte b : digest.digest(encodedCert))
f.format("%02x", b);
}
finally
{
f.close();
}
return sb.toString();
}
/**
* Construct a "simplified name" based on the subject DN from the
* certificate. The purpose is to have something shorter to display in the
* list. The name used is one of the following DN parts, if
* available, otherwise the complete DN:
* 'CN', 'OU' or else 'O'.
* @param cert to read subject DN from
* @return the simplified name
*/
private static String getSimplifiedName(X509Certificate cert)
{
final HashMap<String, String> parts = new HashMap<String, String>();
try
{
for (Rdn name : new LdapName(
cert.getSubjectX500Principal().getName()).getRdns())
{
if (name.getType() != null && name.getValue() != null)
{
parts.put(name.getType(), name.getValue().toString());
}
}
}
catch (InvalidNameException ignored) // NOPMD
{
}
String result = parts.get("CN");
if (result == null)
{
result = parts.get("OU");
}
if (result == null)
{
result = parts.get("O");
}
if (result == null)
{
result = cert.getSubjectX500Principal().getName();
}
return result;
}
/**
* Called when the selection changed in the tree.
* Loads the selected certificate.
* @param e the event
*/
private void valueChangedPerformed(TreeSelectionEvent e)
{
Object o = e.getNewLeadSelectionPath().getLastPathComponent();
if (o instanceof DefaultMutableTreeNode)
{
DefaultMutableTreeNode node = (DefaultMutableTreeNode) o;
infoTextPane.setText(toString(node.getUserObject()));
}
}
}
package net.java.sip.communicator.plugin.desktoputil;
import java.awt.*;
import java.security.*;
import java.security.cert.*;
import java.security.cert.Certificate;
import java.security.interfaces.*;
import java.util.*;
import javax.naming.*;
import javax.naming.ldap.*;
import javax.security.auth.x500.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
import javax.swing.text.*;
import javax.swing.tree.*;
import org.jitsi.service.resources.*;
/**
* Panel that shows the content of an X509Certificate.
*/
public class X509CertificatePanel
extends TransparentPanel
{
private static final long serialVersionUID = -8368302061995971947L;
private final JEditorPane infoTextPane = new JEditorPane();
private final ResourceManagementService R
= DesktopUtilActivator.getResources();
/**
* Constructs a X509 certificate panel from a single certificate.
* If a chain is available instead use the second constructor.
* This constructor is kept for backwards compatibility and for convenience
* when there is only one certificate of interest.
*
* @param certificate <tt>X509Certificate</tt> object
*/
public X509CertificatePanel(Certificate certificate)
{
this(new Certificate[]
{
certificate
});
}
/**
* Constructs a X509 certificate panel.
*
* @param certificates <tt>X509Certificate</tt> objects
*/
public X509CertificatePanel(Certificate[] certificates)
{
setLayout(new BorderLayout(5, 5));
// Certificate chain list
TransparentPanel topPanel = new TransparentPanel(new BorderLayout());
topPanel.add(new JLabel("<html><body><b>"
+ R.getI18NString("service.gui.CERT_INFO_CHAIN")
+ "</b></body></html>"), BorderLayout.NORTH);
DefaultMutableTreeNode top = new DefaultMutableTreeNode();
DefaultMutableTreeNode previous = top;
for (int i = certificates.length - 1; i >= 0; i--)
{
Certificate cert = certificates[i];
DefaultMutableTreeNode next = new DefaultMutableTreeNode(cert);
previous.add(next);
previous = next;
}
JTree tree = new JTree(top);
tree.setBorder(new BevelBorder(BevelBorder.LOWERED));
tree.setRootVisible(false);
tree.setExpandsSelectedPaths(true);
tree.getSelectionModel().setSelectionMode(
TreeSelectionModel.SINGLE_TREE_SELECTION);
tree.setCellRenderer(new DefaultTreeCellRenderer()
{
@Override
public Component getTreeCellRendererComponent(JTree tree,
Object value, boolean sel, boolean expanded, boolean leaf,
int row, boolean hasFocus)
{
JLabel component = (JLabel) super.getTreeCellRendererComponent(
tree, value, sel, expanded, leaf, row, hasFocus);
if (value instanceof DefaultMutableTreeNode)
{
Object o = ((DefaultMutableTreeNode) value).getUserObject();
if (o instanceof X509Certificate)
{
component.setText(
getSimplifiedName((X509Certificate) o));
}
else
{
// We don't know how to represent this certificate type,
// let's use the first 20 characters
String text = o.toString();
if (text.length() > 20)
{
text = text.substring(0, 20);
}
component.setText(text);
}
}
return component;
}
});
tree.getSelectionModel().addTreeSelectionListener(
new TreeSelectionListener()
{
@Override
public void valueChanged(TreeSelectionEvent e)
{
valueChangedPerformed(e);
}
});
tree.setSelectionPath(new TreePath(((
(DefaultTreeModel)tree.getModel()).getPathToRoot(previous))));
topPanel.add(tree, BorderLayout.CENTER);
add(topPanel, BorderLayout.NORTH);
// Certificate details pane
Caret caret = infoTextPane.getCaret();
if (caret instanceof DefaultCaret)
{
((DefaultCaret) caret).setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
}
/*
* Make JEditorPane respect our default font because we will be using it
* to just display text.
*/
infoTextPane.putClientProperty(
JEditorPane.HONOR_DISPLAY_PROPERTIES,
true);
infoTextPane.setOpaque(false);
infoTextPane.setEditable(false);
infoTextPane.setContentType("text/html");
infoTextPane.setText(toString(certificates[0]));
final JScrollPane certScroll = new JScrollPane(infoTextPane);
certScroll.setPreferredSize(new Dimension(300, 500));
add(certScroll, BorderLayout.CENTER);
}
/**
* Creates a String representation of the given object.
* @param certificate to print
* @return the String representation
*/
private String toString(Object certificate)
{
final StringBuilder sb = new StringBuilder();
sb.append("<html><body>\n");
if (certificate instanceof X509Certificate)
{
renderX509(sb, (X509Certificate) certificate);
}
else
{
sb.append("<pre>\n");
sb.append(certificate.toString());
sb.append("</pre>\n");
}
sb.append("</body></html>");
return sb.toString();
}
/**
* Appends an HTML representation of the given X509Certificate.
* @param sb StringBuilder to append to
* @param certificate to print
*/
private void renderX509(StringBuilder sb, X509Certificate certificate)
{
X500Principal issuer = certificate.getIssuerX500Principal();
X500Principal subject = certificate.getSubjectX500Principal();
sb.append("<table cellspacing='1' cellpadding='1'>\n");
// subject
addTitle(sb, R.getI18NString("service.gui.CERT_INFO_ISSUED_TO"));
try
{
for(Rdn name : new LdapName(subject.getName()).getRdns())
{
String nameType = name.getType();
String lblKey = "service.gui.CERT_INFO_" + nameType;
String lbl = R.getI18NString(lblKey);
if ((lbl == null) || ("!" + lblKey + "!").equals(lbl))
lbl = nameType;
final String value;
Object nameValue = name.getValue();
if (nameValue instanceof byte[])
{
byte[] nameValueAsByteArray = (byte[]) nameValue;
value
= getHex(nameValueAsByteArray) + " ("
+ new String(nameValueAsByteArray) + ")";
}
else
value = nameValue.toString();
addField(sb, lbl, value);
}
}
catch (InvalidNameException ine)
{
addField(sb, R.getI18NString("service.gui.CERT_INFO_CN"),
subject.getName());
}
// issuer
addTitle(sb, R.getI18NString("service.gui.CERT_INFO_ISSUED_BY"));
try
{
for(Rdn name : new LdapName(issuer.getName()).getRdns())
{
String nameType = name.getType();
String lblKey = "service.gui.CERT_INFO_" + nameType;
String lbl = R.getI18NString(lblKey);
if ((lbl == null) || ("!" + lblKey + "!").equals(lbl))
lbl = nameType;
final String value;
Object nameValue = name.getValue();
if (nameValue instanceof byte[])
{
byte[] nameValueAsByteArray = (byte[]) nameValue;
value
= getHex(nameValueAsByteArray) + " ("
+ new String(nameValueAsByteArray) + ")";
}
else
value = nameValue.toString();
addField(sb, lbl, value);
}
}
catch (InvalidNameException ine)
{
addField(sb, R.getI18NString("service.gui.CERT_INFO_CN"),
issuer.getName());
}
// validity
addTitle(sb, R.getI18NString("service.gui.CERT_INFO_VALIDITY"));
addField(sb, R.getI18NString("service.gui.CERT_INFO_ISSUED_ON"),
certificate.getNotBefore().toString());
addField(sb, R.getI18NString("service.gui.CERT_INFO_EXPIRES_ON"),
certificate.getNotAfter().toString());
addTitle(sb, R.getI18NString("service.gui.CERT_INFO_FINGERPRINTS"));
try
{
String sha1String = getThumbprint(certificate, "SHA1");
String md5String = getThumbprint(certificate, "MD5");
addField(sb, "SHA1:", sha1String);
addField(sb, "MD5:", md5String);
}
catch (CertificateException e)
{
// do nothing as we cannot show this value
}
addTitle(sb, R.getI18NString("service.gui.CERT_INFO_CERT_DETAILS"));
addField(sb, R.getI18NString("service.gui.CERT_INFO_SER_NUM"),
certificate.getSerialNumber().toString());
addField(sb, R.getI18NString("service.gui.CERT_INFO_VER"),
String.valueOf(certificate.getVersion()));
addField(sb, R.getI18NString("service.gui.CERT_INFO_SIGN_ALG"),
String.valueOf(certificate.getSigAlgName()));
addTitle(sb, R.getI18NString("service.gui.CERT_INFO_PUB_KEY_INFO"));
addField(sb, R.getI18NString("service.gui.CERT_INFO_ALG"),
certificate.getPublicKey().getAlgorithm());
if(certificate.getPublicKey().getAlgorithm().equals("RSA"))
{
RSAPublicKey key = (RSAPublicKey)certificate.getPublicKey();
addField(sb, R.getI18NString("service.gui.CERT_INFO_PUB_KEY"),
R.getI18NString(
"service.gui.CERT_INFO_KEY_BYTES_PRINT",
new String[]{
String.valueOf(key.getModulus().toByteArray().length-1),
key.getModulus().toString(16)
}));
addField(sb, R.getI18NString("service.gui.CERT_INFO_EXP"),
key.getPublicExponent().toString());
addField(sb, R.getI18NString("service.gui.CERT_INFO_KEY_SIZE"),
R.getI18NString(
"service.gui.CERT_INFO_KEY_BITS_PRINT",
new String[]{
String.valueOf(key.getModulus().bitLength())}));
}
else if(certificate.getPublicKey().getAlgorithm().equals("DSA"))
{
DSAPublicKey key =
(DSAPublicKey)certificate.getPublicKey();
addField(sb, "Y:", key.getY().toString(16));
}
addField(sb, R.getI18NString("service.gui.CERT_INFO_SIGN"),
R.getI18NString(
"service.gui.CERT_INFO_KEY_BYTES_PRINT",
new String[]{
String.valueOf(certificate.getSignature().length),
getHex(certificate.getSignature())
}));
sb.append("</table>\n");
}
/**
* Add a title.
*
* @param sb StringBuilder to append to
* @param title to print
*/
private void addTitle(StringBuilder sb, String title)
{
sb.append("<tr><td colspan='2'")
.append(" style='margin-top: 5pt; white-space: nowrap'><p><b>")
.append(title).append("</b></p></td></tr>\n");
}
/**
* Add a field.
* @param sb StringBuilder to append to
* @param field name of the certificate field
* @param value to print
*/
private void addField(StringBuilder sb, String field, String value)
{
sb.append("<tr>")
.append("<td style='margin-left: 5pt; margin-right: 25pt;")
.append(" white-space: nowrap'>")
.append(field).append("</td>")
.append("<td>").append(value).append("</td>")
.append("</tr>\n");
}
/**
* Converts the byte array to hex string.
* @param raw the data.
* @return the hex string.
*/
private String getHex( byte [] raw )
{
if (raw == null)
return null;
StringBuilder hex = new StringBuilder(2 * raw.length);
Formatter f = new Formatter(hex);
try
{
for (byte b : raw)
f.format("%02x", b);
}
finally
{
f.close();
}
return hex.toString();
}
/**
* Calculates the hash of the certificate known as the "thumbprint"
* and returns it as a string representation.
*
* @param cert The certificate to hash.
* @param algorithm The hash algorithm to use.
* @return The SHA-1 hash of the certificate.
* @throws CertificateException
*/
private static String getThumbprint(X509Certificate cert, String algorithm)
throws CertificateException
{
MessageDigest digest;
try
{
digest = MessageDigest.getInstance(algorithm);
}
catch (NoSuchAlgorithmException e)
{
throw new CertificateException(e);
}
byte[] encodedCert = cert.getEncoded();
StringBuilder sb = new StringBuilder(encodedCert.length * 2);
Formatter f = new Formatter(sb);
try
{
for (byte b : digest.digest(encodedCert))
f.format("%02x", b);
}
finally
{
f.close();
}
return sb.toString();
}
/**
* Construct a "simplified name" based on the subject DN from the
* certificate. The purpose is to have something shorter to display in the
* list. The name used is one of the following DN parts, if
* available, otherwise the complete DN:
* 'CN', 'OU' or else 'O'.
* @param cert to read subject DN from
* @return the simplified name
*/
private static String getSimplifiedName(X509Certificate cert)
{
final HashMap<String, String> parts = new HashMap<String, String>();
try
{
for (Rdn name : new LdapName(
cert.getSubjectX500Principal().getName()).getRdns())
{
if (name.getType() != null && name.getValue() != null)
{
parts.put(name.getType(), name.getValue().toString());
}
}
}
catch (InvalidNameException ignored) // NOPMD
{
}
String result = parts.get("CN");
if (result == null)
{
result = parts.get("OU");
}
if (result == null)
{
result = parts.get("O");
}
if (result == null)
{
result = cert.getSubjectX500Principal().getName();
}
return result;
}
/**
* Called when the selection changed in the tree.
* Loads the selected certificate.
* @param e the event
*/
private void valueChangedPerformed(TreeSelectionEvent e)
{
Object o = e.getNewLeadSelectionPath().getLastPathComponent();
if (o instanceof DefaultMutableTreeNode)
{
DefaultMutableTreeNode node = (DefaultMutableTreeNode) o;
infoTextPane.setText(toString(node.getUserObject()));
}
}
}

@ -1,40 +1,40 @@
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Copyright @ 2015 Atlassian Pty Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.java.sip.communicator.service.muc;
/**
* Listener which registers for provider add/remove changes.
*/
public interface ChatRoomProviderWrapperListener
{
/**
* When a provider wrapper is added this method is called to inform
* listeners.
* @param provider which was added.
*/
public void chatRoomProviderWrapperAdded(
ChatRoomProviderWrapper provider);
/**
* When a provider wrapper is removed this method is called to inform
* listeners.
* @param provider which was removed.
*/
public void chatRoomProviderWrapperRemoved(
ChatRoomProviderWrapper provider);
}
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Copyright @ 2015 Atlassian Pty Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.java.sip.communicator.service.muc;
/**
* Listener which registers for provider add/remove changes.
*/
public interface ChatRoomProviderWrapperListener
{
/**
* When a provider wrapper is added this method is called to inform
* listeners.
* @param provider which was added.
*/
public void chatRoomProviderWrapperAdded(
ChatRoomProviderWrapper provider);
/**
* When a provider wrapper is removed this method is called to inform
* listeners.
* @param provider which was removed.
*/
public void chatRoomProviderWrapperRemoved(
ChatRoomProviderWrapper provider);
}

@ -1,4 +1,4 @@
/*
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Copyright @ 2015 Atlassian Pty Ltd
@ -15,54 +15,54 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.java.sip.communicator.slick.popupmessagehandler;
import java.util.*;
import junit.framework.*;
import net.java.sip.communicator.service.systray.*;
import net.java.sip.communicator.util.*;
import org.osgi.framework.*;
/**
*
* @author Symphorien Wanko
*/
public class PopupMessageHandlerSLick extends TestSuite implements BundleActivator
{
/** Logger for this class */
private static Logger logger =
Logger.getLogger(PopupMessageHandlerSLick.class);
/** our bundle context */
protected static BundleContext bundleContext = null;
/** implements BundleActivator.start() */
public void start(BundleContext bc) throws Exception
{
logger.info("starting popup message test ");
bundleContext = bc;
setName("PopupMessageHandlerSLick");
Hashtable<String, String> properties = new Hashtable<String, String>();
properties.put("service.pid", getName());
// we maybe are running on machine without WM and systray
// (test server machine), skip tests
if(ServiceUtils.getService(bc, SystrayService.class) != null)
{
addTest(TestPopupMessageHandler.suite());
}
bundleContext.registerService(getClass().getName(), this, properties);
}
/** implements BundleActivator.stop() */
public void stop(BundleContext bc) throws Exception
{}
}
package net.java.sip.communicator.slick.popupmessagehandler;
import java.util.*;
import junit.framework.*;
import net.java.sip.communicator.service.systray.*;
import net.java.sip.communicator.util.*;
import org.osgi.framework.*;
/**
*
* @author Symphorien Wanko
*/
public class PopupMessageHandlerSLick extends TestSuite implements BundleActivator
{
/** Logger for this class */
private static Logger logger =
Logger.getLogger(PopupMessageHandlerSLick.class);
/** our bundle context */
protected static BundleContext bundleContext = null;
/** implements BundleActivator.start() */
public void start(BundleContext bc) throws Exception
{
logger.info("starting popup message test ");
bundleContext = bc;
setName("PopupMessageHandlerSLick");
Hashtable<String, String> properties = new Hashtable<String, String>();
properties.put("service.pid", getName());
// we maybe are running on machine without WM and systray
// (test server machine), skip tests
if(ServiceUtils.getService(bc, SystrayService.class) != null)
{
addTest(TestPopupMessageHandler.suite());
}
bundleContext.registerService(getClass().getName(), this, properties);
}
/** implements BundleActivator.stop() */
public void stop(BundleContext bc) throws Exception
{}
}

@ -1,4 +1,4 @@
/*
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Copyright @ 2015 Atlassian Pty Ltd
@ -15,487 +15,487 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.java.sip.communicator.slick.protocol.sip;
import static net.java.sip.communicator.service.protocol.ProtocolProviderFactory.USER_ID;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
import java.net.*;
import java.text.*;
import junit.framework.*;
import net.java.sip.communicator.impl.protocol.sip.*;
import net.java.sip.communicator.impl.protocol.sip.net.*;
import net.java.sip.communicator.service.dns.*;
import net.java.sip.communicator.util.*;
/**
* Tests all variations of automatic proxy detection through (simulated) DNS.
*
* @author Ingo Bauersachs
*/
public class TestAutoProxyDetection
extends TestCase
{
private static class TestedAutoProxyDetection extends AutoProxyConnection
{
public TestedAutoProxyDetection(SipAccountIDImpl account,
String defaultTransport)
{
super(account, defaultTransport);
}
@Override
public void setNetworkUtils(LocalNetworkUtils nu)
{
super.setNetworkUtils(nu);
}
public static class NetworkUtils extends LocalNetworkUtils
{
}
}
private SipAccountIDImpl account;
private TestedAutoProxyDetection.NetworkUtils nu;
private SRVRecord srv1;
private SRVRecord srv2;
private SRVRecord srv3;
private InetSocketAddress a1;
private InetSocketAddress a2;
private InetSocketAddress a3;
private InetSocketAddress a4;
private final static String DOMAIN = "example.com";
private InetAddress ia1;
private InetAddress ia2;
private InetAddress ia3;
private InetAddress ia4;
private TestedAutoProxyDetection apd;
@Override
public void setUp()
{
account = createMock(SipAccountIDImpl.class);
expect(account.getAccountPropertyString(USER_ID))
.andReturn("unit@" + DOMAIN);
replay(account);
nu = createMock(TestedAutoProxyDetection.NetworkUtils.class);
apd = new TestedAutoProxyDetection(account, "UDP");
apd.setNetworkUtils(nu);
srv1 = createMock(SRVRecord.class);
expect(srv1.getTarget()).andReturn("proxy1."+DOMAIN);
expect(srv1.getPort()).andReturn(5060);
srv2 = createMock(SRVRecord.class);
expect(srv2.getTarget()).andReturn("proxy2."+DOMAIN);
expect(srv2.getPort()).andReturn(5061);
srv3 = createMock(SRVRecord.class);
expect(srv3.getTarget()).andReturn("proxy3."+DOMAIN);
expect(srv3.getPort()).andReturn(5062);
try
{
ia1 = InetAddress.getByAddress("proxy1." + DOMAIN,
new byte[]{0x7f,0,0,1});
ia2 = InetAddress.getByAddress("proxy2." + DOMAIN,
new byte[]{0x7f,0,0,2});
ia3 = InetAddress.getByAddress("proxy3." + DOMAIN,
new byte[]{0x7f,0,0,3});
ia4 = InetAddress.getByAddress("proxy4." + DOMAIN,
new byte[]{0x7f,0,0,4});
}
catch (UnknownHostException e)
{
fail("unable to initialize: " + e.getMessage());
}
a1 = new InetSocketAddress(ia1, 5060);
a2 = new InetSocketAddress(ia2, 5061);
a3 = new InetSocketAddress(ia3, 5062);
a4 = new InetSocketAddress(ia4, 5063);
}
private void prepareOneNaptrOneSrv() throws ParseException, DnssecException
{
expect(nu.getNAPTRRecords(DOMAIN)).andReturn(new String[][]{
{"0", "udp", "_sip._udp." + DOMAIN}
});
expect(nu.getSRVRecords("_sip._udp."+DOMAIN))
.andReturn(new SRVRecord[]{ srv1 });
}
private void prepareOneNaptrTwoSrv() throws ParseException, DnssecException
{
expect(nu.getNAPTRRecords(DOMAIN)).andReturn(new String[][]{
{"0", "udp", "_sip._udp." + DOMAIN}
});
expect(nu.getSRVRecords("_sip._udp."+DOMAIN))
.andReturn(new SRVRecord[]{ srv1, srv2 });
}
public void testOneNaptrNoSrv() throws ParseException, DnssecException
{
expect(nu.getNAPTRRecords(DOMAIN)).andReturn(new String[][]{
{"0", "udp", "_sip._udp." + DOMAIN}
});
expect(nu.getSRVRecords("_sip._udp." + DOMAIN)).andReturn(null);
replay(nu);
assertFalse(apd.getNextAddress());
verify(account, nu);
}
public void testOneNaptrOneSrvOneA() throws ParseException, DnssecException
{
prepareOneNaptrOneSrv();
expect(nu.getAandAAAARecords("proxy1." + DOMAIN, 5060))
.andReturn(new InetSocketAddress[]{a1});
replay(nu, srv1);
assertTrue(apd.getNextAddress());
assertEquals(a1, apd.getAddress());
assertEquals("UDP", apd.getTransport());
assertFalse(apd.getNextAddress());
verify(account, nu, srv1);
}
public void testOneNaptrOneSrvTwoA() throws ParseException, DnssecException
{
prepareOneNaptrOneSrv();
expect(nu.getAandAAAARecords("proxy1." + DOMAIN, 5060))
.andReturn(new InetSocketAddress[]{a1, a2});
replay(nu, srv1);
assertTrue(apd.getNextAddress());
assertEquals(a1, apd.getAddress());
assertEquals("UDP", apd.getTransport());
assertTrue(apd.getNextAddress());
assertEquals(a2, apd.getAddress());
assertEquals("UDP", apd.getTransport());
assertFalse(apd.getNextAddress());
verify(account, nu, srv1);
}
//-----------------------
public void testOneNaptrTwoSrvOneA() throws ParseException, DnssecException
{
prepareOneNaptrTwoSrv();
expect(nu.getAandAAAARecords("proxy1." + DOMAIN, 5060))
.andReturn(new InetSocketAddress[]{a1});
expect(nu.getAandAAAARecords("proxy2." + DOMAIN, 5061))
.andReturn(new InetSocketAddress[]{a2});
replay(nu, srv1, srv2);
assertTrue(apd.getNextAddress());
assertEquals(a1, apd.getAddress());
assertEquals("UDP", apd.getTransport());
assertTrue(apd.getNextAddress());
assertEquals(a2, apd.getAddress());
assertEquals("UDP", apd.getTransport());
assertFalse(apd.getNextAddress());
verify(account, nu, srv1, srv2);
}
public void testOneNaptrTwoSrvTwoA() throws ParseException, DnssecException
{
prepareOneNaptrTwoSrv();
expect(nu.getAandAAAARecords("proxy1." + DOMAIN, 5060))
.andReturn(new InetSocketAddress[]{a1, a2});
expect(nu.getAandAAAARecords("proxy2." + DOMAIN, 5061))
.andReturn(new InetSocketAddress[]{a3, a4});
replay(nu, srv1, srv2);
assertTrue(apd.getNextAddress());
assertEquals(a1, apd.getAddress());
assertEquals("UDP", apd.getTransport());
assertTrue(apd.getNextAddress());
assertEquals(a2, apd.getAddress());
assertEquals("UDP", apd.getTransport());
assertTrue(apd.getNextAddress());
assertEquals(a3, apd.getAddress());
assertEquals("UDP", apd.getTransport());
assertTrue(apd.getNextAddress());
assertEquals(a4, apd.getAddress());
assertEquals("UDP", apd.getTransport());
assertFalse(apd.getNextAddress());
verify(account, nu, srv1, srv2);
}
//-------------------
public void testThreeNaptrOneSrvEachOneAEach()
throws ParseException,
DnssecException
{
expect(nu.getNAPTRRecords(DOMAIN)).andReturn(new String[][]{
{"0", "udp", "_sip._udp." + DOMAIN},
{"0", "tcp", "_sip._tcp." + DOMAIN},
{"0", "tls", "_sips._tcp." + DOMAIN}
});
expect(nu.getSRVRecords("_sip._udp."+DOMAIN))
.andReturn(new SRVRecord[]{ srv1 });
expect(nu.getSRVRecords("_sip._tcp."+DOMAIN))
.andReturn(new SRVRecord[]{ srv2 });
expect(nu.getSRVRecords("_sips._tcp."+DOMAIN))
.andReturn(new SRVRecord[]{ srv3 });
expect(nu.getAandAAAARecords("proxy1." + DOMAIN, 5060))
.andReturn(new InetSocketAddress[]{a1});
expect(nu.getAandAAAARecords("proxy2." + DOMAIN, 5061))
.andReturn(new InetSocketAddress[]{a1});
expect(nu.getAandAAAARecords("proxy3." + DOMAIN, 5062))
.andReturn(new InetSocketAddress[]{a1});
replay(nu, srv1, srv2, srv3);
assertTrue(apd.getNextAddress());
assertEquals(a1, apd.getAddress());
assertEquals("UDP", apd.getTransport());
assertTrue(apd.getNextAddress());
assertEquals(a1, apd.getAddress());
assertEquals("TCP", apd.getTransport());
assertTrue(apd.getNextAddress());
assertEquals(a1, apd.getAddress());
assertEquals("TLS", apd.getTransport());
assertFalse(apd.getNextAddress());
verify(account, nu, srv1, srv2, srv3);
}
//-----------------------
public void testNoSrvOneA() throws ParseException, DnssecException
{
expect(nu.getNAPTRRecords(DOMAIN)).andReturn(new String[][]{});
expect(nu.getSRVRecords("sips", "TCP", DOMAIN)).andReturn(null);
expect(nu.getSRVRecords("sip", "TCP", DOMAIN)).andReturn(null);
expect(nu.getSRVRecords("sip", "UDP", DOMAIN)).andReturn(null);
expect(nu.getAandAAAARecords(DOMAIN, 5060))
.andReturn(new InetSocketAddress[]{a1});
replay(nu);
assertTrue(apd.getNextAddress());
assertEquals(a1, apd.getAddress());
assertEquals("UDP", apd.getTransport());
assertFalse(apd.getNextAddress());
verify(account, nu);
}
public void testOneSrvNoA() throws ParseException, DnssecException
{
expect(nu.getNAPTRRecords(DOMAIN)).andReturn(new String[][]{});
expect(nu.getSRVRecords("sips", "TCP", DOMAIN)).andReturn(null);
expect(nu.getSRVRecords("sip", "TCP", DOMAIN)).andReturn(null);
expect(nu.getSRVRecords("sip", "UDP", DOMAIN))
.andReturn(new SRVRecord[]{srv1});
expect(nu.getAandAAAARecords("proxy1." + DOMAIN, 5060))
.andReturn(null);
replay(nu, srv1);
assertFalse(apd.getNextAddress());
verify(account, nu, srv1);
}
public void testOneSrvOneA() throws ParseException, DnssecException
{
expect(nu.getNAPTRRecords(DOMAIN)).andReturn(new String[][]{});
expect(nu.getSRVRecords("sips", "TCP", DOMAIN)).andReturn(null);
expect(nu.getSRVRecords("sip", "TCP", DOMAIN)).andReturn(null);
expect(nu.getSRVRecords("sip", "UDP", DOMAIN))
.andReturn(new SRVRecord[]{srv1});
expect(nu.getAandAAAARecords("proxy1." + DOMAIN, 5060))
.andReturn(new InetSocketAddress[]{a1});
replay(nu, srv1);
assertTrue(apd.getNextAddress());
assertEquals(a1, apd.getAddress());
assertEquals("UDP", apd.getTransport());
assertFalse(apd.getNextAddress());
verify(account, nu, srv1);
}
public void testOneSrvTwoA() throws ParseException, DnssecException
{
expect(nu.getNAPTRRecords(DOMAIN)).andReturn(new String[][]{});
expect(nu.getSRVRecords("sips", "TCP", DOMAIN)).andReturn(null);
expect(nu.getSRVRecords("sip", "TCP", DOMAIN)).andReturn(null);
expect(nu.getSRVRecords("sip", "UDP", DOMAIN))
.andReturn(new SRVRecord[]{srv1});
expect(nu.getAandAAAARecords("proxy1." + DOMAIN, 5060))
.andReturn(new InetSocketAddress[]{a1, a2});
replay(nu, srv1);
assertTrue(apd.getNextAddress());
assertEquals(a1, apd.getAddress());
assertEquals("UDP", apd.getTransport());
assertTrue(apd.getNextAddress());
assertEquals(a2, apd.getAddress());
assertEquals("UDP", apd.getTransport());
assertFalse(apd.getNextAddress());
verify(account, nu, srv1);
}
public void testTwoSrvOneA() throws ParseException, DnssecException
{
expect(nu.getNAPTRRecords(DOMAIN)).andReturn(new String[][]{});
expect(nu.getSRVRecords("sips", "TCP", DOMAIN))
.andReturn(new SRVRecord[]{srv2});
expect(nu.getSRVRecords("sip", "TCP", DOMAIN)).andReturn(null);
expect(nu.getSRVRecords("sip", "UDP", DOMAIN))
.andReturn(new SRVRecord[]{srv1});
expect(nu.getAandAAAARecords("proxy1." + DOMAIN, 5060))
.andReturn(new InetSocketAddress[]{a1});
expect(nu.getAandAAAARecords("proxy2." + DOMAIN, 5061))
.andReturn(new InetSocketAddress[]{a2});
replay(nu, srv1, srv2);
assertTrue(apd.getNextAddress());
assertEquals(a2, apd.getAddress());
assertEquals("TLS", apd.getTransport());
assertTrue(apd.getNextAddress());
assertEquals(a1, apd.getAddress());
assertEquals("UDP", apd.getTransport());
assertFalse(apd.getNextAddress());
verify(account, nu, srv1, srv2);
}
public void testTwoSameSrvOneA() throws ParseException, DnssecException
{
expect(nu.getNAPTRRecords(DOMAIN)).andReturn(new String[][]{});
expect(nu.getSRVRecords("sips", "TCP", DOMAIN))
.andReturn(new SRVRecord[]{srv1, srv2});
expect(nu.getSRVRecords("sip", "TCP", DOMAIN)).andReturn(null);
expect(nu.getSRVRecords("sip", "UDP", DOMAIN)).andReturn(null);
expect(nu.getAandAAAARecords("proxy1." + DOMAIN, 5060))
.andReturn(new InetSocketAddress[]{a1});
expect(nu.getAandAAAARecords("proxy2." + DOMAIN, 5061))
.andReturn(new InetSocketAddress[]{a2});
replay(nu, srv1, srv2);
assertTrue(apd.getNextAddress());
assertEquals(a1, apd.getAddress());
assertEquals("TLS", apd.getTransport());
assertEquals(5060, apd.getAddress().getPort());
assertTrue(apd.getNextAddress());
assertEquals(a2, apd.getAddress());
assertEquals("TLS", apd.getTransport());
assertEquals(5061, apd.getAddress().getPort());
assertFalse(apd.getNextAddress());
verify(account, nu, srv1, srv2);
}
//----------------------
public void testNoA() throws ParseException, DnssecException
{
expect(nu.getNAPTRRecords(DOMAIN)).andReturn(new String[][]{});
expect(nu.getSRVRecords("sips", "TCP", DOMAIN)).andReturn(null);
expect(nu.getSRVRecords("sip", "TCP", DOMAIN)).andReturn(null);
expect(nu.getSRVRecords("sip", "UDP", DOMAIN)).andReturn(null);
expect(nu.getAandAAAARecords(DOMAIN, 5060))
.andReturn(new InetSocketAddress[]{});
replay(nu);
assertFalse(apd.getNextAddress());
verify(account, nu);
}
public void testOneA() throws ParseException, DnssecException
{
expect(nu.getNAPTRRecords(DOMAIN)).andReturn(new String[][]{});
expect(nu.getSRVRecords("sips", "TCP", DOMAIN)).andReturn(null);
expect(nu.getSRVRecords("sip", "TCP", DOMAIN)).andReturn(null);
expect(nu.getSRVRecords("sip", "UDP", DOMAIN)).andReturn(null);
expect(nu.getAandAAAARecords(DOMAIN, 5060))
.andReturn(new InetSocketAddress[]{a1});
replay(nu);
assertTrue(apd.getNextAddress());
assertEquals(a1, apd.getAddress());
assertEquals("UDP", apd.getTransport());
assertFalse(apd.getNextAddress());
verify(account, nu);
}
public void testTwoA() throws ParseException, DnssecException
{
expect(nu.getNAPTRRecords(DOMAIN)).andReturn(new String[][]{});
expect(nu.getSRVRecords("sips", "TCP", DOMAIN)).andReturn(null);
expect(nu.getSRVRecords("sip", "TCP", DOMAIN)).andReturn(null);
expect(nu.getSRVRecords("sip", "UDP", DOMAIN)).andReturn(null);
expect(nu.getAandAAAARecords(DOMAIN, 5060))
.andReturn(new InetSocketAddress[]{a1, a2});
replay(nu);
assertTrue(apd.getNextAddress());
assertEquals(a1, apd.getAddress());
assertEquals("UDP", apd.getTransport());
assertTrue(apd.getNextAddress());
assertEquals(a2, apd.getAddress());
assertEquals("UDP", apd.getTransport());
assertFalse(apd.getNextAddress());
verify(account, nu);
}
public void testNotReturningSameAddressTwice()
throws ParseException,
DnssecException
{
expect(srv1.getTarget()).andReturn("proxy1."+DOMAIN);
expect(srv1.getPort()).andReturn(5060);
expect(nu.getNAPTRRecords(DOMAIN)).andReturn(new String[][]{
{"0", "udp", "_sip._udp." + DOMAIN},
{"1", "udp", "_sip._udp." + DOMAIN}
});
expect(nu.getSRVRecords("_sip._udp."+DOMAIN)).andReturn(new SRVRecord[]{
srv1
});
expect(nu.getSRVRecords("_sip._udp."+DOMAIN)).andReturn(new SRVRecord[]{
srv1
});
expect(nu.getAandAAAARecords("proxy1." + DOMAIN, 5060))
.andReturn(new InetSocketAddress[]{a1});
expect(nu.getAandAAAARecords("proxy1." + DOMAIN, 5060))
.andReturn(new InetSocketAddress[]{a1});
replay(nu, srv1);
assertTrue(apd.getNextAddress());
assertEquals(a1, apd.getAddress());
assertEquals("UDP", apd.getTransport());
assertFalse(apd.getNextAddress());
verify(account, nu, srv1);
}
}
package net.java.sip.communicator.slick.protocol.sip;
import static net.java.sip.communicator.service.protocol.ProtocolProviderFactory.USER_ID;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
import java.net.*;
import java.text.*;
import junit.framework.*;
import net.java.sip.communicator.impl.protocol.sip.*;
import net.java.sip.communicator.impl.protocol.sip.net.*;
import net.java.sip.communicator.service.dns.*;
import net.java.sip.communicator.util.*;
/**
* Tests all variations of automatic proxy detection through (simulated) DNS.
*
* @author Ingo Bauersachs
*/
public class TestAutoProxyDetection
extends TestCase
{
private static class TestedAutoProxyDetection extends AutoProxyConnection
{
public TestedAutoProxyDetection(SipAccountIDImpl account,
String defaultTransport)
{
super(account, defaultTransport);
}
@Override
public void setNetworkUtils(LocalNetworkUtils nu)
{
super.setNetworkUtils(nu);
}
public static class NetworkUtils extends LocalNetworkUtils
{
}
}
private SipAccountIDImpl account;
private TestedAutoProxyDetection.NetworkUtils nu;
private SRVRecord srv1;
private SRVRecord srv2;
private SRVRecord srv3;
private InetSocketAddress a1;
private InetSocketAddress a2;
private InetSocketAddress a3;
private InetSocketAddress a4;
private final static String DOMAIN = "example.com";
private InetAddress ia1;
private InetAddress ia2;
private InetAddress ia3;
private InetAddress ia4;
private TestedAutoProxyDetection apd;
@Override
public void setUp()
{
account = createMock(SipAccountIDImpl.class);
expect(account.getAccountPropertyString(USER_ID))
.andReturn("unit@" + DOMAIN);
replay(account);
nu = createMock(TestedAutoProxyDetection.NetworkUtils.class);
apd = new TestedAutoProxyDetection(account, "UDP");
apd.setNetworkUtils(nu);
srv1 = createMock(SRVRecord.class);
expect(srv1.getTarget()).andReturn("proxy1."+DOMAIN);
expect(srv1.getPort()).andReturn(5060);
srv2 = createMock(SRVRecord.class);
expect(srv2.getTarget()).andReturn("proxy2."+DOMAIN);
expect(srv2.getPort()).andReturn(5061);
srv3 = createMock(SRVRecord.class);
expect(srv3.getTarget()).andReturn("proxy3."+DOMAIN);
expect(srv3.getPort()).andReturn(5062);
try
{
ia1 = InetAddress.getByAddress("proxy1." + DOMAIN,
new byte[]{0x7f,0,0,1});
ia2 = InetAddress.getByAddress("proxy2." + DOMAIN,
new byte[]{0x7f,0,0,2});
ia3 = InetAddress.getByAddress("proxy3." + DOMAIN,
new byte[]{0x7f,0,0,3});
ia4 = InetAddress.getByAddress("proxy4." + DOMAIN,
new byte[]{0x7f,0,0,4});
}
catch (UnknownHostException e)
{
fail("unable to initialize: " + e.getMessage());
}
a1 = new InetSocketAddress(ia1, 5060);
a2 = new InetSocketAddress(ia2, 5061);
a3 = new InetSocketAddress(ia3, 5062);
a4 = new InetSocketAddress(ia4, 5063);
}
private void prepareOneNaptrOneSrv() throws ParseException, DnssecException
{
expect(nu.getNAPTRRecords(DOMAIN)).andReturn(new String[][]{
{"0", "udp", "_sip._udp." + DOMAIN}
});
expect(nu.getSRVRecords("_sip._udp."+DOMAIN))
.andReturn(new SRVRecord[]{ srv1 });
}
private void prepareOneNaptrTwoSrv() throws ParseException, DnssecException
{
expect(nu.getNAPTRRecords(DOMAIN)).andReturn(new String[][]{
{"0", "udp", "_sip._udp." + DOMAIN}
});
expect(nu.getSRVRecords("_sip._udp."+DOMAIN))
.andReturn(new SRVRecord[]{ srv1, srv2 });
}
public void testOneNaptrNoSrv() throws ParseException, DnssecException
{
expect(nu.getNAPTRRecords(DOMAIN)).andReturn(new String[][]{
{"0", "udp", "_sip._udp." + DOMAIN}
});
expect(nu.getSRVRecords("_sip._udp." + DOMAIN)).andReturn(null);
replay(nu);
assertFalse(apd.getNextAddress());
verify(account, nu);
}
public void testOneNaptrOneSrvOneA() throws ParseException, DnssecException
{
prepareOneNaptrOneSrv();
expect(nu.getAandAAAARecords("proxy1." + DOMAIN, 5060))
.andReturn(new InetSocketAddress[]{a1});
replay(nu, srv1);
assertTrue(apd.getNextAddress());
assertEquals(a1, apd.getAddress());
assertEquals("UDP", apd.getTransport());
assertFalse(apd.getNextAddress());
verify(account, nu, srv1);
}
public void testOneNaptrOneSrvTwoA() throws ParseException, DnssecException
{
prepareOneNaptrOneSrv();
expect(nu.getAandAAAARecords("proxy1." + DOMAIN, 5060))
.andReturn(new InetSocketAddress[]{a1, a2});
replay(nu, srv1);
assertTrue(apd.getNextAddress());
assertEquals(a1, apd.getAddress());
assertEquals("UDP", apd.getTransport());
assertTrue(apd.getNextAddress());
assertEquals(a2, apd.getAddress());
assertEquals("UDP", apd.getTransport());
assertFalse(apd.getNextAddress());
verify(account, nu, srv1);
}
//-----------------------
public void testOneNaptrTwoSrvOneA() throws ParseException, DnssecException
{
prepareOneNaptrTwoSrv();
expect(nu.getAandAAAARecords("proxy1." + DOMAIN, 5060))
.andReturn(new InetSocketAddress[]{a1});
expect(nu.getAandAAAARecords("proxy2." + DOMAIN, 5061))
.andReturn(new InetSocketAddress[]{a2});
replay(nu, srv1, srv2);
assertTrue(apd.getNextAddress());
assertEquals(a1, apd.getAddress());
assertEquals("UDP", apd.getTransport());
assertTrue(apd.getNextAddress());
assertEquals(a2, apd.getAddress());
assertEquals("UDP", apd.getTransport());
assertFalse(apd.getNextAddress());
verify(account, nu, srv1, srv2);
}
public void testOneNaptrTwoSrvTwoA() throws ParseException, DnssecException
{
prepareOneNaptrTwoSrv();
expect(nu.getAandAAAARecords("proxy1." + DOMAIN, 5060))
.andReturn(new InetSocketAddress[]{a1, a2});
expect(nu.getAandAAAARecords("proxy2." + DOMAIN, 5061))
.andReturn(new InetSocketAddress[]{a3, a4});
replay(nu, srv1, srv2);
assertTrue(apd.getNextAddress());
assertEquals(a1, apd.getAddress());
assertEquals("UDP", apd.getTransport());
assertTrue(apd.getNextAddress());
assertEquals(a2, apd.getAddress());
assertEquals("UDP", apd.getTransport());
assertTrue(apd.getNextAddress());
assertEquals(a3, apd.getAddress());
assertEquals("UDP", apd.getTransport());
assertTrue(apd.getNextAddress());
assertEquals(a4, apd.getAddress());
assertEquals("UDP", apd.getTransport());
assertFalse(apd.getNextAddress());
verify(account, nu, srv1, srv2);
}
//-------------------
public void testThreeNaptrOneSrvEachOneAEach()
throws ParseException,
DnssecException
{
expect(nu.getNAPTRRecords(DOMAIN)).andReturn(new String[][]{
{"0", "udp", "_sip._udp." + DOMAIN},
{"0", "tcp", "_sip._tcp." + DOMAIN},
{"0", "tls", "_sips._tcp." + DOMAIN}
});
expect(nu.getSRVRecords("_sip._udp."+DOMAIN))
.andReturn(new SRVRecord[]{ srv1 });
expect(nu.getSRVRecords("_sip._tcp."+DOMAIN))
.andReturn(new SRVRecord[]{ srv2 });
expect(nu.getSRVRecords("_sips._tcp."+DOMAIN))
.andReturn(new SRVRecord[]{ srv3 });
expect(nu.getAandAAAARecords("proxy1." + DOMAIN, 5060))
.andReturn(new InetSocketAddress[]{a1});
expect(nu.getAandAAAARecords("proxy2." + DOMAIN, 5061))
.andReturn(new InetSocketAddress[]{a1});
expect(nu.getAandAAAARecords("proxy3." + DOMAIN, 5062))
.andReturn(new InetSocketAddress[]{a1});
replay(nu, srv1, srv2, srv3);
assertTrue(apd.getNextAddress());
assertEquals(a1, apd.getAddress());
assertEquals("UDP", apd.getTransport());
assertTrue(apd.getNextAddress());
assertEquals(a1, apd.getAddress());
assertEquals("TCP", apd.getTransport());
assertTrue(apd.getNextAddress());
assertEquals(a1, apd.getAddress());
assertEquals("TLS", apd.getTransport());
assertFalse(apd.getNextAddress());
verify(account, nu, srv1, srv2, srv3);
}
//-----------------------
public void testNoSrvOneA() throws ParseException, DnssecException
{
expect(nu.getNAPTRRecords(DOMAIN)).andReturn(new String[][]{});
expect(nu.getSRVRecords("sips", "TCP", DOMAIN)).andReturn(null);
expect(nu.getSRVRecords("sip", "TCP", DOMAIN)).andReturn(null);
expect(nu.getSRVRecords("sip", "UDP", DOMAIN)).andReturn(null);
expect(nu.getAandAAAARecords(DOMAIN, 5060))
.andReturn(new InetSocketAddress[]{a1});
replay(nu);
assertTrue(apd.getNextAddress());
assertEquals(a1, apd.getAddress());
assertEquals("UDP", apd.getTransport());
assertFalse(apd.getNextAddress());
verify(account, nu);
}
public void testOneSrvNoA() throws ParseException, DnssecException
{
expect(nu.getNAPTRRecords(DOMAIN)).andReturn(new String[][]{});
expect(nu.getSRVRecords("sips", "TCP", DOMAIN)).andReturn(null);
expect(nu.getSRVRecords("sip", "TCP", DOMAIN)).andReturn(null);
expect(nu.getSRVRecords("sip", "UDP", DOMAIN))
.andReturn(new SRVRecord[]{srv1});
expect(nu.getAandAAAARecords("proxy1." + DOMAIN, 5060))
.andReturn(null);
replay(nu, srv1);
assertFalse(apd.getNextAddress());
verify(account, nu, srv1);
}
public void testOneSrvOneA() throws ParseException, DnssecException
{
expect(nu.getNAPTRRecords(DOMAIN)).andReturn(new String[][]{});
expect(nu.getSRVRecords("sips", "TCP", DOMAIN)).andReturn(null);
expect(nu.getSRVRecords("sip", "TCP", DOMAIN)).andReturn(null);
expect(nu.getSRVRecords("sip", "UDP", DOMAIN))
.andReturn(new SRVRecord[]{srv1});
expect(nu.getAandAAAARecords("proxy1." + DOMAIN, 5060))
.andReturn(new InetSocketAddress[]{a1});
replay(nu, srv1);
assertTrue(apd.getNextAddress());
assertEquals(a1, apd.getAddress());
assertEquals("UDP", apd.getTransport());
assertFalse(apd.getNextAddress());
verify(account, nu, srv1);
}
public void testOneSrvTwoA() throws ParseException, DnssecException
{
expect(nu.getNAPTRRecords(DOMAIN)).andReturn(new String[][]{});
expect(nu.getSRVRecords("sips", "TCP", DOMAIN)).andReturn(null);
expect(nu.getSRVRecords("sip", "TCP", DOMAIN)).andReturn(null);
expect(nu.getSRVRecords("sip", "UDP", DOMAIN))
.andReturn(new SRVRecord[]{srv1});
expect(nu.getAandAAAARecords("proxy1." + DOMAIN, 5060))
.andReturn(new InetSocketAddress[]{a1, a2});
replay(nu, srv1);
assertTrue(apd.getNextAddress());
assertEquals(a1, apd.getAddress());
assertEquals("UDP", apd.getTransport());
assertTrue(apd.getNextAddress());
assertEquals(a2, apd.getAddress());
assertEquals("UDP", apd.getTransport());
assertFalse(apd.getNextAddress());
verify(account, nu, srv1);
}
public void testTwoSrvOneA() throws ParseException, DnssecException
{
expect(nu.getNAPTRRecords(DOMAIN)).andReturn(new String[][]{});
expect(nu.getSRVRecords("sips", "TCP", DOMAIN))
.andReturn(new SRVRecord[]{srv2});
expect(nu.getSRVRecords("sip", "TCP", DOMAIN)).andReturn(null);
expect(nu.getSRVRecords("sip", "UDP", DOMAIN))
.andReturn(new SRVRecord[]{srv1});
expect(nu.getAandAAAARecords("proxy1." + DOMAIN, 5060))
.andReturn(new InetSocketAddress[]{a1});
expect(nu.getAandAAAARecords("proxy2." + DOMAIN, 5061))
.andReturn(new InetSocketAddress[]{a2});
replay(nu, srv1, srv2);
assertTrue(apd.getNextAddress());
assertEquals(a2, apd.getAddress());
assertEquals("TLS", apd.getTransport());
assertTrue(apd.getNextAddress());
assertEquals(a1, apd.getAddress());
assertEquals("UDP", apd.getTransport());
assertFalse(apd.getNextAddress());
verify(account, nu, srv1, srv2);
}
public void testTwoSameSrvOneA() throws ParseException, DnssecException
{
expect(nu.getNAPTRRecords(DOMAIN)).andReturn(new String[][]{});
expect(nu.getSRVRecords("sips", "TCP", DOMAIN))
.andReturn(new SRVRecord[]{srv1, srv2});
expect(nu.getSRVRecords("sip", "TCP", DOMAIN)).andReturn(null);
expect(nu.getSRVRecords("sip", "UDP", DOMAIN)).andReturn(null);
expect(nu.getAandAAAARecords("proxy1." + DOMAIN, 5060))
.andReturn(new InetSocketAddress[]{a1});
expect(nu.getAandAAAARecords("proxy2." + DOMAIN, 5061))
.andReturn(new InetSocketAddress[]{a2});
replay(nu, srv1, srv2);
assertTrue(apd.getNextAddress());
assertEquals(a1, apd.getAddress());
assertEquals("TLS", apd.getTransport());
assertEquals(5060, apd.getAddress().getPort());
assertTrue(apd.getNextAddress());
assertEquals(a2, apd.getAddress());
assertEquals("TLS", apd.getTransport());
assertEquals(5061, apd.getAddress().getPort());
assertFalse(apd.getNextAddress());
verify(account, nu, srv1, srv2);
}
//----------------------
public void testNoA() throws ParseException, DnssecException
{
expect(nu.getNAPTRRecords(DOMAIN)).andReturn(new String[][]{});
expect(nu.getSRVRecords("sips", "TCP", DOMAIN)).andReturn(null);
expect(nu.getSRVRecords("sip", "TCP", DOMAIN)).andReturn(null);
expect(nu.getSRVRecords("sip", "UDP", DOMAIN)).andReturn(null);
expect(nu.getAandAAAARecords(DOMAIN, 5060))
.andReturn(new InetSocketAddress[]{});
replay(nu);
assertFalse(apd.getNextAddress());
verify(account, nu);
}
public void testOneA() throws ParseException, DnssecException
{
expect(nu.getNAPTRRecords(DOMAIN)).andReturn(new String[][]{});
expect(nu.getSRVRecords("sips", "TCP", DOMAIN)).andReturn(null);
expect(nu.getSRVRecords("sip", "TCP", DOMAIN)).andReturn(null);
expect(nu.getSRVRecords("sip", "UDP", DOMAIN)).andReturn(null);
expect(nu.getAandAAAARecords(DOMAIN, 5060))
.andReturn(new InetSocketAddress[]{a1});
replay(nu);
assertTrue(apd.getNextAddress());
assertEquals(a1, apd.getAddress());
assertEquals("UDP", apd.getTransport());
assertFalse(apd.getNextAddress());
verify(account, nu);
}
public void testTwoA() throws ParseException, DnssecException
{
expect(nu.getNAPTRRecords(DOMAIN)).andReturn(new String[][]{});
expect(nu.getSRVRecords("sips", "TCP", DOMAIN)).andReturn(null);
expect(nu.getSRVRecords("sip", "TCP", DOMAIN)).andReturn(null);
expect(nu.getSRVRecords("sip", "UDP", DOMAIN)).andReturn(null);
expect(nu.getAandAAAARecords(DOMAIN, 5060))
.andReturn(new InetSocketAddress[]{a1, a2});
replay(nu);
assertTrue(apd.getNextAddress());
assertEquals(a1, apd.getAddress());
assertEquals("UDP", apd.getTransport());
assertTrue(apd.getNextAddress());
assertEquals(a2, apd.getAddress());
assertEquals("UDP", apd.getTransport());
assertFalse(apd.getNextAddress());
verify(account, nu);
}
public void testNotReturningSameAddressTwice()
throws ParseException,
DnssecException
{
expect(srv1.getTarget()).andReturn("proxy1."+DOMAIN);
expect(srv1.getPort()).andReturn(5060);
expect(nu.getNAPTRRecords(DOMAIN)).andReturn(new String[][]{
{"0", "udp", "_sip._udp." + DOMAIN},
{"1", "udp", "_sip._udp." + DOMAIN}
});
expect(nu.getSRVRecords("_sip._udp."+DOMAIN)).andReturn(new SRVRecord[]{
srv1
});
expect(nu.getSRVRecords("_sip._udp."+DOMAIN)).andReturn(new SRVRecord[]{
srv1
});
expect(nu.getAandAAAARecords("proxy1." + DOMAIN, 5060))
.andReturn(new InetSocketAddress[]{a1});
expect(nu.getAandAAAARecords("proxy1." + DOMAIN, 5060))
.andReturn(new InetSocketAddress[]{a1});
replay(nu, srv1);
assertTrue(apd.getNextAddress());
assertEquals(a1, apd.getAddress());
assertEquals("UDP", apd.getTransport());
assertFalse(apd.getNextAddress());
verify(account, nu, srv1);
}
}

Loading…
Cancel
Save