xdg-go/scram

GitHub: xdg-go/scram

该库为 Go 语言提供了 SCRAM 身份验证机制的客户端和服务端实现,支持通道绑定。

Stars: 54 | Forks: 21

[![Go 参考文档](https://pkg.go.dev/badge/github.com/xdg-go/scram.svg)](https://pkg.go.dev/github.com/xdg-go/scram) [![Go 报告卡](https://goreportcard.com/badge/github.com/xdg-go/scram)](https://goreportcard.com/report/github.com/xdg-go/scram) [![Github Actions](https://static.pigsec.cn/wp-content/uploads/repos/cas/ad/ad5834178f7599af9fdda11629d49cae07f2997beec49821b2920eff5bfd50e7.svg)](https://github.com/xdg-go/scram/actions/workflows/test.yml) # scram – RFC-5802 的 Go 实现 ## 描述 scram 包提供了盐化质询响应身份验证机制(SCRAM)的客户端和服务端实现,该机制描述于以下文档: - [RFC-5802](https://tools.ietf.org/html/rfc5802) - [RFC-5929](https://tools.ietf.org/html/rfc5929) - [RFC-7677](https://tools.ietf.org/html/rfc7677) - [RFC-9266](https://tools.ietf.org/html/rfc9266) 它同时包含客户端和服务端的支持。 针对 SCRAM-PLUS 变体支持通道绑定,包括: - `tls-unique` (RFC 5929) - 不安全,但必需 - `tls-server-end-point` (RFC 5929) - 适用于所有 TLS 版本 - `tls-exporter` (RFC 9266) - 推荐用于 TLS 1.3+ 不支持 SCRAM 消息扩展。 ## 示例 ### 客户端 ``` package main import "github.com/xdg-go/scram" func main() { // Get Client with username, password and (optional) authorization ID. clientSHA1, err := scram.SHA1.NewClient("mulder", "trustno1", "") if err != nil { panic(err) } // Prepare the authentication conversation. Use the empty string as the // initial server message argument to start the conversation. conv := clientSHA1.NewConversation() var serverMsg string // Get the first message, send it and read the response. firstMsg, err := conv.Step(serverMsg) if err != nil { panic(err) } serverMsg = sendClientMsg(firstMsg) // Get the second message, send it, and read the response. secondMsg, err := conv.Step(serverMsg) if err != nil { panic(err) } serverMsg = sendClientMsg(secondMsg) // Validate the server's final message. We have no further message to // send so ignore that return value. _, err = conv.Step(serverMsg) if err != nil { panic(err) } return } func sendClientMsg(s string) string { // A real implementation would send this to a server and read a reply. return "" } ``` ### 带通道绑定的客户端 (SCRAM-PLUS) ``` package main import ( "crypto/tls" "github.com/xdg-go/scram" ) func main() { // Establish TLS connection tlsConn, err := tls.Dial("tcp", "server:port", &tls.Config{MinVersion: tls.VersionTLS13}) if err != nil { panic(err) } defer tlsConn.Close() // Get Client with username, password client, err := scram.SHA256.NewClient("mulder", "trustno1", "") if err != nil { panic(err) } // Create channel binding from TLS connection (TLS 1.3 example) // Use NewTLSExporterBinding for TLS 1.3+, NewTLSServerEndpointBinding for all TLS versions channelBinding, err := scram.NewTLSExporterBinding(&tlsConn.ConnectionState()) if err != nil { panic(err) } // Create conversation with channel binding for SCRAM-SHA-256-PLUS conv := client.NewConversationWithChannelBinding(channelBinding) // ... rest of authentication conversation } ``` ## 版权与许可 Copyright 2018 由 David A. Golden 所有。保留所有权利。 基于 Apache License, Version 2.0(“许可证”)授权。您可以在 http://www.apache.org/licenses/LICENSE-2.0 获取许可证副本
标签:EVTX分析, Go库, SCRAM, 加密协议, 底层编程, 日志审计, 网络通信