1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
|
/*
* gsi_socket.h
*
* Interface for a GSI-protected socket.
*/
#ifndef __GSI_SOCKET_H
#define __GSI_SOCKET_H
#include <sys/types.h>
struct _gsi_socket;
typedef struct _gsi_socket GSI_SOCKET;
/*
* Return code for many of the GSI_SOCKET routines:
*/
#define GSI_SOCKET_SUCCESS 0
#define GSI_SOCKET_ERROR -1
#define GSI_SOCKET_TRUNCATED -2
#define GSI_SOCKET_UNAUTHORIZED -3
#define GSI_SOCKET_UNTRUSTED -4
/*
* GSI_SOCKET_new()
*
* Create a new GSI_SOCKET object for a socket descriptor.
*
* Returns NULL on memory allocation failure.
*/
GSI_SOCKET *GSI_SOCKET_new(int sock);
/*
* GSI_SOCKET_destroy()
*
* Destroy the GSI_SOCKET object and deallocated all associated
* memory.
*/
void GSI_SOCKET_destroy(GSI_SOCKET *gsi_socket);
/*
* GSI_SOCKET_get_error_string()
*
* Fills in buffer with a NUL-terminated string (possibly multi-lined)
* describing the last error the occurred with this GSI_SOCKET.
* bufferlen should be the size of buffer. It returns the number of
* characters actually put into buffer (not including the trailing
* NUL).
*
* If there is no error known of, buffer will be set to a zero-length
* string, and zero will be returned.
*
* If the buffer wasn't big enough and the string was truncated,
* -1 will be returned.
*/
int GSI_SOCKET_get_error_string(GSI_SOCKET *gsi_socket,
char *buffer,
int buffer_len);
/*
* GSI_SOCKET_clear_error()
*
* Clears any error state in the given GSI_SOCKET object.
*/
void GSI_SOCKET_clear_error(GSI_SOCKET *gsi_socket);
/*
* GSI_SOCKET_authentication_init()
*
* Perform the client-side authentication process.
* The accepted_peer_names argument must be a NULL terminated array of
* acceptable peer names.
*
* Returns GSI_SOCKET_SUCCESS on success,
* GSI_SOCKET_UNAUTHORIZED if server identity doesn't match one of the
* acceptable peer names, and GSI_SOCKET_ERROR otherwise.
*/
int GSI_SOCKET_authentication_init(GSI_SOCKET *gsi_socket,
gss_name_t accepted_peer_names[]);
/*
* GSI_SOCKET_use_creds()
*
* Use the credentials pointed to by creds for authentication.
* The exact contents of creds is mechanism-specific, but is
* generally a filename. If creds == NULL, the defaults credentials
* should be used.
*
* Returns GSI_SOCKET_SUCCESS on success, GSI_SOCKET_ERROR otherwise.
*/
int GSI_SOCKET_use_creds(GSI_SOCKET *gsi_socket,
const char *creds);
/*
* GSI_SOCKET_check_creds()
*
* Check that valid GSI credentials are available.
*
* Returns GSI_SOCKET_SUCCESS on success, GSI_SOCKET_ERROR otherwise.
*/
int GSI_SOCKET_check_creds(GSI_SOCKET *gsi_socket);
/*
* GSI_SOCKET_authentication_accept()
*
* Perform the server-side authentication process.
*
* Returns GSI_SOCKET_SUCCESS on success, GSI_SOCKET_ERROR otherwise.
*/
int GSI_SOCKET_authentication_accept(GSI_SOCKET *gsi_socket);
/*
* GSI_SOCKET_get_peer_name()
*
* Fill in buffer with a string representation of the authenticated
* identity of the entity on the other side of the socket.
*
* If the peer is not identified, returns GSI_SOCKET_ERROR.
*
* If the buffer is too small and the string is truncated returns
* GSI_SOCKET_TRUNCATED.
*
* Other wise returns the number of characters written into the buffer
* (not including the trailing NUL).
*
*/
int GSI_SOCKET_get_peer_name(GSI_SOCKET *gsi_socket,
char *buffer,
int buffer_len);
/*
* GSI_SOCKET_get_peer_hostname()
*
* Returns the hostname of the entity on the other side of the socket
* or NULL on error. Returned string should be free()'ed by the caller.
*
*/
char *GSI_SOCKET_get_peer_hostname(GSI_SOCKET *gsi_socket);
/*
* GSI_SOCKET_get_peer_fqans()
*
* Returns a NULL terminated list of the client's FQAN's (full quolified
* attribute names).
*
*/
int GSI_SOCKET_get_peer_fqans(GSI_SOCKET *gsi_socket, char ***fqans);
/*
* GSI_SOCKET_write_buffer()
*
* Write the given buffer to the peer. If authentication has been done,
* the buffer will be protected via the GSI.
*
* Returns GSI_SOCKET_SUCCESS on success, GSI_SOCKET_ERROR otherwise.
*/
int GSI_SOCKET_write_buffer(GSI_SOCKET *gsi_socket,
const char *buffer,
size_t buffer_len);
/*
* GSI_SOCKET_read_token()
*
* Read a token from the peer. If authentication has been done,
* the buffer will be protected via the GSI.
*
* buffer will be set to point to an allocated buffer that should
* be freed with GSI_SOCKET_free_token(). buffer_len will be
* set to the length of the buffer.
*
* Returns GSI_SOCKET_SUCCESS or GSI_SOCKET_ERROR.
*/
int GSI_SOCKET_read_token(GSI_SOCKET *gsi_socket,
unsigned char **buffer,
size_t *buffer_len);
/*
* GSI_SOCKET_free_token()
*
* Free a token returned by GSI_SOCKET_read_token().
*/
void GSI_SOCKET_free_token(unsigned char *buffer);
/*
* GSI_SOCKET_delegation_init_ext()
*
* Delegate credentials to the peer.
*
* source_credentials should be a string specifying the location
* of the credentials to delegate. This is mechanism specific,
* but typically a file path. If NULL, the default credentials for
* the current context will be used.
*
* lifetime should be the lifetime of the delegated credentials
* in seconds. A value of GSI_SOCKET_DELEGATION_LIFETIME_MAXIMUM
* indicates that the longest possible lifetime should be delegated.
*
* passphrase is the passphrase set for the source_credentials.
* NULL if no passphrase is set.
*
* Returns GSI_SOCKET_SUCCESS success, GSI_SOCKET_ERROR otherwise.
*/
int GSI_SOCKET_delegation_init_ext(GSI_SOCKET *gsi_socket,
const char *source_credentials,
int lifetime,
const char *passphrase);
/*
* Values for GSI_SOCKET_DELEGATION_init() flags:
*/
#define GSI_SOCKET_DELEGATION_FLAGS_DEFAULT 0x0000
/*
* Values for GSI_SOCKET_DELEGATION_init() lifetime:
*/
#define GSI_SOCKET_DELEGATION_LIFETIME_MAXIMUM 0x0000
/*
* Valyes for GSI_SOCKET_DELEGATION_init() restrictions:
*/
#define GSI_SOCKET_DELEGATION_RESTRICTIONS_DEFAULT NULL
/*
* GSI_SOCKET_delegation_accept()
*
* Accept delegated credentials from the peer.
*
* Return an allocated buffer with the given proxy encoded in PEM format.
* The private key is encrypted with passphrase if provided (can be NULL).
*
* Returns GSI_SOCKET_SUCCESS on success, GSI_SOCKET_ERROR otherwise. */
int GSI_SOCKET_delegation_accept(GSI_SOCKET *gsi_socket,
unsigned char **delegated_credentials,
int *delegated_credentials_len,
char *passphrase);
/*
* GSI_SOCKET_delegation_accept_ext()
*
* Accept delegated credentials from the peer.
*
* delegated_credentials will be filled in with the location of
* the delegated credentials. This is mechanism-specific but
* probably a file path.
*
* passphrase is an optional passphrase to use to encrypt the
* delegated credentials. May be NULL.
*
* Returns GSI_SOCKET_SUCCESS on success, GSI_SOCKET_ERROR otherwise. */
int GSI_SOCKET_delegation_accept_ext(GSI_SOCKET *gsi_socket,
char *delegated_credentials,
int delegated_credentials_len,
char *passphrase);
/*
* GSI_SOCKET_delegation_set_certreq()
*
* Specify the location of a PEM-encoded certificate request to be
* used when accepting delegation via GSI_SOCKET_delegation_accept()
* or GSI_SOCKET_delegation_accept_ext(), rather than generating a new
* keypair and certificate request as part of delegation.
*
* Returns GSI_SOCKET_SUCCESS or GSI_SOCKET_ERROR.
*/
int
GSI_SOCKET_delegation_set_certreq(GSI_SOCKET *gsi_socket,
char *certreq);
/*
* GSI_SOCKET_credentials_accept_ext()
*
* Accept credentials from the peer.
*
* delegated_credentials will be filled in with the location of
* the delegated credentials. This is mechanism-specific but
* probably a file path.
*
* Returns GSI_SOCKET_SUCCESS on success, GSI_SOCKET_ERROR otherwise. */
int
GSI_SOCKET_credentials_accept_ext(GSI_SOCKET *self,
char *credentials,
int credentials_len);
int
GSI_SOCKET_get_creds(GSI_SOCKET *self,
const char *source_credentials);
int
GSI_SOCKET_credentials_init_ext(GSI_SOCKET *self,
const char *source_credentials);
/*
* GSI_SOCKET_allow_anonymous()
*
* If value=1, allow anonymous GSSAPI/SSL authentication.
* Otherwise, the client must have a valid GSSAPI/SSL credential.
* Default is to *not* allow anonymous authentication.
*
*/
int GSI_SOCKET_allow_anonymous(GSI_SOCKET *self, const int value);
/*
* GSI_SOCKET_peer_used_limited_proxy()
*
* Returns 1 if peer used a limited proxy, 0 otherwise.
*
*/
int GSI_SOCKET_peer_used_limited_proxy(GSI_SOCKET *self);
/*
* GSI_SOCKET_set_peer_limited_proxy()
*
* Set the peer's limited proxy flag (1 if yes, 0 if no).
* Used when secondary authentication used a limited proxy
* and so limited proxy policies should apply.
*
*/
int GSI_SOCKET_set_peer_limited_proxy(GSI_SOCKET *self, int flag);
/*
* GSI_SOCKET_set_max_token_len()
*
* Set the maximum size of accepted incoming tokens (in bytes).
* No limit is enforced by default.
* A zero or negative value disables the limit.
*/
int GSI_SOCKET_set_max_token_len(GSI_SOCKET *self, int bytes);
/*
* GSI_SOCKET_context_established()
*
* Returns 1 if the socket's secure context has been established via
* GSI_SOCKET_authentication_init() or
* GSI_SOCKET_authentication_accept(). Returns 0 otherwise.
*
*/
int GSI_SOCKET_context_established(GSI_SOCKET *self);
/*
* GSI_SOCKET_get_errno()
*
* Returns saved errno if the socket exists. Otherwise returns 0.
*
*/
int GSI_SOCKET_get_errno(GSI_SOCKET *self);
#endif /* !__GSI_SOCKET_H */
|