PHPackages                             tourze/tls-handshake-messages - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. tourze/tls-handshake-messages

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

tourze/tls-handshake-messages
=============================

Comprehensive PHP library for handling TLS handshake protocol messages with serialization, deserialization, and validation capabilities

0.0.1(11mo ago)052MITPHPPHP ^8.1CI passing

Since Jun 15Pushed 4mo agoCompare

[ Source](https://github.com/tourze/tls-handshake-messages)[ Packagist](https://packagist.org/packages/tourze/tls-handshake-messages)[ RSS](/packages/tourze-tls-handshake-messages/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

TLS Handshake Messages
======================

[](#tls-handshake-messages)

[English](README.md) | [中文](README.zh-CN.md)

[![Latest Version](https://camo.githubusercontent.com/aac219ff6fdd70b2f425fbc5832892cfd42c9157cad694730c7a89c260dac5d3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f75727a652f746c732d68616e647368616b652d6d657373616765732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/tls-handshake-messages)[![Build Status](https://camo.githubusercontent.com/3c75cbf80739d3f42836bab035102123295320544fd5b4157e0fec7fc34b2780/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f746f75727a652f7068702d6d6f6e6f7265706f2f63692e796d6c3f6272616e63683d6d6173746572267374796c653d666c61742d737175617265)](https://github.com/tourze/php-monorepo/actions)[![PHP Version](https://camo.githubusercontent.com/b90f3605b8b6289ab273be97cd3547f4a4afd474d1e64d19250dfc6c73ec0372/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f746f75727a652f746c732d68616e647368616b652d6d657373616765732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/tls-handshake-messages)[![Quality Score](https://camo.githubusercontent.com/43930c8561a14d3f5a68c62b692ee20749bac4c043e09e88fd3fdd611660198f/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f746f75727a652f7068702d6d6f6e6f7265706f2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/tourze/php-monorepo)[![Code Coverage](https://camo.githubusercontent.com/fce86ff4532b4694c22512e5e192a270f73dd27d6e5495fffb59c73cf14de807/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f746f75727a652f7068702d6d6f6e6f7265706f2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/tourze/php-monorepo)[![Total Downloads](https://camo.githubusercontent.com/89caeac2aac27f6fc3127b88905e79cb80cdd8e293f4aaf5173e11e020835c0f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746f75727a652f746c732d68616e647368616b652d6d657373616765732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/tls-handshake-messages)[![License](https://camo.githubusercontent.com/6aed27e075582e47b291217ab3fd0e2bbb8608e288ee863a7b5ee24a9eff60b8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f746f75727a652f746c732d68616e647368616b652d6d657373616765732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/tls-handshake-messages)

A comprehensive PHP library for handling TLS handshake protocol messages. This package provides complete implementation of TLS handshake message structures with serialization, deserialization, and validation capabilities.

Table of Contents
-----------------

[](#table-of-contents)

- [Features](#features)
- [Installation](#installation)
- [Requirements](#requirements)
- [Supported Message Types](#supported-message-types)
- [Quick Start](#quick-start)
    - [Creating a ClientHello Message](#creating-a-clienthello-message)
    - [Working with Certificates](#working-with-certificates)
    - [Message Validation](#message-validation)
    - [Version Compatibility](#version-compatibility)
- [Architecture](#architecture)
    - [Message Interface](#message-interface)
    - [Message Types](#message-types)
    - [Exception Handling](#exception-handling)
- [Testing](#testing)
- [Development](#development)
    - [Code Quality](#code-quality)
- [Contributing](#contributing)
- [License](#license)
- [Security](#security)
- [Related Packages](#related-packages)

Features
--------

[](#features)

- 🔒 **Complete TLS Message Support**: Implements all major TLS handshake message types
- 📦 **Serialization/Deserialization**: Efficient binary data encoding and decoding
- ✅ **Message Validation**: Built-in integrity and format validation
- 🔄 **Version Compatibility**: Support for multiple TLS versions with compatibility handling
- 🧪 **Well Tested**: Comprehensive test suite with 100+ test cases
- 🚀 **High Performance**: Optimized for production use

Installation
------------

[](#installation)

```
composer require tourze/tls-handshake-messages
```

Requirements
------------

[](#requirements)

- PHP 8.1 or higher
- tourze/enum-extra: ^0.1
- tourze/tls-common: ^0.0

Supported Message Types
-----------------------

[](#supported-message-types)

- **ClientHello**: Client handshake initialization
- **ServerHello**: Server handshake response
- **Certificate**: Certificate chain messages
- **CertificateRequest**: Certificate request from server
- **CertificateVerify**: Certificate verification messages
- **ClientKeyExchange**: Client key exchange messages
- **ServerKeyExchange**: Server key exchange messages
- **Finished**: Handshake completion messages
- **NewSessionTicket**: Session ticket messages
- **EncryptedExtensions**: TLS 1.3 encrypted extensions
- **HelloRequest**: Server hello request messages
- **ServerHelloDone**: Server hello done messages

Quick Start
-----------

[](#quick-start)

### Creating a ClientHello Message

[](#creating-a-clienthello-message)

```
use Tourze\TLSHandshakeMessages\Message\ClientHelloMessage;

// Create a new ClientHello message
$clientHello = new ClientHelloMessage();
$clientHello->setVersion(0x0303); // TLS 1.2
$clientHello->setRandom(random_bytes(32));
$clientHello->setSessionId('');
$clientHello->setCipherSuites([0x1301, 0x1302]); // TLS 1.3 cipher suites
$clientHello->setCompressionMethods([0x00]);

// Add extensions
$clientHello->addExtension(0, hex2bin('00000e7777772e676f6f676c652e636f6d')); // server_name

// Serialize to binary
$binaryData = $clientHello->encode();

// Deserialize from binary
$decodedMessage = ClientHelloMessage::decode($binaryData);
```

### Working with Certificates

[](#working-with-certificates)

```
use Tourze\TLSHandshakeMessages\Message\CertificateMessage;

// Create certificate message with chain
$certificate = new CertificateMessage();
$certificate->setCertificateChain([
    $serverCertificate,
    $intermediateCertificate,
    $rootCertificate
]);

// Or add certificates one by one
$certificate->addCertificate($serverCertificate);
$certificate->addCertificate($intermediateCertificate);

// Validate certificate message
if ($certificate->isValid()) {
    // Process certificate chain
    $chain = $certificate->getCertificateChain();
}
```

### Message Validation

[](#message-validation)

```
// All messages implement validation
if ($message->isValid()) {
    // Message is properly formatted
    $length = $message->getLength();
    $type = $message->getType();
}
```

### Version Compatibility

[](#version-compatibility)

```
use Tourze\TLSHandshakeMessages\Protocol\MessageCompatibilityHandler;

// Adapt message to different TLS versions
$tls12Message = MessageCompatibilityHandler::adaptMessageToVersion(
    $originalMessage,
    MessageCompatibilityHandler::TLS_VERSION_1_2
);

// Check compatibility
if (MessageCompatibilityHandler::isMessageCompatibleWithVersion($message, MessageCompatibilityHandler::TLS_VERSION_1_3)) {
    // Message is compatible with TLS 1.3
}
```

Architecture
------------

[](#architecture)

### Message Interface

[](#message-interface)

All messages implement `HandshakeMessageInterface` which provides:

- `getType()`: Get message type
- `encode()`: Serialize to binary
- `decode()`: Deserialize from binary
- `getLength()`: Get message length
- `isValid()`: Validate message format

### Message Types

[](#message-types)

Message types are defined in `HandshakeMessageType` enum:

```
use Tourze\TLSHandshakeMessages\Protocol\HandshakeMessageType;

$type = HandshakeMessageType::CLIENT_HELLO;
```

### Exception Handling

[](#exception-handling)

The package uses `InvalidMessageException` for handling malformed messages:

```
use Tourze\TLSHandshakeMessages\Exception\InvalidMessageException;

try {
    $message = ClientHelloMessage::decode($invalidData);
} catch (InvalidMessageException $e) {
    // Handle invalid message format
}
```

Testing
-------

[](#testing)

Run the test suite:

```
vendor/bin/phpunit packages/tls-handshake-messages/tests
```

Development
-----------

[](#development)

### Code Quality

[](#code-quality)

```
# Run PHPStan analysis
vendor/bin/phpstan analyse packages/tls-handshake-messages

# Run tests
vendor/bin/phpunit packages/tls-handshake-messages/tests
```

Contributing
------------

[](#contributing)

1. Fork the repository
2. Create a feature branch
3. Write tests for new functionality
4. Ensure all tests pass
5. Submit a pull request

License
-------

[](#license)

MIT License. See [LICENSE](LICENSE) file for details.

Security
--------

[](#security)

This package is designed for defensive security applications. If you discover any security issues, please report them responsibly.

Related Packages
----------------

[](#related-packages)

- [tourze/tls-common](../tls-common) - Common TLS utilities
- [tourze/enum-extra](../enum-extra) - Enhanced enum functionality

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance64

Regular maintenance activity

Popularity8

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

332d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e354fdb316da535dfa8ba2e9193a473c403b6bc6fb9170778d1dc50e304c6e9d?d=identicon)[tourze](/maintainers/tourze)

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tourze-tls-handshake-messages/health.svg)

```
[![Health](https://phpackages.com/badges/tourze-tls-handshake-messages/health.svg)](https://phpackages.com/packages/tourze-tls-handshake-messages)
```

###  Alternatives

[braincrafted/background-process

Start processes in the background that continue running when the PHP process exists.

2976.1k1](/packages/braincrafted-background-process)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
