{"action":"created","issue":{"url":"https://api.github.com/repos/digitalbazaar/forge/issues/431","repository_url":"https://api.github.com/repos/digitalbazaar/forge","labels_url":"https://api.github.com/repos/digitalbazaar/forge/issues/431/labels{/name}","comments_url":"https://api.github.com/repos/digitalbazaar/forge/issues/431/comments","events_url":"https://api.github.com/repos/digitalbazaar/forge/issues/431/events","html_url":"https://github.com/digitalbazaar/forge/issues/431","id":180250531,"number":431,"title":"Sometimes the generated key can't be imported by Go crypto/tls","user":{"login":"Foosvald","id":135475,"avatar_url":"https://avatars.githubusercontent.com/u/135475?v=3","gravatar_id":"","url":"https://api.github.com/users/Foosvald","html_url":"https://github.com/Foosvald","followers_url":"https://api.github.com/users/Foosvald/followers","following_url":"https://api.github.com/users/Foosvald/following{/other_user}","gists_url":"https://api.github.com/users/Foosvald/gists{/gist_id}","starred_url":"https://api.github.com/users/Foosvald/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Foosvald/subscriptions","organizations_url":"https://api.github.com/users/Foosvald/orgs","repos_url":"https://api.github.com/users/Foosvald/repos","events_url":"https://api.github.com/users/Foosvald/events{/privacy}","received_events_url":"https://api.github.com/users/Foosvald/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2016-09-30T08:40:49Z","updated_at":"2016-10-05T20:24:29Z","closed_at":null,"body":"Thanks for a good lib!\r\n\r\nI have a small problem though, which I also posted at https://github.com/golang/go/issues/17279\r\n\r\nWe are using version of Node-forge 0.6.42, and get a problem both in OSX and Linux (running in Node). \r\n\r\nThis is the code we use to generate a key pair:\r\n\r\n```\r\n'use strict'\r\n\r\nconst fs = require('fs')\r\nconst forge = require('node-forge')\r\n\r\nconst caCert = fs.readFileSync(__dirname + '/fixtures/ca_test.pem')\r\nconst caKey = fs.readFileSync(__dirname + '/fixtures/ca_test.key')\r\n\r\nlet cert = generateServerCertificate(\r\n    caKey, caCert, 'etcd', ['127.0.0.1'])\r\n\r\nfs.writeFileSync(__dirname + '/etcd.pem', cert.cert)\r\nfs.writeFileSync(__dirname + '/etcd.key', cert.key)\r\n\r\nfunction generateServerCertificate(caKeyString, caCertString, serviceInstance, ips) {\r\n    var caKey = forge.pki.privateKeyFromPem(caKeyString)\r\n    var caCert = forge.pki.certificateFromPem(caCertString)\r\n\r\n    var keys = forge.pki.rsa.generateKeyPair(2048)\r\n    var cert = forge.pki.createCertificate()\r\n    cert.publicKey = keys.publicKey\r\n    cert.serialNumber = '01'\r\n    cert.validity.notBefore = new Date()\r\n    cert.validity.notAfter = new Date()\r\n    cert.validity.notAfter.setFullYear(cert.validity.notBefore.getFullYear() + 1)\r\n\r\n    var attrsSubject = [\r\n        {\r\n            name: 'commonName',\r\n            value: 'none'\r\n        },\r\n        {\r\n            name: 'organizationName',\r\n            value: 'Our Org'\r\n        },\r\n        {\r\n            shortName: 'OU',\r\n            value: serviceInstance\r\n        }\r\n    ]\r\n\r\n    cert.setSubject(attrsSubject)\r\n    cert.setIssuer(caCert.subject.attributes)\r\n\r\n    cert.setExtensions([\r\n        {\r\n            name: 'subjectAltName',\r\n            altNames: ips.map(ip => {\r\n                return { type: 7, ip: ip }\r\n            }),\r\n        }])\r\n\r\n    cert.sign(caKey, forge.md.sha256.create())\r\n\r\n    var pem = {\r\n        key: forge.pki.privateKeyToPem(keys.privateKey),\r\n        cert: forge.pki.certificateToPem(cert)\r\n    }\r\n\r\n    return pem\r\n}\r\n```\r\nAnd then we import it in Go using \r\n```\r\npackage main\r\n\r\nimport (\r\n    \"crypto/tls\"\r\n    \"log\"\r\n)\r\n\r\nfunc main() {\r\n    _, err := tls.LoadX509KeyPair(\"broken.pem\", \"broken.key\")\r\n    if(err != nil) {\r\n        log.Fatal(err)\r\n    }\r\n    log.Print(\"Go loaded key successfully\")\r\n}\r\n```\r\nAnd in most cases the key is successfully imported by Go, but sometimes it fails with the following error message: `tls: failed to parse private key` which apparently deeper down in the Go crypto/tls module is caused by `asn1: structure error: integer not minimally-encoded`.\r\n\r\nI've attached both a pair of working keys and a pair of broken keys which have been generated in the same way.\r\n[keys.zip](https://github.com/digitalbazaar/forge/files/502463/keys.zip)\r\n\r\nIs this a problem with how we generate and save the key, or is it a problem deeper down in the code? "},"comment":{"url":"https://api.github.com/repos/digitalbazaar/forge/issues/comments/251788706","html_url":"https://github.com/digitalbazaar/forge/issues/431#issuecomment-251788706","issue_url":"https://api.github.com/repos/digitalbazaar/forge/issues/431","id":251788706,"user":{"login":"dlongley","id":168137,"avatar_url":"https://avatars.githubusercontent.com/u/168137?v=3","gravatar_id":"","url":"https://api.github.com/users/dlongley","html_url":"https://github.com/dlongley","followers_url":"https://api.github.com/users/dlongley/followers","following_url":"https://api.github.com/users/dlongley/following{/other_user}","gists_url":"https://api.github.com/users/dlongley/gists{/gist_id}","starred_url":"https://api.github.com/users/dlongley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dlongley/subscriptions","organizations_url":"https://api.github.com/users/dlongley/orgs","repos_url":"https://api.github.com/users/dlongley/repos","events_url":"https://api.github.com/users/dlongley/events{/privacy}","received_events_url":"https://api.github.com/users/dlongley/received_events","type":"User","site_admin":false},"created_at":"2016-10-05T20:24:29Z","updated_at":"2016-10-05T20:24:29Z","body":"Btw, I've also been running the `run` script for ~10 minutes with no failures."}}
{"actor":{"display_login":"dlongley"}}