Annotation of embedaddon/strongswan/src/libimcv/tcg/pts/tcg_pts_attr_get_tpm_version_info.c, revision 1.1.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_get_tpm_version_info.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_get_tpm_version_info_t
                     25:                                        private_tcg_pts_attr_get_tpm_version_info_t;
                     26: 
                     27: /**
                     28:  * Get TPM Version Information
                     29:  * see section 3.10 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:  *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                     35:  *  |                                             Reserved                                                             |
                     36:  *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                     37:  *
                     38:  */
                     39: 
                     40: #define PTS_GET_TPM_VER_INFO_SIZE              4
                     41: #define PTS_GET_TPM_VER_INFO_RESERVED  0x00
                     42: 
                     43: /**
                     44:  * Private data of an tcg_pts_attr_get_tpm_version_info_t object.
                     45:  */
                     46: struct private_tcg_pts_attr_get_tpm_version_info_t {
                     47: 
                     48:        /**
                     49:         * Public members of tcg_pts_attr_get_tpm_version_info_t
                     50:         */
                     51:        tcg_pts_attr_get_tpm_version_info_t public;
                     52: 
                     53:        /**
                     54:         * Vendor-specific attribute type
                     55:         */
                     56:        pen_type_t type;
                     57: 
                     58:        /**
                     59:         * Length of attribute value
                     60:         */
                     61:        size_t length;
                     62: 
                     63:        /**
                     64:         * Attribute value or segment
                     65:         */
                     66:        chunk_t value;
                     67: 
                     68:        /**
                     69:         * Noskip flag
                     70:         */
                     71:        bool noskip_flag;
                     72: 
                     73:        /**
                     74:         * Reference count
                     75:         */
                     76:        refcount_t ref;
                     77: };
                     78: 
                     79: METHOD(pa_tnc_attr_t, get_type, pen_type_t,
                     80:        private_tcg_pts_attr_get_tpm_version_info_t *this)
                     81: {
                     82:        return this->type;
                     83: }
                     84: 
                     85: METHOD(pa_tnc_attr_t, get_value, chunk_t,
                     86:        private_tcg_pts_attr_get_tpm_version_info_t *this)
                     87: {
                     88:        return this->value;
                     89: }
                     90: 
                     91: METHOD(pa_tnc_attr_t, get_noskip_flag, bool,
                     92:        private_tcg_pts_attr_get_tpm_version_info_t *this)
                     93: {
                     94:        return this->noskip_flag;
                     95: }
                     96: 
                     97: METHOD(pa_tnc_attr_t, set_noskip_flag,void,
                     98:        private_tcg_pts_attr_get_tpm_version_info_t *this, bool noskip)
                     99: {
                    100:        this->noskip_flag = noskip;
                    101: }
                    102: 
                    103: METHOD(pa_tnc_attr_t, build, void,
                    104:        private_tcg_pts_attr_get_tpm_version_info_t *this)
                    105: {
                    106:        bio_writer_t *writer;
                    107: 
                    108:        if (this->value.ptr)
                    109:        {
                    110:                return;
                    111:        }
                    112:        writer = bio_writer_create(PTS_GET_TPM_VER_INFO_SIZE);
                    113:        writer->write_uint32 (writer, PTS_GET_TPM_VER_INFO_RESERVED);
                    114: 
                    115:        this->value = writer->extract_buf(writer);
                    116:        this->length = this->value.len;
                    117:        writer->destroy(writer);
                    118: }
                    119: 
                    120: METHOD(pa_tnc_attr_t, process, status_t,
                    121:        private_tcg_pts_attr_get_tpm_version_info_t *this, uint32_t *offset)
                    122: {
                    123:        bio_reader_t *reader;
                    124:        uint32_t reserved;
                    125: 
                    126:        *offset = 0;
                    127: 
                    128:        if (this->value.len < this->length)
                    129:        {
                    130:                return NEED_MORE;
                    131:        }
                    132:        if (this->value.len < PTS_GET_TPM_VER_INFO_SIZE)
                    133:        {
                    134:                DBG1(DBG_TNC, "insufficient data for Get TPM Version Information");
                    135:                return FAILED;
                    136:        }
                    137:        reader = bio_reader_create(this->value);
                    138:        reader->read_uint32 (reader, &reserved);
                    139:        reader->destroy(reader);
                    140: 
                    141:        return SUCCESS;
                    142: }
                    143: 
                    144: METHOD(pa_tnc_attr_t, add_segment, void,
                    145:        private_tcg_pts_attr_get_tpm_version_info_t *this, chunk_t segment)
                    146: {
                    147:        this->value = chunk_cat("mc", this->value, segment);
                    148: }
                    149: 
                    150: METHOD(pa_tnc_attr_t, get_ref, pa_tnc_attr_t*,
                    151:        private_tcg_pts_attr_get_tpm_version_info_t *this)
                    152: {
                    153:        ref_get(&this->ref);
                    154:        return &this->public.pa_tnc_attribute;
                    155: }
                    156: 
                    157: METHOD(pa_tnc_attr_t, destroy, void,
                    158:        private_tcg_pts_attr_get_tpm_version_info_t *this)
                    159: {
                    160:        if (ref_put(&this->ref))
                    161:        {
                    162:                free(this->value.ptr);
                    163:                free(this);
                    164:        }
                    165: }
                    166: 
                    167: /**
                    168:  * Described in header.
                    169:  */
                    170: pa_tnc_attr_t *tcg_pts_attr_get_tpm_version_info_create()
                    171: {
                    172:        private_tcg_pts_attr_get_tpm_version_info_t *this;
                    173: 
                    174:        INIT(this,
                    175:                .public = {
                    176:                        .pa_tnc_attribute = {
                    177:                                .get_type = _get_type,
                    178:                                .get_value = _get_value,
                    179:                                .get_noskip_flag = _get_noskip_flag,
                    180:                                .set_noskip_flag = _set_noskip_flag,
                    181:                                .build = _build,
                    182:                                .process = _process,
                    183:                                .add_segment = _add_segment,
                    184:                                .get_ref = _get_ref,
                    185:                                .destroy = _destroy,
                    186:                        },
                    187:                },
                    188:                .type = { PEN_TCG, TCG_PTS_GET_TPM_VERSION_INFO },
                    189:                .ref = 1,
                    190:        );
                    191: 
                    192:        return &this->public.pa_tnc_attribute;
                    193: }
                    194: 
                    195: 
                    196: /**
                    197:  * Described in header.
                    198:  */
                    199: pa_tnc_attr_t *tcg_pts_attr_get_tpm_version_info_create_from_data(size_t length,
                    200:                                                                                                                                  chunk_t data)
                    201: {
                    202:        private_tcg_pts_attr_get_tpm_version_info_t *this;
                    203: 
                    204:        INIT(this,
                    205:                .public = {
                    206:                        .pa_tnc_attribute = {
                    207:                                .get_type = _get_type,
                    208:                                .get_value = _get_value,
                    209:                                .get_noskip_flag = _get_noskip_flag,
                    210:                                .set_noskip_flag = _set_noskip_flag,
                    211:                                .build = _build,
                    212:                                .process = _process,
                    213:                                .add_segment = _add_segment,
                    214:                                .get_ref = _get_ref,
                    215:                                .destroy = _destroy,
                    216:                        },
                    217:                },
                    218:                .type = { PEN_TCG, TCG_PTS_GET_TPM_VERSION_INFO },
                    219:                .length = length,
                    220:                .value = chunk_clone(data),
                    221:                .ref = 1,
                    222:        );
                    223: 
                    224:        return &this->public.pa_tnc_attribute;
                    225: }

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