-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCertificateAuthorityThread.java
More file actions
78 lines (58 loc) · 1.9 KB
/
CertificateAuthorityThread.java
File metadata and controls
78 lines (58 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//
// CertificateAuthorityThread.java
//
// Written by : Priyank Patel <pkpatel@cs.stanford.edu>
//
// Accepts connection requests and processes them
// socket
import java.net.*;
import java.io.*;
// Swing
import javax.swing.JTextArea;
// Crypto
import java.security.*;
import java.security.spec.*;
import java.security.interfaces.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import javax.crypto.interfaces.*;
public class CertificateAuthorityThread extends Thread {
private CertificateAuthority _ca;
private ServerSocket _serverSocket = null;
private int _portNum;
private String _hostName;
private JTextArea _outputArea;
public CertificateAuthorityThread(CertificateAuthority ca) {
super("CertificateAuthorityThread");
_ca = ca;
_portNum = ca.getPortNumber();
_outputArea = ca.getOutputArea();
_serverSocket = null;
try {
InetAddress serverAddr = InetAddress.getByName(null);
_hostName = serverAddr.getHostName();
} catch (UnknownHostException e) {
_hostName = "0.0.0.0";
}
}
// Accept connections and service them one at a time
public void run() {
try {
_serverSocket = new ServerSocket(_portNum);
_outputArea.append("CA waiting on " + _hostName + " port " + _portNum);
while (true) {
Socket socket = _serverSocket.accept();
//
// Got the connection, now do what is required
// First complete the handshake
// Determine who sent it
// verify the username and password hash
// issue a certificate signed with the private key
//
}
} catch (Exception e) {
System.out.println("CA thread error: " + e.getMessage());
e.printStackTrace();
}
}
}