Return to auth_payload.c CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / strongswan / src / libcharon / encoding / payloads |
1.1 misho 1: /* 2: * Copyright (C) 2005-2010 Martin Willi 3: * Copyright (C) 2010 revosec AG 4: * Copyright (C) 2005 Jan Hutter 5: * HSR Hochschule fuer Technik Rapperswil 6: * 7: * This program is free software; you can redistribute it and/or modify it 8: * under the terms of the GNU General Public License as published by the 9: * Free Software Foundation; either version 2 of the License, or (at your 10: * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. 11: * 12: * This program is distributed in the hope that it will be useful, but 13: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15: * for more details. 16: */ 17: 18: #include "auth_payload.h" 19: 20: #include <encoding/payloads/encodings.h> 21: 22: typedef struct private_auth_payload_t private_auth_payload_t; 23: 24: /** 25: * Private data of an auth_payload_t object. 26: * 27: */ 28: struct private_auth_payload_t { 29: 30: /** 31: * Public auth_payload_t interface. 32: */ 33: auth_payload_t public; 34: 35: /** 36: * Next payload type. 37: */ 38: uint8_t next_payload; 39: 40: /** 41: * Critical flag. 42: */ 43: bool critical; 44: 45: /** 46: * Reserved bits 47: */ 48: bool reserved_bit[7]; 49: 50: /** 51: * Reserved bytes 52: */ 53: uint8_t reserved_byte[3]; 54: 55: /** 56: * Length of this payload. 57: */ 58: uint16_t payload_length; 59: 60: /** 61: * Method of the AUTH Data. 62: */ 63: uint8_t auth_method; 64: 65: /** 66: * The contained auth data value. 67: */ 68: chunk_t auth_data; 69: }; 70: 71: /** 72: * Encoding rules to parse or generate a AUTH payload 73: * 74: * The defined offsets are the positions in a object of type 75: * private_auth_payload_t. 76: */ 77: static encoding_rule_t encodings[] = { 78: /* 1 Byte next payload type, stored in the field next_payload */ 79: { U_INT_8, offsetof(private_auth_payload_t, next_payload) }, 80: /* the critical bit */ 81: { FLAG, offsetof(private_auth_payload_t, critical) }, 82: /* 7 Bit reserved bits */ 83: { RESERVED_BIT, offsetof(private_auth_payload_t, reserved_bit[0]) }, 84: { RESERVED_BIT, offsetof(private_auth_payload_t, reserved_bit[1]) }, 85: { RESERVED_BIT, offsetof(private_auth_payload_t, reserved_bit[2]) }, 86: { RESERVED_BIT, offsetof(private_auth_payload_t, reserved_bit[3]) }, 87: { RESERVED_BIT, offsetof(private_auth_payload_t, reserved_bit[4]) }, 88: { RESERVED_BIT, offsetof(private_auth_payload_t, reserved_bit[5]) }, 89: { RESERVED_BIT, offsetof(private_auth_payload_t, reserved_bit[6]) }, 90: /* Length of the whole payload*/ 91: { PAYLOAD_LENGTH, offsetof(private_auth_payload_t, payload_length) }, 92: /* 1 Byte AUTH type*/ 93: { U_INT_8, offsetof(private_auth_payload_t, auth_method) }, 94: /* 3 reserved bytes */ 95: { RESERVED_BYTE, offsetof(private_auth_payload_t, reserved_byte[0]) }, 96: { RESERVED_BYTE, offsetof(private_auth_payload_t, reserved_byte[1]) }, 97: { RESERVED_BYTE, offsetof(private_auth_payload_t, reserved_byte[2]) }, 98: /* some auth data bytes, length is defined in PAYLOAD_LENGTH */ 99: { CHUNK_DATA, offsetof(private_auth_payload_t, auth_data) } 100: }; 101: 102: /* 103: 1 2 3 104: 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 105: +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 106: ! Next Payload !C! RESERVED ! Payload Length ! 107: +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 108: ! Auth Method ! RESERVED ! 109: +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 110: ! ! 111: ~ Authentication Data ~ 112: ! ! 113: +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 114: */ 115: 116: METHOD(payload_t, verify, status_t, 117: private_auth_payload_t *this) 118: { 119: return SUCCESS; 120: } 121: 122: METHOD(payload_t, get_encoding_rules, int, 123: private_auth_payload_t *this, encoding_rule_t **rules) 124: { 125: *rules = encodings; 126: return countof(encodings); 127: } 128: 129: METHOD(payload_t, get_header_length, int, 130: private_auth_payload_t *this) 131: { 132: return 8; 133: } 134: 135: METHOD(payload_t, get_type, payload_type_t, 136: private_auth_payload_t *this) 137: { 138: return PLV2_AUTH; 139: } 140: 141: METHOD(payload_t, get_next_type, payload_type_t, 142: private_auth_payload_t *this) 143: { 144: return this->next_payload; 145: } 146: 147: METHOD(payload_t, set_next_type, void, 148: private_auth_payload_t *this, payload_type_t type) 149: { 150: this->next_payload = type; 151: } 152: 153: METHOD(payload_t, get_length, size_t, 154: private_auth_payload_t *this) 155: { 156: return this->payload_length; 157: } 158: 159: METHOD(auth_payload_t, set_auth_method, void, 160: private_auth_payload_t *this, auth_method_t method) 161: { 162: this->auth_method = method; 163: } 164: 165: METHOD(auth_payload_t, get_auth_method, auth_method_t, 166: private_auth_payload_t *this) 167: { 168: return this->auth_method; 169: } 170: 171: METHOD(auth_payload_t, set_data, void, 172: private_auth_payload_t *this, chunk_t data) 173: { 174: free(this->auth_data.ptr); 175: this->auth_data = chunk_clone(data); 176: this->payload_length = get_header_length(this) + this->auth_data.len; 177: } 178: 179: METHOD(auth_payload_t, get_data, chunk_t, 180: private_auth_payload_t *this) 181: { 182: return this->auth_data; 183: } 184: 185: METHOD2(payload_t, auth_payload_t, destroy, void, 186: private_auth_payload_t *this) 187: { 188: free(this->auth_data.ptr); 189: free(this); 190: } 191: 192: /* 193: * Described in header 194: */ 195: auth_payload_t *auth_payload_create() 196: { 197: private_auth_payload_t *this; 198: 199: INIT(this, 200: .public = { 201: .payload_interface = { 202: .verify = _verify, 203: .get_encoding_rules = _get_encoding_rules, 204: .get_header_length = _get_header_length, 205: .get_length = _get_length, 206: .get_next_type = _get_next_type, 207: .set_next_type = _set_next_type, 208: .get_type = _get_type, 209: .destroy = _destroy, 210: }, 211: .set_auth_method = _set_auth_method, 212: .get_auth_method = _get_auth_method, 213: .set_data = _set_data, 214: .get_data = _get_data, 215: .destroy = _destroy, 216: }, 217: .next_payload = PL_NONE, 218: .payload_length = get_header_length(this), 219: ); 220: return &this->public; 221: }