about summary refs log tree commit diff
path: root/libnm-core/crypto.c
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2018-09-23 10:11:11 +0200
committerMichael Biebl <biebl@debian.org>2018-09-23 10:11:11 +0200
commit135c3be0fb0eedb7a1b493ffde6c1ab3d23771f6 (patch)
tree40408d2ad887437e3ca63ff7fc6334bf22ae3fe6 /libnm-core/crypto.c
parent81e5928f26b40b0227604ccaf4b051fe14c9b3ef (diff)
parente126f3e804c35480c4f075777430419d6ece23da (diff)
Update upstream source from tag 'upstream/1.12.4'
Update to upstream version '1.12.4'
with Debian dir 650b52e60bf462f2972d0c33deec2cb171953445
Diffstat (limited to 'libnm-core/crypto.c')
-rw-r--r--libnm-core/crypto.c30
1 files changed, 20 insertions, 10 deletions
diff --git a/libnm-core/crypto.c b/libnm-core/crypto.c
index c4e48475..319f8055 100644
--- a/libnm-core/crypto.c
+++ b/libnm-core/crypto.c
@@ -158,7 +158,13 @@ parse_old_openssl_key_file (const guint8 *data,
 				goto parse_error;
 			}
 		} else if (!strncmp (p, DEK_INFO_TAG, strlen (DEK_INFO_TAG))) {
+			static const char *const known_ciphers[] = { CIPHER_DES_EDE3_CBC,
+			                                             CIPHER_DES_CBC,
+			                                             CIPHER_AES_128_CBC,
+			                                             CIPHER_AES_192_CBC,
+			                                             CIPHER_AES_256_CBC };
 			char *comma;
+			guint i;
 
 			if (enc_tags++ != 1 || str->len != 0) {
 				g_set_error (error, NM_CRYPTO_ERROR,
@@ -187,13 +193,13 @@ parse_old_openssl_key_file (const guint8 *data,
 			iv = g_strdup (comma);
 
 			/* Get the private key cipher */
-			if (!strcasecmp (p, "DES-EDE3-CBC")) {
-				cipher = g_strdup (p);
-			} else if (!strcasecmp (p, "DES-CBC")) {
-				cipher = g_strdup (p);
-			} else if (!strcasecmp (p, "AES-128-CBC")) {
-				cipher = g_strdup (p);
-			} else {
+			for (i = 0; i < G_N_ELEMENTS (known_ciphers); i++) {
+				if (!g_ascii_strcasecmp (p, known_ciphers[i])) {
+					cipher = g_strdup (known_ciphers[i]);
+					break;
+				}
+			}
+			if (i == G_N_ELEMENTS (known_ciphers)) {
 				g_set_error (error, NM_CRYPTO_ERROR,
 				             NM_CRYPTO_ERROR_INVALID_DATA,
 				             _("Malformed PEM file: unknown private key cipher '%s'."),
@@ -383,12 +389,16 @@ crypto_make_des_aes_key (const char *cipher,
 	g_return_val_if_fail (password != NULL, NULL);
 	g_return_val_if_fail (out_len != NULL, NULL);
 
-	if (!strcmp (cipher, "DES-EDE3-CBC"))
+	if (!strcmp (cipher, CIPHER_DES_EDE3_CBC))
 		digest_len = 24;
-	else if (!strcmp (cipher, "DES-CBC"))
+	else if (!strcmp (cipher, CIPHER_DES_CBC))
 		digest_len = 8;
-	else if (!strcmp (cipher, "AES-128-CBC"))
+	else if (!strcmp (cipher, CIPHER_AES_128_CBC))
 		digest_len = 16;
+	else if (!strcmp (cipher, CIPHER_AES_192_CBC))
+		digest_len = 24;
+	else if (!strcmp (cipher, CIPHER_AES_256_CBC))
+		digest_len = 32;
 	else {
 		g_set_error (error, NM_CRYPTO_ERROR,
 		             NM_CRYPTO_ERROR_UNKNOWN_CIPHER,