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

can't start server with an SSL certchain #568

Open
ciklysta opened this issue Jul 3, 2024 · 3 comments
Open

can't start server with an SSL certchain #568

ciklysta opened this issue Jul 3, 2024 · 3 comments

Comments

@ciklysta
Copy link

ciklysta commented Jul 3, 2024

I have a certification authority. Its cert is in cacert.pem. That CA signed both my server cert and a client cert.

Imagine I store a server key in server.pem and a server cert in server.key.

I want to run IBM MQ server. So I created a structure according to the documentation. I renamed

  • server.pem to pki/keys/server/tls.crt
  • server.key to pki/keys/server/tls.key
  • cacert.pem to pki/trust/0/tls.crt

When I try to start the server (with pki dir mounted -v ./pki:/etc/mqm/pki) I get an error

Failed to add certificates to CMS keystore: error running "/opt/mqm/bin/runmqakm -cert -add": /opt/mqm/bin/runmqakm: exit status 26 CTGSK3046W The key file "/tmp/cmsTrust.pem" could not be imported.

Am I doing something wrong or is this a bug?

After some investigation, I found out that the following runmqakm commands are run from the go code (in that order):

runmqakm -keydb -create  -type cms -db /run/runmqserver/tls/key.kdb -pw cQZFzsfl95yk -stash
runmqakm -keydb -create  -type p12 -db /run/runmqserver/tls/trust.p12 -pw cQZFzsfl95yk -stash
runmqakm -cert -import  -file /run/runmqserver/tls/hotscan.p12 -pw cQZFzsfl95yk -target /run/runmqserver/tls/key.kdb -target_pw cQZFzsfl95yk -target_type cms
runmqakm -cert -list  -type cms -db /run/runmqserver/tls/key.kdb -pw cQZFzsfl95yk
runmqakm -cert -add  -db /run/runmqserver/tls/trust.p12 -type p12 -pw cQZFzsfl95yk -file /tmp/trust.pem
runmqakm -cert -list  -type p12 -db /run/runmqserver/tls/trust.p12 -pw cQZFzsfl95yk
runmqakm -cert -add  -db /run/runmqserver/tls/key.kdb -type cms -pw cQZFzsfl95yk -file /tmp/cmsTrust.pem

The last one fails with the error message.

Further observations:

  • If I provide an independet CA (not the one that issued the server cert), the server starts correctly.
  • If I don't provide cacert.pem aka pki/trust/0/tls.crt the server starts, but it doesnt talk TLS.
@arthurbarr
Copy link
Member

The runmqserver command creates the cmsTrust.pem file dynamically. I suspect that either:

  1. The PEM file does not contain the full trust chain for the certificate. MQ needs the entire trust chain to be available, in order to validate properly, and won't import a partial chain.
  2. The PEM file is not in a recognized format. It should be able to handle a standard X.509 cert, but it could be there's something unusual about that certificate.

@ciklysta
Copy link
Author

ciklysta commented Jul 5, 2024

Here are my pem files:

pki/trust/0/tls.crt (the CA cert):

-----BEGIN CERTIFICATE-----
MIIDXDCCAkSgAwIBAgIBATANBgkqhkiG9w0BAQsFADBHMRYwFAYDVQQDDA1NeSBj
b21wYW55IENBMQ8wDQYDVQQKDAZNeUNvbXAxDzANBgNVBAcMBlByYWd1ZTELMAkG
A1UEBhMCQ1owHhcNMjQwNzA1MTIwODI2WhcNMzQwNzAzMTIwODI2WjBHMRYwFAYD
VQQDDA1NeSBjb21wYW55IENBMQ8wDQYDVQQKDAZNeUNvbXAxDzANBgNVBAcMBlBy
YWd1ZTELMAkGA1UEBhMCQ1owggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIB
AQC0F0O/rPBxMNRUNF7xcV69GWZa2q+TXFvREhBgEhZpIjPBpeFjrJgvUyBzZIol
KhzYPkpVfdAxB9lgpO9bEVCrxhKBJkw9FSDbXAak0aw4M0gHZP4Qyq5MF7wLERh0
qsU3jgW1CcjfieizT2C50NAx8j3VjPfVsoQ8N+0NHr2+mTDoZCc7xv/3rX0Bcngt
4Krc1sRHHTYntXVBuzY6o765ANTDjE47ocG/7cfRQmDnOLIyuoi8PO/c15OM/waa
rOqJ3hpsW0dgbeAGXbZbCpgMVgsLqtPGNT2MEHvhWjD2YJYFZ8+25Ic7jEF3K0OF
FrHpcahxxPErEpDTmJtPpPCpAgMBAAGjUzBRMB0GA1UdDgQWBBRrV+ARLzgvJ6ZN
uIUkfkmFzEvnqjAfBgNVH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pTcJCN7lRgCA07FG6mh6ZQaAI/ApmkCi1zSa
o6UhOQHK4F1ezkw4489VG4ZTIZQLBqFD9Tl+QjS01SOh6wvWZb1IdbcFqeMUm4Gi
0q8zMfAuZsNYHTDC0Yj0qnxNAgMBAAGjbzBtMAkGA1UdEwQCMAAwCwYDVR0PBAQD
AgXgMBMGA1UdJQQMMAoGCCsGAQUFBwMBMB0GA1UdDgQWBBTiOsz2eiC82bVrunoa
L7kEap6z/jAfBgNVHSMEGDAWgBRrV+ARLzgvJ6ZNuIUkfkmFzEvnqjANBgkqhkiG
9w0BAQsFAAOCAQEArBIv610R1o3oCziDG/RYFUQBNaOetPJTAsKGSg+a7/wH/xHY
XVnVMgNszsEFpGOXTEdO9YPxr0s7ZGA4+8q12YP5v1FdYvlng8nCZa6e0Hz/EDyk
VQRSLtfQehEQVpkudwv/Of50Lq/PhCXr4y/KCn24tVykqDfsaysB+KC/W1vYQxGZ
JFq2B5vgchbM8FqVx7fNNBwoWGRgaT8O4caJ3AXTNjcok99EReuShS8XMPuWT12d
b0rlBDEBVp2QoxCKPTbjdXZvRKNPX061PU8KevP/ZWwonCNrTaZgoDRRQHXla9Zn
rfgRK4pa44mP3vRseG28g/OI/fuJHXJUk6zq+g==
-----END CERTIFICATE-----

pki/keys/mycomp/tls.key (this is generated for testing purposes, no problem in publishing):

-----BEGIN PRIVATE KEY-----
MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCQI8GLPHNrgWbR
vElbbXM33PZ8h5FJb3BFfIYG6UlFyvOM11O47w6yCMf7AWVDZmSvnwyvMQmKlTTF
E9gjJWAgOsMp9CZjbtVT0mbYOeOWgXaNKhxTeJPk9e3eNyt2S6y+Jb4GWAVvcD49
FzU9Z8yy0nxEKbSpBqNSLPkzbCYyuhGuuWAx9b83L5880rzsEd7KasATm0Q1QdI4
yRdaub9lEgo/pTcJCN7lRgCA07FG6mh6ZQaAI/ApmkCi1zSao6UhOQHK4F1ezkw4
489VG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hWXyIgudOWERC3hLeo6JZrXhMcFzh
X+4o95tF7LRUvby4mh/K7SOaxvo2RYaR6sUA6rcCgYAhaeXtgnr8GY7Vi3PZKj2M
Sj21CFVGYB5tBYvh6pCG+DzKI9VbGx4O+FHUHfRpGAY7JIKZ9BFc/jgoNCjao/39
5sY56oI0VGGjg8/Uu2a/1iTQD3HwrTmyEKULT/ZaXO12DMOrIP80EQF0poUktCxX
mLSc7lYEB4+E/2eahOzYhQ==
-----END PRIVATE KEY-----

and both tempfiles (/tmp/trust.pem and /tmp/cmsTrust.pem) contain only what's in pki/trust/0/tls.crt. From what you write, I understand that the go script should join both certs to a certchain. That is not the case.

@arthurbarr
Copy link
Member

You need to have the full trust chain in each place. i.e. the CA cert needs to be in the pki/keys/mycomp/ directory. When that gets imported, the CA will become trusted. The trust directories are for trusted CAs which you don't have a private key for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants