r3409 - in trunk/libmcrypto: . source source/gnutls
mikma at minisip.org
mikma at minisip.org
Thu Aug 30 23:04:36 CEST 2007
Author: mikma
Date: 2007-08-30 23:04:36 +0200 (Thu, 30 Aug 2007)
New Revision: 3409
Added:
trunk/libmcrypto/source/gnutls/TlsSrpSocket.cxx
Removed:
trunk/libmcrypto/source/TlsSrpSocket.cxx
Modified:
trunk/libmcrypto/configure.ac
trunk/libmcrypto/source/Makefile.am
trunk/libmcrypto/source/gnutls/Makefile.am
Log:
* Check for gnutls-extra in libmcrypto configure.
* Move GNU TLS TlsSrpSocket implementation to gnutls subdir.
Modified: trunk/libmcrypto/configure.ac
===================================================================
--- trunk/libmcrypto/configure.ac 2007-08-30 20:21:51 UTC (rev 3408)
+++ trunk/libmcrypto/configure.ac 2007-08-30 21:04:36 UTC (rev 3409)
@@ -32,6 +32,7 @@
if test "${with_gnutls}" = "yes"; then
AM_LIBMCRYPTO_CHECK_GNUTLS([HAVE_GNUTLS=yes],[HAVE_GNUTLS=no])
+ PKG_CHECK_MODULES([GNUTLS_EXTRA],[gnutls-extra],[HAVE_GNUTLS_EXTRA=yes],[HAVE_GNUTLS_EXTRA=no])
have_sha256=${HAVE_GNUTLS}
fi
AM_CONDITIONAL(HAVE_GNUTLS, test "x${HAVE_GNUTLS}" = "xyes")
@@ -72,8 +73,12 @@
[enables TLS-SRP support]),
[ if test "${enable_srp}" = "yes"
then
- AC_DEFINE(ENABLE_SRP, [], [TLS-SRP support is enabled])
- ENABLE_SRP="yes"
+ if test "$HAVE_GNUTLS_EXTRA" = "yes"; then
+ AC_DEFINE(ENABLE_SRP, [], [TLS-SRP support is enabled])
+ ENABLE_SRP="yes"
+ else
+ AC_MSG_ERROR([TLS-SRP support requires GNU TLS extra])
+ fi
fi
])
AM_CONDITIONAL(ENABLE_SRP, test "${ENABLE_SRP}" = "yes" )
Modified: trunk/libmcrypto/source/Makefile.am
===================================================================
--- trunk/libmcrypto/source/Makefile.am 2007-08-30 20:21:51 UTC (rev 3408)
+++ trunk/libmcrypto/source/Makefile.am 2007-08-30 21:04:36 UTC (rev 3409)
@@ -28,13 +28,6 @@
SmartCardException.cxx
endif
-srp_src =
-if ENABLE_SRP
-srp_src += TlsSrpSocket.cxx
-srp_libs = $(GNUTLS_LIBS)
-endif
-
-
libmcrypto_core_la_SOURCES = \
aes.cxx \
SipSim.cxx \
@@ -43,7 +36,6 @@
init.cxx \
$(scsim_src) \
base64.cxx \
- $(srp_src) \
TlsException.cxx \
uuid.cxx \
rijndael-alg-fst.cxx \
@@ -51,7 +43,7 @@
CertificateFinder.cxx \
CertificatePathFinderUcd.cxx
-libmcrypto_core_la_LIBADD = $(srp_libs) $(SCSIM_LIBS)
+libmcrypto_core_la_LIBADD = $(SCSIM_LIBS)
libmcrypto_imp_la_SOURCES = # none
libmcrypto_imp_la_LIBADD = $(BUILD_LIBS)
Deleted: trunk/libmcrypto/source/TlsSrpSocket.cxx
===================================================================
--- trunk/libmcrypto/source/TlsSrpSocket.cxx 2007-08-30 20:21:51 UTC (rev 3408)
+++ trunk/libmcrypto/source/TlsSrpSocket.cxx 2007-08-30 21:04:36 UTC (rev 3409)
@@ -1,179 +0,0 @@
-/*
- * Copyright (C) 2004-2006 the Minisip Team
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- * */
-
-/* Copyright (C) 2006
- *
- * Authors: Erik Ehrlund <eehrlund at kth.se>
-*/
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <gnutls/gnutls.h>
-#include <gnutls/extra.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <iostream>
-#include <string>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <errno.h>
-#include <netdb.h>
-
-#include<libmcrypto/TlsSrpSocket.h>
-#include<libmcrypto/TlsException.h>
-#include<libmnetutil/NetworkException.h>
-using namespace std;
-
-
-/************************************************************************/
-static void checkErr(int a)
-{
- if(a<0)
- {
- perror("An error has occured");
- throw TLSInitFailed();
- return;
- }
-}
-
-/************************************************************************/
-const int kx_priority[] =
-{
- GNUTLS_KX_SRP, 0
-};
-
-/*********************************************************************************/
-/* constructor*/
-TlsSrpSocket::TlsSrpSocket(string addrs, int32_t port, string user, string pass)
-{
- type = SOCKET_TYPE_TLSSRP;
- TlsSrpSocket::TlsSrpSocketSrp_init(addrs, port, user, pass);
-}
-
-/*********************************************************************************/
-TlsSrpSocket::~TlsSrpSocket()
-{
- gnutls_bye (session, GNUTLS_SHUT_WR);
- gnutls_deinit (session);
- gnutls_srp_free_client_credentials (srp_cred);
- gnutls_global_deinit ();
- ::close(fd);
-}
-
-/*********************************************************************************/
-void TlsSrpSocket::TlsSrpSocketSrp_init(string addrs, int32_t port, string user, string pass)
-{
-
- int err=0;
- const char *usr = user.c_str();
- const char *passw = pass.c_str();
- const char *address = addrs.c_str();
- /* init gnutls */
- gnutls_global_init ();
- gnutls_global_init_extra ();
- gnutls_srp_allocate_client_credentials (&srp_cred);
- gnutls_srp_set_client_credentials (srp_cred, usr, passw);
-
- /* fix dest address */
- struct in_addr *dstaddr;
- struct hostent *hst;
- struct sockaddr_in addr;
-
- memset (&addr, '\0', sizeof (addr));
- //cout<<"IPAddress: "<<address<<" usr: "<<usr<<" passw: "<<passw<<endl;
- hst = gethostbyname(address);
- if(hst ==NULL)
- {
- perror("Could not resolve host address");
- throw ResolvError(-1);
- return;
- }
-
- dstaddr = (struct in_addr *)hst->h_addr;
- memcpy(&(addr.sin_addr), dstaddr, sizeof(struct in_addr));
-
- addr.sin_family=AF_INET;
- addr.sin_port = htons(port);
- memset(&(addr.sin_zero), '\0', 8);
-
- /* fix socket desc*/
-
- fd = socket(PF_INET, SOCK_STREAM, 0);
- if(fd<0){
- throw SocketFailed( -1 );
- return;
- }
- err = connect(fd, (struct sockaddr *)&addr, sizeof(struct sockaddr));
- if(err<0)
- {
- ::close(fd);
- throw ConnectFailed(-1);
- return;
- }
-
-
- err = gnutls_init (&session, GNUTLS_CLIENT);
- checkErr(err);
-
- err= gnutls_set_default_priority (session); //use default cipher, mac and key exchange
- checkErr(err);
-
- err = gnutls_kx_set_priority (session, kx_priority); //overides default key exchange
- checkErr(err);
-
- err = gnutls_credentials_set (session, GNUTLS_CRD_SRP, srp_cred);
- checkErr(err);
-
- gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) fd);
-
- err = gnutls_handshake (session);
- if (err<0)
- {
- perror("****** HANDSHAKE FAILED ********");
- gnutls_perror(err);
- throw "handshake failed";
- return;
- }
- return;
-}
-
-/********************************************************************************/
-
-int32_t TlsSrpSocket::write(const void *msg, int length)
-{
- int a ;
- a = gnutls_record_send (session, msg , length);
- return a;
-}
-/*********************************************************************************/
-int32_t TlsSrpSocket::write(string msg)
-{
- int a ;
- a = gnutls_record_send (session, msg.c_str(), msg.size());
- return a;
-}
-
-/*********************************************************************************/
-int32_t TlsSrpSocket::read (void *buf, int maxlength)
-{
- int recv;
- recv = gnutls_record_recv (session, buf, maxlength);
- return recv;
-}
Modified: trunk/libmcrypto/source/gnutls/Makefile.am
===================================================================
--- trunk/libmcrypto/source/gnutls/Makefile.am 2007-08-30 20:21:51 UTC (rev 3408)
+++ trunk/libmcrypto/source/gnutls/Makefile.am 2007-08-30 21:04:36 UTC (rev 3409)
@@ -1,6 +1,13 @@
noinst_LTLIBRARIES = \
libmcgnutls.la
+srp_src =
+if ENABLE_SRP
+srp_src += TlsSrpSocket.cxx
+srp_libs = $(GNUTLS_EXTRA_LIBS)
+endif
+
+
libmcgnutls_la_CPPFLAGS = $(MINISIP_CFLAGS)
libmcgnutls_la_SOURCES = \
aes.cxx \
@@ -14,10 +21,11 @@
sha256.cxx \
TlsServerSocket.cxx \
TlsSocket.cxx \
+ $(srp_src) \
ZrtpDH.cxx
-libmcgnutls_la_LIBADD = $(GNUTLS_LIBS)
+libmcgnutls_la_LIBADD = $(GNUTLS_LIBS) $(srp_libs)
MAINTAINERCLEANFILES = \
$(srcdir)/Makefile.in
Copied: trunk/libmcrypto/source/gnutls/TlsSrpSocket.cxx (from rev 3407, trunk/libmcrypto/source/TlsSrpSocket.cxx)
===================================================================
--- trunk/libmcrypto/source/gnutls/TlsSrpSocket.cxx (rev 0)
+++ trunk/libmcrypto/source/gnutls/TlsSrpSocket.cxx 2007-08-30 21:04:36 UTC (rev 3409)
@@ -0,0 +1,179 @@
+/*
+ * Copyright (C) 2004-2006 the Minisip Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * */
+
+/* Copyright (C) 2006
+ *
+ * Authors: Erik Ehrlund <eehrlund at kth.se>
+*/
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <gnutls/gnutls.h>
+#include <gnutls/extra.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <iostream>
+#include <string>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <errno.h>
+#include <netdb.h>
+
+#include<libmcrypto/TlsSrpSocket.h>
+#include<libmcrypto/TlsException.h>
+#include<libmnetutil/NetworkException.h>
+using namespace std;
+
+
+/************************************************************************/
+static void checkErr(int a)
+{
+ if(a<0)
+ {
+ perror("An error has occured");
+ throw TLSInitFailed();
+ return;
+ }
+}
+
+/************************************************************************/
+const int kx_priority[] =
+{
+ GNUTLS_KX_SRP, 0
+};
+
+/*********************************************************************************/
+/* constructor*/
+TlsSrpSocket::TlsSrpSocket(string addrs, int32_t port, string user, string pass)
+{
+ type = SOCKET_TYPE_TLSSRP;
+ TlsSrpSocket::TlsSrpSocketSrp_init(addrs, port, user, pass);
+}
+
+/*********************************************************************************/
+TlsSrpSocket::~TlsSrpSocket()
+{
+ gnutls_bye (session, GNUTLS_SHUT_WR);
+ gnutls_deinit (session);
+ gnutls_srp_free_client_credentials (srp_cred);
+ gnutls_global_deinit ();
+ ::close(fd);
+}
+
+/*********************************************************************************/
+void TlsSrpSocket::TlsSrpSocketSrp_init(string addrs, int32_t port, string user, string pass)
+{
+
+ int err=0;
+ const char *usr = user.c_str();
+ const char *passw = pass.c_str();
+ const char *address = addrs.c_str();
+ /* init gnutls */
+ gnutls_global_init ();
+ gnutls_global_init_extra ();
+ gnutls_srp_allocate_client_credentials (&srp_cred);
+ gnutls_srp_set_client_credentials (srp_cred, usr, passw);
+
+ /* fix dest address */
+ struct in_addr *dstaddr;
+ struct hostent *hst;
+ struct sockaddr_in addr;
+
+ memset (&addr, '\0', sizeof (addr));
+ //cout<<"IPAddress: "<<address<<" usr: "<<usr<<" passw: "<<passw<<endl;
+ hst = gethostbyname(address);
+ if(hst ==NULL)
+ {
+ perror("Could not resolve host address");
+ throw ResolvError(-1);
+ return;
+ }
+
+ dstaddr = (struct in_addr *)hst->h_addr;
+ memcpy(&(addr.sin_addr), dstaddr, sizeof(struct in_addr));
+
+ addr.sin_family=AF_INET;
+ addr.sin_port = htons(port);
+ memset(&(addr.sin_zero), '\0', 8);
+
+ /* fix socket desc*/
+
+ fd = socket(PF_INET, SOCK_STREAM, 0);
+ if(fd<0){
+ throw SocketFailed( -1 );
+ return;
+ }
+ err = connect(fd, (struct sockaddr *)&addr, sizeof(struct sockaddr));
+ if(err<0)
+ {
+ ::close(fd);
+ throw ConnectFailed(-1);
+ return;
+ }
+
+
+ err = gnutls_init (&session, GNUTLS_CLIENT);
+ checkErr(err);
+
+ err= gnutls_set_default_priority (session); //use default cipher, mac and key exchange
+ checkErr(err);
+
+ err = gnutls_kx_set_priority (session, kx_priority); //overides default key exchange
+ checkErr(err);
+
+ err = gnutls_credentials_set (session, GNUTLS_CRD_SRP, srp_cred);
+ checkErr(err);
+
+ gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) fd);
+
+ err = gnutls_handshake (session);
+ if (err<0)
+ {
+ perror("****** HANDSHAKE FAILED ********");
+ gnutls_perror(err);
+ throw "handshake failed";
+ return;
+ }
+ return;
+}
+
+/********************************************************************************/
+
+int32_t TlsSrpSocket::write(const void *msg, int length)
+{
+ int a ;
+ a = gnutls_record_send (session, msg , length);
+ return a;
+}
+/*********************************************************************************/
+int32_t TlsSrpSocket::write(string msg)
+{
+ int a ;
+ a = gnutls_record_send (session, msg.c_str(), msg.size());
+ return a;
+}
+
+/*********************************************************************************/
+int32_t TlsSrpSocket::read (void *buf, int maxlength)
+{
+ int recv;
+ recv = gnutls_record_recv (session, buf, maxlength);
+ return recv;
+}
More information about the Minisip-devel
mailing list