Friday, September 16, 2016

Notes from Sails tutorial - Part 1

Below are few benefits of it.

Auto generated API
Database ORM
Inbuilt task runner
Security code
Built-in web sockets in routes.
Unlike MEAN stack, where you need to create API's manually and do same repetitive thing again and again, Sails.js allows you to automatically create skeleton APIs. Just a single command, and you will have block of code generated to get you started.

Additionally, Sails.js provides database drivers for every major database systems such as MySQL, MongoDB, PostgreSQL. Sails.js uses Grunt task runner as the default task runner, and also provides an effective way to manage custom grunt tasks.

Furthermore, common security parameters such as CORS and CSRF are already included in Sails.js project. All you need to do is to enable them from respective files and your application is secured with the latest security standards.

Sails.js uses Express to handle HTTP operations and Socket.io to handle web socket messages. It provides web socket messages to your routes without configuring it in back-end or front-end layer.

The controllers and model folders are the most important. Controller contains every piece of the code your application needs to drive a backend system and communicate with the View or User interface.

Model contains how the object in data store will look like. So, if you are using a relational database, then it will be a table in database and JSON object in model file, or if you are using NoSQL databases such as MongoDB, then it will be collection under model.

The database connection is configured in config/connections. Since i was planning to use mongo db, it was like below 

someMongodbServer: {
    adapter: 'sails-mongo',
    host: 'localhost',
    port: 27017,
    // user: 'username',
    // password: 'password',
    database: ‘mymongodb’
  } 

user name and password is commented so that it does not ask for any 

in config/model.js, we can configure to use this connection and tell it to sails. 

connection: 'someMongodbServer',


references:

Tuesday, September 6, 2016

iOS how to resign an application

Problems because of the adhoc builds released for internal testing got expired by its provisioning profile? There is a utility to resign such ipa files easily.

iResign is an application which can be downloaded from the link below which helps to do this easily.

As can be seen in the UI, just select the ipa to resign, select the provisioning profile to be used and the Certificate information. Click resign and thats it. it generate the ipa which is ready to be installed again working.

 


Based on experience, it appears that the installation of the signed one fails if don’t give the bundle id at the time of resign.

references:
https://github.com/maciekish/iReSign

iOS Stack View - Working well with Auto layout.

In combination with Auto Layout, one of the most useful tools for working with layouts like the one you have is stack view (UIStackView). A stack view provides a streamlined interface for laying out a collection of views in either a column or a row. Stack views let you leverage the power of Auto Layout, creating user interfaces that can dynamically adapt to the device’s orientation, screen size, and any changes in the available space.

Lets say we have to create a UI like this below 

Lets divide the task into below steps

Step 1: add the UI elements to the scene
just drag 2 labels, 2 text fields and a button to the scene so that it looks below 


Step 2: Embed the UI elements in UIStackView

Shift select all of the added elements and Editor > Embed In > Stack View 

This shows like below 

Step 3: Now align the Stack view to the centre of the screen by using Align and Pin tools 

After the alignment, it will look like the below. 

Step 4 : Align the components within stack view


Select the Text fields individually and add Pin to the edges of the stack view. 

Thats it. the screen is ready. Just change the label to have required text and the background color for the text fields. 

references:

Monday, September 5, 2016

Mac - How to remove the iOS provisioning profiles

This can be done in below 3 steps

1. Navigate to the profiles folder on Mac machine

The profiles are under the directory ~/Library/MobileDevice/Provisioning Profiles

2. Search for profile if any already exist with same bundle id, which could have been already expired or signed with another identity.

The search can be done in the above folder with grep -lr "com.myserver.ppt" *
If the profile exist, this will list the filename(s) having this key.

Now delete the old profile

3. Generate the new profile from developer console and click to install it.

This ensure the Mac is having the latest profile available.
to Note, if the certificate is already expired, then one should install the certificate too, which is by opening the .p12 file that is given to the developer and providing the password to it.

references:
http://stackoverflow.com/questions/26732251/how-to-remove-provisioning-profiles-from-xcode-6-and-xcode-7

Tuesday, August 30, 2016

Android - How to Kill the application on back button press.

