E-MailRelay

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

gcram.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2018 Graeme Walker <graeme_walker@users.sourceforge.net>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 // ===
17 ///
18 /// \file gcram.h
19 ///
20
21 #ifndef G_AUTH_CRAM__H
22 #define G_AUTH_CRAM__H
23
24 #include "gdef.h"
25 #include "gstrings.h"
26 #include "gsecret.h"
27 #include "gexception.h"
28 #include <string>
29
30 namespace GAuth
31 {
32 class Cram ;
33 }
34
35 /// \class GAuth::Cram
36 /// Implements the standard challenge-response authentication
37 /// mechanism of RFC-2195.
38 ///
39 class GAuth::Cram
40 {
41 public:
42 G_EXCEPTION( BadType , "invalid secret type" ) ;
43 G_EXCEPTION( Mismatch , "mismatched hash types" ) ;
44 G_EXCEPTION( NoState , "no implementation for extracting hash function state" ) ;
45
46 static std::string response( const std::string & hash_type , bool hmac ,
47 const Secret & secret , const std::string & challenge ,
48 const std::string & response_prefix ) ;
49 ///< Constructs a response to a challenge comprising the
50 ///< response-prefix, space, and digest-or-hmac of
51 ///< key-plus-challenge. Returns an empty string on
52 ///< error; does not throw.
53
54 static std::string id( const std::string & response ) ;
55 ///< Returns the leading id part of the response. Returns
56 ///< the empty string on error.
57
58 static bool validate( const std::string & hash_type , bool hmac ,
59 const Secret & secret , const std::string & challenge ,
60 const std::string & response ) ;
61 ///< Validates the response with respect to the original
62 ///< challenge. Returns false on error; does not throw.
63
64 static G::StringArray hashTypes( const std::string & prefix = std::string() , bool require_state = false ) ;
65 ///< Returns a list of supported hash types, such as "MD5"
66 ///< and "SHA1", ordered with the strongest first. Optionally
67 ///< adds a prefix to each type, and optionally limits the
68 ///< list to those hash functions that support initialisation
69 ///< with intermediate state.
70
71 static std::string challenge() ;
72 ///< Returns a challenge string that incorporates a random number
73 ///< and the current time.
74
75 private:
76 static std::string responseImp( const std::string & , bool , const Secret & , const std::string & ) ;
77 Cram() ;
78 } ;
79
80 #endif
gstrings.h
G::StringArray
std::vector< std::string > StringArray
A std::vector of std::strings.
Definition: gstrings.h:33
gsecret.h
GAuth::Cram::validate
static bool validate(const std::string &hash_type, bool hmac, const Secret &secret, const std::string &challenge, const std::string &response)
Validates the response with respect to the original challenge.
Definition: gcram.cpp:110
GAuth::Cram::challenge
static std::string challenge()
Returns a challenge string that incorporates a random number and the current time.
Definition: gcram.cpp:208
GAuth::Cram::id
static std::string id(const std::string &response)
Returns the leading id part of the response.
Definition: gcram.cpp:130
GAuth::Cram::response
static std::string response(const std::string &hash_type, bool hmac, const Secret &secret, const std::string &challenge, const std::string &response_prefix)
Constructs a response to a challenge comprising the response-prefix, space, and digest-or-hmac of key...
Definition: gcram.cpp:90
gexception.h
GAuth::Cram
Implements the standard challenge-response authentication mechanism of RFC-2195.
Definition: gcram.h:39
GAuth
SASL authentication classes.
Definition: gcram.h:30
GAuth::Secret
Encapsulates a shared secret from the secrets file plus the associated userid.
Definition: gsecret.h:42
GAuth::Cram::hashTypes
static G::StringArray hashTypes(const std::string &prefix=std::string(), bool require_state=false)
Returns a list of supported hash types, such as "MD5" and "SHA1", ordered with the strongest first...
Definition: gcram.cpp:183