Obseleted BUILD_PASSPHRASE(_CALLBACK) for private key loading, use credential sets
This commit is contained in:
@@ -50,6 +50,11 @@ struct private_nm_creds_t {
|
||||
*/
|
||||
char *pass;
|
||||
|
||||
/**
|
||||
* Private key decryption password
|
||||
*/
|
||||
char *keypass;
|
||||
|
||||
/**
|
||||
* users certificate
|
||||
*/
|
||||
@@ -239,8 +244,14 @@ static bool shared_enumerate(shared_enumerator_t *this, shared_key_t **key,
|
||||
return FALSE;
|
||||
}
|
||||
*key = this->key;
|
||||
*me = ID_MATCH_PERFECT;
|
||||
*other = ID_MATCH_ANY;
|
||||
if (me)
|
||||
{
|
||||
*me = ID_MATCH_PERFECT;
|
||||
}
|
||||
if (other)
|
||||
{
|
||||
*other = ID_MATCH_ANY;
|
||||
}
|
||||
this->done = TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
@@ -262,18 +273,31 @@ static enumerator_t* create_shared_enumerator(private_nm_creds_t *this,
|
||||
identification_t *other)
|
||||
{
|
||||
shared_enumerator_t *enumerator;
|
||||
chunk_t key;
|
||||
|
||||
if (!this->pass || !this->user)
|
||||
switch (type)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
if (type != SHARED_EAP && type != SHARED_IKE)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
if (me && !me->equals(me, this->user))
|
||||
{
|
||||
return NULL;
|
||||
case SHARED_EAP:
|
||||
case SHARED_IKE:
|
||||
if (!this->pass || !this->user)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
if (me && !me->equals(me, this->user))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
key = chunk_create(this->pass, strlen(this->pass));
|
||||
break;
|
||||
case SHARED_PRIVATE_KEY_PASS:
|
||||
if (!this->keypass)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
key = chunk_create(this->keypass, strlen(this->keypass));
|
||||
break;
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
enumerator = malloc_thing(shared_enumerator_t);
|
||||
@@ -282,9 +306,7 @@ static enumerator_t* create_shared_enumerator(private_nm_creds_t *this,
|
||||
enumerator->this = this;
|
||||
enumerator->done = FALSE;
|
||||
this->lock->read_lock(this->lock);
|
||||
enumerator->key = shared_key_create(type,
|
||||
chunk_clone(chunk_create(this->pass,
|
||||
strlen(this->pass))));
|
||||
enumerator->key = shared_key_create(type, chunk_clone(key));
|
||||
return &enumerator->public;
|
||||
}
|
||||
|
||||
@@ -369,6 +391,17 @@ static void set_username_password(private_nm_creds_t *this, identification_t *id
|
||||
this->lock->unlock(this->lock);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of nm_creds_t.set_key_password
|
||||
*/
|
||||
static void set_key_password(private_nm_creds_t *this, char *password)
|
||||
{
|
||||
this->lock->write_lock(this->lock);
|
||||
free(this->keypass);
|
||||
this->keypass = password ? strdup(password) : NULL;
|
||||
this->lock->unlock(this->lock);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of nm_creds_t.set_cert_and_key
|
||||
*/
|
||||
@@ -430,6 +463,7 @@ nm_creds_t *nm_creds_create()
|
||||
this->public.add_certificate = (void(*)(nm_creds_t*, certificate_t *cert))add_certificate;
|
||||
this->public.load_ca_dir = (void(*)(nm_creds_t*, char *dir))load_ca_dir;
|
||||
this->public.set_username_password = (void(*)(nm_creds_t*, identification_t *id, char *password))set_username_password;
|
||||
this->public.set_key_password = (void(*)(nm_creds_t*, char *password))set_key_password;
|
||||
this->public.set_cert_and_key = (void(*)(nm_creds_t*, certificate_t *cert, private_key_t *key))set_cert_and_key;
|
||||
this->public.clear = (void(*)(nm_creds_t*))clear;
|
||||
this->public.destroy = (void(*)(nm_creds_t*))destroy;
|
||||
|
||||
@@ -58,6 +58,14 @@ struct nm_creds_t {
|
||||
*/
|
||||
void (*set_username_password)(nm_creds_t *this, identification_t *id,
|
||||
char *password);
|
||||
|
||||
/**
|
||||
* Set the passphrase to use for private key decryption.
|
||||
*
|
||||
* @param password password to use
|
||||
*/
|
||||
void (*set_key_password)(nm_creds_t *this, char *password);
|
||||
|
||||
/**
|
||||
* Set the certificate and private key to use for client authentication.
|
||||
*
|
||||
@@ -66,6 +74,7 @@ struct nm_creds_t {
|
||||
*/
|
||||
void (*set_cert_and_key)(nm_creds_t *this, certificate_t *cert,
|
||||
private_key_t *key);
|
||||
|
||||
/**
|
||||
* Clear the stored credentials.
|
||||
*/
|
||||
|
||||
@@ -380,16 +380,15 @@ static gboolean connect_(NMVPNPlugin *plugin, NMConnection *connection,
|
||||
str = nm_setting_vpn_get_data_item(vpn, "userkey");
|
||||
if (!agent && str)
|
||||
{
|
||||
chunk_t secret;
|
||||
char *secret;
|
||||
|
||||
secret.ptr = (char*)nm_setting_vpn_get_secret(vpn, "password");
|
||||
if (secret.ptr)
|
||||
secret = (char*)nm_setting_vpn_get_secret(vpn, "password");
|
||||
if (secret)
|
||||
{
|
||||
secret.len = strlen(secret.ptr);
|
||||
priv->creds->set_key_password(priv->creds, secret);
|
||||
}
|
||||
private = lib->creds->create(lib->creds, CRED_PRIVATE_KEY,
|
||||
KEY_RSA, BUILD_FROM_FILE, str,
|
||||
BUILD_PASSPHRASE, secret, BUILD_END);
|
||||
KEY_RSA, BUILD_FROM_FILE, str, BUILD_END);
|
||||
if (!private)
|
||||
{
|
||||
g_set_error(err, NM_VPN_PLUGIN_ERROR,
|
||||
@@ -524,17 +523,10 @@ static gboolean need_secrets(NMVPNPlugin *plugin, NMConnection *connection,
|
||||
if (path)
|
||||
{
|
||||
private_key_t *key;
|
||||
chunk_t secret;
|
||||
|
||||
secret.ptr = (char*)nm_setting_vpn_get_secret(settings, "password");
|
||||
if (secret.ptr)
|
||||
{
|
||||
secret.len = strlen(secret.ptr);
|
||||
}
|
||||
/* try to load/decrypt the private key */
|
||||
key = lib->creds->create(lib->creds, CRED_PRIVATE_KEY,
|
||||
KEY_RSA, BUILD_FROM_FILE, path,
|
||||
BUILD_PASSPHRASE, secret, BUILD_END);
|
||||
KEY_RSA, BUILD_FROM_FILE, path, BUILD_END);
|
||||
if (key)
|
||||
{
|
||||
key->destroy(key);
|
||||
|
||||
Reference in New Issue
Block a user