Skip to content

Commit

Permalink
app-1231 avoid key generation + test
Browse files Browse the repository at this point in the history
  • Loading branch information
maxml committed Jul 5, 2016
1 parent 1ca9993 commit 136e775
Show file tree
Hide file tree
Showing 13 changed files with 282 additions and 155 deletions.
Expand Up @@ -16,21 +16,11 @@


package org.kaaproject.kaa.client; package org.kaaproject.kaa.client;


import java.io.IOException;
import java.security.GeneralSecurityException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;

import org.kaaproject.kaa.client.bootstrap.BootstrapManager; import org.kaaproject.kaa.client.bootstrap.BootstrapManager;
import org.kaaproject.kaa.client.bootstrap.DefaultBootstrapManager; import org.kaaproject.kaa.client.bootstrap.DefaultBootstrapManager;
import org.kaaproject.kaa.client.channel.BootstrapTransport; import org.kaaproject.kaa.client.channel.BootstrapTransport;
import org.kaaproject.kaa.client.channel.ConfigurationTransport; import org.kaaproject.kaa.client.channel.ConfigurationTransport;
import org.kaaproject.kaa.client.channel.EventTransport; import org.kaaproject.kaa.client.channel.EventTransport;
import org.kaaproject.kaa.client.channel.failover.FailoverManager;
import org.kaaproject.kaa.client.channel.KaaChannelManager; import org.kaaproject.kaa.client.channel.KaaChannelManager;
import org.kaaproject.kaa.client.channel.KaaDataChannel; import org.kaaproject.kaa.client.channel.KaaDataChannel;
import org.kaaproject.kaa.client.channel.KaaInternalChannelManager; import org.kaaproject.kaa.client.channel.KaaInternalChannelManager;
Expand All @@ -42,10 +32,11 @@
import org.kaaproject.kaa.client.channel.TransportConnectionInfo; import org.kaaproject.kaa.client.channel.TransportConnectionInfo;
import org.kaaproject.kaa.client.channel.TransportProtocolId; import org.kaaproject.kaa.client.channel.TransportProtocolId;
import org.kaaproject.kaa.client.channel.UserTransport; import org.kaaproject.kaa.client.channel.UserTransport;
import org.kaaproject.kaa.client.channel.failover.DefaultFailoverManager;
import org.kaaproject.kaa.client.channel.failover.FailoverManager;
import org.kaaproject.kaa.client.channel.failover.strategies.FailoverStrategy; import org.kaaproject.kaa.client.channel.failover.strategies.FailoverStrategy;
import org.kaaproject.kaa.client.channel.impl.DefaultBootstrapDataProcessor; import org.kaaproject.kaa.client.channel.impl.DefaultBootstrapDataProcessor;
import org.kaaproject.kaa.client.channel.impl.DefaultChannelManager; import org.kaaproject.kaa.client.channel.impl.DefaultChannelManager;
import org.kaaproject.kaa.client.channel.failover.DefaultFailoverManager;
import org.kaaproject.kaa.client.channel.impl.DefaultOperationDataProcessor; import org.kaaproject.kaa.client.channel.impl.DefaultOperationDataProcessor;
import org.kaaproject.kaa.client.channel.impl.channels.DefaultBootstrapChannel; import org.kaaproject.kaa.client.channel.impl.channels.DefaultBootstrapChannel;
import org.kaaproject.kaa.client.channel.impl.channels.DefaultOperationTcpChannel; import org.kaaproject.kaa.client.channel.impl.channels.DefaultOperationTcpChannel;
Expand Down Expand Up @@ -101,24 +92,30 @@
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;


import java.io.IOException;
import java.security.GeneralSecurityException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;

