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 Discussion :

Curl - SFTP Export pair-keys


Sujet :

Réseau

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre très actif
    Homme Profil pro
    .
    Inscrit en
    Octobre 2014
    Messages
    174
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : .
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2014
    Messages : 174
    Par défaut Curl - SFTP Export pair-keys
    Bonjour,

    J’essaie actuellement d'établir une connexion entre ma session linux-host et un boitier-client (embarqué) en sftp.
    J'utilise la lib Curl (C++).
    Manque de chance, je ne peux pas générer de clef sur mon boitier puisque la commande ssh-keygen -t rsa n'est pas autorisé, je n'ai pas accès au dossier /.ssh et ne peut donc pas lire les clefs qui s'y trouvent, et pour finir, il n'y a pas de ssh-agent qui tourne dessus.
    Solution que j'ai trouvée: importer des clefs privées/public générées depuis mon PC.
    Mais voilà, ça ne semble pas vouloir marcher puisque je me retrouve avec un message d'erreur:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    * SSH authentication methods available: publickey,password
    * Using SSH public key file '/XXX/id_rsa.pub'
    * Using SSH private key file '/XXX/id_rsa'
    * SSH public key authentication failed: Username/PublicKey combination invalid
    * Authentication failure


    Alors la question est: ai-je le droit d'importer des clefs depuis l'extérieur ou doivent-elles forcement être générées sur le système hôte?

    Merci !!

  2. #2
    Membre Expert
    Avatar de supersnail
    Homme Profil pro
    Inscrit en
    Novembre 2006
    Messages
    1 719
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 1 719
    Par défaut
    Bonjour,

    Tu peux tout à fait importer des clés générées sur un autre système (je l'ai déjà fait sans problème ), par contre il faut que:

    • la clé publique que tu veux utiliser soit dans $HOME/.ssh/authorized_keys du compte sur le serveur aulequel tu veux te connecter
    • s'il y a une passphrase, la fournir à la connexion (sinon ben la clé est pas déchiffrée et l'authentification échoue )


    Sinon poster le bout de code utilisant la libcurl serait peut-être judicieux si tu veux qu'on t'aide

  3. #3
    Membre très actif
    Homme Profil pro
    .
    Inscrit en
    Octobre 2014
    Messages
    174
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : .
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2014
    Messages : 174
    Par défaut
    Merci,

    J'ai rajouter la clef public au fichier Authorized_keys.
    Elle se trouve aussi dans ~/.ssh ainsi que la clef privée. (certainement inutile ^^)

    Mon fichier sshd_config est:

    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
     
    # Package generated configuration file
    # See the sshd_config(5) manpage for details
     
    # What ports, IPs and protocols we listen for
    Port 22
    # Use these options to restrict which interfaces/protocols sshd will bind to
    #ListenAddress ::
    #ListenAddress 0.0.0.0
    Protocol 2
    # HostKeys for protocol version 2
    HostKey /etc/ssh/ssh_host_rsa_key
    HostKey /etc/ssh/ssh_host_dsa_key
    HostKey /etc/ssh/ssh_host_ecdsa_key
    #Privilege Separation is turned on for security
    UsePrivilegeSeparation yes
     
    # Lifetime and size of ephemeral version 1 server key
    KeyRegenerationInterval 3600
    ServerKeyBits 768
     
    # Logging
    SyslogFacility AUTH
    LogLevel INFO
     
    # Authentication:
    LoginGraceTime 120
    PermitRootLogin yes
    StrictModes yes
     
    RSAAuthentication yes
    PubkeyAuthentication yes
    AuthorizedKeysFile	%h/.ssh/authorized_keys
     
    # Don't read the user's ~/.rhosts and ~/.shosts files
    IgnoreRhosts yes
    # For this to work you will also need host keys in /etc/ssh_known_hosts
    RhostsRSAAuthentication no
    # similar for protocol version 2
    HostbasedAuthentication no
    # Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
    #IgnoreUserKnownHosts yes
     
    # To enable empty passwords, change to yes (NOT RECOMMENDED)
    PermitEmptyPasswords no
     
    # Change to yes to enable challenge-response passwords (beware issues with
    # some PAM modules and threads)
    ChallengeResponseAuthentication yes
     
    # Change to no to disable tunnelled clear text passwords
    PasswordAuthentication no
     
    # Kerberos options
    #KerberosAuthentication no
    #KerberosGetAFSToken no
    #KerberosOrLocalPasswd yes
    #KerberosTicketCleanup yes
     
    # GSSAPI options
    #GSSAPIAuthentication no
    #GSSAPICleanupCredentials yes
     
    X11Forwarding yes
    X11DisplayOffset 10
    PrintMotd no
    PrintLastLog yes
    TCPKeepAlive yes
    #UseLogin no
     
    #MaxStartups 10:30:60
    #Banner /etc/issue.net
     
    # Allow client to pass locale environment variables
    AcceptEnv LANG LC_*
     
    Subsystem sftp /usr/lib/openssh/sftp-server
     
    # Set this to 'yes' to enable PAM authentication, account processing,
    # and session processing. If this is enabled, PAM authentication will
    # be allowed through the ChallengeResponseAuthentication and
    # PasswordAuthentication.  Depending on your PAM configuration,
    # PAM authentication via ChallengeResponseAuthentication may bypass
    # the setting of "PermitRootLogin without-password".
    # If you just want the PAM account and session checks to run without
    # PAM authentication, then enable this but set PasswordAuthentication
    # and ChallengeResponseAuthentication to 'no'.
    UsePAM yes
    et mon code:

    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
     
    CURL *curl;
      CURLcode res;
      std::string PrivateKey="/XXX/id_rsa";
      std::string PublicKey="/XXX/id_rsa.pub";
     
      std::string username="appldev";
     
     
      	  std::cout << std::string(username).c_str() << std::endl;
      //generate_key();
     
      struct FtpFile ftpfile={
        "/XXX/file.txt", /* name to store the file as if successful */
        NULL
      };
     
      curl_global_init(CURL_GLOBAL_DEFAULT);
     
      curl = curl_easy_init();
      if(curl) {
        /*
         * You better replace the URL with one that works!
         */
    	curl_easy_setopt(curl, CURLOPT_PROTOCOLS, CURLPROTO_SFTP);
        curl_easy_setopt(curl, CURLOPT_URL,
                         "sftp://10.0.0.100");
        /* Define our callback to get called when there s data to be written */
     
    	curl_easy_setopt(curl, CURLOPT_USERPWD, "appldev:password");
    	//curl_easy_setopt(curl,CURLOPT_KEYPASSWD,"password"); //used if set pass phrase
        curl_easy_setopt(curl, CURLOPT_USERNAME, std::string(username).c_str());
    	curl_easy_setopt(curl, CURLOPT_PORT, 22);
     
        curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 1000);
        curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 10);
     
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite);
        /* Set a pointer to our struct to pass to the callback */
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ftpfile);
     
        curl_easy_setopt(curl, CURLOPT_SSH_PUBLIC_KEYFILE,std::string(PublicKey).c_str());
        curl_easy_setopt(curl, CURLOPT_SSH_PRIVATE_KEYFILE,std::string(PrivateKey).c_str());
     
        curl_easy_setopt(curl, CURLOPT_SSH_AUTH_TYPES,CURLSSH_AUTH_PUBLICKEY);
        //curl_easy_setopt(curl, CURLOPT_SSH_AUTH_TYPES,CURLSSH_AUTH_PASSWORD);
     
    #ifndef DISABLE_SSH_AGENT
        /* We activate ssh agent. For this to work you need
           to have ssh-agent running (type set | grep SSH_AGENT to check) or
           pageant on Windows (there is an icon in systray if so) */
     
        //curl_easy_setopt(curl, CURLOPT_SSH_AUTH_TYPES, CURLSSH_AUTH_AGENT);
    #endif
     
        /* Switch on full protocol/debug output */
        curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
     
        res = curl_easy_perform(curl);
     
        /* always cleanup */
        curl_easy_cleanup(curl);
     
        if(CURLE_OK != res) {
          /* we failed */
          fprintf(stderr, "curl told us %d\n", res);
        }
      }
     
      if(ftpfile.stream)
        fclose(ftpfile.stream); /* close the local file */
     
      curl_global_cleanup();

  4. #4
    Membre très actif
    Homme Profil pro
    .
    Inscrit en
    Octobre 2014
    Messages
    174
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : .
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2014
    Messages : 174
    Par défaut
    "s'il y a une passphrase, la fournir à la connexion (sinon ben la clé est pas déchiffrée et l'authentification échoue )"

    Je n'ai pas mis de passphrase pour me simplifer la vie

  5. #5
    Membre Expert
    Avatar de supersnail
    Homme Profil pro
    Inscrit en
    Novembre 2006
    Messages
    1 719
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 1 719
    Par défaut
    Euh ton fichier s'appelle Authorized_keys ou authorized_keys ? Il est bien dans le dossier .ssh/ du répertoire personnel de ton utilisateur ?

    Sinon je pense que la ligne:
    Code C : Sélectionner tout - Visualiser dans une fenêtre à part
    curl_easy_setopt(curl, CURLOPT_USERPWD, "appldev:password");
    peut poser problème (tu définis un mot de passe qui n'a pas lieu d'être, remplace-la par
    Code C : Sélectionner tout - Visualiser dans une fenêtre à part
    curl_easy_setopt(curl, CURLOPT_USERNAME, "appldev");
    .

    Et accessoirement uploader sa clé privée sur un serveur c'est pas l'idée du siècle

  6. #6
    Membre très actif
    Homme Profil pro
    .
    Inscrit en
    Octobre 2014
    Messages
    174
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : .
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2014
    Messages : 174
    Par défaut
    Mon fichier s'appel authorized_keys et se trouve bien dans ~/.ssh
    effectivement j'aurais du mettre curl_easy_setopt(curl, CURLOPT_USERPWD, "appldev:password"); en commentaire.

    Le problème persiste toujours même avec ce changement

  7. #7
    Membre Expert
    Avatar de supersnail
    Homme Profil pro
    Inscrit en
    Novembre 2006
    Messages
    1 719
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 1 719
    Par défaut
    Question débile: t'arrives bien à t'authentifier avec cette clé avec ssh ? (dans le terminal, sans passer par curl).

    A vrai dire tout me semble correct, je vois pas trop quel problème ça pourrait être à part des mauvaises clés utilisées pour s'authentifier ou un mauvais utilisateur

Discussions similaires

  1. Hash of anonymous hashes : probleme avec une key/pair
    Par AltaJup dans le forum Langage
    Réponses: 2
    Dernier message: 21/02/2012, 18h11
  2. UNIQUE Key apparu à l'export
    Par pierre50 dans le forum Débuter
    Réponses: 5
    Dernier message: 30/09/2011, 16h26
  3. Export vers Access avec Primary Key
    Par benjisan dans le forum SAS Base
    Réponses: 3
    Dernier message: 08/02/2010, 12h15
  4. [cURL] Prise en charge de SFTP ?
    Par Invité dans le forum Bibliothèques et frameworks
    Réponses: 4
    Dernier message: 08/01/2007, 21h41
  5. exportation : fichiers .dat et .key
    Par Crab dans le forum Autres SGBD
    Réponses: 4
    Dernier message: 13/09/2004, 14h51

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