Package com.bj58.spat.gaea.server.core.communication.telnet

Examples of com.bj58.spat.gaea.server.core.communication.telnet.TelnetPipelineFactory


public class CountTest {

  @Test
  public void testCreateCommand() {
    Count count = new Count();
    Command command1 = count.createCommand("count");
    Assert.assertEquals(CommandType.Count, command1.getCommandType());
    Assert.assertEquals("#all#", command1.getMethod());
    Assert.assertEquals(1, command1.getSecond());
   
   
    Command command2 = count.createCommand("count|second 2|method getInfo");
    Assert.assertEquals(CommandType.Count, command2.getCommandType());
    Assert.assertEquals("getInfo", command2.getMethod());
    Assert.assertEquals(2, command2.getSecond());
  }
View Full Code Here


public class ExecTest {

  @Test
  public void testCreateCommand() {
    Exec exec = new Exec();
    Command command1 = exec.createCommand("exec|netstat -na");
    assertEquals(CommandType.Exec, command1.getCommandType());
    assertEquals("netstat -na", command1.getCommand());
   
    Command command2 = exec.createCommand("exec|killall java");
    assertEquals(CommandType.Illegal, command2.getCommandType());
  }
View Full Code Here

public class TimeTest {

  @Test
  public void testCreateCommand() {
    Time time = new Time();
    Command command1 = time.createCommand("time|grep abc|group 10|column -kd");
    assertEquals(CommandType.Time, command1.getCommandType());
    assertEquals("abc", command1.getGrep().get(0));
    assertEquals(ShowColumn.Key, command1.getColumnList().get(0));
    assertEquals(ShowColumn.Description, command1.getColumnList().get(1));
    assertEquals(2, command1.getColumnList().size());
    assertEquals(10, command1.getGroup());
   
   
    Command command2 = time.createCommand("time|grep 123");
    assertEquals(CommandType.Time, command2.getCommandType());
    assertEquals("123", command2.getGrep().get(0));
    assertEquals(ShowColumn.All, command2.getColumnList().get(0));
    assertEquals(1, command2.getColumnList().size());
    assertEquals(0, command2.getGroup());
View Full Code Here

  private static String src = "afh425yqdsf*$#^Q@#%HFGKSHFKG@#$%SFDGSFGK@$TDSF";


  @Test
  public void testDecryptByPubKey() throws Exception {
    RSAHelper helper = RSAHelper.getInstance();
    byte[] destBuf = helper.encryptByPrivateKey(src.getBytes("utf-8"));
    byte[] srcBuf = helper.decryptByPublicKey(destBuf);
    Assert.assertEquals(src, new String(srcBuf, "utf-8"));
  }
View Full Code Here

    Assert.assertEquals(src, new String(srcBuf, "utf-8"));
  }

  @Test
  public void testDecryptByPriKey() throws Exception {
    RSAHelper helper = RSAHelper.getInstance();
    byte[] destBuf = helper.encryptByPublicKey(src.getBytes("utf-8"));
    byte[] srcBuf = helper.decryptByPrivateKey(destBuf);
    Assert.assertEquals(src, new String(srcBuf, "utf-8"));
  }
View Full Code Here

    Assert.assertEquals(src, new String(srcBuf, "utf-8"));
  }
 
  @Test
  public void testPublicKey() throws Exception {
    RSAHelper helper1 = RSAHelper.getInstance();
    String exponent = helper1.getPubExponent();
    String modulus = helper1.getPubModulus();
    System.out.println("-----------------------------------");
   
    byte[] expBuf = exponent.getBytes("utf-8");
    byte[] modBuf = modulus.getBytes("utf-8");
    for(int i=0; i<expBuf.length; i++) {
      System.out.print(expBuf[i] + ",");
    }
    System.out.println("\n-----------------------------------");
    for(int i=0; i<modBuf.length; i++) {
      System.out.print(modBuf[i] + ",");
    }
    System.out.println("\n-----------------------------------");
    System.out.println(exponent);
    System.out.println("-----------------------------------");
    System.out.println(modulus);
    System.out.println("-----------------------------------");
   
   
    byte[] buf = helper1.encryptByPrivateKey(src.getBytes("utf-8"));
    for(int i=0; i<buf.length; i++) {
      System.out.print((buf[i] < 0 ? buf[i] + 256 : buf[i]) + ",");
    }
   
   
   
    RSAHelper helper2 = RSAHelper.getInstance(modulus, exponent);
    byte[] destBuf = helper2.encryptByPublicKey(src.getBytes("utf-8"));
    byte[] srcBuf = helper1.decryptByPrivateKey(destBuf);
    Assert.assertEquals(src, new String(srcBuf, "utf-8"));
  }
View Full Code Here

  @Test
  public void testCustomKey() throws Exception {
    String modulus = new String(new byte[]{65,76,66,70,47,121,82,48,116,99,82,104,118,102,89,81,43,120,114,67,77,66,76,90,103,120,98,119,77,53,74,50,88,71,73,68,121,71,82,67,108,56,86,84,122,66,105,52,116,83,88,116,76,102,86,83,73,77,114,87,119,114,84,102,100,90,83,70,52,80,87,106,121,79,50,65,13,10,97,81,57,66,115,108,65,122,74,71,114,56,110,51,76,104,113,110,114,120,117,102,78,98,47,85,69,56,54,109,50,66,69,51,102,112,83,116,98,109,71,57,66,110,98,97,52,78,120,56,73,50,69,85,84,121,110,101,104,49,98,72,70,121,87,67,85,111,121,79,73,103,106,98,120,79,13,10,111,47,81,49,73,121,104,87,53,116,52,98,98,105,80,109,74,104,71,72,13,10}, "utf-8");
    String exponent = new String(new byte[]{65,81,65,66,13,10}, "utf-8");
   
    RSAHelper helper = RSAHelper.getInstance(modulus, exponent);
    byte[] destBuf = helper.encryptByPrivateKey(src.getBytes("utf-8"));
   
    for(int i=0; i<destBuf.length; i++) {
      System.out.print(destBuf[i] + ",");
    }
  }
View Full Code Here

        SecureContext sc = global.getGlobalSecureContext(context.getChannel().getNettyChannel());
        //判断当前channel是否通过认证
        if(!sc.isRights()){
          //没有通过认证
          if(protocol != null && protocol.getSdpEntity() instanceof HandclaspProtocol){
            SecureKey sk = new SecureKey();
            HandclaspProtocol handclaspProtocol = (HandclaspProtocol)protocol.getSdpEntity();
            /**
             * 接收 客户端公钥
             */
            if("1".equals(handclaspProtocol.getType())){
              sk.initRSAkey();
              //客户端发送公钥数据
              String clientPublicKey = handclaspProtocol.getData();
              if(null == clientPublicKey || "".equals(clientPublicKey)){
                logger.warn("get client publicKey warn!");
              }
              //java 客户端
              if(protocol.getPlatformType() == PlatformType.Java){
                //服务器生成公/私钥,公钥传送给客户端
                sc.setServerPublicKey(sk.getStringPublicKey());
                sc.setServerPrivateKey(sk.getStringPrivateKey());
                sc.setClientPublicKey(clientPublicKey);
                handclaspProtocol.setData(sk.getStringPublicKey());//服务器端公钥
              }
             
              protocol.setSdpEntity(handclaspProtocol);
              response.setResponseBuffer(protocol.toBytes());
              context.setGaeaResponse(response);
              this.setInvokeAndFilter(context);
              logger.info("send server publieKey sucess!");
            }
            /**
             * 接收权限文件
             */
            else if("2".equals(handclaspProtocol.getType())){
              //客户端加密授权文件
              String clientSecureInfo = handclaspProtocol.getData();
              if(null == clientSecureInfo || "".equals(clientSecureInfo)){
                logger.warn("get client secureKey warn!");
              }
              //授权文件客户端原文(服务器私钥解密)
              String sourceInfo = sk.decryptByPrivateKey(clientSecureInfo, sc.getServerPrivateKey());
              //校验授权文件是否相同
              //判断是否合法,如果合法服务器端生成DES密钥,通过客户端提供的公钥进行加密传送给客户端
              if(global.containsSecureMap(sourceInfo)){
                logger.info("secureKey is ok!");
                String desKey = StringUtils.getRandomNumAndStr(8);
                //设置当前channel属性
                sc.setDesKey(desKey);
                sc.setRights(true);
                handclaspProtocol.setData(sk.encryptByPublicKey(desKey, sc.getClientPublicKey()));
                protocol.setSdpEntity(handclaspProtocol);
                response.setResponseBuffer(protocol.toBytes());
                context.setGaeaResponse(response);
              }else{
                logger.error("It's bad secureKey!");
View Full Code Here

      // get local proxy
      IProxyStub localProxy = Global.getSingleton().getProxyFactory().getProxy(request.getLookup());
      logger.debug("proxyFactory.getProxy finish");

      if (localProxy == null) {
        ServiceFrameException sfe = new ServiceFrameException(
            "method:ProxyHandle.invoke--msg:" + request.getLookup() + "." + request.getMethodName() + " not fond",
            context.getChannel().getRemoteIP(),
            context.getChannel().getLocalIP(),
            request,
            ErrorState.NotFoundServiceException,
View Full Code Here

  }
 
  @Override
  public void invoke(final GaeaContext context) throws Exception {
    logger.debug("-------------------begin async invoke-------------------");
    asyncInvoker.run(taskTimeOut, new IAsyncHandler(){
      @Override
      public Object run() throws Throwable {
        logger.debug("begin request filter");
        // request filter
        for(IFilter f : Global.getSingleton().getGlobalRequestFilterList()) {
View Full Code Here

TOP

Related Classes of com.bj58.spat.gaea.server.core.communication.telnet.TelnetPipelineFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.