<?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>Ian Bull &#8211; EclipseSource</title>
	<atom:link href="https://eclipsesource.com/blogs/author/irbull/feed/?category=syndicate" rel="self" type="application/rss+xml" />
	<link>https://eclipsesource.com</link>
	<description>Technology creators at your service</description>
	<lastBuildDate>Thu, 19 Apr 2018 13:41:54 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.9.5</generator>

<image>
	<url>https://eclipsesource.com/wp-content/uploads/2017/03/cropped-es-logo-square-32x32.png</url>
	<title>Ian Bull &#8211; EclipseSource</title>
	<link>https://eclipsesource.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Authenticating Reverse Proxy with KeyCloak</title>
		<link>https://eclipsesource.com/blogs/2018/01/11/authenticating-reverse-proxy-with-keycloak/</link>
		<comments>https://eclipsesource.com/blogs/2018/01/11/authenticating-reverse-proxy-with-keycloak/#comments</comments>
		<pubDate>Thu, 11 Jan 2018 23:49:01 +0000</pubDate>
		<dc:creator><![CDATA[Ian Bull]]></dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[devops]]></category>
		<category><![CDATA[keycloak]]></category>
		<category><![CDATA[nginx]]></category>

		<guid isPermaLink="false">https://eclipsesource.com/?p=37801</guid>
		<description><![CDATA[Authentication &#038; user management is hard Ok, it&#8217;s not one of the two hardest problems in Computer Science, but adding authentication...]]></description>
				<content:encoded><![CDATA[<h1>Authentication &#038; user management is hard</h1>
<p>Ok, it&#8217;s not one of the <a href="https://martinfowler.com/bliki/TwoHardThings.html">two hardest problems in Computer Science</a>, but adding authentication to your web-based application is non-trivial. In addition to the security concerns involved, you are also required to maintain account information, registration, and identity management, which most users are tired of. Nobody wants <strong>Y</strong>et <strong>A</strong>nother <strong>P</strong>assword <strong>T</strong>o <strong>R</strong>emember (YAPTR).</p>
<p>Of course, most of you will point to OAuth and OpenID. You&#8217;ll correctly point out that we should leverage the users existing identities.</p>
<p>This is great, but what if you have a simple static site or download server that you want to protect? Should we build a full web-application just to integrate OAuth?</p>
<p>The easiest answer is, of course, simple <tt>.htaccess</tt> files to protect these sites &#8212; which brings us back to the identity management problem. <em>Can&#8217;t anything be simple?</em></p>
<p>Of course it can! Enter the <strong>Authenticating Reverse Proxy</strong> and <strong>Keycloak</strong>. An authenticating reverse proxy sits in front of your site, and only allows traffic through if it has been authenticated.</p>
<p><a href="http://www.keycloak.org/">Keycloak</a> is an Open Source Identity and Access Management solution. Combing these two technologies gives you an easy mechanism to add authentication to any web-based application.</p>
<h2>Keycloak</h2>
<p><a href="http://www.keycloak.org/about.html">Keycloak is an open source Identity and Access Management solution</a>. It makes it easy to secure applications and services with little to no code. Keycloak handles user identities, user federation, identity brokering and social login.</p>
<p>Users authenticate with Keycloak, rather than with individual services. This means that each service you provide doesn&#8217;t have to manage users. Once a user signs-on with Keycloak, they don&#8217;t need to authenticate again to access other services.</p>
<p><img class="aligncenter wp-image-37804" src="https://eclipsesource.com/wp-content/uploads/2018/01/screen-login.png" alt="" width="500" height="223" srcset="https://eclipsesource.com/wp-content/uploads/2018/01/screen-login.png 638w, https://eclipsesource.com/wp-content/uploads/2018/01/screen-login-300x134.png 300w" sizes="(max-width: 500px) 100vw, 500px" /></p>
<p>In addition to providing the infrastructure required for Single Sign-On (SSO), Keycloak also provides an advanced admin UI, so you can easily manage your users without complicated CLIs or manually editing configuration files.</p>
<p>Through identity brokering and social login, users can login to your Keycloak service with their existing identities (such as Google, Facebook, GitHub, etc&#8230;). Through user federation, Keycloack can be integrated with existing LDAP or Active Directory servers. You can even implement your own provider if you have an existing relational database, for example.</p>
<p><img class="aligncenter size-full wp-image-37802" src="https://eclipsesource.com/wp-content/uploads/2018/01/dia-identity-brokering.png" alt="" width="437" height="250" srcset="https://eclipsesource.com/wp-content/uploads/2018/01/dia-identity-brokering.png 437w, https://eclipsesource.com/wp-content/uploads/2018/01/dia-identity-brokering-300x172.png 300w" sizes="(max-width: 437px) 100vw, 437px" /></p>
<p>In addition to user management, Keycloak can also act as an authentication endpoint. Keycloak implements many standard protocols such as OAuth2 and OpenID Connect. Several client adapters are also available, so integrating your existing services (such as a local Jenkins instance), or a custom service (such as a Java application) is easy.</p>
<p>Finally, Keycloak supports UI theming, so you can easily roll out a highly customized authentication portal as unique as you are. If you need authentication in your application or organization, take a look at <a href="http://www.keycloak.org/">Keycloak</a>.</p>
<p><img class="aligncenter wp-image-37805" src="https://eclipsesource.com/wp-content/uploads/2018/01/login-sunrise.png" alt="" width="500" height="230" srcset="https://eclipsesource.com/wp-content/uploads/2018/01/login-sunrise.png 977w, https://eclipsesource.com/wp-content/uploads/2018/01/login-sunrise-300x138.png 300w, https://eclipsesource.com/wp-content/uploads/2018/01/login-sunrise-768x353.png 768w" sizes="(max-width: 500px) 100vw, 500px" /></p>
<h2>Authenticating Reverse Proxy</h2>
<p>A <strong><a href="https://en.wikipedia.org/wiki/Reverse_proxy">reverse proxy</a> </strong>is a type of proxy server that retrieves resources on behalf of a client from one or more servers. The resources from these servers are returned to the client as if they originate from the Web server itself.</p>
<p><img class="aligncenter size-full wp-image-37807" src="https://eclipsesource.com/wp-content/uploads/2018/01/560px-Reverse_proxy_h2g2bob.svg_.png" alt="" width="560" height="210" srcset="https://eclipsesource.com/wp-content/uploads/2018/01/560px-Reverse_proxy_h2g2bob.svg_.png 560w, https://eclipsesource.com/wp-content/uploads/2018/01/560px-Reverse_proxy_h2g2bob.svg_-300x113.png 300w" sizes="(max-width: 560px) 100vw, 560px" /></p>
<p>An <strong>authenticating reverse proxy </strong>is a reverse proxy that only retrieves the resources on behalf of a client if the client has been authenticated. If a client is not authenticated they can be redirected to a login page.</p>
<p>By structuring your system this way, you can put all your sensitive material on the internal web server, and protect everything through an authenticating reverse proxy. For even more security, the internal web server could be placed on a private Virtual Private Cloud, with absolutely no access from the outside, except through the proxy.</p>
<h2>Lua-Resty-OpenIDC</h2>
<p>To integrate Keycloak and an Authenticating Reverse Proxy, we used <a href="https://github.com/zmartzone/lua-resty-openidc"><tt>lua-resty-openidc</tt></a>.  Lua Resty OpenIDC is a library for <a href="http://openresty.org/">OpenResty</a>, a web-server based on Nginx. OpenResty describes itself as a web platform that integrates the standard Nginx core, LuaJIT and many Lua libraries and high-quality 3rd-party Nginx modules.</p>
<p>It is designed to help developers easily build scalable web applications, web services, and dynamic web gateways. Lua Resty OpenIDC implements the <a href="http://openid.net/specs/openid-connect-core-1_0.html" rel="nofollow">OpenID Connect</a> <strong>Relying Party (RP)</strong> and the <a href="https://tools.ietf.org/html/rfc6749" rel="nofollow">OAuth 2.0</a> <strong>Resource Server (RS)</strong> functionality.</p>
<p>To help you get started, I&#8217;ve created a simple Dockerfile that can be used to build a container with OpenResty, <tt>lua-resty-openidc</tt> and the required dependencies.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="docker">FROM openresty/openresty:alpine-fat

RUN mkdir /var/log/nginx

RUN apk add --no-cache openssl-dev
RUN apk add --no-cache git
RUN apk add --no-cache gcc
RUN luarocks install lua-resty-openidc

ENTRYPOINT ["/usr/local/openresty/nginx/sbin/nginx", "-g", "daemon off;"]
</pre>
<p>Build a docker container using this <tt>Dockerfile</tt> using:<br />
<tt>docker build -t authproxy .<br />
</tt>This will create a container called <tt>authproxy</tt>. You can start this proxy will an appropriate Nginx configuration. I used the following Nginx configuration file to configure <tt>lua-resty-openidc</tt> to integrate with Keycloak.</p>
<pre class="EnlighterJSRAW" data-enlighter-title="nginx.conf">worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
   lua_package_path '/usr/local/openresty/lualib/?.lua;;';
   resolver 8.8.8.8;
   include /etc/nginx/conf.d/*.conf;

   # cache for discovery metadata documents
   lua_shared_dict discovery 1m;
   # cache for JWKs
   lua_shared_dict jwks 1m;

   index   index.html index.htm;

   server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        root         /usr/share/nginx/html;

        access_by_lua '
          local opts = {
            redirect_uri_path = "/",
            discovery = "https://keycloak_server/auth/realms/master/.well-known/openid-configuration",
            client_id = "clientID",
            client_secret = "clientSecret",
            redirect_uri_scheme = "https",
            logout_path = "/logout",
            redirect_after_logout_uri = "https://keycloak_server/auth/realms/master/protocol/openid-connect/logout?redirect_uri=http%3A%2F%2Fianbull.com",
            redirect_after_logout_with_id_token_hint = false,
            session_contents = {id_token=true}
          }
          -- call introspect for OAuth 2.0 Bearer Access Token validation
          local res, err = require("resty.openidc").authenticate(opts)

          if err then
            ngx.status = 403
            ngx.say(err)
            ngx.exit(ngx.HTTP_FORBIDDEN)
          end
       ';

       # I disbled caching so the browser won't cache the site.
       expires           0;
       add_header        Cache-Control private;

       location / {
       }

       # redirect server error pages to the static page /40x.html
       #
       error_page 404 /404.html;
           location = /40x.html {
       }
       # redirect server error pages to the static page /50x.html
       #
       error_page 500 502 503 504 /50x.html;
           location = /50x.html {
       }
   }
}
</pre>
<p>You can now start your docker container, and volume mount the directory containing this configuration file. I put it in my current directory and used the following command to start the container. I also mounted the current directory under <tt>/usr/share/nginx/html</tt> so any html files in the current directory will be hosted behind the authenticating proxy. Finally, I mapped port 80 on the host to port 80 in the container.</p>
<p><tt>docker run -d -it -p 80:80 -v $PWD/:/config -v /:/usr/share/nginx/html authproxy -c /config/nginx.conf<tt></tt></tt></p>
<h2>Conclusion</h2>
<p>Protecting a site using an authenticating reverse proxy is very easy with Keycloak. Keycloak provides you with all the identity and access management tools you need, and the <tt>lua-resty-openidc</tt> library can be used to configure the proxy.</p>
<p>For more information about the tools and technologies we use internally at EclipseSource, follow me on <a href="https://twitter.com/irbull">twitter</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://eclipsesource.com/blogs/2018/01/11/authenticating-reverse-proxy-with-keycloak/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Securing your Mobile JavaScript Applications</title>
		<link>https://eclipsesource.com/blogs/2017/07/07/securing-your-mobile-javascript-applications/</link>
		<comments>https://eclipsesource.com/blogs/2017/07/07/securing-your-mobile-javascript-applications/#comments</comments>
		<pubDate>Fri, 07 Jul 2017 03:47:13 +0000</pubDate>
		<dc:creator><![CDATA[Ian Bull]]></dc:creator>
				<category><![CDATA[EclipseSource News]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[j2v8]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[tabris.js]]></category>

		<guid isPermaLink="false">https://eclipsesource.com/?p=34363</guid>
		<description><![CDATA[JavaScript has been used as a client side language for over 20 years and as a server side language for close...]]></description>
				<content:encoded><![CDATA[<p>JavaScript has been used as a client side language for over 20 years and as a server side language for close to 10. In the past 3 years, JavaScript has emerged as a language of choice for mobile app developers, especially those looking for a cross-platform solution. Technology stacks such as <a href="https://facebook.github.io/react-native/">React Native</a> and <a href="https://tabrisjs.com">Tabris.js</a> are the obvious choices, but some engineers are rolling their own runtimes with tools such as <a href="https://github.com/eclipsesource/j2v8">J2V8</a>.</p>
<p>As more organizations migrate towards JavaScript on Mobile, JavaScript security is becoming a top priority. At EclipseSource, we have been building JavaScript based mobile apps for customers in the fields of health care and financial services. In this post, we will highlight some of the security concerns we uncovered when using JavaScript on Mobile and discuss how to mitigate them.</p>
<p><img class="aligncenter wp-image-34455" src="https://eclipsesource.com/wp-content/uploads/2017/06/lock-1024x633.jpg" alt="" width="500" height="309" srcset="https://eclipsesource.com/wp-content/uploads/2017/06/lock-1024x633.jpg 1024w, https://eclipsesource.com/wp-content/uploads/2017/06/lock-300x185.jpg 300w, https://eclipsesource.com/wp-content/uploads/2017/06/lock-768x474.jpg 768w" sizes="(max-width: 500px) 100vw, 500px" /></p>
<h2>Repackaging Protection</h2>
<p>One attack that is difficult to protect against involves someone taking your application, decompiling it, changing it, and re-publishing it to the app stores. The attacker then tries to get users to install their <em>modified </em>version instead of your official one. A well crafted app will still behave like the original so the user has no idea they are using a version that has been tampered with.</p>
<p>To protect against this, you can perform a check at runtime to see if the code you are executing matches your signing key. On Android, you can check the fingerprint of the signing certificate using <tt>activity.getPackageManager().getPackageInfo().signatures</tt>. Of course, if someone decompiled your source code, it will be trivial to change this logic. To address this, you can either compile this logic directly into your JavaScript engine, which as a native library will be harder to break; or you can embed this logic into your JavaScript, and ship encrypted &#038; obfuscated JavaScript.</p>
<h2>JavaScript Code Obfuscation &#038; Encryption</h2>
<p>Shipping JavaScript based mobile apps often means shipping your JavaScript in plain text to all your users. Even without decompiling your source code, an attacker can often find your JavaScript embedded directly in your packaged app. Anybody with simple editor can inspect your source code to get insights into your application and search for security vulnerabilities. Minified JavaScript can help a bit, but will only slow down an attacker. A better approach is to <a href="https://eclipsesource.com/de/blogs/2017/01/17/tutorial-aes-encryption-and-decryption-with-openssl/">obfuscate your code using an AES key</a> and use that same key at runtime to decrypt the JavaScript as it&#8217;s executed. The AES key can either be encrypted and embedded directly in the binary or it can be negotiated with a server and passed at runtime.</p>
<p>Of course, in the end, the code must be decrypted as it&#8217;s executed. If someone dumps the memory of your app while it&#8217;s running, they may find the JavaScript there. If you are going to obfuscate your code, you should still perform code signing &#038; verification to make sure nobody has tampered with it.</p>
<h2>JavaScript Code Signing &#038; Verification</h2>
<p><a href="https://eclipsesource.com/blogs/2016/09/07/tutorial-code-signing-and-verification-with-openssl/">Code signing and verification</a> is a mechanism used to ensure that the code being executed has not been tampered with. When code is authored, a fingerprint is computed and that fingerprint is <em>signed </em>with a <strong>private key</strong>. At execution time, the same fingerprint is computed and the matching <strong>public key</strong> is used to verify that the signature matches. If the signature matches, then the code can be executed, otherwise the code is rejected with a <em>security exception</em>.</p>
<p>Like the AES key, the public key can either be embedded in the application or negotiated at runtime. Public keys are considered safe to distribute, but if someone does have the public key, they could substitute it for their own. Obfuscating and embedding the key directly in the JavaScript engine makes this attack harder. Furthermore, if the APK itself has been signed, then an attacker won&#8217;t be able to simply change the binary.</p>
<p>We suggest performing JavaScript code signing &#038; verification as a minimum for all JavaScript based apps. This means that you must sign and verify not only your own source code, but all your dependencies too.</p>
<h2>Root Detection</h2>
<p>Finally, most attack vectors require root access to a users device. With root access, an attacker can install alternate VMs or manipulate the Java code running on a Android device using reflection. By disabling the JavaScript engine from running on a rooted phone, these attacks become harder. This can be viewed as an extreme measure, but it helps protect highly sensitive data from being exposed in a potentially hostile environment.</p>
<p>However, disabling apps on rooted phones is also a double-edge sword. Some people root their phones to install security patches, and in some cases rooted phones may actually be more secure than stock installs. If you are going to perform root detection, think about your target audience and if this security measure actually makes sense for your app.</p>
<h2>Summary</h2>
<p>As JavaScript grows and starts to play a more prominent role in the financial and health services, security requirements are becoming a top priority. Because JavaScript is an interpreted language, the source code often ships in plain text to all your clients&#8217; devices. However, there are several measures you can take to address the risks, such as re-packaging protection, code obfuscation &#038; encryption, code signing &#038; verification and root detection. Embedding these checks directly in the JavaScript engine, and halting all execution if those checks fail, can help mitigate the security risks associated with JavaScript on Mobile.</p>
<p>If you are interested in learning more about mobile security and to hear about how we manage this with <a href="https://tabrisjs.com">Tabris.js</a> and <a href="https://github.com/eclipsesource/j2v8">J2V8</a>, please <a href="https://eclipsesource.com/tabris/contact-us/">get in touch</a>. For more information on J2V8 and JavaScript security, follow me on <a href="https://twitter.com/irbull">Twitter</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://eclipsesource.com/blogs/2017/07/07/securing-your-mobile-javascript-applications/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Tabris.js 2.0 – Top 10 Features: Binary Fetch</title>
		<link>https://eclipsesource.com/blogs/2017/07/06/tabris-js-2-0-top-10-features-binary-fetch/</link>
		<comments>https://eclipsesource.com/blogs/2017/07/06/tabris-js-2-0-top-10-features-binary-fetch/#respond</comments>
		<pubDate>Thu, 06 Jul 2017 04:31:27 +0000</pubDate>
		<dc:creator><![CDATA[Ian Bull]]></dc:creator>
				<category><![CDATA[EclipseSource News]]></category>
		<category><![CDATA[tabris.js]]></category>
		<category><![CDATA[Tabris.js 2]]></category>

		<guid isPermaLink="false">https://eclipsesource.com/?p=34681</guid>
		<description><![CDATA[In preparation for the Tabris.js 2.0 release, we started counting down the 10 features of Tabris.js 2.0 that we&#8217;re most excited...]]></description>
				<content:encoded><![CDATA[<p>In preparation for the <a href="https://tabrisjs.com">Tabris.js 2.0</a> release, we started counting down the 10 features of Tabris.js 2.0 <a href="https://eclipsesource.com/blogs/2017/07/05/simplified-api/">that</a> <a href="https://eclipsesource.com/blogs/2017/07/03/tabris-js-2-0-top-10-features-statusbar-and-navigationbar/">we&#8217;re</a> <a href="https://eclipsesource.com/blogs/2017/06/28/tabris-cli/">most</a> <a href="https://eclipsesource.com/blogs/2017/06/29/tabris-js-2-0-top-10-features-security/">excited</a> <a href="https://eclipsesource.com/blogs/2017/06/26/tabris-js-2-0-top-10-features-navigationview/">about</a>. We reached the halfway point, which means that the release is almost here and we have 4 features left to go. Feature Number 6: <strong>Binary Fetch</strong> is a pretty exciting technical feature, especially for me because it required the implementation of <a href="https://eclipsesource.com/blogs/2016/07/25/typedarrays-sharing-memory-between-v8-and-java/">shared memory regions in J2V8</a>; but first, what is Binary Fetch.</p>
<p><a href="https://en.wikipedia.org/wiki/XMLHttpRequest">XHR</a> and <a href="https://fetch.spec.whatwg.org/">Fetch</a> are two standards for retrieving data from a URL. With Tabris.js 1 you could only fetch text-based data through this API, but now you can fetch both text and binary data. The binary data is returned as an ArrayBuffer and can be manipulated in place. On Android, this means that the ArrayBuffer is shared between the underlying V8 instance and the Tabris.js runtime; so no excess data copying is performed.</p>
<p>For example, with binary fetch, you could fetch images from a remote URL and apply different filters before displaying them in an image view.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="javascript" data-enlighter-linenumbers="false">function loadData() {
  fetch('https://tabrisjs.com/assets/public-content/img/iphone-cropped-small.png')
    .then(response => checkStatus(response) && response.arrayBuffer())
    .then(buffer => {
       new PNG({ filterType:4 }).parse( buffer, function(error, data) {
         var options = {  colorType: 0 }
         var out = PNG.sync.write(data, options);
           let base64Encoded =  _arrayBufferToBase64(out);
           imageView.image = { src:'data:image/png;base64,' + base64Encoded};
       });
      return buffer;
    })
    .catch(err => console.error(err)); // Never forget the final catch!
}
</pre>
<p>In this example, we load a PNG as an array buffer, and process the buffer to make it greyscale. You of course could apply all sorts of filters. For those interested, I used <a href="https://www.npmjs.com/package/pngjs">pngjs</a> to process the image.</p>
<p><img class="aligncenter wp-image-34689" src="https://eclipsesource.com/wp-content/uploads/2017/07/binary-fetch-image.png" alt="" width="300" height="520" srcset="https://eclipsesource.com/wp-content/uploads/2017/07/binary-fetch-image.png 684w, https://eclipsesource.com/wp-content/uploads/2017/07/binary-fetch-image-173x300.png 173w, https://eclipsesource.com/wp-content/uploads/2017/07/binary-fetch-image-591x1024.png 591w" sizes="(max-width: 300px) 100vw, 300px" /></p>
<p>The entire snippet is available <a href="https://gist.github.com/irbull/42f3bd7a9db767ce72a770ded9a5bdd1">here</a>.</p>
<p>We are just putting the final touches on Tabris.js 2.0 and it will be publicly available on July 18th. Follow us on <a href="https://twitter.com/tabrisjs">Twitter</a> for all the latest Tabris.js news.</p>
<h2>Tabris.js 2.0 &#8211; Top 10 Features</h2>
<p>The binary fetch() is just one of the cool new additions to Tabris.js 2. Don&#8217;t forget to check out the other top 10 features in the rundown below.</p>
<ol>
<li><a href="https://eclipsesource.com/blogs/2017/07/17/tabris-js-2-0-top-10-features-typescript-jsx/">TypeScript &#038; JSX</a></li>
<li><a href="https://eclipsesource.com/blogs/2017/07/14/tabris-js-2-0-top-10-features-windows-10-support">Windows 10 Support</a></li>
<li><a href="https://eclipsesource.com/blogs/2017/07/12/tabris-js-2-0-top-10-features-filesystem/">File system access</a></li>
<li><a href="https://eclipsesource.com/blogs/2017/07/10/tabris-js-2-0-top-10-features-alertdialog/">AlertDialog</a></li>
<li><a href="https://eclipsesource.com/blogs/2017/07/06/tabris-js-2-0-top-10-features-binary-fetch/">Binary fetch()</a></li>
<li><a href="https://eclipsesource.com/blogs/2017/07/05/simplified-api/">Simplified event and properties API</a></li>
<li><a href="https://eclipsesource.com/blogs/2017/07/03/tabris-js-2-0-top-10-features-statusbar-and-navigationbar/">StatusBar and NavigationBar</a></li>
<li><a href="https://eclipsesource.com/blogs/2017/06/28/tabris-cli/">Tabris CLI</a></li>
<li><a href="https://eclipsesource.com/blogs/2017/06/29/tabris-js-2-0-top-10-features-security/">Security</a></li>
<li><a href="https://eclipsesource.com/blogs/2017/06/26/tabris-js-2-0-top-10-features-navigationview/">NavigationView</a></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>https://eclipsesource.com/blogs/2017/07/06/tabris-js-2-0-top-10-features-binary-fetch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tabris.js 2.0 – Top 10 Features: Security</title>
		<link>https://eclipsesource.com/blogs/2017/06/29/tabris-js-2-0-top-10-features-security/</link>
		<comments>https://eclipsesource.com/blogs/2017/06/29/tabris-js-2-0-top-10-features-security/#respond</comments>
		<pubDate>Thu, 29 Jun 2017 21:10:35 +0000</pubDate>
		<dc:creator><![CDATA[Ian Bull]]></dc:creator>
				<category><![CDATA[EclipseSource News]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[tabris.js]]></category>
		<category><![CDATA[Tabris.js 2]]></category>

		<guid isPermaLink="false">https://eclipsesource.com/?p=34352</guid>
		<description><![CDATA[After over a year of development, Tabris.js 2.0 is almost here. To help celebrate this, the Tabris.js development team is counting...]]></description>
				<content:encoded><![CDATA[<p>After over a year of development, <a href="https://tabrisjs.com">Tabris.js 2.0</a> is almost here. To help celebrate this, the Tabris.js development team is counting down <a href="https://eclipsesource.com/blogs/2017/06/28/tabris-cli/">some of the features</a> <a href="https://eclipsesource.com/blogs/2017/06/26/tabris-js-2-0-top-10-features-navigationview/">we&#8217;re most excited about</a>.</p>
<p>Over the past year, I&#8217;ve had the opporuntity to focus on Tabris.js security related work such as certificate pinning, code signing, code obfuscation, and other security enhancements.</p>
<h2>Certificate Pinning</h2>
<p>When an <a href="http://sudhakar.online/programming/2015/08/09/https.html">SSL connection is first made</a>, the server typically sends its certificate to the client. The client checks to ensure that the certificate is signed by an authority it trusts, and uses that to determine if it can <strong>trust </strong>the server. While this is typically safe, there have been exploits in the past where a false certificate were accepted, and the client ended up trusting an invalid host.</p>
<p>To mitigate this, most security experts advise the use of <strong>certificate pinning</strong>. With certificate pinning, the client stores the fingerprint of the certificate, and checks that the fingerprint matches before continuing with the secure communication. As an aside, this is how SSH works, and if someone tries to spoof the server, you&#8217;ll see this error.</p>
<p><img class="aligncenter wp-image-34354" src="https://eclipsesource.com/wp-content/uploads/2017/06/Screen-Shot-2017-06-26-at-2.21.10-PM-1024x665.png" alt="" width="500" height="325" srcset="https://eclipsesource.com/wp-content/uploads/2017/06/Screen-Shot-2017-06-26-at-2.21.10-PM-1024x665.png 1024w, https://eclipsesource.com/wp-content/uploads/2017/06/Screen-Shot-2017-06-26-at-2.21.10-PM-300x195.png 300w, https://eclipsesource.com/wp-content/uploads/2017/06/Screen-Shot-2017-06-26-at-2.21.10-PM-768x499.png 768w" sizes="(max-width: 500px) 100vw, 500px" /></p>
<p>For more information, checkout <a href="http://owasp.org">OWASP&#8217;s</a> article about <a href="https://www.owasp.org/index.php/Certificate_and_Public_Key_Pinning">certificate pinning</a>.</p>
<p>Tabris.js 2.0 now supports certificate pinning for XHR/Fetch, WebSockets, Image loading and App Patching. Use the <tt>app</tt> object and assigned a list of trusted certificates to the <tt>pinnedCertificates</tt> property.</p>
<pre lang="">const {app} = require('tabris');

app.pinnedCertificates = [{host: 'freegeoip.net', hash: 'sha256/+SVYjThgePRQxQ0e8bWTQDRtPYR/xBRufqyMoeaWteo=', algorithm: 'ECDSA256'}];
</pre>
<p>If an invalid certificate is used, any connection to the server (<a href="https://freegeoip.net">freegeoip.net</a> in this case) will fail. Checkout out docs for <a href="https://tabrisjs.com/tabris-js-docs/latest/api/app.html#pinnedcertificates" rel="nofollow">more information on this API</a>.</p>
<h2>Enterprise Security Enhancements</h2>
<p>In addition to certificate pinning, which is available directly in Tabris.js 2.0, we have also implemented several Tabris.js enterprise modules. Tabris.js has been used successfully to build high quality banking apps for Android and iOS. Due to the nature of these apps, a number of Tabris.js security add-ons have been developed. For example, certificate pinning is only effective if the fingerprint is secure. To enforce this, we have introduced Javascript code signing &#038; fingerprint checking as well as Javascript code obfuscation &#038; script encryption. These can be included as Tabris.js enterprise modules. We also have tools to protect against running Tabris.js apps on rooted phones and native re-packaging protection built right into our Javascript engine. <a href="https://eclipsesource.com/tabris/contact-us/">Contact us for more information on how we can help you protect your mobile applications</a>.</p>
<p>With an improved API, new widgets and more platforms, Tabris.js 2.0 will be the best Tabris.js release yet; and with the security features we&#8217;ve added, it will be the most secure. Make sure to check back next week as we continue our countdown, or follow us on <a href="https://twitter.com/tabrisjs">Twitter</a>.</p>
<h2>Tabris.js 2.0 &#8211; Top 10 Features</h2>
<p>The improved security is just one of the cool new additions to Tabris.js 2. Don&#8217;t forget to check out the other top 10 features in the rundown below.</p>
<ol>
<li><a href="https://eclipsesource.com/blogs/2017/07/17/tabris-js-2-0-top-10-features-typescript-jsx/">TypeScript &#038; JSX</a></li>
<li><a href="https://eclipsesource.com/blogs/2017/07/14/tabris-js-2-0-top-10-features-windows-10-support">Windows 10 Support</a></li>
<li><a href="https://eclipsesource.com/blogs/2017/07/12/tabris-js-2-0-top-10-features-filesystem/">File system access</a></li>
<li><a href="https://eclipsesource.com/blogs/2017/07/10/tabris-js-2-0-top-10-features-alertdialog/">AlertDialog</a></li>
<li><a href="https://eclipsesource.com/blogs/2017/07/06/tabris-js-2-0-top-10-features-binary-fetch/">Binary fetch()</a></li>
<li><a href="https://eclipsesource.com/blogs/2017/07/05/simplified-api/">Simplified event and properties API</a></li>
<li><a href="https://eclipsesource.com/blogs/2017/07/03/tabris-js-2-0-top-10-features-statusbar-and-navigationbar/">StatusBar and NavigationBar</a></li>
<li><a href="https://eclipsesource.com/blogs/2017/06/28/tabris-cli/">Tabris CLI</a></li>
<li><a href="https://eclipsesource.com/blogs/2017/06/29/tabris-js-2-0-top-10-features-security/">Security</a></li>
<li><a href="https://eclipsesource.com/blogs/2017/06/26/tabris-js-2-0-top-10-features-navigationview/">NavigationView</a></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>https://eclipsesource.com/blogs/2017/06/29/tabris-js-2-0-top-10-features-security/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tutorial: AES Encryption and Decryption with OpenSSL</title>
		<link>https://eclipsesource.com/blogs/2017/01/17/tutorial-aes-encryption-and-decryption-with-openssl/</link>
		<comments>https://eclipsesource.com/blogs/2017/01/17/tutorial-aes-encryption-and-decryption-with-openssl/#comments</comments>
		<pubDate>Tue, 17 Jan 2017 21:10:57 +0000</pubDate>
		<dc:creator><![CDATA[Ian Bull]]></dc:creator>
				<category><![CDATA[EclipseSource News]]></category>
		<category><![CDATA[openssl]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://eclipsesource.com/blogs/?p=27583</guid>
		<description><![CDATA[AES (Advanced Encryption Standard) is a symmetric-key encryption algorithm. Symmetric-key algorithms are algorithms for cryptography that use the same cryptographic keys...]]></description>
				<content:encoded><![CDATA[<p>AES (<a href="https://en.wikipedia.org/wiki/Advanced_Encryption_Standard">Advanced Encryption Standard</a>) is a symmetric-key encryption algorithm. Symmetric-key algorithms are algorithms for cryptography that use the same cryptographic keys for both encryption of plaintext and decryption of ciphertext. In this tutorial we will demonstrate how to encrypt plaintext using the OpenSSL command line and decrypt the cipher using the OpenSSL C++ API.</p>
<p>The cryptographic keys used for AES are usually fixed-length (for example, 128 or 256bit keys). Because humans cannot easily remember long random strings, <a href="https://en.wikipedia.org/wiki/Key_stretching">key stretching</a> is performed to create a long, fixed-length key from a short, variable length password. Key stretching uses a key-derivation function. Command line OpenSSL uses a rather simplistic method for computing the cryptographic key from a password, which we will need to mimic using the C++ API. OpenSSL uses a hash of the password and a random 64bit salt. Only a single iteration is performed.</p>
<h1>Encrypting: OpenSSL Command Line</h1>
<p>To encrypt a plaintext using AES with OpenSSL, the <tt>enc</tt> command is used. The following command will prompt you for a password, encrypt a file called plaintext.txt and Base64 encode the output. The output will be written to standard out (the console). SHA1 will be used as the key-derivation function. We will use the password <tt>12345</tt> in this example.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="shell">$ openssl enc -aes-256-cbc -in plaintext.txt -base64 -md sha1</pre>
<p>This will result in a different output each time it is run. This is because a different (random) salt is used. The <em>Salt</em> is written as part of the output, and we will read it back in the next section.</p>
<h1>Decrypting: OpenSSL API</h1>
<p>To decrypt the output of an AES encryption (aes-256-cbc) we will use the OpenSSL C++ API. Unlike the command line, each step must be explicitly performed with the API. There are four steps involved when decrypting: 1) Decoding the input (from Base64), 2) extracting the <em>Salt</em>, 3) creating the key (key-stretching) using the password and the <em>Salt</em>, and 4) performing the AES decryption.</p>
<h2>Base64 Decoding</h2>
<p>When the plaintext was encrypted, we specified <tt>-base64</tt>. This resulted in a Base64 encoding of the output which is important if you wish to process the cipher with a text editor or read it into a string. Before decryption can be performed, the output must be decoded from its Base64 representation. We use the same decoding algorithm that we used in our previous <a href="http://eclipsesource.com/blogs/2016/09/07/tutorial-code-signing-and-verification-with-openssl/">OpenSSL Tutorial</a>:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="cpp">size_t calcDecodeLength(char* b64input) {
  size_t len = strlen(b64input), padding = 0;

  if (b64input[len-1] == '=' && b64input[len-2] == '=') //last two chars are =
    padding = 2;
  else if (b64input[len-1] == '=') //last char is =
    padding = 1;
  return (len*3)/4 - padding;
}

void Base64Decode( char* b64message, unsigned char** buffer, size_t* length) {
  BIO *bio, *b64;

  int decodeLen = calcDecodeLength(b64message);
  *buffer = (unsigned char*)malloc(decodeLen + 1);
  (*buffer)[decodeLen] = '\0';

  bio = BIO_new_mem_buf(b64message, -1);
  b64 = BIO_new(BIO_f_base64());
  bio = BIO_push(b64, bio);

  *length = BIO_read(bio, *buffer, strlen(b64message));
  BIO_free_all(bio);
}</pre>
<p>&nbsp;</p>
<p>Again, special thanks to <a href="http://doctrina.org/Base64-With-OpenSSL-C-API.html">Barry Steyn</a> for providing this.</p>
<h2>Extracting the Salt</h2>
<p>Once we have decoded the cipher, we can read the salt. The <em>Salt</em> is identified by the 8 byte header (<tt>Salted__</tt>), followed by the 8 byte salt. We start by ensuring the header exists, and then we extract the following 8 bytes:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c">unsigned char* ciphertext = ...; // Decoded cipher text
size_t cipher_len = ...; // Length of decoded cipher text, computed during Base64Decode
if (strncmp((const char*)ciphertext,"Salted__",8) == 0) {
  memcpy(salt,&ciphertext[8],8);
  ciphertext += 16;
  cipher_len -= 16;
}</pre>
<p>We then move the ciphertext pointer 16 character into the string, and reduce the length of the cipher text by 16.</p>
<h2>Computing the Key and Initialization Vector</h2>
<p>Once we have extracted the salt, we can use the salt and password to generate the Key and Initialization Vector (IV). To determine the Key and IV from the password (and key-derivation function) use the <tt>EVP_BytesToKey</tt> function:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c">void initAES(const string& pass, unsigned char* salt, unsigned char* key, unsigned char* iv )
{
  bzero(key,sizeof(key));
  bzero(iv,sizeof(iv));
  EVP_BytesToKey(EVP_aes_256_cbc(), EVP_sha1(), salt, (unsigned char*)pass.c_str(), pass.length(), 1, key, iv);
}</pre>
<p>&nbsp;</p>
<p>This initially zeros out the Key and IV, and then uses the <tt>EVP_BytesToKey</tt> to populate these two data structures. In this case we are using <tt>Sha1</tt> as the key-derivation function and the same password used when we encrypted the plaintext. We use a single iteration (the 6th parameter).</p>
<h2>Decrypting the Cipher</h2>
<p>With the Key and IV computed, and the cipher decoded from Base64, we are now ready to decrypt the message. To decrypt the message we need a buffer in which to store it. Since the cipher text is always <a href="http://stackoverflow.com/questions/5727646/what-is-the-length-parameter-of-aes-evp-decrypt">greater (or equal to) the length of the plaintext</a>, we can allocate a buffer with the same length as the ciphertext. OpenSSL will tell us exactly how much data it wrote to that buffer.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c">string decrypt(unsigned char *ciphertext, 
               int ciphertext_len, 
               unsigned char *key,
               unsigned char *iv ) {

  EVP_CIPHER_CTX *ctx;
  unsigned char *plaintexts;
  int len;
  int plaintext_len;
  unsigned char* plaintext = new unsigned char[ciphertext_len];
  bzero(plaintext,ciphertext_len);

  /* Create and initialise the context */
  if(!(ctx = EVP_CIPHER_CTX_new())) handleOpenSSLErrors();

  /* Initialise the decryption operation. IMPORTANT - ensure you use a key
   * and IV size appropriate for your cipher
   * In this example we are using 256 bit AES (i.e. a 256 bit key). The
   * IV size for *most* modes is the same as the block size. For AES this
   * is 128 bits */
  if(1 != EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, key, iv))
    handleOpenSSLErrors();

  EVP_CIPHER_CTX_set_key_length(ctx, EVP_MAX_KEY_LENGTH);

  /* Provide the message to be decrypted, and obtain the plaintext output.
   * EVP_DecryptUpdate can be called multiple times if necessary
   */
  if(1 != EVP_DecryptUpdate(ctx, plaintext, &len, ciphertext, ciphertext_len))
    handleOpenSSLErrors();

  plaintext_len = len;

  /* Finalize the decryption. Further plaintext bytes may be written at
   * this stage.
   */
  int pad_len;
  if(1 != EVP_DecryptFinal_ex(ctx, plaintext + len, &len)) handleOpenSSLErrors();
  plaintext_len += len;

  /* Add the null terminator */
  plaintext[plaintext_len] = 0;

  /* Clean up */
  EVP_CIPHER_CTX_free(ctx);
  string ret = (char*)plaintext;
  delete [] plaintext;
  return ret;
}</pre>
<p>We begin by initializing the Decryption with the AES algorithm, Key and IV. We then pass the <tt>EVP_DecryptUpdate</tt> function the ciphertext, a buffer for the plaintext and a pointer to the length. This will perform the decryption and can be called several times if you wish to decrypt the cipher in blocks. Finally, calling <tt>EVP_DecryptFinal_ex</tt> will complete the decryption. We null terminate the plaintext buffer at the end of the input and return the result.</p>
<h1>Conclusion</h1>
<p>In this tutorial we demonstrated how to encrypt a message using the OpenSSL command line and then how to decrypt the message using the OpenSSL C++ API. The API required a bit more work as we had to manually decode the cipher, extract the salt, compute the Key and perform the decryption. A complete copy of the code for this tutorial can be found <a href="https://gist.github.com/irbull/c76a8c60e049a9fcba1116aa81771253">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://eclipsesource.com/blogs/2017/01/17/tutorial-aes-encryption-and-decryption-with-openssl/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>YubiKey &#8212; Code signing with a smart card</title>
		<link>https://eclipsesource.com/blogs/2016/11/25/yubikey-code-signing-with-a-smart-card/</link>
		<pubDate>Fri, 25 Nov 2016 07:23:02 +0000</pubDate>
		<dc:creator><![CDATA[Ian Bull]]></dc:creator>
				<category><![CDATA[EclipseSource News]]></category>

		<guid isPermaLink="false">http://eclipsesource.com/blogs/?p=27445</guid>
		<description><![CDATA[Code signing and verification is the process of digitally signing executables or scripts to ensure that the software you are executing...]]></description>
				<content:encoded><![CDATA[<p>Code signing and verification is the process of digitally signing executables or scripts to ensure that the software you are executing has not been altered since it was signed. I previously outlined how to <a href="http://eclipsesource.com/blogs/2016/09/07/tutorial-code-signing-and-verification-with-openssl/">perform code signing and verification with OpenSSL</a>, using both the command line and OpenSSL API.</p>
<p>While the tutorial explained how to create an RSA KeyPair, it didn&#8217;t mention anything about protecting the Keys; in particular, protecting the private key. If the private key is ever compromised, someone could change your source code and re-sign it. This would make it appear as though you authored the changes. A great tool for securing private keys is PIV-Compliant Smart Card such as the <a href="https://www.yubico.com/products/yubikey-hardware/">YubiKey 4 or YubiKey Neo</a>. The YubiKey is often used as a Universal Second Factor Authentication Device (U2F), but these devices provide much more functionality. The PIV slot on the Yubikey is a Write-Only slot, meaning you can store a private key on the device but you cannot read it back. You can however use the PIV applet on the device to produce a digital signature using the stored key.</p>
<p>In this extended tutorial we will look at how to create a digital signature with a YubiKey 4 and verify it with OpenSSL.</p>
<div id="attachment_27458" style="width: 510px" class="wp-caption aligncenter"><a href="http://eclipsesource.com/blogs/2016/11/25/yubikey-code-signing-with-a-smart-card/yubikey-4-keychain-and-yubikey-4-nano/" rel="attachment wp-att-27458"><img class="size-full wp-image-27458" src="https://eclipsesource.com/wp-content/uploads/2016/11/YubiKey-4-keychain-and-YubiKey-4-Nano.png" alt="By Yubico - Own work, CC BY-SA 4.0, https://commons.wikimedia.org/w/index.php?curid=52063469" width="500" height="365" srcset="https://eclipsesource.com/wp-content/uploads/2016/11/YubiKey-4-keychain-and-YubiKey-4-Nano.png 500w, https://eclipsesource.com/wp-content/uploads/2016/11/YubiKey-4-keychain-and-YubiKey-4-Nano-300x219.png 300w" sizes="(max-width: 500px) 100vw, 500px" /></a><p class="wp-caption-text">By Yubico &#8211; Own work, CC BY-SA 4.0, https://commons.wikimedia.org/w/index.php?curid=52063469</p></div>
<h1>Introducing the YubiKey</h1>
<p>A <a href="https://www.yubico.com/"><strong>YubiKey</strong></a> is a small hardware device primarily intended to provide second factor authentication. It supports a number of two factor authentication protocols, including One-Time Passwords, Challenge-Response and FIDO-U2F &#8212; a new standard being jointly developed by Yubico, Google and several other members of the <a href="https://fidoalliance.org/">Fido Alliance</a>. In addition to Two-Factory Authentication, the YubiKey has several other <em>slots</em>. The card can be used to <a href="https://developers.yubico.com/PGP/">store PGP Private Keys</a>, emit a static password and even act as a <a href="https://developers.yubico.com/PIV/">personal identity verification (PIV) card</a>.</p>
<p>PIV cards have a number of <a href="https://developers.yubico.com/PIV/Introduction/Certificate_slots.html">certificate slots</a>, which can be used for a variety of tasks such as signing, encryption, decryption and verification (among other things). It is these slots, and in particular the <strong>Certificate for Digital Signatures,</strong> that can be used for code signing.</p>
<h1>Configuring your YubiKey</h1>
<p>RSA keys can be generated on the YubiKey or generated elsewhere and imported. The former is much more secure since the private key never needs to be stored on a computer and since the YubiKey is <em>write-only</em> it can <strong>never be exported</strong>. This means that the only way someone could access your private key is if they stole your physical device. The YubiKey can also be protected with a PIN, so even if someone stole your key, they still couldn&#8217;t use it (after 3 false PIN attempts, the card will <em>lock</em> itself).</p>
<p>Before you begin, there are a number of useful tools to help you manage the PIV functionality of your YubiKey.</p>
<ul>
<li><a href="https://developers.yubico.com/yubico-piv-tool/">YubiKey-PIV-Tool</a></li>
<li><a href="https://developers.yubico.com/yubikey-piv-manager/">YubiKey-PIV-Manager</a></li>
<li><a href="https://github.com/OpenSC/OpenSC/wiki/Download-latest-OpenSC-stable-release">OpenSC</a></li>
</ul>
<p>The first two downloads will help you manage the device itself (set the PIN, generate the keys, etc&#8230;). The first download is a command line tool while the second one provides the functionality via a graphical interface. The 3rd download (OpenSC) provides several tools for working with open smart card standards. These tools provide the signing / encryption functionality. In particular, these tools provide PCKS#11 and PCKS#15, a standard platform-independent API to cryptographic tokens.</p>
<p>You should begin by changing the default PIN and PUK. When you first launch the PIV-Manager it will prompt you to do this. Once configured, you can now generate a public / private key pair. We will generate the pair on slot 9c (Digital Signature).</p>
<p><a href="http://eclipsesource.com/blogs/2016/11/25/yubikey-code-signing-with-a-smart-card/screen-shot-2016-11-24-at-10-09-22-pm/" rel="attachment wp-att-27448"><img class="aligncenter wp-image-27448" src="https://eclipsesource.com/wp-content/uploads/2016/11/Screen-Shot-2016-11-24-at-10.09.22-PM.png" alt="screen-shot-2016-11-24-at-10-09-22-pm" width="500" height="243" /></a></p>
<p>You can now export the certificate and extract the public key or use the <tt>pkcs15-tool</tt> to directly dump the public key:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="shell">$ pkcs15-tool  --read-public-key 02
Using reader with a card: Yubico Yubikey 4 OTP+U2F+CCID
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmnqmPLS3XFlUXgxTAF2/
6GGO9rW9DzbMmqOvAXWsL9Mn66qRZOKX4xfm0jM2p6FBqyvfMvnJto8d6XPHyDz/
VhXBqd9940hnHhZQE4DTioA7nyx4E+EdpLjHbLF2jwZZh325JO1CPTIdQhLK7pIt
m1xCSX5Wvb/3JSfBz7B8baJio3tBD9+aLnqW9deKAiuJOsoFr+NcBEZ98JNXRav1
Xu1Ac6cG3hzOaOaNLM2yq1yDBEFBvz4GXjQIR5lvn8dOFCjsSZ2MYzD3EP85DOop
z45rAnUwJ1JKt7HNNQpyd8GwdlWygqfFmjJ/zl/7src720398Llb+3XzOfsj7NKR
1QIDAQAB
-----END PUBLIC KEY-----</pre>
<h1>Signing with the YubiKey</h1>
<p>When signing documents, you typically sign a <em>hash</em> of the document. This is no different with a YubiKey. In fact, you must first produce the hash and then instruct the key to produce the signature. OpenSSL can be used to produce a hash a follows:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="shell">openssl dgst -sha256 -binary plaintext.txt  > plaintext.txt.sha256</pre>
<p>This uses the SHA-256 hash function to produce a 256 bit value from the document. The YubiKey can now sign this value. Since the private key cannot be read from the card, an applet on the card performs the signing. The applet can be invoked with <tt>pkcs15-crypt</tt>. As an added layer of security, the card will prompt you for your PIN (If you enter the PIN incorrectly 3 times, the card will lock).</p>
<pre class="EnlighterJSRAW" data-enlighter-language="shell">$ pkcs15-crypt -s -i plaintext.txt.sha256 -o signed.output -f openssl --sha-256 --pkcs1 -k 02
Using reader with a card: Yubico Yubikey 4 OTP+U2F+CCID
Enter PIN [PIV Card Holder pin]:</pre>
<p>When the signing command finishes, the signature will be written to <tt>signed.output</tt>. The other arguments are used to specify the input (<tt>plaintext.txt.sha254</tt>), instruct the card to output the data in OpenSSL format, and that the SHA-256 hash function was used. Finally, <tt>-k 02</tt> specifies slot 02 (also known as 9c, where the key was stored).</p>
<h1>Verifying the Signature</h1>
<p>To verify the signature, you only need the public key, signature and the original text, which we exported earlier. This is exactly the same as the previous tutorial. Since we used SHA-256 to produce the hash, we must specify that when verifying the signature.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="shell">$ openssl dgst -sha256 -verify mykey.pub  -signature signed.output plaintext.txt
Verified OK</pre>
<p>Over the next few weeks I&#8217;ll be writing about other uses of the YubiKey, especially for cryptography. Follow me on <a href="https://twitter.com/irbull">Twitter</a> for updates.</p>
]]></content:encoded>
			</item>
		<item>
		<title>Tabris.js Windows 10 Beta Program</title>
		<link>https://eclipsesource.com/blogs/2016/11/03/tabris-js-windows-10-beta-program/</link>
		<pubDate>Thu, 03 Nov 2016 09:52:46 +0000</pubDate>
		<dc:creator><![CDATA[Ian Bull]]></dc:creator>
				<category><![CDATA[EclipseSource News]]></category>
		<category><![CDATA[tabris.js]]></category>
		<category><![CDATA[windows 10]]></category>

		<guid isPermaLink="false">http://eclipsesource.com/blogs/?p=27339</guid>
		<description><![CDATA[Tabris.js is a cross platform mobile toolkit that enables application developers to target multiple platforms from a single JavaScript code base....]]></description>
				<content:encoded><![CDATA[<p><a href="http://tabrisjs.com">Tabris.js</a> is a cross platform mobile toolkit that enables application developers to target multiple platforms from a single JavaScript code base. Unlike some other cross-platform toolkits, Tabris.js does not rely on WebViews, but instead produces native applications. This is achieved by providing a cross-platform API in JavaScript and linking that API to the platform specific widgets. Additionally, Tabris.js also includes a build service. This service enables our users to easily produce mobile apps (<tt>apks</tt> and <tt>ipas</tt>) by simply linking their GitHub repository to the service.</p>
<p>Tabris.js initially targeted Android and iOS devices. <a href="http://eclipsesource.com/blogs/2016/03/29/announcement-windows-10-support-coming-to-tabris-js/">Earlier this year we announced our plans to support Windows 10</a>, and we are happy to announce that this support is now here. This means that you can now build and deliver Tabris.js applications that target the Microsoft Surface, Windows Phone and even Windows 10 desktop devices, as well as iOS and Android. We have released our first application for all these platforms &#8212; <a href="http://eclipsesource.com/blogs/2016/10/22/download-the-eclipsecon-europe-2016-app/">the EclipseCon Europe 2016 Conference app</a>. The application is now available in all three mobile stores.</p>
<div style="width: 100%; margin-bottom: 1.5em;"><img style="float: left; height: 50px; margin: 0 20px 0 0;" src="https://eclipsesource.com/wp-content/uploads/2015/02/appstore.png" alt="appstore" /> <img style="float: left; height: 50px; margin: 0 20px 0 0;" src="https://eclipsesource.com/wp-content/uploads/2015/02/playstore.png" alt="playstore" /><a href="https://www.microsoft.com/en-us/store/p/eclipsecon-europe-2016/9nblggh42xtx#"><img style="height: 50px; margin: 0 20px 0 0;" src="https://assets.windowsphone.com/8d997df3-5b6e-496c-88b3-e3f40117c8fd/English-get-it-from-MS_InvariantCulture_Default.png" srcset="https://assets.windowsphone.com/0100c7e5-1455-40bc-a351-b77d2801ad5a/English_get-it-from-MS_InvariantCulture_Default.png 2x" alt="Get it from Microsoft" /></a></div>
<p><a href="https://eclipsesource.com/wp-content/uploads/2016/10/EclipseCon-Europe-Windows-app.png" rel="attachment wp-att-27340"><img class="alignleft wp-image-27356" src="https://eclipsesource.com/wp-content/uploads/2016/10/EclipseCon-Europe-Windows-app.png" width="280" height="540" style="margin-right:15px;" /></a>Access to the Windows 10 build service will be rolled out over the next few months. If you would like to join our beta program, please sign-up below.</p>
<div style="float:left;">
<!-- Begin MailChimp Signup Form -->
<link href="//cdn-images.mailchimp.com/embedcode/classic-10_7.css" rel="stylesheet" type="text/css">
<style type="text/css">
	#mc_embed_signup{background:none; font:14px Helvetica,Arial,sans-serif;  width:235px;}
	/* Add your own MailChimp form style overrides in your site stylesheet or in this style block.
	   We recommend moving this block and the preceding CSS link to the HEAD of your HTML file. */
</style>
<div id="mc_embed_signup">
<form action="//eclipsesource.us5.list-manage.com/subscribe/post?u=065d3aa18628538c3d2953067&#038;id=de3e5a2a45" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
<div id="mc_embed_signup_scroll">
<h2>Subscribe to Tabris.js mailing list</h2>
<div class="indicates-required"><span class="asterisk">*</span> indicates required</div>
<div class="mc-field-group">
	<label for="mce-EMAIL">Email Address  <span class="asterisk">*</span><br />
</label><input type="email" value="" name="EMAIL" class="required email" id="mce-EMAIL">
</div>
<div class="mc-field-group">
	<label for="mce-NAME">Name </label><input type="text" value="" name="NAME" class="" id="mce-NAME">
</div>
<div class="mc-field-group input-group"><strong>I want to be notified about: </strong></p>
<ul>
<li><input type="checkbox" value="1" name="group[1][1]" id="mce-group[1]-1-0"><label for="mce-group[1]-1-0">Windows build service beta</label></li>
</ul>
</div>
<div id="mce-responses" class="clear">
<div class="response" id="mce-error-response" style="display:none"></div>
<div class="response" id="mce-success-response" style="display:none"></div></div>
<p>    <!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups--></p>
<div style="position: absolute; left: -5000px;" aria-hidden="true"><input type="text" name="b_065d3aa18628538c3d2953067_de3e5a2a45" tabindex="-1" value=""></div>
<div class="clear"><input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="button"></div></div>
</form>
</div>
<p><script type='text/javascript' src='//s3.amazonaws.com/downloads.mailchimp.com/js/mc-validate.js'></script><script type='text/javascript'>(function($) {window.fnames = new Array(); window.ftypes = new Array();fnames[0]='EMAIL';ftypes[0]='email';fnames[1]='NAME';ftypes[1]='text';fnames[2]='ACTIVITY';ftypes[2]='text';}(jQuery));var $mcj = jQuery.noConflict(true);</script><br />
<!--End mc_embed_signup-->
</div>
<div style="clear:both"></div>
]]></content:encoded>
			</item>
		<item>
		<title>Tutorial: Code Signing and Verification with OpenSSL</title>
		<link>https://eclipsesource.com/blogs/2016/09/07/tutorial-code-signing-and-verification-with-openssl/</link>
		<comments>https://eclipsesource.com/blogs/2016/09/07/tutorial-code-signing-and-verification-with-openssl/#comments</comments>
		<pubDate>Wed, 07 Sep 2016 20:54:58 +0000</pubDate>
		<dc:creator><![CDATA[Ian Bull]]></dc:creator>
				<category><![CDATA[EclipseSource News]]></category>
		<category><![CDATA[Editors choice]]></category>
		<category><![CDATA[j2v8]]></category>

		<guid isPermaLink="false">http://eclipsesource.com/blogs/?p=27077</guid>
		<description><![CDATA[Code signing and verification is the process of digitally signing executables or scripts to ensure that the software you are executing...]]></description>
				<content:encoded><![CDATA[<p>Code signing and verification is the process of digitally signing executables or scripts to ensure that the software you are executing has not been altered since it was signed. Code signing helps protect against corrupt artifacts, process breakdown (accidentally delivering the wrong thing) and even malicious intents. We have recently started implementing code verification in <a href="https://github.com/eclipsesource/j2v8">J2V8</a>. Code verification has been implemented in the native code using <a href="https://www.openssl.org/">OpenSSL</a>.</p>
<p>Code signing and verification works as follows. In addition to writing the code, the author executes a <em>hash function</em> with the code as the input, producing a <em>digest</em>. The digest is signed with the author’s private key, producing the <em>signature</em>. The code, signature and hash function are then delivered to the verifier. The verifier produces the digest from the code using the same hash function, and then uses the public key to decrypt the signature. If both digests match, then the verifier can be confident that the code has not been tampered with.</p>
<p>In this tutorial we will demonstrate how you can use OpenSSL to sign and verify a script. This tutorial will describe both the OpenSSL command line, and the C++ APIs.</p>
<h1>Key Generation</h1>
<p>Before you can begin the process of code signing and verification, you must first create a public/private key pair. The <tt>ssh-keygen -t rsa</tt> can be used to generate key pairs.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="shell">$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/irbull/.ssh/id_rsa): ./example_rsa
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in ./example_rsa.
Your public key has been saved in ./example_rsa.pub.
The key fingerprint is:
35:26:61:ae:23:11:6c:e1:88:39:31:c5:0f:06:f7:71 me@mymachine
The key randomart image is:
+--[ RSA 2048]----+
|++o.+.E o        |
| *++o+ o .       |
|+..++   o +      |
| .  .. . + .     |
|    . o S        |
|     . .         |
|                 |
|                 |
|                 |
+-----------------+</pre>
<p>If you&#8217;re interested in what randomart is, checkout the answer on <a href="http://superuser.com/questions/22535/what-is-randomart-produced-by-ssh-keygen">StackExchange</a>.</p>
<h2>Converting to PEM format</h2>
<p>The standard file format for OpenSSL is the PEM format. The PEM format is intended to be readable in ASCII and safe for ASCII editors and text documents. The PEM format is a <em>container format</em> and can include public certificates, or certificate chains including the public key, private key and root certificate. PEM files can be recognized by the BEGIN and END headers. To export a public key in PEM format use the following OpenSSL command.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="shell">$ openssl rsa -in example_rsa -pubout -out public.key.pem</pre>
<h1>Code Signing</h1>
<p>OpenSSL makes it relatively easy to compute the digest and signature from a plaintext using a single API. However, before you begin you must first create an RSA object from your private key:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="cpp">RSA* createPrivateRSA(std::string key) {
  RSA *rsa = NULL;
  const char* c_string = key.c_str();
  BIO * keybio = BIO_new_mem_buf((void*)c_string, -1);
  if (keybio==NULL) {
      return 0;
  }
  rsa = PEM_read_bio_RSAPrivateKey(keybio, &rsa,NULL, NULL);
  return rsa;
}</pre>
<p>With an RSA object and plaintext you can create the digest and digital signature:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="cpp">bool RSASign( RSA* rsa, 
              const unsigned char* Msg, 
              size_t MsgLen,
              unsigned char** EncMsg, 
              size_t* MsgLenEnc) {
  EVP_MD_CTX* m_RSASignCtx = EVP_MD_CTX_create();
  EVP_PKEY* priKey  = EVP_PKEY_new();
  EVP_PKEY_assign_RSA(priKey, rsa);
  if (EVP_DigestSignInit(m_RSASignCtx,NULL, EVP_sha256(), NULL,priKey)<=0) {
      return false;
  }
  if (EVP_DigestSignUpdate(m_RSASignCtx, Msg, MsgLen) <= 0) {
      return false;
  }
  if (EVP_DigestSignFinal(m_RSASignCtx, NULL, MsgLenEnc) <=0) {
      return false;
  }
  *EncMsg = (unsigned char*)malloc(*MsgLenEnc);
  if (EVP_DigestSignFinal(m_RSASignCtx, *EncMsg, MsgLenEnc) <= 0) {
      return false;
  }
  EVP_MD_CTX_cleanup(m_RSASignCtx);
  return true;
}</pre>
<p>This works by first creating a signing context, and then initializing the context with the hash function (SHA-256 in our case) and the private key. The message is then added to the context, and finally the signature length is computed. Space for the signature is then allocated and finally the signature (signed digest) computed. <tt>EncMsg</tt> will hold the signature and <tt>MsgLenEnc</tt> will hold the length of the signature. The signature <strong>should not</strong> be treated as a string.</p>
<p>If you need to print the signature or write it to non-binary file, you should Base64 encode it. OpenSSL provides an API to help with this. <a href="http://doctrina.org/Base64-With-OpenSSL-C-API.html">Barry Steyn</a> has put together a simple example that shows how to use this API. Below is a slightly modified version of his code:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="cpp">void Base64Encode( const unsigned char* buffer, 
                   size_t length, 
                   char** base64Text) { 
  BIO *bio, *b64;
  BUF_MEM *bufferPtr;

  b64 = BIO_new(BIO_f_base64());
  bio = BIO_new(BIO_s_mem());
  bio = BIO_push(b64, bio);

  BIO_write(bio, buffer, length);
  BIO_flush(bio);
  BIO_get_mem_ptr(bio, &bufferPtr);
  BIO_set_close(bio, BIO_NOCLOSE);
  BIO_free_all(bio);

  *base64Text=(*bufferPtr).data;
}</pre>
<p>Putting this all together you can create a signed digest in a Base64 encoded string:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="cpp">char* signMessage(std::string privateKey, std::string plainText) {
  RSA* privateRSA = createPrivateRSA(privateKey);
  unsigned char* encMessage;
  char* base64Text;
  size_t encMessageLength;
  RSASign(privateRSA, (unsigned char*) plainText.c_str(), plainText.length(), &encMessage, &encMessageLength);
  Base64Encode(encMessage, encMessageLength, &base64Text);
  free(encMessage);
  return base64Text;
}</pre>
<p>The character array <tt>base64Text</tt> will hold the result.</p>
<h2>OpenSSL Command Line</h2>
<p>You can also create a digest and digital signature using the following OpenSSL commands. The first command will create the digest and signature. The signature will be written to <tt>sign.txt.sha256</tt> as binary. The second command Base64 encodes the signature.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="shell">openssl dgst -sha256 -sign my_private.key -out sign.txt.sha256 codeToSign.txt
openssl enc -base64 -in sign.txt.sha256 -out sign.txt.sha256.base64</pre>
<h1>Signature Verification</h1>
<p>Signature verification ensures that the signature matches the original code. If the code was altered at all (even the addition of a single newline character) then a different signature will be produced and the verification will fail.</p>
<p>Signature verification works in the opposite direction. In order to verify that the signature is correct, you must first compute the digest using the same algorithm as the author. Then, using the public key, you decrypt the author's signature and verify that the digests match.</p>
<p>Again, OpenSSL has an API for computing the digest and verifying the signature. Since we wrote the signature with a Base64 encoding, we must first decode it. Again, <a href="http://doctrina.org/Base64-With-OpenSSL-C-API.html">Barry Steyn</a> has a detailed example of how to do this on his blog. A copy of his code can be found below.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="cpp">size_t calcDecodeLength(const char* b64input) {
  size_t len = strlen(b64input), padding = 0;

  if (b64input[len-1] == '=' && b64input[len-2] == '=') //last two chars are =
    padding = 2;
  else if (b64input[len-1] == '=') //last char is =
    padding = 1;
  return (len*3)/4 - padding;
}

void Base64Decode(const char* b64message, unsigned char** buffer, size_t* length) {
  BIO *bio, *b64;

  int decodeLen = calcDecodeLength(b64message);
  *buffer = (unsigned char*)malloc(decodeLen + 1);
  (*buffer)[decodeLen] = '\0';

  bio = BIO_new_mem_buf(b64message, -1);
  b64 = BIO_new(BIO_f_base64());
  bio = BIO_push(b64, bio);

  *length = BIO_read(bio, *buffer, strlen(b64message));
  BIO_free_all(bio);
}</pre>
<p>In addition to decoding the Base64 encoded signature, you must also create an RSA object from the public key. This is similar to how the RSA object was created from the private key when the signature was computed.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="cpp">RSA* createPublicRSA(std::string key) {
  RSA *rsa = NULL;
  BIO *keybio;
  const char* c_string = key.c_str();
  keybio = BIO_new_mem_buf((void*)c_string, -1);
  if (keybio==NULL) {
      return 0;
  }
  rsa = PEM_read_bio_RSA_PUBKEY(keybio, &rsa,NULL, NULL);
  return rsa;
}</pre>
<p>Finally, with the RSA object, original message and binary encoded signature, you can verify that the signature matches the plain text.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="cpp">bool RSAVerifySignature( RSA* rsa, 
                         unsigned char* MsgHash, 
                         size_t MsgHashLen, 
                         const char* Msg, 
                         size_t MsgLen, 
                         bool* Authentic) {
  *Authentic = false;
  EVP_PKEY* pubKey  = EVP_PKEY_new();
  EVP_PKEY_assign_RSA(pubKey, rsa);
  EVP_MD_CTX* m_RSAVerifyCtx = EVP_MD_CTX_create();

  if (EVP_DigestVerifyInit(m_RSAVerifyCtx,NULL, EVP_sha256(),NULL,pubKey)<=0) {
    return false;
  }
  if (EVP_DigestVerifyUpdate(m_RSAVerifyCtx, Msg, MsgLen) <= 0) {
    return false;
  }
  int AuthStatus = EVP_DigestVerifyFinal(m_RSAVerifyCtx, MsgHash, MsgHashLen);
  if (AuthStatus==1) {
    *Authentic = true;
    EVP_MD_CTX_cleanup(m_RSAVerifyCtx);
    return true;
  } else if(AuthStatus==0){
    *Authentic = false;
    EVP_MD_CTX_cleanup(m_RSAVerifyCtx);
    return true;
  } else{
    *Authentic = false;
    EVP_MD_CTX_cleanup(m_RSAVerifyCtx);
    return false;
  }
}</pre>
<p>The output variable <tt>Authentic</tt> holds the result of the verification. The verification works by first creating a verification context. The context is initialized with the <em>hash function</em> used (SHA-256 in our case) and the public key. The original message is then provided and finally the verification is performed.</p>
<p>Putting this all together, you can verify a signature given the original text, the signature and public key as follows:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="cpp">bool verifySignature(std::string publicKey, std::string plainText, char* signatureBase64) {
  RSA* publicRSA = createPublicRSA(publicKey);
  unsigned char* encMessage;
  size_t encMessageLength;
  bool authentic;
  Base64Decode(signatureBase64, &encMessage, &encMessageLength);
  bool result = RSAVerifySignature(publicRSA, encMessage, encMessageLength, plainText.c_str(), plainText.length(), &authentic);
  return result & authentic;
}</pre>
<h2>OpenSSL Command Line</h2>
<p>Finally, the OpenSSL command line tool can also be used to decode and verify a digital signature.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="shell">openssl enc -base64 -d -in sign.txt.sha256.base64 -out sign.txt.sha256 
openssl dgst -sha256 -verify public.key.pem -signature sign.txt.sha256 codeToSign.txt</pre>
<h1>Conclusion</h1>
<p>So that's it, with either the OpenSSL API or the command line you can sign and verify a code fragment to ensure that it has not been altered since it was authored. You can even mix & match the command line tools with the API, so you can generate the signatures during a build and verify them during program execution. All the code for this example can be found on <a href="https://gist.github.com/irbull/08339ddcd5686f509e9826964b17bb59">GitHub</a>.</p>
<p>We will be including a code verification API in the upcoming version of <a href="https://github.com/eclipsesource/j2v8">J2V8</a>. For more news about J2V8 and other things I find interesting, follow me on <a href="https://twitter.com/irbull">Twitter</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://eclipsesource.com/blogs/2016/09/07/tutorial-code-signing-and-verification-with-openssl/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Smile: Deploying a mobile app has never been so easy</title>
		<link>https://eclipsesource.com/blogs/2016/08/10/smile-deploying-a-mobile-app-has-never-been-so-easy/</link>
		<pubDate>Wed, 10 Aug 2016 14:31:26 +0000</pubDate>
		<dc:creator><![CDATA[Ian Bull]]></dc:creator>
				<category><![CDATA[EclipseSource News]]></category>
		<category><![CDATA[tabris.js]]></category>

		<guid isPermaLink="false">http://eclipsesource.com/blogs/?p=27050</guid>
		<description><![CDATA[Mobile software development is hard. Before you can even write your first line of code you must: download, install and configure...]]></description>
				<content:encoded><![CDATA[<p>Mobile software development is hard. Before you can even write your first line of code you must: download, install and configure the IDEs and SDKs, configure the emulators or connect a device to your machine, build the application archives (apks / ipas) and install these archives on your device. With Tabris.js we set out to eliminate most of the technical hurdles users face when developing mobile applications.</p>
<p><strong>With Tabris.js, if you can take a picture, you can deploy a mobile app.</strong></p>
<p>Really, it&#8217;s that simple:</p>
<ol>
<li>Install the Tabris.js development app for your device (<a href="https://play.google.com/store/apps/details?id=com.eclipsesource.tabris.js">Android</a>, <a href="https://itunes.apple.com/de/app/tabris.js/id939600018?l=en&#038;mt=8">iOS</a>)</li>
<li>Head to the <a href="https://tabrisjs.com/playground">Tabris.js playground</a> and hack on your app</li>
<li>Take a picture of the QR-Code with your device</li>
</ol>
<p><img class="alignnone wp-image-27116" src="https://eclipsesource.com/wp-content/uploads/2016/08/scan-playground-code.png" alt="Scanning QR code in the Tabris.js app" width="300" height="533" /></p>
<p>That&#8217;s it! Your app is now running on your device. And if you make a change to your app, simply reload it to see the changes.</p>
<p>Tabris.js is a cross platform, mobile application platform. All the apps are developed in JavaScript and they run natively on your device. When you develop an app at <a href="https://tabrisjs.com">tabrisjs.com</a> we create a link to that app. When you scan the QR-Code with the development client, the app is downloaded to your device and executed. No cross compiling. No webviews. Native performance.</p>
<p>The real benefit of Tabris.js is not what we enabled, it&#8217;s what we eliminated:</p>
<ul>
<li>No registration</li>
<li>No IDE installation</li>
<li>No SDKs to deal with</li>
<li>No need to write your app twice (JavaScript runs on both iOS and Android)</li>
<li>No emulators</li>
<li>No complicated deployments</li>
</ul>
<p>And when you want to deploy your app to the stores, we have the tools to make this easy too.</p>
<p>Tabris.js is the easiest way to get started with mobile application development.</p>
<p>Bonus tip: also check out the <a href="https://tabrisjs.com/downloads/ebook/tabrisjs-1.9.pdf">Tabris.js Getting Started ebook</a>, which will tell you everything you need to know to build your first app.</p>
<p><a href="https://tabrisjs.com/downloads/ebook/tabrisjs-1.9.pdf"><img class="wp-image-26911 size-medium alignnone" style="margin-bottom: 20px;" src="https://eclipsesource.com/wp-content/uploads/2016/07/Getting-started-300x212.png" alt="Getting started Ebook" width="300" height="212" /></a></p>
]]></content:encoded>
			</item>
		<item>
		<title>Branching Without an if, A Java Puzzle</title>
		<link>https://eclipsesource.com/blogs/2016/08/06/branching-without-an-if-a-java-puzzle/</link>
		<comments>https://eclipsesource.com/blogs/2016/08/06/branching-without-an-if-a-java-puzzle/#comments</comments>
		<pubDate>Sat, 06 Aug 2016 04:05:13 +0000</pubDate>
		<dc:creator><![CDATA[Ian Bull]]></dc:creator>
				<category><![CDATA[Editors choice]]></category>
		<category><![CDATA[Planet Eclipse]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://eclipsesource.com/blogs/?p=27052</guid>
		<description><![CDATA[I returned home late the other night, and saw this tweet in my timeline: Keyboard broken. Write this Java code without...]]></description>
				<content:encoded><![CDATA[<p>I returned home late the other night, and saw this tweet in my timeline:</p>
<blockquote class="twitter-tweet" data-width="550">
<p lang="en" dir="ltr">Keyboard broken. Write this Java code without using the letter &#39;f&#39;:</p>
<p>int bar(Object o) { if (o == null) return 0; else return 1;}</p>
<p>Anyone?</p>
<p>&mdash; Marc Khouzam (@marckhouzam) <a href="https://twitter.com/marckhouzam/status/761389998788714496">August 5, 2016</a></p></blockquote>
<p><script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script></p>
<p>He added a clarifying note that said the &#8216;?&#8217; was also broken.</p>
<p>For those of you who don&#8217;t know Marc, he is the co-lead of the Eclipse C/C++ Development Tools and all round good guy. I was pretty sure his keyboard wasn&#8217;t actually broken and he was basically asking: <strong>How can you write a branch statement in Java without an <em>if</em></strong>.</p>
<p>My first thought was to use another branching construct, and the <strong>while</strong> loop was the first one to pop into my head:</p>
<p><pre data-enlighter-language="raw" class="EnlighterJSRAW">
&lt;pre lang=&quot;java&quot;&gt;
int bar(Object o) {
  while(o == null) {
    return 0;
  }
  return 1;
}
&lt;/pre&gt;
</pre></p>
<p>However, since I couldn&#8217;t sleep I started thinking of other ways to solve this. Since it could be solved with a <strong>while</strong>, what about a <strong>do while</strong>.</p>
<p><pre data-enlighter-language="raw" class="EnlighterJSRAW">
&lt;pre lang=&quot;java&quot;&gt;
int bar(Object o) {
  int counter = 2;
  do {
    counter--;
  } while(o == null &amp;&amp; counter &gt; 0);
  return counter;
}
&lt;/pre&gt;
</pre></p>
<p>You could likely solve it with a <strong>for loop</strong> too, but that would require an <strong>f.</strong></p>
<p>A <strong>case statement</strong> is the next obvious branching construct. However, you cannot switch on a condition such as <em>does n == null</em>. But you can switch on integers, and the <tt>identityHashCode</tt> is good choice because the <tt>identityHashCode</tt> for null is 0:</p>
<p><pre data-enlighter-language="raw" class="EnlighterJSRAW">
&lt;pre lang=&quot;java&quot;&gt;
int bar(Object o) {
  int hash = System.identityHashCode(o);
  switch(hash) {
    case 0: return 0;
  }
  return 1;
}
&lt;/pre&gt;
</pre></p>
<p>Another conditional construct is the <strong>catch block</strong>, since it only enters into the catch block if an exception is thrown. It&#8217;s pretty easy to raise an exception with a null reference:</p>
<p><pre data-enlighter-language="raw" class="EnlighterJSRAW">
&lt;pre lang=&quot;java&quot;&gt;
int bar(Object o) {
  try {
    o.equals(o);
    return 1;
  } catch(NullPointerException e) {
    return 0;
  }
}
&lt;/pre&gt;
</pre></p>
<p>Finally, I took the original question literally and wrote the <strong>if</strong> <strong>statement</strong> without an <strong>f</strong>. This can be done by replacing the character with its unicode equivalent. I think this was a little cheeky and not really in the spirit of the question though:</p>
<p><pre data-enlighter-language="raw" class="EnlighterJSRAW">
&lt;pre lang=&quot;java&quot;&gt;
int bar(Object o) {
  i\u0066(o == null ) 
    return 0;
  else 
    return 1;
  }
}
&lt;/pre&gt;
</pre></p>
<p>Does anyone else have other suggestions for how to solve this? Or maybe Marc should just take Jesper&#8217;s advice:</p>
<blockquote class="twitter-tweet" data-width="550">
<p lang="en" dir="ltr"><a href="https://twitter.com/irbull">@irbull</a> <a href="https://twitter.com/marckhouzam">@marckhouzam</a> If the ?-key is broken as well, he needs a new keyboard.</p>
<p>&mdash; Jesper Eskilson (@JesperEs) <a href="https://twitter.com/JesperEs/status/761457229035888640">August 5, 2016</a></p></blockquote>
<p><script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script></p>
]]></content:encoded>
			<wfw:commentRss>https://eclipsesource.com/blogs/2016/08/06/branching-without-an-if-a-java-puzzle/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
	</channel>
</rss>
