{"action":"opened","issue":{"url":"https://api.github.com/repos/ARMmbed/mbedtls/issues/396","labels_url":"https://api.github.com/repos/ARMmbed/mbedtls/issues/396/labels{/name}","comments_url":"https://api.github.com/repos/ARMmbed/mbedtls/issues/396/comments","events_url":"https://api.github.com/repos/ARMmbed/mbedtls/issues/396/events","html_url":"https://github.com/ARMmbed/mbedtls/issues/396","id":126349338,"number":396,"title":"mbedtls_pk_write_pubkey_der expects a mbedtls_pk_context that is non-const","user":{"login":"sithglan","id":1595655,"avatar_url":"https://avatars.githubusercontent.com/u/1595655?v=3","gravatar_id":"","url":"https://api.github.com/users/sithglan","html_url":"https://github.com/sithglan","followers_url":"https://api.github.com/users/sithglan/followers","following_url":"https://api.github.com/users/sithglan/following{/other_user}","gists_url":"https://api.github.com/users/sithglan/gists{/gist_id}","starred_url":"https://api.github.com/users/sithglan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sithglan/subscriptions","organizations_url":"https://api.github.com/users/sithglan/orgs","repos_url":"https://api.github.com/users/sithglan/repos","events_url":"https://api.github.com/users/sithglan/events{/privacy}","received_events_url":"https://api.github.com/users/sithglan/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-01-13T06:15:02Z","updated_at":"2016-01-13T06:15:02Z","closed_at":null,"body":"This bug comes from Ray Satiro from the libcurl malilinglist:\r\n\r\n- mbedtls_pk_write_pubkey_der expects a mbedtls_pk_context that is non-const\r\n[3], but mbedtls_ssl_get_peer_cert returns a const certificate. I don't see a\r\nway to make a non-const copy of the public key but there is probably a way to\r\ndo this, or copy the cert or some parent container.\r\n\r\nAnswer from Manuel:\r\n\r\n> Finally, regarding the fact that mbedtls_pk_write_pubkey_der() expects\r\n> a non-const pk_context, I think it is a bug on our side: that function\r\n> should work well with a const public key, and I'm afraid we just\r\n> forgot the const in the prototype :( So I think it should work if you\r\n> just cast the const away. If you want a more correct solution, then\r\n> the easiest thing to make a non-const copy of is the certificate, by\r\n> calling mbedtls_x509_crt_parse_der() on c->raw.p, c->raw.len if c is\r\n> the pointer returned by mbedtls_ssl_get_peer_cert().\r\n\r\nReferences: \r\nhttps://tls.mbed.org/discussions/generic/resumed-tls-handshake\r\nhttp://article.gmane.org/gmane.comp.web.curl.library/46767"}}