Encrypted TCP chat using RSA and AES algorithm



Similar documents
CASE STUDY ALLOCATE SOFTWARE

Project Management Basics

Performance of a Browser-Based JavaScript Bandwidth Test

DISTRIBUTED DATA PARALLEL TECHNIQUES FOR CONTENT-MATCHING INTRUSION DETECTION SYSTEMS. G. Chapman J. Cleese E. Idle

CASE STUDY BRIDGE.

Cluster-Aware Cache for Network Attached Storage *

DISTRIBUTED DATA PARALLEL TECHNIQUES FOR CONTENT-MATCHING INTRUSION DETECTION SYSTEMS

SHARESYNC SECURITY FEATURES

Optical Illusion. Sara Bolouki, Roger Grosse, Honglak Lee, Andrew Ng

Apigee Edge: Apigee Cloud vs. Private Cloud. Evaluating deployment models for API management

Announcing the ADVANCED ENCRYPTION STANDARD (AES)

A technical guide to 2014 key stage 2 to key stage 4 value added measures

Performance of Multiple TFRC in Heterogeneous Wireless Networks

Warehouse Security System based on Embedded System

A Review On Software Testing In SDlC And Testing Tools

Pekka Helkiö, 58490K Antti Seppälä, 63212W Ossi Syd, 63513T

FEDERATION OF ARAB SCIENTIFIC RESEARCH COUNCILS

Third Party Technical Guidelines

License & SW Asset Management at CES Design Services

A Note on Profit Maximization and Monotonicity for Inbound Call Centers

SPECIFICATIONS FOR PERIMETER FIREWALL. APPENDIX-24 Complied (Yes / No) Remark s. S.No Functional Requirements :

OPINION PIECE. It s up to the customer to ensure security of the Cloud

A Spam Message Filtering Method: focus on run time

A note on profit maximization and monotonicity for inbound call centers

Control of Wireless Networks with Flow Level Dynamics under Constant Time Scheduling

Utility-Based Flow Control for Sequential Imagery over Wireless Networks

SELF-MANAGING PERFORMANCE IN APPLICATION SERVERS MODELLING AND DATA ARCHITECTURE

Queueing systems with scheduled arrivals, i.e., appointment systems, are typical for frontal service systems,

A New Optimum Jitter Protection for Conversational VoIP

CHARACTERISTICS OF WAITING LINE MODELS THE INDICATORS OF THE CUSTOMER FLOW MANAGEMENT SYSTEMS EFFICIENCY

How Enterprises Can Build Integrated Digital Marketing Experiences Using Drupal

Mobile Network Configuration for Large-scale Multimedia Delivery on a Single WLAN

Tips For Success At Mercer


Availability of WDM Multi Ring Networks

TIME SERIES ANALYSIS AND TRENDS BY USING SPSS PROGRAMME

Two Dimensional FEM Simulation of Ultrasonic Wave Propagation in Isotropic Solid Media using COMSOL

Report b Measurement report. Sylomer - field test

Acceleration-Displacement Crash Pulse Optimisation A New Methodology to Optimise Vehicle Response for Multiple Impact Speeds

Bio-Plex Analysis Software

Laureate Network Products & Services Copyright 2013 Laureate Education, Inc.

Return on Investment and Effort Expenditure in the Software Development Environment

Unit 11 Using Linear Regression to Describe Relationships

SeChat: An AES Encrypted Chat

Profitability of Loyalty Programs in the Presence of Uncertainty in Customers Valuations

Network Architecture for Joint Failure Recovery and Traffic Engineering

Development Progress

Software Engineering Management: strategic choices in a new decade

Achieving Quality Through Problem Solving and Process Improvement

Products and Services

SRA SOLOMON : MUC-4 TEST RESULTS AND ANALYSI S

TRADING rules are widely used in financial market as

A Novel Web-Based Student Academic Records Information System

Chapter 10 Stocks and Their Valuation ANSWERS TO END-OF-CHAPTER QUESTIONS

! Search engines are highly profitable. n 99% of Google s revenue from ads. n Yahoo, bing also uses similar model

Socially Optimal Pricing of Cloud Computing Resources

Risk Management for a Global Supply Chain Planning under Uncertainty: Models and Algorithms

MSc Financial Economics: International Finance. Bubbles in the Foreign Exchange Market. Anne Sibert. Revised Spring Contents

Assessing the Discriminatory Power of Credit Scores

Four Ways Companies Can Use Open Source Social Publishing Tools to Enhance Their Business Operations

Redesigning Ratings: Assessing the Discriminatory Power of Credit Scores under Censoring

Control Theory based Approach for the Improvement of Integrated Business Process Interoperability

Distributed, Secure Load Balancing with Skew, Heterogeneity, and Churn

A Resolution Approach to a Hierarchical Multiobjective Routing Model for MPLS Networks

Free Enterprise, the Economy and Monetary Policy

Algorithms for Advance Bandwidth Reservation in Media Production Networks

Exposure Metering Relating Subject Lighting to Film Exposure

REDUCTION OF TOTAL SUPPLY CHAIN CYCLE TIME IN INTERNAL BUSINESS PROCESS OF REAMER USING DOE AND TAGUCHI METHODOLOGY. Abstract. 1.

Progress 8 measure in 2016, 2017, and Guide for maintained secondary schools, academies and free schools

1 Introduction. Reza Shokri* Privacy Games: Optimal User-Centric Data Obfuscation

Growth and Sustainability of Managed Security Services Networks: An Economic Perspective

QUANTIFYING THE BULLWHIP EFFECT IN THE SUPPLY CHAIN OF SMALL-SIZED COMPANIES

Graph Analyi I Network Meaure of the Networked Adaptive Agents

IMPORTANT: Read page 2 ASAP. *Please feel free to (longo.physics@gmail.com) me at any time if you have questions or concerns.

G*Power 3: A flexible statistical power analysis program for the social, behavioral, and biomedical sciences

RISK MANAGEMENT POLICY

v = x t = x 2 x 1 t 2 t 1 The average speed of the particle is absolute value of the average velocity and is given Distance travelled t

JVD Software Development

Patient Satisfaction Tip Book Improving Patient Perceptions

Transcription:

Encrypted TCP chat uing RSA and AES algorithm Krzyztof Jakub Szala Bachelor Thei April 2014 Degree Programme in Information Technology Technology, communication and tranport

DESCRIPTION Author() SZALA Krzyztof Jakub Type of publication Bachelor Thei Page 46 Title ENCRYPTED TCP CHAT USING RSA AND AES ALGORITHM Date 23.04.2014 Language Englih Permiion for web publication ( X ) Degree Programme Information Technology Tutor() MIESKOLAINEN, Matti Aigned by Decom Oy Abtract Secure Communication Application i a tandalone project which can be ued to ecure communication between two computer running on Window. The purpoe of the project wa to create an application which can be eaily divided in-to part, which allow replacing the uer interface by a different one. The project wa realized under the uperviion of Decom oy. Thi thei demontrate the proce of creating the core of the application reponible for communication over TCP protocol between two computer and the uer interface. Secure communication wa the mot important part of it. The firt part explain the reaon and motivation to create uch an application. The goal are alo dicued. The following chapter preent the development environment and important theory. Next, the way of deigning and developing thi application i dicued. Later the way how to replace a uer interface with another i demontrated and finally, the application i teted and the reult and concluion are preented. The reult of the thei i functional oftware able to enure ecure communication between two computer. The program were hown with ucce to the project upervior. Neverthele, further development would be required to make the application more ecure and mooth Keyword C++, Java, meage, chat, ending, receiving, encryption, AES, RSA, OpenSSL, TCP Micellaneou

2 CONTENT CONTENT... 2 ACRONYMS... 4 FIGURES... 5 2 OBJECTIVE OF THE THESIS... 8 3 DEVELOPMENT ENVIRONMENT... 9 3.1 C/C++... 9 3.2 JAVA... 9 3.3 OPENSSL... 9 4 THEORY... 11 4.1 CIPHERING ALGORITHMS... 11 4.2 RSA OVERVIEW.... 12 4.3 RSA DETAILS.... 12 4.4 AES OVERVIEW.... 14 4.5 AES DETAILS... 14 4.6 HMAC... 17 4.7 TCP PROTOCOL... 18 5 DESIGN AND IMPLEMENTATIONS... 19 5.1 CONCEPT... 19 5.2 COMMUNICATION LAYER... 26 5.2.1 Winock... 26 5.2.2 Parameter and requirement... 29 5.3 CIPHERING LAYER... 30 5.3.1 Creating/Reading RSA key from file... 30 5.3.2 Creating AES key... 31 5.3.3 AES key exchange... 32 5.3.4 Encrypting/decrypting AES eion key uing RSA algorithm.. 32 5.3.5 Uing AES algorithm... 33 5.3.6 HMAC... 34 5.4 USER INTERFACE LAYER... 36 5.4.1 Socket... 36 5.4.2 Data taken from uer... 36 5.4.3 How to change UI... 38 6 INSTALLATION... 40

7 TESTING... 41 8 FURTHER DEVELOPMENT... 44 8.1 WHAT HAS BEEN DONE... 44 8.2 WHAT SHOULD BE DONE... 44 9 CONCLUSION... 45 REFERENCES... 46 3

4 ACRONYMS ACK - Acknowledgment AES Advanced Encryption Standard HMAC - Hah-baed meage authentication code IP Internet protocol IV Initialization vector JDK - Java Developing Kit LAN Local area network MAC - Meage Authentication Code UI Uer interface SYN - Synchronize TCP Tranmiion Control Protocol VS Viual Studio

5 FIGURES FIGURE 1 Amount of data in internet (Silicon angle).... 6 FIGURE 2 High level architecture meage cycle.... 21 FIGURE 3 High level architecture with port decription.... 22 FIGURE 4 Example cenario for application.... 23 FIGURE 5 Example configuration.... 37 FIGURE 6 Example meage exchange.... 38 FIGURE 7 How RawCap i working.... 42 FIGURE 8 Meage ent from UI to C++ application.... 42 FIGURE 9 Meage ent from one C++ application to another one.... 43 FIGURE 10 Meage ent from C++ apllication to UI.... 43

6 1 INTRODUCTION We live in a ociety that i awah with information, but few of u really undertand what information i. (Floridi L. 2010) Nowaday people need to communicate with each other all the time. Communication often take place between people who are far from each other, o they ue the Internet to that. They are exchanging information with ignificant value. Thi fact lead to the tatement that the meage that they are exchanging hould remain ecret for other partie who are not authorized. FIGURE 1 Amount of data on the internet (Silicon angle). Security i nowaday one of the mot important iue in a network. Every company hould have their own application which enable their worker to communicate ecurely and freely. Beide meage, people exchange file which hould alo be encrypted. To achieve ecure communication application allowing uer to exchange meage via Internet hould have implemented cryptographic algorithm which hould be checked, teted and reliable ince people exchanging a lot of meage, encryption algorithm hould work fat.

7 According to everything what wa mentioned previouly, it wa decided to an create application with implemented cryptographic algorithm that meet the previouly mentioned goal. The name of the application i Secure Communication Application (further referred to a SecureCA).

