summaryrefslogtreecommitdiff
path: root/cpp/src/IceSSL/CertificateDesc.h
blob: 6f44c755dcf70b0d85b57fcd7b9c8d222a13b3a5 (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
114
115
116
117
118
119
120
121
122
123
124
// **********************************************************************
//
// Copyright (c) 2003-2004 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************

#ifndef ICE_SSL_CERTIFICATE_DESC_H
#define ICE_SSL_CERTIFICATE_DESC_H

#include <IceUtil/Config.h>
#include <openssl/ssl.h>
#include <vector>

namespace IceSSL
{

class CertificateFile
{
public:

    CertificateFile();
    CertificateFile(const std::string&, const int);
    CertificateFile(const CertificateFile&);

    std::string getFileName() const;
    int getEncoding() const;

protected:

    std::string _fileName;
    int _encoding;
};

class DiffieHellmanParamsFile : public CertificateFile
{
public:

    DiffieHellmanParamsFile();
    DiffieHellmanParamsFile(const int, const std::string&, const int);
    DiffieHellmanParamsFile(const DiffieHellmanParamsFile&);

    int getKeySize() const;

protected:

    int _keySize;
};

class CertificateDesc
{
public:

    CertificateDesc();
    CertificateDesc(const int, const CertificateFile&, const CertificateFile&);
    CertificateDesc(const CertificateDesc&);

    int getKeySize() const;

    const CertificateFile& getPublic() const;
    const CertificateFile& getPrivate() const;

protected:

    int _keySize;
    CertificateFile _public;
    CertificateFile _private;
};

typedef std::vector<CertificateDesc> RSAVector;
typedef std::vector<CertificateDesc> DSAVector;
typedef std::vector<DiffieHellmanParamsFile> DHVector;

template<class Stream>
inline Stream& operator << (Stream& target, const CertificateFile& certFile)
{
    if(certFile.getEncoding() == SSL_FILETYPE_PEM)
    {
        target << "[PEM]: " << certFile.getFileName();
    }
    else if(certFile.getEncoding() == SSL_FILETYPE_ASN1)
    {
        target << "[ASN1]: " << certFile.getFileName();
    }

    return target;
}

template<class Stream>
inline Stream& operator << (Stream& target, const DiffieHellmanParamsFile& dhParams)
{
    if(dhParams.getKeySize() != 0)
    {
        target << "Keysize: " << dhParams.getKeySize() << "\n";
        target << "File:    ";
        IceSSL::operator<<(target, ((CertificateFile&)dhParams));
        target << "\n";
    }

    return target;
}

template<class Stream>
inline Stream& operator << (Stream& target, const CertificateDesc& certDesc)
{
    if(certDesc.getKeySize() != 0)
    {
        target << "Keysize: " << certDesc.getKeySize() << "\n";
        target << "Public:  ";
        IceSSL::operator<<(target,  certDesc.getPublic());
        target << "\n";
        target << "Private: ";
        IceSSL::operator<<(target, certDesc.getPrivate());
        target << "\n";
    }

    return target;
}

}

#endif