Skip to content

Commit 7e59a7a

Browse files
committed
System Touch
1 parent 23befa5 commit 7e59a7a

5 files changed

Lines changed: 115 additions & 1 deletion

File tree

source/Main.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ public class Main
2525

2626
protected static final String BITCOIN_WEBEXPRESS_SERVER_THREAD_NAME = "WEBEXPRESS_BITCOIN_SERVER";
2727

28+
protected static final Integer RSA_WEBEXPRESS_SERVER_SOCKET = NitroWebExpress.Aspect.RSACompliant.DEFAULT_PORT;
29+
30+
protected static final String RSA_WEBEXPRESS_REMOTE_HOST = "localhost";
31+
32+
protected static final String RSA_WEBEXPRESS_SERVER_THREAD_NAME = NitroWebExpress.Aspect.RSACompliant.DEFAULT_THREAD;
33+
2834
protected static final String WEBEXPRESS_HOSTNAME = "localhost";
2935

3036
protected static final String AES_WEBEXPRESS_REMOTE_HOST = "localhost";
@@ -96,6 +102,8 @@ public Main()
96102

97103
NITRO.BRIDGE.BITCOIN_COMPONENT = new NitroWebExpress.Aspect.BitcoinCompliant(BITCOIN_WEBEXPRESS_REMOTE_HOST, BITCOIN_WEBEXPRESS_SERVER_SOCKET, BITCOIN_WEBEXPRESS_SERVER_THREAD_NAME, Boolean.TRUE);
98104

105+
NITRO.BRIDGE.RSA_COMPONENT = new NitroWebExpress.Aspect.RSACompliant(RSA_WEBEXPRESS_REMOTE_HOST, RSA_WEBEXPRESS_SERVER_SOCKET, RSA_WEBEXPRESS_SERVER_THREAD_NAME, Boolean.TRUE);
106+
99107
NITRO.BRIDGE.CONNECTION_STATUS = new NitroWebExpress.Aspect.ConnectionStatusServer(CONNECTION_STATUS_SERVER_HOST, NITRO.CURRENT_CONNECTIONS, NITRO.PORT);
100108

101109
NITRO.BRIDGE.MODULE_INSTALLER_SERVICE = new NitroWebExpress.Aspect.ModuleInstallationService(MODULE_INSTALLER_SERVICE_HOST);

source/commons/CommonRails.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,7 @@ public static void printShutdownSignal(final Object OWNER, final int PORT, final
838838
case 49177: module = "ASCIICreatorServer"; break;
839839
case 5512: module = "AES"; break;
840840
case 6682: module = "Bitcoin"; break;
841+
case 7743: module = "RSA"; break;
841842
default: module = "Unknown"; break;
842843
}
843844
printSystemComponent(OWNER, OWNER.hashCode(),
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package encryption.module.rsa;
2+
3+
import commons.CommonRails;
4+
5+
import javax.crypto.Cipher;
6+
import java.security.*;
7+
8+
/**
9+
* Minimal RSA encryption module for internet-facing data transmission.
10+
* Generates a 2048-bit RSA key pair on construction; exposes encrypt/decrypt.
11+
*/
12+
public class EncryptionModuleRSA
13+
{
14+
public final PublicKey PUBLIC_KEY;
15+
public final PrivateKey PRIVATE_KEY;
16+
17+
public EncryptionModuleRSA()
18+
{
19+
try
20+
{
21+
KeyPairGenerator gen = KeyPairGenerator.getInstance("RSA");
22+
gen.initialize(2048, new SecureRandom());
23+
KeyPair pair = gen.generateKeyPair();
24+
PUBLIC_KEY = pair.getPublic();
25+
PRIVATE_KEY = pair.getPrivate();
26+
CommonRails.printSystemComponent(this, this.hashCode(), ". EncryptionModuleRSA 2048-bit key pair generated .");
27+
}
28+
catch (Exception e) { throw new RuntimeException(e); }
29+
}
30+
31+
public byte[] encrypt(final byte[] DATA, final PublicKey KEY) throws Exception
32+
{
33+
Cipher c = Cipher.getInstance("RSA/ECB/OAEPWithSHA-256AndMGF1Padding");
34+
c.init(Cipher.ENCRYPT_MODE, KEY);
35+
return c.doFinal(DATA);
36+
}
37+
38+
public byte[] decrypt(final byte[] DATA) throws Exception
39+
{
40+
Cipher c = Cipher.getInstance("RSA/ECB/OAEPWithSHA-256AndMGF1Padding");
41+
c.init(Cipher.DECRYPT_MODE, PRIVATE_KEY);
42+
return c.doFinal(DATA);
43+
}
44+
}

source/server/nitro/NitroWebExpress.java

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ public static class Aspect
104104

105105
public BitcoinCompliant BITCOIN_COMPONENT;
106106

107+
public RSACompliant RSA_COMPONENT;
108+
107109
public ConnectionStatusServer CONNECTION_STATUS;
108110

109111
public MySQLComponent MYSQL_COMPONENT = new MySQLComponent();
@@ -115,6 +117,7 @@ public static class Aspect
115117
/** Start CONNECTION_STATUS and NitroWebExpress.SELF together. */
116118
public void start()
117119
{
120+
if (RSA_COMPONENT != null) RSA_COMPONENT.start();
118121
if (CONNECTION_STATUS != null) CONNECTION_STATUS.start();
119122
if (MODULE_INSTALLER_SERVICE != null) MODULE_INSTALLER_SERVICE.start();
120123
if (ASCII_CREATOR_SERVER != null) ASCII_CREATOR_SERVER.start();
@@ -886,6 +889,64 @@ public void send_message(final String MESSAGE)
886889
}
887890
}
888891

892+
public static class RSACompliant extends WebExpress
893+
{
894+
public static final Integer DEFAULT_PORT = 7743;
895+
public static final String DEFAULT_THREAD = "WEBEXPRESS_RSA_SERVER";
896+
897+
protected final RSACompliant.MessageOutputHandler RSA_MESSAGE_OUTPUT_HANDLER = new RSACompliant.MessageOutputHandler();
898+
899+
public messaging.MessageQueueSorter MESSAGE_QUEUE_SORTER;
900+
public messaging.MessageQueue MESSAGE_QUEUE;
901+
public java.net.Socket SOCKET;
902+
903+
public final encryption.module.rsa.EncryptionModuleRSA ENCRYPTION_MODULE =
904+
new encryption.module.rsa.EncryptionModuleRSA();
905+
906+
public RSACompliant(final String HOST, final Integer PORT, final String THREAD_NAME, final Boolean TELNET_PROXY_ENABLED)
907+
{
908+
if (HOST == null || PORT == null || THREAD_NAME == null || TELNET_PROXY_ENABLED == null)
909+
throw new SecurityException("//bodi/connect");
910+
911+
super(HOST, PORT, THREAD_NAME, TELNET_PROXY_ENABLED);
912+
913+
this.HOST = HOST;
914+
this.PORT = PORT;
915+
this.MESSAGE_QUEUE = new messaging.MessageQueue(this);
916+
this.MESSAGE_QUEUE_SORTER = new messaging.MessageQueueSorter(this);
917+
this.setName(THREAD_NAME);
918+
919+
CommonRails.printSystemComponent(this, this.hashCode(),
920+
". RSACompliant starting on " + HOST + ":" + PORT + " .");
921+
}
922+
923+
public RSACompliant() {}
924+
925+
protected static class MessageOutputHandler
926+
{
927+
public java.net.Socket SOCKET;
928+
929+
public MessageOutputHandler()
930+
{
931+
CommonRails.printSystemComponent(this, this.hashCode(), ". RSACompliant MessageOutputHandler starts .");
932+
}
933+
934+
public void send_message(final String MESSAGE)
935+
{
936+
if (MESSAGE == null) throw new SecurityException("//bodi/connect");
937+
messaging.MessageOutputHandler h = new messaging.MessageOutputHandler(SOCKET, MESSAGE);
938+
h.run();
939+
}
940+
941+
public void send_message(final StringBuffer BUFFER)
942+
{
943+
if (BUFFER == null) throw new SecurityException("//bodi/connect");
944+
messaging.MessageOutputHandler h = new messaging.MessageOutputHandler(SOCKET, BUFFER);
945+
h.run();
946+
}
947+
}
948+
}
949+
889950
public static class BitcoinCompliant extends WebExpress
890951
{
891952
protected BitcoinCompliant.MessageOutputHandler bitcoin_message_output_handler = new BitcoinCompliant.MessageOutputHandler();

source/shutdown/ShutdownHooks.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313
public class ShutdownHooks
1414
{
15-
public static final int[] PORTS = { 49152, 49155, 49166, 49177, 5512, 6682 };
15+
public static final int[] PORTS = { 49152, 49155, 49166, 49177, 5512, 6682, 7743 };
1616

1717
public static void register()
1818
{

0 commit comments

Comments
 (0)