Annotation of embedaddon/strongswan/src/libstrongswan/credentials/sets/ocsp_response_wrapper.c, revision 1.1.1.1

1.1       misho       1: /*
                      2:  * Copyright (C) 2008 Martin Willi
                      3:  * HSR 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: 
                     16: #include "ocsp_response_wrapper.h"
                     17: 
                     18: typedef struct private_ocsp_response_wrapper_t private_ocsp_response_wrapper_t;
                     19: 
                     20: /**
                     21:  * private data of ocsp_response_wrapper
                     22:  */
                     23: struct private_ocsp_response_wrapper_t {
                     24: 
                     25:        /**
                     26:         * public functions
                     27:         */
                     28:        ocsp_response_wrapper_t public;
                     29: 
                     30:        /**
                     31:         * wrapped OCSP response
                     32:         */
                     33:        ocsp_response_t *response;
                     34: };
                     35: 
                     36: /**
                     37:  * enumerator for ocsp_response_wrapper_t.create_cert_enumerator()
                     38:  */
                     39: typedef struct {
                     40:        /** implements enumerator_t */
                     41:        enumerator_t public;
                     42:        /** enumerator over ocsp response */
                     43:        enumerator_t *inner;
                     44:        /** type of cert */
                     45:        certificate_type_t cert;
                     46:        /** type of key */
                     47:        key_type_t key;
                     48:        /** filtering identity */
                     49:        identification_t *id;
                     50: } wrapper_enumerator_t;
                     51: 
                     52: METHOD(enumerator_t, enumerate, bool,
                     53:        wrapper_enumerator_t *this, va_list args)
                     54: {
                     55:        certificate_t *current, **cert;
                     56:        public_key_t *public;
                     57: 
                     58: 
                     59:        VA_ARGS_VGET(args, cert);
                     60: 
                     61:        while (this->inner->enumerate(this->inner, &current))
                     62:        {
                     63:                if (this->cert != CERT_ANY && this->cert != current->get_type(current))
                     64:                {       /* CERT type requested, but does not match */
                     65:                        continue;
                     66:                }
                     67:                public = current->get_public_key(current);
                     68:                if (this->key != KEY_ANY && !public)
                     69:                {       /* key type requested, but no public key */
                     70:                        DESTROY_IF(public);
                     71:                        continue;
                     72:                }
                     73:                if (this->key != KEY_ANY && public && this->key != public->get_type(public))
                     74:                {       /* key type requested, but public key has another type */
                     75:                        DESTROY_IF(public);
                     76:                        continue;
                     77:                }
                     78:                DESTROY_IF(public);
                     79:                if (this->id && !current->has_subject(current, this->id))
                     80:                {       /* subject requested, but does not match */
                     81:                        continue;
                     82:                }
                     83:                *cert = current;
                     84:                return TRUE;
                     85:        }
                     86:        return FALSE;
                     87: }
                     88: 
                     89: METHOD(enumerator_t, enumerator_destroy, void,
                     90:        wrapper_enumerator_t *this)
                     91: {
                     92:        this->inner->destroy(this->inner);
                     93:        free(this);
                     94: }
                     95: 
                     96: METHOD(credential_set_t, create_enumerator, enumerator_t*,
                     97:        private_ocsp_response_wrapper_t *this,certificate_type_t cert,
                     98:        key_type_t key, identification_t *id, bool trusted)
                     99: {
                    100:        wrapper_enumerator_t *enumerator;
                    101: 
                    102:        if (trusted)
                    103:        {
                    104:                return NULL;
                    105:        }
                    106: 
                    107:        INIT(enumerator,
                    108:                .public = {
                    109:                        .enumerate = enumerator_enumerate_default,
                    110:                        .venumerate = _enumerate,
                    111:                        .destroy = _enumerator_destroy,
                    112:                },
                    113:                .cert = cert,
                    114:                .key = key,
                    115:                .id = id,
                    116:                .inner = this->response->create_cert_enumerator(this->response),
                    117:        );
                    118:        return &enumerator->public;
                    119: }
                    120: 
                    121: METHOD(ocsp_response_wrapper_t, destroy, void,
                    122:        private_ocsp_response_wrapper_t *this)
                    123: {
                    124:        free(this);
                    125: }
                    126: 
                    127: /*
                    128:  * see header file
                    129:  */
                    130: ocsp_response_wrapper_t *ocsp_response_wrapper_create(ocsp_response_t *response)
                    131: {
                    132:        private_ocsp_response_wrapper_t *this;
                    133: 
                    134:        INIT(this,
                    135:                .public = {
                    136:                        .set = {
                    137:                                .create_cert_enumerator = _create_enumerator,
                    138:                                .create_private_enumerator = (void*)return_null,
                    139:                                .create_shared_enumerator = (void*)return_null,
                    140:                                .create_cdp_enumerator = (void*)return_null,
                    141:                                .cache_cert = (void*)nop,
                    142:                        },
                    143:                        .destroy = _destroy,
                    144:                },
                    145:                .response = response,
                    146:        );
                    147: 
                    148:        return &this->public;
                    149: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>