]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
certtool is able to set certificate policies via a template
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Mon, 19 Nov 2012 23:12:14 +0000 (00:12 +0100)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Mon, 19 Nov 2012 23:19:32 +0000 (00:19 +0100)
NEWS
doc/invoke-certtool.texi
src/certtool-args.c
src/certtool-args.def
src/certtool-args.h
src/certtool-cfg.c
src/certtool-cfg.h
src/certtool.c

diff --git a/NEWS b/NEWS
index b415b13c7dcdcf309f78142e9edd1521683b1031..289b9553dbb2eb2f83c108585666321638c4561d 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -19,6 +19,8 @@ affected combined levels. Patch by Tim Kosse.
 --load-privkey in order to print the corresponding public key of a private 
 key.
 
+** certtool: It is able to set certificate policies via a template.
+
 ** p11tool: After key generation, outputs the public key (useful in
 tokens that do not store the public key).
 
index 329c26dca1fe13de163a9f0d76494ba58edf67f2..ed521186a8e17737bb449f45b5e20d138a781038 100644 (file)
@@ -6,7 +6,7 @@
 # 
 # DO NOT EDIT THIS FILE   (invoke-certtool.texi)
 # 
-# It has been AutoGen-ed  November 11, 2012 at 08:40:03 PM by AutoGen 5.16
+# It has been AutoGen-ed  November 20, 2012 at 12:17:13 AM by AutoGen 5.16
 # From the definitions    ../src/certtool-args.def
 # and the template file   agtexi-cmd.tpl
 @end ignore
@@ -543,9 +543,20 @@ signing_key
 # CA issuers URI
 # ca_issuers_uri = http://my.ca.issuer
 
+# Certificate policies
+# policy = 1.3.6.1.4.1.5484.1.10.99.1.0
+# policy1_txt = "This is a long policy to summarize"
+# policy1_url = http://www.example.com/a-policy-to-read
+
+# policy = 1.3.6.1.4.1.5484.1.10.99.1.1
+# policy2_txt = "This is a short policy"
+# policy2_url = http://www.example.com/another-policy-to-read
+
+
 # Options for proxy certificates
 # proxy_policy_language = 1.3.6.1.5.5.7.21.1
 
+
 # Options for generating a CRL
 
 # next CRL update will be in 43 days (wow)
index 26d78f91786f65344237483edcaedaa1b4ce1ffe..33f7ad071f87f541fe85688d014fdc4adb81e7ba 100644 (file)
@@ -2,7 +2,7 @@
  *  
  *  DO NOT EDIT THIS FILE   (certtool-args.c)
  *  
- *  It has been AutoGen-ed  November 11, 2012 at 08:37:40 PM by AutoGen 5.16
+ *  It has been AutoGen-ed  November 20, 2012 at 12:12:56 AM by AutoGen 5.16
  *  From the definitions    certtool-args.def
  *  and the template file   options
  *
index 480c16eb6ce8e5e501ba22e384eda96465f11c0d..34c2d42d8df3fd4150d05db64b11721cf1029789 100644 (file)
@@ -633,9 +633,20 @@ signing_key
 # CA issuers URI
 # ca_issuers_uri = http://my.ca.issuer
 
+# Certificate policies
+# policy = 1.3.6.1.4.1.5484.1.10.99.1.0
+# policy1_txt = "This is a long policy to summarize"
+# policy1_url = http://www.example.com/a-policy-to-read
+
+# policy = 1.3.6.1.4.1.5484.1.10.99.1.1
+# policy2_txt = "This is a short policy"
+# policy2_url = http://www.example.com/another-policy-to-read
+
+
 # Options for proxy certificates
 # proxy_policy_language = 1.3.6.1.5.5.7.21.1
 
+
 # Options for generating a CRL
 
 # next CRL update will be in 43 days (wow)
index 6c0b9449c20830ae49db3b26007bb095f007ac2b..46af66d63f38f358bff7e3f4da051246c605aa7a 100644 (file)
@@ -2,7 +2,7 @@
  *  
  *  DO NOT EDIT THIS FILE   (certtool-args.h)
  *  
- *  It has been AutoGen-ed  November 11, 2012 at 08:37:40 PM by AutoGen 5.16
+ *  It has been AutoGen-ed  November 20, 2012 at 12:12:55 AM by AutoGen 5.16
  *  From the definitions    certtool-args.def
  *  and the template file   options
  *
index 768c58d7c83923ee89a011183264565c4f8099d8..c2cf1c1234a0063d90b90da629f386175aa60705 100644 (file)
@@ -61,6 +61,9 @@ typedef struct _cfg_ctx
   char *challenge_password;
   char *pkcs9_email;
   char *country;
