• Xanza@lemm.ee
    link
    fedilink
    English
    arrow-up
    51
    arrow-down
    1
    ·
    edit-2
    4 days ago

    The only real advantage to using SSH vs PGP keys is you don’t need an external dependency (GPG). PGP is always going to be better, because you get the advantage of WOT, and PGP public key servers to verify identities over just “this is who I am, here’s my key.” You should always sign your commits, no matter what you use. Identity verification is very important in open source.

    $ git config --global gpg.format ssh
    $ git config --global user.signingkey ~/.ssh/examplekey.pub
    
    • SigmarStern@discuss.tchncs.de
      link
      fedilink
      arrow-up
      19
      arrow-down
      2
      ·
      3 days ago

      Are you using your public ssh key for signing? Wouldn’t it make more sense to use the private one as people can then verify your identity by using your public key?

      • codesaIat@discuss.tchncs.de
        link
        fedilink
        arrow-up
        36
        ·
        edit-2
        3 days ago

        Ha, good catch! Behind the scences, git is actually using your private key to sign the commit. You’re only specifying the ssh key git should ask ssh-agent about. You can also specify the private key and actually need to when not using an agent and the key is not available. See docs

      • Xanza@lemm.ee
        link
        fedilink
        English
        arrow-up
        8
        arrow-down
        2
        ·
        3 days ago

        You seem to be fundamentally misunderstanding how the shared keys work, here. You don’t get to choose which key you sign with, either private or public.

        If you sign a statement, it uses your private key. Period. The methodology is only the original owner of the keys has access to the private key, so any signed statement also using that private key, is directly from the key owner. Alternatively, anyone has access to your private key, and can encrypt data using it, that only the owner, with access to the private key, can decrypt.

        Anyone in the world can encrypt a message that only you can decrypt. That’s the way it works. Alternatively, when you sign a statement, you’re establishing that the owner of the key pair signed it, as only the owner has access to the private key. Then, anyone in the world can verify your signed statement using your public key.

        You don’t get to choose which one you use. In the example from my original post, the ssh-agent only needs reference to the location of one of the two keys, and will use the filename regardless, to distinguish between public and private. If I point the configuration option to this_is_my_key indicating a private key, it will automatically use this_is_my_key.pub as a public key. If I indicate this_is_my_key.pub then it does the reverse and will assume that this_is_my_key is the private key. It doesn’t matter which one you specify, the ssh-agent just needs a filename to work with.

          • Xanza@lemm.ee
            link
            fedilink
            English
            arrow-up
            1
            arrow-down
            1
            ·
            3 days ago

            Anyone only has access to your public key if you give them access to your public key. So no, not really. They should have access to it. It’s not something you should keep private, but SSH shared keys aren’t PGP shared keys. There’s no key servers for SSH shared keys.

              • Xanza@lemm.ee
                link
                fedilink
                English
                arrow-up
                1
                ·
                3 days ago

                Then, anyone in the world can verify your signed statement using your public key.

                Of course. The only barrier is the possession of your public key. I really don’t understand what you’re getting at here. Anyone with your public key can verify a PSK signed statement you made, which obviously is predicated on them having access to the key.

            • Eager Eagle@lemmy.world
              link
              fedilink
              English
              arrow-up
              2
              arrow-down
              1
              ·
              edit-2
              3 days ago

              “Alternatively, anyone has access to your private public key, and can encrypt data using it, that only the owner, with access to the private key, can decrypt.”

        • SigmarStern@discuss.tchncs.de
          link
          fedilink
          arrow-up
          18
          arrow-down
          1
          ·
          3 days ago

          But why? Public is public. People can take my public key. The can encrypt my commit, making it indistinguishable from my commit.

          Isn’t the idea to use your private key for encryption so that everyone can use your public key to decrypt your signature and to verify that it’s you who actually did the commit, because no one else has access to the private key?

          • Gyroplast@pawb.social
            link
            fedilink
            English
            arrow-up
            7
            arrow-down
            1
            ·
            3 days ago

            Consider a key pair, consisting of two brutally large numbers, but otherwise pretty much identical. Magical math exists that makes it so that if you math your data with one of these brutally large numbers, you get the original data back only if you math it with the other large number. That’s basically it.

            Now we slap convention onto this, and keep one of the paired, large numbers a secret, and call it our private key, the other number is disseminated and called the public key for that reason.

            Now everyone can math data with your public key, so that only the paired private key, which only you know, can de-math it. This is encryption/decryption.

            Signing is very similar, but now you use your private key, which only you know, to math a digest of your data, and all the world can de-math this correctly only with your public key, thus proving it was indeed your private key used to math the data in the first place, and by extension attribute the signature to your public key identity. Your private key is never known to anyone but you, which is an essential difference to “classical” symmetric encryption with a shared secret.

            You may realize how easily a code signature can become a liability, if you fail to keep your private key secret for any reason. You can be trivially impersonated, with basically no chance of recourse or deniability with an SSH key, while you can at least invalidate a GPG key publicly and mark it as “stolen” that way. This is potentially very important, if there’s any legal meaning attached to your signature, and if not, why bother with code signing in the first place, if “trust me bro” is well enough.

            • SigmarStern@discuss.tchncs.de
              link
              fedilink
              arrow-up
              4
              ·
              edit-2
              3 days ago

              Yeah, sorry, I meant signing, not encrypting. I know about asymmetrical encryption. That’s why I was confused by the original statement. For signing you use your private key so that others can verify your identity by using your public key for checking the signature. For encrypting data you use the public key of the receiver.

              The original comment used the public key for signing, which is not what you want to do. I now read the explanation.

          • Xanza@lemm.ee
            link
            fedilink
            English
            arrow-up
            4
            ·
            edit-2
            3 days ago

            People can take my public key.

            And they can also encrypt things with it. That’s the whole point. Only the owner of the private key can decrypt what’s been encrypted with the public key, and that establishes ownership.

            Why the person you responded to is being down-voted, and why people in this thread don’t seem to understand how shared keys work is pretty insane to me. This technology has exited, and remained relatively unchanged, for like… 40 years.

            The can encrypt my commit, making it indistinguishable from my commit.

            That’s not how commits are verified. The commit is signed with your private key (not encrypted), not your public key. Referencing the public key simply tells the ssh agent which key-pair to use, and the ssh daemon decides which key to use (public or private) based on the action that you’re doing.

            Signing a commit requires your private key, so no. People can’t just grab your public key and sign commits to impersonate you. They can simply encrypt text with it. That’s it. This is all self evident by the git property user.signingkeysign”. You’re signing the commit message, not encrypting anything.

            • SigmarStern@discuss.tchncs.de
              link
              fedilink
              arrow-up
              2
              ·
              3 days ago

              Sorry for the confusion about “encryption”. I meant “signing” which is encrypting a hash of the commit with your private key, so that others can verify that your the author of the commit using your public key and the hash.

              I think, the only confusion here was the original comment that referenced the public key for signing, but this was resolved, as it is just telling git which key pair to use. Probably, all people here understand the basics of asymmetrical encryption and signing and it was merely misunderstanding of how the command for signing git commits can be used.

              • Xanza@lemm.ee
                link
                fedilink
                English
                arrow-up
                4
                ·
                3 days ago

                Signing isn’t encryption. It’s a non-cipher hash.

                $ ❯ echo "This is a signed message." | ssh-keygen -Y sign -n file -f ~/.ssh/id_ed25519 > content.txt.sig
                Signing data on standard input
                

                Which outputs the hash of the signed statement, which was signed with my private key;

                -----BEGIN SSH SIGNATURE-----
                U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAgCwxAYX85ptsTc+Dtz3a0IRondh
                qFF3wKMsTqt+c4oGMAAAAEZmlsZQAAAAAAAAAGc2hhNTEyAAAAUwAAAAtzc2gtZWQyNTUx
                OQAAAECvqKLkm+kWUgFh0bI8jYIR5BPUaq76MZ94exp2yUn+KnK5YA79ggFY/C4VsnDqJp
                SAedWp4eOUwPNG8RR59KsP
                -----END SSH SIGNATURE-----
                

                And can then be verified using my public key;

                ❯ echo "This is a signed message." | ssh-keygen -Y check-novalidate -n file -f ~/.ssh/id_ed25519.pub -s content.txt.sig
                Good "file" signature with ED25519 key SHA256:ltAIkPgF9rLt1KlRRh6tQUtWNT8/wErhtAibmSHfbVs
                
                • frezik@midwest.social
                  link
                  fedilink
                  arrow-up
                  2
                  ·
                  3 days ago

                  Mathematically, signing is encryption using the private key. That’s how the algorithm works. The input to the function is irrelevant.

                • SigmarStern@discuss.tchncs.de
                  link
                  fedilink
                  arrow-up
                  1
                  ·
                  3 days ago

                  Thanks for that rabbit hole. My former colleagues and I have just started a new conversation thread in our WhatsApp group about the differences of (non-) cryptographic hashes and encryption. And all because I was confused why you’ve chosen to reference the public key file in your original comment. Well, at least I’m learning something.

        • Thunderwolf@lemmy.world
          link
          fedilink
          arrow-up
          3
          arrow-down
          1
          ·
          edit-2
          3 days ago

          I think encrypting with a public key is mostly used in client -> server traffic (client encrypts with server’s public key, server decrypts with private), and not code signing. However, I’m no TLS/asymmetric crypto savant.

          • Xanza@lemm.ee
            link
            fedilink
            English
            arrow-up
            2
            ·
            edit-2
            3 days ago

            Encryption can only be done with the PGP public key. Even if you specifically use the private key, it contains the public key, and GPG already knows to use the public key for encryption. You cannot create encrypted cipher text using a GPG private key.

            Likewise, you cannot decrypt data using the public key, nor can you sign statements with a public key. For those processes you must use a private key.

            I had no idea people found GPG this confusing…

    • 0x0@lemmy.zip
      link
      fedilink
      arrow-up
      1
      arrow-down
      2
      ·
      3 days ago

      Wouldn’t that mean you’d have to share your public key anyway?
      I have the same repos in multiple vms, keeping tabs of that key would be… interesting, considering i often use passwordless-logins across the board.

      • Xanza@lemm.ee
        link
        fedilink
        English
        arrow-up
        4
        ·
        3 days ago

        Wouldn’t that mean you’d have to share your public key anyway?

        Public keys aren’t meant to be private. The function is literally in the name… But no, you don’t necessarily have to share your public key, but for someone to verify that a specific public key was used to sign a commit, the public key is required. So there’s absolutely no reason to sign your commits if you intend on keeping your public key, private… It completely defeats the entire purpose…

        • 0x0@lemmy.zip
          link
          fedilink
          arrow-up
          1
          ·
          3 days ago

          Thanks, i know what “public” means.
          I don’t see “not usually installed on your system” as a strong enough disadvantage to PGP for this use case.

  • Eager Eagle@lemmy.world
    link
    fedilink
    English
    arrow-up
    1
    ·
    3 days ago

    does anyone know how to configure SSH signing on a remote server without creating another key on that server?

    If I’m using the same SSH key pair to access the remote server it kinda makes sense to use it to sign, but I don’t know how I would go about configuring git to do it.