Tuesday, April 14, 2015

SIP Authentication Procedure - Part I


SIP provides a stateless, challenge based mechanism for authentication that is based on authentication in HTTP. Any time that a proxy server or UA receive a request, it may challenge the originator to provide assurance of its identity. 

The framework for SIP authentication closely parallels the HTTP (RFC 2617) In particular, the BNF form for auth-scheme, auth-param, challenge, realm, realm-value, and credential is identical  (although the use of “Basic” as a scheme is not permitted) . In SIP, a UAS uses the 401 response to challenge the identify of a UAC. Additionally, registrars and redirect servers may make use of 401. The proxies must make use of 407 response code for the same. The requirements for inclusion of Proxy-Authenticate, Proxy-Authorisation, WWW-Authenticate, and Authorization in various messages are identical to those described in RFC 2617. 

Below are the rules for creating realm string for the operators of user agents or proxy servers. 

1. Realm string must be globally unique. It is recommended to have hostname or domain name. 
2. Realm string should present a human- readable identifier that can be rendered to a user. 

For e.g. 

INVITE sip: bob@biloxi.com SIP/2.0 
Authorisation : Digest realm=“biloxi.com”, <…>

generally SIP authentication is meaningful for a specific realm, a protection domain. Thus for a digest authentication, each such protection domain has its own username and password. If a server does not require authentication or password if may accept a default user name “anonymous”, which has no password (password of “”). Similarly UAC representing many users such as PSTN gateways may have their own device specific user name and password, rather than accounts for a particular users, for their realm. 

ACK and CANCEL are special request that does require special handling. 

UAC creating an ACK message will duplicate all of the authorisation and Proxy-Authorization header field value that appeared in the INVITE to which the ACK corresponds. Servers must not attempt to challenge ACK. 

When UAC receives a challenge, it SHOULD render it to the user the contents of the “realm” parameter in the challenge which appears either in the WWW-Authenticate or Proxy-Authenticate header header field. This is needed if the UAC does not already know the credential for the realm. 

References:



Monday, April 13, 2015

Android Shared Preferences

Saving values 

        Context ctx = AppUtils.getAppContext();
        if(ctx != null && prefKey != null && prefValue != null)
        {
            Log.v(LOG_TAG,"context value exists: "+ctx);
            this.sensorPreferenceStorage = ctx.getSharedPreferences(PREFERNCE_STORE,  AppUtils.getAppContext().MODE_PRIVATE);
            Log.v(LOG_TAG,"preference storage is :"+this.sensorPreferenceStorage);
            SharedPreferences.Editor editor = this.sensorPreferenceStorage.edit();
            editor.putString(prefKey,prefValue);
            editor.commit();
        }

Reading value 

        Context ctx = AppUtils.getAppContext();
        Log.v(LOG_TAG,"getting the Sensor preferece value for key:"+preferenceKey);
        if(ctx != null && preferenceKey != null)
        {
            this.sensorPreferenceStorage = ctx.getSharedPreferences(PREFERNCE_STORE,  AppUtils.getAppContext().MODE_PRIVATE);
            String strVal = this.sensorPreferenceStorage.getString(preferenceKey, null);
            Log.v(LOG_TAG,"value retrieved is:"+strVal);
            return strVal;
        }

References: 

Thursday, April 9, 2015

Java Using Reflection to Invoke method.

Below code is an example for it

import java.lang.reflect.Method;
import java.lang.reflect.Type;

public class MethodReflection {
    
    public static void main(String a[]) throws Exception
    {
        
        RuleEvaluator evaluator = new RuleEvaluator();
        Method[] allMethods = evaluator.getClass().getDeclaredMethods();
        for (Method m : allMethods) {
            String mname = m.getName();
            if(mname.startsWith("difference"))
            {
                Type[] pType = m.getGenericParameterTypes();
                for (int i = 0; i < pType.length; i++)
                {
                    System.out.println("pType is :"+pType[i]);
                }
                Object o = m.invoke(evaluator,1,2,3,4);
                System.out.println("difference is:"+(Integer)o);
            }
        }
    }
}

