Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.vscode/settings.json
.DS_Store
rubixcorejava.jar
tests/thunder-tests/thunderActivity.db
tests/thunder-tests/thunderclient.db
tests/thunder-tests/thunderCollection.db
tests/thunder-tests/thunderEnvironment.db
44 changes: 28 additions & 16 deletions src/com/rubix/AuthenticateNode/Authenticate.java
Original file line number Diff line number Diff line change
@@ -1,41 +1,54 @@
package com.rubix.AuthenticateNode;

import io.ipfs.api.IPFS;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.json.JSONException;
import org.json.JSONObject;
import static com.rubix.Resources.Functions.DATA_PATH;
import static com.rubix.Resources.Functions.IPFS_PORT;
import static com.rubix.Resources.Functions.LOGGER_PATH;
import static com.rubix.Resources.Functions.getValues;
import static com.rubix.Resources.Functions.nodeData;
import static com.rubix.Resources.Functions.randomPositions;
import static com.rubix.Resources.Functions.strToIntArray;
import static com.rubix.Resources.Functions.syncDataTable;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import static com.rubix.Resources.Functions.*;
import javax.imageio.ImageIO;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.json.JSONException;
import org.json.JSONObject;

import io.ipfs.api.IPFS;

public class Authenticate {
public static Logger AuthenticateLogger = Logger.getLogger(Authenticate.class);
public static int verifyCount = 0;

/**
* This method is used to authenticate a node in Rubix implementing text based two level NLSS.
* <P>It is customized for 32 positions verification. The position can be changed by
* This method is used to authenticate a node in Rubix implementing text based
* two level NLSS.
* <P>
* It is customized for 32 positions verification. The position can be changed
* by
* modifying the numberofpositions for integer array sizes accordingly
*
* @param detailString Details for verification
* @return boolean returns true if verified and false if not verified
* @throws IOException handles IO Exception
* @throws IOException handles IO Exception
* @throws JSONException handles JSON Exception
*/

public static boolean verifySignature(String detailString) throws IOException, JSONException {
PropertyConfigurator.configure(LOGGER_PATH + "log4jWallet.properties");
verifyCount++;
IPFS ipfs = new IPFS("/ip4/127.0.0.1/tcp/" + IPFS_PORT);
System.out.println(IPFS_PORT);
JSONObject details = new JSONObject(detailString);
String decentralizedID = details.getString("did");
String hash = details.getString("hash");
String signature = details.getString("signature");

syncDataTable(decentralizedID, null);
String walletIdIpfsHash = getValues(DATA_PATH + "DataTable.json", "walletHash", "didHash", decentralizedID);
nodeData(decentralizedID, walletIdIpfsHash, ipfs);

Expand All @@ -48,7 +61,7 @@ public static boolean verifySignature(String detailString) throws IOException, J
int[] SenderSign = strToIntArray(signature);
JSONObject P = randomPositions("verifier", hash, 32, SenderSign);
int[] posForSign = (int[]) P.get("posForSign");
int[] originalPos =(int[]) P.get("originalPos");
int[] originalPos = (int[]) P.get("originalPos");
for (int positionsLevelTwoTrail : posForSign)
senderWalletID.append(walletID.charAt(positionsLevelTwoTrail));

Expand All @@ -59,9 +72,9 @@ public static boolean verifySignature(String detailString) throws IOException, J
positionsLevelZero[k] = ((originalPos[k]) / 8);

StringBuilder decentralizedIDForAuth = new StringBuilder();
for (int value : positionsLevelZero) decentralizedIDForAuth.append(senderDIDBin.charAt(value));
for (int value : positionsLevelZero)
decentralizedIDForAuth.append(senderDIDBin.charAt(value));
if (recombinedResult.equals(decentralizedIDForAuth.toString())) {
AuthenticateLogger.info("Verification True");
return true;
} else {
AuthenticateLogger.info("Verification Failed");
Expand All @@ -71,4 +84,3 @@ public static boolean verifySignature(String detailString) throws IOException, J
}

}

56 changes: 24 additions & 32 deletions src/com/rubix/AuthenticateNode/Interact.java
Original file line number Diff line number Diff line change
@@ -1,67 +1,62 @@
package com.rubix.AuthenticateNode;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import static com.rubix.Resources.Functions.LOGGER_PATH;

import java.awt.image.BufferedImage;
import java.io.IOException;

import static com.rubix.Resources.Functions.LOGGER_PATH;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

public class Interact
{
public String privateShare = "", candidateShare = "",bits;
public class Interact {
public String privateShare = "", candidateShare = "", bits;
public static BufferedImage privateImage, walletImage;
public StringBuilder pvt,cnd;
public StringBuilder pvt, cnd;
public int[][] candidateArray;
public int[][] secret;
public static Logger InteractLogger = Logger.getLogger(Interact.class);


/**
* Constructor for setting the secret string
*
* @param inputSecret Secret string
*/

Interact(String inputSecret){
bits = inputSecret ;
Interact(String inputSecret) {
bits = inputSecret;
}

/**
* This method creates two shares using NLSS (1,2,2)
*
* @return Returns a boolean yes if shares are created successfully
* @throws IOException handles IO Exception
*/
public boolean createShare() throws IOException {
PropertyConfigurator.configure(LOGGER_PATH + "log4jDID.properties");
bits=bits.replaceAll("\\s+","");
secret= new int[bits.length()][8];
bits = bits.replaceAll("\\s+", "");
secret = new int[bits.length()][8];
candidateArray = new int[bits.length()][8];
SecretShare share;
pvt = new StringBuilder();
cnd = new StringBuilder();
for(int i = 0; i < bits.length(); i++)
{
if(bits.charAt(i)=='0')
{
for (int i = 0; i < bits.length(); i++) {
if (bits.charAt(i) == '0') {
share = new SecretShare(0);
share.starts();
for(int j=0;j<8;j++) {
for (int j = 0; j < 8; j++) {
secret[i][j] = SecretShare.S0[j];
candidateArray[i][j] = SecretShare.Y1[j];
pvt.append(SecretShare.S0[j]);
cnd.append(SecretShare.Y1[j]);
}
}
if(bits.charAt(i)=='1')
{
if (bits.charAt(i) == '1') {
share = new SecretShare(1);
share.starts();
for(int j=0;j<8;j++)
{
secret[i][j]= SecretShare.S0[j];
candidateArray[i][j]= SecretShare.Y1[j];
for (int j = 0; j < 8; j++) {
secret[i][j] = SecretShare.S0[j];
candidateArray[i][j] = SecretShare.Y1[j];
pvt.append(SecretShare.S0[j]);
cnd.append(SecretShare.Y1[j]);
}
Expand All @@ -74,17 +69,16 @@ public boolean createShare() throws IOException {
return checkShare();
}


/**
* This method combines the two shares to verify is the split is right or not
*
* @throws IOException handles IO Exceptions
*/
public boolean checkShare() throws IOException {
int i,j,sum;
int i, j, sum;
boolean verified = true;

for(i=0;i<secret.length;i++) {
for (i = 0; i < secret.length; i++) {
sum = 0;
for (j = 0; j < secret[i].length; j++)
sum += secret[i][j] * candidateArray[i][j];
Expand All @@ -95,13 +89,11 @@ public boolean checkShare() throws IOException {
verified = false;
}

if(verified) {
privateImage = PropImage.generateRGB(privateShare, 1024, 512);
walletImage = PropImage.generateRGB(candidateShare, 1024, 512);
if (verified) {
privateImage = PropImage.generateRGB(privateShare, 1024, 512);
walletImage = PropImage.generateRGB(candidateShare, 1024, 512);
}
return verified;
}

}


35 changes: 17 additions & 18 deletions src/com/rubix/AuthenticateNode/PropImage.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package com.rubix.AuthenticateNode;



import java.awt.image.BufferedImage;

import static com.rubix.Resources.Functions.binarytoDec;
import static com.rubix.Resources.Functions.intToBinary;

import java.awt.image.BufferedImage;

public class PropImage {

public static String img2bin(BufferedImage image){
public static String img2bin(BufferedImage image) {
int p, R, G, B;
StringBuilder bin = new StringBuilder();
int width = image.getWidth();
Expand All @@ -29,17 +26,18 @@ public static String img2bin(BufferedImage image){
return bin.toString();
}

public static BufferedImage generateRGB(String info, int width, int height){
public static BufferedImage generateRGB(String info, int width, int height) {
String dec = binarytoDec(info);
String[] splitval = dec.split("\\s");
if(splitval.length != width * height * 3)
if (splitval.length != width * height * 3)
return null;
else {
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
int a = 255, l = 0, q;
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
q = (a << 24) | (Integer.parseInt(splitval[l]) << 16) | (Integer.parseInt(splitval[l + 1]) << 8) | Integer.parseInt(splitval[l + 2]);
q = (a << 24) | (Integer.parseInt(splitval[l]) << 16) | (Integer.parseInt(splitval[l + 1]) << 8)
| Integer.parseInt(splitval[l + 2]);
image.setRGB(j, i, q);
l = l + 3;
}
Expand All @@ -48,20 +46,21 @@ public static BufferedImage generateRGB(String info, int width, int height){
}

}
public static String getpos(String s1, String s2){
int i,j,temp,temp1,sum;
if(s1.length()!=s2.length()||s1.length()<1){

public static String getpos(String s1, String s2) {
int i, j, temp, temp1, sum;
if (s1.length() != s2.length() || s1.length() < 1) {
return "";
}
StringBuilder tempo = new StringBuilder();
for(i=0;i<s1.length();i+=8){
sum=0;
for(j=i;j<i+8;j++){
temp = s1.charAt(j)-'0';
temp1 = s2.charAt(j)-'0';
sum+=temp*temp1;
for (i = 0; i < s1.length(); i += 8) {
sum = 0;
for (j = i; j < i + 8; j++) {
temp = s1.charAt(j) - '0';
temp1 = s2.charAt(j) - '0';
sum += temp * temp1;
}
sum%=2;
sum %= 2;
tempo.append(sum);
}
return tempo.toString();
Expand Down
Loading