Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 380257 | Differences between
and this patch

Collapse All | Expand All

(-)src/database.cc (-6 / +4 lines)
Lines 3425-3433 database::encrypt_rsa(key_id const & pub Link Here
3425
  rsa_pub_key pub;
3425
  rsa_pub_key pub;
3426
  get_key(pub_id, pub);
3426
  get_key(pub_id, pub);
3427
3427
3428
  SecureVector<Botan::byte> pub_block;
3428
  SecureVector<Botan::byte> pub_block
3429
  pub_block.set(reinterpret_cast<Botan::byte const *>(pub().data()),
3429
    (reinterpret_cast<Botan::byte const *>(pub().data()), pub().size());
3430
                pub().size());
3431
3430
3432
  shared_ptr<X509_PublicKey> x509_key(Botan::X509::load_key(pub_block));
3431
  shared_ptr<X509_PublicKey> x509_key(Botan::X509::load_key(pub_block));
3433
  shared_ptr<RSA_PublicKey> pub_key
3432
  shared_ptr<RSA_PublicKey> pub_key
Lines 3471-3484 database::check_signature(key_id const & Link Here
3471
  else
3470
  else
3472
    {
3471
    {
3473
      rsa_pub_key pub;
3472
      rsa_pub_key pub;
3474
      SecureVector<Botan::byte> pub_block;
3475
3473
3476
      if (!public_key_exists(id))
3474
      if (!public_key_exists(id))
3477
        return cert_unknown;
3475
        return cert_unknown;
3478
3476
3479
      get_key(id, pub);
3477
      get_key(id, pub);
3480
      pub_block.set(reinterpret_cast<Botan::byte const *>(pub().data()),
3478
      SecureVector<Botan::byte> pub_block
3481
                    pub().size());
3479
        (reinterpret_cast<Botan::byte const *>(pub().data()), pub().size());
3482
3480
3483
      L(FL("building verifier for %d-byte pub key") % pub_block.size());
3481
      L(FL("building verifier for %d-byte pub key") % pub_block.size());
3484
      shared_ptr<X509_PublicKey> x509_key(Botan::X509::load_key(pub_block));
3482
      shared_ptr<X509_PublicKey> x509_key(Botan::X509::load_key(pub_block));
(-)src/gzip.cc (-16 / +32 lines)
Lines 110-116 Gzip_Compression::Gzip_Compression(u32bi Link Here
110
   if(deflateInit2(&(zlib->stream), level, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY) != Z_OK)
110
   if(deflateInit2(&(zlib->stream), level, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY) != Z_OK)
111
      {
111
      {
112
      delete zlib; zlib = 0;
112
      delete zlib; zlib = 0;
113
      throw Exception("Gzip_Compression: Memory allocation error");
113
      throw Memory_Exhaustion();
114
      }
114
      }
115
   }
115
   }
116
116
Lines 137-143 void Gzip_Compression::start_msg() Link Here
137
/*************************************************
137
/*************************************************
138
* Compress Input with Gzip                       *
138
* Compress Input with Gzip                       *
139
*************************************************/
139
*************************************************/
140
void Gzip_Compression::write(const byte input[], u32bit length)
140
void Gzip_Compression::write(const byte input[], filter_length_t length)
141
   {
141
   {
142
142
143
   count += length;
143
   count += length;
Lines 152-158 void Gzip_Compression::write(const byte Link Here
152
      zlib->stream.avail_out = buffer.size();
152
      zlib->stream.avail_out = buffer.size();
153
      int rc = deflate(&(zlib->stream), Z_NO_FLUSH);
153
      int rc = deflate(&(zlib->stream), Z_NO_FLUSH);
154
      if (rc != Z_OK && rc != Z_STREAM_END)
154
      if (rc != Z_OK && rc != Z_STREAM_END)
155
         throw Exception("Internal error in Gzip_Compression deflate.");
155
         throw Invalid_State("Internal error in Gzip_Compression deflate.");
156
      send(buffer.begin(), buffer.size() - zlib->stream.avail_out);
156
      send(buffer.begin(), buffer.size() - zlib->stream.avail_out);
157
      }
157
      }
158
   }
158
   }
Lines 172-178 void Gzip_Compression::end_msg() Link Here
172
      zlib->stream.avail_out = buffer.size();
172
      zlib->stream.avail_out = buffer.size();
173
      rc = deflate(&(zlib->stream), Z_FINISH);
173
      rc = deflate(&(zlib->stream), Z_FINISH);
174
      if (rc != Z_OK && rc != Z_STREAM_END)
174
      if (rc != Z_OK && rc != Z_STREAM_END)
175
         throw Exception("Internal error in Gzip_Compression finishing deflate.");
175
         throw Invalid_State("Internal error in Gzip_Compression finishing deflate.");
176
      send(buffer.begin(), buffer.size() - zlib->stream.avail_out);
176
      send(buffer.begin(), buffer.size() - zlib->stream.avail_out);
177
      }
177
      }
