Friday, June 2, 2017

#337: An Introduction to Commonly Used ES6 Features

This week's JavaScript newsRead this e-mail on the Web
JavaScript Weekly
Issue 337 — June 2, 2017
A new major release of Node is here with many significant updates including V8 5.8, npm 5, async_hooks, N-API.. See this week’s Node Weekly for a comprehensive roundup.
Node.js Foundation

A ‘tale of adventure’ in moving from the long standing Mocha test framework to Facebook’s Jest.
Patrick Hund

In this session from Google I/O, Addy Osmani covers PWA best practices, patterns for efficiently loading websites and the latest tools for getting fast and staying fast.
Google Chrome Developers

ROLLBAR
See how Rollbar pairs perfectly with New Relic to give you greater coverage + much more insight into application errors.
ROLLBAR   Sponsor

If you’re not yet using ES6 on a frequent basis, this is a thorough introduction to seven of the most useful concepts.
Zell Liew

It’s been around a while but has had a lot of updates recently.

1.5 brings dynamic imports, code splitting, and bundle size analysis. It’s still based around Node v4, but will move up to Node v6 in Meteor 1.6.
Ben Newman

From the basics to advanced topics with simple, but detailed explanations.
Ilya Kantor

Jobs Supported by Hired.com

Can't find the right job? Want companies to apply to you? Try Hired.com.

In Brief

Announcing TypeScript Support in Electron news
Zeke Sikelianos

Assert(js): A Forthcoming JS Testing Conference in Texas news
Currently just seeking speakers.

A Curated List of 68 React and Redux Tutorials, Walkthroughs and Courses 
Mark Erikson

How to Hire for JavaScript Development 
We hire awesome JavaScript developers. Learn how we identify, test, and hire for JavaScript.
Code My Views  Sponsor

The Most Important Features and Fixes of Node 8 tutorial
Gergely Nemeth

Delivering Untranspiled Source Code via npm tutorial
Dr. Axel Rauschmayer

The Anatomy of a Modern JavaScript Application tutorial
SitePoint

Managing State in Aurelia with Higher Order Components tutorial
Vildan Softic

WebAssembly: Mozilla Won opinion
“I think WebAssembly is a big victory for asm.js and Mozilla’s vision.”
Robert O'Callahan

Redux vs MobX: Which Is Best for Your Project? opinion
Michael Wanyoike

Switching From React to Vue.js opinion
Anthony Gore

Using terminal to view test results is a productivity killer tools
You write code in your favorite editor, we run tests and deliver the results in realtime to the editor.
Wallaby.js  Sponsor

Storybook 3.0: An Interact Dev Environment for React Components tools
Michael Shilman

vue-devtools: A Chrome DevTools Extension for Debugging Vue.js Apps tools
It’s also on the Chrome Web Store.

O: An In-Browser Loader, Bundler and Dependency Injection Builder tools
In progress and proof of concept, but the team wants to know what you think.
GardenHQ

taxi-rank: A JSDom-Based Selenium Webdriver API code
Uses Zombie under the hood.
Forbes Lindesay

Nile.js: A P2P Live Video Streaming Library Built on WebTorrent code
Miranda, Qiu, and Pierson

Timelinejs: A jQuery Timeline Slider Plugin code
ilker Yılmaz

vue-recyclerview: A Fast Way to Render Large Lists with Vue code

Picodom: A 1KB Virtual DOM Builder and Patch Algorithm code
Handy for building your own view library, for instance.

micro-http-client: A 'fetch' Wrapper to Specify Common Request and Response Processing in a Single Location code
remerge GmbH

Have you tried MongoDB Atlas yet? 
MONGODB  Sponsor

Curated by Peter Cooper and published by Cooperpress.

Like this? You may also enjoy: FrontEnd Focus : Node Weekly : React Status

Stop getting JavaScript Weekly : Change email address : Read this issue on the Web

© Cooperpress Ltd. Office 30, Lincoln Way, Louth, LN11 0LS, UK


by via JavaScript Weekly

Space Wallpapers

Minimal One Pager promoting a set of Space Wallpapers for your iPhone curated by popular blog, The Beauty Of Space. When clicking the collection link a slick off-canvas content area slides out with a preview of all wallpapers 🛰

by Rob Hope via One Page Love

Using Font Awesome with WordPress

