Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error Parsing CA Pem File #16203

Closed
jnapl1 opened this issue Jun 30, 2022 · 23 comments
Closed

Error Parsing CA Pem File #16203

jnapl1 opened this issue Jun 30, 2022 · 23 comments
Labels
auth/cert Authentication - certificates core/cli storage/postgresql

Comments

@jnapl1
Copy link

jnapl1 commented Jun 30, 2022

Describe the bug
Vault returns errors when trying to parse a pem file for the server certificate signing CA.

I have gotten this error for the use of VAULT_CACERT env variable and the sslrootcert parameter of the Postgresql storage connection url.

To Reproduce
Steps to reproduce the behavior:

Case 1:

  1. Run VAULT_CACERT=/path/to/vault-ca.pem vault status
  2. See error: failed to read environment: ERROR loading CA File: Couldn't parse PEM in: /path/to/vault-ca.pem

Case 2:

  1. Set postgresql connection_url to postgres://{user}:{password}@{db-host:port}/vaultdb?sslmode=verify-full&sslrootcert=/path/to/vault-ca.pem&sslcert=/path/to/vault-cert.pem&sslkey=/path/to/vault-key.pem
  2. Run vault server -config=/path/to/config.hcl
  3. See error: Error initializing storage of type postgesql: failed to check for native upsert: pq: couldn't parse pem in sslrootcert

Expected behavior
I expected these parameters to make use of the signing CA. Use of VAULT_CACERT will work with the Vault server certificate, though this seems like a workaround and not really a solution. Use of the server cert for sslrootcert has not worked so far.

Environment:

  • Vault v1.9.3
  • RHEL 7

Vault server configuration file(s):

storage "postgresql" {
    connection_url = "postgres://{user}:{password}@{db-host:port}/vaultdb?sslmode=verify-full&sslrootcert=/path/to/vault-ca.pem&sslcert=/path/to/vault-cert.pem&sslkey=/path/to/vault-key.pem"
    table = "vault_kv_store"
    max_parallel = "128"
    ha_enabled = "true"
    ha_table = "vault_ha_locks"
}

listener "tcp" {
    address = "[::]:8200"
    tls_disable= false
    tls_cert_file = "/path/to/vault-cert.pem"
    tls_key_file = "/path/to/vault-key.pem"
}

plugin_directory = "/etc/vault/plugins"
api_addr = "https://{vault-host}:8200"
cluster_addr = "https://{vault-host}:8201"
ui = true
log_level = "trace"
disable_mlock = true

Additional context
I came across this issue while attempting to implement mTLS between Vault and Postgresql. I didn't go into to much detail on this here because I was trying to keep this focused on what I thought was the bug.

If it would be helpful, more details can be found here: https://discuss.hashicorp.com/t/configure-vault-postgresql-storage-with-mutual-tls-connection/40809

I have also briefly tried Vault v1.10.4, but this was just to see if a newer version would resolve the issue. Most troubleshooting effort has been done with v1.9.3.

@hsimon-hashicorp
Copy link
Contributor

Hi there - what are the contents of the PEM file? Can it be read with other tools, ie openssl verify?

@hsimon-hashicorp hsimon-hashicorp added auth/cert Authentication - certificates waiting-for-response and removed auth/cert Authentication - certificates labels Jun 30, 2022
@jnapl1
Copy link
Author

jnapl1 commented Jun 30, 2022

I was able to read it with both openssl verify -CAfile ./root.pem ./vault-ca.pem and openssl x509 -in vault-ca.pem -text.

Unfortunately, I am unable to copy and paste the contents of the PEM. Is there anything in particular I should be looking for? Otherwise I can type out what I can from the output of the openssl x509 ... command, or any other that may be more helpful.

@hsimon-hashicorp
Copy link
Contributor

The only other thing I can think of is the environment variable may not be getting passed in correctly. The output says it can't parse the file at ./vault-ca.pem, but your environment variable has a fully-qualified directory in it.

@jnapl1
Copy link
Author

jnapl1 commented Jun 30, 2022

My bad. That was a typo. Corrected it.

@hsimon-hashicorp hsimon-hashicorp added storage/postgresql auth/cert Authentication - certificates labels Jun 30, 2022
@hsimon-hashicorp
Copy link
Contributor

Darn - I was hoping I could answer it easily for you. I'll check with engineering to see if there's something else I may have missed. Thanks! :)

@hsimon-hashicorp
Copy link
Contributor