178
178
Lines 228-234 Gzip_Decompression::Gzip_Decompression() Link Here
228
   no_writes(true), pipe(new Hash_Filter("CRC32")), footer(0)
228
   no_writes(true), pipe(new Hash_Filter("CRC32")), footer(0)
229
   {
229
   {
230
   if (DEFAULT_BUFFERSIZE < sizeof(GZIP::GZIP_HEADER))
230
   if (DEFAULT_BUFFERSIZE < sizeof(GZIP::GZIP_HEADER))
231
      throw Exception("DEFAULT_BUFFERSIZE is too small");
231
      throw Decoding_Error("DEFAULT_BUFFERSIZE is too small");
232
232
233
   zlib = new Zlib_Stream;
233
   zlib = new Zlib_Stream;
234
234
Lines 237-243 Gzip_Decompression::Gzip_Decompression() Link Here
237
   if(inflateInit2(&(zlib->stream), -15) != Z_OK)
237
   if(inflateInit2(&(zlib->stream), -15) != Z_OK)
238
      {
238
      {
239
      delete zlib; zlib = 0;
239
      delete zlib; zlib = 0;
240
      throw Exception("Gzip_Decompression: Memory allocation error");
240
      throw Memory_Exhaustion();
241
      }
241
      }
242
   }
242
   }
