本文整理汇总了Golang中encoding/pem.Block类的典型用法代码### 示例。如果您正苦于以下问题:Golang Block类的具体用法?Golang Block怎么用?Golang Block使用的例子?那么恭喜您, 这里精选的类代码### 示例或许可以为您提供帮助。

在下文中一共展示了Block类的20个代码### 示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码### 示例。

示例1: ReadPEMData

// Read a PEM file and ask for a password to decrypt it if needed
func ReadPEMData(pemFile string, pemPass []byte) ([]byte, error) {
    pemData, err := ioutil.ReadFile(pemFile)
    if err != nil {
        return pemData, err
    }

    // We should really just get the pem.Block back here, if there's other
    // junk on the end, warn about it.
    pemBlock, rest := pem.Decode(pemData)
    if len(rest) > 0 {
        log.Warning("Didn't parse all of", pemFile)
    }

    if x509.IsEncryptedPEMBlock(pemBlock) {
        // Decrypt and get the ASN.1 DER bytes here
        pemData, err = x509.DecryptPEMBlock(pemBlock, pemPass)
        if err != nil {
            return pemData, err
        } else {
            log.Info("Decrypted", pemFile, "successfully")
        }
        // Shove the decrypted DER bytes into a new pem Block with blank headers
        var newBlock pem.Block
        newBlock.Type = pemBlock.Type
        newBlock.Bytes = pemData
        // This is now like reading in an uncrypted key from a file and stuffing it
        // into a byte stream
        pemData = pem.EncodeToMemory(&newBlock)
    }
    return pemData, nil
}

开发者ID:BrianIp,项目名称:orchestrator,代码行数:32,代码来源:ssl.go

示例2: CertificateLockFile

// CertificateLockFile adds a new certificate lock on the given Client and
// Config that ensures that a server's certificate is signed by the same CA
// from connection-to-connection. This is helpful when connecting to servers
// with self-signed certificates.
//
// If filename does not exist, the server's certificate chain will be written
// to that file. If it does exist, certificates will be read from that file and
// added to RootCAs in config's TLSConfig.
//
// Example:
//
//  if firstConnectionToServer {
//      // Allow self-signed certificates to be accepted on the initial
//      // connection.
//      config.TLSConfig.InsecureSkipVerify = true
//  }
//  gumbleutil.CertificateLockFile(client, &config, filename)
//
//  if err := client.Connect(); err != nil {
//      panic(err)
//  }
func CertificateLockFile(client *gumble.Client, config *gumble.Config, filename string) (gumble.Detacher, error) {
    if file, err := os.Open(filename); err == nil {
        defer file.Close()
        if config.TLSConfig.RootCAs == nil {
            config.TLSConfig.RootCAs = x509.NewCertPool()
        }
        if data, err := ioutil.ReadAll(file); err == nil {
            config.TLSConfig.RootCAs.AppendCertsFromPEM(data)
        }
        return nil, nil
    }

    return client.Attach(Listener{
        Connect: func(e *gumble.ConnectEvent) {
            tlsClient, ok := e.Client.Conn().(*tls.Conn)
            if !ok {
                return
            }
            serverCerts := tlsClient.ConnectionState().PeerCertificates
            file, err := os.Create(filename)
            if err != nil {
                return
            }
            block := pem.Block{
                Type: "CERTIFICATE",
            }
            for _, cert := range serverCerts {
                block.Bytes = cert.Raw
                pem.Encode(file, &block)
            }
            file.Close()
        },
    }), nil
}

开发者ID:nadams,项目名称:gomumblesoundboard,代码行数:55,代码来源:certificatelock.go

示例3: Marshal

func (pk *PrivateKey) Marshal(ss ...string) ([]byte, error) {
    var k = x509.MarshalPKCS1PrivateKey(&pk.PrivateKey)
    var block pem.Block
    block.Bytes = k
    block.Type = strings.Join(ss, " ")
    return pem.EncodeToMemory(&block), nil
}

开发者ID:wzshiming,项目名称:base,代码行数:7,代码来源:key.go

示例4: execSSH

func execSSH(url, uuid string, key *rsa.PrivateKey, args []string) error {
    f, err := ioutil.TempFile("", "runx")
    if err != nil {
        return fmt.Errorf("tmpfile: %s", err)
    }
    defer f.Close()
    var b pem.Block
    b.Type = "RSA PRIVATE KEY"
    b.Bytes = x509.MarshalPKCS1PrivateKey(key)
    if err = pem.Encode(f, &b); err != nil {
        return fmt.Errorf("pem: %s", err)
    }
    f.Seek(0, 0)
    argv := []string{
        "ssh",
        "-i" + f.Name(),
        "-oProxyCommand=hk runx [proxy]",
        "-oLocalCommand=rm " + f.Name(),
        "-oStrictHostKeyChecking=no",
        "-oUserKnownHostsFile=/dev/null",
        "[email protected]" + uuid,
    }
    env := append(os.Environ(), "RUNX_URL="+url)
    return syscall.Exec("/usr/bin/ssh", append(argv, args...), env)
}

开发者ID:kr,项目名称:runx,代码行数:25,代码来源:main.go

示例5: EncodePEM

func EncodePEM(binary []byte, blockType string, password string) (pemBlock string, err error) {

    var blk *pem.Block
    /* Awaiting Go 1.1 */
    if password != "" {
        passwordBytes := ([]byte)(password)
        blk, err = x509.EncryptPEMBlock(rand.Reader, blockType, binary, passwordBytes, x509.PEMCipherAES256)
        if err != nil {
            return
        }
    } else {
        /* */
        blk = new(pem.Block)
        blk.Type = blockType
        blk.Bytes = binary
        /* Awaiting Go 1.1 */
    }
    /* */

    buf := new(bytes.Buffer)

    err = pem.Encode(buf, blk)
    if err != nil {
        return
    }

    pemBlock = buf.String()
    return
}

开发者ID:eric-hawthorne,项目名称:relish,代码行数:29,代码来源:crypto_util.go

最后编辑: kuteng  文档更新时间: 2021-08-23 19:14   作者:kuteng