Search in sources :

Example 26 with ServiceLocationException

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();
    }
}
Also used : Hashtable(java.util.Hashtable) ServiceURL(ch.ethz.iks.slp.ServiceURL) ServiceLocationException(ch.ethz.iks.slp.ServiceLocationException)

Example 27 with ServiceLocationException

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]);
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ServiceLocationException(ch.ethz.iks.slp.ServiceLocationException)

Example 28 with ServiceLocationException

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");
    }
}
Also used : PrivateKey(java.security.PrivateKey) Signature(java.security.Signature) ServiceLocationException(ch.ethz.iks.slp.ServiceLocationException) IOException(java.io.IOException) ServiceLocationException(ch.ethz.iks.slp.ServiceLocationException)

Example 29 with ServiceLocationException

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());
    }
}
Also used : DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) 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