Kea 3.2.0-git
gss_tsig_api.h
Go to the documentation of this file.
1// Copyright (C) 2021-2026 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
25
26#ifndef GSS_TSIG_UTIL_H
27#define GSS_TSIG_UTIL_H
28
30#include <boost/noncopyable.hpp>
31#include <boost/shared_ptr.hpp>
32#include <gssapi/gssapi_krb5.h>
33#include <iostream>
34#include <string>
35#include <vector>
36
37namespace isc {
38namespace gss_tsig {
39
41class GssApiError : public Exception {
42public:
43 GssApiError(const char* file, size_t line, const char* what) :
44 isc::Exception(file, line, what) {
45 }
46};
47
48class GssCredExpired : public Exception {
49public:
50 GssCredExpired(const char* file, size_t line, const char* what) :
51 isc::Exception(file, line, what) {
52 }
53};
54
59public:
62
64 virtual ~GssApiLastError();
65
69 int getLastError() const {
70 return (last_error_);
71 }
72
76 void setLastError(int error) {
77 last_error_ = error;
78 }
79
80private:
82 int last_error_;
83};
84
92std::string gssApiErrMsg(OM_uint32 major, OM_uint32 minor);
93
100class GssApiBuffer : public boost::noncopyable {
101public:
103 GssApiBuffer();
104
109 GssApiBuffer(size_t length, const void* value);
110
114 explicit GssApiBuffer(const std::vector<uint8_t>& content);
115
119 explicit GssApiBuffer(const std::string& content);
120
125
129 bool empty() const {
130 return (buffer_.value == 0);
131 }
132
136 gss_buffer_t getPtr() {
137 return (&buffer_);
138 }
139
143 size_t getLength() const {
144 return (buffer_.length);
145 }
146
153 void* getValue() {
154 return (buffer_.value);
155 }
156
160 std::vector<uint8_t> getContent() const;
161
172 std::string getString(bool trim = false) const;
173
174private:
176 gss_buffer_desc buffer_;
177};
178
180typedef boost::shared_ptr<GssApiBuffer> GssApiBufferPtr;
181
185
187class GssApiName : public boost::noncopyable, public GssApiLastError {
188public:
190 GssApiName();
191
195 explicit GssApiName(const std::string& gname);
196
200 ~GssApiName();
201
203 gss_name_t get() {
204 return (name_);
205 }
206
210 gss_name_t* getPtr() {
211 return (&name_);
212 }
213
220 bool compare(GssApiName& other);
221
227 std::string toString();
228
229private:
231 gss_name_t name_;
232};
233
235typedef boost::shared_ptr<GssApiName> GssApiNamePtr;
236
242class GssApiCred : public boost::noncopyable, public GssApiLastError {
243public:
245 GssApiCred();
246
254 GssApiCred(GssApiName& gname, gss_cred_usage_t cred_usage,
255 OM_uint32& lifetime);
256
260 ~GssApiCred();
261
263 gss_cred_id_t get() {
264 return (cred_);
265 }
266
274 void inquire(GssApiName& name, gss_cred_usage_t& cred_usage,
275 OM_uint32& lifetime);
276
277private:
279 gss_cred_id_t cred_;
280};
281
283typedef boost::shared_ptr<GssApiCred> GssApiCredPtr;
284
290class GssApiSecCtx : public boost::noncopyable, public GssApiLastError {
291public:
298
302 explicit GssApiSecCtx(gss_ctx_id_t sec_ctx);
303
309 explicit GssApiSecCtx(const std::vector<uint8_t>& import);
310
315
317 gss_ctx_id_t get() {
318 return (sec_ctx_);
319 }
320
324 gss_ctx_id_t* getPtr() {
325 return (&sec_ctx_);
326 }
327
333 std::vector<uint8_t> serialize();
334
339 OM_uint32 getLifetime();
340
352 void inquire(GssApiName& source, GssApiName& target, OM_uint32& lifetime,
353 OM_uint32& flags, bool& local, bool& established);
354
361 void sign(GssApiBuffer& gmessage, GssApiBuffer& gsig);
362
369 void verify(GssApiBuffer& gmessage, GssApiBuffer& gsig);
370
387 bool init(GssApiCredPtr credp, GssApiName& target, OM_uint32 flags,
388 GssApiBuffer& intoken, GssApiBuffer& outtoken,
389 OM_uint32& lifetime);
390
405 bool accept(GssApiCred& cred, GssApiBuffer& intoken, GssApiName& source,
406 GssApiBuffer& outtoken);
407
408private:
410 gss_ctx_id_t sec_ctx_;
411};
412
421class GssApiOid : public boost::noncopyable {
422public:
424 GssApiOid();
425
429 explicit GssApiOid(const std::vector<uint8_t>& elements);
430
438 explicit GssApiOid(const std::string& str);
439
443 ~GssApiOid();
444
446 gss_OID get() {
447 return (oid_);
448 }
449
455 std::string toString();
456
457private:
459 gss_OID oid_;
460};
461
464
467
469typedef boost::shared_ptr<GssApiOid> GssApiOidPtr;
470
476class GssApiOidSet : public boost::noncopyable {
477public:
482 explicit GssApiOidSet(bool fill = true);
483
488
490 gss_OID_set get() {
491 return (oid_set_);
492 }
493
494private:
496 gss_OID_set oid_set_;
497};
498
500typedef boost::shared_ptr<GssApiOidSet> GssApiOidSetPtr;
501
502} // end of namespace isc::gss_tsig
503} // end of namespace isc
504
505#endif // GSS_TSIG_UTIL_H
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Exception(const char *file, size_t line, const char *what)
std::vector< uint8_t > getContent() const
Get the content as a vector.
bool empty() const
Empty predicate.
gss_buffer_t getPtr()
Get pointer.
void * getValue()
Get the value.
size_t getLength() const
Get the length.
std::string getString(bool trim=false) const
Get the content as a string.
GSS-API credential.
void inquire(GssApiName &name, gss_cred_usage_t &cred_usage, OM_uint32 &lifetime)
Inquire.
gss_cred_id_t get()
Get the value.
GssApiError(const char *file, size_t line, const char *what)
void setLastError(int error)
Set the last error.
int getLastError() const
Get the last error.
virtual ~GssApiLastError()
Destructor.
gss_name_t * getPtr()
Get pointer.
std::string toString()
textual representation.
gss_name_t get()
Get the value.
bool compare(GssApiName &other)
Compare.
gss_OID_set get()
Get the value.
GssApiOidSet(bool fill=true)
Constructor.
gss_OID get()
Get the value.
std::string toString()
Get textual representation.
gss_ctx_id_t get()
Get the value.
void sign(GssApiBuffer &gmessage, GssApiBuffer &gsig)
Sign.
static bool ignore_bad_direction_
Ignore bad direction flag.
bool init(GssApiCredPtr credp, GssApiName &target, OM_uint32 flags, GssApiBuffer &intoken, GssApiBuffer &outtoken, OM_uint32 &lifetime)
Init.
void verify(GssApiBuffer &gmessage, GssApiBuffer &gsig)
Verify.
std::vector< uint8_t > serialize()
Export.
OM_uint32 getLifetime()
Get the lifetime (validity in seconds).
gss_ctx_id_t * getPtr()
Get a pointer to the security context.
GssApiSecCtx(gss_ctx_id_t sec_ctx)
Constructor.
void inquire(GssApiName &source, GssApiName &target, OM_uint32 &lifetime, OM_uint32 &flags, bool &local, bool &established)
Inquire.
bool accept(GssApiCred &cred, GssApiBuffer &intoken, GssApiName &source, GssApiBuffer &outtoken)
Accept.
GssCredExpired(const char *file, size_t line, const char *what)
GssApiOid ISC_GSS_SPNEGO_MECHANISM(ISC_GSS_SPNEGO_MECHANISM_vect)
The SPNEGO OID.
boost::shared_ptr< GssApiName > GssApiNamePtr
Shared pointer to GSS-API name.
boost::shared_ptr< GssApiOid > GssApiOidPtr
Shared pointer to GSS-API OID.
string gssApiErrMsg(OM_uint32 major, OM_uint32 minor)
An the error message.
boost::shared_ptr< GssApiBuffer > GssApiBufferPtr
Shared pointer to GSS-API buffer.
boost::shared_ptr< GssApiOidSet > GssApiOidSetPtr
Shared pointer to GSS-API OID set.
GssApiOid ISC_GSS_KRB5_MECHANISM(ISC_GSS_KRB5_MECHANISM_vect)
The Kerberos 5 OID.
boost::shared_ptr< GssApiCred > GssApiCredPtr
Shared pointer to GSS-API credential.
Defines the logger used by the top-level component of kea-lfc.