blob: 2029a581a7acb63c9b2afe97d923aa1faadb9ee5 (
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
|
// **********************************************************************
//
// Copyright (c) 2001
// MutableRealms, Inc.
// Huntsville, AL, USA
//
// All Rights Reserved
//
// **********************************************************************
#include <IceUtil/Config.h>
#include <IceUtil/Base64.h>
#include <Ice/SslRSAPrivateKey.h>
#include <Ice/SslIceUtils.h>
#include <assert.h>
void ::IceInternal::incRef(::IceSecurity::Ssl::OpenSSL::RSAPrivateKey* p) { p->__incRef(); }
void ::IceInternal::decRef(::IceSecurity::Ssl::OpenSSL::RSAPrivateKey* p) { p->__decRef(); }
using std::back_inserter;
using std::string;
using IceUtil::Base64;
IceSecurity::Ssl::OpenSSL::RSAPrivateKey::RSAPrivateKey(const string& key)
{
_privateKey = 0;
ByteSeq keySeq = Base64::decode(key);
byteSeqToKey(keySeq);
}
IceSecurity::Ssl::OpenSSL::RSAPrivateKey::RSAPrivateKey(const ByteSeq& keySeq)
{
_privateKey = 0;
byteSeqToKey(keySeq);
}
IceSecurity::Ssl::OpenSSL::RSAPrivateKey::~RSAPrivateKey()
{
RSA_free(_privateKey);
}
void
IceSecurity::Ssl::OpenSSL::RSAPrivateKey::keyToBase64(string& b64Key)
{
ByteSeq keySeq;
keyToByteSeq(keySeq);
b64Key = Base64::encode(keySeq);
}
void
IceSecurity::Ssl::OpenSSL::RSAPrivateKey::keyToByteSeq(ByteSeq& 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);
IceSecurity::Ssl::ucharToByteSeq(privateKeyBuffer, privKeySize, keySeq);
delete []privateKeyBuffer;
}
RSA*
IceSecurity::Ssl::OpenSSL::RSAPrivateKey::getRSAPrivateKey() const
{
return _privateKey;
}
IceSecurity::Ssl::OpenSSL::RSAPrivateKey::RSAPrivateKey(RSA* rsa) :
_privateKey(rsa)
{
}
void
IceSecurity::Ssl::OpenSSL::RSAPrivateKey::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;
}
|