-
Notifications
You must be signed in to change notification settings - Fork 56
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
feat(tls-certificate): generate and parse libp2p tls certificate #1209
base: master
Are you sure you want to change the base?
Conversation
const extValueSize = 256 # Buffer size for ASN.1 encoding | ||
var | ||
extValue: array[extValueSize, byte] | ||
extPtr: ptr byte = addr extValue[extValueSize - 1] # Start at the end of the buffer |
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.
At first I thought it was an error, I had to check mbedtls_asn1_write_octet_string
to understand that this function works backward. Maybe you can add this as a comment somewhere.
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.
done.
|
||
# Exception types for TLS certificate errors | ||
type | ||
TLSCertificateError* = object of Exception |
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.
As it is inside nim-libp2p, maybe inherit from LPError instead of exception?
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.
done.
return extValueSeq | ||
|
||
proc makeLibp2pExtension( | ||
identityKeypair: KeyPair, certificateKeypair: mbedtls_pk_context |
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.
Maybe it's my C background talking, but I would use a ptr mbedtls_pk_context
here instead of mbedtls_pk_context
. It could work in Nim (I'm not sure if it uses a copy, a reference or a pointer for this kind of call), but as mbedtls only use pointer for their context, I would change that for our own function aswell.
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.
What's the benefit of it? I don't think this is a pattern in Nim, is it?
for i in 0 ..< LIBP2P_EXT_OID_DER.len: | ||
if ptrInc(oid.p, i.uint)[] != LIBP2P_EXT_OID_DER[i]: | ||
return MBEDTLS_ERR_OID_NOT_FOUND # Extension not handled by this callback |
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.
Maybe use nimCmpMem
? Not sure if importing just for that is necessary.
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.
Where is it defined?
aedd4d3
to
e2e6b6b
Compare
The certificates that was being generated was considered invalid due to not having a serial number. This was fixed in last commit and now the certificates are readable in openssl:
cc: @kaiserd |
Commits must follow the Conventional Commits specification
|
This PR implements the certificate generation and parsing for https://github.com/libp2p/specs/blob/master/tls/tls.md.