{"record":{"id":"f97e405dc8ae886d","repo":"grafana/k6","slug":"unsupported-public-key-algorithm","errorCode":null,"errorMessage":"unsupported public key algorithm","messagePattern":"unsupported public key algorithm","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/crypto/x509/x509.go","lineNumber":210,"sourceCode":"\t\tCountry:             first(issuer.Country),\n\t\tStateOrProvinceName: first(issuer.Province),\n\t\tLocalityName:        first(issuer.Locality),\n\t\tOrganizationName:    first(issuer.Organization),\n\t\tNames:               makeRdns(issuer.Names),\n\t}\n}\n\nfunc makePublicKey(parsed any) (PublicKey, error) {\n\tvar algorithm string\n\tswitch parsed.(type) {\n\tcase *dsa.PublicKey:\n\t\talgorithm = \"DSA\"\n\tcase *ecdsa.PublicKey:\n\t\talgorithm = \"ECDSA\"\n\tcase *rsa.PublicKey:\n\t\talgorithm = \"RSA\"\n\tdefault:\n\t\terr := errors.New(\"unsupported public key algorithm\")\n\t\treturn PublicKey{}, err\n\t}\n\treturn PublicKey{\n\t\tAlgorithm: algorithm,\n\t\tKey:       parsed,\n\t}, nil\n}\n\nfunc first(values []string) string {\n\tif len(values) > 0 {\n\t\treturn values[0]\n\t}\n\treturn \"\"\n}\n\nfunc iso8601(value time.Time) string {\n\treturn value.Format(time.RFC3339)\n}","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/modules/k6/crypto/x509/x509.go#L192-L228","documentation":"k6's k6/crypto/x509 module exposes parse(), which turns a PEM certificate into a Certificate struct that includes a PublicKey field. makePublicKey only maps three Go key types to an algorithm name: DSA, ECDSA and RSA. Any other key type (most commonly Ed25519) falls into the default branch and the whole parse() call fails with this error, even though the certificate itself parsed successfully.","triggerScenarios":"Calling x509.parse(pemBytes) (import x509 from 'k6/crypto/x509') on a certificate whose SubjectPublicKeyInfo is not DSA/ECDSA/RSA, e.g. a certificate generated with 'openssl req -x509 -newkey ed25519' or issued by a CA that defaults to Ed25519. Only parse() hits this path; getSubject, getIssuer and getAltNames do not build a PublicKey.","commonSituations":"Modern TLS 1.3 setups and OpenSSL 3.x where Ed25519 keys are cheap and popular; certificates from cloud CAs or internal PKI that switched to Ed25519; reusing service mTLS certificates in k6 scripts to inspect them.","solutions":["Regenerate the certificate with a supported algorithm: RSA (>=2048 bits) or ECDSA (P-256/P-384), e.g. 'openssl req -x509 -newkey rsa:2048 -nodes -keyout key.pem -out cert.pem'.","If you only need subject/issuer/altNames, call x509.getSubject/getIssuer/getAltNames instead of x509.parse - those do not touch the public key.","If the certificate is fixed, inspect it outside k6 (openssl x509 -text -noout -in cert.pem) and drop the x509.parse call from the script.","Upgrade to the latest k6 in case newer algorithms were added to makePublicKey."],"exampleFix":"// before: cert created with `openssl req -x509 -newkey ed25519 ...`\nimport x509 from 'k6/crypto/x509';\nconst cert = x509.parse(open('./cert.pem')); // throws: unsupported public key algorithm\n\n// after: regenerate cert with RSA/ECDSA, or avoid the public-key path\nimport x509 from 'k6/crypto/x509';\nconst subject = x509.getSubject(open('./cert.pem')); // works for Ed25519 certs","handlingStrategy":"validation","validationCode":"# run before shipping the script; reject keys k6 cannot parse\nopenssl x509 -in cert.pem -noout -text | grep 'Public Key Algorithm'\n# must print rsaEncryption / id-ecPublicKey / DSA; id-Ed25519 will fail in k6","typeGuard":null,"tryCatchPattern":"try {\n  const cert = x509.parse(pem);\n} catch (e) {\n  if (String(e.message).includes('unsupported public key algorithm')) {\n    console.warn('cert uses an unsupported key algorithm; using getSubject instead');\n    return x509.getSubject(pem);\n  }\n  throw e;\n}","preventionTips":["Standardize test certificates on RSA-2048 or ECDSA P-256.","Add a CI check that greps cert files for 'BEGIN ... PRIVATE KEY' and Ed25519 OIDs before k6 runs.","Prefer getSubject/getIssuer/getAltNames when you don't need the public key."],"tags":["k6","crypto","x509","certificate","public-key","ed25519"],"backgroundTag":"unsupported-crypto-algorithm","analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}