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;

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.DefaultBootstrapManager;
import org.kaaproject.kaa.client.channel.BootstrapTransport;
import org.kaaproject.kaa.client.channel.ConfigurationTransport;
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.KaaDataChannel;
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.TransportProtocolId;
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.impl.DefaultBootstrapDataProcessor;
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.channels.DefaultBootstrapChannel;
import org.kaaproject.kaa.client.channel.impl.channels.DefaultOperationTcpChannel;
Expand Down Expand Up @@ -101,24 +92,30 @@
import org.slf4j.Logger;
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>
* Abstract class that holds general elements of Kaa library.
* </p>
*
* <p>
* This class creates and binds Kaa library modules. Public access to each
* module is performed using {@link KaaClient} interface.
* </p>
*
* <p>
* Http client ({@link AbstractHttpClient}) is used to provide basic
* communication with Bootstrap and Operation servers using HTTP protocol.
* </p>
*
* @author Yaroslav Zeygerman
* @author Andrew Shvayka
*
* @see KaaClient
* @see AbstractHttpClient
* @see PersistentStorage
Expand Down Expand Up @@ -155,7 +152,7 @@ protected enum State {
STARTED,
PAUSED,
STOPPED
};
}

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 {
this(context, listener, false);
}

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

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

if (context.getProperties() != null) {
this.properties = context.getProperties();
} else {
Expand All @@ -194,7 +198,8 @@ protected void setClientState(State state) {
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);

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

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

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

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

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

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

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

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

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

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.KaaRuntimeException;
import org.kaaproject.kaa.client.exceptions.KaaUnsupportedPlatformException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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

/**
* Creates new Kaa client based on {@link KaaClientPlatformContext platform
* context} and optional {@link KaaClientStateListener state listener}.
*
* @author Andrew Shvayka
*
* @author Andrew Shvayka
*/
public class Kaa {
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 {
return newClient(context, listener, false);
}

public static KaaClient newClient(KaaClientPlatformContext context, KaaClientStateListener listener, boolean isUserKeyStrategy)
throws KaaRuntimeException {
try {
return new BaseKaaClient(context, listener);
return new BaseKaaClient(context, listener, isUserKeyStrategy);
} catch (GeneralSecurityException e) {
LOG.error("Failed to create Kaa client", e);
throw new KaaUnsupportedPlatformException(e);
} catch (IOException 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;

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.IOException;
import java.nio.ByteBuffer;
Expand All @@ -29,17 +40,6 @@
import java.util.Properties;
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;

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

private static Properties loadProperties(String propsLocation) throws IOException {
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) {
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);
}
}

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

package org.kaaproject.kaa.client.bootstrap;

import java.util.List;

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.TransportProtocolId;
import org.kaaproject.kaa.client.channel.failover.FailoverManager;
import org.kaaproject.kaa.client.channel.failover.FailoverStatus;
import org.kaaproject.kaa.client.transport.TransportException;
import org.kaaproject.kaa.common.endpoint.gen.ProtocolMetaData;

import java.util.List;

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

/**
* Receives the latest list of servers from the bootstrap server.
*
* @throws TransportException the transport exception
*/
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}
*
* @param transportId of the transport protocol.
* @param status failover status
* @see TransportProtocolId
*/
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.
*
* @param accessPointId endpoint's DNS.
*
*/
void useNextOperationsServerByAccessPointId(int accessPointId);

Expand Down

0 comments on commit 136e775

Please sign in to comment.