1
0
Эх сурвалжийг харах

puttygen switches --new-passphrase and --old-passphrase are recognized

Side-effect is deprecation of syntax -P <newpassphrase> (which puttygen does not support)

Source commit: 5567942948efcdee16be6d313e8ccfbd8764e8d1
Martin Prikryl 2 жил өмнө
parent
commit
de63014d9e

+ 1 - 1
source/core/Option.cpp

@@ -72,7 +72,7 @@ void __fastcall TOptions::Add(UnicodeString Value)
         // This is to treat /home/martin as parameter, not as switch.
         else if ((Value[Index] == L'?') ||
                  IsLetter(Value[Index]) ||
-                 ((Index == 2) && (Value[1] == L'-') && (Value[Index] == L'-'))) // allow --certificate
+                 ((Value[Index] == L'-') && (SwitchMark == L'-') && (Value[2] == L'-'))) // allow --puttygen-switches
         {
           // noop
         }

+ 21 - 12
source/windows/ConsoleRunner.cpp

@@ -2536,7 +2536,9 @@ int __fastcall BatchSettings(TConsole * Console, TProgramParams * Params)
 bool __fastcall FindPuttygenCompatibleSwitch(
   TProgramParams * Params, const UnicodeString & Name, const UnicodeString & PuttygenName, UnicodeString & Value, bool & Set)
 {
-  bool Result = Params->FindSwitch(Name, Value, Set);
+  bool Result =
+    !Name.IsEmpty() &&
+    Params->FindSwitch(Name, Value, Set);
   if (!Result)
   {
     std::unique_ptr<TStrings> Args(new TStringList());
@@ -2574,15 +2576,25 @@ int __fastcall KeyGen(TConsole * Console, TProgramParams * Params)
     UnicodeString NewComment;
     FindPuttygenCompatibleSwitch(Params, KEYGEN_COMMENT_SWITCH, L"C", NewComment, ValueSet);
 
+    bool ChangePassphrase;
     bool NewPassphraseSet;
-    bool ChangePassphrase =
-      FindPuttygenCompatibleSwitch(Params, KEYGEN_CHANGE_PASSPHRASE_SWITCH, L"P", NewPassphrase, NewPassphraseSet);
+    if (Params->FindSwitchCaseSensitive(L"P"))
+    {
+      ChangePassphrase = true;
+      FindPuttygenCompatibleSwitch(Params, EmptyStr, L"-new-passphrase", NewPassphrase, NewPassphraseSet);
+    }
+    else
+    {
+      ChangePassphrase = Params->FindSwitch(KEYGEN_CHANGE_PASSPHRASE_SWITCH, NewPassphrase, NewPassphraseSet);
+    }
 
     bool CertificateSet;
     UnicodeString Certificate;
     // It's --certificate in puttygen
     FindPuttygenCompatibleSwitch(Params, KEYGEN_CERTIFICATE_SWITCH, L"-certificate", Certificate, CertificateSet);
 
+    FindPuttygenCompatibleSwitch(Params, PassphraseOption, L"-old-passphrase", Passphrase, ValueSet);
+
     if (Params->ParamCount > 0)
     {
       throw Exception(LoadStr(TOO_MANY_PARAMS_ERROR));
@@ -2629,17 +2641,14 @@ int __fastcall KeyGen(TConsole * Console, TProgramParams * Params)
     }
 
     UnicodeString Comment;
-    if (IsKeyEncrypted(Type, InputFileName, Comment))
+    if (IsKeyEncrypted(Type, InputFileName, Comment) &&
+        Passphrase.IsEmpty())
     {
-      Passphrase = Params->SwitchValue(PassphraseOption);
-      if (Passphrase.IsEmpty())
+      Console->Print(StripHotkey(FMTLOAD(PROMPT_KEY_PASSPHRASE, (Comment))) + L" ");
+      if (!Console->Input(Passphrase, false, 0) ||
+          Passphrase.IsEmpty())
       {
-        Console->Print(StripHotkey(FMTLOAD(PROMPT_KEY_PASSPHRASE, (Comment))) + L" ");
-        if (!Console->Input(Passphrase, false, 0) ||
-            Passphrase.IsEmpty())
-        {
-          Abort();
-        }
+        Abort();
       }
     }