4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: JuHak Park <juhaki.park@samsung.com>,
7 * JuneHyuk Lee <junhyuk7.lee@samsung.com>,
8 * SunBong Ha <sunbong.ha@samsung.com>
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
28 * For any sort of issue you concern as to this software,
29 * you may use following point of contact.
30 * All resources contributed on this software
31 * are orinigally written by S-Core Inc., a member of Samsung Group.
33 * SeongWon Shim <seongwon.shim@samsung.com>
39 * @brief This file is the source file of implementation of utility function
42 #include "agent-framework/securityAssistant/EXT_SA_Encryption_Decryption.h"
43 #include "agent-framework/Utility/fw_log.h"
44 #include "ServiceAdapter/SA_Util.h"
46 #define LOG_TAG "OMA_DS_SA"
48 void put_into_list(GList **commands, GList **commands_last, void *pCommand)
51 if (*commands_last == NULL) {
52 *commands_last = *commands = g_list_append(*commands, pCommand);
54 temp = g_list_append(*commands_last, pCommand);
55 *commands_last = g_list_next(*commands_last);
59 SA_ErrorType create_cred_string(AuthType type, const char *username, const char *password,
60 const char *nonce, unsigned int nonce_size, char **pCred)
63 SA_ErrorType errortype = SA_INTERNAL_OK;
68 char *plain = g_strjoin(":", username, password, NULL);
69 *pCred = g_base64_encode((unsigned char *) plain, strlen(plain));
72 errortype = SA_INTERNAL_NO_MEMORY;
81 /* How does syncml:auth-md5 works?
87 * username + ":" + password
95 /* Let's determine the string for the comparison. */
96 char *auth = g_strjoin(":", username, password, NULL);
97 FW_LOGV("username:password = %s", auth);
98 unsigned char *digest = NULL;
99 digest = SA_Get_Encryption_Value(SA_ENCRYPTION_MD5, auth, strlen(auth));
101 *pCred = g_base64_encode(digest, 16);
103 if (*pCred == NULL) {
104 errortype = SA_INTERNAL_NO_MEMORY;
109 FW_LOGV("nonce = %s", nonce);
110 FW_LOGV("nonce_size = %d", nonce_size);
112 int auth_size = strlen(*pCred) + nonce_size + 1;
113 auth = (char *)calloc(auth_size + 1, sizeof(char));
114 memcpy(auth, *pCred, strlen(*pCred));
115 auth[strlen(*pCred)] = ':';
116 memcpy(auth + strlen(*pCred) + 1, nonce, nonce_size);
117 FW_LOGV("base64[md5[username:password]] = %s", *pCred);
118 FW_LOGV("before last base64 encoding = %s", auth);
121 /*MD5GetDigest (auth, strlen(auth), digest);*/
124 GChecksum* pMd5 = g_checksum_new(G_CHECKSUM_MD5);
125 g_checksum_update(pMd5, auth, auth_size);
127 digest = (unsigned char*)calloc(16, sizeof(unsigned char));
128 g_checksum_get_digest(pMd5, digest, &temp);
131 digest = SA_Get_Encryption_Value(SA_ENCRYPTION_MD5, auth, auth_size);
132 FW_LOGV("md5[base64[md5[username:password]]] = %s", digest);
135 *pCred = g_base64_encode(digest, 16);
137 FW_LOGV("base64[md5[base64[md5[username:password]]]] = %s", *pCred);
138 if (*pCred == NULL) {
139 errortype = SA_INTERNAL_NO_MEMORY;
144 case AUTH_TYPE_UNKNOWN:
154 FW_LOGE("error : %d", errortype);
158 void set_xml_to_file(char *xml, const char *path)
163 pFile = fopen(path, "a");
168 fputs("==================================================================================", pFile);