Secure Sockets SSL (Secure Sockets Layer) is a standard security technology for establishing an encrypted link between a server and a client—typically.

Slides:



Advertisements
Similar presentations
Jan Java Networking UDP Yangjun Chen Dept. Business Computing University of Winnipeg.
Advertisements

Prepared By E. Musa Alyaman1 URLs, InetAddresses, and URLConnections Chapter 9.
User Datagram Protocol. Introduction UDP is a connectionless transport protocol, i.e. it doesn't guarantee either packet delivery or that packets arrive.
Prepared By E. Musa Alyaman1 User Datagram Protocol (UDP) Chapter 5.
1 Java Networking – Part I CS , Spring 2008/9.
1 L53 Networking (2). 2 OBJECTIVES In this chapter you will learn:  To understand Java networking with URLs, sockets and datagrams.  To implement Java.
Networking Support In Java 2 Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
1 Java Networking CS , Spring 2008/9. 2 Today’s Menu Networking Basics  TCP, UDP, Ports, DNS, Client-Server Model TCP/IP in Java Sockets URL 
Internet Programming In Java. References Java.sun.com Java552 Many of the programs shown.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L24 (Chapter 25) Networking.
2: Application Layer1 Socket Programming. 2: Application Layer2 Socket-programming using TCP Socket: a door between application process and end- end-transport.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 25 Networking.
Networking Support In Java 2 Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Datagram Programming A datagram is an independent, self-contained message sent over the network whose arrival, arrival time, and content are not guaranteed.
13-Jul-15 Sockets and URLs. 2 Sockets A socket is a low-level software device for connecting two computers together Sockets can also be used to connect.
Networking java.net package, which provides support for networking. Its creators have called Java “programming for the Internet.” Socket :- A network socket.
1 Networking with Java. 2 Introduction to Networking.
1 Java Networking CS , Spring Today’s Menu Networking Basics  TCP, UDP, Ports, DNS, Client-Server Model TCP/IP in Java Sockets URL  The.
CS4273: Distributed System Technologies and Programming I Lecture 5: Java Socket Programming.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
Application Protocols: HTTP CSNB534 Semester 2, 2007/2008 Asma Shakil.
VIII. UDP Datagrams and Sockets. The User Datagram Protocol (UDP) is an alternative protocol for sending data over IP that is very quick, but not reliable:
Import java.net.*; import java.io.*; public class LowPortScanner { public static void main(String[] args) { String host = "localhost"; if (args.length.
CS 424/524: Introduction to Java Programming Lecture 25 Spring 2002 Department of Computer Science University of Alabama Joel Jones.
DBI Representation and Management of Data on the Internet.
1 A TCP/IP Application Programming Perspective Chris Greenhalgh G53ACC.
Object Oriented Programming in Java Lecture 16. Networking in Java Concepts Technicalities in java.
Lecture 9 Network programming. Manipulating URLs URL is an acronym for Uniform Resource Locator and is a reference (an address) to a resource on the Internet.
1 Chapter 28 Networking. 2 Objectives F To comprehend socket-based communication in Java (§28.2). F To understand client/server computing (§28.2). F To.
Java Sockets Programming
UDP User Datagram Protocol. User Datagram Protocol (UDP) UDP is the protocol available to network programmers who wish to send datagrams UDP datagrams.
NETWORK PROGRAMMING.
Networks Sockets and Streams. TCP/IP in action server ports …65535 lower port numbers ( ) are reserved port echo7 time13 ftp20 telnet23.
Networking Java (2/3)
By Vivek Dimri. Basic Concepts on Networking IP Address – Protocol – Ports – The Client/Server Paradigm – Sockets The Java Networking Package – The InetAddress.
CSI 3125, Preliminaries, page 1 Networking. CSI 3125, Preliminaries, page 2 Inetaddress Class When establishing a connection across the Internet, addresses.
UNIT-6. Basics of Networking TCP/IP Sockets Simple Client Server program Multiple clients Sending file from Server to Client Parallel search server.
Java Programming II Java Network (I) Java Programming II.
1 Lecture 9: Network programming. 2 Manipulating URLs URL is an acronym for Uniform Resource Locator and is a reference (an address) to a resource on.
1 CSCD 330 Network Programming Fall 2013 Some Material in these slides from J.F Kurose and K.W. Ross All material copyright Lecture 8a Application.
UDP User Datagram Protocol. About the UDP A commonly used transport protocol Does not guarantee either packet delivery or order The packets may travel.
Agenda Socket Programming The OSI reference Model The OSI protocol stack Sockets Ports Java classes for sockets Input stream and.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
Network Programming. These days almost all devices.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 33 Networking.
Network Programming Communication between processes Many approaches:
Java.net CS-328 Dick Steflik.
Object-Orientated Analysis, Design and Programming
Chapter 03 Networking & Security
Network Programming Introduction
Networking with Java 2.
Network Programming Introduction
Sockets and URLs 17-Sep-18.
„Networking”.
Sockets and URLs 13-Nov-18.
Chapter 2: outline 2.1 principles of network applications
URL in Java C343 Lab (Week 13).
Hypertext Transfer Protocol
Networking.
Sockets and URLs 3-Dec-18.
CSCD 330 Network Programming
Hypertext Transfer Protocol
Networking.
CSCD 330 Network Programming
Hypertext Transfer Protocol
Java Socket Programming
Socket Programming 2: Application Layer.
CPSC 441 UDP Socket Programming
Hypertext Transfer Protocol
Presentation transcript:

Secure Sockets SSL (Secure Sockets Layer) is a standard security technology for establishing an encrypted link between a server and a client—typically a web server (website) and a browser, or a mail server and a mail client. To get a certificate, you must create a Certificate Signing Request (CSR) on your server. This process creates a private key and public key on your server. The CSR data file that you send to the SSL Certificate issuer (called a Certificate Authority or CA) contains the public key. The CA uses the CSR data file to create a data structure to match your private key. The CA never sees the private key. Once you receive the SSL Certificate, you install it on your server. You also install an intermediate certificate that establishes the credibility of your SSL Certificate by tying it to your CA’s root certificate. The instructions for installing and testing your certificate will be different depending on your server.

Secure Sockets When a browser attempts to access a website that is secured by SSL, the browser and the web server establish an SSL connection using a process called an “SSL Handshake” (see diagram below). Note that the SSL Handshake is invisible to the user and happens instantaneously. Essentially, three keys are used to set up the SSL connection: the public, private, and session keys. Anything encrypted with the public key can only be decrypted with the private key, and vice versa. Because encrypting and decrypting with private and public key takes a lot of processing power, they are only used during the SSL Handshake to create a symmetric session key. After the secure connection is made, the session key is used to encrypt all transmitted data.

Secure Sockets

Secure Sockets Browser connects to a web server (website) secured with SSL (https). Browser requests that the server identify itself. Server sends a copy of its SSL Certificate, including the server’s public key. Browser checks the certificate root against a list of trusted CAs and that the certificate is unexpired, unrevoked, and that its common name is valid for the website that it is connecting to. If the browser trusts the certificate, it creates, encrypts, and sends back a symmetric session key using the server’s public key. Server decrypts the symmetric session key using its private key and sends back an acknowledgement encrypted with the session key to start the encrypted session. Server and Browser now encrypt all transmitted data with the session key.

Java URL The Java URL class represents an URL. URL is an acronym for Uniform Resource Locator. It points to a resource on the World Wide Web. For example: http://www.javatpoint.com/java-tutorial   A URL contains many information: Protocol: In this case, http is the protocol. Server name or IP Address: In this case, www.javatpoint.com is the server name. Port Number: It is an optional attribute. If we write http//ww.javatpoint.com:80/sonoojaiswal/ , 80 is the port number. If port number is not mentioned in the URL, it returns -1. File Name or directory name: In this case, index.jsp is the file name.

B.E COMPUTER SCIENCE AND ENGINEERING(UG) Commonly used methods of Java URL class The java.net.URL class provides many methods. The important methods of URL class are given below. Method Description public String getProtocol() it returns the protocol of the URL. public String getHost() it returns the host name of the URL. public String getPort() it returns the Port Number of the URL. public String getFile() it returns the file name of the URL. public URLConnection openConnection() it returns the instance of URLConnection i.e. associated with this URL. 4/12/2018 B.E COMPUTER SCIENCE AND ENGINEERING(UG)

Java URL //URLDemo.java Output: Protocol: http import java.io.*;   import java.net.*;   public class URLDemo{   public static void main(String[] args){   try{   URL url=new URL("http://www.javatpoint.com/java-tutorial");   System.out.println("Protocol: "+url.getProtocol());   System.out.println("Host Name: "+url.getHost());   System.out.println("Port Number: "+url.getPort());   System.out.println("File Name: "+url.getFile());   }catch(Exception e){System.out.println(e);}  }  }   Output: Protocol: http Host Name: www.javatpoint.com Port Number: -1 File Name: /java-tutorial

Java URLConnection class The Java URLConnection class represents a communication link between the URL and the application. This class can be used to read and write data to the specified resource referred by the URL. How to get the object of URLConnection class The openConnection() method of URL class returns the object of URLConnection class. Syntax: public URLConnection openConnection()throws IOException{}   Displaying source code of a webpage by URLConnecton class The URLConnection class provides many methods, we can display all the data of a webpage by using the getInputStream() method. The getInputStream() method returns all the data of the specified URL in the stream that can be read and displayed 4/12/2018 B.E COMPUTER SCIENCE AND ENGINEERING(UG)

Eg.Java URLConnection class import java.io.*; import java.net.*; public class URLConnectionExample { public static void main(String[] args){ try{ URL url=new URL("http://www.javatpoint.com/java-tutorial"); URLConnection urlcon=url.openConnection(); InputStream stream=urlcon.getInputStream(); int i; while((i=stream.read())!=-1){ System.out.print((char)i); } }catch(Exception e){System.out.println(e);} } } Output: Displays Source Code of the Web page 4/12/2018 B.E COMPUTER SCIENCE AND ENGINEERING(UG)

Java HttpURLConnection class The Java HttpURLConnection class is http specific URLConnection. It works for HTTP protocol only. By the help of HttpURLConnection class, you can information of any HTTP URL such as header information, status code, response code etc. The java.net.HttpURLConnection is subclass of URLConnection class. How to get the object of HttpURLConnection class The openConnection() method of URL class returns the object of URLConnection class. Syntax: public URLConnection openConnection()throws IOException{}   You can typecast it to HttpURLConnection type as given below. URL url=new URL("http://www.javatpoint.com/java-tutorial");     HttpURLConnection huc=(HttpURLConnection)url.openConnection();   4/12/2018 B.E COMPUTER SCIENCE AND ENGINEERING(UG)

B.E COMPUTER SCIENCE AND ENGINEERING(UG) Eg. import java.io.*; import java.net.*; public class HttpURLConnectionDemo{ public static void main(String[] args){ try{ URL url=new URL("http://www.javatpoint.com/java-tutorial"); HttpURLConnection huc=(HttpURLConnection)url.openConnection(); for(int i=1;i<=8;i++){ System.out.println(huc.getHeaderFieldKey(i)+" = "+huc.getHeaderField(i)); } huc.disconnect(); }catch(Exception e){System.out.println(e);} } } OUTPUT: Date = Wed, 08 Feb 2017 17:00:48 GMT Server = Apache Set-Cookie = JSESSIONID=4429C9793A4D5C4B5717C9DC53C30D77; Path=/ Content-Type = text/html Cache-Control = max-age=2592000 Expires = Fri, 10 Mar 2017 17:00:48 GMT Vary = Accept-Encoding,User-Agent Keep-Alive = timeout=5, max=500 4/12/2018 B.E COMPUTER SCIENCE AND ENGINEERING(UG)

B.E COMPUTER SCIENCE AND ENGINEERING(UG) Inet Addresses Java InetAddress class represents an IP address. The java.net.InetAddress class provides methods to get the IP of any host name for example www.javatpoint.com, www.google.com, www.facebook.com etc. Method Description public static InetAddress getByName(String host) throws UnknownHostException it returns the instance of InetAddress containing LocalHost IP and name. public static InetAddress getLocalHost() throws UnknownHostException it returns the instance of InetAdddress containing local host name and address. public String getHostName() it returns the host name of the IP address. public String getHostAddress() it returns the IP address in string format. 4/12/2018 B.E COMPUTER SCIENCE AND ENGINEERING(UG)

B.E COMPUTER SCIENCE AND ENGINEERING(UG) Eg. import java.io.*; import java.net.*; public class InetDemo{ public static void main(String[] args){ try{ InetAddress ip=InetAddress.getByName("www.javatpoint.com"); System.out.println("Host Name: "+ip.getHostName()); System.out.println("IP Address: "+ip.getHostAddress()); }catch(Exception e){System.out.println(e);} } } Output: Host Name: www.javatpoint.com IP Address: 206.51.231.148 4/12/2018 B.E COMPUTER SCIENCE AND ENGINEERING(UG)

B.E COMPUTER SCIENCE AND ENGINEERING(UG) UDP Datagram The UDP provides unguaranteed connectionless transmission of data across an IP Network.By contrast TCP provides reliable Connection-Oriented Transmission of data UDP Classes: Java.net.DatagramSocket Java.net.DatagramPacket 4/12/2018 B.E COMPUTER SCIENCE AND ENGINEERING(UG)

Java DatagramSocket and DatagramPacket Java DatagramSocket and DatagramPacket classes are used for connection-less socket programming. Java DatagramSocket class Java DatagramSocket class represents a connection-less socket for sending and receiving datagram packets. A datagram is basically information but there is no guarantee of its content, arrival or arrival time. Commonly used Constructors of DatagramSocket class DatagramSocket() throws SocketException: it creates a datagram socket and binds it with the available Port Number on the localhost machine. DatagramSocket(int port) throws SocketEeption: it creates a datagram socket and binds it with the given Port Number. DatagramSocket(int port, InetAddress address) throws SocketException: it creates a datagram socket and binds it with the specified port number and host address

Java DatagramSocket and DatagramPacket Java DatagramPacket class Java DatagramPacket is a message that can be sent or received. If you send multiple packet, it may arrive in any order. Additionally, packet delivery is not guaranteed. Commonly used Constructors of DatagramPacket class DatagramPacket(byte[] barr, int length): it creates a datagram packet. This constructor is used to receive the packets. DatagramPacket(byte[] barr, int length, InetAddress address, int port): it creates a datagram packet. This constructor is used to send the packets.

Example of Sending DatagramPacket by DatagramSocket //DSender.java   import java.net.*;   public class DSender{    public static void main(String[] args) throws Exception {    DatagramSocket ds = new DatagramSocket();    String str = "Welcome java";    InetAddress ip = InetAddress.getByName("127.0.0.1");     DatagramPacket dp = new DatagramPacket(str.getBytes(), str.length(), ip, 3000);       ds.send(dp);       ds.close();     }   }   4/12/2018 B.E COMPUTER SCIENCE AND ENGINEERING(UG)

Example of Sending DatagramPacket by DatagramSocket //DReceiver.java   import java.net.*;   public class DReceiver{     public static void main(String[] args) throws Exception {       DatagramSocket ds = new DatagramSocket(3000);       byte[] buf = new byte[1024];       DatagramPacket dp = new DatagramPacket(buf, 1024);       ds.receive(dp);       String str = new String(dp.getData(), 0, dp.getLength());       System.out.println(str);       ds.close();     }   }   4/12/2018 B.E COMPUTER SCIENCE AND ENGINEERING(UG)