opensshkeyfilereader_p.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2018 The Qt Company Ltd.
  4. ** Contact: https://www.qt.io/licensing/
  5. **
  6. ** This file is part of Qt Creator.
  7. **
  8. ** Commercial License Usage
  9. ** Licensees holding valid commercial Qt licenses may use this file in
  10. ** accordance with the commercial license agreement provided with the
  11. ** Software or, alternatively, in accordance with the terms contained in
  12. ** a written agreement between you and The Qt Company. For licensing terms
  13. ** and conditions see https://www.qt.io/terms-conditions. For further
  14. ** information use the contact form at https://www.qt.io/contact-us.
  15. **
  16. ** GNU General Public License Usage
  17. ** Alternatively, this file may be used under the terms of the GNU
  18. ** General Public License version 3 as published by the Free Software
  19. ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
  20. ** included in the packaging of this file. Please review the following
  21. ** information to ensure the GNU General Public License requirements will
  22. ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
  23. **
  24. ****************************************************************************/
  25. #pragma once
  26. #include <QByteArray>
  27. #include <QList>
  28. #include <botan/bigint.h>
  29. #include <memory>
  30. namespace Botan {
  31. class Private_Key;
  32. class RandomNumberGenerator;
  33. }
  34. namespace QSsh {
  35. namespace Internal {
  36. class OpenSshKeyFileReader
  37. {
  38. public:
  39. OpenSshKeyFileReader(Botan::RandomNumberGenerator &rng) : m_rng(rng) {}
  40. bool parseKey(const QByteArray &privKeyFileContents);
  41. QByteArray keyType() const { return m_keyType; }
  42. std::unique_ptr<Botan::Private_Key> privateKey() const;
  43. QList<Botan::BigInt> allParameters() const { return m_parameters; }
  44. QList<Botan::BigInt> publicParameters() const;
  45. private:
  46. void doParse(const QByteArray &payload);
  47. void parseKdfOptions(const QByteArray &kdfOptions);
  48. void decryptPrivateKeyList();
  49. void parsePrivateKeyList();
  50. [[noreturn]] void throwException(const QString &reason);
  51. Botan::RandomNumberGenerator &m_rng;
  52. QByteArray m_keyType;
  53. QList<Botan::BigInt> m_parameters;
  54. QByteArray m_cipherName;
  55. QByteArray m_kdf;
  56. QByteArray m_salt;
  57. quint32 m_rounds;
  58. QByteArray m_privateKeyList;
  59. };
  60. } // namespace Internal
  61. } // namespace QSsh