8 2 OBJECTIVE OF THE THESIS A mentioned in the previou chapter the application hould be: Fat Working over TCP protocol Reliable Allow to communicate between two uer Work on computer with Window 7 x64 operating ytem Implementation hould allow to eaily change uer interface in future To provide the above requirement it wa decided to ue cryptographic function: RSA algorithm Advanced Encryption Standard Hah-baed meage authentication code The project aumed providing communication only between two uer at a time. Communication hould take place via two different channel, one allowing to receive meage, the other one to end them. Channel are working independently one from another. It wa alo aumed that before the etablihment of communication, uer exchange their public key, although the application can create a new key pair for uer, but after that the key hould be exchange again and application need to be retarted again. Enuring communication with multiple uer at the ame time and certification authority hould be implemented in the future. Each time the application i tarted it hould create a new eion key. To implify etablihing a connection it wa alo aumed that each uer know that communication will take place, and run hi own erver before other uer tart to try connect to that erver.

9 3 DEVELOPMENT ENVIRONMENT The application wa developed under Window 7 x64 operating ytem. 3.1 C/C++ The core of the application reponible for implementation of ciphering algorithm and communication via network wa written uing C++ programing language in Microoft Viual Studio 2012. Thi language wa choen becaue it i fat, efficiency and compatible with library, which wa ued to provide implementation of cipher algorithm, written uing C language. When intalling Microoft Viual Studio 2012 all needed librarie are intalled o that there i no needed to intall anything ele. Microoft Viual Studio 2012 licene i alo needed. Intead of VS 2012 NetBean can be ued. 3.2 Java The uer interface wa written uing Java programing language in NetBean which can be found on the following webpage: http://netbean.org/download/ Before intalling NetBean JDK needed to be intalled. The latet verion of JDK can be downloaded on the following webpage: http://www.oracle.com/technetwork/java/javae/download/jdk8-download- 2133151.html 3.3 OpenSSL OpenSSL library wa ued to provide encrypting algorithm. In thi project Win32 OpenSSL v 1.0.1 f wa ued. Thi library can be downloaded from following webpage: http://lproweb.com/product/win32openssl.html

10 To ue OpenSSL library in C++ project following needed to be done in project propertie: C/C++ tab in Additional Include Directorie et path to folder with OpenSSL library, ubfolder include(default: C:\OpenSSL- Win32\include) Linker tab in Additional Library Directorie et path to folder with OpenSSL library, ubfolder lib, ubfolder VC(default: C:\OpenSSL- Win32\lib\VC) In Linker tab, ubtab Input in Additional Dependencie et name of library that hould be ued in project( in thi project wa ued: libeay32mdd.lib, leay32mdd.lib) The function from OpenSSL library that wa ued in that project will be decribed later on in thi thei.

11 4 THEORY To create ciphering application it i very important to undertand firt algorithm that are ued in that kind of program. If theory placed below i not enough it i recommended to read Fip 197 about AES and PKCS #1 about RSA. 4.1 Ciphering algorithm. Before tarting to develop that project, there were very important deciion to be made. The algorithm wa choen carefully according to information about ecurity and reliable. A aymmetric algorithm to encrypt eion key RSA algorithm wa choen. AES wa decided to be ymmetric algorithm reponible for encrypting and decrypting meage. HMAC with SHA-256 a hah function wa choen to be olution for authenticating meage. An important part of that application i alo the communication protocol which allow hot to end information via public Internet.

12 4.2 RSA overview. RSA i an aymmetric encrypting algorithm normally ued to end a eion key between uer and which will be ued in the future by uer in ciphering with the ue of ymmetric algorithm. Thi algorithm i not ued to cipher communication becaue it need a great deal of reource and time to encrypt and decrypt data. RSA ue two key in ciphering, public key and private key. Uer provide the public key to other uer and protect and keep hi/her own private key in ecret. It i trongly recommended to ue at leat 2048 bit long key becaue horter key are conidered not to be ecure. Alo, public exponent hould be a large a poible to ecure uer from attack againt mall public exponent. (RSA PKCS) The trength of thi algorithm lie in two mathematical problem: The problem of factoring large number RSA problem 4.3 RSA detail. To generate RSA key pair thi algorithm had to be ued: 1. Choe randomly two large prime number p and q. 2. Solve n = p q 3. Solve Euler function value for n: ϕ ( n) = ( p 1) ( q 1) 4. Choe number e uch a 1 < e < ϕ( n) relatively prime with ϕ ( n) 1 5. Solve d = e modϕ( n) Public key i defined a number pair ( n, e) while private key i defined a pair ( n, d ) To encrypt with RSA algorithm meage have to be divide in to value not larger than n and then cipher with pattern: c = m i e i mod n mi block of

13 To decrypt with RSA algorithm every c i block had to be tranform like thi: m i = c d i mod n Until March 2 nd 2014 the larger key that wa decompoed into prime factor 768-bit length key, RSA i conidered to be ecure ciphering algorithm nowaday.

14 4.4 AES overview. AES i a ymmetric encrypting algorithm normally ued to encrypt data with one the ame key for encryption and decryption which work in variou mode. For thi application, counter mode wa choen. The algorithm i baed on Rijandel algorithm, a ymmetric block cipher able to tranform 128- bit long data block. The key can have three different length: 128, 192 and 256 bit. Depending on the key length, the algorithm conit of 10, 12 or 14 round. (Fip 197) 4.5 AES detail The algorithm operate on a 4x4 column-major order matrix of byte called tate arranged a follow: byte byte byte byte 0 1 2 3 byte byte byte byte 4 5 6 7 byte byte byte byte 8 9 10 11 byte byte byte byte 12 13 14 15 All operation in AES are byte-baed. The tate conit of 128 bit which are equal to 16 byte High-level AES architecture: 1. AddRoundKey 2. For each of round( 10, 12 or 14 time): 2.1. SubByte 2.2. ShiftRow 2.3. MixColumn 2.4. AddRoundKey 3. After lat round tate i returned a ciphered text.

