Repository: Netflix/lemur

Issue:
Trouble with submitting a CSR to the verisign plugin
There is an issue were accepting a CSR from the UI as opposed to having Lemur generate the CSR is causing Unicode errors:

```
2016-02-19 21:19:04,405 ERROR: 45 [in /apps/lemur/lemur/common/utils.py:60]
Traceback (most recent call last):
  File "/apps/lemur/lemur/common/utils.py", line 46, in wrapper
    resp = f(*args, **kwargs)
  File "/apps/lemur/lemur/certificates/views.py", line 387, in post
    return service.create(**args)
  File "/apps/lemur/lemur/certificates/service.py", line 247, in create
    cert, private_key, cert_chain = mint(kwargs)
  File "/apps/lemur/lemur/certificates/service.py", line 151, in mint
    cert_body, cert_chain = issuer.create_certificate(csr, issuer_options)
  File "/apps/lemur/lemur/plugins/lemur_verisign/plugin.py", line 156, in create_certificate
    response = self.session.post(url, data=data)
  File "/apps/python/local/lib/python2.7/site-packages/requests/sessions.py", line 511, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/apps/python/local/lib/python2.7/site-packages/requests/sessions.py", line 454, in request
    prep = self.prepare_request(req)
  File "/apps/python/local/lib/python2.7/site-packages/requests/sessions.py", line 388, in prepare_request
    hooks=merge_hooks(request.hooks, self.hooks),
  File "/apps/python/local/lib/python2.7/site-packages/requests/models.py", line 296, in prepare
    self.prepare_body(data, files, json)
  File "/apps/python/local/lib/python2.7/site-packages/requests/models.py", line 450, in prepare_body
    body = self._encode_params(data)
  File "/apps/python/local/lib/python2.7/site-packages/requests/models.py", line 97, in _encode_params
    return urlencode(result, doseq=True)
  File "/usr/lib/python2.7/urllib.py", line 1338, in urlencode
    v = quote_plus(v)
  File "/usr/lib/python2.7/urllib.py", line 1293, in quote_plus
    s = quote(s, safe + ' ')
  File "/usr/lib/python2.7/urllib.py", line 1288, in quote
    return ''.join(map(quoter, s))
KeyError: 45
```

Most likely the CSR contains bytes that are not able to be decoded by urllib.



Discussion:

Resolving patch:
diff --git a/lemur/certificates/service.py b/lemur/certificates/service.py
--- a/lemur/certificates/service.py
+++ b/lemur/certificates/service.py
@@ -144,7 +144,7 @@ def mint(issuer_options):
     if not issuer_options.get('csr'):
         csr, private_key = create_csr(issuer_options)
     else:
-        csr = issuer_options.get('csr')
+        csr = str(issuer_options.get('csr'))
         private_key = None
 
     issuer_options['creator'] = g.user.email
diff --git a/lemur/certificates/views.py b/lemur/certificates/views.py
--- a/lemur/certificates/views.py
+++ b/lemur/certificates/views.py
@@ -232,7 +232,7 @@ def post(self):
                 "owner": "bob@example.com",
                 "description": "test",
                 "selectedAuthority": "timetest2",
-                "csr",
+                "csr": "----BEGIN CERTIFICATE REQUEST-----...",
                 "authority": {
                     "body": "-----BEGIN...",
                     "name": "timetest2",


Test patch: