RawByteString THierarchicalStorage::ReadBinaryData(const UnicodeString & Name) const
{
  size_t Size = BinaryDataSize(Name);
  RawByteString Value;
  Value.SetLength(Size);
  ReadBinaryData(Name, static_cast<void *>(const_cast<char *>(Value.c_str())), Size);
  return Value;
}
Esempio n. 2
0
UnicodeString TConfiguration::BannerHash(const UnicodeString & Banner) const
{
  RawByteString Result;
  Result.SetLength(16);
  md5checksum(
    reinterpret_cast<const char *>(Banner.c_str()), static_cast<int>(Banner.Length() * sizeof(wchar_t)),
    reinterpret_cast<uint8_t *>(const_cast<char *>(Result.c_str())));
  return BytesToHex(Result);
}
Esempio n. 3
0
//---------------------------------------------------------------------------
UnicodeString __fastcall TConfiguration::BannerHash(const UnicodeString & Banner)
{
  RawByteString Result;
  Result.SetLength(16);
  md5checksum(
    reinterpret_cast<const char*>(Banner.c_str()), Banner.Length() * sizeof(wchar_t),
    (unsigned char*)Result.c_str());
  return BytesToHex(Result);
}
Esempio n. 4
0
UnicodeString TConfiguration::DecryptPassword(const RawByteString & Password, const UnicodeString & Key)
{
  if (Password.IsEmpty())
  {
    return UnicodeString();
  }
  else
  {
    return ::DecryptPassword(Password, Key);
  }
}
Esempio n. 5
0
//---------------------------------------------------------------------------
UnicodeString __fastcall TConfiguration::DecryptPassword(RawByteString Password, UnicodeString Key)
{
  if (Password.IsEmpty())
  {
    return UnicodeString();
  }
  else
  {
    return ::DecryptPassword(Password, Key);
  }
}
UnicodeString MungeStr(const UnicodeString & Str, bool ForceAnsi)
{
  RawByteString Source;
  if (ForceAnsi)
  {
    Source = RawByteString(AnsiString(Str));
  }
  else
  {
    Source = RawByteString(UTF8String(Str));
    if (Source.Length() > Str.Length())
    {
      Source.Insert(CONST_BOM, 1);
    }
  }
  // should contain ASCII characters only
  RawByteString Dest;
  char * Buffer = Dest.SetLength(Source.Length() * 3 + 1);
  putty_mungestr(Source.c_str(), Buffer);
  PackStr(Dest);
  return UnicodeString(Dest.c_str(), Dest.Length());
}
UnicodeString UnMungeStr(const UnicodeString & Str)
{
  // Str should contain ASCII characters only
  RawByteString Source = Str;
  RawByteString Dest;
  char * Buffer = Dest.SetLength(Source.GetLength());
  putty_unmungestr(Source.c_str(), Buffer, static_cast<int>(Source.GetLength()));
  // Cut the string at null character
  PackStr(Dest);
  UnicodeString Result;
  const std::string Bom(CONST_BOM);
  if (Dest.Pos(Bom.c_str()) == 1)
  {
    Dest.Delete(1, Bom.size());
    Result = UTF8ToString(Dest);
  }
  else
  {
    Result = AnsiToString(Dest);
  }
  return Result;
}
Esempio n. 8
0
const AnsiString & __fastcall AnsiString::operator +=(const RawByteString & rhs)
{
  Data.append(reinterpret_cast<const char *>(rhs.c_str()), rhs.size());
  return *this;
}
Esempio n. 9
0
AnsiString __fastcall AnsiString::operator +(const RawByteString & rhs) const
{
  std::string Result = Data + rhs.c_str();
  return AnsiString(Result.c_str(), static_cast<int>(Result.size()));
}
Esempio n. 10
0
const UnicodeString & __fastcall UnicodeString::operator +=(const RawByteString & rhs)
{
  UnicodeString s(rhs.c_str(), rhs.size());
  Data.append(s.Data.c_str(), s.size());
  return *this;
}
void THierarchicalStorage::WriteBinaryData(const UnicodeString & Name,
  const RawByteString & Value)
{
  WriteBinaryData(Name, Value.c_str(), Value.Length());
}
Esempio n. 12
0
int GetUserpassInput(prompts_t * p, const uint8_t * /*in*/, int /*inlen*/)
{
  DebugAssert(p != nullptr);
  TSecureShell * SecureShell = NB_STATIC_DOWNCAST(TSecureShell, p->frontend);
  DebugAssert(SecureShell != nullptr);

  int Result;
  std::unique_ptr<TStrings> Prompts(new TStringList());
  std::unique_ptr<TStrings> Results(new TStringList());
  {
    UnicodeString Name = UTF8ToString(p->name);
    UnicodeString AName = Name;
    TPromptKind PromptKind = SecureShell->IdentifyPromptKind(AName);
    bool UTF8Prompt = (PromptKind != pkPassphrase);

    for (size_t Index = 0; Index < p->n_prompts; ++Index)
    {
      prompt_t * Prompt = p->prompts[Index];
      UnicodeString S;
      if (UTF8Prompt)
      {
        S = UTF8ToString(Prompt->prompt);
      }
      else
      {
        S = UnicodeString(AnsiString(Prompt->prompt));
      }
      Prompts->AddObject(S, reinterpret_cast<TObject *>(static_cast<size_t>(FLAGMASK(Prompt->echo, pupEcho))));
      // this fails, when new passwords do not match on change password prompt,
      // and putty retries the prompt
      DebugAssert(Prompt->resultsize == 0);
      Results->Add(L"");
    }

    UnicodeString Instructions = UTF8ToString(p->instruction);
    if (SecureShell->PromptUser(p->to_server != 0, Name, p->name_reqd != 0,
          Instructions, p->instr_reqd != 0, Prompts.get(), Results.get()))
    {
      for (size_t Index = 0; Index < p->n_prompts; ++Index)
      {
        prompt_t * Prompt = p->prompts[Index];
        RawByteString S;
        if (UTF8Prompt)
        {
          S = RawByteString(UTF8String(Results->GetString(Index)));
        }
        else
        {
          S = RawByteString(AnsiString(Results->GetString(Index)));
        }
        prompt_set_result(Prompt, S.c_str());
      }
      Result = 1;
    }
    else
    {
      Result = 0;
    }
  }
  __finally
  {
//    delete Prompts;
//    delete Results;
  };

  return Result;
}
Esempio n. 13
0
AnsiString AnsiString::operator +(const RawByteString & rhs) const
{
  AnsiString Result = AnsiString(Data.c_str(), Data.size());
  Result += rhs.c_str();
  return Result;
}
Esempio n. 14
0
TEncodeType DetectUTF8Encoding(const RawByteString & S)
{
  const uint8_t *buf = reinterpret_cast<const uint8_t *>(S.c_str());
  intptr_t len = S.Length();
  const uint8_t * endbuf = buf + len;
  uint8_t byte2mask = 0x00;
  int trailing = 0;  // trailing (continuation) bytes to follow

  while (buf != endbuf)
  {
    uint8_t c = *buf++;
    if (trailing)
    {
      if ((c & 0xC0) == 0x80)  // Does trailing byte follow UTF-8 format?
      {
      if (byte2mask)        // Need to check 2nd byte for proper range?
      {
        if (c & byte2mask)     // Are appropriate bits set?
          byte2mask = 0x00;
        else
          return etANSI;
      }
        trailing--;
      }
      else
        return etANSI;
    }
    else
    {
      if ((c & 0x80) == 0x00)
        continue;      // valid 1 byte UTF-8
      else if ((c & 0xE0) == 0xC0)            // valid 2 byte UTF-8
      {
        if (c & 0x1E)                     // Is UTF-8 byte in
          // proper range?
          trailing = 1;
        else
          return etANSI;
      }
      else if ((c & 0xF0) == 0xE0)           // valid 3 byte UTF-8
      {
        if (!(c & 0x0F))                // Is UTF-8 byte in
          // proper range?
          byte2mask = 0x20;              // If not set mask
        // to check next byte
        trailing = 2;
      }
      else if ((c & 0xF8) == 0xF0)           // valid 4 byte UTF-8
      {
        if (!(c & 0x07))                // Is UTF-8 byte in
        {
          // proper range?

          byte2mask = 0x30;              // If not set mask
        }
        // to check next byte
        trailing = 3;
      }
      else if ((c & 0xFC) == 0xF8)           // valid 5 byte UTF-8
      {
        if (!(c & 0x03))                // Is UTF-8 byte in
          // proper range?
          byte2mask = 0x38;              // If not set mask
        // to check next byte
        trailing = 4;
      }
      else if ((c & 0xFE) == 0xFC)           // valid 6 byte UTF-8
      {
        if (!(c & 0x01))                // Is UTF-8 byte in
          // proper range?
          byte2mask = 0x3C;              // If not set mask
        // to check next byte
        trailing = 5;
      }
      else
        return etANSI;
    }
  }
  return trailing == 0 ? etUTF8 : etANSI;
}