Changeset 4261

Show
Ignore:
Timestamp:
08/20/08 10:51:18 (3 months ago)
Author:
martin
Message:

fixed shared key lookup by ID
proper auth method selection

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/charon/plugins/nm/gnome/nm-strongswan-service.name.in

    r4241 r4261  
    55 
    66[GNOME] 
    7 auth-dialog=nm-strongswan-auth-dialog 
     7auth-dialog=@LIBEXECDIR@/nm-strongswan-auth-dialog 
    88properties=libnm-strongswan-properties 
  • trunk/src/charon/plugins/nm/gnome/properties/nm-strongswan.c

    r4257 r4261  
    179179    if (!widget) 
    180180        return FALSE; 
    181     gtk_combo_box_append_text (GTK_COMBO_BOX (widget), "EAP"); 
     181    gtk_combo_box_append_text (GTK_COMBO_BOX (widget), _("EAP")); 
     182    gtk_combo_box_append_text (GTK_COMBO_BOX (widget), _("PSK (insecure)")); 
    182183    value = g_hash_table_lookup (settings->data, "method"); 
    183184    if (value) { 
    184         if (g_strcasecmp (value, "EAP") == 0) { 
     185        if (g_strcasecmp (value, "eap") == 0) { 
    185186            gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0); 
     187        } 
     188        if (g_strcasecmp (value, "psk") == 0) { 
     189            gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 1); 
    186190        } 
    187191    } 
     
    273277 
    274278    widget = glade_xml_get_widget (priv->xml, "method-combo"); 
    275     str = (char *) gtk_combo_box_get_active_text (GTK_COMBO_BOX (widget)); 
    276     if (str) { 
    277         g_hash_table_insert (settings->data, g_strdup ("method"), g_strdup(str)); 
    278     } 
     279    switch (gtk_combo_box_get_active (GTK_COMBO_BOX (widget))) 
     280    { 
     281        default: 
     282            str = "eap"; 
     283            break; 
     284        case 1: 
     285            str = "psk"; 
     286            break; 
     287        case 2: 
     288            str = "pubkey"; 
     289            break; 
     290    } 
     291    g_hash_table_insert (settings->data, g_strdup ("method"), g_strdup(str)); 
    279292     
    280293    widget = glade_xml_get_widget (priv->xml, "virtual-check"); 
  • trunk/src/charon/plugins/nm/nm_creds.c

    r4257 r4261  
    4141     
    4242    /** 
     43     * User name 
     44     */ 
     45    identification_t *user; 
     46     
     47    /** 
    4348     * User password 
    4449     */ 
     
    5863                            identification_t *id, bool trusted) 
    5964{ 
    60     if (!this->cert || 
    61         (cert != CERT_ANY && cert != this->cert->get_type(this->cert))) 
    62     { 
    63         return NULL; 
    64     } 
     65    if (!this->cert) 
     66    { 
     67        return NULL; 
     68    } 
     69    if (cert != CERT_ANY && cert != this->cert->get_type(this->cert)) 
     70    { 
     71        return NULL; 
     72    } 
     73    if (id && !this->cert->has_subject(this->cert, id)) 
     74    { 
     75        return NULL; 
     76    } 
     77    if (key != KEY_ANY) 
     78    { 
     79        public_key_t *public; 
     80     
     81        public = this->cert->get_public_key(this->cert); 
     82        if (!public) 
     83        { 
     84            return NULL; 
     85        } 
     86        if (public->get_type(public) != key) 
     87        { 
     88            public->destroy(public); 
     89            return NULL; 
     90        } 
     91        public->destroy(public); 
     92    } 
     93    pthread_rwlock_rdlock(&this->lock); 
    6594    return enumerator_create_cleaner(enumerator_create_single(this->cert, NULL), 
    6695                                     (void*)pthread_rwlock_unlock, &this->lock); 
    6796} 
    6897 
     98/** 
     99 * shared key enumerator implementation 
     100 */ 
     101typedef struct { 
     102    enumerator_t public; 
     103    private_nm_creds_t *this; 
     104    shared_key_t *key; 
     105    bool done; 
     106} shared_enumerator_t; 
     107 
     108/** 
     109 * enumerate function for shared enumerator 
     110 */ 
     111static bool shared_enumerate(shared_enumerator_t *this, shared_key_t **key, 
     112                             id_match_t *me, id_match_t *other) 
     113{ 
     114    if (this->done) 
     115    { 
     116        return FALSE; 
     117    } 
     118    *key = this->key; 
     119    *me = ID_MATCH_PERFECT; 
     120    *other = ID_MATCH_ANY; 
     121    this->done = TRUE; 
     122    return TRUE; 
     123} 
     124 
     125/** 
     126 * Destroy function for shared enumerator 
     127 */ 
     128static void shared_destroy(shared_enumerator_t *this) 
     129{ 
     130    this->key->destroy(this->key); 
     131    pthread_rwlock_unlock(&this->this->lock); 
     132    free(this); 
     133} 
    69134/** 
    70135 * Implements credential_set_t.create_cert_enumerator 
     
    74139                            identification_t *other) 
    75140{ 
    76     shared_key_t *key; 
    77  
    78     if (!this->pass || (type != SHARED_EAP && type != SHARED_IKE)) 
    79     { 
    80         return NULL; 
    81     } 
    82     key = shared_key_create(type, chunk_clone( 
    83                                 chunk_create(this->pass, strlen(this->pass)))); 
    84     return enumerator_create_cleaner( 
    85                         enumerator_create_single(key, (void*)key->destroy), 
    86                         (void*)pthread_rwlock_unlock, &this->lock); 
     141    shared_enumerator_t *enumerator; 
     142 
     143    if (!this->pass || !this->user) 
     144    { 
     145        return NULL; 
     146    } 
     147    if (type != SHARED_EAP && type != SHARED_IKE) 
     148    { 
     149        return NULL; 
     150    } 
     151    if (me && !me->equals(me, this->user)) 
     152    { 
     153        return NULL; 
     154    } 
     155     
     156    enumerator = malloc_thing(shared_enumerator_t); 
     157    enumerator->public.enumerate = (void*)shared_enumerate; 
     158    enumerator->public.destroy = (void*)shared_destroy; 
     159    enumerator->this = this; 
     160    enumerator->done = FALSE; 
     161    pthread_rwlock_rdlock(&this->lock); 
     162    enumerator->key = shared_key_create(type, 
     163                                        chunk_clone(chunk_create(this->pass, 
     164                                                    strlen(this->pass)))); 
     165    return &enumerator->public; 
    87166} 
    88167 
     
    101180 * Implementation of nm_creds_t.set_password 
    102181 */ 
    103 static void set_password(private_nm_creds_t *this, char *password) 
     182static void set_password(private_nm_creds_t *this, identification_t *id, 
     183                         char *password) 
    104184{ 
    105185    pthread_rwlock_wrlock(&this->lock); 
     186    DESTROY_IF(this->user); 
     187    this->user = id->clone(id); 
    106188    free(this->pass); 
    107189    this->pass = strdup(password); 
     
    115197{ 
    116198    DESTROY_IF(this->cert); 
     199    DESTROY_IF(this->user); 
    117200    free(this->pass); 
    118201    pthread_rwlock_destroy(&this->lock); 
     
    133216    this->public.set.cache_cert = (void*)nop; 
    134217    this->public.set_certificate = (void(*)(nm_creds_t*, certificate_t *cert))set_certificate; 
    135     this->public.set_password = (void(*)(nm_creds_t*, char *password))set_password; 
     218    this->public.set_password = (void(*)(nm_creds_t*, identification_t *id, char *password))set_password; 
    136219    this->public.destroy = (void(*)(nm_creds_t*))destroy; 
    137220     
     
    139222     
    140223    this->cert = NULL; 
     224    this->user = NULL; 
    141225    this->pass = NULL; 
    142226     
  • trunk/src/charon/plugins/nm/nm_creds.h

    r4257 r4261  
    4646     
    4747    /** 
    48      * Set the users password for authentication. 
     48     * Set the username/password for authentication. 
    4949     * 
     50     * @param id        ID of the user 
    5051     * @param password  password to use for authentication 
    5152     */ 
    52     void (*set_password)(nm_creds_t *this, char *password); 
     53    void (*set_password)(nm_creds_t *this, identification_t *id, char *password); 
    5354     
    5455    /** 
  • trunk/src/charon/plugins/nm/nm_service.c

    r4257 r4261  
    143143            case IKE_UP_FAILED: 
    144144            case CHD_UP_FAILED: 
     145                /* TODO: NM does not handle this failure!?  
    145146                nm_vpn_plugin_failure(private->plugin, 
    146                                       NM_VPN_PLUGIN_FAILURE_CONNECT_FAILED); 
    147                 /* TODO: NM does not react on this failure!? So additionaly 
    148                  * reset state */ 
     147                                      NM_VPN_PLUGIN_FAILURE_LOGIN_FAILED); */ 
    149148                nm_vpn_plugin_set_state(private->plugin, 
    150149                                        NM_VPN_SERVICE_STATE_STOPPED); 
     
    173172    traffic_selector_t *ts; 
    174173    ike_sa_t *ike_sa; 
     174    config_auth_method_t method = CONF_AUTH_EAP; 
    175175     
    176176    /** 
     
    208208    str = g_hash_table_lookup(settings->data, "ipcomp"); 
    209209    ipcomp = str && streq(str, "yes"); 
     210    str = g_hash_table_lookup(settings->data, "method"); 
     211    if (str) 
     212    { 
     213        if (streq(str, "psk")) 
     214        { 
     215            method = CONF_AUTH_PSK; 
     216        } 
     217        else if (streq(str, "pubkey")) 
     218        { 
     219            method = CONF_AUTH_PUBKEY; 
     220        } 
     221    } 
    210222     
    211223    /** 
     
    226238    if (str) 
    227239    { 
    228         creds->set_password(creds, str); 
     240        creds->set_password(creds, user, str); 
    229241    } 
    230242     
     
    236248    peer_cfg = peer_cfg_create(CONFIG_NAME, 2, ike_cfg, user, 
    237249                    identification_create_from_encoding(ID_ANY, chunk_empty), 
    238                     CERT_SEND_IF_ASKED, UNIQUE_REPLACE, CONF_AUTH_PSK
     250                    CERT_SEND_IF_ASKED, UNIQUE_REPLACE, method
    239251                    0, 0, 1, /* EAP method, vendor, keyingtries */ 
    240252                    18000, 0, /* rekey 5h, reauth none */