Repository: Netflix/lemur

Issue:
[Web UI] Invalid Certificates basic info
Tab 'Certificates' -> choose any certificate-> Tab 'BASIC INFO'

> Not Before: Invalid date
> Not After: Invalid date
> Signing Algorithm: [Empty] ---->'Signature Algorithm'?


Discussion:
Can you view your certificate in the public certificate field? What kind of certificate are you issuing?
Hi @kevgliss , I am also facing the same issue. Basic Info for the created cert is not displayed properly. Following are the fields which are not displayed at all or getting displayed incorrectly:

1. Creator
2. Not Before --- Shows "invalid date"
3. Not After --- Shows "invalid date"
4. San  ---  A cross is displayed
5. Signing algorithm --- Nothing is displayed
6. Validity  - Unknown is diplayed
7. Chain is also not displayed


Note : I am able to see public certificate and private key field with their respective values for that cert. Attaching image with this comment. I can also see the "not_before" key's value in the response from the lemur server as "2017-03-23T12:00:00+00:00" (when checked using developer tool in chrome browser).
![1](https://cloud.githubusercontent.com/assets/24436584/24349297/31d04b38-12fc-11e7-9bbf-bd586930cf12.jpg)
![2](https://cloud.githubusercontent.com/assets/24436584/24349298/31fa5798-12fc-11e7-8465-6fb4484b6aa3.jpg)


Could you provide me the the full json response for that certificate (minus the private key)?
Hi @kevgliss , I got the creator, not before, not after and signing algorithm fields to work. I suspect the problem was with the camel casing to underscore conversion. I changed in view.tpl.html file and got these fields to show the info. Please see the attached screenshot for the same.
![2_2](https://cloud.githubusercontent.com/assets/24436584/24391548/6a9c1b0c-13ad-11e7-988a-bff3813c2261.jpg)

I am still facing issues with the chain field though. And it seems that the problem here might be related to chain not getting saved in the db(I might be wrong) as there is "null" value returned corresponding to chain field. Attaching the sample response with this comment.

[sampleResponse.txt](https://github.com/Netflix/lemur/files/874660/sampleResponse.txt)

Are you setting `CFSSL_INTERMEDIATE`? See:
http://lemur.readthedocs.io/en/latest/administration.html#cfssl-issuer-plugin
and
https://github.com/Netflix/lemur/blob/master/lemur/plugins/lemur_cfssl/plugin.py#L52 
> camel casing to underscore conversion

Could you explain this a little more, what did you change in the view.tpl.html?
> Are you setting CFSSL_INTERMEDIATE? See:
http://lemur.readthedocs.io/en/latest/administration.html#cfssl-issuer-plugin
and
https://github.com/Netflix/lemur/blob/master/lemur/plugins/lemur_cfssl/plugin.py#L52

Yes I have set that variable properly in **lemur.conf.py**. Please find the attached screenshot for the same.

![4_2](https://cloud.githubusercontent.com/assets/24436584/24448661/7c63a130-1492-11e7-9922-90264e2f74a7.jpg)

> Could you explain this a little more, what did you change in the view.tpl.html?

I have made changes in **lemur/static/dist/angular/certificates/view/view.tpl.html** file. Not sure if they are valid but it solved my issue. 
Changed following piece of line 
`<strong>Not Before</strong> <span class="pull-right" uib-tooltip="{{ certificate.notBefore }}">{{ momentService.createMoment(certificate.notBefore) }}`

to

`<strong>Not Before</strong> <span class="pull-right" uib-tooltip="{{ certificate.notBefore }}">{{ momentService.createMoment(certificate.not_before) }}`

Thats interesting... the response you sent over has a key of `notBefore` not `not_before` the javascript doesn't do much other than assign these values to an object. Are you on master or some other branch?
I am experiencing this issue as well. Let me know if there is information I can provide to help.
![image](https://cloud.githubusercontent.com/assets/704271/24568157/d78647f0-162e-11e7-8d54-4efcaf3ef8fb.png)

@RickB17 Can you confirm you are on master? Do you see the value key as `not_before` or is it `notBefore` in your JSON response?
@kevgliss Yes, I'm on master. It is being returned at ```not_before```.

![image](https://cloud.githubusercontent.com/assets/704271/24581903/8e40ca1a-16f2-11e7-9859-a346d880001a.png)

Are there other underscores as keys or just `not_after` and `not_before`? Sorry for all the questions but I have not yet been able to reproduce this locally.
@kevgliss Looks like there are a few other keys. ```validity_end```, ```validity_start```, and ```path_length```

![image](https://cloud.githubusercontent.com/assets/704271/24593086/b1b2ba5c-17ed-11e7-95ac-942601e22209.png)

![image](https://cloud.githubusercontent.com/assets/704271/24593077/91d805ac-17ed-11e7-9c32-829f2dcc716e.png)

@kevgliss  attached are the outputs from ```pip freeze``` from both environments (working and non-working). Lots of version differences between the environment that works and the one that doesn't.

**Working Environment**
![image](https://cloud.githubusercontent.com/assets/704271/24829176/11d07acc-1c3b-11e7-9199-2d9ad0258ab2.png)
[works.txt](https://github.com/Netflix/lemur/files/907468/works.txt)

**Non-Working Environment**
![image](https://cloud.githubusercontent.com/assets/704271/24829177/20071998-1c3b-11e7-979a-b58c9c7976a9.png)
[no-works.txt](https://github.com/Netflix/lemur/files/907469/no-works.txt)

I mirrored your non-working environment and was unable to reproduce. Could you issue a `git pull` or a `git log` on your non-working environment to rule out any code changes.
```pip freeze``` for this specific instance (it's different than the original non-working one I posted, but is the same one that I shared the json responses from earlier:

[pip_freeze.txt](https://github.com/Netflix/lemur/files/907773/pip_freeze.txt)

```git log``` output
[git_log.txt](https://github.com/Netflix/lemur/files/907770/git_log.txt)

I get this same issue where the output of the api shows as snake case rather than camel case as well. Trying to investigate it at the moment. I get this on both the master branch and the 0.5.0 release. The strange thing is that it seemed to be working for a while where it was showing camel case then it changed back to snake case. It seems like a bit of a strange one.

Edit:

I'm able to reproduce this using a fresh clone of: https://github.com/Netflix/lemur-docker
So it's as @RickB17 suggested, it's related to the version, when changing from `marshmallow v2.13.4` to `marshmallow 2.4.0` we see the api response camelized. Something seems to have changed in between versions that's caused it to no longer parse things correctly. I would recommend changing back to version `2.4.0` until we find out what's wrong so that email notifications and views work correctly. This bug seems to effect mail templates as well.

Also worth mentioning I tried to upgrade to the latest version but it also has this problem.

Here is the PR if you agree: https://github.com/Netflix/lemur/pull/761
I've been able to confirm this issue via the docker image via the 0.5 tags as well as on master. I think the workaround is okay for now but I'd like to try and determine the root cause. I'm still not able to replicate it anywhere other than that docker image; locally, production, etc. all seem to work fine for me with 2.13.4. 

Unfortunately, my docker foo isn't quite up to par and it is quite annoying to troubleshoot this from within the docker container itself. What I have found so far is that when we see issues, we don't see any certificate data enter here:

https://github.com/Netflix/lemur/blob/master/lemur/common/schema.py#L90

We can, however, see other pieces of data correctly receive the serialization (notifications, roles, etc.,). This would lead me to believe that there is some interaction going on between marshmallow and the certificate schema (https://github.com/Netflix/lemur/blob/master/lemur/common/schema.py#L90) that I don't quite understand yet. 
So I've narrowed it down to be an issues that occurred between version `2.10.0` -> `2.10.1` the change log mentions the following changes:
```
- Fix behavior when using validate.Equal(False) (#484). Thanks @pktangyue for reporting and thanks @tuukkamustonen for the fix.
- Fix strict behavior when errors are raised in pre_dump/post_dump processors (#521). Thanks @tvuotila for the catch and patch.
- Fix validation of nested fields on dumping (#528). Thanks again @tvuotila.
```

Will keep looking into it.
🎉 🎉 🎉  Found it 🎉 🎉 🎉 

So between version `2.10.0` and `2.10.1` it seems that when an error is raised with the schema it will no longer run the `post_dump` function. There is an error raised because the default lemur email address is not a valid email address as it is `lemur@nobody` if it was`lemur@nobody.com` this would not be an issue. So to fix it in your environment you need to set your lemur user to have a valid email address otherwise all hell breaks loose 😈 .

Note: This is only an issue if you've used the lemur user to create things

@kevgliss would you be able to change the defaults?
@RickB17 you should now be able to fix it for yourself by just updating your lemur user to have a valid email.
Well this was timely.. thanks @treacher, modifying Lemur user to have an email address via web UI worked for me. 👍 
Ah, that explains why I can't recreate it! Good find.

Resolving patch:
diff --git a/lemur/manage.py b/lemur/manage.py
--- a/lemur/manage.py
+++ b/lemur/manage.py
@@ -222,7 +222,7 @@ def run(self, password):
                     sys.stderr.write("[!] Passwords do not match!\n")
                     sys.exit(1)
 
-            user_service.create("lemur", password, 'lemur@nobody', True, None, [admin_role])
+            user_service.create("lemur", password, 'lemur@nobody.com', True, None, [admin_role])
             sys.stdout.write("[+] Created the user 'lemur' and granted it the 'admin' role!\n")
 
         else:


Test patch: