Today one of my virtual servers suddenly showed up as offline in my New Relic console (Which is an amazing tool and free by the way).
I checked the log file /var/log/newrelic/nrsysmond.log and it had these contents:
2015-08-15 02:06:04.512 (915) error: nria_context_create(): SIGAR_OK != status; goto error; status=13
2015-08-15 02:06:04.512 (915) error: nria_context_create(): in error label
2015-08-15 02:06:04.512 (915) error: failed to create sampling context
2015-08-15 02:06:04.512 (913) info: worker process exited with 1 – NOT restarting
I found a post on the New Relic forum which provided the solution:
-> Run the newrelic service as root
This can be done by editing /etc/sysconfig/newrelic-sysmond and uncommenting the option RUNAS:
# User to run the Server Monitor as
Not a perfect solution since ideally this should run with the newrelic user but at least it got the server online on my console again.
Chiefly, I learned two things:
- The .gwt.rpc files are only used by the server. The client never reads them.
- The .gwt.rpc files are generated in the ProxyCreator class.
I have listed some further classes and links below.
GWT Framework Classes
ProxyCreator: Creates the .gwt.rpc file
RemoteServiceProxy: Manages calls to services
ClientSerializationStreamWriter: Write serialization on client for server
ClientSerializationStreamReader: Read responses from server on client
Serializer: Interface for serialization contract for class
The GWT RPC Wire Protocol
For this I need to load code generated in GWT into a Nashorn engine.
This is not very easy since the load process of GWT libraries includes various ‘hacks’ which involve the DOM.
I don’t know yet how I am going to do this exactly. I found the gwt-node project. This project is meant to run GWT code on Node.js.
I think by working with the custom linker developed there (GwtNodeLinker.java) I might be able work something out.
The JVM is by design an insecure environment and it is generally difficult to run untrusted code in a sandboxed environment.
UPDATE I have implemented two little libraries which takes care of the grunt work of sandboxing Nashorn and Rhino code in Java:
Nashorn Sandbox (on GitHub)
Rhino Sandbox (on Github)
Restricting Script Access to Specified Java Classes: From the Oracle Nashorn docs. Shows how to restrict access to specific Java classes.
Class ContextFactory: Useful for monitoring and setting restrictions on Rhino code.
Method initSafeStandardObjects: Useful for creating sandboxed Rhino code.
Sandboxing Rhino in Java: Blog post
Securing Rhino in Java6: Blog post
Example Code Monitoring Threads: Example code how thread CPU usage can be monitored.
The Java Sandbox: A library for sandboxing any Java code. Might be useful to sandbox the Java code with runs the script.
It seems to me like every time I have to do something that has to do with SSL certificates – be they self-signed or signed by a certificate authority – things do not go smoothly. I only do this from time to time, so I am by no means an expert; but I do believe my difficulties result to some degree from the intrinsic complexities within SSL and the systems which support it.
I have created another guide which walks step by step through the process of configuring a Java key store with a signed SSL certificate. If you do want this to succeed, note that you have to follow every step precisely. Even minor omissions can lead to errors (believe me, I’ve tried it myself).
- Download Portecle (from here) and Unzip it
- Start portecle.jar by double clicking it
- Go to File / New Keystore
- Select JKS and click [OK]
- Go to Tools / Generate Key Pair
- Select Algorithm RSA and Key size 2048
- Increase validity from the default 356 to 1000 or more days
- In Common Name provide the domain or subdomain of the domain you want to protect
- Provide some input for all other fields – do not leave any empty
- Provide a password and remember it (This can be the same password as for the the whole store)
- Provide an alias – best the name of your domain
- You should see the following:
- Right click the key pair you have create and select ‘Generate Certification Request’
- Portecle will generate file ‘XYZ.csr‘ for you.
- Provide the contents of this file to the SSL provider of your choice (see a brief comparison here – I’ve had good experiences with RapidSSL certificates from GoGetSSL).
- Your SSL provider should supply you with an SSL certificate. This file should end with ‘.crt‘. Download it.
- Go back to Portecle and right click your key pair again. Select ‘Import CA Reply’.
- Import the .crt file you got from your SSL provider.
- If this does not work, first proceed to import the certificates as listed in the next steps, then try again to import the CA Reply.
- You can import the ROOT certificate of your SSL provider just in case.
- Also, your SSL provider will supply you with an intermediate and server certificate. You can import these into your keystore as well.
- Note that when importing the ROOT certificate of your provider, you might get a warning that no trust chain can be established to the certificate. However, when importing the intermediate and server certificates AFTER importing the root certificate, there should be no warning that no chain can be established.
- Your keystore should look something like this now:
- Now go to File / Save Keystore
- Provide the same password you used before.
Now you can use the created key store in Java servers. For an easy way how to use a keystore with Java, check out step 7 in this post.