Search in sources :

Example 11 with ServiceLocationException

use of ch.ethz.iks.slp.ServiceLocationException in project ecf by eclipse.

the class AuthenticatedURL method getAuthData.

/**
 * get the byte representation of the authentication data.
 *
 * @param spi
 *            the SPI string as defined in RFC 2608
 * @param timestamp
 *            a timestamp as defined in RFC 2608
 * @return a byte array.
 * @throws ServiceLocationException
 *             in case of internal errors.
 */
private byte[] getAuthData(final String spi, final int timestamp) throws ServiceLocationException {
    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        DataOutputStream dos = new DataOutputStream(bos);
        byte[] temp = spi.getBytes();
        dos.writeShort(temp.length);
        dos.write(temp);
        temp = toString().getBytes();
        dos.writeShort(temp.length);
        dos.write(temp);
        dos.writeInt(timestamp);
        return bos.toByteArray();
    } catch (IOException ioe) {
        throw new ServiceLocationException(ServiceLocationException.INTERNAL_SYSTEM_ERROR, ioe.getMessage());
    }
}
Also used : DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ServiceLocationException(ch.ethz.iks.slp.ServiceLocationException)

Example 12 with ServiceLocationException

use of ch.ethz.iks.slp.ServiceLocationException in project ecf by eclipse.

the class AuthenticationBlock method verify.

/**
 * verify the authBlock.
 *
 * @param verData
 *            the auth data.
 * @return true if verification suceeds.
 * @throws ServiceLocationException
 *             in case of IO errors.
 */
boolean verify(final byte[] verData) throws ServiceLocationException {
    try {
        PublicKey publicKey = SLPCore.CONFIG.getPublicKey(spi);
        Signature signature = Signature.getInstance("SHA1withDSA");
        signature.initVerify(publicKey);
        signature.update(verData);
        boolean success = signature.verify(sig);
        SLPCore.platform.logDebug((success ? "Verified with SPI: " : "Verification failed with SPI: ") + spi);
        return success;
    } catch (Exception e) {
        SLPCore.platform.logError(e.getMessage(), e.fillInStackTrace());
        throw new ServiceLocationException(ServiceLocationException.AUTHENTICATION_FAILED, "Could not verify data with SPI: " + spi);
    }
}
Also used : PublicKey(java.security.PublicKey) Signature(java.security.Signature) ServiceLocationException(ch.ethz.iks.slp.ServiceLocationException) IOException(java.io.IOException) ServiceLocationException(ch.ethz.iks.slp.ServiceLocationException)

Example 13 with ServiceLocationException

use of ch.ethz.iks.slp.ServiceLocationException in project ecf by eclipse.

the class LocatorImpl method sendRequest.

/**
 * send a request. Uses direct communication to a DA or multicast
 * convergence, if no DA is known for the specific scope.
 *
 * @param req
 *            the request.
 * @param scopeList
 *            the scopes.
 * @return the list of results.
 * @throws ServiceLocationException
 *             if something goes wrong.
 */
