Adapted the config backends to the new lifetime configuration.
[strongswan.git] / src / charon / plugins / medcli / medcli_config.c
index e6ae720..d3b2e38 100644 (file)
@@ -95,9 +95,11 @@ static peer_cfg_t *get_peer_cfg_by_name(private_medcli_config_t *this, char *nam
 {
        enumerator_t *e;
        peer_cfg_t *peer_cfg, *med_cfg;
+       auth_cfg_t *auth;
        ike_cfg_t *ike_cfg;
        child_cfg_t *child_cfg;
        chunk_t me, other;
+       lifetime_cfg_t *lifetime;
        char *address, *local_net, *remote_net;
        
        /* query mediation server config:
@@ -116,8 +118,6 @@ static peer_cfg_t *get_peer_cfg_by_name(private_medcli_config_t *this, char *nam
        ike_cfg->add_proposal(ike_cfg, proposal_create_default(PROTO_IKE));
        med_cfg = peer_cfg_create(
                "mediation", 2, ike_cfg,
-               identification_create_from_encoding(ID_KEY_ID, me),
-               identification_create_from_encoding(ID_KEY_ID, other),
                CERT_NEVER_SEND, UNIQUE_REPLACE, 
                1, this->rekey*60, 0,                   /* keytries, rekey, reauth */
                this->rekey*5, this->rekey*3,   /* jitter, overtime */
@@ -126,6 +126,17 @@ static peer_cfg_t *get_peer_cfg_by_name(private_medcli_config_t *this, char *nam
                TRUE, NULL, NULL);                              /* mediation, med by, peer id */
        e->destroy(e);
        
+       auth = auth_cfg_create();
+       auth->add(auth, AUTH_RULE_AUTH_CLASS, AUTH_CLASS_PUBKEY);
+       auth->add(auth, AUTH_RULE_IDENTITY,
+                         identification_create_from_encoding(ID_KEY_ID, me));
+       med_cfg->add_auth_cfg(med_cfg, auth, TRUE);
+       auth = auth_cfg_create();
+       auth->add(auth, AUTH_RULE_AUTH_CLASS, AUTH_CLASS_PUBKEY);
+       auth->add(auth, AUTH_RULE_IDENTITY,
+                         identification_create_from_encoding(ID_KEY_ID, other));
+       med_cfg->add_auth_cfg(med_cfg, auth, FALSE);
+       
        /* query mediated config:
         * - use any-any ike_cfg
         * - build peer_cfg on-the-fly using med_cfg
@@ -144,8 +155,6 @@ static peer_cfg_t *get_peer_cfg_by_name(private_medcli_config_t *this, char *nam
        }
        peer_cfg = peer_cfg_create(
                name, 2, this->ike->get_ref(this->ike),
-               identification_create_from_encoding(ID_KEY_ID, me),
-               identification_create_from_encoding(ID_KEY_ID, other),
                CERT_NEVER_SEND, UNIQUE_REPLACE, 
                1, this->rekey*60, 0,                   /* keytries, rekey, reauth */
                this->rekey*5, this->rekey*3,   /* jitter, overtime */
@@ -154,8 +163,21 @@ static peer_cfg_t *get_peer_cfg_by_name(private_medcli_config_t *this, char *nam
                FALSE, med_cfg,                                 /* mediation, med by */
                identification_create_from_encoding(ID_KEY_ID, other));
        
-       child_cfg = child_cfg_create(name, this->rekey*60 + this->rekey,
-                                                         this->rekey*60, this->rekey, NULL, TRUE,
+       auth = auth_cfg_create();
+       auth->add(auth, AUTH_RULE_AUTH_CLASS, AUTH_CLASS_PUBKEY);
+       auth->add(auth, AUTH_RULE_IDENTITY,
+                         identification_create_from_encoding(ID_KEY_ID, me));
+       peer_cfg->add_auth_cfg(peer_cfg, auth, TRUE);
+       auth = auth_cfg_create();
+       auth->add(auth, AUTH_RULE_AUTH_CLASS, AUTH_CLASS_PUBKEY);
+       auth->add(auth, AUTH_RULE_IDENTITY,
+                         identification_create_from_encoding(ID_KEY_ID, other));
+       peer_cfg->add_auth_cfg(peer_cfg, auth, FALSE);
+       
+       lifetime = lifetime_cfg_create_time(this->rekey * 60 + this->rekey,
+                                                                               this->rekey, this->rekey);
+       
+       child_cfg = child_cfg_create(name, lifetime, NULL, TRUE,
                                                          MODE_TUNNEL, ACTION_NONE, ACTION_NONE, FALSE);
        child_cfg->add_proposal(child_cfg, proposal_create_default(PROTO_ESP));
        child_cfg->add_traffic_selector(child_cfg, TRUE, ts_from_string(local_net));
@@ -197,7 +219,9 @@ static bool peer_enumerator_enumerate(peer_enumerator_t *this, peer_cfg_t **cfg)
        char *name, *local_net, *remote_net;
        chunk_t me, other;
        child_cfg_t *child_cfg;
-
+       auth_cfg_t *auth;
+       lifetime_cfg_t *lifetime;
+       
        DESTROY_IF(this->current);
        if (!this->inner->enumerate(this->inner, &name, &me, &other,
                                                                &local_net, &remote_net))
@@ -207,18 +231,29 @@ static bool peer_enumerator_enumerate(peer_enumerator_t *this, peer_cfg_t **cfg)
        }
        this->current = peer_cfg_create(
                                name, 2, this->ike->get_ref(this->ike),
-                               identification_create_from_encoding(ID_KEY_ID, me),
-                               identification_create_from_encoding(ID_KEY_ID, other),
                                CERT_NEVER_SEND, UNIQUE_REPLACE, 
                                1, this->rekey*60, 0,                   /* keytries, rekey, reauth */
                                this->rekey*5, this->rekey*3,   /* jitter, overtime */
                                TRUE, this->dpd,                                /* mobike, dpddelay */
                                NULL, NULL,                                     /* vip, pool */
                                FALSE, NULL, NULL);                     /* mediation, med by, peer id */
-       child_cfg = child_cfg_create(
-                               name, this->rekey*60 + this->rekey,
-                               this->rekey*60, this->rekey, NULL, TRUE,
-                               MODE_TUNNEL, ACTION_NONE, ACTION_NONE, FALSE);
+       
+       auth = auth_cfg_create();
+       auth->add(auth, AUTH_RULE_AUTH_CLASS, AUTH_CLASS_PUBKEY);
+       auth->add(auth, AUTH_RULE_IDENTITY,
+                         identification_create_from_encoding(ID_KEY_ID, me));
+       this->current->add_auth_cfg(this->current, auth, TRUE);
+       auth = auth_cfg_create();
+       auth->add(auth, AUTH_RULE_AUTH_CLASS, AUTH_CLASS_PUBKEY);
+       auth->add(auth, AUTH_RULE_IDENTITY,
+                         identification_create_from_encoding(ID_KEY_ID, other));
+       this->current->add_auth_cfg(this->current, auth, FALSE);
+       
+       lifetime = lifetime_cfg_create_time(this->rekey * 60 + this->rekey,
+                                                                               this->rekey, this->rekey);
+       
+       child_cfg = child_cfg_create(name, lifetime, NULL, TRUE, MODE_TUNNEL,
+                                                                ACTION_NONE, ACTION_NONE, FALSE);
        child_cfg->add_proposal(child_cfg, proposal_create_default(PROTO_ESP));
        child_cfg->add_traffic_selector(child_cfg, TRUE, ts_from_string(local_net));
        child_cfg->add_traffic_selector(child_cfg, FALSE, ts_from_string(remote_net));