Skip to content

Commit e4a3583

Browse files
author
Josef Fröhle c5252118
committed
Add support for DC Certificates fix #83
1 parent 34f3fe6 commit e4a3583

File tree

5 files changed

+35
-20
lines changed

5 files changed

+35
-20
lines changed

LICENSE

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Copyright (c) 2012 Andris Reinman
2+
Copyright (c) 2016 Josef Fröhle
23

34
Permission is hereby granted, free of charge, to any person obtaining a copy
45
of this software and associated documentation files (the "Software"), to deal

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pem
33

44
Create private keys and certificates with node.js
55

6-
[![Build Status](https://secure.travis-ci.org/andris9/pem.png)](http://travis-ci.org/andris9/pem)
6+
[![Build Status](https://secure.travis-ci.org/Dexus/pem.png)](http://travis-ci.org/Dexus/pem)
77
[![npm version](https://badge.fury.io/js/pem.svg)](http://badge.fury.io/js/pem)
88

99
## Installation
@@ -234,6 +234,10 @@ pem.config({
234234
// do something with the pem module
235235
```
236236

237+
### Specialthanks to
238+
239+
- Andris Reinman (@andris9) - Initiator of pem
240+
237241
## License
238242

239243
**MIT**

lib/pem.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,9 @@ function fetchCertificateData(certData, callback) {
770770
//email
771771
tmp = extra.match(/emailAddress=([^\n\/].*?)[\n\/]/);
772772
certValues.emailAddress = tmp && tmp[1] || '';
773+
// DC name
774+
tmp = subject2.match(/\sDC=([^\n].*?)[\n]/);
775+
certValues.dc = tmp && tmp[1] || '';
773776
}
774777

775778
if ((issuer = certData.match(/Issuer:([^\n]*)\n/)) && issuer.length > 1) {
@@ -793,6 +796,9 @@ function fetchCertificateData(certData, callback) {
793796
// common name
794797
tmp = issuer2.match(/\sCN=([^\n].*?)[\n]/);
795798
certValues.issuer.commonName = tmp && tmp[1] || '';
799+
// DC
800+
tmp = issuer2.match(/\sDC=([^\n].*?)[\n]/);
801+
certValues.issuer.dc = tmp && tmp[1] || '';
796802
}
797803

798804
if ((san = certData.match(/X509v3 Subject Alternative Name: \n([^\n]*)\n/)) && san.length > 1) {
@@ -823,8 +829,8 @@ function fetchCertificateData(certData, callback) {
823829

824830
function linebrakes(content) {
825831
var helper_x, subject, type;
826-
helper_x = content.replace(/(C|L|O|OU|ST|CN)=/g, '\n$1=');
827-
helper_x = preg_match_all('((C|L|O|OU|ST|CN)=[^\n].*)', helper_x);
832+
helper_x = content.replace(/(C|L|O|OU|ST|CN|DC)=/g, '\n$1=');
833+
helper_x = preg_match_all('((C|L|O|OU|ST|CN|DC)=[^\n].*)', helper_x);
828834
for (var p=0; p<helper_x.length; p++) {
829835
subject = helper_x[p].trim();
830836
type = subject.split('=');
@@ -872,6 +878,7 @@ function generateCSRSubject(options) {
872878
O: options.organization || options.O,
873879
OU: options.organizationUnit || options.OU,
874880
CN: options.commonName || options.CN || 'localhost',
881+
DC: options.dc || options.DC || '',
875882
emailAddress: options.emailAddress
876883
};
877884

package.json

+6-10
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
],
1010
"name": "pem",
1111
"description": "Create private keys and certificates with node.js and io.js",
12-
"version": "1.9.1",
12+
"version": "1.9.3",
1313
"repository": {
1414
"type": "git",
1515
"url": "https://github.com/Dexus/pem.git"
@@ -24,11 +24,11 @@
2424
"which": "^1.2.4"
2525
},
2626
"devDependencies": {
27-
"grunt": "^0.4.5",
28-
"grunt-contrib-jshint": "^0.11.3",
29-
"grunt-contrib-nodeunit": "^0.4.1",
30-
"nodeunit": "^0.9.1",
31-
"semantic-release": "^6.3.2",
27+
"grunt": "^1.0.1",
28+
"grunt-contrib-jshint": "^1.1.0",
29+
"grunt-contrib-nodeunit": "^1.0.0",
30+
"nodeunit": "^0.10.2",
31+
"semantic-release": "^6.3.4",
3232
"semantic-release-tamia": "^1.0.0"
3333
},
3434
"optionalDependencies": {},
@@ -37,9 +37,5 @@
3737
"iojs": "*"
3838
},
3939
"release": {
40-
"analyzeCommits": "semantic-release-tamia/analyzeCommits",
41-
"generateNotes": "semantic-release-tamia/generateNotes",
42-
"verifyRelease": "semantic-release-tamia/verifyRelease",
43-
"verifyConditions": "./"
4440
}
4541
}

test/pem.js

+14-7
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ exports['General Tests'] = {
101101
organization: 'Node.ee',
102102
organizationUnit: 'test',
103103
commonName: 'www.node.ee',
104-
emailAddress: '[email protected]'
104+
emailAddress: '[email protected]',
105+
dc: ''
105106
};
106107

107108
pem.createCSR({ csrConfigFile: './test/fixtures/test.cnf' }, function(error, data) {
@@ -223,7 +224,8 @@ exports['General Tests'] = {
223224
organization: '',
224225
organizationUnit: '',
225226
commonName: 'localhost',
226-
emailAddress: ''
227+
emailAddress: '',
228+
dc: ''
227229
});
228230
test.ok(fs.readdirSync('./tmp').length === 0);
229231
test.done();
@@ -240,7 +242,8 @@ exports['General Tests'] = {
240242
organization: 'Node.ee',
241243
organizationUnit: 'test',
242244
commonName: 'www.node.ee',
243-
emailAddress: '[email protected]'
245+
emailAddress: '[email protected]',
246+
dc: ''
244247
};
245248
pem.createCSR(Object.create(certInfo), function(error, data) {
246249
var csr = (data && data.csr || '').toString();
@@ -279,15 +282,17 @@ exports['General Tests'] = {
279282
locality: '',
280283
organization: '',
281284
organizationUnit: '',
282-
commonName: 'localhost'
285+
commonName: 'localhost',
286+
dc: ''
283287
},
284288
country: '',
285289
state: '',
286290
locality: '',
287291
organization: '',
288292
organizationUnit: '',
289293
commonName: 'localhost',
290-
emailAddress: ''
294+
emailAddress: '',
295+
dc: ''
291296
});
292297
test.ok(fs.readdirSync('./tmp').length === 0);
293298
test.done();
@@ -303,15 +308,17 @@ exports['General Tests'] = {
303308
locality: 'Tallinn',
304309
organization: 'Node.ee',
305310
organizationUnit: 'test',
306-
commonName: 'www.node.ee'
311+
commonName: 'www.node.ee',
312+
dc: ''
307313
},
308314
country: 'EE',
309315
state: 'Harjumaa',
310316
locality: 'Tallinn',
311317
organization: 'Node.ee',
312318
organizationUnit: 'test',
313319
commonName: 'www.node.ee',
314-
emailAddress: '[email protected]'
320+
emailAddress: '[email protected]',
321+
dc: ''
315322
};
316323
pem.createCertificate(Object.create(certInfo), function(error, data) {
317324
var certificate = (data && data.certificate || '').toString();

0 commit comments

Comments
 (0)