Annotation of embedaddon/strongswan/src/libimcv/tcg/pts/tcg_pts_attr_dh_nonce_params_resp.c, revision 1.1

1.1     ! misho       1: /*
        !             2:  * Copyright (C) 2011-2012 Sansar Choinyambuu
        !             3:  * Copyright (C) 2011-2014 Andreas Steffen
        !             4:  * HSR Hochschule fuer Technik Rapperswil
        !             5:  *
        !             6:  * This program is free software; you can redistribute it and/or modify it
        !             7:  * under the terms of the GNU General Public License as published by the
        !             8:  * Free Software Foundation; either version 2 of the License, or (at your
        !             9:  * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
        !            10:  *
        !            11:  * This program is distributed in the hope that it will be useful, but
        !            12:  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
        !            13:  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
        !            14:  * for more details.
        !            15:  */
        !            16: 
        !            17: #include "tcg_pts_attr_dh_nonce_params_resp.h"
        !            18: 
        !            19: #include <pa_tnc/pa_tnc_msg.h>
        !            20: #include <bio/bio_writer.h>
        !            21: #include <bio/bio_reader.h>
        !            22: #include <utils/debug.h>
        !            23: 
        !            24: typedef struct private_tcg_pts_attr_dh_nonce_params_resp_t
        !            25:                                        private_tcg_pts_attr_dh_nonce_params_resp_t;
        !            26: 
        !            27: /**
        !            28:  * PTS DH Nonce Parameters Response
        !            29:  * see section 3.8.2 of PTS Protocol: Binding to TNC IF-M Specification
        !            30:  *
        !            31:  *                                        1                               2                               3
        !            32:  *   0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
        !            33:  *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
        !            34:  *  |                                  Reserved                                        |   Nonce Len   |
        !            35:  *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
        !            36:  *  |          Selected D-H Group              |       Hash Algorithm Set              |
        !            37:  *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
        !            38:  *  |                                          D-H Responder Nonce ...                                 |
        !            39:  *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
        !            40:  *  |                                  D-H Responder Public Value ...                          |
        !            41:  *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
        !            42:  *
        !            43:  */
        !            44: 
        !            45: #define PTS_DH_NONCE_PARAMS_RESP_SIZE                  16
        !            46: #define PTS_DH_NONCE_PARAMS_RESP_RESERVED              0x0000
        !            47: 
        !            48: /**
        !            49:  * Private data of an tcg_pts_attr_dh_nonce_params_resp_t object.
        !            50:  */
        !            51: struct private_tcg_pts_attr_dh_nonce_params_resp_t {
        !            52: 
        !            53:        /**
        !            54:         * Public members of tcg_pts_attr_dh_nonce_params_resp_t
        !            55:         */
        !            56:        tcg_pts_attr_dh_nonce_params_resp_t public;
        !            57: 
        !            58:        /**
        !            59:         * Vendor-specific attribute type
        !            60:         */
        !            61:        pen_type_t type;
        !            62: 
        !            63:        /**
        !            64:         * Length of attribute value
        !            65:         */
        !            66:        size_t length;
        !            67: 
        !            68:        /**
        !            69:         * Attribute value or segment
        !            70:         */
        !            71:        chunk_t value;
        !            72: 
        !            73:        /**
        !            74:         * Noskip flag
        !            75:         */
        !            76:        bool noskip_flag;
        !            77: 
        !            78:        /**
        !            79:         * Selected Diffie Hellman group
        !            80:         */
        !            81:        pts_dh_group_t dh_group;
        !            82: 
        !            83:        /**
        !            84:         * Supported Hashing Algorithms
        !            85:         */
        !            86:        pts_meas_algorithms_t hash_algo_set;
        !            87: 
        !            88:        /**
        !            89:         * DH Responder Nonce
        !            90:         */
        !            91:        chunk_t responder_nonce;
        !            92: 
        !            93:        /**
        !            94:         * DH Responder Public Value
        !            95:         */
        !            96:        chunk_t responder_value;
        !            97: 
        !            98:        /**
        !            99:         * Reference count
        !           100:         */
        !           101:        refcount_t ref;
        !           102: };
        !           103: 
        !           104: METHOD(pa_tnc_attr_t, get_type, pen_type_t,
        !           105:        private_tcg_pts_attr_dh_nonce_params_resp_t *this)
        !           106: {
        !           107:        return this->type;
        !           108: }
        !           109: 
        !           110: METHOD(pa_tnc_attr_t, get_value, chunk_t,
        !           111:        private_tcg_pts_attr_dh_nonce_params_resp_t *this)
        !           112: {
        !           113:        return this->value;
        !           114: }
        !           115: 
        !           116: METHOD(pa_tnc_attr_t, get_noskip_flag, bool,
        !           117:        private_tcg_pts_attr_dh_nonce_params_resp_t *this)
        !           118: {
        !           119:        return this->noskip_flag;
        !           120: }
        !           121: 
        !           122: METHOD(pa_tnc_attr_t, set_noskip_flag,void,
        !           123:        private_tcg_pts_attr_dh_nonce_params_resp_t *this, bool noskip)
        !           124: {
        !           125:        this->noskip_flag = noskip;
        !           126: }
        !           127: 
        !           128: METHOD(pa_tnc_attr_t, build, void,
        !           129:        private_tcg_pts_attr_dh_nonce_params_resp_t *this)
        !           130: {
        !           131:        bio_writer_t *writer;
        !           132: 
        !           133:        if (this->value.ptr)
        !           134:        {
        !           135:                return;
        !           136:        }
        !           137:        writer = bio_writer_create(PTS_DH_NONCE_PARAMS_RESP_SIZE);
        !           138:        writer->write_uint24(writer, PTS_DH_NONCE_PARAMS_RESP_RESERVED);
        !           139:        writer->write_uint8 (writer, this->responder_nonce.len);
        !           140:        writer->write_uint16(writer, this->dh_group);
        !           141:        writer->write_uint16(writer, this->hash_algo_set);
        !           142:        writer->write_data  (writer, this->responder_nonce);
        !           143:        writer->write_data  (writer, this->responder_value);
        !           144: 
        !           145:        this->value = writer->extract_buf(writer);
        !           146:        this->length = this->value.len;
        !           147:        writer->destroy(writer);
        !           148: }
        !           149: 
        !           150: METHOD(pa_tnc_attr_t, process, status_t,
        !           151:        private_tcg_pts_attr_dh_nonce_params_resp_t *this, uint32_t *offset)
        !           152: {
        !           153:        bio_reader_t *reader;
        !           154:        uint32_t reserved;
        !           155:        uint8_t nonce_len;
        !           156:        uint16_t dh_group, hash_algo_set;
        !           157: 
        !           158:        *offset = 0;
        !           159: 
        !           160:        if (this->value.len < this->length)
        !           161:        {
        !           162:                return NEED_MORE;
        !           163:        }
        !           164:        if (this->value.len < PTS_DH_NONCE_PARAMS_RESP_SIZE)
        !           165:        {
        !           166:                DBG1(DBG_TNC, "insufficient data for PTS DH Nonce Parameters Response");
        !           167:                return FAILED;
        !           168:        }
        !           169:        reader = bio_reader_create(this->value);
        !           170:        reader->read_uint24(reader, &reserved);
        !           171:        reader->read_uint8 (reader, &nonce_len);
        !           172:        reader->read_uint16(reader, &dh_group);
        !           173:        reader->read_uint16(reader, &hash_algo_set);
        !           174:        reader->read_data(reader, nonce_len, &this->responder_nonce);
        !           175:        reader->read_data(reader, reader->remaining(reader), &this->responder_value);
        !           176:        this->dh_group = dh_group;
        !           177:        this->hash_algo_set = hash_algo_set;
        !           178:        this->responder_nonce = chunk_clone(this->responder_nonce);
        !           179:        this->responder_value = chunk_clone(this->responder_value);
        !           180:        reader->destroy(reader);
        !           181: 
        !           182:        return SUCCESS;
        !           183: }
        !           184: 
        !           185: METHOD(pa_tnc_attr_t, add_segment, void,
        !           186:        private_tcg_pts_attr_dh_nonce_params_resp_t *this, chunk_t segment)
        !           187: {
        !           188:        this->value = chunk_cat("mc", this->value, segment);
        !           189: }
        !           190: 
        !           191: METHOD(pa_tnc_attr_t, get_ref, pa_tnc_attr_t*,
        !           192:        private_tcg_pts_attr_dh_nonce_params_resp_t *this)
        !           193: {
        !           194:        ref_get(&this->ref);
        !           195:        return &this->public.pa_tnc_attribute;
        !           196: }
        !           197: 
        !           198: METHOD(pa_tnc_attr_t, destroy, void,
        !           199:        private_tcg_pts_attr_dh_nonce_params_resp_t *this)
        !           200: {
        !           201:        if (ref_put(&this->ref))
        !           202:        {
        !           203:                free(this->value.ptr);
        !           204:                free(this->responder_nonce.ptr);
        !           205:                free(this->responder_value.ptr);
        !           206:                free(this);
        !           207:        }
        !           208: }
        !           209: 
        !           210: METHOD(tcg_pts_attr_dh_nonce_params_resp_t, get_dh_group, pts_dh_group_t,
        !           211:        private_tcg_pts_attr_dh_nonce_params_resp_t *this)
        !           212: {
        !           213:        return this->dh_group;
        !           214: }
        !           215: 
        !           216: METHOD(tcg_pts_attr_dh_nonce_params_resp_t, get_hash_algo_set,
        !           217:           pts_meas_algorithms_t, private_tcg_pts_attr_dh_nonce_params_resp_t *this)
        !           218: {
        !           219:        return this->hash_algo_set;
        !           220: }
        !           221: 
        !           222: METHOD(tcg_pts_attr_dh_nonce_params_resp_t, get_responder_nonce, chunk_t,
        !           223:        private_tcg_pts_attr_dh_nonce_params_resp_t *this)
        !           224: {
        !           225:        return this->responder_nonce;
        !           226: }
        !           227: 
        !           228: METHOD(tcg_pts_attr_dh_nonce_params_resp_t, get_responder_value, chunk_t,
        !           229:        private_tcg_pts_attr_dh_nonce_params_resp_t *this)
        !           230: {
        !           231:        return this->responder_value;
        !           232: }
        !           233: 
        !           234: /**
        !           235:  * Described in header.
        !           236:  */
        !           237: pa_tnc_attr_t *tcg_pts_attr_dh_nonce_params_resp_create(pts_dh_group_t dh_group,
        !           238:                                                                                        pts_meas_algorithms_t hash_algo_set,
        !           239:                                                                                        chunk_t responder_nonce,
        !           240:                                                                                        chunk_t responder_value)
        !           241: {
        !           242:        private_tcg_pts_attr_dh_nonce_params_resp_t *this;
        !           243: 
        !           244:        INIT(this,
        !           245:                .public = {
        !           246:                        .pa_tnc_attribute = {
        !           247:                                .get_type = _get_type,
        !           248:                                .get_value = _get_value,
        !           249:                                .get_noskip_flag = _get_noskip_flag,
        !           250:                                .set_noskip_flag = _set_noskip_flag,
        !           251:                                .build = _build,
        !           252:                                .process = _process,
        !           253:                                .add_segment = _add_segment,
        !           254:                                .get_ref = _get_ref,
        !           255:                                .destroy = _destroy,
        !           256:                        },
        !           257:                        .get_dh_group = _get_dh_group,
        !           258:                        .get_hash_algo_set = _get_hash_algo_set,
        !           259:                        .get_responder_nonce = _get_responder_nonce,
        !           260:                        .get_responder_value = _get_responder_value,
        !           261:                },
        !           262:                .type = { PEN_TCG, TCG_PTS_DH_NONCE_PARAMS_RESP },
        !           263:                .dh_group = dh_group,
        !           264:                .hash_algo_set = hash_algo_set,
        !           265:                .responder_nonce = chunk_clone(responder_nonce),
        !           266:                .responder_value = responder_value,
        !           267:                .ref = 1,
        !           268:        );
        !           269: 
        !           270:        return &this->public.pa_tnc_attribute;
        !           271: }
        !           272: 
        !           273: /**
        !           274:  * Described in header.
        !           275:  */
        !           276: pa_tnc_attr_t *tcg_pts_attr_dh_nonce_params_resp_create_from_data(size_t length,
        !           277:                                                                                                                                  chunk_t value)
        !           278: {
        !           279:        private_tcg_pts_attr_dh_nonce_params_resp_t *this;
        !           280: 
        !           281:        INIT(this,
        !           282:                .public = {
        !           283:                        .pa_tnc_attribute = {
        !           284:                                .get_type = _get_type,
        !           285:                                .get_value = _get_value,
        !           286:                                .get_noskip_flag = _get_noskip_flag,
        !           287:                                .set_noskip_flag = _set_noskip_flag,
        !           288:                                .build = _build,
        !           289:                                .process = _process,
        !           290:                                .add_segment = _add_segment,
        !           291:                                .get_ref = _get_ref,
        !           292:                                .destroy = _destroy,
        !           293:                        },
        !           294:                        .get_dh_group = _get_dh_group,
        !           295:                        .get_hash_algo_set = _get_hash_algo_set,
        !           296:                        .get_responder_nonce = _get_responder_nonce,
        !           297:                        .get_responder_value = _get_responder_value,
        !           298:                },
        !           299:                .type = { PEN_TCG, TCG_PTS_DH_NONCE_PARAMS_RESP },
        !           300:                .length = length,
        !           301:                .value = chunk_clone(value),
        !           302:                .ref = 1,
        !           303:        );
        !           304: 
        !           305:        return &this->public.pa_tnc_attribute;
        !           306: }

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