Skip to content

Commit

Permalink
Add openconnect_get_cert_DER() function
Browse files Browse the repository at this point in the history
This translates a cert into an SSL-library-agnostic form, so that the caller
can then process it using their own choice of tools.

As with the new openconnect_get_cert_details(), this isn't marked as a
public function yet because we anticipate more changes to the API.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
  • Loading branch information
David Woodhouse authored and David Woodhouse committed May 29, 2012
1 parent 412cab3 commit af19e15
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions libopenconnect.map.in
Expand Up @@ -54,5 +54,6 @@ OPENCONNECT_PRIVATE {
openconnect_create_useragent;
openconnect_report_ssl_errors;
openconnect_get_cert_details;
openconnect_get_cert_DER;
openconnect_sha1;
};
4 changes: 4 additions & 0 deletions openconnect.h
Expand Up @@ -130,6 +130,10 @@ int openconnect_get_cert_sha1(struct openconnect_info *vpninfo,
struct x509_st *cert, char *buf);
char *openconnect_get_cert_details(struct openconnect_info *vpninfo,
struct x509_st *cert);
/* Returns the length of the created DER output, in a newly-allocated buffer
that will need to be freed by the caller. */
int openconnect_get_cert_DER(struct openconnect_info *vpninfo,
struct x509_st *cert, unsigned char **buf);
int openconnect_set_http_proxy(struct openconnect_info *vpninfo, char *proxy);
int openconnect_passphrase_from_fsid(struct openconnect_info *vpninfo);
int openconnect_obtain_cookie(struct openconnect_info *vpninfo);
Expand Down
26 changes: 26 additions & 0 deletions openssl.c
Expand Up @@ -22,6 +22,8 @@
* Boston, MA 02110-1301 USA
*/

#include <errno.h>

#include <openssl/evp.h>

#include "openconnect-internal.h"
Expand All @@ -36,3 +38,27 @@ int openconnect_sha1(unsigned char *result, void *data, int len)

return 0;
}

int openconnect_get_cert_DER(struct openconnect_info *vpninfo,
struct x509_st *cert, unsigned char **buf)
{
BIO *bp = BIO_new(BIO_s_mem());
BUF_MEM *certinfo;
size_t l;

if (!i2d_X509_bio(bp, cert)) {
BIO_free(bp);
return -EIO;
}

BIO_get_mem_ptr(bp, &certinfo);
l = certinfo->length;
*buf = malloc(l);
if (!*buf) {
BIO_free(bp);
return -ENOMEM;
}
memcpy(*buf, certinfo->data, l);
BIO_free(bp);
return l;
}

0 comments on commit af19e15

Please sign in to comment.