IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Réseau C Discussion :

[SSL] pas de trame SSL sur Wireshark.pourquoi?


Sujet :

Réseau C

  1. #1
    Membre du Club Avatar de Bathou
    Inscrit en
    Mars 2007
    Messages
    179
    Détails du profil
    Informations personnelles :
    Âge : 37

    Informations forums :
    Inscription : Mars 2007
    Messages : 179
    Points : 52
    Points
    52
    Par défaut [SSL] pas de trame SSL sur Wireshark.pourquoi?
    Bonjour!
    alors, voila, jai un petit problème... j'ai réalisé deux applis, une serveur, une client qui ouvre une connexion SSL avec OpenSSL. jusque la, tout avait l'air de marcher...
    seulement, j'ai utilisé wireshark pour voir si tout se passait bien et...
    je ne vois aucune trame SSL...

    donc je trouve ca un peu bizarre... (et les trames tcp que je vois, ont pour la pluspart un "checksum incorrect"...) si quelqu'un avait une idée...

    je poste le code :

    le serveur :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <errno.h>
    #include <netdb.h>
    #include <unistd.h> 
    #ifdef __VMS
    #include <types.h>
    #include <socket.h>
    #include <in.h>
    #include <inet.h> 
    #else
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <arpa/inet.h>
    #endif 
    #include <openssl/crypto.h>
    #include <openssl/ssl.h>
    #include <openssl/err.h> 
    #define RSA_SERVER_CERT     "serveur_ssl_cert.pem"
    #define RSA_SERVER_KEY          "serveur_ssl_priv_key.key" 
    #define RSA_SERVER_CA_CERT "../cassl/cassl_cert.pem"
    #define RSA_SERVER_CA_PATH   "bathou1" 
    #define ON 1
    #define OFF 0 
    #define RETURN_NULL(x) if ((x)==NULL) exit(1)
    #define RETURN_ERR(err,s) if ((err)==-1) { perror(s); exit(1); }
    #define RETURN_SSL(err) if ((err)==-1) { ERR_print_errors_fp(stderr); exit(1); } 
     
    int main()
    {    
    int     err;        
    int     verify_client = OFF; /* To verify a client certificate, set ON */       
    int     listen_sock;        
    int     sock;       
    struct sockaddr_in sa_serv;         
    struct sockaddr_in sa_cli;          
    size_t client_len;          
    char    *str;       
    char     buf[4096];     
    SSL_CTX         *ctx;        
    SSL            *ssl;       
    SSL_METHOD      *meth; 
    X509            *client_cert = NULL;    
    short int       s_port = 5555;
     
     
    /*----------------------------------------------------------------*/      
     
    /* Load encryption & hashing algorithms for the SSL program */  
    SSL_library_init();     
     
    /* Load the error strings for SSL & CRYPTO APIs */      
    SSL_load_error_strings();       
     
    /* Create a SSL_METHOD structure (choose a SSL/TLS protocol version) */     
    meth = SSLv3_method();  
     
    /* Create a SSL_CTX structure */    
    ctx = SSL_CTX_new(meth);        
    if (!ctx) 
        {             
        ERR_print_errors_fp(stderr);            
    exit(1);        
        }       
     
    /* Load the server certificate into the SSL_CTX structure */       
    if (SSL_CTX_use_certificate_file(ctx, RSA_SERVER_CERT, SSL_FILETYPE_PEM) <= 0) 
        {                    
        ERR_print_errors_fp(stderr);                    
        exit(1);       
        }       
     
    /* Load the private-key corresponding to the server certificate */          
    if (SSL_CTX_use_PrivateKey_file(ctx, RSA_SERVER_KEY, SSL_FILETYPE_PEM) <= 0) 
        {               
        ERR_print_errors_fp(stderr);                
        exit(1);    
        }       
     
    /* Check if the server certificate and private-key matches */       
    if (!SSL_CTX_check_private_key(ctx)) 
        {                  
        fprintf(stderr,"Private key does not match the certificate public key\n");                  
        exit(1);    
        }      
     
    if(verify_client == ON)        
        {               
        /* Load the RSA CA certificate into the SSL_CTX structure */                
        if (!SSL_CTX_load_verify_locations(ctx, RSA_SERVER_CA_CERT, NULL)) 
            {                    
            ERR_print_errors_fp(stderr);                        
            exit(1);            
            }               
     
        /* Set to require peer (client) certificate verification */         
        SSL_CTX_set_verify(ctx,SSL_VERIFY_PEER,NULL);           
        /* Set the verification depth to 1 */               
        SSL_CTX_set_verify_depth(ctx,1);       
        }  
     
     
    /* ----------------------------------------------- */       
     
    /* Set up a TCP socket */       
    listen_sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);        
    RETURN_ERR(listen_sock, "socket");          
    memset (&sa_serv, '\0', sizeof(sa_serv));       
    sa_serv.sin_family      = AF_INET;          
    sa_serv.sin_addr.s_addr = INADDR_ANY;       
    sa_serv.sin_port        = htons (s_port);     
     
    /* Server Port number */         
    err = bind(listen_sock, (struct sockaddr*)&sa_serv,sizeof(sa_serv));        
    RETURN_ERR(err, "bind");        
     
    /* Wait for an incoming TCP connection. */          
    err = listen(listen_sock, 5);                           
    RETURN_ERR(err, "listen");          
    client_len = sizeof(sa_cli);    
     
    /* Socket for a TCP/IP connection is created */     
    sock = accept(listen_sock, (struct sockaddr*)&sa_cli, &client_len);     
    RETURN_ERR(sock, "accept");         
    close (listen_sock);    
    printf ("Connection from %lx, port %x\n", sa_cli.sin_addr.s_addr,sa_cli.sin_port);     
     
    /* ----------------------------------------------- */       
    /* TCP connection is ready. */      
     
    /* A SSL structure is created */    
    ssl = SSL_new(ctx);     
    RETURN_NULL(ssl);       
     
    /* Assign the socket into the SSL structure (SSL and socket without BIO) */ 
    SSL_set_fd(ssl, sock);  
     
    /* Perform SSL Handshake on the SSL server */       
    err = SSL_accept(ssl);  RETURN_SSL(err);        
     
    /* Informational output (optional) */       
    printf("SSL connection using %s\n", SSL_get_cipher (ssl));     
    if (verify_client == ON)   
        {           
        /* Get the client's certificate (optional) */       
        client_cert = SSL_get_peer_certificate(ssl);        
        if (client_cert != NULL)            
            {               
            printf ("Client certificate:\n");                   
            str = X509_NAME_oneline(X509_get_subject_name(client_cert), 0, 0);                  
            RETURN_NULL(str);                   
            printf ("\t subject: %s\n", str);                   
            free (str);                 
            str = X509_NAME_oneline(X509_get_issuer_name(client_cert), 0, 0);                   
            RETURN_NULL(str);                   
            printf ("\t issuer: %s\n", str);                    
            free (str);                 
            X509_free(client_cert);     
            }       
        else                    
            printf("The SSL client does not have certificate.\n");  
        }       
     
    /*------- DATA EXCHANGE - Receive message and send reply. -------*/ 
     
    /* Receive data from the SSL client */      
    err = SSL_read(ssl, buf, sizeof(buf) - 1);      
    RETURN_SSL(err);        buf[err] = '\0';        
    printf ("Received %d chars:'%s'\n", err, buf);  
     
    /* Send data to the SSL client */   
    err = SSL_write(ssl, "This message is from the SSL server",strlen("This message is from the SSL server"));         RETURN_SSL(err);        
     
     
    /*--------------- SSL closure ---------------*/     
     
    /* Shutdown this side (server) of the connection. */    
    err = SSL_shutdown(ssl);        
    RETURN_SSL(err);        
     
    /* Terminate communication on a socket */   
    err = close(sock);      
    RETURN_ERR(err, "close");      
     
    /* Free the SSL structure */        
    SSL_free(ssl); 
     
    /* Free the SSL_CTX structure */   
    SSL_CTX_free(ctx); 
     
    }
    le client :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    #include <stdio.h>
    #include <string.h>
    #include <errno.h>
    #include <netdb.h>
    #include <unistd.h>
    #ifdef __VMS
    #include <socket.h>
    #include <inet.h> 
    #include <in.h>
    #else
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <arpa/inet.h>
    #endif 
    #include <openssl/crypto.h>
    #include <openssl/ssl.h>
    #include <openssl/err.h> 
    #define RETURN_NULL(x) if ((x)==NULL) exit (1)
    #define RETURN_ERR(err,s) if ((err)==-1) { perror(s); exit(1); }
    #define RETURN_SSL(err) if ((err)==-1) { ERR_print_errors_fp(stderr); exit(1); } 
     
    static int verify_callback(int ok, X509_STORE_CTX *ctx); 
     
    #define RSA_CLIENT_CERT       "client_ssl_cert.pem"
    #define RSA_CLIENT_KEY  "client_ssl_priv_key.key" 
    #define RSA_CLIENT_CA_CERT      "../cassl/cassl_cert.pem"
    #define RSA_CLIENT_CA_PATH      "bathou1" 
    #define ON      1
    #define OFF     0 
     
    int main()
    {          
    int     err; 
     
     
     
    int     verify_client = ON; /* To not verify a client certificate, set OFF */   
    int     sock;         
    struct sockaddr_in server_addr;     
    char  *str;       
    char    buf [4096];         
    char    hello[80]; 
     
     
    SSL_CTX         *ctx;       
    SSL            *ssl;       
    SSL_METHOD      *meth;      
    X509            *server_cert;        
    EVP_PKEY        *pkey; 
     
     
    short int       s_port = 5555;      
    const char      *s_ipaddr = "10.102.13.114";      
     
     
     
     
    /*----------------------------------------------------------*/      
     
    printf ("Message to be sent to the SSL server: ");          
    fgets (hello, 80, stdin);       
     
    /* Load encryption & hashing algorithms for the SSL program */  
    SSL_library_init();     
     
    /* Load the error strings for SSL & CRYPTO APIs */      
    SSL_load_error_strings();      
     
    /* Create an SSL_METHOD structure (choose an SSL/TLS protocol version) */   
    meth = SSLv3_method();  
     
     
    /* Create an SSL_CTX structure */   
    ctx = SSL_CTX_new(meth);                                
    RETURN_NULL(ctx);   
     
     
     
    /*----------------------------------------------------------*/  
     
     
    if(verify_client == ON)         
    {               
      /* Load the client certificate into the SSL_CTX structure */               
      if (SSL_CTX_use_certificate_file(ctx, RSA_CLIENT_CERT,       SSL_FILETYPE_PEM) <= 0) 
          {                   
          ERR_print_errors_fp(stderr);                        
          exit(1);            
         }               
     
      /* Load the private-key corresponding to the client certificate */          
      if (SSL_CTX_use_PrivateKey_file(ctx, RSA_CLIENT_KEY,SSL_FILETYPE_PEM) <= 0) 
          {                     
          ERR_print_errors_fp(stderr);                        
          exit(1);            
          }               
     
      /* Check if the client certificate and private-key matches */               
      if (!SSL_CTX_check_private_key(ctx)) 
          {                      
          fprintf(stderr,"Private key does not match the certificate public key\n");                    
          exit(1);            
          }   printf("check certif et private clé\n");
    }       
     
    /* Load the RSA CA certificate into the SSL_CTX structure */        
    /* This will allow this client to verify the server's     */        
    /* certificate.                                           */ 
     
     
    if (!SSL_CTX_load_verify_locations(ctx, RSA_CLIENT_CA_CERT, NULL)) 
        {                
        ERR_print_errors_fp(stderr);                
        exit(1);    
        }         
     
    /* Set flag in context to require peer (server) certificate */        
    /* verification */         /*
    SSL_CTX_set_verify(ctx,SSL_VERIFY_PEER,NULL);         
    SSL_CTX_set_verify_depth(ctx,1);*/       
    printf("VERIFICATION OK!");
     
     
     
    /* ------------------------------------------------------------- */         
     
    /* Set up a TCP socket */       
    sock = socket (PF_INET, SOCK_STREAM, IPPROTO_TCP);              
    RETURN_ERR(sock, "socket");     
    memset (&server_addr, '\0', sizeof(server_addr));       
    server_addr.sin_family = AF_INET;  
    server_addr.sin_port = htons(s_port);       
     
    /* Server Port number */     
    server_addr.sin_addr.s_addr = inet_addr(s_ipaddr); 
     
    /* Server IP */      
     
    /* Establish a TCP/IP connection to the SSL client */           
    err = connect(sock, (struct sockaddr*) &server_addr, sizeof(server_addr));          
    RETURN_ERR(err, "connect");         
     
     
     
    /* ----------------------------------------------- */       
     
    /* An SSL structure is created */       
    ssl = SSL_new (ctx);    
    RETURN_NULL(ssl);       
     
    /* Assign the socket into the SSL structure (SSL and socket without BIO) */         
    SSL_set_fd(ssl, sock);  
     
    /* Perform SSL Handshake on the SSL client */       
    err = SSL_connect(ssl);         
    RETURN_SSL(err);        
     
    /* Informational output (optional) */       
    printf ("SSL connection using %s\n", SSL_get_cipher (ssl));     
     
    /* Get the server's certificate (optional) */       
    server_cert = SSL_get_peer_certificate (ssl);           
    if (server_cert != NULL)       
        {               
        printf ("Server certificate:\n"); 
        str = X509_NAME_oneline(X509_get_subject_name(server_cert),0,0);            
        RETURN_NULL(str);           
        printf ("\t subject: %s\n", str);           
        free (str);             
        str = X509_NAME_oneline(X509_get_issuer_name(server_cert),0,0);             
        RETURN_NULL(str);           
        printf ("\t issuer: %s\n", str);            
        free(str);              
        X509_free (server_cert); 
        }        
    else                
        printf("The SSL server does not have certificate.\n");     
     
     
     
    /*-------- DATA EXCHANGE - send message and receive reply. -------*/        
     
     
    /* Send data to the SSL server */   
    err = SSL_write(ssl, hello, strlen(hello));     
    RETURN_SSL(err);     
     
    /* Receive data from the SSL server */      
    err = SSL_read(ssl, buf, sizeof(buf)-1);                        
    RETURN_SSL(err);    
    buf[err] = '\0';   
    printf ("Received %d chars:'%s'\n", err, buf);         
     
     
     
    /*--------------- SSL closure ---------------*/       
     
    /* Shutdown the client side of the SSL connection */         
    err = SSL_shutdown(ssl);        
    RETURN_SSL(err);         
     
    /* Terminate communication on a socket */        
    err = close(sock);         
    RETURN_ERR(err, "close");         
     
    /* Free the SSL structure */        
    SSL_free(ssl);         
     
    /* Free the SSL_CTX structure */        
    SSL_CTX_free(ctx);
     
    }
    merci par avance à ceux qui pourront m'aider...

  2. #2
    Rédacteur

    Avatar de ram-0000
    Homme Profil pro
    Consultant en sécurité
    Inscrit en
    Mai 2007
    Messages
    11 517
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Consultant en sécurité
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mai 2007
    Messages : 11 517
    Points : 50 367
    Points
    50 367
    Par défaut
    Sur Wireshark chez moi aussi, le checksum est incorrect
    Version 0.99.6a (SVN Rev 22276)
    Donc pas de panique, c'est peut être un bug de wireshark ou alors un comportement que je ne comprends pas.

    En ce qui concerne tes trames SSL, c'est un peu normal que tu ne les voies pas avec Wireshark. Tu utilise le port 5555 et Wireshark même s'il est intelligent ne peut deviner que c'est du openssl.

    Il faudrait que tu changes de port pour l'aider un peu et je pense que si tu utilises 443 ou 22 (qui sont des ports connus pour véhiculer du ssl), cela irait mieux.

    Ceci dit, tu verras le début de la négociation SSL et c'est tout, après c'est crypté et même Wireshark ne peut rien (ou alors tu as un problème )

  3. #3
    Membre du Club Avatar de Bathou
    Inscrit en
    Mars 2007
    Messages
    179
    Détails du profil
    Informations personnelles :
    Âge : 37

    Informations forums :
    Inscription : Mars 2007
    Messages : 179
    Points : 52
    Points
    52
    Par défaut
    ok!merci beaucoup et j'arrete de paniquer (lol)
    euh... par contre les numéros de port... ca marche pas :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    bind: Address already in use
    donc je suppose que ces numéros de port là sont déja occupés...
    aurais tu une autre idée de numéro que j'essayerai...???
    (ca me ferait plaisir de voir la négociation SSL après qu'openSSL m'en a fait bavé!)

  4. #4
    Rédacteur

    Avatar de ram-0000
    Homme Profil pro
    Consultant en sécurité
    Inscrit en
    Mai 2007
    Messages
    11 517
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Consultant en sécurité
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mai 2007
    Messages : 11 517
    Points : 50 367
    Points
    50 367
    Par défaut
    les 2 ports 22 et 443 sont utilisés sur ta machine

    Alors arrête un des 2 serveurs

  5. #5
    Membre du Club Avatar de Bathou
    Inscrit en
    Mars 2007
    Messages
    179
    Détails du profil
    Informations personnelles :
    Âge : 37

    Informations forums :
    Inscription : Mars 2007
    Messages : 179
    Points : 52
    Points
    52
    Par défaut
    quel serveur...?
    après une petite recherche sur j'ai trouvé le numéro de port 563 et alleluia, ca marche!!!
    merci beaucoup

  6. #6
    Rédacteur

    Avatar de ram-0000
    Homme Profil pro
    Consultant en sécurité
    Inscrit en
    Mai 2007
    Messages
    11 517
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Consultant en sécurité
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mai 2007
    Messages : 11 517
    Points : 50 367
    Points
    50 367
    Par défaut
    Citation Envoyé par Bathou Voir le message
    quel serveur...?
    Je voulais dire les services SSH ou HTTPS

    Citation Envoyé par Bathou Voir le message
    après une petite recherche sur j'ai trouvé le numéro de port 563
    Je l'avais oublié, c'est les news sur SSL donc c'est normal que Wireshark connaisse.

  7. #7
    Futur Membre du Club
    Inscrit en
    Mars 2009
    Messages
    11
    Détails du profil
    Informations forums :
    Inscription : Mars 2009
    Messages : 11
    Points : 5
    Points
    5
    Par défaut
    salut a tous j'ai eu le meme probleme que vous, et ai finalement trouvé la soluce sur le site de wireshark:

    Wireshark est capable de reconnaitre du SSL et ce quelque soit le ports, mais seulement en lui spécifient le chemin des clefs RSA.

    Il suffit pour cela d'aller dans les préférence systeme, puis "SSL" et de rentrer dans le champs RSA keys list :

    exemple 1: @ip1,port,protocole,/chemin/clef1.key;@ip2,port,protocole,/chemin/clef2.key

    exemple 2: 127.0.0.1,443,http,/path/to/snakeoil2.key

    Une fois ces données entrés Wireshark affiche la totalité du handshake SSL.

    source

    Pedro

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. apache 2 et SSL : pas de tutoriel ?
    Par marveljojo75 dans le forum Apache
    Réponses: 2
    Dernier message: 24/10/2008, 14h52
  2. Réponses: 14
    Dernier message: 09/03/2008, 16h24
  3. tutorial ssl pas clair
    Par chillansky dans le forum Apache
    Réponses: 6
    Dernier message: 03/07/2007, 17h04
  4. Réponses: 9
    Dernier message: 14/09/2006, 17h03
  5. Pourquoi n'y à t'il pas de rubrique Windev sur www.developpez.com ?
    Par TicTacToe dans le forum Evolutions du club
    Réponses: 12
    Dernier message: 21/04/2006, 17h44

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo