2 * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
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.
18 #include "RegReqTlvEncoder.h"
20 #include "AsmHelper.h"
21 #include "AuthnrTypes.h"
23 RegAssertionTlvEncoder::RegAssertionTlvEncoder(void) {}
26 RegAssertionTlvEncoder::encode(const void *authData)
28 _INFO("RegAssertionTlvEncoder::encode start");
30 RET_IF_FAIL(authData != NULL, NULL);
32 _INFO("RegAssertionTlvEncoder::encode start with valid ip");
35 RegisterReq *getRegReq = (RegisterReq*)authData;
36 _INFO("RegAssertionTlvEncoder::encode 2");
38 tlv_builder_s *builder = tlv_builder_create();
39 _INFO("RegAssertionTlvEncoder::encode 3");
41 tlv_builder_start_composite(builder, TAG_UAFV1_REGISTER_CMD);
42 _INFO("RegAssertionTlvEncoder::encode 4");
44 tlv_builder_add_int8(builder, TAG_AUTHENTICATOR_INDEX, getRegReq->authIdx);
45 _INFO("RegAssertionTlvEncoder::encode 5");
47 if (getRegReq->appId != NULL) {
48 tlv_builder_add_string(builder, TAG_APPID, getRegReq->appId);
49 _INFO("RegAssertionTlvEncoder::encode 6");
52 tlv_builder_add_buffer(builder, TAG_FINAL_CHALLENGE, getRegReq->fch);
53 _INFO("RegAssertionTlvEncoder::encode 7");
55 tlv_builder_add_string(builder, TAG_USERNAME, getRegReq->userName);
56 _INFO("RegAssertionTlvEncoder::encode 8");
58 tlv_builder_add_int16(builder, TAG_ATTESTATION_TYPE, getRegReq->attType);
59 _INFO("RegAssertionTlvEncoder::encode 9");
61 tlv_builder_add_buffer(builder, TAG_KEYHANDLE_ACCESS_TOKEN, getRegReq->khAccessToken);
62 _INFO("RegAssertionTlvEncoder::encode 10");
64 if (getRegReq->userVToken != NULL) {
65 tlv_builder_add_string(builder, TAG_USERVERIFY_TOKEN, getRegReq->userVToken);
66 _INFO("RegAssertionTlvEncoder::encode 11");
69 tlv_builder_end_composite(builder);
70 _INFO("RegAssertionTlvEncoder::encode 12");
72 Buffer *buff = tlv_builder_get_buffer(builder);
79 RegAssertionTlvEncoder::decode(const unsigned char *rawData)
81 _INFO("RegAssertionInfoTlvEncoder::decode start");
82 RET_IF_FAIL(rawData != NULL, NULL);
84 tlv_s* root = tlv_decode(rawData);
85 RET_IF_FAIL(root != NULL, NULL);
86 if (root->tag != TAG_UAFV1_REGISTER_CMD) {
87 SAFE_DELETE(root->val);
93 int endIter = rawIter + root->len;
95 tlv_s* child = tlv_decode(root->val);
97 SAFE_DELETE(root->val);
103 bool foundMember = false;
104 RegisterReq *getRegReqInfo = ALLOC(RegisterReq);
108 case TAG_AUTHENTICATOR_INDEX:
111 int *pauthIdx = (int*)__intTlvEncoder.decode(rawData + rawIter);
112 getRegReqInfo->authIdx = *pauthIdx;
113 _INFO("authIdx = [%d]", getRegReqInfo->authIdx);
114 SAFE_DELETE(pauthIdx);
120 getRegReqInfo->appId = (char*)__strTlvEncoder.decode(rawData + rawIter);
121 _INFO("appId = [%s]", getRegReqInfo->appId);
125 case TAG_FINAL_CHALLENGE:
127 getRegReqInfo->fch = (Buffer*)__buffTlvEncoder.decode(rawData + rawIter);
133 getRegReqInfo->userName = (char*)__strTlvEncoder.decode(rawData + rawIter);
134 _INFO("userName = [%s]", getRegReqInfo->userName);
138 case TAG_ATTESTATION_TYPE:
141 int *pattType = (int*)__intTlvEncoder.decode(rawData + rawIter);
142 getRegReqInfo->attType = *pattType;
143 _INFO("attType = [%d]", getRegReqInfo->attType);
144 SAFE_DELETE(pattType);
148 case TAG_KEYHANDLE_ACCESS_TOKEN:
150 getRegReqInfo->khAccessToken = (Buffer*)__buffTlvEncoder.decode(rawData + rawIter);
151 if (getRegReqInfo->khAccessToken == NULL) {
152 SAFE_DELETE(root->val);
154 SAFE_DELETE(child->val);
156 SAFE_DELETE(getRegReqInfo);
159 _INFO("khAccessToken = [%s]", getRegReqInfo->khAccessToken->data);
163 case TAG_USERVERIFY_TOKEN:
165 getRegReqInfo->userVToken = (char*)__strTlvEncoder.decode(rawData + rawIter);
166 _INFO("userVToken = [%s]", getRegReqInfo->userVToken);
175 rawIter = rawIter + 2 + 2 + child->len;
176 if (rawIter >= endIter)
179 SAFE_DELETE(child->val);
181 child = tlv_decode(rawData + rawIter);
183 SAFE_DELETE(root->val);
186 SAFE_DELETE(getRegReqInfo);
191 SAFE_DELETE(child->val);
193 SAFE_DELETE(root->val);
196 if (foundMember == false) {
197 SAFE_DELETE(getRegReqInfo->khAccessToken);
198 SAFE_DELETE(getRegReqInfo->fch);
204 _INFO("RegAssertionInfoTlvEncoder::decode end");
205 return getRegReqInfo;