Professional Documents
Culture Documents
– Enhanced Services
Technical Report
Elsa Estevez
Vincent Douwe
Tomasz Janowski
version 1.0
location www.egov.iist.unu.edu/outputs
TABLE OF CONTENTS
Summary .................................................................................................................................................................................... i
Table of Contents ...................................................................................................................................................................... ii
List of Tables............................................................................................................................................................................. iii
List of Figures ........................................................................................................................................................................... iii
Abbreviations ........................................................................................................................................................................... iv
Revisions .................................................................................................................................................................................. iv
1. Introduction .......................................................................................................................................................................... 1
2. Encrypting and Decrypting Messages.................................................................................................................................... 2
2.1. Enabling Encryption/Decryption Extension .................................................................................................................. 3
2.2. Setting the PIN ............................................................................................................................................................... 4
2.3. Configuring Encryption/Decryption Extension ............................................................................................................. 4
2.4. Disabling the Encrytion/Decryption Extension ............................................................................................................. 7
2.5. Sending an Encrypted Message ..................................................................................................................................... 8
2.6. Receiving an Encrypted Message .................................................................................................................................. 9
3. New APIs for Legacy Systems .............................................................................................................................................. 10
3.1. Programming Languages used by Macao Government Agencies ............................................................................... 10
3.2. APIs for Delphi ............................................................................................................................................................. 11
3.3. APIs for Sending and Receiving Messages from the Command Line .......................................................................... 13
4. Deployment Components and Procedure .......................................................................................................................... 16
4.1. Deployment Components ............................................................................................................................................ 16
4.2. Deployment Procedure................................................................................................................................................ 17
5. Conclusions ......................................................................................................................................................................... 19
References............................................................................................................................................................................... 20
Appendices .............................................................................................................................................................................. 21
A. Java Classes Used by the Encryption Extension .............................................................................................................. 21
B. Delphi APIs...................................................................................................................................................................... 31
C. Programming Languages and Tools Used by Government Applications ........................................................................ 51
D. Java Classes for Sending and Receiving Messages through the Command Line ............................................................ 60
E. Gateway Configuration File ............................................................................................................................................ 63
LIST OF TABLES
Table 1: Encrypting and Decrypting Messages using RSA and AES ............................................................................................ 2
Table 2: Programming Languages and Tools Mostly Used by Government Applications........................................................ 10
LIST OF FIGURES
Figure 1: Smart Card Issued by Macao Post and Smart Card Reader ........................................................................................ 2
Figure 2: Enabling Encryption/Decryption Extension ................................................................................................................ 3
Figure 3: Setting the PIN ............................................................................................................................................................ 4
Figure 4: User Interface for Setting the PIN .............................................................................................................................. 5
Figure 5: Configuring Encryption/Decryption – Owner’s Side ................................................................................................... 5
Figure 6: Configuring Encryption/Decryption – Subscriber’s Side ............................................................................................. 6
Figure 7: Disabling Encryption/Decryption – Owner s’ Side ...................................................................................................... 7
Figure 8: Disabling Encryption/Decryption – Subscriber’s Side ................................................................................................. 7
Figure 9: Sending an Encrypted Message .................................................................................................................................. 8
Figure 10: Receiving an Encrypted Message ............................................................................................................................. 9
Figure 11: Send Class - Main Method ...................................................................................................................................... 14
Figure 12: Receive Class - Main Method ................................................................................................................................. 15
Figure 13: Extensible Message Gateway – Deployment Folders ............................................................................................. 16
Figure 14: Folder Structure for Receiving and Sending Messages through the Command Line .............................................. 18
ABBREVIATIONS
REVISIONS
2. ENCRYPTING AND DECRYPTING MESSAGES Figure 1: Smart Card Issued by Macao Post and Smart
Card Reader
Encryption/Decryption is one of the extensions provided
by the first release of the Extensible Messaging Gate-
way. The extension enables encoding of message con-
tents while messages are exchanged by members
through channels. In the first release, the extension
encoded messages using the RSA [6] method. The me-
thod, proposed by R.L. Rivest, A. Shamir and L. Adleman,
implements a private-public key cryptosystem enabling
exchange of ciphered messages without need to com-
municate keys along with the message. The RSA method
implemented by the Gateway extension assigned to the
Gateway Administrator – Admin member, the responsi-
bility for generating the pairs of private-public keys for
each member. Although the approach successfully
showed the behavior of the Encryption/Decryption ex-
tension, the use of these auto-generated keys should be
reviewed before adopting the Gateway in real e-
Government solutions. Following the encryption approach suggested by
eSignTrust, the new release of the Gateway extension
One of the revised objectives of the Macao Data Ex- encodes message contents using a hybrid combination
change Gateway Project for 2008 was to replace the of RSA, the method used by the first release of the Ga-
private-public keys generated by the Gateway Adminis- teway, and Advanced Encryption Standard (AES) [7]
trator, by the certificates issued by Macao Post Office. In method. The AES algorithm is a symmetric block cipher
support of the EDS Law no. 5/2005 promoting the use of for encrypting and decrypting information. The ap-
new technologies for assuring secure electronic transac- proach implemented by the Gateway extension is as
tions over open communication networks, Macao Post follows. The message content (c) and a randomly gener-
established eSignTrust – a Certification Service Provider ated key (k) are encrypted using AES, producing an en-
[8]. Among other tasks, eSignTrust is responsible for crypted content (c’). If the message is sent by a channel
issuing encipherment certificates which can be used for subscriber, the generated key (k) is encrypted with the
encrypting and decrypting data, sending encrypted mes- public key of the channel owner (PuK) using the RSA
sages, decrypting messages, and acknowledging the method producing an encoded key (k’). If the message is
receipt of an encrypted message using digital signature. sent by the channel owner, the generated key (k) is en-
Encipherment certificates and their public and private crypted with the channel owner’s private key (PrK). Fi-
keys are stored in smart cards, which can be read nally, the encoded content (c’) and the encrypted key
through a wide range of industry smart card readers, (k’) are sent. For decrypting the message, first the en-
and are also available through their website. Figure 1 crypted key (k’) is decrypted following the RSA method,
shows an example of smart card and smart card reader. and the generated key (k) is obtained.
SENDER RECEIVER
NO ACTION NO ACTION
If the message recipient is a channel subscriber, the e) Sending an Encrypted Message – messages sent
encrypted key (k’) is decrypted using the channel own- through a channel having the Encryp-
er’s public key (PuK); while, if the recipient is the chan- tion/Decryption extension enabled and configured
nel owner, it is decrypted using its private key (PrK). are encrypted using the procedure defined in Table
Second, the encrypted message (c’) is decrypted using 1.
the generated key (k) following the AES method, pro-
ducing the plain message (c). Finally, the plain text of f) Receiving an Encrypted Message – messages re-
the message (c) is received by the recipient application. ceived through a channel having the Encryp-
Table 1 summarizes this process. tion/Decryption extension enabled and configured
are decrypted using the procedure defined in Table
Based on the motivations explained above, a new re- 1.
lease of the Encryption/Decryption extension using the
certificates issued by eSignTrust is provided. The exten- The following sections explain technical details for
sion provides the following services: enabling the extension (Section 2.1), setting the pin
(Section 2.2), configuring (Section 2.2) and disabling
a) Enabling Encryption/Decryption – after enabling the (Section 2.3) the extension, and for sending (Section 2.4)
extension for a channel, all messages sent through and receiving (Section 2.5) messages using the new ex-
the channel will be encrypted by the sender and tension release. The source code of the Java classes
decrypted by the recipients using the public and used by the extension is included in Appendix A.
private keys of the channel owner.
2.1. ENABLING ENCRYPTION/DECRYPTION
b) Setting Pin – enables to define the Personal Identi- EXTENSION
fication Number (PIN) for the member to access the
smart card for reading the private/public keys. The Encryption/Decryption extension is a channel-
oriented extension. In the new release, no changes were
c) Configuring Encryption/Decryption – involves dis- introduced for enabling a channel-oriented extension.
tributing the public key of the channel owner The process is depicted in Figure 2 and explained as
among channel subscribers. follows. The External Application requests the member
acting on its behalf to enable the extension
d) Disabling Encryption/Decryption – after disabling (1:enableExtension). The member prepares the
the extension, messages sent through the channel message to be sent to the Gateway administrator
are exchanged in plain text – they are no longer en-
crypted.
(2:msgToAdminExtension) and sends the message Figure 3 presents the sequence diagram explaining the
(3:sendMessage). The Admin member receives the implementation of the setPin operation. The external
message (4:receiveMessage) and pushes it to the application requires its member to set the PIN
application listener of the Gateway Administrator (1:setPin). The member invokes the function for
(5:receiveMessage). The administrator processes setting the PIN provided by the ExtensionsUtil
the request (6:requestExtension), which includes class (2:setPin). The utility class encrypts the PIN and
creating a new object for enabling the extension on the the member identifier using the AES method
Administrator’s side (7:create), setting the extension (3:encryptWithAES), and stores the PIN in a file
parameters (8:setParameters) – like the channel (4:storeToFile). The file is stored in the folder indi-
identifier for which the extension is enabled, storing the cated by the WorkFolder parameter of the Gateway
new enabled extension in the database configuration file. The file name starts with “PIN-“
(9:storeExtension) and replying to the member followed by the member identification, and ends with
(10:sendMessage). Upon receiving the reply mes- “.xg2g”.
sage (11:receiveMessage), the member requests
the channel owner to enable the extension In addition to the Gateway libraries, the user interface
(12:configureExtension). The channel forwards was modified to include the service for setting the PIN.
the request to the object managing all channel-oriented The interface is shown in Figure 4. The option for re-
extensions (13:configureExtension). Finally, the questing the service is at the bottom of the Exten-
member replies the result to the external application sion Menu on the left. Once selected, a window re-
(14:recChExtensionReply). In the figure, the four questing to introduce the PIN number and to confirm
objects on the left – depicted in green, are located at (Set button) is presented to the user. In the figure,
the member’s node, while the three objects on the right these features are highlighted by the ellipsis in red.
– depicted in orange are located at the Gateway admin-
istrator’s node. 2.3. CONFIGURING ENCRYPTION/DECRYPTION
EXTENSION
2.2. SETTING THE PIN
Configuring the Encryption/Decryption extensions re-
Configuring the Encryption/Decryption extension implies quires reading the channel owner’s public key stored in
distributing the public key of the channel owner to the smart card and distributing it to channel subscribers.
channel subscribers. The public and private keys issued The process is explained in two parts: i) from the chan-
by eSignTrust and used by the EncryptionDecryption nel owner’s side, and ii) from the channel subscriber’s
extension are stored in smart cards. For accessing a side.
smart card through the card reader, a PIN – Personal
Identification Number is requested. The PIN is given to Figure 5 shows the process for configuring the extension
the card holder upon issuance of the smart card. There- from the owner’s side. ExternalApplication re-
fore, if a member – owner of a channel, is willing to quests the member to configure the extension
enable the Encryption/Decryption extension on its (1:configureExtension). Five parameters are
owned channel, it needs to know its PIN to be able to required for configuring the extension. The parameters
access the public and private keys stored on the smart and their corresponding values are as follows:
card. A new operation was added to the IMember in-
terface – setPin, for addressing this need. The Mem- i) extension type – the value must be “channel”,
ber class implements this operation. since Encryption is a channel-oriented extension;
Figure 3: Setting the PIN ii) channel identifier – id of the channel for which the
extension is configured;
Following the configuration request, Member asks Ex- database (10:storeParam). Finally, the Encryp-
tensionsUtil to get the public and private keys tion object requests the member to forward its public
from the smart card (2:getKeys). To fulfill the re- key to all subscribers
quest, ExtensionsUtil gets the configuration file (11:forwardToAllSubscribers). Member for-
where details of the smart card reader are stored, reads wards this message to all channel subscribers
the keys from the smart card, and returns the pair of (12:forwardMessage). And finally, the recConfigu-
keys (3:pair) to the member. Member prepares a reChExtension of the ApplicationListener is invoked.
message to the Administrator
(4:msgToAdminConfigure) and invokes the opera- Figure 6 presents the process for configuring the exten-
tion for configuring the extension in the owned channel sion on the subscriber’s side. Upon receiving the mes-
object (5:configureExtension). In this particular sage (1:receive), the member identifies the message
case, the message prepared to the Administrator is used was received by a subscribed channel and invokes the
but not really sent since all parameters required to con- method of this class (2:receive). Since it is a for-
figure the extension are locally available on the smart warded message, it is passed to the member for
card. Following the request from Member, Owned- processing (3:recForwardReply). After identifying
Channel requests ChAllExtMgr to configure the the type of message, the member’s enableSubsEx-
extension (6:configureExtension). ChAl- tension method is invoked
lExtMgr invokes its method for getting the object for (4:enableSubsExtension). The method requests
the specific extension (7:getExtension). Following to the ChExtensionParam class to add the parame-
the request, an instance of Encryption is returned, and ter received – the channel owner’s public key (5:add),
ChAllExtMgr invokes the configureExtension and to the ChExtManager to store the parameter in
operation in this object (8:configureExtension). the database (6:store). After storing the parameter,
For fulfilling the request, the Encryption object re- the member requests the subscribed channel to enable
quests its super class (ChAllExtension) to configure the extension (7:enableExtension). The channel
the extension (9:configureExtension). This me- forwards the message to the ChAllExtMgr
thod request the object managing the extension para- (8:enableExtension), which creates an instance of
meters in the databae – ChExtParamManager, to the Encryption object (9:get) and adds it as an exten-
store the configuration parameters – public key – in the sion of the channel (10:put).
2.4. DISABLING THE ENCRYTION/DECRYPTION prepares the message to be sent to the Gateway admin-
EXTENSION istrator (3:msgToAdminExtension) and sends the
message (4:send). The Admin member receives the
Disabling the Encryption/Decryption extension requires message (5:receiveMessage) and pushes the mes-
some processing at the channel owner’s side and also at sage to the Admin application (6:receiveMessage).
the subscribers’ side. The administrator processes the request
(7:removeExtension), which includes removing
Figure 7 shows the process executed at the owner’s side data about the disabled channel extension in the data-
including the one executed by the Administrator’s side. base (8:removeExtension) and replying to the
The External Application requests its member to disable member confirming the extension was disabled
the extension (1:disableExtension). The member (9:sendMessage). Upon receiving the reply message
identifies it as a channel-oriented extension and invokes (10:receiveMessage), and identifying the message
the method for disabling this type of extension type, the Administrator’s reply is processed
(2:disableChannelExtension). This method (11:disableChExtension).
The request for disabling the extension is forwarded to tabase (5:remove), and requesting the subscribed
the channel owned (12:disableExtension), who channel to disable the extension
passes the request to the ChAllExtMgr (6:disableExtension). The subscribed channel
(13:disableExtension). ChAllExtMgr requests forwards the message to the ChAllExtMgr
the ChannelExtensionManager to remove the (7:disableExtension), which deletes the Encryp-
extension (14:removeExtension). Removing the tion/Decryption extension from the array of extensions
extension comprises removing the channel extension- enabled for the channel.
related information from the database and from the
array of channel extensions. Finally, a message is sent 2.5. SENDING AN ENCRYPTED MESSAGE
to all channel subscribers
(15:forwardToAllSubscribers) requesting to The process for sending a message is the same as in the
disable the extension. first release. The difference is only in the process-
Message method of the Encryption class.
Figure 8 presents the process for disabling the extension
on the subscriber’s side. Upon receiving the message Figure 9 presents the sequence diagram for sending an
(1:receiveMessage), the member identifies the encrypted message. The channel – may be owned or
message was received by a subscribed channel and in- subscribed, requests the ChAllExtMgr to process the
vokes the method of this class (2:receiveMessage). outgoing messages
Since it is a forwarded message, it is passed to the (1:processOutgoingMessage). This method looks
member for processing (3:recForwardReply). After for the corresponding extension – Encryption, and
identifying the type of message, the member’s method requests the object to process the message
for disabling the extension is invoked (2:processMessage). First, the extension gets the
(4:disableSubsExtension). The later method encryption key (key); if the sender is the channel own-
comprises requesting the ChannelExtensionMa- er, by getting its private key (3:getPrivateKey);
nager to remove the channel extension from the da-
otherwise, by getting the public key of the channel subscribed, requests the ChAllExtMgr to process the
owner (4:getPublicKey). Second, it requests the incoming messages
ExtensionsUtil class to encrypt the message pro- (1:processIncomingMessage). This method looks
viding the message content (content) and the encryp- for the corresponding extension – Encryption, and
tion key (key). For encrypting the message, Exten- requests the object to process the message
sionsUtil executes the following: i) generates an (2:processMessage). First, the extension gets the
AES session key (6:createAESKey) – generated- encryption key (key); if the sender is the channel own-
Key; ii) encrypts, using the AES algorithm, the message er, by getting its private key (3:getPrivateKey);
content (content) using generatedKey otherwise, by getting the public key of the channel
(7:encryptAES); iii) encrypts, following the RSA me- owner (4:getPublicKey). Second, it requests the
thod, generatedKey using the encryption key – key ExtensionsUtil class to decrypt the message pro-
(8:encryptRSA); and builds the reply by returning viding the encrypted message (encMsg) and the en-
the encrypted generated key – the result of 8, and the cryption key (key). For decrypting the message, Ex-
encrypted content – the result of 7. Finally, the en- tensionsUtil executes the following: i) gets the
crypted message is returned to the channel encrypted generated key (encKey) from the encrypted
(10,11,12:encryptedMsg). message (6:getEncryptedKey); ii) gets the en-
crypted content (encContent) from the encrypted
2.6. RECEIVING AN ENCRYPTED MESSAGE message (7:getEncryptedContent); iii) decrypts,
following the RSA method, the encrypted generated key
The process for receiving a message is the same as in (encKey – obtained in 6) using the encryption key –
the previous release. The difference is only in the pro- key (8:decryptRSA); and iv) decrypts, following
cessIncomingMessage method of the Encryp- the AES method, the encrypted content – the result of 7,
tion class. using the decrypted generated key – the result of 8
(9:decryptAES). Finally, the decrypted message is
Figure 10 presents the sequence diagram for receiving returned to the channel
an encrypted message. The channel – may be owned or (10,11,12:decryptedMsg).
3. NEW APIS FOR LEGACY SYSTEMS mostly used by Macao SAR Government Agencies (Sec-
tion 3.1), the set of APIs developed for Delphi applica-
One of the revised objectives of the Macao Data Ex- tions (Section 3.2), and the executable files and Java
change Gateway Project was to provide APIs for invok- classes for sending and receiving messages through the
ing the Gateway services by non-Java applications. For command line (Section 3.3).
specifying the required APIs, programming languages
and tools used by legacy applications deployed in Gov- 3.1. PROGRAMMING LANGUAGES USED BY
ernment Agencies were retrieved from the survey car- MACAO GOVERNMENT AGENCIES
ried out as part of e-Macao Phase I [10]. The results
shown Delphi, Visual Basic, Visual FoxPro and FoxPro, Based on the information gathered during e-Macao
Access and COBOL are the languages and tools mostly Phase I – Agency Survey [10], a detailed list of the appli-
used. Following the results, since Delphi was largely the cations used by Macao Government Agencies is pre-
most used language, APIs for Delphi applications was sented in Appendix C.1. The list specifies the agency
developed. In addition, two executable files that can be code, the application name, and the programming lan-
invoked from the command line are provided for send- guage or tool used for application development. Based
ing and receiving messages. These files aim at providing on the detailed list, a summarized list was prepared
a general solution for sending and receiving messages by indicating the total number of applications using each of
any legacy application able to access the command line, the programming languages and/or tools. The list is
regardless of the programming language used. The fol- presented in Appendix C.2. Finally, the latter list was
lowing three sections present the results about the pro- consolidated and the result is presented in Table 2.
gramming languages and development environments
Delphi 71
Visual Basic 26
Access 21
COBOL 21
AS/400 RPG 11
PowerBuilder 9
ASP 8
Oracle tools 3
C 1
Clipper 1
DBASE 1
ESRI ArcIMS 1
Fortran 1
string) – for subscribing the member acting on be configured with one parameter – the name of
behalf of the Delphi application to a channel. Three the XML Schema used for validating messages.
parameters are required: i) the member object Suppose, the XML Schema is a Gateway resource
(member), ii) the channel identifier to which the called XML-Food-License, then the data para-
subscription is requested (chId), and iii) the chan- meter should be precisely that name (XML-Food-
nel owner identifier (oId). License), and the order should be 1.
3.3.1. SEND CLASS – MAIN METHOD 3.3.2. RECEIVE CLASS – MAIN METHOD
The behavior of the Send class main method is de- The main method of the Receive class requires the
picted in Figure 11 and explained below. same parameters as those used for invoking the Re-
ceive command. Its behavior is depicted in Figure 12,
The main method requires the same parameters as and its source code is included in Appendix D.2.
those used for invoking the Send command. The me-
thod validates that the number of parameters is correct The method validates that the number of parameters is
(1:validatesParametersNumber) and that the correct (1:validatesParametersNumber). This
filename indicated as the third parameter exists in the function is not implemented as a separate method, but
corresponding folder (2:verifiesFileExist). as part of the method logic. After validating the parame-
These two functions are not implemented as separate ter, a new instance of LegacyApplicationLis-
methods, but as part of the method logic. After validat- tener object is created (2:new) and as a result, the
ing the parameters, a new instance of LegacyAppli- listener object is returned (3:listener). A new
cationListener object is created (3:new) and as a instance of the Anon member is instantiated (4:new),
result, the listener object is returned to whom the request for getting the member is sent
(4:listener). A new instance of the Anon member is (5:getMember). The parameters for getting the mem-
instantiated (5:new), to whom the request for getting ber include the member identifier – the first argument
the member is sent (6:getMember). The parameters of the main method (args[0]), and the application
for getting the member include the member identifier – listener recently created (listener). The Anon
the first argument of the main method (args[0]), and Member instantiates the Member object (6:new) and
the application listener recently created (listener). the object is returned as result (7:Member). Finally, a
The Anon Member instantiates the Member object thread is started for 10 seconds. While the member is
(7:new) and the object is returned as result active, the first message received triggers the invocation
(8:Member). The message to be sent is read from the of the method for receiving a message in the Application
file (9:readsFile) - this function is implemented Listener (9:receiveMessage), and the listener
within the method logic. After reading the message, the writes the message to a fie (10:writesFile).
member is requested to format it
(10:formatMessage), returning the message to be
sent (11:msg); and to send it (12:sendMessage).
The components highlighted in red in Figure 13 are the o JNIUtils.dcu – is required by JNI-
modified components in the new release. The justifica- Utils.pas;
tion for their modifications follows.
o XWrapper.pas – is responsible for invoking the
o xg2g-Admin – i) removing the functions for ge- Gateway methods;
nerating the public and private keys required by the
previous release of the Encryption/Decryption ex- o XWrapper.dcu – is required by XWrap-
tension; per.pas.
o xg2g-Communication services – i) replac- Similar structure as the one provided for xg2g-
ing the Encryption/Decryption extension with the Delphi is followed for xg2g-OtherLegacy. The
new release; and ii) adding the new service for set- content of the two subfolders is as follows.
ting the PIN – part of the Extended Services.
The bin folder contains:
o xg2g-Configuration file – a new parame-
ter – CardReaderConfigFile, was added for o lib – a folder containing all the libraries used by
specifying the location of the configuration file for the Gateway;
the card reader used by the new extension release.
o logs – a folder for storing the log files;
o xg2g-Services – adding the new service for
setting the PIN.
o Send.bat – the executable file for sending mes-
sages;
The xg2g-Delphi folder includes two subfolders: i)
bin – containing the binary code; and ii) src – contain- o Receive.bat – the executable file for receiving
ing the source files. The content of these folders follows. messages.
The bin folder contains: The src folder contains the source code of the three
Java classes – Send, Receive and LegacyAppli-
o libs – a folder containing all the libraries used cationListener.
by the Gateway;
4.2. DEPLOYMENT PROCEDURE
o logs – a folder for storing the log files;
The deployment procedure for the application imple-
o config – contains the config.properties file for menting the Gateway Administrator member (xg2g-
specifying the path to the Java Virtual Machine li- Admin), the Gateway APIs (xg2g-Communication
brary and the name of the library to be loaded by Services), the web services responsible for exchang-
DelphiApplicationListener; ing messages and providing the semantic extensions
(xg2g-Web Services), the Administrator repository
o DelphiImpl.dll – is the default implementa- (xg2g-Repository), and the User Interface (xg2g-
tion of the Gateway Application Listener. User Interface) were not changed with respect to
the previous release and are explained in details in the
The src folder contains: Extensible Message Gateway - User Manual [11], Chap-
ter 4.
o DelphiApplicationListener.java – is
the implementation of the Gateway Application Lis- Compared with the previous release, only one change
teener that will be used by Delphi applications; was introduced to the procedure for deploying the Ga-
teway configuration file (xg2g-Configuration
o DelphiImpl.dpr – is the default implementa- File). For the previous release, a detailed description
tion of DelphiImpl library; for the procedure was provided in [11]. In the new re-
lease, there is one more parameter in the file requiring
o JNI.pas – is a Delphi implementation of JNI; personalization – CardReaderConfigFile. If the
Encryption/Decryption extension will be used in a node,
o JNI.dcu – is required by JNI.pas; the configuration file of the smart card reader shall be
stored in a local folder. The value of the CardReader-
o JNI_MD.INC – is required by JNI.pas; ConfigFile parameter shall be the full path plus the
name of this file. For example, the default value of the
o JNIUtils.pas – is a collection of utility methods parameter is C:\\config\\pkcs11.cfg. It means
for using JNI.pas; that the folder config exists on drive C: and the file
pkcs11.cfg placed in that folder is the configuration
file of the smart card reader to be used by the Encryp- cated by the WorkFolder parameter of
tion/Decryption extension. the configuration file.
The deployment of the Dephi APIs is as follows: b. Create the sub-folders send and re-
ceive within the member’s folder.
1) Copy the bin folder to the desired library;
The deployment of the executable files for sending and For example, assuming the working folder of the Gate-
receiving messages from the command line requires: way is D:\Gateway\tmp, and three members –
100007, 100014, and 100062; are registered in the
1) copy the content of the bin folder to the folder node and are willing to use the executable files, Figure
in which the executable files will be executed; 14 shows the folders that are required, according to the
above procedure. In the case of the folders for receiving
files, if the folders do not exist, they are created at run-
2) For each member using these files:
time.
a. Create a folder labeled with the member
identifier within the folder used as the
working folder of the Gateway – indi-
APPENDICES
package edu.unu.iist.emacao.xg2g.extensions;
import java.security.Key;
import java.security.KeyFactory;
import java.security.KeyPair;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.spec.X509EncodedKeySpec;
import java.util.Collection;
import java.util.Map;
import org.apache.commons.codec.binary.Hex;
import org.apache.log4j.Logger;
import org.apache.xmlbeans.XmlObject;
import edu.unu.iist.emacao.gateway.xmlUtil.ExtAction;
import edu.unu.iist.emacao.gateway.xmlUtil.ForwardMessage;
import edu.unu.iist.emacao.gateway.xmlUtil.UserMessage;
import edu.unu.iist.emacao.xg2g.core.Member;
import edu.unu.iist.emacao.xg2g.core.Message;
import edu.unu.iist.emacao.xg2g.database.ChExtensionParam;
import edu.unu.iist.emacao.xg2g.database.ChannelExtension;
import edu.unu.iist.emacao.xg2g.database.ChannelExtensionManager;
import edu.unu.iist.emacao.xg2g.util.ExtensionsUtil;
@Override
public String processIncomingMessage(String message) throws Exception {
// This method is used for processing incoming messages.
// This consists typically to getting the key and decrypting the message
String msgToReturn = null;
try {
// Saves the user message to a file
Message msgAux = new Message(message);
UserMessage usrMsg = UserMessage.Factory.parse(msgAux
.getUserDefinedMessage());
String pp = XmlObject.Factory.parse(usrMsg.getContent().toString())
.xmlText();
logger.info("Encrypting the message : " + pp);
// gets the schema
Key val = null;
if (isOwner)
val = getPrivateKey();
else {
String encoded = getEncodedPublicKey();
if (encoded == null)
throw new Exception(
"The encryption extension is not properly confi-
gured");
val = getPublicKey(Hex.decodeHex(encoded.toCharArray()));
}
String text = util.decrypt(pp, val);
usrMsg.setContent(XmlObject.Factory.parse(text));
msgToReturn = msgAux.setUserDefinedMessage(usrMsg.toString());
} catch (Exception e) {
logger.error("Exception ", e);
}
return msgToReturn;
}
if (isOwner) {
return new String(Hex.encodeHex(getPublicKey().getEncoded()));
} else {
ChannelExtensionManager chMgr = new ChannelExtensionManager();
Collection<ChExtensionParam> listParam = chMgr
.getParameter(extension);
if (listParam == null || listParam.size() == 0)
throw new Exception("Unable to find the key for encryption");
for (ChExtensionParam ts : listParam) {
return ts.getChExtParam();
}
}
return null;
@Override
public String processMessage(String message) throws Exception {
// This method is used for processing outgoing messages
// This typically consists to getting the key and encrypting the message
String msgToReturn = null;
try {
// Saves the user message to a file
Message msgAux = new Message(message);
UserMessage usrMsg = UserMessage.Factory.parse(msgAux
.getUserDefinedMessage());
String pp = XmlObject.Factory.parse(usrMsg.getContent().toString())
.xmlText();
logger.info("Encrypting the message : " + pp);
Key val = null;
if (isOwner)
val = getPrivateKey();
else {
String encoded = getEncodedPublicKey();
if (encoded == null)
throw new Exception(
"The encryption extension is not properly confi-
gured");
val = getPublicKey(Hex.decodeHex(encoded.toCharArray()));
}
String text = util.encrypt(pp, val);
usrMsg.setContent(XmlObject.Factory.parse(text));
msgToReturn = msgAux.setUserDefinedMessage(usrMsg.toString());
} catch (Exception e) {
logger.error("Exception ", e);
}
return msgToReturn;
}
@Override
public void configureExtension(Map<Integer, String> msg) throws Exception {
super.configureExtension(msg);
String data = msg.get(1);
member.forwardToAllSubscribers(ExtAction.ENABLE, extension.getChannel()
.getChannelId(), name, data);
}
@Override
public void newSubscriber(String mId) throws Exception {
// String data = getChExtParam(PRIVATE_KEY).getChExtParam();
String data = getEncodedPublicKey();
ForwardMessage fm = ForwardMessage.Factory.newInstance();
fm.setAction(ExtAction.ENABLE);
fm.setChannelId(extension.getChannel().getChannelId());
fm.setData(data);
fm.setMemberId(mId);
fm.setExtName(name);
member.forwardMessage(mId, fm.toString());
package edu.unu.iist.emacao.xg2g.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.security.Key;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.KeyStore;
import java.security.MessageDigest;
import java.security.PrivateKey;
import java.security.Provider;
import java.security.PublicKey;
import java.security.Security;
import java.security.cert.Certificate;
import java.util.Enumeration;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import sun.security.pkcs11.SunPKCS11;
while (values.hasMoreElements()) {
String value = values.nextElement();
Key key = store.getKey(value, pin);
if (key instanceof PrivateKey) {
Certificate cert = store.getCertificate(value);
PublicKey publicKey = cert.getPublicKey();
pair = new KeyPair(publicKey, (PrivateKey) key);
}
}
}
return pair;
}
B. DELPHI APIS
package edu.unu.iist.emacao.xg2g.delphi;
import java.io.FileInputStream;
import java.util.Properties;
import edu.unu.iist.emacao.xg2g.core.ApplicationListener;
}
native public void recChExtensionReply(String arg0);
library DelphiImpl;
uses
SysUtils,
Classes,
JNI in 'JNI.pas',
JNIUtils in 'JNIUtils.pas',
xg2g in 'xg2g.pas',
XWrapper in 'XWrapper.pas';
Writeln(msg);
end;
Writeln(msg);
end;
recChExtensionReply(value);
end;
(*
* Class: edu_unu_iist_emacao_xg2g_delphi_DelphiApplicationListener
* Method: recConfigureChExtensionReply
* Signature: (Ljava/lang/String;)V
*)
procedure Ja-
va_edu_unu_iist_emacao_xg2g_delphi_DelphiApplicationListener_recConfigureChExtensionReply(PEnv:
PJNIEnv; Obj: JObject; Arg1: JString);
{$IFDEF WIN32} stdcall; {$ENDIF} {$IFDEF LINUX} cdecl; {$ENDIF}
var
FJNIEnv: TJNIEnv;
value: String;
begin
FJNIEnv:=TJNIEnv.Create(PEnv);
value:=FJNIEnv.JStringToString(Arg1);
recConfigureChExtensionReply(value);
end;
(*
* Class: edu_unu_iist_emacao_xg2g_delphi_DelphiApplicationListener
* Method: recCreateChannelReply
* Signature: (Ljava/lang/String;)V
*)
procedure Ja-
va_edu_unu_iist_emacao_xg2g_delphi_DelphiApplicationListener_recCreateChannelReply(PEnv: PJNIEnv;
Obj: JObject; Arg1: JString);
{$IFDEF WIN32} stdcall; {$ENDIF} {$IFDEF LINUX} cdecl; {$ENDIF}
var
FJNIEnv: TJNIEnv;
value: String;
begin
FJNIEnv:=TJNIEnv.Create(PEnv);
value:=FJNIEnv.JStringToString(Arg1);
recCreateChannelReply(value);
end;
(*
* Class: edu_unu_iist_emacao_xg2g_delphi_DelphiApplicationListener
* Method: recDestroyChannelReply
* Signature: (Ljava/lang/String;)V
*)
procedure Ja-
va_edu_unu_iist_emacao_xg2g_delphi_DelphiApplicationListener_recDestroyChannelReply(PEnv: PJNIEnv;
Obj: JObject; Arg1: JString);
{$IFDEF WIN32} stdcall; {$ENDIF} {$IFDEF LINUX} cdecl; {$ENDIF}
var
FJNIEnv: TJNIEnv;
value: String;
begin
FJNIEnv:=TJNIEnv.Create(PEnv);
value:=FJNIEnv.JStringToString(Arg1);
recDestroyChannelReply(value);
end;
(*
* Class: edu_unu_iist_emacao_xg2g_delphi_DelphiApplicationListener
* Method: recForwardReply
* Signature: (Ljava/lang/String;)V
*)
procedure Ja-va_edu_unu_iist_emacao_xg2g_delphi_DelphiApplicationListener_recForwardReply(PEnv:
PJNIEnv; Obj: JObject; Arg1: JString);
{$IFDEF WIN32} stdcall; {$ENDIF} {$IFDEF LINUX} cdecl; {$ENDIF}
var
FJNIEnv: TJNIEnv;
value: String;
begin
FJNIEnv:=TJNIEnv.Create(PEnv);
value:=FJNIEnv.JStringToString(Arg1);
recForwardReply(value);
end;
(*
* Class: edu_unu_iist_emacao_xg2g_delphi_DelphiApplicationListener
* Method: recGetMemberReply
* Signature: (Ljava/lang/String;)V
*)
procedure Ja-
va_edu_unu_iist_emacao_xg2g_delphi_DelphiApplicationListener_recGetMemberReply(PEnv: PJNIEnv;
Obj: JObject; Arg1: JString);
{$IFDEF WIN32} stdcall; {$ENDIF} {$IFDEF LINUX} cdecl; {$ENDIF}
var
FJNIEnv: TJNIEnv;
value: String;
begin
FJNIEnv:=TJNIEnv.Create(PEnv);
value:=FJNIEnv.JStringToString(Arg1);
recGetMemberReply(value);
end;
(*
* Class: edu_unu_iist_emacao_xg2g_delphi_DelphiApplicationListener
* Method: recManageReply
* Signature: (Ljava/lang/String;)V
*)
procedure Ja-va_edu_unu_iist_emacao_xg2g_delphi_DelphiApplicationListener_recManageReply(PEnv:
PJNIEnv; Obj: JObject; Arg1: JString);
{$IFDEF WIN32} stdcall; {$ENDIF} {$IFDEF LINUX} cdecl; {$ENDIF}
var
FJNIEnv: TJNIEnv;
value: String;
begin
FJNIEnv:=TJNIEnv.Create(PEnv);
value:=FJNIEnv.JStringToString(Arg1);
recManageReply(value);
end;
(*
* Class: edu_unu_iist_emacao_xg2g_delphi_DelphiApplicationListener
* Method: recMemberUnsubscribe
* Signature: (Ljava/lang/String;)V
*)
procedure Ja-
va_edu_unu_iist_emacao_xg2g_delphi_DelphiApplicationListener_recMemberUnsubscribe(PEnv: PJNIEnv;
Obj: JObject; Arg1: JString);
{$IFDEF WIN32} stdcall; {$ENDIF} {$IFDEF LINUX} cdecl; {$ENDIF}
var
FJNIEnv: TJNIEnv;
value: String;
begin
FJNIEnv:=TJNIEnv.Create(PEnv);
value:=FJNIEnv.JStringToString(Arg1);
recMemberUnsubscribe(value);
end;
(*
* Class: edu_unu_iist_emacao_xg2g_delphi_DelphiApplicationListener
* Method: recReceiveMessageReply
* Signature: (Ljava/lang/String;)V
*)
procedure Ja-
va_edu_unu_iist_emacao_xg2g_delphi_DelphiApplicationListener_recReceiveMessageReply(PEnv: PJNIEnv;
Obj: JObject; Arg1: JString);
{$IFDEF WIN32} stdcall; {$ENDIF} {$IFDEF LINUX} cdecl; {$ENDIF}
var
FJNIEnv: TJNIEnv;
value: String;
begin
FJNIEnv:=TJNIEnv.Create(PEnv);
value:=FJNIEnv.JStringToString(Arg1);
recReceiveMessageReply(value);
end;
(*
* Class: edu_unu_iist_emacao_xg2g_delphi_DelphiApplicationListener
* Method: recRegisterReply
* Signature: (Ljava/lang/String;)V
*)
procedure Ja-va_edu_unu_iist_emacao_xg2g_delphi_DelphiApplicationListener_recRegisterReply(PEnv:
PJNIEnv; Obj: JObject; Arg1: JString);
{$IFDEF WIN32} stdcall; {$ENDIF} {$IFDEF LINUX} cdecl; {$ENDIF}
var
FJNIEnv: TJNIEnv;
value: String;
begin
FJNIEnv:=TJNIEnv.Create(PEnv);
value:=FJNIEnv.JStringToString(Arg1);
recRegisterReply(value);
end;
(*
* Class: edu_unu_iist_emacao_xg2g_delphi_DelphiApplicationListener
* Method: recSendMessageReply
* Signature: (Ljava/lang/String;)V
*)
procedure Ja-
va_edu_unu_iist_emacao_xg2g_delphi_DelphiApplicationListener_recSendMessageReply(PEnv: PJNIEnv;
Obj: JObject; Arg1: JString);
{$IFDEF WIN32} stdcall; {$ENDIF} {$IFDEF LINUX} cdecl; {$ENDIF}
var
FJNIEnv: TJNIEnv;
value: String;
begin
FJNIEnv:=TJNIEnv.Create(PEnv);
value:=FJNIEnv.JStringToString(Arg1);
recSendMessageReply(value);
end;
(*
* Class: edu_unu_iist_emacao_xg2g_delphi_DelphiApplicationListener
* Method: recSubscribeChannelReply
* Signature: (Ljava/lang/String;)V
*)
procedure Ja-
va_edu_unu_iist_emacao_xg2g_delphi_DelphiApplicationListener_recSubscribeChannelReply(PEnv:
PJNIEnv; Obj: JObject; Arg1: JString);
{$IFDEF WIN32} stdcall; {$ENDIF} {$IFDEF LINUX} cdecl; {$ENDIF}
var
FJNIEnv: TJNIEnv;
value: String;
begin
FJNIEnv:=TJNIEnv.Create(PEnv);
value:=FJNIEnv.JStringToString(Arg1);
recSubscribeChannelReply(value);
end;
(*
* Class: edu_unu_iist_emacao_xg2g_delphi_DelphiApplicationListener
* Method: recUnRegisterReply
* Signature: (Ljava/lang/String;)V
*)
procedure Ja-
va_edu_unu_iist_emacao_xg2g_delphi_DelphiApplicationListener_recUnRegisterReply(PEnv: PJNIEnv; Obj:
JObject; Arg1: JString);
{$IFDEF WIN32} stdcall; {$ENDIF} {$IFDEF LINUX} cdecl; {$ENDIF}
var
FJNIEnv: TJNIEnv;
value: String;
begin
FJNIEnv:=TJNIEnv.Create(PEnv);
value:=FJNIEnv.JStringToString(Arg1);
recUnRegisterReply(value);
end;
(*
* Class: edu_unu_iist_emacao_xg2g_delphi_DelphiApplicationListener
* Method: recUnsubscribeChannelReply
* Signature: (Ljava/lang/String;)V
*)
procedure Ja-
va_edu_unu_iist_emacao_xg2g_delphi_DelphiApplicationListener_recUnsubscribeChannelReply(PEnv:
PJNIEnv; Obj: JObject; Arg1: JString);
{$IFDEF WIN32} stdcall; {$ENDIF} {$IFDEF LINUX} cdecl; {$ENDIF}
var
FJNIEnv: TJNIEnv;
value: String;
begin
FJNIEnv:=TJNIEnv.Create(PEnv);
value:=FJNIEnv.JStringToString(Arg1);
recUnsubscribeChannelReply(value);
end;
(*
* Class: edu_unu_iist_emacao_xg2g_delphi_DelphiApplicationListener
* Method: receiveMessage
* Signature: (Ljava/lang/String;)V
*)
procedure Ja-va_edu_unu_iist_emacao_xg2g_delphi_DelphiApplicationListener_receiveMessage(PEnv:
PJNIEnv; Obj: JObject; Arg1: JString);
{$IFDEF WIN32} stdcall; {$ENDIF} {$IFDEF LINUX} cdecl; {$ENDIF}
var
FJNIEnv: TJNIEnv;
value: String;
begin
FJNIEnv:=TJNIEnv.Create(PEnv);
value:=FJNIEnv.JStringToString(Arg1);
receiveMessage(value);
end;
exports
Java_edu_unu_iist_emacao_xg2g_delphi_DelphiApplicationListener_recChExtensionReply,
Ja-va_edu_unu_iist_emacao_xg2g_delphi_DelphiApplicationListener_recConfigureChExtensionReply,
Java_edu_unu_iist_emacao_xg2g_delphi_DelphiApplicationListener_recCreateChannelReply,
Java_edu_unu_iist_emacao_xg2g_delphi_DelphiApplicationListener_recDestroyChannelReply,
Java_edu_unu_iist_emacao_xg2g_delphi_DelphiApplicationListener_recForwardReply,
Java_edu_unu_iist_emacao_xg2g_delphi_DelphiApplicationListener_recGetMemberReply,
Java_edu_unu_iist_emacao_xg2g_delphi_DelphiApplicationListener_recManageReply,
Java_edu_unu_iist_emacao_xg2g_delphi_DelphiApplicationListener_recMemberUnsubscribe,
Java_edu_unu_iist_emacao_xg2g_delphi_DelphiApplicationListener_recReceiveMessageReply,
Java_edu_unu_iist_emacao_xg2g_delphi_DelphiApplicationListener_recRegisterReply,
Java_edu_unu_iist_emacao_xg2g_delphi_DelphiApplicationListener_recSendMessageReply,
Java_edu_unu_iist_emacao_xg2g_delphi_DelphiApplicationListener_recSubscribeChannelReply,
Java_edu_unu_iist_emacao_xg2g_delphi_DelphiApplicationListener_recUnRegisterReply,
Java_edu_unu_iist_emacao_xg2g_delphi_DelphiApplicationListener_recUnsubscribeChannelReply,
Java_edu_unu_iist_emacao_xg2g_delphi_DelphiApplicationListener_receiveMessage;
begin
end.
unit XWrapper;
interface
uses
ShareMem,
SysUtils,
Classes,
JNI,
JNIUtils;
public
{I need to comment these methods}
constructor Create();
// These two methods are used by Anon
function registerMember(name: string;descriptionfile:string): JObject;
function getMember(memberId:string):JObject;
// These methods are used by member
procedure sendMessage(member:JObject;chId:string;msg:string);
procedure receiveMessage(member:JObject;msg:string);
procedure createChannel(member:JObject;chName:string);
procedure destroyChannel(member:JObject;chId:string);
procedure subscribeChannel(member:JObject;chId:string;oId:string);
procedure unsubscribeChannel(member:JObject;chId:string;oId:string);
procedure unregisterMember(member: JObject);
procedure enableExtension(member:JObject;extType:string;chId:string;extName:string);
procedure disableExtension(member:JObject;extType:string;chId:string;extName:string);
procedure configureExten-sion(member:JObject;extType:string;chId:string;extName:string;data:string;order:Integer);
procedure forwardMessage(member:JObject;chId:string;msg:string);
function getMessage(member:JObject; chId:string):string;
procedure setPin(member:JObject; pin:string);
published
{ déclarations published }
end;
implementation
{Used to create a new instance of the XG2GWrapper class}
// Maybe in the future this constructor will take at least two parameters
// The path to the jvm.dll file and the classpath variable. Another solution will be
// the use of a configuration file
constructor XG2GWrapper.Create();
begin
try
// Create the JVM using a wrapper class. It instantiate the JVM machine and the JRE variable
// The best way will be to take this value as a parameter or read it from a configuration file
JavaVM:=TJavaVM.Create(JNI_VERSION_1_4, getJVMPath());
// set the options for the VM. Probably instead of hard-coding this value I just derive as a parameter
Options[0].optionString:='-Djava.class.path=.;.\libs';
VM_args.version:=JNI_VERSION_1_4;
VM_args.options:=@Options;
VM_args.nOptions:=1;
// Load the VM
Errcode:=JavaVM.LoadVM(VM_args);
if Errcode<0 then
Begin
end;
end
else
begin
Writeln('Configuration file not found');
Exit;
end;
end;
procedure XG2GWrapper.callMethod(member: JObject; method: string; sig: string; params: array of JValue);
var Cls:JClass;
mId: JMethodID;
begin
end;
except
on E: Exception do
writeln('Error: ' + E.Message);
end;
end;
mId:=JNIEnv.GetStaticMethodID(cls,'forString','(Ljava/lang/String;)Ledu/unu/iist/emacao/gateway/xmlUtil/ExtType$Enu
m;');
if mId=nil then
Begin
Writeln('Can''t method forString of the class : edu/unu/iist/emacao/gateway/xmlUtil/ExtType$Enum');
Exit;
End;
ags[1].l:=JNIEnv.StringToJString(pansichar(extType));
Result:=JNIEnv.CallStaticObjectMethodA(cls,mId,@ags);
end;
{*format a message according to the destination channel*}
function XG2GWrapper.formatMessage(member: JObject;chId: string; msg: string; attachment: array of string):string;
var params:array[1..3] of JValue;
begin
Cls:=JNIEnv.GetObjectClass(member);
if Cls=nil then
begin
Writeln('Unable to find the class of the object');
exit ;
end;
// find the method with name method
mId:=JNIEnv.GetMethodID(Cls,'formatMessage','(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;)Ljava/lang/String;
');
if mId=nil then
begin
Writeln('Unable to find the method formatMessage of class Member');
exit;
end;
// Prepapre the parameters
params[1].l:=JNienv.StringToJString(PansiChar(chId));
params[2].l:=JNienv.StringToJString(PansiChar(msg));
params[3].l:=nil;
// call the method
Result:=JNIEnv.JStringToString(JNIEnv.CallObjectMethodA(member,mId,@params));
end;
{*Implementation of the register method*}
function XG2GWrapper.registerMember(name: string; descriptionfile: string):JObject;
var
arg0: JString;
arg1: JString;
ARGS:array[0..2] of JValue;
begin
Result:=nil;
try
//Cls:=JNIEnv.FindClass('edu/unu/iist/emacao/xg2g/core/Anon');
apListObject:= CreateJavaOb-ject('edu/unu/iist/emacao/xg2g/delphi/DelphiApplicationListener',apListClass);
Mid:=JNIEnv.GetMethodID(cls,'registerMember','(Ljava/lang/String;Ljava/lang/String;Ledu/unu/iist/emacao/xg2g/core/A
pplicationListener;)Ledu/unu/iist/emacao/xg2g/core/Member;');
if Mid= nil then
begin
Writeln('Can''t find method registerMember');
Exit;
end;
// Call the method with the giving parameters
arg0:=JNIEnv.StringToJString(PAnsiChar(name));
arg1:=JNIEnv.StringToJString(PAnsiChar(descriptionFile));
ARGS[0].l:=arg0;
ARGS[1].l:=arg1;
ARGS[2].l:=apListObject;
Result:=JNIEnv.CallObjectMethodA(AnonObject,Mid,@ARGS);
except
on E: Exception do
Writeln('Error: '+e.Message);
end;
end;
{*
* The implementation of Anon's getMember
*}
function XG2GWrapper.getMember(memberId: string) :JObject;
var
args:array[1..2] of JValue;
begin
Mid:=JNIEnv.GetMethodID(Cls,'getMember','(Ljava/lang/String;Ledu/unu/iist/emacao/xg2g/core/ApplicationListener;)Le
du/unu/iist/emacao/xg2g/core/Member;');
// Create an instance of the DelphiApplicationListener
apListOb-ject:=CreateJavaObject('edu/unu/iist/emacao/xg2g/delphi/DelphiApplicationListener',apListClass);
// create the argument
//JNIEnv.StringToJString(PAnsiChar(memberId));
args[1].l:=JNIEnv.StringToJString(PAnsiChar(memberId));
args[2].l:=apListObject;
// invoke the method with the giving parameters
Result:=JNIEnv.CallObjectMethodA(anonObject,mId,@args);
end;
procedure XG2GWrapper.sendMessage(member: JObject; chId: string; msg: string);
var args: array[1..2] of JValue;
ms:string;
begin
ms:=formatMessage(member,chId,msg,[]);
args[1].l:=JNIEnv.StringToJString(PAnsiChar(chId));
args[2].l:=JNIEnv.StringToJString(PAnsiChar(ms));
callMethod(member,'sendMessage','(Ljava/lang/String;Ljava/lang/String;)V',args);
end;
{I need to provide an implementation for this method}
procedure XG2GWrapper.receiveMessage(member: JObject; msg: string);
var args: array[1..1] of JValue;
begin
args[1].l:=JNIEnv.StringToJString(PAnsiChar(msg));;
callMethod(member,'receiveMessage','(Ljava/lang/String;)V', args);
end;
ext:=getExtensionType(extType);
if ext=nil then
Begin
Writeln('Unknown ExtensionType '+extType);
Exit;
end;
args[1].l:=ext;
args[2].l:=JNIEnv.StringToJString(PansiChar(chId));
args[3].l:=JNIEnv.StringToJString(PansiChar(extName));
callMe-
thod(member,'enableExtension','(Ledu/unu/iist/emacao/gateway/xmlUtil/ExtType$Enum;Ljava/lang/String;Ljava/lang/St
ring;)V',args);
end;
{I need to provide an implementation for this method}
procedure XG2GWrapper.disableExtension(member: JObject; extType: string; chId: string; extName: string);
var args:array[1..3] of JValue;
ext:JObject;
begin
ext:=getExtensionType(extType);
if ext=nil then
Begin
Writeln('Unknown ExtensionType '+extType);
Exit;
end;
args[1].l:=ext;
args[2].l:=JNIEnv.StringToJString(PansiChar(chId));
args[3].l:=JNIEnv.StringToJString(PansiChar(extName));
callMe-
thod(member,'disableExtension','(Ledu/unu/iist/emacao/gateway/xmlUtil/ExtType$Enum;Ljava/lang/String;Ljava/lang/St
ring;)V',args);
end;
{I need to provide an implementation for this method}
procedure XG2GWrapper.configureExtension(member: JObject; extType: string; chId: string; extName: string; data:
string; order: Integer);
var args:array[1..5] of JValue;
ext:JObject;
begin
ext:=getExtensionType(extType);
if ext=nil then
Begin
Writeln('Unknown ExtensionType '+extType);
Exit;
end;
args[1].l:=ext;
args[2].l:=JNIEnv.StringToJString(PansiChar(chId));
args[3].l:=JNIEnv.StringToJString(PansiChar(extName));
args[4].l:=JNIEnv.StringToJString(PansiChar(data));
args[5].i:=order;
callMe-
thod(member,'configureExtension','(Ledu/unu/iist/emacao/gateway/xmlUtil/ExtType$Enum;Ljava/lang/String;Ljava/lang
/String;Ljava/lang/String;I)V',args);
end;
{I need to provide an implementation for this method}
procedure XG2GWrapper.forwardMessage(member: JObject; chId: string; msg: string);
var args: array[1..2] of JValue;
begin
args[1].l:=JNIEnv.StringToJString(PAnsiChar(chId));
args[2].l:=JNIEnv.StringToJString(PAnsiChar(msg));
callMethod(member,'forwardMessage','(Ljava/lang/String;Ljava/lang/String;)V',args);
end;
{*the setPin method*}
procedure XG2GWrapper.setPin(member: JObject; pin: string);
var args: array[1..1] of JValue;
begin
args[1].l:=JNIEnv.StringToJString(PAnsiChar(pin));
callMethod(member,'setPin','(Ljava/lang/String;)V',args);
end;
{*The getMessage*}
function XG2GWrapper.getMessage(member: JObject; chId: string):string;
var args:array[1..1] of JValue;
begin
args[1].l:=JNIEnv.StringToJString(PansiChar(chId));
Result:='welcome';
end;
end.
DSE CA COBOL
DSE CO COBOL
DSE ID COBOL
DSE LC COBOL
DSE PI Delphi
DSE QT COBOL
DSI BIR Application Forms Printing Borland C++ Builder, C for AS400
DSI Data Entry for Criminal Record and other Certificates Cobol for VSE(S/390)
DSI Data Entry Program for ID Card System Cobol for VSE(S/390)
DSI Data Entry Program for Travel Documents Cobol for VSE(S/390)
DSSOPT Suggestion, Complaint and Claim System Delphi & Delphi 400
ID Venci DBASE
IH CU Delphi
IH FN Delphi
IH NR Delphi
IH US Delphi
ON Salario Access
ON Sinfon Access
ON Verbas Access
SA EDI Delphi
SA IPI Delphi
SA MIC Delphi
SA SUB Delphi
Access 13
Access 2000/97 6
Access v.97/2000 2
AS/400 RPG 11
ASP 4
ASP .net 1
ASP.net 3
C 1
Clipper 1
COBOL 18
DBASE 1
Delphi 57
Delphi 6 Count 3
Delphi 7 Count 1
Fortran Count 1
FoxPro Count 3
Powerbuilder Count 9
VB.Net Count 5
D. JAVA CLASSES FOR SENDING AND RECEIVING MESSAGES THROUGH THE COMMAND LINE
package edu.unu.iist.emacao.xg2g.legacy;
import java.io.File;
import java.io.FileInputStream;
import edu.unu.iist.emacao.xg2g.core.Anon;
import edu.unu.iist.emacao.xg2g.core.ApplicationListener;
import edu.unu.iist.emacao.xg2g.core.Member;
import edu.unu.iist.emacao.xg2g.util.GlobalVariables;
package edu.unu.iist.emacao.xg2g.legacy;
import edu.unu.iist.emacao.xg2g.core.Anon;
import edu.unu.iist.emacao.xg2g.core.ApplicationListener;
import edu.unu.iist.emacao.xg2g.core.Member;
System.exit(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
File f=new
File(GlobalVariables.getWorkFolder()+File.separator+memberId+File.separator+"receive");
if((!f.exists())||(!f.isDirectory())){
// create the directory first
f.mkdirs();
}