-
-
Notifications
You must be signed in to change notification settings - Fork 655
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
sys.ssl.Certificate API #9018
Comments
Another thing I don't understand in the actual implementations is this class Certificate {
var __h:Null<Certificate>;
var __x:CertificatePtr;
@:allow(sys.ssl.Socket)
function new(x:CertificatePtr, ?h:Null<Certificate>) {
__x = x;
__h = h;
} The only place this is read at is the public function next():Null<Certificate> {
var n = NativeSsl.cert_get_next(__x);
return n == null ? null : new Certificate(n, __h == null ? this : __h);
} Seems to me like this is entirely pointless because all we do with it is pass it through to other instances. |
It looks like that code is almost trying to emulate something like a chain in mbedtls. |
Another thing I find strange is that various functions have a built-in looping mechanism like so: HL_PRIM vbyte *HL_NAME(cert_get_issuer)(hl_ssl_cert *cert, vbyte *objname) {
mbedtls_x509_name *obj;
int r;
const char *oname, *rname;
obj = &cert->c->issuer;
if (obj == NULL)
hl_error("Invalid issuer");
rname = (char*)objname;
while (obj != NULL) {
r = mbedtls_oid_get_attr_short_name(&obj->oid, &oname);
if (r == 0 && strcmp(oname, rname) == 0)
return asn1_buf_to_string(&obj->val);
obj = obj->next;
}
return NULL;
} This corresponds to the Haxe function Has this API ever been used before? If so, I'd love to see some usage sample so I get a better understanding of what exactly we're exposing here and why. |
Oh I see, this isn't the And
|
static function readPEM(data:String, isPublic:Bool, ?pass:String):Key;
static function readDER(data:haxe.io.Bytes, isPublic:Bool):Key; This won't allow a DER format with a password, which is not something
In fact, the HL implementation calls the same function with or without password in the PEM case: else if (pass == NULL)
r = mbedtls_pk_parse_key(pk, buf, len, NULL, 0);
else
r = mbedtls_pk_parse_key(pk, buf, len, (const unsigned char*)pass, strlen((char*)pass)); It seems like the only distinction at Haxe-level should be between the |
Well, I guess nobody really cares about this. |
I ran into some of these issues and more while attempting to implement a non mbedtls ssl for hxcpp (HaxeFoundation/hxcpp#1135). For Could we change this to say that you must pass in a valid OID string instead (e.g. '2.5.4.3' for CommonName) to remove this ambiguity? We could provide an enum abstract with common OIDs since they're not very intuative. enum abstract DistinguishedNames(String) to String {
var CommonName = '2.5.4.3';
} When I first ran into this I looked around github and it seems the only "real" (non test code) user of these two functions is an OpenFL certificate class, and the function which uses them doesn't seem to be used in any other projects so while technically breaking behaviour the number of people effected would probably be close to zero. |
While working on #9009 I noticed that the existing sys.ssl.Certificate API (on neko, cpp and hl) offers various functions that create new certificates. https://github.com/HaxeFoundation/hashlink/blob/master/libs/ssl/ssl.c calls
mbedtls_x509_crt_init
in these functions:cert_load_file
cert_load_path
cert_load_defaults
cert_add_pem
cert_add_der
The mbedtls x509_crt API works differently in that functions operate on a single
chain
instance and then "add them to the chained list". This means that through the Haxe API, we couldn't create a certificate chain that involves, for instance, twoparse_file
calls.It seems more straightforward to have a real constructor for
Certificate
and then define all these chaining operations as instance methods:I don't know if this is something worth changing, but we should at least discuss it. I'd be willing to work on this, though I'm concerned about the fact that we have zero tests for this stuff.
The text was updated successfully, but these errors were encountered: