~ubuntu-branches/ubuntu/oneiric/strongswan/oneiric

« back to all changes in this revision

Viewing changes to src/charon/plugins/eap_sim_file/eap_sim_file_card.c

  • Committer: Bazaar Package Importer
  • Author(s): Rene Mayrhofer
  • Date: 2008-12-05 17:21:42 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20081205172142-9g77wgyzcj0blq7p
* New upstream release, fixes a MOBIKE issue.
  Closes: #507542: strongswan: endless loop
* Explicitly enable compilation with libcurl for CRL fetching
  Closes: #497756: strongswan: not compiled with curl support; crl 
                   fetching not available
* Enable compilation with SSH agent support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2008 Martin Willi
 
3
 * Hochschule fuer Technik Rapperswil
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify it
 
6
 * under the terms of the GNU General Public License as published by the
 
7
 * Free Software Foundation; either version 2 of the License, or (at your
 
8
 * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful, but
 
11
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 
12
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 
13
 * for more details.
 
14
 *
 
15
 * $Id$
 
16
 */
 
17
 
 
18
#include "eap_sim_file_card.h"
 
19
 
 
20
typedef struct private_eap_sim_file_card_t private_eap_sim_file_card_t;
 
21
 
 
22
/**
 
23
 * Private data of an eap_sim_file_card_t object.
 
24
 */
 
25
struct private_eap_sim_file_card_t {
 
26
        
 
27
        /**
 
28
         * Public eap_sim_file_card_t interface.
 
29
         */
 
30
        eap_sim_file_card_t public;
 
31
        
 
32
        /**
 
33
         * IMSI, is ID_ANY for file implementation
 
34
         */
 
35
        identification_t *imsi;
 
36
        
 
37
        /**
 
38
         * source of triplets
 
39
         */
 
40
        eap_sim_file_triplets_t *triplets;
 
41
};
 
42
 
 
43
#include <daemon.h>
 
44
 
 
45
/**
 
46
 * Implementation of sim_card_t.get_triplet
 
47
 */
 
48
static bool get_triplet(private_eap_sim_file_card_t *this,
 
49
                                                char *rand, char *sres, char *kc)
 
50
{
 
51
        enumerator_t *enumerator;
 
52
        identification_t *id;
 
53
        char *c_rand, *c_sres, *c_kc;
 
54
        
 
55
        
 
56
        DBG1(DBG_CFG, "looking for rand: %b", rand, RAND_LEN);
 
57
        
 
58
        enumerator = this->triplets->create_enumerator(this->triplets);
 
59
        while (enumerator->enumerate(enumerator, &id, &c_rand, &c_sres, &c_kc))
 
60
        {
 
61
                DBG1(DBG_CFG, "found triplet: %b %b %b", c_rand, RAND_LEN, c_sres, SRES_LEN, c_kc, KC_LEN);
 
62
                if (memeq(c_rand, rand, RAND_LEN))
 
63
                {
 
64
                        memcpy(sres, c_sres, SRES_LEN);
 
65
                        memcpy(kc, c_kc, KC_LEN);
 
66
                        enumerator->destroy(enumerator);
 
67
                        return TRUE;
 
68
                }
 
69
        }
 
70
        enumerator->destroy(enumerator);
 
71
        return FALSE;
 
72
}
 
73
 
 
74
/**
 
75
 * Implementation of sim_card_t.get_imsi
 
76
 */
 
77
static identification_t* get_imsi(private_eap_sim_file_card_t *this)
 
78
{
 
79
        return this->imsi;
 
80
}
 
81
 
 
82
/**
 
83
 * Implementation of eap_sim_file_card_t.destroy.
 
84
 */
 
85
static void destroy(private_eap_sim_file_card_t *this)
 
86
{
 
87
        this->imsi->destroy(this->imsi);
 
88
        free(this);
 
89
}
 
90
 
 
91
/**
 
92
 * See header
 
93
 */
 
94
eap_sim_file_card_t *eap_sim_file_card_create(eap_sim_file_triplets_t *triplets)
 
95
{
 
96
        private_eap_sim_file_card_t *this = malloc_thing(private_eap_sim_file_card_t);
 
97
        
 
98
        this->public.card.get_triplet = (bool(*)(sim_card_t*, char *rand, char *sres, char *kc))get_triplet;
 
99
        this->public.card.get_imsi = (identification_t*(*)(sim_card_t*))get_imsi;
 
100
        this->public.destroy = (void(*)(eap_sim_file_card_t*))destroy;
 
101
        
 
102
        /* this SIM card implementation does not have an ID, serve ID_ANY */
 
103
        this->imsi = identification_create_from_encoding(ID_ANY, chunk_empty);
 
104
        this->triplets = triplets;
 
105
        
 
106
        return &this->public;
 
107
}
 
108