diff options
| -rw-r--r-- | libdino/meson.build | 6 | ||||
| -rw-r--r-- | libdino/src/crypto/dtls_srtp.vala (renamed from plugins/ice/src/dtls_srtp.vala) | 2 | ||||
| -rw-r--r-- | libdino/src/crypto/gnu/dtls_srtp.vala (renamed from plugins/ice/src/dtls_srtp_gnutls.vala) | 8 | ||||
| -rw-r--r-- | libdino/src/crypto/openssl/dtls_srtp.vala (renamed from plugins/ice/src/dtls_srtp_openssl.vala) | 8 | ||||
| -rw-r--r-- | libdino/src/crypto/openssl/utils.c (renamed from plugins/ice/src/openssl_utils.c) | 2 | ||||
| -rw-r--r-- | libdino/src/crypto/openssl/utils.h (renamed from plugins/ice/src/openssl_utils.h) | 0 | ||||
| -rw-r--r-- | libdino/vapi/gnutls.vapi (renamed from plugins/ice/vapi/gnutls.vapi) | 0 | ||||
| -rw-r--r-- | libdino/vapi/openssl.vapi | 2 | ||||
| -rw-r--r-- | plugins/ice/meson.build | 13 | ||||
| -rw-r--r-- | plugins/ice/src/module.vala | 4 | ||||
| -rw-r--r-- | plugins/ice/src/transport_parameters.vala | 2 | ||||
| -rw-r--r-- | plugins/ice/vapi/openssl.vapi | 218 |
12 files changed, 21 insertions, 244 deletions
diff --git a/libdino/meson.build b/libdino/meson.build index 5c7c20c4..67ac6a83 100644 --- a/libdino/meson.build +++ b/libdino/meson.build @@ -19,6 +19,7 @@ sources = files( 'src/dbus/upower.vala', 'src/crypto/cipher.vala', 'src/crypto/cipher_converter.vala', + 'src/crypto/dtls_srtp.vala', 'src/crypto/error.vala', 'src/crypto/srtp.vala', 'src/entity/account.vala', @@ -92,15 +93,18 @@ sources = files( sources += [version_c] if crypto_backend == 'gnu' - dependencies += [ dep_libgcrypt ] + dependencies += [ dep_libgcrypt, dep_gnutls ] sources += files( 'src/crypto/gnu/cipher.vala', + 'src/crypto/gnu/dtls_srtp.vala', 'src/crypto/gnu/utils.vala', ) elif crypto_backend == 'openssl' dependencies += [ dep_openssl ] sources += files( 'src/crypto/openssl/cipher.vala', + 'src/crypto/openssl/dtls_srtp.vala', + 'src/crypto/openssl/utils.c', 'src/crypto/openssl/utils.vala', ) endif diff --git a/plugins/ice/src/dtls_srtp.vala b/libdino/src/crypto/dtls_srtp.vala index 41918359..884f1a43 100644 --- a/plugins/ice/src/dtls_srtp.vala +++ b/libdino/src/crypto/dtls_srtp.vala @@ -1,4 +1,4 @@ -namespace Dino.Plugins.Ice.DtlsSrtp { +namespace Dino.Crypto.DtlsSrtp { public abstract class CredentialsCapsule : Object { public uint8[] own_fingerprint; diff --git a/plugins/ice/src/dtls_srtp_gnutls.vala b/libdino/src/crypto/gnu/dtls_srtp.vala index 91a7cfb2..f6f0a24e 100644 --- a/plugins/ice/src/dtls_srtp_gnutls.vala +++ b/libdino/src/crypto/gnu/dtls_srtp.vala @@ -1,10 +1,10 @@ using GnuTLS; -namespace Dino.Plugins.Ice.DtlsSrtp { +namespace Dino.Crypto.DtlsSrtp { public class CredentialsCapsuleGnuTLS : CredentialsCapsule { - public X509.Certificate[] own_cert; - public X509.PrivateKey private_key; + internal X509.Certificate[] own_cert; + internal X509.PrivateKey private_key; } private uint8[] get_fingerprint(X509.Certificate certificate, DigestAlgorithm digest_algo) { @@ -19,7 +19,7 @@ private uint8[] get_fingerprint(X509.Certificate certificate, DigestAlgorithm di return ret; } -internal CredentialsCapsule generate_credentials () throws GLib.Error { +public CredentialsCapsule generate_credentials () throws GLib.Error { int err = 0; X509.PrivateKey private_key = X509.PrivateKey.create (); diff --git a/plugins/ice/src/dtls_srtp_openssl.vala b/libdino/src/crypto/openssl/dtls_srtp.vala index 86f080e5..192f0da2 100644 --- a/plugins/ice/src/dtls_srtp_openssl.vala +++ b/libdino/src/crypto/openssl/dtls_srtp.vala @@ -1,13 +1,13 @@ using OpenSSL; -namespace Dino.Plugins.Ice.DtlsSrtp { +namespace Dino.Crypto.DtlsSrtp { public class CredentialsCapsuleOpenSSL : CredentialsCapsule { - public X509.Certificate own_cert; - public EVP.Key private_key; + internal X509.Certificate own_cert; + internal EVP.Key private_key; } -internal CredentialsCapsule generate_credentials () throws GLib.Error { +public CredentialsCapsule generate_credentials () throws GLib.Error { EVP.Key key = new EVP.Key.generate_ecdsa ("prime256v1"); var start_time = new DateTime.now_local().add_days(-1); diff --git a/plugins/ice/src/openssl_utils.c b/libdino/src/crypto/openssl/utils.c index 7f4bf331..1a84f642 100644 --- a/plugins/ice/src/openssl_utils.c +++ b/libdino/src/crypto/openssl/utils.c @@ -1,4 +1,4 @@ -#include "openssl_utils.h" +#include "utils.h" #include <openssl/opensslv.h> #include <openssl/ec.h> diff --git a/plugins/ice/src/openssl_utils.h b/libdino/src/crypto/openssl/utils.h index bcc6f53a..bcc6f53a 100644 --- a/plugins/ice/src/openssl_utils.h +++ b/libdino/src/crypto/openssl/utils.h diff --git a/plugins/ice/vapi/gnutls.vapi b/libdino/vapi/gnutls.vapi index 86a8c401..86a8c401 100644 --- a/plugins/ice/vapi/gnutls.vapi +++ b/libdino/vapi/gnutls.vapi diff --git a/libdino/vapi/openssl.vapi b/libdino/vapi/openssl.vapi index 87693d37..57e4022c 100644 --- a/libdino/vapi/openssl.vapi +++ b/libdino/vapi/openssl.vapi @@ -86,7 +86,7 @@ namespace OpenSSL { [CCode (cname = "EVP_PKEY", lower_case_cprefix = "EVP_PKEY_", cprefix = "EVP_PKEY_", ref_function = "EVP_PKEY_up_ref", ref_function_void = true, unref_function = "EVP_PKEY_free")] public class Key { public Key (); - [CCode (cheader_filename = "openssl_utils.h")] + [CCode (cheader_filename = "crypto/openssl/utils.h")] public Key.generate_ecdsa (string curve); } [Compact] diff --git a/plugins/ice/meson.build b/plugins/ice/meson.build index 99f8e6a1..19030259 100644 --- a/plugins/ice/meson.build +++ b/plugins/ice/meson.build @@ -8,7 +8,6 @@ dependencies = [ dep_xmpp_vala, ] sources = files( - 'src/dtls_srtp.vala', 'src/module.vala', 'src/plugin.vala', 'src/transport_parameters.vala', @@ -21,18 +20,6 @@ c_args = vala_c_args + [ vala_args = [ '--vapidir', meson.current_source_dir() / 'vapi', ] -if crypto_backend == 'gnu' - dependencies += [ dep_gnutls ] - sources += files( - 'src/dtls_srtp_gnutls.vala' - ) -elif crypto_backend == 'openssl' - dependencies += [ dep_openssl ] - sources += files( - 'src/dtls_srtp_openssl.vala', - 'src/openssl_utils.c', - ) -endif lib_ice = shared_library('ice', sources, name_prefix: '', c_args: c_args, vala_args: vala_args, include_directories: include_directories('src'), dependencies: dependencies, install: true, install_dir: get_option('libdir') / get_option('plugindir'), install_rpath: default_install_rpath) dep_ice = declare_dependency(link_with: lib_ice, include_directories: include_directories('.')) summary('Peer-to-peer communication (ice)', dep_ice.found(), bool_yn: true, section: 'Plugins') diff --git a/plugins/ice/src/module.vala b/plugins/ice/src/module.vala index ace62108..c3c92124 100644 --- a/plugins/ice/src/module.vala +++ b/plugins/ice/src/module.vala @@ -1,4 +1,6 @@ using Gee; + +using Dino.Crypto; using Xmpp; using Xmpp.Xep; @@ -43,7 +45,7 @@ public class Dino.Plugins.Ice.Module : JingleIceUdp.Module { string from_to_id = local_full_jid.to_string() + peer_full_jid.to_string(); try { if (!cerds.has_key(from_to_id)) cerds[from_to_id] = DtlsSrtp.generate_credentials(); - } catch (Error e) { + } catch (GLib.Error e) { warning("Error creating dtls credentials: %s", e.message); } return cerds[from_to_id]; diff --git a/plugins/ice/src/transport_parameters.vala b/plugins/ice/src/transport_parameters.vala index 66dde8b1..122207c5 100644 --- a/plugins/ice/src/transport_parameters.vala +++ b/plugins/ice/src/transport_parameters.vala @@ -1,4 +1,6 @@ using Gee; + +using Dino.Crypto; using Xmpp; using Xmpp.Xep; diff --git a/plugins/ice/vapi/openssl.vapi b/plugins/ice/vapi/openssl.vapi deleted file mode 100644 index e0654869..00000000 --- a/plugins/ice/vapi/openssl.vapi +++ /dev/null @@ -1,218 +0,0 @@ -[CCode (cprefix = "")] -namespace OpenSSL { - [CCode (cprefix = "ASN1_", lower_case_cprefix = "ASN1_", cheader_filename = "openssl/asn1.h")] - namespace ASN1 { - [Compact] - [CCode (cname = "ASN1_INTEGER", lower_case_cprefix = "ASN1_INTEGER_", cprefix = "ASN1_INTEGER_", free_function = "ASN1_INTEGER_free")] - public class Integer { - public bool @set (long v); - } - - [Compact] - [CCode (cname = "ASN1_TIME", lower_case_cprefix = "ASN1_TIME_", cprefix = "ASN1_TIME_", copy_function = "ASN1_TIME_dup", free_function = "ASN1_STRING_free")] - public class Time { - public bool @set (time_t t); - } - } - [Compact] - [CCode (cname = "BIO", lower_case_cprefix = "BIO_", cprefix = "BIO_", ref_function = "BIO_up_ref", ref_function_void = true, unref_function = "BIO_free", cheader_filename = "openssl/bio.h", simple_generics = true)] - public class BIO<T> { - [Compact] - [CCode (cname = "BIO_METHOD", lower_case_cprefix = "BIO_meth_", cprefix = "BIO_meth_", unref_function = "BIO_meth_free", simple_generics = true)] - public class Method<T> { - public Method (Type type, string name); - [CCode (has_target = false)] - public delegate int WriteFunc<T> (BIO<T> bio, [CCode (type = "const char *", array_length_type = "int")] uint8[] buf); - [CCode (has_target = false)] - public delegate int ReadFunc<T> (BIO<T> bio, [CCode (type = "char *", array_length_type = "int")] uint8[] out_buf); - [CCode (has_target = false, simple_generics = true)] - public delegate long CtrlFunc<T> (BIO<T> bio, ControlCommand cmd, long num, void* ptr); - public WriteFunc<T> write { get; set; } - public ReadFunc<T> read { get; set; } - public CtrlFunc<T> ctrl { get; set; } - } - - [Flags] - [CCode (cname = "int")] - public enum Type { - SOURCE_SINK, - DGRAM, - } - - [CCode (cname = "int", cprefix = "BIO_CTRL_", has_type_id = false)] - public enum ControlCommand { - RESET, - EOF, - SET, - GET, - PUSH, - POP, - GET_CLOSE, - SET_CLOSE, - PENDING, - FLUSH, - DUP, - WPENDING, - - DGRAM_QUERY_MTU, - DGRAM_GET_MTU, - DGRAM_SET_MTU, - DGRAM_SET_PEER, - DGRAM_SET_NEXT_TIMEOUT, - DGRAM_GET_PEER, - DGRAM_GET_FALLBACK_MTU, - DGRAM_SET_DONT_FRAG, - DGRAM_GET_MTU_OVERHEAD, - } - - public BIO (Method<T> type); - public T data { get; set; } - - public void clear_retry_flags (); - public void set_retry_read (); - public bool should_read (); - } - - [CCode (cprefix = "ERR_", lower_case_cprefix = "ERR_", cheader_filename = "openssl/err.h")] - namespace ERR { - public ulong get_error (); - public unowned string lib_error_string (ulong error); - public unowned string reason_error_string (ulong error); - } - - [CCode (cprefix = "EVP_", lower_case_cprefix = "EVP_", cheader_filename = "openssl/evp.h")] - namespace EVP { - [Compact] - [CCode (cname = "EVP_PKEY", lower_case_cprefix = "EVP_PKEY_", cprefix = "EVP_PKEY_", ref_function = "EVP_PKEY_up_ref", ref_function_void = true, unref_function = "EVP_PKEY_free")] - public class Key { - public Key (); - [CCode (cheader_filename = "openssl_utils.h")] - public Key.generate_ecdsa (string curve); - } - [Compact] - [CCode (cname = "EVP_MD", lower_case_cprefix = "EVP_MD_", cprefix = "EVP_MD_", ref_function = "EVP_MD_up_ref", ref_function_void = true, unref_function = "EVP_MD_free")] - public class MessageDigest { - } - - public static unowned MessageDigest sha256 (); - } - - [Compact] - [CCode (cname = "SSL", lower_case_cprefix = "SSL_", cprefix = "SSL_", ref_function = "SSL_up_ref", ref_function_void = true, unref_function = "SSL_free", cheader_filename = "openssl/ssl.h")] - class SSL { - [Compact] - [CCode (cname = "SSL_CTX", lower_case_cprefix = "SSL_CTX_", cprefix = "SSL_CTX_", ref_function = "SSL_CTX_up_ref", ref_function_void = true, unref_function = "SSL_CTX_free")] - public class Context { - public Context (Method method); - public int set_tlsext_use_srtp (string profiles); - public int use_certificate (X509.Certificate certificate); - [CCode (cname = "SSL_CTX_use_PrivateKey")] - public int use_private_key (EVP.Key private_key); - } - - [CCode (cname = "const SSL_METHOD*")] - public enum Method { - [CCode (cname = "DTLS_client_method()")] - DTLS_CLIENT, - [CCode (cname = "DTLS_server_method()")] - DTLS_SERVER, - } - - [CCode (cname = "int", has_type_id = false)] - public enum Error { - NONE, - ZERO_RETURN, - WANT_READ, - WANT_WRITE, - WANT_CONNECT, - WANT_ACCEPT, - WANT_X509_LOOKUP, - WANT_ASYNC, - WANT_ASYNC_JOB, - WANT_CLIENT_HELLO_CB, - SYSCALL, - SSL - } - - public SSL (Context context); - public BIO rbio { get; [CCode (cname="SSL_set0_rbio")] owned set; } - public BIO wbio { get; [CCode (cname="SSL_set0_wbio")] owned set; } - - [CCode (cname = "SSL_do_handshake")] - private int do_handshake_ (); - [CCode (cname = "SSL_do_handshake_")] - public Error do_handshake () throws GLib.Error { - int ret = throw_if_error (do_handshake_ ()); - return get_error (ret); - } - [CCode (cname = "SSL_export_keying_material")] - private int export_keying_material_ (uint8[] out, string label, size_t llen, [CCode (type = "const unsigned char *")] string context, size_t contextlen, bool use_context); - [CCode (cname = "SSL_export_keying_material_")] - public void export_keying_material (uint8[] out, string label, string? context = null) throws GLib.Error { - throw_if_error (export_keying_material_ (@out, label, label.length, context, context == null ? 0 : context.length, context != null)); - } - public Error get_error (int ret); - public void set_accept_state (); - public void set_connect_state (); - public int want (); - } - - [CCode (cprefix = "X509_", lower_case_cprefix = "X509_", cheader_filename = "openssl/x509.h")] - namespace X509 { - [Compact] - [CCode (cname = "X509", lower_case_cprefix = "X509_", cprefix = "X509_", ref_function = "X509_up_ref", ref_function_void = true, unref_function = "X509_free")] - public class Certificate { - public Certificate (); - public ASN1.Time not_before { - [CCode (cname = "X509_get_notBefore")] - get; - [CCode (cname = "X509_set_notBefore")] - set; - } - public ASN1.Time not_after { - [CCode (cname = "X509_get_notAfter")] - get; - [CCode (cname = "X509_set_notAfter")] - set; - } - public ASN1.Integer serial_number { - [CCode (cname = "X509_get_serialNumber")] - get; - [CCode (cname = "X509_set_serialNumber")] - set; - } - [CCode (cname = "X509_digest")] - private int digest_ (EVP.MessageDigest type, uchar* md, ref uint len); - [CCode (cname = "X509_digest_")] - public uint8[] digest (EVP.MessageDigest type, size_t buf_len = 512) throws GLib.Error { - uint8[] buf = new uint8[buf_len]; - uint buf_out_size = (uint) buf_len; - throw_if_error (digest_ (type, (uchar*) buf, ref buf_out_size)); - - uint8[] ret = new uint8[buf_out_size]; - for (int i = 0; i < buf_out_size; i++) { - ret[i] = buf[i]; - } - return ret; - } - [CCode (cname = "X509_set_pubkey")] - public int set_public_key (EVP.Key public_key); - public int set_version (long version); - [CCode (cname = "X509_sign")] - private int sign_ (EVP.Key private_key, EVP.MessageDigest md); - [CCode (cname = "X509_sign_")] - public void sign (EVP.Key private_key, EVP.MessageDigest md) throws GLib.Error { - throw_if_error (sign_ (private_key, md)); - } - } - } - - public int throw_if_error(int res) throws GLib.Error { - if (res <= 0) { - ulong error = ERR.get_error (); - if (error == 0) return res; - throw new GLib.Error (-1, (int) error, "%s:%s", ERR.lib_error_string (error), ERR.reason_error_string (error)); - } - return res; - } -}
\ No newline at end of file |
