Create a simple HTTPS server with OPENSSL S_SERVER

This post will mostly serve as a reference for future posts, the goal is to create the simplest HTTPS webserver possible, which will serve to test certificates, authentication via private keys and in the end; configure SSL offloading to an Apache HTTPD, which will act as a proxy between your client and the secure endpoint.
GOAL: At the end of this article, you will have a running secure web server which you can access via your web browser and/or via an SSL client. Continue reading “Create a simple HTTPS server with OPENSSL S_SERVER”

Comparing sed stream output in linux

Sed is very very powerful, which is a good thing to be aware of.
I was looking to compare the output of a sed command to the original file before I wanted to execute the sed command directly on the file and came across this handy trick.
It works by using temporary named pipes inside the diff command.
Contents of file:
[code title=”contents of numbers.txt:”]
One
Two
Three
Four
Five
[/code]
If I just want to remove the line which begins with “Four”, I can check my sed command like this:
[code title=”Terminal output:”]
joris@beanie ~
$ diff <(sed ‘/Four/d’ numbers.txt) numbers.txt
3a4
> Four
[/code]
Awesome possum, now I know my sed command won’t destroy anything.

Fedora Gnome-shell abnormal high CPU usage in combination with Intel GM 4000 videocard

I’ve been using my trustworthy thinkpad for a couple of years now, but as soon as I installed Fedora on it, it became quite slow due to gnome-shell using a huge amount of CPU power.
My thinkpad isn’t the quickest out there, it’s a dual core machine from around 2006, but 50% CPU on two cores for just Gnome was a bit excessive.
I’ve been searching a lot, and didn’t found any solution, until I started fiddling with Gnome-tweak-tool and saw the “Background logo” entry.
If you haven’t yet; Install gnome-tweak-tool with the following command:
sudo yum install gnome-tweak-tool
The background logo is an PNG overlay on your desktop, and that overlay doesn’t work well with Intel GM cards.
Start gnome-tweak-tool, disable that extention and see your CPU usage drop to 2%, which is what it should be.
Selection_001

Weblogic, 1 managed server gives HTTP Error 401 Unauthorized, other works fine.

I encountered this weird behaviour last week where one managed server in a cluster of two servers constantly gave the error “HTTP Error 401 Unauthorized“.
The setup was a standard Oracle Service Bus installation on Oracle Weblogic.
The domain consisted out of one Admin server, one cluster with two managed servers.
Managed Server #1 was acting without problems but all the requests which needed authentication and which where pointed to Managed Server #2 failed and responded with a 401 Unauthorized message.
There was an error in the logs of MS#2, which is displayed at the bottom of this post as well.
#### <> <Inbound http BASIC authentication failed
javax.security.auth.login.FailedLoginException: [Security:090304]Authentication Failed: User webhosting javax.security.auth.login.FailedLoginException: [Security:090302]Authentication Failed: User webhosting denied

The solution to this problem lies in the internal LDAP configuration of the faulty Managed Server. I did not find an answer to what might have caused this problem, but the solution was to rebuild the LDAP setting of the Managed Server.
This is done by following these steps:

  1. Shut down Managed Server via Weblogic Console
  2. Log in via SSH
  3. Rename the following folder: %domain_directory%/servers/%osb_managed_server_1%/data/ldap
  4. Start the Managed Server via Weblogic Console

These steps will rebuild the LDAP folder, which is the internal LDAP to which Weblogic authenticates.
You can then remove the folder you’ve backed up in step 3.
Continue reading “Weblogic, 1 managed server gives HTTP Error 401 Unauthorized, other works fine.”

Install Oracle Java in Fedora, Red Hat or CentOS using Yum and RPM

Hi guys,
This post will outline how to install Oracle Java JDK in Fedora, Red Hat or CentOS.
Please note that this will only install the JDK, when you’re done you will need to select this JDK to be able to use it. That is outlined in this blog post: Easily switch between java versions using alternatives in Linux
First determine if you need 32 or 64 bit. If you’re unsure you can check using “uname -p” in a terminal which will display your kernel and which architecture you’re using.
Next, download the JDK that you wish to use. In this example I will be installing the latest JDK from Oracle, you can find it here: Oracle Java Downloads.
I have chosen Java Platform (JDK) 8u31, which downloads the RPM.
1612441
After the download is finished, open a terminal and go to the location of the download.
Next, enter this command:
[code gutter=”false”]
sudo yum install jdk-8u31-linux-x64.rpm
[/code]
This will install the JDK.
Important: After this is done, you have placed all the files in the right location, but can’t use it until you’ve finished the steps in this blog post: Easily switch between java versions using alternatives in Linux

Easily switch between java versions using alternatives in Linux