private List sendRequest(final RequestMessage req, final List scopeList) throws ServiceLocationException {
    List scopes = scopeList != null ? scopeList : Arrays.asList(new String[] { "default" });
    ArrayList result = new ArrayList();
    for (Iterator scopeIter = scopes.iterator(); scopeIter.hasNext(); ) {
        String scope = (String) scopeIter.next();
        scope = scope.toLowerCase();
        List dAs = (List) SLPCore.dAs.get(scope);
        SLPCore.platform.logDebug("DAS FOR SCOPE " + scope + ": " + dAs);
        // try to find one
        if ((dAs == null || dAs.isEmpty()) && !SLPCore.noDiscovery) {
            SLPCore.daLookup(Arrays.asList(new String[] { scope }));
            // wait a short time for incoming replies
            synchronized (SLPCore.dAs) {
                try {
                    SLPCore.dAs.wait(SLPCore.CONFIG.getWaitTime() / 4);
                } catch (InterruptedException e) {
                    SLPCore.platform.logError(e.getMessage(), e);
                    // Restore the interrupted status as we're not the owner of the current thread
                    Thread.currentThread().interrupt();
                }
            }
            dAs = (List) SLPCore.dAs.get(scope);
        }
        if (dAs != null && !dAs.isEmpty()) {
            // a DA is known for this scope, so contact it
            try {
                result.addAll(sendRequestToDA(req, dAs));
            } catch (ServiceLocationException slp) {
                result.addAll(SLPCore.multicastConvergence(req));
            }
            continue;
        } else {
            if (SLPCore.noDiscovery) {
                throw new ServiceLocationException(ServiceLocationException.SCOPE_NOT_SUPPORTED, "Scope " + scope + " is not supported");
            }
            // still no DA available, use multicast
            result.addAll(SLPCore.multicastConvergence(req));
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) ServiceLocationException(ch.ethz.iks.slp.ServiceLocationException)

Example 14 with ServiceLocationException

use of ch.ethz.iks.slp.ServiceLocationException in project ecf by eclipse.

the class JSLPDiscoveryContainer method getServiceTypes.

/* (non-Javadoc)
	 * @see org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#getServiceTypes()
	 */
public IServiceTypeID[] getServiceTypes() {
    Set result = new HashSet();
    try {
        List aList = Activator.getDefault().getLocator().getServiceURLs((String) null, null);
        for (Iterator itr = aList.iterator(); itr.hasNext(); ) {
            ServiceURL serviceURL = (ServiceURL) itr.next();
            IServiceTypeID serviceTypeId = (IServiceTypeID) getConnectNamespace().createInstance(new Object[] { serviceURL, new String[] {} });
            result.add(serviceTypeId);
        }
    } catch (ServiceLocationException e) {
        // $NON-NLS-1$
        Trace.catching(Activator.PLUGIN_ID, JSLPDebugOptions.EXCEPTIONS_CATCHING, this.getClass(), "getServiceTypes(int)", e);
    } catch (IDCreateException e) {
        // $NON-NLS-1$
        Trace.catching(Activator.PLUGIN_ID, JSLPDebugOptions.EXCEPTIONS_CATCHING, this.getClass(), "getServiceTypes(int)", e);
    }
    return (IServiceTypeID[]) result.toArray(new IServiceTypeID[result.size()]);
}
Also used : ServiceURL(ch.ethz.iks.slp.ServiceURL) ServiceLocationException(ch.ethz.iks.slp.ServiceLocationException)

Example 15 with ServiceLocationException

use of ch.ethz.iks.slp.ServiceLocationException in project ecf by eclipse.

the class AttributeParserTest method testBadTag.

public void testBadTag() {
    SLPTestMessage stm = new SLPTestMessage();
    // #bad-tag 		= CR / LF / HTAB / "_";
    List inputs = new ArrayList();
    inputs.add("(bad_tag=foo)");
    inputs.add("(bat\ttag=foo)");
    inputs.add("(bad\rtag=foo)");
    inputs.add("(bad\ntag=foo)");
    for (Iterator iterator = inputs.iterator(); iterator.hasNext(); ) {
        String input = (String) iterator.next();
        try {
            stm.attributeStringToList(input);
        } catch (ServiceLocationException e) {
            continue;
        }
        fail("Input " + input + " must throw an Exception");
    }
}
Also used : ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) ServiceLocationException(ch.ethz.iks.slp.ServiceLocationException)

Aggregations

ServiceLocationException (ch.ethz.iks.slp.ServiceLocationException)29 IOException (java.io.IOException)15 ArrayList (java.util.ArrayList)14 List (java.util.List)13 InterruptedIOException (java.io.InterruptedIOException)6 Iterator (java.util.Iterator)6 DataOutputStream (java.io.DataOutputStream)5 ProtocolException (java.net.ProtocolException)5 SocketException (java.net.SocketException)5 ServiceURL (ch.ethz.iks.slp.ServiceURL)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 DatagramPacket (java.net.DatagramPacket)4 UnknownHostException (java.net.UnknownHostException)4 ServiceType (ch.ethz.iks.slp.ServiceType)3 DataInputStream (java.io.DataInputStream)3 DatagramSocket (java.net.DatagramSocket)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 BindException (java.net.BindException)2 InetAddress (java.net.InetAddress)2 MulticastSocket (java.net.MulticastSocket)2