Changeset 5424

Show
Ignore:
Timestamp:
03/17/08 11:52:44 (4 months ago)
Author:
morris
Message:

Add wi_p7_socket_public_key(), rename RSA methods

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • libwired/trunk/libwired/p7/wi-p7-socket.c

    r5417 r5424  
    143143         
    144144        wi_boolean_t                                                    encryption_enabled; 
    145         wi_rsa_t                                                                *rsa; 
     145        wi_rsa_t                                                                *private_key; 
     146        wi_rsa_t                                                                *public_key; 
    146147        wi_cipher_t                                                             *cipher; 
    147148         
     
    284285        wi_release(p7_socket->name); 
    285286        wi_release(p7_socket->version); 
    286         wi_release(p7_socket->rsa); 
     287        wi_release(p7_socket->private_key); 
     288        wi_release(p7_socket->public_key); 
    287289        wi_release(p7_socket->cipher); 
    288290} 
     
    304306#pragma mark - 
    305307 
    306 void wi_p7_socket_set_private_rsa(wi_p7_socket_t *p7_socket, wi_rsa_t *rsa) { 
     308void wi_p7_socket_set_private_key(wi_p7_socket_t *p7_socket, wi_rsa_t *rsa) { 
    307309        wi_retain(rsa); 
    308         wi_release(p7_socket->rsa); 
    309          
    310         p7_socket->rsa = rsa; 
    311 
    312  
    313  
    314  
    315 wi_rsa_t * wi_p7_socket_private_rsa(wi_p7_socket_t *p7_socket) { 
    316         return p7_socket->rsa; 
     310        wi_release(p7_socket->private_key); 
     311         
     312        p7_socket->private_key = rsa; 
     313
     314 
     315 
     316 
     317wi_rsa_t * wi_p7_socket_private_key(wi_p7_socket_t *p7_socket) { 
     318        return p7_socket->private_key; 
     319
     320 
     321 
     322 
     323wi_rsa_t * wi_p7_socket_public_key(wi_p7_socket_t *p7_socket) { 
     324        return p7_socket->public_key; 
    317325} 
    318326 
     
    714722        } 
    715723         
    716         p7_socket->rsa = wi_rsa_init_with_public_key(wi_rsa_alloc(), rsa); 
    717          
    718         if(!p7_socket->rsa
     724        p7_socket->public_key = wi_rsa_init_with_public_key(wi_rsa_alloc(), rsa); 
     725         
     726        if(!p7_socket->public_key
    719727                return false; 
    720728         
     
    729737                return false; 
    730738         
    731         data = wi_rsa_encrypt(p7_socket->rsa, wi_cipher_key(p7_socket->cipher)); 
     739        data = wi_rsa_encrypt(p7_socket->public_key, wi_cipher_key(p7_socket->cipher)); 
    732740         
    733741        if(!wi_p7_message_set_data_for_name(p7_message, data, WI_STR("p7.encryption.cipher.key"))) 
     
    737745         
    738746        if(data) { 
    739                 data = wi_rsa_encrypt(p7_socket->rsa, data); 
     747                data = wi_rsa_encrypt(p7_socket->public_key, data); 
    740748                 
    741749                if(!wi_p7_message_set_data_for_name(p7_message, data, WI_STR("p7.encryption.cipher.iv"))) 
     
    746754                username = WI_STR(""); 
    747755         
    748         data = wi_rsa_encrypt(p7_socket->rsa, wi_string_data(username)); 
     756        data = wi_rsa_encrypt(p7_socket->public_key, wi_string_data(username)); 
    749757         
    750758        if(!data) 
     
    760768        client_password2 = wi_data_sha1(wi_data_by_appending_data(rsa, wi_string_data(wi_string_sha1(password)))); 
    761769         
    762         data = wi_rsa_encrypt(p7_socket->rsa, wi_string_data(client_password1)); 
     770        data = wi_rsa_encrypt(p7_socket->public_key, wi_string_data(client_password1)); 
    763771         
    764772        if(!data) 
     
    830838                return false; 
    831839         
    832         if(!p7_socket->rsa) { 
     840        if(!p7_socket->private_key) { 
    833841                wi_error_set_libwired_error(WI_ERROR_P7_NORSAKEY); 
    834842                 
     
    836844        } 
    837845         
    838         rsa = wi_rsa_public_key(p7_socket->rsa); 
     846        rsa = wi_rsa_public_key(p7_socket->private_key); 
    839847         
    840848        if(!wi_p7_message_set_data_for_name(p7_message, rsa, WI_STR("p7.encryption.public_key"))) 
     
    867875        } 
    868876         
    869         key = wi_rsa_decrypt(p7_socket->rsa, key); 
     877        key = wi_rsa_decrypt(p7_socket->private_key, key); 
    870878         
    871879        if(iv) 
    872                 iv = wi_rsa_decrypt(p7_socket->rsa, iv); 
     880                iv = wi_rsa_decrypt(p7_socket->private_key, iv); 
    873881         
    874882        p7_socket->cipher = wi_cipher_init_with_key(wi_cipher_alloc(), _WI_P7_ENCRYPTION_OPTIONS_TO_CIPHER(p7_socket->options), key, iv); 
     
    886894        } 
    887895         
    888         data = wi_rsa_decrypt(p7_socket->rsa, data); 
     896        data = wi_rsa_decrypt(p7_socket->private_key, data); 
    889897         
    890898        if(!data) 
     
    902910        } 
    903911         
    904         data = wi_rsa_decrypt(p7_socket->rsa, data); 
     912        data = wi_rsa_decrypt(p7_socket->private_key, data); 
    905913         
    906914        if(!data) 
  • libwired/trunk/libwired/p7/wi-p7-socket.h

    r5417 r5424  
    8383WI_EXPORT wi_p7_socket_t *                                                      wi_p7_socket_init_with_socket(wi_p7_socket_t *, wi_socket_t *, wi_p7_spec_t *); 
    8484 
    85 WI_EXPORT void                                                                          wi_p7_socket_set_private_rsa(wi_p7_socket_t *, wi_rsa_t *); 
    86 WI_EXPORT wi_rsa_t *                                                            wi_p7_socket_private_rsa(wi_p7_socket_t *); 
     85WI_EXPORT void                                                                          wi_p7_socket_set_private_key(wi_p7_socket_t *, wi_rsa_t *); 
     86WI_EXPORT wi_rsa_t *                                                            wi_p7_socket_private_key(wi_p7_socket_t *); 
     87WI_EXPORT wi_rsa_t *                                                            wi_p7_socket_public_key(wi_p7_socket_t *); 
    8788WI_EXPORT void                                                                          wi_p7_socket_set_tls(wi_p7_socket_t *, wi_socket_tls_t *); 
    8889WI_EXPORT wi_socket_tls_t *                                                     wi_p7_socket_tls(wi_p7_socket_t *);