-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add kem support #4
Changes from all commits
b1f866a
71b9b35
3974259
5de3e13
0a32ca5
19b5539
9545e41
181afc4
191ed08
367bcf5
b072001
77fd2df
43f7b08
3b53f3b
464079e
ba6dcd5
8f53865
58b8b0f
0a56fe6
a00cf23
7587a73
43e4703
e090035
8e9151d
36505aa
4b14d3d
ed6fb45
28bc2b3
b219a7d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -391,10 +391,31 @@ static OSSL_CMP_PKISI *process_rr(OSSL_CMP_SRV_CTX *srv_ctx, | |
return OSSL_CMP_PKISI_dup(ctx->statusOut); | ||
} | ||
|
||
static OSSL_CMP_ITAV *process_genm_itav(mock_srv_ctx *ctx, int req_nid, | ||
const OSSL_CMP_ITAV *req) | ||
/* TODO: extend it to check for certificate with KEM key (PQ keys) */ | ||
static X509 *extracert_withKEM(STACK_OF(X509) *certs) | ||
{ | ||
OSSL_CMP_ITAV *rsp; | ||
int i; | ||
|
||
if (certs == NULL) | ||
return NULL; | ||
|
||
for (i = 0; i < sk_X509_num(certs); i++) { | ||
X509 *cert = sk_X509_value(certs, i); | ||
|
||
if ((X509_get_key_usage(cert) & X509v3_KU_KEY_ENCIPHERMENT)) { | ||
return cert; | ||
} | ||
} | ||
return NULL; | ||
} | ||
|
||
static OSSL_CMP_ITAV *process_genm_itav(OSSL_CMP_SRV_CTX *srv_ctx, | ||
int req_nid, | ||
const OSSL_CMP_ITAV *req, | ||
const OSSL_CMP_MSG *genm) | ||
{ | ||
OSSL_CMP_ITAV *rsp = NULL; | ||
mock_srv_ctx *ctx = OSSL_CMP_SRV_CTX_get0_custom_ctx(srv_ctx); | ||
|
||
switch (req_nid) { | ||
case NID_id_it_caCerts: | ||
|
@@ -405,6 +426,18 @@ static OSSL_CMP_ITAV *process_genm_itav(mock_srv_ctx *ctx, int req_nid, | |
ctx->newWithOld, | ||
ctx->oldWithNew); | ||
break; | ||
case NID_id_it_KemCiphertextInfo: | ||
if (OSSL_CMP_ITAV_get0_value(req) == NULL) { | ||
X509 *kemcert; | ||
|
||
/* TODO: add certificate path validation */ | ||
kemcert = extracert_withKEM(OSSL_CMP_MSG_get_extraCerts(genm)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Trying to determine if the sender side uses a KEM cert this way can go wrong. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree it is not the best way and also certificate validation need to be performed ( will add TODO). |
||
if (kemcert == NULL) | ||
break; | ||
rsp = OSSL_CMP_SRV_kem_get_ss(srv_ctx, X509_get0_pubkey(kemcert)); | ||
break; | ||
} | ||
/* fall through */ | ||
default: | ||
rsp = OSSL_CMP_ITAV_dup(req); | ||
} | ||
|
@@ -434,7 +467,7 @@ static int process_genm(OSSL_CMP_SRV_CTX *srv_ctx, | |
|
||
if ((*out = sk_OSSL_CMP_ITAV_new_reserve(NULL, 1)) == NULL) | ||
return 0; | ||
rsp = process_genm_itav(ctx, OBJ_obj2nid(obj), req); | ||
rsp = process_genm_itav(srv_ctx, OBJ_obj2nid(obj), req, genm); | ||
if (rsp != NULL && sk_OSSL_CMP_ITAV_push(*out, rsp)) | ||
return 1; | ||
sk_OSSL_CMP_ITAV_free(*out); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,33 @@ ASN1_SEQUENCE(OSSL_CMP_CAKEYUPDANNCONTENT) = { | |
} ASN1_SEQUENCE_END(OSSL_CMP_CAKEYUPDANNCONTENT) | ||
IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_CAKEYUPDANNCONTENT) | ||
|
||
ASN1_SEQUENCE(OSSL_CMP_RSAKEMPARAMETERS) = { | ||
ASN1_SIMPLE(OSSL_CMP_RSAKEMPARAMETERS, KeyDerivationFunction, X509_ALGOR), | ||
ASN1_SIMPLE(OSSL_CMP_RSAKEMPARAMETERS, KeyLength, ASN1_INTEGER) | ||
} ASN1_SEQUENCE_END(OSSL_CMP_RSAKEMPARAMETERS) | ||
IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_RSAKEMPARAMETERS) | ||
Comment on lines
+58
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think. this is entirely independent of CMP and should go into some more general OpenSSL source file. |
||
|
||
ASN1_SEQUENCE(OSSL_CMP_KEMCIPHERTEXTINFO) = { | ||
ASN1_SIMPLE(OSSL_CMP_KEMCIPHERTEXTINFO, kem, X509_ALGOR), | ||
ASN1_SIMPLE(OSSL_CMP_KEMCIPHERTEXTINFO, ct, ASN1_OCTET_STRING) | ||
} ASN1_SEQUENCE_END(OSSL_CMP_KEMCIPHERTEXTINFO) | ||
IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_KEMCIPHERTEXTINFO) | ||
|
||
ASN1_SEQUENCE(OSSL_CMP_KEMOTHERINFO) = { | ||
ASN1_SEQUENCE_OF(OSSL_CMP_KEMOTHERINFO, staticString, ASN1_UTF8STRING), | ||
ASN1_SIMPLE(OSSL_CMP_KEMOTHERINFO, transactionID, ASN1_OCTET_STRING), | ||
ASN1_EXP_OPT(OSSL_CMP_KEMOTHERINFO, kemContext, ASN1_OCTET_STRING, 0), | ||
} ASN1_SEQUENCE_END(OSSL_CMP_KEMOTHERINFO) | ||
IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_KEMOTHERINFO) | ||
|
||
ASN1_SEQUENCE(OSSL_CMP_KEMBMPARAMETER) = { | ||
ASN1_SIMPLE(OSSL_CMP_KEMBMPARAMETER, kdf, X509_ALGOR), | ||
ASN1_EXP_OPT(OSSL_CMP_KEMBMPARAMETER, kemContext, ASN1_OCTET_STRING, 0), | ||
ASN1_SIMPLE(OSSL_CMP_KEMBMPARAMETER, len, ASN1_INTEGER), | ||
ASN1_SIMPLE(OSSL_CMP_KEMBMPARAMETER, mac, X509_ALGOR) | ||
} ASN1_SEQUENCE_END(OSSL_CMP_KEMBMPARAMETER) | ||
IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_KEMBMPARAMETER) | ||
|
||
ASN1_SEQUENCE(OSSL_CMP_ERRORMSGCONTENT) = { | ||
ASN1_SIMPLE(OSSL_CMP_ERRORMSGCONTENT, pKIStatusInfo, OSSL_CMP_PKISI), | ||
ASN1_OPT(OSSL_CMP_ERRORMSGCONTENT, errorCode, ASN1_INTEGER), | ||
|
@@ -120,6 +147,9 @@ ASN1_ADB(OSSL_CMP_ITAV) = { | |
ADB_ENTRY(NID_id_it_certProfile, | ||
ASN1_SEQUENCE_OF_OPT(OSSL_CMP_ITAV, infoValue.certProfile, | ||
ASN1_UTF8STRING)), | ||
ADB_ENTRY(NID_id_it_KemCiphertextInfo, | ||
ASN1_OPT(OSSL_CMP_ITAV, infoValue.KemCiphertextInfoValue, | ||
OSSL_CMP_KEMCIPHERTEXTINFO)), | ||
} ASN1_ADB_END(OSSL_CMP_ITAV, 0, infoType, 0, | ||
&infotypeandvalue_default_tt, NULL); | ||
|
||
|
@@ -223,6 +253,74 @@ int OSSL_CMP_ITAV_get0_certProfile(const OSSL_CMP_ITAV *itav, | |
return 1; | ||
} | ||
|
||
OSSL_CMP_ITAV *ossl_cmp_itav_new_KemCiphertext(X509_ALGOR *kem, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For consistency, either move definitions of similar constructors such as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved definition of ossl_cmp_kem_KemOtherInfo_new( ) to cmp_asn.c |
||
unsigned char *in_ct, | ||
int len) | ||
{ | ||
OSSL_CMP_ITAV *itav = NULL; | ||
OSSL_CMP_KEMCIPHERTEXTINFO *KemCtInfoValue; | ||
|
||
if (kem == NULL || in_ct == NULL) | ||
return NULL; | ||
|
||
if ((KemCtInfoValue = OSSL_CMP_KEMCIPHERTEXTINFO_new()) == NULL | ||
|| !ossl_cmp_x509_algor_set0(&KemCtInfoValue->kem, kem) | ||
|| !ossl_cmp_asn1_octet_string_set1_bytes(&KemCtInfoValue->ct, | ||
in_ct, len)) | ||
goto err; | ||
|
||
if ((itav = OSSL_CMP_ITAV_new()) == NULL) | ||
goto err; | ||
|
||
itav->infoType = OBJ_nid2obj(NID_id_it_KemCiphertextInfo); | ||
itav->infoValue.KemCiphertextInfoValue = KemCtInfoValue; | ||
|
||
return itav; | ||
|
||
err: | ||
OSSL_CMP_KEMCIPHERTEXTINFO_free(KemCtInfoValue); | ||
OSSL_CMP_ITAV_free(itav); | ||
return NULL; | ||
} | ||
|
||
#define KEMCMP_STATICSTRING "CMP-KEM" | ||
int ossl_cmp_kem_KemOtherInfo_new(OSSL_CMP_CTX *ctx, | ||
unsigned char **out, int *len) | ||
{ | ||
int ret = 0; | ||
OSSL_CMP_KEMOTHERINFO *kemOtherInfo; | ||
|
||
if (out == NULL || len == NULL) | ||
return 0; | ||
|
||
if ((kemOtherInfo = OSSL_CMP_KEMOTHERINFO_new()) == NULL) | ||
return 0; | ||
|
||
if (!ossl_cmp_sk_ASN1_UTF8STRING_push_str(kemOtherInfo->staticString, | ||
KEMCMP_STATICSTRING, -1)) | ||
goto err; | ||
|
||
kemOtherInfo->transactionID = ctx->transactionID; | ||
|
||
#if 0 | ||
/*setting kemContext with ct for testing*/ | ||
if (ctx->kem_ct != NULL | ||
&& !ossl_cmp_asn1_octet_string_set1(&kemOtherInfo->kemContext, | ||
ctx->kem_ct)) | ||
goto err; | ||
#endif | ||
*out = NULL; | ||
if ((*len = i2d_OSSL_CMP_KEMOTHERINFO(kemOtherInfo, out)) <= 0) | ||
goto err; | ||
|
||
ret = 1; | ||
|
||
err: | ||
kemOtherInfo->transactionID = NULL; | ||
OSSL_CMP_KEMOTHERINFO_free(kemOtherInfo); | ||
return ret; | ||
} | ||
|
||
OSSL_CMP_ITAV *OSSL_CMP_ITAV_new_caCerts(const STACK_OF(X509) *caCerts) | ||
{ | ||
OSSL_CMP_ITAV *itav = OSSL_CMP_ITAV_new(); | ||
|
@@ -303,7 +401,7 @@ OSSL_CMP_ITAV *OSSL_CMP_ITAV_new_rootCaKeyUpdate(const X509 *newWithNew, | |
itav->infoValue.rootCaKeyUpdate = upd; | ||
return itav; | ||
|
||
err: | ||
err: | ||
OSSL_CMP_ROOTCAKEYUPDATE_free(upd); | ||
return NULL; | ||
} | ||
|
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.
Taking the key usage can easily go wrong - maybe for RSA keys there is not much better choice,
but at least add a TODO for other key types (such as PQ keys) that checking the key type (as far as makes sense) needs to be preferrred.