Web Icons

Users today are focused just as much on the visual design of a website as they are about the content they need from it.

Traditionally designers and developers have used individual images/sprite-sheets for their icons; these graphics were a series of pixel perfect images that would be used in specific parts of the site (such as the search bar, navigational elements, loading icons and other elements).

Displaying icons with images/sprites worked well for a long time (and many websites will still use them). However, with the focus on responsive design more important than ever, the challenge has been providing stunning iconography that looks great regardless of your device.

What Are Font Icons?

Font icons are a way in which we can display fully responsive, customizable icons on our website without the use of additional images or sprite-sheets.

Font Icons are exactly what they sound like, a font made of icons.

Continue reading %Using Font Awesome with WordPress%


by Simon Codrington via SitePoint

Playful Little Tooltip Ideas with SVG and Anime.js

Some little ideas for bouncy and playful tooltip shapes and animations with SVG and anime.js. Among other styles, we use shape morphing and transform.


by via jQuery-Plugins.net RSS Feed

Dotcore

Dotcore

Dark-scheme One Pager with a background animation and pretty neat content load transitions for new tech innovation studio, Dotcore.

by Rob Hope via One Page Love

10 Best PHP URL Shortener Scripts

Securing iOS Data at Rest: The Keychain

Any app that saves the user's data has to take care of the security and privacy of that data. As we've seen with recent data breaches, there can be very serious consequences for failing to protect your users' stored data. In this tutorial, you'll learn some best practices for protecting your users' data.

In the previous post, you learned how to protect files using the Data Protection API. File-based protection is a powerful feature for secure bulk data storage. But it might be overkill for a small amount of information to protect, such as a key or password. For these types of items, the keychain is the recommended solution.

Keychain Services

The keychain is a great place to store smaller amounts of information such as sensitive strings and IDs that persist even when the user deletes the app. An example might be a device or session token that your server returns to the app upon registration. Whether you call it a secret string or unique token, the keychain refers to all of these items as passwords

There are a few popular third-party libraries for keychain services, such as Strongbox (Swift) and SSKeychain (Objective-C). Or, if you want complete control over your own code, you may wish to directly use the Keychain Services API, which is a C API. 

I will briefly explain how the keychain works. You can think of the keychain as a typical database where you run queries on a table. The functions of the keychain API all require a CFDictionary object that contains attributes of the query. 

Each entry in the keychain has a service name. The service name is an identifier: a key for whatever value you want to store or retrieve in the keychain. To allow a keychain item to be stored for a specific user only, you'll also often want to specify an account name. 

Because each keychain function takes a similar dictionary with many of the same parameters to make a query, you can avoid duplicate code by making a helper function that returns this query dictionary.

This code sets up the query Dictionary with your account and service names and tells the keychain that we will be storing a password. 

Similarly to how you can set the protection level for individual files (as we discussed in the previous post), you can also set the protection levels for your keychain item using the kSecAttrAccessible key

Adding a Password

The SecItemAdd() function adds data to the keychain. This function takes a Data object, which makes it versatile for storing many kinds of objects. Using the password query function we created above, let's store a string in the keychain. To do this, we just have to convert the String to Data.

Deleting a Password

To prevent duplicate inserts, the code above first deletes the previous entry if there is one. Let's write that function now. This is accomplished using the SecItemDelete() function.

Retrieving a Password

Next, to retrieve an entry from the keychain, use the SecItemCopyMatching() function. It will return an AnyObject that matches your query.

In this code, we set the kSecReturnData parameter to kCFBooleanTruekSecReturnData means the actual data of the item will be returned. A different option could be to return the attributes (kSecReturnAttributes) of the item. The key takes a CFBoolean type which holds the constants kCFBooleanTrue or kCFBooleanFalse. We are setting kSecMatchLimit to kSecMatchLimitOne so that only the first item found in the keychain will be returned, as opposed to an unlimited number of results.

Public and Private Keys

The keychain is also the recommended place to store public and private key objects, for example, if your app works with and needs to store EC or RSA SecKey objects. 

The main difference is that instead of telling the keychain to store a password, we can tell it to store a key. In fact, we can get specific by setting the types of keys stored, such as whether it is public or private. All that needs to be done is to adapt the query helper function to work with the type of key you want. 

Keys generally are identified using a reverse domain tag such as com.mydomain.mykey instead of service and account names (since public keys are openly shared between different companies or entities). We will take the service and account strings and convert them to a tag Data object. For example, the above code adapted to store an RSA Private SecKey would look like this:

Application Passwords

Items secured with the kSecAttrAccessibleWhenUnlocked flag are only unlocked when the device is unlocked, but it relies on the user having a passcode or Touch ID set up in the first place. 

The applicationPassword credential allows items in the keychain to be secured using an additional password. This way, if the user does not have a passcode or Touch ID set up, the items will still be secure, and it adds an extra layer of security if they do have a passcode set.  

As an example scenario, after your app authenticates with your server, your server could return the password over HTTPS that is required to unlock the keychain item. This is the preferred way of supplying that additional password. Hardcoding a password in the binary is not recommended.

Another scenario might be to retrieve the additional password from a user-provided password in your app; however, this requires more work to secure properly (using PBKDF2). We will look at securing user-provided passwords in the next tutorial. 

Another use of an application password is for storing a sensitive key—for example, one that you would not want to be exposed just because the user had not yet set up a passcode. 

applicationPassword is only available on iOS 9 and above, so you will need a fallback that doesn't use applicationPassword if you are targeting lower iOS versions. To use the code, you will need to add the following into your bridging header:

The following code sets a password for the query Dictionary.

Notice that we set kSecAttrAccessControl on the Dictionary. This is used in place of kSecAttrAccessible, which was previously set in our passwordQuery method. If you try to use both, you'll get an OSStatus -50 error.

User Authentication

Starting in iOS 8, you can store data in the keychain that can only be accessed after the user successfully authenticates on the device with Touch ID or a passcode. When it's time for the user to authenticate, Touch ID will take priority if it is set up, otherwise the passcode screen is presented. Saving to the keychain will not require the user to authenticate, but retrieving the data will. 

You can set a keychain item to require user authentication by providing an access control object set to .userPresence. If no passcode is set up then any keychain requests with .userPresence will fail. 

This feature is good when you want to make sure that your app is being used by the right person. For example, it would be important for the user to authenticate before being able to log in to a banking app. This will protect users who have left their device unlocked, so that the banking cannot be accessed. 

Also, if you do not have a server-side component to your app, you can use this feature to perform device-side authentication instead.

For the load query, you can provide a description of why the user needs to authenticate.

When retrieving the data with SecItemCopyMatching(), the function will show the authentication UI and wait for the user to use Touch ID or enter the passcode. Since SecItemCopyMatching() will block until the user has finished authenticating, you will need to call the function from a background thread in order to allow the main UI thread to stay responsive.

Again, we are setting kSecAttrAccessControl on the query Dictionary. You will need to remove kSecAttrAccessible, which was previously set in our passwordQuery method. Using both at once will result in an OSStatus -50 error.

Conclusion

In this article, you've had a tour of the Keychain Services API. Along with the Data Protection API that we saw in the previous post, use of this library is part of the best practices for securing data. 

However, if the user does not have a passcode or Touch ID on the device, there is no encryption for either framework. Because the Keychain Services and Data Protection APIs are commonly used by iOS apps, they are sometimes targeted by attackers, especially on jailbroken devices. If your app does not work with highly sensitive information, this may be an acceptable risk. While iOS is constantly updating the security of the frameworks, we are still at the mercy of the user updating the OS, using a strong passcode, and not jailbreaking their device. 

The keychain is meant for smaller pieces of data, and you may have a larger amount of data to secure that is independent of the device authentication. While iOS updates add some great new features such as the application password, you may still need to support lower iOS versions and still have strong security. For some of these reasons, you may instead want to encrypt the data yourself. 

The final article in this series covers encrypting the data yourself using AES encryption, and while it's a more advanced approach, this allows you to have full control over how and when your data is encrypted.

So stay tuned. And in the meantime, check out some of our other posts on iOS app development!

  • iOS SDK
    Securing Communications on iOS
    Collin Stuart
  • Mobile Development
    Back-End as a Service for Mobile Apps
    Bala Durage Sandamal Siripathi
  • iOS SDK
    The Right Way to Share State Between Swift View Controllers
    Matteo Manferdini
  • Swift
    Swift From Scratch: Closures
    Bart Jacobs

by Collin Stuart via Envato Tuts+ Code