class RuleEvaluator
{
    public int difference(int srcLat, int srcLon, int dstLon, int dstLat)
    {
        System.out.println("--Invoking difference --");
        return srcLat - srcLon - dstLon - dstLon;
    }
    
    public int total(int one, int two)
    {
        return 10;
    }
    
    public int sumOf(int[] args)
    {
        return 10;
    }


}

References:
https://docs.oracle.com/javase/tutorial/reflect/member/methodInvocation.html

Sunday, April 5, 2015

A look at think app blog about apple watch

this tutorial basically walk through the Apple’s Sample App for Apple Watch, Watchkit Catalog. 

Watch kit acts a a conduit that connects to the watch kit extension which resides in the iPhone app and orchastrates the watch app interface. 
When the user interacts with the watch interface, WatchKit signals to the paired iPhone and Watchkit extension then creates the objects at runtime needed to manage 
the appropriate screens the user interacts with. 

The watch kit architecture is like below 



If one need to add a watch kit app to a project, below step can be followed 

file -> New > Target -> and then select Apple Watch. 

On this screen we can select whether we need glance or Notification. 

Notification can be two, static and dynamic.

Once we create glance or notification, we can run that by selecting the executable accordingly by creating a new target. 

References:

WatchKit FAQ Items


This is a summary of few main points got in to me about the watch kit after going through the article in reference. 

How many Apple watches can be paired with iPhone? 
one Apple watch at a time. 

Can one pair Apple watch with iPad? 
No. 

Can iPhone app wake up watch extension and watch app?
No. Only watch kit extension can request System to launch the iPhone app which happens in the background and not the other way around. 

Can third party app make phone calls from a watch app? 
No. There is no third party api that lets one to initiate a phone call directly from watch kit extension. Since the companion app cannot be brought to foreground either, all the calls to the openURL are ignored silently. 

Can a watch app access hardware sensors such as heartbeat sensors and other sensors on the watch from watch app? 
No, there is no API to access hardware sensors on the watch from Watch app at this time. 

What are the difference between Short-look, long-look, static and dynamic notifications? 
Short-Look : a short look notification is provided by the system. Similar to a notification that appears on the iPhone at the banner, user don’t have any control over this short look notification. A short look notification displays App icon, app name and the title string from the notifications payload. When the notification arrives, system displays the notification and if the user raise the wrist, it get converted to a long-look notification after a slight pause. 

Long-Look. A long look notification can be either static or dynamic. 

Static: A static notification includes a single label that is populated automatically using the notifications payload. One can create a static notification scene in the watch app’s storyboard, but can’t really customise it beyond changing the color of the label and title. 

Dynamic: Dynamic notification require one to subclass WKUserInterfaceController. It is instantiated from the storyboard, and one can provide own custom interface. Note that there is no guarantee that a dynamic notification interface will be displayed. For e.g. if the watch battery is low, system may decide to show a static notification interface instead of dynamic one in the interest to preserve the battery. 

To note, one cannot create and add subviews dynamically in the app watch app, it is possible to hide and show the ui elements those are already in the story board. 

Is there UIActivityIndicator or UIAlertViewController? 
No, but one can display WKInterfaceCotnroller modally. One can work around the activity indicator by providing a series of images that is necessary for creating animation. 

Can one use Coregraphics to generate image dynamically and then use them in a watch app? Can they be cached on the watch? 
YEs, but the composition of those images should be happening in the iPhone watch kit extension. Once we have rendered the core graphics drawing context into an image, one can cache that on to the watch app by calling addCachedImage() from WKInterfaceDevice 

Can one create Custom Views in the Apple Watch? Can the public interface be customised ? 
No. Once cannot customize any views. Watch kit only support certain native interface elements. 

