Tuesday, November 12, 2013

Bitcoin how to export private keys

Here I will collect some smart tips regarding Bitcoin apps.

I have tried the Bitcoin wallet app on Android. It has a Export Key function that results in an encrypted file that you can backup.

To decrypt this file you need openssl and then you run this command:
openssl enc -d -aes-256-cbc -a -in <filename>

If you are using Bitcoin-qt you can see your private keys by first listing your public keys with
listreceivedbyaddress 0 true

or
bitcoind listaddressgroupings

and then you can use
dumpprivkey <publickey>

to see your private key.
The console is brought up by using
launch your bitcoin client as usual and wait for it to load the blockchain and start up
click on 'help' in the menu bar (top right)
click on 'debug window'
select the 'console' tab
type: walletpassphrase "your walletpassphrase here" 600
type: dumpprivkey [your public key here]
this will return the private key, you can copy it now; ensure you clear your clipboard/history afterwards
type: walletlock

Tuesday, July 09, 2013

Google Currents

I'm trying out Google Currents at the moment. I stumbled across it searching for a replacement to Google Reader.
So far I kind of like it. Clicking Feeds and "Add..." even allows me to add all the RSS feeds I used to have in google reader. That's pretty nice.
Unfortunately I can't watch all my feeds on one and single page. I have to check them individually.

Other than that I like the layout and stuff when reading magazines and "Breaking Stories" for each category is also a nice feature giving you a quick heads up on current news. Seems pretty useful if there would a disaster somewhere in the world or something like that.

So far I have only used the iPad and Android app. I'm looking forward to see a web based version though. 

Tuesday, May 07, 2013

Setting up Eclipse with incremental hot deploy of maven projects

After spending several hours searching the net for a good way to make Eclipse, JBoss and Maven to do Hot Deploy incrementally after saving a file and never finding any good instructions I decided to do it myself.

Here is one way to do it. It might not be the best or the most correct way, but it works (at least for me).

After writing this document I discovered "Jboss Maven Integration" plugin and tried it out.
I had problems with it. It didn't generate my wsdl java classes as specified in my pom and after this I didn't have time to look more at it.

These instructions are based on that I have an EAR project, one or more EJB projects with API projects and one or more WAR projects that I want to hot deploy. My projects are located in a Subversion directory.


