Source File
common.go
Belonging Package
golang.org/x/crypto/ssh
const (
compressionNone = "none"
serviceUserAuth = "ssh-userauth"
serviceSSH = "ssh-connection"
)
var supportedCiphers = []string{
"aes128-ctr", "aes192-ctr", "aes256-ctr",
"aes128-gcm@openssh.com",
chacha20Poly1305ID,
"arcfour256", "arcfour128", "arcfour",
aes128cbcID,
tripledescbcID,
}
var preferredCiphers = []string{
"aes128-gcm@openssh.com",
chacha20Poly1305ID,
"aes128-ctr", "aes192-ctr", "aes256-ctr",
}
var supportedKexAlgos = []string{
var serverForbiddenKexAlgos = map[string]struct{}{
kexAlgoDHGEXSHA1: {}, // server half implementation is only minimal to satisfy the automated tests
kexAlgoDHGEXSHA256: {}, // server half implementation is only minimal to satisfy the automated tests
}
var supportedMACs = []string{
"hmac-sha2-256-etm@openssh.com", "hmac-sha2-256", "hmac-sha1", "hmac-sha1-96",
}
var supportedCompressions = []string{compressionNone}
var hashFuncs = map[string]crypto.Hash{
KeyAlgoRSA: crypto.SHA1,
KeyAlgoDSA: crypto.SHA1,
KeyAlgoECDSA256: crypto.SHA256,
KeyAlgoECDSA384: crypto.SHA384,
KeyAlgoECDSA521: crypto.SHA512,
CertAlgoRSAv01: crypto.SHA1,
CertAlgoDSAv01: crypto.SHA1,
CertAlgoECDSA256v01: crypto.SHA256,
CertAlgoECDSA384v01: crypto.SHA384,
CertAlgoECDSA521v01: crypto.SHA512,
}
func ( uint8) error {
return fmt.Errorf("ssh: parse error in message type %d", )
}
func ( string, []string, []string) ( string, error) {
for , := range {
for , := range {
if == {
return , nil
}
}
}
return "", fmt.Errorf("ssh: no common algorithm for %s; client offered: %v, server offered: %v", , , )
}
type directionAlgorithms struct {
Cipher string
MAC string
Compression string
}
switch .Cipher {
case "aes128-ctr", "aes192-ctr", "aes256-ctr", gcmCipherID, aes128cbcID:
return 16 * (1 << 32)
}
return 1 << 30
}
type algorithms struct {
kex string
hostKey string
w directionAlgorithms
r directionAlgorithms
}
func ( bool, , *kexInitMsg) ( *algorithms, error) {
:= &algorithms{}
.kex, = findCommon("key exchange", .KexAlgos, .KexAlgos)
if != nil {
return
}
.hostKey, = findCommon("host key", .ServerHostKeyAlgos, .ServerHostKeyAlgos)
if != nil {
return
}
, := &.w, &.r
if {
, = ,
}
.Cipher, = findCommon("client to server cipher", .CiphersClientServer, .CiphersClientServer)
if != nil {
return
}
.Cipher, = findCommon("server to client cipher", .CiphersServerClient, .CiphersServerClient)
if != nil {
return
}
.MAC, = findCommon("client to server MAC", .MACsClientServer, .MACsClientServer)
if != nil {
return
}
.MAC, = findCommon("server to client MAC", .MACsServerClient, .MACsServerClient)
if != nil {
return
}
.Compression, = findCommon("client to server compression", .CompressionClientServer, .CompressionClientServer)
if != nil {
return
}
.Compression, = findCommon("server to client compression", .CompressionServerClient, .CompressionServerClient)
if != nil {
return
}
return , nil
}
const minRekeyThreshold uint64 = 256
= append(, )
}
}
.Ciphers =
if .KeyExchanges == nil {
.KeyExchanges = preferredKexAlgos
}
if .MACs == nil {
.MACs = supportedMACs
}
} else if .RekeyThreshold < minRekeyThreshold {
.RekeyThreshold = minRekeyThreshold
.RekeyThreshold = math.MaxInt64
}
}
func ( []byte, userAuthRequestMsg, , []byte) []byte {
:= struct {
[]byte
byte
string
string
string
bool
[]byte
[]byte
}{
,
msgUserAuthRequest,
.User,
.Service,
.Method,
true,
,
,
}
return Marshal()
}
func ( []byte, uint16) []byte {
return append(, byte(>>8), byte())
}
func ( []byte, uint32) []byte {
return append(, byte(>>24), byte(>>16), byte(>>8), byte())
}
func ( []byte, uint64) []byte {
return append(,
byte(>>56), byte(>>48), byte(>>40), byte(>>32),
byte(>>24), byte(>>16), byte(>>8), byte())
}
func ( []byte, int) []byte {
return appendU32(, uint32())
}
func ( []byte, string) []byte {
= appendU32(, uint32(len()))
= append(, ...)
return
}
func ( []byte, bool) []byte {
if {
return append(, 1)
}
return append(, 0)
}
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |