File: libmoonshot.h

package info (click to toggle)
moonshot-ui 1.1.0+libsecret~2
  • links: PTS
  • area: main
  • in suites: bullseye, sid
  • size: 4,460 kB
  • sloc: ansic: 39,118; sh: 4,682; makefile: 201; sed: 27; xml: 10
file content (205 lines) | stat: -rw-r--r-- 9,213 bytes parent folder | download | duplicates (2)
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
/* libmoonshot - Moonshot client library
 * Copyright (c) 2011, JANET(UK)
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * 3. Neither the name of JANET(UK) nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * Author: Sam Thursfield <samthursfield@codethink.co.uk>
 */

#ifndef __LIBMOONSHOT_H
#define __LIBMOONSHOT_H

/**
 * moonshot_free:
 * @pointer: pointer to be freed
 *
 * All the strings returned by the get_identity() functions must be
 * freed using this function when they are no longer needed.
 *
 * @pointer may be %NULL, in which case no action is taken.
 */
void moonshot_free (void *data);

typedef enum {
    MOONSHOT_ERROR_UNABLE_TO_START_SERVICE,
    MOONSHOT_ERROR_NO_IDENTITY_SELECTED,
    MOONSHOT_ERROR_INSTALLATION_ERROR,
    MOONSHOT_ERROR_OS_ERROR,
    MOONSHOT_ERROR_IPC_ERROR
} MoonshotErrorCode;

typedef struct {
    int   code;    /* A MoonshotErrorCode */
    char *message;
} MoonshotError;

/**
 * moonshot_error_free:
 * @error: A #MoonshotError
 *
 * Releases the memory used by @error. This function must be called if
 * a function has returned an error, once it has been reported.
 */
void moonshot_error_free (MoonshotError *error);

/**
 * moonshot_get_identity:
 * @nai: Name and issuer constraint for the required identity, or %NULL.
 * @password: Password for the identity, or %NULL.
 * @service: Service constraint for the required identity, or %NULL.
 * @nai_out: A pointer to a string which receives the name and issuer of the
 *           selected identity.
 * @password_out: A pointer to a string which receives the password.
 * @server_certificate_hash_out: Receives a hash of the identity server's
 *                               certificate, or %NULL.
 * @ca_certificate_out: The CA certificate, if @server_certificate_hash was
 *                      %NULL.
 * @subject_name_constraint_out: Set if @ca_certificate is set, otherwise %NULL.
 * @subject_alt_name_constraint_out: Set if @ca_certificate is set, otherwise
 *                                   %NULL.
 * @error: Return location for a #MoonshotError.
 *
 * This function calls the Moonshot server to request an ID card. The server
 * will be activated if it is not already running. The user interface will be
 * displayed if there is more than one matching identity and the user will be
 * asked to select one.
 *
 * There are two types of trust anchor that may be returned. If
 * @server_certificate_hash is non-empty, the remaining parameters will be
 * empty. Otherwise, the @ca_certificate parameter and the subject name
 * constraints will be returned.
 *
 * Error reporting is handled by a simple mechanism similar to #GError. If
 * an error occurs, as well as returning %FALSE a #MoonshotError object will
 * be stored at *@error, with a code and message string. This must be freed
 * using moonshot_error_free().
 *
 * Return value: %TRUE if an identity was successfully selected, %FALSE on
 *               failure.
 */
int moonshot_get_identity (const char     *nai,
                           const char     *password,
                           const char     *service,
                           char          **nai_out,
                           char          **password_out,
                           char          **server_certificate_hash_out,
                           char          **ca_certificate_out,
                           char          **subject_name_constraint_out,
                           char          **subject_alt_name_constraint_out,
                           MoonshotError **error);

/**
 * moonshot_get_default_identity:
 * @nai_out: A pointer to a string which receives the name and issuer of the
 *           identity.
 * @password_out: A pointer to a string which receives the password.
 * @server_certificate_hash_out: Receives a hash of the identity server's
 *                               certificate, or %NULL.
 * @ca_certificate_out: The CA certificate, if @server_certificate_hash was
 *                      %NULL.
 * @subject_name_constraint_out: Set if @ca_certificate is set, otherwise %NULL.
 * @subject_alt_name_constraint_out: Set if @ca_certificate is set, otherwise
 *                                   %NULL.
 * @error: Return location for a #MoonshotError.
 *
 * This function calls the Moonshot server to request the default identity
 * (the one most recently used). Its semantics are otherwise the same as
 * moonshot_get_identity().
 *
 * Return value: %TRUE if an identity was available, otherwise %FALSE.
 */
int moonshot_get_default_identity (char          **nai_out,
                                   char          **password_out,
                                   char          **server_certificate_hash_out,
                                   char          **ca_certificate_out,
                                   char          **subject_name_constraint_out,
                                   char          **subject_alt_name_constraint_out,
                                   MoonshotError **error);


/**
 * moonshot_install_id_card:
 * @display_name: Display name of card
 * @user_name: Username for identity, or %NULL
 * @password: Password for identity, or %NULL
 * @realm: Realm for identity, or %NULL
 * @rules_patterns: Array of patterns for the service matching rules
 * @rules_patterns_length: Length of @rules_patterns and @rules_always_confirm arrays
 * @rules_always_confirm: Array of 'always confirm' flags corresponding to patterns
 * @rules_always_confirm_length: Length of @rules_patterns and @rules_always_confirm arrays
 * @services: Array of strings listing the services this identity provides
 * @services_length: Length of @services array
 * @ca_cert: The CA certificate, or %NULL
 * @subject: Subject name constraint for @ca_cert, or %NULL
 * @subject_alt: Subject alternative name constraint for @ca_cert, or %NULL
 * @server_cert: Hash of the server certificate; required if @ca_cert is %NULL
 * @error: Return location for a #MoonshotError.
 *
 * Calls the Moonshot server to add a new identity. The user will be prompted
 * if they would like to add the ID card.
 *
 * The values for @rules_patterns_length and @rules_always_confirm_length should
 * always be the same. They are present as separate parameters as a concession to
 * the Vala bindings.
 *
 * Return value: %TRUE if the ID card was successfully added, %FALSE otherwise
 */
int moonshot_install_id_card (const char     *display_name,
                              const char     *user_name,
                              const char     *password,
                              const char     *realm,
                              char           *rules_patterns[],
                              int             rules_patterns_length,
                              char           *rules_always_confirm[],
                              int             rules_always_confirm_length,
                              char           *services[],
                              int             services_length,
                              const char     *ca_cert,
                              const char     *subject,
                              const char     *subject_alt,
                              const char     *server_cert,
                              int             force_flat_file_store,
                              MoonshotError **error);



/**
 * moonshot_confirm_ca_certificate
 * @
 * Return value: %TRUE if the certificate is approved; %FALSE otherwise
 */

int moonshot_confirm_ca_certificate (const char           *identity_name,
                                     const char           *realm,
                                     const unsigned char  *sha256,
                                     int                   sha256_length,
                                     MoonshotError       **error);


#endif