Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow for adding ssh extensions to certificate #63

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,9 @@ Parameters
`lifetime` will be ignored
- `serial` -- optional Buffer, the serial number of the certificate
- `purposes` -- optional Array of String, X.509 key usage restrictions
- `extensions` -- optional Array of String to defined openssh extensions
permit-pty, permit-user-rc, permit-port-forwarding,
permit-agent-forwarding, permit-X11-forwarding

### `Certificate#subjects`

Expand Down
32 changes: 28 additions & 4 deletions lib/certificate.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,26 @@ Certificate.createSelfSigned = function (subjectOrSubjects, key, options) {
purposes.indexOf('encryption') === -1)
purposes.push('encryption');
}
}
}

var extensions = (options.extensions || []).map((ext) => {
return {
"critical": false,
"name": ext,
"format": "openssh"
}
})

var signatures = {}
if (extensions.length > 0)
signatures = { openssh: { exts: extensions }}

var cert = new Certificate({
subjects: subjects,
issuer: subjects[0],
subjectKey: key.toPublic(),
issuerKey: key.toPublic(),
signatures: {},
signatures: signatures,
serial: serial,
validFrom: validFrom,
validUntil: validUntil,
Expand Down Expand Up @@ -353,12 +365,24 @@ Certificate.create =
purposes.push('encryption');
}

var cert = new Certificate({
var extensions = (options.extensions || []).map((ext) => {
return {
"critical": false,
"name": ext,
"format": "openssh"
}
})

var signatures = {}
if (extensions.length > 0)
signatures = { openssh: { exts: extensions } }

var cert = new Certificate({
subjects: subjects,
issuer: issuer,
subjectKey: key,
issuerKey: issuerKey.toPublic(),
signatures: {},
signatures: signatures,
serial: serial,
validFrom: validFrom,
validUntil: validUntil,
Expand Down
7 changes: 5 additions & 2 deletions lib/formats/openssh-cert.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,11 @@ function toBuffer(cert, noSig) {
exts.forEach(function (ext) {
if (ext.critical === true)
return;
extbuf.writeString(ext.name);
extbuf.writeBuffer(ext.data);
extbuf.writeString(ext.name);
if ('data' in ext)
extbuf.writeBuffer(ext.data);
else
extbuf.writeString('');
});
buf.writeBuffer(extbuf.toBuffer());

Expand Down