Would you be willing to run openssl x509 -in vault-ca.pem -inform PEM -text and let us know the output? Thanks! (Unfortunately, Go isn't as much help in debugging certificate issues as we'd like, so we're having to sort of try to "triangulate" this.)

@jnapl1
Copy link
Author

jnapl1 commented Jun 30, 2022

Here's the output I get (slightly edited to save time. I have to type it out manually). I can try and fill it in more if what I excluded was important.

Certificate:
    Data:
        Version: 3 (0x2)
        Serial Number: ...
    Signature Algorithm: sha256WithRSAEncryption
        Issuer: <root CA>
        Validity
            Not Before: May 24 00:00:00 2022 GMT
            Not After: Apr 20 00:00:00 2025 GMT
        Subject: <issuing CA>
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
                Public-Key: (2048 bit)
                Modulus:
                    ...
                Exponent: 65537 (0x10001)
        X509v3 extensions:
            X509v3 Authority Key Identifier:
                keyid: ...

            X509v3 Subject Key Identifier:
                ...
            X509v3 Basic Constraints: critical
                CA: TRUE
            X509v3 Key Usage:
                Digital Signature, Certificate Sign, CRL Sign
    Signature Algorithm: sha256WithRsaEncryption
        ...
-----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----

@cipherboy
Copy link
Contributor

Hey @jnapl1 --

A program like this (suggested by my colleague @swenson) might be helpful to diagnose the problem:

package main

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

func main() {
	data, err := os.ReadFile(os.Args[1])
	if err != nil {
		panic(err)
	}

	block, _ := pem.Decode(data)
	if block == nil {
		panic("Invalid PEM block")
	}
	cert, err := x509.ParseCertificate(block.Bytes)
	if err != nil {
		panic(err)
	}
	fmt.Printf("Read certificate okay: %+v\n", cert)
}

If you run it with:

$ go run ./prog.go "$VAULT_CACERT"

it should let us know if there's an issue with the certificate or if it reads OK:

E.g. for an invalid PEM file I get:

[cipherboy@xps15 148]$ go run ./prog.go isrg-root-x1-cross-signed.pem 
panic: Invalid PEM block

goroutine 1 [running]:
main.main()
	/home/cipherboy/tmp/148/prog.go:18 +0xe5
exit status 2

But for a valid cert I get:

[cipherboy@xps15 148]$ go run ./prog.go cert.txt 
Read certificate okay: &{Raw:[48 130 5 96 48 130 4  ... more output elided ...

The details of the panic should be sufficient to help identify the cause. :-)

This is essentially what is being done in that program. The output comes from: https://github.com/hashicorp/go-rootcerts/blob/master/rootcerts.go#L71-L89 -- which calls https://cs.opensource.google/go/go/+/refs/tags/go1.18.3:src/crypto/x509/cert_pool.go;l=206

Seems like it might potentially be a bug in this version of Go; a newer 1.9.7 binary might not have this problem if its already been fixed.

@jnapl1
Copy link
Author

jnapl1 commented Jul 1, 2022

Honestly, I've never used go before. So I haven't been able to get this to run just yet.

But I tried replicating the error on my personal VM, using certificates I created with openssl, so that I could share the certificates I was using and for whatever reason it worked. I think the error could be from the v3 extensions, but not sure which ones or why it would be a problem.

(sorry, this is going to be a long one)

These certificates worked:
root.pem

Certificate:
    Data:
        Version: 3 (0x2)
        Serial Number:
            f2:85:d0:d2:c5:41:56:70
    Signature Algorithm: sha256WithRSAEncryption
        Issuer: C=US, L=Default City, O=Default Company Ltd, CN=ROOT CA
        Validity
            Not Before: Jul  1 13:13:01 2022 GMT
            Not After : Jun 28 13:13:01 2032 GMT
        Subject: C=US, L=Default City, O=Default Company Ltd, CN=ROOT CA
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
                Public-Key: (2048 bit)
                Modulus:
                    00:d0:19:f6:59:e1:02:ac:0b:9f:03:b5:81:8c:a5:
                    4d:15:a9:a6:ef:df:23:66:dd:ac:34:75:fc:be:7c:
                    2c:f8:60:ca:d8:7c:99:99:01:cd:90:19:33:d1:24:
                    b1:bb:f5:80:75:17:41:08:8d:b3:e8:56:2a:22:98:
                    f7:0a:44:0f:50:35:24:ee:4e:bd:95:49:13:50:4e:
                    87:34:67:fa:8e:a1:aa:48:9f:91:b7:65:45:c4:95:
                    7c:73:cb:38:7f:9a:63:dd:a4:2c:c0:4d:3e:fe:09:
                    3f:fe:2e:8a:31:a0:2d:a5:04:15:e8:12:08:14:40:
                    4e:90:db:9f:38:8b:a6:fd:91:a1:c2:57:14:98:8b:
                    82:fb:69:1c:00:1a:4d:bf:66:81:a1:58:fb:13:8d:
                    22:5e:63:8e:14:48:02:91:65:5e:f8:a0:ba:f2:f8:
                    07:aa:5c:98:b3:13:4a:48:3a:be:ee:f2:bd:7e:ac:
                    05:08:22:4d:6f:79:6f:6e:63:94:38:4e:d9:1c:09:
                    a5:67:aa:6a:9d:a9:60:9c:b8:73:36:80:d0:16:e1:
                    df:41:a3:a6:8b:7b:21:49:91:92:6f:bb:36:b4:6c:
                    1a:30:59:0a:06:a0:fa:47:34:67:ce:3a:8c:98:38:
                    5e:c7:6a:b3:50:c8:e8:f4:96:40:fc:c8:c8:40:22:
                    25:4b
                Exponent: 65537 (0x10001)
        X509v3 extensions:
            X509v3 Subject Key Identifier: 
                31:04:6B:8B:08:29:4F:3D:E4:59:B3:DF:AA:57:F1:BE:67:38:A6:0A
            X509v3 Authority Key Identifier: 
                keyid:31:04:6B:8B:08:29:4F:3D:E4:59:B3:DF:AA:57:F1:BE:67:38:A6:0A

            X509v3 Basic Constraints: 
                CA:TRUE
    Signature Algorithm: sha256WithRSAEncryption
         cd:ac:28:87:69:4b:1f:4f:09:53:e8:ab:ac:1e:89:11:2b:c8:
         65:eb:7e:5a:a9:dd:f0:52:50:31:79:d7:93:84:12:7a:5f:86:
         40:10:2a:c6:c1:89:69:20:f7:29:1d:52:41:34:03:59:2b:4a:
         14:fd:4e:59:59:02:57:d0:94:28:30:83:25:69:5c:cc:9c:14:
         9f:76:b6:91:b6:5a:14:91:d7:dd:f1:9b:44:c4:43:87:89:ec:
         81:fa:af:b9:59:aa:e9:6d:8f:a2:b1:e9:21:cf:03:a1:3f:7f:
         6a:96:a8:52:15:1c:b6:5e:81:d0:b0:f5:bc:09:ce:a6:af:63:
         93:fa:98:e7:1a:99:01:4d:34:55:9f:98:e7:53:5c:fb:42:52:
         34:5f:ed:8c:fc:86:8c:50:93:8c:25:60:2e:d7:d6:61:3c:59:
         57:eb:38:41:52:02:0e:d7:7c:7c:a4:43:17:7c:5b:a9:de:b8:
         17:e0:91:dc:ff:15:a8:bb:cd:ad:79:0d:20:b7:97:00:89:d6:
         d7:e2:d5:bb:db:f5:5f:2f:ef:c0:22:9b:60:db:9b:33:03:ae:
         12:56:cb:53:c9:19:b3:bd:22:66:66:53:73:74:46:26:38:e9:
         04:c2:63:58:92:ca:25:5f:da:b6:93:8a:48:51:00:51:4c:36:
         74:4b:08:7a
-----BEGIN CERTIFICATE-----
MIIDezCCAmOgAwIBAgIJAPKF0NLFQVZwMA0GCSqGSIb3DQEBCwUAMFQxCzAJBgNV
BAYTAlVTMRUwEwYDVQQHDAxEZWZhdWx0IENpdHkxHDAaBgNVBAoME0RlZmF1bHQg
Q29tcGFueSBMdGQxEDAOBgNVBAMMB1JPT1QgQ0EwHhcNMjIwNzAxMTMxMzAxWhcN
MzIwNjI4MTMxMzAxWjBUMQswCQYDVQQGEwJVUzEVMBMGA1UEBwwMRGVmYXVsdCBD
aXR5MRwwGgYDVQQKDBNEZWZhdWx0IENvbXBhbnkgTHRkMRAwDgYDVQQDDAdST09U
IENBMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0Bn2WeECrAufA7WB
jKVNFamm798jZt2sNHX8vnws+GDK2HyZmQHNkBkz0SSxu/WAdRdBCI2z6FYqIpj3
CkQPUDUk7k69lUkTUE6HNGf6jqGqSJ+Rt2VFxJV8c8s4f5pj3aQswE0+/gk//i6K
MaAtpQQV6BIIFEBOkNufOIum/ZGhwlcUmIuC+2kcABpNv2aBoVj7E40iXmOOFEgC
kWVe+KC68vgHqlyYsxNKSDq+7vK9fqwFCCJNb3lvbmOUOE7ZHAmlZ6pqnalgnLhz
NoDQFuHfQaOmi3shSZGSb7s2tGwaMFkKBqD6RzRnzjqMmDhex2qzUMjo9JZA/MjI
QCIlSwIDAQABo1AwTjAdBgNVHQ4EFgQUMQRriwgpTz3kWbPfqlfxvmc4pgowHwYD
VR0jBBgwFoAUMQRriwgpTz3kWbPfqlfxvmc4pgowDAYDVR0TBAUwAwEB/zANBgkq
hkiG9w0BAQsFAAOCAQEAzawoh2lLH08JU+irrB6JESvIZet+Wqnd8FJQMXnXk4QS
el+GQBAqxsGJaSD3KR1SQTQDWStKFP1OWVkCV9CUKDCDJWlczJwUn3a2kbZaFJHX
3fGbRMRDh4nsgfqvuVmq6W2PorHpIc8DoT9/apaoUhUctl6B0LD1vAnOpq9jk/qY
5xqZAU00VZ+Y51Nc+0JSNF/tjPyGjFCTjCVgLtfWYTxZV+s4QVICDtd8fKRDF3xb
qd64F+CR3P8VqLvNrXkNILeXAInW1+LVu9v1Xy/vwCKbYNubMwOuElbLU8kZs70i
ZmZTc3RGJjjpBMJjWJLKJV/atpOKSFEAUUw2dEsIeg==
-----END CERTIFICATE-----

vault.pem

Certificate:
    Data:
        Version: 3 (0x2)
        Serial Number:
            fc:5a:16:51:e9:37:e5:fd
    Signature Algorithm: sha256WithRSAEncryption
        Issuer: C=US, L=Default City, O=Default Company Ltd, CN=ROOT CA
        Validity
            Not Before: Jul  1 13:40:18 2022 GMT
            Not After : Jul  1 13:40:18 2023 GMT
        Subject: C=US, L=Default City, O=Default Company Ltd, CN=VAULT
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
                Public-Key: (2048 bit)
                Modulus:
                    00:a4:df:eb:ba:8f:68:e1:b6:90:aa:8b:cb:12:1b:
                    25:bc:1a:e4:5d:30:1f:39:4c:07:aa:36:78:ce:e5:
                    c6:58:26:c0:f0:47:4d:50:18:34:d4:05:18:3c:14:
                    e6:8a:1a:cc:49:54:29:21:e8:9e:7a:f7:c5:50:30:
                    0a:e0:0b:4e:08:01:d6:f5:f2:fc:41:30:d5:91:84:
                    48:db:1d:31:a5:31:e1:97:d6:c0:08:bf:f0:70:94:
                    a4:d4:97:4c:62:f7:db:aa:46:89:91:fa:a5:7a:d4:
                    4f:b7:0c:cf:de:e5:07:d6:55:f1:04:39:b1:1a:1d:
                    c3:e1:3d:b4:e3:3b:65:40:ef:69:0e:f6:95:ae:40:
                    a7:89:67:6b:75:3a:16:8d:98:25:48:88:f6:1b:78:
                    94:3a:b5:e4:0e:16:3e:fe:ae:9c:0a:68:48:09:a4:
                    4e:94:e6:04:05:7b:31:41:1f:ad:f3:22:7c:35:ed:
                    16:2d:e0:3e:43:e8:6b:7d:b4:30:ad:1d:21:cb:84:
                    92:72:aa:d8:88:f9:a0:e5:5d:db:d5:dd:90:00:f8:
                    e1:1f:c6:3f:d5:2c:dc:bd:c4:7d:4d:4c:71:84:3c:
                    8c:df:7d:a2:f5:69:12:1c:cd:d7:aa:29:25:4e:8f:
                    11:4a:db:2b:c7:65:e9:8e:5a:64:70:5b:a4:53:be:
                    0b:d3
                Exponent: 65537 (0x10001)
        X509v3 extensions:
            X509v3 Authority Key Identifier: 
                keyid:31:04:6B:8B:08:29:4F:3D:E4:59:B3:DF:AA:57:F1:BE:67:38:A6:0A

            X509v3 Basic Constraints: 
                CA:FALSE
            X509v3 Subject Alternative Name: 
                IP Address:127.0.0.1
    Signature Algorithm: sha256WithRSAEncryption
         3f:e5:9d:fc:f3:b4:aa:dd:f0:19:ce:97:64:2b:f7:6d:fb:fa:
         eb:e0:c1:aa:40:5e:46:cc:dc:c7:46:89:92:2d:46:4c:52:41:
         de:f9:10:80:ab:15:05:a3:dd:b7:d4:7d:a6:7d:71:a8:d0:8f:
         25:f2:57:a9:cf:b7:36:28:6c:8f:de:4b:17:58:26:a2:0d:1d:
         20:a9:6b:45:80:66:45:72:93:20:68:28:be:28:1a:de:5c:47:
         2e:6c:3e:54:59:6f:5a:91:80:f0:96:30:dc:55:e6:fc:1d:9c:
         5a:74:a0:e7:ac:c5:b6:ce:69:6e:87:46:6a:d3:5c:da:43:d6:
         81:20:bb:aa:b6:de:b6:b4:65:11:cc:c1:03:b7:fa:e3:c7:9a:
         30:2f:88:9f:77:ea:19:ff:49:6d:30:c1:e3:f8:bd:89:69:14:
         e4:b1:83:12:5d:6a:eb:a1:11:3d:0e:d3:50:38:35:e1:ee:2f:
         41:e3:01:c3:e7:17:44:c2:31:1a:22:01:91:1b:04:87:5f:51:
         f3:85:16:46:08:e4:57:e0:51:21:17:6f:17:43:e1:1c:83:12:
         31:3e:fc:82:3d:65:f4:e6:9e:b4:03:1f:38:75:93:86:a4:8e:
         73:da:b6:f8:54:eb:07:fd:b4:dc:d8:24:4e:90:29:73:8d:ca:
         99:51:ea:98
-----BEGIN CERTIFICATE-----
MIIDaDCCAlCgAwIBAgIJAPxaFlHpN+X9MA0GCSqGSIb3DQEBCwUAMFQxCzAJBgNV
BAYTAlVTMRUwEwYDVQQHDAxEZWZhdWx0IENpdHkxHDAaBgNVBAoME0RlZmF1bHQg
Q29tcGFueSBMdGQxEDAOBgNVBAMMB1JPT1QgQ0EwHhcNMjIwNzAxMTM0MDE4WhcN
MjMwNzAxMTM0MDE4WjBSMQswCQYDVQQGEwJVUzEVMBMGA1UEBwwMRGVmYXVsdCBD
aXR5MRwwGgYDVQQKDBNEZWZhdWx0IENvbXBhbnkgTHRkMQ4wDAYDVQQDDAVWQVVM
VDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKTf67qPaOG2kKqLyxIb
Jbwa5F0wHzlMB6o2eM7lxlgmwPBHTVAYNNQFGDwU5ooazElUKSHonnr3xVAwCuAL
TggB1vXy/EEw1ZGESNsdMaUx4ZfWwAi/8HCUpNSXTGL326pGiZH6pXrUT7cMz97l
B9ZV8QQ5sRodw+E9tOM7ZUDvaQ72la5Ap4lna3U6Fo2YJUiI9ht4lDq15A4WPv6u
nApoSAmkTpTmBAV7MUEfrfMifDXtFi3gPkPoa320MK0dIcuEknKq2Ij5oOVd29Xd
kAD44R/GP9Us3L3EfU1McYQ8jN99ovVpEhzN16opJU6PEUrbK8dl6Y5aZHBbpFO+
C9MCAwEAAaM/MD0wHwYDVR0jBBgwFoAUMQRriwgpTz3kWbPfqlfxvmc4pgowCQYD
VR0TBAIwADAPBgNVHREECDAGhwR/AAABMA0GCSqGSIb3DQEBCwUAA4IBAQA/5Z38
87Sq3fAZzpdkK/dt+/rr4MGqQF5GzNzHRomSLUZMUkHe+RCAqxUFo9231H2mfXGo
0I8l8lepz7c2KGyP3ksXWCaiDR0gqWtFgGZFcpMgaCi+KBreXEcubD5UWW9akYDw
ljDcVeb8HZxadKDnrMW2zmluh0Zq01zaQ9aBILuqtt62tGURzMEDt/rjx5owL4if
d+oZ/0ltMMHj+L2JaRTksYMSXWrroRE9DtNQODXh7i9B4wHD5xdEwjEaIgGRGwSH
X1HzhRZGCORX4FEhF28XQ+EcgxIxPvyCPWX05p60Ax84dZOGpI5z2rb4VOsH/bTc
2CROkClzjcqZUeqY
-----END CERTIFICATE-----

These certificates failed:
I tried creating certificates with the similar v3 extensions as my vault-ca.pem (specifically key usage) and get this error when trying VAULT_CACERT=root2.pem vault status

Error checking seal status: Get "https://127.0.0.1:7200/v1/sys/seal-status": x509: certificate signed by unknown authority (possibly because of "x509: invalid signature: parent certificate cannot sign this kind of certificate" while trying to verify candidate authority certificate "ROOT CA")

root2.pem

Certificate:
    Data:
        Version: 3 (0x2)
        Serial Number:
            eb:94:14:11:7f:a7:6f:43
    Signature Algorithm: sha256WithRSAEncryption
        Issuer: C=US, CN=ROOT CA
        Validity
            Not Before: Jul  1 14:06:30 2022 GMT
            Not After : Jun 28 14:06:30 2032 GMT
        Subject: C=US, CN=ROOT CA
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
                Public-Key: (2048 bit)
                Modulus:
                    00:9b:74:df:14:f8:ce:20:c0:af:86:0b:32:fc:ce:
                    10:12:5c:62:d7:6b:5a:48:f3:72:6e:f5:6e:61:0e:
                    20:2e:68:79:a4:43:ac:33:d2:28:29:cc:8e:0d:bd:
                    e2:3c:b0:cc:0d:1a:d1:07:dd:46:b2:cb:ea:28:2f:
                    c7:b2:0c:87:89:f7:ab:78:2f:79:70:52:14:84:5a:
                    b0:f7:fe:18:f5:9d:1b:e9:50:70:94:95:e5:18:58:
                    17:2d:17:bf:a9:36:47:55:ab:eb:55:31:10:71:ac:
                    93:87:25:d3:7f:7c:3f:a0:97:57:60:d9:31:3e:eb:
                    ea:1b:cf:52:24:df:7d:10:c6:7d:63:d4:14:18:6d:
                    5e:86:3c:97:30:a6:ba:c3:ff:9b:46:6b:03:92:9f:
                    47:b1:43:b9:59:4f:8d:10:4d:fb:7b:94:9b:de:65:
                    40:1d:3a:e7:aa:90:40:21:ee:03:0c:e5:b5:4b:52:
                    fb:6e:87:35:95:a4:f7:7d:a9:42:62:57:c4:c8:3b:
                    fe:8e:57:65:6b:56:3b:71:e4:1a:ee:43:e4:25:73:
                    bc:f1:10:18:34:93:ca:b3:73:84:8c:b4:74:ea:ff:
                    0f:0c:ff:64:dd:42:4c:3b:39:23:ee:7f:df:a5:2b:
                    90:ca:38:bc:c7:60:84:c4:3e:d0:c5:0e:cc:2f:de:
                    27:2d
                Exponent: 65537 (0x10001)
        X509v3 extensions:
            X509v3 Key Usage: 
                Digital Signature, Certificate Sign, CRL Sign
    Signature Algorithm: sha256WithRSAEncryption
         56:4d:01:7a:e0:c1:de:cb:a6:8f:a2:50:e5:ae:e7:2f:c1:aa:
         6e:09:e7:44:21:1a:28:02:6e:be:24:7e:58:67:b9:cc:58:a8:
         97:ff:55:d5:0e:90:42:b7:4a:53:b0:0e:4d:c0:de:d8:ba:49:
         d7:73:7d:be:63:15:eb:cb:c5:6a:0a:04:0b:05:5c:72:0e:f6:
         60:4c:2d:0a:1c:1e:57:5d:86:d3:b1:b8:b5:0e:d3:0f:34:e0:
         04:cb:88:5a:b9:2b:1f:c3:22:58:6c:c7:6c:13:a8:c0:72:51:
         22:5b:f1:65:1e:ff:ea:0e:09:31:7d:44:79:cb:3e:5c:a5:f8:
         22:32:b2:ef:16:dc:dc:2c:fa:51:c9:37:15:a0:24:5c:7a:69:
         99:bc:66:35:2e:a9:9f:63:65:5f:d8:2e:cc:a9:77:af:6e:bf:
         1b:ef:b2:da:38:56:a7:ac:57:dc:48:8a:99:3a:60:52:73:30:
         01:47:41:8f:42:26:33:2b:6a:00:bf:c5:60:f1:74:f6:3d:81:
         5d:75:6f:89:cb:de:48:46:6e:00:e2:e8:53:cc:3d:40:a2:99:
         54:63:bc:68:f0:6d:e8:94:20:fa:3b:1f:8a:67:ed:be:99:35:
         ad:84:ca:ee:93:f4:6e:41:e0:90:a4:38:ca:05:e3:78:50:49:
         f7:9c:51:32
-----BEGIN CERTIFICATE-----
MIIC0DCCAbigAwIBAgIJAOuUFBF/p29DMA0GCSqGSIb3DQEBCwUAMB8xCzAJBgNV
BAYTAlVTMRAwDgYDVQQDDAdST09UIENBMB4XDTIyMDcwMTE0MDYzMFoXDTMyMDYy
ODE0MDYzMFowHzELMAkGA1UEBhMCVVMxEDAOBgNVBAMMB1JPT1QgQ0EwggEiMA0G
CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCbdN8U+M4gwK+GCzL8zhASXGLXa1pI
83Ju9W5hDiAuaHmkQ6wz0igpzI4NveI8sMwNGtEH3Uayy+ooL8eyDIeJ96t4L3lw
UhSEWrD3/hj1nRvpUHCUleUYWBctF7+pNkdVq+tVMRBxrJOHJdN/fD+gl1dg2TE+
6+obz1Ik330Qxn1j1BQYbV6GPJcwprrD/5tGawOSn0exQ7lZT40QTft7lJveZUAd
OueqkEAh7gMM5bVLUvtuhzWVpPd9qUJiV8TIO/6OV2VrVjtx5BruQ+Qlc7zxEBg0
k8qzc4SMtHTq/w8M/2TdQkw7OSPuf9+lK5DKOLzHYITEPtDFDswv3ictAgMBAAGj
DzANMAsGA1UdDwQEAwIBhjANBgkqhkiG9w0BAQsFAAOCAQEAVk0BeuDB3sumj6JQ
5a7nL8GqbgnnRCEaKAJuviR+WGe5zFiol/9V1Q6QQrdKU7AOTcDe2LpJ13N9vmMV
68vFagoECwVccg72YEwtChweV12G07G4tQ7TDzTgBMuIWrkrH8MiWGzHbBOowHJR
IlvxZR7/6g4JMX1Eecs+XKX4IjKy7xbc3Cz6Uck3FaAkXHppmbxmNS6pn2NlX9gu
zKl3r26/G++y2jhWp6xX3EiKmTpgUnMwAUdBj0ImMytqAL/FYPF09j2BXXVvicve
SEZuAOLoU8w9QKKZVGO8aPBt6JQg+jsfimftvpk1rYTK7pP0bkHgkKQ4ygXjeFBJ
95xRMg==
-----END CERTIFICATE-----

vault2.pem

Certificate:
    Data:
        Version: 3 (0x2)
        Serial Number:
            eb:03:5f:af:c3:fe:4b:84
    Signature Algorithm: sha256WithRSAEncryption
        Issuer: C=US, CN=ROOT CA
        Validity
            Not Before: Jul  1 14:26:09 2022 GMT
            Not After : Jul  1 14:26:09 2023 GMT
        Subject: C=US, L=Default City, O=Default Company Ltd, CN=VAULT
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
                Public-Key: (2048 bit)
                Modulus:
                    00:a4:df:eb:ba:8f:68:e1:b6:90:aa:8b:cb:12:1b:
                    25:bc:1a:e4:5d:30:1f:39:4c:07:aa:36:78:ce:e5:
                    c6:58:26:c0:f0:47:4d:50:18:34:d4:05:18:3c:14:
                    e6:8a:1a:cc:49:54:29:21:e8:9e:7a:f7:c5:50:30:
                    0a:e0:0b:4e:08:01:d6:f5:f2:fc:41:30:d5:91:84:
                    48:db:1d:31:a5:31:e1:97:d6:c0:08:bf:f0:70:94:
                    a4:d4:97:4c:62:f7:db:aa:46:89:91:fa:a5:7a:d4:
                    4f:b7:0c:cf:de:e5:07:d6:55:f1:04:39:b1:1a:1d:
                    c3:e1:3d:b4:e3:3b:65:40:ef:69:0e:f6:95:ae:40:
                    a7:89:67:6b:75:3a:16:8d:98:25:48:88:f6:1b:78:
                    94:3a:b5:e4:0e:16:3e:fe:ae:9c:0a:68:48:09:a4:
                    4e:94:e6:04:05:7b:31:41:1f:ad:f3:22:7c:35:ed:
                    16:2d:e0:3e:43:e8:6b:7d:b4:30:ad:1d:21:cb:84:
                    92:72:aa:d8:88:f9:a0:e5:5d:db:d5:dd:90:00:f8:
                    e1:1f:c6:3f:d5:2c:dc:bd:c4:7d:4d:4c:71:84:3c:
                    8c:df:7d:a2:f5:69:12:1c:cd:d7:aa:29:25:4e:8f:
                    11:4a:db:2b:c7:65:e9:8e:5a:64:70:5b:a4:53:be:
                    0b:d3
                Exponent: 65537 (0x10001)
        X509v3 extensions:
            X509v3 Authority Key Identifier: 
                0.
            X509v3 Basic Constraints: 
                CA:FALSE
            X509v3 Subject Alternative Name: 
                IP Address:127.0.0.1
    Signature Algorithm: sha256WithRSAEncryption
         32:7d:45:a3:24:c5:a6:9b:11:ec:66:c2:79:a1:33:be:78:4a:
         79:11:7b:9a:59:5c:09:4f:38:b6:08:40:1c:03:ba:84:7d:13:
         68:72:0a:91:9b:58:9d:3b:23:ea:39:65:9d:2c:66:ea:df:49:
         42:b0:9b:75:cd:6f:28:c4:f8:28:71:ea:fe:28:fe:0d:94:92:
         13:1f:ec:34:4c:f2:77:f3:e3:6e:2e:d6:1d:47:1e:41:8a:92:
         aa:03:ed:c1:53:5d:a9:c4:72:74:70:a0:69:98:9d:bb:e6:b2:
         83:cb:bc:0c:b1:af:89:5d:8f:d3:fa:4b:f5:02:f9:8a:06:84:
         e3:c7:fc:fc:2d:63:c8:a0:8a:20:67:62:60:7d:8b:31:ee:1f:
         88:42:a3:b6:8d:38:9f:32:f4:dd:4c:3e:b7:ec:f7:e1:d3:cd:
         1e:ff:a5:68:ae:43:bc:a8:bf:41:b7:b7:5e:ee:84:58:0c:00:
         a9:ea:d4:19:f3:95:23:38:f1:2d:07:46:f8:32:8d:f9:a0:81:
         4d:b8:e7:fe:42:20:d9:cc:3d:1e:3b:31:e4:d9:ea:8b:e0:07:
         bf:25:73:2f:8e:55:69:57:d8:91:ea:de:6e:cd:1d:d4:08:42:
         9d:3e:3b:34:2d:19:a6:e2:95:d6:f4:e5:cf:1c:03:59:60:7a:
         af:ee:f1:9b
-----BEGIN CERTIFICATE-----
MIIDHTCCAgWgAwIBAgIJAOsDX6/D/kuEMA0GCSqGSIb3DQEBCwUAMB8xCzAJBgNV
BAYTAlVTMRAwDgYDVQQDDAdST09UIENBMB4XDTIyMDcwMTE0MjYwOVoXDTIzMDcw
MTE0MjYwOVowUjELMAkGA1UEBhMCVVMxFTATBgNVBAcMDERlZmF1bHQgQ2l0eTEc
MBoGA1UECgwTRGVmYXVsdCBDb21wYW55IEx0ZDEOMAwGA1UEAwwFVkFVTFQwggEi
MA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCk3+u6j2jhtpCqi8sSGyW8GuRd
MB85TAeqNnjO5cZYJsDwR01QGDTUBRg8FOaKGsxJVCkh6J5698VQMArgC04IAdb1
8vxBMNWRhEjbHTGlMeGX1sAIv/BwlKTUl0xi99uqRomR+qV61E+3DM/e5QfWVfEE
ObEaHcPhPbTjO2VA72kO9pWuQKeJZ2t1OhaNmCVIiPYbeJQ6teQOFj7+rpwKaEgJ
pE6U5gQFezFBH63zInw17RYt4D5D6Gt9tDCtHSHLhJJyqtiI+aDlXdvV3ZAA+OEf
xj/VLNy9xH1NTHGEPIzffaL1aRIczdeqKSVOjxFK2yvHZemOWmRwW6RTvgvTAgMB
AAGjKTAnMAkGA1UdIwQCMAAwCQYDVR0TBAIwADAPBgNVHREECDAGhwR/AAABMA0G
CSqGSIb3DQEBCwUAA4IBAQAyfUWjJMWmmxHsZsJ5oTO+eEp5EXuaWVwJTzi2CEAc
A7qEfRNocgqRm1idOyPqOWWdLGbq30lCsJt1zW8oxPgocer+KP4NlJITH+w0TPJ3
8+NuLtYdRx5BipKqA+3BU12pxHJ0cKBpmJ275rKDy7wMsa+JXY/T+kv1AvmKBoTj
x/z8LWPIoIogZ2JgfYsx7h+IQqO2jTifMvTdTD637Pfh080e/6VorkO8qL9Bt7de
7oRYDACp6tQZ85UjOPEtB0b4Mo35oIFNuOf+QiDZzD0eOzHk2eqL4Ae/JXMvjlVp
V9iR6t5uzR3UCEKdPjs0LRmm4pXW9OXPHANZYHqv7vGb
-----END CERTIFICATE-----

@maxb
Copy link
Contributor

maxb commented Jul 2, 2022

Honestly, I've never used go before. So I haven't been able to get this to run just yet.

To make use of the program shown earlier, all you need to do is:

  • Install Go, often packaged as golang, from your OS package manager
  • Save the provided source code to a file
  • Run the provided go run command

That's all - go run handles all of the build and execution in one command.

But I tried replicating the error on my personal VM, using certificates I created with openssl, so that I could share the certificates I was using and for whatever reason it worked.

No, I don't think it did - you're showing us a different unrelated failure.

Please can you show us the first and last lines of the problematic vault-ca.pem ... I have a theory something is wrong with the PEM BEGIN/END framing.

@jnapl1
Copy link
Author

jnapl1 commented Jul 11, 2022

Yes, you're right. Sorry. I was in a rush to get my last post up and didn't pay enough attention to the error message.

My development environment is a little restrictive, so I was limited in the version of go available to me (v1.9.4). Let me know if this is an issue. But considering that vault 1.9.3 (compiled with go v1.17) couldn't parse it, I'd guess it is the same issue.

I receive the following error when running the provided go code.

panic: Invalid PEM block

goroutine 1 [running]:
main.main()
    /path/to/test.go:20 +0x16a
exit status 2

I'm unable to copy/paste, in case there are potential typos. openssl -in vault-ca.pem -text parses the file with no problem if that helps.

First and last line appear as follows.:

-----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----

Let me know if more details are needed.

@cipherboy
Copy link
Contributor

cipherboy commented Jul 12, 2022

Hey @jnapl1,

So this says the PEM file is improperly formatted. You might find RFC 1421 interesting.

It is surprising that OpenSSL accepts it but Go's doesn't.

I wonder if its whitespace? Something like hexdump -C /path/to/failing.pem versus hexdump -C /path/to/working.pem (on your VM) might be useful to find the difference.

@jnapl1
Copy link
Author

jnapl1 commented Jul 25, 2022

Quick update (Sorry I got a little preoccupied).

So far I've been unable to duplicate my error, which is leading me to consider that our certificate provider may be formatting the certificates in a incompatible way. Certificates generated with openssl commands ran locally on the same machine hosting Vault has, so far, worked as expected. Need to perform a few more tests to confirm this though. I'll post what I find out.

@cipherboy
Copy link
Contributor

Out of curiosity, if you have the original cert still, could you take and convert it from PEM->DER->PEM via OpenSSL and get something Go would accept?

Something like:

openssl x509 -in vault-ca.pem -outform DER -out vault-ca.der
openssl x509 -in vault-ca.der -outform PEM -out vault-ca-reencoded.pem

By going to DER (binary contents of the PEM), you can ensure any issues in the outer wrapper are discarded, and that PEM wrapper recreated from scratch by OpenSSL.

@jnapl1
Copy link
Author

jnapl1 commented Jul 25, 2022

Unfortunately, that didn't seem to work.

@cipherboy
Copy link
Contributor

Iiiinteresting, and you definitely see panic: Invalid PEM block when running the Go program on both PEMs?

If you can get permission from your organization, please share it with our support personnel, I'd love to see the CA cert in question to understand the problem better.

@jnapl1
Copy link
Author

jnapl1 commented Jul 26, 2022

Yes, I get the message on both.

And I am not able to provide the certificates.

@jnapl1
Copy link
Author

jnapl1 commented Jul 29, 2022

It looks like the issue may have been caused by subject/authority key identifiers in the v3 extensions being SHA256 hashes. After reissuing the certificate with the values generated with SHA1, it was able to parse the new CA file specified with VAULT_CACERT. Is this expected behavior for Vault and/or Go?

I haven't been able to test the postgresql connection yet, so I can't say for sure I have everything working yet.

@cipherboy
Copy link
Contributor

cipherboy commented Jul 29, 2022

@jnapl1 That's very interesting -- I wouldn't have expected the SKID to result in a panic: Invalid PEM block error. I'm not able to reproduce it either. Here's a certificate chain:

X.509 CA Chain with OpenSSL info
$ openssl x509 -in ~/.local/share/mkcert/rootCA.pem -text
Certificate:
    Data:
        Version: 3 (0x2)
        Serial Number:
            c0:ec:3b:07:69:2e:d3:6c:35:b1:3d:13:c2:7d:d1:e2
        Signature Algorithm: ecdsa-with-SHA256
        Issuer: O = mkcert development CA, OU = cipherboy@xps15.local.cipherboy.com (Alexander Scheel), CN = mkcert cipherboy@xps15.local.cipherboy.com (Alexander Scheel)
        Validity
            Not Before: Jul 29 13:46:28 2022 GMT
            Not After : Jul 29 13:46:28 2032 GMT
        Subject: O = mkcert development CA, OU = cipherboy@xps15.local.cipherboy.com (Alexander Scheel), CN = mkcert cipherboy@xps15.local.cipherboy.com (Alexander Scheel)
        Subject Public Key Info:
            Public Key Algorithm: id-ecPublicKey
                Public-Key: (256 bit)
                pub:
                    04:e0:78:c8:96:5e:77:b6:e6:4d:ef:2b:46:28:9e:
                    0a:26:fd:ae:93:93:a5:cc:8f:20:39:67:58:af:f8:
                    a9:7f:b8:bd:62:d1:a2:f9:2d:eb:2d:78:c6:a8:eb:
                    4c:99:41:90:2c:70:a3:ec:ac:61:56:47:5e:f5:8b:
                    c2:63:70:1d:ab
                ASN1 OID: prime256v1
                NIST CURVE: P-256
        X509v3 extensions:
            X509v3 Key Usage: critical
                Certificate Sign
            X509v3 Basic Constraints: critical
                CA:TRUE, pathlen:0
            X509v3 Subject Key Identifier: 
                DE:9B:10:F5:38:0B:09:D5:A1:36:A7:40:4B:60:1C:C5:13:06:7A:35:AE:1A:9D:CB:72:FD:40:43:71:5D:2C:B0
            X509v3 Authority Key Identifier: 
                DE:9B:10:F5:38:0B:09:D5:A1:36:A7:40:4B:60:1C:C5:13:06:7A:35:AE:1A:9D:CB:72:FD:40:43:71:5D:2C:B0
    Signature Algorithm: ecdsa-with-SHA256
    Signature Value:
        30:44:02:20:0e:54:5a:e2:f4:7c:37:93:f1:ab:01:06:ef:5f:
        07:97:2d:f8:27:83:44:e6:f8:aa:2e:25:95:43:72:e8:19:92:
        02:20:33:69:31:be:64:8c:a8:2f:4e:a6:3b:0d:ce:52:48:c5:
        18:4d:7e:2d:c2:9c:50:b0:0e:1e:91:28:f7:8f:74:6a
-----BEGIN CERTIFICATE-----
MIIC0DCCAnegAwIBAgIRAMDsOwdpLtNsNbE9E8J90eIwCgYIKoZIzj0EAwIwgakx
HjAcBgNVBAoTFW1rY2VydCBkZXZlbG9wbWVudCBDQTE/MD0GA1UECww2Y2lwaGVy
Ym95QHhwczE1LmxvY2FsLmNpcGhlcmJveS5jb20gKEFsZXhhbmRlciBTY2hlZWwp
MUYwRAYDVQQDDD1ta2NlcnQgY2lwaGVyYm95QHhwczE1LmxvY2FsLmNpcGhlcmJv
eS5jb20gKEFsZXhhbmRlciBTY2hlZWwpMB4XDTIyMDcyOTEzNDYyOFoXDTMyMDcy
OTEzNDYyOFowgakxHjAcBgNVBAoTFW1rY2VydCBkZXZlbG9wbWVudCBDQTE/MD0G
A1UECww2Y2lwaGVyYm95QHhwczE1LmxvY2FsLmNpcGhlcmJveS5jb20gKEFsZXhh
bmRlciBTY2hlZWwpMUYwRAYDVQQDDD1ta2NlcnQgY2lwaGVyYm95QHhwczE1Lmxv
Y2FsLmNpcGhlcmJveS5jb20gKEFsZXhhbmRlciBTY2hlZWwpMFkwEwYHKoZIzj0C
AQYIKoZIzj0DAQcDQgAE4HjIll53tuZN7ytGKJ4KJv2uk5OlzI8gOWdYr/ipf7i9
YtGi+S3rLXjGqOtMmUGQLHCj7KxhVkde9YvCY3Adq6N+MHwwDgYDVR0PAQH/BAQD
AgIEMBIGA1UdEwEB/wQIMAYBAf8CAQAwKQYDVR0OBCIEIN6bEPU4CwnVoTanQEtg
HMUTBno1rhqdy3L9QENxXSywMCsGA1UdIwQkMCKAIN6bEPU4CwnVoTanQEtgHMUT
Bno1rhqdy3L9QENxXSywMAoGCCqGSM49BAMCA0cAMEQCIA5UWuL0fDeT8asBBu9f
B5ct+CeDROb4qi4llUNy6BmSAiAzaTG+ZIyoL06mOw3OUkjFGE1+LcKcULAOHpEo
9490ag==
-----END CERTIFICATE-----
$ openssl x509 -in client.pem  -text
Certificate:
    Data:
        Version: 3 (0x2)
        Serial Number:
            5a:15:32:38:79:b9:74:b8:47:b3:ad:c0:3b:5f:04:18
        Signature Algorithm: ecdsa-with-SHA256
        Issuer: O = mkcert development CA, OU = cipherboy@xps15.local.cipherboy.com (Alexander Scheel), CN = mkcert cipherboy@xps15.local.cipherboy.com (Alexander Scheel)
        Validity
            Not Before: Jul 29 13:46:28 2022 GMT
            Not After : Oct 29 13:46:28 2024 GMT
        Subject: O = mkcert development certificate, OU = cipherboy@xps15.local.cipherboy.com (Alexander Scheel)
        Subject Public Key Info:
            Public Key Algorithm: id-ecPublicKey
                Public-Key: (256 bit)
                pub:
                    04:5d:69:8f:a3:e3:76:1b:7c:07:75:38:f1:3b:61:
                    b1:45:11:43:b5:68:ee:9d:43:02:32:8e:b4:d1:f9:
                    ce:f1:fd:ef:35:f6:3b:c2:0f:cf:2c:58:70:7e:e9:
                    ea:fa:17:4b:15:7a:52:7d:7f:92:b6:66:f6:af:d4:
                    df:13:d4:56:57
                ASN1 OID: prime256v1
                NIST CURVE: P-256
        X509v3 extensions:
            X509v3 Key Usage: critical
                Digital Signature, Key Encipherment
            X509v3 Extended Key Usage: 
                TLS Web Client Authentication, TLS Web Server Authentication
            X509v3 Subject Key Identifier: 
                34:B1:6B:CD:B7:34:59:42:1A:B0:68:7D:3E:10:CC:51:CD:19:85:22:A5:A7:D3:BD:02:45:5F:CC:BA:A2:6F:7A
            X509v3 Authority Key Identifier: 
                DE:9B:10:F5:38:0B:09:D5:A1:36:A7:40:4B:60:1C:C5:13:06:7A:35:AE:1A:9D:CB:72:FD:40:43:71:5D:2C:B0
            X509v3 Subject Alternative Name: 
                DNS:vault-agent.example.com
    Signature Algorithm: ecdsa-with-SHA256
    Signature Value:
        30:45:02:21:00:8d:87:f8:e4:53:13:95:c5:91:68:b0:2b:86:
        0c:93:20:e1:71:72:2c:d7:21:ea:dd:8b:fc:d3:2d:6f:d3:dd:
        06:02:20:0c:aa:7a:0a:10:74:24:48:24:42:d9:ea:2f:cb:2c:
        bd:b6:5e:ba:5f:e6:da:89:9e:b8:40:45:ab:e1:02:0e:4f
-----BEGIN CERTIFICATE-----
MIICwTCCAmegAwIBAgIQWhUyOHm5dLhHs63AO18EGDAKBggqhkjOPQQDAjCBqTEe
MBwGA1UEChMVbWtjZXJ0IGRldmVsb3BtZW50IENBMT8wPQYDVQQLDDZjaXBoZXJi
b3lAeHBzMTUubG9jYWwuY2lwaGVyYm95LmNvbSAoQWxleGFuZGVyIFNjaGVlbCkx
RjBEBgNVBAMMPW1rY2VydCBjaXBoZXJib3lAeHBzMTUubG9jYWwuY2lwaGVyYm95
LmNvbSAoQWxleGFuZGVyIFNjaGVlbCkwHhcNMjIwNzI5MTM0NjI4WhcNMjQxMDI5
MTM0NjI4WjBqMScwJQYDVQQKEx5ta2NlcnQgZGV2ZWxvcG1lbnQgY2VydGlmaWNh
dGUxPzA9BgNVBAsMNmNpcGhlcmJveUB4cHMxNS5sb2NhbC5jaXBoZXJib3kuY29t
IChBbGV4YW5kZXIgU2NoZWVsKTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABF1p
j6Pjdht8B3U48TthsUURQ7Vo7p1DAjKOtNH5zvH97zX2O8IPzyxYcH7p6voXSxV6
Un1/krZm9q/U3xPUVlejga4wgaswDgYDVR0PAQH/BAQDAgWgMB0GA1UdJQQWMBQG
CCsGAQUFBwMCBggrBgEFBQcDATApBgNVHQ4EIgQgNLFrzbc0WUIasGh9PhDMUc0Z
hSKlp9O9AkVfzLqib3owKwYDVR0jBCQwIoAg3psQ9TgLCdWhNqdAS2AcxRMGejWu
Gp3Lcv1AQ3FdLLAwIgYDVR0RBBswGYIXdmF1bHQtYWdlbnQuZXhhbXBsZS5jb20w
CgYIKoZIzj0EAwIDSAAwRQIhAI2H+ORTE5XFkWiwK4YMkyDhcXIs1yHq3Yv80y1v
090GAiAMqnoKEHQkSCRC2eovyyy9tl66X+baiZ64QEWr4QIOTw==
-----END CERTIFICATE-----

As you can see, the SKID/AKID on the leaf (and on the root) both have SHA-256 hashes (32-bytes) as their SKIDs.

When run on the program above, I get a valid parse:

Output of `main.go` above
$ ./main ~/.local/share/mkcert/rootCA.pem
Read certificate okay: &{Raw:[48 130 2 208 48 130 2 119 160 3 2 1 2 2 17 0 192 236 59 7 105 46 211 108 53 177 61 19 194 125 209 226 48 10 6 8 42 134 72 206 61 4 3 2 48 129 169 49 30 48 28 6 3 85 4 10 19 21 109 107 99 101 114 116 32 100 101 118 101 108 111 112 109 101 110 116 32 67 65 49 63 48 61 6 3 85 4 11 12 54 99 105 112 104 101 114 98 111 121 64 120 112 115 49 53 46 108 111 99 97 108 46 99 105 112 104 101 114 98 111 121 46 99 111 109 32 40 65 108 101 120 97 110 100 101 114 32 83 99 104 101 101 108 41 49 70 48 68 6 3 85 4 3 12 61 109 107 99 101 114 116 32 99 105 112 104 101 114 98 111 121 64 120 112 115 49 53 46 108 111 99 97 108 46 99 105 112 104 101 114 98 111 121 46 99 111 109 32 40 65 108 101 120 97 110 100 101 114 32 83 99 104 101 101 108 41 48 30 23 13 50 50 48 55 50 57 49 51 52 54 50 56 90 23 13 51 50 48 55 50 57 49 51 52 54 50 56 90 48 129 169 49 30 48 28 6 3 85 4 10 19 21 109 107 99 101 114 116 32 100 101 118 101 108 111 112 109 101 110 116 32 67 65 49 63 48 61 6 3 85 4 11 12 54 99 105 112 104 101 114 98 111 121 64 120 112 115 49 53 46 108 111 99 97 108 46 99 105 112 104 101 114 98 111 121 46 99 111 109 32 40 65 108 101 120 97 110 100 101 114 32 83 99 104 101 101 108 41 49 70 48 68 6 3 85 4 3 12 61 109 107 99 101 114 116 32 99 105 112 104 101 114 98 111 121 64 120 112 115 49 53 46 108 111 99 97 108 46 99 105 112 104 101 114 98 111 121 46 99 111 109 32 40 65 108 101 120 97 110 100 101 114 32 83 99 104 101 101 108 41 48 89 48 19 6 7 42 134 72 206 61 2 1 6 8 42 134 72 206 61 3 1 7 3 66 0 4 224 120 200 150 94 119 182 230 77 239 43 70 40 158 10 38 253 174 147 147 165 204 143 32 57 103 88 175 248 169 127 184 189 98 209 162 249 45 235 45 120 198 168 235 76 153 65 144 44 112 163 236 172 97 86 71 94 245 139 194 99 112 29 171 163 126 48 124 48 14 6 3 85 29 15 1 1 255 4 4 3 2 2 4 48 18 6 3 85 29 19 1 1 255 4 8 48 6 1 1 255 2 1 0 48 41 6 3 85 29 14 4 34 4 32 222 155 16 245 56 11 9 213 161 54 167 64 75 96 28 197 19 6 122 53 174 26 157 203 114 253 64 67 113 93 44 176 48 43 6 3 85 29 35 4 36 48 34 128 32 222 155 16 245 56 11 9 213 161 54 167 64 75 96 28 197 19 6 122 53 174 26 157 203 114 253 64 67 113 93 44 176 48 10 6 8 42 134 72 206 61 4 3 2 3 71 0 48 68 2 32 14 84 90 226 244 124 55 147 241 171 1 6 239 95 7 151 45 248 39 131 68 230 248 170 46 37 149 67 114 232 25 146 2 32 51 105 49 190 100 140 168 47 78 166 59 13 206 82 72 197 24 77 126 45 194 156 80 176 14 30 145 40 247 143 116 106] RawTBSCertificate:[48 130 2 119 160 3 2 1 2 2 17 0 192 236 59 7 105 46 211 108 53 177 61 19 194 125 209 226 48 10 6 8 42 134 72 206 61 4 3 2 48 129 169 49 30 48 28 6 3 85 4 10 19 21 109 107 99 101 114 116 32 100 101 118 101 108 111 112 109 101 110 116 32 67 65 49 63 48 61 6 3 85 4 11 12 54 99 105 112 104 101 114 98 111 121 64 120 112 115 49 53 46 108 111 99 97 108 46 99 105 112 104 101 114 98 111 121 46 99 111 109 32 40 65 108 101 120 97 110 100 101 114 32 83 99 104 101 101 108 41 49 70 48 68 6 3 85 4 3 12 61 109 107 99 101 114 116 32 99 105 112 104 101 114 98 111 121 64 120 112 115 49 53 46 108 111 99 97 108 46 99 105 112 104 101 114 98 111 121 46 99 111 109 32 40 65 108 101 120 97 110 100 101 114 32 83 99 104 101 101 108 41 48 30 23 13 50 50 48 55 50 57 49 51 52 54 50 56 90 23 13 51 50 48 55 50 57 49 51 52 54 50 56 90 48 129 169 49 30 48 28 6 3 85 4 10 19 21 109 107 99 101 114 116 32 100 101 118 101 108 111 112 109 101 110 116 32 67 65 49 63 48 61 6 3 85 4 11 12 54 99 105 112 104 101 114 98 111 121 64 120 112 115 49 53 46 108 111 99 97 108 46 99 105 112 104 101 114 98 111 121 46 99 111 109 32 40 65 108 101 120 97 110 100 101 114 32 83 99 104 101 101 108 41 49 70 48 68 6 3 85 4 3 12 61 109 107 99 101 114 116 32 99 105 112 104 101 114 98 111 121 64 120 112 115 49 53 46 108 111 99 97 108 46 99 105 112 104 101 114 98 111 121 46 99 111 109 32 40 65 108 101 120 97 110 100 101 114 32 83 99 104 101 101 108 41 48 89 48 19 6 7 42 134 72 206 61 2 1 6 8 42 134 72 206 61 3 1 7 3 66 0 4 224 120 200 150 94 119 182 230 77 239 43 70 40 158 10 38 253 174 147 147 165 204 143 32 57 103 88 175 248 169 127 184 189 98 209 162 249 45 235 45 120 198 168 235 76 153 65 144 44 112 163 236 172 97 86 71 94 245 139 194 99 112 29 171 163 126 48 124 48 14 6 3 85 29 15 1 1 255 4 4 3 2 2 4 48 18 6 3 85 29 19 1 1 255 4 8 48 6 1 1 255 2 1 0 48 41 6 3 85 29 14 4 34 4 32 222 155 16 245 56 11 9 213 161 54 167 64 75 96 28 197 19 6 122 53 174 26 157 203 114 253 64 67 113 93 44 176 48 43 6 3 85 29 35 4 36 48 34 128 32 222 155 16 245 56 11 9 213 161 54 167 64 75 96 28 197 19 6 122 53 174 26 157 203 114 253 64 67 113 93 44 176] RawSubjectPublicKeyInfo:[48 89 48 19 6 7 42 134 72 206 61 2 1 6 8 42 134 72 206 61 3 1 7 3 66 0 4 224 120 200 150 94 119 182 230 77 239 43 70 40 158 10 38 253 174 147 147 165 204 143 32 57 103 88 175 248 169 127 184 189 98 209 162 249 45 235 45 120 198 168 235 76 153 65 144 44 112 163 236 172 97 86 71 94 245 139 194 99 112 29 171] RawSubject:[48 129 169 49 30 48 28 6 3 85 4 10 19 21 109 107 99 101 114 116 32 100 101 118 101 108 111 112 109 101 110 116 32 67 65 49 63 48 61 6 3 85 4 11 12 54 99 105 112 104 101 114 98 111 121 64 120 112 115 49 53 46 108 111 99 97 108 46 99 105 112 104 101 114 98 111 121 46 99 111 109 32 40 65 108 101 120 97 110 100 101 114 32 83 99 104 101 101 108 41 49 70 48 68 6 3 85 4 3 12 61 109 107 99 101 114 116 32 99 105 112 104 101 114 98 111 121 64 120 112 115 49 53 46 108 111 99 97 108 46 99 105 112 104 101 114 98 111 121 46 99 111 109 32 40 65 108 101 120 97 110 100 101 114 32 83 99 104 101 101 108 41] RawIssuer:[48 129 169 49 30 48 28 6 3 85 4 10 19 21 109 107 99 101 114 116 32 100 101 118 101 108 111 112 109 101 110 116 32 67 65 49 63 48 61 6 3 85 4 11 12 54 99 105 112 104 101 114 98 111 121 64 120 112 115 49 53 46 108 111 99 97 108 46 99 105 112 104 101 114 98 111 121 46 99 111 109 32 40 65 108 101 120 97 110 100 101 114 32 83 99 104 101 101 108 41 49 70 48 68 6 3 85 4 3 12 61 109 107 99 101 114 116 32 99 105 112 104 101 114 98 111 121 64 120 112 115 49 53 46 108 111 99 97 108 46 99 105 112 104 101 114 98 111 121 46 99 111 109 32 40 65 108 101 120 97 110 100 101 114 32 83 99 104 101 101 108 41] Signature:[48 68 2 32 14 84 90 226 244 124 55 147 241 171 1 6 239 95 7 151 45 248 39 131 68 230 248 170 46 37 149 67 114 232 25 146 2 32 51 105 49 190 100 140 168 47 78 166 59 13 206 82 72 197 24 77 126 45 194 156 80 176 14 30 145 40 247 143 116 106] SignatureAlgorithm:ECDSA-SHA256 PublicKeyAlgorithm:ECDSA PublicKey:0xc00013c6a0 Version:3 SerialNumber:+256438354498634355000658220074030453218 Issuer:CN=mkcert cipherboy@xps15.local.cipherboy.com (Alexander Scheel),OU=cipherboy@xps15.local.cipherboy.com (Alexander Scheel),O=mkcert development CA Subject:CN=mkcert cipherboy@xps15.local.cipherboy.com (Alexander Scheel),OU=cipherboy@xps15.local.cipherboy.com (Alexander Scheel),O=mkcert development CA NotBefore:2022-07-29 13:46:28 +0000 UTC NotAfter:2032-07-29 13:46:28 +0000 UTC KeyUsage:32 Extensions:[{Id:2.5.29.15 Critical:true Value:[3 2 2 4]} {Id:2.5.29.19 Critical:true Value:[48 6 1 1 255 2 1 0]} {Id:2.5.29.14 Critical:false Value:[4 32 222 155 16 245 56 11 9 213 161 54 167 64 75 96 28 197 19 6 122 53 174 26 157 203 114 253 64 67 113 93 44 176]} {Id:2.5.29.35 Critical:false Value:[48 34 128 32 222 155 16 245 56 11 9 213 161 54 167 64 75 96 28 197 19 6 122 53 174 26 157 203 114 253 64 67 113 93 44 176]}] ExtraExtensions:[] UnhandledCriticalExtensions:[] ExtKeyUsage:[] UnknownExtKeyUsage:[] BasicConstraintsValid:true IsCA:true MaxPathLen:0 MaxPathLenZero:true SubjectKeyId:[222 155 16 245 56 11 9 213 161 54 167 64 75 96 28 197 19 6 122 53 174 26 157 203 114 253 64 67 113 93 44 176] AuthorityKeyId:[222 155 16 245 56 11 9 213 161 54 167 64 75 96 28 197 19 6 122 53 174 26 157 203 114 253 64 67 113 93 44 176] OCSPServer:[] IssuingCertificateURL:[] DNSNames:[] EmailAddresses:[] IPAddresses:[] URIs:[] PermittedDNSDomainsCritical:false PermittedDNSDomains:[] ExcludedDNSDomains:[] PermittedIPRanges:[] ExcludedIPRanges:[] PermittedEmailAddresses:[] ExcludedEmailAddresses:[] PermittedURIDomains:[] ExcludedURIDomains:[] CRLDistributionPoints:[] PolicyIdentifiers:[]}
$ ./main /home/cipherboy/GitHub/cipherboy/mkcert/client.pem
Read certificate okay: &{Raw:[48 130 2 193 48 130 2 103 160 3 2 1 2 2 16 90 21 50 56 121 185 116 184 71 179 173 192 59 95 4 24 48 10 6 8 42 134 72 206 61 4 3 2 48 129 169 49 30 48 28 6 3 85 4 10 19 21 109 107 99 101 114 116 32 100 101 118 101 108 111 112 109 101 110 116 32 67 65 49 63 48 61 6 3 85 4 11 12 54 99 105 112 104 101 114 98 111 121 64 120 112 115 49 53 46 108 111 99 97 108 46 99 105 112 104 101 114 98 111 121 46 99 111 109 32 40 65 108 101 120 97 110 100 101 114 32 83 99 104 101 101 108 41 49 70 48 68 6 3 85 4 3 12 61 109 107 99 101 114 116 32 99 105 112 104 101 114 98 111 121 64 120 112 115 49 53 46 108 111 99 97 108 46 99 105 112 104 101 114 98 111 121 46 99 111 109 32 40 65 108 101 120 97 110 100 101 114 32 83 99 104 101 101 108 41 48 30 23 13 50 50 48 55 50 57 49 51 52 54 50 56 90 23 13 50 52 49 48 50 57 49 51 52 54 50 56 90 48 106 49 39 48 37 6 3 85 4 10 19 30 109 107 99 101 114 116 32 100 101 118 101 108 111 112 109 101 110 116 32 99 101 114 116 105 102 105 99 97 116 101 49 63 48 61 6 3 85 4 11 12 54 99 105 112 104 101 114 98 111 121 64 120 112 115 49 53 46 108 111 99 97 108 46 99 105 112 104 101 114 98 111 121 46 99 111 109 32 40 65 108 101 120 97 110 100 101 114 32 83 99 104 101 101 108 41 48 89 48 19 6 7 42 134 72 206 61 2 1 6 8 42 134 72 206 61 3 1 7 3 66 0 4 93 105 143 163 227 118 27 124 7 117 56 241 59 97 177 69 17 67 181 104 238 157 67 2 50 142 180 209 249 206 241 253 239 53 246 59 194 15 207 44 88 112 126 233 234 250 23 75 21 122 82 125 127 146 182 102 246 175 212 223 19 212 86 87 163 129 174 48 129 171 48 14 6 3 85 29 15 1 1 255 4 4 3 2 5 160 48 29 6 3 85 29 37 4 22 48 20 6 8 43 6 1 5 5 7 3 2 6 8 43 6 1 5 5 7 3 1 48 41 6 3 85 29 14 4 34 4 32 52 177 107 205 183 52 89 66 26 176 104 125 62 16 204 81 205 25 133 34 165 167 211 189 2 69 95 204 186 162 111 122 48 43 6 3 85 29 35 4 36 48 34 128 32 222 155 16 245 56 11 9 213 161 54 167 64 75 96 28 197 19 6 122 53 174 26 157 203 114 253 64 67 113 93 44 176 48 34 6 3 85 29 17 4 27 48 25 130 23 118 97 117 108 116 45 97 103 101 110 116 46 101 120 97 109 112 108 101 46 99 111 109 48 10 6 8 42 134 72 206 61 4 3 2 3 72 0 48 69 2 33 0 141 135 248 228 83 19 149 197 145 104 176 43 134 12 147 32 225 113 114 44 215 33 234 221 139 252 211 45 111 211 221 6 2 32 12 170 122 10 16 116 36 72 36 66 217 234 47 203 44 189 182 94 186 95 230 218 137 158 184 64 69 171 225 2 14 79] RawTBSCertificate:[48 130 2 103 160 3 2 1 2 2 16 90 21 50 56 121 185 116 184 71 179 173 192 59 95 4 24 48 10 6 8 42 134 72 206 61 4 3 2 48 129 169 49 30 48 28 6 3 85 4 10 19 21 109 107 99 101 114 116 32 100 101 118 101 108 111 112 109 101 110 116 32 67 65 49 63 48 61 6 3 85 4 11 12 54 99 105 112 104 101 114 98 111 121 64 120 112 115 49 53 46 108 111 99 97 108 46 99 105 112 104 101 114 98 111 121 46 99 111 109 32 40 65 108 101 120 97 110 100 101 114 32 83 99 104 101 101 108 41 49 70 48 68 6 3 85 4 3 12 61 109 107 99 101 114 116 32 99 105 112 104 101 114 98 111 121 64 120 112 115 49 53 46 108 111 99 97 108 46 99 105 112 104 101 114 98 111 121 46 99 111 109 32 40 65 108 101 120 97 110 100 101 114 32 83 99 104 101 101 108 41 48 30 23 13 50 50 48 55 50 57 49 51 52 54 50 56 90 23 13 50 52 49 48 50 57 49 51 52 54 50 56 90 48 106 49 39 48 37 6 3 85 4 10 19 30 109 107 99 101 114 116 32 100 101 118 101 108 111 112 109 101 110 116 32 99 101 114 116 105 102 105 99 97 116 101 49 63 48 61 6 3 85 4 11 12 54 99 105 112 104 101 114 98 111 121 64 120 112 115 49 53 46 108 111 99 97 108 46 99 105 112 104 101 114 98 111 121 46 99 111 109 32 40 65 108 101 120 97 110 100 101 114 32 83 99 104 101 101 108 41 48 89 48 19 6 7 42 134 72 206 61 2 1 6 8 42 134 72 206 61 3 1 7 3 66 0 4 93 105 143 163 227 118 27 124 7 117 56 241 59 97 177 69 17 67 181 104 238 157 67 2 50 142 180 209 249 206 241 253 239 53 246 59 194 15 207 44 88 112 126 233 234 250 23 75 21 122 82 125 127 146 182 102 246 175 212 223 19 212 86 87 163 129 174 48 129 171 48 14 6 3 85 29 15 1 1 255 4 4 3 2 5 160 48 29 6 3 85 29 37 4 22 48 20 6 8 43 6 1 5 5 7 3 2 6 8 43 6 1 5 5 7 3 1 48 41 6 3 85 29 14 4 34 4 32 52 177 107 205 183 52 89 66 26 176 104 125 62 16 204 81 205 25 133 34 165 167 211 189 2 69 95 204 186 162 111 122 48 43 6 3 85 29 35 4 36 48 34 128 32 222 155 16 245 56 11 9 213 161 54 167 64 75 96 28 197 19 6 122 53 174 26 157 203 114 253 64 67 113 93 44 176 48 34 6 3 85 29 17 4 27 48 25 130 23 118 97 117 108 116 45 97 103 101 110 116 46 101 120 97 109 112 108 101 46 99 111 109] RawSubjectPublicKeyInfo:[48 89 48 19 6 7 42 134 72 206 61 2 1 6 8 42 134 72 206 61 3 1 7 3 66 0 4 93 105 143 163 227 118 27 124 7 117 56 241 59 97 177 69 17 67 181 104 238 157 67 2 50 142 180 209 249 206 241 253 239 53 246 59 194 15 207 44 88 112 126 233 234 250 23 75 21 122 82 125 127 146 182 102 246 175 212 223 19 212 86 87] RawSubject:[48 106 49 39 48 37 6 3 85 4 10 19 30 109 107 99 101 114 116 32 100 101 118 101 108 111 112 109 101 110 116 32 99 101 114 116 105 102 105 99 97 116 101 49 63 48 61 6 3 85 4 11 12 54 99 105 112 104 101 114 98 111 121 64 120 112 115 49 53 46 108 111 99 97 108 46 99 105 112 104 101 114 98 111 121 46 99 111 109 32 40 65 108 101 120 97 110 100 101 114 32 83 99 104 101 101 108 41] RawIssuer:[48 129 169 49 30 48 28 6 3 85 4 10 19 21 109 107 99 101 114 116 32 100 101 118 101 108 111 112 109 101 110 116 32 67 65 49 63 48 61 6 3 85 4 11 12 54 99 105 112 104 101 114 98 111 121 64 120 112 115 49 53 46 108 111 99 97 108 46 99 105 112 104 101 114 98 111 121 46 99 111 109 32 40 65 108 101 120 97 110 100 101 114 32 83 99 104 101 101 108 41 49 70 48 68 6 3 85 4 3 12 61 109 107 99 101 114 116 32 99 105 112 104 101 114 98 111 121 64 120 112 115 49 53 46 108 111 99 97 108 46 99 105 112 104 101 114 98 111 121 46 99 111 109 32 40 65 108 101 120 97 110 100 101 114 32 83 99 104 101 101 108 41] Signature:[48 69 2 33 0 141 135 248 228 83 19 149 197 145 104 176 43 134 12 147 32 225 113 114 44 215 33 234 221 139 252 211 45 111 211 221 6 2 32 12 170 122 10 16 116 36 72 36 66 217 234 47 203 44 189 182 94 186 95 230 218 137 158 184 64 69 171 225 2 14 79] SignatureAlgorithm:ECDSA-SHA256 PublicKeyAlgorithm:ECDSA PublicKey:0xc0000126e0 Version:3 SerialNumber:+119740576449600831982756924842257089560 Issuer:CN=mkcert cipherboy@xps15.local.cipherboy.com (Alexander Scheel),OU=cipherboy@xps15.local.cipherboy.com (Alexander Scheel),O=mkcert development CA Subject:OU=cipherboy@xps15.local.cipherboy.com (Alexander Scheel),O=mkcert development certificate NotBefore:2022-07-29 13:46:28 +0000 UTC NotAfter:2024-10-29 13:46:28 +0000 UTC KeyUsage:5 Extensions:[{Id:2.5.29.15 Critical:true Value:[3 2 5 160]} {Id:2.5.29.37 Critical:false Value:[48 20 6 8 43 6 1 5 5 7 3 2 6 8 43 6 1 5 5 7 3 1]} {Id:2.5.29.14 Critical:false Value:[4 32 52 177 107 205 183 52 89 66 26 176 104 125 62 16 204 81 205 25 133 34 165 167 211 189 2 69 95 204 186 162 111 122]} {Id:2.5.29.35 Critical:false Value:[48 34 128 32 222 155 16 245 56 11 9 213 161 54 167 64 75 96 28 197 19 6 122 53 174 26 157 203 114 253 64 67 113 93 44 176]} {Id:2.5.29.17 Critical:false Value:[48 25 130 23 118 97 117 108 116 45 97 103 101 110 116 46 101 120 97 109 112 108 101 46 99 111 109]}] ExtraExtensions:[] UnhandledCriticalExtensions:[] ExtKeyUsage:[2 1] UnknownExtKeyUsage:[] BasicConstraintsValid:false IsCA:false MaxPathLen:0 MaxPathLenZero:false SubjectKeyId:[52 177 107 205 183 52 89 66 26 176 104 125 62 16 204 81 205 25 133 34 165 167 211 189 2 69 95 204 186 162 111 122] AuthorityKeyId:[222 155 16 245 56 11 9 213 161 54 167 64 75 96 28 197 19 6 122 53 174 26 157 203 114 253 64 67 113 93 44 176] OCSPServer:[] IssuingCertificateURL:[] DNSNames:[vault-agent.example.com] EmailAddresses:[] IPAddresses:[] URIs:[] PermittedDNSDomainsCritical:false PermittedDNSDomains:[] ExcludedDNSDomains:[] PermittedIPRanges:[] ExcludedIPRanges:[] PermittedEmailAddresses:[] ExcludedEmailAddresses:[] PermittedURIDomains:[] ExcludedURIDomains:[] CRLDistributionPoints:[] PolicyIdentifiers:[]}

Indeed, if I go even farther and hex-encode the SKID before passing it as the SKID (creating a 64-byte SKID) -- and then repeat it three times (for a total length of 192 bytes!), it still parses fine in Go:

~snip~
            X509v3 Subject Key Identifier: 
                31:37:61:38:34:30:32:30:31:62:37:63:36:64:35:30:35:34:62:33:30:62:35:30:63:62:32:65:32:62:61:37:37:37:35:66:30:34:32:33:39:39:64:36:63:63:63:30:38:61:64:64:63:61:62:63:63:39:61:64:66:66:66:35:31:37:61:38:34:30:32:30:31:62:37:63:36:64:35:30:35:34:62:33:30:62:35:30:63:62:32:65:32:62:61:37:37:37:35:66:30:34:32:33:39:39:64:36:63:63:63:30:38:61:64:64:63:61:62:63:63:39:61:64:66:66:66:35:31:37:61:38:34:30:32:30:31:62:37:63:36:64:35:30:35:34:62:33:30:62:35:30:63:62:32:65:32:62:61:37:37:37:35:66:30:34:32:33:39:39:64:36:63:63:63:30:38:61:64:64:63:61:62:63:63:39:61:64:66:66:66:35
            X509v3 Authority Key Identifier: 
                31:37:61:38:34:30:32:30:31:62:37:63:36:64:35:30:35:34:62:33:30:62:35:30:63:62:32:65:32:62:61:37:37:37:35:66:30:34:32:33:39:39:64:36:63:63:63:30:38:61:64:64:63:61:62:63:63:39:61:64:66:66:66:35:31:37:61:38:34:30:32:30:31:62:37:63:36:64:35:30:35:34:62:33:30:62:35:30:63:62:32:65:32:62:61:37:37:37:35:66:30:34:32:33:39:39:64:36:63:63:63:30:38:61:64:64:63:61:62:63:63:39:61:64:66:66:66:35:31:37:61:38:34:30:32:30:31:62:37:63:36:64:35:30:35:34:62:33:30:62:35:30:63:62:32:65:32:62:61:37:37:37:35:66:30:34:32:33:39:39:64:36:63:63:63:30:38:61:64:64:63:61:62:63:63:39:61:64:66:66:66:35

~snip~

...

$  ./main /home/cipherboy/GitHub/cipherboy/mkcert/client.pem
Read certificate okay: &{ ... snip ... }

So again... without the root CA public certificate (which will not include private keys necessary to create certs -- and which can be securely sent to our Support team)... I'm unable to reproduce this on the basis of it being a AKID/SKID encoding problem.

Perhaps more fruitfully, could you try loading the vault binary in gdb or dlv and seeing if you could attach a call graph of where the parsing fails on this certificate?

@jnapl1
Copy link
Author

jnapl1 commented Aug 2, 2022

My bad. I had mistyped the given example. The PEM blocks are valid.

Returned error:

panic: x509: invalid basic constraints b

goroutine 1 [running]:
main.main()
    /path/to/test.go:24 +0xd2
exit status 2

Not sure why this is the case, since the basic constraints on these certificates are the same as those with a SHA1 SKID, which are read successfully.

Basic Constraints:

X509v3 Basic Constraints: critical
    CA: TRUE

@cipherboy
Copy link
Contributor

This keeps getting more interesting... :-) Can you share just the ASN.1 of that constraint?

If you run something like this:

OpenSSL command to parse ASN1 structure
$ openssl asn1parse -in ea-root.pem 
    0:d=0  hl=4 l= 796 cons: SEQUENCE          
    4:d=1  hl=4 l= 516 cons: SEQUENCE          
    8:d=2  hl=2 l=   3 cons: cont [ 0 ]        
   10:d=3  hl=2 l=   1 prim: INTEGER           :02
   13:d=2  hl=2 l=  20 prim: INTEGER           :1D6A04FF56F69DDBBDC9405191B0DCDF779BD213
   35:d=2  hl=2 l=  13 cons: SEQUENCE          
   37:d=3  hl=2 l=   9 prim: OBJECT            :sha256WithRSAEncryption
   48:d=3  hl=2 l=   0 prim: NULL              
   50:d=2  hl=2 l=  20 cons: SEQUENCE          
   52:d=3  hl=2 l=  18 cons: SET               
   54:d=4  hl=2 l=  16 cons: SEQUENCE          
   56:d=5  hl=2 l=   3 prim: OBJECT            :commonName
   61:d=5  hl=2 l=   9 prim: PRINTABLESTRING   :ea - root
   72:d=2  hl=2 l=  30 cons: SEQUENCE          
   74:d=3  hl=2 l=  13 prim: UTCTIME           :220802162732Z
   89:d=3  hl=2 l=  13 prim: UTCTIME           :220903162802Z
  104:d=2  hl=2 l=  20 cons: SEQUENCE          
  106:d=3  hl=2 l=  18 cons: SET               
  108:d=4  hl=2 l=  16 cons: SEQUENCE          
  110:d=5  hl=2 l=   3 prim: OBJECT            :commonName
  115:d=5  hl=2 l=   9 prim: PRINTABLESTRING   :ea - root
  126:d=2  hl=4 l= 290 cons: SEQUENCE          
  130:d=3  hl=2 l=  13 cons: SEQUENCE          
  132:d=4  hl=2 l=   9 prim: OBJECT            :rsaEncryption
  143:d=4  hl=2 l=   0 prim: NULL              
  145:d=3  hl=4 l= 271 prim: BIT STRING        
  420:d=2  hl=2 l= 102 cons: cont [ 3 ]        
  422:d=3  hl=2 l= 100 cons: SEQUENCE          
  424:d=4  hl=2 l=  14 cons: SEQUENCE          
  426:d=5  hl=2 l=   3 prim: OBJECT            :X509v3 Key Usage
  431:d=5  hl=2 l=   1 prim: BOOLEAN           :255
  434:d=5  hl=2 l=   4 prim: OCTET STRING      [HEX DUMP]:03020106
  440:d=4  hl=2 l=  18 cons: SEQUENCE          
  442:d=5  hl=2 l=   3 prim: OBJECT            :X509v3 Basic Constraints
  447:d=5  hl=2 l=   1 prim: BOOLEAN           :255
  450:d=5  hl=2 l=   8 prim: OCTET STRING      [HEX DUMP]:30060101FF020102
  460:d=4  hl=2 l=  29 cons: SEQUENCE          
  462:d=5  hl=2 l=   3 prim: OBJECT            :X509v3 Subject Key Identifier
  467:d=5  hl=2 l=  22 prim: OCTET STRING      [HEX DUMP]:041444EF158F0926D9FA1F630FCD4C62F6DE53685853
  491:d=4  hl=2 l=  31 cons: SEQUENCE          
  493:d=5  hl=2 l=   3 prim: OBJECT            :X509v3 Authority Key Identifier
  498:d=5  hl=2 l=  24 prim: OCTET STRING      [HEX DUMP]:3016801444EF158F0926D9FA1F630FCD4C62F6DE53685853
  524:d=1  hl=2 l=  13 cons: SEQUENCE          
  526:d=2  hl=2 l=   9 prim: OBJECT            :sha256WithRSAEncryption
  537:d=2  hl=2 l=   0 prim: NULL              
  539:d=1  hl=4 l= 257 prim: BIT STRING        

The first column lists byte offsets in the ASN.1 contents; d is the depth, hl is the header length and l= is the content's length.

If you go up one depth (X509v3 Basic Constraints is an object at d=5 / offset=442), to the corresponding SEQUENCE (d=4 / offset=440), can you grab that snippet of the cert (make sure to add hl and l together for a total of 20 bytes in my example) and share it?

For me, that looks like:

Command to extract snippet
$ openssl x509 -in ea-root.pem  -outform DER | dd bs=1 skip=440 count=20 | xxd -p
30120603551d130101ff040830060101ff020102
20+0 records in
20+0 records out
20 bytes copied, 0.017041 s, 1.2 kB/s

You can verify this with:

[cipherboy@xps15 159]$ openssl x509 -in ea-root.pem  -outform DER | dd bs=1 skip=440 count=20 | openssl asn1parse -inform DER
20+0 records in
20+0 records out
    0:d=0  hl=2 l=  18 cons: SEQUENCE          
20 bytes copied, 0.0173411 s, 1.2 kB/s
    2:d=1  hl=2 l=   3 prim: OBJECT            :X509v3 Basic Constraints
    7:d=1  hl=2 l=   1 prim: BOOLEAN           :255
   10:d=1  hl=2 l=   8 prim: OCTET STRING      [HEX DUMP]:30060101FF020102

The hex is important so I can reconstruct just that portion of the certificate. ASN.1 parse is a touch more useful than the openssl x509 -text form. But I'm worried I might not understand the contents of just the openssl asn1parse if they don't make sense (I generally prefer asn1js's output).


Here's the error in the Go code:

https://github.com/golang/go/blob/cd6e0d7cad147b686f9f8066b651b0079e6f51c6/src/crypto/x509/parser.go#L347-L366

func parseBasicConstraintsExtension(der cryptobyte.String) (bool, int, error) {
	var isCA bool
	if !der.ReadASN1(&der, cryptobyte_asn1.SEQUENCE) {
		return false, 0, errors.New("x509: invalid basic constraints a")
	}
	if der.PeekASN1Tag(cryptobyte_asn1.BOOLEAN) {
		if !der.ReadASN1Boolean(&isCA) {
			return false, 0, errors.New("x509: invalid basic constraints b") // <<<< YOUR ERROR HERE
		}
	}
	maxPathLen := -1
	if !der.Empty() && der.PeekASN1Tag(cryptobyte_asn1.INTEGER) {
		if !der.ReadASN1Integer(&maxPathLen) {
			return false, 0, errors.New("x509: invalid basic constraints c")
		}
	}

	// TODO: map out.MaxPathLen to 0 if it has the -1 default value? (Issue 19285)
	return isCA, maxPathLen, nil
}

Per RFC 5280 / Section 4.2.1.9 on Basic Constraints:


   id-ce-basicConstraints OBJECT IDENTIFIER ::=  { id-ce 19 }

   BasicConstraints ::= SEQUENCE {
        cA                      BOOLEAN DEFAULT FALSE,
        pathLenConstraint       INTEGER (0..MAX) OPTIONAL }

What's happening is, for some reason, your certificate's ASN.1 is causing Go to fail to parse that isCA boolean constraint; it could be there's spurious data ahead of that boolean (unlikely, I would've expected OpenSSL to complain) or that boolean is encoded incorrectly (perhaps a different value for true than 0xff / 255?).

See the implementation of ReadASN1Boolean for reference:

https://github.com/golang/go/blob/cd6e0d7cad147b686f9f8066b651b0079e6f51c6/src/vendor/golang.org/x/crypto/cryptobyte/asn1.go#L246-L265

// ReadASN1Boolean decodes an ASN.1 BOOLEAN and converts it to a boolean
// representation into out and advances. It reports whether the read
// was successful.
func (s *String) ReadASN1Boolean(out *bool) bool {
	var bytes String
	if !s.ReadASN1(&bytes, asn1.BOOLEAN) || len(bytes) != 1 {
		return false
	}

	switch bytes[0] {
	case 0:
		*out = false
	case 0xff:
		*out = true
	default:
		return false
	}

	return true
}

There's a Go issue that might be related: golang/go#11091 -- it likely is the same underlying issue and Go declined to fix it.

In particular, DER does indeed require 0xff be used for the boolean value true, so I'm inclined to agree with them.

Regardless, the hex should tell us.

@jnapl1
Copy link
Author

jnapl1 commented Aug 2, 2022

This is the certificate that fails (vault-ca.pem):

577:d=4    hl=2 l=   15  cons: SEQUENCE
579:d=5    hl=2 l=    3  prim: OBJECT          :X509v3 Basic Constraints
584:d=5    hl=2 l=    1  prim: BOOLEAN         :255
587:d=5    hl=2 l=    5  prim: OCTET STRING    [HEX DUMP]:3003010101

Go parses this correctly (created with the SHA1 SKID):

566:d=4    hl=2 l=   15  cons: SEQUENCE
568:d=5    hl=2 l=    3  prim: OBJECT          :X509v3 Basic Constraints
573:d=5    hl=2 l=    1  prim: BOOLEAN         :255
576:d=5    hl=2 l=    5  prim: OCTET STRING    [HEX DUMP]:30030101FF

If I understand correctly, the issue you're referring to is with end of the hex dump.

I have no idea why the hex value would change with the SKID hash method (maybe just some dumb luck). Will need to look into that more. But at least I have a better idea what I'm looking for. Unless you have more to add, I think this issue can be closed.

Thanks.

@cipherboy
Copy link
Contributor

Yep, the earlier Go issue I linked is correct and is the root cause of this behavior.

You've got a boolean with value 0x01 which is fine according to BER / Basic Encoding Rules, but not fine according to DER / Distinguished Encoding Rules. (See explanation of differences). It is not spec-compliant behavior to use it with TLS or PKIX. This certificate is non-conforming and results in issues like this one, depending on strictness of the correlated implementation.

Running this certificate through a linting tool such as zlint should highlight the issue as well.

This isn't resolvable on our end and Go has closed the corresponding issue as WONTFIX.

While not ideal, I do strongly suggest reissuing the certificate to correctly conform to the standards.

As such, I'm closing this ticket as the issue is in our dependency, Go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auth/cert Authentication - certificates core/cli storage/postgresql
Projects
None yet
Development

No branches or pull requests

4 participants