{"action":"opened","issue":{"url":"https://api.github.com/repos/hashicorp/nomad-java-sdk/issues/15","repository_url":"https://api.github.com/repos/hashicorp/nomad-java-sdk","labels_url":"https://api.github.com/repos/hashicorp/nomad-java-sdk/issues/15/labels{/name}","comments_url":"https://api.github.com/repos/hashicorp/nomad-java-sdk/issues/15/comments","events_url":"https://api.github.com/repos/hashicorp/nomad-java-sdk/issues/15/events","html_url":"https://github.com/hashicorp/nomad-java-sdk/issues/15","id":343568960,"node_id":"MDU6SXNzdWUzNDM1Njg5NjA=","number":15,"title":"API config builder not working with PKCS#8 TLS key file","user":{"login":"hpuac","id":1850100,"node_id":"MDQ6VXNlcjE4NTAxMDA=","avatar_url":"https://avatars0.githubusercontent.com/u/1850100?v=4","gravatar_id":"","url":"https://api.github.com/users/hpuac","html_url":"https://github.com/hpuac","followers_url":"https://api.github.com/users/hpuac/followers","following_url":"https://api.github.com/users/hpuac/following{/other_user}","gists_url":"https://api.github.com/users/hpuac/gists{/gist_id}","starred_url":"https://api.github.com/users/hpuac/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hpuac/subscriptions","organizations_url":"https://api.github.com/users/hpuac/orgs","repos_url":"https://api.github.com/users/hpuac/repos","events_url":"https://api.github.com/users/hpuac/events{/privacy}","received_events_url":"https://api.github.com/users/hpuac/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-07-23T10:07:16Z","updated_at":"2018-07-23T10:07:16Z","closed_at":null,"author_association":"NONE","body":"## Issue\r\nWhen generating a key with `openssl genpkey -algorithm RSA`, the default output format is a PKCS#8 TLS key file.\r\nUnfortunately the config builder is not working with this file and only works with a PKCS#1 TLS key file.\r\n\r\n## Technical analysis\r\nA PKCS#1 TLS key file starts with `-----BEGIN RSA PRIVATE KEY-----`.\r\nA PKCS#8 TLS key file starts with `-----BEGIN PRIVATE KEY-----`.\r\nIn the [TlsUtils](https://github.com/hashicorp/nomad-java-sdk/blob/master/sdk/src/main/java/com/hashicorp/nomad/javasdk/TlsUtils.java) class, the [loadPemKey function](https://github.com/hashicorp/nomad-java-sdk/blob/master/sdk/src/main/java/com/hashicorp/nomad/javasdk/TlsUtils.java#L47) is calling `readObject` of the [bouncycastle openssl PEMParser](https://github.com/bcgit/bc-java/blob/master/pkix/src/main/java/org/bouncycastle/openssl/PEMParser.java#L58). \r\nThis function is returning a `PEMKeyPair` if it's a PKCS#1 TLS key, or a `PrivateKeyInfo` if it's a PKCS#8 TLS key file.\r\nThe [loadPemKey function](https://github.com/hashicorp/nomad-java-sdk/blob/master/sdk/src/main/java/com/hashicorp/nomad/javasdk/TlsUtils.java#L51) is then doing a cast to a `PEMKeyPair` that is failing in case that we passed in a PKCS#8 TLS key file.\r\n\r\n## Request\r\nPlease make the config builder able of using PKCS#8 TLS key file.\r\nAlso the nomad cli tools are capable of handling both types of key files.\r\n\r\n## Resources\r\nhttps://stackoverflow.com/questions/20065304/differences-between-begin-rsa-private-key-and-begin-private-key#20065522\r\n"}}
{"actor":{"display_login":"hpuac"}}