Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Static Public Member Functions | List of all members
Botan::TLS::Signature_Algorithms Class Referencefinal

`#include <tls_extensions.h>`

Inheritance diagram for Botan::TLS::Signature_Algorithms:

## Public Member Functions
bool | empty () const override
std::vector< uint8_t > | serialize () const override
| Signature_Algorithms (const std::vector< std::string > &hashes, const std::vector< std::string > &sig_algos)
| Signature_Algorithms (const std::vector< std::pair< std::string, std::string >> &algos)
| Signature_Algorithms (TLS_Data_Reader &reader, uint16_t extension_size)
const std::vector< std::pair< std::string, std::string > > & | supported_signature_algorthms () const
Handshake_Extension_Type | type () const override

## Static Public Member Functions
static uint8_t | hash_algo_code (const std::string &name)
static std::string | hash_algo_name (uint8_t code)
static uint8_t | sig_algo_code (const std::string &name)
static std::string | sig_algo_name (uint8_t code)
static Handshake_Extension_Type | static_type ()

## Detailed Description

Signature Algorithms Extension for TLS 1.2 (RFC 5246)

Definition at line 294 of file tls_extensions.h.

## Constructor & Destructor Documentation

Botan::TLS::Signature_Algorithms::Signature_Algorithms | ( | const std::vector< std::string > & | hashes,
|  | const std::vector< std::string > & | sig_algos
| ) |  |

Definition at line 519 of file tls_extensions.cpp.

521 {
522 for(size_t i = 0; i != hashes.size(); ++i)
523 for(size_t j = 0; j != sigs.size(); ++j)
524 m_supported_algos.push_back(std::make_pair(hashes[i], sigs[j]));
525 }

Botan::TLS::Signature_Algorithms::Signature_Algorithms | ( | const std::vector< std::pair< std::string, std::string >> & | algos | ) |
| inline explicit

Definition at line 322 of file tls_extensions.h.

322 :
323 m_supported_algos(algos) {}

Botan::TLS::Signature_Algorithms::Signature_Algorithms | ( | TLS_Data_Reader & | reader,
|  | uint16_t | extension_size
| ) |  |

Definition at line 527 of file tls_extensions.cpp.

References Botan::TLS::Alert::DECODE_ERROR, Botan::TLS::TLS_Data_Reader::get_byte(), Botan::TLS::TLS_Data_Reader::get_uint16_t(), hash_algo_name(), and sig_algo_name().

529 {
530 uint16_t len = reader.get_uint16_t();
531
532 if(len + 2 != extension_size)
533 throw Decoding_Error("Bad encoding on signature algorithms extension");
534
535 while(len)
536 {
537 const uint8_t hash_code = reader.get_byte();
538 const uint8_t sig_code = reader.get_byte();
539 len -= 2;
540
541 if(sig_code == 0)
542 {
543 /*
544 RFC 5247 7.4.1.4.1 explicitly prohibits anonymous (0) signature code in
545 the client hello. ("It MUST NOT appear in this extension.")
546 */
547 throw TLS_Exception(Alert::DECODE_ERROR, "Client sent ANON signature");
548 }
549
550 const std::string hash_name = hash_algo_name(hash_code);
551 const std::string sig_name = sig_algo_name(sig_code);
552
553 // If not something we know, ignore it completely
554 if(hash_name.empty() || sig_name.empty())
555 continue;
556
557 m_supported_algos.push_back(std::make_pair(hash_name, sig_name));
558 }
559 }
Botan::TLS::Alert::DECODE_ERROR
Definition: tls_alert.h:44
Botan::TLS::Signature_Algorithms::sig_algo_name
static std::string sig_algo_name(uint8_t code)
Definition: tls_extensions.cpp:466
Botan::TLS::Signature_Algorithms::hash_algo_name
static std::string hash_algo_name(uint8_t code)
Definition: tls_extensions.cpp:427

## Member Function Documentation

bool Botan::TLS::Signature_Algorithms::empty | ( |  | ) | const
| inline override virtual

Returns
  if we should encode this extension or not

Implements Botan::TLS::Extension.

Definition at line 317 of file tls_extensions.h.

317 { return false; }

uint8_t Botan::TLS::Signature_Algorithms::hash_algo_code | ( | const std::string & | name | ) |
| static

Definition at line 449 of file tls_extensions.cpp.

Referenced by serialize().

450 {
451 if(name == "SHA-1")
452 return 2;
453
454 if(name == "SHA-256")
455 return 4;
456
457 if(name == "SHA-384")
458 return 5;
459
460 if(name == "SHA-512")
461 return 6;
462
463 throw Internal_Error("Unknown hash ID " + name + " for signature_algorithms");
464 }