15 AddRoundKey - function that XOR the round key with the tate SubByte - function that ubtitute on each byte with uing of one S-box (predefined 16x16 table) ShiftRow - cyclically hift the element of i-th row i element to the left for encryption and right for decryption a it i hown below: 0,0 1,0 2,0 3,0 0,1 1,1 2,1 3,2 0,2 1,2 2,2 3,2 0,3 1,3 2,3 3,3 0,0 1,1 2,2 3,3 0,1 1,2 2,3 3,0 0,2 1,3 2,0 3,1 0,3 1,0 2,1 3,2 MixColumn in tate replace each byte of a column by a function of all the byte in the ame column. Function for each row i decribed below: Firt row: ', j ( 0x02 0, j ) ( 0x 1, j ) 2, j 3, j 0 = 03 Second row: ( 0x02 j ) ( 0x j ) 3 j ' 1, j = 0, j 1, 03 2,, Third row: ( 0 x02 ) ( 0x ) ', j = 0, j 1, j 2, j 3, j 2 03 Fourth row: ( 0 x03 ) ( 0x ) ' 3, j = 0, j 1, j 2, j 02 3, j Summarize each byte in a column i replaced by two time that byte, plu three time next byte, plu the byte that left. It hould be mentioned here alo that next to the byte that i in the lat row i a byte in the firt row. Round key are created bae on AES key. Firt key i arranged a it i hown below:

16 k k k k 0 1 2 3 k k k k 4 5 6 7 k k k k 8 9 10 11 k k k k 12 13 14 15 [ w w w w ] 0 1 2 3 Where w i called word and it conit of four byte from key. Baed on thoe four word next four are created and o on until 40 word are obtained beide tarting four. Below i the algorithm how to get next four word: w w w w i+ 4 i+ 5 i+ 6 i+ 7 = = = = w w w w i g i+ 4 i+ 5 i+ 6 ( w ) w w w i+ 3 i+ 1 i+ 2 i+ 3 Where g function conit of following tep: 1. One-byte left circular rotation on the argument. 2. SubByte explained on previou page. 3. XOR obtained byte with round contant. Where round contant i created thi way: RC RC [ ] = ( RC[ i],0x00,0x00,0x00) [ 1] = 0x01 [ j] = 0x02 RC[ j 1] Rcon i

17 4.6 HMAC HMAC i MAC code with mixed ecret key. Thank to that enure both the protection of the integrity and authenticity of data. Standard MAC code provide integrity protection, however, it may be ubject to adulteration if it i not protected by an additional mechanim to protect it authenticity. To protect the integrity and authenticity HMAC wa created. A it wa mentioned before HMAC add ecret key to each MAC meage: HMAC K ( m) = h ( ) ( K opad ) h ( K ipad ) m ) Where opad and ipad are fixed complementary value, m i text for which HMAC i created and K i ecret key. To create right HMAC code the key i needed, which enure that the data are protected. In thi application HMAC baed on SHA-256 cryptographic hah function wa ued. (RFC 2014)

18 4.7 TCP protocol TCP protocol wa choen to be the internet layer on which communication will be built and etablihed. Thi protocol provide reliable, ordered and errorchecked delivery of meage between hot via LAN, intranet or public Internet. It belong to tranport layer of TCP/IP uite and communication ervice between application program and IP. TCP work in client-erver mode. Server i waiting for connection on pecified port, while client i trying to initialize the connection. Thi protocol guaranteed that all meage will be delivered in correct order and without duplication. Thi enure a reliable connection at the expene of greater overhead in the form of a header and a larger number of packet ent. To etablihed a connection three-way handhake procedure i ued, like thi: 1. Hot A end to hot B SYN egment with information about the lower end of the equence number ued to number of egment ent by hot A. 2. Hot B replie with SYN-ACK egment which contain hot B equence number and acknowledgment number which i hot A equence number incremented by 1. 3. Hot A end to hot B ACK egment with acknowledge number which i hot B equence number incremented by 1. After that three tep connection i conidered to be etablihed and normal communication can be ent. After one of hot receive packet from another one it thi hot hould reply with ACK egment which contain equence number of previouly received data. (RFC 793)

19 5 DESIGN AND IMPLEMENTATIONS 5.1 Concept The idea for the project wa to create an application that provide ecure communication over TCP protocol and the uer of which interface can be eaily changed into a different one, even implemented in a different language than Java programming language. To provide the aforementioned functionality, the project wa divided into three layer uch a communication, ciphering and uer interface layer. Communication and ciphering layer are integrated into one application which can be launched alone without uer interface. The ciphering layer can be eaily extracted from that project and ued to create application to ciphering file, or to provide ciphering in another operation ytem than the Window. It provide implementation of ymmetric and aymmetric algorithm to encrypt and decrypt data. Uer doe not have to interact with the ciphering or communication layer. It i only needed to input the IP addre and the port number with which communication hould be etablihed C++ language wa choen to be the language with the ue of which the application core reponible for communication over TCP protocol and ciphering i to be written. To create a uer interface uing Java programing language wa choen due to the eaiet method in implementing graphic element. It i recommended to ue a ready library to provide an encryption algorithm and not to implement it by ourelve becaue it i conidered to be more ecure. All thee kind of librarie are public and it wa teted many time and proved to be ecure and well implemented. Therefore it wa decided to ue OpenSSL a library with encrypting function.

20 Communication between Java and C++ application wa decided to be implemented with uage of ocket on port 8080 and 8081 and IP addre 127.0.0.1. That IP addre i a loopback addre in the Window operating ytem, and allow to end information between the port of the ame local machine. A erver implemented in Java ue port 8080 to receive data from C++ application and the client i uing port 8081 to end data to C++ application. Decrypting C++ application ha a client which end data obtained from a partner computer working on port 8080. C++ application encrypting data ha erver litening on port 8081 for data from Java application. A it wa mentioned earlier uer ha to input port number of partner erver in uer interface and partner IP addre and alo port for hi own erver. The application and all file hould be placed in directory: C:/SecureCA/. Otherwie, program will not run properly. Below i the cenario for the application: Uer on PC1 type ome data into the uer interface application and decide to end it. Data i ent via port number 8081 to the ciphering application which encrypt them and end via port the number of which wa earlier defined when the application wa tarted and on an IP addre which alo wa earlier defined. C++ application which i run on PC2 whoe IP addre i the ame a the one defined on PC1 uer interface application receive data from PC1 on port the number of which wa defined earlier in the uer interface. They are decrypted and ent via port 8080 to the uer interface which i receiving decrypted data on port number 8080, and finally data are hown on uer interface for uer. (See Figure: 1. 2. 3.)

