| 
									
										
										
										
											2016-08-11 09:43:11 -06:00
										 |  |  | cert-info.js | 
					
						
							|  |  |  | ============ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-11 09:15:10 -06:00
										 |  |  | Read basic info from a cert.pem / x509 certificate. | 
					
						
							| 
									
										
										
										
											2016-08-11 09:43:11 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 19:47:37 -06:00
										 |  |  | Used for [Greenlock.js](https://git.coolaj86.com/coolaj86/greenlock-express.js) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-11 09:43:11 -06:00
										 |  |  | Install | 
					
						
							|  |  |  | ======= | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ```bash | 
					
						
							|  |  |  | # bin
 | 
					
						
							|  |  |  | npm install --global certpem | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # node.js library
 | 
					
						
							|  |  |  | npm install --save certpem | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Usage | 
					
						
							|  |  |  | ===== | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-11 10:06:11 -06:00
										 |  |  | CLI | 
					
						
							|  |  |  | --- | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-11 09:43:11 -06:00
										 |  |  | For basic info (subject, altnames, issuedAt, expiresAt): | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ```bash | 
					
						
							|  |  |  | certpem /path/to/cert.pem | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Output all info by passing `--debug` or use `--json` to see the basic info pretty-printed. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-11 10:06:11 -06:00
										 |  |  | node.js | 
					
						
							|  |  |  | ------- | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-11 09:43:11 -06:00
										 |  |  | ```javascript | 
					
						
							|  |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var certpem = require('certpem').certpem | 
					
						
							|  |  |  | var cert = fs.readFile('cert.pem', 'ascii', function (err, certstr) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-11 10:01:24 -06:00
										 |  |  |   // basic info | 
					
						
							| 
									
										
										
										
											2016-08-11 10:06:55 -06:00
										 |  |  |   console.info(certpem.info(certstr)); | 
					
						
							| 
									
										
										
										
											2016-08-11 10:01:24 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // way too much info | 
					
						
							| 
									
										
										
										
											2018-08-16 19:47:37 -06:00
										 |  |  |   // (requires npm install --save node.extend@1) | 
					
						
							| 
									
										
										
										
											2016-08-11 10:06:55 -06:00
										 |  |  |   console.info(certpem.debug(certstr)); | 
					
						
							| 
									
										
										
										
											2016-08-11 10:01:24 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-11 09:43:11 -06:00
										 |  |  | }); | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-11 10:06:55 -06:00
										 |  |  | Example output: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-11 09:43:11 -06:00
										 |  |  | ```javascript | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   "subject": "localhost.daplie.com", | 
					
						
							|  |  |  |   "altnames": [ | 
					
						
							|  |  |  |     "localhost.daplie.com" | 
					
						
							|  |  |  |   ], | 
					
						
							|  |  |  |   "issuedAt": 1465516800000, | 
					
						
							|  |  |  |   "expiresAt": 1499731199000 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | ``` | 
					
						
							| 
									
										
										
										
											2016-08-11 10:06:11 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | With a few small changes this could also work in the browser (that's how its dependencies are designed). |