2007-05-15 09:05:53 +00:00
|
|
|
/******************************************************************************
|
|
|
|
** $Id$
|
|
|
|
**
|
2009-04-06 18:30:04 +00:00
|
|
|
** Copyright (C) 2006-2009 ascolab GmbH. All Rights Reserved.
|
2007-05-15 09:05:53 +00:00
|
|
|
** Web: http://www.ascolab.com
|
|
|
|
**
|
|
|
|
** This program is free software; you can redistribute it and/or
|
|
|
|
** modify it under the terms of the GNU General Public License
|
|
|
|
** as published by the Free Software Foundation; either version 2
|
|
|
|
** of the License, or (at your option) any later version.
|
|
|
|
**
|
|
|
|
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
|
|
|
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
**
|
|
|
|
** Project: OpcUa Wireshark Plugin
|
|
|
|
**
|
|
|
|
** Description: OpcUa Transport Layer Decoder.
|
|
|
|
**
|
|
|
|
** Author: Gerhard Gappmeier <gerhard.gappmeier@ascolab.com>
|
|
|
|
** Last change by: $Author: gergap $
|
|
|
|
**
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2007-05-21 18:08:47 +00:00
|
|
|
#include <glib.h>
|
2007-05-15 09:05:53 +00:00
|
|
|
#include <epan/packet.h>
|
2007-05-15 09:53:26 +00:00
|
|
|
#include "opcua_security_layer.h"
|
|
|
|
#include "opcua_application_layer.h"
|
2007-05-15 09:05:53 +00:00
|
|
|
#include "opcua_simpletypes.h"
|
|
|
|
|
|
|
|
void dispatchService(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int ServiceId);
|
|
|
|
|
2009-04-06 18:30:04 +00:00
|
|
|
static int hf_opcua_transport_type = -1;
|
|
|
|
static int hf_opcua_transport_chunk = -1;
|
|
|
|
static int hf_opcua_transport_size = -1;
|
2007-05-15 09:05:53 +00:00
|
|
|
static int hf_opcua_transport_ver = -1;
|
2009-04-06 18:30:04 +00:00
|
|
|
static int hf_opcua_transport_scid = -1;
|
2007-05-15 09:05:53 +00:00
|
|
|
static int hf_opcua_transport_lifetime = -1;
|
2009-04-06 18:30:04 +00:00
|
|
|
static int hf_opcua_transport_rbs = -1;
|
|
|
|
static int hf_opcua_transport_sbs = -1;
|
|
|
|
static int hf_opcua_transport_mms = -1;
|
|
|
|
static int hf_opcua_transport_mcc = -1;
|
2007-05-15 09:05:53 +00:00
|
|
|
static int hf_opcua_transport_endpoint = -1;
|
2009-04-06 18:30:04 +00:00
|
|
|
static int hf_opcua_transport_error = -1;
|
|
|
|
static int hf_opcua_transport_reason = -1;
|
|
|
|
static int hf_opcua_transport_spu = -1;
|
|
|
|
static int hf_opcua_transport_scert = -1;
|
|
|
|
static int hf_opcua_transport_rcthumb = -1;
|
|
|
|
static int hf_opcua_transport_seq = -1;
|
2007-05-15 09:05:53 +00:00
|
|
|
static int hf_opcua_transport_rqid = -1;
|
|
|
|
extern gint ett_opcua_nodeid;
|
|
|
|
|
|
|
|
/** subtree types */
|
|
|
|
extern gint ett_opcua_extensionobject;
|
|
|
|
|
|
|
|
/** Register transport layer types. */
|
|
|
|
void registerTransportLayerTypes(int proto)
|
|
|
|
{
|
2009-06-22 04:58:08 +00:00
|
|
|
static hf_register_info hf[] =
|
|
|
|
{
|
|
|
|
{ &hf_opcua_transport_type,
|
|
|
|
/* full name , abbreviation , type , display , strings, bitmask, blurb, id, parent, ref_count, bitshift */
|
2009-06-22 18:23:58 +00:00
|
|
|
{ "Message Type", "transport.type", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }
|
2009-06-22 04:58:08 +00:00
|
|
|
},
|
|
|
|
{ &hf_opcua_transport_chunk,
|
2009-06-22 18:23:58 +00:00
|
|
|
{ "Chunk Type", "transport.chunk", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }
|
2009-06-22 04:58:08 +00:00
|
|
|
},
|
|
|
|
{ &hf_opcua_transport_size,
|
2009-06-22 18:23:58 +00:00
|
|
|
{ "Message Size", "transport.size", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
|
2009-06-22 04:58:08 +00:00
|
|
|
},
|
|
|
|
{ &hf_opcua_transport_ver,
|
2009-06-22 18:23:58 +00:00
|
|
|
{ "Version", "transport.ver", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
|
2009-06-22 04:58:08 +00:00
|
|
|
},
|
|
|
|
{ &hf_opcua_transport_scid,
|
2009-06-22 18:23:58 +00:00
|
|
|
{ "SecureChannelId", "transport.scid", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
|
2009-06-22 04:58:08 +00:00
|
|
|
},
|
|
|
|
{ &hf_opcua_transport_lifetime,
|
2009-06-22 18:23:58 +00:00
|
|
|
{ "Lifetime", "transport.lifetime", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
|
2009-06-22 04:58:08 +00:00
|
|
|
},
|
|
|
|
{ &hf_opcua_transport_rbs,
|
2009-06-22 18:23:58 +00:00
|
|
|
{ "ReceiveBufferSize", "transport.rbs", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
|
2009-06-22 04:58:08 +00:00
|
|
|
},
|
|
|
|
{ &hf_opcua_transport_sbs,
|
2009-06-22 18:23:58 +00:00
|
|
|
{ "SendBufferSize", "transport.sbs", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
|
2009-06-22 04:58:08 +00:00
|
|
|
},
|
|
|
|
{ &hf_opcua_transport_mms,
|
2009-06-22 18:23:58 +00:00
|
|
|
{ "MaxMessageSize", "transport.mms", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
|
2009-06-22 04:58:08 +00:00
|
|
|
},
|
|
|
|
{ &hf_opcua_transport_mcc,
|
2009-06-22 18:23:58 +00:00
|
|
|
{ "MaxChunkCount", "transport.mcc", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
|
2009-06-22 04:58:08 +00:00
|
|
|
},
|
|
|
|
{ &hf_opcua_transport_endpoint,
|
2009-06-22 18:23:58 +00:00
|
|
|
{ "EndPointUrl", "transport.endpoint", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }
|
2009-06-22 04:58:08 +00:00
|
|
|
},
|
|
|
|
{ &hf_opcua_transport_error,
|
2009-06-22 18:23:58 +00:00
|
|
|
{ "Error", "transport.error", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL }
|
2009-06-22 04:58:08 +00:00
|
|
|
},
|
|
|
|
{ &hf_opcua_transport_reason,
|
2009-06-22 18:23:58 +00:00
|
|
|
{ "Reason", "transport.reason", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }
|
2009-06-22 04:58:08 +00:00
|
|
|
},
|
|
|
|
/* { &hf_opcua_transport_spul,
|
|
|
|
{ "SecurityPolicyUriLength", "transport.spul", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }
|
|
|
|
},*/
|
|
|
|
{ &hf_opcua_transport_spu,
|
2009-06-22 18:23:58 +00:00
|
|
|
{ "SecurityPolicyUri", "security.spu", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }
|
2009-06-22 04:58:08 +00:00
|
|
|
},
|
|
|
|
{ &hf_opcua_transport_scert,
|
2009-06-22 18:23:58 +00:00
|
|
|
{ "SenderCertificate", "security.scert", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
|
2009-06-22 04:58:08 +00:00
|
|
|
},
|
|
|
|
{ &hf_opcua_transport_rcthumb,
|
2009-06-22 18:23:58 +00:00
|
|
|
{ "ReceiverCertificateThumbprint", "security.rcthumb", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
|
2009-06-22 04:58:08 +00:00
|
|
|
},
|
|
|
|
{ &hf_opcua_transport_seq,
|
2009-06-22 18:23:58 +00:00
|
|
|
{ "SequenceNumber", "security.seq", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
|
2009-06-22 04:58:08 +00:00
|
|
|
},
|
|
|
|
{ &hf_opcua_transport_rqid,
|
2009-06-22 18:23:58 +00:00
|
|
|
{ "RequestId", "security.rqid", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
|
2009-06-22 04:58:08 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2007-05-15 09:05:53 +00:00
|
|
|
proto_register_field_array(proto, hf, array_length(hf));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Transport Layer: message parsers */
|
2010-12-04 02:54:59 +00:00
|
|
|
int parseHello(proto_tree *tree, tvbuff_t *tvb, gint *pOffset)
|
2007-05-15 09:05:53 +00:00
|
|
|
{
|
2011-10-18 00:17:48 +00:00
|
|
|
proto_tree_add_item(tree, hf_opcua_transport_type, tvb, *pOffset, 3, ENC_ASCII|ENC_NA); *pOffset+=3;
|
2011-10-15 19:58:31 +00:00
|
|
|
proto_tree_add_item(tree, hf_opcua_transport_chunk, tvb, *pOffset, 1, ENC_ASCII|ENC_NA); *pOffset+=1;
|
2011-10-06 14:46:34 +00:00
|
|
|
proto_tree_add_item(tree, hf_opcua_transport_size, tvb, *pOffset, 4, ENC_LITTLE_ENDIAN); *pOffset+=4;
|
|
|
|
proto_tree_add_item(tree, hf_opcua_transport_ver, tvb, *pOffset, 4, ENC_LITTLE_ENDIAN); *pOffset+=4;
|
|
|
|
proto_tree_add_item(tree, hf_opcua_transport_rbs, tvb, *pOffset, 4, ENC_LITTLE_ENDIAN); *pOffset+=4;
|
|
|
|
proto_tree_add_item(tree, hf_opcua_transport_sbs, tvb, *pOffset, 4, ENC_LITTLE_ENDIAN); *pOffset+=4;
|
|
|
|
proto_tree_add_item(tree, hf_opcua_transport_mms, tvb, *pOffset, 4, ENC_LITTLE_ENDIAN); *pOffset+=4;
|
|
|
|
proto_tree_add_item(tree, hf_opcua_transport_mcc, tvb, *pOffset, 4, ENC_LITTLE_ENDIAN); *pOffset+=4;
|
2007-05-15 09:05:53 +00:00
|
|
|
parseString(tree, tvb, pOffset, hf_opcua_transport_endpoint);
|
2010-12-04 02:54:59 +00:00
|
|
|
return -1;
|
2007-05-15 09:05:53 +00:00
|
|
|
}
|
|
|
|
|
2010-12-04 02:54:59 +00:00
|
|
|
int parseAcknowledge(proto_tree *tree, tvbuff_t *tvb, gint *pOffset)
|
2007-05-15 09:05:53 +00:00
|
|
|
{
|
2011-10-18 00:17:48 +00:00
|
|
|
proto_tree_add_item(tree, hf_opcua_transport_type, tvb, *pOffset, 3, ENC_ASCII|ENC_NA); *pOffset+=3;
|
2011-10-15 19:58:31 +00:00
|
|
|
proto_tree_add_item(tree, hf_opcua_transport_chunk, tvb, *pOffset, 1, ENC_ASCII|ENC_NA); *pOffset+=1;
|
2011-10-06 14:46:34 +00:00
|
|
|
proto_tree_add_item(tree, hf_opcua_transport_size, tvb, *pOffset, 4, ENC_LITTLE_ENDIAN); *pOffset+=4;
|
|
|
|
proto_tree_add_item(tree, hf_opcua_transport_ver, tvb, *pOffset, 4, ENC_LITTLE_ENDIAN); *pOffset+=4;
|
|
|
|
proto_tree_add_item(tree, hf_opcua_transport_rbs, tvb, *pOffset, 4, ENC_LITTLE_ENDIAN); *pOffset+=4;
|
|
|
|
proto_tree_add_item(tree, hf_opcua_transport_sbs, tvb, *pOffset, 4, ENC_LITTLE_ENDIAN); *pOffset+=4;
|
|
|
|
proto_tree_add_item(tree, hf_opcua_transport_mms, tvb, *pOffset, 4, ENC_LITTLE_ENDIAN); *pOffset+=4;
|
|
|
|
proto_tree_add_item(tree, hf_opcua_transport_mcc, tvb, *pOffset, 4, ENC_LITTLE_ENDIAN); *pOffset+=4;
|
2010-12-04 02:54:59 +00:00
|
|
|
return -1;
|
2007-05-15 09:05:53 +00:00
|
|
|
}
|
|
|
|
|
2010-12-04 02:54:59 +00:00
|
|
|
int parseError(proto_tree *tree, tvbuff_t *tvb, gint *pOffset)
|
2007-05-15 09:05:53 +00:00
|
|
|
{
|
2011-10-18 00:17:48 +00:00
|
|
|
proto_tree_add_item(tree, hf_opcua_transport_type, tvb, *pOffset, 3, ENC_ASCII|ENC_NA); *pOffset+=3;
|
2011-10-15 19:58:31 +00:00
|
|
|
proto_tree_add_item(tree, hf_opcua_transport_chunk, tvb, *pOffset, 1, ENC_ASCII|ENC_NA); *pOffset+=1;
|
2011-10-06 14:46:34 +00:00
|
|
|
proto_tree_add_item(tree, hf_opcua_transport_size, tvb, *pOffset, 4, ENC_LITTLE_ENDIAN); *pOffset+=4;
|
|
|
|
proto_tree_add_item(tree, hf_opcua_transport_error, tvb, *pOffset, 4, ENC_LITTLE_ENDIAN); *pOffset+=4;
|
2009-04-06 18:30:04 +00:00
|
|
|
parseString(tree, tvb, pOffset, hf_opcua_transport_reason);
|
2010-12-04 02:54:59 +00:00
|
|
|
return -1;
|
2007-05-15 09:05:53 +00:00
|
|
|
}
|
|
|
|
|
2010-12-04 02:54:59 +00:00
|
|
|
int parseMessage(proto_tree *tree, tvbuff_t *tvb, gint *pOffset)
|
2007-05-15 09:05:53 +00:00
|
|
|
{
|
|
|
|
proto_item *ti;
|
|
|
|
proto_tree *encobj_tree;
|
|
|
|
proto_tree *nodeid_tree;
|
|
|
|
int ServiceId = 0;
|
|
|
|
|
2011-10-18 00:17:48 +00:00
|
|
|
proto_tree_add_item(tree, hf_opcua_transport_type, tvb, *pOffset, 3, ENC_ASCII|ENC_NA); *pOffset+=3;
|
2011-10-15 19:58:31 +00:00
|
|
|
proto_tree_add_item(tree, hf_opcua_transport_chunk, tvb, *pOffset, 1, ENC_ASCII|ENC_NA); *pOffset+=1;
|
2011-10-06 14:46:34 +00:00
|
|
|
proto_tree_add_item(tree, hf_opcua_transport_size, tvb, *pOffset, 4, ENC_LITTLE_ENDIAN); *pOffset+=4;
|
|
|
|
proto_tree_add_item(tree, hf_opcua_transport_scid, tvb, *pOffset, 4, ENC_LITTLE_ENDIAN); *pOffset+=4;
|
2007-05-15 09:05:53 +00:00
|
|
|
|
|
|
|
/* message data contains the security layer */
|
|
|
|
parseSecurityLayer(tree, tvb, pOffset);
|
|
|
|
|
|
|
|
/* AT THE MOMENT NO SECURITY IS IMPLEMENTED IN UA.
|
|
|
|
* WE CAN JUST JUMP INTO THE APPLICATION LAYER DATA.
|
|
|
|
* THIS WILL CHAHNGE IN THE FUTURE. */
|
|
|
|
|
|
|
|
/* add encodeable object subtree */
|
|
|
|
ti = proto_tree_add_text(tree, tvb, 0, -1, "Message : Encodeable Object");
|
|
|
|
encobj_tree = proto_item_add_subtree(ti, ett_opcua_extensionobject);
|
|
|
|
|
|
|
|
/* add nodeid subtree */
|
|
|
|
ti = proto_tree_add_text(encobj_tree, tvb, 0, -1, "TypeId : ExpandedNodeId");
|
|
|
|
nodeid_tree = proto_item_add_subtree(ti, ett_opcua_nodeid);
|
2011-03-23 08:03:02 +00:00
|
|
|
ServiceId = parseServiceNodeId(nodeid_tree, tvb, pOffset);
|
2007-05-15 09:05:53 +00:00
|
|
|
|
|
|
|
dispatchService(encobj_tree, tvb, pOffset, ServiceId);
|
2010-12-04 02:54:59 +00:00
|
|
|
return ServiceId;
|
2007-05-15 09:05:53 +00:00
|
|
|
}
|
|
|
|
|
2010-12-04 02:54:59 +00:00
|
|
|
int parseOpenSecureChannel(proto_tree *tree, tvbuff_t *tvb, gint *pOffset)
|
2007-05-15 09:05:53 +00:00
|
|
|
{
|
2009-04-06 18:30:04 +00:00
|
|
|
proto_item *ti;
|
|
|
|
proto_tree *encobj_tree;
|
|
|
|
proto_tree *nodeid_tree;
|
|
|
|
int ServiceId = 0;
|
|
|
|
|
2011-10-18 00:17:48 +00:00
|
|
|
proto_tree_add_item(tree, hf_opcua_transport_type, tvb, *pOffset, 3, ENC_ASCII|ENC_NA); *pOffset+=3;
|
2011-10-15 19:58:31 +00:00
|
|
|
proto_tree_add_item(tree, hf_opcua_transport_chunk, tvb, *pOffset, 1, ENC_ASCII|ENC_NA); *pOffset+=1;
|
2011-10-06 14:46:34 +00:00
|
|
|
proto_tree_add_item(tree, hf_opcua_transport_size, tvb, *pOffset, 4, ENC_LITTLE_ENDIAN); *pOffset+=4;
|
|
|
|
proto_tree_add_item(tree, hf_opcua_transport_scid, tvb, *pOffset, 4, ENC_LITTLE_ENDIAN); *pOffset+=4;
|
2009-04-06 18:30:04 +00:00
|
|
|
parseString(tree, tvb, pOffset, hf_opcua_transport_spu);
|
|
|
|
parseByteString(tree, tvb, pOffset, hf_opcua_transport_scert);
|
|
|
|
parseByteString(tree, tvb, pOffset, hf_opcua_transport_rcthumb);
|
2011-10-06 14:46:34 +00:00
|
|
|
proto_tree_add_item(tree, hf_opcua_transport_seq, tvb, *pOffset, 4, ENC_LITTLE_ENDIAN); *pOffset+=4;
|
|
|
|
proto_tree_add_item(tree, hf_opcua_transport_rqid, tvb, *pOffset, 4, ENC_LITTLE_ENDIAN); *pOffset+=4;
|
2009-04-06 18:30:04 +00:00
|
|
|
|
|
|
|
/* add encodeable object subtree */
|
|
|
|
ti = proto_tree_add_text(tree, tvb, 0, -1, "Message : Encodeable Object");
|
|
|
|
encobj_tree = proto_item_add_subtree(ti, ett_opcua_extensionobject);
|
|
|
|
|
|
|
|
/* add nodeid subtree */
|
|
|
|
ti = proto_tree_add_text(encobj_tree, tvb, 0, -1, "TypeId : ExpandedNodeId");
|
|
|
|
nodeid_tree = proto_item_add_subtree(ti, ett_opcua_nodeid);
|
2011-03-23 08:03:02 +00:00
|
|
|
ServiceId = parseServiceNodeId(nodeid_tree, tvb, pOffset);
|
2009-04-06 18:30:04 +00:00
|
|
|
|
|
|
|
dispatchService(encobj_tree, tvb, pOffset, ServiceId);
|
2010-12-04 02:54:59 +00:00
|
|
|
return -1;
|
2007-05-15 09:05:53 +00:00
|
|
|
}
|
|
|
|
|
2010-12-04 02:54:59 +00:00
|
|
|
int parseCloseSecureChannel(proto_tree *tree, tvbuff_t *tvb, gint *pOffset)
|
2007-05-15 09:05:53 +00:00
|
|
|
{
|
2011-10-18 00:17:48 +00:00
|
|
|
proto_tree_add_item(tree, hf_opcua_transport_type, tvb, *pOffset, 3, ENC_ASCII|ENC_NA); *pOffset+=3;
|
2011-10-15 19:58:31 +00:00
|
|
|
proto_tree_add_item(tree, hf_opcua_transport_chunk, tvb, *pOffset, 1, ENC_ASCII|ENC_NA); *pOffset+=1;
|
2011-10-06 14:46:34 +00:00
|
|
|
proto_tree_add_item(tree, hf_opcua_transport_size, tvb, *pOffset, 4, ENC_LITTLE_ENDIAN); *pOffset+=4;
|
|
|
|
proto_tree_add_item(tree, hf_opcua_transport_scid, tvb, *pOffset, 4, ENC_LITTLE_ENDIAN); *pOffset+=4;
|
2010-12-04 02:54:59 +00:00
|
|
|
return -1;
|
2007-05-15 09:05:53 +00:00
|
|
|
}
|
2009-04-06 18:30:04 +00:00
|
|
|
|