~ubuntu-branches/ubuntu/trusty/pdns/trusty-security

« back to all changes in this revision

Viewing changes to pdns/polarrsakeyinfra.cc

  • Committer: Package Import Robot
  • Author(s): Marc Haber, Marc Haber, Evgeni Golov
  • Date: 2012-05-11 23:51:27 UTC
  • mfrom: (1.1.9) (12.1.14 sid)
  • Revision ID: package-import@ubuntu.com-20120511235127-v0qjuaplfckcb2cd
Tags: 3.1-1
[ Marc Haber ]
* Imported Upstream version 3.1
  * reduce column size for 'algorithm' to 50. Closes: #662935
  * handle smallcaps RRs. Closes: #656788
* refresh patches
* remove unused patches
* add patch to turn off the traceback handler at run time
* add patch for changeset 2575 (race condition with supermasters)
* fix mysql multiarch build failure, set cflags etc to hardening defaults
* do not run bootstrap a build time, using autotools_dev
* use dh-autoreconf, remove autofoo created files from
  patches/fix-mongodb-backend-patch
* fix dh invocation
* create MySQL databases with engine=innodb instead of type
* set debian/compat to 9
* Standards-Version: 3.9.3 (no changes needed)
* add myself to uploaders, change Vcs-Header to my git. Closes: #672550

[ Evgeni Golov ]
* use system libpolarssl if present, local copy otherwise.
  Closes: #671856, #656861

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifdef HAVE_LIBPOLARSSLSSL
1
2
#include <polarssl/rsa.h>
2
3
#include <polarssl/base64.h>
3
4
#include <polarssl/sha1.h>
4
5
#include <polarssl/sha2.h>
5
6
#include <polarssl/sha4.h>
6
7
#include <polarssl/havege.h>
 
8
#else
 
9
#include "ext/polarssl-1.1.2/include/polarssl/rsa.h"
 
10
#include "ext/polarssl-1.1.2/include/polarssl/base64.h"
 
11
#include "ext/polarssl-1.1.2/include/polarssl/sha1.h"
 
12
#include "ext/polarssl-1.1.2/include/polarssl/sha2.h"
 
13
#include "ext/polarssl-1.1.2/include/polarssl/sha4.h"
 
14
#include "ext/polarssl-1.1.2/include/polarssl/havege.h"
 
15
#endif
7
16
#include <boost/assign/std/vector.hpp> // for 'operator+=()'
8
17
#include <boost/foreach.hpp>
9
18
#include "dnssecinfra.hh"
10
19
using namespace boost::assign;
11
20
 
12
 
#define PDNSSEC_MI(x) mpi_init(&d_context.x, 0)
 
21
#define PDNSSEC_MI(x) mpi_init(&d_context.x)
13
22
#define PDNSSEC_MC(x) PDNSSEC_MI(x); mpi_copy(&d_context.x, const_cast<mpi*>(&orig.d_context.x))
14
 
#define PDNSSEC_MF(x) mpi_free(&d_context.x, 0)
 
23
#define PDNSSEC_MF(x) mpi_free(&d_context.x)
15
24
 
16
25
class RSADNSCryptoKeyEngine : public DNSCryptoKeyEngine
17
26
{
39
48
 
40
49
  RSADNSCryptoKeyEngine(const RSADNSCryptoKeyEngine& orig) : DNSCryptoKeyEngine(orig.d_algorithm)
41
50
  {
42
 
    d_context.ver = orig.d_context.ver;
 
51
    // this part is a little bit scary.. we make a 'deep copy' of an RSA state, and polarssl isn't helping us so we delve into thr struct
 
52
    d_context.ver = orig.d_context.ver; 
43
53
    d_context.len = orig.d_context.len;
44
54
 
45
55
    d_context.padding = orig.d_context.padding;
46
56
    d_context.hash_id = orig.d_context.hash_id;
47
 
    d_context.f_rng = orig.d_context.f_rng;
48
 
    d_context.p_rng = orig.d_context.p_rng;
49
57
    
50
58
    PDNSSEC_MC(N); 
51
59
    PDNSSEC_MC(E); PDNSSEC_MC(D); PDNSSEC_MC(P); PDNSSEC_MC(Q); PDNSSEC_MC(DP); PDNSSEC_MC(DQ); PDNSSEC_MC(QP); PDNSSEC_MC(RN); PDNSSEC_MC(RP); PDNSSEC_MC(RQ);
107
115
  havege_state hs;
108
116
  havege_init( &hs );
109
117
  
110
 
  rsa_init(&d_context, RSA_PKCS_V15, 0, havege_rand, &hs ); // FIXME this leaks memory
111
 
  int ret=rsa_gen_key(&d_context, bits, 65537);
 
118
  rsa_init(&d_context, RSA_PKCS_V15, 0); // FIXME this leaks memory (it does?)
 
119
  int ret=rsa_gen_key(&d_context, havege_random, (void*)&hs, bits, 65537);
112
120
  if(ret < 0) 
113
121
    throw runtime_error("Key generation failed");
114
122
}
141
149
  else
142
150
    hashKind = SIG_RSA_SHA512;
143
151
  
144
 
  int ret=rsa_pkcs1_sign(const_cast<rsa_context*>(&d_context), RSA_PRIVATE, 
 
152
  int ret=rsa_pkcs1_sign(const_cast<rsa_context*>(&d_context), NULL, NULL, RSA_PRIVATE, 
145
153
    hashKind,
146
154
    hash.size(),
147
155
    (const unsigned char*) hash.c_str(), signature);
234
242
  typedef map<string, mpi*> places_t;
235
243
  places_t places;
236
244
  
237
 
  rsa_init(&d_context, RSA_PKCS_V15, 0, NULL, NULL );
 
245
  rsa_init(&d_context, RSA_PKCS_V15, 0);
238
246
 
239
247
  places["Modulus"]=&d_context.N;
240
248
  places["PublicExponent"]=&d_context.E;
265
273
  cerr<<"Got "<<integers.size()<<" integers"<<endl; 
266
274
  map<int, mpi*> places;
267
275
  
268
 
  rsa_init(&d_context, RSA_PKCS_V15, 0, NULL, NULL );
 
276
  rsa_init(&d_context, RSA_PKCS_V15, 0);
269
277
 
270
278
  places[1]=&d_context.N;
271
279
  places[2]=&d_context.E;
305
313
 
306
314
void RSADNSCryptoKeyEngine::fromPublicKeyString(const std::string& rawString)
307
315
{
308
 
  rsa_init(&d_context, RSA_PKCS_V15, 0, NULL, NULL );
 
316
  rsa_init(&d_context, RSA_PKCS_V15, 0);
309
317
  string exponent, modulus;
310
318
  const unsigned char* raw = (const unsigned char*)rawString.c_str();
311
319