The easiest way to do this is to clear all the top activities and call the finish() on the activities. The below code needs to be done by overriding the onBackPressed method.

    Intent intent = new Intent(this, LaunchActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra("Exit", true);
    startActivity(intent);
    finish();

On the launch activity, now we need to have the below code at the end of onCreate, note that should not spin any new thread in the OnCreate method.

    if( getIntent().getBooleanExtra("Exit", false)){
        finish();
    }

In some cases, we may not want to have back traces left for specific activity on the activity stack. In such cases, we can just have the below code for each activity in the Android Manifest xml. for e.g. SplashScreen , Login Screen etc.

android:noHistory="true"

One another way is to have the homescreen shown while the app activity is not forcefully finished. The code below should be placed on OnBackPressed overriden method.

Intent a = new Intent(Intent.ACTION_MAIN);
a.addCategory(Intent.CATEGORY_HOME);
a.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(a);


references:
http://stackoverflow.com/questions/3226495/how-to-exit-from-the-application-and-show-the-home-screen

Over the Air Profile Delivery concepts

There are three phases involved in this:

1. authentication
2. enrollment
3. device configuration 

Authentication Phase (Phase 1):

Two main aims of this step are

1. Ensure the enrolment request is from valid entity 
2. It captures info about user’s device for use in the certificate enrolment process. 

The steps involved in this are: 

1. User visits the root URL and receives a welcome message. 
2. The user visits the certificate authority URL (/CA) to get the root cert. 
3. The user visits the enrolment URL (/enroll) to start the enrolment process. In this step, user is prompted to authenticate himself or herself using HTTP basic authentication or using existing directory services. 
4. The server’s enrolment handler determines whether the user is allowed to enrol the device. If allowed, server sends a profile service payload. The service payload (.mobileconfig) contains a request for additional device-specific information that device must provide in next step. The payload may include a Challenge token (optional) so that the server can associate the request with the original user. This allows one to customise the configuration process for each user, if desired. 

The device attributes that the service can request are the iOS version, WiFi device ID, product type, phone equipment ID, and SIM card Identifier.  

Certificate Enrolment (X.509 Identities and SCEP) - Phase 2
In the enrolment phase, device contacts the CA and obtains a signed X.509 identify cert, which is used for encryption. 
To acquire an identity, a device first generates an asymmetric key and stores it in its keychain. The secret in this keychain can be read only by that specific device
The device then sends it public key to CA and sends back the signed X.509 certificate. This certificate then combined with the private key on device forms the identify.

The above exchange is possible because iOS supports SCEP. SCEP is a communication protocol that provides a networked front end to a private certificate authority. Support for SCEP is provided by a number of CAs and there are complete open source software of certificate authorities with SCEP support. 

Below are the steps in enrolment phase
1. The user accepts the installation of the profile from phase 1 
2. The device looks up the requested attributes, adds the challenge response (if provided), signs the response using Apple’s built in identity and sends it back to the profile distribution service using POST .
3. The server’s profile request handler sends back a configuration profile that instructs the device to enrol using SCEP.
4. The device Enrolls using SCEP, resulting in a valid identity certificate installed on device. 

Device Configuration and Encrypted Profiles (Phase 3)
This is the phase where the actual profile itself is delivered. The profile that is delivered will be customised for the requested device. To provide protection, iOS allows to encrypt the profile so that they can be installed only on single device. 
An encrypted profile is just like a normal profile except the configuration profile is encrypted with the public key associated with the device’s X.509 identity. 

For encryption and and signing, iOS uses the Cryptographic Message Syntax (CMS) a standard that is also used in S/MIME. Payloads are encrypted using PKCS#7 enveloped data. Profiles are signed using PKCS#7 signed data. 

The steps in the device configuration phase are: 

1. The device sends a signed request for the /profile handler again to request the final profile. The request is signed with the identity certificate obtained in the previous step. 
2. The server profile handler sends the final encrypted profile to the device. 

references:

Friday, August 5, 2016

Android, ImageView Does not fill the parent

Below needs to be done so that the ImageView scales appropriately. scaleXY is important 
<imageview android:id="@+id/image_tag&#8221; android:layout_width=" android:layout_height="wrap_content" android:layout_marginleft="20dp" android:layout_marginright="20dp" android:src="@drawable/bg_image&#8221; android:scaleType=" fill_parent="" fitxy=""> </imageview>




references: