send well-formed TNCCS-Batch
[strongswan.git] / src / libcharon / plugins / eap_tnc / tnc_if_tnccs.c
1 /*
2 * Copyright (C) 2010 Andreas Steffen
3 * Copyright (C) 2010 HSR Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 #include "tnc_if_tnccs.h"
17
18 #include <debug.h>
19
20 typedef struct private_tnc_if_tnccs_t private_tnc_if_tnccs_t;
21
22 /**
23 * Private data of a tnc_if_tnccs_t object.
24 */
25 struct private_tnc_if_tnccs_t {
26
27 /**
28 * Public tls_t interface.
29 */
30 tls_t public;
31
32 /**
33 * Role this TNC IF-TNCCS stack acts as.
34 */
35 bool is_server;
36
37 /**
38 * TLS stack purpose, as given to constructor
39 */
40 tls_purpose_t purpose;
41 };
42
43 METHOD(tls_t, process, status_t,
44 private_tnc_if_tnccs_t *this, void *buf, size_t buflen)
45 {
46 /* TODO */
47 return NEED_MORE;
48 }
49
50 METHOD(tls_t, build, status_t,
51 private_tnc_if_tnccs_t *this, void *buf, size_t *buflen, size_t *msglen)
52 {
53 char output[] =
54 "<?xml version=\"1.0\"?> "
55 "<TNCCS-Batch BatchId=\"1\" Recipient=\"TNCS\" "
56 "xmlns=\"http://www.trustedcomputinggroup.org/IWG/TNC/1_0/IF_TNCCS#\" "
57 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
58 "xsi:schemaLocation=\"http://www.trustedcomputinggroup.org/IWG/TNC/1_0/IF_TNCCS# "
59 "https://www.trustedcomputinggroup.org/XML/SCHEMA/TNCCS_1.0.xsd\"> "
60 "</TNCCS-Batch>";
61
62 size_t len = strlen(output);
63
64 /* TODO */
65 *buflen = len;
66 *msglen = len;
67 memcpy(buf, output, len);
68
69 return ALREADY_DONE;
70 }
71
72 METHOD(tls_t, is_server, bool,
73 private_tnc_if_tnccs_t *this)
74 {
75 return this->is_server;
76 }
77
78 METHOD(tls_t, get_purpose, tls_purpose_t,
79 private_tnc_if_tnccs_t *this)
80 {
81 return this->purpose;
82 }
83
84 METHOD(tls_t, is_complete, bool,
85 private_tnc_if_tnccs_t *this)
86 {
87 /* TODO */
88 return TRUE;
89 }
90
91 METHOD(tls_t, get_eap_msk, chunk_t,
92 private_tnc_if_tnccs_t *this)
93 {
94 return chunk_empty;
95 }
96
97 METHOD(tls_t, destroy, void,
98 private_tnc_if_tnccs_t *this)
99 {
100 free(this);
101 }
102
103 /**
104 * See header
105 */
106 tls_t *tnc_if_tnccs_create(bool is_server, tls_purpose_t purpose)
107 {
108 private_tnc_if_tnccs_t *this;
109
110 switch (purpose)
111 {
112 case TLS_PURPOSE_EAP_TNC:
113 break;
114 default:
115 return NULL;
116 }
117
118 INIT(this,
119 .public = {
120 .process = _process,
121 .build = _build,
122 .is_server = _is_server,
123 .get_purpose = _get_purpose,
124 .is_complete = _is_complete,
125 .get_eap_msk = _get_eap_msk,
126 .destroy = _destroy,
127 },
128 .is_server = is_server,
129 .purpose = purpose,
130 );
131
132 return &this->public;
133 }