R2B
diff --git a/TLS_CNL113806.tpd b/TLS_CNL113806.tpd
new file mode 100644
index 0000000..a15c3d1
--- /dev/null
+++ b/TLS_CNL113806.tpd
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<TITAN_Project_File_Information version="1.0">
+ <ProjectName>TLS_CNL113806</ProjectName>
+ <ReferencedProjects>
+ <ReferencedProject name="ProtocolModules_Common" projectLocationURI="../COMMON/ProtocolModules_Common.tpd"/>
+ </ReferencedProjects>
+ <Folders>
+ <FolderResource projectRelativePath="src" relativeURI="src"/>
+ </Folders>
+ <Files>
+ <FileResource projectRelativePath="src/TLS_CNL113806.grp" relativeURI="src/TLS_CNL113806.grp"/>
+ <FileResource projectRelativePath="src/TLS_Constants.ttcn" relativeURI="src/TLS_Constants.ttcn"/>
+ <FileResource projectRelativePath="src/TLS_EncDec.cc" relativeURI="src/TLS_EncDec.cc"/>
+ <FileResource projectRelativePath="src/TLS_Types.ttcn" relativeURI="src/TLS_Types.ttcn"/>
+ </Files>
+ <ActiveConfiguration>Default</ActiveConfiguration>
+ <Configurations>
+ <Configuration name="Default">
+ <ProjectProperties>
+ <MakefileSettings>
+ <generateInternalMakefile>true</generateInternalMakefile>
+ <GNUMake>true</GNUMake>
+ <incrementalDependencyRefresh>true</incrementalDependencyRefresh>
+ <targetExecutable>bin/TLS_CNL113806</targetExecutable>
+ <buildLevel>Level3-Creatingobjectfileswithdependencyupdate</buildLevel>
+ </MakefileSettings>
+ <LocalBuildSettings>
+ <workingDirectory>bin</workingDirectory>
+ </LocalBuildSettings>
+ </ProjectProperties>
+ </Configuration>
+ </Configurations>
+</TITAN_Project_File_Information>
\ No newline at end of file
diff --git a/src/TLS_CNL113806.grp b/src/TLS_CNL113806.grp
new file mode 100644
index 0000000..0f20762
--- /dev/null
+++ b/src/TLS_CNL113806.grp
@@ -0,0 +1,28 @@
+<!--
+///////////////////////////////////////////////////////////////////////////////
+//
+// Copyright (c) 2000-2016 Ericsson Telecom AB
+//
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// which accompanies this distribution, and is available at
+// http://www.eclipse.org/legal/epl-v10.html
+///////////////////////////////////////////////////////////////////////////////
+
+//
+// File: TLS_CNL113806.grp
+// Description: TLS Protocol Module group file
+// Rev: R2B
+// Prodnr: CNL 113 806
+// Updated: 2014-06-27
+// Contact: http://ttcn.ericsson.se
+//
+-->
+<!DOCTYPE TITAN_GUI_FileGroup_file>
+<FileGroup TITAN_version="4.2.pl0" >
+ <File_Group name="TLS_CNL113806.grp" >
+ <File path="TLS_Constants.ttcn" />
+ <File path="TLS_EncDec.cc" />
+ <File path="TLS_Types.ttcn" />
+ </File_Group>
+</FileGroup>
diff --git a/src/TLS_Constants.ttcn b/src/TLS_Constants.ttcn
new file mode 100644
index 0000000..7f62019
--- /dev/null
+++ b/src/TLS_Constants.ttcn
@@ -0,0 +1,89 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+// Copyright (c) 2000-2016 Ericsson Telecom AB
+//
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// which accompanies this distribution, and is available at
+// http://www.eclipse.org/legal/epl-v10.html
+///////////////////////////////////////////////////////////////////////////////
+//
+// File: TLS_Constants.ttcn
+// Description: TLS Constants
+// Rev: R2B
+// Prodnr: CNL 113 806
+// Updated: 2014-06-13
+// Contact: http://ttcn.ericsson.se
+// Reference: http://tools.ietf.org/html/rfc4346
+//
+//
+
+
+module TLS_Constants {
+ import from TLS_Types all;
+
+ const ProtocolVersion cg_TLSv1_1_PROTOCOL_VERSION := { 3, 2 };
+
+ const CipherSuite cg_TLS_NULL_WITH_NULL_NULL := { '00'O, '00'O };
+ const CipherSuite cg_TLS_RSA_WITH_NULL_MD5 := { '00'O, '01'O };
+ const CipherSuite cg_TLS_RSA_WITH_NULL_SHA := { '00'O, '02'O };
+ const CipherSuite cg_TLS_RSA_WITH_RC4_128_MD5 := { '00'O, '04'O };
+ const CipherSuite cg_TLS_RSA_WITH_RC4_128_SHA := { '00'O, '05'O };
+ const CipherSuite cg_TLS_RSA_WITH_IDEA_CBC_SHA := { '00'O, '07'O };
+ const CipherSuite cg_TLS_RSA_WITH_DES_CBC_SHA := { '00'O, '09'O };
+ const CipherSuite cg_TLS_RSA_WITH_3DES_EDE_CBC_SHA := { '00'O, '0A'O };
+
+ const CipherSuite cg_TLS_DH_DSS_WITH_DES_CBC_SHA := {'00'O, '0C'O };
+ const CipherSuite cg_TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA := {'00'O, '0D'O };
+ const CipherSuite cg_TLS_DH_RSA_WITH_DES_CBC_SHA := {'00'O, '0F'O };
+ const CipherSuite cg_TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA := {'00'O, '10'O };
+ const CipherSuite cg_TLS_DHE_DSS_WITH_DES_CBC_SHA := {'00'O, '12'O };
+ const CipherSuite cg_TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA := {'00'O, '13'O };
+ const CipherSuite cg_TLS_DHE_RSA_WITH_DES_CBC_SHA := {'00'O, '15'O };
+ const CipherSuite cg_TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA := {'00'O, '16'O };
+
+ const CipherSuite cg_TLS_DH_anon_WITH_RC4_128_MD5 := { '00'O, '18'O };
+ const CipherSuite cg_TLS_DH_anon_WITH_DES_CBC_SHA := { '00'O, '1A'O };
+ const CipherSuite cg_TLS_DH_anon_WITH_3DES_EDE_CBC_SHA := { '00'O, '1B'O };
+
+ const CipherSuite cg_TLS_RSA_EXPORT_WITH_RC4_40_MD5 := { '00'O, '03'O };
+ const CipherSuite cg_TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5 := { '00'O, '06'O };
+ const CipherSuite cg_TLS_RSA_EXPORT_WITH_DES40_CBC_SHA := { '00'O, '08'O };
+ const CipherSuite cg_TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA := { '00'O, '0B'O };
+ const CipherSuite cg_TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA := { '00'O, '0E'O };
+ const CipherSuite cg_TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA := { '00'O, '11'O };
+ const CipherSuite cg_TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA := { '00'O, '14'O };
+ const CipherSuite cg_TLS_DH_anon_EXPORT_WITH_RC4_40_MD5 := { '00'O, '17'O };
+ const CipherSuite cg_TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA := { '00'O, '19'O };
+
+ const CipherSuite cg_TLS_KRB5_WITH_DES_CBC_SHA := { '00'O, '1E'O };
+ const CipherSuite cg_TLS_KRB5_WITH_3DES_EDE_CBC_SHA := { '00'O, '1F'O };
+ const CipherSuite cg_TLS_KRB5_WITH_RC4_128_SHA := { '00'O, '20'O };
+ const CipherSuite cg_TLS_KRB5_WITH_IDEA_CBC_SHA := { '00'O, '21'O };
+ const CipherSuite cg_TLS_KRB5_WITH_DES_CBC_MD5 := { '00'O, '22'O };
+ const CipherSuite cg_TLS_KRB5_WITH_3DES_EDE_CBC_MD5 := { '00'O, '23'O };
+ const CipherSuite cg_TLS_KRB5_WITH_RC4_128_MD5 := { '00'O, '24'O };
+ const CipherSuite cg_TLS_KRB5_WITH_IDEA_CBC_MD5 := { '00'O, '25'O };
+
+ const CipherSuite cg_TLS_KRB5_EXPORT_WITH_DES_CBC_40_SHA := { '00'O, '26'O};
+ const CipherSuite cg_TLS_KRB5_EXPORT_WITH_RC2_CBC_40_SHA := { '00'O, '27'O};
+ const CipherSuite cg_TLS_KRB5_EXPORT_WITH_RC4_40_SHA := { '00'O, '28'O};
+ const CipherSuite cg_TLS_KRB5_EXPORT_WITH_DES_CBC_40_MD5 := { '00'O, '29'O};
+ const CipherSuite cg_TLS_KRB5_EXPORT_WITH_RC2_CBC_40_MD5 := { '00'O, '2A'O};
+ const CipherSuite cg_TLS_KRB5_EXPORT_WITH_RC4_40_MD5 := { '00'O, '2B'O};
+
+ const CipherSuite cg_TLS_RSA_WITH_AES_128_CBC_SHA := { '00'O, '2F'O };
+ const CipherSuite cg_TLS_DH_DSS_WITH_AES_128_CBC_SHA := { '00'O, '30'O };
+ const CipherSuite cg_TLS_DH_RSA_WITH_AES_128_CBC_SHA := { '00'O, '31'O };
+ const CipherSuite cg_TLS_DHE_DSS_WITH_AES_128_CBC_SHA := { '00'O, '32'O };
+ const CipherSuite cg_TLS_DHE_RSA_WITH_AES_128_CBC_SHA := { '00'O, '33'O };
+ const CipherSuite cg_TLS_DH_anon_WITH_AES_128_CBC_SHA := { '00'O, '34'O };
+
+ const CipherSuite cg_TLS_RSA_WITH_AES_256_CBC_SHA := { '00'O, '35'O };
+ const CipherSuite cg_TLS_DH_DSS_WITH_AES_256_CBC_SHA := { '00'O, '36'O };
+ const CipherSuite cg_TLS_DH_RSA_WITH_AES_256_CBC_SHA := { '00'O, '37'O };
+ const CipherSuite cg_TLS_DHE_DSS_WITH_AES_256_CBC_SHA := { '00'O, '38'O };
+ const CipherSuite cg_TLS_DHE_RSA_WITH_AES_256_CBC_SHA := { '00'O, '39'O };
+ const CipherSuite cg_TLS_DH_anon_WITH_AES_256_CBC_SHA := { '00'O, '3A'O };
+
+} with { encode "RAW" } //end of module
diff --git a/src/TLS_EncDec.cc b/src/TLS_EncDec.cc
new file mode 100644
index 0000000..309ea81
--- /dev/null
+++ b/src/TLS_EncDec.cc
@@ -0,0 +1,2213 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+// Copyright (c) 2000-2016 Ericsson Telecom AB
+//
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// which accompanies this distribution, and is available at
+// http://www.eclipse.org/legal/epl-v10.html
+///////////////////////////////////////////////////////////////////////////////
+//
+// File: TLS_EncDec.cc
+// Description: Encode/decode functions for TLS messages
+// Rev: R2B
+// Prodnr: CNL 113 806
+// Updated: 2014-06-20
+// Contact: http://ttcn.ericsson.se
+
+#include "TLS_Types.hh"
+#include "memory.h"
+#include <string.h>
+#include <stdio.h>
+#include <iostream>
+#include <exception>
+
+namespace TLS__Types{
+
+struct TLS_Exception {
+ const char* what;
+ const char* file;
+ int line;
+ const char* func;
+};
+
+OCTETSTRING padd_os_to_len(const OCTETSTRING& os, const INTEGER& len) throw(TLS_Exception){
+ if(len < os.lengthof()) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid CompressionMethod";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ return int2oct(0, len-os.lengthof()) + os ;
+}
+
+/////////////////////////////////////
+//// Protocol Version EncDec
+/////////////////////////////////////
+
+void enc__TLS__ProtocolVersion(const TLS__Types::ProtocolVersion& version, TTCN_Buffer& buf) {
+ buf.put_os(int2oct(version.major__(), 1));
+ buf.put_os(int2oct(version.minor__(), 1));
+}
+
+ProtocolVersion dec__TLS__ProtocolVersion(const OCTETSTRING& stream) throw(TLS_Exception) {
+ ProtocolVersion ret;
+
+ ret.major__() = oct2int(substr(stream, 0, 1));
+ ret.minor__() = oct2int(substr(stream, 1, 1));
+
+ return ret;
+}
+
+/////////////////////////////////////
+//// Content Type EncDec
+/////////////////////////////////////
+
+void enc__TLS__ContentType(const TLS__Types::ContentType& ctype, TTCN_Buffer& buf) {
+ buf.put_os(int2oct(ctype, 1));
+}
+
+ContentType dec__TLS__ContentType(const OCTETSTRING& stream) throw(TLS_Exception){
+ if(!ContentType::is_valid_enum(oct2int(stream))){
+ TLS_Exception e;
+ e.what = (const char*)"Invalid ComponentType";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+
+ return (ContentType) oct2int(stream);
+}
+
+/////////////////////////////////////
+//// Compression Method EncDec
+/////////////////////////////////////
+
+void enc__TLS__CompressionMethod(const TLS__Types::CompressionMethod& method, TTCN_Buffer& buf) {
+ buf.put_os(int2oct(method, 1));
+}
+
+CompressionMethod dec__TLS__CompressionMethod(const OCTETSTRING& stream) throw(TLS_Exception){
+ if(!CompressionMethod::is_valid_enum(oct2int(stream))){
+ TLS_Exception e;
+ e.what = (const char*)"Invalid CompressionMethod";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+
+ return (CompressionMethod) oct2int(stream);
+}
+
+/////////////////////////////////////
+//// Connection End EncDec
+/////////////////////////////////////
+
+void enc__TLS__ConnectionEnd(const TLS__Types::ConnectionEnd& ce, TTCN_Buffer& buf) {
+ buf.put_os(int2oct(ce, 1));
+}
+
+ConnectionEnd dec__TLS__ConnectionEnd(const OCTETSTRING& stream) throw(TLS_Exception){
+ if(!ConnectionEnd::is_valid_enum(oct2int(stream))){
+ TLS_Exception e;
+ e.what = (const char*)"Invalid ConnectionEnd";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+
+ return (ConnectionEnd) oct2int(stream);;
+}
+
+/////////////////////////////////////
+//// Bulk Cipher Algorithm EncDec
+/////////////////////////////////////
+
+void enc__TLS__BulkCipherAlgorithm(const TLS__Types::BulkCipherAlgorithm& bca, TTCN_Buffer& buf) throw(TLS_Exception){
+ buf.put_os(int2oct(bca, 1));
+}
+
+BulkCipherAlgorithm dec__TLS__BulkCipherAlgorithm(const OCTETSTRING& stream) throw(TLS_Exception){
+ if(!BulkCipherAlgorithm::is_valid_enum(oct2int(stream))){
+ TLS_Exception e;
+ e.what = (const char*)"Invalid BulkCipherAlgorithm";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ return (BulkCipherAlgorithm) oct2int(stream);
+}
+
+/////////////////////////////////////
+//// Cipher Type EncDec
+/////////////////////////////////////
+
+void enc__TLS__CipherType(const TLS__Types::CipherType& ct, TTCN_Buffer& buf) {
+ buf.put_os(int2oct(ct, 1));
+}
+
+CipherType dec__TLS__CipherType(const OCTETSTRING& stream) throw(TLS_Exception){
+ if(!CipherType::is_valid_enum(oct2int(stream))){
+ TLS_Exception e;
+ e.what = (const char*)"Invalid CipherType";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+
+ return (CipherType) oct2int(stream);
+}
+
+/////////////////////////////////////
+//// MAC Algorithm EncDec
+/////////////////////////////////////
+
+void enc__TLS__MACAlgorithm(const TLS__Types::MACAlgorithm& ct, TTCN_Buffer& buf) {
+ buf.put_os(int2oct(ct, 1));
+}
+
+MACAlgorithm dec__TLS__MACAlgorithm(const OCTETSTRING& stream) throw(TLS_Exception){
+ if(!MACAlgorithm::is_valid_enum(oct2int(stream))){
+ TLS_Exception e;
+ e.what = (const char*)"Invalid MACAlgorithm";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+
+ return (MACAlgorithm) oct2int(stream);
+}
+
+/////////////////////////////////////
+//// Security Parameters EncDec
+/////////////////////////////////////
+
+OCTETSTRING enc__TLS__SecurityParameters(const TLS__Types::SecurityParameters& sp) {
+ TTCN_Buffer buf;
+ OCTETSTRING ret;
+
+ enc__TLS__ConnectionEnd(sp.entity(), buf);
+ enc__TLS__BulkCipherAlgorithm(sp.bulk__cipher__algorithm(), buf);
+ enc__TLS__CipherType(sp.cipher__type(), buf);
+ buf.put_os(int2oct(sp.key__size(), 1));
+ buf.put_os(int2oct(sp.key__material__length(), 1));
+ enc__TLS__MACAlgorithm(sp.mac__algorithm(),buf);
+ buf.put_os(int2oct(sp.hash__size(), 1));
+ enc__TLS__CompressionMethod(sp.compression__algorithm(), buf);
+ buf.put_os(sp.master__secret());
+ buf.put_os(sp.client__random());
+ buf.put_os(sp.server__random());
+
+ buf.get_string(ret);
+
+ return ret;
+}
+
+INTEGER dec__TLS__SecurityParameters(const OCTETSTRING& stream, TLS__Types::SecurityParameters& ret) {
+ if(stream.lengthof() < 120) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ try {
+ ret.entity() = dec__TLS__ConnectionEnd(substr(stream, 0, 1));
+ ret.bulk__cipher__algorithm() = dec__TLS__BulkCipherAlgorithm(substr(stream, 1, 1));
+ ret.cipher__type() = dec__TLS__CipherType(substr(stream, 2 , 1));
+ ret.key__size() = oct2int(substr(stream, 3, 1));
+ ret.key__material__length() = oct2int(substr(stream, 4, 1));
+ ret.mac__algorithm() = dec__TLS__MACAlgorithm(substr(stream, 5, 1));
+ ret.hash__size() = oct2int(substr(stream, 6, 1));
+ ret.compression__algorithm() = dec__TLS__CompressionMethod(substr(stream, 7, 1));
+ ret.master__secret() = substr(stream, 8, 48);
+ ret.client__random() = substr(stream, 56, 32);
+ ret.server__random() = substr(stream, 88, 32);
+ } catch (TLS_Exception e) {
+ TTCN_Logger::begin_event(TTCN_WARNING);
+ TTCN_Logger::log_event("***Error has occured: %s. In file: %s in function: %s at line: %d", e.what, e.file, e.func, e.line);
+ TTCN_Logger::end_event();
+ return 0;
+ }
+
+ return 1;
+}
+
+/////////////////////////////////////
+//// Change Cipher Specs Enum EncDec
+/////////////////////////////////////
+
+void enc__TLS__ChangeCipherSpecEnum(const TLS__Types::ChangeCipherSpecEnum& ccse, TTCN_Buffer& buf) {
+ buf.put_os(int2oct(ccse, 1));
+}
+
+ChangeCipherSpecEnum dec__TLS__ChangeCipherSpecEnum(const OCTETSTRING& stream) throw(TLS_Exception){
+ if(!ChangeCipherSpecEnum::is_valid_enum(oct2int(stream))){
+ TLS_Exception e;
+ e.what = (const char*)"Invalid ChangeCipherSpecEnum";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ return (ChangeCipherSpecEnum) oct2int(stream);;
+}
+
+/////////////////////////////////////
+//// Change Cipher Specs EncDec
+/////////////////////////////////////
+
+void enc__TLS__ChangeCipherSpec(const TLS__Types::ChangeCipherSpec& ccs, TTCN_Buffer& buf) {
+ enc__TLS__ChangeCipherSpecEnum(ccs.type__(), buf);
+}
+
+ChangeCipherSpec dec__TLS__ChangeCipherSpec(const OCTETSTRING& stream){
+ ChangeCipherSpec ret;
+ ret.type__() = dec__TLS__ChangeCipherSpecEnum(stream);
+
+ return ret;
+}
+
+/////////////////////////////////////
+//// Alert Level EncDec
+/////////////////////////////////////
+
+void enc__TLS__AlertLevel(const TLS__Types::AlertLevel& al, TTCN_Buffer& buf) {
+ buf.put_os(int2oct(al, 1));
+}
+
+AlertLevel dec__TLS__AlertLevel(const OCTETSTRING& stream) throw(TLS_Exception){
+ if(!AlertLevel::is_valid_enum(oct2int(stream))){
+ TLS_Exception e;
+ e.what = (const char*)"Invalid AlertLevel";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ return (AlertLevel) oct2int(stream);
+}
+
+/////////////////////////////////////
+//// Alert Description EncDec
+/////////////////////////////////////
+
+void enc__TLS__AlertDescription(const TLS__Types::AlertDescription& ald, TTCN_Buffer& buf) {
+ buf.put_os(int2oct(ald, 1));
+}
+
+AlertDescription dec__TLS__AlertDescription(const OCTETSTRING& stream) throw(TLS_Exception){
+ if(!AlertDescription::is_valid_enum(oct2int(stream))){
+ TLS_Exception e;
+ e.what = (const char*)"Invalid AlertDescription";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+
+ return (AlertDescription) oct2int(stream);
+}
+
+/////////////////////////////////////
+//// Alert EncDec
+/////////////////////////////////////
+
+void enc__TLS__Alert(const TLS__Types::Alert& alert, TTCN_Buffer& buf) {
+ enc__TLS__AlertLevel(alert.level(), buf);
+ enc__TLS__AlertDescription(alert.description(),buf);
+}
+
+Alert dec__TLS__Alert(const OCTETSTRING& stream) {
+ Alert ret;
+
+ ret.level() = dec__TLS__AlertLevel(substr(stream, 0, 1));
+ ret.description() = dec__TLS__AlertDescription(substr(stream, 1, 1));
+
+ return ret;
+}
+
+/////////////////////////////////////
+//// Handshake Type EncDec
+/////////////////////////////////////
+
+void enc__TLS__HandshakeType(const TLS__Types::HandshakeType& ht, TTCN_Buffer& buf) {
+ buf.put_os(int2oct(ht, 1));
+}
+
+INTEGER dec__TLS__HandshakeType(const OCTETSTRING& stream, TLS__Types::HandshakeType& ret) {
+ if(!HandshakeType::is_valid_enum(oct2int(stream))){
+ return 0;
+ }
+ ret = (HandshakeType) oct2int(stream);
+ return 1;
+}
+
+/////////////////////////////////////
+//// Hello Request EncDec
+/////////////////////////////////////
+
+void enc__TLS__HelloRequest(const HelloRequest& hr, TTCN_Buffer& buf) {
+ buf.put_os(OCTETSTRING(0, (const unsigned char*)""));
+}
+
+HelloRequest dec__TLS__HelloRequest(const OCTETSTRING& stream) {
+ HelloRequest ret = HelloRequest(NULL_VALUE);
+
+ return ret;
+}
+
+/////////////////////////////////////
+//// Random EncDec
+/////////////////////////////////////
+
+void enc__TLS__Random(const TLS__Types::Random& rnd, TTCN_Buffer& buf) {
+ buf.put_os(int2oct(rnd.gmt__unix__time(), 4));
+ buf.put_os(rnd.random__bytes());
+
+}
+
+Random dec__TLS__Random(const OCTETSTRING& stream) throw(TLS_Exception){
+ Random ret;
+
+ ret.gmt__unix__time() = oct2int(substr(stream, 0, 4));
+ ret.random__bytes() = substr(stream, 4, 28);
+
+ return ret;
+}
+
+/////////////////////////////////////
+//// SessionID EncDec
+/////////////////////////////////////
+
+void enc__TLS__SessionID(const TLS__Types::SessionID& sid, TTCN_Buffer& buf) {
+ buf.put_os(int2oct(sid.lengthof(), 1));
+ buf.put_os((OCTETSTRING) sid);
+}
+
+SessionID dec__TLS__SessionID(const OCTETSTRING& stream) {
+ SessionID ret = (SessionID) stream;
+
+ return ret;
+}
+
+/////////////////////////////////////
+//// Cipher Suite EncDec
+/////////////////////////////////////
+
+void enc__TLS__CipherSuite(const TLS__Types::CipherSuite& cs, TTCN_Buffer& buf) {
+ buf.put_os(cs.field1());
+ buf.put_os(cs.field2());
+}
+
+CipherSuite dec__TLS__CipherSuite(const OCTETSTRING& stream) throw(TLS_Exception){
+ CipherSuite ret;
+
+ if(stream.lengthof() < 2) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+
+ ret.field1() = substr(stream, 0, 1);
+ ret.field2() = substr(stream, 1, 1);
+
+ return ret;
+}
+
+/////////////////////////////////////
+//// Cipher Suite List EncDec
+/////////////////////////////////////
+
+void enc__TLS__CipherSuiteList(const TLS__Types::CipherSuiteList& csl, TTCN_Buffer& buf) {
+ int size = csl.size_of();
+
+ buf.put_os(int2oct(size*2, 2));
+ for(int i = 0; i < size; i++){
+ enc__TLS__CipherSuite(csl[i], buf);
+ }
+}
+
+CipherSuiteList dec__TLS__CipherSuiteList(const OCTETSTRING& stream, const INTEGER& len) throw(TLS_Exception){
+ CipherSuiteList ret;
+ int size = len/2;
+ if(stream.lengthof() != len) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ for(int i = 0; i < size; i++){
+ ret[i] = dec__TLS__CipherSuite(substr(stream, (i*2), 2));
+ }
+
+ return ret;
+}
+
+/////////////////////////////////////
+//// Compression Method List EncDec
+/////////////////////////////////////
+
+void enc__TLS__CompressionMethodList(const TLS__Types::CompressionMethodList& cml, TTCN_Buffer& buf) {
+ int size = (cml.size_of());
+
+ buf.put_os(int2oct(size, 1));
+ for(int i = 0; i < size; i++){
+ enc__TLS__CompressionMethod(cml[i], buf);
+ }
+}
+
+CompressionMethodList dec__TLS__CompressionMethodList(const OCTETSTRING& stream, const INTEGER& len) throw(TLS_Exception){
+ CompressionMethodList ret;
+
+ if(stream.lengthof() != len) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+
+ for(int i = 0; i < len; i++){
+ ret[i] = dec__TLS__CompressionMethod(substr(stream, i, 1));
+ }
+
+ return ret;
+}
+
+/////////////////////////////////////
+//// Client Hello EncDec
+/////////////////////////////////////
+
+void enc__TLS__ClientHello(const TLS__Types::ClientHello& hello, TTCN_Buffer& buf) {
+ enc__TLS__ProtocolVersion(hello.client__version(), buf);
+ enc__TLS__Random(hello.random(), buf);
+ if(hello.session__id().ispresent()){
+ enc__TLS__SessionID(hello.session__id(), buf);
+ } else {
+ buf.put_c(0);
+ }
+ enc__TLS__CipherSuiteList(hello.cipher__suites(), buf);
+ enc__TLS__CompressionMethodList(hello.compression__methods(), buf);
+
+ if(hello.extension__().ispresent()) {
+ buf.put_os(hello.extension__()());
+ }
+}
+
+ClientHello dec__TLS__ClientHello(const OCTETSTRING& stream) throw(TLS_Exception){
+ ClientHello ret;
+ int offset = 0;
+ int len = 0;
+ int str_len = stream.lengthof();
+
+ if(str_len < offset + 2) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ ret.client__version() = dec__TLS__ProtocolVersion(substr(stream, offset, 2));
+ offset += 2;
+
+ if(str_len < offset + 32) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ ret.random() = dec__TLS__Random(substr(stream, offset, 32));
+ offset += 32;
+
+ if(str_len < offset + 1) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ len = oct2int(substr(stream, offset, 1));
+ offset += 1;
+
+ if(len != 0) {
+ if(str_len < offset + len) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ ret.session__id() = dec__TLS__SessionID(substr(stream, offset, len));
+ offset += len;
+ } else {
+ ret.session__id() = OMIT_VALUE;
+ }
+
+ if(str_len < offset + 2) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ len = oct2int(substr(stream, offset, 2));
+ offset += 2;
+
+ if(str_len < offset + len) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ ret.cipher__suites() = dec__TLS__CipherSuiteList(substr(stream, offset, len), len);
+ offset += len;
+
+ if(str_len < offset + 1) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ len = oct2int(substr(stream,offset, 1));
+ offset += 1;
+
+ if(str_len < offset + len) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ ret.compression__methods() = dec__TLS__CompressionMethodList(substr(stream, offset, len), len);
+ offset += len;
+
+ if(str_len == offset){
+ ret.extension__() = OMIT_VALUE;
+ } else {
+ ret.extension__()() = substr(stream, offset, str_len-offset);
+ }
+
+
+ return ret;
+}
+
+/////////////////////////////////////
+//// Server Hello EncDec
+/////////////////////////////////////
+
+void enc__TLS__ServerHello(const TLS__Types::ServerHello& hello, TTCN_Buffer& buf) {
+ enc__TLS__ProtocolVersion(hello.server__version(), buf);
+ enc__TLS__Random(hello.random(), buf);
+ if(hello.session__id().ispresent()){
+ enc__TLS__SessionID(hello.session__id(), buf);
+ } else {
+ buf.put_c(0);
+ }
+ enc__TLS__CipherSuite(hello.cipher__suite(), buf);
+ enc__TLS__CompressionMethod(hello.compression__method(), buf);
+}
+
+ServerHello dec__TLS__ServerHello(const OCTETSTRING& stream) throw(TLS_Exception){
+ ServerHello ret;
+ int offset = 0;
+ int len;
+ int str_len = stream.lengthof();
+
+ if(str_len < offset + 2) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ ret.server__version() = dec__TLS__ProtocolVersion(substr(stream, offset, 2));
+ offset += 2;
+
+ if(str_len < offset + 32) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ ret.random() = dec__TLS__Random(substr(stream, offset, 32));
+ offset += 32;
+
+ if(str_len < offset + 1) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ len = oct2int(substr(stream, offset, 1));
+ offset += 1;
+
+ if(len != 0) {
+ if(str_len < offset + len) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ ret.session__id() = dec__TLS__SessionID(substr(stream, offset, len));
+ offset += len;
+ } else {
+ ret.session__id() = OMIT_VALUE;
+ }
+
+ if(str_len < offset + 2) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ ret.cipher__suite() = dec__TLS__CipherSuite(substr(stream, offset, 2));
+ offset += 2;
+
+ if(str_len < offset + 1) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ ret.compression__method() = dec__TLS__CompressionMethod(substr(stream, offset, 1));
+
+ return ret;
+}
+
+/////////////////////////////////////
+//// Certificate List EncDec
+/////////////////////////////////////
+
+void enc__TLS__CertificateList(const TLS__Types::CertificateList& certl, TTCN_Buffer& buf) {
+ int size = certl.size_of();
+
+ for(int i = 0; i < size; i++){
+ buf.put_os(int2oct(certl[i].lengthof(), 3));
+ buf.put_os(certl[i]);
+ }
+}
+
+CertificateList dec__TLS__CertificateList(const OCTETSTRING& stream, const INTEGER& stream_len) throw(TLS_Exception){
+ CertificateList ret;
+ int len;
+ int i = 0;
+ int offset = 0;
+ if(stream_len != stream.lengthof()) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ do {
+ len = oct2int(substr(stream, offset, 3));
+ offset += 3;
+ if(stream_len < offset + len) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ ret[i] = substr(stream, offset, len);
+ offset += len;
+ i++;
+ } while(offset + 3 <= stream_len);
+
+ return ret;
+}
+
+/////////////////////////////////////
+//// Certificate EncDec
+/////////////////////////////////////
+
+void enc__TLS__Certificate(const TLS__Types::Certificate& cert, TTCN_Buffer& buf) {
+ int len=0;
+ int size = cert.certificate__list()().size_of();
+
+ for(int i = 0; i < size; i++){
+ len += cert.certificate__list()()[i].lengthof();
+ }
+
+ buf.put_os(int2oct(len+3*size, 3));
+ enc__TLS__CertificateList(cert.certificate__list(), buf);
+}
+
+Certificate dec__TLS__Certificate(const OCTETSTRING& stream) throw(TLS_Exception){
+ Certificate ret;
+ int len;
+ int str_len = stream.lengthof();
+
+ if(str_len < 3) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ len = oct2int(substr(stream, 0, 3));
+
+ if(str_len < len + 3) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ ret.certificate__list() = dec__TLS__CertificateList(substr(stream, 3, len), len);
+
+ return ret;
+}
+
+/////////////////////////////////////
+//// Key Exchange Algorithm EncDec
+/////////////////////////////////////
+
+void enc__TLS__KeyExchangeAlgorithm(const TLS__Types::KeyExchangeAlgorithm& kea, TTCN_Buffer& buf) {
+ buf.put_os(int2oct(kea, 1));
+}
+
+KeyExchangeAlgorithm dec__TLS__KeyExchangeAlgorithm(const OCTETSTRING& stream) throw(TLS_Exception){
+ if(!KeyExchangeAlgorithm::is_valid_enum(oct2int(stream))){
+ TLS_Exception e;
+ e.what = (const char*)"Invalid KeyExchangeAlgorithm";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ KeyExchangeAlgorithm ret = (KeyExchangeAlgorithm) oct2int(stream);
+
+ return ret;
+}
+
+/////////////////////////////////////
+//// Server RSA Params EncDec
+/////////////////////////////////////
+
+void enc__TLS__ServerRSAParams(const TLS__Types::ServerRSAParams& srsap, TTCN_Buffer& buf) {
+ buf.put_os(int2oct(srsap.rsa__modulus().lengthof(), 2));
+ buf.put_os(srsap.rsa__modulus());
+ buf.put_os(int2oct(srsap.rsa__exponent().lengthof(), 2));
+ buf.put_os(srsap.rsa__exponent());
+}
+
+ServerRSAParams dec__TLS__ServerRSAParams(const OCTETSTRING& stream) throw(TLS_Exception){
+ ServerRSAParams ret;
+ int offset = 0;
+ int len = 0;
+ int str_len = stream.lengthof();
+
+ if(str_len < offset + 2) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ len = oct2int(substr(stream, offset, 2));
+ offset += 2;
+
+ if(str_len < offset + len) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ ret.rsa__modulus() = substr(stream, offset, len);
+ offset += len;
+
+ if(str_len < offset + 2) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ len = oct2int(substr(stream, offset, 2));
+ offset += 2;
+
+ if(str_len < offset + len) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ ret.rsa__exponent() = substr(stream, offset, len);
+
+ return ret;
+}
+
+/////////////////////////////////////
+//// Server DH Params EncDec
+/////////////////////////////////////
+
+void enc__TLS__ServerDHParams(const TLS__Types::ServerDHParams& sdhp, TTCN_Buffer& buf) {
+ buf.put_os(int2oct(sdhp.dh__p().lengthof(), 2));
+ buf.put_os(sdhp.dh__p());
+ buf.put_os(int2oct(sdhp.dh__g().lengthof(), 2));
+ buf.put_os(sdhp.dh__g());
+ buf.put_os(int2oct(sdhp.dh__Ys().lengthof(), 2));
+ buf.put_os(sdhp.dh__Ys());
+}
+
+ServerDHParams dec__TLS__ServerDHParams(const OCTETSTRING& stream) throw(TLS_Exception){
+ ServerDHParams ret;
+ int offset = 0;
+ int len;
+ int str_len = stream.lengthof();
+
+ if(str_len < offset + 2) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ len = oct2int(substr(stream, offset, 2));
+ offset += 2;
+
+ if(str_len < offset + len) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ ret.dh__p() = substr(stream, offset, len);
+ offset += len;
+
+ if(str_len < offset + 2) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ len = oct2int(substr(stream, offset, 2));
+ offset += 2;
+
+ if(str_len < offset + len) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ ret.dh__g() = substr(stream, offset, len);
+ offset += len;
+
+ if(str_len < offset + 2) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ len = oct2int(substr(stream, offset, 2));
+ offset += 2;
+
+ if(str_len < offset + len) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ ret.dh__Ys() = substr(stream, offset, len);
+
+ return ret;
+}
+
+/////////////////////////////////////
+//// RSA Signature EncDec
+/////////////////////////////////////
+
+void enc__TLS__RSASignature(const TLS__Types::RSASignature& rsasign, TTCN_Buffer& buf) {
+ buf.put_os(rsasign.md5__hash());
+ buf.put_os(rsasign.sha__hash());
+}
+
+RSASignature dec__TLS__RSASignature(const OCTETSTRING& stream) throw(TLS_Exception){
+ RSASignature ret;
+ int str_len = stream.lengthof();
+
+ if(str_len < 36) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+
+ ret.md5__hash() = substr(stream, 0, 16);
+ ret.sha__hash() = substr(stream, 16, 20);
+
+ return ret;
+}
+
+/////////////////////////////////////
+//// DSA Signature EncDec
+/////////////////////////////////////
+
+void enc__TLS__DSASignature(const TLS__Types::DSASignature& dsasign, TTCN_Buffer& buf) {
+ buf.put_os(dsasign.sha__hash());
+}
+
+DSASignature dec__TLS__DSASignature(const OCTETSTRING& stream) throw(TLS_Exception){
+ DSASignature ret;
+ int str_len = stream.lengthof();
+
+ if(str_len < 20) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ ret.sha__hash() = substr(stream, 0, 20);
+
+ return ret;
+}
+
+/////////////////////////////////////
+//// Anonym Signature EncDec
+/////////////////////////////////////
+
+void enc__TLS__AnonymSignature(const TLS__Types::AnonymSignature& anonsign, TTCN_Buffer& buf) {
+ buf.put_os(OCTETSTRING(0, (const unsigned char*)""));
+}
+
+AnonymSignature dec__TLS__AnonymSignature(const OCTETSTRING& stream) {
+ AnonymSignature ret = AnonymSignature(NULL_VALUE);
+
+ return ret;
+}
+
+/////////////////////////////////////
+//// Signature EncDec
+/////////////////////////////////////
+
+void enc__TLS__Signature(const TLS__Types::Signature& sign, TTCN_Buffer& buf) {
+ switch(sign.get_selection()){
+ case Signature::ALT_anonym : enc__TLS__AnonymSignature(sign.anonym(), buf); break;
+ case Signature::ALT_rsa : enc__TLS__RSASignature(sign.rsa(), buf); break;
+ case Signature::ALT_dsa : enc__TLS__DSASignature(sign.dsa(), buf); break;
+ default : ;
+ }
+}
+
+Signature dec__TLS__Signature(const OCTETSTRING& stream) throw(TLS_Exception){
+ Signature ret;
+ switch(stream.lengthof()){
+ case 0 : ret.anonym() = dec__TLS__AnonymSignature(stream); break;
+ case 36 : ret.rsa() = dec__TLS__RSASignature(stream); break;
+ case 20 : ret.dsa() = dec__TLS__DSASignature(stream); break;
+ default : ;
+ }
+
+ return ret;
+}
+
+/////////////////////////////////////
+//// Server Params EncDec
+/////////////////////////////////////
+
+void enc__TLS__ServerParams(const TLS__Types::ServerParams& sp, TTCN_Buffer& buf) {
+ switch(sp.get_selection()){
+ case ServerParams::ALT_dh__params : enc__TLS__ServerDHParams(sp.dh__params(), buf); break;
+ case ServerParams::ALT_rsa__params : enc__TLS__ServerRSAParams(sp.rsa__params(), buf); break;
+ default :
+ TTCN_Logger::begin_event(TTCN_WARNING);
+ TTCN_Logger::log_event("Wrong field was selected from ServerParams");
+ TTCN_Logger::end_event();
+
+ }
+}
+
+ServerParams dec__TLS__ServerParams(const OCTETSTRING& stream) throw(TLS_Exception){
+ ServerParams ret;
+ int len;
+ int str_len = stream.lengthof();
+
+ if(str_len < 2) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ len = oct2int(substr(stream, 0, 2));
+ len += oct2int(substr(stream, len + 2, len + 4));
+
+ ret.dh__params() = dec__TLS__ServerDHParams(stream);
+ if((len + 4) == str_len){
+ ret.rsa__params() = dec__TLS__ServerRSAParams(stream);
+ } else {
+ ret.dh__params() = dec__TLS__ServerDHParams(stream);
+ }
+ return ret;
+}
+
+/////////////////////////////////////
+//// Server Key Exchange EncDec
+/////////////////////////////////////
+
+void enc__TLS__ServerKeyExchange(const TLS__Types::ServerKeyExchange& ske, TTCN_Buffer& buf) {
+ enc__TLS__ServerParams(ske.params(), buf);
+ enc__TLS__Signature(ske.signed__params(), buf);
+}
+
+ServerKeyExchange dec__TLS__ServerKeyExchange(const OCTETSTRING& stream, const TLS__Types::KeyExchangeAlgorithm& kea) throw(TLS_Exception){
+ ServerKeyExchange ret;
+ int len = 0;
+ int offset = 0;
+ int str_len = stream.lengthof();
+ OCTETSTRING p1;
+ OCTETSTRING p2;
+ OCTETSTRING p3;
+
+ switch(kea){
+ case KeyExchangeAlgorithm::diffie__hellman :
+ if(str_len < offset + 2) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ len = oct2int(substr(stream, offset, 2));
+ offset += 2;
+
+ if(str_len < offset + len) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ p1 = substr(stream, offset, len);
+ offset += len;
+
+ if(str_len < offset + 2) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ len = oct2int(substr(stream, offset, 2));
+ offset += 2;
+
+ if(str_len < offset + len) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ p2 = substr(stream, offset, len);
+ offset += len;
+
+ if(str_len < offset + 2) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ len = oct2int(substr(stream, offset, 2));
+ offset += 2;
+
+ if(str_len < offset + len) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ p3 = substr(stream, offset, len);
+ offset += len;
+
+ ret.params().dh__params().dh__p() = p1;
+ ret.params().dh__params().dh__g() = p2;
+ ret.params().dh__params().dh__Ys() = p3;
+
+ break;
+
+ case KeyExchangeAlgorithm::rsa :
+ if(str_len < offset + 2) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ len = oct2int(substr(stream, offset, 2));
+ offset += 2;
+
+ if(str_len < offset + len) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ p1 = substr(stream, offset, len);
+ offset += len;
+
+ if(str_len < offset + 2) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ len = oct2int(substr(stream, offset, 2));
+ offset += 2;
+
+ if(str_len < offset + len) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ p2 = substr(stream, offset, len);
+ offset += len;
+
+ ret.params().rsa__params().rsa__modulus() = p1;
+ ret.params().rsa__params().rsa__exponent() = p2;
+
+ break;
+
+ default : break;
+ }
+
+ ret.signed__params() = dec__TLS__Signature(substr(stream, offset, str_len - offset));
+ return ret;
+}
+
+/////////////////////////////////////
+//// Signature Algorithm EncDec
+/////////////////////////////////////
+
+void enc__TLS__SignatureAlgorithm(const TLS__Types::SignatureAlgorithm& sa, TTCN_Buffer& buf) {
+ buf.put_os(int2oct(sa, 1));
+}
+
+SignatureAlgorithm dec__TLS__SignatureAlgorithm(const OCTETSTRING& stream) throw(TLS_Exception){
+ if(!SignatureAlgorithm::is_valid_enum(oct2int(stream))) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid SignatureAlgorithm";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ SignatureAlgorithm ret = (SignatureAlgorithm) oct2int(stream);
+
+ return ret;
+}
+
+/////////////////////////////////////
+//// Client Certificate Type EncDec
+/////////////////////////////////////
+
+void enc__TLS__ClientCertificateType(const TLS__Types::ClientCertificateType& cct, TTCN_Buffer& buf) {
+ buf.put_os(int2oct(cct, 1));
+}
+
+ClientCertificateType dec__TLS__ClientCertificateType(const OCTETSTRING& stream) throw(TLS_Exception){
+ if(!ClientCertificateType::is_valid_enum(oct2int(stream))) {
+ return ClientCertificateType::UNKNOWN_VALUE;
+// TLS_Exception e;
+// e.what = (const char*)"Invalid ClientCertificateType";
+// e.file = (const char*)__FILE__;
+// e.line = __LINE__-4;
+// e.func = __func__;
+// throw e;
+ }
+ ClientCertificateType ret = (ClientCertificateType) oct2int(stream);
+
+ return ret;
+}
+
+/////////////////////////////////////
+//// Client Certificate Type List EncDec
+/////////////////////////////////////
+
+void enc__TLS__ClientCertificateTypeList(const TLS__Types::ClientCertificateTypeList& cctl, TTCN_Buffer& buf) {
+ int size = cctl.size_of();
+
+ buf.put_os(int2oct(size, 1));
+ for(int i = 0; i < size; i++){
+ enc__TLS__ClientCertificateType(cctl[i], buf);
+ }
+}
+
+ClientCertificateTypeList dec__TLS__ClientCertificateTypeList(const OCTETSTRING& stream, const INTEGER& size) throw(TLS_Exception){
+ ClientCertificateTypeList ret;
+ if(stream.lengthof() < size) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid ClientCertificateTypeList";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ for(int i = 0; i < size; i++){
+ ret[i] = dec__TLS__ClientCertificateType(substr(stream, i, 1));
+ }
+
+ return ret;
+}
+
+/////////////////////////////////////
+//// Distinguished Name EncDec
+/////////////////////////////////////
+
+void enc__TLS__DistinguishedName(const TLS__Types::DistinguishedName& dn, TTCN_Buffer& buf) {
+ buf.put_os(int2oct(dn.lengthof(), 2));
+ buf.put_os(dn);
+}
+
+DistinguishedName dec__TLS__DistinguishedName(const OCTETSTRING& stream) throw(TLS_Exception){
+ DistinguishedName ret;
+ int str_len = stream.lengthof();
+
+ if(str_len < 2) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ int len = oct2int(substr(stream, 0, 2));
+ if(len != 0) {
+ if(str_len < len + 2) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ ret = substr(stream, 2, len);
+ } else {
+ ret = OCTETSTRING(0,NULL);
+ }
+
+ return ret;
+}
+
+/////////////////////////////////////
+//// Certificate Request EncDec
+/////////////////////////////////////
+
+void enc__TLS__CertificateRequest(const TLS__Types::CertificateRequest& cr, TTCN_Buffer& buf) {
+ enc__TLS__ClientCertificateTypeList(cr.certificate__types(), buf);
+ buf.put_os(int2oct(cr.certificate__authorities()().lengthof()+2, 2));
+ if(cr.certificate__authorities().ispresent()){
+ enc__TLS__DistinguishedName(cr.certificate__authorities(), buf);
+ } else {
+ buf.put_os(OCTETSTRING(2, (const unsigned char*)"0000"));
+ }
+}
+
+CertificateRequest dec__TLS__CertificateRequest(const OCTETSTRING& stream) throw(TLS_Exception){
+ CertificateRequest ret;
+ int offset = 0;
+ int str_len = stream.lengthof();
+
+ if(str_len < offset + 1) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ int len = oct2int(substr(stream, 0, 1));
+ offset += 1;
+
+ if(str_len < offset + len) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ ret.certificate__types() = dec__TLS__ClientCertificateTypeList(substr(stream, offset, len), len);
+ offset += len;
+
+ if(str_len < offset + 2) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ len = oct2int(substr(stream, offset, 2));
+ offset += 2;
+
+ if(str_len < offset + len) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ if (len == 0) {
+ ret.certificate__authorities() = OMIT_VALUE;
+ } else {
+ ret.certificate__authorities() = dec__TLS__DistinguishedName(substr(stream, offset, len));
+ }
+
+ if(!ret.certificate__authorities().is_bound()){
+ ret.certificate__authorities() = OMIT_VALUE;
+ }
+
+ return ret;
+}
+
+/////////////////////////////////////
+//// Server Hello Done EncDec
+/////////////////////////////////////
+
+void enc__TLS__ServerHelloDone(const ServerHelloDone& shd, TTCN_Buffer& buf) {
+ buf.put_os(OCTETSTRING(0, (const unsigned char*)""));
+}
+
+ServerHelloDone dec__TLS__ServerHelloDone(const OCTETSTRING& stream) {
+ return ServerHelloDone(NULL_VALUE);
+}
+
+/////////////////////////////////////
+//// Certificate Verify EncDec
+/////////////////////////////////////
+
+void enc__TLS__CertificateVerify(const TLS__Types::CertificateVerify& cv, TTCN_Buffer& buf) {
+ /*enc__TLS__Signature(cv.signature__(), buf);*/
+ buf.put_os(cv.signature__());
+}
+
+CertificateVerify dec__TLS__CertificateVerify(const OCTETSTRING& stream) {
+ CertificateVerify ret;
+
+ //ret.signature__() = dec__TLS__Signature(stream);
+ ret.signature__() = stream;
+
+ return ret;
+}
+
+/////////////////////////////////////
+//// Public Value Encoding EncDec
+/////////////////////////////////////
+
+void enc__TLS__PublicValueEncoding(const TLS__Types::PublicValueEncoding& pve, TTCN_Buffer& buf) {
+ buf.put_os(int2oct(pve, 1));
+}
+
+PublicValueEncoding dec__TLS__PublicValueEncoding(const OCTETSTRING& stream) throw(TLS_Exception){
+ if(!PublicValueEncoding::is_valid_enum(oct2int(stream))) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid PublicValueEncoding";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ PublicValueEncoding ret = (PublicValueEncoding) oct2int(stream);
+
+ return ret;
+}
+
+/////////////////////////////////////
+//// Premaster Secret EncDec
+/////////////////////////////////////
+
+void enc__TLS__PreMasterSecret(const TLS__Types::PreMasterSecret& ps, TTCN_Buffer& buf) {
+ enc__TLS__ProtocolVersion(ps.client__version(), buf);
+ buf.put_os(ps.random());
+}
+
+PreMasterSecret dec__TLS__PreMasterSecret(const OCTETSTRING& stream) throw(TLS_Exception){
+ PreMasterSecret ret;
+ int str_len = stream.lengthof();
+
+ if(str_len < 2) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ ret.client__version() = dec__TLS__ProtocolVersion(substr(stream, 0, 2));
+
+ if(str_len < 48) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ ret.random() = substr(stream, 2, 46);
+
+ return ret;
+}
+
+/////////////////////////////////////
+//// Encrypted PreMaster Secret EncDec
+/////////////////////////////////////
+
+void enc__TLS__EncryptedPreMasterSecret(const TLS__Types::EncryptedPreMasterSecret epms, TTCN_Buffer& buf) {
+ enc__TLS__PreMasterSecret(epms.pre__master__secret(), buf);
+}
+
+EncryptedPreMasterSecret dec__TLS__EncryptedPreMasterSecret(const OCTETSTRING& stream) {
+ EncryptedPreMasterSecret ret;
+
+ ret.pre__master__secret() = dec__TLS__PreMasterSecret(stream);
+
+ return ret;
+}
+
+/////////////////////////////////////
+//// Client Diffie Hellman Public Implicit EncDec
+/////////////////////////////////////
+
+void enc__TLS__ClientDiffieHellmanPublicImplicit(const TLS__Types::ClientDiffieHellmanPublicImplicit cdhpi, TTCN_Buffer& buf) {
+ buf.put_os(OCTETSTRING(0, (const unsigned char*)""));
+}
+
+ClientDiffieHellmanPublicImplicit dec__TLS__ClientDiffieHellmanPublicImplicit(const OCTETSTRING& stream) {
+ return ClientDiffieHellmanPublicImplicit(NULL_VALUE);
+}
+
+/////////////////////////////////////
+//// Client Diffie Hellman Public Explicit EncDec
+/////////////////////////////////////
+
+void enc__TLS__ClientDiffieHellmanPublicExplicit(const TLS__Types::ClientDiffieHellmanPublicExplicit cdhpe, TTCN_Buffer& buf) {
+ buf.put_os(int2oct(cdhpe.DH__Yc().lengthof(), 2));
+ buf.put_os(cdhpe.DH__Yc());
+}
+
+ClientDiffieHellmanPublicExplicit dec__TLS__ClientDiffieHellmanPublicExplicit(const OCTETSTRING& stream) throw(TLS_Exception){
+ ClientDiffieHellmanPublicExplicit ret;
+ int len;
+ int str_len = stream.lengthof();
+
+ if(str_len < 2) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ len = oct2int(substr(stream, 0, 2));
+
+ if(str_len < len + 2) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ ret.DH__Yc() = substr(stream, 2, len);
+
+ return ret;
+}
+
+/////////////////////////////////////
+//// Client Diffie Hellman Public Values EncDec
+/////////////////////////////////////
+
+void enc__TLS__ClientDiffieHellmanPublicValues(const TLS__Types::ClientDiffieHellmanPublicValues cdhpv, const TLS__Types::PublicValueEncoding pve, TTCN_Buffer& buf) {
+ switch(pve) {
+ case PublicValueEncoding::implicit : enc__TLS__ClientDiffieHellmanPublicImplicit(cdhpv.implicit(), buf); break;
+ case PublicValueEncoding::explicit__ : enc__TLS__ClientDiffieHellmanPublicExplicit(cdhpv.explicit__(), buf); break;
+ default :
+ TTCN_Logger::begin_event(TTCN_WARNING);
+ TTCN_Logger::log_event("Wrong field was selected from ClientDiffieHellmanPublicValues");
+ TTCN_Logger::end_event();
+ }
+}
+
+ClientDiffieHellmanPublicValues dec__TLS__ClientDiffieHellmanPublicValues(const OCTETSTRING& stream, const TLS__Types::PublicValueEncoding pve) {
+ ClientDiffieHellmanPublicValues ret;
+
+ switch(pve) {
+ case PublicValueEncoding::implicit : ret.implicit() = dec__TLS__ClientDiffieHellmanPublicImplicit(stream); break;
+ case PublicValueEncoding::explicit__ : ret.explicit__() = dec__TLS__ClientDiffieHellmanPublicExplicit(stream); break;
+ default :
+ TTCN_Logger::begin_event(TTCN_WARNING);
+ TTCN_Logger::log_event("Wrong field was selected from ClientDiffieHellmanPublicValues");
+ TTCN_Logger::end_event();
+ }
+
+ return ret;
+}
+
+/////////////////////////////////////
+//// Client Diffie Hellman Public EncDec
+/////////////////////////////////////
+
+void enc__TLS__ClientDiffieHellmanPublic(const TLS__Types::ClientDiffieHellmanPublic cdhp, TTCN_Buffer& buf) {
+ PublicValueEncoding pve;
+
+ if(cdhp.dh__public().get_selection() == ClientDiffieHellmanPublicValues::ALT_implicit){
+ pve = PublicValueEncoding::implicit;
+ } else {
+ pve = PublicValueEncoding::explicit__;
+ }
+
+ enc__TLS__ClientDiffieHellmanPublicValues(cdhp.dh__public(), pve, buf);
+}
+
+ClientDiffieHellmanPublic dec__TLS__ClientDiffieHellmanPublic(const OCTETSTRING& stream) {
+ ClientDiffieHellmanPublic ret;
+ PublicValueEncoding pve;
+
+ if(stream.lengthof() == 0){
+ pve = PublicValueEncoding::implicit;
+ } else {
+ pve = PublicValueEncoding::explicit__;
+ }
+
+ ret.dh__public() = dec__TLS__ClientDiffieHellmanPublicValues(stream, pve);
+
+ return ret;
+}
+
+/////////////////////////////////////
+//// Client Key Exchange Keys EncDec
+/////////////////////////////////////
+
+void enc__TLS__ClientKeyExchangeKeys(const TLS__Types::ClientKeyExchangeKeys ckek, const TLS__Types::KeyExchangeAlgorithm& kea, TTCN_Buffer& buf) {
+ switch(kea){
+ case KeyExchangeAlgorithm::rsa : enc__TLS__EncryptedPreMasterSecret(ckek.rsa(), buf); break;
+ case KeyExchangeAlgorithm::diffie__hellman : enc__TLS__ClientDiffieHellmanPublic(ckek.diffie__hellman(), buf); break;
+ default :
+ TTCN_Logger::begin_event(TTCN_WARNING);
+ TTCN_Logger::log_event("Wrong field was selected from ClientKeyExchangeKeys");
+ TTCN_Logger::end_event();
+ }
+}
+
+ClientKeyExchangeKeys dec__TLS__ClientKeyExchangeKeys(const OCTETSTRING& stream, const TLS__Types::KeyExchangeAlgorithm& kea) {
+ ClientKeyExchangeKeys ret;
+
+ switch(kea){
+ case KeyExchangeAlgorithm::rsa : ret.rsa() = dec__TLS__EncryptedPreMasterSecret(stream); break;
+ case KeyExchangeAlgorithm::diffie__hellman : ret.diffie__hellman() = dec__TLS__ClientDiffieHellmanPublic(stream); break;
+ default :
+ TTCN_Logger::begin_event(TTCN_WARNING);
+ TTCN_Logger::log_event("Wrong field was selected from ClientKeyExchangeKeys");
+ TTCN_Logger::end_event();
+ };
+
+ return ret;
+}
+
+/////////////////////////////////////
+//// Client Key Exchange EncDec
+/////////////////////////////////////
+
+void enc__TLS__ClientKeyExchange(const TLS__Types::ClientKeyExchange& cke, TTCN_Buffer& buf) {
+ /*KeyExchangeAlgorithm kea;
+
+ if(cke.exchange__keys().get_selection() == ClientKeyExchangeKeys::ALT_rsa) {
+ kea = KeyExchangeAlgorithm::rsa;
+ } else {
+ kea = KeyExchangeAlgorithm::diffie__hellman;
+ }
+
+ enc__TLS__ClientKeyExchangeKeys(cke.exchange__keys(), kea, buf);*/
+ buf.put_os(cke.exchange__keys());
+}
+
+ClientKeyExchange dec__TLS__ClientKeyExchange(const OCTETSTRING& stream) {
+ ClientKeyExchange ret;
+ /*KeyExchangeAlgorithm kea;
+
+ if(stream.lengthof() == 48) {
+ kea = KeyExchangeAlgorithm::rsa;
+ } else {
+ kea = KeyExchangeAlgorithm::diffie__hellman;
+ }
+
+ ret.exchange__keys() = dec__TLS__ClientKeyExchangeKeys(stream, kea);*/
+
+ ret.exchange__keys() = stream;
+
+ return ret;
+}
+
+/////////////////////////////////////
+//// Finished EncDec
+/////////////////////////////////////
+
+void enc__TLS__Finished(const TLS__Types::Finished& fin, TTCN_Buffer& buf) {
+ buf.put_os(fin.verify__data());
+}
+
+Finished dec__TLS__Finished(const OCTETSTRING& stream) {
+ Finished ret;
+
+ ret.verify__data() = stream;
+
+ return ret;
+}
+
+/////////////////////////////////////
+//// Handshake Body EncDec
+/////////////////////////////////////
+
+void enc__TLS__HandshakeBody(const TLS__Types::HandshakeBody& body, const TLS__Types::HandshakeType& type, TTCN_Buffer& buf) {
+ switch(type){
+ case HandshakeType::hello__request : enc__TLS__HelloRequest(body.hello__request(), buf); break;
+ case HandshakeType::client__hello : enc__TLS__ClientHello(body.client__hello(), buf); break;
+ case HandshakeType::server__hello : enc__TLS__ServerHello(body.server__hello(), buf); break;
+ case HandshakeType::certificate : enc__TLS__Certificate(body.certificate(), buf); break;
+ case HandshakeType::server__key__exchange : enc__TLS__ServerKeyExchange(body.server__key__exchange(), buf); break;
+ case HandshakeType::certificate__request : enc__TLS__CertificateRequest(body.certificate__request(), buf); break;
+ case HandshakeType::server__hello__done : enc__TLS__ServerHelloDone(body.server__hello__done(), buf); break;
+ case HandshakeType::certificate__verify : enc__TLS__CertificateVerify(body.certificate__verify(), buf); break;
+ case HandshakeType::client__key__exchange : enc__TLS__ClientKeyExchange(body.client__key__exchange(), buf); break;
+ case HandshakeType::finished : enc__TLS__Finished(body.finished(), buf); break;
+ default :
+ TTCN_Logger::begin_event(TTCN_WARNING);
+ TTCN_Logger::log_event("Wrong field was selected from HandshakeBody");
+ TTCN_Logger::end_event();
+ }
+}
+
+HandshakeBody dec__TLS__HandshakeBody(const OCTETSTRING& stream, const TLS__Types::HandshakeType& type, const TLS__Types::KeyExchangeAlgorithm& kea) {
+ HandshakeBody ret;
+ switch(type){
+ case HandshakeType::hello__request : ret.hello__request() = dec__TLS__HelloRequest(stream); break;
+ case HandshakeType::client__hello : ret.client__hello() = dec__TLS__ClientHello(stream); break;
+ case HandshakeType::server__hello : ret.server__hello() = dec__TLS__ServerHello(stream); break;
+ case HandshakeType::certificate : ret.certificate() = dec__TLS__Certificate(stream); break;
+ case HandshakeType::server__key__exchange : ret.server__key__exchange() = dec__TLS__ServerKeyExchange(stream, kea); break;
+ case HandshakeType::certificate__request : ret.certificate__request() = dec__TLS__CertificateRequest(stream); break;
+ case HandshakeType::server__hello__done : ret.server__hello__done() = dec__TLS__ServerHelloDone(stream); break;
+ case HandshakeType::certificate__verify : ret.certificate__verify() = dec__TLS__CertificateVerify(stream); break;
+ case HandshakeType::client__key__exchange : ret.client__key__exchange() = dec__TLS__ClientKeyExchange(stream); break;
+ case HandshakeType::finished : ret.finished() = dec__TLS__Finished(stream); break;
+ default :
+ TTCN_Logger::begin_event(TTCN_WARNING);
+ TTCN_Logger::log_event("Wrong field was selected from HandshakeBody");
+ TTCN_Logger::end_event();
+ }
+
+ return ret;
+}
+
+/////////////////////////////////////
+//// Handshake Enc
+/////////////////////////////////////
+
+void enc__TLS__Handshake(const TLS__Types::Handshake& hs, TTCN_Buffer& buf) {
+ TTCN_Buffer temp_buf;
+ if(hs.msg__type().ispresent()) {
+ enc__TLS__HandshakeType(hs.msg__type(), buf);
+ enc__TLS__HandshakeBody(hs.body(), hs.msg__type(), temp_buf);
+ buf.put_os(int2oct(temp_buf.get_len(), 3));
+ buf.put_buf(temp_buf);
+ } else {
+ buf.put_os(hs.body().encrypted());
+ }
+}
+
+/////////////////////////////////////
+//// Multiple Handshake EncDec
+/////////////////////////////////////
+
+void enc__TLS__MultipleHandshake(const TLS__Types::MultipleHandshake& hs, TTCN_Buffer& buf) {
+ for(int i = 0; i < hs.size_of(); i++){
+ enc__TLS__Handshake(hs[i], buf);
+ }
+}
+
+MultipleHandshake dec__TLS__MultipleHandshake(const OCTETSTRING& stream, const TLS__Types::KeyExchangeAlgorithm& kea) throw(TLS_Exception){
+ MultipleHandshake ret;
+ int offset = 0;
+ int i = 0;
+ int str_len = stream.lengthof();
+
+ do {
+ if(str_len < offset + 1) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ int res = dec__TLS__HandshakeType(substr(stream, offset, 1), ret[i].msg__type()());
+ if(res != 1){
+ ret[i].body().encrypted() = substr(stream, offset, str_len - offset);
+ ret[i].msg__type() = OMIT_VALUE;
+ ret[i].length__() = OMIT_VALUE;
+ return ret;
+ }
+ offset += 1;
+
+ if(str_len < offset + 3) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ ret[i].length__() = oct2int(substr(stream, offset, 3));
+ offset += 3;
+ try {
+ ret[i].body() = dec__TLS__HandshakeBody(substr(stream, offset, ret[i].length__()()), ret[i].msg__type()(), kea);
+ } catch (TLS_Exception e) {
+ ret[i].body().encrypted() = substr(stream, offset, str_len - offset);
+ ret[i].msg__type() = OMIT_VALUE;
+ ret[i].length__() = OMIT_VALUE;
+ return ret;
+ }
+ offset += ret[i].length__()();
+ i++;
+ } while(offset < str_len);
+
+ return ret;
+}
+
+/////////////////////////////////////
+//// Content EncDec
+/////////////////////////////////////
+
+OCTETSTRING enc__TLS__Content(const TLS__Types::Content& cont, const TLS__Types::ContentType& ctype, TTCN_Buffer& buf){
+ OCTETSTRING ret;
+ switch(ctype) {
+ case ContentType::change__cipher__spec : enc__TLS__ChangeCipherSpec(cont.change__cipher__spec(), buf); break;
+ case ContentType::alert : enc__TLS__Alert(cont.alert(), buf); break;
+ case ContentType::handshake : enc__TLS__MultipleHandshake(cont.multiple__handshake(), buf); break;
+ case ContentType::application__data : buf.put_os(cont.application__data()); break;
+ default :
+ TTCN_Logger::begin_event(TTCN_WARNING);
+ TTCN_Logger::log_event("Wrong field was selected from Content");
+ TTCN_Logger::end_event();
+ }
+ buf.get_string(ret);
+
+ return ret;
+
+}
+
+Content dec__TLS__Content(const OCTETSTRING& stream, const TLS__Types::ContentType& ctype, const KeyExchangeAlgorithm& kea){
+ Content ret;
+
+ switch(ctype) {
+ case ContentType::change__cipher__spec : ret.change__cipher__spec() = dec__TLS__ChangeCipherSpec(stream); break;
+ case ContentType::alert : ret.alert() = dec__TLS__Alert(stream); break;
+ case ContentType::handshake : ret.multiple__handshake() = dec__TLS__MultipleHandshake(stream, kea); break;
+ case ContentType::application__data : ret.application__data() = stream; break;
+ default :
+ TTCN_Logger::begin_event(TTCN_WARNING);
+ TTCN_Logger::log_event("Wrong field was selected from Content");
+ TTCN_Logger::end_event();
+ }
+
+ return ret;
+
+}
+
+/////////////////////////////////////
+//// TLS Plaintext EncDec
+/////////////////////////////////////
+
+void enc__TLS__TLSPlaintext(const TLS__Types::TLSPlaintext& text, TTCN_Buffer& buf) {
+ TTCN_Buffer temp_buf;
+ enc__TLS__ContentType(text.type__(), buf);
+ enc__TLS__ProtocolVersion(text.version(), buf);
+ enc__TLS__Content(text.fragment(), text.type__(), temp_buf);
+ buf.put_os(int2oct(temp_buf.get_len(), 2));
+ buf.put_buf(temp_buf);
+}
+
+TLSPlaintext dec__TLS__TLSPlaintext(const OCTETSTRING& stream, const TLS__Types::KeyExchangeAlgorithm& kea) {
+ TLSPlaintext ret;
+ int str_len = stream.lengthof();
+ int offset = 0;
+
+ if(str_len < offset + 1) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ ret.type__() = dec__TLS__ContentType( substr(stream, offset, 1));
+
+ offset += 1;
+
+ if(str_len < offset + 2) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ ret.version() = dec__TLS__ProtocolVersion( substr(stream, offset, 2));
+ offset += 2;
+
+ if(str_len < offset + 2) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ ret.length__() = oct2int(substr( stream, offset, 2));
+ offset += 2;
+
+ if(str_len < offset) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ ret.fragment() = dec__TLS__Content(substr(stream, offset, str_len - offset), ret.type__(), kea);
+ return ret;
+}
+
+/////////////////////////////////////
+//// TLS Plaintexts EncDec
+/////////////////////////////////////
+
+OCTETSTRING enc__TLS__TLSPlaintexts(const TLS__Types::TLSPlaintexts& texts) {
+ TTCN_Buffer buf;
+ OCTETSTRING ret;
+ int size = texts.size_of();
+
+ for(int i = 0; i < size; i++) {
+ enc__TLS__TLSPlaintext(texts[i], buf);
+ }
+
+ buf.get_string(ret);
+
+ return ret;
+}
+
+INTEGER dec__TLS__TLSPlaintexts(const OCTETSTRING& stream, TLS__Types::TLSPlaintexts& ret, const TLS__Types::KeyExchangeAlgorithm& kea=TLS__Types::KeyExchangeAlgorithm::null__) {
+ int str_len = stream.lengthof();
+ int offset = 0;
+ int len;
+ int i = 0;
+ do {
+ try {
+ if(str_len < offset + 5) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ len = oct2int(substr(stream, offset + 3, 2));
+
+ if(str_len < offset + len + 5) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ ret[i] = dec__TLS__TLSPlaintext(substr(stream, offset, len + 5), kea);
+ } catch (TLS_Exception e) {
+ TTCN_Logger::begin_event(TTCN_USER);
+ TTCN_Logger::log_event("***Error has occured: %s. In file: %s in function: %s at line: %d", e.what, e.file, e.func, e.line);
+ TTCN_Logger::end_event();
+ return 0;
+ }
+
+ i++;
+ offset += len + 5;
+ } while(offset != str_len);
+
+ return 1;
+}
+
+/////////////////////////////////////
+//// TLS Compressed EncDec
+/////////////////////////////////////
+
+OCTETSTRING enc__TLS__TLSCompressed(const TLS__Types::TLSCompressed& text) {
+ TTCN_Buffer buf;
+ TTCN_Buffer temp_buf;
+ OCTETSTRING ret;
+
+ enc__TLS__ContentType(text.type__(), buf);
+ enc__TLS__ProtocolVersion(text.version(), buf);
+ enc__TLS__Content(text.fragment(), text.type__(), temp_buf);
+ buf.put_os(int2oct(temp_buf.get_len(), 2));
+ buf.put_buf(temp_buf);
+
+ buf.get_string(ret);
+
+ return ret;
+}
+
+INTEGER dec__TLS__TLSCompressed(const OCTETSTRING& stream, TLS__Types::TLSCompressed& ret, const TLS__Types::KeyExchangeAlgorithm& kea=TLS__Types::KeyExchangeAlgorithm::null__) {
+ int stream_len = stream.lengthof();
+ int offset = 0;
+
+ if(stream_len > 5) {
+ try{
+ ret.type__() = dec__TLS__ContentType(substr(stream, offset, 1));
+ offset += 1;
+
+ ret.version() = dec__TLS__ProtocolVersion(substr(stream, offset, 2));
+ offset += 2;
+
+ ret.length__() = oct2int(substr(stream, offset, 2));
+ offset += 2;
+
+ if(stream_len - offset == ret.length__()) {
+ ret.fragment() = dec__TLS__Content(substr( stream, offset, stream_len - offset), ret.type__(), kea);
+ return 1;
+ }
+ } catch (TLS_Exception e) {
+ TTCN_Logger::begin_event(TTCN_WARNING);
+ TTCN_Logger::log_event("***Error has occured: %s. In file: %s in function: %s at line: %d", e.what, e.file, e.func, e.line);
+ TTCN_Logger::end_event();
+ return 0;
+ }
+ }
+ return 0;
+}
+
+/////////////////////////////////////
+//// Generic Stream Cipher EncDec
+/////////////////////////////////////
+
+void enc__TLS__GenericStreamCipher(const TLS__Types::GenericStreamCipher& gsc, const TLS__Types::TLSCompressed& cmpd, const TLS__Types::SecurityParameters& sp, TTCN_Buffer& buf) {
+ buf.put_os(padd_os_to_len(enc__TLS__Content(gsc.content(), cmpd.type__(), buf), cmpd.length__()));
+ buf.put_os(padd_os_to_len(gsc.mac(), sp.hash__size()));
+}
+
+GenericStreamCipher dec__TLS__GenericStreamCipher(const OCTETSTRING& stream, const TLS__Types::TLSCompressed& cmpd, const TLS__Types::SecurityParameters& sp, const KeyExchangeAlgorithm& kea) throw(TLS_Exception){
+ GenericStreamCipher ret;
+ int str_len = stream.lengthof();
+
+ if(str_len < cmpd.length__()) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ ret.content() = dec__TLS__Content(substr(stream, 0, cmpd.length__()), cmpd.type__(), kea);
+
+ if(str_len < cmpd.length__() + sp.hash__size()) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ ret.mac() = substr(stream, cmpd.length__(), sp.hash__size());
+
+ return ret;
+}
+
+/////////////////////////////////////
+//// Generic Block Cipher EncDec
+/////////////////////////////////////
+
+void enc__TLS__GenericBlockCipher(const TLS__Types::GenericBlockCipher& gbc, const TLS__Types::TLSCompressed& cmpd, const TLS__Types::SecurityParameters& sp, TTCN_Buffer& buf) {
+ buf.put_os(gbc.iv());
+ buf.put_os(padd_os_to_len(enc__TLS__Content(gbc.content(), cmpd.type__(), buf), cmpd.length__()));
+ buf.put_os(padd_os_to_len(gbc.mac(), sp.hash__size()));
+ buf.put_os(int2oct(gbc.padding(), 1));
+ buf.put_os(int2oct(gbc.padding__length(), 1));
+}
+
+GenericBlockCipher dec__TLS__GenericBlockCipher(const OCTETSTRING& stream, const TLS__Types::TLSCompressed& cmpd, const TLS__Types::SecurityParameters& sp, const KeyExchangeAlgorithm& kea) throw(TLS_Exception){
+ GenericBlockCipher ret;
+ int str_len = stream.lengthof();
+
+ if(str_len < 2+cmpd.length__()+sp.hash__size()) {
+ TLS_Exception e;
+ e.what = (const char*)"Invalid length";
+ e.file = (const char*)__FILE__;
+ e.line = __LINE__-4;
+ e.func = __func__;
+ throw e;
+ }
+ ret.padding__length() = oct2int(substr(stream, str_len-1, 1));
+ ret.padding() = oct2int(substr(stream, str_len-2, 1));
+ ret.mac() = substr(stream, str_len-2-sp.hash__size(), sp.hash__size());
+ ret.content() = dec__TLS__Content(substr(stream, str_len-2-sp.hash__size()-cmpd.length__(), cmpd.length__()), cmpd.type__(), kea);
+ ret.iv() = substr(stream, 0, str_len-2-cmpd.length__()-sp.hash__size());
+
+
+ return ret;
+}
+
+/////////////////////////////////////
+//// Cipher Spec Type EncDec
+/////////////////////////////////////
+
+OCTETSTRING enc__TLS__CipherSpecType(const TLS__Types::CipherSpecType& cst, const TLS__Types::TLSCompressed& cmpd, const TLS__Types::SecurityParameters& sp, TTCN_Buffer& buf) {
+ OCTETSTRING ret;
+ switch(cst.get_selection()){
+ case CipherSpecType::ALT_stream : enc__TLS__GenericStreamCipher(cst.stream(), cmpd, sp, buf); break;
+ case CipherSpecType::ALT_block : enc__TLS__GenericBlockCipher(cst.block(), cmpd, sp, buf); break;
+ default :
+ TTCN_Logger::begin_event(TTCN_WARNING);
+ TTCN_Logger::log_event("Wrong field was selected from CipherSpecType");
+ TTCN_Logger::end_event();
+ }
+
+ buf.get_string(ret);
+
+ return ret;
+}
+
+CipherSpecType dec__TLS__CipherSpecType(const OCTETSTRING& stream, const TLS__Types::TLSCompressed& cmpd, const TLS__Types::SecurityParameters& sp, const TLS__Types::KeyExchangeAlgorithm& kea) {
+ CipherSpecType ret;
+ if(stream.lengthof() == cmpd.length__() + sp.hash__size())
+ ret.stream() = dec__TLS__GenericStreamCipher(stream, cmpd, sp, kea);
+ else
+ ret.block() = dec__TLS__GenericBlockCipher(stream, cmpd, sp, kea);
+
+ return ret;
+}
+
+/////////////////////////////////////
+//// TLS Ciphertext EncDec
+/////////////////////////////////////
+
+OCTETSTRING enc__TLS__TLSCiphertext(const TLS__Types::TLSCiphertext& text, const TLS__Types::TLSCompressed& cmpd, const TLS__Types::SecurityParameters& sp) {
+ TTCN_Buffer buf;
+ TTCN_Buffer temp_buf;
+ OCTETSTRING ret;
+
+ enc__TLS__ContentType(text.type__(), buf);
+ enc__TLS__ProtocolVersion(text.version(), buf);
+ enc__TLS__CipherSpecType(text.fragment(), cmpd, sp, temp_buf);
+ buf.put_os(int2oct(temp_buf.get_len(), 2));
+ buf.put_buf(temp_buf);
+
+ buf.get_string(ret);
+
+ return ret;
+}
+
+INTEGER dec__TLS__TLSCiphertext(const OCTETSTRING& stream, const TLS__Types::TLSCompressed& cmpd, const TLS__Types::SecurityParameters& sp, const TLS__Types::KeyExchangeAlgorithm& kea, TLS__Types::TLSCiphertext& ret) {
+ int stream_len = stream.lengthof();
+
+ if(stream_len > 5){
+ try {
+ ret.type__() = dec__TLS__ContentType(substr(stream, 0, 1));
+ ret.version() = dec__TLS__ProtocolVersion(substr(stream, 1, 2));
+ ret.length__() = oct2int(substr(stream, 3, 2));
+ if(ret.length__() == stream_len - 5){
+ ret.fragment() = dec__TLS__CipherSpecType(substr(stream, 5, stream_len - 5), cmpd, sp, kea);
+ return 1;
+ }
+ } catch (TLS_Exception e) {
+ TTCN_Logger::begin_event(TTCN_WARNING);
+ TTCN_Logger::log_event("***Error has occured: %s. In file: %s in function: %s at line: %d", e.what, e.file, e.func, e.line);
+ TTCN_Logger::end_event();
+ return 0;
+ }
+ }
+
+ return 0;
+}
+
+}//namespace
diff --git a/src/TLS_Types.ttcn b/src/TLS_Types.ttcn
new file mode 100644
index 0000000..d85c15b
--- /dev/null
+++ b/src/TLS_Types.ttcn
@@ -0,0 +1,470 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+// Copyright (c) 2000-2016 Ericsson Telecom AB
+//
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// which accompanies this distribution, and is available at
+// http://www.eclipse.org/legal/epl-v10.html
+///////////////////////////////////////////////////////////////////////////////
+//
+// File: TLS_Types.ttcn
+// Description: TLS Types
+// Rev: R2B
+// Prodnr: CNL 113 806
+// Updated: 2014-06-13
+// Contact: http://ttcn.ericsson.se
+// Reference: http://tools.ietf.org/html/rfc4346
+//
+//
+
+
+module TLS_Types {
+
+ external function enc_TLS_TLSPlaintexts(in TLSPlaintexts pl_texts) return octetstring;
+ external function dec_TLS_TLSPlaintexts(in octetstring pl_stream, out TLSPlaintexts pl_texts, in KeyExchangeAlgorithm pl_kea:=null_) return integer;
+
+ external function enc_TLS_TLSCompressed( in TLSCompressed pl_cmpd) return octetstring;
+ external function dec_TLS_TLSCompressed( in octetstring pl_stream, out TLSCompressed pl_decoded, in KeyExchangeAlgorithm pl_kea:=null_) return integer;
+
+ external function enc_TLS_SecurityParameters( in SecurityParameters pl_sp) return octetstring;
+ external function dec_TLS_SecurityParameters( in octetstring pl_stream, out SecurityParameters pl_decoded) return integer;
+
+ external function enc_TLS_TLSCiphertext( in TLSCiphertext pl_text, in TLSCompressed pl_cmpd, in SecurityParameters pl_sp) return octetstring;
+ external function dec_TLS_TLSCiphertext( in octetstring pl_stream, in TLSCompressed pl_cmpd, in SecurityParameters pl_sp, in KeyExchangeAlgorithm pl_kea, out TLSCiphertext pl_decoded) return integer;
+
+ import from General_Types all;
+
+ type octetstring OCT1_16 length(1..16);
+ type octetstring OCT23 length(23);
+ type octetstring OCT24 length(24);
+ type octetstring OCT28 length(28);
+ type octetstring OCT0_32 length(0..32);
+ type octetstring OCT48 length(48);
+
+ type integer LIN3 (0..16777216);
+ type integer LIN4 (0..4294967295);
+
+
+
+ /**********************************************************************/
+ /**********Begining of the type definitions of Record Layer************/
+ /**********************************************************************/
+
+ type record ProtocolVersion {
+ LIN1 major_,
+ LIN1 minor_
+ }
+
+ type enumerated ContentType{
+ change_cipher_spec (20),
+ alert (21),
+ handshake (22),
+ application_data (23)
+ }
+
+ type record of Handshake MultipleHandshake;
+
+ type union Content {
+ ChangeCipherSpec change_cipher_spec,
+ Alert alert,
+ MultipleHandshake multiple_handshake,
+ octetstring application_data
+ }
+
+ type record TLSPlaintext {
+ ContentType type_,
+ ProtocolVersion version,
+ LIN2 length_,
+ Content fragment
+ }
+
+ type record of TLSPlaintext TLSPlaintexts;
+
+ type record TLSCompressed {
+ ContentType type_,
+ ProtocolVersion version,
+ LIN2 length_,
+ Content fragment
+ }
+
+ type record TLSCiphertext {
+ ContentType type_,
+ ProtocolVersion version,
+ LIN2 length_,
+ CipherSpecType fragment
+ }
+
+ type record GenericStreamCipher {
+ Content content,
+ octetstring mac
+ }
+
+ type record GenericBlockCipher {
+ octetstring iv,
+ Content content,
+ octetstring mac,
+ LIN1 padding,
+ LIN1 padding_length
+ }
+
+ type union CipherSpecType {
+ GenericStreamCipher stream,
+ GenericBlockCipher block
+ }
+
+ /**********************************************************************/
+ /************End of the type definitions of Record Layer***************/
+ /**********************************************************************/
+
+ /***********************************************************************/
+ /****Begining of the type definitions of Change Cipher Specs Message****/
+ /***********************************************************************/
+
+ type record ChangeCipherSpec {
+ ChangeCipherSpecEnum type_
+ }
+
+ type enumerated ChangeCipherSpecEnum {
+ change_cipher_spec (1)
+ }
+
+ /***********************************************************************/
+ /******End of the Change Cipher Specs Message's type definitions********/
+ /***********************************************************************/
+
+ /***********************************************************************/
+ /**********Begining of the type definitions of Alert Messages***********/
+ /***********************************************************************/
+
+ type enumerated AlertLevel {
+ warning (1),
+ fatal (2)
+ }
+
+ type enumerated AlertDescription {
+ close_notify (0),
+ unexpected_message (10),
+ bad_record_mac (20),
+ decryption_failed (21),
+ record_overflow (22),
+ decompression_failure (30),
+ handshake_failure (40),
+ no_certificate_RESERVED (41),
+ bad_certificate (42),
+ unsupported_certificate (43),
+ certificate_revoked (44),
+ certificate_expired (45),
+ certificate_unknown (46),
+ illegar_parameter (47),
+ unknown_ca (48),
+ access_denied (49),
+ decode_error (50),
+ decrypt_error (51),
+ export_restriction_RESERVED (60),
+ protocol_version (70),
+ insufficient_security (71),
+ internal_error (80),
+ user_canceled (90),
+ no_renegotiation (100)
+ }
+
+ type record Alert{
+ AlertLevel level,
+ AlertDescription description
+ }
+
+ /***********************************************************************/
+ /*************End of the type definitions of Alert Messages*************/
+ /***********************************************************************/
+
+ /***********************************************************************/
+ /********Begining of the type definitions of Handshake Protocol*********/
+ /***********************************************************************/
+
+ type enumerated HandshakeType {
+ hello_request (0),
+ client_hello (1),
+ server_hello (2),
+ certificate (11),
+ server_key_exchange (12),
+ certificate_request (13),
+ server_hello_done (14),
+ certificate_verify (15),
+ client_key_exchange (16),
+ finished (20)
+ };
+
+ type union HandshakeBody {
+ HelloRequest hello_request,
+ ClientHello client_hello,
+ ServerHello server_hello,
+ Certificate certificate,
+ ServerKeyExchange server_key_exchange,
+ CertificateRequest certificate_request,
+ ServerHelloDone server_hello_done,
+ CertificateVerify certificate_verify,
+ ClientKeyExchange client_key_exchange,
+ Finished finished,
+ octetstring encrypted
+ }
+
+ type record Handshake {
+ HandshakeType msg_type optional,
+ LIN3 length_ optional,
+ HandshakeBody body
+ }
+
+ /*---------------------------------------------------------------------*/
+ /*---------Begining of the type definitions of Hello messages----------*/
+ /*---------------------------------------------------------------------*/
+
+ type record HelloRequest {}
+
+ type record Random {
+ LIN4 gmt_unix_time,
+ OCT28 random_bytes
+ }
+
+ type OCT0_32 SessionID;
+
+
+ type record CipherSuite {
+ OCT1 field1,
+ OCT1 field2
+ };
+
+ type enumerated CompressionMethod {
+ null_ (0)
+ }
+
+ type set length (1..32768) of CipherSuite CipherSuiteList;
+
+ type set length (1..255) of CompressionMethod CompressionMethodList;
+
+ type record ClientHello {
+ ProtocolVersion client_version,
+ Random random,
+ SessionID session_id optional,
+ CipherSuiteList cipher_suites,
+ CompressionMethodList compression_methods,
+ octetstring extension_ optional
+ }
+
+ type record ServerHello {
+ ProtocolVersion server_version,
+ Random random,
+ SessionID session_id optional,
+ CipherSuite cipher_suite,
+ CompressionMethod compression_method
+ }
+
+ /*---------------------------------------------------------------------*/
+ /*-----------End of the type definitions of Hello messages-------------*/
+ /*---------------------------------------------------------------------*/
+
+ /*---------------------------------------------------------------------*/
+ /*-------Begining of the type definitions of SA and Key Exchange-------*/
+ /*---------------------------------------------------------------------*/
+
+ type octetstring ASN_1Cert length (1..16777215);
+
+ type set length (1..16777215) of ASN_1Cert CertificateList;
+
+ type record Certificate {
+ CertificateList certificate_list optional
+ }
+
+ type enumerated KeyExchangeAlgorithm {
+ rsa,
+ diffie_hellman,
+ null_ (255)
+ }
+
+ type record ServerRSAParams {
+ OCT1_16 rsa_modulus,
+ OCT1_16 rsa_exponent
+ }
+
+ type record ServerDHParams {
+ OCT1_16 dh_p,
+ OCT1_16 dh_g,
+ OCT1_16 dh_Ys
+ }
+
+ type record ServerKeyExchange {
+ ServerParams params,
+ Signature signed_params
+ }
+
+ type enumerated SignatureAlgorithm {
+ anonymous,
+ rsa,
+ dsa
+ }
+
+ type union ServerParams {
+ ServerDHParams dh_params,
+ ServerRSAParams rsa_params
+ }
+
+ type record AnonymSignature {
+
+ }
+
+ type record RSASignature {
+ OCT16 md5_hash,
+ OCT20 sha_hash
+ }
+
+ type record DSASignature {
+ OCT20 sha_hash
+ }
+
+ type union Signature {
+ AnonymSignature anonym,
+ RSASignature rsa,
+ DSASignature dsa
+ }
+
+ type enumerated ClientCertificateType{
+ rsa_sign (1),
+ dss_sign (2),
+ rsa_fixed_dh (3),
+ dss_fixed_dh (4),
+ rsa_ephemeral_dh_RESERVED (5),
+ dss_ephemeral_dh_RESERVED (6),
+ fortezza_dms_RESERVED (20),
+ ecdsa_sign (64)
+ }
+
+ type OCT1_16 DistinguishedName;
+
+ type set length (1..255) of ClientCertificateType ClientCertificateTypeList;
+
+ type record CertificateRequest {
+ ClientCertificateTypeList certificate_types,
+ DistinguishedName certificate_authorities optional
+ }
+
+ type record ServerHelloDone {}
+ /*---------------------------------------------------------------------*/
+ /*---------End of the type definitions of SA and Key Exchange----------*/
+ /*---------------------------------------------------------------------*/
+
+ /*---------------------------------------------------------------------*/
+ /*-------Begining of the type definitions of CA and Key Exchange-------*/
+ /*---------------------------------------------------------------------*/
+
+ type union ClientKeyExchangeKeys {
+ EncryptedPreMasterSecret rsa,
+ ClientDiffieHellmanPublic diffie_hellman
+ }
+
+ type record ClientKeyExchange {
+ octetstring exchange_keys
+ }
+
+ type enumerated PublicValueEncoding {
+ implicit,
+ explicit_
+ }
+
+ type record ClientDiffieHellmanPublicImplicit {}
+
+ type record ClientDiffieHellmanPublicExplicit {
+ OCT1_16 DH_Yc
+ }
+
+ type union ClientDiffieHellmanPublicValues {
+ ClientDiffieHellmanPublicImplicit implicit,
+ ClientDiffieHellmanPublicExplicit explicit_
+ }
+
+ type record ClientDiffieHellmanPublic {
+ ClientDiffieHellmanPublicValues dh_public
+ }
+
+ type record PreMasterSecret {
+ ProtocolVersion client_version,
+ OCT46 random
+ }
+
+ type record EncryptedPreMasterSecret {
+ PreMasterSecret pre_master_secret
+ }
+
+ type record CertificateVerify {
+ octetstring signature_
+ }
+
+ /*---------------------------------------------------------------------*/
+ /*---------End of the type definitions of CA and Key Exchange----------*/
+ /*---------------------------------------------------------------------*/
+
+ /*---------------------------------------------------------------------*/
+ /*--Begining of the type definitions of Handshake Finalization Message-*/
+ /*---------------------------------------------------------------------*/
+
+ type record Finished {
+ OCT12 verify_data
+ }
+
+ /*---------------------------------------------------------------------*/
+ /*----End of the type definitions of Handshake Finalization Message----*/
+ /*---------------------------------------------------------------------*/
+
+ /***********************************************************************/
+ /**********End of the type definitions of Handshake Protocol************/
+ /***********************************************************************/
+
+ /***********************************************************************/
+ /*******Begining of the type definitions of The Security Parameters*****/
+ /***********************************************************************/
+
+ type enumerated ConnectionEnd {
+ server,
+ client
+ }
+
+ type enumerated BulkCipherAlgorithm {
+ null_,
+ rc4,
+ rc2,
+ des,
+ three_des,
+ des40,
+ aes,
+ idea
+ }
+
+ type enumerated CipherType {
+ stream,
+ block
+ }
+
+ type enumerated MACAlgorithm {
+ null_,
+ md5,
+ sha
+ }
+
+ type record SecurityParameters {
+ ConnectionEnd entity,
+ BulkCipherAlgorithm bulk_cipher_algorithm,
+ CipherType cipher_type,
+ LIN1 key_size,
+ LIN1 key_material_length,
+ MACAlgorithm mac_algorithm,
+ LIN1 hash_size,
+ CompressionMethod compression_algorithm,
+ OCT48 master_secret,
+ OCT32 client_random,
+ OCT32 server_random
+ }
+
+ /***********************************************************************/
+ /********End of the type definitions of The Security Parameters*********/
+ /***********************************************************************/
+
+} //end of module