Add ECDSA key import.
This commit is contained in:
parent
1e2d9b0899
commit
95e1cc36d3
4 changed files with 118 additions and 3 deletions
|
@ -11,7 +11,7 @@ tincd_SOURCES = \
|
||||||
protocol_key.c protocol_subnet.c route.c subnet.c tincd.c
|
protocol_key.c protocol_subnet.c route.c subnet.c tincd.c
|
||||||
|
|
||||||
nodist_tincd_SOURCES = \
|
nodist_tincd_SOURCES = \
|
||||||
device.c cipher.c crypto.c ecdh.c digest.c prf.c rsa.c
|
device.c cipher.c crypto.c ecdh.c ecdsa.c digest.c prf.c rsa.c
|
||||||
|
|
||||||
tincctl_SOURCES = \
|
tincctl_SOURCES = \
|
||||||
utils.c getopt.c getopt1.c dropin.c \
|
utils.c getopt.c getopt1.c dropin.c \
|
||||||
|
@ -32,7 +32,7 @@ INCLUDES = @INCLUDES@ -I$(top_builddir)
|
||||||
|
|
||||||
noinst_HEADERS = \
|
noinst_HEADERS = \
|
||||||
xalloc.h utils.h getopt.h list.h splay_tree.h dropin.h fake-getaddrinfo.h fake-getnameinfo.h fake-gai-errnos.h ipv6.h ipv4.h ethernet.h \
|
xalloc.h utils.h getopt.h list.h splay_tree.h dropin.h fake-getaddrinfo.h fake-getnameinfo.h fake-gai-errnos.h ipv6.h ipv4.h ethernet.h \
|
||||||
buffer.h cipher.h conf.h connection.h control.h control_common.h crypto.h device.h digest.h ecdh.h ecdsagen.c edge.h graph.h logger.h meta.h net.h netutl.h node.h prf.h process.h \
|
buffer.h cipher.h conf.h connection.h control.h control_common.h crypto.h device.h digest.h ecdh.h ecdsa.h ecdsagen.h edge.h graph.h logger.h meta.h net.h netutl.h node.h prf.h process.h \
|
||||||
protocol.h route.h rsa.h rsagen.h subnet.h tincctl.h top.h bsd/tunemu.h
|
protocol.h route.h rsa.h rsagen.h subnet.h tincctl.h top.h bsd/tunemu.h
|
||||||
|
|
||||||
LIBS = @LIBS@ @LIBGCRYPT_LIBS@
|
LIBS = @LIBS@ @LIBGCRYPT_LIBS@
|
||||||
|
|
81
src/openssl/ecdsa.c
Normal file
81
src/openssl/ecdsa.c
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
/*
|
||||||
|
ecdsa.c -- ECDSA key handling
|
||||||
|
Copyright (C) 2011 Guus Sliepen <guus@tinc-vpn.org>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "system.h"
|
||||||
|
|
||||||
|
#include <openssl/pem.h>
|
||||||
|
#include <openssl/err.h>
|
||||||
|
|
||||||
|
#include "logger.h"
|
||||||
|
#include "ecdsa.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
|
// Set ECDSA keys
|
||||||
|
|
||||||
|
bool ecdsa_set_base64_public_key(ecdsa_t *ecdsa, const char *p) {
|
||||||
|
*ecdsa = EC_KEY_new_by_curve_name(NID_secp521r1);
|
||||||
|
|
||||||
|
int len = strlen(p);
|
||||||
|
unsigned char pubkey[len / 4 * 3 + 3];
|
||||||
|
const unsigned char *ppubkey = pubkey;
|
||||||
|
len = b64decode(p, pubkey, len);
|
||||||
|
|
||||||
|
if(!o2i_ECPublicKey(ecdsa, &ppubkey, len)) {
|
||||||
|
logger(LOG_DEBUG, "o2i_ECPublicKey failed: %s", ERR_error_string(ERR_get_error(), NULL));
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read PEM ECDSA keys
|
||||||
|
|
||||||
|
bool ecdsa_read_pem_public_key(ecdsa_t *ecdsa, FILE *fp) {
|
||||||
|
*ecdsa = PEM_read_EC_PUBKEY(fp, ecdsa, NULL, NULL);
|
||||||
|
|
||||||
|
if(*ecdsa)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
logger(LOG_ERR, "Unable to read ECDSA public key: %s", ERR_error_string(ERR_get_error(), NULL));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ecdsa_read_pem_private_key(ecdsa_t *ecdsa, FILE *fp) {
|
||||||
|
*ecdsa = PEM_read_ECPrivateKey(fp, NULL, NULL, NULL);
|
||||||
|
|
||||||
|
if(*ecdsa)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
logger(LOG_ERR, "Unable to read ECDSA private key: %s", ERR_error_string(ERR_get_error(), NULL));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t ecdsa_size(ecdsa_t *ecdsa) {
|
||||||
|
return ECDSA_size(*ecdsa);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ecdsa_sign(ecdsa_t *ecdsa, const void *in, size_t len, void *sig) {
|
||||||
|
logger(LOG_ERR, "Unable to perform ECDSA signature: %s", ERR_error_string(ERR_get_error(), NULL));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ecdsa_verify(ecdsa_t *ecdsa, const void *in, size_t len, const void *sig) {
|
||||||
|
logger(LOG_ERR, "Unable to perform ECDSA verification: %s", ERR_error_string(ERR_get_error(), NULL));
|
||||||
|
return false;
|
||||||
|
}
|
34
src/openssl/ecdsa.h
Normal file
34
src/openssl/ecdsa.h
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
/*
|
||||||
|
ecdsa.h -- ECDSA key handling
|
||||||
|
Copyright (C) 2011 Guus Sliepen <guus@tinc-vpn.org>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __TINC_ECDSA_H__
|
||||||
|
#define __TINC_ECDSA_H__
|
||||||
|
|
||||||
|
#include <openssl/ec.h>
|
||||||
|
|
||||||
|
typedef EC_KEY *ecdsa_t;
|
||||||
|
|
||||||
|
extern bool ecdsa_set_base64_public_key(ecdsa_t *ecdsa, const char *p);
|
||||||
|
extern bool ecdsa_read_pem_public_key(ecdsa_t *ecdsa, FILE *fp);
|
||||||
|
extern bool ecdsa_read_pem_private_key(ecdsa_t *ecdsa, FILE *fp);
|
||||||
|
extern size_t ecdsa_size(ecdsa_t *ecdsa);
|
||||||
|
extern bool ecdsa_sign(ecdsa_t *ecdsa, const void *in, size_t inlen, void *out);
|
||||||
|
extern bool ecdsa_verify(ecdsa_t *ecdsa, const void *in, size_t inlen, const void *out);
|
||||||
|
|
||||||
|
#endif
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
ecdsagen.c -- ECDSA key generation and export
|
ecdsagen.c -- ECDSA key generation and export
|
||||||
Copyright (C) 2008 Guus Sliepen <guus@tinc-vpn.org>
|
Copyright (C) 2011 Guus Sliepen <guus@tinc-vpn.org>
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
This program is free software; you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|
Loading…
Reference in a new issue