interface cleanup: decouple header files
[siplcs.git] / src / core / sip-sec.h
blob73a7ce9d5e335025976bdf27549c7e9fae62a969
1 /**
2 * @file sip-sec.h
4 * pidgin-sipe
6 * Copyright (C) 2010 SIPE Project <http://sipe.sourceforge.net/>
7 * Copyright (C) 2009 pier11 <pier11@operamail.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #define SIPE_UNUSED_PARAMETER __attribute__((unused))
27 /* Opaque type definition for security context */
28 typedef struct sip_sec_context *SipSecContext;
30 typedef enum sip_sec_auth_type
32 AUTH_TYPE_UNSET = 0,
33 AUTH_TYPE_DIGEST,
34 AUTH_TYPE_NTLM,
35 AUTH_TYPE_KERBEROS,
36 AUTH_TYPE_NEGOTIATE
37 } SipSecAuthType;
39 //// Sipe convenience methods ////
41 /**
42 * Initializes Sipe security context.
43 * Obtains cashed initial credentials (TGT for Kerberos) or requests new ones if required.
44 * In former case domain/username/password information is unnecessary.
46 * @param type (in) authentication type
47 * @param sso (in) use Single Sign-On
48 * @param is_connection_based (in) context is used for a connection
49 * @param domain (in) NTLM Domain/Kerberos Realm.
50 * @param username (in) user name (can be NULL)
51 * @param password (in) password (can be NULL)
53 * @return context security context to store and pass between security method invocations
55 SipSecContext
56 sip_sec_create_context(SipSecAuthType type,
57 const int sso,
58 int is_connection_based,
59 const char *domain,
60 const char *username,
61 const char *password);
63 /**
64 * Obtains Service ticket (for Kerberos), base64 encodes it and provide as output.
66 * @param context (in) security context to pass between security method invocations
67 * @param target (in) security target. Service principal name on case of Kerberos.
68 * @param input_toked_base64 (in) base64 encoded input security token. This is Type2 NTLM message or NULL.
69 * @param output_toked_base64 (out) base64 encoded output token to send to server.
70 * @param expires (out) security context expiration time in seconds.
72 * @return SIP_SEC_* value signifying success of the operation.
75 unsigned long
76 sip_sec_init_context_step(SipSecContext context,
77 const char *target,
78 const char *input_toked_base64,
79 char **output_toked_base64,
80 int *expires);
82 /**
83 * A convenience method for sipe. Combines execution on sip_sec_create_context()
84 * and sip_sec_init_context_step(). Suitable for connectionless NTLM (as in SIP).
85 * Unsuitable for connection-based (TCP, TLS) Web authentication.
87 * Initializes security context.
88 * Obtains cashed initial credentials (TGT for Kerberos) or requests new ones if required. In former case domain/username/password information is unnecessary.
89 * Then obtains Service ticket (for Kerberos) , base64 encodes it and provide as output.
91 * @param context (in,out) security context to store and pass between security method invocations
92 * @param mech (in) security mechanism - NTLM or Kerberos
93 * @param domain (in) NTLM Domain/Kerberos Realm.
94 * @param target (in) security target. Service principal name on case of Kerberos.
95 * @param input_toked_base64 (in) base64 encoded input security token. This is Type2 NTLM message or NULL for Kerberos.
96 * @param expires (out) security context expiration time in seconds.
98 * @return base64 encoded output token to send to server.
100 char *sip_sec_init_context(SipSecContext *context,
101 int *expires,
102 SipSecAuthType type,
103 const int sso,
104 const char *domain,
105 const char *username,
106 const char *password,
107 const char *target,
108 const char *input_toked_base64);
111 * A convenience method for sipe.
112 * Destroys security context.
114 * @param context (in,out) security context to destroy
116 void sip_sec_destroy_context(SipSecContext context);
119 * A convenience method for sipe.
120 * Signs incoming message.
122 * @param message (in) a message to sign.
124 * @return signature for the message. Converted to Hex null terminated string;
126 char *sip_sec_make_signature(SipSecContext context,
127 const char *message);
130 * A convenience method for sipe.
131 * Verifies signature for the message.
133 * @param mesage (in) which signature to verify. Null terminated string.
134 * @param signature_hex (in) signature to test in Hex representation. Null terminated string. Example: "602306092A864886F71201020201011100FFFFFFFF1A306ACB7BE311827BBF7208D80D15E3"
136 * @return FALSE on error
138 int sip_sec_verify_signature(SipSecContext context,
139 const char *message,
140 const char *signature_hex);