[安全] Golang 1.13.2 和 1.12.11 版本正式发布

[安全] Golang 1.13.2 和 1.12.11 版本正式发布 大家好,

我们刚刚发布了 Go 1.13.2 和 Go 1.12.11 版本,以解决一个近期报告的安全问题。我们建议所有受影响的用户更新到这些版本之一(如果不确定选哪个,请选择 Go 1.13.2)。

无效的 DSA 公钥可能导致 dsa.Verify 发生 panic。具体来说,对精心构造的 X.509 证书链使用 crypto/x509.Verify 可能导致 panic,即使这些证书并未链接到受信任的根证书。该证书链可以通过 crypto/tls 连接传递给客户端,或者传递给接受并验证客户端证书的服务器。net/http 客户端可能因 HTTPS 服务器而崩溃,而接受客户端证书的 net/http 服务器会恢复 panic 且不受影响。

此外,应用程序在调用 crypto/x509.(*CertificateRequest).CheckSignature 处理 X.509 证书请求时、解析 golang.org/x/crypto/openpgp 实体时,或在 golang.org/x/crypto/otr 会话期间也可能崩溃。最后,golang.org/x/crypto/ssh 客户端可能因格式错误的 host key 而 panic,而服务器则可能在 PublicKeyCallback 接受格式错误的公钥,或者 IsUserAuthority 接受带有格式错误公钥的证书时发生 panic。

此问题编号为 CVE-2019-17596,Go 问题跟踪编号为 golang.org/issue/34960

感谢 Daniel Mandragona 发现并报告此问题。我们还要感谢 regilero 先前对 CVE-2019-16276 的披露。

Go 1.13.2 版本还包含一个编译器修复,防止在极少数情况下不当访问负的切片索引。受影响的代码(编译器能证明索引为零或负值的情况)在 Go 1.12 中会导致 panic,但在 Go 1.13 和 Go 1.13.1 中可能导致任意的内存读写。此问题编号为 golang.org/issue/34802

所有支持平台的下载包均可在 https://golang.org/dl 获取。

祝好, 🐕 Katie 代表 Go 团队


更多关于[安全] Golang 1.13.2 和 1.12.11 版本正式发布的实战教程也可以访问 https://www.itying.com/category-94-b0.html

1 回复

更多关于[安全] Golang 1.13.2 和 1.12.11 版本正式发布的实战系列教程也可以访问 https://www.itying.com/category-94-b0.html


// 示例:演示如何安全地处理证书验证以避免panic
package main

import (
    "crypto/x509"
    "encoding/pem"
    "fmt"
    "log"
)

func main() {
    // 假设这是从外部接收的证书数据
    certPEM := []byte(`-----BEGIN CERTIFICATE-----
MIIB... // 实际证书数据
-----END CERTIFICATE-----`)

    // 安全地解析证书
    block, _ := pem.Decode(certPEM)
    if block == nil {
        log.Fatal("failed to parse certificate PEM")
    }

    // 在Go 1.13.2/1.12.11之前,以下调用可能因无效DSA公钥而panic
    cert, err := x509.ParseCertificate(block.Bytes)
    if err != nil {
        // 现在会返回错误而不是panic
        log.Printf("证书解析失败: %v", err)
        return
    }

    // 验证证书链
    roots := x509.NewCertPool()
    // 添加根证书到roots...
    
    opts := x509.VerifyOptions{
        Roots: roots,
    }

    // 在修复版本中,即使证书链包含无效DSA密钥也不会panic
    if _, err := cert.Verify(opts); err != nil {
        log.Printf("证书验证失败: %v", err)
        return
    }

    fmt.Println("证书验证通过")
}

// SSH连接示例,展示如何处理格式错误的host key
import (
    "golang.org/x/crypto/ssh"
    "net"
)

func connectSSH() {
    config := &ssh.ClientConfig{
        User: "username",
        Auth: []ssh.AuthMethod{
            ssh.Password("password"),
        },
        // 在修复版本中,格式错误的host key会返回错误而不是panic
        HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error {
            // 安全地处理host key验证
            if key.Type() == "ssh-dss" {
                // DSA密钥需要额外验证
                if err := validateDSAKey(key); err != nil {
                    return fmt.Errorf("无效的DSA密钥: %v", err)
                }
            }
            return nil
        },
    }
}

func validateDSAKey(key ssh.PublicKey) error {
    // 实现DSA密钥的验证逻辑
    // 在修复版本中,不会因为格式错误的DSA密钥而panic
    return nil
}

这个安全修复主要涉及:

  1. crypto/dsa.Verify - 现在对无效公钥返回错误而不是panic
  2. crypto/x509.Verify - 安全地处理包含无效DSA密钥的证书链
  3. crypto/x509.(*CertificateRequest).CheckSignature - 改进错误处理
  4. golang.org/x/crypto/openpgp - 安全解析实体
  5. golang.org/x/crypto/otr - 安全的OTR会话处理
  6. golang.org/x/crypto/ssh - 客户端和服务器端的密钥验证

更新到Go 1.13.2或1.12.11后,上述场景都会从panic改为返回适当的错误值,提高了程序的稳定性。

回到顶部