1 /***************************************************************************
2     begin       : Mon Mar 01 2004
3     copyright   : (C) 2019 by Martin Preuss
4     email       : martin@libchipcard.de
5 
6  ***************************************************************************
7  *          Please see toplevel file COPYING for license details           *
8  ***************************************************************************/
9 
10 #ifndef AH_USER_H
11 #define AH_USER_H
12 
13 #include "aqhbci/aqhbci.h"
14 #include "aqhbci/tan/tanmethod.h"
15 
16 #include <gwenhywfar/misc.h>
17 #include <gwenhywfar/stringlist.h>
18 #include <gwenhywfar/cryptkeyrsa.h>
19 
20 
21 /** @defgroup G_AB_BE_AQHBCI_USER HBCI User Extensions
22  * @ingroup G_AB_BE_AQHBCI
23  * @short HBCI-specific user functions
24  * @author Martin Preuss<martin@libchipcard.de>
25  *
26  */
27 /*@{*/
28 
29 #include <aqbanking/backendsupport/user.h>
30 
31 #include <gwenhywfar/db.h>
32 #include <gwenhywfar/url.h>
33 
34 
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 /** @name HBCI User Flags
41  *
42  */
43 /*@{*/
44 /** bank doesn't sign its messages */
45 #define AH_USER_FLAGS_BANK_DOESNT_SIGN         0x00000001
46 /** bank uses correct signature sequence counters for its messages */
47 #define AH_USER_FLAGS_BANK_USES_SIGNSEQ        0x00000002
48 #define AH_USER_FLAGS_RESERVED1                0x00000004
49 #define AH_USER_FLAGS_RESERVED2                0x00000008
50 
51 /** this flag is set automatically by AqHBCI upon BPD/UPD receiption. It
52 * indicates that some jobs are supported even when there is no UPD job
53 * description for it */
54 #define AH_USER_FLAGS_IGNORE_UPD               0x00000020
55 
56 /** do not encode message in BASE64 (needed for APO bank) */
57 #define AH_USER_FLAGS_NO_BASE64                0x00000080
58 
59 /** Normally the SWIFT parser removed double blanks, with this flag set it
60  * no longer does (as requested by Andreas Filsinger).
61  */
62 #define AH_USER_FLAGS_KEEP_MULTIPLE_BLANKS     0x00000100
63 
64 /** Some TAN jobs have a field for the account to be used to charge
65  * for SMS. This field is semi-optional (some banks need it, some need
66  * you not to use it).
67  * If this flag is set then the SMS account specification is omitted.
68  */
69 #define AH_USER_FLAGS_TAN_OMIT_SMS_ACCOUNT      0x00000200
70 
71 #define AH_USER_FLAGS_USE_STRICT_SEPA_CHARSET   0x00000800
72 
73 /* ignore error "GNUTLS_E_PREMATURE_TERMINATION" */
74 /*#define AH_USER_FLAGS_TLS_IGN_PREMATURE_CLOSE   0x00001000 (ignored) */
75 
76 /**
77  * This flag is set when there is no public sign key of the bank
78  * and the user has been informed about it.
79  */
80 #define AH_USER_FLAGS_VERIFY_NO_BANKSIGNKEY     0x00002000
81 
82 /*@}*/
83 
84 
85 
86 /** @name Functions for Flags and Status
87  *
88  */
89 /*@{*/
90 
91 AQHBCI_API
92 void AH_User_Flags_toDb(GWEN_DB_NODE *db, const char *name, uint32_t flags);
93 AQHBCI_API
94 uint32_t AH_User_Flags_fromDb(GWEN_DB_NODE *db, const char *name);
95 
96 
97 typedef enum {
98   AH_UserStatusNew=0,
99   AH_UserStatusEnabled,
100   AH_UserStatusPending,
101   AH_UserStatusDisabled,
102   AH_UserStatusUnknown=999
103 } AH_USER_STATUS;
104 AQHBCI_API
105 const char *AH_User_Status_toString(AH_USER_STATUS st);
106 AQHBCI_API
107 AH_USER_STATUS AH_User_Status_fromString(const char *s);
108 
109 
110 AQHBCI_API
111 AH_USER_STATUS AH_User_GetStatus(const AB_USER *u);
112 AQHBCI_API
113 void AH_User_SetStatus(AB_USER *u, AH_USER_STATUS i);
114 
115 /**
116  * Returns 0 if the bank doesn't sign messages, 1 otherwise.
117  * This can be used in case the bank sends a sign key upon request but
118  * never signs it's messages.
119  */
120 AQHBCI_API
121 uint32_t AH_User_GetFlags(const AB_USER *u);
122 
123 AQHBCI_API
124 void AH_User_SetFlags(AB_USER *u, uint32_t flags);
125 
126 AQHBCI_API
127 void AH_User_AddFlags(AB_USER *u, uint32_t flags);
128 
129 AQHBCI_API
130 void AH_User_SubFlags(AB_USER *u, uint32_t flags);
131 
132 
133 /*@}*/
134 
135 
136 /** @name PIN/TAN Specific Functions
137  *
138  */
139 /*@{*/
140 
141 AQHBCI_API
142 const int *AH_User_GetTanMethodList(const AB_USER *u);
143 AQHBCI_API
144 int AH_User_GetTanMethodCount(const AB_USER *u);
145 AQHBCI_API
146 int AH_User_HasTanMethod(const AB_USER *u, int method);
147 AQHBCI_API
148 int AH_User_HasTanMethodOtherThan(const AB_USER *u, int method);
149 AQHBCI_API
150 void AH_User_AddTanMethod(AB_USER *u, int method);
151 AQHBCI_API
152 void AH_User_ClearTanMethodList(AB_USER *u);
153 
154 AQHBCI_API
155 int AH_User_GetSelectedTanMethod(const AB_USER *u);
156 AQHBCI_API
157 void AH_User_SetSelectedTanMethod(AB_USER *u, int i);
158 
159 
160 /**
161  * Return selected TAN inpout method (see @ref AB_BANKING_TANMETHOD_TEXT and following).
162  *
163  * @return selected mechanism (0 if none selected)
164  */
165 int AH_User_GetSelectedTanInputMechanism(const AB_USER *u);
166 
167 
168 void AH_User_SetSelectedTanInputMechanism(AB_USER *u, int i);
169 
170 
171 AQHBCI_API
172 const char *AH_User_GetHttpContentType(const AB_USER *u);
173 AQHBCI_API
174 void AH_User_SetHttpContentType(AB_USER *u, const char *s);
175 
176 /*@}*/
177 
178 
179 
180 AQHBCI_API
181 const char *AH_User_GetTokenType(const AB_USER *u);
182 AQHBCI_API
183 void AH_User_SetTokenType(AB_USER *u, const char *s);
184 AQHBCI_API
185 const char *AH_User_GetTokenName(const AB_USER *u);
186 AQHBCI_API
187 void AH_User_SetTokenName(AB_USER *u, const char *s);
188 AQHBCI_API
189 uint32_t AH_User_GetTokenContextId(const AB_USER *u);
190 AQHBCI_API
191 void AH_User_SetTokenContextId(AB_USER *u, uint32_t id);
192 
193 
194 
195 /** @name Miscellanous Settings
196  *
197  */
198 /*@{*/
199 /**
200  * Crypt mode (see @ref AH_CryptMode_Ddv and following).
201  */
202 AQHBCI_API
203 AH_CRYPT_MODE AH_User_GetCryptMode(const AB_USER *u);
204 AQHBCI_API
205 void AH_User_SetCryptMode(AB_USER *u, AH_CRYPT_MODE m);
206 
207 AQHBCI_API
208 int AH_User_GetRdhType(const AB_USER *u);
209 
210 AQHBCI_API
211 void AH_User_SetRdhType(AB_USER *u, int i);
212 
213 AQHBCI_API
214 const char *AH_User_GetPeerId(const AB_USER *u);
215 AQHBCI_API
216 void AH_User_SetPeerId(AB_USER *u, const char *s);
217 
218 AQHBCI_API
219 const char *AH_User_GetSystemId(const AB_USER *u);
220 AQHBCI_API
221 void AH_User_SetSystemId(AB_USER *u, const char *s);
222 
223 
224 AQHBCI_API
225 const GWEN_URL *AH_User_GetServerUrl(const AB_USER *u);
226 AQHBCI_API
227 void AH_User_SetServerUrl(AB_USER *u, const GWEN_URL *url);
228 
229 
230 AQHBCI_API
231 int AH_User_GetHbciVersion(const AB_USER *u);
232 AQHBCI_API
233 void AH_User_SetHbciVersion(AB_USER *u, int i);
234 
235 
236 AQHBCI_API
237 const char *AH_User_GetSepaTransferProfile(const AB_USER *u);
238 AQHBCI_API
239 void AH_User_SetSepaTransferProfile(AB_USER *u, const char *profileName);
240 AQHBCI_API
241 const char *AH_User_GetSepaDebitNoteProfile(const AB_USER *u);
242 AQHBCI_API
243 void AH_User_SetSepaDebitNoteProfile(AB_USER *u, const char *profileName);
244 /*@}*/
245 
246 
247 
248 /** @name Pin/Tan Settings
249  *
250  */
251 /*@{*/
252 /**
253  * Returns the major HTTP version to be used in PIN/TAN mode (defaults to 1).
254  */
255 AQHBCI_API
256 int AH_User_GetHttpVMajor(const AB_USER *u);
257 AQHBCI_API
258 void AH_User_SetHttpVMajor(AB_USER *u, int i);
259 
260 /**
261  * Returns the minor HTTP version to be used in PIN/TAN mode (defaults to 1).
262  */
263 AQHBCI_API
264 int AH_User_GetHttpVMinor(const AB_USER *u);
265 AQHBCI_API
266 void AH_User_SetHttpVMinor(AB_USER *u, int i);
267 
268 
269 
270 AQHBCI_API
271 const char *AH_User_GetHttpUserAgent(const AB_USER *u);
272 AQHBCI_API
273 void AH_User_SetHttpUserAgent(AB_USER *u, const char *s);
274 
275 
276 AQHBCI_API
277 const char *AH_User_GetTanMediumId(const AB_USER *u);
278 
279 AQHBCI_API
280 void AH_User_SetTanMediumId(AB_USER *u, const char *s);
281 
282 
283 /*@}*/
284 
285 
286 /** @name Passwords/Pins/Tans
287  *
288  */
289 /*@{*/
290 
291 AQHBCI_API
292 int AH_User_MkPasswdName(const AB_USER *u, GWEN_BUFFER *buf);
293 
294 AQHBCI_API
295 int AH_User_MkPinName(const AB_USER *u, GWEN_BUFFER *buf);
296 
297 AQHBCI_API
298 int AH_User_MkTanName(const AB_USER *u,
299                       const char *challenge,
300                       GWEN_BUFFER *buf);
301 
302 /**
303  * The list returned is only valid until the next call to this function!
304  */
305 AQHBCI_API
306 const AH_TAN_METHOD_LIST *AH_User_GetTanMethodDescriptions(AB_USER *u);
307 
308 
309 /*@}*/
310 
311 
312 AQHBCI_API int AH_User_GetMaxTransfersPerJob(const AB_USER *u);
313 AQHBCI_API void AH_User_SetMaxTransfersPerJob(AB_USER *u, int i);
314 AQHBCI_API int AH_User_GetMaxDebitNotesPerJob(const AB_USER *u);
315 AQHBCI_API void AH_User_SetMaxDebitNotesPerJob(AB_USER *u, int i);
316 
317 AQHBCI_API void AH_User_SetBankPubSignKey(AB_USER *u, GWEN_CRYPT_KEY *bankPubKey);
318 AQHBCI_API GWEN_CRYPT_KEY *AH_User_GetBankPubSignKey(const AB_USER *u);
319 
320 AQHBCI_API void AH_User_SetBankPubCryptKey(AB_USER *u, GWEN_CRYPT_KEY *bankPubKey);
321 AQHBCI_API GWEN_CRYPT_KEY *AH_User_GetBankPubCryptKey(const AB_USER *u);
322 
323 /*@}*/ /* defgroup */
324 
325 #ifdef __cplusplus
326 }
327 #endif
328 
329 #endif /* AH_USER_H */
330 
331 
332 
333 
334 
335 
336