The project has several components -
- Producer Server
- Consumer server
- Android Application
- Blockchain
To run the Android app -
-
Navigate to https://firebase.google.com/docs/android/setup#console
-
Follow the steps prescribed under the section "Option1: Add Firebase using the Firebase console"
-
In step 2, use the Android package name as "com.example.producerapp." These steps are required to acquire the "google-services.json" file for your device.
-
Navigate to your Firebase console and click on your project. Click on the settings icon, select "Project settings" and navigate to the "Cloud Messaging" tab.
-
Make a note of the values in the fields "Sender ID" and "Server key".
-
Run the app on your device. Go to your Firebase project, go to Cloud Messaging and create a new notification with the following fields:
Notification Notification title = Test Notification Notification text = Test Notification Text Target App = com.example.producerapp Scheduling Send to eligible users = Now Additional options Custom data (Add 1 key-value pair here) message = Authentication -
You will receive a notification on your app. The Android Studio console will display a message that says "YOUR TOKEN IS: ." Make a note of this token value.
-
The app may crash if you click on the notification and select yes/no, since it has not been configured completely.
To run the servers -
- Go to src->main->java->edu.cmu.producerserver->utils->MessagingCredentials and paste the value of "Sender ID" from the previous step in the "projectID" field and the "Server key" in the "apiKey" field.
- Paste the token value in the field "senderRegistrationID" .
- Download and Install Ganache GUI from - https://www.trufflesuite.com/ganache
- Open Ganache, Settings, and make sure that the Server Port number is 8545.
- Create a save a Workspace using a name of your choice.
- On the Accounts page, you will have 10 accounts and their corresponding addresses.
- Click on the "key" icon of one of the accounts and copy the Private key value to PRIVATE_KEY variable in the Transaction class of the blockchain folder, src->main->java->edu.cmu.producerserver->service Transaction class, and src->main->java->edu.cmu.consumerserver->service Transaction class.
- Run the Blockchain class in the blockchain folder.
- There will be an address printed on the console. This is the address where the Contract is deployed. This contract holds a map of the ID and the public keys for the producer and consumer that we have defined for the purpose of demonstration of this prototype.
- Copy the address and paste it to the deployedAddress variable in src->main->java->edu.cmu.producerserver->service Transaction and src->main->java->edu.cmu.consumerserver->service Transaction class.
- Run the Producer server and the Consumer server
- Go to the command line and make a note of the producer server's IP address
- In the android project, go to app->src->main->java->com->example->producerapp->ServerDetails. Set urlString to "http://<producer server's IP address>:8082". Run the app again.
- Run the different stages of the application.
We're using jasypt to encrypt the database connection url and password.
Usage:
-
Include dependency in pom.xml
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>2.1.0</version>
</dependency>
-
Add your private key into application.properties
jasypt.encryptor.password=<your private key>
-
Encrypt the url/password with your private key
@Autowired
StringEncryptor encryptor;
@Test
void getPass() {
String url = encryptor.encrypt(<your url>);
}
-
Replace the original url with the encrypted string in application.properties
spring.data.mongodb.uri=ENC(<your encrypted string>)
-
Remove your private key from application.propterties
-
Make your private key as a runtime parameter
-jasypt.encryptor.password=<your private key>