mirror of
https://github.com/strongswan/strongswan.git
synced 2025-10-15 00:00:16 -04:00
implemented PGP fingerprinting
This commit is contained in:
parent
e773fe4cab
commit
d1b3e8607e
@ -6,6 +6,7 @@ AM_CFLAGS = -rdynamic
|
||||
plugin_LTLIBRARIES = libstrongswan-pgp.la
|
||||
|
||||
libstrongswan_pgp_la_SOURCES = pgp_plugin.h pgp_plugin.c \
|
||||
pgp_encoder.h pgp_encoder.c \
|
||||
pgp_builder.h pgp_builder.c
|
||||
|
||||
libstrongswan_pgp_la_LDFLAGS = -module -avoid-version
|
||||
|
68
src/libstrongswan/plugins/pgp/pgp_encoder.c
Normal file
68
src/libstrongswan/plugins/pgp/pgp_encoder.c
Normal file
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (C) 2009 Martin Willi
|
||||
* Hochschule fuer Technik Rapperswil
|
||||
*
|
||||
* 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. See <http://www.fsf.org/copyleft/gpl.txt>.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "pgp_encoder.h"
|
||||
|
||||
#include <debug.h>
|
||||
|
||||
/**
|
||||
* Build a PGPv3 fingerprint
|
||||
*/
|
||||
static bool build_v3_fingerprint(chunk_t *encoding, va_list args)
|
||||
{
|
||||
hasher_t *hasher;
|
||||
chunk_t n, e;
|
||||
|
||||
if (key_encoding_args(args, KEY_PART_RSA_MODULUS, &n,
|
||||
KEY_PART_RSA_PUB_EXP, &e, KEY_PART_END))
|
||||
{
|
||||
hasher = lib->crypto->create_hasher(lib->crypto, HASH_MD5);
|
||||
if (!hasher)
|
||||
{
|
||||
DBG1("MD5 hash algorithm not supported, PGP fingerprinting failed");
|
||||
return FALSE;
|
||||
}
|
||||
/* remove leading zero bytes before hashing modulus and exponent */
|
||||
while (n.len > 0 && n.ptr[0] == 0x00)
|
||||
{
|
||||
n = chunk_skip(n, 1);
|
||||
}
|
||||
while (e.len > 0 && e.ptr[0] == 0x00)
|
||||
{
|
||||
e = chunk_skip(e, 1);
|
||||
}
|
||||
hasher->allocate_hash(hasher, n, NULL);
|
||||
hasher->allocate_hash(hasher, e, encoding);
|
||||
hasher->destroy(hasher);
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* See header.
|
||||
*/
|
||||
bool pgp_encoder_encode(key_encoding_type_t type, chunk_t *encoding,
|
||||
va_list args)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case KEY_ID_PGPV3:
|
||||
return build_v3_fingerprint(encoding, args);
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
32
src/libstrongswan/plugins/pgp/pgp_encoder.h
Normal file
32
src/libstrongswan/plugins/pgp/pgp_encoder.h
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (C) 2009 Martin Willi
|
||||
* Hochschule fuer Technik Rapperswil
|
||||
*
|
||||
* 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. See <http://www.fsf.org/copyleft/gpl.txt>.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup pgp_encoder pgp_encoder
|
||||
* @{ @ingroup pgp
|
||||
*/
|
||||
|
||||
#ifndef PGP_ENCODER_H_
|
||||
#define PGP_ENCODER_H_
|
||||
|
||||
#include <credentials/keys/key_encoding.h>
|
||||
|
||||
/**
|
||||
* Encoding function for PGP fingerprints.
|
||||
*/
|
||||
bool pgp_encoder_encode(key_encoding_type_t type, chunk_t *encoding,
|
||||
va_list args);
|
||||
|
||||
#endif /* PGP_ENCODER_ @}*/
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include <library.h>
|
||||
#include "pgp_builder.h"
|
||||
#include "pgp_encoder.h"
|
||||
|
||||
typedef struct private_pgp_plugin_t private_pgp_plugin_t;
|
||||
|
||||
@ -40,6 +41,9 @@ static void destroy(private_pgp_plugin_t *this)
|
||||
(builder_constructor_t)pgp_public_key_builder);
|
||||
lib->creds->remove_builder(lib->creds,
|
||||
(builder_constructor_t)pgp_private_key_builder);
|
||||
|
||||
lib->encoding->remove_encoder(lib->encoding, pgp_encoder_encode);
|
||||
|
||||
free(this);
|
||||
}
|
||||
|
||||
@ -59,6 +63,8 @@ plugin_t *plugin_create()
|
||||
lib->creds->add_builder(lib->creds, CRED_PRIVATE_KEY, KEY_RSA,
|
||||
(builder_constructor_t)pgp_private_key_builder);
|
||||
|
||||
lib->encoding->add_encoder(lib->encoding, pgp_encoder_encode);
|
||||
|
||||
return &this->public.plugin;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user