Home | History | Annotate | Download | only in gpac
      1 /*
      2  * Copyright (C) 2017 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 /*
     17  * Copyright (c) 2017, The Linux Foundation.
     18  */
     19 
     20 /*
     21  * Copyright 2012 Giesecke & Devrient GmbH.
     22  *
     23  * Licensed under the Apache License, Version 2.0 (the "License");
     24  * you may not use this file except in compliance with the License.
     25  * You may obtain a copy of the License at
     26  *
     27  *      http://www.apache.org/licenses/LICENSE-2.0
     28  *
     29  * Unless required by applicable law or agreed to in writing, software
     30  * distributed under the License is distributed on an "AS IS" BASIS,
     31  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     32  * See the License for the specific language governing permissions and
     33  * limitations under the License.
     34  */
     35 package com.android.se.security.gpac;
     36 
     37 import java.util.ArrayList;
     38 
     39 /**
     40  * Response_ARAC_AID_DO
     41  *
     42  * <p>A list of AIDs containing an AID for each ARA-C.
     43  *
     44  * <p>In response to STORE DATA (Command-Get-ClientAIDs-DO), the ARA-M shall return the AID of each
     45  * of the ARA-Cs currently registered within a Response-ARAC-AID-DO.
     46  */
     47 public class Response_ARAC_AID_DO extends BerTlv {
     48 
     49     public static final int TAG = 0xFF70;
     50 
     51     private ArrayList<AID_REF_DO> mAidDos = new ArrayList<AID_REF_DO>();
     52 
     53     public Response_ARAC_AID_DO(byte[] rawData, int valueIndex, int valueLength) {
     54         super(rawData, TAG, valueIndex, valueLength);
     55     }
     56 
     57     public ArrayList<AID_REF_DO> getAidRefDos() {
     58         return mAidDos;
     59     }
     60 
     61     @Override
     62     /**
     63      * Tag: FF 70
     64      *
     65      * <p>Length: n or 0 If n is equal to zero, then there are no rules to fetch.
     66      *
     67      * <p>Value: AID-REF-DO 1..n or empty AID-REF-DOs can occur several times in a concatenated DO
     68      * chain if several ARA-C instances exist on the SE. The value is empty if no ARA-C instance
     69      * exist.
     70      */
     71     public void interpret() throws ParserException {
     72 
     73         mAidDos.clear();
     74 
     75         byte[] data = getRawData();
     76         int index = getValueIndex();
     77 
     78         if (getValueLength() == 0) {
     79             // No Access rule available for the requested reference.
     80             return;
     81         }
     82 
     83         if (index + getValueLength() > data.length) {
     84             throw new ParserException("Not enough data for Response_ARAC_AID_DO!");
     85         }
     86 
     87         BerTlv temp;
     88         int currentPos = index;
     89         int endPos = index + getValueLength();
     90         do {
     91             temp = BerTlv.decode(data, currentPos);
     92 
     93             AID_REF_DO tempAidDo;
     94 
     95             if (temp.getTag() == AID_REF_DO.TAG
     96                     || temp.getTag() == AID_REF_DO.TAG_DEFAULT_APPLICATION) {
     97                 tempAidDo =
     98                         new AID_REF_DO(data, temp.getTag(), temp.getValueIndex(),
     99                                 temp.getValueLength());
    100                 tempAidDo.interpret();
    101                 mAidDos.add(tempAidDo);
    102             } else {
    103                 // uncomment following line if a more restrictive
    104                 // behavior is necessary.
    105                 // throw new ParserException("Invalid DO in Response_ARAC_AID_DO!");
    106             }
    107             // get AID-REF-DOs as long as data is available.
    108             currentPos = temp.getValueIndex() + temp.getValueLength();
    109         } while (currentPos < endPos);
    110     }
    111 }
    112