<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Gerbrand on ICT &#187; security</title>
	<atom:link href="http://www.gerbrand-ict.nl/tag/security/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gerbrand-ict.nl</link>
	<description>Weblog on JEE and software-engineering</description>
	<lastBuildDate>Wed, 11 Aug 2010 20:51:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Proxying authentication using JBoss</title>
		<link>http://www.gerbrand-ict.nl/2010/06/proxying-authentication-using-jboss/</link>
		<comments>http://www.gerbrand-ict.nl/2010/06/proxying-authentication-using-jboss/#comments</comments>
		<pubDate>Mon, 21 Jun 2010 23:00:19 +0000</pubDate>
		<dc:creator>gerbrand</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jboss]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.gerbrand-ict.nl/?p=264</guid>
		<description><![CDATA[Wouldn&#8217;t it be nice if the connection to the database is done using the same username as the username used to login to a (JEE) application? Oracle has a solution for that: proxy authentication.  When using proxy authentication, every application user is also a database user: meaning when someone logins to your JEE webapplication using [...]]]></description>
			<content:encoded><![CDATA[<p>Wouldn&#8217;t it be nice if the connection to the database is done using the same username as the username used to login to a (JEE) application? Oracle has a solution for that: <a href="http://download.oracle.com/docs/cd/B28359_01/java.111/b31224/proxya.htm">proxy authentication</a>.  When using proxy authentication, every application user is also a database user: meaning when someone logins to your JEE webapplication using username john, he&#8217;ll also access the database as user john. This way all actions of the user are logged at the database-level: an administrator or auditer can see exactly what data a certain user modified or accessed during a JEE session.</p>
<p><span id="more-264"></span></p>
<p>Also, this allows for fine-grained security at database level: <a href="http://www.oracle.com/technology/deploy/security/database-security-10g/virtual-private-database/index.html">Virtual Private Database</a>.</p>
<div id="attachment_297" class="wp-caption alignnone" style="width: 466px"><a href="http://www.oracle.com/technology/deploy/security/database-security-10g/virtual-private-database/index.html"><img class="size-full wp-image-297" title="virtual-private-database1" src="http://www.gerbrand-ict.nl/wp-content/uploads/2009/06/virtual-private-database1.gif" alt="Virtual private database" width="456" height="175" /></a><p class="wp-caption-text">(c) Oracle</p></div>
<p>As described in the above image and referenced article, the user identified by userid 106 (let&#8217;s say that&#8217;s user john) will access the database using a private database connection. The user can only access rows that have that userid as primary or foreign key.  John can&#8217;t see the passwords, orders, credit card data or anything of other users even if he would somehow hack the webapplication. How to set up this finegrained securiy is beyond this article, but I hope the above example explains what the purpose VPD is.</p>
<p>If you develop your JEE software using Oracle software  proxy authentication requires only a bit of configuration, for example, see the following article how to setup proxy authentication using <a href="http://blogs.oracle.com/jheadstart/2008/01/28/">JHeadstart</a>.</p>
<p>However, what if you&#8217;re JEE applicication consists of non-oracle software? Can you still use proxy authentication when you use software like JBoss, Hibernate, IBatis, MyFaces, Wicket etc? Yes you can! I&#8217;ll explain below how to set up proxy authentication using JBoss in such a way you don&#8217;t have to modify any of the code that uses JDBC, directly or indirectly.</p>
<ul>
<li>First a way is needed to set a username for each (JDBC) database connection retrieved. <a href="http://www.it-eye.nl/weblog/2005/09/12/oracle-proxy-users-by-example/">It-eye weblog</a> explains how to open a connection to a database using java, and then switch to another username.</li>
<li>Secondly, in your application users should authenticate them self using the default mechanism of J2EE 1.4 (and higher) application, using <a href="http://java.sun.com/javase/technologies/security/">JAAS</a>. Usually creating a security policy inside your web.xml or inside your ear is enough. Here&#8217;s the information how to do this under JBoss: <a href="http://www.jboss.org/community/wiki/SecureAWebApplicationUsingACustomForm">Secure a webapplication</a>.<br />
Since we&#8217;re using a database, the best option would be to use database based authentication, meaning user information comes out of a database table. There&#8217;s a lot of documentation on the web how to do add security, so I won&#8217;t repeat that here.</li>
<li>Database connection in JBoss are retrieved using connection pooling, as is custom in any JEE server.  You can create a custom connection pool, that changes the switches to the user name that is currently logged in at the webapplication. That way, every action on the database is done under a database user that is currently logged in.Do to be able to do that, first, you&#8217;ll need a custom connection factory that extends the default connection factory. Our connection factory will return a customized datasource that modifies code.Here&#8217;s a code listing:
<pre class="brush: java;">package nl.gerbrandict.dbconnaudit;

import java.sql.SQLException;
import javax.resource.ResourceException;
import javax.resource.spi.ConnectionManager;

import org.apache.log4j.Logger;
import org.apache.commons.lang.StringUtils;
import org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory;

/**
 * An extended connection factory, that uses the Oracle feature to change the username of an existing connection
 *

 * When a user authenticated on the application server, the database connection will switch to that username.
 * This allows for better auditing and potentially for improved security.
 *
 * Properties (get'ers and set'ters) can be set via the configuration section of the -ds file
 * @author gvdieijen
 */
public class DBConnAuditConnectionFactory extends LocalManagedConnectionFactory {

    private String defaultProxyUser;

    public DBConnAuditConnectionFactory() throws SQLException {
        super();

    }

    @Override
    public Object createConnectionFactory(ConnectionManager cm) throws ResourceException {
        return new OracleWrapperDataSource(this, cm);
    }

    public void setEnableProxySession(Boolean enableProxySession) {
        this.enableDbConnAudit = enableProxySession;
    }

    public void setDefaultProxyUser(final String defaultProxyUser) {
        if (StringUtils.isEmpty(defaultProxyUser)) {
            this.defaultProxyUser=null;
        } else {
             this.defaultProxyUser = defaultProxyUser;
        }
    }

    /**
     * Default db user to open proxy session for, when no authenticated user is active
     * @return
     */
    public String getDefaultProxyUser() {
    	return this.defaultProxyUser;
    }
}</pre>
<p>As you can see, the file returns a OracleWrapperDatasource. That&#8217;s custom class, that extends the default WrapperDatasource of JBoss, and changes the user of jdbc connection just before the connection is handed of to the application. To speak in terms of the fine book</li>
<li>Now, How can you use that new class? They have to be packed into a rar file. Functionally, that&#8217;s a Resource Adapter, a module that allows a J2EE application to use resources. Technically (and practically), it&#8217;s just a jar-archive similar to a war, with a different extension. Maven can create these files automatically for you, if you set the packaging type to rar instead of jar (which is the default).</li>
<li>When you download JBoss, you&#8217;ll get a sample connection pool for a in-memory database: default-ds.xml, located in the server/default/deploy directory of jboss. To use the custom classses, copy the file into (for example) myoracleproxy-ds.xml and create a minor modification so a custom connection factory is used &#8211; update the managedconnectionfactory property, that a custom connectionfactory is used, that returns the proxied connections:
<pre class="brush: xml;">&lt;managedconnectionfactory-class&gt;nl.gerbrandict.dbconnaudit.DBConnAuditConnectionFactory&lt;/managedconnectionfactory-class&gt;</pre>
</li>
</ul>
<p>All in all, after some tweaking, all queries and updates to your Oracle database are done under the J2EE username. This means when user Joe logs in, all his database access will be logged under user Joe as well. This can improve auditing as well as security.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gerbrand-ict.nl/2010/06/proxying-authentication-using-jboss/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Breaking SMS security</title>
		<link>http://www.gerbrand-ict.nl/2009/05/breaking-sms-security/</link>
		<comments>http://www.gerbrand-ict.nl/2009/05/breaking-sms-security/#comments</comments>
		<pubDate>Fri, 22 May 2009 12:53:25 +0000</pubDate>
		<dc:creator>gerbrand</dc:creator>
				<category><![CDATA[Various]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://www.gerbrand-ict.nl/?p=291</guid>
		<description><![CDATA[I wrote some time ago about false sense of security in many secure applications such as internet-banking. Now one of the predictions I made have become reality, as you can read on this (Dutch) article on webwereld: Onderzoekers kapen tan-code met Nokia 1100. Using a hacked mobile phone, a security company could intercept a TAN-code [...]]]></description>
			<content:encoded><![CDATA[<p>I wrote some time ago about <a href="http://www.gerbrand-ict.nl/wp-admin/post.php?action=edit&amp;post=121">false sense of security</a> in many secure applications such as internet-banking. Now one of the predictions I made have become reality, as you can read on this (Dutch) article on webwereld: <a href="http://webwereld.nl/nieuws/58572/onderzoekers-kapen-tan-code-met-nokia-1100.html">Onderzoekers kapen tan-code met Nokia 1100</a>.<br />
Using a hacked mobile phone, a security company could intercept a TAN-code that is used to authorize payments and money-transfers using internet-banking. Although there is no reported use of this hack, researchers did notice second-hand mobile phones did increase a lot in value.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gerbrand-ict.nl/2009/05/breaking-sms-security/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>False sense of security in https</title>
		<link>http://www.gerbrand-ict.nl/2009/03/false-sense-of-security-in-https/</link>
		<comments>http://www.gerbrand-ict.nl/2009/03/false-sense-of-security-in-https/#comments</comments>
		<pubDate>Sun, 15 Mar 2009 14:09:16 +0000</pubDate>
		<dc:creator>gerbrand</dc:creator>
				<category><![CDATA[Various]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://www.gerbrand-ict.nl/?p=121</guid>
		<description><![CDATA[Like most Internet users, I use https a lot. Whenever I login to a, say, my bank, Firefox shows a nice picture of the bank and a message the communication is secured and authorized. Should for any reason the communication between my computer and the bank being intercepted, I should get a security warning. That [...]]]></description>
			<content:encoded><![CDATA[<p>Like most Internet users, I use https a lot. Whenever I login to a, say, my bank, Firefox shows a nice picture of the bank and a message the communication is secured and authorized. Should for any reason the communication between my computer and the bank being intercepted, I should get a security warning. That way I should be assured, I am communication with the bank and not with a <a href="http://www.xs4all.nl/veiligheid/phishing/">phishing </a>site.<br />
<img class="alignnone size-full wp-image-125" title="https-example1" src="http://www.gerbrand-ict.nl/wp-content/uploads/2009/03/https-example1.jpg" alt="https-example1" width="543" height="110" /></p>
<p>Few people realize even when you make certain you don&#8217;t ignore any security warnings there&#8217;s still a chance the communication is compromised: when the computer you&#8217;re using is itself compromised by, for example, a sophisticated virus.</p>
<p>A sophisticated computer virus or hacker could install software on the computer that changes both the DNS settings of the computer and changes the root-certificates of the browser.<br />
DNS is used by your own computer to &#8216;know&#8217; what particular ip-address and server it should communicate to.  The computer asks the DNS-server of your provider (like XS4all, AOL) to translate www.myexample.com to an address like 192.168.33.55. A popular metaphor for DNS is the &#8216;yellow pages&#8217; or &#8216;telephone directory&#8217;.<br />
The address of the DNS server itself are usually set by you&#8217;re provider, but a virus or hacker could change them. That way, you could be redirected to a physing site, even if webbrowsers should www.myexample.com.</p>
<p>Far fetched? A few months ago there was a virus that would <a href="http://www.f-secure.com/v-descs/dnschang.shtml">change dns-settings</a> on the computer that it infected. The virus was infecting the computers in the students-flat I lived a few year ago. <a href="http://support.microsoft.com/kb/827315">Microsoft </a>has a page on the same subject too and I found a <a href="http://forums.whatthetech.com/Hijack_Logs_Unable_change_DNS_servers_t97718.html">few</a> <a href="http://www.technologyquestions.com/technology/889548-post4.html">forum </a>postings.</p>
<p>If the DNS settings are changed only, you would still get a https warning when you login to site that&#8217;s secured using https. However, what if a hacker of virus would also take over your browser and change the root-certicates? A bit harde, but certainly not impossible. That way, the webrowser will display no security warning, eventhough you&#8217;re communicating with a con site.</p>
<p>Fortunately, all banks in the Netherlands still require an extern device while doing any money transfers, payments or other sensitive operations. <a href="http://www.rabobank.nl/particulieren/">Rabobank </a>uses requires a <a href="http://www.rabobank.nl/particulieren/servicemenu/toegankelijkheid/moeite_met_zien/random_reader_comfort/">Random Reader</a> that generates a number you have to enter manually, <a href="http://www.ing.nl/particulier/">ING (formerly postbank)</a> requires you to enter a number you receive at your <a href="http://www.ing.nl/zakelijk/klantenservice/veelgestelde-vragen/internetbankieren/internetbankieren/tan-codes/algemeen/index.aspx?faquri=tcm:7-21922">mobile phone</a>.<br />
The random reader doesn&#8217;t have any external interface (you have to enter the data manually) so hacking that device is virtually impossible. The only way would be breaking into someone&#8217;s house and replacing it with your own random reader.<br />
As said ING requires you to enter a number you receive via you&#8217;re cell-phone. A modern cell-phone or mobile-phone is connected to the internet, and installing software is possible on many modern phones. That way, a mobile phone <em>could </em>be compromised. Using a sophisticated combination of a hacked computer and a hacked mobile phone, a hacker could get someone to transfer money to his own bank account. Hard, but not entirely impossible.</p>
<p>Final word, I mention two banks in the above example. My article however, is not limited to banking sites, but to any site that uses https or https in combination with sms-verification using a cell-phone.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gerbrand-ict.nl/2009/03/false-sense-of-security-in-https/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
