summaryrefslogtreecommitdiff
path: root/cpp/src/Ice/SslConnectionOpenSSL.h
blob: 22f6ad3e943473c759e48143895032c6120fbc75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// **********************************************************************
//
// Copyright (c) 2001
// MutableRealms, Inc.
// Huntsville, AL, USA
//
// All Rights Reserved
//
// **********************************************************************

#ifndef ICE_SSL_CONNECTION_OPENSSL_H
#define ICE_SSL_CONNECTION_OPENSSL_H

#include <openssl/ssl.h>
#include <Ice/SslConnection.h>
#include <Ice/SslSystem.h>
#include <Ice/Buffer.h>
#include <Ice/TraceLevels.h>
#include <Ice/Logger.h>

namespace IceSecurity
{

namespace Ssl
{

namespace OpenSSL
{

using namespace Ice;

class Connection : public IceSecurity::Ssl::Connection
{

public:

    Connection(SSL*, string&);
    virtual ~Connection();

    virtual void shutdown();

    virtual int read(Buffer&, int) = 0;
    virtual int write(Buffer&, int) = 0;

    virtual int init(int timeout = 0) = 0;

    void setTrace(TraceLevelsPtr traceLevels) { _traceLevels = traceLevels; };
    void setLogger(LoggerPtr traceLevels) { _logger = traceLevels; };


protected:

    int connect();
    int accept();
    int renegotiate();

    inline int pending() { return SSL_pending(_sslConnection); };
    inline int getLastError() const { return SSL_get_error(_sslConnection, _lastError); };

    int sslRead(char*, int);
    int sslWrite(char*, int);

    void printGetError(int);

    void protocolWrite();

    int readInBuffer(Buffer&);

    int readSelect(int);
    int writeSelect(int);

    int readSSL(Buffer&, int);

    virtual void showConnectionInfo() = 0;

    void showCertificateChain(BIO*);
    void showPeerCertificate(BIO*, const char*);
    void showSharedCiphers(BIO*);
    void showSessionInfo(BIO*);
    void showSelectedCipherInfo(BIO*);
    void showHandshakeStats(BIO*);
    void showClientCAList(BIO*, const char*);

    void setLastError(int errorCode) { _lastError = errorCode; };

    // Pointer to the OpenSSL Connection structure.
    SSL* _sslConnection;

    int _lastError;

    // TODO: Review this after a healthy stint of testing
    // Buffer for application data that may be returned during handshake
    // (probably won't contain anything, may be removed later).
    Buffer _inBuffer;
    JTCMutex _inBufferMutex;

    TraceLevelsPtr _traceLevels;
    LoggerPtr _logger;

    System* _system;

    JTCMutex _initMutex;
    int initWantRead;
    int initWantWrite;
};

}

}

}

#endif