/** /**
* <p> * <p>
* Abstract class that holds general elements of Kaa library. * Abstract class that holds general elements of Kaa library.
* </p> * </p>
*
* <p> * <p>
* This class creates and binds Kaa library modules. Public access to each * This class creates and binds Kaa library modules. Public access to each
* module is performed using {@link KaaClient} interface. * module is performed using {@link KaaClient} interface.
* </p> * </p>
*
* <p> * <p>
* Http client ({@link AbstractHttpClient}) is used to provide basic * Http client ({@link AbstractHttpClient}) is used to provide basic
* communication with Bootstrap and Operation servers using HTTP protocol. * communication with Bootstrap and Operation servers using HTTP protocol.
* </p> * </p>
* *
* @author Yaroslav Zeygerman * @author Yaroslav Zeygerman
* @author Andrew Shvayka * @author Andrew Shvayka
*
* @see KaaClient * @see KaaClient
* @see AbstractHttpClient * @see AbstractHttpClient
* @see PersistentStorage * @see PersistentStorage
Expand Down Expand Up @@ -155,7 +152,7 @@ protected enum State {
STARTED, STARTED,
PAUSED, PAUSED,
STOPPED STOPPED
}; }


protected volatile State clientState = State.CREATED; protected volatile State clientState = State.CREATED;


Expand All @@ -176,8 +173,15 @@ protected void setClientState(State state) {
} }


AbstractKaaClient(KaaClientPlatformContext context, KaaClientStateListener listener) throws IOException, GeneralSecurityException { AbstractKaaClient(KaaClientPlatformContext context, KaaClientStateListener listener) throws IOException, GeneralSecurityException {
this(context, listener, false);
}

AbstractKaaClient(KaaClientPlatformContext context, KaaClientStateListener listener, boolean isUserKeyStrategy)
throws IOException, GeneralSecurityException {

this.context = context; this.context = context;
this.stateListener = listener; this.stateListener = listener;

if (context.getProperties() != null) { if (context.getProperties() != null) {
this.properties = context.getProperties(); this.properties = context.getProperties();
} else { } else {
Expand All @@ -194,7 +198,8 @@ protected void setClientState(State state) {
Collections.shuffle(cursor.getValue()); Collections.shuffle(cursor.getValue());
} }


kaaClientState = new KaaClientPropertiesState(context.createPersistentStorage(), context.getBase64(), this.properties); kaaClientState = new KaaClientPropertiesState(context.createPersistentStorage(), context.getBase64(),
properties, isUserKeyStrategy);


TransportContext transportContext = buildTransportContext(properties, kaaClientState); TransportContext transportContext = buildTransportContext(properties, kaaClientState);


Expand Down Expand Up @@ -365,7 +370,7 @@ private ExecutorService getLifeCycleExecutor() {
@Override @Override
public void setProfileContainer(ProfileContainer container) { public void setProfileContainer(ProfileContainer container) {
this.profileManager.setProfileContainer(container); this.profileManager.setProfileContainer(container);
}; }


@Override @Override
public void updateProfile() { public void updateProfile() {
Expand Down Expand Up @@ -506,16 +511,17 @@ public PublicKey getClientPublicKey() {
return kaaClientState.getPublicKey(); return kaaClientState.getPublicKey();
} }


@Override
public String getEndpointKeyHash() {
return kaaClientState.getEndpointKeyHash().getKeyHash();
}


@Override @Override
public PrivateKey getClientPrivateKey() { public PrivateKey getClientPrivateKey() {
return kaaClientState.getPrivateKey(); return kaaClientState.getPrivateKey();
} }


@Override
public String getEndpointKeyHash() {
return kaaClientState.getEndpointKeyHash().getKeyHash();
}

@Override @Override
public void setEndpointAccessToken(String token) { public void setEndpointAccessToken(String token) {
endpointRegistrationManager.updateEndpointAccessToken(token); endpointRegistrationManager.updateEndpointAccessToken(token);
Expand Down
Expand Up @@ -39,8 +39,14 @@
@Generated("BaseKaaClient.java.template") @Generated("BaseKaaClient.java.template")
public class BaseKaaClient extends AbstractKaaClient implements KaaClient { public class BaseKaaClient extends AbstractKaaClient implements KaaClient {


public BaseKaaClient(KaaClientPlatformContext context, KaaClientStateListener listener) throws IOException, GeneralSecurityException { public BaseKaaClient(KaaClientPlatformContext context, KaaClientStateListener listener, boolean isUserKeyStrategy)
super(context, listener); throws IOException, GeneralSecurityException {
super(context, listener, isUserKeyStrategy);
}

public BaseKaaClient(KaaClientPlatformContext context, KaaClientStateListener listener)
throws IOException, GeneralSecurityException {
super(context, listener, false);
} }


@Override @Override
Expand Down
Expand Up @@ -16,21 +16,20 @@


package org.kaaproject.kaa.client; package org.kaaproject.kaa.client;


import java.io.IOException;
import java.security.GeneralSecurityException;

import org.kaaproject.kaa.client.exceptions.KaaInvalidConfigurationException; import org.kaaproject.kaa.client.exceptions.KaaInvalidConfigurationException;
import org.kaaproject.kaa.client.exceptions.KaaRuntimeException; import org.kaaproject.kaa.client.exceptions.KaaRuntimeException;
import org.kaaproject.kaa.client.exceptions.KaaUnsupportedPlatformException; import org.kaaproject.kaa.client.exceptions.KaaUnsupportedPlatformException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;


import java.io.IOException;
import java.security.GeneralSecurityException;

/** /**
* Creates new Kaa client based on {@link KaaClientPlatformContext platform * Creates new Kaa client based on {@link KaaClientPlatformContext platform
* context} and optional {@link KaaClientStateListener state listener}. * context} and optional {@link KaaClientStateListener state listener}.
*
* @author Andrew Shvayka
* *
* @author Andrew Shvayka
*/ */
public class Kaa { public class Kaa {
private static final Logger LOG = LoggerFactory.getLogger(Kaa.class); private static final Logger LOG = LoggerFactory.getLogger(Kaa.class);
Expand All @@ -43,14 +42,19 @@ public static KaaClient newClient(KaaClientPlatformContext context) throws KaaRu
} }


