integrity: provide a function to load x509 certificate from the kernel
authorDmitry Kasatkin <d.kasatkin@samsung.com>
Wed, 5 Nov 2014 15:01:13 +0000 (17:01 +0200)
committerMimi Zohar <zohar@linux.vnet.ibm.com>
Tue, 18 Nov 2014 04:11:59 +0000 (23:11 -0500)
Provide the function to load x509 certificates from the kernel into the
integrity kernel keyring.

Changes in v2:
* configuration option removed
* function declared as '__init'

Signed-off-by: Dmitry Kasatkin <d.kasatkin@samsung.com>
Signed-off-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
security/integrity/digsig.c
security/integrity/integrity.h

index 4f643d1b34dd78ba49c7cedc455f0e61a7d29908..5e3bd72b299ae5822490addbc3b4572fc5f0d739 100644 (file)
@@ -14,7 +14,7 @@
 
 #include <linux/err.h>
 #include <linux/sched.h>
-#include <linux/rbtree.h>
+#include <linux/slab.h>
 #include <linux/cred.h>
 #include <linux/key-type.h>
 #include <linux/digsig.h>
@@ -84,3 +84,37 @@ int __init integrity_init_keyring(const unsigned int id)
        }
        return err;
 }
+
+int __init integrity_load_x509(const unsigned int id, char *path)
+{
+       key_ref_t key;
+       char *data;
+       int rc;
+
+       if (!keyring[id])
+               return -EINVAL;
+
+       rc = integrity_read_file(path, &data);
+       if (rc < 0)
+               return rc;
+
+       key = key_create_or_update(make_key_ref(keyring[id], 1),
+                                  "asymmetric",
+                                  NULL,
+                                  data,
+                                  rc,
+                                  ((KEY_POS_ALL & ~KEY_POS_SETATTR) |
+                                   KEY_USR_VIEW | KEY_USR_READ),
+                                  KEY_ALLOC_NOT_IN_QUOTA | KEY_ALLOC_TRUSTED);
+       if (IS_ERR(key)) {
+               rc = PTR_ERR(key);
+               pr_err("Problem loading X.509 certificate (%d): %s\n",
+                      rc, path);
+       } else {
+               pr_notice("Loaded X.509 cert '%s': %s\n",
+                         key_ref_to_ptr(key)->description, path);
+               key_ref_put(key);
+       }
+       kfree(data);
+       return 0;
+}
index 20d220481025a4e8e229891222331c9cf88a077b..1057abbd31cdeb4de93e76ce810963a8b2001b77 100644 (file)
@@ -134,6 +134,7 @@ int integrity_digsig_verify(const unsigned int id, const char *sig, int siglen,
                            const char *digest, int digestlen);
 
 int __init integrity_init_keyring(const unsigned int id);
+int __init integrity_load_x509(const unsigned int id, char *path);
 #else
 
 static inline int integrity_digsig_verify(const unsigned int id,
@@ -147,6 +148,7 @@ static inline int integrity_init_keyring(const unsigned int id)
 {
        return 0;
 }
+
 #endif /* CONFIG_INTEGRITY_SIGNATURE */
 
 #ifdef CONFIG_INTEGRITY_ASYMMETRIC_KEYS