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

[panic: runtime error: invalid memory address or nil pointer dereference ]Throw errors gracefully when the certificate can't be found based on the name of key #500

Open
CLIN42 opened this issue Jun 28, 2022 · 0 comments

Comments

@CLIN42
Copy link

CLIN42 commented Jun 28, 2022

issue statement

when supplying key can and crt pair at \etc\mqm\pki\keys, if the name of the crt and key doesn't match, below errors will be thrown while the container is being started

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x66c824]
goroutine 1 [running]:
github.com/ibm-messaging/mq-container/vendor/software.sslmate.com/src/go-pkcs12.Encode(0xa51000, 0xc00009c210, 0x971740, 0xc000180c40, 0x0, 0xc00002e880, 0x5, 0x8, 0xc0002200e0, 0xc, ...)
	/opt/app-root/src/go/src/github.com/ibm-messaging/mq-container/vendor/software.sslmate.com/src/go-pkcs12/pkcs12.go:467 +0xe4
github.com/ibm-messaging/mq-container/internal/tls.processKeys(0xc00016d700, 0x9c1fa5, 0x15, 0x9bfcff, 0x11, 0xc, 0x0, 0x0, 0x0)
	/opt/app-root/src/go/src/github.com/ibm-messaging/mq-container/internal/tls/tls.go:234 +0x453
github.com/ibm-messaging/mq-container/internal/tls.configureTLSKeystores(0x9c1fa5, 0x15, 0x9bfcff, 0x11, 0x9c0595, 0x12, 0x1, 0x40, 0x30, 0x0, ...)
	/opt/app-root/src/go/src/github.com/ibm-messaging/mq-container/internal/tls/tls.go:88 +0x165
github.com/ibm-messaging/mq-container/internal/tls.ConfigureDefaultTLSKeystores(0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
	/opt/app-root/src/go/src/github.com/ibm-messaging/mq-container/internal/tls/tls.go:104 +0xfb
main.doMain(0x0, 0x0)
	/opt/app-root/src/go/src/github.com/ibm-messaging/mq-container/cmd/runmqserver/main.go:147 +0xc18
main.main()
	/opt/app-root/src/go/src/github.com/ibm-messaging/mq-container/cmd/runmqserver/main.go:300 +0x25

environment

version: 9.2.4
platform: Azure Kubernetes service

steps to produce

  1. create a certificate and key pair, mq1.key and mq1-cer.crt
  2. mount them to \etc\mqm\pki\keys as either ConfigMap or secret in the pod spec
  3. start the pod

Analysis

  1. method vendor/software.sslmate.com/src/go-pkcs12.Encode takes in public certificate as parameter
  2. public certificate is generated by method internal\tls\tls.go:365. the method takes in keyPrefix as parameter and uses it to find the corresponding certificate internal\tls\tls.go:372
  3. keyPrefix is returned by method processPrivateKey at internal\tls\tls.go:330. its value is the name of key without extension at internal\tls\tls.go:357
    e.g. if the key name is mq.key, it will look for certificate mq.crt.
  4. before create a new PKCS#12 Keystore, there is no check if the public certificate is null or not
// Process certificates (*.crt) - public certificate & optional CA certificate
			publicCertificate, caCertificate, err := processCertificates(keyDir, keySet.Name(), keyPrefix, keys, &tlsStore.Keystore, &tlsStore.Truststore)
			if err != nil {
				return "", err
			}

			// Create a new PKCS#12 Keystore - containing private key, public certificate & optional CA certificate
			file, err := pkcs.Encode(rand.Reader, privateKey, publicCertificate, caCertificate, tlsStore.Keystore.Password)
			if err != nil {
				return "", fmt.Errorf("Failed to encode PKCS#12 Keystore %s: %v", keySet.Name()+".p12", err)
			}

Proposal

  1. check if public and ca certificate is null before create keystore
  2. throw gracefully when it is null.
@CLIN42 CLIN42 changed the title Throw errors gracefully when the certificate can't be found based on the name of key [panic: runtime error: invalid memory address or nil pointer dereference ]Throw errors gracefully when the certificate can't be found based on the name of key Jun 28, 2022
JEFFLUFC added a commit that referenced this issue Aug 25, 2023
Update UBI and Go version (v9.3.0.x)
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

1 participant