Coder Social home page Coder Social logo

tlssyntax's Introduction

TLS Syntax

TLS defines its own syntax for describing structures used in that protocol. To facilitate experimentation with TLS in Go, this module maps that syntax to the Go structure syntax, taking advantage of Go's type annotations to encode non-type information carried in the TLS presentation format.

For example, in the TLS specification, a ClientHello message has the following structure:

uint16 ProtocolVersion;
opaque Random[32];
uint8 CipherSuite[2];
enum { ... (65535)} ExtensionType;

struct {
    ExtensionType extension_type;
    opaque extension_data<0..2^16-1>;
} Extension;

struct {
    ProtocolVersion legacy_version = 0x0303;    /* TLS v1.2 */
    Random random;
    opaque legacy_session_id<0..32>;
    CipherSuite cipher_suites<2..2^16-2>;
    opaque legacy_compression_methods<1..2^8-1>;
    Extension extensions<0..2^16-1>;
} ClientHello;

This maps to the following Go type definitions:

type protocolVersion uint16
type random [32]byte
type cipherSuite uint16 // or [2]byte
type extensionType uint16

type extension struct {
  ExtensionType extensionType
  ExtensionData []byte `tls:"head=2"`
}

type clientHello struct {
	LegacyVersion            protocolVersion
	Random                   random
	LegacySessionID          []byte        `tls:"head=1,max=32"`
	CipherSuites             []cipherSuite `tls:"head=2,min=2"`
	LegacyCompressionMethods []byte        `tls:"head=1,min=1"`
	Extensions               []extension   `tls:"head=2"`
}

Then you can just declare, marshal, and unmarshal structs just like you would with, say JSON.

The available annotations right now are all related to vectors:

  • head: The number of bytes of length to use as a "header"
  • min: The minimum length of the vector, in bytes
  • max: The maximum length of the vector, in bytes

Not supported

  • The select() syntax for creating alternate version of the same struct (see, e.g., the KeyShare extension)

  • The backreference syntax for array lengths or select parameters, as in opaque fragment[TLSPlaintext.length]. Note, however, that in cases where the length immediately preceds the array, these can be reframed as vectors with appropriate sizes.

tlssyntax's People

Contributors

bifurcation avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.