aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstrongswan
diff options
context:
space:
mode:
authorMartin Willi <martin@strongswan.org>2008-08-22 10:44:51 +0000
committerMartin Willi <martin@strongswan.org>2008-08-22 10:44:51 +0000
commit822901061beb899947f22288c2dc7eb5a13eeb87 (patch)
treeb3f8e84bba26bd24a8c4d3ba26ad4bf4fc03ec01 /src/libstrongswan
parent7c112a12c06c0320ee3945cd593c2beafe6b56dc (diff)
downloadstrongswan-822901061beb899947f22288c2dc7eb5a13eeb87.tar.bz2
strongswan-822901061beb899947f22288c2dc7eb5a13eeb87.tar.xz
ported parts of two-sim branch
eap_identity parameter to exchange in eap_identity some auth_info/peer_cfg refactorings fixed some bugs, introduced new ones
Diffstat (limited to 'src/libstrongswan')
-rw-r--r--src/libstrongswan/chunk.c20
-rw-r--r--src/libstrongswan/chunk.h5
-rw-r--r--src/libstrongswan/utils/identification.c2
-rw-r--r--src/libstrongswan/utils/identification.h5
4 files changed, 26 insertions, 6 deletions
diff --git a/src/libstrongswan/chunk.c b/src/libstrongswan/chunk.c
index cbd90bd6a..d682eeb16 100644
--- a/src/libstrongswan/chunk.c
+++ b/src/libstrongswan/chunk.c
@@ -298,16 +298,28 @@ static char hex2bin(char hex)
chunk_t chunk_from_hex(chunk_t hex, char *buf)
{
int i, len;
+ bool odd = FALSE;
- len = hex.len / 2;
+ len = (hex.len / 2);
+ if (hex.len % 2)
+ {
+ odd = TRUE;
+ len++;
+ }
if (!buf)
{
buf = malloc(len);
}
- for (i = 0; i < len; i++)
+ /* buffer is filled from the right */
+ memset(buf, 0, len);
+ hex.ptr += hex.len;
+ for (i = len - 1; i >= 0; i--)
{
- buf[i] = hex2bin(*hex.ptr++) << 4;
- buf[i] |= hex2bin(*hex.ptr++);
+ buf[i] = hex2bin(*(--hex.ptr));
+ if (i > 0 || !odd)
+ {
+ buf[i] |= hex2bin(*(--hex.ptr)) << 4;
+ }
}
return chunk_create(buf, len);
}
diff --git a/src/libstrongswan/chunk.h b/src/libstrongswan/chunk.h
index 195d01fcd..8d63f6092 100644
--- a/src/libstrongswan/chunk.h
+++ b/src/libstrongswan/chunk.h
@@ -100,7 +100,8 @@ chunk_t chunk_to_hex(chunk_t chunk, char *buf, bool uppercase);
/**
* Convert a hex encoded in a binary chunk.
*
- * If buf is supplied, it must hold at least (hex.len / 2).
+ * If buf is supplied, it must hold at least (hex.len / 2) + (hex.len % 2)
+ * bytes. It is filled by the right to give correct values for short inputs.
*
* @param hex hex encoded input data
* @param buf buffer to write decoded data, NULL to malloc
@@ -164,7 +165,7 @@ void chunk_clear(chunk_t *chunk);
/**
* Clone a chunk on heap
*/
-#define chunk_clone(chunk) chunk_create_clone(malloc(chunk.len), chunk)
+#define chunk_clone(chunk) chunk_create_clone((chunk).len ? malloc(chunk.len) : NULL, chunk)
/**
* Clone a chunk on stack
diff --git a/src/libstrongswan/utils/identification.c b/src/libstrongswan/utils/identification.c
index e1fb54007..4b7ba357b 100644
--- a/src/libstrongswan/utils/identification.c
+++ b/src/libstrongswan/utils/identification.c
@@ -915,6 +915,7 @@ static int print(FILE *stream, const struct printf_info *info,
case ID_FQDN:
case ID_RFC822_ADDR:
case ID_DER_ASN1_GN_URI:
+ case ID_EAP:
proper = sanitize_chunk(this->encoded);
snprintf(buf, sizeof(buf), "%.*s", proper.len, proper.ptr);
chunk_free(&proper);
@@ -1169,6 +1170,7 @@ identification_t *identification_create_from_encoding(id_type_t type, chunk_t en
case ID_PUBKEY_INFO_SHA1:
case ID_PUBKEY_SHA1:
case ID_CERT_DER_SHA1:
+ case ID_EAP:
default:
break;
}
diff --git a/src/libstrongswan/utils/identification.h b/src/libstrongswan/utils/identification.h
index 29318ce47..3b1f55ab2 100644
--- a/src/libstrongswan/utils/identification.h
+++ b/src/libstrongswan/utils/identification.h
@@ -142,6 +142,11 @@ enum id_type_t {
* SHA1 hash of the binary DER encoding of a certificate
*/
ID_CERT_DER_SHA1,
+
+ /**
+ * Generic EAP identity
+ */
+ ID_EAP,
};
/**