aboutsummaryrefslogtreecommitdiff
path: root/contrib/libfido2/examples/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/libfido2/examples/util.c')
-rw-r--r--contrib/libfido2/examples/util.c65
1 files changed, 62 insertions, 3 deletions
diff --git a/contrib/libfido2/examples/util.c b/contrib/libfido2/examples/util.c
index 8b360af21c7a..0c0c77a94001 100644
--- a/contrib/libfido2/examples/util.c
+++ b/contrib/libfido2/examples/util.c
@@ -1,7 +1,8 @@
/*
- * Copyright (c) 2018 Yubico AB. All rights reserved.
+ * Copyright (c) 2018-2022 Yubico AB. All rights reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file.
+ * SPDX-License-Identifier: BSD-2-Clause
*/
#include <sys/types.h>
@@ -13,6 +14,7 @@
#include <fido.h>
#include <fido/es256.h>
+#include <fido/es384.h>
#include <fido/rs256.h>
#include <fido/eddsa.h>
@@ -158,7 +160,7 @@ fail:
}
int
-write_ec_pubkey(const char *path, const void *ptr, size_t len)
+write_es256_pubkey(const char *path, const void *ptr, size_t len)
{
FILE *fp = NULL;
EVP_PKEY *pkey = NULL;
@@ -214,6 +216,63 @@ fail:
return (ok);
}
+int
+write_es384_pubkey(const char *path, const void *ptr, size_t len)
+{
+ FILE *fp = NULL;
+ EVP_PKEY *pkey = NULL;
+ es384_pk_t *pk = NULL;
+ int fd = -1;
+ int ok = -1;
+
+ if ((pk = es384_pk_new()) == NULL) {
+ warnx("es384_pk_new");
+ goto fail;
+ }
+
+ if (es384_pk_from_ptr(pk, ptr, len) != FIDO_OK) {
+ warnx("es384_pk_from_ptr");
+ goto fail;
+ }
+
+ if ((fd = open(path, O_WRONLY | O_CREAT, 0644)) < 0) {
+ warn("open %s", path);
+ goto fail;
+ }
+
+ if ((fp = fdopen(fd, "w")) == NULL) {
+ warn("fdopen");
+ goto fail;
+ }
+ fd = -1; /* owned by fp now */
+
+ if ((pkey = es384_pk_to_EVP_PKEY(pk)) == NULL) {
+ warnx("es384_pk_to_EVP_PKEY");
+ goto fail;
+ }
+
+ if (PEM_write_PUBKEY(fp, pkey) == 0) {
+ warnx("PEM_write_PUBKEY");
+ goto fail;
+ }
+
+ ok = 0;
+fail:
+ es384_pk_free(&pk);
+
+ if (fp != NULL) {
+ fclose(fp);
+ }
+ if (fd != -1) {
+ close(fd);
+ }
+ if (pkey != NULL) {
+ EVP_PKEY_free(pkey);
+ }
+
+ return (ok);
+}
+
RSA *
read_rsa_pubkey(const char *path)
{
@@ -247,7 +306,7 @@ fail:
}
int
-write_rsa_pubkey(const char *path, const void *ptr, size_t len)
+write_rs256_pubkey(const char *path, const void *ptr, size_t len)
{
FILE *fp = NULL;
EVP_PKEY *pkey = NULL;