Added support for different encryption schemes to private/public keys
This commit is contained in:
@@ -299,7 +299,8 @@ METHOD(private_key_t, get_type, key_type_t,
|
||||
}
|
||||
|
||||
METHOD(private_key_t, decrypt, bool,
|
||||
private_agent_private_key_t *this, chunk_t crypto, chunk_t *plain)
|
||||
private_agent_private_key_t *this, encryption_scheme_t scheme,
|
||||
chunk_t crypto, chunk_t *plain)
|
||||
{
|
||||
DBG1(DBG_LIB, "private key decryption not supported by ssh-agent");
|
||||
return FALSE;
|
||||
|
||||
@@ -226,13 +226,20 @@ METHOD(private_key_t, sign, bool,
|
||||
}
|
||||
|
||||
METHOD(private_key_t, decrypt, bool,
|
||||
private_gcrypt_rsa_private_key_t *this, chunk_t encrypted, chunk_t *plain)
|
||||
private_gcrypt_rsa_private_key_t *this, encryption_scheme_t scheme,
|
||||
chunk_t encrypted, chunk_t *plain)
|
||||
{
|
||||
gcry_error_t err;
|
||||
gcry_sexp_t in, out;
|
||||
chunk_t padded;
|
||||
u_char *pos = NULL;;
|
||||
|
||||
if (scheme != ENCRYPT_RSA_PKCS1)
|
||||
{
|
||||
DBG1(DBG_LIB, "encryption scheme %N not supported",
|
||||
encryption_scheme_names, scheme);
|
||||
return FALSE;
|
||||
}
|
||||
err = gcry_sexp_build(&in, NULL, "(enc-val(flags)(rsa(a %b)))",
|
||||
encrypted.len, encrypted.ptr);
|
||||
if (err)
|
||||
|
||||
@@ -193,11 +193,18 @@ METHOD(public_key_t, verify, bool,
|
||||
}
|
||||
|
||||
METHOD(public_key_t, encrypt_, bool,
|
||||
private_gcrypt_rsa_public_key_t *this, chunk_t plain, chunk_t *encrypted)
|
||||
private_gcrypt_rsa_public_key_t *this, encryption_scheme_t scheme,
|
||||
chunk_t plain, chunk_t *encrypted)
|
||||
{
|
||||
gcry_sexp_t in, out;
|
||||
gcry_error_t err;
|
||||
|
||||
if (scheme != ENCRYPT_RSA_PKCS1)
|
||||
{
|
||||
DBG1(DBG_LIB, "encryption scheme %N not supported",
|
||||
encryption_scheme_names, scheme);
|
||||
return FALSE;
|
||||
}
|
||||
/* "pkcs1" uses PKCS 1.5 (section 8.1) block type 2 encryption:
|
||||
* 00 | 02 | RANDOM | 00 | DATA */
|
||||
err = gcry_sexp_build(&in, NULL, "(data(flags pkcs1)(value %b))",
|
||||
|
||||
@@ -314,11 +314,18 @@ METHOD(private_key_t, sign, bool,
|
||||
}
|
||||
|
||||
METHOD(private_key_t, decrypt, bool,
|
||||
private_gmp_rsa_private_key_t *this, chunk_t crypto, chunk_t *plain)
|
||||
private_gmp_rsa_private_key_t *this, encryption_scheme_t scheme,
|
||||
chunk_t crypto, chunk_t *plain)
|
||||
{
|
||||
chunk_t em, stripped;
|
||||
bool success = FALSE;
|
||||
|
||||
if (scheme != ENCRYPT_RSA_PKCS1)
|
||||
{
|
||||
DBG1(DBG_LIB, "encryption scheme %N not supported",
|
||||
encryption_scheme_names, scheme);
|
||||
return FALSE;
|
||||
}
|
||||
/* rsa decryption using PKCS#1 RSADP */
|
||||
stripped = em = rsadp(this, crypto);
|
||||
|
||||
|
||||
@@ -309,20 +309,20 @@ METHOD(public_key_t, verify, bool,
|
||||
#define MIN_PS_PADDING 8
|
||||
|
||||
METHOD(public_key_t, encrypt_, bool,
|
||||
private_gmp_rsa_public_key_t *this, chunk_t plain, chunk_t *crypto)
|
||||
private_gmp_rsa_public_key_t *this, encryption_scheme_t scheme,
|
||||
chunk_t plain, chunk_t *crypto)
|
||||
{
|
||||
chunk_t em;
|
||||
u_char *pos;
|
||||
int padding, i;
|
||||
rng_t *rng;
|
||||
|
||||
rng = lib->crypto->create_rng(lib->crypto, RNG_WEAK);
|
||||
if (rng == NULL)
|
||||
if (scheme != ENCRYPT_RSA_PKCS1)
|
||||
{
|
||||
DBG1(DBG_LIB, "no random generator available");
|
||||
DBG1(DBG_LIB, "encryption scheme %N not supported",
|
||||
encryption_scheme_names, scheme);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* number of pseudo-random padding octets */
|
||||
padding = this->k - plain.len - 3;
|
||||
if (padding < MIN_PS_PADDING)
|
||||
@@ -331,6 +331,12 @@ METHOD(public_key_t, encrypt_, bool,
|
||||
MIN_PS_PADDING);
|
||||
return FALSE;
|
||||
}
|
||||
rng = lib->crypto->create_rng(lib->crypto, RNG_WEAK);
|
||||
if (rng == NULL)
|
||||
{
|
||||
DBG1(DBG_LIB, "no random generator available");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* padding according to PKCS#1 7.2.1 (RSAES-PKCS1-v1.5-ENCRYPT) */
|
||||
DBG2(DBG_LIB, "padding %u bytes of data to the rsa modulus size of"
|
||||
|
||||
@@ -171,7 +171,8 @@ METHOD(private_key_t, sign, bool,
|
||||
}
|
||||
|
||||
METHOD(private_key_t, decrypt, bool,
|
||||
private_openssl_ec_private_key_t *this, chunk_t crypto, chunk_t *plain)
|
||||
private_openssl_ec_private_key_t *this, encryption_scheme_t scheme,
|
||||
chunk_t crypto, chunk_t *plain)
|
||||
{
|
||||
DBG1(DBG_LIB, "EC private key decryption not implemented");
|
||||
return FALSE;
|
||||
|
||||
@@ -169,7 +169,8 @@ METHOD(public_key_t, verify, bool,
|
||||
}
|
||||
|
||||
METHOD(public_key_t, encrypt, bool,
|
||||
private_openssl_ec_public_key_t *this, chunk_t crypto, chunk_t *plain)
|
||||
private_openssl_ec_public_key_t *this, encryption_scheme_t scheme,
|
||||
chunk_t crypto, chunk_t *plain)
|
||||
{
|
||||
DBG1(DBG_LIB, "EC public key encryption not implemented");
|
||||
return FALSE;
|
||||
|
||||
@@ -166,7 +166,8 @@ METHOD(private_key_t, sign, bool,
|
||||
}
|
||||
|
||||
METHOD(private_key_t, decrypt, bool,
|
||||
private_openssl_rsa_private_key_t *this, chunk_t crypto, chunk_t *plain)
|
||||
private_openssl_rsa_private_key_t *this, encryption_scheme_t scheme,
|
||||
chunk_t crypto, chunk_t *plain)
|
||||
{
|
||||
DBG1(DBG_LIB, "RSA private key decryption not implemented");
|
||||
return FALSE;
|
||||
|
||||
@@ -148,7 +148,8 @@ METHOD(public_key_t, verify, bool,
|
||||
}
|
||||
|
||||
METHOD(public_key_t, encrypt, bool,
|
||||
private_openssl_rsa_public_key_t *this, chunk_t crypto, chunk_t *plain)
|
||||
private_openssl_rsa_public_key_t *this, encryption_scheme_t scheme,
|
||||
chunk_t crypto, chunk_t *plain)
|
||||
{
|
||||
DBG1(DBG_LIB, "RSA public key encryption not implemented");
|
||||
return FALSE;
|
||||
|
||||
@@ -129,7 +129,7 @@ static bool sign_not_allowed(private_key_t *this, signature_scheme_t scheme,
|
||||
/**
|
||||
* Implementation of private_key_t.decrypt for signature-only keys
|
||||
*/
|
||||
static bool decrypt_not_allowed(private_key_t *this,
|
||||
static bool decrypt_not_allowed(private_key_t *this, encryption_scheme_t scheme,
|
||||
chunk_t crypto, chunk_t *plain)
|
||||
{
|
||||
DBG1(DBG_LIB, "decryption failed - signature only key");
|
||||
|
||||
@@ -193,7 +193,8 @@ METHOD(private_key_t, sign, bool,
|
||||
}
|
||||
|
||||
METHOD(private_key_t, decrypt, bool,
|
||||
private_pkcs11_private_key_t *this, chunk_t crypto, chunk_t *plain)
|
||||
private_pkcs11_private_key_t *this, encryption_scheme_t scheme,
|
||||
chunk_t crypto, chunk_t *plain)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -119,7 +119,8 @@ METHOD(public_key_t, verify, bool,
|
||||
}
|
||||
|
||||
METHOD(public_key_t, encrypt, bool,
|
||||
private_pkcs11_public_key_t *this, chunk_t plain, chunk_t *crypto)
|
||||
private_pkcs11_public_key_t *this, encryption_scheme_t scheme,
|
||||
chunk_t plain, chunk_t *crypto)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user