diff options
author | Martin Willi <martin@revosec.ch> | 2014-10-29 11:18:35 +0100 |
---|---|---|
committer | Martin Willi <martin@revosec.ch> | 2014-10-30 11:05:44 +0100 |
commit | c0da835a9f773800d2ff8c002e234fd441fdcf0a (patch) | |
tree | fd8ebe5840f0de231d4c3412b187d06be11557a6 /src/libstrongswan/utils/identification.c | |
parent | 46001e1131e8239772627aa47f1e5867d82184e4 (diff) | |
download | strongswan-c0da835a9f773800d2ff8c002e234fd441fdcf0a.tar.bz2 strongswan-c0da835a9f773800d2ff8c002e234fd441fdcf0a.tar.xz |
identification: Support prefixes in string constructors for an explicit type
Diffstat (limited to 'src/libstrongswan/utils/identification.c')
-rw-r--r-- | src/libstrongswan/utils/identification.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/libstrongswan/utils/identification.c b/src/libstrongswan/utils/identification.c index 46ac7e890..43aa0908c 100644 --- a/src/libstrongswan/utils/identification.c +++ b/src/libstrongswan/utils/identification.c @@ -927,6 +927,49 @@ static private_identification_t *identification_create(id_type_t type) return this; } +/** + * Create an identity for a specific type, determined by prefix + */ +static private_identification_t* create_from_string_with_prefix_type(char *str) +{ + struct { + const char *str; + id_type_t type; + } prefixes[] = { + { "ipv4:", ID_IPV4_ADDR }, + { "ipv6:", ID_IPV6_ADDR }, + { "rfc822:", ID_RFC822_ADDR }, + { "email:", ID_RFC822_ADDR }, + { "userfqdn:", ID_USER_FQDN }, + { "fqdn:", ID_FQDN }, + { "dns:", ID_FQDN }, + { "asn1dn:", ID_DER_ASN1_DN }, + { "asn1gn:", ID_DER_ASN1_GN }, + { "keyid:", ID_KEY_ID }, + }; + private_identification_t *this; + int i; + + for (i = 0; i < countof(prefixes); i++) + { + if (strcasepfx(str, prefixes[i].str)) + { + this = identification_create(prefixes[i].type); + str += strlen(prefixes[i].str); + if (*str == '#') + { + this->encoded = chunk_from_hex(chunk_from_str(str + 1), NULL); + } + else + { + this->encoded = chunk_clone(chunk_from_str(str)); + } + return this; + } + } + return NULL; +} + /* * Described in header. */ @@ -939,6 +982,11 @@ identification_t *identification_create_from_string(char *string) { string = "%any"; } + this = create_from_string_with_prefix_type(string); + if (this) + { + return &this->public; + } if (strchr(string, '=') != NULL) { /* we interpret this as an ASCII X.501 ID_DER_ASN1_DN. |