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

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