2015-07-21 19:25:04 +02:00
|
|
|
|
;;;; -*- mode: Scheme; indent-tabs-mode: nil; fill-column: 80; -*-
|
|
|
|
|
;;;;
|
|
|
|
|
;;;; Copyright © 2015 Rémi Delrue <asgeir@free.fr>
|
|
|
|
|
;;;;
|
|
|
|
|
;;;; This program is free software: you can redistribute it and/or modify
|
|
|
|
|
;;;; it under the terms of the GNU General Public License as published by
|
|
|
|
|
;;;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
;;;; (at your option) any later version.
|
|
|
|
|
;;;;
|
|
|
|
|
;;;; This program is distributed in the hope that it will be useful,
|
|
|
|
|
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;;;; GNU General Public License for more details.
|
|
|
|
|
;;;;
|
|
|
|
|
;;;; You should have received a copy of the GNU General Public License
|
|
|
|
|
;;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
(define-module (gnu gnunet identity)
|
|
|
|
|
#:use-module (srfi srfi-9)
|
|
|
|
|
#:use-module (system foreign)
|
|
|
|
|
#:use-module (rnrs bytevectors)
|
|
|
|
|
#:use-module (gnu gnunet common)
|
|
|
|
|
#:use-module (gnu gnunet binding-utils)
|
|
|
|
|
#:use-module (gnu gnunet configuration)
|
|
|
|
|
#:export (<ego>
|
|
|
|
|
ego?
|
|
|
|
|
wrap-ego
|
|
|
|
|
unwrap-ego
|
|
|
|
|
|
|
|
|
|
ego-private-key
|
|
|
|
|
ego-public-key
|
|
|
|
|
open-identity-service
|
|
|
|
|
close-identity-service
|
|
|
|
|
get-default-ego
|
|
|
|
|
set-default-ego
|
|
|
|
|
cancel-operation!
|
|
|
|
|
start-ego-lookup
|
2015-07-31 12:10:34 +02:00
|
|
|
|
stop-ego-lookup!
|
|
|
|
|
ecdsa-public-key->string))
|
2015-07-21 19:25:04 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define-record-type <ego>
|
|
|
|
|
(wrap-ego pointer)
|
2015-07-24 21:31:42 +02:00
|
|
|
|
ego?
|
2015-07-21 19:25:04 +02:00
|
|
|
|
(pointer unwrap-ego))
|
|
|
|
|
|
|
|
|
|
|
2015-07-24 21:31:42 +02:00
|
|
|
|
(define-gnunet-id %get-private-key
|
2015-07-21 19:25:04 +02:00
|
|
|
|
"GNUNET_IDENTITY_ego_get_private_key" : '(*) -> '*)
|
2015-07-24 21:31:42 +02:00
|
|
|
|
(define-gnunet-id %get-public-key
|
2015-07-21 19:25:04 +02:00
|
|
|
|
"GNUNET_IDENTITY_ego_get_public_key" : '(* *) -> void)
|
|
|
|
|
|
2015-07-24 21:31:42 +02:00
|
|
|
|
(define-gnunet-id %identity-connect
|
2015-07-21 19:25:04 +02:00
|
|
|
|
"GNUNET_IDENTITY_connect" : '(* * *) -> '*)
|
2015-07-24 21:31:42 +02:00
|
|
|
|
(define-gnunet-id %identity-disconnect
|
2015-07-21 19:25:04 +02:00
|
|
|
|
"GNUNET_IDENTITY_disconnect" : '(*) -> void)
|
|
|
|
|
|
2015-07-24 21:31:42 +02:00
|
|
|
|
(define-gnunet-id %identity-get
|
2015-07-21 19:25:04 +02:00
|
|
|
|
"GNUNET_IDENTITY_get" : '(* * * *) -> '*)
|
2015-07-24 21:31:42 +02:00
|
|
|
|
(define-gnunet-id %identity-set!
|
2015-07-21 19:25:04 +02:00
|
|
|
|
"GNUNET_IDENTITY_set" : '(* * * * *) -> '*)
|
|
|
|
|
|
2015-07-24 21:31:42 +02:00
|
|
|
|
(define-gnunet-id %cancel! "GNUNET_IDENTITY_cancel" : '(*) -> void)
|
2015-07-21 19:25:04 +02:00
|
|
|
|
|
2015-07-24 21:31:42 +02:00
|
|
|
|
(define-gnunet-id %ego-lookup
|
2015-07-21 19:25:04 +02:00
|
|
|
|
"GNUNET_IDENTITY_ego_lookup" : '(* * * *) -> '*)
|
2015-07-24 21:31:42 +02:00
|
|
|
|
(define-gnunet-id %ego-lookup-cancel!
|
2015-07-21 19:25:04 +02:00
|
|
|
|
"GNUNET_IDENTITY_ego_lookup_cancel" : '(*) -> void)
|
2015-07-31 12:10:34 +02:00
|
|
|
|
|
|
|
|
|
(define-gnunet %ecdsa-public-key->string
|
|
|
|
|
"GNUNET_CRYPTO_ecdsa_public_key_to_string" : '(*) -> '*)
|
2015-07-21 19:25:04 +02:00
|
|
|
|
|
|
|
|
|
(define (ego-private-key ego)
|
|
|
|
|
(%get-private-key (unwrap-ego ego)))
|
|
|
|
|
|
|
|
|
|
(define (ego-public-key ego)
|
|
|
|
|
(let ((key (bytevector->pointer
|
|
|
|
|
(make-bytevector (sizeof ecdsa-public-key)))))
|
|
|
|
|
(%get-public-key (unwrap-ego ego) key)
|
|
|
|
|
key))
|
|
|
|
|
|
|
|
|
|
(define (identity-callback->pointer thunk)
|
|
|
|
|
(procedure->pointer void
|
|
|
|
|
(lambda (closure ego context name)
|
|
|
|
|
(thunk (if (eq? %null-pointer ego) #f (wrap-ego ego))
|
|
|
|
|
(pointer->string* name)))
|
|
|
|
|
'(* * * *)))
|
|
|
|
|
|
|
|
|
|
(define (open-identity-service config identity-callback)
|
|
|
|
|
"Connect to the identity service. IDENTITY-CALLBACK is called on each ego
|
|
|
|
|
known by the service, and once with arguments (#f #f) to mark the end of the
|
|
|
|
|
initial pass. Please note IDENTITY-CALLBACK can still be called after that: on
|
|
|
|
|
error (with arguments (#f #f)), and whenever an ego’s name changes or if it is
|
|
|
|
|
deleted.
|
|
|
|
|
|
|
|
|
|
IDENTITY-CALLBACK is a function of two arguments: an ego (or #f) and the name
|
|
|
|
|
assigned by the user for this ego (or #f if the user just deleted this ego).
|
|
|
|
|
|
|
|
|
|
Return a handle to the identity service that’s needed by every identity related
|
|
|
|
|
function."
|
2015-08-10 19:18:22 +02:00
|
|
|
|
(or%
|
|
|
|
|
(%identity-connect (unwrap-configuration config)
|
|
|
|
|
(identity-callback->pointer identity-callback)
|
|
|
|
|
%null-pointer)
|
|
|
|
|
(throw 'invalid-result "open-identity-service" "%identity-connect"
|
|
|
|
|
%null-pointer)))
|
2015-07-21 19:25:04 +02:00
|
|
|
|
|
|
|
|
|
(define (close-identity-service identity-handle)
|
|
|
|
|
"Disconnect from the identity service."
|
|
|
|
|
(%identity-disconnect identity-handle))
|
|
|
|
|
|
|
|
|
|
(define (get-default-ego identity-handle service identity-callback)
|
|
|
|
|
"Obtain the ego that is currently prefered/default for SERVICE.
|
|
|
|
|
|
|
|
|
|
IDENTITY-CALLBACK is called once with arguments (#f #f) on error and with
|
|
|
|
|
non-null arguments on success, in which case OPEN-IDENTITY-SERVICE’s own
|
|
|
|
|
IDENTITY-CALLBACK will also be called.
|
|
|
|
|
|
|
|
|
|
Returns a handle to the “ego retrieving operation” that can be used to
|
|
|
|
|
cancel it (see CANCEL-OPERATION!)."
|
|
|
|
|
(when (string-null? service)
|
2015-08-03 12:38:31 +02:00
|
|
|
|
(throw 'invalid-arg "get-default-ego" service))
|
2015-07-21 19:25:04 +02:00
|
|
|
|
(%identity-get identity-handle (string->pointer service)
|
|
|
|
|
(identity-callback->pointer identity-callback) %null-pointer))
|
|
|
|
|
|
|
|
|
|
(define (set-default-ego identity-handle service ego identity-callback)
|
|
|
|
|
"Set the preferred/default ego for SERVICE.
|
|
|
|
|
|
|
|
|
|
IDENTITY-CALLBACK is called once with arguments (#f #f) on error and with
|
|
|
|
|
non-null arguments on success, in which case OPEN-IDENTITY-SERVICE’s own
|
|
|
|
|
IDENTITY-CALLBACK will also be called.
|
|
|
|
|
|
|
|
|
|
Returns a handle to the “ego setting operation” that can be used to cancel
|
|
|
|
|
it (see CANCEL-OPERATION!)."
|
|
|
|
|
(when (string-null? service)
|
|
|
|
|
(throw 'invalid-arg "set-current-ego" service))
|
|
|
|
|
(when (eq? %null-pointer ego)
|
|
|
|
|
(throw 'invalid-arg "set-current-ego" ego))
|
|
|
|
|
(%identity-set! identity-handle (string->pointer service) (unwrap-ego ego)
|
|
|
|
|
(identity-callback->pointer identity-callback) %null-pointer))
|
|
|
|
|
|
|
|
|
|
(define (cancel-operation! op)
|
|
|
|
|
"Cancel an identity operation.
|
|
|
|
|
|
|
|
|
|
Note that the operation may still be executed, notably if the request was
|
|
|
|
|
already transmitted to the service."
|
|
|
|
|
(when (eq? %null-pointer op)
|
|
|
|
|
(throw 'invalid-arg "cancel-operation!" op))
|
|
|
|
|
(%cancel! op))
|
|
|
|
|
|
|
|
|
|
(define (ego-callback->pointer thunk)
|
|
|
|
|
(procedure->pointer void
|
|
|
|
|
(lambda (closure ego)
|
|
|
|
|
(thunk (if (eq? %null-pointer ego) #f (wrap-ego ego))))
|
|
|
|
|
'(* *)))
|
|
|
|
|
|
|
|
|
|
(define (start-ego-lookup config name ego-callback)
|
|
|
|
|
"Lookup an ego by NAME.
|
|
|
|
|
|
|
|
|
|
Return a handle to the lookup that can be cancelled with CANCEL-EGO-LOOKUP!"
|
2015-07-24 21:31:42 +02:00
|
|
|
|
(when (or (not (string? name))
|
|
|
|
|
(string-null? name))
|
2015-07-21 19:25:04 +02:00
|
|
|
|
(throw 'invalid-arg "lookup-ego" name))
|
|
|
|
|
(%ego-lookup (unwrap-configuration config) (string->pointer name)
|
|
|
|
|
(ego-callback->pointer ego-callback) %null-pointer))
|
|
|
|
|
|
|
|
|
|
(define (stop-ego-lookup! lookup)
|
|
|
|
|
"Abort an ego lookup attempt."
|
|
|
|
|
(%ego-lookup-cancel! lookup))
|
2015-07-31 12:10:34 +02:00
|
|
|
|
|
|
|
|
|
(define (ecdsa-public-key->string key)
|
|
|
|
|
(let* ((%s (%ecdsa-public-key->string key))
|
|
|
|
|
(res (pointer->string %s)))
|
|
|
|
|
(%free %s)
|
|
|
|
|
res))
|