use of ch.ethz.iks.slp.ServiceLocationException in project ecf by eclipse.
the class SelfDiscoveryTest method setUp.
/* (non-Javadoc)
* @see junit.framework.TestCase#setUp()
*/
public void setUp() throws InterruptedException {
try {
service = new ServiceURL("service:osgi://" + HOST_AND_PORT, 10800);
int i = 0;
properties = new Hashtable();
properties.put("attr", Boolean.FALSE);
properties.put("attr" + i++, "value");
properties.put("attr" + i++, "foo,bar");
properties.put("attr" + i++, "foo:bar");
properties.put("attr" + i++, "foo bar");
TestActivator.advertiser.register(service, properties);
} catch (ServiceLocationException e) {
Assert.fail(e.getMessage());
e.printStackTrace();
}
}
use of ch.ethz.iks.slp.ServiceLocationException in project ecf by eclipse.
the class AuthenticationBlock method parse.
/**
* parse a AuthenticationBlock array.
*
* @param input
* the DataInput.
* @return a AuthenticationBlock array.
* @throws ServiceLocationException
* in case of parse / IO errors.
* @throws IOException
* @throws ServiceLocationException
*/
static AuthenticationBlock[] parse(final DataInputStream input) throws IOException, ServiceLocationException {
List blocks = new ArrayList();
short blockCount = (short) input.readByte();
for (int i = 0; i < blockCount; i++) {
AuthenticationBlock authBlock = new AuthenticationBlock();
short bsd = (short) input.readShort();
if (bsd != BSD_DSA) {
throw new ServiceLocationException(ServiceLocationException.AUTHENTICATION_FAILED, "BSD " + bsd + " is not supported.");
}
int size = input.readShort();
authBlock.timestamp = input.readInt();
authBlock.spi = input.readUTF();
authBlock.sig = new byte[size - 2 - 2 - 4 - 2 - authBlock.spi.getBytes().length];
try {
input.readFully(authBlock.sig);
} catch (IOException ioe) {
throw new ServiceLocationException(ServiceLocationException.PARSE_ERROR, ioe.getMessage());
}
blocks.add(authBlock);
}
if (!SLPCore.CONFIG.getSecurityEnabled()) {
return new AuthenticationBlock[0];
}
return (AuthenticationBlock[]) blocks.toArray(new AuthenticationBlock[0]);
}
use of ch.ethz.iks.slp.ServiceLocationException in project ecf by eclipse.
the class AuthenticationBlock method sign.
/**
* sign the AuthenticationBlock.
*
* @throws ServiceLocationException
* in case of processing errors.
*/
private void sign() throws ServiceLocationException {
try {
PrivateKey privateKey = SLPCore.CONFIG.getPrivateKey(spi);
SLPCore.platform.logDebug("Signing with SPI: " + spi);
Signature signature = Signature.getInstance("SHA1withDSA");
signature.initSign(privateKey);
signature.update(data);
sig = signature.sign();
} catch (Exception e) {
SLPCore.platform.logError(e.getMessage(), e.fillInStackTrace());
throw new ServiceLocationException(ServiceLocationException.AUTHENTICATION_FAILED, "Could not sign data");
}
}
use of ch.ethz.iks.slp.ServiceLocationException in project ecf by eclipse.
the class DAAdvertisement method getAuthData.
/**
* get the authentication data.
*
* @param spiStr
* the SPI
* @param timestamp
* the timestamp
* @return the authentication data.
* @throws ServiceLocationException
* in case of IO errors.
*/
private byte[] getAuthData(final String spiStr, final int timestamp) throws ServiceLocationException {
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos);
dos.writeUTF(spiStr);
dos.writeInt(statelessBootTimestamp);
dos.writeUTF(origURL);
/*
* THIS IS WRONG: RFC 2608 wants the attrs first, followed by the
* scopes but OpenSLP makes it the other way around !!!
*
* see bug #1346056
*/
dos.writeUTF(origScopes);
dos.writeUTF(origAttrs);
dos.writeUTF(spi);
dos.writeInt(timestamp);
return bos.toByteArray();
} catch (IOException ioe) {
throw new ServiceLocationException(ServiceLocationException.INTERNAL_SYSTEM_ERROR, ioe.getMessage());
}
}
Aggregations