Fix load tester shared key enumerator, provide dedicated EAP password
authorMartin Willi <martin@revosec.ch>
Tue, 3 May 2011 11:15:37 +0000 (13:15 +0200)
committerMartin Willi <martin@revosec.ch>
Mon, 16 May 2011 13:24:13 +0000 (15:24 +0200)
src/libcharon/plugins/load_tester/load_tester_creds.c

index 890703c..4665abc 100644 (file)
@@ -49,9 +49,14 @@ struct private_load_tester_creds_t {
        u_int32_t serial;
 
        /**
        u_int32_t serial;
 
        /**
-        * Preshared key
+        * Preshared key for IKE
         */
         */
-       shared_key_t *shared;
+       shared_key_t *psk;
+
+       /**
+        * Password for EAP
+        */
+       shared_key_t *pwd;
 };
 
 /**
 };
 
 /**
@@ -131,7 +136,7 @@ CwMLbJ7vQqwPHXRitDmNkEOK9H+vRnDf
 -----END CERTIFICATE-----
 
  */
 -----END CERTIFICATE-----
 
  */
-char cert[] = {
+static char cert[] = {
   0x30,0x82,0x01,0xf4,0x30,0x82,0x01,0x5d,0xa0,0x03,0x02,0x01,0x02,0x02,0x01,0x00,
   0x30,0x0d,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x05,0x05,0x00,0x30,
   0x37,0x31,0x0c,0x30,0x0a,0x06,0x03,0x55,0x04,0x03,0x13,0x03,0x73,0x72,0x76,0x31,
   0x30,0x82,0x01,0xf4,0x30,0x82,0x01,0x5d,0xa0,0x03,0x02,0x01,0x02,0x02,0x01,0x00,
   0x30,0x0d,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x05,0x05,0x00,0x30,
   0x37,0x31,0x0c,0x30,0x0a,0x06,0x03,0x55,0x04,0x03,0x13,0x03,0x73,0x72,0x76,0x31,
@@ -175,6 +180,11 @@ static char psk[] = {
 };
 
 /**
 };
 
 /**
+ * Password for EAP
+ */
+static char pwd[] = "test#123";
+
+/**
  * Implements credential_set_t.create_private_enumerator
  */
 static enumerator_t* create_private_enumerator(private_load_tester_creds_t *this,
  * Implements credential_set_t.create_private_enumerator
  */
 static enumerator_t* create_private_enumerator(private_load_tester_creds_t *this,
@@ -264,14 +274,44 @@ static enumerator_t* create_cert_enumerator(private_load_tester_creds_t *this,
        return NULL;
 }
 
        return NULL;
 }
 
+static bool shared_filter(void *null, shared_key_t **in, shared_key_t **out,
+                               void **un1, id_match_t *me, void **un2, id_match_t *other)
+{
+       *out = *in;
+       if (me)
+       {
+               *me = ID_MATCH_ANY;
+       }
+       if (other)
+       {
+               *other = ID_MATCH_ANY;
+       }
+       return TRUE;
+}
+
 /**
  * Implements credential_set_t.create_shared_enumerator
  */
 static enumerator_t* create_shared_enumerator(private_load_tester_creds_t *this,
 /**
  * Implements credential_set_t.create_shared_enumerator
  */
 static enumerator_t* create_shared_enumerator(private_load_tester_creds_t *this,
-                                                       shared_key_type_t type, identification_t *me,
+                                                       shared_key_type_t type, identification_t *me,
                                                        identification_t *other)
 {
                                                        identification_t *other)
 {
-       return enumerator_create_single(this->shared, NULL);
+       shared_key_t *shared;
+
+       switch (type)
+       {
+               case SHARED_IKE:
+                       shared = this->psk;
+                       break;
+               case SHARED_EAP:
+                       shared = this->pwd;
+                       break;
+               default:
+                       return NULL;
+       }
+       return enumerator_create_filter(
+                                               enumerator_create_single(this->pwd, NULL),
+                                               (void*)shared_filter, NULL, NULL);
 }
 
 /**
 }
 
 /**
@@ -281,7 +321,8 @@ static void destroy(private_load_tester_creds_t *this)
 {
        DESTROY_IF(this->private);
        DESTROY_IF(this->ca);
 {
        DESTROY_IF(this->private);
        DESTROY_IF(this->ca);
-       this->shared->destroy(this->shared);
+       this->psk->destroy(this->psk);
+       this->pwd->destroy(this->pwd);
        free(this);
 }
 
        free(this);
 }
 
@@ -305,8 +346,10 @@ load_tester_creds_t *load_tester_creds_create()
                                BUILD_X509_FLAG, X509_CA,
                                BUILD_END);
 
                                BUILD_X509_FLAG, X509_CA,
                                BUILD_END);
 
-       this->shared = shared_key_create(SHARED_IKE,
-                                                                        chunk_clone(chunk_create(psk, sizeof(psk))));
+       this->psk = shared_key_create(SHARED_IKE,
+                                                                 chunk_clone(chunk_create(psk, sizeof(psk))));
+       this->pwd = shared_key_create(SHARED_EAP,
+                                                                 chunk_clone(chunk_create(pwd, strlen(pwd))));
        this->serial = 0;
        return &this->public;
 }
        this->serial = 0;
        return &this->public;
 }