Giter VIP home page Giter VIP logo

chartsy-jshell's Introduction

JShell via RMI

This project provides a custom JShell execution engine that can connect to an already-running remote JVM (host) and execute code snippets in the target JVM using the Java RMI technology.

The client and the host must both have project's compiled library chartsy-jshell.jar on its classpaths. The client requires classes from the package one.chartsy.jshell on the classpath while host needs both one.chartsy.jshell and one.chartsy.jshell.host.

Technologies used

Example usage

  1. Start the host and run the following code somewhere from your codebase. The intention is to create an instance of the remotely accessible JShellLink object and binding it to the RMI registry.
int port = 52099;
JShellLink.register(new JShellLinkFacade(port), LocateRegistry.createRegistry(port), false);
  1. Launch JShell client with custom execution engine using the following command:
jshell -J-cp -J./lib/chartsy-jshell.jar --execution rmi:host(localhost),port(52099)

In the above command you may need to alter the host and port parameters to match the target JVM hostname and the port number on which the RMI registry was created.

(Un)Security

It should be obvious that disastrous things can happen when bad people gain access to your JVM instance using JShell. To prevent bad things to happen the RMI port should not be publicly accessible.

This project takes some additional security measures to prevent unauthorised access by incorporating a secret access key that must be passed from the client to the host before JShell session can be established. The host verifies if the hash of the access key provided by the client matches the hash stored on the host.

To enable this feature:

  1. On the host side start the JVM with system property chartsy.jshell.secret.hash set to the hash of the access key computed using the algorithm implemented in the PBKDF2 class. This system property can be set either on the command line or programatically, for example, by executing:
System.setProperty("chartsy.jshell.secret.hash", "22lEL0T36LRs313UEzoHg5iqwvV5rRqTzL4JfG4tbdc=");
  1. On the client side launch the JShell passing an additional secret parameter to the execution engine:
jshell -J-cp -J./lib/chartsy-jshell.jar --execution rmi:host(localhost),port(52099),secret(password123)

Known limitations

  • The host I/O is not redirected to the JShell console, thus when executing methods like System.out.println or e.printStackTrace the results are visible only in the host VM logs and not on your screen.
  • The remote runtime system flags (-Rflag) of the JShell command-line are ignored.

Disclaimer

This project comes with absolutely no warranty. Use at your own risk.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.