- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

gpopauth.cpp
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2013 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 // gpopauth.cpp
19 //
20
21 #include "gdef.h"
22 #include "gpop.h"
23 #include "gpopauth.h"
24 #include "gsaslserver.h"
25 #include "gsaslserverfactory.h"
26 #include "gstr.h"
27 #include "gmemory.h"
28
31 class GPop::AuthImp
32 {
33 public:
34 explicit AuthImp( const Secrets & ) ;
35 bool valid() const ;
36 bool init( const std::string & mechanism ) ;
37 bool authenticated( const std::string & , const std::string & ) ;
38 bool mustChallenge() const ;
39 std::string challenge() ;
40 std::string id() const ;
41 std::string mechanisms() const ;
42 bool sensitive() const ;
43
44 private:
45 const Secrets & m_secrets ;
46 std::auto_ptr<GAuth::SaslServer> m_sasl ;
47 } ;
48
49 // ==
50
51 GPop::AuthImp::AuthImp( const Secrets & secrets ) :
52 m_secrets(secrets) ,
53 m_sasl(GAuth::SaslServerFactory::newSaslServer(secrets,true,false))
54 {
55 m_sasl->init( "APOP" ) ; // for the initial challenge()
56 }
57
58 bool GPop::AuthImp::valid() const
59 {
60 return m_secrets.valid() && m_sasl->active() ;
61 }
62
63 bool GPop::AuthImp::init( const std::string & mechanism )
64 {
65 G_DEBUG( "GPop::AuthImp::init: mechanism " << mechanism ) ;
66 return m_sasl->init(mechanism) ;
67 }
68
69 bool GPop::AuthImp::authenticated( const std::string & p1 , const std::string & p2 )
70 {
71 bool done_1 = false ;
72 std::string challenge_1 = m_sasl->apply( p1 , done_1 ) ;
73 if( done_1 )
74 {
75 return challenge_1.empty() && m_sasl->authenticated() ;
76 }
77 else
78 {
79 bool done_2 = false ;
80 std::string challenge_2 = m_sasl->apply( p2 , done_2 ) ;
81 return done_2 && challenge_2.empty() && m_sasl->authenticated() ;
82 }
83 }
84
85 bool GPop::AuthImp::mustChallenge() const
86 {
87 return m_sasl->mustChallenge() ;
88 }
89
90 std::string GPop::AuthImp::challenge()
91 {
92 return m_sasl->initialChallenge() ;
93 }
94
95 std::string GPop::AuthImp::id() const
96 {
97 return m_sasl->id() ;
98 }
99
100 std::string GPop::AuthImp::mechanisms() const
101 {
102 return m_sasl->mechanisms() ;
103 }
104
105 bool GPop::AuthImp::sensitive() const
106 {
107 return m_sasl->requiresEncryption() ;
108 }
109
110 // ==
111
112 GPop::Auth::Auth( const Secrets & secrets ) :
113 m_imp( new AuthImp(secrets) )
114 {
115 }
116
117 GPop::Auth::~Auth()
118 {
119 delete m_imp ;
120 }
121
122 bool GPop::Auth::valid() const
123 {
124 return m_imp->valid() ;
125 }
126
127 bool GPop::Auth::init( const std::string & mechanism )
128 {
129 return m_imp->init(mechanism) ;
130 }
131
132 bool GPop::Auth::authenticated( const std::string & p1 , const std::string & p2 )
133 {
134 return m_imp->authenticated(p1,p2) ;
135 }
136
137 bool GPop::Auth::mustChallenge() const
138 {
139 return m_imp->mustChallenge() ;
140 }
141
142 std::string GPop::Auth::challenge()
143 {
144 return m_imp->challenge() ;
145 }
146
147 std::string GPop::Auth::id() const
148 {
149 return m_imp->id() ;
150 }
151
152 std::string GPop::Auth::mechanisms() const
153 {
154 return m_imp->mechanisms() ;
155 }
156
157 bool GPop::Auth::sensitive() const
158 {
159 return m_imp->sensitive() ;
160 }
GPop::AuthImp::AuthImp
AuthImp(const Secrets &)
Definition: gpopauth.cpp:51
GPop::Secrets
A simple interface to a store of secrets as used in authentication.
Definition: gpopsecrets.h:44
GPop::Auth::mechanisms
std::string mechanisms() const
Returns a space-separated list of standard, supported SASL mechanisms (so not including APOP)...
Definition: gpopauth.cpp:152
gsaslserver.h
GPop::AuthImp::mechanisms
std::string mechanisms() const
Definition: gpopauth.cpp:100
GPop::Auth::mustChallenge
bool mustChallenge() const
Returns true if the init()ialised mechanism requires an initial challenge.
Definition: gpopauth.cpp:137
GPop::AuthImp::sensitive
bool sensitive() const
Definition: gpopauth.cpp:105
gstr.h
GPop::Auth::init
bool init(const std::string &mechanism)
Initialises or reinitialises with the specified mechanism.
Definition: gpopauth.cpp:127
GPop::AuthImp::challenge
std::string challenge()
Definition: gpopauth.cpp:90
GPop::Auth::challenge
std::string challenge()
Returns an initial challenge appropriate to the current mechanism.
Definition: gpopauth.cpp:142
GPop::Auth::id
std::string id() const
Returns the authenticated user id.
Definition: gpopauth.cpp:147
G_DEBUG
#define G_DEBUG(expr)
Definition: glog.h:95
gpop.h
GPop::Auth::sensitive
bool sensitive() const
Returns true if the implementation requires authentication to be restricted to encrypted transports...
Definition: gpopauth.cpp:157
GPop::Auth::authenticated
bool authenticated(const std::string &rsp1, const std::string &rsp2)
Authenticates a one-step (APOP,PLAIN) or two-step (LOGIN) challenge-response sequence.
Definition: gpopauth.cpp:132
GPop::AuthImp::init
bool init(const std::string &mechanism)
Definition: gpopauth.cpp:63
GPop::AuthImp
A private pimple-pattern implementation class used by GPop::Auth.
Definition: gpopauth.cpp:31
GPop::AuthImp::id
std::string id() const
Definition: gpopauth.cpp:95
gsaslserverfactory.h
GPop::Auth::~Auth
~Auth()
Destructor.
Definition: gpopauth.cpp:117
GPop::Auth::valid
bool valid() const
Returns true if the secrets are valid.
Definition: gpopauth.cpp:122
gpopauth.h
GAuth
SASL authentication classes.
gmemory.h
GPop::AuthImp::authenticated
bool authenticated(const std::string &, const std::string &)
Definition: gpopauth.cpp:69
GPop::AuthImp::mustChallenge
bool mustChallenge() const
Definition: gpopauth.cpp:85
GPop::Auth::Auth
Auth(const Secrets &)
Constructor.
Definition: gpopauth.cpp:112
GPop::AuthImp::valid
bool valid() const
Definition: gpopauth.cpp:58