+  char **policy_oid;
+  char *policy_txt[MAX_ENTRIES];
+  char *policy_url[MAX_ENTRIES];
   char **dc;
   char **dns_name;
   char **uri;
@@ -182,6 +185,7 @@ template_parse (const char *template)
   unsigned int i;
   tOptionValue const * pov;
   const tOptionValue* val;
+  char tmpstr[256];
 
   pov = configFileLoad(template);
   if (pov == NULL)
@@ -232,6 +236,29 @@ template_parse (const char *template)
   if (val != NULL && val->valType == OPARG_TYPE_STRING)
     cfg.country = strdup(val->v.strVal);
   
+  READ_MULTI_LINE("policy", cfg.policy_oid);
+  
+  if (cfg.policy_oid != NULL) 
+    {
+      int i = 0;
+      while(cfg.policy_oid[i] != NULL) 
+        {
+          snprintf(tmpstr, sizeof(tmpstr), "policy%d_url", i+1);
+          val = optionGetValue(pov, tmpstr);
+          if (val != NULL && val->valType == OPARG_TYPE_STRING)
+            cfg.policy_url[i] = strdup(val->v.strVal);
+
+          snprintf(tmpstr, sizeof(tmpstr), "policy%d_txt", i+1);
+          val = optionGetValue(pov, tmpstr);
+          if (val != NULL && val->valType == OPARG_TYPE_STRING)
+            {
+              cfg.policy_txt[i] = strdup(val->v.strVal);
+            }
+          
+          i++;
+        }
+    }
+  
   READ_MULTI_LINE("dc", cfg.dc);
   READ_MULTI_LINE("dns_name", cfg.dns_name);
   READ_MULTI_LINE("uri", cfg.uri);
@@ -1211,6 +1238,54 @@ get_dns_name_set (int type, void *crt)
     }
 }
 
+void
+get_policy_set (gnutls_x509_crt_t crt)
+{
+  int ret = 0, i;
+  gnutls_x509_policy_st policy;
+
+  if (batch)
+    {
+      if (!cfg.policy_oid)
+        return;
+
+      for (i = 0; cfg.policy_oid[i] != NULL; i++)
+        {
+          memset(&policy, 0, sizeof(policy));
+          policy.oid = cfg.policy_oid[i];
+          
+          if (cfg.policy_txt[i] != NULL)
+            {
+              policy.qualifier[policy.qualifiers].type = GNUTLS_X509_QUALIFIER_NOTICE;
+              policy.qualifier[policy.qualifiers].data = cfg.policy_txt[i];
+              policy.qualifier[policy.qualifiers].size = strlen(cfg.policy_txt[i]);
+              policy.qualifiers++;
+            }
+
+          if (cfg.policy_url[i] != NULL)
+            {
+              policy.qualifier[policy.qualifiers].type = GNUTLS_X509_QUALIFIER_URI;
+              policy.qualifier[policy.qualifiers].data = cfg.policy_url[i];
+              policy.qualifier[policy.qualifiers].size = strlen(cfg.policy_url[i]);
+              policy.qualifiers++;
+            }
+
+fprintf(stderr, "setting policy %s with %d qualifiers\n", policy.oid, policy.qualifiers);
+          
+          ret =
+            gnutls_x509_crt_set_policy (crt, &policy, 0);
+          if (ret < 0)
+            break;
+        }
+    }
+
+  if (ret < 0)
+    {
+      fprintf (stderr, "set_policy: %s\n", gnutls_strerror (ret));
+      exit (1);
+    }
+}
+
 void
 get_uri_set (int type, void *crt)
 {
index 878ecac34f73be2ee7d0740a39528f275f2868d2..bcb96d742896205d413732e1e8733b50c7664845 100644 (file)
@@ -67,6 +67,7 @@ int get_encrypt_status (int server);
 int get_sign_status (int server);
 void get_ip_addr_set (int type, void *crt);
 void get_dns_name_set (int type, void *crt);
+void get_policy_set (gnutls_x509_crt_t);
 void get_uri_set (int type, void *crt);
 void get_email_set (int type, void *crt);
 int get_ipsec_ike_status (void);
index 2f2eca72634de26b725c98a77694cdf32155f4a5..dd34e3ac29fd90f7d84fee2b043ef4a35bfb05b4 100644 (file)
@@ -399,6 +399,7 @@ generate_certificate (gnutls_privkey_t * ret_key,
       get_dns_name_set (TYPE_CRT, crt);
       get_uri_set (TYPE_CRT, crt);
       get_ip_addr_set (TYPE_CRT, crt);
+      get_policy_set (crt);
 
       if (server != 0)
         {