{"record":{"id":"87a5dcaef4c14a2c","repo":"karatelabs/karate","slug":"failed-to-create-client-ssl-context-message","errorCode":null,"errorMessage":"failed to create client SSL context: <message>","messagePattern":"failed to create client SSL context: <message>","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/core/SslContextFactory.java","lineNumber":65,"sourceCode":"    private static final Logger logger = LogContext.RUNTIME_LOGGER;\n\n    /**\n     * Create an SSLContext for client use (connecting to HTTPS servers).\n     */\n    public static SSLContext createClientContext(SslConfig config) {\n        try {\n            if (config.isTrustAll()) {\n                return createTrustAllContext(config.getAlgorithm());\n            }\n\n            TrustManager[] trustManagers = loadTrustManagers(config);\n            KeyManager[] keyManagers = loadKeyManagers(config);\n\n            SSLContext ctx = SSLContext.getInstance(config.getAlgorithm());\n            ctx.init(keyManagers, trustManagers, new SecureRandom());\n            return ctx;\n        } catch (Exception e) {\n            throw new RuntimeException(\"failed to create client SSL context: \" + e.getMessage(), e);\n        }\n    }\n\n    /**\n     * Create an SSLContext for server use (accepting HTTPS connections).\n     */\n    public static SSLContext createServerContext(SslConfig config) {\n        try {\n            if (config.getCertPath() == null) {\n                // Generate self-signed certificate\n                return SslUtils.generateSelfSigned();\n            }\n            return loadFromPem(config.getCertPath(), config.getKeyPath(), config.getAlgorithm());\n        } catch (Exception e) {\n            throw new RuntimeException(\"failed to create server SSL context: \" + e.getMessage(), e);\n        }\n    }\n","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/core/SslContextFactory.java#L47-L83","documentation":"SslContextFactory.createClientContext builds an SSLContext from the given SSL/TLS config (trust material, key managers, algorithm). Any failure during that construction is wrapped and rethrown as \"failed to create client SSL context: <message>\" with the original exception attached.","triggerScenarios":"Calling the HTTP client initialization with an SSL config whose trust store file is missing/unreadable, keystore password wrong, PEM is malformed, or algorithm name is invalid — any Exception in the try block.","commonSituations":"Typo in trustStore/keystore path; wrong keystore password; internal company CA file not mounted in the container; unsupported algorithm string like 'TLSvX'; corrupt or expired PEM files.","solutions":["Read the chained cause's message to identify the exact failure (missing file, bad password, bad algorithm) and fix the config value","Verify configured paths exist and are readable from the working directory/classpath, and passwords are correct","Validate the algorithm name (e.g. 'TLS' or 'TLSv1.2') is supported by the JVM (SSLContext.getDefaultAlgorithm())"],"exampleFix":"// before\n* configure ssl = { trustStore: 'classpath:missing.jks', trustStorePassword: 'wrong' }\n// after\n* configure ssl = { trustStore: 'classpath:trusted.jks', trustStorePassword: 'changeit', algorithm: 'TLSv1.2' }","handlingStrategy":"validation","validationCode":"// pre-flight: confirm configured SSL material exists before creating the context\njava.nio.file.Path ts = java.nio.file.Path.of(trustStorePath);\nif (!java.nio.file.Files.isReadable(ts)) throw new IllegalStateException(\"trust store not readable: \" + ts);\nif (!List.of(\"TLS\",\"TLSv1.2\",\"TLSv1.3\").contains(algorithm)) throw new IllegalStateException(\"unsupported algorithm: \" + algorithm);","typeGuard":null,"tryCatchPattern":"try { SslContextFactory.createClientContext(config); } catch (RuntimeException e) { throw new IllegalStateException(\"check ssl config: \" + e.getCause(), e); }","preventionTips":["Verify trust store / keystore paths resolve from the working directory or classpath","Double-check passwords and algorithm names against JVM defaults","Mount CA files into containers and confirm permissions"],"tags":["ssl","tls","configuration"],"backgroundTag":"invalid-config-value","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-16T19:17:19.609Z"}