das2C
das core C utilities (v3)
credentials.h
Go to the documentation of this file.
1 /* Copyright (C) 2017-2023 Chris Piker <chris-piker@uiowa.edu>
2  *
3  * This file is part of das2C, the Core Das2 C Library.
4  *
5  * das2C is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU Lesser General Public License version 2.1 as published
7  * by the Free Software Foundation.
8  *
9  * das2C is distributed in the hope that it will be useful, but WITHOUT ANY
10  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * version 2.1 along with das2C; if not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef _das_credmngr_h_
19 #define _das_credmngr_h_
20 
21 #include <stdio.h>
22 
23 #include <das2/array.h>
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
46 DAS_API char* das_b64_encode(
47  const unsigned char* data, size_t input_length, size_t* output_length
48 );
49 
50 
64 typedef bool (*das_prompt)(
65  const char* sServer, const char* sRealm, const char* sDataset,
66  const char* sMessage, char* sUser, char* sPassword
67 );
68 
69 #define DASCRED_SRV_SZ 128
70 #define DASCRED_REALM_SZ 128
71 #define DASCRED_DSET_SZ 128
72 #define DASCRED_HASH_SZ 256
73 
75 typedef struct das_credential_t{
76  bool bValid;
77  char sServer[DASCRED_SRV_SZ];
78  char sRealm[DASCRED_REALM_SZ];
79  char sDataset[DASCRED_DSET_SZ];
80  char sHash[DASCRED_HASH_SZ];
82 
83 
105 DAS_API bool das_cred_init(
106  das_credential* pCred, const char* sServer, const char* sRealm,
107  const char* sDataset, const char* sHash
108 );
109 
110 #define DASCMGR_FILE_SZ 128
111 #define DASCMGR_MSG_SZ 1024
112 
117 typedef struct das_credmngr{
118  DasAry* pCreds;
119  das_prompt prompt;
120  char sKeyFile[DASCMGR_FILE_SZ];
121  char sLastAuthMsg[DASCMGR_MSG_SZ];
122 } DasCredMngr;
123 
135 DAS_API DasCredMngr* new_CredMngr(const char* sKeyStore);
136 
143 DAS_API void del_CredMngr(DasCredMngr* pThis);
144 
159 DAS_API int CredMngr_addCred(DasCredMngr* pThis, const das_credential* pCred);
160 
161 
177  DasCredMngr* pThis, const char* sServer, const char* sRealm,
178  const char* sDataset, bool bValidOnly
179 );
180 
200  DasCredMngr* pThis, const char* sServer, const char* sRealm,
201  const char* sDataset, const char* sUser, const char* sPass
202 );
203 
217 DAS_API const char* CredMngr_getHttpAuth(
218  DasCredMngr* pThis, const char* sServer, const char* sRealm, const char* sDataset
219 );
220 
235 DAS_API void CredMngr_authFailed(
236  DasCredMngr* pThis, const char* sServer, const char* sRealm,
237  const char* sDataset, const char* sMsg
238 );
239 
240 
256 
275 DAS_API int CredMngr_save(DasCredMngr* pThis, const char* sSymKey, const char* sFile);
276 
298 DAS_API int CredMngr_load(DasCredMngr* pThis, const char* sSymKey, const char* sFile);
299 
300 
301 #ifdef __cplusplus
302 }
303 #endif
304 
305 #endif /* _das_credmngr_h_ */
306 
A dynamic buffer with multi-dimensional array style access.
DAS_API das_credential * CredMngr_getCred(DasCredMngr *pThis, const char *sServer, const char *sRealm, const char *sDataset, bool bValidOnly)
Get direct memory access to a stored credential.
DAS_API int CredMngr_addUserPass(DasCredMngr *pThis, const char *sServer, const char *sRealm, const char *sDataset, const char *sUser, const char *sPass)
Manually add a credential to a credentials manager instead of prompting the user.
DAS_API int CredMngr_addCred(DasCredMngr *pThis, const das_credential *pCred)
Manually add a credential to a credentials manager instead of prompting the user.
DAS_API bool das_cred_init(das_credential *pCred, const char *sServer, const char *sRealm, const char *sDataset, const char *sHash)
Initialize a credential to be cached in the credentials manager.
bool(* das_prompt)(const char *sServer, const char *sRealm, const char *sDataset, const char *sMessage, char *sUser, char *sPassword)
Function signature for swapping out the user-prompt for credentials acquisition.
Definition: credentials.h:64
DAS_API char * das_b64_encode(const unsigned char *data, size_t input_length, size_t *output_length)
Encode provided binary data as base64 characters in a new buffer.
Dynamic recursive ragged arrays.
Definition: array.h:270
Credentials manager Handles a list of login credentials and supplies these as needed for network oper...
Definition: credentials.h:117
DAS_API void del_CredMngr(DasCredMngr *pThis)
Delete a credentials manager free'ing it's internal credential store.
DAS_API const char * CredMngr_getHttpAuth(DasCredMngr *pThis, const char *sServer, const char *sRealm, const char *sDataset)
Retrieve an HTTP basic authentication token for a given dataset on a given server.
DAS_API void CredMngr_authFailed(DasCredMngr *pThis, const char *sServer, const char *sRealm, const char *sDataset, const char *sMsg)
Let the credentials manager know that a particular authorization method failed.
DAS_API int CredMngr_load(DasCredMngr *pThis, const char *sSymKey, const char *sFile)
Merge in credentials from the given filename.
DAS_API int CredMngr_save(DasCredMngr *pThis, const char *sSymKey, const char *sFile)
Save the current credentials to the given filename.
DAS_API DasCredMngr * new_CredMngr(const char *sKeyStore)
Initialize a new credentials manager, optionally from a saved list.
DAS_API das_prompt CredMngr_setPrompt(DasCredMngr *pThis, das_prompt new_prompt)
Change the function used to prompt users for das2 server credentials.
A single credential.
Definition: credentials.h:75