-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Fix Support for ssh-certificates #477
Open
Senjuu
wants to merge
1
commit into
romanz:master
Choose a base branch
from
Senjuu:fix-sign-certificate
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+107
−11
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
"""Utilities for signing ssh-certificates.""" | ||
import io | ||
|
||
from . import formats, util | ||
|
||
|
||
def _parse_stringlist(i): | ||
res = [] | ||
length, = util.recv(i, '>L') | ||
while length >= 4: | ||
size, = util.recv(i, '>L') | ||
length -= 4 | ||
size = min(size, length) | ||
if size == 0: | ||
continue | ||
res.append(util.recv(i, size).decode('utf8')) | ||
length -= size | ||
return res | ||
|
||
|
||
def parse(blob): | ||
"""Parses a data blob to a to-be-signed ssh-certificate.""" | ||
# https://github.com/openssh/openssh-portable/blob/master/PROTOCOL.certkeys | ||
res = {} | ||
i = io.BytesIO(blob) | ||
firstString = util.read_frame(i) | ||
if firstString.endswith(b'cert-v01@openssh.com'): | ||
res['isCertificate'] = True | ||
_certificate_key_type = firstString | ||
_nonce = util.read_frame(i) | ||
if (_certificate_key_type.startswith(b'ssh-rsa')): | ||
_pub_key = {} | ||
_pub_key['e'] = util.read_frame(i) | ||
_pub_key['n'] = util.read_frame(i) | ||
elif (_certificate_key_type.startswith(b'ssh-dsa')): | ||
_pub_key = {} | ||
_pub_key['p'] = util.read_frame(i) | ||
_pub_key['q'] = util.read_frame(i) | ||
_pub_key['g'] = util.read_frame(i) | ||
_pub_key['y'] = util.read_frame(i) | ||
elif (_certificate_key_type.startswith(b'ecdsa-sha2-nistp')): | ||
_curve = util.read_frame(i) | ||
_pub_key = util.read_frame(i) | ||
elif (_certificate_key_type.startswith(b'ssh-ed25519')): | ||
_pub_key = util.read_frame(i) | ||
else: | ||
raise ValueError('unknown certificate key type: '+_certificate_key_type.decode('utf8')) | ||
_serial_number, = util.recv(i, '>Q') | ||
res['certificate_type'], = util.recv(i, '>L') | ||
_key_id_ = util.read_frame(i) | ||
res['principals'] = _parse_stringlist(i) | ||
res['principals'] = ', '.join(res['principals']) | ||
_valid_after, = util.recv(i, '>Q') | ||
_valid_before, = util.recv(i, '>Q') | ||
_critical_options = _parse_stringlist(i) | ||
_extensions = _parse_stringlist(i) | ||
_reserved = util.read_frame(i) | ||
_signature_key = util.read_frame(i) | ||
assert not i.read() | ||
return res | ||
res['isCertificate'] = False | ||
i.close() | ||
return res | ||
|
||
|
||
def format(certificate): | ||
""" | ||
Makes certificate better human readable. | ||
|
||
Formats list properties to comma seperated strings and | ||
the signature key to human readable string. | ||
""" | ||
certificate['principals'] = ', '.join(certificate['principals']) | ||
certificate['critical_options'] = ', '.join(certificate['critical_options']) | ||
certificate['extensions'] = ', '.join(certificate['extensions']) | ||
certificate['signature_key'] = formats.parse_pubkey(certificate['signature_key']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no
format()
defined inlibagent.ssh.certificate
module.It produces the following error: