Skip to content

Commit

Permalink
Changes to support multirow
Browse files Browse the repository at this point in the history
Now functions work both with single and multirow. Also updated script to record time to understand performance differences.
  • Loading branch information
flautrup committed Aug 17, 2018
1 parent e5be035 commit 3428414
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 66 deletions.
26 changes: 3 additions & 23 deletions server/capabilities.js
Expand Up @@ -22,7 +22,7 @@ capabilities = {
{
functionId: 1,
name: 'AESEncryptData',
functionType: proto.FunctionType.SCALAR,
functionType: proto.FunctionType.TENSOR,
returnType: proto.DataType.STRING,
params: [{
name: 'str1',
Expand All @@ -32,7 +32,7 @@ capabilities = {
{
functionId: 2,
name: 'AESDecryptData',
functionType: proto.FunctionType.SCALAR,
functionType: proto.FunctionType.TENSOR,
returnType: proto.DataType.STRING,
params: [{
name: 'str1',
Expand All @@ -42,7 +42,7 @@ capabilities = {
{
functionId: 3,
name: 'FPEEncryptData',
functionType: proto.FunctionType.SCALAR,
functionType: proto.FunctionType.TENSOR,
returnType: proto.DataType.STRING,
params: [{
name: 'str1',
Expand All @@ -52,26 +52,6 @@ capabilities = {
{
functionId: 4,
name: 'FPEDecryptData',
functionType: proto.FunctionType.SCALAR,
returnType: proto.DataType.STRING,
params: [{
name: 'str1',
dataType: proto.DataType.STRING
}]
},
{
functionId: 5,
name: 'AESEncryptMultiRowData',
functionType: proto.FunctionType.TENSOR,
returnType: proto.DataType.STRING,
params: [{
name: 'str1',
dataType: proto.DataType.STRING
}]
},
{
functionId: 6,
name: 'AESDecryptMultiRowData',
functionType: proto.FunctionType.TENSOR,
returnType: proto.DataType.STRING,
params: [{
Expand Down
76 changes: 73 additions & 3 deletions server/example_script.txt
Expand Up @@ -52,6 +52,9 @@ Autogenerate 100


//AES test
TimeLog:
LOAD Now() as LogTime, 'StartAESEnc' as LogStatus AUTOGENERATE(1);

AESTransactionsSSE:
Load
Dim1 as SSEDim1,
Expand All @@ -61,31 +64,98 @@ Autogenerate 100
secSSE.AESEncryptData(Dim1) as AESEncDim1
resident Transactions;

TimeLog:
LOAD Now() as LogTime, 'StopAESEnc' as LogStatus AUTOGENERATE(1);

TimeLog:
LOAD Now() as LogTime, 'StartAESDec' as LogStatus AUTOGENERATE(1);

AESTransactionSSEDecrypt:
Load
AESEncDim1 as EncTmpDim1,
secSSE.AESDecryptData(AESEncDim1) as AESDim1Decrypted,
SSEDim1 as OrgDim1
resident AESTransactionsSSE;


TimeLog:
LOAD Now() as LogTime, 'StopAESDec' as LogStatus AUTOGENERATE(1);


//FPE

TimeLog:
LOAD Now() as LogTime, 'StartFPEEnc' as LogStatus AUTOGENERATE(1);

FPETransactionsSSE:
Load
CardNbr as FPECardNbr,
secSSE.FPEEncryptData(CardNbr) as FPEEncCardNbr
resident Transactions;

TimeLog:
LOAD Now() as LogTime, 'StopFPEEnc' as LogStatus AUTOGENERATE(1);

TimeLog:
LOAD Now() as LogTime, 'StartFPEDec' as LogStatus AUTOGENERATE(1);


FPETransactionSSEDecrypt:
Load
FPEEncCardNbr,
secSSE.FPEDecryptData(FPEEncCardNbr) as FPECardNbrDecrypted,
FPECardNbr as OrgCardNbr
resident FPETransactionsSSE;

TimeLog:
LOAD Now() as LogTime, 'StopFPEDec' as LogStatus AUTOGENERATE(1);


//Multi-row test AES test
TimeLog:
LOAD Now() as LogTime, 'StartAESEncMulti' as LogStatus AUTOGENERATE(1);

AESMultirowTransactionSSE:
Load Field1 as SSEMDim1 Extension secSSE.AESEncryptMultiRowData(Transactions{Dim1});
Load
Field1 as SSEMDim1
Extension secSSE.AESEncryptData(Transactions{Dim1});

TimeLog:
LOAD Now() as LogTime, 'StopAESEncMulti' as LogStatus AUTOGENERATE(1);

TimeLog:
LOAD Now() as LogTime, 'StartAESDecMulti' as LogStatus AUTOGENERATE(1);

AESMultirowTransactionSSEDecrypt:
Load Field1 as SSEMDim1Decrypted Extension secSSE.AESDecryptMultiRowData(AESMultirowTransactionSSE{SSEMDim1});
Load
Field1 as SSEMDim1Decrypted
Extension secSSE.AESDecryptData(AESMultirowTransactionSSE{SSEMDim1});

TimeLog:
LOAD Now() as LogTime, 'StartAESDecMulti' as LogStatus AUTOGENERATE(1);


//Multi-row test FPE
TimeLog:
LOAD Now() as LogTime, 'StartFPEEncMulti' as LogStatus AUTOGENERATE(1);


FPEMultirowTransactionSSE:
Load
Field1 as SSEMFPECardNbr,
Extension secSSE.FPEEncryptData(Transactions{CardNbr});

TimeLog:
LOAD Now() as LogTime, 'StopFPEEncMulti' as LogStatus AUTOGENERATE(1);


TimeLog:
LOAD Now() as LogTime, 'StartFPEDecMulti' as LogStatus AUTOGENERATE(1);


FPEMultirowTransactionSSEDecrypt:
Load
Field1 as SSEMFPECardNbrDecrypted
Extension secSSE.FPEDecryptData(FPEMultirowTransactionSSE{SSEMFPECardNbr});

TimeLog:
LOAD Now() as LogTime, 'StopFPEDecMulti' as LogStatus AUTOGENERATE(1);
43 changes: 3 additions & 40 deletions server/index.js
@@ -1,5 +1,3 @@
//Todo: Don't need seperate functions. Instead have versions that both work with multi-row and single row.

//Load modules
const grpc = require('grpc');
const protobuf = require('protobufjs');
Expand Down Expand Up @@ -43,10 +41,6 @@ const ExecuteFunction = (call) => {
rowData = fpeEncryptData(rowData);
} else if (header.functionId == 4) {
rowData = fpeDecryptData(rowData);
} else if (header.functionId == 5) {
rowData = aesEncryptMultiRowData(rowData);
} else if (header.functionId == 6) {
rowData = aesDecryptMultiRowData(rowData);
}

call.write(rowData);
Expand All @@ -71,21 +65,22 @@ const helloWorld = (rowData) => {

//AES encryption/decryption
const aesEncryptData = (rowData) => {
const cipher = crypto.createCipher(config.algorithm, config.key);
for (count = 0; count < rowData.rows.length; count++) {
let cipher = crypto.createCipher(config.algorithm, config.key);
let encrypted = cipher.update(rowData.rows[count].duals[0].strData, 'utf8', 'hex');
encrypted += cipher.final('hex');
//console.log(encrypted);

rowData.rows[count].duals[0].strData = encrypted;
rowData.rows[count].duals[0].numData = 0;
}

return rowData;
}

const aesDecryptData = (rowData) => {
const decipher = crypto.createDecipher(config.algorithm, config.key);
for (count = 0; count < rowData.rows.length; count++) {
let decipher = crypto.createDecipher(config.algorithm, config.key);
let decrypted = decipher.update(rowData.rows[count].duals[0].strData, 'hex', 'utf8');
decrypted += decipher.final('utf8');
//console.log(decrypted);
Expand All @@ -100,7 +95,6 @@ const aesDecryptData = (rowData) => {
const fpeEncryptData = (rowData) => {
const fpeCipher = fpeCrypto({password: config.key, domain: config.domain});
for (count = 0; count < rowData.rows.length; count++) {

rowData.rows[count].duals[0].strData = fpeCipher.encrypt(rowData.rows[count].duals[0].strData);
rowData.rows[count].duals[0].numData = 0;
}
Expand All @@ -110,44 +104,13 @@ const fpeEncryptData = (rowData) => {
const fpeDecryptData = (rowData) => {
const fpeCipher = fpeCrypto({password: config.key, domain: config.domain});
for (count = 0; count < rowData.rows.length; count++) {

rowData.rows[count].duals[0].strData = fpeCipher.decrypt(rowData.rows[count].duals[0].strData);
rowData.rows[count].duals[0].numData = 0;
}

return rowData;
}

//AES encryption/decryption of multi-row data
const aesEncryptMultiRowData = (rowData) => {
console.log(rowData);
for (count = 0; count < rowData.rows.length; count++) {
let cipher = crypto.createCipher(config.algorithm, config.key);
let encrypted = cipher.update(rowData.rows[count].duals[0].strData, 'utf8', 'hex');
encrypted += cipher.final('hex');
//console.log(encrypted);

rowData.rows[count].duals[0].strData = encrypted;
rowData.rows[count].duals[0].numData = 0;
}

return rowData;
}

const aesDecryptMultiRowData = (rowData) => {
console.log(rowData);
for (count = 0; count < rowData.rows.length; count++) {
let decipher = crypto.createDecipher(config.algorithm, config.key);
let decrypted = decipher.update(rowData.rows[count].duals[0].strData, 'hex', 'utf8');
decrypted += decipher.final('utf8');
//console.log(decrypted);

rowData.rows[count].duals[0].strData = decrypted;
rowData.rows[count].duals[0].numData = 0;
}
return rowData;
}

//define the callable methods that correspond to the methods defined in the protofile
server.addService(proto.qlik.sse.Connector.service, {
getCapabilities: GetCapabilities,
Expand Down

0 comments on commit 3428414

Please sign in to comment.