summaryrefslogtreecommitdiff
path: root/mobicore/rootpa/Code/Android/app/src/com/gd/mobicore/pa/service/ProvisioningService.java
diff options
context:
space:
mode:
Diffstat (limited to 'mobicore/rootpa/Code/Android/app/src/com/gd/mobicore/pa/service/ProvisioningService.java')
-rw-r--r--mobicore/rootpa/Code/Android/app/src/com/gd/mobicore/pa/service/ProvisioningService.java206
1 files changed, 112 insertions, 94 deletions
diff --git a/mobicore/rootpa/Code/Android/app/src/com/gd/mobicore/pa/service/ProvisioningService.java b/mobicore/rootpa/Code/Android/app/src/com/gd/mobicore/pa/service/ProvisioningService.java
index 9aea5fb..0fa9cca 100644
--- a/mobicore/rootpa/Code/Android/app/src/com/gd/mobicore/pa/service/ProvisioningService.java
+++ b/mobicore/rootpa/Code/Android/app/src/com/gd/mobicore/pa/service/ProvisioningService.java
@@ -3,29 +3,29 @@ Copyright © Trustonic Limited 2013
All rights reserved.
-Redistribution and use in source and binary forms, with or without modification,
+Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the Trustonic Limited nor the names of its contributors
- may be used to endorse or promote products derived from this software
+ 3. Neither the name of the Trustonic Limited nor the names of its contributors
+ may be used to endorse or promote products derived from this software
without specific prior written permission.
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
-BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
-OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
*/
@@ -65,32 +65,32 @@ public class ProvisioningService extends BaseService {
private static final int PROVISIONING_UID_FOR_LOCK=0x11110000;
private static final int LONG_SIZE=8;
- private final RootPAServiceIfc.Stub mBinder = new ServiceIfc();
-
- // using this instead of anonymous inner class in order to allow call to some of the private methods we define here
+ private final RootPAServiceIfc.Stub mBinder = new ServiceIfc();
+
+ // using this instead of anonymous inner class in order to allow call to some of the private methods we define here
private class ServiceIfc extends RootPAServiceIfc.Stub {
public ServiceIfc(){
super();
}
-
+
private CommonPAWrapper commonPAWrapper(){
return ProvisioningService.this.commonPAWrapper();
}
-
+
public CommandResult executeCmpCommands(int uid, List<CmpCommand> commands, List<CmpResponse> responses){
- Log.d(TAG,">>RootPAServiceIfc.Stub.executeCmpCommands "+commands+" "+responses);
+ Log.d(TAG,">>RootPAServiceIfc.Stub.executeCmpCommands "+commands+" "+responses);
if(commands==null||responses==null){ // having null out variable leads to null pointer exception in the client, however we still want to do checking so that there is not unncessary execution of the following code
- Log.d(TAG,"RootPAServiceIfc.Stub.executeCmpCommands, illegal argument");
+ Log.d(TAG,"RootPAServiceIfc.Stub.executeCmpCommands, illegal argument");
return new CommandResult(CommandResult.ROOTPA_ERROR_ILLEGAL_ARGUMENT);
- }
-
+ }
+
if(locked(uid)){
return new CommandResult(CommandResult.ROOTPA_ERROR_LOCK);
}
-
+
int ret=CommandResult.ROOTPA_OK;
try{
ret=commonPAWrapper().executeCmpCommands(uid, commands, responses);
@@ -102,17 +102,17 @@ public class ProvisioningService extends BaseService {
Log.d(TAG,"<<RootPAServiceIfc.Stub.executeCmpCommands");
return new CommandResult(ret);
}
-
+
public CommandResult isRootContainerRegistered(BooleanResult result){
- Log.d(TAG,">>RootPAServiceIfc.Stub.isRootContainerRegistered");
+ Log.d(TAG,">>RootPAServiceIfc.Stub.isRootContainerRegistered");
if(result==null){ // having null out variable leads to null pointer exception in the client, however we stll want to do checking so that there is not unncessary execution of the following code
Log.d(TAG,"RootPAServiceIfc.Stub.isRootContainerRegistered result null");
return new CommandResult(CommandResult.ROOTPA_ERROR_ILLEGAL_ARGUMENT);
- }
-
+ }
+
int internalUidForLock=new Random().nextInt();
-
+
if(!ProvisioningService.this.acquireLock(internalUidForLock, false).isOk())
{
return new CommandResult(CommandResult.ROOTPA_ERROR_LOCK);
@@ -126,7 +126,7 @@ public class ProvisioningService extends BaseService {
Log.e(TAG,"CommonPAWrapper().isRootContainerRegistered exception: ", e);
ret=CommandResult.ROOTPA_ERROR_INTERNAL;
}
- result.setResult(isRegistered[0]);
+ result.setResult(isRegistered[0]);
CommandResult res=ProvisioningService.this.releaseLock(internalUidForLock, false);
if(!res.isOk()){
@@ -134,14 +134,14 @@ public class ProvisioningService extends BaseService {
// this return code is not returned to the client since
// the command may have succeeded and there is just something wrong with the lock
// we leave it the the next command if the problem remains
- }
+ }
- Log.d(TAG,"<<RootPAServiceIfc.Stub.isRootContainerRegistered");
+ Log.d(TAG,"<<RootPAServiceIfc.Stub.isRootContainerRegistered");
return new CommandResult(ret);
}
public CommandResult isSPContainerRegistered(SPID spid, BooleanResult result){
- Log.d(TAG,">>RootPAServiceIfc.Stub.isSPContainerRegistered");
+ Log.d(TAG,">>RootPAServiceIfc.Stub.isSPContainerRegistered");
if(spid==null || result==null){ // having null out variable leads to null pointer exception in the client, however we still want to do checking so that there is not unncessary execution of the following code
Log.d(TAG,"RootPAServiceIfc.Stub.isSPContainerRegistered spid "+spid+" result "+result);
@@ -171,15 +171,15 @@ public class ProvisioningService extends BaseService {
// this return code is not returned to the client since
// the command may have succeeded and there is just something wrong with the lock
// we leave it the the next command if the problem remains
- }
+ }
- Log.d(TAG,"<<RootPAServiceIfc.Stub.isSPContainerRegistered ");
+ Log.d(TAG,"<<RootPAServiceIfc.Stub.isSPContainerRegistered ");
return new CommandResult(ret);
}
public CommandResult getVersion(Version version){
- Log.d(TAG,">>RootPAServiceIfc.Stub.getVersion");
+ Log.d(TAG,">>RootPAServiceIfc.Stub.getVersion");
int internalUidForLock=new Random().nextInt();
if(!ProvisioningService.this.acquireLock(internalUidForLock, false).isOk())
@@ -196,7 +196,7 @@ public class ProvisioningService extends BaseService {
try{
ret=commonPAWrapper().getVersion(productId, keys, values);
if(ret == CommandResult.ROOTPA_OK && (keys.size() != values.size())){
- ret=CommandResult.ROOTPA_ERROR_INTERNAL;
+ ret=CommandResult.ROOTPA_ERROR_INTERNAL;
}
}catch(Exception e){
Log.e(TAG,"CommonPAWrapper().getVersion exception: ", e);
@@ -219,15 +219,15 @@ public class ProvisioningService extends BaseService {
// this return code is not returned to the client since
// the command may have succeeded and there is just something wrong with the lock
// we leave it the the next command if the problem remains
- }
+ }
- Log.d(TAG,"<<RootPAServiceIfc.Stub.getVersion "+ret);
+ Log.d(TAG,"<<RootPAServiceIfc.Stub.getVersion "+ret);
return new CommandResult(ret);
}
public CommandResult getDeviceId(SUID suid){
- Log.d(TAG,">>RootPAServiceIfc.Stub.getDeviceId");
+ Log.d(TAG,">>RootPAServiceIfc.Stub.getDeviceId");
int internalUidForLock=new Random().nextInt();
if(!ProvisioningService.this.acquireLock(internalUidForLock, false).isOk())
@@ -251,40 +251,40 @@ public class ProvisioningService extends BaseService {
// this return code is not returned to the client since
// the command may have succeeded and there is just something wrong with the lock
// we leave it the the next command if the problem remains
- }
+ }
- Log.d(TAG,"<<RootPAServiceIfc.Stub.getDeviceId");
+ Log.d(TAG,"<<RootPAServiceIfc.Stub.getDeviceId");
return new CommandResult(ret);
}
public CommandResult acquireLock(int uid){
return ProvisioningService.this.acquireLock(uid, true);
}
-
+
public CommandResult releaseLock(int uid){
return ProvisioningService.this.releaseLock(uid, true);
}
-
+
public CommandResult doProvisioning(int uid, SPID spid){
- Log.d(TAG,">>RootPAServiceIfc.Stub.doProvisioning");
+ Log.d(TAG,">>RootPAServiceIfc.Stub.doProvisioning");
int ret=CommandResult.ROOTPA_OK;
if(spid==null){ // having null out variable leads to null pointer exception in the client, however we still want to do checking so that there is not unncessary execution of the following code
Log.d(TAG,"RootPAServiceIfc.Stub.doProvisioning spid==null");
return new CommandResult(CommandResult.ROOTPA_ERROR_ILLEGAL_ARGUMENT);
- }
-
- // we do not use uid here since we do not want to let the client to released the lock, it is done
- // internally at CommonPAWrapper.java when sending Intents.
-
+ }
+
+ // we do not use uid here since we do not want to let the client to released the lock, it is done
+ // internally at CommonPAWrapper.java when sending Intents.
+
int tmpSuid=uid+PROVISIONING_UID_FOR_LOCK+new Random().nextInt();
if(!ProvisioningService.this.acquireLock(tmpSuid, false).isOk()){
return new CommandResult(CommandResult.ROOTPA_ERROR_LOCK);
}
doProvisioningLockSuid_=tmpSuid;
-
+
try{
setupProxy();
ret=commonPAWrapper().doProvisioning(uid, spid.spid(), se_);
@@ -292,12 +292,12 @@ public class ProvisioningService extends BaseService {
Log.d(TAG,"CommonPAWrapper()).doProvisioning failed "+e);
ret=CommandResult.ROOTPA_ERROR_INTERNAL;
}
-
- Log.d(TAG,"CommonPAWrapper()).doProvisioning returned "+ret);
+
+ Log.d(TAG,"CommonPAWrapper()).doProvisioning returned "+ret);
if(ret!=CommandResult.ROOTPA_OK){
if(!ProvisioningService.this.releaseLock(doProvisioningLockSuid_, false).isOk()){
Log.e(TAG,"releasing lock failed after doProvisioning returned an error");
- }
+ }
doProvisioningLockSuid_=0;
}
@@ -306,26 +306,26 @@ public class ProvisioningService extends BaseService {
}
public CommandResult getSPContainerStructure(SPID spid, SPContainerStructure cs){
- Log.d(TAG,">>RootPAServiceIfc.Stub.getSPContainerStructure");
+ Log.d(TAG,">>RootPAServiceIfc.Stub.getSPContainerStructure");
if(spid==null||cs==null){ // having null out variable leads to null pointer exception in the client, however we still want to do checking so that there is not unncessary execution of the following code
return new CommandResult(CommandResult.ROOTPA_ERROR_ILLEGAL_ARGUMENT);
- }
-
+ }
+
int internalUidForLock=new Random().nextInt();
if(!ProvisioningService.this.acquireLock(internalUidForLock, false).isOk())
{
return new CommandResult(CommandResult.ROOTPA_ERROR_LOCK);
}
-
+
int ret=CommandResult.ROOTPA_OK;
final int CONTAINER_STATE_IDX=0;
- final int NUMBER_OF_TLTS_IDX=1;
+ final int NUMBER_OF_TLTS_IDX=1;
final int NUMBER_OF_ELEMENTS=2;
final int MAX_NUMBER_OF_TRUSTLETS=16;
final int UUID_LENGTH=16;
-
+
int[] ints = new int[NUMBER_OF_ELEMENTS];
int[] trustletStates = new int[MAX_NUMBER_OF_TRUSTLETS];
byte[][] uuidArray = new byte[MAX_NUMBER_OF_TRUSTLETS][];
@@ -338,15 +338,15 @@ public class ProvisioningService extends BaseService {
}
if(ret==CommandResult.ROOTPA_OK){
-
+
SPContainerState s=mapSpContainerState(ints[CONTAINER_STATE_IDX]);
- cs.setState(s);
+ cs.setState(s);
if (s == SPContainerState.UNDEFINED){
- ret=CommandResult.ROOTPA_ERROR_INTERNAL;
+ ret=CommandResult.ROOTPA_ERROR_INTERNAL;
}
-
+
for(int i=0; i<ints[NUMBER_OF_TLTS_IDX]; i++){
- byte[] msBytes=new byte[LONG_SIZE];
+ byte[] msBytes=new byte[LONG_SIZE];
System.arraycopy(uuidArray[i], 0, msBytes, 0, LONG_SIZE);
BigInteger mostSignificant=new BigInteger(msBytes);
@@ -355,16 +355,16 @@ public class ProvisioningService extends BaseService {
BigInteger leastSignificant=new BigInteger(lsBytes);
Log.d(TAG,"UUID: ls ms"+leastSignificant+" "+mostSignificant);
-
+
TrustletContainerState ts=mapTltContainerState(trustletStates[i]);
if (ts == TrustletContainerState.UNDEFINED){
- ret=CommandResult.ROOTPA_ERROR_INTERNAL;
+ ret=CommandResult.ROOTPA_ERROR_INTERNAL;
}
cs.add(new TrustletContainer(new UUID(mostSignificant.longValue(), leastSignificant.longValue()), ts));
}
-
+
}else if (ret==CommandResult.ROOTPA_ERROR_INTERNAL_NO_CONTAINER){
- cs.setState(SPContainerState.DOES_NOT_EXIST);
+ cs.setState(SPContainerState.DOES_NOT_EXIST);
ret=CommandResult.ROOTPA_OK;
}
@@ -374,16 +374,16 @@ public class ProvisioningService extends BaseService {
// this return code is not returned to the client since
// the command may have succeeded and there is just something wrong with the lock
// we leave it the the next command if the problem remains
- }
+ }
- Log.d(TAG,"<<RootPAServiceIfc.Stub.getSPContainerStructure");
- return new CommandResult(ret);
+ Log.d(TAG,"<<RootPAServiceIfc.Stub.getSPContainerStructure");
+ return new CommandResult(ret);
}
-
+
public CommandResult getSPContainerState(SPID spid, SPContainerStateParcel state){
- Log.d(TAG,">>RootPAServiceIfc.Stub.getSPContainerState");
+ Log.d(TAG,">>RootPAServiceIfc.Stub.getSPContainerState");
if(spid==null||state==null){ // having null out variable leads to null pointer exception in the client, however we still want to do checking so that there is not unncessary execution of the following code
return new CommandResult(CommandResult.ROOTPA_ERROR_ILLEGAL_ARGUMENT);
@@ -405,17 +405,17 @@ public class ProvisioningService extends BaseService {
ret=CommandResult.ROOTPA_ERROR_INTERNAL;
}
- Log.d(TAG,"RootPAServiceIfc.Stub.getSPContainerState received " + containerState[0] + " "+ ret);
-
+ Log.d(TAG,"RootPAServiceIfc.Stub.getSPContainerState received " + containerState[0] + " "+ ret);
+
if(ret==CommandResult.ROOTPA_OK){
-
+
SPContainerState s=mapSpContainerState(containerState[0]);
- state.setEnumeratedValue(s);
+ state.setEnumeratedValue(s);
if (s == SPContainerState.UNDEFINED){
- ret=CommandResult.ROOTPA_ERROR_INTERNAL;
+ ret=CommandResult.ROOTPA_ERROR_INTERNAL;
}
}else if (ret==CommandResult.ROOTPA_ERROR_INTERNAL_NO_CONTAINER){
- state.setEnumeratedValue(SPContainerState.DOES_NOT_EXIST);
+ state.setEnumeratedValue(SPContainerState.DOES_NOT_EXIST);
ret=CommandResult.ROOTPA_OK;
}
@@ -425,13 +425,31 @@ public class ProvisioningService extends BaseService {
// this return code is not returned to the client since
// the command may have succeeded and there is just something wrong with the lock
// we leave it the the next command if the problem remains
- }
+ }
- Log.d(TAG,"<<RootPAServiceIfc.Stub.getSPContainerState");
+ Log.d(TAG,"<<RootPAServiceIfc.Stub.getSPContainerState");
return new CommandResult(ret);
}
+ public CommandResult storeTA(SPID spid, byte[] uuid, byte[] taBinary){
+ Log.d(TAG,">>RootPAServiceIfc.Stub.storeTA");
+ if(spid==null||uuid==null||taBinary==null|| taBinary.length == 0 || spid.spid()==0){ // having null out variable leads to null pointer exception in the client, however we still want to do checking so that there is not unncessary execution of the following code
+ return new CommandResult(CommandResult.ROOTPA_ERROR_ILLEGAL_ARGUMENT);
+ }
+
+ int ret=CommandResult.ROOTPA_OK;
+ try{
+ ret=commonPAWrapper().storeTA(spid.spid(), uuid, taBinary);
+ }catch(Exception e){
+ Log.e(TAG,"CommonPAWrapper().storeTA exception: ", e);
+ ret=CommandResult.ROOTPA_ERROR_INTERNAL;
+ }
+
+ Log.d(TAG,"<<RootPAServiceIfc.Stub.storeTA");
+ return new CommandResult(ret);
+ }
+
private final static int MC_CONT_STATE_UNREGISTERED=0;
private final static int MC_CONT_STATE_REGISTERED=1;
private final static int MC_CONT_STATE_ACTIVATED=2;
@@ -449,13 +467,13 @@ public class ProvisioningService extends BaseService {
state=TrustletContainerState.ACTIVATED;
break;
case MC_CONT_STATE_SP_LOCKED:
- state=TrustletContainerState.SP_LOCKED;
+ state=TrustletContainerState.SP_LOCKED;
break;
default:
Log.e(TAG,"mapTltContainerState returning undefined: "+ containerState);
- state=TrustletContainerState.UNDEFINED;
+ state=TrustletContainerState.UNDEFINED;
break;
- }
+ }
return state;
}
@@ -472,17 +490,17 @@ public class ProvisioningService extends BaseService {
state=SPContainerState.ACTIVATED;
break;
case MC_CONT_STATE_ROOT_LOCKED:
- state=SPContainerState.ROOT_LOCKED;
+ state=SPContainerState.ROOT_LOCKED;
break;
case MC_CONT_STATE_SP_LOCKED:
- state=SPContainerState.SP_LOCKED;
+ state=SPContainerState.SP_LOCKED;
break;
case MC_CONT_STATE_ROOT_SP_LOCKED:
- state=SPContainerState.ROOT_SP_LOCKED;
+ state=SPContainerState.ROOT_SP_LOCKED;
break;
default:
Log.e(TAG,"mapSpContainerState returning undefined: "+ containerState);
- state=SPContainerState.UNDEFINED;
+ state=SPContainerState.UNDEFINED;
break;
}
return state;
@@ -502,10 +520,10 @@ public class ProvisioningService extends BaseService {
}
public void onDestroy(){
- super.onDestroy();
+ super.onDestroy();
Log.d(TAG,"ProvisioningService being destroyed");
}
-
+
@Override
public IBinder onBind(Intent intent){
try{
@@ -514,7 +532,7 @@ public class ProvisioningService extends BaseService {
Log.i(TAG,"ProvisioningService something wrong in the given ip "+e );
}
- try{
+ try{
Log.setLoggingLevel(intent.getIntExtra("LOG",0));
}catch(Exception e){
Log.i(TAG,"ProvisioningService something wrong in the given logging level "+e );
@@ -527,6 +545,6 @@ public class ProvisioningService extends BaseService {
@Override
public int onStartCommand(Intent i, int flags, int startid){
Log.d(TAG,"ProvisioningService starting");
- return START_STICKY;
+ return START_STICKY;
}
}