Browse Source

Support for new private key files formats + Recognition of public key files + Conversion of new OpenSSH private key format

Source commit: 3f50dd10f0ccaebb3d0ba35871020a5f050e4dd7
Martin Prikryl 9 years ago
parent
commit
eee5e3964a

+ 5 - 2
source/core/PuttyIntf.cpp

@@ -527,6 +527,7 @@ TKeyType KeyType(UnicodeString FileName)
 {
   DebugAssert(ktUnopenable == SSH_KEYTYPE_UNOPENABLE);
   DebugAssert(ktSSHCom == SSH_KEYTYPE_SSHCOM);
+  DebugAssert(ktSSH2PublicOpenSSH == SSH_KEYTYPE_SSH2_PUBLIC_OPENSSH);
   UTF8String UtfFileName = UTF8String(FileName);
   Filename * KeyFile = filename_from_str(UtfFileName.c_str());
   TKeyType Result = (TKeyType)key_type(KeyFile);
@@ -546,7 +547,8 @@ bool IsKeyEncrypted(TKeyType KeyType, const UnicodeString & FileName, UnicodeStr
       Result = (ssh2_userkey_encrypted(KeyFile, &CommentStr) != 0);
       break;
 
-    case ktOpenSSH:
+    case ktOpenSSHPEM:
+    case ktOpenSSHNew:
     case ktSSHCom:
       Result = (import_encrypted(KeyFile, KeyType, &CommentStr) != NULL);
       break;
@@ -585,7 +587,8 @@ TPrivateKey * LoadKey(TKeyType KeyType, const UnicodeString & FileName, const Un
       Ssh2Key = ssh2_load_userkey(KeyFile, AnsiPassphrase.c_str(), &ErrorStr);
       break;
 
-    case ktOpenSSH:
+    case ktOpenSSHPEM:
+    case ktOpenSSHNew:
     case ktSSHCom:
       Ssh2Key = import_ssh2(KeyFile, KeyType, AnsiPassphrase.c_str(), &ErrorStr);
       break;

+ 7 - 1
source/core/PuttyTools.h

@@ -2,7 +2,13 @@
 #ifndef PuttyToolsH
 #define PuttyToolsH
 //---------------------------------------------------------------------------
-enum TKeyType { ktUnopenable, ktUnknown, ktSSH1, ktSSH2, ktOpenSSH, ktSSHCom };
+enum TKeyType
+{
+  ktUnopenable, ktUnknown,
+  ktSSH1, ktSSH2,
+  ktOpenSSHAuto, ktOpenSSHPEM, ktOpenSSHNew, ktSSHCom,
+  ktSSH1Public, ktSSH2PublicRFC4716, ktSSH2PublicOpenSSH
+};
 TKeyType KeyType(UnicodeString FileName);
 bool IsKeyEncrypted(TKeyType KeyType, const UnicodeString & FileName, UnicodeString & Comment);
 struct TPrivateKey;

+ 1 - 0
source/resource/TextsWin.h

@@ -82,6 +82,7 @@
 #define UPDATE_MISSING_ADDRESS  1196
 #define UPDATE_TOO_LOW          1197
 #define TIPS_NONE               1198
+#define KEYGEN_PUBLIC           1199
 
 #define WIN_CONFIRMATION_STRINGS 1300
 #define CONFIRM_OVERWRITE_SESSION 1301

+ 1 - 0
source/resource/TextsWin1.rc

@@ -88,6 +88,7 @@ BEGIN
         UPDATE_MISSING_ADDRESS, "To enable automatic updates, please provide us your postal address using a link from your donation receipt."
         UPDATE_TOO_LOW, "Your donation is below the limit required to enable automatic updates."
         TIPS_NONE, "No tips."
+        KEYGEN_PUBLIC, "Converting public keys is not supported."
 
         WIN_CONFIRMATION_STRINGS, "WIN_CONFIRMATION"
         CONFIRM_OVERWRITE_SESSION, "Site with name '%s' already exists. Overwrite?"

+ 8 - 1
source/windows/ConsoleRunner.cpp

@@ -2279,7 +2279,8 @@ int __fastcall KeyGen(TConsole * Console, TProgramParams * Params)
         }
         break;
 
-      case ktOpenSSH:
+      case ktOpenSSHPEM:
+      case ktOpenSSHNew:
       case ktSSHCom:
         if (OutputFileName.IsEmpty())
         {
@@ -2287,9 +2288,15 @@ int __fastcall KeyGen(TConsole * Console, TProgramParams * Params)
         }
         break;
 
+      case ktSSH1Public:
+      case ktSSH2PublicRFC4716:
+      case ktSSH2PublicOpenSSH:
+        throw Exception(LoadStr(KEYGEN_PUBLIC));
+
       case ktUnopenable:
         throw EOSExtException(FMTLOAD(KEY_TYPE_UNOPENABLE, (InputFileName)), Error);
 
+      case ktOpenSSHAuto:
       default:
         DebugFail();
         // fallthru

+ 10 - 2
source/windows/Tools.cpp

@@ -1004,10 +1004,11 @@ static void __fastcall DoVerifyKey(
     std::unique_ptr<TStrings> MoreMessages;
     switch (Type)
     {
-      case ktOpenSSH:
+      case ktOpenSSHPEM:
+      case ktOpenSSHNew:
       case ktSSHCom:
         {
-          UnicodeString TypeName = (Type == ktOpenSSH) ? L"OpenSSH SSH-2" : L"ssh.com SSH-2";
+          UnicodeString TypeName = ((Type == ktOpenSSHPEM) || (Type == ktOpenSSHNew)) ? L"OpenSSH SSH-2" : L"ssh.com SSH-2";
           Message = FMTLOAD(KEY_TYPE_UNSUPPORTED2, (FileName, TypeName));
 
           if (Convert)
@@ -1049,6 +1050,13 @@ static void __fastcall DoVerifyKey(
         }
         break;
 
+      case ktSSH1Public:
+      case ktSSH2PublicRFC4716:
+      case ktSSH2PublicOpenSSH:
+        // noop
+        // Do not even bother checking SSH protocol version
+        break;
+
       case ktUnopenable:
         Message = MainInstructions(FMTLOAD(KEY_TYPE_UNOPENABLE, (FileName)));
         if (Error != ERROR_SUCCESS)