public static KaaClient newClient(KaaClientPlatformContext context, KaaClientStateListener listener) throws KaaRuntimeException { public static KaaClient newClient(KaaClientPlatformContext context, KaaClientStateListener listener) throws KaaRuntimeException {
return newClient(context, listener, false);
}

public static KaaClient newClient(KaaClientPlatformContext context, KaaClientStateListener listener, boolean isUserKeyStrategy)
throws KaaRuntimeException {
try { try {
return new BaseKaaClient(context, listener); return new BaseKaaClient(context, listener, isUserKeyStrategy);
} catch (GeneralSecurityException e) { } catch (GeneralSecurityException e) {
LOG.error("Failed to create Kaa client", e); LOG.error("Failed to create Kaa client", e);
throw new KaaUnsupportedPlatformException(e); throw new KaaUnsupportedPlatformException(e);
} catch (IOException e) { } catch (IOException e) {
LOG.error("Failed to create Kaa client", e); LOG.error("Failed to create Kaa client", e);
throw new KaaInvalidConfigurationException(e); throw new KaaInvalidConfigurationException(e);
} }
} }
} }
Expand Up @@ -16,6 +16,17 @@


package org.kaaproject.kaa.client; package org.kaaproject.kaa.client;


import org.apache.commons.compress.utils.Charsets;
import org.kaaproject.kaa.client.channel.GenericTransportInfo;
import org.kaaproject.kaa.client.channel.ServerType;
import org.kaaproject.kaa.client.channel.TransportConnectionInfo;
import org.kaaproject.kaa.client.channel.TransportProtocolId;
import org.kaaproject.kaa.client.util.Base64;
import org.kaaproject.kaa.common.endpoint.gen.ProtocolMetaData;
import org.kaaproject.kaa.common.endpoint.gen.ProtocolVersionPair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
Expand All @@ -29,17 +40,6 @@
import java.util.Properties; import java.util.Properties;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;


import org.apache.commons.compress.utils.Charsets;
import org.kaaproject.kaa.client.channel.GenericTransportInfo;
import org.kaaproject.kaa.client.channel.TransportConnectionInfo;
import org.kaaproject.kaa.client.channel.ServerType;
import org.kaaproject.kaa.client.channel.TransportProtocolId;
import org.kaaproject.kaa.client.util.Base64;
import org.kaaproject.kaa.common.endpoint.gen.ProtocolMetaData;
import org.kaaproject.kaa.common.endpoint.gen.ProtocolVersionPair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.kaaproject.kaa.client.util.Utils.isBlank; import static org.kaaproject.kaa.client.util.Utils.isBlank;