243
243
Lines 256-262 void Gzip_Decompression::start_msg() Link Here
256
void Gzip_Decompression::start_msg()
256
void Gzip_Decompression::start_msg()
257
   {
257
   {
258
   if (!no_writes)
258
   if (!no_writes)
259
      throw Exception("Gzip_Decompression: start_msg after already writing");
259
      throw Decoding_Error("Gzip_Decompression: start_msg after already writing");
260
260
261
   pipe.start_msg();
261
   pipe.start_msg();
262
   datacount = 0;
262
   datacount = 0;
Lines 267-273 void Gzip_Decompression::start_msg() Link Here
267
/*************************************************
267
/*************************************************
268
* Decompress Input with Gzip                     *
268
* Decompress Input with Gzip                     *
269
*************************************************/
269
*************************************************/
270
void Gzip_Decompression::write(const byte input[], u32bit length)
270
void Gzip_Decompression::write(const byte input[], filter_length_t length)
271
   {
271
   {
272
   if(length) no_writes = false;
272
   if(length) no_writes = false;
273
273
Lines 277-291 void Gzip_Decompression::write(const byt Link Here
277
         u32bit eat_len = eat_footer(input, length);
277
         u32bit eat_len = eat_footer(input, length);
278
         input += eat_len;
278
         input += eat_len;
279
         length -= eat_len;
279
         length -= eat_len;
280
         if (length == 0)
281
            return;
282
      }
280
      }
283
281
282
   if (length == 0)
283
     return;
284
284
   // Check the gzip header
285
   // Check the gzip header
285
   if (pos < sizeof(GZIP::GZIP_HEADER))
286
   if (pos < sizeof(GZIP::GZIP_HEADER))
286
      {
287
      {
287
      u32bit len = std::min((u32bit)sizeof(GZIP::GZIP_HEADER)-pos, length);
288
      filter_length_t len = std::min((filter_length_t)sizeof(GZIP::GZIP_HEADER)-pos, length);
288
      u32bit cmplen = len;
289
      filter_length_t cmplen = len;
289
      // The last byte is the OS flag - we don't care about that
290
      // The last byte is the OS flag - we don't care about that
290
      if (pos + len - 1 >= GZIP::HEADER_POS_OS)
291
      if (pos + len - 1 >= GZIP::HEADER_POS_OS)
291
         cmplen--;
292
         cmplen--;
Lines 317-324 void Gzip_Decompression::write(const byt Link Here
317
         if(rc == Z_NEED_DICT)
318
         if(rc == Z_NEED_DICT)
318
            throw Decoding_Error("Gzip_Decompression: Need preset dictionary");
319
            throw Decoding_Error("Gzip_Decompression: Need preset dictionary");
319
         if(rc == Z_MEM_ERROR)
320
         if(rc == Z_MEM_ERROR)
320
            throw Exception("Gzip_Decompression: Memory allocation error");
321
            throw Memory_Exhaustion();
321
         throw Exception("Gzip_Decompression: Unknown decompress error");
322
         throw Decoding_Error("Gzip_Decompression: Unknown decompress error");
322
         }
323
         }
323
      send(buffer.begin(), buffer.size() - zlib->stream.avail_out);
324
      send(buffer.begin(), buffer.size() - zlib->stream.avail_out);
324
      pipe.write(buffer.begin(), buffer.size() - zlib->stream.avail_out);
325
      pipe.write(buffer.begin(), buffer.size() - zlib->stream.avail_out);
Lines 346-353 u32bit Gzip_Decompression::eat_footer(co Link Here
346
      if (footer.size() >= GZIP::FOOTER_LENGTH)
347
      if (footer.size() >= GZIP::FOOTER_LENGTH)
347
         throw Decoding_Error("Gzip_Decompression: Data integrity error in footer");
348
         throw Decoding_Error("Gzip_Decompression: Data integrity error in footer");
348
349
350
#if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(1,9,11)
351
      size_t eat_len = std::min(GZIP::FOOTER_LENGTH-footer.size(),
352
                                static_cast<size_t>(length));
353
      footer += std::make_pair(input, eat_len);
354
#else
349
      u32bit eat_len = std::min(GZIP::FOOTER_LENGTH-footer.size(), length);
355
      u32bit eat_len = std::min(GZIP::FOOTER_LENGTH-footer.size(), length);
350
      footer.append(input, eat_len);
356
      footer.append(input, eat_len);
357
#endif
351
358
352
      if (footer.size() == GZIP::FOOTER_LENGTH)
359
      if (footer.size() == GZIP::FOOTER_LENGTH)
353
         {
360
         {
Lines 364-370 void Gzip_Decompression::check_footer() Link Here
364
void Gzip_Decompression::check_footer()
371
void Gzip_Decompression::check_footer()
365
   {
372
   {
366
   if (footer.size() != GZIP::FOOTER_LENGTH)
373
   if (footer.size() != GZIP::FOOTER_LENGTH)
367
      throw Exception("Gzip_Decompression: Error finalizing decompression");
374
      throw Decoding_Error("Gzip_Decompression: Error finalizing decompression");
368
375
369
   pipe.end_msg();
376
   pipe.end_msg();
370
377
Lines 377-383 void Gzip_Decompression::check_footer() Link Here
377
  for (int i = 0; i < 4; i++)
384
  for (int i = 0; i < 4; i++)
378
     buf[3-i] = tmpbuf[i];
385
     buf[3-i] = tmpbuf[i];
379
386
387
#if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(1,9,11)
388
  tmpbuf.resize(4);
389
  tmpbuf.copy(footer.begin(), 4);
390
#else
380
  tmpbuf.set(footer.begin(), 4);
391
  tmpbuf.set(footer.begin(), 4);
392
#endif
381
  if (buf != tmpbuf)
393
  if (buf != tmpbuf)
382
      throw Decoding_Error("Gzip_Decompression: Data integrity error - CRC32 error");
394
      throw Decoding_Error("Gzip_Decompression: Data integrity error - CRC32 error");
383
395
Lines 400-406 void Gzip_Decompression::end_msg() Link Here
400
   // read, clear() will reset no_writes
412
   // read, clear() will reset no_writes
401
   if(no_writes) return;
413
   if(no_writes) return;
402
414
403
   throw Exception("Gzip_Decompression: didn't find footer");
415
   throw Decoding_Error("Gzip_Decompression: didn't find footer");
404
416
405
   }
417
   }
406
418
Lines 412-418 void Gzip_Decompression::clear() Link Here
412
   no_writes = true;
424
   no_writes = true;
413
   inflateReset(&(zlib->stream));
425
   inflateReset(&(zlib->stream));
414
426
427
#if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(1,9,11)
428
   footer.clear();
429
#else
415
   footer.destroy();
430
   footer.destroy();
431
#endif
416
   pos = 0;
432
   pos = 0;
417
   datacount = 0;
433
   datacount = 0;
418
   }
434
   }
(-)src/gzip.hh (-2 / +15 lines)
Lines 7-17 Link Here
7
#ifndef BOTAN_EXT_GZIP_H__
7
#ifndef BOTAN_EXT_GZIP_H__
8
#define BOTAN_EXT_GZIP_H__
8
#define BOTAN_EXT_GZIP_H__
9
9
10
#include <botan/version.h>
10
#include <botan/filter.h>
11
#include <botan/filter.h>
11
#include <botan/pipe.h>
12
#include <botan/pipe.h>
12
13
13
namespace Botan {
14
namespace Botan {
14
15
16
#if BOTAN_VERSION_CODE < BOTAN_VERSION_CODE_FOR(1,9,4)
17
// Only 1.9.4 and newer export the Memory_Exception. Give this gzip
18
// implementation something compatible to work with.
19
typedef std::bad_alloc Memory_Exhaustion;
20
#endif
21
15
namespace GZIP {
22
namespace GZIP {
16
23
17
   /* A basic header - we only need to set the IDs and compression method */
24
   /* A basic header - we only need to set the IDs and compression method */
Lines 30-42 namespace GZIP { Link Here
30
37
31
}
38
}
32
39
40
#if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(1,9,11)
41
typedef size_t filter_length_t;
42
#else
43
typedef u32bit filter_length_t;
44
#endif
45
33
/*************************************************
46
/*************************************************
34
* Gzip Compression Filter                        *
47
* Gzip Compression Filter                        *
35
*************************************************/
48
*************************************************/
36
class Gzip_Compression : public Filter
49
class Gzip_Compression : public Filter
37
   {
50
   {
38
   public:
51
   public:
39
      void write(const byte input[], u32bit length);
52
      void write(const byte input[], filter_length_t length);
40
      void start_msg();
53
      void start_msg();
41
      void end_msg();
54
      void end_msg();
42
      std::string name() const { return "Gzip_Compression"; }
55
      std::string name() const { return "Gzip_Compression"; }
Lines 60-66 class Gzip_Decompression : public Filter Link Here
60
class Gzip_Decompression : public Filter
73
class Gzip_Decompression : public Filter
61
   {
74
   {
62
   public:
75
   public:
63
      void write(const byte input[], u32bit length);
76
      void write(const byte input[], filter_length_t length);
64
      void start_msg();
77
      void start_msg();
65
      void end_msg();
78
      void end_msg();
66
      std::string name() const { return "Gzip_Decompression"; }
79
      std::string name() const { return "Gzip_Decompression"; }
(-)src/key_packet.cc (-2 / +2 lines)
Lines 106-113 namespace Link Here
106
    void validate_public_key_data(string const & name, string const & keydata) const
106
    void validate_public_key_data(string const & name, string const & keydata) const
107
    {
107
    {
108
      string decoded = decode_base64_as<string>(keydata, origin::user);
108
      string decoded = decode_base64_as<string>(keydata, origin::user);
109
      Botan::SecureVector<Botan::byte> key_block;
109
      Botan::SecureVector<Botan::byte> key_block
110
      key_block.set(reinterpret_cast<Botan::byte const *>(decoded.c_str()), decoded.size());
110
        (reinterpret_cast<Botan::byte const *>(decoded.c_str()), decoded.size());
111
      try
111
      try
112
        {
112
        {
113
          Botan::X509::load_key(key_block);
113
          Botan::X509::load_key(key_block);
(-)src/key_store.cc (-7 / +34 lines)
Lines 572-584 key_store_state::decrypt_private_key(key Link Here
572
  try // with empty passphrase
572
  try // with empty passphrase
573
    {
573
    {
574
      Botan::DataSource_Memory ds(kp.priv());
574
      Botan::DataSource_Memory ds(kp.priv());
575
#if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(1,7,7)
575
#if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(1,9,11)
576
      pkcs8_key.reset(Botan::PKCS8::load_key(ds, lazy_rng::get(), Dummy_UI()));
577
#elif BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(1,7,7)
576
      pkcs8_key.reset(Botan::PKCS8::load_key(ds, lazy_rng::get(), ""));
578
      pkcs8_key.reset(Botan::PKCS8::load_key(ds, lazy_rng::get(), ""));
577
#else
579
#else
578
      pkcs8_key.reset(Botan::PKCS8::load_key(ds, ""));
580
      pkcs8_key.reset(Botan::PKCS8::load_key(ds, ""));
579
#endif
581
#endif
580
    }
582
    }
583
#if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(1,9,11)
584
  catch (Passphrase_Required & e)
585
#elif BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(1,9,4)
586
  catch (Botan::Invalid_Argument & e)
587
#else
581
  catch (Botan::Exception & e)
588
  catch (Botan::Exception & e)
589
#endif
582
    {
590
    {
583
      L(FL("failed to load key with no passphrase: %s") % e.what());
591
      L(FL("failed to load key with no passphrase: %s") % e.what());
584
592
Lines 605-617 key_store_state::decrypt_private_key(key Link Here
605
          {
613
          {
606
            Botan::DataSource_Memory ds(kp.priv());
614
            Botan::DataSource_Memory ds(kp.priv());
607
#if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(1,7,7)
615
#if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(1,7,7)
608
            pkcs8_key.reset(Botan::PKCS8::load_key(ds, lazy_rng::get(), phrase()));
616
            pkcs8_key.reset(Botan::PKCS8::load_key(ds, lazy_rng::get(),
617
                                                   phrase()));
609
#else
618
#else
610
            pkcs8_key.reset(Botan::PKCS8::load_key(ds, phrase()));
619
            pkcs8_key.reset(Botan::PKCS8::load_key(ds, phrase()));
611
#endif
620
#endif
612
            break;
621
            break;
613
          }
622
          }
623
#if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(1,9,4)
624
        catch (Botan::Invalid_Argument)
625
#else
614
        catch (Botan::Exception & e)
626
        catch (Botan::Exception & e)
627
#endif
615
          {
628
          {
616
            cycles++;
629
            cycles++;
617
            L(FL("decrypt_private_key: failure %d to load encrypted key: %s")
630
            L(FL("decrypt_private_key: failure %d to load encrypted key: %s")
Lines 822-831 key_store::decrypt_rsa(key_id const & id Link Here
822
      plaintext = string(reinterpret_cast<char const*>(plain.begin()),
835
      plaintext = string(reinterpret_cast<char const*>(plain.begin()),
823
                         plain.size());
836
                         plain.size());
824
    }
837
    }
825
  catch (Botan::Exception & ex)
838
#if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(1,9,4)
839
  catch (std::exception & e)
840
#else
841
  catch (Botan::Exception & e)
842
#endif
826
    {
843
    {
827
      E(false, ciphertext.made_from,
844
      E(false, ciphertext.made_from,
828
        F("Botan error decrypting data: '%s'") % ex.what());
845
        F("Botan error decrypting data: '%s'") % e.what());
829
    }
846
    }
830
}
847
}
831
848
Lines 856-864 key_store::make_signature(database & db, Link Here
856
    {
873
    {
857
      if (agent.connected()) {
874
      if (agent.connected()) {
858
        //grab the monotone public key as an RSA_PublicKey
875
        //grab the monotone public key as an RSA_PublicKey
859
        SecureVector<Botan::byte> pub_block;
876
        SecureVector<Botan::byte> pub_block
860
        pub_block.set(reinterpret_cast<Botan::byte const *>(key.pub().data()),
877
          (reinterpret_cast<Botan::byte const *>(key.pub().data()),
861
                      key.pub().size());
878
           key.pub().size());
862
        L(FL("make_signature: building %d-byte pub key") % pub_block.size());
879
        L(FL("make_signature: building %d-byte pub key") % pub_block.size());
863
        shared_ptr<X509_PublicKey> x509_key =
880
        shared_ptr<X509_PublicKey> x509_key =
864
          shared_ptr<X509_PublicKey>(Botan::X509::load_key(pub_block));
881
          shared_ptr<X509_PublicKey>(Botan::X509::load_key(pub_block));
Lines 1031-1038 key_store_state::migrate_old_key_pair Link Here
1031
  for (;;)
1048
  for (;;)
1032
    try
1049
    try
1033
      {
1050
      {
1051
#if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(1,9,11)
1052
        arc4_key.resize(phrase().size());
1053
        arc4_key.copy(reinterpret_cast<Botan::byte const *>(phrase().data()),
1054
                      phrase().size());
1055
#else
1034
        arc4_key.set(reinterpret_cast<Botan::byte const *>(phrase().data()),
1056
        arc4_key.set(reinterpret_cast<Botan::byte const *>(phrase().data()),
1035
                     phrase().size());
1057
                     phrase().size());
1058
#endif
1036
1059
1037
        Pipe arc4_decryptor(get_cipher("ARC4", arc4_key, Botan::DECRYPTION));
1060
        Pipe arc4_decryptor(get_cipher("ARC4", arc4_key, Botan::DECRYPTION));
1038
1061
Lines 1051-1057 key_store_state::migrate_old_key_pair Link Here
1051
#endif
1074
#endif
1052
        break;
1075
        break;
1053
      }
1076
      }
1077
#if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(1,9,4)
1078
    catch (Botan::Invalid_Argument & e)
1079
#else
1054
    catch (Botan::Exception & e)
1080
    catch (Botan::Exception & e)
1081
#endif
1055
      {
1082
      {
1056
        L(FL("migrate_old_key_pair: failure %d to load old private key: %s")
1083
        L(FL("migrate_old_key_pair: failure %d to load old private key: %s")
1057
          % cycles % e.what());
1084
          % cycles % e.what());
(-)src/monotone.cc (-15 / +41 lines)
Lines 156-182 cpp_main(int argc, char ** argv) Link Here
156
      E(linked_botan_version != BOTAN_VERSION_CODE_FOR(1,7,14), origin::system,
156
      E(linked_botan_version != BOTAN_VERSION_CODE_FOR(1,7,14), origin::system,
157
        F("monotone does not support Botan 1.7.14"));
157
        F("monotone does not support Botan 1.7.14"));
158
158
159
#if BOTAN_VERSION_CODE <= BOTAN_VERSION_CODE_FOR(1,7,6)
159
      // In Botan 1.9.9, the DataSink_Stream cannot be instantiated per
160
      // se. As 1.10.1 is already out, let's simply disable support for
161
      // that specific (testing) version of botan.
162
      E(linked_botan_version != BOTAN_VERSION_CODE_FOR(1,9,9), origin::system,
163
        F("monotone does not support Botan 1.9.9"));
164
165
#if BOTAN_VERSION_CODE < BOTAN_VERSION_CODE_FOR(1,7,7)
166
      // motonote binary compiled against botan younger than 1.7.7
160
      E(linked_botan_version >= BOTAN_VERSION_CODE_FOR(1,6,3), origin::system,
167
      E(linked_botan_version >= BOTAN_VERSION_CODE_FOR(1,6,3), origin::system,
161
        F("this monotone binary requires Botan 1.6.3 or newer"));
168
        F("this monotone binary requires Botan 1.6.3 or newer"));
162
      E(linked_botan_version <= BOTAN_VERSION_CODE_FOR(1,7,6), origin::system,
169
      E(linked_botan_version < BOTAN_VERSION_CODE_FOR(1,7,7), origin::system,
163
        F("this monotone binary does not work with Botan newer than 1.7.6"));
170
        F("this monotone binary does not work with Botan 1.7.7 or newer"));
164
#elif BOTAN_VERSION_CODE <= BOTAN_VERSION_CODE_FOR(1,7,22)
171
165
      E(linked_botan_version > BOTAN_VERSION_CODE_FOR(1,7,6), origin::system,
172
#elif BOTAN_VERSION_CODE < BOTAN_VERSION_CODE_FOR(1,7,22)
173
      // motonote binary compiled against botan 1.7.7 - 1.7.21
174
      E(linked_botan_version >= BOTAN_VERSION_CODE_FOR(1,7,7), origin::system,
166
        F("this monotone binary requires Botan 1.7.7 or newer"));
175
        F("this monotone binary requires Botan 1.7.7 or newer"));
167
      // While compiling against 1.7.22 or newer is recommended, because
176
      // While compiling against 1.7.22 or newer is recommended, because it
168
      // it enables new features of Botan, the monotone binary compiled
177
      // enables new features of Botan, the monotone binary compiled against
169
      // against Botan 1.7.21 and before should still work with newer Botan
178
      // Botan 1.7.21 and before should still work with newer Botan version,
170
      // versions, including all of the stable branch 1.8.x.
179
      // including all of the stable branch 1.8.x, up to and including
171
      E(linked_botan_version < BOTAN_VERSION_CODE_FOR(1,9,0), origin::system,
180
      // 1.9.3.
172
        F("this monotone binary does not work with Botan 1.9.x"));
181
      E(linked_botan_version < BOTAN_VERSION_CODE_FOR(1,9,4), origin::system,
173
#else
182
        F("this monotone binary does not work with Botan 1.9.4 or newer"));
174
      E(linked_botan_version > BOTAN_VERSION_CODE_FOR(1,7,22), origin::system,
183
184
#elif BOTAN_VERSION_CODE < BOTAN_VERSION_CODE_FOR(1,9,4)
185
      // motonote binary compiled against botan 1.7.22 - 1.9.3
186
      E(linked_botan_version >= BOTAN_VERSION_CODE_FOR(1,7,22), origin::system,
175
        F("this monotone binary requires Botan 1.7.22 or newer"));
187
        F("this monotone binary requires Botan 1.7.22 or newer"));
176
      E(linked_botan_version < BOTAN_VERSION_CODE_FOR(1,9,0), origin::system,
188
      E(linked_botan_version < BOTAN_VERSION_CODE_FOR(1,9,4), origin::system,
177
        F("this monotone binary does not work with Botan 1.9.x"));
189
        F("this monotone binary does not work with Botan 1.9.4 or newer"));
190
191
#elif BOTAN_VERSION_CODE < BOTAN_VERSION_CODE_FOR(1,9,11)
192
      // motonote binary compiled against botan 1.9.4 - 1.9.10
193
#pragma message ( "The resulting monotone binary won't be able to run with any stable release of botan." )
194
      E(linked_botan_version >= BOTAN_VERSION_CODE_FOR(1,9,4), origin::system,
195
        F("this monotone binary requires Botan 1.9.4 or newer"));
196
      E(linked_botan_version < BOTAN_VERSION_CODE_FOR(1,9,11), origin::system,
197
        F("this monotone binary does not work with Botan 1.9.11 or newer"));
198
199
#else
200
      // motonote binary compiled against botan 1.9.11 and newer
201
      E(linked_botan_version >= BOTAN_VERSION_CODE_FOR(1,9,11), origin::system,
202
        F("this monotone binary requires Botan 1.9.11 or newer"));
178
#endif
203
#endif
179
204
205
180
      app_state app;
206
      app_state app;
181
      try
207
      try
182
        {
208
        {
(-)src/packet.cc (-4 / +18 lines)
Lines 156-163 namespace Link Here
156
    void validate_public_key_data(string const & name, string const & keydata) const
156
    void validate_public_key_data(string const & name, string const & keydata) const
157
    {
157
    {
158
      string decoded = decode_base64_as<string>(keydata, origin::user);
158
      string decoded = decode_base64_as<string>(keydata, origin::user);
159
      Botan::SecureVector<Botan::byte> key_block;
159
      Botan::SecureVector<Botan::byte> key_block
160
      key_block.set(reinterpret_cast<Botan::byte const *>(decoded.c_str()), decoded.size());
160
        (reinterpret_cast<Botan::byte const *>(decoded.c_str()), decoded.size());
161
      try
161
      try
162
        {
162
        {
163
          Botan::X509::load_key(key_block);
163
          Botan::X509::load_key(key_block);
Lines 175-181 namespace Link Here
175
      Botan::DataSource_Memory ds(decoded);
175
      Botan::DataSource_Memory ds(decoded);
176
      try
176
      try
177
        {
177
        {
178
#if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(1,7,7)
178
#if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(1,9,11)
179
          Botan::PKCS8::load_key(ds, lazy_rng::get(), Dummy_UI());
180
#elif BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(1,7,7)
179
          Botan::PKCS8::load_key(ds, lazy_rng::get(), string());
181
          Botan::PKCS8::load_key(ds, lazy_rng::get(), string());
180
#else
182
#else
181
          Botan::PKCS8::load_key(ds, string());
183
          Botan::PKCS8::load_key(ds, string());
Lines 189-195 namespace Link Here
189
        }
191
        }
190
      // since we do not want to prompt for a password to decode it finally,
192
      // since we do not want to prompt for a password to decode it finally,
191
      // we ignore all other exceptions
193
      // we ignore all other exceptions
194
#if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(1,9,11)
195
      catch (Passphrase_Required) {}
196
#else
192
      catch (Botan::Invalid_Argument) {}
197
      catch (Botan::Invalid_Argument) {}
198
#endif
193
    }
199
    }
194
    void validate_certname(string const & cn) const
200
    void validate_certname(string const & cn) const
195
    {
201
    {
Lines 460-467 read_packets(istream & in, packet_consum Link Here
460
  return count;
466
  return count;
461
}
467
}
462
468
469
// Dummy User_Interface implementation for Botan
470
#if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(1,9,11)
471
std::string
472
Dummy_UI::get_passphrase(const std::string &, const std::string &,
473
                         Botan::User_Interface::UI_Result&) const
474
{
475
  throw Passphrase_Required("Passphrase required");
476
}
477
#endif
463
478
464
465
// Local Variables:
479
// Local Variables:
466
// mode: C++
480
// mode: C++
467
// fill-column: 76
481
// fill-column: 76
(-)src/packet.hh (+19 lines)
Lines 10-15 Link Here
10
#ifndef __PACKET_HH__
10
#ifndef __PACKET_HH__
11
#define __PACKET_HH__
11
#define __PACKET_HH__
12
12
13
#if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(1,9,11)
14
#include <botan/ui.h>
15
#endif
16
13
#include "vocab.hh"
17
#include "vocab.hh"
14
18
15
struct cert;
19
struct cert;
Lines 84-91 size_t read_packets(std::istream & in, p Link Here
84
88
85
size_t read_packets(std::istream & in, packet_consumer & cons);
89
size_t read_packets(std::istream & in, packet_consumer & cons);
86
90
91
#if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(1,9,11)
92
// A helper class implementing Botan::User_Interface - which doesn't really
93
// interface with the user, but provides the necessary plumbing for Botan.
94
//
95
// See Botan commit 2d09d7d0cd4bd0e7155d001dd65a4f29103b158c
96
typedef std::runtime_error Passphrase_Required;
97
98
class Dummy_UI : public Botan::User_Interface
99
{
100
public:
101
  virtual std::string get_passphrase(const std::string &, const std::string &,
102
                                     Botan::User_Interface::UI_Result &) const;
103
};
87
#endif
104
#endif
88
105
106
#endif
107
89
// Local Variables:
108
// Local Variables:
90
// mode: C++
109
// mode: C++
91
// fill-column: 76
110
// fill-column: 76
(-)src/sha1.cc (-1 / +4 lines)
Lines 50-58 CMD_HIDDEN(benchmark_sha1, "benchmark_sh Link Here
50
  Botan::Default_Benchmark_Timer timer;
50
  Botan::Default_Benchmark_Timer timer;
51
  std::map<std::string, double> results =
51
  std::map<std::string, double> results =
52
    Botan::algorithm_benchmark("SHA-1",  milliseconds, timer, rng, af);
52
    Botan::algorithm_benchmark("SHA-1",  milliseconds, timer, rng, af);
53
#elif BOTAN_VERSION_CODE < BOTAN_VERSION_CODE_FOR(1,9,11)
54
  std::map<std::string, double> results =
55
    Botan::algorithm_benchmark("SHA-1",  milliseconds, rng, af);
53
#else
56
#else
54
  std::map<std::string, double> results =
57
  std::map<std::string, double> results =
55
    Botan::algorithm_benchmark("SHA-1",  milliseconds, rng, af);
58
    Botan::algorithm_benchmark("SHA-1",  af, rng, milliseconds, 16);
56
#endif
59
#endif
57
60
58
  for(std::map<std::string, double>::const_iterator i = results.begin();
61
  for(std::map<std::string, double>::const_iterator i = results.begin();
(-)src/ssh_agent.cc (-3 / +3 lines)
Lines 385-393 ssh_agent::has_key(const keypair & key) Link Here
385
ssh_agent::has_key(const keypair & key)
385
ssh_agent::has_key(const keypair & key)
386
{
386
{
387
  //grab the monotone public key as an RSA_PublicKey
387
  //grab the monotone public key as an RSA_PublicKey
388
  SecureVector<Botan::byte> pub_block;
388
  SecureVector<Botan::byte> pub_block
389
  pub_block.set(reinterpret_cast<Botan::byte const *>((key.pub)().data()),
389
    (reinterpret_cast<Botan::byte const *>((key.pub)().data()),
390
                (key.pub)().size());
390
     (key.pub)().size());
391
  L(FL("has_key: building %d-byte pub key") % pub_block.size());
391
  L(FL("has_key: building %d-byte pub key") % pub_block.size());
392
  shared_ptr<X509_PublicKey> x509_key =
392
  shared_ptr<X509_PublicKey> x509_key =
393
    shared_ptr<X509_PublicKey>(Botan::X509::load_key(pub_block));
393
    shared_ptr<X509_PublicKey>(Botan::X509::load_key(pub_block));
(-)src/transforms.cc (-7 / +8 lines)
Lines 53-67 using Botan::Hash_Filter; Link Here
53
// paradigm "must" be used. this program is intended for source code
53
// paradigm "must" be used. this program is intended for source code
54
// control and I make no bones about it.
54
// control and I make no bones about it.
55
55
56
NORETURN(static inline void error_in_transform(Botan::Exception & e));
56
NORETURN(static inline void error_in_transform(std::exception & e));
57
57
58
static inline void
58
static inline void
59
error_in_transform(Botan::Exception & e, origin::type caused_by)
59
error_in_transform(std::exception & e, origin::type caused_by)
60
{
60
{
61
  // these classes can all indicate data corruption
61
  // these classes can all indicate data corruption
62
  if (typeid(e) == typeid(Botan::Encoding_Error)
62
  if (typeid(e) == typeid(Botan::Encoding_Error)
63
      || typeid(e) == typeid(Botan::Decoding_Error)
63
      || typeid(e) == typeid(Botan::Decoding_Error)
64
      || typeid(e) == typeid(Botan::Stream_IO_Error)
64
      || typeid(e) == typeid(Botan::Stream_IO_Error)
65
      || typeid(e) == typeid(Botan::Invalid_Argument)
65
      || typeid(e) == typeid(Botan::Integrity_Failure))
66
      || typeid(e) == typeid(Botan::Integrity_Failure))
66
    {
67
    {
67
      // clean up the what() string a little: throw away the
68
      // clean up the what() string a little: throw away the
Lines 107-113 error_in_transform(Botan::Exception & e, Link Here
107
        pipe->process_msg(in);                                  \
108
        pipe->process_msg(in);                                  \
108
        out = pipe->read_all_as_string(Pipe::LAST_MESSAGE);     \
109
        out = pipe->read_all_as_string(Pipe::LAST_MESSAGE);     \
109
      }                                                         \
110
      }                                                         \
110
    catch (Botan::Exception & e)                                \
111
    catch (std::exception & e)                                   \
111
      {                                                         \
112
      {                                                         \
112
        pipe.reset(new Pipe(new T(carg)));                      \
113
        pipe.reset(new Pipe(new T(carg)));                      \
113
        error_in_transform(e, made_from);                       \
114
        error_in_transform(e, made_from);                       \
Lines 173-179 template<> string xform<Botan::Hex_Decod Link Here
173
            {
174
            {
174
              throw Botan::Decoding_Error(string("invalid hex character '") + (char)c + "'");
175
              throw Botan::Decoding_Error(string("invalid hex character '") + (char)c + "'");
175
            }
176
            }
176
          catch(Botan::Exception & e)
177
          catch(std::exception & e)
177
            {
178
            {
178
              error_in_transform(e, made_from);
179
              error_in_transform(e, made_from);
179
            }
180
            }
Lines 219-225 void pack(T const & in, base64< gzip<T> Link Here
219
      tmp = pipe->read_all_as_string(Pipe::LAST_MESSAGE);
220
      tmp = pipe->read_all_as_string(Pipe::LAST_MESSAGE);
220
      out = base64< gzip<T> >(tmp, in.made_from);
221
      out = base64< gzip<T> >(tmp, in.made_from);
221
    }
222
    }
222
  catch (Botan::Exception & e)
223
  catch (std::exception & e)
223
    {
224
    {
224
      pipe.reset(new Pipe(new Gzip_Compression,
225
      pipe.reset(new Pipe(new Gzip_Compression,
225
                          new Base64_Encoder));
226
                          new Base64_Encoder));
Lines 237-243 void unpack(base64< gzip<T> > const & in Link Here
237
      pipe->process_msg(in());
238
      pipe->process_msg(in());
238
      out = T(pipe->read_all_as_string(Pipe::LAST_MESSAGE), in.made_from);
239
      out = T(pipe->read_all_as_string(Pipe::LAST_MESSAGE), in.made_from);
239
    }
240
    }
240
  catch (Botan::Exception & e)
241
  catch (std::exception & e)
241
    {
242
    {
242
      pipe.reset(new Pipe(new Base64_Decoder,
243
      pipe.reset(new Pipe(new Base64_Decoder,
243
                          new Gzip_Decompression));
244
                          new Gzip_Decompression));
Lines 264-270 calculate_ident(data const & dat, Link Here
264
      p->process_msg(dat());
265
      p->process_msg(dat());
265
      ident = id(p->read_all_as_string(Pipe::LAST_MESSAGE), dat.made_from);
266
      ident = id(p->read_all_as_string(Pipe::LAST_MESSAGE), dat.made_from);
266
    }
267
    }
267
  catch (Botan::Exception & e)
268
  catch (std::exception & e)
268
    {
269
    {
269
      p.reset(new Pipe(new Hash_Filter("SHA-160")));
270
      p.reset(new Pipe(new Hash_Filter("SHA-160")));
270
      error_in_transform(e, dat.made_from);
271
      error_in_transform(e, dat.made_from);

Return to bug 380257