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

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