signkey.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * Dropbear - a SSH2 server
  3. *
  4. * Copyright (c) 2002,2003 Matt Johnston
  5. * All rights reserved.
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy
  8. * of this software and associated documentation files (the "Software"), to deal
  9. * in the Software without restriction, including without limitation the rights
  10. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. * copies of the Software, and to permit persons to whom the Software is
  12. * furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in
  15. * all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23. * SOFTWARE. */
  24. #ifndef DROPBEAR_SIGNKEY_H_
  25. #define DROPBEAR_SIGNKEY_H_
  26. #include "buffer.h"
  27. /* Forward declarations */
  28. struct dropbear_DSS_Key;
  29. struct dropbear_RSA_Key;
  30. struct dropbear_ED25519_Key;
  31. /* Must match with signature_type below */
  32. enum signkey_type {
  33. #if DROPBEAR_RSA
  34. DROPBEAR_SIGNKEY_RSA,
  35. #endif
  36. #if DROPBEAR_DSS
  37. DROPBEAR_SIGNKEY_DSS,
  38. #endif
  39. #if DROPBEAR_ECDSA
  40. DROPBEAR_SIGNKEY_ECDSA_NISTP256,
  41. DROPBEAR_SIGNKEY_ECDSA_NISTP384,
  42. DROPBEAR_SIGNKEY_ECDSA_NISTP521,
  43. #if DROPBEAR_SK_ECDSA
  44. DROPBEAR_SIGNKEY_SK_ECDSA_NISTP256,
  45. #endif /* DROPBEAR_SK_ECDSA */
  46. #endif /* DROPBEAR_ECDSA */
  47. #if DROPBEAR_ED25519
  48. DROPBEAR_SIGNKEY_ED25519,
  49. #if DROPBEAR_SK_ED25519
  50. DROPBEAR_SIGNKEY_SK_ED25519,
  51. #endif
  52. #endif
  53. DROPBEAR_SIGNKEY_NUM_NAMED,
  54. DROPBEAR_SIGNKEY_ECDSA_KEYGEN = 70, /* just "ecdsa" for keygen */
  55. DROPBEAR_SIGNKEY_ANY = 80,
  56. DROPBEAR_SIGNKEY_NONE = 90,
  57. };
  58. /* Must match with signkey_type above, apart from rsa */
  59. enum signature_type {
  60. #if DROPBEAR_DSS
  61. DROPBEAR_SIGNATURE_DSS = DROPBEAR_SIGNKEY_DSS,
  62. #endif
  63. #if DROPBEAR_ECDSA
  64. DROPBEAR_SIGNATURE_ECDSA_NISTP256 = DROPBEAR_SIGNKEY_ECDSA_NISTP256,
  65. DROPBEAR_SIGNATURE_ECDSA_NISTP384 = DROPBEAR_SIGNKEY_ECDSA_NISTP384,
  66. DROPBEAR_SIGNATURE_ECDSA_NISTP521 = DROPBEAR_SIGNKEY_ECDSA_NISTP521,
  67. #if DROPBEAR_SK_ECDSA
  68. DROPBEAR_SIGNATURE_SK_ECDSA_NISTP256 = DROPBEAR_SIGNKEY_SK_ECDSA_NISTP256,
  69. #endif /* DROPBEAR_SK_ECDSA */
  70. #endif /* DROPBEAR_ECDSA */
  71. #if DROPBEAR_ED25519
  72. DROPBEAR_SIGNATURE_ED25519 = DROPBEAR_SIGNKEY_ED25519,
  73. #if DROPBEAR_SK_ED25519
  74. DROPBEAR_SIGNATURE_SK_ED25519 = DROPBEAR_SIGNKEY_SK_ED25519,
  75. #endif
  76. #endif
  77. #if DROPBEAR_RSA_SHA1
  78. DROPBEAR_SIGNATURE_RSA_SHA1 = 100, /* ssh-rsa signature (sha1) */
  79. #endif
  80. #if DROPBEAR_RSA_SHA256
  81. DROPBEAR_SIGNATURE_RSA_SHA256 = 101, /* rsa-sha2-256 signature. has a ssh-rsa key */
  82. #endif
  83. DROPBEAR_SIGNATURE_NONE = DROPBEAR_SIGNKEY_NONE,
  84. };
  85. /* Sources for signing keys */
  86. typedef enum {
  87. SIGNKEY_SOURCE_RAW_FILE,
  88. SIGNKEY_SOURCE_AGENT,
  89. SIGNKEY_SOURCE_INVALID,
  90. } signkey_source;
  91. struct SIGN_key {
  92. enum signkey_type type;
  93. signkey_source source;
  94. char *filename;
  95. #if DROPBEAR_DSS
  96. struct dropbear_DSS_Key * dsskey;
  97. #endif
  98. #if DROPBEAR_RSA
  99. struct dropbear_RSA_Key * rsakey;
  100. #endif
  101. #if DROPBEAR_ECDSA
  102. #if DROPBEAR_ECC_256
  103. ecc_key * ecckey256;
  104. #endif
  105. #if DROPBEAR_ECC_384
  106. ecc_key * ecckey384;
  107. #endif
  108. #if DROPBEAR_ECC_521
  109. ecc_key * ecckey521;
  110. #endif
  111. #endif
  112. #if DROPBEAR_ED25519
  113. struct dropbear_ED25519_Key * ed25519key;
  114. #endif
  115. #if DROPBEAR_SK_ECDSA || DROPBEAR_SK_ED25519
  116. /* application ID for U2F/FIDO key types, a malloced string */
  117. char * sk_app;
  118. unsigned int sk_applen;
  119. #endif
  120. };
  121. typedef struct SIGN_key sign_key;
  122. sign_key * new_sign_key(void);
  123. const char* signkey_name_from_type(enum signkey_type type, unsigned int *namelen);
  124. enum signkey_type signkey_type_from_name(const char* name, unsigned int namelen);
  125. const char* signature_name_from_type(enum signature_type type, unsigned int *namelen);
  126. enum signature_type signature_type_from_name(const char* name, unsigned int namelen);
  127. enum signkey_type signkey_type_from_signature(enum signature_type sigtype);
  128. enum signature_type signature_type_from_signkey(enum signkey_type keytype);
  129. int buf_get_pub_key(buffer *buf, sign_key *key, enum signkey_type *type);
  130. int buf_get_priv_key(buffer* buf, sign_key *key, enum signkey_type *type);
  131. void buf_put_pub_key(buffer* buf, sign_key *key, enum signkey_type type);
  132. void buf_put_priv_key(buffer* buf, sign_key *key, enum signkey_type type);
  133. void sign_key_free(sign_key *key);
  134. void buf_put_sign(buffer* buf, sign_key *key, enum signature_type sigtype, const buffer *data_buf);
  135. #if DROPBEAR_SIGNKEY_VERIFY
  136. int buf_verify(buffer * buf, sign_key *key, enum signature_type expect_sigtype, const buffer *data_buf);
  137. int sk_buf_verify(buffer * buf, sign_key *key, enum signature_type expect_sigtype, const buffer *data_buf, char* app, unsigned int applen);
  138. char * sign_key_fingerprint(const unsigned char* keyblob, unsigned int keybloblen);
  139. #endif
  140. int cmp_base64_key(const unsigned char* keyblob, unsigned int keybloblen,
  141. const unsigned char* algoname, unsigned int algolen,
  142. const buffer * line, char ** fingerprint);
  143. void** signkey_key_ptr(sign_key *key, enum signkey_type type);
  144. #endif /* DROPBEAR_SIGNKEY_H_ */