FIGURE 2 High level architecture meage cycle. 21

FIGURE 3 High level architecture with port decription. 22

FIGURE 4 Example cenario for application. 23

24 Below i the cenario for the C++ SecureCAServer : 1. Start application. 2. Etablih the connection with UI 3. Start to liten for incoming connection from SecureCA working on another hot. 4. Accept the incoming connection from another hot. 5. Receive encrypted AES key received from another hot. 6. Decrypt AES key. 7. Receive encrypted IV from another hot 8. Decrypt IV received from another hot 9. Initialize data for AES cipher. 10. Start to liten for incoming meage from the other hot. 11. When receive any meage: a. Store it a the hmacmeage. b. Store next incoming meage a EncryptedMeage. c. Create the hah from the EncryptedMeage. d. Compare created hah with the received on. i. If they are the ame decrypt the EncryptedMeage, and end to UI ii. Otherwie do nothing e. Still liten for incoming meage 12. If the connection with another hot i lot, turn off the application

25 Below i the cenario for the C++ SecureCAClient : 1. Start application. 2. Start to liten for incoming connection from UI. 3. Accept the incoming connection from UI. 4. Etablih connection with SecureCA working on another hot. 5. Generate the AES key and the IV. 6. Encrypt AES key. 7. Send encrypted AES key to another hot. 8. Encrypt IV. 9. Send encrypted IV to another hot 10. Initialize data for AES cipher. 11. Start to liten for incoming meage from the UI. 12. When receive any meage: a. Encrypt that meage uing AES algorithm and tore a EncryptedMeage. b. Create the hah from the EncryptedMeage. c. Send created hah to another hot. d. Send EncryptedMeage meage to another hot. e. Still liten for incoming meage 13. If the connection with UI i lot, turn off the application.

26 5.2 Communication layer 5.2.1 Winock Communication between two hot i implemented with the help of Winock. It i a technical pecification that define how to acce the network ervice from Window operating ytem. Microoft deliver the library needed to implement that communication. In that application window, winock2 and w2tcpip are ued. Thoe librarie provide u with the baic function and data tructure neceary to etablih the connection. Server ide need two ocket, one for liting for incoming connection. The other one hould be aigned after accepting the incoming connection which wa etablihed. After that there i no need to liten to the ocket anymore, only the econd ocket need to end data from client received. The following code how data needed to initialize connection baed on Winock erver ide: WSADATA wadata; SOCKET LitenSocket; SOCKET ClientSocket; truct addrinfo *reult; truct addrinfo hint; The following code how data needed to etablihed connection baed on Winock erver ide: WSAStartup(MAKEWORD(2,2), & getwadata()); ZeroMemory(&hint, izeof(hint)); hint.ai_family = AF_INET; hint.ai_ocktype = SOCK_STREAM; hint.ai_protocol = IPPROTO_TCP;

27 hint.ai_flag = AI_PASSIVE; The following code how proce of creating, litening and accepting connection on erver ide: Reolve the erver addre and port getaddrinfo(null, portnumber, &hint, &reult); Create a SOCKET for connecting to erver etlitensocket(ocket(reult->ai_family, reult->ai_ocktype, reult->ai_protocol)); Setup the TCP litening ocket bind(getlitensocket(), reult->ai_addr, (int)reult->ai_addrlen); Liten for incoming connection liten(getlitensocket(), SOMAXCONN); Accept a client ocket etclientsocket(accept(getlitensocket(), NULL, NULL)); The client ide need only one ocket which i ued to connect to erver, and after the connection i etablihed, thi ocket i ued to end and receive data from erver. The following code how the data needed to initialize connection baed on Winock client ide: WSADATA wadata; SOCKET ConnectSocket; truct addrinfo *reult; truct addrinfo *ptr; truct addrinfo hint; The following code how data needed to etablihed connection baed on Winock client ide:

28 WSAStartup(MAKEWORD(2,2), &getwadata()); ZeroMemory( &hint, izeof(hint) ); hint.ai_family = AF_UNSPEC; hint.ai_ocktype = SOCK_STREAM; hint.ai_protocol = IPPROTO_TCP; The following code how proce of creating and connection to erver on client ide: Reolve the erver addre and port getaddrinfo(getipaddre(),getportnumber(), &hint, &reult); Attempt to connect to an addre until one ucceed for(ptr=reult; ptr!= NULL ;ptr=ptr->ai_next) { Create a SOCKET for connecting to erver etconnectsocket(ocket(ptr->ai_family, ptr->ai_ocktype, ptr->ai_protocol)); Connect to erver. connect(getconnectsocket(), ptr->ai_addr, (int)ptr->ai_addrlen); } After etablihing the connection data are exchanged between erver and client with the uage of two function end() and recv(). Data ent between uer in SecureCA cannot be longer than 256 byte which allow uer to end at once 256 char. The following code how function ued to end and receive data: Sending and receiving data on client ide end(connectsocket, endbuf, (int) trlen(endbuf), 0); recv(connectsocket, recvbuf, recvbuflen, 0); Sending and receiving data on erver ide recv(clientsocket, recvbuf, recvbuflen, 0);

