Having an issue onverting PFX to Pem

Viewed 422

I'm trying to convert PFX to PEM without success due to this error:

pkcs12: error reading P12 data: asn1: syntax error: indefinite length found (not DER)

Searching online results in an indication to Encode BER to DER and then the ToPEM will not throw this annoying error. I couldn't find any solution whatsoever.

The pfx file is encoded with base64 and decoded to []byte which doesn't suppose to affect the error in any case.

I don't have any option to change the pfx file which is inserted into this variable config.ClusterCertificate

The code:

blocks, err := pkcs12.ToPEM(config.ClusterCertificate, "")
    if err != nil {
        return nil, err
    }
    var pemData []byte
    for _, b := range blocks {
        pemData = append(pemData, pem.EncodeToMemory(b)...)
    }

    // then use PEM data for tls to construct tls certificate:
    cert, err := tls.X509KeyPair(pemData, pemData)
    if err != nil {
        return nil, err
    }

    config := &tls.Config{
        Certificates: []tls.Certificate{cert},
    }

    _ = config

    x509cert, err := x509.ParseCertificate(cert.Certificate[0])
    if err != nil {
        return nil, err
    }
    store.TrustStore = x509cert
    store.Certificate = &cert

pfx

certutil dump

enter image description here

0 Answers
Related