annotate common/listutil.h @ 251:c596568fa45b

Add utf16 conversion functions for Windows. This also includes a null pointer checking free.
author Andre Heinecke <aheinecke@intevation.de>
date Tue, 01 Apr 2014 10:48:35 +0000
parents 571f68c7a38f
children 881ce5126f07
rev   line source
7
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents: 4
diff changeset
1 #ifndef LISTUTIL_H
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents: 4
diff changeset
2 #define LISTUTIL_H
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents: 4
diff changeset
3
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents: 4
diff changeset
4 #ifdef __cplusplus
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents: 4
diff changeset
5 extern "C" {
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents: 4
diff changeset
6 #endif
4
9849250f50f2 Start implementation of certificatelist parser
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
7
9849250f50f2 Start implementation of certificatelist parser
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
8 #include <stddef.h>
9849250f50f2 Start implementation of certificatelist parser
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
9
9849250f50f2 Start implementation of certificatelist parser
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
10 /**
9849250f50f2 Start implementation of certificatelist parser
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
11 * @file listutil.h
9849250f50f2 Start implementation of certificatelist parser
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
12 * @brief Functions to work with the certificate list.
9849250f50f2 Start implementation of certificatelist parser
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
13 */
9849250f50f2 Start implementation of certificatelist parser
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
14
7
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents: 4
diff changeset
15 /**
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents: 4
diff changeset
16 * @brief Status of the List Operations
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents: 4
diff changeset
17 */
4
9849250f50f2 Start implementation of certificatelist parser
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
18 typedef enum {
31
37fc66967517 Implement signature verification wiht polarssl
Andre Heinecke <aheinecke@intevation.de>
parents: 28
diff changeset
19 Valid = 100, // Could be read and signature matched
4
9849250f50f2 Start implementation of certificatelist parser
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
20 UnknownError = 1, // The expected unexpected
9849250f50f2 Start implementation of certificatelist parser
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
21 TooLarge = 2, // Failed because the file exeeds the limit
9849250f50f2 Start implementation of certificatelist parser
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
22 InvalidFormat = 3, // File does not appear to be in list format
9849250f50f2 Start implementation of certificatelist parser
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
23 InvalidSignature = 4, // Signature was invalid
31
37fc66967517 Implement signature verification wiht polarssl
Andre Heinecke <aheinecke@intevation.de>
parents: 28
diff changeset
24 SeekFailed = 5, // Could not seek in the file
37fc66967517 Implement signature verification wiht polarssl
Andre Heinecke <aheinecke@intevation.de>
parents: 28
diff changeset
25 ReadFailed = 6, // File exists but could not read the file
70
64c8c6350e60 Add default constructor to certificatelist. Remove Q_OBJECT use
Andre Heinecke <aheinecke@intevation.de>
parents: 68
diff changeset
26 IncompatibleVersion = 7, // The Format Version does not match
64c8c6350e60 Add default constructor to certificatelist. Remove Q_OBJECT use
Andre Heinecke <aheinecke@intevation.de>
parents: 68
diff changeset
27 NoList = 8 // No list parsed
4
9849250f50f2 Start implementation of certificatelist parser
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
28 } list_status_t;
9849250f50f2 Start implementation of certificatelist parser
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
29
68
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
30 /* Definitions based on the format */
123
571f68c7a38f Specified line length is 9999 and not 1000!
Andre Heinecke <aheinecke@intevation.de>
parents: 70
diff changeset
31 #define MAX_LINE_LENGTH 9999
68
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
32 #define MAX_LINES 1000
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
33
4
9849250f50f2 Start implementation of certificatelist parser
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
34 /**
9849250f50f2 Start implementation of certificatelist parser
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
35 * @brief Obtain the complete and verified Certificate list.
9849250f50f2 Start implementation of certificatelist parser
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
36 *
9849250f50f2 Start implementation of certificatelist parser
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
37 * This checks if the file fileName is a valid certificate
9849250f50f2 Start implementation of certificatelist parser
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
38 * list signed by the key specified in pubkey.h
9849250f50f2 Start implementation of certificatelist parser
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
39 *
9849250f50f2 Start implementation of certificatelist parser
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
40 * The caller has to free data.
9849250f50f2 Start implementation of certificatelist parser
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
41 *
9849250f50f2 Start implementation of certificatelist parser
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
42 * @param[in] fileName Name of the file (UTF-8 encoded).
9849250f50f2 Start implementation of certificatelist parser
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
43 * @param[out] data Newly allocated pointer to the file content.
9849250f50f2 Start implementation of certificatelist parser
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
44 * @param[out] size Size in Bytes of the file content.
9849250f50f2 Start implementation of certificatelist parser
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
45 *
9849250f50f2 Start implementation of certificatelist parser
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
46 * @return status of the operation.
9849250f50f2 Start implementation of certificatelist parser
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
47 */
28
e783fd99a9eb Add public key parsing
Andre Heinecke <aheinecke@intevation.de>
parents: 22
diff changeset
48 list_status_t read_and_verify_list(const char *fileName, char **data, size_t *size);
59
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
49
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
50 /** @brief verify the certificate list
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
51 *
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
52 * The public key to verify against is the static publicKeyPEM data defined
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
53 * in the pubkey header.
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
54 *
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
55 * @param [in] data the list data
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
56 * @param [in] size the size of the data
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
57 *
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
58 * @returns 0 if the list is valid a polarssl error or -1 otherwise
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
59 */
68
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
60 int verify_list(const char *data, const size_t size);
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
61
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
62 /** @brief get a list of the certificates marked with I:
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
63 *
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
64 * Get a list of certificates that should be installed by the
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
65 * certificatelist pointed to by data.
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
66 * On Success this function makes a copy of the certificates
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
67 * and the certificates need to be freed by the caller.
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
68 *
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
69 * @param [in] data the certificatelist to parse
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
70 * @param [in] size the size of the certificatelist
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
71 *
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
72 * @returns a newly allocated array of strings containing the encoded
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
73 * certificates or NULL on error.
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
74 * */
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
75 char **get_certs_to_install(const char *data, const size_t size);
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
76
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
77 /** @brief get a list of the certificates marked with R:
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
78 *
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
79 * Get a list of certificates that should be removed by the
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
80 * certificatelist pointed to by data.
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
81 * On Success this function makes a copy of the certificates
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
82 * and the certificates need to be freed by the caller.
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
83 *
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
84 * @param [in] data the certificatelist to parse
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
85 * @param [in] size the size of the certificatelist
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
86 *
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
87 * @returns a newly allocated array of strings containing the encoded
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
88 * certificates or NULL on error.
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
89 * */
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
90 char **get_certs_to_remove(const char *data, const size_t size);
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
91
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
92
7
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents: 4
diff changeset
93 #ifdef __cplusplus
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents: 4
diff changeset
94 }
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents: 4
diff changeset
95 #endif
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents: 4
diff changeset
96 #endif

http://wald.intevation.org/projects/trustbridge/