-
Notifications
You must be signed in to change notification settings - Fork 101
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
Implement encoder/decoder #2
Comments
The more I look into this, the more I'm confused. Sample questions (I guess to @levitte @mattcaswell @romen if you'd have time):
-> How and where does the "global default lib context" as per the error message come into play again? I'd have thought my explicit command line has switched it off (?) Or did I already at first try run into a corner as per the below?
(from open-quantum-safe/openssl#243 (comment)) -> Should I rather open issues/questions for this in the main OpenSSL issues tracking system? Thanks in advance for any feedback/input as per the questions above! |
Quickly commenting on the third issue: does it go away if the provider argument comes before the algorithm selection (or if the provider is loaded via conf file)? |
This seems like a reasonable approach - with the addition that you should ideally check that the thing you have decoded has the same values in it as the thing you encoded. You might take some inspiration from test/endecode_test.c. Obviously this will only test that you can serialize a key to a file and deserialize it again. What it won't do is test that you got the encoding correct according to standards. The only real way to do that is to do some kind of interoperability testing with other implementations (if there are any).
For decoding there is a generic pem-to-der decoder. So you only need to implement the der-to-key decoder. The implementation should be able to chain the two together and give you pem-to-key "for free". I believe the current encoder implementation doesn't have this same flexibility and so you need to support both pem and der. I think this is probably one of those "rough" corners and I think @levitte wanted to harmonise the way encoders work with the way decoders work a bit more. Perhaps @levitte can comment here? Wrt "text", that's only relevant for encoding. The command line apps use the text encoders to be able to display details about keys to the user with the various "-text" command line options (e.g. "openssl pkey -text"). So if you want end users to be able to examine the details of keys you'll need a text encoder.
Hmmm. This looks like it should work. Probably raise this as an issue in our tracker so someone takes a look at it.
No - your command line just loads providers. It doesn't say anything about which lib ctx is used. Its perfectly possible (and normal) to load providers into the global default lib ctx, and this is what the command line apps generally do - so nothing unusual there. |
Excellent question. The answer points to a real bug in the code:
never returns but sends my CPU load to 100%..... |
For testing, I would actually check the result against files that you have generated with your 1.1.1 port of OQS. Basically, build up a set of test vectors and use that as a reference for "getting it right". |
Yes, that's more or less it. |
@baentsch : quick tip: have a look at |
Implementing encoder functionality means the OQS-provider needs to deliver ASN.1 objects for all OQS algorithms. To avoid writing our own ASN.1 generator, we use in the OQS-OpenSSL 1.1.1 fork the Makefile target For the standalone provider, it'd also be straightforward to (re)use the OpenSSL object generator perl scripts, but there's something making me uneasy about this: a) re-using "someone else's code" -- albeit that should be OK as we'd be calling into source code complete with OpenSSL Copyright notices. More troubling in my eyes is that b) this generates header files with OpenSSL Copyright notices -- and we'd need to check them in: That arguably is not OK, right? Specifically tagging @levitte and @mattcaswell for guidance on this. WIP code to see what I mean available here with resultant headers e.g. here. Comments and alternative suggestions (pointer to other OID->ASN-object generator code if available?) very welcome. |
I don't see a problem here. You aren't distributing OpenSSL itself. You just expect it to be present in order to form part of your toolchain, e.g. just like gcc, or "make", or whatever other tools you use.
Caveating my answer with "I am not a lawyer" so I can only offer "opinion", but... its difficult to see how we (OpenSSL) could claim copyright on those generated sources any more than "gcc" could claim copyright on the object files it generates from your ".c" files. The "data" is just your data from the objects.txt input file that you wrote in a reformatted form. And the "structural" bits seem trivial. The objects.pl script is available under the Apache license and therefore you are allowed to amend it. So one "hack" you could do to "fix" this, is for your scripts to create a temporary copy of objects.pl and then automatically hack it to amend the generated copyright message to one of your choosing. Create the header files using the hacked objects.pl, and then delete it. Or alternatively, if you're willing to have the Apache 2 licensed code in your repo, just take a copy of that one script. Modify the copyright message it generates and commit the script, and use your copy of the script henceforth. We do something similar with some third party perl stuff that we use here: https://github.com/openssl/openssl/blob/master/external/perl/Downloaded.txt |
Thanks for the many suggestions, @mattcaswell ! I think I'll go for
|
Now "found" an alternative way to the above: Using the core/provider callbacks to register new algorithms' OIDs ( However, one issue has me wondering: In order for the X509(pubkey) logic to work correctly ("find" the new/provider signature algorithms), it seems to be required to also call into If so, this is conceptually great, if there were a message digest that one could meaningfully register when calling So my question is this: Would it make sense (to change its implementation) for As always thanks in advance for suggestions/corrections. |
Well, my first question is, why do you want to implement EncryptedPrivateKeyInfo -> PrivateKeyInfo decoding? There is already a decoder that does this explicitly in OpenSSL. However, there's really nothing magic about our internal pw functions, they should be easy to replicate... something like this would do: struct key2any_ctx_st {
PROV_OQS_CTX *provctx;
/* Set to 0 if parameters should not be saved (dsa only) */
int save_parameters;
/* Set to 1 if intending to encrypt/decrypt, otherwise 0 */
int cipher_intent;
EVP_CIPHER *cipher;
OSSL_PASSPHRASE_CALLBACK *pwcb;
void *pwcbarg;
}; // A passphrase wrapper
int get_passphrase(char *pass, size_t pass_size, size_t *pass_len, struct key2any_ctx_st *ctx)
{
return ctx->pwcb(pass, pass_size, pass_len, NULL, ctx->pwcbarg);
} Then use this wrapper instead of ctx->pwcb = pwcb;
ctx->pwcbarg = pwcbarg; There's really not much more to it. The reason that OpenSSL has the set of |
Also, the |
@levitte Thanks very much for the explanation. I failed to grasp how to use the callback but now got it. Is there documentation for this? Would it make sense to point to that in closing openssl/openssl#16746 for the benefit of others? What I found in documentation about the callback arguments doesn't seem to be totally in line with the above. |
Asking for advice from @mattcaswell @levitte (rephrasing/shortening the above]: Is it intentional/required for a provider to call When not doing this, So my question is this: Would it make sense (to change its implementation) for |
Hi @baentsch ,
I don't think the logic would be so deeply embedded as both ED25519 and ED448 can also sign arbitrary length data. If you investigate what they do, you can try to mimic the approach taken there. |
There is precedent in OpenSSL for signature algs without an associated digest. For example Ed25519 and Ed448 do not use one. See: IMO the correct thing to do would be to still call However, I note that we actually explicitly disallow this, even though we have built-in algorithms that do this: This seems like a bug to me. |
I raised this as a bug in OpenSSL: |
DOH! I stand corrected. |
"Glad" to hear that: Already ran into that but assumed there was a good reason for that check. Thanks for creating OpenSSL#16761: If that were resolved (permitting sig ops without digest) the issue here would indeed be dealt with. |
As per https://www.openssl.org/docs/manmaster/man7/provider-encoder.html
The text was updated successfully, but these errors were encountered: