public AuthenticateUserOpImpl(Connection con, ExecutablePool pool) {
      super(MessageType.USER_CREDENTIAL_MESSAGE, 1);
      byte[] credentialBytes = null;
      // TODO this is not a valid way to create a member ID
      DistributedMember server =
          new InternalDistributedMember(
              con.getSocket().getInetAddress(), con.getSocket().getPort(), false);
      DistributedSystem sys = InternalDistributedSystem.getConnectedInstance();
      String authInitMethod =
          sys.getProperties().getProperty(DistributionConfig.SECURITY_CLIENT_AUTH_INIT_NAME);
      Properties tmpSecurityProperties = sys.getSecurityProperties();

      // LOG: following passes the DS API LogWriters into the security API
      Properties credentials =
          HandShake.getCredentials(
              authInitMethod,
              tmpSecurityProperties,
              server,
              false,
              (InternalLogWriter) sys.getLogWriter(),
              (InternalLogWriter) sys.getSecurityLogWriter());

      getMessage().setEarlyAck(Message.MESSAGE_HAS_SECURE_PART);
      HeapDataOutputStream heapdos = new HeapDataOutputStream(Version.CURRENT);
      try {
        DataSerializer.writeProperties(credentials, heapdos);
        credentialBytes = ((ConnectionImpl) con).getHandShake().encryptBytes(heapdos.toByteArray());
      } catch (Exception e) {
        throw new ServerOperationException(e);
      } finally {
        heapdos.close();
      }
      getMessage().addBytesPart(credentialBytes);
    }
Ejemplo n.º 2
0
 /**
  * Retrieve a set of currently connected I2PSockets, either initiated locally or remotely.
  *
  * @return set of currently connected I2PSockets
  */
 public Set<I2PSocket> listSockets() {
   Set<Connection> connections = _connectionManager.listConnections();
   Set<I2PSocket> rv = new HashSet<I2PSocket>(connections.size());
   for (Connection con : connections) {
     if (con.getSocket() != null) rv.add(con.getSocket());
   }
   return rv;
 }
 @Override
 protected Object attemptReadResponse(Connection cnx) throws Exception {
   Message msg = createResponseMessage();
   if (msg != null) {
     msg.setComms(
         cnx.getSocket(),
         cnx.getInputStream(),
         cnx.getOutputStream(),
         cnx.getCommBuffer(),
         cnx.getStats());
     if (msg instanceof ChunkedMessage) {
       try {
         return processResponse(cnx, msg);
       } finally {
         msg.unsetComms();
         processSecureBytes(cnx, msg);
       }
     } else {
       try {
         msg.recv();
       } finally {
         msg.unsetComms();
         processSecureBytes(cnx, msg);
       }
       return processResponse(cnx, msg);
     }
   } else {
     return null;
   }
 }
    @Override
    protected void sendMessage(Connection cnx) throws Exception {
      HeapDataOutputStream hdos = new HeapDataOutputStream(Version.CURRENT);
      byte[] secureBytes = null;
      hdos.writeLong(cnx.getConnectionID());
      if (this.securityProperties != null) {
        byte[] credentialBytes = null;
        // TODO this is not a valid way to create a member ID
        DistributedMember server =
            new InternalDistributedMember(
                cnx.getSocket().getInetAddress(), cnx.getSocket().getPort(), false);
        DistributedSystem sys = InternalDistributedSystem.getConnectedInstance();
        String authInitMethod =
            sys.getProperties().getProperty(DistributionConfig.SECURITY_CLIENT_AUTH_INIT_NAME);

        Properties credentials =
            HandShake.getCredentials(
                authInitMethod,
                this.securityProperties,
                server,
                false,
                (InternalLogWriter) sys.getLogWriter(),
                (InternalLogWriter) sys.getSecurityLogWriter());
        HeapDataOutputStream heapdos = new HeapDataOutputStream(Version.CURRENT);
        try {
          DataSerializer.writeProperties(credentials, heapdos);
          credentialBytes =
              ((ConnectionImpl) cnx).getHandShake().encryptBytes(heapdos.toByteArray());
        } finally {
          heapdos.close();
        }
        getMessage().addBytesPart(credentialBytes);
      }
      try {
        secureBytes = ((ConnectionImpl) cnx).getHandShake().encryptBytes(hdos.toByteArray());
      } finally {
        hdos.close();
      }
      getMessage().setSecurePart(secureBytes);
      getMessage().send(false);
    }
Ejemplo n.º 5
0
 public NIOMsgReader(Connection conn, Version version) throws SocketException {
   super(conn, version);
   this.inputChannel = conn.getSocket().getChannel();
 }