2 * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 /* standard library header */
19 /* SLP library header */
23 #include "PKCS15ODF.h"
24 #include "SimpleTLV.h"
25 #include "NumberStream.h"
27 namespace smartcard_service_api
29 static const unsigned int ODF_FID = 0x3150;
31 static const unsigned int TAG_DODF = (unsigned int)0xA7;
32 static const unsigned int TAG_CDF = (unsigned int)0xA5;
34 PKCS15ODF::PKCS15ODF(Channel *channel) :
35 PKCS15Object(channel), cdf(NULL), dodf(NULL)
39 if ((ret = select(ODF_FID)) >= SCARD_ERROR_OK) {
40 ByteArray odfData, extra;
42 _DBG("response : %s", selectResponse.toString().c_str());
44 if ((ret = readBinaryAll(0, odfData)) == 0) {
45 _DBG("odfData : %s", odfData.toString().c_str());
49 _ERR("readBinary failed, [%d]", ret);
52 _ERR("select failed, [%d]", ret);
56 PKCS15ODF::PKCS15ODF(Channel *channel, const ByteArray &selectResponse) :
57 PKCS15Object(channel, selectResponse), dodf(NULL)
62 if ((ret = readBinaryAll(0, odfData)) == 0) {
63 _DBG("odfData : %s", odfData.toString().c_str());
67 _ERR("readBinary failed, [%d]", ret);
71 PKCS15ODF::~PKCS15ODF()
80 bool PKCS15ODF::parseData(const ByteArray &data)
85 while (tlv.decodeTLV())
95 dodf = PKCS15Object::getOctetStream(tlv.getValue());
97 _DBG("path : %s", dodf.toString().c_str());
99 pair<unsigned int, ByteArray> newPair(tlv.getTag(), dodf);
100 dataList.insert(newPair);
110 tokeninfo = PKCS15Object::getOctetStream(tlv.getValue());
112 _DBG("path : %s", tokeninfo.toString().c_str());
114 pair<unsigned int, ByteArray> newPair(tlv.getTag(), tokeninfo);
115 dataList.insert(newPair);
120 _DBG("Unknown tlv : t [%X], l [%d], v %s",
121 tlv.getTag(), tlv.size(), tlv.getValue().toString().c_str());
126 _INFO("dataList.size() = %d", dataList.size());
131 PKCS15DODF *PKCS15ODF::getDODF()
133 map<unsigned int, ByteArray>::iterator item;
136 item = dataList.find(TAG_DODF);
137 if (item != dataList.end()) {
138 NumberStream num(item->second);
139 unsigned int fid = num.getLittleEndianNumber();
141 _DBG("dodf fid [%X]", fid);
143 dodf = new PKCS15DODF(fid, channel);
144 if (dodf != NULL && dodf->isClosed() == true) {
145 _ERR("failed to open DODF");
151 _ERR("[%02X] is not found. total [%d]", TAG_DODF, dataList.size());
155 _DBG("dodf [%p]", dodf);
160 PKCS15CDF *PKCS15ODF::getCDF()
162 map<unsigned int, ByteArray>::iterator item;
165 item = dataList.find(TAG_CDF);
166 if (item != dataList.end()) {
167 NumberStream num(item->second);
168 unsigned int fid = num.getLittleEndianNumber();
170 _DBG("cdf fid [%X]", fid);
172 cdf = new PKCS15CDF(fid, channel);
173 if (cdf != NULL && cdf->isClosed() == true) {
174 _ERR("failed to open CDF");
180 _ERR("[%02X] is not found. total [%d]", TAG_CDF, dataList.size());
184 _DBG("cdf [%p]", cdf);
188 } /* namespace smartcard_service_api */