sk-api.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* $OpenBSD: sk-api.h,v 1.11 2020/09/09 03:08:01 djm Exp $ */
  2. /*
  3. * Copyright (c) 2019 Google LLC
  4. *
  5. * Permission to use, copy, modify, and distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #ifndef _SK_API_H
  18. #define _SK_API_H 1
  19. #include <stddef.h>
  20. #ifdef HAVE_STDINT_H
  21. #include <stdint.h>
  22. #endif
  23. /* Flags */
  24. #define SSH_SK_USER_PRESENCE_REQD 0x01
  25. #define SSH_SK_USER_VERIFICATION_REQD 0x04
  26. #define SSH_SK_RESIDENT_KEY 0x20
  27. /* Algs */
  28. #define SSH_SK_ECDSA 0x00
  29. #define SSH_SK_ED25519 0x01
  30. /* Error codes */
  31. #define SSH_SK_ERR_GENERAL -1
  32. #define SSH_SK_ERR_UNSUPPORTED -2
  33. #define SSH_SK_ERR_PIN_REQUIRED -3
  34. #define SSH_SK_ERR_DEVICE_NOT_FOUND -4
  35. struct sk_enroll_response {
  36. uint8_t *public_key;
  37. size_t public_key_len;
  38. uint8_t *key_handle;
  39. size_t key_handle_len;
  40. uint8_t *signature;
  41. size_t signature_len;
  42. uint8_t *attestation_cert;
  43. size_t attestation_cert_len;
  44. uint8_t *authdata;
  45. size_t authdata_len;
  46. };
  47. struct sk_sign_response {
  48. uint8_t flags;
  49. uint32_t counter;
  50. uint8_t *sig_r;
  51. size_t sig_r_len;
  52. uint8_t *sig_s;
  53. size_t sig_s_len;
  54. };
  55. struct sk_resident_key {
  56. uint32_t alg;
  57. size_t slot;
  58. char *application;
  59. struct sk_enroll_response key;
  60. uint8_t flags;
  61. };
  62. struct sk_option {
  63. char *name;
  64. char *value;
  65. uint8_t required;
  66. };
  67. #define SSH_SK_VERSION_MAJOR 0x00070000 /* current API version */
  68. #define SSH_SK_VERSION_MAJOR_MASK 0xffff0000
  69. /* Return the version of the middleware API */
  70. uint32_t sk_api_version(void);
  71. /* Enroll a U2F key (private key generation) */
  72. int sk_enroll(uint32_t alg, const uint8_t *challenge, size_t challenge_len,
  73. const char *application, uint8_t flags, const char *pin,
  74. struct sk_option **options, struct sk_enroll_response **enroll_response);
  75. /* Sign a challenge */
  76. int sk_sign(uint32_t alg, const uint8_t *data, size_t data_len,
  77. const char *application, const uint8_t *key_handle, size_t key_handle_len,
  78. uint8_t flags, const char *pin, struct sk_option **options,
  79. struct sk_sign_response **sign_response);
  80. /* Enumerate all resident keys */
  81. int sk_load_resident_keys(const char *pin, struct sk_option **options,
  82. struct sk_resident_key ***rks, size_t *nrks);
  83. #endif /* _SK_API_H */