SecureSocket: add some certificate support

* Instead of creating an OpenSSL context ofor each socket, use a global
one and initialize it lazily when the first SecureSocket is created
* Load the certificates from our certificate list so SSL certificates
sent by servers can be validated.
* Add a callback for signalling that certificate validation failed, the
default implementation proceeds with the connection anyway (to keep the
old behavior).
* Introduce BCertificate class, that provides some information about a
certificate. Currently it's only used by the callback mentionned above,
but it will be possible to get the leaf certificate for the connection
after it's established.

Review of the API and implementation is welcome, before I start making
use of this in HttpRequest and WebKit to allow the user to accept new
certificates.
This commit is contained in:
Adrien Destugues
2014-01-15 17:45:21 +01:00
parent b11772acca
commit 5ebdc79955
6 changed files with 287 additions and 14 deletions
+32
View File
@@ -0,0 +1,32 @@
/*
* Copyright 2014 Haiku, Inc.
* Distributed under the terms of the MIT License.
*/
#ifndef _CERTIFICATE_H
#define _CERTIFICATE_H
#include <SecureSocket.h>
#include <String.h>
class BCertificate {
public:
~BCertificate();
BString String();
bigtime_t StartDate();
bigtime_t ExpirationDate();
BString Issuer();
BString Subject();
private:
friend class BSecureSocket::Private;
class Private;
BCertificate(Private* data);
Private* fPrivate;
};
#endif
+8
View File
@@ -9,6 +9,9 @@
#include <Socket.h>
class BCertificate;
class BSecureSocket : public BSocket {
public:
BSecureSocket();
@@ -17,6 +20,10 @@ public:
BSecureSocket(const BSecureSocket& other);
virtual ~BSecureSocket();
virtual bool CertificateVerificationFailed(BCertificate);
// BSocket implementation
virtual status_t Connect(const BNetworkAddress& peer,
bigtime_t timeout = B_INFINITE_TIMEOUT);
virtual void Disconnect();
@@ -30,6 +37,7 @@ public:
virtual ssize_t Write(const void* buffer, size_t size);
private:
friend class BCertificate;
class Private;
Private* fPrivate;
};