根据squid改写golang tls标准库

需求

golang 重写squid tls_bump验证squid tls_bump
获取 SNI
改完支持https透明代理

支持https 代理

定义bump相关数据结构

// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package mytls

import (
	"net"
	"net/http"
)

type BumpMode uint8

const (
	bumpNone        BumpMode = 0
	bumpClientFirst BumpMode = 1
	bumpServerFirst BumpMode = 2
	bumpPeek        BumpMode = 3
	bumpStare       BumpMode = 4
	bumpBump        BumpMode = 5
	bumpSplice      BumpMode = 6
	bumpTerminate   BumpMode = 7
	/* bumpErr */
	bumpEnd alert = 8
)

type XactionStep uint8

const (
	tlsBump1 XactionStep = 0
	tlsBump2 XactionStep = 1
	tlsBump3 XactionStep = 2
)

type actBump struct {
	step1 BumpMode
	step2 BumpMode
	step3 BumpMode
}

type ServerBump struct {
	request *http.Request
	session *ClientSessionState
	cert    *Certificate
	act     *actBump
	step    XactionStep
}

type TlsDetails struct {
	compressionSupported  bool
	serverName            string
	doHeartBeats          bool
	tlsTicketsExtension   bool
	hasTlsTicket          bool
	tlsStatusRequest      bool
	unsupportedExtensions bool
	tlsAppLayerProtoNeg   string
	clientRandom          string
	seessionID            string
	Ciphers               map[int]string
}
type ParserState uint8

const (
	atHelloNone ParserState = iota
	atHelloStarted
	atHelloReceived
	atHelloDoneReceived
	atNstReceived
	atCcsReceived
	atFinishReceived
)

type MessageSource uint8

const (
	fromClient MessageSource = iota
	fromServer
)

type BinaryTokenizer struct {
	address    *net.IP
	data       string //
	parsed     uint8
	syncPoint  uint8
	expectMore bool
}

type SetHow uint8

const (
	optUnspecified SetHow = iota
	optImplicitly
	optConfigured
)

type YesNoNone struct {
	setHow SetHow
	option bool
}

type HandShakeParser struct {
	details                *TlsDetails
	state                  ParserState
	resumingSession        bool
	messageSource          MessageSource
	currentContentType     uint8
	done                   []byte
	fragments              string
	tkRecords              *BinaryTokenizer
	tkMessage              *BinaryTokenizer
	expectingModernRecords *YesNoNone
}
posted @   心亘久  阅读(81)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
点击右上角即可分享
微信分享提示