How does the Apple watch communicate with the iPhone? 
The Apple watch leverage both bluetooth LE or Wifi technologies to communicate with its paired phone. The exact nature of communication and its implementation is opaque to both users and developers. 

Can one use Apple watch while in Airplane mode? 
Yes. If bluetooth and WiFi can be turned on while in airplane mode, Apple watch can communicate with the phone. 

What happens when watch app cannot communicate with the paired iPhone ? 
The app won’t run and if running already, it will be suspended. 

In the Watchkit extension, didDeactivate() method will be called to indicate the loss of connectivity. Also, a red icon will be displayed on the status bar on the watch to indicate the loss of connectivity. 

How can a watch app communicate with its companion iPhone app? 
There are various techniques for this, one being watch app writes the data in a shared container and notifies the iPhone app. 
Another technique is to pass the data into the iPhone app as a dictionary, but this can be only initiated by the watch app. There is a single API for the watch kit extension; call the parent Application openParentApplication(userInfo:reply) of WKInterfaceController, as shown in the following snippet. 

to receive this communication, the companion app must implement application(:handleWatchKitExtensionRequest:reply)
If the companion app is in the background, then it will be waken up to process this. Companion app can pass the data back as well allowing the watch app to be able to process the response. 

  
Referencnes:

Inspecting WatchKit Catalog app.

there seems to be main three components :

1. Apple Watch Settings App 
2. Apple Watch app on the device (Watchkit Catalog)
3. Apple watch app running on the watch  (Watchkit Catalog WatchKit App)
4. Apple watch app extension (Watchkit Catalog Watchkit Extension)

WatchKit Catalog WatchKit App doesn’t seem to be doing much of the things exccept that it defines the ui for the app running on the device. The watckit extension does the major tasks which get invoked as the user interact with the app ui on the watch device. 

The Watch app running on the device is having interface.storyboard which defines all of the ui for the app. 

1. Opening the Watch Settings app (“Apple Watch”) shown the app installed on the watch. User can select each app listed in this app and select whether to show up on the Apple Watch device or not. 

2. Apple Watch app on the device. 
This app did not have much code except the Main xib file that contained bit of information on how to use the app. 

The interface.storyboard gives much detail of all the screens present in the Apple watch app.  

Upon running the app, AAPLNotificationController willActivate get called.  

Many of the Ui components are similar to the ones in 

WKInterfaceTable, => Table 
WKInterfaceLabel  => Label 
WKInterfaceButton => Button 
WKInterfaceSwitch => Switch 
WKInterfaceSlider => slider
WKInterfaceImage => image
WKInterfaceMap => Map 
WKInterfaceDevice => Gets device details 


References: 

Contact Header in SIP Request

Contact header provides a meaning which depends on the type of request or response it is in. 
A contact header may provide a display name, a URI with URI parameters and header parameters 

the q and expires are parameters in the in the Contact header. These parameters are contained in a REGISTER request. It is upto the specification if it want to define additional parameters. 

When the header field contains a display name, the URI including all URI parameters are enclosed in “<“ and “>”. If no < and > is present, then all parameters after the URI are header parameters not uri parameters. The display name can be tokens or quoted string if a large character set is desired. 

For e.g. in the Contact header below, 

Contact: ;+sip.custom=“value”;+sip.9193023016-socktest3
tranport=tcp is a contact uri parameter, while + sip.custom =“value” is a contact parameter. 

Even if the display-name is empty, the “name-addr” form MUST be used if the “addr-spec“ contains comma or semicolon or question mark 

The rule for parsing display name, uri and uri parameters also applies to the headers To and From. 

The compact form of the Contact header is “m” (moved) 

Some of the samples are: 
Contact: "Mr. Watson"
         ;q=0.7; expires=3600,
         "Mr. Watson" ;q=0.1
      m: ;expires=60


References: