Browse code

Merge ab58649393713c0291e1fa6f0dc3d39359858587 into 0d9380c8812d4e57b0c92f5f68b6c20001b28819

riccardv authored on 24/05/2022 10:37:24 • GitHub committed on 24/05/2022 10:37:24
Showing 1 changed files
... ...
@@ -182,34 +182,57 @@ int add_sa(struct mnl_socket* nl_sock, const struct ip_addr *src_addr_param, con
182 182
     // Set the proper algorithm by r_alg str
183 183
     if(strncasecmp(r_alg.s, "hmac-md5-96", r_alg.len) == 0) {
184 184
         strcpy(l_auth_algo->alg_name,"md5");
185
-    }
186
-    else if(strncasecmp(r_alg.s, "hmac-sha-1-96", r_alg.len) == 0) {
185
+        l_auth_algo->alg_key_len = ik.len * 4;
186
+        string_to_key(l_auth_algo->alg_key, ik);
187
+    } else if(strncasecmp(r_alg.s, "hmac-sha-1-96", r_alg.len) == 0) {
187 188
         strcpy(l_auth_algo->alg_name,"sha1");
189
+        str ik1;
190
+        ik1.len = ik.len+8;
191
+        ik1.s = pkg_malloc (ik1.len+1);
192
+        if (ik1.s == NULL) {
193
+            LM_ERR("Error allocating memory\n");
194
+            return -1;
195
+        }
196
+        memcpy (ik1.s,ik.s,ik.len);
197
+        ik1.s[ik.len]=0;
198
+        strcat (ik1.s,"00000000");
199
+        l_auth_algo->alg_key_len = ik1.len * 4;
200
+        string_to_key(l_auth_algo->alg_key, ik1);
201
+        pkg_free(ik1.s);
188 202
     } else {
189
-        // set default algorithm to sha1
190
-        strcpy(l_auth_algo->alg_name,"sha1");
203
+        LM_DBG("Creating security associations: UNKNOW Auth Algorithm\n");
204
+        return -1;
191 205
     }
192 206
 
193
-    l_auth_algo->alg_key_len = ik.len * 4;
194
-    string_to_key(l_auth_algo->alg_key, ik);
195
-
196 207
     mnl_attr_put(l_nlh, XFRMA_ALG_AUTH, sizeof(struct xfrm_algo) + l_auth_algo->alg_key_len, l_auth_algo);
197 208
 
198 209
     // add encription algorithm for this SA
199 210
     l_enc_algo = (struct xfrm_algo *)l_enc_algo_buf;
211
+    // cipher_null, des,  des3_ede, aes
200 212
     if (strncasecmp(r_ealg.s,"aes-cbc",r_ealg.len) == 0) {
201 213
         strcpy(l_enc_algo->alg_name,"aes");
202 214
         l_enc_algo->alg_key_len = ck.len * 4;
203 215
         string_to_key(l_enc_algo->alg_key, ck);
204
-    }
205
-    else if (strncasecmp(r_ealg.s,"des-ede3-cbc",r_ealg.len) == 0) {
216
+    } else if (strncasecmp(r_ealg.s,"des-ede3-cbc",r_ealg.len) == 0) {
206 217
         strcpy(l_enc_algo->alg_name,"des3_ede");
207
-        l_enc_algo->alg_key_len = ck.len * 4;
208
-        string_to_key(l_enc_algo->alg_key, ck);
209
-    } else {
210
-        // set default algorithm to null
218
+        str ck1;
219
+        ck1.len = ck.len+ck.len/2;
220
+        ck1.s = pkg_malloc (ck1.len+1);
221
+        if (ck1.s == NULL) {
222
+            LM_ERR("Error allocating memory\n");
223
+            return -1;
224
+        }
225
+        memcpy (ck1.s,ck.s,ck.len);
226
+        memcpy (ck1.s+ck.len,ck.s,ck.len/2);
227
+        l_enc_algo->alg_key_len = ck1.len * 4;
228
+        string_to_key(l_enc_algo->alg_key, ck1);
229
+        pkg_free(ck1.s);
230
+    } else if (strncasecmp(r_ealg.s,"null",r_ealg.len) == 0) {
211 231
         strcpy(l_enc_algo->alg_name,"cipher_null");
212
-    	l_enc_algo->alg_key_len = 0;
232
+        l_enc_algo->alg_key_len = 0;
233
+    } else {
234
+        LM_DBG("Creating security associations: UNKNOW Enc Algorithm\n");
235
+        return -1;
213 236
     }
214 237
 
215 238
     mnl_attr_put(l_nlh, XFRMA_ALG_CRYPT, sizeof(struct xfrm_algo) + l_enc_algo->alg_key_len, l_enc_algo);