Automatically exchange ECDSA keys and upgrade to new authentication protocol.
[tinc] / src / openssl / ecdsa.c
index a4f0f30..43464d8 100644 (file)
@@ -26,8 +26,8 @@
 #include "ecdsa.h"
 #include "utils.h"
 
-// Set ECDSA keys
-
+// Get and set ECDSA keys
+//
 bool ecdsa_set_base64_public_key(ecdsa_t *ecdsa, const char *p) {
        *ecdsa = EC_KEY_new_by_curve_name(NID_secp521r1);
 
@@ -44,6 +44,18 @@ bool ecdsa_set_base64_public_key(ecdsa_t *ecdsa, const char *p) {
        return true;
 }
 
+char *ecdsa_get_base64_public_key(ecdsa_t *ecdsa) {
+       unsigned char *pubkey = NULL;
+       int len = i2o_ECPublicKey(*ecdsa, &pubkey);
+
+       char *base64 = malloc(len * 4 / 3 + 5);
+       b64encode(pubkey, base64, len);
+
+       free(pubkey);
+
+       return base64;
+}
+
 // Read PEM ECDSA keys
 
 bool ecdsa_read_pem_public_key(ecdsa_t *ecdsa, FILE *fp) {