These are the steps.


  1. In Eclipse, check out projects EarProject1, EjbProject1 and EjbApiProject1 and WarProject1 as New General Projects. These are all Maven projects.
  2. When the projects have been checked out, delete them in Eclipse but do not remove them from the hard drive. This is done because we are going to scrap the eclipse settings files with maven.
  3. Next we open a command prompt or a unix terminal and for each project run "mvn eclipse:clean eclipse:eclipse" and "mvn clean package". This helps us with download dependencies and set up our classpaths.
  4. Now delete the ".settings" directory in each project. This is done because we do not want Eclipse to treat this as a Maven project any more, and for some reason, if I did not delete this folder Eclipse will not allow me to add any Modules to my EAR project. The "Deployment Assembly" tab does not show in the EAR properties window.
  5. Import the projects in Eclipse as "General/Existing Projects into Workspace".
  6. Set the project Facets for all the projects
    EAR as EAR
    EJB as EJB Module and Java
    API as Java
    WAR as Dynamic Web Module and Java
  7. In the WAR project open properties and go to "Java Build Path" and make sure you don't have any Junit test folders in your "Source" tab. I ran into a problem when not doing this because the junit tests were using different config files than what should be deployed.
  8. In the WAR projects properties go to "Deployment Assembly" and replace "/WebContent" with the folder where you have your Web Application files.
    I use "/src/main/webapp" to store my "WEB-INF" and jsp, css, javascripts etc. So remove "/WebContent" and add "Folder" and choose your Web Application folder. When this is done you can delete the default "WebContent" folder in your project if your'e not using it.
  9. Also add all jars that must be included in your WAR project. Choose Add... and select "Java Build Path Entries" and select the ones needed. I could not select everyone since some of them were provided by JBoss and including them caused the application to not know which one to use. My jars are located in my M2 repo so an example of what I added was
    M2_REPO/org/apache/poi/poi/3.9/poi-3.9.jar
  10. In the WAR projects "Java Build Path" also make sure you don't have any EJB project included under "Libraries" tab that should be included under the "Projects" tab. My WAR1 project depends on my EJB1 project, so I remove the EJB1 project from "Libraries" tab and add it under the "Projects" tab instead.
  11. I didn't have to do anything with my EJB project. It worked out of the box. But if you run into problems check the following in your EJB projects properties:
    - In "Deployment Assembly" make sure you have all the folders you need included. Including any Web Service generated source folders if you have any such.
    - In "Java Build Path" make sure you have removed the possible API project or any other project you want to hot-deploy under the "Libraries" tab and add them instead under the "Projects" tab.
  12. Do the same procedure with "Deployment Assembly" and "Java Build Path" for your other EJB, WAR and API projects as well.
  13. Now it's time for the EAR project. We are going to use some of the structure that maven has built for us.
    Open Properties and go to "Deployment Assembly". If you are not using the default directory architecture that that Eclipse uses, replace the "/EarContent" entry with your directory. I do not use "EarContent" so I removed this entry and chose "Add..." - "Folder" and selected my "/target/EAR1" directory. This is the directory that maven has created for me with all modules and lib jars that the EAR project needs.
    Also add the Projects that you want to deploy in your EAR file. I choose my EJB1 and WAR1 project and, if I had one, I would also choose my API project.
    Select Apply and OK.
  14. Maven has of course included all dependencies for me in my EAR project so had to remove the .jar files from the EAR project that I want to include as Eclipse Modules. In my case I remove the following:
    /target/EAR1/WAR1.jar
    /target/EAR1/EJB1.jar
    and if you have an API project this would have been located in
    /target/EAR1/lib/API1.jar
  15. Now I can delete my "EarContent" directory in the EAR projects root since I don't use it.
    I can also delete any META-INF in the root directory since I use the one under "/target/EAR1" instead.
    I also delete the "/target/EAR1/META-INF/application.xml" file since we are going to regenerate this one.
    Next I right click on the EAR project and select "Java EE Tools/Generate Deployment Descriptor Stub". This will create a new "/target/EAR1/META-INF/application.xml" file for me with the correct Modules included.

    In Eclipse Juno you can under "Deployment Assembly" select "Advanced" and choose which folder that should be used for you Deployment Descriptor. In Eclipse Indigo it always chooses your alphabetically first folder.
  16. I also had to Rename my EAR project in Eclipse. The project is actually called MyEARProject1 but all the remote services look for the jndi appname "EAR1" and JavaEE5 uses the filename of the ear as application name.
    So I right click on the EAR project and name it EAR1 instead.
    If you are using a JavaEE6 server I guess this could be fixed by setting "application-name" in the "application.xml" instead of renaming the project.
  17. One last thing to do. Check your "${JBOSS_HOME}/server/<conf>/deploy" (Jboss6.1)directory so you don't have any of the projects that we are hot-deploying in it.
    In my case I had to remove my "EAR1.ear" from the deploy folder.
  18. Now I can add my EAR project to my Eclipse JBoss server and start it up.

Done.
If you have any questions or suggestions regarding this document, please let me know.




Wednesday, October 17, 2012

Remote debugging with Eclipse

Sometimes you can run out of memory on your local workstation when you run a JBoss server. In this case it can be useful to run the application remote on a server that has more memory available and debug it remotely with Eclipse. This is a how-to to get you started.

In this example I will use an EAR application.

Do your code changes locally and publish to your local JBoss server. Do not start the server, just publish to it.
Once you have done this copy the EAR file to the server you want to debug it on.
Publish the application as normal to the JBoss server by copying it to
${JBOSS_HOME}/server/${JBOSS_CONFIG}/deploy/.
In this case I place it here:
/apps/jboss/server/mpo/deploy/test.ear

To start JBoss in remote debug mode you can take two different approaches. The first one includes editing a file that you must remember to change back once you’re done. The second one is cleaner, but might not be supported by your JBoss setup, and includes setting an environment variable.
If you start JBoss from “/etc/init.d/[jboss-script]” you must choose the Alter file approach.
If you wish to run JBoss directly from “/apps/jboss/bin/run.sh” you can choose the Environment Variable approach.

