[seahorse] ssh: fix magic key length detection.



commit 19431ea842114551647df0f67e73fbe62e08839a
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Wed Aug 8 01:30:01 2018 +0200

    ssh: fix magic key length detection.
    
    Fixed this after a hint from someone in #52.
    
    So, why do we need to substract the magic number 23?
    We assume that we're dealing with a key file that follows [RFC4716].
    That means that if we base64-decode this, we find the following fields:
    
    * the string "ssh-rsa"                7 bytes
    *  ... prefixed by its length         4 bytes
    * the exponent (usually 65537)        3 bytes
    *  ... prefixed by its length         4 bytes
    * the modulus                         X bytes
    *  ... prefixed by its length         4 bytes
    ---------------------------------     ------------ +
         Total length:                    X + 22 bytes
    
    So we need to substract at least 22 bytes from the total key length.
    
    But then why do you substract 23 you say? Because this all is base64
    encoded, which requires the total bytes to be a multitude of 3. Since
    this is most of the time not the case (22 isn't divisible by 3 and the
    modulus length very often is a power of 2 so even), we need to pad with
    another byte.
    
    Fixes #52. Now, we will only get strange results when people use a
    non-conventional exponent or modulus.
    
    [RFC4716]: http://tools.ietf.org/html/rfc4716

 ssh/key-data.vala | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
---
diff --git a/ssh/key-data.vala b/ssh/key-data.vala
index ac3e5b2e..1fdb1e6a 100644
--- a/ssh/key-data.vala
+++ b/ssh/key-data.vala
@@ -123,7 +123,7 @@ public class Seahorse.Ssh.KeyData : GLib.Object {
         switch (algo) {
             case Algorithm.RSA:
                 // Seems accurate to nearest 8 bits
-                return ((len - 21) * 8);
+                return ((len - 23) * 8);
 
             case Algorithm.DSA:
                 // DSA keys seem to only work at 'bits % 64 == 0' boundaries


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]