2170
2179
return g_string_free (data, FALSE);
2173
2184
* ag_account_sign:
2174
2185
* @key: the name of the key or prefix of the keys to be signed.
2175
* @token: token for creating signature.
2186
* @token: aegis token (NULL teminated string) or NULL in order to use the
2187
application aegis ID token, for creating the signature. The
2188
application must possess (request) the token.
2177
* Creates signature of the @key with given @token.
2190
* Creates signature of the @key with given @token. The account must be
2191
* stored prior to calling this function.
2180
2194
ag_account_sign (AgAccount *account, const gchar *key, const gchar *token)
2196
#ifdef HAVE_AEGISCRYPTO
2182
2197
AgSignature *sgn;
2183
2198
AgAccountPrivate *priv;
2184
2199
AgServiceChanges *sc;
2201
struct aegis_signature_t signature;
2202
gchar *signature_string;
2187
2204
g_return_if_fail (key != NULL);
2188
2205
g_return_if_fail (token != NULL);
2193
2210
g_return_if_fail (data != NULL);
2195
/* TODO: sign data with token - depends on libmaemosec */
2212
aegis_crypto_result result_sign =
2213
aegis_crypto_sign (data,
2218
g_return_if_fail (result_sign == aegis_crypto_ok);
2197
priv = account->priv;
2198
sc = account_service_changes_get (priv, priv->service, TRUE);
2220
aegis_crypto_signature_to_string (&signature,
2200
2225
sgn = g_slice_new (AgSignature);
2201
sgn->signature = data; //signed_data;
2226
sgn->signature = g_strdup (signature_string);
2227
aegis_crypto_free (signature_string);
2202
2228
sgn->token = g_strdup (token);
2230
priv = account->priv;
2231
sc = account_service_changes_get (priv, priv->service, TRUE);
2204
2233
g_hash_table_insert (sc->signatures,
2205
2234
g_strdup (key), sgn);
2236
aegis_crypto_finish ();
2238
g_warning ("ag_account_sign: aegis-crypto not found! Unable to sign the key.");
2209
2243
* ag_account_verify:
2210
2244
* @key: the name of the key or prefix of the keys to be verified.
2211
* @token: location to receive the pointer to token.
2245
* @token: location to receive the pointer to aegis token.
2213
2247
* Verify if the key is signed and the signature matches the value
2214
* and provides the token which was used for signing the @key.
2248
* and provides the aegis token which was used for signing the @key.
2216
2250
* Returns: %TRUE if the key is signed and the signature matches
2220
2254
ag_account_verify (AgAccount *account, const gchar *key, const gchar **token)
2256
#ifdef HAVE_AEGISCRYPTO
2222
2257
AgAccountPrivate *priv;
2223
2258
AgServiceSettings *ss;
2224
2259
guint service_id;
2227
2262
AgSignature sgn;
2264
aegis_system_mode_t made_in_mode;
2265
aegis_crypto_result result_verify;
2266
aegis_crypto_result result_convert;
2267
struct aegis_signature_t signature;
2229
2270
g_return_val_if_fail (AG_IS_ACCOUNT (account), FALSE);
2236
2277
service_id = (priv->service != NULL) ? priv->service->id : 0;
2239
2279
sql_str = g_string_sized_new (512);
2240
2280
_ag_string_append_printf (sql_str,
2241
2281
"SELECT signature, token FROM Signatures "
2246
2286
(AgQueryCallback)got_account_signature,
2250
data = signature_data(account, key);
2252
/* TODO: verify data with sgn->signature - depends on libmaemosec */
2290
data = signature_data (account, key);
2292
aegis_crypto_init();
2295
result_convert = aegis_crypto_string_to_signature (sgn.signature,
2299
if (result_convert != aegis_crypto_ok) {
2301
aegis_crypto_finish ();
2306
result_verify = aegis_crypto_verify (&signature,
2312
if (result_verify != aegis_crypto_ok) {
2314
aegis_crypto_free (token_name);
2315
aegis_crypto_finish ();
2320
*token = g_strdup (token_name);
2322
aegis_crypto_free (token_name);
2324
aegis_crypto_finish ();
2256
/* temporary solution */
2330
g_warning ("ag_account_verify: aegis-crypto not found! Unable to verify the key.");
2262
* ag_account_verify_with_token:
2336
* ag_account_verify_with_tokens:
2263
2337
* @key: the name of the key or prefix of the keys to be verified.
2264
* @tokens: array of tokens.
2338
* @tokens: array of aegis tokens.
2266
* Verify if the @key is signed with any of the token from the @tokens
2340
* Verify if the @key is signed with any of the tokens from the @tokens
2267
2341
* and the signature is valid.
2269
* Returns: %TRUE if the key is signed with any of the given token
2343
* Returns: %TRUE if the key is signed with any of the given tokens
2270
2344
* and the signature is valid.