29 end(clientsocket, recvbuf, ireult, 0); Send and recv function require 4 variable a input. The firt i a decriptor that identifie the connected ocket which hould end/receive data. The econd i a pointer to the buffer to end/receive data. The third i the length in byte, of the ending data or the ize of buffer for toring the received data. The fourth i not ued in that program and it i a et of flag that influence the behavior of thoe function. (MSDN Send, MSDN Recv) 5.2.2 Parameter and requirement The implementation of communication layer require from uer to deliver two parameter to et up the client ide and one parameter for the erver layer. For the client the uer need to input port number on which communication will be etablihed. The port number hould be higher than 1023 and lower than 65535. The econd parameter i the IP addre of the hot with which uer want to communicate. It hould be 32-bit number coniting of 4 octet in dot-decimal notation compatible with Internet Protocol Verion 4, in example 191.168.1.1. (RFC 3330, RFC 6335) For the erver uer need to input only one parameter which i the port number on which the erver will be litening for incoming connection. The port number hould be a figure between 1023 and 65535. (RFC 6335)

30 5.3 Ciphering layer Ciphering layer wa written uing C++ programing language with uage of OpenSSL library which provide baic cryptographic function. To enable RSA and AES function it wa needed to include in project file uch a rand.h, ra.h, ae.h, hmac.h, engine.h, applink.c and pem.h. Thi layer conit of two independent program, the firt (further referred to a SecureCAServer) i reponible for receiving data, decrypting and ending to uer interface, the econd (further referred to a SecureCAClient) i reponible for receiving data from uer interface, encrypting and ending to peron with which the uer want to communicate. 5.3.1 Creating/Reading RSA key from file Thi program allow uer to create RSA key pair or read it from file. The key length i 4096 bit and the exponential ued to create key i 65537. The key i tored in RSA* data type. If while the application wa tarted there were no RSA key pair in the folder where the application i placed, they are created and aved in the ame folder where the application i, however, i required to retart the application to work properly. The following code liting how function which are ued to generate, read and write to file RSA key. SecureCAServer read another hot public key, while SecureCAClient read the hot on which the private key from file i running. RSA_generate_key(RSA_KEYLENGTH, RSA_E, NULL, NULL); PEM_write_RSAPrivateKey(filePrivateRSAKey, thi->thirsakey NULL,NULL,0,NULL,NULL); PEM_write_RSAPublicKey(filePublicRSAKey, thi->thirsakey); PEM_read_RSAPrivateKey(filePrivateRSAKey,&thi->thiRSAKey,NULL,NULL); PEM_read_RSAPublicKey(filePublicRSAKey, &thi->otherrsakey, NULL, NULL); RSA_generate_key function need to provide 4 parameter. The firt i the length of the key, the econd exponent number, and the third and fourth are not ued in that program. (OpenSSL RSA)

31 PEM are a family of function provided by OpenSSL to operate with a file. Read function require 4 parameter. The firt one i a pointer to file from which the key hould be read, the econd pointer to a variable in which the key hould be written, the third i a callback and the fourth i a pa phrae to file. The lat two are not ued in that program. In PEM_write_RSAPublicKey the firt parameter i a pointer to which file key hould be written. The econd i a pointer to data from which the key hould be read. In PEM_writeRSAPrivateKey the firt and the endo parameter are the ame a in PEM_write_RSAPublicKey function. The lat five argument refer to ecure file with a paword and they are not ued in that program.(openssl PEM) 5.3.2 Creating AES key AES key i created for every new communication eion for each channel o there are two key independent for each other. It i 128-bit long and i created with uage of random bit. Becaue AES i ued in counter mode there i alo initialization vector needed to be created which i 16-byte long random byte. The key i tored in a data tructure called AES_KEY. SecureCAClient i reponible for generating AES key while SecureCAServer i receiving that key from another hot thank to SecureCAClient. The following code liting how the function which are ued to generate, aign and tore AES key. AES_KEY ae_key; RAND_byte(thi->thiAESKey, AES_KEYLENGTH/8) RAND_byte(thi->thiAESIV, 16) AES_et_encrypt_key(thiAESKey(), AES_KEYLENGTH, &ae_key); RAND_byte i a function from OpenSSL library which generate random byte. Two argument are needed a input for that function. The firt i a pointer to char array in which the data hould be tored and the econd i the number of byte that hould be generated. (OpenSSL RAND) AES_et_encrypt_key i a function that generate round key for AES algorithm and ave them to AES_KEY tructure. The function require three

32 argument a input. The firt i a pointer to key baed on which round key are generated. The econd i the length of the key in bit, thi variable can have three different value that are 128, 192, 156 bit. The third argument i a pointer to AES_KEY tructure which tore round key. (Foie AES) 5.3.3 AES key exchange AES key are exchanged between hot right after the connection i etablihed with the uage of RSA algorithm. Initialization vector are alo ent, becaue they are needed for the correct working of SecureCA. Encrypted key and IV end via TCP protocol, from SecureCAClient working on the firt hot to SecureCAServer working on the econd hot, and they are viible only for them. 5.3.4 Encrypting/decrypting AES eion key uing RSA algorithm To enure that AES key and IV are not viible for potential attacker who can monitor communication, it wa decided to encrypt them with the uage of RSA algorithm. SecureCAClient working on the firt hot encrypt AES key and IV with RSA public key of the econd hot and SecureCAServer working on the econd hot decrypt the received key and the IV with the econd hot private key. The following code liting how the function which are ued to encrypt and decrypt AES key and IV. RSA_public_encrypt(AES_KEYLENGTH/8, ciphering->getthiaeskey(), mgencrypredaeskey, ciphering->getotherrsakey(), RSA_PKCS1_PADDING); RSA_public_encrypt(16, ciphering->getthiaesiv(), mgencrypredaeskey, ciphering- >getotherrsakey(), RSA_PKCS1_PADDING); RSA_private_decrypt(erver->iReult,(unigned char *) mgencrypredaeskey,(unigned char *) mgotheraeskey, ciphering->getthirsakey(), RSA_PKCS1_PADDING); RSA_private_decrypt(erver->iReult,(unigned char *) mgencrypredaeskey,(unigned char *) mgotheraesiv, ciphering->getthirsakey(), RSA_PKCS1_PADDING);

