Changeset 5406

Show
Ignore:
Timestamp:
03/15/08 09:31:25 (4 months ago)
Author:
morris
Message:

Add WI_P7_TLS socket options, allows tunneling P7 over a TLS connection

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • libwired/trunk/config.m4

    r5030 r5406  
    9797AC_DEFUN([WI_INCLUDE_P7_LIBRARIES], [ 
    9898        WI_INCLUDE_CRYPTO_LIBRARY 
     99        WI_INCLUDE_SSL_LIBRARY 
    99100        WI_INCLUDE_LIBXML2_LIBRARY 
    100101        WI_INCLUDE_ZLIB_LIBRARY 
  • libwired/trunk/configure

    r5338 r5406  
    37063706 
    37073707if test -n "$enable_p7"; then 
    3708         CPPFLAGS="$CPPFLAGS -DWI_P7 -DWI_LIBXML2 -DWI_CRYPTO -DWI_ZLIB" 
     3708        CPPFLAGS="$CPPFLAGS -DWI_P7 -DWI_LIBXML2 -DWI_CRYPTO -DWI_SSL -DWI_ZLIB" 
    37093709fi 
    37103710 
     
    72547254 
    72557255                        LIBS="$LIBS -lcrypto" 
     7256 
     7257else 
     7258 
     7259 
     7260        { { echo "$as_me:$LINENO: error: could not locate OpenSSL 
     7261 
     7262If you installed OpenSSL into a non-standard directory, please run: 
     7263 
     7264    env CPPFLAGS=\"-I/path/to/include\" LDFLAGS=\"-L/path/to/lib\" ./configure" >&5 
     7265echo "$as_me: error: could not locate OpenSSL 
     7266 
     7267If you installed OpenSSL into a non-standard directory, please run: 
     7268 
     7269    env CPPFLAGS=\"-I/path/to/include\" LDFLAGS=\"-L/path/to/lib\" ./configure" >&2;} 
     7270   { (exit 1); exit 1; }; } 
     7271 
     7272 
     7273fi 
     7274 
     7275 
     7276else 
     7277 
     7278 
     7279        { { echo "$as_me:$LINENO: error: could not locate OpenSSL 
     7280 
     7281If you installed OpenSSL into a non-standard directory, please run: 
     7282 
     7283    env CPPFLAGS=\"-I/path/to/include\" LDFLAGS=\"-L/path/to/lib\" ./configure" >&5 
     7284echo "$as_me: error: could not locate OpenSSL 
     7285 
     7286If you installed OpenSSL into a non-standard directory, please run: 
     7287 
     7288    env CPPFLAGS=\"-I/path/to/include\" LDFLAGS=\"-L/path/to/lib\" ./configure" >&2;} 
     7289   { (exit 1); exit 1; }; } 
     7290 
     7291 
     7292fi 
     7293 
     7294done 
     7295 
     7296 
     7297 
     7298 
     7299        if test "$_wi_ssl_paths_added" != yes ; then 
     7300                if test -d /usr/local/ssl/include; then 
     7301                        CPPFLAGS="$CPPFLAGS -I/usr/local/ssl/include" 
     7302                fi 
     7303 
     7304                if test -d /usr/kerberos/include; then 
     7305                        CPPFLAGS="$CPPFLAGS -I/usr/kerberos/include" 
     7306                fi 
     7307 
     7308                if test -d /usr/local/ssl/lib; then 
     7309                        LDFLAGS="$LDFLAGS -L/usr/local/ssl/lib" 
     7310                fi 
     7311        fi 
     7312 
     7313        _wi_ssl_paths_added=yes 
     7314 
     7315 
     7316 
     7317for ac_header in openssl/ssl.h 
     7318do 
     7319as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh` 
     7320if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then 
     7321  { echo "$as_me:$LINENO: checking for $ac_header" >&5 
     7322echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6; } 
     7323if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then 
     7324  echo $ECHO_N "(cached) $ECHO_C" >&6 
     7325fi 
     7326ac_res=`eval echo '${'$as_ac_Header'}'` 
     7327               { echo "$as_me:$LINENO: result: $ac_res" >&5 
     7328echo "${ECHO_T}$ac_res" >&6; } 
     7329else 
     7330  # Is the header compilable? 
     7331{ echo "$as_me:$LINENO: checking $ac_header usability" >&5 
     7332echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6; } 
     7333cat >conftest.$ac_ext <<_ACEOF 
     7334/* confdefs.h.  */ 
     7335_ACEOF 
     7336cat confdefs.h >>conftest.$ac_ext 
     7337cat >>conftest.$ac_ext <<_ACEOF 
     7338/* end confdefs.h.  */ 
     7339$ac_includes_default 
     7340#include <$ac_header> 
     7341_ACEOF 
     7342rm -f conftest.$ac_objext 
     7343if { (ac_try="$ac_compile" 
     7344case "(($ac_try" in 
     7345  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; 
     7346  *) ac_try_echo=$ac_try;; 
     7347esac 
     7348eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 
     7349  (eval "$ac_compile") 2>conftest.er1 
     7350  ac_status=$? 
     7351  grep -v '^ *+' conftest.er1 >conftest.err 
     7352  rm -f conftest.er1 
     7353  cat conftest.err >&5 
     7354  echo "$as_me:$LINENO: \$? = $ac_status" >&5 
     7355  (exit $ac_status); } && { 
     7356         test -z "$ac_c_werror_flag" || 
     7357         test ! -s conftest.err 
     7358       } && test -s conftest.$ac_objext; then 
     7359  ac_header_compiler=yes 
     7360else 
     7361  echo "$as_me: failed program was:" >&5 
     7362sed 's/^/| /' conftest.$ac_ext >&5 
     7363 
     7364        ac_header_compiler=no 
     7365fi 
     7366 
     7367rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext 
     7368{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 
     7369echo "${ECHO_T}$ac_header_compiler" >&6; } 
     7370 
     7371# Is the header present? 
     7372{ echo "$as_me:$LINENO: checking $ac_header presence" >&5 
     7373echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6; } 
     7374cat >conftest.$ac_ext <<_ACEOF 
     7375/* confdefs.h.  */ 
     7376_ACEOF 
     7377cat confdefs.h >>conftest.$ac_ext 
     7378cat >>conftest.$ac_ext <<_ACEOF 
     7379/* end confdefs.h.  */ 
     7380#include <$ac_header> 
     7381_ACEOF 
     7382if { (ac_try="$ac_cpp conftest.$ac_ext" 
     7383case "(($ac_try" in 
     7384  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; 
     7385  *) ac_try_echo=$ac_try;; 
     7386esac 
     7387eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 
     7388  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 
     7389  ac_status=$? 
     7390  grep -v '^ *+' conftest.er1 >conftest.err 
     7391  rm -f conftest.er1 
     7392  cat conftest.err >&5 
     7393  echo "$as_me:$LINENO: \$? = $ac_status" >&5 
     7394  (exit $ac_status); } >/dev/null && { 
     7395         test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || 
     7396         test ! -s conftest.err 
     7397       }; then 
     7398  ac_header_preproc=yes 
     7399else 
     7400  echo "$as_me: failed program was:" >&5 
     7401sed 's/^/| /' conftest.$ac_ext >&5 
     7402 
     7403  ac_header_preproc=no 
     7404fi 
     7405 
     7406rm -f conftest.err conftest.$ac_ext 
     7407{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 
     7408echo "${ECHO_T}$ac_header_preproc" >&6; } 
     7409 
     7410# So?  What about this header? 
     7411case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in 
     7412  yes:no: ) 
     7413    { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 
     7414echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} 
     7415    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5 
     7416echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;} 
     7417    ac_header_preproc=yes 
     7418    ;; 
     7419  no:yes:* ) 
     7420    { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 
     7421echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} 
     7422    { echo "$as_me:$LINENO: WARNING: $ac_header:     check for missing prerequisite headers?" >&5 
     7423echo "$as_me: WARNING: $ac_header:     check for missing prerequisite headers?" >&2;} 
     7424    { echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5 
     7425echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;} 
     7426    { echo "$as_me:$LINENO: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&5 
     7427echo "$as_me: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&2;} 
     7428    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 
     7429echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} 
     7430    { echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5 
     7431echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} 
     7432    ( cat <<\_ASBOX 
     7433## ------------------------------------- ## 
     7434## Report this to axel@zankasoftware.com ## 
     7435## ------------------------------------- ## 
     7436_ASBOX 
     7437     ) | sed "s/^/$as_me: WARNING:     /" >&2 
     7438    ;; 
     7439esac 
     7440{ echo "$as_me:$LINENO: checking for $ac_header" >&5 
     7441echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6; } 
     7442if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then 
     7443  echo $ECHO_N "(cached) $ECHO_C" >&6 
     7444else 
     7445  eval "$as_ac_Header=\$ac_header_preproc" 
     7446fi 
     7447ac_res=`eval echo '${'$as_ac_Header'}'` 
     7448               { echo "$as_me:$LINENO: result: $ac_res" >&5 
     7449echo "${ECHO_T}$ac_res" >&6; } 
     7450 
     7451fi 
     7452if test `eval echo '${'$as_ac_Header'}'` = yes; then 
     7453  cat >>confdefs.h <<_ACEOF 
     7454#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1 
     7455_ACEOF 
     7456 
     7457                { echo "$as_me:$LINENO: checking for SSL_library_init in -lssl" >&5 
     7458echo $ECHO_N "checking for SSL_library_init in -lssl... $ECHO_C" >&6; } 
     7459if test "${ac_cv_lib_ssl_SSL_library_init+set}" = set; then 
     7460  echo $ECHO_N "(cached) $ECHO_C" >&6 
     7461else 
     7462  ac_check_lib_save_LIBS=$LIBS 
     7463LIBS="-lssl  $LIBS" 
     7464cat >conftest.$ac_ext <<_ACEOF 
     7465/* confdefs.h.  */ 
     7466_ACEOF 
     7467cat confdefs.h >>conftest.$ac_ext 
     7468cat >>conftest.$ac_ext <<_ACEOF 
     7469/* end confdefs.h.  */ 
     7470 
     7471/* Override any GCC internal prototype to avoid an error. 
     7472   Use char because int might match the return type of a GCC 
     7473   builtin and then its argument prototype would still apply.  */ 
     7474#ifdef __cplusplus 
     7475extern "C" 
     7476#endif 
     7477char SSL_library_init (); 
     7478int 
     7479main () 
     7480{ 
     7481return SSL_library_init (); 
     7482  ; 
     7483  return 0; 
     7484} 
     7485_ACEOF 
     7486rm -f conftest.$ac_objext conftest$ac_exeext 
     7487if { (ac_try="$ac_link" 
     7488case "(($ac_try" in 
     7489  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; 
     7490  *) ac_try_echo=$ac_try;; 
     7491esac 
     7492eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 
     7493  (eval "$ac_link") 2>conftest.er1 
     7494  ac_status=$? 
     7495  grep -v '^ *+' conftest.er1 >conftest.err 
     7496  rm -f conftest.er1 
     7497  cat conftest.err >&5 
     7498  echo "$as_me:$LINENO: \$? = $ac_status" >&5 
     7499  (exit $ac_status); } && { 
     7500         test -z "$ac_c_werror_flag" || 
     7501         test ! -s conftest.err 
     7502       } && test -s conftest$ac_exeext && 
     7503       $as_test_x conftest$ac_exeext; then 
     7504  ac_cv_lib_ssl_SSL_library_init=yes 
     7505else 
     7506  echo "$as_me: failed program was:" >&5 
     7507sed 's/^/| /' conftest.$ac_ext >&5 
     7508 
     7509        ac_cv_lib_ssl_SSL_library_init=no 
     7510fi 
     7511 
     7512rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ 
     7513      conftest$ac_exeext conftest.$ac_ext 
     7514LIBS=$ac_check_lib_save_LIBS 
     7515fi 
     7516{ echo "$as_me:$LINENO: result: $ac_cv_lib_ssl_SSL_library_init" >&5 
     7517echo "${ECHO_T}$ac_cv_lib_ssl_SSL_library_init" >&6; } 
     7518if test $ac_cv_lib_ssl_SSL_library_init = yes; then 
     7519 
     7520                        LIBS="$LIBS -lssl" 
    72567521 
    72577522else 
  • libwired/trunk/configure.in

    r5338 r5406  
    8989 
    9090if test -n "$enable_p7"; then 
    91         CPPFLAGS="$CPPFLAGS -DWI_P7 -DWI_LIBXML2 -DWI_CRYPTO -DWI_ZLIB" 
     91        CPPFLAGS="$CPPFLAGS -DWI_P7 -DWI_LIBXML2 -DWI_CRYPTO -DWI_SSL -DWI_ZLIB" 
    9292fi 
    9393 
  • libwired/trunk/libwired/p7/wi-p7-socket.c

    r5383 r5406  
    138138        wi_p7_options_t                                                 options; 
    139139         
     140        wi_boolean_t                                                    tls_enabled; 
     141        wi_socket_tls_t                                                 *tls; 
     142         
    140143        wi_boolean_t                                                    encryption_enabled; 
    141144        wi_rsa_t                                                                *rsa; 
     
    178181static wi_boolean_t                                                     _wi_p7_socket_connect_handshake(wi_p7_socket_t *, wi_time_interval_t, wi_p7_options_t); 
    179182static wi_boolean_t                                                     _wi_p7_socket_accept_handshake(wi_p7_socket_t *, wi_time_interval_t, wi_p7_options_t); 
     183static wi_boolean_t                                                     _wi_p7_socket_connect_tls(wi_p7_socket_t *, wi_time_interval_t); 
     184static wi_boolean_t                                                     _wi_p7_socket_accept_tls(wi_p7_socket_t *, wi_time_interval_t); 
    180185static wi_boolean_t                                                     _wi_p7_socket_connect_key_exchange(wi_p7_socket_t *, wi_time_interval_t, wi_string_t *, wi_string_t *); 
    181186static wi_boolean_t                                                     _wi_p7_socket_accept_key_exchange(wi_p7_socket_t *, wi_time_interval_t); 
     
    313318 
    314319 
     320void wi_p7_socket_set_tls(wi_p7_socket_t *p7_socket, wi_socket_tls_t *tls) { 
     321        wi_retain(tls); 
     322        wi_release(p7_socket->tls); 
     323         
     324        p7_socket->tls = tls; 
     325} 
     326 
     327 
     328 
     329wi_socket_tls_t * wi_p7_socket_tls(wi_p7_socket_t *p7_socket) { 
     330        return p7_socket->tls; 
     331} 
     332 
     333 
     334 
    315335#pragma mark - 
    316336 
     
    357377        wi_string_t                     *version; 
    358378        wi_p7_message_t         *p7_message; 
    359         wi_p7_enum_t            flag; 
     379        wi_p7_enum_t            eflag; 
     380        wi_p7_boolean_t         bflag; 
    360381         
    361382        p7_message = wi_p7_message_with_name(WI_STR("p7.handshake.client_handshake"), wi_p7_socket_spec(p7_socket)); 
     
    367388                return false; 
    368389         
    369         if(!wi_p7_message_set_string_for_name(p7_message, wi_p7_spec_name(p7_socket->spec), WI_STR("p7.handshake.protocol_name"))) 
    370                 return false; 
    371          
    372         if(!wi_p7_message_set_string_for_name(p7_message, wi_p7_spec_version(p7_socket->spec), WI_STR("p7.handshake.protocol_version"))) 
     390        if(!wi_p7_message_set_string_for_name(p7_message, wi_p7_spec_name(p7_socket->spec), WI_STR("p7.handshake.protocol.name"))) 
     391                return false; 
     392         
     393        if(!wi_p7_message_set_string_for_name(p7_message, wi_p7_spec_version(p7_socket->spec), WI_STR("p7.handshake.protocol.version"))) 
    373394                return false; 
    374395         
    375396        if(p7_socket->serialization == WI_P7_BINARY) { 
     397                if(WI_P7_TLS_ENABLED(options)) { 
     398                        if(!wi_p7_message_set_bool_for_name(p7_message, true, WI_STR("p7.handshake.tls"))) 
     399                                return false; 
     400                } 
     401 
    376402                if(WI_P7_COMPRESSION_ENABLED(options)) { 
    377403                        if(!wi_p7_message_set_enum_for_name(p7_message, 
     
    432458        } 
    433459         
    434         p7_socket->name = wi_retain(wi_p7_message_string_for_name(p7_message, WI_STR("p7.handshake.protocol_name"))); 
     460        p7_socket->name = wi_retain(wi_p7_message_string_for_name(p7_message, WI_STR("p7.handshake.protocol.name"))); 
    435461         
    436462        if(!p7_socket->name) { 
    437463                wi_error_set_libwired_p7_error(WI_ERROR_P7_HANDSHAKEFAILED, 
    438                         WI_STR("Message has no \"p7.handshake.protocol_name\" field")); 
    439                  
    440                 return false; 
    441         } 
    442          
    443         p7_socket->version = wi_retain(wi_p7_message_string_for_name(p7_message, WI_STR("p7.handshake.protocol_version"))); 
     464                        WI_STR("Message has no \"p7.handshake.protocol.name\" field")); 
     465                 
     466                return false; 
     467        } 
     468         
     469        p7_socket->version = wi_retain(wi_p7_message_string_for_name(p7_message, WI_STR("p7.handshake.protocol.version"))); 
    444470 
    445471        if(!p7_socket->version) { 
    446472                wi_error_set_libwired_p7_error(WI_ERROR_P7_HANDSHAKEFAILED, 
    447                         WI_STR("Message has no \"p7.handshake.protocol_version\" field")); 
     473                        WI_STR("Message has no \"p7.handshake.protocol.version\" field")); 
    448474                 
    449475                return false; 
     
    453479 
    454480        if(p7_socket->serialization == WI_P7_BINARY) { 
    455                 if(wi_p7_message_get_enum_for_name(p7_message, &flag, WI_STR("p7.handshake.compression"))) 
    456                         p7_socket->options |= _WI_P7_COMPRESSION_ENUM_TO_OPTIONS(flag); 
    457          
    458                 if(wi_p7_message_get_enum_for_name(p7_message, &flag, WI_STR("p7.handshake.encryption"))) 
    459                         p7_socket->options |= _WI_P7_ENCRYPTION_ENUM_TO_OPTIONS(flag); 
    460          
    461                 if(wi_p7_message_get_enum_for_name(p7_message, &flag, WI_STR("p7.handshake.checksum"))) 
    462                         p7_socket->options |= _WI_P7_CHECKSUM_ENUM_TO_OPTIONS(flag); 
     481                if(wi_p7_message_get_bool_for_name(p7_message, &bflag, WI_STR("p7.handshake.tls")) && bflag) 
     482                        p7_socket->options |= WI_P7_TLS; 
     483                         
     484                if(wi_p7_message_get_enum_for_name(p7_message, &eflag, WI_STR("p7.handshake.compression"))) 
     485                        p7_socket->options |= _WI_P7_COMPRESSION_ENUM_TO_OPTIONS(eflag); 
     486         
     487                if(wi_p7_message_get_enum_for_name(p7_message, &eflag, WI_STR("p7.handshake.encryption"))) 
     488                        p7_socket->options |= _WI_P7_ENCRYPTION_ENUM_TO_OPTIONS(eflag); 
     489         
     490                if(wi_p7_message_get_enum_for_name(p7_message, &eflag, WI_STR("p7.handshake.checksum"))) 
     491                        p7_socket->options |= _WI_P7_CHECKSUM_ENUM_TO_OPTIONS(eflag); 
    463492        } 
    464493         
     
    487516        wi_string_t                     *version; 
    488517        wi_p7_message_t         *p7_message; 
    489         wi_p7_enum_t            flag; 
     518        wi_p7_enum_t            eflag; 
     519        wi_p7_boolean_t         bflag; 
    490520        wi_p7_options_t         client_options; 
    491521         
     
    520550        } 
    521551         
    522         p7_socket->name = wi_retain(wi_p7_message_string_for_name(p7_message, WI_STR("p7.handshake.protocol_name"))); 
     552        p7_socket->name = wi_retain(wi_p7_message_string_for_name(p7_message, WI_STR("p7.handshake.protocol.name"))); 
    523553         
    524554        if(!p7_socket->name) { 
    525555                wi_error_set_libwired_p7_error(WI_ERROR_P7_HANDSHAKEFAILED, 
    526                         WI_STR("Message has no \"p7.handshake.protocol_name\" field")); 
    527                  
    528                 return false; 
    529         } 
    530          
    531         p7_socket->version = wi_retain(wi_p7_message_string_for_name(p7_message, WI_STR("p7.handshake.protocol_version"))); 
     556                        WI_STR("Message has no \"p7.handshake.protocol.name\" field")); 
     557                 
     558                return false; 
     559        } 
     560         
     561        p7_socket->version = wi_retain(wi_p7_message_string_for_name(p7_message, WI_STR("p7.handshake.protocol.version"))); 
    532562 
    533563        if(!p7_socket->version) { 
    534564                wi_error_set_libwired_p7_error(WI_ERROR_P7_HANDSHAKEFAILED, 
    535                         WI_STR("Message has no \"p7.handshake.protocol_version\" field")); 
     565                        WI_STR("Message has no \"p7.handshake.protocol.version\" field")); 
    536566                 
    537567                return false; 
     
    541571 
    542572        if(p7_socket->serialization == WI_P7_BINARY) { 
    543                 if(wi_p7_message_get_enum_for_name(p7_message, &flag, WI_STR("p7.handshake.compression"))) { 
    544                         client_options = _WI_P7_COMPRESSION_ENUM_TO_OPTIONS(flag)
     573                if(wi_p7_message_get_bool_for_name(p7_message, &bflag, WI_STR("p7.handshake.tls")) && bflag) { 
     574                        client_options = WI_P7_TLS
    545575                         
    546576                        if(options & client_options) 
     
    548578                } 
    549579                 
    550                 if(wi_p7_message_get_enum_for_name(p7_message, &flag, WI_STR("p7.handshake.encryption"))) { 
    551                         client_options = _WI_P7_ENCRYPTION_ENUM_TO_OPTIONS(flag); 
    552  
     580                if(wi_p7_message_get_enum_for_name(p7_message, &eflag, WI_STR("p7.handshake.compression"))) { 
     581                        client_options = _WI_P7_COMPRESSION_ENUM_TO_OPTIONS(eflag); 
     582                         
    553583                        if(options & client_options) 
    554584                                p7_socket->options |= client_options; 
    555585                } 
    556586                 
    557                 if(wi_p7_message_get_enum_for_name(p7_message, &flag, WI_STR("p7.handshake.checksum"))) { 
    558                         client_options = _WI_P7_CHECKSUM_ENUM_TO_OPTIONS(flag); 
     587                if(wi_p7_message_get_enum_for_name(p7_message, &eflag, WI_STR("p7.handshake.encryption"))) { 
     588                        client_options = _WI_P7_ENCRYPTION_ENUM_TO_OPTIONS(eflag); 
    559589 
    560590                        if(options & client_options) 
    561591                                p7_socket->options |= client_options; 
    562592                } 
     593                 
     594                if(wi_p7_message_get_enum_for_name(p7_message, &eflag, WI_STR("p7.handshake.checksum"))) { 
     595                        client_options = _WI_P7_CHECKSUM_ENUM_TO_OPTIONS(eflag); 
     596 
     597                        if(options & client_options) 
     598                                p7_socket->options |= client_options; 
     599                } 
    563600        } 
    564601         
     
    571608                return false; 
    572609         
    573         if(!wi_p7_message_set_string_for_name(p7_message, wi_p7_spec_name(p7_socket->spec), WI_STR("p7.handshake.protocol_name"))) 
    574                 return false; 
    575          
    576         if(!wi_p7_message_set_string_for_name(p7_message, wi_p7_spec_version(p7_socket->spec), WI_STR("p7.handshake.protocol_version"))) 
     610        if(!wi_p7_message_set_string_for_name(p7_message, wi_p7_spec_name(p7_socket->spec), WI_STR("p7.handshake.protocol.name"))) 
     611                return false; 
     612         
     613        if(!wi_p7_message_set_string_for_name(p7_message, wi_p7_spec_version(p7_socket->spec), WI_STR("p7.handshake.protocol.version"))) 
    577614                return false; 
    578615         
    579616        if(p7_socket->serialization == WI_P7_BINARY) { 
     617                if(WI_P7_TLS_ENABLED(p7_socket->options)) { 
     618                        if(!wi_p7_message_set_bool_for_name(p7_message, true, WI_STR("p7.handshake.tls"))) 
     619                                return false; 
     620                } 
     621 
    580622                if(WI_P7_COMPRESSION_ENABLED(p7_socket->options)) { 
    581623                        if(!wi_p7_message_set_enum_for_name(p7_message, 
     
    632674 
    633675 
     676static wi_boolean_t _wi_p7_socket_connect_tls(wi_p7_socket_t *p7_socket, wi_time_interval_t timeout) { 
     677        return wi_socket_connect_tls(p7_socket->socket, p7_socket->tls, timeout); 
     678} 
     679 
     680 
     681 
     682static wi_boolean_t _wi_p7_socket_accept_tls(wi_p7_socket_t *p7_socket, wi_time_interval_t timeout) { 
     683        return wi_socket_accept_tls(p7_socket->socket, p7_socket->tls, timeout); 
     684} 
     685 
     686 
     687 
    634688static wi_boolean_t _wi_p7_socket_connect_key_exchange(wi_p7_socket_t *p7_socket, wi_time_interval_t timeout, wi_string_t *username, wi_string_t *password) { 
    635689        wi_p7_message_t         *p7_message; 
     
    676730        data = wi_rsa_encrypt(p7_socket->rsa, wi_cipher_key(p7_socket->cipher)); 
    677731         
    678         if(!wi_p7_message_set_data_for_name(p7_message, data, WI_STR("p7.encryption.cipher_key"))) 
     732        if(!wi_p7_message_set_data_for_name(p7_message, data, WI_STR("p7.encryption.cipher.key"))) 
    679733                return false; 
    680734 
     
    684738                data = wi_rsa_encrypt(p7_socket->rsa, data); 
    685739                 
    686                 if(!wi_p7_message_set_data_for_name(p7_message, data, WI_STR("p7.encryption.cipher_iv"))) 
     740                if(!wi_p7_message_set_data_for_name(p7_message, data, WI_STR("p7.encryption.cipher.iv"))) 
    687741                        return false; 
    688742        } 
     
    802856        } 
    803857 
    804         key             = wi_p7_message_data_for_name(p7_message, WI_STR("p7.encryption.cipher_key")); 
    805         iv              = wi_p7_message_data_for_name(p7_message, WI_STR("p7.encryption.cipher_iv")); 
     858        key             = wi_p7_message_data_for_name(p7_message, WI_STR("p7.encryption.cipher.key")); 
     859        iv              = wi_p7_message_data_for_name(p7_message, WI_STR("p7.encryption.cipher.iv")); 
    806860         
    807861        if(!key) { 
    808862                wi_error_set_libwired_p7_error(WI_ERROR_P7_HANDSHAKEFAILED, 
    809                         WI_STR("Message has no \"p7.encryption.cipher_key\" field")); 
     863                        WI_STR("Message has no \"p7.encryption.cipher.key\" field")); 
    810864                 
    811865                return false; 
     
    13951449                _wi_p7_socket_configure_checksum(p7_socket); 
    13961450         
     1451        if(WI_P7_TLS_ENABLED(p7_socket->options)) { 
     1452                if(!_wi_p7_socket_connect_tls(p7_socket, timeout)) 
     1453                        return false; 
     1454        } 
     1455         
    13971456        if(WI_P7_ENCRYPTION_ENABLED(p7_socket->options)) { 
    13981457                if(!_wi_p7_socket_connect_key_exchange(p7_socket, timeout, username, password)) 
     
    14261485        if(WI_P7_CHECKSUM_ENABLED(p7_socket->options)) 
    14271486                _wi_p7_socket_configure_checksum(p7_socket); 
     1487         
     1488        if(WI_P7_TLS_ENABLED(p7_socket->options)) { 
     1489                if(!_wi_p7_socket_accept_tls(p7_socket, timeout)) 
     1490                        return false; 
     1491        } 
    14281492         
    14291493        if(WI_P7_ENCRYPTION_ENABLED(p7_socket->options)) { 
  • libwired/trunk/libwired/p7/wi-p7-socket.h

    r5295 r5406  
    3535#include <wired/wi-socket.h> 
    3636 
     37#define WI_P7_TLS_ENABLED(options)                                                      \ 
     38        (((options) & WI_P7_TLS)) 
     39 
    3740#define WI_P7_COMPRESSION_ENABLED(options)                                      \ 
    3841        (((options) & WI_P7_COMPRESSION_DEFLATE)) 
     
    5053 
    5154enum _wi_p7_options { 
    52         WI_P7_COMPRESSION_DEFLATE                                               = (1 << 0), 
    53         WI_P7_ENCRYPTION_RSA_AES128_SHA1                                = (1 << 1), 
    54         WI_P7_ENCRYPTION_RSA_AES192_SHA1                                = (1 << 2), 
    55         WI_P7_ENCRYPTION_RSA_AES256_SHA1                                = (1 << 3), 
    56         WI_P7_ENCRYPTION_RSA_BF128_SHA1                                 = (1 << 4), 
    57         WI_P7_ENCRYPTION_RSA_3DES192_SHA1                               = (1 << 5), 
    58         WI_P7_CHECKSUM_SHA1                                                             = (1 << 6), 
    59         WI_P7_ALL                                                                               = (WI_P7_COMPRESSION_DEFLATE | 
     55        WI_P7_TLS                                                                               = (1 << 0), 
     56        WI_P7_COMPRESSION_DEFLATE                                               = (1 << 1), 
     57        WI_P7_ENCRYPTION_RSA_AES128_SHA1                                = (1 << 2), 
     58        WI_P7_ENCRYPTION_RSA_AES192_SHA1                                = (1 << 3), 
     59        WI_P7_ENCRYPTION_RSA_AES256_SHA1                                = (1 << 4), 
     60        WI_P7_ENCRYPTION_RSA_BF128_SHA1                                 = (1 << 5), 
     61        WI_P7_ENCRYPTION_RSA_3DES192_SHA1                               = (1 << 6), 
     62        WI_P7_CHECKSUM_SHA1                                                             = (1 << 7), 
     63        WI_P7_ALL                                                                               = (WI_P7_TLS | 
     64                                                                                                           WI_P7_COMPRESSION_DEFLATE | 
    6065                                                                                                           WI_P7_ENCRYPTION_RSA_AES128_SHA1 | 
    6166                                                                                                           WI_P7_ENCRYPTION_RSA_AES192_SHA1 | 
     
    7984WI_EXPORT void                                                                          wi_p7_socket_set_private_rsa(wi_p7_socket_t *, wi_rsa_t *); 
    8085WI_EXPORT wi_rsa_t *                                                            wi_p7_socket_private_rsa(wi_p7_socket_t *); 
     86WI_EXPORT void                                                                          wi_p7_socket_set_tls(wi_p7_socket_t *, wi_socket_tls_t *); 
     87WI_EXPORT wi_socket_tls_t *                                                     wi_p7_socket_tls(wi_p7_socket_t *); 
    8188 
    8289WI_EXPORT wi_socket_t *                                                         wi_p7_socket_socket(wi_p7_socket_t *); 
  • libwired/trunk/libwired/p7/wi-p7-spec.c

    r5381 r5406  
    368368        "       <p7:fields>" 
    369369        "               <p7:field name=\"p7.handshake.version\" type=\"string\" id=\"1\" />" 
    370         "               <p7:field name=\"p7.handshake.protocol_name\" type=\"string\" id=\"2\" />" 
    371         "               <p7:field name=\"p7.handshake.protocol_version\" type=\"string\" id=\"3\" />" 
    372         "               <p7:field name=\"p7.handshake.compression\" type=\"enum\" id=\"4\">" 
     370        "               <p7:field name=\"p7.handshake.protocol.name\" type=\"string\" id=\"2\" />" 
     371        "               <p7:field name=\"p7.handshake.protocol.version\" type=\"string\" id=\"3\" />" 
     372        "               <p7:field name=\"p7.handshake.tls\" type=\"bool\" id=\"4\" />" 
     373        "               <p7:field name=\"p7.handshake.compression\" type=\"enum\" id=\"5\">" 
    373374        "                       <p7:enum name=\"p7.handshake.compression.deflate\" value=\"0\" />" 
    374375        "               </p7:field>" 
    375         "               <p7:field name=\"p7.handshake.encryption\" type=\"enum\" id=\"5\">" 
     376        "               <p7:field name=\"p7.handshake.encryption\" type=\"enum\" id=\"6\">" 
    376377        "                       <p7:enum name=\"p7.handshake.encryption.rsa_aes128_sha1\" value=\"0\" />" 
    377378        "                       <p7:enum name=\"p7.handshake.encryption.rsa_aes192_sha1\" value=\"1\" />" 
     
    380381        "                       <p7:enum name=\"p7.handshake.encryption.rsa_3des192_sha1\" value=\"4\" />" 
    381382        "               </p7:field>" 
    382         "               <p7:field name=\"p7.handshake.checksum\" type=\"enum\" id=\"6\">" 
     383        "               <p7:field name=\"p7.handshake.checksum\" type=\"enum\" id=\"7\">" 
    383384        "                       <p7:enum name=\"p7.handshake.checksum.sha1\" value=\"0\" />" 
    384385        "               </p7:field>" 
    385         "               <p7:field name=\"p7.handshake.compatibility_check\" type=\"bool\" id=\"7\" />" 
     386        "               <p7:field name=\"p7.handshake.compatibility_check\" type=\"bool\" id=\"8\" />" 
    386387        "" 
    387         "               <p7:field name=\"p7.encryption.public_key\" id=\"8\" type=\"data\" />" 
    388         "               <p7:field name=\"p7.encryption.cipher_key\" id=\"9\" type=\"data\" />" 
    389         "               <p7:field name=\"p7.encryption.cipher_iv\" id=\"10\" type=\"data\" />" 
    390         "               <p7:field name=\"p7.encryption.username\" id=\"11\" type=\"data\" />" 
    391         "               <p7:field name=\"p7.encryption.client_password\" id=\"12\" type=\"data\" />" 
    392         "               <p7:field name=\"p7.encryption.server_password\" id=\"13\" type=\"data\" />" 
     388        "               <p7:field name=\"p7.encryption.public_key\" id=\"9\" type=\"data\" />" 
     389        "               <p7:field name=\"p7.encryption.cipher.key\" id=\"10\" type=\"data\" />" 
     390        "               <p7:field name=\"p7.encryption.cipher.iv\" id=\"11\" type=\"data\" />" 
     391        "               <p7:field name=\"p7.encryption.username\" id=\"12\" type=\"data\" />" 
     392        "               <p7:field name=\"p7.encryption.client_password\" id=\"13\" type=\"data\" />" 
     393        "               <p7:field name=\"p7.encryption.server_password\" id=\"14\" type=\"data\" />" 
    393394        "" 
    394         "               <p7:field name=\"p7.compatibility_check.specification\" id=\"14\" type=\"string\" />" 
    395         "               <p7:field name=\"p7.compatibility_check.status\" id=\"15\" type=\"bool\" />" 
     395        "               <p7:field name=\"p7.compatibility_check.specification\" id=\"15\" type=\"string\" />" 
     396        "               <p7:field name=\"p7.compatibility_check.status\" id=\"16\" type=\"bool\" />" 
    396397        "       </p7:fields>" 
    397398        "" 
     
    399400        "               <p7:message name=\"p7.handshake.client_handshake\" id=\"1\">" 
    400401        "                       <p7:parameter field=\"p7.handshake.version\" use=\"required\" />" 
    401         "                       <p7:parameter field=\"p7.handshake.protocol_name\" use=\"required\" />" 
    402         "                       <p7:parameter field=\"p7.handshake.protocol_version\" use=\"required\" />" 
     402        "                       <p7:parameter field=\"p7.handshake.protocol.name\" use=\"required\" />" 
     403        "                       <p7:parameter field=\"p7.handshake.protocol.version\" use=\"required\" />" 
     404        "                       <p7:parameter field=\"p7.handshake.tls\" />" 
    403405        "                       <p7:parameter field=\"p7.handshake.encryption\" />" 
    404406        "                       <p7:parameter field=\"p7.handshake.compression\" />" 
     
    408410        "               <p7:message name=\"p7.handshake.server_handshake\" id=\"2\">" 
    409411        "                       <p7:parameter field=\"p7.handshake.version\" use=\"required\" />" 
    410         "                       <p7:parameter field=\"p7.handshake.protocol_name\" use=\"required\" />" 
    411         "                       <p7:parameter field=\"p7.handshake.protocol_version\" use=\"required\" />" 
     412        "                       <p7:parameter field=\"p7.handshake.protocol.name\" use=\"required\" />" 
     413        "                       <p7:parameter field=\"p7.handshake.protocol.version\" use=\"required\" />" 
     414        "                       <p7:parameter field=\"p7.handshake.tls\" />" 
    412415        "                       <p7:parameter field=\"p7.handshake.encryption\" />" 
    413416        "                       <p7:parameter field=\"p7.handshake.compression\" />" 
     
    425428        "" 
    426429        "               <p7:message name=\"p7.encryption.client_key\" id=\"5\">" 
    427         "                       <p7:parameter field=\"p7.encryption.cipher_key\" use=\"required\" />" 
    428         "                       <p7:parameter field=\"p7.encryption.cipher_iv\" />" 
     430        "                       <p7:parameter field=\"p7.encryption.cipher.key\" use=\"required\" />" 
     431        "                       <p7:parameter field=\"p7.encryption.cipher.iv\" />" 
    429432        "                       <p7:parameter field=\"p7.encryption.username\" use=\"required\" />" 
    430433        "                       <p7:parameter field=\"p7.encryption.client_password\" use=\"required\" />" 
     
    516519 
    517520wi_p7_spec_t * wi_p7_spec_builtin_spec(void) { 
    518         if(!_wi_p7_spec_builtin_spec) 
     521        if(!_wi_p7_spec_builtin_spec) { 
    519522                _wi_p7_spec_builtin_spec = _wi_p7_spec_init_builtin_spec(wi_p7_spec_alloc()); 
     523                 
     524                if(!_wi_p7_spec_builtin_spec) 
     525                        wi_log_info(WI_STR("Could not load builtin P7 spec: %m")); 
     526        } 
    520527         
    521528        return _wi_p7_spec_builtin_spec;