from Gerhard Gappmeier (ascolab):
[obnox/wireshark/wip.git] / plugins / opcua / ua_security_layer.c
1 /******************************************************************************\r
2 ** $Id: ua_security_layer.c,v 1.2 2007/02/08 12:16:59 gergap Exp $\r
3 **\r
4 ** Copyright (C) 2006-2007 ascolab GmbH. All Rights Reserved.\r
5 ** Web: http://www.ascolab.com\r
6 ** \r
7 ** This program is free software; you can redistribute it and/or\r
8 ** modify it under the terms of the GNU General Public License\r
9 ** as published by the Free Software Foundation; either version 2\r
10 ** of the License, or (at your option) any later version.\r
11 ** \r
12 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE\r
13 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\r
14 ** \r
15 ** Project: OpcUa Wireshark Plugin\r
16 **\r
17 ** Description: OpcUa Security Layer Decoder.\r
18 **\r
19 ** Author: Gerhard Gappmeier <gerhard.gappmeier@ascolab.com>\r
20 ** Last change by: $Author: gergap $\r
21 **\r
22 ******************************************************************************/\r
23 \r
24 #ifdef HAVE_CONFIG_H\r
25 # include "config.h"\r
26 #endif\r
27 \r
28 #include <gmodule.h>\r
29 #include <epan/packet.h>\r
30 #include "ua_application_layer.h"\r
31 #include "opcua_simpletypes.h"\r
32 \r
33 /** NodeClass enum table */\r
34 static const value_string g_SecSigTable[] = {
35   { 0, "GetSecurityPolcies" },
36   { 1, "OpenSecureChannel" },
37   { 2, "CloseSecureChannel" },
38   { 3, "Message" },\r
39   { 0, NULL }
40 };\r
41 static int hf_opcua_SecuritySigEnum = -1;\r
42 \r
43 static int hf_opcua_security_sig = -1;\r
44 static int hf_opcua_security_policy = -1;\r
45 static int hf_opcua_security_channel = -1;\r
46 static int hf_opcua_security_token = -1;\r
47 \r
48 static hf_register_info hf[] =\r
49 {\r
50     { &hf_opcua_security_sig,\r
51     {  "Security Signature",       "security.sig",     FT_UINT16, BASE_HEX,  VALS(g_SecSigTable), 0x0, "", HFILL }\r
52     },\r
53     { &hf_opcua_security_policy,\r
54     {  "Security Policy",          "security.policy",  FT_STRING, BASE_NONE,  NULL, 0x0,    "",    HFILL }\r
55     },\r
56     { &hf_opcua_security_channel,\r
57     {  "Secure Channel Id",        "security.channel", FT_GUID,   BASE_NONE,  NULL, 0x0,    "",    HFILL }\r
58     },\r
59     { &hf_opcua_security_token,\r
60     {  "Security Token Id",        "security.token",   FT_STRING, BASE_NONE,  NULL, 0x0,    "",    HFILL }\r
61     }\r
62 };\r
63 \r
64 /** Register security layer types. */\r
65 void registerSecurityLayerTypes(int proto)\r
66 {\r
67     proto_register_field_array(proto, hf, array_length(hf));\r
68 }\r
69 \r
70 \r
71 /* Security Layer: message parsers\r
72  * Only works for Security Policy "NoSecurity" at the moment.\r
73  */\r
74 void parseSecurityLayer(proto_tree *tree, tvbuff_t *tvb, gint *pOffset)\r
75 {\r
76     guint16 Sig;\r
77     \r
78     Sig = tvb_get_letohs(tvb, pOffset[0]);\r
79     proto_tree_add_item(tree, hf_opcua_security_sig, tvb, *pOffset, 2, TRUE); *pOffset+=2;\r
80 \r
81     switch (Sig)\r
82     {\r
83     case 0: /* GetSecurityPolicies */\r
84         break;\r
85     case 1: /* OpenSecureChannel */\r
86         parseGuid(tree, tvb,   pOffset, hf_opcua_security_channel);\r
87         parseString(tree, tvb, pOffset, hf_opcua_security_policy);\r
88         break;\r
89     case 2: /* CloseSecureChannel */\r
90         parseGuid(tree, tvb,   pOffset, hf_opcua_security_channel);\r
91         parseString(tree, tvb, pOffset, hf_opcua_security_token);\r
92         break;\r
93     case 3: /* Other Services Messages */\r
94         parseGuid(tree, tvb,   pOffset, hf_opcua_security_channel);\r
95         parseString(tree, tvb, pOffset, hf_opcua_security_token);\r
96         break;\r
97     }\r
98 }\r
99 \r