Kea 3.1.1
gss_tsig_api.h
Go to the documentation of this file.
1// Copyright (C) 2021-2025 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:
295 explicit GssApiSecCtx(gss_ctx_id_t sec_ctx);
296
302 explicit GssApiSecCtx(const std::vector<uint8_t>& import);
303
308
310 gss_ctx_id_t get() {
311 return (sec_ctx_);
312 }
313
317 gss_ctx_id_t* getPtr() {
318 return (&sec_ctx_);
319 }
320
326 std::vector<uint8_t> serialize();
327
332 OM_uint32 getLifetime();
333
345 void inquire(GssApiName& source, GssApiName& target, OM_uint32& lifetime,
346 OM_uint32& flags, bool& local, bool& established);
347
354 void sign(GssApiBuffer& gmessage, GssApiBuffer& gsig);
355
362 void verify(GssApiBuffer& gmessage, GssApiBuffer& gsig);
363
380 bool init(GssApiCredPtr credp, GssApiName& target, OM_uint32 flags,
381 GssApiBuffer& intoken, GssApiBuffer& outtoken,
382 OM_uint32& lifetime);
383
398 bool accept(GssApiCred& cred, GssApiBuffer& intoken, GssApiName& source,
399 GssApiBuffer& outtoken);
400
401private:
403 gss_ctx_id_t sec_ctx_;
404};
405
414class GssApiOid : public boost::noncopyable {
415public:
417 GssApiOid();
418
422 explicit GssApiOid(const std::vector<uint8_t>& elements);
423
431 explicit GssApiOid(const std::string& str);
432
436 ~GssApiOid();
437
439 gss_OID get() {
440 return (oid_);
441 }
442
448 std::string toString();
449
450private:
452 gss_OID oid_;
453};
454
457
460
462typedef boost::shared_ptr<GssApiOid> GssApiOidPtr;
463
469class GssApiOidSet : public boost::noncopyable {
470public:
475 explicit GssApiOidSet(bool fill = true);
476
481
483 gss_OID_set get() {
484 return (oid_set_);
485 }
486
487private:
489 gss_OID_set oid_set_;
490};
491
493typedef boost::shared_ptr<GssApiOidSet> GssApiOidSetPtr;
494
495} // end of namespace isc::gss_tsig
496} // end of namespace isc
497
498#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.
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.