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());
}
}
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);
}
}
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;
}
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()]);
}
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");
}
}
Aggregations