150 lines
10 KiB
Java
150 lines
10 KiB
Java
|
|
package com.foundation.orb;
|
||
|
|
|
||
|
|
import java.util.Random;
|
||
|
|
|
||
|
|
import com.common.debug.Debug;
|
||
|
|
import com.common.io.ByteArrayOutputStream;
|
||
|
|
import com.common.io.IClassReplacementHandler;
|
||
|
|
import com.common.io.StreamSupport;
|
||
|
|
import com.common.orb.Orb;
|
||
|
|
import com.common.security.IHashAlgorithm;
|
||
|
|
import com.common.security.ISignatureAlgorithm;
|
||
|
|
import com.common.security.Random2;
|
||
|
|
import com.common.security.Rijndael;
|
||
|
|
import com.common.security.RsaAlgorithm;
|
||
|
|
import com.common.security.Sha1;
|
||
|
|
import com.common.security.Sha512;
|
||
|
|
import com.common.util.LiteHashMap;
|
||
|
|
import com.common.util.LiteList;
|
||
|
|
import com.common.util.StringSupport;
|
||
|
|
import com.de22.orb.AbstractConnection;
|
||
|
|
import com.de22.orb.Address;
|
||
|
|
import com.de22.orb.NioEngine;
|
||
|
|
import com.de22.orb.development.OrbClassLoader;
|
||
|
|
import com.de22.orb.io.IOrbOutputStream;
|
||
|
|
import com.de22.orb.io.OrbByteArrayInputStream;
|
||
|
|
import com.de22.orb.io.OrbByteArrayOutputStream;
|
||
|
|
import com.de22.orb.io.OrbObjectInputStream;
|
||
|
|
import com.de22.orb.io.OrbObjectOutputStream;
|
||
|
|
import com.de22.orb.optional.CommonOrbWrapper;
|
||
|
|
import com.de22.orb.optional.ServerSocketOptions;
|
||
|
|
import com.de22.orb.optional.SocketOptions;
|
||
|
|
import com.de22.orb.security.SslSecurityProvider;
|
||
|
|
|
||
|
|
public class Server implements ITest, ITestService {
|
||
|
|
|
||
|
|
/**
|
||
|
|
* A standard replacment handler class that is used to replace one class name with another to facilitate communications between two processes where one or more may be mangled.
|
||
|
|
*/
|
||
|
|
protected static class ClassReplacementHandler implements IClassReplacementHandler {
|
||
|
|
public String getReplacementClassName(String className) {
|
||
|
|
return className;
|
||
|
|
}//getReplacementClassName()//
|
||
|
|
}//ClassReplacementHandler//
|
||
|
|
|
||
|
|
public static void test() {
|
||
|
|
RsaAlgorithm r = new RsaAlgorithm(1024*4);//15424
|
||
|
|
byte[] b;
|
||
|
|
|
||
|
|
b = r.getPublicKeyBytes();
|
||
|
|
// System.out.print("{");
|
||
|
|
// for(int i = 0; i < b.length; i++) {
|
||
|
|
// if(i != 0) {
|
||
|
|
// System.out.print(", ");
|
||
|
|
// }
|
||
|
|
// System.out.print("" + (b[i] & 0xFF));
|
||
|
|
// }
|
||
|
|
// System.out.println("}");
|
||
|
|
System.out.println(StringSupport.toHexString(b));
|
||
|
|
|
||
|
|
b = r.getPrivateKeyBytes();
|
||
|
|
System.out.println(StringSupport.toHexString(b));
|
||
|
|
// System.out.print("{");
|
||
|
|
// for(int i = 0; i < b.length; i++) {
|
||
|
|
// if(i != 0) {
|
||
|
|
// System.out.print(", ");
|
||
|
|
// }
|
||
|
|
// System.out.print("" + (b[i] & 0xFF));
|
||
|
|
// }
|
||
|
|
// System.out.println("}");
|
||
|
|
// long x = -284458917919895546L;
|
||
|
|
// long y;
|
||
|
|
// byte[] buffer = new byte[8];
|
||
|
|
//
|
||
|
|
// StreamSupport.writeLong(x, buffer, 0, StreamSupport.NUMBER_MSF);
|
||
|
|
// y = StreamSupport.readLong(buffer, 0, StreamSupport.NUMBER_MSF);
|
||
|
|
//
|
||
|
|
// Debug.log(x + " == " + y);
|
||
|
|
//
|
||
|
|
// try {
|
||
|
|
// OrbByteArrayOutputStream bout = new OrbByteArrayOutputStream(0);
|
||
|
|
// IOrbOutputStream stream = bout;
|
||
|
|
// OrbObjectOutputStream out = new OrbObjectOutputStream(stream, bout, new LiteHashMap(), null, new ClassReplacementHandler());
|
||
|
|
// long l = -284458917919895546L;
|
||
|
|
// long l2;
|
||
|
|
//
|
||
|
|
// out.writeLong(l);
|
||
|
|
//
|
||
|
|
// OrbByteArrayInputStream bin = new OrbByteArrayInputStream(bout.getBuffer());
|
||
|
|
// OrbObjectInputStream in = new OrbObjectInputStream(bin, bin, null, null, new LiteList(), null, null, null);
|
||
|
|
//
|
||
|
|
// l2 = in.readLong();
|
||
|
|
//
|
||
|
|
// Debug.log(l + " == " + l2);
|
||
|
|
// }//try//
|
||
|
|
// catch(Throwable e) {
|
||
|
|
// Debug.log(e);
|
||
|
|
// }//catch//
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* @param args
|
||
|
|
*/
|
||
|
|
public static void main(String[] args) {
|
||
|
|
//test();
|
||
|
|
// Sha512 t = new Sha512();
|
||
|
|
//
|
||
|
|
// t.add("Testing 123".getBytes())
|
||
|
|
// t.hash("Testing 123");
|
||
|
|
|
||
|
|
|
||
|
|
Orb.setOrbWrapper(new CommonOrbWrapper(new OrbClassLoader(), null, null));
|
||
|
|
Address address = new Address("localhost", port);
|
||
|
|
|
||
|
|
try {
|
||
|
|
NioEngine engine = new NioEngine(10);
|
||
|
|
ServerSocketOptions serverSocketOptions = new ServerSocketOptions(address, address, new SocketOptions(1), engine, new String[] {}, 120000, 60000, new SslSecurityProvider("SSLv3", "./test.key", "kspassword", "kpassword")) {
|
||
|
|
IHashAlgorithm hash = new Sha1();
|
||
|
|
ISignatureAlgorithm signature = new RsaAlgorithm(StringSupport.fromHexString("0000010000000100000001010000010100000201000001010000010000000201421C87D95A953BDA6B59BFD93DF8FA0EEB448F61FF04BAF14A58EE9E7634AD2E14E28B865C6CC3EAB1616DDFCBEFC3865128AE73B12DB7323BC0167B3B2D27CA52F84B4983D11362A357CBB54DD3F9903AC9882D969A09EE7496465401DEA88A91BCD3986175DF973F7815D98009987C242A54EF69C91474D96965777E48E1B2E12BAD57ADB6E5C291553B13C38B16640E18DB8C63891A1F2BD285FCEBBBF213CFF92C81177FB7F979F5BFA0AF6AAE4230D599A2C765BD0B6594D2BC458282191BCDACF5E8FBFEE8E08F9E41677CB394EB28D0A07FF2E3D1DE38EA65158687D455BF978F6C24F785E1639200DBE84A5BC702F912630D195739AD417D1004AD8200F19E42757A527FC58B928E64F53AB1D3596483661867CD9F94CCD12E20FA3448E0004A13DBBB6C499ECE1A7C9FCE995AFD19E326F4E024A7FFCC93B69FFC97913589704DA10D53B55D16D90762800B78A8865387509908C187148E46461888FA453A618EC706E38AAFF95A06F0E5389FF2B5BBD0C8D0C6365B07BF2A819ECF1F3D7163937AF2AA0CD9059CECDF4B7364D0E038435A0FB7347AD80ECF436148B447EE9A70EEBFA256D83C8D405AC6ECB3E08B3C5D2ACB4AE4419D344E2EBDBD14A1E7C7C9539C4B309C0EAFBF7344D8221C59A41275CE37FDF8BEDF368D466E777AD0276B7A801CA8DE14FF8A53AFF9EDA3DDC35C73B4CE7D035F488187A074F300B88D4B740B2C56824079BB9B0B483A44F02E2FF5A2045D515877B83C37D06777A6D33F9FF49BED837A10B6C94CE89CB782A460ED56412B84C66381EB2B0EE33813B8FF460CF1503EB11970BE9E2AF3567A0BA74B1936210D8EB7126B73743C4ECF8C4DE09C4D3E555465FEB211B9658DF471A50AFB87ACC439C800E55E14ACA9C9FD6E0DD9B6CC4DEA7EA168027329E858B6C44FDB1379D421D3BB53A488F55F4DA2971184F4966E65DF1D678A9ED660B59379F730BF08CFE16878478315D223C280BFF99AED521D7706AA53E3EEC18787D37EC1A0695723C1A87691CAB309103D065D53BE774B24FBAD5B67E2CEEBF1B6766F29E5DFB33454C06A4983222BAF00977F4371BB4128F40C5256961D70CE8BCECDFB395955956552DBCFE03961A4733B38DE2950EAC9B31D601F1CD611A57BB05F951AE295ED4D3694BF59BDC44CA690C43A9B30B32AFB70C707C353B8360AF040B8749C91D69584D07EFABA6812A1B3539BFFCFB04E5F5896BDD7464837F40608FAEB02B4D931DA0EB75D4D6D6249CDEE74ABACDF3F9BD01366D158D42D0F883ADC0A147111475ABA5E686E14336DF0B1795B2B150DC203CB4D4B2BD0A9DCEDC09BF7A6E64C1372CC10DFE9B21E3687D80FC799AA2F781D9C8F9CC6253032A967706085E6C6E43963E8968AAC0C5FEF8E2F527D17ED3D2824B8160999543549BD42412A31E9BF231BD7253C3161A6A6C72D8C005F9D7CAC79EB3C838FAADA4C2E41712392300FA7BECAAC0CBA35FD2F4C0A7172E66BB20D21062BF79373BDC7C05CDB14267DDEB7977E820B9176AAD6ACA03BE0EDFA3B41085D6D7CA7216B34A9818AB0977C3F7530C25E95FC1D9C126CA1E3DD46D791A305E03EC065B70131543F9767A5336022F45F91965DD94A06D930C5A4FC0D0B68D81BCB686B558CEF9E153DF87347B19CCED9D033BB6DAF2DB69B2E1340726DF202D366A1F7A8BAFFEF53267BB13679ECA7527FE00DE4A6B97D13D0C9F2DCB4E2EB45AFD55B53540E9F9FD8EDFA4BF28DC9D429DFC762BDD1B6529B370D7A4478788A4B03F7833669154C57F019D1CD41B2D1C1D1BF10FF00E9975DA8BF730F7E9CB14008E01CF26B0858BF28C01FB0F9D3F88F09100FC63A5F7A9C42A26B46765BA28FDD6337ACAB3F78903AB59AEA9D08B06F563EE04CFF393DB9ABABFF7EF8BFCF50417C0A61127525D5FE1A8D25E0B65FA0B181BA5F2FC0BC459A6CE3B048A855A215384028E073FC524BC17CE29C07AE655765C5BE6D304E9224B1F9661CA4ADFC1421E9806EC3228E38CAF8928640EA887456429125D95AAE5501E236780282E2678BD43E3B1B9DA9F9A62AA9B5F3D9EBD7B09866C1A62C1E4DE1C5DBCBD736417E13E25D3A4187D1BA7B91B31DC6B1350C5EBD92F4B68EFA59167EA7CBDD8D3E6CED1BCD202EF3DCEAFFD345865E1E2053B71AA02911970A1D1BC6FE16F0388311EEA36550B53C5F2CA5EFA515EB80E0B717125CC12006D2FBA467498A749FC22AEDB67FC85F36BCCFC7635DC01F194973A425D1A68A735DE7254CB7DB8D7040FBCB41756722F681CAA0A5A590BC62B2AF2A789D129229665B309179A023F5311688C5A68698C5CA8594A293FF78AA74FA1806280E87B04E3CDD95138B68C2CA98BED0EC2F7673E1B3DF4B92D62F2DC8A30C6D81E05774B6A8DE125C99278631188F6D6D2F8EB14A1E90719820CD70A9C80A7A02E8525B84F7523D5481999940DC73164F2AD621BC15839933F26EDC9F16336094ADBAA8C46B787555BDBF416E15C3D2EA80954A34A17B10FBB347363582A878455100AE2F1B25EE59D90C86EE395F2BE15A05DA20523047150AA57A6AA37D39BDD956744C2CE3443033E30181DC541B50BEC879679B6D855415267438C67F12C5829CAA9BBE70885942878AD761DA61A2CCEEA83C48554B68A4CA46E220FF619321A048A2D946709F86E5826D25B5CD8A0379FF78430AB8E1C5522C814DACEEBC4FBF875E43FF3BE38DC67A445132329CE150128CB543C4260185FCBCD1CE9D46798CC4C21C27EFE65ABDB4358DB28131B6AA313E
|
||
|
|
|
||
|
|
public int getSignatureSize(int applicationProtocolVersion) {
|
||
|
|
return signature.getSignedSize(hash.getHashSize());
|
||
|
|
}//getSignatureSize()//
|
||
|
|
public byte[] sign(int applicationProtocolVersion, byte[] unsignedBytes, byte[] responseBytes) {
|
||
|
|
hash.reset();
|
||
|
|
hash.add(responseBytes);
|
||
|
|
responseBytes = hash.hash();
|
||
|
|
|
||
|
|
for(int index = 0; index < unsignedBytes.length; index++) {
|
||
|
|
responseBytes[index] ^= unsignedBytes[index];
|
||
|
|
}//for//
|
||
|
|
|
||
|
|
return signature.sign(responseBytes);
|
||
|
|
}//sign()//
|
||
|
|
};
|
||
|
|
Object serverSocketId = Orb.openServerSocket("ServerSocket", serverSocketOptions);
|
||
|
|
|
||
|
|
if(serverSocketId == null) {
|
||
|
|
Debug.log("Failed to open the server socket");
|
||
|
|
System.exit(0);
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
Orb.bind(Orb.getProxy(new Server(), ITestService.class), ITestService.ID, null);
|
||
|
|
}//try//
|
||
|
|
catch(Throwable e) {
|
||
|
|
Debug.log(e);
|
||
|
|
}//catch//
|
||
|
|
}//main()//
|
||
|
|
public String performAction(String input) {
|
||
|
|
return "Hello World: " + input;
|
||
|
|
}//performAction()//
|
||
|
|
}//Server//
|