This approach works in several distros, I’ve been using it in Ubuntu for a while and just used it in Fedora as well.
As a developer, you might need to switch between java versions often, this approach will come in handy then.
We will be using the command “alternatives”, in this case to check the configuration of your Java installation. The default is most often OpenJDK, while you might need Oracle Java.
Run “alternatives –display java” to see which versions you can currently choose from:
[code gutter=”false”]
[joris@today ~]$ alternatives –display java
java – status is manual.
link currently points to /usr/java/latest/bin/java
Current `best’ version is /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.31-3.b13.fc21.x86_64/jre/bin/java.
[joris@today ~]$
[/code]
There’s no Oracle Java yet, make sure you’ve installed Oracle Java. If you haven’t, you can check this blog post: Install Oracle Java in Fedora, Red Hat or CentOS using Yum and RPM
When Oracle Java is installed, you can add it to your alternatives: “sudo alternatives –install /usr/bin/java java /usr/java/latest/bin/java 20000”
Please note: I used “latest” in the command above, another options is to specifically set the version you want. This way you can install several JDK’s and switch as shown below.
When that is finished, you can select your current flavour of Java:
[code gutter=”false”]
[joris@today ~]$ sudo alternatives –config java
There are 2 programs which provide ‘java’.
Selection Command
———————————————–
* 1 /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.31-3.b13.fc21.x86_64/jre/bin/java
+ 2 /usr/java/latest/bin/java
Enter to keep the current selection[+], or type selection number:
[/code]
Choose the option you want to switch between Java versions.
As mentioned by enkouyami, please check if you need to use update-java-alternatives instead of alternatives. The use of alternatives was valid when I wrote the post, but might not be working anymore!

Select an XML tag or node using Oracle PL SQL

Hi guys,
I’ve been using this trick for a while and it’s quite useful when querying Oracle Service Bus logs. I found myself trying to explain this one to a colleague and thought it made a nice post 🙂
Let’s start with the basic command:
extractvalue
Which translates into:
[code language=”sql”]
SELECT EXTRACTVALUE(
xmltype(xml_val),
‘/xml-fragment/tns:product’,
‘xmlns:tns="http://example.org/"’,
‘xmlns:ans="http://anothernamespace.org/"’,
‘xmlns:yans="http://yetanothernamespace.org/"’
)
x
FROM xml_table
[/code]
Note: the first argument is being cast from CLOB to XMLTYPE and that you can keep adding namespaces at the end by adding commas.
I’ve added three rows in my table “XML_TABLE” for this example:
[code language=”XML”]
ROW1:
<book category="WEB">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
ROW2:
<book category="CHILDREN">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
ROW3:
<book category="WEB">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
[/code]
Next we’ll query our XML_TABLE:
[code language=”sql”]
SELECT
EXTRACTVALUE( xmltype(xmlval), ‘/book/title’ ) AS title,
EXTRACTVALUE( xmltype(xmlval), ‘/book/author’ ) AS author,
EXTRACTVALUE( xmltype(xmlval), ‘/book/year’ ) AS year,
EXTRACTVALUE( xmltype(xmlval), ‘/book/price’ ) AS price
FROM xml_table;
[/code]
Which results in this output:
Workspace 1_034
Awesome, right!? 🙂
Continue reading “Select an XML tag or node using Oracle PL SQL”

Bash: Shortcuts to your favorite directories with CDPATH

This is a fairly handy trick.
I’m always logging in to different servers, which all have a different location for their logs. With this trick you can login and just type “cd logs” from anywhere.
First we will add our directory to the CDPATH variable:
[code language=”Bash”]
joris@badattitude /data/share/my_domain
$ echo $CDPATH
joris@badattitude /data/share/my_domain
$ export CDPATH=/data/share/my_domain
joris@badattitude /data/share/my_domain
$ echo $CDPATH
/data/share/my_domain
[/code]
Then we’ll check if it is working:
[code language=”Bash”]
joris@badattitude ~
$ cd logs
/data/share/my_domain/logs
joris@badattitude /data/share/my_domain/logs
$
[/code]
Awesome, we’ve arrived in our logs directory straight from our homedir!

SSH Remote Execute command, multiple command and with interaction

This article shows how to execute remote commands via ssh, but you’ll send the commands from your own shell.
[code highlight=”1″]
ssh my_server ‘ls -l /home/my_home_dir’
[/code]
This will result in this output:
[code highlight=”1″]
$ ssh ae2 ‘ls -lha ~’
total 36K
drwxr-xr-x 2 joris joris 4.0K Jan 23 11:42 .
drwxr-xr-x. 5 root root 4.0K Jan 23 11:41 ..
-rw-r–r– 1 joris joris 54 Jan 23 11:41 .bash_logout
-rw-r–r– 1 joris joris 507 Jan 23 11:41 .bash_profile
-rw-r–r– 1 joris joris 213 Jan 23 11:41 .bashrc
-rw——- 1 joris joris 51 Jan 23 11:42 .history
-rw-r–r– 1 joris joris 171 Jan 23 11:41 .kshrc
-rw-r–r– 1 joris joris 375 Jan 23 11:41 .profile
-rw-r–r– 1 joris joris 153 Jan 23 11:41 .vimrc
[/code]
What’s even better, is that you can run multiple commands separated with a semi colon, like this:
[code highlight=”1″]
ssh my_server ‘ls -l /home/my_home_dir;whoami’
[/code]
And the best trick is this one, user input with an interactive command, sending input and output back and forth!
[code highlight=”1″]
ssh -t my_server ‘vi ~/.bash_profile’
[/code]