Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MBS-15 CLEAN-UP #3

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ae74162
UPLOAD: Work in progress...
mhawila Jun 20, 2019
1bccbc5
UPLOAD: Utils & media save works like charm
mhawila Jun 21, 2019
ec56320
UPLOAD: Uploading metadata plus file works like charm
mhawila Jun 24, 2019
36e5eec
UPLOAD: Added Swagger integration for REST API automatic documentatio…
mhawila Jun 24, 2019
259e7dc
Media files: Added ability to retrieve media metadata along with file…
mhawila Jun 28, 2019
6230a69
MBS-11: WIP... Problem: Caused by: java.security.InvalidAlgorithmPara…
mhawila Aug 5, 2019
2ed4a6f
MBS-12: Signature verification for SMS, MMS and Media implemented. (#3)
mhawila Aug 19, 2019
8327317
identity key
samuelowino Aug 27, 2019
93be9b3
MBS-11
samuelowino Sep 6, 2019
e458bfd
Keysore Errors
samuelowino Sep 10, 2019
dac63ff
initialized keystore
samuelowino Sep 10, 2019
5ebbc98
Register To Signal Now Works
samuelowino Sep 10, 2019
7dca5c7
MBS-11
samuelowino Sep 17, 2019
35c8ee0
MBS-11 Resolve conflicts
samuelowino Sep 17, 2019
42d2c8f
MBS 11 (#4)
samuelowino Sep 17, 2019
7d5fac7
Fcm Push Notifications Infra Setup
samuelowino Sep 19, 2019
4b2fad1
MBS-14
samuelowino Oct 2, 2019
762f9fc
Resolved Remote Conflicts
samuelowino Oct 2, 2019
f32714b
More Code Clean Up
samuelowino Oct 2, 2019
e831045
Code Review - Cleanup
samuelowino Oct 4, 2019
563847c
Removed unnecessary annotations
samuelowino Oct 4, 2019
1d586a5
Version Bump
samuelowino Oct 4, 2019
225049f
rollback to snapshot
samuelowino Oct 8, 2019
96bb4c6
Refactor for server
samuelowino Oct 8, 2019
4670182
End Point Fixes
samuelowino Oct 13, 2019
99cab5b
Clean up
samuelowino Oct 15, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[*]
charset=utf-8
end_of_line=lf
insert_final_newline=false
indent_style=space
indent_size=4

[*.json]
indent_style=space
indent_size=2

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ HELP.md

### VS Code ###
.vscode/

media_directory/
73 changes: 72 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,74 @@
# Turkana Message Backup Service
This application provide a service to allow backing up of client messages exchanged using
Muzima mobile applications.
Muzima mobile applications.

## REST API Specification
Provided using [Swagger 2 | https://swagger.io]. To access these API docs using the browser simply visit
`/swagger-ui.html` and to get a json response use the endpoint `/v2/api-docs`

## MESSAGE/PAYLOAD VERIFICATION
Before saving submitted messages to be backed up, the server provides the facility to verify them. The process works as follows.

### Single SMS submission
The sender signs the message body using their private key. The algorithm used for this is `SHA256withRSA`. The URL base64 encoded signature is then
sent along with the payload as the `signature` query parameter. Below is the java snippet to accomplish that.
```java
import java.security.Signature;
import java.security.SignatureException;
import java.util.Base64;

class SignDemo {
public static final String ALGORITHM = "SHA256withRSA";

public static String signMessage(String messageBody, PrivateKey privateKey) throws NoSuchAlgorithmException, InvalidKeyException,
SignatureException {
Signature rsa = Signature.getInstance(ALGORITHM);
rsa.initSign(privateKey);
rsa.update(messageBody.getBytes());

byte[] signature = rsa.sign();
return Base64.getUrlEncoder().encodeToString(signature);
}
}
```

### Multiple SMSes SENT TOGETHER.
The procedure is similar to single SMS except in this one, all message bodies are concatenated, hashed using the `SHA-256` algorithm, signed and then
signed. See example snippet below.

*Note:* The order of messages matters.
```java
import java.security.Signature;
import java.security.SignatureException;
import java.util.Base64;
import java.security.MessageDigest;

class SignDemo {
public static final String ALGORITHM = "SHA256withRSA";
public static final String MD_ALG = "SHA-256";

public static String signMessage(String[] messageBodies, PrivateKey privateKey) throws NoSuchAlgorithmException, InvalidKeyException,
SignatureException {
Signature rsa = Signature.getInstance(ALGORITHM);
rsa.initSign(privateKey);

MessageDigest md = MessageDigest.getInstance(MD_ALG);

StringBuilder sb = new StringBuilder();
for(String messageBody: messageBodies) {
sb.append(messageBody);
}
// Digest.
byte[] digested = md.digest(sb.toString().getBytes());
rsa.update(digested);
byte[] signature = rsa.sign();
return Base64.getUrlEncoder().encodeToString(signature);
}
}
```

### Single & Multiple MMS
These work similar to SMS implementation.

### Media (Image, Audio, Video, Documents) Uploads.
This uses three metadata fields namely phonenumber, size, and media type in that order. The three are concatenated and signed.
255 changes: 148 additions & 107 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,121 +1,162 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>org.muzima</groupId>
<artifactId>turkana</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>Turkana</name>
<description>Message Backup Server</description>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
<relativePath/>
<!-- lookup parent from repository -->
</parent>
<groupId>org.muzima</groupId>
<artifactId>turkana</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>Turkana</name>
<description>Message Backup Server</description>

<developers>
<developers>

<developer>
<name>Samuel Owino</name>
<email>[email protected]</email>
<organization>mUzima</organization>
<organizationUrl>www.muzima.org</organizationUrl>
</developer>
<developer>
<name>Samuel Owino</name>
<email>[email protected]</email>
<organization>mUzima</organization>
<organizationUrl>www.muzima.org</organizationUrl>
</developer>

<developer>
<name>Mhawila Mhawila (Willa)</name>
<email>[email protected]</email>
<organization>VUMC</organization>
<organizationUrl> www.vumc.org</organizationUrl>
</developer>
</developers>
<developer>
<name>Mhawila Mhawila (Willa)</name>
<email>[email protected]</email>
<organization>VUMC</organization>
<organizationUrl>www.vumc.org</organizationUrl>
</developer>

</developers>

<properties>
<java.version>1.8</java.version>
</properties>

<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
<version>${querydsl.version}</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${h2.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
<version>${querydsl.version}</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${h2.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>

<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>1.1.3</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources/java</outputDirectory>
<processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>${querydsl.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<dependency>
<groupId>org.whispersystems</groupId>
<artifactId>signal-service-java</artifactId>
<version>2.7.2</version>
</dependency>

<dependency>
<groupId>com.google.gcm</groupId>
<artifactId>gcm-server</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.google.firebase</groupId>
<artifactId>firebase-admin</artifactId>
<version>6.8.1</version>
</dependency>
<dependency>
<groupId>com.google.gcm</groupId>
<artifactId>gcm-server</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>net.coobird</groupId>
<artifactId>thumbnailator</artifactId>
<version>0.4.8</version>
</dependency>

<dependency>
<groupId>org.greenrobot</groupId>
<artifactId>eventbus</artifactId>
<version>3.0.0</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>

<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>1.1.3</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources/java</outputDirectory>
<processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>${querydsl.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>

</project>
1 change: 0 additions & 1 deletion src/main/java/org/muzima/TurkanaApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ public class TurkanaApplication {
public static void main(String[] args) {
SpringApplication.run(TurkanaApplication.class, args);
}

}
Loading