diff --git a/client/client-multi/client-java-android/src/main/java/org/kaaproject/kaa/client/transport/AndroidHttpClient.java b/client/client-multi/client-java-android/src/main/java/org/kaaproject/kaa/client/transport/AndroidHttpClient.java index 2b9d91f955..19dde4d35d 100644 --- a/client/client-multi/client-java-android/src/main/java/org/kaaproject/kaa/client/transport/AndroidHttpClient.java +++ b/client/client-multi/client-java-android/src/main/java/org/kaaproject/kaa/client/transport/AndroidHttpClient.java @@ -24,7 +24,7 @@ import org.apache.http.entity.mime.MultipartEntity; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.util.ByteArrayBuffer; -import org.kaaproject.kaa.common.endpoint.CommonEPConstans; +import org.kaaproject.kaa.common.endpoint.CommonEpConstans; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -135,7 +135,7 @@ private byte[] getResponseBody(HttpResponse response, boolean verifyResponse) th if (verifyResponse) { Header signatureHeader = response - .getFirstHeader(CommonEPConstans.SIGNATURE_HEADER_NAME); + .getFirstHeader(CommonEpConstans.SIGNATURE_HEADER_NAME); if (signatureHeader == null) { throw new IOException("can't verify message"); diff --git a/client/client-multi/client-java-core/src/main/java/org/kaaproject/kaa/client/AbstractKaaClient.java b/client/client-multi/client-java-core/src/main/java/org/kaaproject/kaa/client/AbstractKaaClient.java index 51cb105193..1bfd4c0985 100644 --- a/client/client-multi/client-java-core/src/main/java/org/kaaproject/kaa/client/AbstractKaaClient.java +++ b/client/client-multi/client-java-core/src/main/java/org/kaaproject/kaa/client/AbstractKaaClient.java @@ -595,7 +595,7 @@ protected TransportContext buildTransportContext(KaaClientProperties properties, LogTransport logTransport = buildLogTransport(); - EndpointObjectHash publicKeyHash = EndpointObjectHash.fromSHA1(kaaClientState.getPublicKey().getEncoded()); + EndpointObjectHash publicKeyHash = EndpointObjectHash.fromSha1(kaaClientState.getPublicKey().getEncoded()); MetaDataTransport mdTransport = new DefaultMetaDataTransport(); mdTransport.setClientProperties(properties); mdTransport.setClientState(kaaClientState); diff --git a/client/client-multi/client-java-core/src/main/java/org/kaaproject/kaa/client/channel/impl/channels/HttpRequestCreator.java b/client/client-multi/client-java-core/src/main/java/org/kaaproject/kaa/client/channel/impl/channels/HttpRequestCreator.java index e88e5965e4..c756d4c786 100644 --- a/client/client-multi/client-java-core/src/main/java/org/kaaproject/kaa/client/channel/impl/channels/HttpRequestCreator.java +++ b/client/client-multi/client-java-core/src/main/java/org/kaaproject/kaa/client/channel/impl/channels/HttpRequestCreator.java @@ -17,7 +17,7 @@ package org.kaaproject.kaa.client.channel.impl.channels; import org.kaaproject.kaa.common.Constants; -import org.kaaproject.kaa.common.endpoint.CommonEPConstans; +import org.kaaproject.kaa.common.endpoint.CommonEpConstans; import org.kaaproject.kaa.common.endpoint.security.MessageEncoderDecoder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -64,11 +64,11 @@ static LinkedHashMap createHttpRequest(byte[] body, MessageEncod } LinkedHashMap requestEntity = new LinkedHashMap(); //NOSONAR if (sign) { - requestEntity.put(CommonEPConstans.REQUEST_SIGNATURE_ATTR_NAME, signature); + requestEntity.put(CommonEpConstans.REQUEST_SIGNATURE_ATTR_NAME, signature); } - requestEntity.put(CommonEPConstans.REQUEST_KEY_ATTR_NAME, requestKeyEncoded); - requestEntity.put(CommonEPConstans.REQUEST_DATA_ATTR_NAME, requestBodyEncoded); - requestEntity.put(CommonEPConstans.NEXT_PROTOCOL_ATTR_NAME, nextProtocol); + requestEntity.put(CommonEpConstans.REQUEST_KEY_ATTR_NAME, requestKeyEncoded); + requestEntity.put(CommonEpConstans.REQUEST_DATA_ATTR_NAME, requestBodyEncoded); + requestEntity.put(CommonEpConstans.NEXT_PROTOCOL_ATTR_NAME, nextProtocol); return requestEntity; } diff --git a/client/client-multi/client-java-core/src/main/java/org/kaaproject/kaa/client/channel/impl/transports/DefaultProfileTransport.java b/client/client-multi/client-java-core/src/main/java/org/kaaproject/kaa/client/channel/impl/transports/DefaultProfileTransport.java index 161a159f95..ea3a0b5bd1 100644 --- a/client/client-multi/client-java-core/src/main/java/org/kaaproject/kaa/client/channel/impl/transports/DefaultProfileTransport.java +++ b/client/client-multi/client-java-core/src/main/java/org/kaaproject/kaa/client/channel/impl/transports/DefaultProfileTransport.java @@ -52,7 +52,7 @@ public void sync() { public ProfileSyncRequest createProfileRequest() throws IOException { if (clientState != null && manager != null && properties != null) { byte[] serializedProfile = manager.getSerializedProfile(); - EndpointObjectHash currentProfileHash = EndpointObjectHash.fromSHA1(serializedProfile); + EndpointObjectHash currentProfileHash = EndpointObjectHash.fromSha1(serializedProfile); if (isProfileOutDated(currentProfileHash) || !clientState.isRegistered() || clientState.isNeedProfileResync()) { diff --git a/client/client-multi/client-java-core/src/main/java/org/kaaproject/kaa/client/configuration/base/AbstractConfigurationManager.java b/client/client-multi/client-java-core/src/main/java/org/kaaproject/kaa/client/configuration/base/AbstractConfigurationManager.java index 7e80fdadb4..aa8aa01f69 100644 --- a/client/client-multi/client-java-core/src/main/java/org/kaaproject/kaa/client/configuration/base/AbstractConfigurationManager.java +++ b/client/client-multi/client-java-core/src/main/java/org/kaaproject/kaa/client/configuration/base/AbstractConfigurationManager.java @@ -161,7 +161,7 @@ protected byte[] getDefaultConfigurationData() { private class HashContainer implements ConfigurationHashContainer { @Override public EndpointObjectHash getConfigurationHash() { - return EndpointObjectHash.fromSHA1(getConfigurationData()); + return EndpointObjectHash.fromSha1(getConfigurationData()); } } } diff --git a/client/client-multi/client-java-core/src/main/java/org/kaaproject/kaa/client/persistence/KaaClientPropertiesState.java b/client/client-multi/client-java-core/src/main/java/org/kaaproject/kaa/client/persistence/KaaClientPropertiesState.java index 9fa4c98422..0c41e852f3 100644 --- a/client/client-multi/client-java-core/src/main/java/org/kaaproject/kaa/client/persistence/KaaClientPropertiesState.java +++ b/client/client-multi/client-java-core/src/main/java/org/kaaproject/kaa/client/persistence/KaaClientPropertiesState.java @@ -410,8 +410,8 @@ private KeyPair getOrInitKeyPair(boolean isAutogeneratedKeys) { @Override public EndpointKeyHash getEndpointKeyHash() { if (keyHash == null) { - EndpointObjectHash publicKeyHash = EndpointObjectHash.fromSHA1(getOrInitKeyPair(isAutogeneratedKeys) - .getPublic().getEncoded()); + EndpointObjectHash publicKeyHash = EndpointObjectHash.fromSha1(getOrInitKeyPair(isAutogeneratedKeys) + .getPublic().getEncoded()); keyHash = new EndpointKeyHash(new String(base64.encodeBase64(publicKeyHash.getData()))); } return keyHash; diff --git a/client/client-multi/client-java-core/src/test/java/org/kaaproject/kaa/client/channel/DefaultMetaDataTransportTest.java b/client/client-multi/client-java-core/src/test/java/org/kaaproject/kaa/client/channel/DefaultMetaDataTransportTest.java index 6eb55069d2..82c2c9c62e 100644 --- a/client/client-multi/client-java-core/src/test/java/org/kaaproject/kaa/client/channel/DefaultMetaDataTransportTest.java +++ b/client/client-multi/client-java-core/src/test/java/org/kaaproject/kaa/client/channel/DefaultMetaDataTransportTest.java @@ -31,8 +31,8 @@ public class DefaultMetaDataTransportTest { public void testCreateMetaDataRequest() { KaaClientProperties properties = Mockito.mock(KaaClientProperties.class); KaaClientState state = Mockito.mock(KaaClientState.class); - Mockito.when(state.getProfileHash()).thenReturn(EndpointObjectHash.fromSHA1("123")); - EndpointObjectHash publicKeyHash = EndpointObjectHash.fromSHA1("567"); + Mockito.when(state.getProfileHash()).thenReturn(EndpointObjectHash.fromSha1("123")); + EndpointObjectHash publicKeyHash = EndpointObjectHash.fromSha1("567"); MetaDataTransport transport = new DefaultMetaDataTransport(); transport.createMetaDataRequest(); transport.setClientProperties(properties); diff --git a/client/client-multi/client-java-core/src/test/java/org/kaaproject/kaa/client/channel/DefaultProfileTransportTest.java b/client/client-multi/client-java-core/src/test/java/org/kaaproject/kaa/client/channel/DefaultProfileTransportTest.java index bf7afb4a47..d60be75e72 100644 --- a/client/client-multi/client-java-core/src/test/java/org/kaaproject/kaa/client/channel/DefaultProfileTransportTest.java +++ b/client/client-multi/client-java-core/src/test/java/org/kaaproject/kaa/client/channel/DefaultProfileTransportTest.java @@ -92,7 +92,7 @@ public void testUpToDateProfile() throws Exception { byte[] profile = new byte[]{1, 2, 3}; KaaClientState clientState = Mockito.mock(KaaClientState.class); Mockito.when(clientState.isRegistered()).thenReturn(true); - Mockito.when(clientState.getProfileHash()).thenReturn(EndpointObjectHash.fromSHA1(profile)); + Mockito.when(clientState.getProfileHash()).thenReturn(EndpointObjectHash.fromSha1(profile)); KaaClientProperties properties = Mockito.mock(KaaClientProperties.class); ProfileManager profileManager = Mockito.mock(ProfileManager.class); Mockito.when(profileManager.getSerializedProfile()).thenReturn(new byte[]{1, 2, 3}); diff --git a/client/client-multi/client-java-core/src/test/java/org/kaaproject/kaa/client/persistance/KaaClientPropertiesStateTest.java b/client/client-multi/client-java-core/src/test/java/org/kaaproject/kaa/client/persistance/KaaClientPropertiesStateTest.java index 818ac7dbfd..28432d1c6a 100644 --- a/client/client-multi/client-java-core/src/test/java/org/kaaproject/kaa/client/persistance/KaaClientPropertiesStateTest.java +++ b/client/client-multi/client-java-core/src/test/java/org/kaaproject/kaa/client/persistance/KaaClientPropertiesStateTest.java @@ -178,7 +178,7 @@ public void testRecreateKeys() throws IOException, InvalidKeyException { @Test public void testProfileHash() throws IOException { KaaClientState state = new KaaClientPropertiesState(new FilePersistentStorage(), CommonsBase64.getInstance(), getProperties()); - EndpointObjectHash hash = EndpointObjectHash.fromSHA1(new byte[]{1, 2, 3}); + EndpointObjectHash hash = EndpointObjectHash.fromSha1(new byte[]{1, 2, 3}); state.setProfileHash(hash); assertEquals(hash, state.getProfileHash()); } diff --git a/client/client-multi/client-java-desktop/src/main/java/org/kaaproject/kaa/client/transport/DesktopHttpClient.java b/client/client-multi/client-java-desktop/src/main/java/org/kaaproject/kaa/client/transport/DesktopHttpClient.java index e45cfc40a8..b5a99398ca 100644 --- a/client/client-multi/client-java-desktop/src/main/java/org/kaaproject/kaa/client/transport/DesktopHttpClient.java +++ b/client/client-multi/client-java-desktop/src/main/java/org/kaaproject/kaa/client/transport/DesktopHttpClient.java @@ -27,7 +27,7 @@ import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.util.EntityUtils; -import org.kaaproject.kaa.common.endpoint.CommonEPConstans; +import org.kaaproject.kaa.common.endpoint.CommonEpConstans; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -99,7 +99,7 @@ private byte[] getResponseBody(HttpResponse response, boolean verifyResponse) th if (verifyResponse) { Header signatureHeader = response - .getFirstHeader(CommonEPConstans.SIGNATURE_HEADER_NAME); + .getFirstHeader(CommonEpConstans.SIGNATURE_HEADER_NAME); if (signatureHeader == null) { throw new IOException("can't verify message"); diff --git a/common/endpoint-shared/src/main/java/org/kaaproject/kaa/common/bootstrap/CommonBSConstants.java b/common/endpoint-shared/src/main/java/org/kaaproject/kaa/common/bootstrap/CommonBsConstants.java similarity index 90% rename from common/endpoint-shared/src/main/java/org/kaaproject/kaa/common/bootstrap/CommonBSConstants.java rename to common/endpoint-shared/src/main/java/org/kaaproject/kaa/common/bootstrap/CommonBsConstants.java index eb500b1336..b5d6d7d73e 100644 --- a/common/endpoint-shared/src/main/java/org/kaaproject/kaa/common/bootstrap/CommonBSConstants.java +++ b/common/endpoint-shared/src/main/java/org/kaaproject/kaa/common/bootstrap/CommonBsConstants.java @@ -21,13 +21,13 @@ /** * Common Bootstrap Constants. */ -public interface CommonBSConstants extends Constants { //NOSONAR +public interface CommonBsConstants extends Constants { //NOSONAR public static final String BOOTSTRAP_DOMAIN = "BS"; //NOSONAR public static final String BOOTSTRAP_RESOLVE_COMMAND = "Resolve"; //NOSONAR - public static final String BOOTSTRAP_RESOLVE_URI = URI_DELIM + BOOTSTRAP_DOMAIN + URI_DELIM //NOSONAR - + BOOTSTRAP_RESOLVE_COMMAND; + public static final String BOOTSTRAP_RESOLVE_URI = URI_DELIM + BOOTSTRAP_DOMAIN + + URI_DELIM + BOOTSTRAP_RESOLVE_COMMAND; //NOSONAR /** * The Constant RESPONSE_TYPE. diff --git a/common/endpoint-shared/src/main/java/org/kaaproject/kaa/common/endpoint/CommonEPConstans.java b/common/endpoint-shared/src/main/java/org/kaaproject/kaa/common/endpoint/CommonEpConstans.java similarity index 90% rename from common/endpoint-shared/src/main/java/org/kaaproject/kaa/common/endpoint/CommonEPConstans.java rename to common/endpoint-shared/src/main/java/org/kaaproject/kaa/common/endpoint/CommonEpConstans.java index 76f075e740..d862e6648b 100644 --- a/common/endpoint-shared/src/main/java/org/kaaproject/kaa/common/endpoint/CommonEPConstans.java +++ b/common/endpoint-shared/src/main/java/org/kaaproject/kaa/common/endpoint/CommonEpConstans.java @@ -19,9 +19,9 @@ import org.kaaproject.kaa.common.Constants; /** - * The Interface CommonEPConstans. + * The Interface CommonEpConstans. */ -public interface CommonEPConstans extends Constants { //NOSONAR +public interface CommonEpConstans extends Constants { //NOSONAR /** * The Constant ENDPOINT_DOMAIN. @@ -36,8 +36,8 @@ public interface CommonEPConstans extends Constants { //NOSONAR /** * The Constant ENDPOINT_REGISTER_URI. */ - public static final String ENDPOINT_REGISTER_URI = URI_DELIM + ENDPOINT_DOMAIN + URI_DELIM //NOSONAR - + ENDPOINT_REGISTER_COMMAND; + public static final String ENDPOINT_REGISTER_URI = URI_DELIM + ENDPOINT_DOMAIN + //NOSONAR + URI_DELIM + ENDPOINT_REGISTER_COMMAND; /** * The Constant ENDPOINT_UPDATE_COMMAND. @@ -64,12 +64,14 @@ public interface CommonEPConstans extends Constants { //NOSONAR /** * The Constant SYNC_URI. */ - public static final String SYNC_URI = URI_DELIM + ENDPOINT_DOMAIN + URI_DELIM + SYNC_COMMAND; //NOSONAR + public static final String SYNC_URI = URI_DELIM + ENDPOINT_DOMAIN + URI_DELIM + + SYNC_COMMAND; //NOSONAR /** * The Constant SYNC_URI. */ - public static final String LONG_SYNC_URI = URI_DELIM + ENDPOINT_DOMAIN + URI_DELIM + LONG_SYNC_COMMAND; //NOSONAR + public static final String LONG_SYNC_URI = URI_DELIM + ENDPOINT_DOMAIN + URI_DELIM + + LONG_SYNC_COMMAND; //NOSONAR /** diff --git a/common/endpoint-shared/src/main/java/org/kaaproject/kaa/common/endpoint/security/KeyUtil.java b/common/endpoint-shared/src/main/java/org/kaaproject/kaa/common/endpoint/security/KeyUtil.java index e5878f372a..c942ea2bb6 100644 --- a/common/endpoint-shared/src/main/java/org/kaaproject/kaa/common/endpoint/security/KeyUtil.java +++ b/common/endpoint-shared/src/main/java/org/kaaproject/kaa/common/endpoint/security/KeyUtil.java @@ -64,7 +64,8 @@ private KeyUtil() { * @param publicKeyFile the public key file * @throws IOException Signals that an I/O exception has occurred. */ - public static void saveKeyPair(KeyPair keyPair, String privateKeyFile, String publicKeyFile) throws IOException { + public static void saveKeyPair(KeyPair keyPair, String privateKeyFile, String publicKeyFile) + throws IOException { File privateFile = makeDirs(privateKeyFile); File publicFile = makeDirs(publicKeyFile); OutputStream privateKeyOutput = null; @@ -87,7 +88,9 @@ public static void saveKeyPair(KeyPair keyPair, String privateKeyFile, String pu * @param publicKeyOutput the public key output stream * @throws IOException Signals that an I/O exception has occurred. */ - public static void saveKeyPair(KeyPair keyPair, OutputStream privateKeyOutput, OutputStream publicKeyOutput) throws IOException { + public static void saveKeyPair( + KeyPair keyPair, OutputStream privateKeyOutput, OutputStream publicKeyOutput) + throws IOException { PrivateKey privateKey = keyPair.getPrivate(); PublicKey publicKey = keyPair.getPublic(); @@ -103,15 +106,17 @@ public static void saveKeyPair(KeyPair keyPair, OutputStream privateKeyOutput, O } /** - * Create all required directories + * Create all required directories. * * @param privateKeyFile the private key file * @return the file */ private static File makeDirs(String privateKeyFile) { File privateFile = new File(privateKeyFile); - if (privateFile.getParentFile() != null && !privateFile.getParentFile().exists() && !privateFile.getParentFile().mkdirs()) { - LOG.warn("Failed to create required directories: {}", privateFile.getParentFile().getAbsolutePath()); + if (privateFile.getParentFile() != null && !privateFile.getParentFile().exists() + && !privateFile.getParentFile().mkdirs()) { + LOG.warn("Failed to create required directories: {}", + privateFile.getParentFile().getAbsolutePath()); } return privateFile; } @@ -128,8 +133,8 @@ public static KeyPair generateKeyPair(String privateKeyLocation, String publicKe KeyPair clientKeyPair = generateKeyPair(); saveKeyPair(clientKeyPair, privateKeyLocation, publicKeyLocation); return clientKeyPair; - } catch (Exception e) { - LOG.error("Error generating client key pair", e); + } catch (Exception ex) { + LOG.error("Error generating client key pair", ex); } return null; } @@ -141,13 +146,14 @@ public static KeyPair generateKeyPair(String privateKeyLocation, String publicKe * @param publicKeyOutput the public key output stream * @return the key pair */ - public static KeyPair generateKeyPair(OutputStream privateKeyOutput, OutputStream publicKeyOutput) { + public static KeyPair generateKeyPair( + OutputStream privateKeyOutput, OutputStream publicKeyOutput) { try { KeyPair clientKeyPair = generateKeyPair(); saveKeyPair(clientKeyPair, privateKeyOutput, publicKeyOutput); return clientKeyPair; - } catch (Exception e) { - LOG.error("Error generating client key pair", e); + } catch (Exception ex) { + LOG.error("Error generating client key pair", ex); } return null; } @@ -161,17 +167,17 @@ public static KeyPair generateKeyPair() throws NoSuchAlgorithmException { /** * Gets the public key from file. * - * @param f the f + * @param file the file * @return the public * @throws IOException the i/o exception * @throws InvalidKeyException invalid key exception */ - public static PublicKey getPublic(File f) throws IOException, InvalidKeyException { + public static PublicKey getPublic(File file) throws IOException, InvalidKeyException { DataInputStream dis = null; try { - FileInputStream fis = new FileInputStream(f); + FileInputStream fis = new FileInputStream(file); dis = new DataInputStream(fis); - byte[] keyBytes = new byte[(int) f.length()]; + byte[] keyBytes = new byte[(int) file.length()]; dis.readFully(keyBytes); return getPublic(keyBytes); } finally { @@ -190,9 +196,9 @@ public static PublicKey getPublic(File f) throws IOException, InvalidKeyExceptio public static PublicKey getPublic(InputStream input) throws IOException, InvalidKeyException { ByteArrayOutputStream output = new ByteArrayOutputStream(); byte[] buffer = new byte[4096]; - int n = 0; - while (-1 != (n = input.read(buffer))) { - output.write(buffer, 0, n); + int len = 0; + while (-1 != (len = input.read(buffer))) { + output.write(buffer, 0, len); } byte[] keyBytes = output.toByteArray(); @@ -211,25 +217,25 @@ public static PublicKey getPublic(byte[] keyBytes) throws InvalidKeyException { X509EncodedKeySpec spec = new X509EncodedKeySpec(keyBytes); KeyFactory kf = KeyFactory.getInstance(RSA); return kf.generatePublic(spec); - } catch (NoSuchAlgorithmException | InvalidKeySpecException e) { - throw new InvalidKeyException(e); + } catch (NoSuchAlgorithmException | InvalidKeySpecException ex) { + throw new InvalidKeyException(ex); } } /** * Gets the private key from file. * - * @param f the f + * @param file the file * @return the private * @throws IOException the i/o exception * @throws InvalidKeyException invalid key exception */ - public static PrivateKey getPrivate(File f) throws IOException, InvalidKeyException { + public static PrivateKey getPrivate(File file) throws IOException, InvalidKeyException { DataInputStream dis = null; try { - FileInputStream fis = new FileInputStream(f); + FileInputStream fis = new FileInputStream(file); dis = new DataInputStream(fis); - byte[] keyBytes = new byte[(int) f.length()]; + byte[] keyBytes = new byte[(int) file.length()]; dis.readFully(keyBytes); return getPrivate(keyBytes); } finally { @@ -248,9 +254,9 @@ public static PrivateKey getPrivate(File f) throws IOException, InvalidKeyExcept public static PrivateKey getPrivate(InputStream input) throws IOException, InvalidKeyException { ByteArrayOutputStream output = new ByteArrayOutputStream(); byte[] buffer = new byte[4096]; - int n = 0; - while (-1 != (n = input.read(buffer))) { - output.write(buffer, 0, n); + int len = 0; + while (-1 != (len = input.read(buffer))) { + output.write(buffer, 0, len); } byte[] keyBytes = output.toByteArray(); @@ -269,13 +275,13 @@ public static PrivateKey getPrivate(byte[] keyBytes) throws InvalidKeyException PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(keyBytes); KeyFactory kf = KeyFactory.getInstance(RSA); return kf.generatePrivate(spec); - } catch (NoSuchAlgorithmException | InvalidKeySpecException e) { - throw new InvalidKeyException(e); + } catch (NoSuchAlgorithmException | InvalidKeySpecException ex) { + throw new InvalidKeyException(ex); } } /** - * Validates RSA public and private key + * Validates RSA public and private key. * * @param keyPair the keypair * @return true if keys matches @@ -298,8 +304,8 @@ public static boolean validateKeyPair(KeyPair keyPair) { try { encodedPayload = encDec.encodeData(rawPayload); decodedPayload = encDec.decodeData(encodedPayload); - } catch (GeneralSecurityException e) { - LOG.error("Validation keypair error ", e); + } catch (GeneralSecurityException ex) { + LOG.error("Validation keypair error ", ex); return false; } return Arrays.equals(rawPayload, decodedPayload); diff --git a/common/endpoint-shared/src/main/java/org/kaaproject/kaa/common/endpoint/security/MessageEncoderDecoder.java b/common/endpoint-shared/src/main/java/org/kaaproject/kaa/common/endpoint/security/MessageEncoderDecoder.java index a56fea4511..44ef36a645 100644 --- a/common/endpoint-shared/src/main/java/org/kaaproject/kaa/common/endpoint/security/MessageEncoderDecoder.java +++ b/common/endpoint-shared/src/main/java/org/kaaproject/kaa/common/endpoint/security/MessageEncoderDecoder.java @@ -55,13 +55,16 @@ protected Cipher initialValue() { return cipherForAlgorithm(RSA); } }; - private static final ThreadLocal SHA1WITH_RSA_SIGNATURE = new ThreadLocal() { + private static final ThreadLocal SHA1WITH_RSA_SIGNATURE = new + ThreadLocal() { @Override protected Signature initialValue() { return signatureForAlgorithm(SHA1WITH_RSA); } }; - private static final ThreadLocal SESSION_KEY_GENERATOR = new ThreadLocal() { + + private static final ThreadLocal SESSION_KEY_GENERATOR = new + ThreadLocal() { @Override protected KeyGenerator initialValue() { return keyGeneratorForAlgorithm(SESSION_KEY_ALGORITHM, SESSION_KEY_SIZE); @@ -90,7 +93,8 @@ public MessageEncoderDecoder(PrivateKey privateKey, PublicKey publicKey) { * @param publicKey the public key * @param remotePublicKey the remote public key */ - public MessageEncoderDecoder(PrivateKey privateKey, PublicKey publicKey, PublicKey remotePublicKey) { + public MessageEncoderDecoder( + PrivateKey privateKey, PublicKey publicKey, PublicKey remotePublicKey) { super(); this.privateKey = privateKey; this.publicKey = publicKey; @@ -106,8 +110,8 @@ public MessageEncoderDecoder(PrivateKey privateKey, PublicKey publicKey, PublicK static Cipher cipherForAlgorithm(String algorithm) { try { return Cipher.getInstance(algorithm); - } catch (NoSuchAlgorithmException | NoSuchPaddingException e) { - LOG.error("Cipher init error", e); + } catch (NoSuchAlgorithmException | NoSuchPaddingException ex) { + LOG.error("Cipher init error", ex); return null; } } @@ -117,8 +121,8 @@ static KeyGenerator keyGeneratorForAlgorithm(String algorithm, int size) { KeyGenerator keyGen = KeyGenerator.getInstance(algorithm); keyGen.init(size); return keyGen; - } catch (NoSuchAlgorithmException e) { - LOG.error("Key generator init error", e); + } catch (NoSuchAlgorithmException ex) { + LOG.error("Key generator init error", ex); return null; } } @@ -126,12 +130,17 @@ static KeyGenerator keyGeneratorForAlgorithm(String algorithm, int size) { static Signature signatureForAlgorithm(String algorithm) { try { return Signature.getInstance(algorithm); - } catch (NoSuchAlgorithmException e) { - LOG.error("Signature init error", e); + } catch (NoSuchAlgorithmException ex) { + LOG.error("Signature init error", ex); return null; } } + /** + * Convert bytes to hex format. + * @param bytes the input bytes + * @return the string of converted bytes in hex format + */ public static String bytesToHex(byte[] bytes) { char[] hexChars = new char[bytes.length * 3]; for (int j = 0; j < bytes.length; j++) { @@ -312,14 +321,14 @@ public void setSessionCipherPair(CipherPair sessionCipher) { /** * Cipher Pair holds references for encoding and decoding Ciphers that are initialized with the - * same key + * same key. */ public static class CipherPair { private Cipher decCipher; private Cipher encCipher; /** - * Creates enc/dec ciphers based on cipher algorithm and secret key + * Creates enc/dec ciphers based on cipher algorithm and secret key. * * @param algorithm - Cipher algorithm * @param secretKey - Secret key diff --git a/common/endpoint-shared/src/main/java/org/kaaproject/kaa/common/hash/EndpointObjectHash.java b/common/endpoint-shared/src/main/java/org/kaaproject/kaa/common/hash/EndpointObjectHash.java index 0f83686882..50e96e5365 100644 --- a/common/endpoint-shared/src/main/java/org/kaaproject/kaa/common/hash/EndpointObjectHash.java +++ b/common/endpoint-shared/src/main/java/org/kaaproject/kaa/common/hash/EndpointObjectHash.java @@ -25,7 +25,7 @@ /** - * The class EndpointObjectHash is responsible for hash calculation + * The class EndpointObjectHash is responsible for hash calculation. * * @author Andrew Shvayka */ @@ -79,7 +79,7 @@ public static EndpointObjectHash fromBytes(byte[] data) { * @param data the data * @return the endpoint object hash */ - public static EndpointObjectHash fromSHA1(String data) { + public static EndpointObjectHash fromSha1(String data) { if (data == null) { return null; } @@ -92,7 +92,7 @@ public static EndpointObjectHash fromSHA1(String data) { * @param data the data * @return the endpoint object hash */ - public static EndpointObjectHash fromSHA1(byte[] data) { + public static EndpointObjectHash fromSha1(byte[] data) { if (data == null) { return null; } diff --git a/common/endpoint-shared/src/test/java/org/kaaproject/kaa/common/hash/EndpointObjectHashTest.java b/common/endpoint-shared/src/test/java/org/kaaproject/kaa/common/hash/EndpointObjectHashTest.java index b90fee5db5..e90de720e1 100644 --- a/common/endpoint-shared/src/test/java/org/kaaproject/kaa/common/hash/EndpointObjectHashTest.java +++ b/common/endpoint-shared/src/test/java/org/kaaproject/kaa/common/hash/EndpointObjectHashTest.java @@ -27,33 +27,33 @@ public class EndpointObjectHashTest { @Test public void deltaSameEndpointObjectHashTest() { - EndpointObjectHash hash1 = EndpointObjectHash.fromSHA1("test"); - EndpointObjectHash hash2 = EndpointObjectHash.fromSHA1("test"); + EndpointObjectHash hash1 = EndpointObjectHash.fromSha1("test"); + EndpointObjectHash hash2 = EndpointObjectHash.fromSha1("test"); Assert.assertEquals(hash1, hash2); - hash1 = EndpointObjectHash.fromSHA1("test".getBytes()); - hash2 = EndpointObjectHash.fromSHA1("test".getBytes()); + hash1 = EndpointObjectHash.fromSha1("test".getBytes()); + hash2 = EndpointObjectHash.fromSha1("test".getBytes()); Assert.assertEquals(hash1, hash2); } @Test public void deltaDifferentEndpointObjectHashTest() { - EndpointObjectHash hash1 = EndpointObjectHash.fromSHA1("test1"); - EndpointObjectHash hash2 = EndpointObjectHash.fromSHA1("test2"); + EndpointObjectHash hash1 = EndpointObjectHash.fromSha1("test1"); + EndpointObjectHash hash2 = EndpointObjectHash.fromSha1("test2"); Assert.assertNotEquals(hash1, hash2); - hash1 = EndpointObjectHash.fromSHA1("test1".getBytes()); - hash2 = EndpointObjectHash.fromSHA1("test2".getBytes()); + hash1 = EndpointObjectHash.fromSha1("test1".getBytes()); + hash2 = EndpointObjectHash.fromSha1("test2".getBytes()); Assert.assertNotEquals(hash1, hash2); } @Test public void nullEndpointObjectHashTest() { byte[] binaryData = null; - EndpointObjectHash hash1 = EndpointObjectHash.fromSHA1(binaryData); + EndpointObjectHash hash1 = EndpointObjectHash.fromSha1(binaryData); Assert.assertNull(hash1); hash1 = EndpointObjectHash.fromBytes(binaryData); Assert.assertNull(hash1); String strData = null; - hash1 = EndpointObjectHash.fromSHA1(strData); + hash1 = EndpointObjectHash.fromSha1(strData); Assert.assertNull(hash1); } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/delta/DefaultDeltaService.java b/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/delta/DefaultDeltaService.java index 9cee346cbf..967618113f 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/delta/DefaultDeltaService.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/delta/DefaultDeltaService.java @@ -369,7 +369,7 @@ public Pair compute(List key) { private ConfigurationCacheEntry buildBaseResyncDelta(String endpointId, String jsonData, String schema, EndpointObjectHash userConfigurationHash) throws IOException { byte[] configuration = GenericAvroConverter.toRawData(jsonData, schema); - return new ConfigurationCacheEntry(configuration, new BaseBinaryDelta(configuration), EndpointObjectHash.fromSHA1(configuration), + return new ConfigurationCacheEntry(configuration, new BaseBinaryDelta(configuration), EndpointObjectHash.fromSha1(configuration), userConfigurationHash); } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/profile/DefaultProfileService.java b/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/profile/DefaultProfileService.java index 7b288d18ce..c881b171db 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/profile/DefaultProfileService.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/profile/DefaultProfileService.java @@ -121,7 +121,7 @@ public EndpointProfileDto registerProfile(RegisterProfileRequest request) { String profileJson = decodeProfile(request.getProfile(), appSeqNumber.getAppToken(), sdkProfile.getProfileSchemaVersion()); - EndpointObjectHash keyHash = EndpointObjectHash.fromSHA1(request.getEndpointKey()); + EndpointObjectHash keyHash = EndpointObjectHash.fromSha1(request.getEndpointKey()); EndpointProfileDto dto = endpointService.findEndpointProfileByKeyHash(keyHash.getData()); if (dto == null) { @@ -131,7 +131,7 @@ public EndpointProfileDto registerProfile(RegisterProfileRequest request) { dto.setEndpointKey(request.getEndpointKey()); dto.setEndpointKeyHash(keyHash.getData()); dto.setClientProfileBody(profileJson); - dto.setProfileHash(EndpointObjectHash.fromSHA1(request.getProfile()).getData()); + dto.setProfileHash(EndpointObjectHash.fromSha1(request.getProfile()).getData()); try { Optional endpointRegistrationLookup = endpointRegistrationService.findEndpointRegistrationByEndpointId(endpointId); @@ -195,7 +195,7 @@ public EndpointProfileDto updateProfile(UpdateProfileRequest request) { profile.setAccessToken(request.getAccessToken()); } profile.setClientProfileBody(profileJson); - profile.setProfileHash(EndpointObjectHash.fromSHA1(request.getProfile()).getData()); + profile.setProfileHash(EndpointObjectHash.fromSha1(request.getProfile()).getData()); populateVersionStates(appSeqNumber.getTenantId(), profile, sdkProfile); profile.setGroupState(new ArrayList<>()); diff --git a/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/OperationsServiceIT.java b/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/OperationsServiceIT.java index cf341e4ed5..d1f8c5f663 100644 --- a/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/OperationsServiceIT.java +++ b/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/OperationsServiceIT.java @@ -344,7 +344,7 @@ private EndpointProfileDto registerEndpoint() throws IOException, GetDeltaExcept ClientSyncMetaData md = new ClientSyncMetaData(); md.setApplicationToken(application.getApplicationToken()); - md.setEndpointPublicKeyHash(ByteBuffer.wrap(EndpointObjectHash.fromSHA1(ENDPOINT_KEY).getData())); + md.setEndpointPublicKeyHash(ByteBuffer.wrap(EndpointObjectHash.fromSha1(ENDPOINT_KEY).getData())); md.setSdkToken(SDK_TOKEN); request.setClientSyncMetaData(md); @@ -378,7 +378,7 @@ public void basicDoubleRegistrationTest() throws GetDeltaException, IOException ClientSyncMetaData md = new ClientSyncMetaData(); md.setApplicationToken(application.getApplicationToken()); - md.setEndpointPublicKeyHash(ByteBuffer.wrap(EndpointObjectHash.fromSHA1(ENDPOINT_KEY).getData())); + md.setEndpointPublicKeyHash(ByteBuffer.wrap(EndpointObjectHash.fromSha1(ENDPOINT_KEY).getData())); md.setSdkToken(SDK_TOKEN); request.setClientSyncMetaData(md); @@ -423,8 +423,8 @@ public void basicUpdateTest() throws GetDeltaException, IOException { ClientSync request = new ClientSync(); ClientSyncMetaData md = new ClientSyncMetaData(); md.setApplicationToken(application.getApplicationToken()); - md.setEndpointPublicKeyHash(ByteBuffer.wrap(EndpointObjectHash.fromSHA1(ENDPOINT_KEY).getData())); - md.setProfileHash(ByteBuffer.wrap(EndpointObjectHash.fromSHA1(oldProfile).getData())); + md.setEndpointPublicKeyHash(ByteBuffer.wrap(EndpointObjectHash.fromSha1(ENDPOINT_KEY).getData())); + md.setProfileHash(ByteBuffer.wrap(EndpointObjectHash.fromSha1(oldProfile).getData())); md.setSdkToken(SDK_TOKEN); request.setClientSyncMetaData(md); @@ -461,8 +461,8 @@ public void basicProfileResyncTest() throws GetDeltaException, IOException { ClientSyncMetaData md = new ClientSyncMetaData(); md.setApplicationToken(application.getApplicationToken()); - md.setEndpointPublicKeyHash(ByteBuffer.wrap(EndpointObjectHash.fromSHA1(ENDPOINT_KEY).getData())); - md.setProfileHash(ByteBuffer.wrap(EndpointObjectHash.fromSHA1(profile).getData())); + md.setEndpointPublicKeyHash(ByteBuffer.wrap(EndpointObjectHash.fromSha1(ENDPOINT_KEY).getData())); + md.setProfileHash(ByteBuffer.wrap(EndpointObjectHash.fromSha1(profile).getData())); request.setClientSyncMetaData(md); ConfigurationClientSync confSyncRequest = new ConfigurationClientSync(); @@ -489,8 +489,8 @@ public void basicDeltaTest() throws GetDeltaException, IOException { ClientSyncMetaData md = new ClientSyncMetaData(); md.setApplicationToken(application.getApplicationToken()); - md.setEndpointPublicKeyHash(ByteBuffer.wrap(EndpointObjectHash.fromSHA1(ENDPOINT_KEY).getData())); - md.setProfileHash(ByteBuffer.wrap(EndpointObjectHash.fromSHA1(profile).getData())); + md.setEndpointPublicKeyHash(ByteBuffer.wrap(EndpointObjectHash.fromSha1(ENDPOINT_KEY).getData())); + md.setProfileHash(ByteBuffer.wrap(EndpointObjectHash.fromSha1(profile).getData())); request.setClientSyncMetaData(md); ConfigurationClientSync confSyncRequest = new ConfigurationClientSync(); @@ -523,8 +523,8 @@ public void basicMandatoryNotificationsTest() throws GetDeltaException, IOExcept ClientSyncMetaData md = new ClientSyncMetaData(); md.setApplicationToken(application.getApplicationToken()); - md.setEndpointPublicKeyHash(ByteBuffer.wrap(EndpointObjectHash.fromSHA1(ENDPOINT_KEY).getData())); - md.setProfileHash(ByteBuffer.wrap(EndpointObjectHash.fromSHA1(profile).getData())); + md.setEndpointPublicKeyHash(ByteBuffer.wrap(EndpointObjectHash.fromSha1(ENDPOINT_KEY).getData())); + md.setProfileHash(ByteBuffer.wrap(EndpointObjectHash.fromSha1(profile).getData())); request.setClientSyncMetaData(md); NotificationClientSync nfSyncRequest = new NotificationClientSync(); @@ -556,8 +556,8 @@ public void basicOptionalNotificationsTest() throws GetDeltaException, IOExcepti ClientSyncMetaData md = new ClientSyncMetaData(); md.setApplicationToken(application.getApplicationToken()); - md.setEndpointPublicKeyHash(ByteBuffer.wrap(EndpointObjectHash.fromSHA1(ENDPOINT_KEY).getData())); - md.setProfileHash(ByteBuffer.wrap(EndpointObjectHash.fromSHA1(profile).getData())); + md.setEndpointPublicKeyHash(ByteBuffer.wrap(EndpointObjectHash.fromSha1(ENDPOINT_KEY).getData())); + md.setProfileHash(ByteBuffer.wrap(EndpointObjectHash.fromSha1(profile).getData())); request.setClientSyncMetaData(md); NotificationClientSync nfSyncRequest = new NotificationClientSync(); @@ -596,7 +596,7 @@ private EndpointProfileDto createSecondEndpoint() throws GetDeltaException, IOEx ClientSyncMetaData md = new ClientSyncMetaData(); md.setApplicationToken(application.getApplicationToken()); - md.setEndpointPublicKeyHash(ByteBuffer.wrap(EndpointObjectHash.fromSHA1(ENDPOINT_KEY2).getData())); + md.setEndpointPublicKeyHash(ByteBuffer.wrap(EndpointObjectHash.fromSha1(ENDPOINT_KEY2).getData())); md.setSdkToken(SDK_TOKEN); request.setClientSyncMetaData(md); @@ -630,8 +630,8 @@ public void basicEndpointAttachTest() throws GetDeltaException, IOException { ClientSyncMetaData md = new ClientSyncMetaData(); md.setApplicationToken(application.getApplicationToken()); - md.setEndpointPublicKeyHash(ByteBuffer.wrap(EndpointObjectHash.fromSHA1(ENDPOINT_KEY).getData())); - md.setProfileHash(ByteBuffer.wrap(EndpointObjectHash.fromSHA1(profile).getData())); + md.setEndpointPublicKeyHash(ByteBuffer.wrap(EndpointObjectHash.fromSha1(ENDPOINT_KEY).getData())); + md.setProfileHash(ByteBuffer.wrap(EndpointObjectHash.fromSha1(profile).getData())); request.setClientSyncMetaData(md); UserClientSync userRequest = new UserClientSync(); @@ -671,8 +671,8 @@ public void basicEndpointAttachFailTest() throws GetDeltaException, IOException ClientSyncMetaData md = new ClientSyncMetaData(); md.setApplicationToken(application.getApplicationToken()); - md.setEndpointPublicKeyHash(ByteBuffer.wrap(EndpointObjectHash.fromSHA1(ENDPOINT_KEY).getData())); - md.setProfileHash(ByteBuffer.wrap(EndpointObjectHash.fromSHA1(profile).getData())); + md.setEndpointPublicKeyHash(ByteBuffer.wrap(EndpointObjectHash.fromSha1(ENDPOINT_KEY).getData())); + md.setProfileHash(ByteBuffer.wrap(EndpointObjectHash.fromSha1(profile).getData())); request.setClientSyncMetaData(md); UserClientSync userRequest = new UserClientSync(); @@ -710,12 +710,12 @@ public void basicEndpointDetachTest() throws GetDeltaException, IOException { ClientSyncMetaData md = new ClientSyncMetaData(); md.setApplicationToken(application.getApplicationToken()); - md.setEndpointPublicKeyHash(ByteBuffer.wrap(EndpointObjectHash.fromSHA1(ENDPOINT_KEY).getData())); - md.setProfileHash(ByteBuffer.wrap(EndpointObjectHash.fromSHA1(profile).getData())); + md.setEndpointPublicKeyHash(ByteBuffer.wrap(EndpointObjectHash.fromSha1(ENDPOINT_KEY).getData())); + md.setProfileHash(ByteBuffer.wrap(EndpointObjectHash.fromSha1(profile).getData())); request.setClientSyncMetaData(md); UserClientSync userRequest = new UserClientSync(); - userRequest.setEndpointDetachRequests(Collections.singletonList(new EndpointDetachRequest(REQUEST_ID1, Base64Util.encode(EndpointObjectHash.fromSHA1(ENDPOINT_KEY2).getData())))); + userRequest.setEndpointDetachRequests(Collections.singletonList(new EndpointDetachRequest(REQUEST_ID1, Base64Util.encode(EndpointObjectHash.fromSha1(ENDPOINT_KEY2).getData())))); request.setUserSync(userRequest); SyncContext context = createContext(request); @@ -748,13 +748,13 @@ public void basicEndpointDetachFailTest() throws GetDeltaException, IOException ClientSyncMetaData md = new ClientSyncMetaData(); md.setApplicationToken(application.getApplicationToken()); - md.setEndpointPublicKeyHash(ByteBuffer.wrap(EndpointObjectHash.fromSHA1(ENDPOINT_KEY).getData())); - md.setProfileHash(ByteBuffer.wrap(EndpointObjectHash.fromSHA1(profile).getData())); + md.setEndpointPublicKeyHash(ByteBuffer.wrap(EndpointObjectHash.fromSha1(ENDPOINT_KEY).getData())); + md.setProfileHash(ByteBuffer.wrap(EndpointObjectHash.fromSha1(profile).getData())); request.setClientSyncMetaData(md); UserClientSync userRequest = new UserClientSync(); userRequest.setUserAttachRequest(new UserAttachRequest(USER_VERIFIER_ID, USER_EXTERNAL_ID, USER_ACCESS_TOKEN)); - userRequest.setEndpointDetachRequests(Collections.singletonList(new EndpointDetachRequest(REQUEST_ID1, Base64Util.encode(EndpointObjectHash.fromSHA1(ENDPOINT_KEY2).getData())))); + userRequest.setEndpointDetachRequests(Collections.singletonList(new EndpointDetachRequest(REQUEST_ID1, Base64Util.encode(EndpointObjectHash.fromSha1(ENDPOINT_KEY2).getData())))); request.setUserSync(userRequest); profileDto.setEndpointUserId(userDto.getId()); @@ -786,8 +786,8 @@ public void basicEventListenerFailTest() throws GetDeltaException, IOException { ClientSyncMetaData md = new ClientSyncMetaData(); md.setApplicationToken(application.getApplicationToken()); - md.setEndpointPublicKeyHash(ByteBuffer.wrap(EndpointObjectHash.fromSHA1(ENDPOINT_KEY).getData())); - md.setProfileHash(ByteBuffer.wrap(EndpointObjectHash.fromSHA1(profile).getData())); + md.setEndpointPublicKeyHash(ByteBuffer.wrap(EndpointObjectHash.fromSha1(ENDPOINT_KEY).getData())); + md.setProfileHash(ByteBuffer.wrap(EndpointObjectHash.fromSha1(profile).getData())); request.setClientSyncMetaData(md); EventClientSync eventRequest = new EventClientSync(); diff --git a/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/akka/DefaultAkkaServiceTest.java b/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/akka/DefaultAkkaServiceTest.java index f80219e415..6a238f8fea 100644 --- a/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/akka/DefaultAkkaServiceTest.java +++ b/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/akka/DefaultAkkaServiceTest.java @@ -358,7 +358,7 @@ public void before() throws GeneralSecurityException, CredentialsServiceExceptio private void registerPublicKey(PublicKey publicKey) throws EndpointRegistrationServiceException { byte[] clientPublicKeyBytes = publicKey.getEncoded(); - String endpointId = Base64Util.encode(EndpointObjectHash.fromSHA1(clientPublicKeyBytes).getData()); + String endpointId = Base64Util.encode(EndpointObjectHash.fromSha1(clientPublicKeyBytes).getData()); EndpointRegistrationDto endpointRegistration = new EndpointRegistrationDto(APP_ID, endpointId, endpointId, null, null); Mockito.when(registrationService.findEndpointRegistrationByCredentialsId(endpointId)).thenReturn(Optional.of(endpointRegistration)); } @@ -472,7 +472,7 @@ public void testDecodeSessionException() throws Exception { ErrorBuilder errorBuilder = Mockito.mock(ErrorBuilder.class); SessionInfo sessionInfo = new SessionInfo(UUID.randomUUID(), Constants.KAA_PLATFORM_PROTOCOL_AVRO_ID, - Mockito.mock(ChannelContext.class), ChannelType.ASYNC, Mockito.mock(CipherPair.class), EndpointObjectHash.fromSHA1("test"), + Mockito.mock(ChannelContext.class), ChannelType.ASYNC, Mockito.mock(CipherPair.class), EndpointObjectHash.fromSha1("test"), "applicationToken", "sdkToken", 100, true); Mockito.when(message.getChannelContext()).thenReturn(Mockito.mock(ChannelContext.class)); Mockito.when(message.getErrorBuilder()).thenReturn(errorBuilder); @@ -1140,7 +1140,7 @@ public void testEndpointNotAttachedEvent() throws Exception { when(actorCtxMock.parent()).thenReturn(parentMock); EndpointEventReceiveMessage msg = mock(EndpointEventReceiveMessage.class); LocalEndpointActorMessageProcessor processor = spy(new LocalEndpointActorMessageProcessor( - context, APP_TOKEN, EndpointObjectHash.fromSHA1(clientPublicKeyHash.array()), "ACTOR_TOKEN" + context, APP_TOKEN, EndpointObjectHash.fromSha1(clientPublicKeyHash.array()), "ACTOR_TOKEN" )); processor.processEndpointEventReceiveMessage(actorCtxMock, msg); Assert.assertEquals( diff --git a/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/akka/actors/core/EventDeliveryTableTest.java b/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/akka/actors/core/EventDeliveryTableTest.java index b4e59293c2..5214d759cc 100644 --- a/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/akka/actors/core/EventDeliveryTableTest.java +++ b/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/akka/actors/core/EventDeliveryTableTest.java @@ -31,9 +31,9 @@ public class EventDeliveryTableTest { @Test public void testEventDeliveryTable() { EventDeliveryTable table = new EventDeliveryTable(); - EndpointEvent event = new EndpointEvent(EndpointObjectHash.fromSHA1("sender"), new Event(1, "eventClassFQN", ByteBuffer.wrap(new byte[3]), "sender", "target")); - RouteTableAddress routeAddress = new RouteTableAddress(EndpointObjectHash.fromSHA1("target"), "applicationToken"); - RouteTableAddress routeAddress2 = new RouteTableAddress(EndpointObjectHash.fromSHA1("target2"), "applicationToken"); + EndpointEvent event = new EndpointEvent(EndpointObjectHash.fromSha1("sender"), new Event(1, "eventClassFQN", ByteBuffer.wrap(new byte[3]), "sender", "target")); + RouteTableAddress routeAddress = new RouteTableAddress(EndpointObjectHash.fromSha1("target"), "applicationToken"); + RouteTableAddress routeAddress2 = new RouteTableAddress(EndpointObjectHash.fromSha1("target2"), "applicationToken"); Assert.assertFalse(table.clear(event)); table.registerDeliveryAttempt(event, routeAddress); diff --git a/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/akka/actors/core/endpoint/EndpointActorMessageProcessorTest.java b/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/akka/actors/core/endpoint/EndpointActorMessageProcessorTest.java index 85e23fb084..cdeb1a502a 100644 --- a/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/akka/actors/core/endpoint/EndpointActorMessageProcessorTest.java +++ b/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/akka/actors/core/endpoint/EndpointActorMessageProcessorTest.java @@ -43,7 +43,7 @@ public void noChannelsForEventsTest() { Mockito.when(context.getOperationsService()).thenReturn(osMock); LocalEndpointActorMessageProcessor processor = Mockito.spy(new LocalEndpointActorMessageProcessor(context, "APP_TOKEN", EndpointObjectHash - .fromSHA1("key"), "actorKey")); + .fromSha1("key"), "actorKey")); EndpointEventReceiveMessage msg = Mockito.mock(EndpointEventReceiveMessage.class); Mockito.doNothing().when(processor).tellParent(Mockito.any(ActorContext.class), Mockito.any(Object.class)); @@ -62,7 +62,7 @@ public void actorTimeoutTest() { Mockito.when(context.getOperationsService()).thenReturn(osMock); LocalEndpointActorMessageProcessor processor = Mockito.spy(new LocalEndpointActorMessageProcessor(context, "APP_TOKEN", EndpointObjectHash - .fromSHA1("key"), "actorKey")); + .fromSha1("key"), "actorKey")); ActorTimeoutMessage msg = new ActorTimeoutMessage(System.currentTimeMillis()); Mockito.doNothing().when(processor).tellParent(Mockito.any(ActorContext.class), Mockito.any(Object.class)); @@ -81,7 +81,7 @@ public void actorTimeoutNegativeTest() { Mockito.when(context.getOperationsService()).thenReturn(osMock); LocalEndpointActorMessageProcessor processor = Mockito.spy(new LocalEndpointActorMessageProcessor(context, "APP_TOKEN", EndpointObjectHash - .fromSHA1("key"), "actorKey")); + .fromSha1("key"), "actorKey")); ActorTimeoutMessage msg = new ActorTimeoutMessage(-1); Mockito.doNothing().when(processor).tellParent(Mockito.any(ActorContext.class), Mockito.any(Object.class)); @@ -100,7 +100,7 @@ public void processDisconnectMessageTest() { Mockito.when(context.getOperationsService()).thenReturn(osMock); LocalEndpointActorMessageProcessor processor = Mockito.spy(new LocalEndpointActorMessageProcessor(context, "APP_TOKEN", EndpointObjectHash - .fromSHA1("key"), "actorKey")); + .fromSha1("key"), "actorKey")); ChannelAware msg = Mockito.mock(ChannelAware.class); Assert.assertFalse(processor.processDisconnectMessage(ctxMock, msg)); diff --git a/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/akka/actors/core/user/UserActorMessageProcessorTest.java b/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/akka/actors/core/user/UserActorMessageProcessorTest.java index e361849da0..8435aaeec2 100644 --- a/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/akka/actors/core/user/UserActorMessageProcessorTest.java +++ b/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/akka/actors/core/user/UserActorMessageProcessorTest.java @@ -80,9 +80,9 @@ public class UserActorMessageProcessorTest { private static final String TENANT_ID = "TENANT_ID"; private static final String USER_ID = "USER_ID"; - private final EndpointObjectHash endpoint1Key = EndpointObjectHash.fromSHA1("endpoint1"); - private final EndpointObjectHash endpoint2Key = EndpointObjectHash.fromSHA1("endpoint2"); - private final EndpointObjectHash endpoint3Key = EndpointObjectHash.fromSHA1("endpoint3"); + private final EndpointObjectHash endpoint1Key = EndpointObjectHash.fromSha1("endpoint1"); + private final EndpointObjectHash endpoint2Key = EndpointObjectHash.fromSha1("endpoint2"); + private final EndpointObjectHash endpoint3Key = EndpointObjectHash.fromSha1("endpoint3"); private LocalUserActorMessageProcessor messageProcessor; private List ecfVersions; private EventClassFamilyVersion ecfVersion1; diff --git a/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/akka/messages/core/endpoint/EndpointAwareMessageTest.java b/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/akka/messages/core/endpoint/EndpointAwareMessageTest.java index fe6c54734e..d47c3c1f0f 100644 --- a/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/akka/messages/core/endpoint/EndpointAwareMessageTest.java +++ b/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/akka/messages/core/endpoint/EndpointAwareMessageTest.java @@ -25,8 +25,8 @@ public class EndpointAwareMessageTest { @Test public void endpointAwareMessageTest() { - EndpointAwareMessage message1 = new EndpointAwareMessage("appToken1", EndpointObjectHash.fromSHA1("1"), null); - EndpointAwareMessage message2 = new EndpointAwareMessage("appToken1", EndpointObjectHash.fromSHA1("1"), null); + EndpointAwareMessage message1 = new EndpointAwareMessage("appToken1", EndpointObjectHash.fromSha1("1"), null); + EndpointAwareMessage message2 = new EndpointAwareMessage("appToken1", EndpointObjectHash.fromSha1("1"), null); Assert.assertTrue(message1.equals(message1)); Assert.assertEquals(message1.hashCode(), message1.hashCode()); @@ -37,14 +37,14 @@ public void endpointAwareMessageTest() { Assert.assertNotEquals(message1.getUuid(), message2.getUuid()); UUID uuid = UUID.randomUUID(); - EndpointAwareMessage message3 = new EndpointAwareMessage(uuid, "appToken1", EndpointObjectHash.fromSHA1("1"), null); - EndpointAwareMessage message4 = new EndpointAwareMessage(uuid, "appToken1", EndpointObjectHash.fromSHA1("1"), null); + EndpointAwareMessage message3 = new EndpointAwareMessage(uuid, "appToken1", EndpointObjectHash.fromSha1("1"), null); + EndpointAwareMessage message4 = new EndpointAwareMessage(uuid, "appToken1", EndpointObjectHash.fromSha1("1"), null); Assert.assertTrue(message3.equals(message4)); Assert.assertEquals(message3.hashCode(), message4.hashCode()); Assert.assertNotEquals(message1, new String("")); - Assert.assertNotEquals(message1, new EndpointAwareMessage(null, "appToken1", EndpointObjectHash.fromSHA1("1"), null)); + Assert.assertNotEquals(message1, new EndpointAwareMessage(null, "appToken1", EndpointObjectHash.fromSha1("1"), null)); } } diff --git a/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/cache/ConcurrentCacheServiceTest.java b/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/cache/ConcurrentCacheServiceTest.java index d37abaa28d..8009b34a36 100644 --- a/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/cache/ConcurrentCacheServiceTest.java +++ b/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/cache/ConcurrentCacheServiceTest.java @@ -133,7 +133,7 @@ public class ConcurrentCacheServiceTest extends AbstractTest { private static final ProfileFilterDto TEST_PROFILE_FILTER = new ProfileFilterDto(); private static final List TEST_PROFILE_FILTER_LIST = Collections.singletonList(TEST_PROFILE_FILTER); - private static final EndpointObjectHash CF1_HASH = EndpointObjectHash.fromSHA1(CF1_ID); + private static final EndpointObjectHash CF1_HASH = EndpointObjectHash.fromSha1(CF1_ID); private static final EndpointObjectHash TLCE1_HASH = CF1_HASH; private static final TopicListEntryDto TLCE1 = new TopicListEntryDto(100, TLCE1_HASH.getData(), null); @@ -342,11 +342,11 @@ public EndpointProfileSchemaDto answer(InvocationOnMock invocation) throws Throw publicKey = keyGen.genKeyPair().getPublic(); byte[] key = publicKey.getEncoded(); - publicKeyHash = EndpointObjectHash.fromSHA1(key); + publicKeyHash = EndpointObjectHash.fromSha1(key); publicKey2 = keyGen.genKeyPair().getPublic(); byte[] key2 = publicKey2.getEncoded(); - publicKeyHash2 = EndpointObjectHash.fromSHA1(key2); + publicKeyHash2 = EndpointObjectHash.fromSha1(key2); final EndpointProfileDto ep = new EndpointProfileDto(); ep.setEndpointKey(key); diff --git a/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/cache/DeltaCacheKeyTest.java b/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/cache/DeltaCacheKeyTest.java index fad5eef03c..72d78678eb 100644 --- a/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/cache/DeltaCacheKeyTest.java +++ b/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/cache/DeltaCacheKeyTest.java @@ -35,8 +35,8 @@ public void deltaCacheKeyEqualsTest() { @Test public void deltaSameCacheKeyTest() { - DeltaCacheKey key1 = new DeltaCacheKey(new AppVersionKey("appId1", 1), null, null, EndpointObjectHash.fromSHA1("test1")); - DeltaCacheKey key2 = new DeltaCacheKey(new AppVersionKey("appId1", 1), null, null, EndpointObjectHash.fromSHA1("test1")); + DeltaCacheKey key1 = new DeltaCacheKey(new AppVersionKey("appId1", 1), null, null, EndpointObjectHash.fromSha1("test1")); + DeltaCacheKey key2 = new DeltaCacheKey(new AppVersionKey("appId1", 1), null, null, EndpointObjectHash.fromSha1("test1")); Assert.assertEquals(key1, key2); key1 = new DeltaCacheKey(new AppVersionKey("appId1", 1), null, null, null); key2 = new DeltaCacheKey(new AppVersionKey("appId1", 1), null, null, null); @@ -50,20 +50,20 @@ public void deltaSameCacheKeyTest() { public void deltaDifferentCacheKeyTest() { List egsList = new ArrayList<>(); egsList.add(new EndpointGroupStateDto("eg1", "pf1", "cf1")); - DeltaCacheKey key1 = new DeltaCacheKey(new AppVersionKey("appId1", 1), egsList, null, EndpointObjectHash.fromSHA1("test1")); - DeltaCacheKey key2 = new DeltaCacheKey(new AppVersionKey("appId1", 1), egsList, null, EndpointObjectHash.fromSHA1("test2")); + DeltaCacheKey key1 = new DeltaCacheKey(new AppVersionKey("appId1", 1), egsList, null, EndpointObjectHash.fromSha1("test1")); + DeltaCacheKey key2 = new DeltaCacheKey(new AppVersionKey("appId1", 1), egsList, null, EndpointObjectHash.fromSha1("test2")); Assert.assertNotEquals(key1, key2); List egsList2 = new ArrayList<>(); egsList2.add(new EndpointGroupStateDto("eg1", "pf1", "cf2")); - DeltaCacheKey key3 = new DeltaCacheKey(new AppVersionKey("appId1", 1), egsList2, null, EndpointObjectHash.fromSHA1("test1")); + DeltaCacheKey key3 = new DeltaCacheKey(new AppVersionKey("appId1", 1), egsList2, null, EndpointObjectHash.fromSha1("test1")); Assert.assertNotEquals(key1, key3); - DeltaCacheKey key4 = new DeltaCacheKey(new AppVersionKey("appId2", 1), egsList, null, EndpointObjectHash.fromSHA1("test1")); + DeltaCacheKey key4 = new DeltaCacheKey(new AppVersionKey("appId2", 1), egsList, null, EndpointObjectHash.fromSha1("test1")); Assert.assertNotEquals(key1, key4); - DeltaCacheKey key5 = new DeltaCacheKey(new AppVersionKey("appId1", 2), egsList, null, EndpointObjectHash.fromSHA1("test1")); + DeltaCacheKey key5 = new DeltaCacheKey(new AppVersionKey("appId1", 2), egsList, null, EndpointObjectHash.fromSha1("test1")); Assert.assertNotEquals(key1, key5); } diff --git a/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/delta/DefaultDeltaServiceTest.java b/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/delta/DefaultDeltaServiceTest.java index 3744b1bcb0..c18d185b2b 100644 --- a/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/delta/DefaultDeltaServiceTest.java +++ b/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/delta/DefaultDeltaServiceTest.java @@ -46,10 +46,10 @@ public class DefaultDeltaServiceTest { private static final RawBinaryDelta DELTA = new TestRawBinaryDelta("delta"); private static final String PROFILE_SERVICE = "profileService"; private static final String CACHE_SERVICE = "cacheService"; - private static final EndpointObjectHash PROFILE_HASH = EndpointObjectHash.fromSHA1("profileHash"); - private static final EndpointObjectHash ENDPOINT_KEY_HASH = EndpointObjectHash.fromSHA1("endpointKey"); + private static final EndpointObjectHash PROFILE_HASH = EndpointObjectHash.fromSha1("profileHash"); + private static final EndpointObjectHash ENDPOINT_KEY_HASH = EndpointObjectHash.fromSha1("endpointKey"); private static final String TEST_APP = "testApp"; - private static final EndpointObjectHash CONFIGURATION_HASH = EndpointObjectHash.fromSHA1("configurationHash"); + private static final EndpointObjectHash CONFIGURATION_HASH = EndpointObjectHash.fromSha1("configurationHash"); private static final String NEW_CONF = "{ \"type\": \"newConf\" }"; private static final RawBinaryDelta NEW_CONF_DELTA = new TestRawBinaryDelta("{ \"type\": \"newConf\" }"); @@ -148,7 +148,7 @@ private EndpointProfileDto createDefaultTestProfile(List // when(profileService.getClientProfileBody(ENDPOINT_KEY_HASH)).thenReturn(profile); // // GetDeltaRequest request = new GetDeltaRequest(TEST_APP, ENDPOINT_KEY_HASH, -// EndpointObjectHash.fromSHA1("invalidProfileHash"), null, 41); +// EndpointObjectHash.fromSha1("invalidProfileHash"), null, 41); // GetDeltaResponse response = deltaService.getDelta(request); // // assertNotNull(response); @@ -178,7 +178,7 @@ private EndpointProfileDto createDefaultTestProfile(List // when(profileService.getClientProfileBody(ENDPOINT_KEY_HASH)).thenReturn(profile); // // when(cacheService.getDelta(Mockito.any(DeltaCacheKey.class), Mockito.any(Computable.class))) -// .thenReturn(new DeltaCacheEntry(NEW_CONF, DELTA, EndpointObjectHash.fromSHA1("hash"))); +// .thenReturn(new DeltaCacheEntry(NEW_CONF, DELTA, EndpointObjectHash.fromSha1("hash"))); // // // GetDeltaRequest request = new GetDeltaRequest(TEST_APP, ENDPOINT_KEY_HASH, PROFILE_HASH, CONFIGURATION_HASH, 41); @@ -186,7 +186,7 @@ private EndpointProfileDto createDefaultTestProfile(List // // assertNotNull(response); // verify(profileService, times(1)).getClientProfileBody(ENDPOINT_KEY_HASH); -// verify(profileService, times(1)).updateProfile(profile, 42, EndpointObjectHash.fromSHA1("hash")); +// verify(profileService, times(1)).updateProfile(profile, 42, EndpointObjectHash.fromSha1("hash")); // // assertEquals(GetDeltaResponseType.DELTA, response.getResponseType()); // assertEquals(DELTA, response.getDelta()); @@ -212,14 +212,14 @@ private EndpointProfileDto createDefaultTestProfile(List // when(profileService.getClientProfileBody(ENDPOINT_KEY_HASH)).thenReturn(profile); // // when(cacheService.getDelta(Mockito.any(DeltaCacheKey.class), Mockito.any(Computable.class))) -// .thenReturn(new DeltaCacheEntry(NEW_CONF, NEW_CONF_DELTA, EndpointObjectHash.fromSHA1(NEW_CONF))); +// .thenReturn(new DeltaCacheEntry(NEW_CONF, NEW_CONF_DELTA, EndpointObjectHash.fromSha1(NEW_CONF))); // // GetDeltaRequest request = new GetDeltaRequest(TEST_APP, ENDPOINT_KEY_HASH, PROFILE_HASH, CONFIGURATION_HASH, 41); // GetDeltaResponse response = deltaService.getDelta(request); // // assertNotNull(response); // verify(profileService, times(1)).getClientProfileBody(ENDPOINT_KEY_HASH); -// verify(profileService, times(1)).updateProfile(profile, 42, EndpointObjectHash.fromSHA1(NEW_CONF)); +// verify(profileService, times(1)).updateProfile(profile, 42, EndpointObjectHash.fromSha1(NEW_CONF)); // // assertEquals(GetDeltaResponseType.DELTA, response.getResponseType()); // assertEquals(NEW_CONF_DELTA, response.getDelta()); @@ -246,15 +246,15 @@ private EndpointProfileDto createDefaultTestProfile(List // when(profileService.getClientProfileBody(ENDPOINT_KEY_HASH)).thenReturn(profile); // // when(cacheService.getDelta(Mockito.any(DeltaCacheKey.class), Mockito.any(Computable.class))).thenReturn( -// new DeltaCacheEntry(NEW_CONF, NEW_CONF_DELTA, EndpointObjectHash.fromSHA1("hash"))); +// new DeltaCacheEntry(NEW_CONF, NEW_CONF_DELTA, EndpointObjectHash.fromSha1("hash"))); // // GetDeltaRequest request = new GetDeltaRequest(TEST_APP, ENDPOINT_KEY_HASH, PROFILE_HASH, -// EndpointObjectHash.fromSHA1("invalidConfigurationHash"), 41); +// EndpointObjectHash.fromSha1("invalidConfigurationHash"), 41); // GetDeltaResponse response = deltaService.getDelta(request); // // assertNotNull(response); // verify(profileService, times(1)).getClientProfileBody(ENDPOINT_KEY_HASH); -// verify(profileService, times(1)).updateProfile(profile, 42, EndpointObjectHash.fromSHA1("hash")); +// verify(profileService, times(1)).updateProfile(profile, 42, EndpointObjectHash.fromSha1("hash")); // // assertEquals(GetDeltaResponseType.CONF_RESYNC, response.getResponseType()); // assertEquals(NEW_CONF_DELTA, response.getDelta()); @@ -280,15 +280,15 @@ private EndpointProfileDto createDefaultTestProfile(List // when(profileService.getClientProfileBody(ENDPOINT_KEY_HASH)).thenReturn(profile); // // when(cacheService.getDelta(Mockito.any(DeltaCacheKey.class), Mockito.any(Computable.class))) -// .thenReturn(new DeltaCacheEntry(NEW_CONF, NEW_CONF_DELTA, EndpointObjectHash.fromSHA1(NEW_CONF))); +// .thenReturn(new DeltaCacheEntry(NEW_CONF, NEW_CONF_DELTA, EndpointObjectHash.fromSha1(NEW_CONF))); // // GetDeltaRequest request = new GetDeltaRequest(TEST_APP, ENDPOINT_KEY_HASH, PROFILE_HASH, -// EndpointObjectHash.fromSHA1("invalidConfigurationHash"), 41); +// EndpointObjectHash.fromSha1("invalidConfigurationHash"), 41); // GetDeltaResponse response = deltaService.getDelta(request); // // assertNotNull(response); // verify(profileService, times(1)).getClientProfileBody(ENDPOINT_KEY_HASH); -// verify(profileService, times(1)).updateProfile(profile, 42, EndpointObjectHash.fromSHA1(NEW_CONF)); +// verify(profileService, times(1)).updateProfile(profile, 42, EndpointObjectHash.fromSha1(NEW_CONF)); // // assertEquals(GetDeltaResponseType.CONF_RESYNC, response.getResponseType()); // assertEquals(NEW_CONF_DELTA, response.getDelta()); diff --git a/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/delta/DeltaServiceIT.java b/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/delta/DeltaServiceIT.java index 2a4fd69946..c773f1ce08 100644 --- a/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/delta/DeltaServiceIT.java +++ b/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/delta/DeltaServiceIT.java @@ -220,7 +220,7 @@ public void beforeTest() throws IOException, DeltaCalculatorException, ControlSe endpointConfiguration = new EndpointConfigurationDto(); endpointConfiguration.setConfiguration(confDto.getBody().getBytes(UTF_8)); - endpointConfiguration.setConfigurationHash(EndpointObjectHash.fromSHA1(confDto.getBody()).getData()); + endpointConfiguration.setConfigurationHash(EndpointObjectHash.fromSha1(confDto.getBody()).getData()); endpointConfiguration = endpointService.saveEndpointConfiguration(endpointConfiguration); assertNotNull(endpointConfiguration); @@ -233,7 +233,7 @@ public void beforeTest() throws IOException, DeltaCalculatorException, ControlSe endpointProfile.setApplicationId(application.getId()); endpointProfile.setEndpointKeyHash(UUID.randomUUID().toString().getBytes()); endpointProfile.setClientProfileBody(PROFILE_JSON); - endpointProfile.setProfileHash(EndpointObjectHash.fromSHA1(PROFILE_BYTES).getData()); + endpointProfile.setProfileHash(EndpointObjectHash.fromSha1(PROFILE_BYTES).getData()); endpointProfile.setConfigurationHash(endpointConfiguration.getConfigurationHash()); endpointProfile.setConfigurationVersion(CONF_SCHEMA_VERSION); endpointProfile.setClientProfileVersion(PROFILE_VERSION); @@ -250,8 +250,8 @@ public void afterTest() { @Test public void testDeltaServiceNoHistoryDelta() throws Exception { - GetDeltaRequest request = new GetDeltaRequest(application.getApplicationToken(), EndpointObjectHash.fromSHA1(endpointConfiguration - .getConfiguration()), true); + GetDeltaRequest request = new GetDeltaRequest(application.getApplicationToken(), EndpointObjectHash.fromSha1(endpointConfiguration + .getConfiguration()), true); request.setEndpointProfile(endpointProfile); GetDeltaResponse response = deltaService.getDelta(request); assertNotNull(response); diff --git a/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/event/RouteTableTest.java b/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/event/RouteTableTest.java index 00e6437bed..e5b8dea2ed 100644 --- a/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/event/RouteTableTest.java +++ b/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/event/RouteTableTest.java @@ -28,7 +28,7 @@ public class RouteTableTest { private static final String SERVER1 = "server1"; private static final String ECF1 = "ECF1"; private static final String APP_TOKEN = "APP_TOKEN"; - private static final EndpointObjectHash endpoint = EndpointObjectHash.fromSHA1("endpoint1"); + private static final EndpointObjectHash endpoint = EndpointObjectHash.fromSha1("endpoint1"); private RouteTable testTable; diff --git a/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/profile/ProfileServiceIT.java b/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/profile/ProfileServiceIT.java index c3ad21c5db..0a4a88135e 100644 --- a/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/profile/ProfileServiceIT.java +++ b/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/profile/ProfileServiceIT.java @@ -183,9 +183,9 @@ public void registerProfileServiceTest() throws IOException { Assert.assertNotNull(dto); Assert.assertNotNull(dto.getId()); Assert.assertTrue(Arrays.equals(ENDPOINT_KEY, dto.getEndpointKey())); - Assert.assertTrue(Arrays.equals(EndpointObjectHash.fromSHA1(ENDPOINT_KEY).getData(), dto.getEndpointKeyHash())); + Assert.assertTrue(Arrays.equals(EndpointObjectHash.fromSha1(ENDPOINT_KEY).getData(), dto.getEndpointKeyHash())); Assert.assertEquals(baseAvroConverter.encodeToJson(ENDPOINT_PROFILE), dto.getClientProfileBody().replaceAll(" ", "")); - Assert.assertTrue(Arrays.equals(EndpointObjectHash.fromSHA1(profile).getData(), dto.getProfileHash())); + Assert.assertTrue(Arrays.equals(EndpointObjectHash.fromSha1(profile).getData(), dto.getProfileHash())); } @Test @@ -198,7 +198,7 @@ public void updateProfileServiceTest() throws IOException { Assert.assertEquals(baseAvroConverter.encodeToJson(ENDPOINT_PROFILE), oldDto.getClientProfileBody().replaceAll(" ", "")); byte[] newProfile = newAvroConverter.encode(NEW_ENDPOINT_PROFILE); - UpdateProfileRequest updateRequest = new UpdateProfileRequest(application.getApplicationToken(), EndpointObjectHash.fromSHA1(ENDPOINT_KEY), null, + UpdateProfileRequest updateRequest = new UpdateProfileRequest(application.getApplicationToken(), EndpointObjectHash.fromSha1(ENDPOINT_KEY), null, newProfile, newSdkToken); EndpointProfileDto newDto = profileService.updateProfile(updateRequest); @@ -206,6 +206,6 @@ public void updateProfileServiceTest() throws IOException { Assert.assertNotNull(newDto.getId()); Assert.assertEquals(oldDto.getId(), newDto.getId()); Assert.assertEquals(newAvroConverter.encodeToJson(NEW_ENDPOINT_PROFILE), newDto.getClientProfileBody().replaceAll(" ", "")); - Assert.assertTrue(Arrays.equals(EndpointObjectHash.fromSHA1(newProfile).getData(), newDto.getProfileHash())); + Assert.assertTrue(Arrays.equals(EndpointObjectHash.fromSha1(newProfile).getData(), newDto.getProfileHash())); } } diff --git a/server/transports/http/transport/src/main/java/org/kaaproject/kaa/server/transports/http/transport/commands/AbstractHttpSyncCommand.java b/server/transports/http/transport/src/main/java/org/kaaproject/kaa/server/transports/http/transport/commands/AbstractHttpSyncCommand.java index 47c0123211..a445d52186 100644 --- a/server/transports/http/transport/src/main/java/org/kaaproject/kaa/server/transports/http/transport/commands/AbstractHttpSyncCommand.java +++ b/server/transports/http/transport/src/main/java/org/kaaproject/kaa/server/transports/http/transport/commands/AbstractHttpSyncCommand.java @@ -37,7 +37,7 @@ import org.apache.commons.codec.binary.Base64; import org.kaaproject.kaa.common.Constants; -import org.kaaproject.kaa.common.endpoint.CommonEPConstans; +import org.kaaproject.kaa.common.endpoint.CommonEpConstans; import org.kaaproject.kaa.common.endpoint.security.MessageEncoderDecoder; import org.kaaproject.kaa.server.common.server.BadRequestException; import org.kaaproject.kaa.server.transport.channel.ChannelType; @@ -122,7 +122,7 @@ public void parse() throws Exception { LOG.trace("Multipart1 name " + data.getName() + " type " + data.getHttpDataType().name()); if (data.getHttpDataType() == HttpDataType.Attribute) { Attribute attribute = (Attribute) data; - if (CommonEPConstans.REQUEST_SIGNATURE_ATTR_NAME.equals(data.getName())) { + if (CommonEpConstans.REQUEST_SIGNATURE_ATTR_NAME.equals(data.getName())) { requestSignature = attribute.get(); if (LOG.isTraceEnabled()) { LOG.trace("Multipart name " + data.getName() + " type " + data.getHttpDataType().name() + " Signature set. size: " @@ -130,21 +130,21 @@ public void parse() throws Exception { LOG.trace(MessageEncoderDecoder.bytesToHex(requestSignature)); } - } else if (CommonEPConstans.REQUEST_KEY_ATTR_NAME.equals(data.getName())) { + } else if (CommonEpConstans.REQUEST_KEY_ATTR_NAME.equals(data.getName())) { requestKey = attribute.get(); if (LOG.isTraceEnabled()) { LOG.trace("Multipart name " + data.getName() + " type " + data.getHttpDataType().name() + " requestKey set. size: " + requestKey.length); LOG.trace(MessageEncoderDecoder.bytesToHex(requestKey)); } - } else if (CommonEPConstans.REQUEST_DATA_ATTR_NAME.equals(data.getName())) { + } else if (CommonEpConstans.REQUEST_DATA_ATTR_NAME.equals(data.getName())) { requestData = attribute.get(); if (LOG.isTraceEnabled()) { LOG.trace("Multipart name " + data.getName() + " type " + data.getHttpDataType().name() + " requestData set. size: " + requestData.length); LOG.trace(MessageEncoderDecoder.bytesToHex(requestData)); } - } else if (CommonEPConstans.NEXT_PROTOCOL_ATTR_NAME.equals(data.getName())) { + } else if (CommonEpConstans.NEXT_PROTOCOL_ATTR_NAME.equals(data.getName())) { nextProtocol = ByteBuffer.wrap(attribute.get()).getInt(); LOG.trace("[{}] next protocol is {}", getSessionUuid(), nextProtocol); } @@ -209,12 +209,12 @@ public HttpResponse getResponse() { LOG.warn("Response data: {}", Arrays.toString(data.array())); FullHttpResponse httpResponse = new DefaultFullHttpResponse(HTTP_1_1, OK, data); - httpResponse.headers().set(CONTENT_TYPE, CommonEPConstans.RESPONSE_CONTENT_TYPE); + httpResponse.headers().set(CONTENT_TYPE, CommonEpConstans.RESPONSE_CONTENT_TYPE); httpResponse.headers().set(CONTENT_LENGTH, data.readableBytes()); LOG.warn("Response size: {}", data.readableBytes()); - httpResponse.headers().set(CommonEPConstans.RESPONSE_TYPE, CommonEPConstans.RESPONSE_TYPE_OPERATION); + httpResponse.headers().set(CommonEpConstans.RESPONSE_TYPE, CommonEpConstans.RESPONSE_TYPE_OPERATION); if (responseSignature != null) { - httpResponse.headers().set(CommonEPConstans.SIGNATURE_HEADER_NAME, Base64.encodeBase64String(responseSignature)); + httpResponse.headers().set(CommonEpConstans.SIGNATURE_HEADER_NAME, Base64.encodeBase64String(responseSignature)); } if (isNeedConnectionClose()) { httpResponse.headers().set(CONNECTION, HttpHeaders.Values.CLOSE); diff --git a/server/transports/http/transport/src/main/java/org/kaaproject/kaa/server/transports/http/transport/commands/LongSyncCommandFactory.java b/server/transports/http/transport/src/main/java/org/kaaproject/kaa/server/transports/http/transport/commands/LongSyncCommandFactory.java index d4efb8a6a0..a56a6f1416 100644 --- a/server/transports/http/transport/src/main/java/org/kaaproject/kaa/server/transports/http/transport/commands/LongSyncCommandFactory.java +++ b/server/transports/http/transport/src/main/java/org/kaaproject/kaa/server/transports/http/transport/commands/LongSyncCommandFactory.java @@ -19,14 +19,14 @@ import io.netty.handler.codec.http.HttpRequest; import io.netty.handler.codec.http.HttpResponse; -import org.kaaproject.kaa.common.endpoint.CommonEPConstans; +import org.kaaproject.kaa.common.endpoint.CommonEpConstans; import org.kaaproject.kaa.server.common.server.KaaCommandProcessor; public class LongSyncCommandFactory extends SyncCommandFactory { @Override public String getCommandName() { - return CommonEPConstans.LONG_SYNC_COMMAND; + return CommonEpConstans.LONG_SYNC_COMMAND; } @Override diff --git a/server/transports/http/transport/src/main/java/org/kaaproject/kaa/server/transports/http/transport/commands/SyncCommand.java b/server/transports/http/transport/src/main/java/org/kaaproject/kaa/server/transports/http/transport/commands/SyncCommand.java index 2866a7ebd5..183d1e57ee 100644 --- a/server/transports/http/transport/src/main/java/org/kaaproject/kaa/server/transports/http/transport/commands/SyncCommand.java +++ b/server/transports/http/transport/src/main/java/org/kaaproject/kaa/server/transports/http/transport/commands/SyncCommand.java @@ -19,13 +19,13 @@ */ package org.kaaproject.kaa.server.transports.http.transport.commands; -import org.kaaproject.kaa.common.endpoint.CommonEPConstans; +import org.kaaproject.kaa.common.endpoint.CommonEpConstans; import org.kaaproject.kaa.server.transport.channel.ChannelType; /** * The Class SyncCommand. */ -public class SyncCommand extends AbstractHttpSyncCommand implements CommonEPConstans { +public class SyncCommand extends AbstractHttpSyncCommand implements CommonEpConstans { /** * Instantiates a new sync command. diff --git a/server/transports/http/transport/src/main/java/org/kaaproject/kaa/server/transports/http/transport/commands/SyncCommandFactory.java b/server/transports/http/transport/src/main/java/org/kaaproject/kaa/server/transports/http/transport/commands/SyncCommandFactory.java index aea292e2f2..b4d6e9d3fb 100644 --- a/server/transports/http/transport/src/main/java/org/kaaproject/kaa/server/transports/http/transport/commands/SyncCommandFactory.java +++ b/server/transports/http/transport/src/main/java/org/kaaproject/kaa/server/transports/http/transport/commands/SyncCommandFactory.java @@ -19,7 +19,7 @@ import io.netty.handler.codec.http.HttpRequest; import io.netty.handler.codec.http.HttpResponse; -import org.kaaproject.kaa.common.endpoint.CommonEPConstans; +import org.kaaproject.kaa.common.endpoint.CommonEpConstans; import org.kaaproject.kaa.server.common.server.KaaCommandProcessor; import org.kaaproject.kaa.server.common.server.KaaCommandProcessorFactory; @@ -42,7 +42,7 @@ public class SyncCommandFactory implements KaaCommandProcessorFactory> header, byte[] body) throws Exception { - if (header.containsKey(CommonEPConstans.SIGNATURE_HEADER_NAME) - && header.get(CommonEPConstans.SIGNATURE_HEADER_NAME) != null - && header.get(CommonEPConstans.SIGNATURE_HEADER_NAME).size() > 0) { - String sigHeader = header.get(CommonEPConstans.SIGNATURE_HEADER_NAME).get(0); + if (header.containsKey(CommonEpConstans.SIGNATURE_HEADER_NAME) + && header.get(CommonEpConstans.SIGNATURE_HEADER_NAME) != null + && header.get(CommonEpConstans.SIGNATURE_HEADER_NAME).size() > 0) { + String sigHeader = header.get(CommonEpConstans.SIGNATURE_HEADER_NAME).get(0); byte[] respSignature = Base64.decodeBase64(sigHeader); byte[] respData = body; crypt.verify(respData, respSignature); @@ -315,7 +315,7 @@ protected R decodeHttpResponse(Map> header, byte[] body) th byte[] respDecoded = crypt.decodeData(respData); return responseConverter.fromByteArray(respDecoded); } else { - throw new Exception("HTTP response incorrect, no signature fields " + CommonEPConstans.SIGNATURE_HEADER_NAME); + throw new Exception("HTTP response incorrect, no signature fields " + CommonEpConstans.SIGNATURE_HEADER_NAME); } } diff --git a/server/transports/http/transport/src/test/java/org/kaaproject/kaa/server/transports/http/transport/commands/HttpCommandsTest.java b/server/transports/http/transport/src/test/java/org/kaaproject/kaa/server/transports/http/transport/commands/HttpCommandsTest.java index d3b94288ad..4528021f74 100644 --- a/server/transports/http/transport/src/test/java/org/kaaproject/kaa/server/transports/http/transport/commands/HttpCommandsTest.java +++ b/server/transports/http/transport/src/test/java/org/kaaproject/kaa/server/transports/http/transport/commands/HttpCommandsTest.java @@ -22,7 +22,7 @@ import org.junit.Assert; import org.junit.Test; -import org.kaaproject.kaa.common.endpoint.CommonEPConstans; +import org.kaaproject.kaa.common.endpoint.CommonEpConstans; import org.kaaproject.kaa.server.transports.http.transport.messages.NettyHttpSyncMessage; import org.kaaproject.kaa.server.transports.http.transport.netty.AbstractCommand; import org.mockito.Mockito; @@ -68,6 +68,6 @@ public void nettyHttpSyncMessageTest() { @Test public void longSyncCommandTest() { - Assert.assertEquals(CommonEPConstans.LONG_SYNC_COMMAND, LongSyncCommand.getCommandName()); + Assert.assertEquals(CommonEpConstans.LONG_SYNC_COMMAND, LongSyncCommand.getCommandName()); } } diff --git a/server/transports/tcp/transport/src/test/java/org/kaaproject/kaa/server/transports/tcp/transport/TcpHandlerTest.java b/server/transports/tcp/transport/src/test/java/org/kaaproject/kaa/server/transports/tcp/transport/TcpHandlerTest.java index 9df0a584ba..2eb66532a8 100644 --- a/server/transports/tcp/transport/src/test/java/org/kaaproject/kaa/server/transports/tcp/transport/TcpHandlerTest.java +++ b/server/transports/tcp/transport/src/test/java/org/kaaproject/kaa/server/transports/tcp/transport/TcpHandlerTest.java @@ -195,6 +195,6 @@ private ChannelHandlerContext buildDummyCtxMock() { protected SessionInfo buildSessionInfo(UUID uuid) { return new SessionInfo(uuid, Constants.KAA_PLATFORM_PROTOCOL_AVRO_ID, Mockito.mock(ChannelContext.class), ChannelType.ASYNC, - Mockito.mock(CipherPair.class), EndpointObjectHash.fromSHA1("test"), "applicationToken", "sdkToken", 100, true); + Mockito.mock(CipherPair.class), EndpointObjectHash.fromSha1("test"), "applicationToken", "sdkToken", 100, true); } } diff --git a/server/transports/tcp/transport/src/test/java/org/kaaproject/kaa/server/transports/tcp/transport/messages/NettyTcpMessageTest.java b/server/transports/tcp/transport/src/test/java/org/kaaproject/kaa/server/transports/tcp/transport/messages/NettyTcpMessageTest.java index 06f8c6d96f..c614bc3ff8 100644 --- a/server/transports/tcp/transport/src/test/java/org/kaaproject/kaa/server/transports/tcp/transport/messages/NettyTcpMessageTest.java +++ b/server/transports/tcp/transport/src/test/java/org/kaaproject/kaa/server/transports/tcp/transport/messages/NettyTcpMessageTest.java @@ -41,7 +41,7 @@ public void connectTest() { ChannelContext ctx = Mockito.mock(ChannelContext.class); ChannelType channelType = ChannelType.ASYNC; CipherPair sessionKey = Mockito.mock(CipherPair.class); - EndpointObjectHash key = EndpointObjectHash.fromSHA1("key"); + EndpointObjectHash key = EndpointObjectHash.fromSha1("key"); String applicationToken = "AppToken"; String sdkToken = "SdkToken"; int keepAlive = 100; @@ -80,7 +80,7 @@ public void syncTest() { ChannelContext ctx = Mockito.mock(ChannelContext.class); ChannelType channelType = ChannelType.ASYNC; CipherPair sessionKey = Mockito.mock(CipherPair.class); - EndpointObjectHash key = EndpointObjectHash.fromSHA1("key"); + EndpointObjectHash key = EndpointObjectHash.fromSha1("key"); String applicationToken = "AppToken"; String sdkToken = "SdkToken"; int keepAlive = 100; @@ -103,7 +103,7 @@ public void disconnectTest() { ChannelContext ctx = Mockito.mock(ChannelContext.class); ChannelType channelType = ChannelType.ASYNC; CipherPair sessionKey = Mockito.mock(CipherPair.class); - EndpointObjectHash key = EndpointObjectHash.fromSHA1("key"); + EndpointObjectHash key = EndpointObjectHash.fromSha1("key"); String applicationToken = "AppToken"; String sdkToken = "SdkToken"; int keepAlive = 100; @@ -125,7 +125,7 @@ public void pingTest() { ChannelContext ctx = Mockito.mock(ChannelContext.class); ChannelType channelType = ChannelType.ASYNC; CipherPair sessionKey = Mockito.mock(CipherPair.class); - EndpointObjectHash key = EndpointObjectHash.fromSHA1("key"); + EndpointObjectHash key = EndpointObjectHash.fromSha1("key"); String applicationToken = "AppToken"; String sdkToken = "SdkToken"; int keepAlive = 100;