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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
// **********************************************************************
//
// Copyright (c) 2001
// MutableRealms, Inc.
// Huntsville, AL, USA
//
// All Rights Reserved
//
// **********************************************************************
#include <IceUtil/Config.h>
#include <IceUtil/Base64.h>
#include <Ice/SslRSAKeyPair.h>
#include <Ice/SslRSAPrivateKey.h>
#include <Ice/SslRSAPublicKey.h>
#include <assert.h>
void ::IceInternal::incRef(::IceSecurity::Ssl::OpenSSL::RSAKeyPair* p) { p->__incRef(); }
void ::IceInternal::decRef(::IceSecurity::Ssl::OpenSSL::RSAKeyPair* p) { p->__decRef(); }
using std::back_inserter;
using std::string;
using IceUtil::Base64;
IceSecurity::Ssl::OpenSSL::RSAKeyPair::RSAKeyPair(const string& key, const string& cert) :
_privateKey(new RSAPrivateKey(key)),
_publicKey(new RSAPublicKey(cert))
{
/*
_privateKey = 0;
_publicKey = 0;
ByteSeq keySeq = Base64::decode(key);
ByteSeq certSeq = Base64::decode(cert);
byteSeqToKey(keySeq);
byteSeqToCert(certSeq);
*/
}
IceSecurity::Ssl::OpenSSL::RSAKeyPair::RSAKeyPair(const ByteSeq& keySeq, const ByteSeq& certSeq) :
_privateKey(new RSAPrivateKey(keySeq)),
_publicKey(new RSAPublicKey(certSeq))
{
/*
_privateKey = 0;
_publicKey = 0;
byteSeqToKey(keySeq);
byteSeqToCert(certSeq);
*/
}
IceSecurity::Ssl::OpenSSL::RSAKeyPair::~RSAKeyPair()
{
/*
RSA_free(_privateKey);
X509_free(_publicKey);
*/
}
void
IceSecurity::Ssl::OpenSSL::RSAKeyPair::keyToBase64(string& b64Key)
{
_privateKey->keyToBase64(b64Key);
/*
ByteSeq keySeq;
keyToByteSeq(keySeq);
b64Key = Base64::encode(keySeq);
*/
}
void
IceSecurity::Ssl::OpenSSL::RSAKeyPair::certToBase64(string& b64Cert)
{
_publicKey->certToBase64(b64Cert);
/*
ByteSeq certSeq;
certToByteSeq(certSeq);
b64Cert = Base64::encode(certSeq);
*/
}
void
IceSecurity::Ssl::OpenSSL::RSAKeyPair::keyToByteSeq(ByteSeq& keySeq)
{
_privateKey->keyToByteSeq(keySeq);
/*
assert(_privateKey);
// Output the Private Key to a char buffer
unsigned int privKeySize = i2d_RSAPrivateKey(_privateKey, 0);
assert(privKeySize > 0);
unsigned char* privateKeyBuffer = new unsigned char[privKeySize];
// We have to do this because i2d_RSAPrivateKey changes the pointer.
unsigned char* privKeyBuff = privateKeyBuffer;
i2d_RSAPrivateKey(_privateKey, &privKeyBuff);
ucharToByteSeq(privateKeyBuffer, privKeySize, keySeq);
delete []privateKeyBuffer;
*/
}
void
IceSecurity::Ssl::OpenSSL::RSAKeyPair::certToByteSeq(ByteSeq& certSeq)
{
_publicKey->certToByteSeq(certSeq);
/*
assert(_publicKey);
// Output the Public Key to a char buffer
unsigned int pubKeySize = i2d_X509(_publicKey, 0);
assert(pubKeySize > 0);
unsigned char* publicKeyBuffer = new unsigned char[pubKeySize];
// We have to do this because i2d_X509_PUBKEY changes the pointer.
unsigned char* pubKeyBuff = publicKeyBuffer;
i2d_X509(_publicKey, &pubKeyBuff);
ucharToByteSeq(publicKeyBuffer, pubKeySize, certSeq);
delete []publicKeyBuffer;
*/
}
RSA*
IceSecurity::Ssl::OpenSSL::RSAKeyPair::getRSAPrivateKey() const
{
return _privateKey->getRSAPrivateKey();
}
X509*
IceSecurity::Ssl::OpenSSL::RSAKeyPair::getX509PublicKey() const
{
return _publicKey->getX509PublicKey();
}
// IceSecurity::Ssl::OpenSSL::RSAKeyPair::RSAKeyPair(RSA* rsa, X509* x509) :
IceSecurity::Ssl::OpenSSL::RSAKeyPair::RSAKeyPair(const RSAPrivateKeyPtr& rsa, const RSAPublicKeyPtr& x509) :
_privateKey(rsa),
_publicKey(x509)
{
}
/*
void
IceSecurity::Ssl::OpenSSL::RSAKeyPair::byteSeqToKey(const ByteSeq& keySeq)
{
unsigned char* privateKeyBuffer = byteSeqToUChar(keySeq);
assert(privateKeyBuffer);
unsigned char* privKeyBuff = privateKeyBuffer;
unsigned char** privKeyBuffpp = &privKeyBuff;
RSA** rsapp = &_privateKey;
_privateKey = d2i_RSAPrivateKey(rsapp, privKeyBuffpp, (long)keySeq.size());
assert(_privateKey);
delete []privateKeyBuffer;
}
void
IceSecurity::Ssl::OpenSSL::RSAKeyPair::byteSeqToCert(const ByteSeq& certSeq)
{
unsigned char* publicKeyBuffer = byteSeqToUChar(certSeq);
assert(publicKeyBuffer);
// We have to do this because d2i_X509 changes the pointer.
unsigned char* pubKeyBuff = publicKeyBuffer;
unsigned char** pubKeyBuffpp = &pubKeyBuff;
X509** x509pp = &_publicKey;
_publicKey = d2i_X509(x509pp, pubKeyBuffpp, (long)certSeq.size());
assert(_publicKey);
delete []publicKeyBuffer;
}
void
IceSecurity::Ssl::OpenSSL::RSAKeyPair::ucharToByteSeq(unsigned char* ucharBuffer, int length, ByteSeq& destBuffer)
{
destBuffer.reserve(length);
std::copy(ucharBuffer, (ucharBuffer + length), back_inserter(destBuffer));
}
unsigned char*
IceSecurity::Ssl::OpenSSL::RSAKeyPair::byteSeqToUChar(const ByteSeq& sequence)
{
int seqSize = sequence.size();
assert(seqSize > 0);
unsigned char* ucharSeq = new unsigned char[seqSize];
unsigned char* ucharPtr = ucharSeq;
std::copy(sequence.begin(), sequence.end(), ucharPtr);
return ucharSeq;
}
*/
|