Alter file example
If you choose or need to take this approach edit this file or the file you usually use to start JBoss:
/apps/jboss/bin/run-jboss.sh
If you don’t have a file like this you need to change the global config file. Be warned that this file is used by all JBoss instances when started so the need to change it back is even greater.
/apps/jboss/bin/run.conf

If you have “/apps/jboss/bin/run-my-jboss.sh” add a line so the file matches this look:

JAVA_OPTS="$JAVA_OPTS -Xms128m -Xmx1024m -XX:MaxPermSize=256m -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Duser.country=SE -Duser.language=sv"
JAVA_OPTS="$JAVA_OPTS -Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"
export JAVA_OPTS

If you don’t have that file do your changes to the following file.
In the end of the file “/apps/jboss/bin/run.conf” uncomment this line
#JAVA_OPTS="$JAVA_OPTS -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"
and alter it so it looks like this
JAVA_OPTS="$JAVA_OPTS -Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"

-Xdebug - Enables debugging.

-Xrunjdwp:<sub-options> - Loads the JPDA reference implementation of JDWP. This library resides in the target VM and uses JVMDI and JNI to interact with it. It uses a transport and the JDWP protocol to communicate with a separate debugger application. Specific sub-options are described below.

transport=dt_socket - Use a network socket to communicate with debugger application.

address=8787 - Use local port 8787 to communicate with debugger application

server=y - If "y", listen for a debugger application to attach; otherwise, attach to the debugger application at the specified address.

suspend=n - Do not suspend the VM before main class. This will start the server and you must attach the debugger application and set a breakpoint somewhere in the code that you will hit. If you want to debug everything from main class, set this to “y”.


Environment variable example
This approach is just like the first, but you don’t have to edit any files and thus, don’t need to remember to change the file back to it’s original. Just export the JAVA_OPTS environment variable with the above line.
JAVA_OPTS="$JAVA_OPTS -Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"
export JAVA_OPTS


Start the server
Start the server in your preferred way.

If you used Alter file approach, use
sudo /etc/init.d/run-jboss.sh start

If you used Environment Variable approach, as user jboss run
/apps/jboss/bin/run.sh


Getting through firewalls
Now it’s time to connect Eclipse debugger to the server. To do this we need to connect to port 8787 on the server and this is usually not allowed through the firewall that the server is behind. To solve this we use a tcp tunnel through ssh. To set this up in Putty.exe do the following.
Connect to the server via ssh with Putty.exe.
Once connected and logged in with your user, click the putty icon in your putty window and select “Change Settings...”. On the left side of the “Putty Reconfiguration” window expand the folders “Connection” and the subfolder “SSH” and go to “Tunnels”.
Set it up like this:


Click Add and then Apply.


Create a debug configuration in Eclipse
Now it’s time to create a new debug configuration in Eclipse to connect to your VM.
In Eclipse, select “Run” from the main menu and then select “Debug Configurations...”.
Right click “Remote Java Application” and select “New”.
Give your new configuration a name to recognize it. I’ll use “Remote Java debugger”.

In Project I choose the project that contains the code you want to put a breakpoint in. If you try to set a breakpoint in another project then what you choose here, the server will stop but it Eclipse won’t be able to map the remote class to your local code.

Connection Type should be “Standard (Socket Attach)”.

Host should be “localhost” or “127.0.0.1”.
Port should be 8787.
We use this because we will attach to our ssh tunnel that is listening on localhost for connections on port 8787. Whatever connects to 127.0.0.1:8787 will be sent to the server that ssh is connected and the port 8787 on that server.

I choose NOT to “Allow termination of remote VM”. If you do choose this you can kill the VM on the remote server by hitting the “Terminate” button in Eclipse. It’s up to you, but I prefer to stop the VM manually on my own through ssh.

Click “Apply” and “Debug”.
You’re done now.
Set a breakpoint somewhere in you code and surf to the webserver as usual. Once your VM on the remote server hits your breakpoint it stops and Eclipse.