33 RSA_private_decrypt i a function which decrypt data previouly encrypted uing a paired public key and require 5 argument. The firt i length of decrypting data in byte. The econd i a pointer to char array which hould be decrypted. The third i a pointer to char array to which the decrypted data hould be written. The fourth i pointer to RSA tructure which tore private key. The fifth i the number of padding which hould be ued. (OpenSSL RSA) RSA_public_encrypt i a function which encrypt data with the uage of a public key and require five argument a input. The firt i the length of data that hould be encrypted in byte. The econd i a pointer to char array which hould be encrypted. The third i a pointer to char array in which encrypted data hould be tored. The fourth i a pointer to RSA tructure which hold the public key. The lat on i the number of padding. (OpenSSL RSA) 5.3.5 Uing AES algorithm AES i working in variou mode. In that application AES work in a counter mode which allow the proceing of data of varying length without any problem and worrie about padding. In the counter mode it i needed to create a tructure which take care of the number of iteration. Thi tructure conit of three data. The firt i the number reponible for counting iteration. The econd i a pointer to char array, which tore encrypted iteration key. The third i a pointer to char array, which tore IV. The following code liting how a field in the tructure and the initialization of tructure. truct ctrstate{ }; unigned int number; unigned char ecount[16]; unigned char ivec[16]; void initctrstate(truct ctrstate *tate, cont unigned char iv[8]){ tate->number = 0; memet(tate->ecount, 0, 16); memet(tate->ivec + 8, 0, 8); memcpy(tate->ivec, iv, 8); }

34 AES i a ymmetric algorithm that mean it ue the ame key to encrypt and decrypt data, alo the function ued to encrypt and decrypt data i the ame: AES_ctr128_encrypt(meageEncrypted, meage, erver->ireult, &ae_key, controlstructure.ivec, controlstructure.ecount, &controlstructure.number); AES_ctr128_encrypt i a function from OpenSSL library that encrypt/decrypt data with the uage of AES algorithm in counter mode. The function need even argument a input. The firt i a pointer to char array with data to encrypt/decrypt. The econd i a pointer to char array in which decrypted /encrypted data hould be tored. The third i the length of data to encrypt/decrypt in byte. The fourth i pointer to AES_KEY tructure which tore AES round key. The lat three are pointer to variable from ctrstate to control iteration of AES. (Foie AES) 5.3.6 HMAC HMAC i ued to authenticate the ource from which a meage come from. It i alway created before ending the meage via network and it i alo end before exact meage. When the application receive a meage it create hah from that meage and compare it to the previouly received hah. If the hahe are the ame it mean that data were not changed by unauthorized people. The following code liting how the function which are ued to create hah from a meage. HMAC(EVP_ha256(), ciphering->getotheraeskey(), AES_KEYLENGTH/8,meageEncrypted, erver->ireult, NULL, NULL); HMAC i delivered by OpenSSL library. It require even argument a input. The firt i name of hah function. The econd i pointer to char array that tore the key which will be ued to cipher data. The third i the length in byte of key. The fourth i a pointer to char array which tore data from which

hah hould be created. The fifth i the length in byte of data to be hahed. The lat two are not ued in that application. (OpenSSL HMAC) 35

36 5.4 Uer interface layer UI wa created uing Java programming language and Swing library. It conit of one application window which ha two text area for howing received and ent data. There i alo a text field to input data which hould be ent to another uer and a button by preing which the uer confirm ending a meage. At the beginning of the application thoe field and the button are hidden. Uer ha to fill in the firt port number for erver and IP addre and the port number for client, and confirm the parameter by preing correponding button. 5.4.1 Socket To communicate with C++ application ocket are neceary. There i one Socket and one ServerSocket for erver ide and one Socket for client ide. Connection i etablihed with uage of port number 8081 for erver ide and port number 8080 for the client ide. Communication take place with IP addre 127.0.0.1 which i conider to be loopback and allow application to end data between the application running on the ame hot with uage of port. The following code liting how how to create and configure ocket for UI. private Socket clientsocket; private ServerSocket erver; private Socket clientforserver; clientsocket = new Socket("127.0.0.1", 8080); erver = new ServerSocket(8081); clientforserver = erver.accept(); 5.4.2 Data taken from uer A it wa mentioned before, at the tart of the application uer ha to input port number for erver, which hould be between 1023 and 65535 and confirm thi by preing button Turn erver to enable a receiving meage from other hot. Port number between 1023 and 65535 and IP addre in dot-

decimal notation of hot to which uer want to end data hould be et in field above button Connect, and confirmed by preing that button (FIGURE 3). 37 FIGURE 5 Example configuration. After thoe tep uer i able to end and receive a meage. Thi tep doe not have to be done in that order, however, erver on hot with which uer want to communicate hould be turned on before uer et up hi own client. However, if uer want only to end or receive meage, only client or erver can be et up in hi application.

38 FIGURE 6 Example meage exchange. 5.4.3 How to change UI The core of SecureCA application wa deigned the way that allow to eaily change UI to another. During the implementation of the new UI few thing had to be kept in mind. There are two different C++ application. SecureCAClient i reponible for ending meage to another hot, while SecureCAServer i reponible for receiving meage. Thoe two C++ application have to be tarted from UI. Communication between UI and C++ application i realized with uage of ocket. SecureCAClient ha ocket configured a erver and i litening for incoming connection from UI on the port number 8080 and IP addre 127.0.0.1. SecureCAServer ha ocket configured a client and i trying to connect via the port number 8081 and IP addre127.0.0.1.

39 For SecureCAClient two parameter have to be input on tart. The firt one i the port number through which application hould connect to erver. The econd one i the IP addre of hot with which communication hould be etablihed. For SecureCAServer only one parameter ha to be input on tart. Thi parameter i the port number on which erver will be litening for incoming connection.

40 6 INSTALLATION Requirement from hot: 1. Operating ytem : Window 7 x 86 2. Java JDK 8: http://www.oracle.com/technetwork/java/javae/download/jdk8- download-2133151.html 3. Win32 OpenSSL v1.0.1f and Viual C++ 2008 Reditributable: http://lproweb.com/product/win32openssl.html The program hould unzipped to: C:/SecureCA/. After unzipping, the application hould be turned on and off without etablihing any connection. After that RSA key pair will be created in file: privatersakey.pem private RSA key publicrsakey.pem public RSA key Public RSA key hould be delivered to hot with which we want to communicate, and placed in folder with intalled application. After completing thee tep, the application i ready to ue.

41 7 TESTING The tet wa realized with the uage of niffer called Wirehark and RawCap. Thee niffer are available for free on the following web ite: http://www.wirehark.org/download.html http://www.netreec.com/?page=rawcap RawCap allow monitoring the network layer. With the uage of RawCap it i poible to check what data were ent and received by hot. Wirehark wa ued to read the package captured by RawCap. SecureCA connection realized with uage of TCP protocol. Meage ent via thi protocol wa checked while application wa working with RawCap. The teting wa completed on one machine and the meage wa ent on the IP addre 127.0.0.1 which i a loopback addre in Window and allow ending the meage from the hot to himelf. Figure 7 how that RawCap i working. Figure 8 how the meage ent from UI to C++ app and that data are not encrypted while on Figure 9 it i poible to ee data ent from one C++ app to another and that data are encrypted. Figure 10 how encrypted meage received from C++ application which are ent to UI.

42 FIGURE 7 How RawCap i working. FIGURE 8 Meage ent from UI to C++ application.

43 FIGURE 9 Meage ent from one C++ application to another one. FIGURE 10 Meage ent from C++ apllication to UI. On Figure 8 10 the whole proce of ending meage can be een. The firt plain text i ent from UI via the port 8080 to SecureCAClient. After that the meage i encrypted and ent via the port 8088 to SecuraCAServer. At lat the meage i decrypted and ent via the port number 8081 to UI.

44 8 Further development 8.1 What ha been done All the goal that have been etablihed have been realized. The application i working a proper way. The application i able to: 1. Generate the RSA key pair. 2. Read the RSA key from file. 3. Generate the AES key and the IV. 4. Encrypt with uage of RSA algorithm AES key and IV. 5. Etablih the connection between two hot via the TCP protocol 6. Send encrypted key and IV to another hot. 7. Encrypt and decrypt meage with uage of AES algorithm 8. Send encrypted meage between two hot. 9. Create HMAC of encrypted meage. 10. Check with uage of HMAC authentication of meage. 11. Communicate between UI and get from it data. 8.2 What hould be done The application till need to be improved to provide better and more ecure communication. Future development hould provide: 1. Implementation of CA. 2. Communication between multiple uer at one time. 3. Creating conference chat. 4. Better, uer-friendly and intuitive UI 5. New UI hould allow uer to create contact lit. It i highly recommended to create new UI with uage of C++. That will allow replacing three application with one o the communication between UI and ciphering application will be within a ingle proce rather than inter-proce.

45 9 CONCLUSION During implementing thi project I learned many new iue mainly about OpenSSL. It wa hard to work with that kind of library becaue the documentation i very poor. I already had enough knowledge about the ciphering algorithm before realization of that project. However, thi project allowed me to olidify it, and even expand at ome point. Working with C++ in VS 2012 wa ometime very frutrating. However, I have learned very ueful thing about debugging. Implementing the communication between hot via ocket wa very imple and went for the firt time without having to make any amendment. Creating UI with Java wa a nice break from working with C++. Swing library i imple in uage, and creating ocket communication i even impler than in C++. The ciphering algorithm are in my opinion one of the mot important algorithm. The number of meage ent by uer uing the Internet continue to grow. Thee meage have different monetary value, however, uer may want to be protected againt acce by third partie for peronal reaon. Ciphering application are already often ued by people, and in future will be ued even more often, becaue our ociety i uing the internet more and more.

46 REFERENCES Fip 197 http://crc.nit.gov/publication/fip/fip197/fip-197.pdf referred to, on April 3rd, 2014 Floridi L. 2010 "Information: A Very Short Introduction" ISBN: 0199551375 Foie AES http://foie.org/dox/openl-1.0.1f/crypto_2ae_2ae_8h.html referred to, on March 30th, 2014 MSDN Recv http://mdn.microoft.com/enu/library/window/dektop/m740121(v=v.85).apx referred to, on March 30th, 2014 MSDN Send http://mdn.microoft.com/enu/library/window/dektop/m740149(v=v.85).apx referred to, on March 30th, 2014 OpenSSL HMAC http://www.openl.org/doc/crypto/hmac.html referred to, on March 30th, 2014 OpenSSL RSA http://www.openl.org/doc/crypto/ra.html referred to, on March 30th, 2014 OpenSSL RAND http://www.openl.org/doc/crypto/rand_byte.html referred to, on March 30th, 2014 OpenSSL PEM http://www.openl.org/doc/crypto/pem.html referred to, on March 30th, 2014 RFC 793 http://tool.ietf.org/html/rfc793 referred to, on April 2nd, 2014 RFC 2014 http://tool.ietf.org/html/rfc2104 referred to, on April 2nd, 2014 RFC 3330 http://tool.ietf.org/html/rfc3330 referred to, on March 30th, 2014 RFC 6335 http://tool.ietf.org/html/rfc6335 referred to, on March 30th, 2014 RSA PKCS ftp://ftp.raecurity.com/pub/pkc/pkc-1/pkc-1v2-1.pdf referred to, on April 2nd, 2014 Silicon angle http://iliconangle.com/blog/2013/01/17/re-imagining-big-data-in- 2013-prediction-for-mobile-it-and-more/ referred to, on March 30th, 2014