Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
FENTEC_DIGCUR_UC_PUB
Customer_service_pub
Commits
6c7be1ce
Commit
6c7be1ce
authored
Sep 25, 2020
by
Miguel Mateo Montero
Browse files
release 09-2020
parent
92b44a6b
Changes
11
Expand all
Hide whitespace changes
Inline
Side-by-side
pom.xml
0 → 100644
View file @
6c7be1ce
<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/maven-v4_0_0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
eu.ari.fentec
</groupId>
<artifactId>
customer_service
</artifactId>
<packaging>
war
</packaging>
<version>
1.0-SNAPSHOT
</version>
<name>
customer_service Maven Webapp
</name>
<url>
http://maven.apache.org
</url>
<build>
<finalName>
customer_service
</finalName>
<plugins>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-compiler-plugin
</artifactId>
<version>
2.5.1
</version>
<inherited>
true
</inherited>
<configuration>
<source>
1.8
</source>
<target>
1.8
</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>
org.glassfish.jersey
</groupId>
<artifactId>
jersey-bom
</artifactId>
<version>
${jersey.version}
</version>
<type>
pom
</type>
<scope>
import
</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>
org.glassfish.jersey.containers
</groupId>
<artifactId>
jersey-container-servlet-core
</artifactId>
<!-- use the following artifactId if you don't need servlet 2.x compatibility -->
<!-- artifactId>jersey-container-servlet</artifactId -->
</dependency>
<dependency>
<groupId>
org.glassfish.jersey.inject
</groupId>
<artifactId>
jersey-hk2
</artifactId>
</dependency>
<dependency>
<groupId>
org.glassfish.jersey.media
</groupId>
<artifactId>
jersey-media-json-binding
</artifactId>
</dependency>
<dependency>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
<version>
3.8.1
</version>
<scope>
test
</scope>
</dependency>
<!-- <dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-ext-jdk15on</artifactId>
<version>1.62</version>
</dependency>-->
<dependency>
<groupId>
com.google.code.gson
</groupId>
<artifactId>
gson
</artifactId>
<version>
2.8.2
</version>
</dependency>
<dependency>
<groupId>
log4j
</groupId>
<artifactId>
log4j
</artifactId>
<version>
1.2.17
</version>
</dependency>
<dependency>
<groupId>
org.json
</groupId>
<artifactId>
json
</artifactId>
<version>
20151123
</version>
</dependency>
<dependency>
<groupId>
com.squareup.okhttp3
</groupId>
<artifactId>
okhttp
</artifactId>
<version>
3.10.0
</version>
</dependency>
<dependency>
<groupId>
eu.ari.fentec
</groupId>
<artifactId>
digcur_utils
</artifactId>
<version>
1
</version>
</dependency>
<!--dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-base</artifactId>
<version>11.0.2</version>
</dependency-->
</dependencies>
<properties>
<jersey.version>
2.27
</jersey.version>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
</properties>
</project>
src/main/java/eu/ari/fentec/connector/ExchangeConnector.java
0 → 100644
View file @
6c7be1ce
/**
*
*FENTEC Functional Encryption Technologies
*Privacy-preserving and Auditable Digital Currency Use Case
*Copyright © 2019 Atos Spain SA
*
*This program is free software: you can redistribute it and/or modify
*it under the terms of the GNU General Public License as published by
*the Free Software Foundation, either version 3 of the License, or
*(at your option) any later version.
*
*This program is distributed in the hope that it will be useful,
*but WITHOUT ANY WARRANTY; without even the implied warranty of
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
*GNU General Public License for more details.
*
*You should have received a copy of the GNU General Public License
*along with this program. If not, see <http://www.gnu.org/licenses/>.
**/
package
eu.ari.fentec.connector
;
import
java.util.ArrayList
;
import
org.apache.log4j.Logger
;
import
org.bouncycastle.util.encoders.Base64
;
import
org.json.JSONArray
;
import
org.json.JSONObject
;
import
eu.ari.fentec.payment.ECoinTypeMetaDataReduced
;
import
eu.ari.fentec.utils.conf.Configuration
;
import
eu.ari.fentec.utils.crypto.Utils
;
import
okhttp3.MediaType
;
import
okhttp3.OkHttpClient
;
import
okhttp3.Request
;
import
okhttp3.RequestBody
;
import
okhttp3.Response
;
public
class
ExchangeConnector
{
private
Logger
logger
=
Logger
.
getLogger
(
ExchangeConnector
.
class
);
/**
* @param funds ammount of ecoins
* @param walletID
* @param eCoinTypeName
* @return result of the operation
*/
public
boolean
wireTransferRequest
(
int
funds
,
byte
[]
walletID
,
ArrayList
<
String
>
eCoinTypeName
)
{
try
{
String
jsonS
=
getJsonTransfer
(
funds
,
walletID
,
eCoinTypeName
);
RequestBody
body
=
RequestBody
.
create
(
MediaType
.
parse
(
"Application/Json"
),
jsonS
);
logger
.
debug
(
"wiring transfer to exchange to create the account: "
+
jsonS
);
Request
request
=
new
Request
.
Builder
().
url
(
Configuration
.
getConfiguration
().
getProperty
(
"EXCHANGE_END_POINT"
)
+
"wireTranfer"
)
.
post
(
body
)
.
build
();
Response
response
;
OkHttpClient
mClient
=
new
OkHttpClient
();
response
=
mClient
.
newCall
(
request
).
execute
();
if
(
response
.
code
()
==
200
)
{
return
true
;
}
else
{
logger
.
error
(
"error while creating wiring transfer for merchant account to exchange."
);
logger
.
error
(
" exchange response: "
+
response
.
code
());
logger
.
error
(
" exchange msg: "
+
response
.
message
());
return
false
;
}
}
catch
(
Exception
e
)
{
logger
.
error
(
e
,
e
);
return
false
;
}
}
/**
* Creates the JSON for the request to Exchange
* @param funds
* @param walletID
* @param eCoinTypeName
* @return JSON body for the request
*/
private
String
getJsonTransfer
(
int
funds
,
byte
[]
walletID
,
ArrayList
<
String
>
eCoinTypeName
)
{
JSONObject
jo
=
new
JSONObject
();
jo
.
put
(
"funds"
,
funds
);
jo
.
put
(
"walletID"
,
Base64
.
toBase64String
(
walletID
));
for
(
String
s
:
eCoinTypeName
)
jo
.
append
(
"ect"
,
s
);
return
jo
.
toString
();
}
/**
* @return string array of Ecoin types name
*/
public
String
[]
getEcoinTypes
()
{
try
{
logger
.
debug
(
"retrieving eCoin names"
);
Request
request
=
new
Request
.
Builder
().
url
(
Configuration
.
getConfiguration
().
getProperty
(
"EXCHANGE_END_POINT"
)
+
"ecointype"
)
.
get
()
.
build
();
Response
response
;
OkHttpClient
mClient
=
new
OkHttpClient
();
response
=
mClient
.
newCall
(
request
).
execute
();
if
(
response
.
code
()
==
200
)
{
JSONObject
jo
=
new
JSONObject
(
response
.
body
().
string
());
JSONArray
ja
=
jo
.
getJSONArray
(
"ectNames"
);
String
nameA
[]
=
new
String
[
ja
.
length
()];
for
(
int
i
=
0
;
i
<
ja
.
length
();
i
++)
nameA
[
i
]=
ja
.
getString
(
i
);
return
nameA
;
}
else
{
logger
.
error
(
"error while retrieveing eCoint type names to exchange."
);
logger
.
error
(
" exchange response: "
+
response
.
code
());
logger
.
error
(
" exchange msg: "
+
response
.
message
());
return
null
;
}
}
catch
(
Exception
e
)
{
logger
.
error
(
e
,
e
);
return
null
;
}
}
/**
* @param name
* @return Ecoin type metadata (name, denominations)
*/
public
ECoinTypeMetaDataReduced
getEcoinType
(
String
name
){
try
{
Request
request
=
new
Request
.
Builder
().
url
(
Configuration
.
getConfiguration
().
getProperty
(
"EXCHANGE_END_POINT"
)
+
"ecointype/"
+
name
)
.
get
()
.
build
();
Response
response
;
OkHttpClient
mClient
=
new
OkHttpClient
();
response
=
mClient
.
newCall
(
request
).
execute
();
if
(
response
.
code
()
==
200
)
{
String
ectS
=
response
.
body
().
string
();
logger
.
debug
(
"serialized ect length: "
+
ectS
.
length
());
logger
.
debug
(
"serialized ect: "
+
ectS
);
ECoinTypeMetaDataReduced
ectR
=
new
Utils
().
deserializeECoinType
(
ectS
);
if
(
ectR
!=
null
)
return
ectR
;
else
{
logger
.
error
(
"no se pudo deserializar ectS"
);
return
null
;
}
}
else
{
logger
.
error
(
"error while retrieveing eCoint type from exchange."
);
logger
.
error
(
" exchange response: "
+
response
.
code
());
logger
.
error
(
" exchange msg: "
+
response
.
message
());
return
null
;
}
}
catch
(
Exception
e
)
{
logger
.
error
(
e
,
e
);
return
null
;
}
}
/**
* @param blindData
* @param eCoinTypeName
* @param denomination
* @param walletId
* @return blind signature encoded in base64 String format
*/
public
String
blindSignatureRequest
(
byte
[]
blindData
,
String
eCoinTypeName
,
int
denomination
,
byte
[]
walletId
)
{
try
{
String
jsonSsignature
=
jsonSsignature
(
blindData
,
eCoinTypeName
,
denomination
,
walletId
);
RequestBody
body
=
RequestBody
.
create
(
MediaType
.
parse
(
"Application/Json"
),
jsonSsignature
);
logger
.
debug
(
"Requesting blind signature: "
+
jsonSsignature
);
Request
request
=
new
Request
.
Builder
().
url
(
Configuration
.
getConfiguration
().
getProperty
(
"EXCHANGE_END_POINT"
)
+
"blindSignature"
)
.
post
(
body
)
.
build
();
Response
response
;
OkHttpClient
mClient
=
new
OkHttpClient
();
response
=
mClient
.
newCall
(
request
).
execute
();
if
(
response
.
code
()
==
200
)
{
String
signature
=
response
.
body
().
string
();
logger
.
debug
(
"blind signature received"
);
return
signature
;
}
else
{
logger
.
error
(
"error while creating wiring transfer for merchant account to exchange."
);
logger
.
error
(
" exchange response: "
+
response
.
code
());
logger
.
error
(
" exchange msg: "
+
response
.
message
());
return
null
;
}
}
catch
(
Exception
e
)
{
logger
.
error
(
e
,
e
);
return
null
;
}
}
/**
* @param blindData
* @param eCoinTypeName
* @param denomination
* @param walletId
* @return JSON body for the request
*/
private
String
jsonSsignature
(
byte
[]
blindData
,
String
eCoinTypeName
,
int
denomination
,
byte
[]
walletId
)
{
JSONObject
jo
=
new
JSONObject
();
jo
.
put
(
"data"
,
Base64
.
toBase64String
(
blindData
));
jo
.
put
(
"ect"
,
eCoinTypeName
);
jo
.
put
(
"value"
,
denomination
);
jo
.
put
(
"id"
,
Base64
.
toBase64String
(
walletId
));
return
jo
.
toString
();
}
/**
* @param eInvoiceJson base64 String format of the cyphered eInvoice
* @return
*/
public
String
uploadEInvoice
(
String
eInvoiceJson
)
{
try
{
RequestBody
body
=
RequestBody
.
create
(
MediaType
.
parse
(
"Application/Json"
),
eInvoiceJson
);
logger
.
debug
(
"Uploadinig eInvoice"
);
Request
request
=
new
Request
.
Builder
().
url
(
Configuration
.
getConfiguration
().
getProperty
(
"EXCHANGE_END_POINT"
)
+
"eInvoice"
)
.
post
(
body
)
.
build
();
Response
response
;
OkHttpClient
mClient
=
new
OkHttpClient
();
response
=
mClient
.
newCall
(
request
).
execute
();
if
(
response
.
code
()==
200
||
response
.
code
()
==
201
)
{
return
""
;
}
else
{
logger
.
error
(
"error while uploading eInvoice to Exchange."
);
logger
.
error
(
" exchange response: "
+
response
.
code
());
logger
.
error
(
" exchange msg: "
+
response
.
message
());
return
null
;
}
}
catch
(
Exception
e
)
{
logger
.
error
(
e
,
e
);
return
null
;
}
}
}
src/main/java/eu/ari/fentec/connector/MerchantConnector.java
0 → 100644
View file @
6c7be1ce
/**
*
*FENTEC Functional Encryption Technologies
*Privacy-preserving and Auditable Digital Currency Use Case
*Copyright © 2019 Atos Spain SA
*
*This program is free software: you can redistribute it and/or modify
*it under the terms of the GNU General Public License as published by
*the Free Software Foundation, either version 3 of the License, or
*(at your option) any later version.
*
*This program is distributed in the hope that it will be useful,
*but WITHOUT ANY WARRANTY; without even the implied warranty of
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
*GNU General Public License for more details.
*
*You should have received a copy of the GNU General Public License
*along with this program. If not, see <http://www.gnu.org/licenses/>.
**/
package
eu.ari.fentec.connector
;
import
java.util.ArrayList
;
import
org.apache.log4j.Logger
;
import
eu.ari.fentec.econtract.Product
;
import
eu.ari.fentec.econtract.ProductList
;
import
eu.ari.fentec.utils.conf.Configuration
;
import
eu.ari.fentec.utils.crypto.Utils
;
import
okhttp3.MediaType
;
import
okhttp3.OkHttpClient
;
import
okhttp3.Request
;
import
okhttp3.RequestBody
;
import
okhttp3.Response
;
public
class
MerchantConnector
{
Logger
logger
=
Logger
.
getLogger
(
MerchantConnector
.
class
);
/**
* @param merchantName
* @return ArrayList of products
*/
public
ArrayList
<
Product
>
retrieveProducts
(
String
merchantName
)
{
logger
.
debug
(
"retrieving products from merchant: "
);
try
{
Request
request
=
new
Request
.
Builder
().
url
(
Configuration
.
getConfiguration
().
getProperty
(
"MERCHANT_END_POINT"
)
+
merchantName
+
"/products"
)
.
get
()
.
build
();
Response
response
;
OkHttpClient
mClient
=
new
OkHttpClient
();
response
=
mClient
.
newCall
(
request
).
execute
();
if
(
response
.
code
()
==
200
)
{
String
productsS
=
response
.
body
().
string
();
ProductList
pl
=
new
Utils
().
deserializeProducts
(
productsS
);
return
pl
.
getProductList
();
}
else
{
logger
.
error
(
"error while retrieving products from customer"
);
logger
.
error
(
" merchange response: "
+
response
.
code
());
logger
.
error
(
"merchant msg: "
+
response
.
message
());
return
null
;
}
}
catch
(
Exception
e
)
{
logger
.
error
(
e
,
e
);
return
null
;
}
}
//econtractRequest(productsS);
/**
* @param productsS Serialization of list of Products of the purchase
* @param merchantName
* @return eContract
*/
public
String
econtractRequest
(
String
productsS
,
String
merchantName
)
{
logger
.
debug
(
"requesting econtract"
);
try
{
RequestBody
body
=
RequestBody
.
create
(
MediaType
.
parse
(
"Application/Text"
),
productsS
);
Request
request
=
new
Request
.
Builder
().
url
(
Configuration
.
getConfiguration
().
getProperty
(
"MERCHANT_END_POINT"
)
+
merchantName
+
"/econtractRequest"
)
.
post
(
body
)
.
build
();
Response
response
;
OkHttpClient
mClient
=
new
OkHttpClient
();
response
=
mClient
.
newCall
(
request
).
execute
();
if
(
response
.
code
()
==
200
)
{
String
econtractS
=
response
.
body
().
string
();
return
econtractS
;
}
else
{
logger
.
error
(
"error while crequesting ."
);
logger
.
error
(
" trusted authority response: "
+
response
.
code
());
logger
.
error
(
"trusted authority msg: "
+
response
.
message
());
return
null
;
}
}
catch
(
Exception
e
)
{
logger
.
error
(
e
,
e
);
return
null
;
}
}
//econtractSendback
/**
* This method is used to perform a payment
* @param econtractS
* @param merchantName
* @return result of the operation
*/
public
boolean
econtractSendBack
(
String
econtractS
,
String
merchantName
)
{
logger
.
debug
(
"econtractSendBack"
);
try
{
RequestBody
body
=
RequestBody
.
create
(
MediaType
.
parse
(
"Application/Text"
),
econtractS
);
Request
request
=
new
Request
.
Builder
().
url
(
Configuration
.
getConfiguration
().
getProperty
(
"MERCHANT_END_POINT"
)
+
merchantName
+
"/econtractSendBack"
)
.
post
(
body
)
.
build
();
Response
response
;
OkHttpClient
mClient
=
new
OkHttpClient
();
response
=
mClient
.
newCall
(
request
).
execute
();
if
(
response
.
code
()
==
200
)
{
return
true
;
}
else
{
logger
.
error
(
"error while sending back econtract ."
);
logger
.
error
(
"merchant response: "
+
response
.
code
());
logger
.
error
(
"merchant msg: "
+
response
.
message
());
return
false
;
}
}
catch
(
Exception
e
)
{
logger
.
error
(
e
,
e
);
return
false
;
}
}
}
src/main/java/eu/ari/fentec/connector/TrustedAuthorityConnector.java
0 → 100644
View file @
6c7be1ce
/**
*
*FENTEC Functional Encryption Technologies
*Privacy-preserving and Auditable Digital Currency Use Case
*Copyright © 2019 Atos Spain SA
*
*This program is free software: you can redistribute it and/or modify
*it under the terms of the GNU General Public License as published by
*the Free Software Foundation, either version 3 of the License, or
*(at your option) any later version.
*
*This program is distributed in the hope that it will be useful,
*but WITHOUT ANY WARRANTY; without even the implied warranty of
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
*GNU General Public License for more details.
*
*You should have received a copy of the GNU General Public License
*along with this program. If not, see <http://www.gnu.org/licenses/>.
**/
package
eu.ari.fentec.connector
;
import
java.util.ArrayList
;
import
org.apache.log4j.Logger
;
import
org.json.JSONObject
;
import
eu.ari.fentec.payment.ValidationToken
;
import
eu.ari.fentec.utils.conf.Configuration
;
import
eu.ari.fentec.utils.crypto.Utils
;
import
okhttp3.MediaType
;
import
okhttp3.OkHttpClient
;
import
okhttp3.Request
;
import
okhttp3.RequestBody
;
import
okhttp3.Response
;
public
class
TrustedAuthorityConnector
{
private
Logger
logger
=
Logger
.
getLogger
(
TrustedAuthorityConnector
.
class
);
/**
* @param name
* @param ectAL
* @param type
* @return ID of the account, null in case of error
*/
public
String
createAccountRequest
(
String
name
,
ArrayList
<
String
>
ectAL
,
String
type
)
{
try
{
String
jsonS
=
getJsonB
(
name
,
ectAL
,
type
);
RequestBody
body
=
RequestBody
.
create
(
MediaType
.
parse
(
"Application/Json"
),
jsonS
);
logger
.
debug
(
"Creating account for customer: "
+
jsonS
);
Request
request
=
new
Request
.
Builder
().
url
(
Configuration
.
getConfiguration
().
getProperty
(
"TRUSTEDAUTH_END_POINT"
)+
"createAccount"
)
.
post
(
body
)
.
build
();
Response
response
;
OkHttpClient
mClient
=
new
OkHttpClient
();
response
=
mClient
.
newCall
(
request
).
execute
();
if
(
response
.
code
()
==
200
)
{
String
id
=
response
.
message
();
return
id
;
}
else
{
logger
.
error
(
"error while creating customer account at the trusted authority."
);
logger
.
error
(
" trusted authority response: "
+
response
.
code
());
logger
.
error
(
"trusted authority msg: "
+
response
.
message
());
return
null
;
}
}
catch
(
Exception
e
)
{
logger
.
error
(
e
,
e
);
return
null
;
}
}
/**
* @param name