/** /**
Expand Down Expand Up @@ -92,7 +92,7 @@ public KaaClientProperties(Properties properties) {


private static Properties loadProperties(String propsLocation) throws IOException { private static Properties loadProperties(String propsLocation) throws IOException {
Properties properties = null; Properties properties = null;
String propertiesLocation = isBlank(propsLocation) ? DEFAULT_CLIENT_PROPERTIES : propsLocation; String propertiesLocation = isBlank(propsLocation) ? DEFAULT_CLIENT_PROPERTIES : propsLocation;
if (System.getProperty(KAA_CLIENT_PROPERTIES_FILE) != null) { if (System.getProperty(KAA_CLIENT_PROPERTIES_FILE) != null) {
propertiesLocation = System.getProperty(KAA_CLIENT_PROPERTIES_FILE); propertiesLocation = System.getProperty(KAA_CLIENT_PROPERTIES_FILE);
} }
Expand Down Expand Up @@ -264,5 +264,4 @@ private static void checkNotBlankProperty(String fileName, String errorMessage)
throw new IllegalArgumentException(errorMessage); throw new IllegalArgumentException(errorMessage);
} }
} }

} }
Expand Up @@ -16,26 +16,26 @@


package org.kaaproject.kaa.client.bootstrap; package org.kaaproject.kaa.client.bootstrap;


import java.util.List;

import org.kaaproject.kaa.client.channel.BootstrapTransport; import org.kaaproject.kaa.client.channel.BootstrapTransport;
import org.kaaproject.kaa.client.channel.failover.FailoverManager;
import org.kaaproject.kaa.client.channel.KaaInternalChannelManager; import org.kaaproject.kaa.client.channel.KaaInternalChannelManager;
import org.kaaproject.kaa.client.channel.TransportProtocolId; import org.kaaproject.kaa.client.channel.TransportProtocolId;
import org.kaaproject.kaa.client.channel.failover.FailoverManager;
import org.kaaproject.kaa.client.channel.failover.FailoverStatus; import org.kaaproject.kaa.client.channel.failover.FailoverStatus;
import org.kaaproject.kaa.client.transport.TransportException; import org.kaaproject.kaa.client.transport.TransportException;
import org.kaaproject.kaa.common.endpoint.gen.ProtocolMetaData; import org.kaaproject.kaa.common.endpoint.gen.ProtocolMetaData;


import java.util.List;

/** /**
* Bootstrap manager manages the list of available operation servers. * Bootstrap manager manages the list of available operation servers.
* *
* @author Yaroslav Zeygerman * @author Yaroslav Zeygerman
*
*/ */
public interface BootstrapManager { public interface BootstrapManager {


/** /**
* Receives the latest list of servers from the bootstrap server. * Receives the latest list of servers from the bootstrap server.
*
* @throws TransportException the transport exception * @throws TransportException the transport exception
*/ */
void receiveOperationsServerList() throws TransportException; void receiveOperationsServerList() throws TransportException;
Expand All @@ -44,6 +44,7 @@ public interface BootstrapManager {
* Force switch to the next operations server that support given {@link TransportProtocolId} * Force switch to the next operations server that support given {@link TransportProtocolId}
* *
* @param transportId of the transport protocol. * @param transportId of the transport protocol.
* @param status failover status
* @see TransportProtocolId * @see TransportProtocolId
*/ */
void useNextOperationsServer(TransportProtocolId transportId, FailoverStatus status); void useNextOperationsServer(TransportProtocolId transportId, FailoverStatus status);
Expand All @@ -52,7 +53,6 @@ public interface BootstrapManager {
* Update the Channel Manager with endpoint's properties retrieved by its DNS. * Update the Channel Manager with endpoint's properties retrieved by its DNS.
* *
* @param accessPointId endpoint's DNS. * @param accessPointId endpoint's DNS.
*
*/ */
void useNextOperationsServerByAccessPointId(int accessPointId); void useNextOperationsServerByAccessPointId(int accessPointId);


Expand Down

0 comments on commit 136e775

Please sign in to comment.