std::string Botan::TLS::Signature_Algorithms::hash_algo_name | ( | uint8_t | code | ) |
| static

Definition at line 427 of file tls_extensions.cpp.

Referenced by Botan::TLS::Certificate_Req::Certificate_Req(), Botan::TLS::Certificate_Verify::Certificate_Verify(), Botan::TLS::Server_Key_Exchange::Server_Key_Exchange(), and Signature_Algorithms().

428 {
429 switch(code)
430 {
431 // code 1 is MD5 - ignore it
432
433 case 2:
434 return "SHA-1";
435
436 // code 3 is SHA-224
437
438 case 4:
439 return "SHA-256";
440 case 5:
441 return "SHA-384";
442 case 6:
443 return "SHA-512";
444 default:
445 return "";
446 }
447 }

std::vector< uint8_t > Botan::TLS::Signature_Algorithms::serialize | ( |  | ) | const
| override virtual

Returns
  serialized binary for the extension

Implements Botan::TLS::Extension.

Definition at line 495 of file tls_extensions.cpp.

References Botan::get_byte(), hash_algo_code(), and sig_algo_code().

496 {
497 std::vector<uint8_t> buf(2);
498
499 for(size_t i = 0; i != m_supported_algos.size(); ++i)
500 {
501 try
502 {
503 const uint8_t hash_code = hash_algo_code(m_supported_algos[i].first);
504 const uint8_t sig_code = sig_algo_code(m_supported_algos[i].second);
505
506 buf.push_back(hash_code);
507 buf.push_back(sig_code);
508 }
509 catch(...)
510 {}
511 }
512
513 buf[0] = get_byte(0, static_cast<uint16_t>(buf.size()-2));
514 buf[1] = get_byte(1, static_cast<uint16_t>(buf.size()-2));
515
516 return buf;
517 }
Botan::TLS::Signature_Algorithms::sig_algo_code
static uint8_t sig_algo_code(const std::string &name)
Definition: tls_extensions.cpp:481
Botan::TLS::Signature_Algorithms::hash_algo_code
static uint8_t hash_algo_code(const std::string &name)
Definition: tls_extensions.cpp:449
Botan::get_byte
uint8_t get_byte(size_t byte_num, T input)
Definition: loadstor.h:47

uint8_t Botan::TLS::Signature_Algorithms::sig_algo_code | ( | const std::string & | name | ) |
| static

Definition at line 481 of file tls_extensions.cpp.

Referenced by serialize().

482 {
483 if(name == "RSA")
484 return 1;
485
486 if(name == "DSA")
487 return 2;
488
489 if(name == "ECDSA")
490 return 3;
491
492 throw Internal_Error("Unknown sig ID " + name + " for signature_algorithms");
493 }

std::string Botan::TLS::Signature_Algorithms::sig_algo_name | ( | uint8_t | code | ) |
| static

Definition at line 466 of file tls_extensions.cpp.

Referenced by Botan::TLS::Certificate_Req::Certificate_Req(), Botan::TLS::Certificate_Verify::Certificate_Verify(), Botan::TLS::Server_Key_Exchange::Server_Key_Exchange(), and Signature_Algorithms().

467 {
468 switch(code)
469 {
470 case 1:
471 return "RSA";
472 case 2:
473 return "DSA";
474 case 3:
475 return "ECDSA";
476 default:
477 return "";
478 }
479 }

static Handshake_Extension_Type Botan::TLS::Signature_Algorithms::static_type | ( |  | ) |
| inline static

Definition at line 297 of file tls_extensions.h.

References Botan::TLS::TLSEXT_SIGNATURE_ALGORITHMS.

Referenced by type().

298 { return TLSEXT_SIGNATURE_ALGORITHMS; }
Botan::TLS::TLSEXT_SIGNATURE_ALGORITHMS
Definition: tls_extensions.h:35

const std::vector<std::pair<std::string, std::string> >& Botan::TLS::Signature_Algorithms::supported_signature_algorthms | ( |  | ) | const
| inline

Definition at line 310 of file tls_extensions.h.

311 {
312 return m_supported_algos;
313 }

Handshake_Extension_Type Botan::TLS::Signature_Algorithms::type | ( |  | ) | const
| inline override virtual

Returns
  code number of the extension

Implements Botan::TLS::Extension.

Definition at line 300 of file tls_extensions.h.

References static_type().

300 { return static_type(); }
Botan::TLS::Signature_Algorithms::static_type
static Handshake_Extension_Type static_type()
Definition: tls_extensions.h:297

The documentation for this class was generated from the following files:

- src/lib/tls/tls_extensions.h
- src/lib/tls/tls_extensions.cpp